| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_config 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // No direct access 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modelform'); 13 14 /** 15 * @package Joomla.Administrator 16 * @subpackage com_config 17 */ 18 class ConfigModelApplication extends JModelForm 19 { 20 /** 21 * Method to get a form object. 22 * 23 * @param array $data Data for the form. 24 * @param boolean $loadData True if the form is to load its own data (default case), false if not. 25 * 26 * @return mixed A JForm object on success, false on failure 27 * 28 * @since 1.6 29 */ 30 public function getForm($data = array(), $loadData = true) 31 { 32 // Get the form. 33 $form = $this->loadForm('com_config.application', 'application', array('control' => 'jform', 'load_data' => $loadData)); 34 if (empty($form)) 35 { 36 return false; 37 } 38 39 return $form; 40 } 41 42 /** 43 * Method to get the configuration data. 44 * 45 * This method will load the global configuration data straight from 46 * JConfig. If configuration data has been saved in the session, that 47 * data will be merged into the original data, overwriting it. 48 * 49 * @return array An array containg all global config data. 50 * 51 * @since 1.6 52 */ 53 public function getData() 54 { 55 // Get the config data. 56 $config = new JConfig(); 57 $data = JArrayHelper::fromObject($config); 58 59 // Prime the asset_id for the rules. 60 $data['asset_id'] = 1; 61 62 // Get the text filter data 63 $params = JComponentHelper::getParams('com_config'); 64 $data['filters'] = JArrayHelper::fromObject($params->get('filters')); 65 66 // If no filter data found, get from com_content (update of 1.6/1.7 site) 67 if (empty($data['filters'])) 68 { 69 $contentParams = JComponentHelper::getParams('com_content'); 70 $data['filters'] = JArrayHelper::fromObject($contentParams->get('filters')); 71 } 72 73 // Check for data in the session. 74 $temp = JFactory::getApplication()->getUserState('com_config.config.global.data'); 75 76 // Merge in the session data. 77 if (!empty($temp)) 78 { 79 $data = array_merge($data, $temp); 80 } 81 82 return $data; 83 } 84 85 /** 86 * Method to save the configuration data. 87 * 88 * @param array An array containing all global config data. 89 * 90 * @return bool True on success, false on failure. 91 * 92 * @since 1.6 93 */ 94 public function save($data) 95 { 96 // Save the rules 97 if (isset($data['rules'])) 98 { 99 $rules = new JAccessRules($data['rules']); 100 101 // Check that we aren't removing our Super User permission 102 // Need to get groups from database, since they might have changed 103 $myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id')); 104 $myRules = $rules->getData(); 105 $hasSuperAdmin = $myRules['core.admin']->allow($myGroups); 106 if (!$hasSuperAdmin) { 107 $this->setError(JText::_('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN')); 108 return false; 109 } 110 111 $asset = JTable::getInstance('asset'); 112 if ($asset->loadByName('root.1')) 113 { 114 $asset->rules = (string) $rules; 115 116 if (!$asset->check() || !$asset->store()) 117 { 118 JError::raiseNotice('SOME_ERROR_CODE', $asset->getError()); 119 } 120 } 121 else 122 { 123 $this->setError(JText::_('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND')); 124 return false; 125 } 126 unset($data['rules']); 127 } 128 129 // Save the text filters 130 if (isset($data['filters'])) 131 { 132 $registry = new JRegistry(); 133 $registry->loadArray(array('filters' => $data['filters'])); 134 135 $extension = JTable::getInstance('extension'); 136 137 // Get extension_id 138 $extension_id = $extension->find(array('name' => 'com_config')); 139 140 if ($extension->load((int) $extension_id)) 141 { 142 $extension->params = (string) $registry; 143 if (!$extension->check() || !$extension->store()) 144 { 145 JError::raiseNotice('SOME_ERROR_CODE', $extension->getError()); 146 } 147 } 148 else 149 { 150 $this->setError(JText::_('COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND')); 151 return false; 152 } 153 unset($data['filters']); 154 } 155 156 // Get the previous configuration. 157 $prev = new JConfig(); 158 $prev = JArrayHelper::fromObject($prev); 159 160 // Merge the new data in. We do this to preserve values that were not in the form. 161 $data = array_merge($prev, $data); 162 163 /* 164 * Perform miscellaneous options based on configuration settings/changes. 165 */ 166 // Escape the offline message if present. 167 if (isset($data['offline_message'])) 168 { 169 $data['offline_message'] = JFilterOutput::ampReplace($data['offline_message']); 170 } 171 172 // Purge the database session table if we are changing to the database handler. 173 if ($prev['session_handler'] != 'database' && $data['session_handler'] == 'database') 174 { 175 $table = JTable::getInstance('session'); 176 $table->purge(-1); 177 } 178 179 if (empty($data['cache_handler'])) 180 { 181 $data['caching'] = 0; 182 } 183 184 // Clean the cache if disabled but previously enabled. 185 if (!$data['caching'] && $prev['caching']) 186 { 187 $cache = JFactory::getCache(); 188 $cache->clean(); 189 } 190 191 // Create the new configuration object. 192 $config = new JRegistry('config'); 193 $config->loadArray($data); 194 195 // Overwrite the old FTP credentials with the new ones. 196 $temp = JFactory::getConfig(); 197 $temp->set('ftp_enable', $data['ftp_enable']); 198 $temp->set('ftp_host', $data['ftp_host']); 199 $temp->set('ftp_port', $data['ftp_port']); 200 $temp->set('ftp_user', $data['ftp_user']); 201 $temp->set('ftp_pass', $data['ftp_pass']); 202 $temp->set('ftp_root', $data['ftp_root']); 203 204 // Write the configuration file. 205 return $this->writeConfigFile($config); 206 } 207 208 /** 209 * Method to unset the root_user value from configuration data. 210 * 211 * This method will load the global configuration data straight from 212 * JConfig and remove the root_user value for security, then save the configuration. 213 * 214 * @since 1.6 215 */ 216 function removeroot() 217 { 218 // Get the previous configuration. 219 $prev = new JConfig(); 220 $prev = JArrayHelper::fromObject($prev); 221 222 // Create the new configuration object, and unset the root_user property 223 $config = new JRegistry('config'); 224 unset($prev['root_user']); 225 $config->loadArray($prev); 226 227 // Write the configuration file. 228 return $this->writeConfigFile($config); 229 230 return true; 231 } 232 233 /** 234 * Method to write the configuration to a file. 235 * 236 * @param JRegistry $config A JRegistry object containing all global config data. 237 * 238 * @return bool True on success, false on failure. 239 * 240 * @since 2.5.4 241 */ 242 private function writeConfigFile(JRegistry $config) 243 { 244 jimport('joomla.filesystem.path'); 245 jimport('joomla.filesystem.file'); 246 247 // Set the configuration file path. 248 $file = JPATH_CONFIGURATION . '/configuration.php'; 249 250 // Get the new FTP credentials. 251 $ftp = JClientHelper::getCredentials('ftp', true); 252 253 // Attempt to make the file writeable if using FTP. 254 if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) 255 { 256 JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE')); 257 } 258 259 // Attempt to write the configuration file as a PHP class named JConfig. 260 if (!JFile::write($file, $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)))) 261 { 262 $this->setError(JText::_('COM_CONFIG_ERROR_WRITE_FAILED')); 263 return false; 264 } 265 266 // Attempt to make the file unwriteable if using FTP. 267 if ($prev['ftp_enable'] == 0 && !$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) 268 { 269 JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE')); 270 } 271 272 return true; 273 } 274 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |