function uploadFile($filename, $userfile_name, &$msg, $tmp_folder = '') { if (!$tmp_folder) { $tmp_folder = JPATH_SITE . DS . "tmp"; } jimport('joomla.filesystem.path'); $baseDir = JPath::clean($tmp_folder); $baseDir = rtrim($baseDir, DS) . DS; if (file_exists($baseDir)) { if (is_writable($baseDir)) { if (move_uploaded_file($filename, $baseDir . $userfile_name)) { if (JPath::setPermissions($baseDir . $userfile_name)) { return true; } else { $msg = 'Failed to change the permissions of the uploaded file.'; } } else { $msg = 'Failed to move uploaded file to tmp directory.'; } } else { $msg = 'Upload failed as tmp directory is not writable.'; } } else { $msg = 'Upload failed as tmp directory does not exist.'; } return false; }
/** * Chmods files and directories recursively to given permissions. * * @param string $path Root path to begin changing mode [without trailing slash]. * @param string $filemode Octal representation of the value to change file mode to [null = no change]. * @param string $foldermode Octal representation of the value to change folder mode to [null = no change]. * * @return boolean True if successful [one fail means the whole operation failed]. * * @since 11.1 */ public static function setPermissions($path, $filemode = '0644', $foldermode = '0755') { // Initialise return value $ret = true; if (is_dir($path)) { $dh = opendir($path); while ($file = readdir($dh)) { if ($file != '.' && $file != '..') { $fullpath = $path . '/' . $file; if (is_dir($fullpath)) { if (!JPath::setPermissions($fullpath, $filemode, $foldermode)) { $ret = false; } } else { if (isset($filemode)) { if (!@chmod($fullpath, octdec($filemode))) { $ret = false; } } } } } closedir($dh); if (isset($foldermode)) { if (!@chmod($path, octdec($foldermode))) { $ret = false; } } } else { if (isset($filemode)) { $ret = @chmod($path, octdec($filemode)); } } return $ret; }
public static function uploader() { $params = modPwebcontactHelper::getParams(); // check if upload is enabled if (!$params->get('show_upload', 0)) { if (PWEBCONTACT_DEBUG) { modPwebcontactHelper::setLog('Uploader disabled'); } return array('status' => 402, 'files' => array()); } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $path = $params->get('upload_path'); if (!JFolder::exists($path)) { JFolder::create($path, 0777); } if (!is_writable($path) and JPath::canChmod($path)) { JPath::setPermissions($path, null, '0777'); } if (!is_writable($path)) { if (PWEBCONTACT_DEBUG) { modPwebcontactHelper::setLog('Upload dir is not writable'); } return array('status' => 403, 'files' => array()); } // load uploader $uploader = new modPWebContactUploader(array('upload_dir' => $params->get('upload_path'), 'upload_url' => $params->get('upload_url'), 'accept_file_types' => '/(\\.|\\/)(' . $params->get('upload_allowed_ext', '.+') . ')$/i', 'max_file_size' => (double) $params->get('upload_size_limit', 1) * 1024 * 1024, 'image_versions' => array(), 'delete_type' => 'POST'), false, array(1 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_1'), 3 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_3'), 4 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_4'), 6 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_6'), 7 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_7'), 8 => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_8'), 'post_max_size' => JText::_('MOD_PWEBCONTACT_UPLOAD_ERR_1'), 'max_file_size' => JText::_('MOD_PWEBCONTACT_UPLOAD_SIZE_ERR'), 'accept_file_types' => JText::_('MOD_PWEBCONTACT_UPLOAD_TYPE_ERR'))); $response = $uploader->handleRequest(); if (PWEBCONTACT_DEBUG) { modPwebcontactHelper::setLog('Uploader exit'); } return $response; }
/** * Disables the unsupported eAccelerator caching method, replacing it with the * "file" caching method. * * @return void * * @since 3.2 */ function admin_postinstall_eaccelerator_action() { $prev = new JConfig(); $prev = JArrayHelper::fromObject($prev); $data = array('cacheHandler' => 'file'); $data = array_merge($prev, $data); $config = new Registry('config'); $config->loadArray($data); jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); // Set the configuration file path. $file = JPATH_CONFIGURATION . '/configuration.php'; // Get the new FTP credentials. $ftp = JClientHelper::getCredentials('ftp', true); // Attempt to make the file writeable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE')); } // Attempt to write the configuration file as a PHP class named JConfig. $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)); if (!JFile::write($file, $configuration)) { JFactory::getApplication()->enqueueMessage(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'), 'error'); return; } // Attempt to make the file unwriteable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE')); } }
/** * A JParameter object holding the parameters for the plugin * * @var A JParameter object * @access public * @since 1.5 */ public function onCheck() { $mainframe = JFactory::getApplication(); //Check System requirements for the editor define('JCK_BASE', JPATH_CONFIGURATION . DS . 'plugins' . DS . 'editors' . DS . 'jckeditor'); if (!JFolder::exists(JCK_BASE)) { return; } $perms = fileperms(JPATH_CONFIGURATION . DS . 'index.php'); $perms = decoct($perms & 0777); $default_fperms = '0644'; $default_dperms = '0755'; if ($perms == 777 || $perms == 666) { $default_fperms = '0666'; $default_dperms = '0777'; } $fperms = JCK_BASE . DS . 'config.js'; if (!stristr(PHP_OS, 'WIN') && JPath::canChmod(JCK_BASE) && $perms != decoct(fileperms($fperms) & 0777)) { $path = JCK_BASE . DS . 'plugins'; if (!JPath::setPermissions($path, $default_fperms, $default_dperms)) { $mainframe->enqueueMessage(JText::_('Auto correction failed for incorrect file permissions for the JCK Editor'), 'error'); } } $mainframe->enqueueMessage(JText::_('System checked and updated')); }
function save($data) { // Get the previous configuration. if (is_object($data)) { $data = JArrayHelper::fromObject($data); } $prev = JTheFactoryHelper::getConfig(); $prev = JArrayHelper::fromObject($prev); $data = array_merge($prev, $data); $configfile = JTheFactoryAdminHelper::getConfigFile(); $config = new JRegistry('config'); $config->loadArray($data); jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); jimport('joomla.client.helper'); // Get the new FTP credentials. $ftp = JClientHelper::getCredentials('ftp', true); // Attempt to make the file writeable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0644')) { JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE')); } // Attempt to write the configuration file as a PHP class named JConfig. $configString = $config->toString('PHP', array('class' => ucfirst(APP_PREFIX) . "Config", 'closingtag' => false)); if (!JFile::write($configfile, $configString)) { JError::raiseWarning(101, JText::_('FACTORY_SETTINGS_FILE_WRITE_FAILED')); return false; } // Attempt to make the file unwriteable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0444')) { JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE')); } return true; }
/** * doExecute * * @return void * * @throws \Exception */ protected function doExecute() { jimport('joomla.filesystem.file'); $file = JPATH_CONFIGURATION . '/configuration.php'; \JPath::setPermissions($file, '0644'); $config = \JFactory::getConfig(); $config->set('offline', $this->offline); $class = $config->toString('php', array('class' => 'JConfig')); if (!\JFile::write($file, $class)) { throw new \Exception('Writing config fail.'); } \JPath::setPermissions($file, '0444'); $this->out("\nSystem <info>" . strtoupper($this->name) . "</info>"); return; }
/** * Get a page and save it as file. * * @param string $url A url to request. * @param string $path A system path with file name to save it. * @param array $option An option array to override CURL OPT. * * @return Object Object with success or fail information. */ public static function download($url, $path = null, $option = array()) { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.path'); $url = new \JUri($url); $path = \JPath::clean($path); // $folder_path = JPATH_ROOT.DS.'files'.DS.$url->task_id ; if (substr($path, -1) == DIRECTORY_SEPARATOR) { $file_name = basename($url); $file_path = $path . $file_name; $folder_path = $path; } else { $file_path = $path; $folder_path = str_replace(basename($path), '', $file_path); } \JPath::setPermissions($folder_path, 644, 755); if (!\is_dir($folder_path)) { \JFolder::create($folder_path); } $fp = fopen($file_path, 'w+'); $ch = curl_init(); $options = array(CURLOPT_URL => UriHelper::safe($url), CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1", CURLOPT_FOLLOWLOCATION => !ini_get('open_basedir') ? true : false, CURLOPT_FILE => $fp, CURLOPT_SSL_VERIFYPEER => false); // Merge option foreach ($option as $key => $opt) { if (isset($option[$key])) { $options[$key] = $option[$key]; } } curl_setopt_array($ch, $options); curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch); fclose($fp); if ($errno) { $return = new Object(); $return->set('errorCode', $errno); $return->set('errorMsg', $errmsg); return $return; } else { $return = new Object(); $return->set('filePath', $file_path); return $return; } }
function genRandomFilename($directory, $filename = '' , $extension = '', $length = 11) { if (strlen($directory) < 1) return false; $directory = JPath::clean($directory); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); if (!JFile::exists($directory)){ JFolder::create( $directory); JPath::setPermissions($directory, '0777'); } if (strlen($filename) > 0) $filename = JFile::makeSafe($filename); if (!strlen($extension) > 0) $extension = ''; $dotExtension = $filename ? JFile::getExt($filename) : $extension; $dotExtension = $dotExtension ? '.' . $dotExtension : ''; $map = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $len = strlen($map); $stat = stat(__FILE__); $randFilename = ''; if(empty($stat) || !is_array($stat)) $stat = array(php_uname()); mt_srand(crc32(microtime() . implode('|', $stat))); for ($i = 0; $i < $length; $i ++) { $randFilename .= $map[mt_rand(0, $len -1)]; } $randFilename .= $dotExtension; if (JFile::exists($directory . DS . $randFilename)) { genRandomFilename($directory, $filename, $extension, $length); } return $randFilename; }
function resize($src, $dest = null, $width, $height, $quality, $sx = null, $sy = null, $sw = null, $sh = null) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); require_once dirname(__FILE__) . DS . 'wideimage' . DS . 'WideImage.php'; if (!isset($dest) || $dest == '') { $dest = $src; } $ext = strtolower(JFile::getExt($src)); $src = @JFile::read($src); if ($src) { $image = @WideImage::loadFromString($src); // cropped thumbnail if (($sx || $sy) && $sw && $sh) { $result = @$image->crop($sx, $sy, $sw, $sh)->resize($width, $height, 'fill'); } else { $result = @$image->resize($width, $height); } switch ($ext) { case 'jpg': case 'jpeg': $quality = intval($quality); if ($this->get('ftp', 0)) { @JFile::write($dest, $result->asString($ext, $quality)); } else { @$result->saveToFile($dest, $quality); } break; default: if ($this->get('ftp', 0)) { @JFile::write($dest, $result->asString($ext)); } else { @$result->saveToFile($dest); } break; } unset($image); unset($result); } if (file_exists($dest)) { @JPath::setPermissions($dest); return $dest; } return false; }
public function setDatabaseType() { $path = JPATH_CONFIGURATION . '/configuration.php'; $result = false; // Set FTP credentials, if given jimport('joomla.client.helper'); $ftp = JClientHelper::getCredentials('ftp'); jimport('joomla.filesystem.path'); if ($ftp['enabled'] || JPath::isOwner($path) && JPath::setPermissions($path, '0644')) { $search = JFile::read($path); $replaced = str_replace('$dbtype = \'mysql\';', '$dbtype = \'mysqli\';', $search); $result = JFile::write($path, $replaced); if (!$ftp['enabled'] && JPath::isOwner($path)) { JPath::setPermissions($path, '0444'); } } return $result; }
/** * Up **/ public function up() { // Update configuration, replacing mysql with pdo $configuration = file_get_contents(PATH_ROOT . DS . 'configuration.php'); $configuration = preg_replace('/(var \\$dbtype[\\s]*=[\\s]*[\'"]*)mysql([\'"]*)/', '$1pdo$2', $configuration); // The configuration file typically doesn't even give write permissions to the owner // Change that and then write it out $permissions = substr(decoct(fileperms(PATH_ROOT . DS . 'configuration.php')), 2); if (substr($permissions, 1, 1) != '6') { \JPath::setPermissions(PATH_ROOT . DS . 'configuration.php', substr_replace($permissions, '6', 1, 1)); } if (!file_put_contents(PATH_ROOT . DS . 'configuration.php', $configuration)) { $this->setError('Unable to write out new configuration file: permission denied', 'warning'); return false; } // Change permissions back to what they were before \JPath::setPermissions(PATH_ROOT . DS . 'configuration.php', $permissions); }
function delete(&$id) { $element = $this->get(reset($id)); if (!$element) { return false; } jimport('joomla.filesystem.file'); if (!JFile::exists($element->override)) { return true; } jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); if (!$ftp['enabled'] && !JPath::setPermissions($element->override, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', JText::sprintf('FILE_NOT_WRITABLE', $element->override)); } $result = JFile::delete($element->override); return $result; }
public function display() { //Prepare MediaHelper JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php'); //Set the cache expire, which is 3 months in seconds $this->expires = 7889231; $item = $this->getModel()->getItem(); $image = $this->getModel()->getImage(); if (is_a($image, 'ComNinjaHelperImage')) { $path = $image->file; } else { $path = $image; $image = KFactory::get('admin::com.ninja.helper.image', array('image' => $path)); } //$this->mimetype = 'image/'.MediaHelper::getTypeIcon($image->file); $this->mimetype = $image->mime; $identifier = $this->getIdentifier(); $cache = JPATH_ROOT . '/cache/com_' . $identifier->package . '/' . KInflector::pluralize($this->getName()); $cache .= '/' . $item->id . '/' . $identifier->name . '&' . urldecode(http_build_query($image->actions)) . '.' . $image->ext; if (!JFile::exists($cache)) { //To avoid "image directory unwritable" messages JFile::write($cache, ''); $image->save($cache); JPath::setPermissions($cache); } else { //Time since created, in seconds $mtime = filemtime($cache); $created = time() - date('U', $mtime); //Set modified since header //header('Last-Modified: '.gmdate("D, d M Y H:i:s", $mtime).' GMT'); if ($created > $this->expires) { //To avoid permission errors on some systems, delete the image first instead of overwriting JFile::delete($cache); $image->save($cache); JPath::setPermissions($cache); } } $this->disposition = 'inline'; $this->output = JFile::read($cache); $this->filename = basename($path); return parent::display(); }
/** * Check if the path exists, and if not, tries to create it * @param string $dir * @param bool $create */ function checkDirectory($dir, $create = true) { $return = true; if (!($exists = JFolder::exists($dir))) { if ($create) { if (!($return = JFolder::create($dir))) { self::setError("Attempted to Create Dir But Failed"); } } else { $return = false; self::setError("Dir Does Not Exist and Did Not Attempt to Create"); } } if (!is_writable($dir)) { if (!($change = JPath::setPermissions($dir))) { self::setError("Changing Permissions on Dir Failed"); } } return $return; }
/** * Saves the css * */ function savecss() { global $mainframe; JRequest::checkToken() or die('Invalid Token'); // Initialize some variables $option = JRequest::getVar('option'); $filename = JRequest::getVar('filename', '', 'post', 'cmd'); $filecontent = JRequest::getVar('filecontent', '', '', '', JREQUEST_ALLOWRAW); if (!$filecontent) { $mainframe->redirect('index.php?option=' . $option, JText::_('OPERATION FAILED') . ': ' . JText::_('CONTENT EMPTY')); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = JPATH_SITE . DS . 'components' . DS . 'com_eventlist' . DS . 'assets' . DS . 'css' . DS . $filename; // Try to make the css file writeable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', 'COULD NOT MAKE CSS FILE WRITABLE'); } jimport('joomla.filesystem.file'); $return = JFile::write($file, $filecontent); // Try to make the css file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', 'COULD NOT MAKE CSS FILE UNWRITABLE'); } if ($return) { $task = JRequest::getVar('task'); switch ($task) { case 'applycss': $mainframe->redirect('index.php?option=' . $option . '&view=editcss', JText::_('CSS FILE SUCCESSFULLY ALTERED')); break; case 'savecss': default: $mainframe->redirect('index.php?option=' . $option, JText::_('CSS FILE SUCCESSFULLY ALTERED')); break; } } else { $mainframe->redirect('index.php?option=' . $option, JText::_('OPERATION FAILED') . ': ' . JText::sprintf('FAILED TO OPEN FILE FOR WRITING', $file)); } }
protected function onAfterSave(&$table) { if ($table->body_source == 'file' && $table->body_source_file != '-1') { jimport('joomla.filesystem.file'); $app = JFactory::getApplication(); $fileName = $table->body_source_file; $filePath = JPath::clean(JPATH_ADMINISTRATOR . '/components/com_j2store/views/emailtemplate/tpls/' . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); $user = get_current_user(); chown($filePath, $user); JPath::setPermissions($filePath, '0644'); // Try to make the template file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } $source = JFactory::getApplication()->input->get('source', '', 'RAW'); jimport('joomla.filter.filterinput'); $filter = JFilterInput::getInstance(null, null, 1, 1); $value = $filter->clean($source, 'raw'); $return = true; if (!empty($value)) { $return = JFile::write($filePath, $value); } // Try to make the template file unwritable. if (JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'), 'error'); return false; } elseif (!$return) { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } } }
function save() { $app =& JFactory::getApplication(); // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = JPATH_RSGALLERY2_SITE . '/templates/' . $this->template . '/html/' . $this->filename; // Try to make the css file writeable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', 'Could not make the html file writable'); } jimport('joomla.filesystem.file'); $return = JFile::write($file, $this->content); // Try to make the css file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', 'Could not make the html file unwritable'); } if ($return) { $app->enqueueMessage('File saved'); } return $return; }
/** * A JParameter object holding the parameters for the plugin * * @var A JParameter object * @access public * @since 1.5 */ public function onCheck() { //Check System requirements for the editor define('JCK_BASE', JPATH_CONFIGURATION . DS . 'plugins' . DS . 'editors' . DS . 'jckeditor'); if (!JFolder::exists(JCK_BASE)) { return; } $perms = fileperms(JPATH_CONFIGURATION . DS . 'index.php'); $perms = decoct($perms & 0777); $default_fperms = '0644'; $default_dperms = '0755'; if ($perms == 777 || $perms == 666) { $default_fperms = '0666'; $default_dperms = '0777'; } $fperms = JCK_BASE . DS . 'config.js'; if (!stristr(PHP_OS, 'WIN') && JPath::canChmod(JCK_BASE) && $perms != decoct(fileperms($fperms) & 0777)) { $path = JCK_BASE . DS . 'plugins'; if (!JPath::setPermissions($path, $default_fperms, $default_dperms)) { $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_AUTO_CORRECTION_FAILED_INCORRECT_FILE_PERMISSION'), 'error'); } } $this->app->enqueueMessage(JText::_('COM_JCKMAN_CPANEL_SYSTEM_CHECKED_AND_UPDATED')); }
/** * Method to store the source file contents. * * @param array $data The source data to save. * * @return boolean True on success, false otherwise and internal error set. * * @since 1.6 */ public function save($data) { jimport('joomla.filesystem.file'); // Get the template. $template = $this->getTemplate(); if (empty($template)) { return false; } $app = JFactory::getApplication(); $fileName = base64_decode($app->input->get('file')); $client = JApplicationHelper::getClientInfo($template->client_id); $filePath = JPath::clean($client->path . '/templates/' . $template->element . '/' . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); $user = get_current_user(); chown($filePath, $user); JPath::setPermissions($filePath, '0644'); // Try to make the template file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } // Make sure EOL is Unix $data['source'] = str_replace(array("\r\n", "\r"), "\n", $data['source']); $return = JFile::write($filePath, $data['source']); if (!$return) { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } $explodeArray = explode('.', $fileName); $ext = end($explodeArray); if ($ext == 'less') { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_COMPILE_LESS', $fileName)); } return true; }
/** * Method to write the configuration to a file. * * @param Registry $config A Registry object containing all global config data. * * @return boolean True on success, false on failure. * * @since 2.5.4 * @throws RuntimeException */ private function writeConfigFile(Registry $config) { jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); // Set the configuration file path. $file = JPATH_CONFIGURATION . '/configuration.php'; // Get the new FTP credentials. $ftp = JClientHelper::getCredentials('ftp', true); $app = JFactory::getApplication(); // Attempt to make the file writeable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice'); } // Attempt to write the configuration file as a PHP class named JConfig. $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)); if (!JFile::write($file, $configuration)) { throw new RuntimeException(JText::_('COM_CONFIG_ERROR_WRITE_FAILED')); } // Attempt to make the file unwriteable if using FTP. if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) { $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice'); } return true; }
function addonInstall() { jimport('joomla.installer.helper'); jimport('joomla.filesystem.path'); $filename = $_FILES['addon_installer']['name']; $baseDir = JPATH_ROOT . "/tmp/"; if (file_exists($baseDir)) { if (is_writable($baseDir)) { if (move_uploaded_file($_FILES['addon_installer']['tmp_name'], $baseDir . $filename)) { if (JPath::setPermissions($baseDir . $filename)) { $msg = ''; } else { $msg = JText::_("BLBE_UPL_PERM"); } } else { $msg = JText::_("BLBE_UPL_MOVE"); } } else { $msg = JText::_("BLBE_UPL_TMP"); } } else { $msg = JText::_("BLBE_UPL_TMPEX"); } if ($msg != '') { JError::raiseError(500, $msg); } $retval = JInstallerHelper::unpack($baseDir . $filename); if (count($retval)) { if (is_dir($retval['dir'] . "/BE/models/")) { $this->_copy_directory($retval['dir'] . "/BE/models/", JPATH_ROOT . "/administrator/components/com_joomsport/models"); } if (is_dir($retval['dir'] . "/BE/views/")) { $this->_copy_directory($retval['dir'] . "/BE/views/", JPATH_ROOT . "/administrator/components/com_joomsport/views"); } if (is_dir($retval['dir'] . "/BE/tables/")) { $this->_copy_directory($retval['dir'] . "/BE/tables/", JPATH_ROOT . "/administrator/components/com_joomsport/tables"); } if (is_dir($retval['dir'] . "/FE/models/")) { $this->_copy_directory($retval['dir'] . "/FE/models/", JPATH_ROOT . "/components/com_joomsport/models"); } if (is_dir($retval['dir'] . "/FE/views/")) { $this->_copy_directory($retval['dir'] . "/FE/views/", JPATH_ROOT . "/components/com_joomsport/views"); } $xml = JFactory::getXML($retval['dir'] . "/addon.xml"); if (file_exists($retval['dir'] . "/addon.sql.xml")) { $sql = JFactory::getXML($retval['dir'] . "/addon.sql.xml"); $queries = $sql->query; if ($queries) { foreach ($queries as $q) { $this->db->setQuery($q); $this->db->query(); } } } if ($xml) { $query = "INSERT INTO #__bl_addons(name,title,description,version,published) VALUES('{$xml->name}','{$xml->title}','{$xml->description}','{$xml->version}','0')"; $this->db->setQuery($query); $this->db->query(); } } }
/** * Method to store the source file contents. * * @param array The souce data to save. * * @return boolean True on success, false otherwise and internal error set. * @since 1.6 */ public function save($data) { jimport('joomla.filesystem.file'); jimport('joomla.client.helper'); // Get the template. $template = $this->getTemplate(); if (empty($template)) { return false; } $dispatcher = JDispatcher::getInstance(); $fileName = $this->getState('filename'); $client = JApplicationHelper::getClientInfo($template->client_id); $filePath = JPath::clean($client->path . '/templates/' . $template->element . '/' . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the template file writeable. if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) { $this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE')); return false; } // Trigger the onExtensionBeforeSave event. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_templates.source', &$data, false)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } $return = JFile::write($filePath, $data['source']); // Try to make the template file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) { $this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE')); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName)); return false; } } // Trigger the onExtensionAfterSave event. $dispatcher->trigger('onExtensionAfterSave', array('com_templates.source', &$table, false)); return true; }
/** * @param string $lessfile * @param bool $cssfile * @param int $priority * * @param array $options * * @throws RuntimeException */ public function addLess($lessfile, $cssfile = null, $priority = self::DEFAULT_STYLE_PRIORITY, array $options = array()) { $less_search_paths = array(); // setup the less filename if (dirname($lessfile) == '.') { //set up the check for template with plartform based dirs $less_search_paths = $this->platform->getAvailablePlatformVersions($this->templatePath . '/less'); foreach ($less_search_paths as $less_path) { if (is_dir($less_path)) { $search_file = preg_replace('#[/\\\\]+#', '/', $less_path . '/' . $lessfile); if (is_file($search_file)) { $lessfile = $search_file; break; } } } } $less_file_md5 = md5($lessfile); $less_file_path = $this->convertToPath($lessfile); $less_file_url = $this->convertToUrl($less_file_path); // abort if the less file isnt there if (!is_file($less_file_path)) { return; } // get an md5 sum of any passed in options $tmp_options = $options; array_walk($tmp_options, create_function('&$v,$k', '$v = " * @".$k." = " .$v;')); $options_string = implode($tmp_options, "\n"); $options_md5 = md5($options_string . (string) $this->get('less-compression', true)); $css_append = ''; if (!empty($options)) { $css_append = '-' . $options_md5; } $default_compiled_css_dir = $this->templatePath . '/css-compiled'; if (!file_exists($default_compiled_css_dir)) { @JFolder::create($default_compiled_css_dir); if (!file_exists($default_compiled_css_dir)) { throw new Exception(sprintf('Unable to create default directory (%s) for compiled less files. Please check your filesystem permissions.', $default_compiled_css_dir)); } } // setup the output css file name if (is_null($cssfile)) { $css_file_path = $default_compiled_css_dir . '/' . pathinfo($lessfile, PATHINFO_FILENAME) . $css_append . '.css'; $css_passed_path = pathinfo($css_file_path, PATHINFO_BASENAME); } else { if (dirname($cssfile) == '.') { $css_file_path = $default_compiled_css_dir . '/' . pathinfo($cssfile, PATHINFO_FILENAME) . $css_append . '.css'; $css_passed_path = pathinfo($css_file_path, PATHINFO_BASENAME); } else { $css_file_path = dirname($this->convertToPath($cssfile)) . '/' . pathinfo($cssfile, PATHINFO_FILENAME) . $css_append . '.css'; $css_passed_path = $css_file_path; } } $cssfile_md5 = md5($css_file_path); // set base compile modes $force_compile = false; $single_compile = false; $app = JFactory::getApplication(); if (!$app->isAdmin()) { $cachegroup = self::LESS_SITE_CACHE_GROUP; } else { $cachegroup = self::LESS_ADMIN_CACHE_GROUP; } $runcompile = false; $cache_handler = GantryCache::getCache($cachegroup, null, true); $cached_less_compile = $cache_handler->get($cssfile_md5, false); if ($cached_less_compile === false || !file_exists($css_file_path)) { $cached_less_compile = $less_file_path; $runcompile = true; } elseif (is_array($cached_less_compile) && isset($cached_less_compile['root'])) { if (isset($cached_less_compile['files']) and is_array($cached_less_compile['files'])) { foreach ($cached_less_compile['files'] as $fname => $ftime) { if (!file_exists($fname) or filemtime($fname) > $ftime) { // One of the files we knew about previously has changed // so we should look at our incoming root again. $runcompile = true; break; } } } } if ($runcompile) { gantry_import('core.utilities.gantrylesscompiler'); $quick_expire_cache = GantryCache::getCache($cachegroup, $this->get('less-compilewait', self::LESS_MAX_COMPILE_WAIT_TIME)); $timewaiting = 0; while ($quick_expire_cache->get($cssfile_md5 . '-compiling') !== false) { $wait = 100000; // 1/10 of a second; usleep($wait); $timewaiting += $wait; if ($timewaiting >= $this->get('less-compilewait', self::LESS_MAX_COMPILE_WAIT_TIME) * 1000000) { break; } } $less = new GantryLessCompiler(); $less->setImportDir($less_search_paths); $less->addImportDir($this->gantryPath . '/assets'); if (!empty($options)) { $less->setVariables($options); } if ($this->get('less-compression', true)) { $less->setFormatter("compressed"); } $quick_expire_cache->set($cssfile_md5 . '-compiling', true); try { $new_cache = $less->cachedCompile($cached_less_compile, $force_compile); } catch (Exception $ex) { $quick_expire_cache->clear($cssfile_md5 . '-compiling'); throw new RuntimeException('Less Parse Error: ' . $ex->getMessage()); } if (!is_array($cached_less_compile) || $new_cache['updated'] > $cached_less_compile['updated']) { $cache_handler->set($cssfile_md5, $new_cache); $tmp_ouput_file = tempnam(dirname($css_file_path), 'gantry_less'); $header = ''; if ($this->get('less-debugheader', false)) { $header .= sprintf("/*\n * Main File : %s", str_replace(JURI::root(true), '', $less_file_url)); if (!empty($options)) { $header .= sprintf("\n * Variables :\n %s", $options_string); } if (count($new_cache['files']) > 1) { $included_files = array_keys($new_cache['files']); unset($included_files[0]); array_walk($included_files, create_function('&$v,$k', 'global $gantry;$v=" * ".$gantry->convertToUrl($v);')); $header .= sprintf("\n * Included Files : \n%s", implode("\n", str_replace(JURI::root(true), '', $included_files))); } $header .= "\n */\n"; } file_put_contents($tmp_ouput_file, $header . $new_cache['compiled']); // Do the messed up file renaming for windows if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $move_old_file_name = tempnam(dirname($css_file_path), 'gantry_less'); if (is_file($css_file_path)) { @rename($css_file_path, $move_old_file_name); } @rename($tmp_ouput_file, $css_file_path); @unlink($move_old_file_name); } else { @rename($tmp_ouput_file, $css_file_path); } JPath::setPermissions($css_file_path); } $quick_expire_cache->clear($cssfile_md5 . '-compiling'); } $this->addStyle($css_passed_path, $priority); if (!empty($css_append) && !is_null($cssfile) && dirname($cssfile) == '.') { $this->addStyle($cssfile, $priority); } }
function install($parent) { $version = $parent->get("manifest")->version; $mainframe = JFactory::getApplication(); $db = JFactory::getDBO(); $query = "SELECT count(1) FROM #__modules" . " WHERE position IN ( '" . implode("', '", $this->positions) . "' )"; $db->setQuery($query); $count = $db->loadResult(); if ($count) { $this->uninstall($parent); } jimport('joomla.filesystem.folder'); $src = 'components' . DS . 'com_arkeditor' . DS . 'modules' . DS; $dest = 'modules' . DS; foreach ($this->modules as $module) { if (!JFolder::copy($src . $module, $dest . $module, JPATH_ADMINISTRATOR, true)) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', $module . ' module!')); } } /*===========================================================> */ /*==============================================> LEFT MODULES */ /*===========================================================> */ $row = JTable::getInstance('module'); $row->module = ''; $row->position = 'ark_icon'; $row->published = 1; $row->showtitle = 1; $row->access = 1; $row->client_id = 1; $row->params = '{}'; /*$row->id = 0; $row->title = 'Dashboard'; $row->module = 'mod_arkquickicon'; $row->ordering = $row->getNextOrder( "position='ark_icon'" ); if (!$row->store()) { $mainframe->enqueueMessage( JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL','Control Panel icon Module data!') ); }*/ $row->id = 0; $row->title = 'Statistics'; $row->module = 'mod_arkstats'; $row->params = '{"moduleclass_sfx":"box-arkstats","icon":"bars"}'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Statistical Module data!')); } $row->id = 0; $row->title = 'Spread The Love'; $row->module = 'mod_arkvote'; $row->params = '{"moduleclass_sfx":"box-arkvote","icon":"heart-2"}'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Vote Module data!')); } $row->id = 0; $row->title = 'Update Available'; $row->module = 'mod_arkupdate'; $row->params = '{"moduleclass_sfx":"box-arkupdate","icon":"loop"}'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Update Module data!')); } /*===========================================================> */ /*=============================================> RIGHT MODULES */ /*===========================================================> */ $row = JTable::getInstance('module'); $row->module = ''; $row->position = 'ark_cpanel'; $row->published = 1; $row->showtitle = 1; $row->access = 1; $row->client_id = 1; $row->params = '{}'; $row->id = 0; $row->title = 'Ark Editor v' . $version; $row->module = 'mod_custom'; $row->params = '{"moduleclass_sfx":"box-arkinfo","icon":"info-circle"}'; $row->content = '<table class="table table-striped"> <tr> <td rowspan="6"><img src="components/com_arkeditor/icons/ark-editor-logo-lg.png" alt="Logo"></td> </tr> <tr> <td>Version:</td> <td>' . $version . '</td> </tr> <tr> <td>Author:</td> <td><a href="http://www.arkextensions.com" target="_blank">www.arkextensions.com</a></td> </tr> <tr> <td>Copyright:</td> <td>© WebxSolution Ltd, All rights reserved.</td> </tr> <tr> <td>License:</td> <td>GPLv2.0</td> </tr> <tr> <td>More info:</td> <td><a href="http://arkextensions.com/terms-of-use" target="_blank">http://arkextensions.com/terms-of-use</a></td> </tr> </table>'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Ark Editor custom Module data!')); } $row->id = 0; $row->title = 'Tip of the Day'; $row->module = 'mod_arktip'; $row->params = '{"moduleclass_sfx":"box-arktip","icon":"info-circle"}'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Tip of the day data!')); } $row->id = 0; $row->title = 'GO PRO!'; $row->module = 'mod_arkpro'; $row->params = '{"moduleclass_sfx":"box-arkpro","icon":"lightning"}'; $row->ordering = $row->getNextOrder("position='ark_cpanel'"); if (!$row->store()) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL', 'Pro Module data!')); } /*===========================================================> */ /*============================================> FOOTER MODULES */ /*===========================================================> */ $row = JTable::getInstance('module'); $row->module = ''; $row->position = 'ark_footer'; $row->published = 1; $row->showtitle = 1; $row->access = 1; $row->client_id = 1; $row->params = '{}'; /*$row->id = 0; $row->title = 'Dashboard'; $row->module = 'mod_arkquickicon'; $row->ordering = $row->getNextOrder( "position='ark_footer'" ); if (!$row->store()) { $mainframe->enqueueMessage( JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL','Control Panel icon Module data!') ); }*/ jimport('joomla.filesystem.file'); //Check System requirements for the editor define('ARKEDITOR_BASE', JPATH_CONFIGURATION . DS . 'plugins' . DS . 'editors' . DS . 'arkeditor/ckeditor'); if (!JFolder::exists(ARKEDITOR_BASE)) { $mainframe->enqueueMessage(JText::_('COM_ARKEDITOR_CUSTOM_INSTALL_SYSTEM_DETECTED_EDITOR_NOT_INSTALLED')); return; } $perms = fileperms(JPATH_CONFIGURATION . DS . 'index.php'); $perms = decoct($perms & 0777); $default_fperms = '0644'; $default_dperms = '0755'; if ($perms == 777 || $perms == 666) { $default_fperms = '0666'; $default_dperms = '0777'; } $fperms = ARKEDITOR_BASE . DS . 'config.js'; if (!stristr(PHP_OS, 'WIN') && JPath::canChmod(ARKEDITOR_BASE) && $perms != decoct(fileperms($fperms) & 0777)) { $path = ARKEDITOR_BASE . DS . 'plugins'; if (!JPath::setPermissions($path, $default_fperms, $default_dperms)) { $mainframe->enqueueMessage(JText::_('COM_ARKEDITOR_CUSTOM_INSTALL_SYSTEM_DETECTED_INCORRECT_FILE_PERMISSONS_FOR_EDITOR')); } } //for upgrade $query = 'SELECT p.name FROM `#__ark_editor_plugins` p WHERE p.iscore = 0'; $db->setQuery($query); $results = $db->loadObjectList(); if (!empty($results)) { for ($i = 0; $i < count($results); $i++) { if (JFolder::exists(JPATH_PLUGINS . DS . 'editors' . DS . 'arkeditor' . DS . 'plugins' . DS . $results[$i]->name) && !JFolder::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_arkeditor' . DS . 'editor' . DS . 'plugins' . DS . $results[$i]->name)) { $src = JPATH_PLUGINS . DS . 'editors' . DS . 'arkeditor' . DS . 'plugins' . DS . $results[$i]->name; $dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_arkeditor' . DS . 'editor' . DS . 'plugins' . DS . $results[$i]->name; if (!JFolder::copy($src, $dest)) { $mainframe->enqueueMessage(JText::sprintf('COM_ARKEDITOR_CUSTOM_INSTALL_UNABLE_TO_MOVE_SPRINTF', 'base plugin .' . $results[$i]->name . ' to ARK backup folder!')); } } } //end for loop } //fix remove component install file from the editor's folder $file = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_arkeditor' . DS . 'editor' . DS . 'com_arkeditor.xml'; if (JFile::exists($file)) { JFile::delete($file); } }
function upgrade() { $extDir = JPATH_ROOT . DS . 'components' . DS . 'com_sef' . DS . 'sef_ext'; $fromServer = JRequest::getVar('fromserver'); $extension = JRequest::getVar('ext'); if (!empty($extension) && !JFile::exists($extDir . DS . $extension . '.php')) { $this->setState('message', JText::_('You are not allowed to upgrade this extension.')); return false; } if (is_null($fromServer)) { $this->setState('message', JText::_('Upgrade source not given.')); return false; } if ($fromServer == 1) { $package = $this->_getPackageFromServer($extension); } else { $package = $this->_getPackageFromUpload(); } // was the package unpacked? if (!$package) { $this->setState('message', 'Unable to find install package.'); return false; } // create an array of upgrade files $upgradeDir = $package['dir'] . DS . 'upgrade'; $upgradeFiles = JFolder::files($upgradeDir, '.php$'); if (empty($upgradeFiles)) { $this->setState('message', JText::_('This package does not contain any upgrade informations.')); JFolder::delete($package['dir']); return false; } // Find the XML file in the package $xmlFile = $package['dir'] . DS . 'sef.xml'; if (!JFile::exists($xmlFile)) { // Try to find the extension XML file $xmlFiles = JFolder::files($package['dir'], '^com_[^.]+\\.xml$'); if (empty($xmlFiles)) { $this->setState('message', 'Could not find the installation XML file.'); return false; } // Set the file and the extension $xmlFile = $xmlFiles[0]; $extension = substr($xmlFile, 0, -4); } // get current version if (empty($extension)) { $curVersion = SEFTools::getSEFVersion(); } else { $curVersion = SEFTools::getExtVersion($extension); } if (empty($curVersion)) { $this->setState('message', JText::_('Could not find current version.')); JFolder::delete($package['dir']); return false; } // check if current version is upgradeable with downloaded package $reinstall = false; if (!in_array($curVersion . '.php', $upgradeFiles)) { if (empty($extension)) { // check if current version is being manually reinstalled with the same version package $xmlFile = $package['dir'] . DS . 'sef.xml'; $packVersion = $this->_getXmlText($xmlFile, 'version'); if ($packVersion == $curVersion && JFile::exists($upgradeDir . DS . 'reinstall.php')) { // initiate the reinstall $reinstall = true; $mainframe =& JFactory::getApplication(); $mainframe->enqueueMessage(JText::_('INFO_SEF_REINSTALL')); } } if (!$reinstall) { $this->setState('message', JText::_('ERROR_CANT_UPGRADE')); JFolder::delete($package['dir']); return false; } } natcasesort($upgradeFiles); // prepare arrays of upgrade operations and functions to manipulate them $this->_fileError = false; $this->_fileList = array(); $this->_sqlList = array(); $this->_scriptList = array(); if (!$reinstall) { // load each upgrade file starting with current version in ascending order foreach ($upgradeFiles as $uFile) { //if (!eregi("^[0-9]+\.[0-9]+\.[0-9]+\.php$", $uFile)) { if (!preg_match("/^[0-9]+\\.[0-9]+\\.[0-9]+\\.php\$/i", $uFile)) { continue; } if (strnatcasecmp($uFile, $curVersion . ".php") >= 0) { require_once $upgradeDir . DS . $uFile; } } } else { // create list of all files to upgrade require_once $upgradeDir . DS . 'reinstall.php'; } // Check if the free/paid version of JoomSEF is being changed if (empty($extension) && !$reinstall) { $xmlFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sef' . DS . 'sef.xml'; $license = $this->_getXmlText($xmlFile, 'license'); $packXmlFile = $package['dir'] . DS . 'sef.xml'; $packLicense = $this->_getXmlText($packXmlFile, 'license'); $curFree = stripos($license, 'gpl') !== false; $packFree = stripos($packLicense, 'gpl') !== false; if ($curFree != $packFree) { // Add all the files like during reinstall require_once $upgradeDir . DS . 'reinstall.php'; } } if ($this->_fileError == false) { // set errors variable $errors = false; // first of all check if all the files are writeable // ONLY IF FTP IS DISABLED jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); if ($ftpOptions['enabled'] != 1) { foreach ($this->_fileList as $dest => $op) { $file = JPath::clean(JPATH_ROOT . DS . $dest); // check if source file is present in upgrade package if ($op->operation == 'upgrade') { $from = JPath::clean($package['dir'] . DS . $op->packagePath); if (!JFile::exists($from)) { JError::raiseWarning(100, JText::_('File does not exist in upgrade package') . ': ' . $op->packagePath); $errors = true; } } if ($op->operation == 'delete' && JFile::exists($file) || $op->operation == 'upgrade' && !JFile::exists($file)) { // if the file is to be deleted or created, the file's directory must be writable $dir = dirname($file); if (!JFolder::exists($dir)) { // we need to create the directory where the file is to be created if (!JFolder::create($dir)) { JError::raiseWarning(100, JText::_('Directory could not be created') . ': ' . $dir); $errors = true; } } if (!is_writable($dir)) { if (!JPath::setPermissions($dir, '0755', '0777')) { JError::raiseWarning(100, JText::_('Directory not writeable') . ': ' . $dir); $errors = true; } } } elseif ($op->operation == 'upgrade') { // the file itself must be writeable if (!is_writable($file)) { if (!JPath::setPermissions($file, '0755', '0777')) { JError::raiseWarning(100, JText::_('File not writeable') . ': ' . $file); $errors = true; } } } } } // If there are no errors, let's upgrade if (!$errors) { $db =& JFactory::getDBO(); // execute SQL queries foreach ($this->_sqlList as $sql) { $db->setQuery($sql); if (!$db->query()) { JError::raiseWarning(100, JText::_('Unable to execute SQL query') . ': ' . $sql); $errors = true; } } // perform file operations foreach ($this->_fileList as $dest => $op) { if ($op->operation == 'delete') { $file = JPath::clean(JPATH_ROOT . DS . $dest); if (JFile::exists($file)) { $success = JFile::delete($file); if (!$success) { JError::raiseWarning(100, JText::_('Could not delete file. Please, check the write permissions on') . ' ' . $dest); $errors = true; } } } elseif ($op->operation == 'upgrade') { $from = JPath::clean($package['dir'] . DS . $op->packagePath); $to = JPath::clean(JPATH_ROOT . DS . $dest); $destDir = dirname($to); // create the destination directory if needed if (!JFolder::exists($destDir)) { JFolder::create($destDir); } $success = JFile::copy($from, $to); if (!$success) { JError::raiseWarning(100, JText::_('Could not rewrite file. Please, check the write permissions on') . ' ' . $dest); $errors = true; } } } // run scripts foreach ($this->_scriptList as $script) { $file = JPath::clean($package['dir'] . DS . $script); if (!JFile::exists($file)) { JError::raiseWarning(100, JText::_('Could not find script file') . ': ' . $script); $errors = true; } else { include $file; } } } if (!$errors) { $what = empty($extension) ? JText::_('JoomSEF') : JText::_('SEF Extension') . ' ' . $extension; $this->setState('message', $what . ' ' . JText::_('successfully upgraded.')); } else { $this->setState('message', JText::_('ERROR_UPGRADE_PROBLEM')); } } JFolder::delete($package['dir']); return true; }
/** * * save Profile */ function saveProfile() { $mainframe =& JFactory::getApplication(); // Initialize some variables $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); $post = $_POST; $profile = JRequest::getCmd('profile'); $result = array(); if (!$profile) { $result['error'] = JText::_('INVALID_DATA_TO_SAVE_PROFILE'); echo json_encode($result); exit; } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $errors = array(); $file = dirname(dirname(__FILE__)) . DS . 'profiles' . DS . $profile . '.ini'; $params = new JRegistry(); if (isset($post)) { foreach ($post as $k => $v) { $params->set($k, $v); } } $data = (string) $params; if (JFile::exists($file)) { @chmod($file, 0777); } $return = @JFile::write($file, $data); // Try to make the params file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { $errors[] = sprintf(JText::_('JA file unwritable'), $file); } if (!$return) { $errors[] = JText::_('OPERATION_FAILED'); } if ($errors) { $result['error'] = implode('<br/>', $errors); } else { $result['successful'] = sprintf(JText::_('SAVE_PROFILE_SUCCESSFULLY'), $profile); $result['profile'] = $profile; $result['type'] = 'new'; } echo json_encode($result); exit; }
public function save($data) { jimport('joomla.filesystem.file'); // New if ($data['id'] < 1) { $data['type'] = 2; // Custom in every case if ($data['title'] != '') { $filename = JApplication::stringURLSafe($data['title']); if (trim(str_replace('-', '', $filename)) == '') { $filename = JFactory::getDate()->format("Y-m-d-H-i-s"); } } else { $filename = JFactory::getDate()->format("Y-m-d-H-i-s"); } $filename = $filename . '.css'; $data['filename'] = $filename; $filePath = PhocaGalleryFile::existsCSS($filename, $data['type']); if ($filePath) { $this->setError(JText::sprintf('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS', $fileName)); return false; } else { $filePath = PhocaGalleryFile::getCSSPath($data['type']) . $filename; } } else { $filename = PhocaGalleryFile::getCSSFile($data['id']); $filePath = PhocaGalleryFile::existsCSS($filename, $data['type']); } //$dispatcher = JEventDispatcher::getInstance(); $fileName = $filename; // Include the extension plugins for the save events. //JPluginHelper::importPlugin('extension'); // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the template file writeable. if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) { $this->setError(JText::_('COM_PHOCAGALLERY_ERROR_SOURCE_FILE_NOT_WRITABLE')); return false; } // Trigger the onExtensionBeforeSave event. /*$result = $dispatcher->trigger('onExtensionBeforeSave', array('com_phocagallery.source', &$data, false)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; }*/ $return = JFile::write($filePath, $data['source']); // Try to make the template file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) { $this->setError(JText::_('COM_PHOCAGALLERY_ERROR_SOURCE_FILE_NOT_UNWRITABLE')); return false; } elseif (!$return) { $this->setError(JText::sprintf('COM_PHOCAGALLERY_ERROR_FAILED_TO_SAVE_FILENAME', $fileName)); return false; } // Trigger the onExtensionAfterSave event. //$dispatcher->trigger('onExtensionAfterSave', array('com_templates.source', &$table, false)); //return true; return parent::save($data); }
/** * Moves an uploaded file to a destination folder * * @param string $src The name of the php (temporary) uploaded file * @param string $dest The path (including filename) to move the uploaded file to * * @return boolean True on success * @since 1.5 */ public static function upload($src, $dest, $use_streams = false) { // Ensure that the path is valid and clean $dest = JPath::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { jimport('joomla.filesystem.folder'); JFolder::create($baseDir); } if ($use_streams) { $stream = JFactory::getStream(); if (!$stream->upload($src, $dest)) { JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError())); return false; } return true; } else { // Initialise variables. jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ret = false; if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path for the FTP account $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Copy the file to the destination directory if (is_uploaded_file($src) && $ftp->store($src, $dest)) { unlink($src); $ret = true; } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (JPath::setPermissions($dest)) { $ret = true; } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR01')); } } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } return $ret; } }
/** * Save the configuration */ function save() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); //Save user and media manager settings $table =& JTable::getInstance('component'); $userpost['params'] = JRequest::getVar('userparams', array(), 'post', 'array'); $userpost['option'] = 'com_users'; $table->loadByOption('com_users'); $table->bind($userpost); // pre-save checks if (!$table->check()) { JError::raiseWarning(500, $table->getError()); return false; } // save the changes if (!$table->store()) { JError::raiseWarning(500, $table->getError()); return false; } $mediapost['params'] = JRequest::getVar('mediaparams', array(), 'post', 'array'); $mediapost['option'] = 'com_media'; //Sanitize $file_path and $image_path $file_path = $mediapost['params']['file_path']; $image_path = $mediapost['params']['image_path']; if (strpos($file_path, '/') === 0 || strpos($file_path, '\\') === 0) { //Leading slash. Kill it and default to /media $file_path = 'images'; } if (strpos($image_path, '/') === 0 || strpos($image_path, '\\') === 0) { //Leading slash. Kill it and default to /media $image_path = 'images/stories'; } if (strpos($file_path, '..') !== false) { //downward directories. Kill it and default to images/ $file_path = 'images'; } if (strpos($image_path, '..') !== false) { //downward directories Kill it and default to images/stories $image_path = 'images/stories'; } $mediapost['params']['file_path'] = $file_path; $mediapost['params']['image_path'] = $image_path; $table->loadByOption('com_media'); $table->bind($mediapost); // pre-save checks if (!$table->check()) { JError::raiseWarning(500, $table->getError()); return false; } // save the changes if (!$table->store()) { JError::raiseWarning(500, $table->getError()); return false; } $config = new JRegistry('config'); $config_array = array(); // SITE SETTINGS $config_array['offline'] = JRequest::getVar('offline', 0, 'post', 'int'); $config_array['editor'] = JRequest::getVar('editor', 'tinymce', 'post', 'cmd'); $config_array['list_limit'] = JRequest::getVar('list_limit', 20, 'post', 'int'); $config_array['helpurl'] = JRequest::getVar('helpurl', 'http://help.joomla.org', 'post', 'string'); // DEBUG $config_array['debug'] = JRequest::getVar('debug', 0, 'post', 'int'); $config_array['debug_lang'] = JRequest::getVar('debug_lang', 0, 'post', 'int'); // SEO SETTINGS $config_array['sef'] = JRequest::getVar('sef', 0, 'post', 'int'); $config_array['sef_rewrite'] = JRequest::getVar('sef_rewrite', 0, 'post', 'int'); $config_array['sef_suffix'] = JRequest::getVar('sef_suffix', 0, 'post', 'int'); // FEED SETTINGS $config_array['feed_limit'] = JRequest::getVar('feed_limit', 10, 'post', 'int'); $config_array['feed_email'] = JRequest::getVar('feed_email', 'author', 'post', 'word'); // SERVER SETTINGS $config_array['secret'] = JRequest::getVar('secret', 0, 'post', 'string'); $config_array['gzip'] = JRequest::getVar('gzip', 0, 'post', 'int'); $config_array['error_reporting'] = JRequest::getVar('error_reporting', -1, 'post', 'int'); $config_array['xmlrpc_server'] = JRequest::getVar('xmlrpc_server', 0, 'post', 'int'); $config_array['log_path'] = JRequest::getVar('log_path', JPATH_ROOT . DS . 'logs', 'post', 'string'); $config_array['tmp_path'] = JRequest::getVar('tmp_path', JPATH_ROOT . DS . 'tmp', 'post', 'string'); $config_array['live_site'] = rtrim(JRequest::getVar('live_site', '', 'post', 'string'), '/\\'); $config_array['force_ssl'] = JRequest::getVar('force_ssl', 0, 'post', 'int'); // LOCALE SETTINGS $config_array['offset'] = JRequest::getVar('offset', 0, 'post', 'float'); // CACHE SETTINGS $config_array['caching'] = JRequest::getVar('caching', 0, 'post', 'int'); $config_array['cachetime'] = JRequest::getVar('cachetime', 900, 'post', 'int'); $config_array['cache_handler'] = JRequest::getVar('cache_handler', 'file', 'post', 'word'); $config_array['memcache_settings'] = JRequest::getVar('memcache_settings', array(), 'post'); // FTP SETTINGS $config_array['ftp_enable'] = JRequest::getVar('ftp_enable', 0, 'post', 'int'); $config_array['ftp_host'] = JRequest::getVar('ftp_host', '', 'post', 'string'); $config_array['ftp_port'] = JRequest::getVar('ftp_port', '', 'post', 'int'); $config_array['ftp_user'] = JRequest::getVar('ftp_user', '', 'post', 'string'); $config_array['ftp_pass'] = JRequest::getVar('ftp_pass', '', 'post', 'string', JREQUEST_ALLOWRAW); $config_array['ftp_root'] = JRequest::getVar('ftp_root', '', 'post', 'string'); // DATABASE SETTINGS $config_array['dbtype'] = JRequest::getVar('dbtype', 'mysql', 'post', 'word'); $config_array['host'] = JRequest::getVar('host', 'localhost', 'post', 'string'); $config_array['user'] = JRequest::getVar('user', '', 'post', 'string'); $config_array['db'] = JRequest::getVar('db', '', 'post', 'string'); $config_array['dbprefix'] = JRequest::getVar('dbprefix', 'jos_', 'post', 'string'); // MAIL SETTINGS $config_array['mailer'] = JRequest::getVar('mailer', 'mail', 'post', 'word'); $config_array['mailfrom'] = JRequest::getVar('mailfrom', '', 'post', 'string'); $config_array['fromname'] = JRequest::getVar('fromname', 'Joomla 1.5', 'post', 'string'); $config_array['sendmail'] = JRequest::getVar('sendmail', '/usr/sbin/sendmail', 'post', 'string'); $config_array['smtpauth'] = JRequest::getVar('smtpauth', 0, 'post', 'int'); $config_array['smtpsecure'] = JRequest::getVar('smtpsecure', 'none', 'post', 'word'); $smtpport = JRequest::getVar('smtpport', '', 'post', 'int'); $config_array['smtpport'] = $smtpport ? $smtpport : '25'; $config_array['smtpuser'] = JRequest::getVar('smtpuser', '', 'post', 'string'); $config_array['smtppass'] = JRequest::getVar('smtppass', '', 'post', 'string', JREQUEST_ALLOWRAW); $config_array['smtphost'] = JRequest::getVar('smtphost', '', 'post', 'string'); // META SETTINGS $config_array['MetaAuthor'] = JRequest::getVar('MetaAuthor', 1, 'post', 'int'); $config_array['MetaTitle'] = JRequest::getVar('MetaTitle', 1, 'post', 'int'); // SESSION SETTINGS $config_array['lifetime'] = JRequest::getVar('lifetime', 0, 'post', 'int'); $config_array['session_handler'] = JRequest::getVar('session_handler', 'none', 'post', 'word'); //LANGUAGE SETTINGS //$config_array['lang'] = JRequest::getVar('lang', 'none', 'english', 'cmd'); //$config_array['language'] = JRequest::getVar('language', 'en-GB', 'post', 'cmd'); $config->loadArray($config_array); //override any possible database password change $config->setValue('config.password', $mainframe->getCfg('password')); // handling of special characters $sitename = htmlspecialchars(JRequest::getVar('sitename', '', 'post', 'string'), ENT_COMPAT, 'UTF-8'); $config->setValue('config.sitename', $sitename); $MetaDesc = htmlspecialchars(JRequest::getVar('MetaDesc', '', 'post', 'string'), ENT_COMPAT, 'UTF-8'); $config->setValue('config.MetaDesc', $MetaDesc); $MetaKeys = htmlspecialchars(JRequest::getVar('MetaKeys', '', 'post', 'string'), ENT_COMPAT, 'UTF-8'); $config->setValue('config.MetaKeys', $MetaKeys); // handling of quotes (double and single) and amp characters // htmlspecialchars not used to preserve ability to insert other html characters $offline_message = JRequest::getVar('offline_message', '', 'post', 'string'); $offline_message = JFilterOutput::ampReplace($offline_message); $offline_message = str_replace('"', '"', $offline_message); $offline_message = str_replace("'", ''', $offline_message); $config->setValue('config.offline_message', $offline_message); //purge the database session table (only if we are changing to a db session store) if ($mainframe->getCfg('session_handler') != 'database' && $config->getValue('session_handler') == 'database') { $table =& JTable::getInstance('session'); $table->purge(-1); } // Get the path of the configuration file $fname = JPATH_CONFIGURATION . DS . 'configuration.php'; // Update the credentials with the new settings $oldconfig =& JFactory::getConfig(); $oldconfig->setValue('config.ftp_enable', $config_array['ftp_enable']); $oldconfig->setValue('config.ftp_host', $config_array['ftp_host']); $oldconfig->setValue('config.ftp_port', $config_array['ftp_port']); $oldconfig->setValue('config.ftp_user', $config_array['ftp_user']); $oldconfig->setValue('config.ftp_pass', $config_array['ftp_pass']); $oldconfig->setValue('config.ftp_root', $config_array['ftp_root']); JClientHelper::getCredentials('ftp', true); if (!$config->get('caching') && $oldconfig->get('caching')) { $cache = JFactory::getCache(); $cache->clean(); } // Try to make configuration.php writeable jimport('joomla.filesystem.path'); if (!$ftp['enabled'] && JPath::isOwner($fname) && !JPath::setPermissions($fname, '0644')) { JError::raiseNotice('SOME_ERROR_CODE', 'Could not make configuration.php writable'); } // Get the config registry in PHP class format and write it to configuation.php jimport('joomla.filesystem.file'); if (JFile::write($fname, $config->toString('PHP', 'config', array('class' => 'JConfig')))) { $msg = JText::_('The Configuration Details have been updated'); } else { $msg = JText::_('ERRORCONFIGFILE'); } // Redirect appropriately $task = $this->getTask(); switch ($task) { case 'apply': $this->setRedirect('index.php?option=com_config', $msg); break; case 'save': default: $this->setRedirect('index.php', $msg); break; } // Try to make configuration.php unwriteable //if (!$ftp['enabled'] && JPath::isOwner($fname) && !JPath::setPermissions($fname, '0444')) { if ($config_array['ftp_enable'] == 0 && !$ftp['enabled'] && JPath::isOwner($fname) && !JPath::setPermissions($fname, '0444')) { JError::raiseNotice('SOME_ERROR_CODE', 'Could not make configuration.php unwritable'); } }