english/administrator/components/com_config/models/application.php
/**
	 * Method to save the configuration data.
	 *
	 * @param	array	An array containing all global config data.
	 * @return	bool	True on success, false on failure.
	 * @since	1.6
	 */
Method to save the configuration data.
@param       array   An array containing all global config data.
@return      bool    True on success, false on failure.
Method to save the configuration data . @param array An array containing all global config data . @return bool True on success false on failure .
public function save($data)
	{
		if (isset($data['rules']))
		{
			jimport('joomla.access.rules');
			$rules	= new JRules($data['rules']);
			$myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'));
			$myRules = $rules->getData();
			$hasSuperAdmin = $myRules['core.admin']->allow($myGroups);
			if (!$hasSuperAdmin) {
				$this->setError(JText::_('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN'));
				return false;
			}
			$asset	= JTable::getInstance('asset');
			if ($asset->loadByName('root.1'))
			{
				$asset->rules = (string) $rules;
				if (!$asset->check() || !$asset->store()) {
					JError::raiseNotice('SOME_ERROR_CODE', $asset->getError());
				}
			}
			else
			{
				$this->setError(JText::_('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND'));
				return false;
			}
			unset($data['rules']);
		}
		$prev = new JConfig();
		$prev = JArrayHelper::fromObject($prev);
		$data = array_merge($prev, $data);
		if (isset($data['sitename'])) {
			$data['sitename'] = $data['sitename'];
		}
		if (isset($data['MetaDesc'])) {
			$data['MetaDesc'] = $data['MetaDesc'];
		}
		if (isset($data['MetaKeys'])) {
			$data['MetaKeys'] = $data['MetaKeys'];
		}
		if (isset($data['offline_message'])) {
			$data['offline_message']	= JFilterOutput::ampReplace($data['offline_message']);
		}
		if ($prev['session_handler'] != 'database' && $data['session_handler'] == 'database')
		{
			$table = JTable::getInstance('session');
			$table->purge(-1);
		}
		if (empty($data['cache_handler'])) {
			$data['caching'] = 0;
		}
		if (!$data['caching'] && $prev['caching']) {
			$cache = JFactory::getCache();
			$cache->clean();
		}
		$config = new JRegistry('config');
		$config->loadArray($data);
		jimport('joomla.filesystem.path');
		jimport('joomla.filesystem.file');
		$file = JPATH_CONFIGURATION . '/configuration.php';
		$temp = JFactory::getConfig();
		$temp->set('ftp_enable', $data['ftp_enable']);
		$temp->set('ftp_host', $data['ftp_host']);
		$temp->set('ftp_port', $data['ftp_port']);
		$temp->set('ftp_user', $data['ftp_user']);
		$temp->set('ftp_pass', $data['ftp_pass']);
		$temp->set('ftp_root', $data['ftp_root']);
		$ftp = JClientHelper::getCredentials('ftp', true);
		if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
			JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'));
		}
		$configString = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
		if (!JFile::write($file, $configString)) {
			$this->setError(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'));
			return false;
		}
		if ($data['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;
	}
public function save ( $ data ) { if ( isset ( $ data [ 'rules' ] ) ) { jimport ( 'joomla.access.rules' ) ; $ rules = new JRules ( $ data [ 'rules' ] ) ; $ myGroups = JAccess :: getGroupsByUser ( JFactory :: getUser ( ) -> get ( 'id' ) ) ; $ myRules = $ rules -> getData ( ) ; $ hasSuperAdmin = $ myRules [ 'core.admin' ] -> allow ( $ myGroups ) ; if ( ! $ hasSuperAdmin ) { $ this -> setError ( JText :: _ ( 'COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN' ) ) ; return false ; } $ asset = JTable :: getInstance ( 'asset' ) ; if ( $ asset -> loadByName ( 'root.1' ) ) { $ asset -> rules = ( string ) $ rules ; if ( ! $ asset -> check ( ) || ! $ asset -> store ( ) ) { JError :: raiseNotice ( 'SOME_ERROR_CODE' , $ asset -> getError ( ) ) ; } } else { $ this -> setError ( JText :: _ ( 'COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND' ) ) ; return false ; } unset ( $ data [ 'rules' ] ) ; } $ prev = new JConfig ( ) ; $ prev = JArrayHelper :: fromObject ( $ prev ) ; $ data = array_merge ( $ prev , $ data ) ; if ( isset ( $ data [ 'sitename' ] ) ) { $ data [ 'sitename' ] = $ data [ 'sitename' ] ; } if ( isset ( $ data [ 'MetaDesc' ] ) ) { $ data [ 'MetaDesc' ] = $ data [ 'MetaDesc' ] ; } if ( isset ( $ data [ 'MetaKeys' ] ) ) { $ data [ 'MetaKeys' ] = $ data [ 'MetaKeys' ] ; } if ( isset ( $ data [ 'offline_message' ] ) ) { $ data [ 'offline_message' ] = JFilterOutput :: ampReplace ( $ data [ 'offline_message' ] ) ; } if ( $ prev [ 'session_handler' ] != 'database' && $ data [ 'session_handler' ] == 'database' ) { $ table = JTable :: getInstance ( 'session' ) ; $ table -> purge ( - 1 ) ; } if ( empty ( $ data [ 'cache_handler' ] ) ) { $ data [ 'caching' ] = 0 ; } if ( ! $ data [ 'caching' ] && $ prev [ 'caching' ] ) { $ cache = JFactory :: getCache ( ) ; $ cache -> clean ( ) ; } $ config = new JRegistry ( 'config' ) ; $ config -> loadArray ( $ data ) ; jimport ( 'joomla.filesystem.path' ) ; jimport ( 'joomla.filesystem.file' ) ; $ file = JPATH_CONFIGURATION . '/configuration.php' ; $ temp = JFactory :: getConfig ( ) ; $ temp -> set ( 'ftp_enable' , $ data [ 'ftp_enable' ] ) ; $ temp -> set ( 'ftp_host' , $ data [ 'ftp_host' ] ) ; $ temp -> set ( 'ftp_port' , $ data [ 'ftp_port' ] ) ; $ temp -> set ( 'ftp_user' , $ data [ 'ftp_user' ] ) ; $ temp -> set ( 'ftp_pass' , $ data [ 'ftp_pass' ] ) ; $ temp -> set ( 'ftp_root' , $ data [ 'ftp_root' ] ) ; $ ftp = JClientHelper :: getCredentials ( 'ftp' , true ) ; if ( ! $ ftp [ 'enabled' ] && JPath :: isOwner ( $ file ) && ! JPath :: setPermissions ( $ file , '0644' ) ) { JError :: raiseNotice ( 'SOME_ERROR_CODE' , JText :: _ ( 'COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE' ) ) ; } $ configString = $ config -> toString ( 'PHP' , array ( 'class' => 'JConfig' , 'closingtag' => false ) ) ; if ( ! JFile :: write ( $ file , $ configString ) ) { $ this -> setError ( JText :: _ ( 'COM_CONFIG_ERROR_WRITE_FAILED' ) ) ; return false ; } if ( $ data [ '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 ; }
Method to save the configuration data.
Method to save the configuration data .
// Save the rules // Check that we aren't removing our Super User permission // Need to get groups from database, since they might have changed // Get the previous configuration. // Merge the new data in. We do this to preserve values that were not in the form. /*
		 * Perform miscellaneous options based on configuration settings/changes.
		 */ // Escape the sitename if present. // Escape the MetaDesc if present. // Escape the MetaKeys if present. // Escape the offline message if present. // Purge the database session table if we are changing to the database handler. // Clean the cache if disabled but previously enabled. // Create the new configuration object. /*
		 * Write the configuration file.
		 */ // Set the configuration file path. // Overwrite the old FTP credentials with the new ones. // Get the new FTP credentials. // Attempt to make the file writeable if using FTP. // Attempt to write the configuration file as a PHP class named JConfig. // Attempt to make the file unwriteable if using FTP.