/** * 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')); } }
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; }
/** * Determines if a given path is writable in the current environment * * @param string $path Path to check * * @return boolean True if writable * * @since 4.0 */ public static function isWritable($path) { if (JFactory::getConfig()->get('config.ftp_enable')) { return true; } else { while (!file_exists($path)) { $path = dirname($path); } return is_writable($path) || JPath::isOwner($path) || JPath::canChmod($path); } }
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; }
/** * 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; }
/** * 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'); } }
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); }
/** * Method to unset the root_user value from configuration data. * * This method will load the global configuration data straight from * JConfig and remove the root_user value for security, then save the configuration. * * @since 1.6 */ function removeroot() { // Include client helper jimport('joomla.client.helper'); // Get the previous configuration. $prev = new JConfig(); $prev = JArrayHelper::fromObject($prev); // Clean the cache if disabled but previously enabled. if ($prev['caching']) { $cache = JFactory::getCache(); $cache->clean(); } // Create the new configuration object, and unset the root_user property $config = new JRegistry('config'); unset($prev['root_user']); $config->loadArray($prev); /* * Write the configuration file. */ jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); // Set the configuration file path. $file = JPATH_CONFIGURATION . DS . 'configuration.php'; // Overwrite the old FTP credentials with the new ones. $temp = JFactory::getConfig(); $temp->set('ftp_enable', $prev['ftp_enable']); $temp->set('ftp_host', $prev['ftp_host']); $temp->set('ftp_port', $prev['ftp_port']); $temp->set('ftp_user', $prev['ftp_user']); $temp->set('ftp_pass', $prev['ftp_pass']); $temp->set('ftp_root', $prev['ftp_root']); // 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. if (!JFile::write($file, $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)))) { $this->setError(JText::_('COM_CONFIG_ERROR_WRITE_FAILED')); return false; } // Attempt to make the file unwriteable if using FTP. if ($prev['ftp_enable'] == 0 && !$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE')); } return true; }
function saveTemplateCSS() { $kunena_app =& JFactory::getApplication(); $option = JRequest::getCmd('option'); $template = JRequest::getVar('id', '', 'post', 'cmd'); $filename = JRequest::getVar('filename', '', 'post', 'cmd'); $filecontent = JRequest::getVar('filecontent', '', 'post', 'string', JREQUEST_ALLOWRAW); if (!$template) { while (@ob_end_clean()) { } $kunena_app->redirect(JURI::base() . 'index.php?option=' . $option . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_NOT_SPECIFIED.')); } if (!$filecontent) { while (@ob_end_clean()) { } $kunena_app->redirect(JURI::base() . 'index.php?option=' . $option . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_CONTENT_EMPTY')); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = KUNENA_PATH_TEMPLATE . '/' . $template . '/css/' . $filename; if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_COULD_NOT_CSS_WRITABLE')); } jimport('joomla.filesystem.file'); $return = JFile::write($file, $filecontent); if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_COULD_NOT_CSS_UNWRITABLE')); } if ($return) { while (@ob_end_clean()) { } $kunena_app->redirect(JURI::base() . 'index.php?option=' . $option . '&task=editKTemplate&cid[]=' . $template, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_FILE_SAVED')); } else { while (@ob_end_clean()) { } $kunena_app->redirect(JURI::base() . 'index.php?option=' . $option . '&id=' . $template . '&task=chooseCSSTemplate', JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED') . ': ' . JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_FAILED_OPEN_FILE.', $file)); } }
function setStatus($state) { $ajax = intval(JRequest::getVar('ajax')) == 1; if (!$ajax) { JRequest::checkToken() or jexit('Invalid Token'); } $type = JRequest::getVar('cid', array(''), 'post', 'array'); $type = JRequest::getVar('statusType', $type[0], 'post', 'string'); $types = array('sef', 'mod_rewrite', 'sef_suffix', 'joomsef', 'plugin', 'newurls', 'versioncheck', 'jfrouter'); $msg = ''; if (in_array($type, $types)) { // SEF and mod_rewrite settings if ($type == 'sef' || $type == 'mod_rewrite' || $type == 'sef_suffix') { jimport('joomla.client.helper'); jimport('joomla.filesystem.path'); jimport('joomla.filesystem.file'); // We need to load the config file manually, // because on Joomla 3 the global JFactory::getConfig() // already contains some changed themeParams data, // which causes fatal error after saving $file = JPATH_CONFIGURATION . '/configuration.php'; if (!is_file($file)) { $msg = JText::_('COM_SEF_ERROR_LOADING_CONFIG'); } else { include_once $file; if (!class_exists('JConfig')) { $msg = JText::_('COM_SEF_ERROR_LOADING_CONFIG'); } else { $config = new JRegistry(); $data = new JConfig(); $config->loadObject($data); if ($type == 'sef') { $config->set('sef', $state); } else { if ($type == 'mod_rewrite') { $config->set('sef_rewrite', $state); } else { $config->set('sef_suffix', $state); } } // Store the configuration // 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')) { $msg = JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'); } if (!JFile::write($file, $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)))) { $msg = JText::_('COM_SEF_ERROR_WRITING_CONFIG'); } } } } else { if ($type == 'joomsef' || $type == 'newurls' || $type == 'versioncheck') { // JoomSEF and new URLs settings $sefConfig = SEFConfig::getConfig(); if ($type == 'joomsef') { $sefConfig->enabled = $state; } else { if ($type == 'newurls') { $sefConfig->disableNewSEF = 1 - $state; } else { $sefConfig->versionChecker = $state; } } // Store the configuration if (!$sefConfig->saveConfig()) { $msg = JText::_('COM_SEF_ERROR_WRITING_CONFIG'); } } else { if ($type == 'plugin' || $type == 'jfrouter') { // Plugins settings $db = JFactory::getDBO(); if ($type == 'plugin') { $plg = 'joomsef'; } else { if ($type == 'jfrouter') { $plg = 'jfrouter'; } } $query = "UPDATE `#__extensions` SET `enabled` = '{$state}' WHERE (`type` = 'plugin') AND (`element` = '{$plg}') AND (`folder` = 'system') LIMIT 1"; $db->setQuery($query); if (!$db->query()) { $msg = JText::_('COM_SEF_ERROR_WRITING_CONFIG'); } // Clear cache for com_plugins! $model = $this->getModel(); $model->clearCache('com_plugins'); } } } } if ($ajax) { $obj = new stdClass(); $obj->id = $type; $obj->newValue = $state; $ret = array($obj); echo json_encode($ret); $app = JFactory::getApplication(); $app->close(); } else { $return = JRequest::getVar('return', 'index.php?option=com_sef'); $this->setRedirect($return, $msg); } }
function saveTemplateCSS() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // Initialize some variables $option = JRequest::getCmd('option'); $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); $template = JRequest::getVar('id', '', 'post', 'cmd'); $filename = JRequest::getVar('filename', '', 'post', 'cmd'); $filecontent = JRequest::getVar('filecontent', '', 'post', 'string', JREQUEST_ALLOWRAW); if (!$template) { $mainframe->redirect('index.php?option=' . $option . '&client=' . $client->id, JText::_('Operation Failed') . ': ' . JText::_('No template specified.')); } if (!$filecontent) { $mainframe->redirect('index.php?option=' . $option . '&client=' . $client->id, JText::_('Operation Failed') . ': ' . JText::_('Content empty.')); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = $client->path . DS . 'templates' . DS . $template . 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', JText::_('Could not make the 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', JText::_('Could not make the css file unwritable')); } if ($return) { $task = JRequest::getCmd('task'); switch ($task) { case 'apply_css': $mainframe->redirect('index.php?option=' . $option . '&client=' . $client->id . '&task=edit_css&id=' . $template . '&filename=' . $filename, JText::_('File Saved')); break; case 'save_css': default: $mainframe->redirect('index.php?option=' . $option . '&client=' . $client->id . '&task=edit&cid[]=' . $template, JText::_('File Saved')); break; } } else { $mainframe->redirect('index.php?option=' . $option . '&client=' . $client->id . '&id=' . $template . '&task=choose_css', JText::_('Operation Failed') . ': ' . JText::sprintf('Failed to open file for writing.', $file)); } }
/** * 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; }
/** * 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; }
/** * Updates the template parameter file * @access protected */ function update() { global $rsgConfig; $app =& JFactory::getApplication(); if (!$this->template) { JError::raiseError(500, "No template specified"); return; } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = JPATH_RSGALLERY2_SITE . '/templates/' . $this->template . '/params.ini'; jimport('joomla.filesystem.file'); if (JFile::exists($file) && count($this->params)) { $txt = null; foreach ($this->params as $k => $v) { $txt .= "{$k}={$v}\n"; } // Try to make the params file writeable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file writable')); return; } $return = JFile::write($file, $txt); // Try to make the params file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file unwritable')); return; } } $app->enqueueMessage('Template saved'); }
/** * Saves the acl file * */ function saveacl() { JRequest::checkToken() or jexit('Invalid Token'); // Initialize some variables $app = JFactory::getApplication(); $option = JRequest::getVar('option'); $filename = JRequest::getVar('filename', '', 'post', 'cmd'); $filecontent = JRequest::getVar('filecontent', '', '', '', JREQUEST_ALLOWRAW); if (!$filecontent) { $app->redirect('index.php?option=' . $option, JText::_('FLEXI_OPERATION_FAILED') . ': ' . JText::_('FLEXI_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_flexicontent' . DS . 'classes' . DS . $filename; // Try to make the acl file writeable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('FLEXI_COULD_NOT_MAKE_ACL_FILE_WRITABLE')); } jimport('joomla.filesystem.file'); $return = JFile::write($file, $filecontent); // Try to make the acl file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('FLEXI_COULD_NOT_MAKE_ACL_FILE_UNWRITABLE')); } if ($return) { $task = JRequest::getVar('task'); switch ($task) { case 'applyacl': $app->redirect('index.php?option=' . $option . '&view=editacl', JText::_('FLEXI_ACL_FILE_SUCCESSFULLY_ALTERED')); break; case 'saveacl': default: $app->redirect('index.php?option=' . $option, JText::_('FLEXI_ACL_FILE_SUCCESSFULLY_ALTERED')); break; } } else { $app->redirect('index.php?option=' . $option, JText::_('FLEXI_OPERATION_FAILED') . ': ' . JText::sprintf('FLEXI_FAILED_TO_OPEN_FILE_FOR_WRITING', $file)); } }
/** * Method to write the configuration to a file. * * @param JRegistry $config A JRegistry object containing all global config data. * * @return bool True on success, false on failure. * * @since 2.5.4 */ private function writeConfigFile(JRegistry $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); // 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)) { $this->setError(JText::_('COM_CONFIG_ERROR_WRITE_FAILED')); return false; } // 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')); } return true; }
/** * Method to save data * * @param array the data to save * @return boolean success or failure */ public function save($data) { // Get the package name $name = $data['name']; // Get the package $package = $this->getItem(); $path = JPATH_COMPONENT_ADMINISTRATOR . "/packages/{$name}.xml"; $manifest = $package->manifest ? $package->manifest : 'fil_localise_package_' . $name; $client = $package->client ? $package->client : 'site'; if ($package->standalone) { $title = $package->title ? $package->title : 'fil_localise_package_' . $name; $description = $package->description ? $package->description : 'fil_localise_package_' . $name . '_desc'; // Prepare text to save for the xml package description $text = ''; $text .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $text .= '<package>' . "\n"; $text .= '<title>' . $title . '</title>' . "\n"; $text .= '<description>' . $description . '</description>' . "\n"; $text .= '<manifest client="' . $client . '">' . $manifest . '</manifest>' . "\n"; $text .= '<icon>' . $data['icon'] . '</icon>' . "\n"; $text .= '<author>' . $data['author'] . '</author>' . "\n"; $text .= '<copyright>' . $data['copyright'] . '</copyright>' . "\n"; $text .= '<license>' . $data['license'] . '</license>' . "\n"; $administrator = array(); $site = array(); $installation = array(); foreach ($data['translations'] as $translation) { if (preg_match('/^site_(.*)$/', $translation, $matches)) { $site[] = $matches[1]; } if (preg_match('/^administrator_(.*)$/', $translation, $matches)) { $administrator[] = $matches[1]; } if (preg_match('/^installation_(.*)$/', $translation, $matches)) { $installation[] = $matches[1]; } } if (count($site)) { $text .= '<site>' . "\n"; foreach ($site as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</site>' . "\n"; } if (count($administrator)) { $text .= '<administrator>' . "\n"; foreach ($administrator as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</administrator>' . "\n"; } if (count($installation)) { $text .= '<installation>' . "\n"; foreach ($installation as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</installation>' . "\n"; } $text .= '</package>' . "\n"; // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $path)); return false; } $return = JFile::write($path, $text); // Try to make the file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0444')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $path)); return false; } } } // Save the title and the description in the language file $translation_path = LocaliseHelper::findTranslationPath($client, JFactory::getLanguage()->getTag(), $manifest); $translation_id = LocaliseHelper::getFileId($translation_path); $translation_model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true)); if ($translation_model->checkout($translation_id)) { $translation_model->setState('translation.path', $translation_path); $translation_model->setState('translation.client', $client); $translation = $translation_model->getItem(); $sections = LocaliseHelper::parseSections($translation_path); } else { } $text = ''; $text .= strtoupper($title) . '="' . str_replace('"', '"_QQ_"', $data['title']) . "\"\n"; $text .= strtoupper($description) . '="' . str_replace('"', '"_QQ_"', $data['description']) . "\"\n"; $tag = JFactory::getLanguage()->getTag(); $languagePath = JPATH_SITE . "/language/{$tag}/{$tag}.{$manifest}.ini"; // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $languagePath)); return false; } $return = JFile::write($languagePath, $text); // Try to make the file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0444')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $languagePath)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $languagePath)); return false; } } $id = LocaliseHelper::getFileId($path); $this->setState('package.id', $id); // Bind the rules. $table = $this->getTable(); $table->load($id); if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } return true; }
public function saveFile($data) { $path = $this->getState('translation.path'); $refpath = $this->getState('translation.refpath'); $exists = JFile::exists($path); $refexists = JFile::exists($refpath); $client = $this->getState('translation.client'); // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_WRITABLE', $path)); return false; } if (array_key_exists('source', $data)) { $contents = $data['source']; } else { $data['description'] = str_replace(array("\r\n", "\n", "\r"), " ", $data['description']); $additionalcopyrights = trim($data['additionalcopyright']); if (empty($additionalcopyrights)) { $additionalcopyrights = array(); } else { $additionalcopyrights = explode("\n", $additionalcopyrights); } $contents2 = ''; if (!empty($data['svn'])) { $contents2 .= "; " . $data['svn'] . "\n;\n"; } if (!empty($data['package'])) { $contents2 .= "; @package " . $data['package'] . "\n"; } if (!empty($data['subpackage'])) { $contents2 .= "; @subpackage " . $data['subpackage'] . "\n"; } if (!empty($data['description'])) { $contents2 .= "; @description " . $data['description'] . "\n"; } if (!empty($data['version'])) { $contents2 .= "; @version " . $data['version'] . "\n"; } if (!empty($data['creationdate'])) { $contents2 .= "; @date " . $data['creationdate'] . "\n"; } if (!empty($data['author'])) { $contents2 .= "; @author " . $data['author'] . "\n"; } if (!empty($data['maincopyright'])) { $contents2 .= "; @copyright " . $data['maincopyright'] . "\n"; } foreach ($additionalcopyrights as $copyright) { $contents2 .= "; @copyright " . $copyright . "\n"; } if (!empty($data['license'])) { $contents2 .= "; @license " . $data['license'] . "\n"; } if (array_key_exists('complete', $data) && $data['complete'] == '1') { $contents2 .= "; @note Complete\n"; } $contents2 .= "; @note Client " . ucfirst($client) . "\n"; $contents2 .= "; @note All ini files need to be saved as UTF-8 - No BOM\n\n"; $contents = array(); $stream = new JStream(); if ($exists) { $stream->open($path); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (preg_match('/^(;.*)$/', $line, $matches)) { //$contents[] = $matches[1]."\n"; } else { break; } } if ($refexists) { $stream->close(); $stream->open($refpath); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (!preg_match('/^(;.*)$/', $line, $matches)) { break; } } } } else { $stream->open($refpath); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (preg_match('/^(;.*)$/', $line, $matches)) { $contents[] = $matches[1] . "\n"; } else { break; } } } $strings = $data['strings']; while (!$stream->eof()) { if (preg_match('/^([A-Z][A-Z0-9_\\-\\.]*)\\s*=/', $line, $matches)) { $key = $matches[1]; if (isset($strings[$key])) { $contents[] = $key . '="' . str_replace('"', '"_QQ_"', $strings[$key]) . "\"\n"; unset($strings[$key]); } } else { $contents[] = $line; } $line = $stream->gets(); } if (!empty($strings)) { $contents[] = "\n[New Strings]\n\n"; foreach ($strings as $key => $string) { $contents[] = $key . '="' . str_replace('"', '"_QQ_"', $string) . "\"\n"; } } $stream->close(); $contents = implode($contents); $contents = $contents2 . $contents; } $return = JFile::write($path, $contents); // Try to make the template file unwriteable. // Get the parameters $coparams = JComponentHelper::getParams('com_localise'); // Get the file save permission $fsper = $coparams->get('filesavepermission', '0444'); if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fsper)) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_FILESAVE', $path)); return false; } } // Remove the cache $conf = JFactory::getConfig(); $caching = $conf->get('caching') >= 1; if ($caching) { $keycache = $this->getState('translation.client') . '.' . $this->getState('translation.tag') . '.' . $this->getState('translation.filename') . '.' . 'translation'; $cache = JFactory::getCache('com_localise', ''); $cache->remove($keycache); } }
/** * * 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; }
/** * 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 extension. $extension = $this->getExtension(); if (empty($extension)) { return false; } $app = JFactory::getApplication(); $fileName = base64_decode($app->input->get('file')); $filePath = JPath::clean(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'com_visforms' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $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 css file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_VISFORMS_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_VISFORMS_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_VISFORMS_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } $return = JFile::write($filePath, $data['source']); // Try to make the css file unwritable. if (JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) { $app->enqueueMessage(JText::_('COM_VISFORMS_ERROR_SOURCE_FILE_NOT_UNWRITABLE'), 'error'); return false; } elseif (!$return) { $app->enqueueMessage(JText::sprintf('COM_VISFORMS_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } $explodeArray = explode('.', $fileName); $ext = end($explodeArray); return true; }
function _getDirInfo($folder, $relative = 1, $text = '') { jimport('joomla.filesystem.path'); $ret = ""; $writeable = 'Writable'; $unwriteable = 'Unwritable'; $ret .= $text; if ($relative) { $path = "../{$folder}"; } else { $path = $folder; } $ret .= $path; if (is_dir($path)) { $ret .= '/'; } if (file_exists($path)) { $ret .= " - "; $ret .= is_writable($path) ? $writeable : $unwriteable; $ret .= " - Owner: "; $ret .= JPath::isOwner($path) ? "Yes" : "No"; $ret .= " - Permissions: " . JPath::getPermissions($path); } else { $ret .= " - Does Not Exist"; } return $ret; }
function copyFiles($files, $overwrite = null) { $ftp = JClientHelper::getCredentials('ftp'); // try to make writeable if ($overwrite || $this->getOverwrite()) { foreach ($files as $file) { $type = array_key_exists('type', $file) ? $file['type'] : 'file'; switch ($type) { case 'file': if (!$ftp['enabled'] && JFile::exists($file['dest']) && JPath::isOwner($file['dest'])) { JPath::setPermissions($file['dest']); } break; case 'folder': if (!$ftp['enabled'] && JFolder::exists($file['dest']) && JPath::isOwner($file['dest'])) { JPath::setPermissions($file['dest']); } break; } } } return parent::copyFiles($files, $overwrite); }
/** * 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) { // Get the template. $template = $this->getTemplate(); if (empty($template)) { return false; } $fileName = $this->getState('filename'); $client = JApplicationHelper::getClientInfo($template->client_id); $filePath = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/' . $fileName); // 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) && !Filesystem::setPermissions($filePath, '0644')) { $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE')); return false; } // Trigger the onExtensionBeforeSave event. $result = Event::trigger('extension.onExtensionBeforeSave', array('com_templates.source', &$data, false)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // [!] HUBZERO - Force line endings to be consistent with the server environment $data['source'] = preg_replace('~\\R~u', PHP_EOL, $data['source']); $return = Filesystem::write($filePath, $data['source']); // Try to make the template file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0444')) { $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE')); return false; } elseif (!$return) { $this->setError(Lang::txt('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName)); return false; } // Trigger the onExtensionAfterSave event. Event::trigger('extension.onExtensionAfterSave', array('com_templates.source', &$table, false)); return true; }
/** * Save Profile to module folder */ public function saveProfile() { //This function only run in backend $app = JFactory::getApplication(); if (!$app->isAdmin()) { return false; } //Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); //Do NOT filter, HTML can be saved in profile $data_json = JRequest::getVar('data_json', '', 'post', 'string', JREQUEST_ALLOWRAW); //Create profile folder if does not exist $moduleprofilefolder = JPATH_SITE . DS . 'modules' . DS . $this->modulename . DS . 'profiles'; if (!is_dir($moduleprofilefolder)) { mkdir($moduleprofilefolder); //Create blank index.html file $fp = fopen($moduleprofilefolder . DS . 'index.html', 'w'); fwrite($fp, '<!DOCTYPE html><title></title>'); fclose($fp); } $file = self::getIniFileModule(); if (JFile::exists($file)) { chmod($file, 0777); } $data = array(); if (JFile::write($file, $data_json)) { $data['success'] = 1; $data['reports'] = JText::_('SAVE_PROFILE_SUCCESSFULLY'); } else { $data['success'] = 0; $data['reports'] = JText::_('FILE_UNWRITEABLE'); } // Try to make the params file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { $data['success'] = 0; $data['reports'] = JText::_('FILE_UNWRITEABLE'); } return $data; }
function savecss() { $app = JFactory::getApplication (); $template = JRequest::getVar('id', '', 'post', 'cmd'); $filename = JRequest::getVar('filename', '', 'post', 'cmd'); $filecontent = JRequest::getVar('filecontent', '', 'post', 'string', JREQUEST_ALLOWRAW); if (! JRequest::checkToken ()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $app->redirect ( KunenaRoute::_($this->baseurl, false) ); } if (!$template) { $app->enqueueMessage (JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED').': '.JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_NOT_SPECIFIED.')); $app->redirect ( KunenaRoute::_($this->baseurl, false) ); } if (!$filecontent) { $app->enqueueMessage (JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED').': '.JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_CONTENT_EMPTY')); $app->redirect ( KunenaRoute::_($this->baseurl, false) ); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = KPATH_SITE.'/template/'.$template.'/css/'.$filename; if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_COULD_NOT_CSS_WRITABLE')); } jimport('joomla.filesystem.file'); $return = JFile::write($file, $filecontent); if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_COULD_NOT_CSS_UNWRITABLE')); } if ($return) { $app->enqueueMessage (JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_FILE_SAVED')); $this->setRedirect(KunenaRoute::_($this->baseurl."&layout=edit&cid[]='.$template", false)); } else { $app->enqueueMessage (JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED').': '.JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_FAILED_OPEN_FILE.', $file)); $this->setRedirect(KunenaRoute::_($this->baseurl.'&layout=choosecss&id='.$template, false)); } }
public function save($data = array()) { $id = $this->getState('language.id'); $tag = $data['tag']; $client = $data['client']; $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.xml"; $exists = JFile::exists($path); if ($exists && !empty($id) || !$exists && empty($id)) { $text = ''; $text .= '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $text .= '<metafile version="3.1" client="' . htmlspecialchars($client, ENT_COMPAT, 'UTF-8') . '">' . "\n"; $text .= "\t" . '<tag>' . htmlspecialchars($tag, ENT_COMPAT, 'UTF-8') . '</tag>' . "\n"; $text .= "\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n"; $text .= "\t" . '<description>' . htmlspecialchars($data['description'], ENT_COMPAT, 'UTF-8') . '</description>' . "\n"; $text .= "\t" . '<version>' . htmlspecialchars($data['version'], ENT_COMPAT, 'UTF-8') . '</version>' . "\n"; $text .= "\t" . '<creationDate>' . htmlspecialchars($data['creationDate'], ENT_COMPAT, 'UTF-8') . '</creationDate>' . "\n"; $text .= "\t" . '<author>' . htmlspecialchars($data['author'], ENT_COMPAT, 'UTF-8') . '</author>' . "\n"; $text .= "\t" . '<authorEmail>' . htmlspecialchars($data['authorEmail'], ENT_COMPAT, 'UTF-8') . '</authorEmail>' . "\n"; $text .= "\t" . '<authorUrl>' . htmlspecialchars($data['authorUrl'], ENT_COMPAT, 'UTF-8') . '</authorUrl>' . "\n"; $text .= "\t" . '<copyright>' . htmlspecialchars($data['joomlacopyright'], ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n"; $data['copyright'] = explode("\n", $data['copyright']); foreach ($data['copyright'] as $copyright) { if ($copyright) { $text .= "\t" . '<copyright>' . htmlspecialchars($copyright, ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n"; } } $text .= "\t" . '<license>' . htmlspecialchars($data['license'], ENT_COMPAT, 'UTF-8') . '</license>' . "\n"; if ($tag == 'en-GB') { $text .= "\t" . '<files>' . "\n"; $xml = simplexml_load_file($path); foreach ($xml->files->children() as $file) { $text .= "\t\t" . '<filename>' . $file . '</filename>' . "\n"; } $text .= "\t" . '</files>' . "\n"; } else { $text .= "\t" . '<files>' . "\n"; $xml = simplexml_load_file(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/en-GB/en-GB.xml"); foreach ($xml->files->children() as $file) { $text .= "\t\t" . '<filename>' . str_replace('en-GB', $tag, $file) . '</filename>' . "\n"; } $text .= "\t" . '</files>' . "\n"; } $text .= "\t" . '<metadata>' . "\n"; $text .= "\t\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n"; $text .= "\t\t" . '<tag>' . htmlspecialchars($data['tag'], ENT_COMPAT, 'UTF-8') . '</tag>' . "\n"; $text .= "\t\t" . '<rtl>' . htmlspecialchars($data['rtl'], ENT_COMPAT, 'UTF-8') . '</rtl>' . "\n"; $text .= "\t\t" . '<locale>' . htmlspecialchars($data['locale'], ENT_COMPAT, 'UTF-8') . '</locale>' . "\n"; $text .= "\t\t" . '<firstDay>' . htmlspecialchars($data['firstDay'], ENT_COMPAT, 'UTF-8') . '</firstDay>' . "\n"; $text .= "\t" . '</metadata>' . "\n"; $text .= "\t" . '<params />' . "\n"; $text .= '</metafile>' . "\n"; // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_WRITABLE', $path)); return false; } $return = JFile::write($path, $text); // Get the Localise parameters $params = JComponentHelper::getParams('com_localise'); // Get the file save permission $fileSavePermission = $params->get('filesavepermission', '0444'); // Try to make the template file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fileSavePermission)) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILESAVE', $path)); return false; } } $id = LocaliseHelper::getFileId($path); $this->setState('language.id', $id); // Bind the rules. $table = $this->getTable(); $table->load($id); if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } return true; } else { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILERESET', $path)); return false; } }
/** * 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; }
function saveGeneral($post = null) { global $mainframe; t3_import('core/admin/util'); // Initialize some variables $db =& JFactory::getDBO(); $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); if (!$post) { $json = JRequest::getVar('json'); $json = str_replace(array("\\n", "\\t"), array("\n", "\t"), $json); $json = str_replace('\\', '', $json); $post = json_decode($json); } $template = JRequest::getCmd('template'); $result = array(); if (!$template) { $result['error'] = JText::_('Operation Failed') . ': ' . JText::_('No template specified.'); echo json_encode($result); exit; } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $errors = array(); if ($post) { if (isset($post)) { $file = $client->path . DS . 'templates' . DS . $template . DS . 'params.ini'; $params = new JParameter(''); foreach ($post as $k => $v) { $v = str_replace(array("\\n", "\\t"), array("\n", "\t"), $v); $v = str_replace('\\', '', $v); $params->set($k, $v); } $data = $params->toString(); 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::_('Could not make the %s file unwritable'), $file); } if (!$return) { $errors[] = JText::_('Operation Failed') . ': ' . JText::sprintf('Failed to open file for writing.', $file); } } } if (JRequest::getCmd('jat3action') != 'saveGeneral') { return $errors; } if ($errors) { $result['error'] = implode('<br/>', $errors); } else { $result['successful'] = JText::_('SAVE DATA SUCCESSFULLY'); } echo json_encode($result); exit; }