| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 5 * @license GNU General Public License version 2 or later; see LICENSE.txt 6 */ 7 8 // no direct access 9 defined('_JEXEC') or die; 10 11 jimport('joomla.application.component.helper'); 12 13 /** 14 * Joomla! Application class 15 * 16 * Provide many supporting API functions 17 * 18 * @package Joomla.Administrator 19 * @final 20 * @since 1.5 21 */ 22 class JAdministrator extends JApplication 23 { 24 /** 25 * Class constructor 26 * 27 * @param array An optional associative array of configuration settings. 28 * Recognized key values include 'clientId' (this list is not meant to be comprehensive). 29 * 30 * @since 1.5 31 */ 32 public function __construct($config = array()) 33 { 34 $config['clientId'] = 1; 35 parent::__construct($config); 36 37 //Set the root in the URI based on the application name 38 JURI::root(null, str_ireplace('/'.$this->getName(), '', JURI::base(true))); 39 } 40 41 /** 42 * Initialise the application. 43 * 44 * @param array $options An optional associative array of configuration settings. 45 * 46 * @return void 47 * @since 1.5 48 */ 49 public function initialise($options = array()) 50 { 51 $config = JFactory::getConfig(); 52 53 // if a language was specified it has priority 54 // otherwise use user or default language settings 55 if (empty($options['language'])) 56 { 57 $user = JFactory::getUser(); 58 $lang = $user->getParam('admin_language'); 59 60 // Make sure that the user's language exists 61 if ($lang && JLanguage::exists($lang)) { 62 $options['language'] = $lang; 63 } else { 64 $params = JComponentHelper::getParams('com_languages'); 65 $client = JApplicationHelper::getClientInfo($this->getClientId()); 66 $options['language'] = $params->get($client->name, $config->get('language', 'en-GB')); 67 } 68 } 69 70 // One last check to make sure we have something 71 if (!JLanguage::exists($options['language'])) { 72 $lang = $config->get('language', 'en-GB'); 73 if (JLanguage::exists($lang)) { 74 $options['language'] = $lang; 75 } else { 76 $options['language'] = 'en-GB'; // as a last ditch fail to english 77 } 78 } 79 80 // Execute the parent initialise method. 81 parent::initialise($options); 82 83 // Load Library language 84 $lang = JFactory::getLanguage(); 85 $lang->load('lib_joomla', JPATH_ADMINISTRATOR); 86 } 87 88 /** 89 * Route the application 90 * 91 * @return void 92 * @since 1.5 93 */ 94 public function route() 95 { 96 $uri = JURI::getInstance(); 97 98 if ($this->getCfg('force_ssl') >= 1 && strtolower($uri->getScheme()) != 'https') { 99 //forward to https 100 $uri->setScheme('https'); 101 $this->redirect((string)$uri); 102 } 103 104 // Trigger the onAfterRoute event. 105 JPluginHelper::importPlugin('system'); 106 $this->triggerEvent('onAfterRoute'); 107 } 108 109 /** 110 * Return a reference to the JRouter object. 111 * 112 * @return JRouter 113 * @since 1.5 114 */ 115 static public function getRouter($name = null, array $options = array()) 116 { 117 $router = parent::getRouter('administrator'); 118 return $router; 119 } 120 121 /** 122 * Dispatch the application 123 * 124 * @param string $component The component to dispatch. 125 * 126 * @return void 127 * @since 1.5 128 */ 129 public function dispatch($component = null) 130 { 131 try 132 { 133 if ($component === null) { 134 $component = JAdministratorHelper::findOption(); 135 } 136 137 $document = JFactory::getDocument(); 138 $user = JFactory::getUser(); 139 140 switch ($document->getType()) { 141 case 'html': 142 $document->setMetaData('keywords', $this->getCfg('MetaKeys')); 143 break; 144 145 default: 146 break; 147 } 148 149 $document->setTitle($this->getCfg('sitename'). ' - ' .JText::_('JADMINISTRATION')); 150 $document->setDescription($this->getCfg('MetaDesc')); 151 $document->setGenerator('Joomla! - Open Source Content Management'); 152 153 $contents = JComponentHelper::renderComponent($component); 154 $document->setBuffer($contents, 'component'); 155 156 // Trigger the onAfterDispatch event. 157 JPluginHelper::importPlugin('system'); 158 $this->triggerEvent('onAfterDispatch'); 159 } 160 // Mop up any uncaught exceptions. 161 catch (Exception $e) 162 { 163 $code = $e->getCode(); 164 JError::raiseError($code ? $code : 500, $e->getMessage()); 165 } 166 } 167 168 /** 169 * Display the application. 170 * 171 * @return void 172 * @since 1.5 173 */ 174 public function render() 175 { 176 $component = JRequest::getCmd('option', 'com_login'); 177 $template = $this->getTemplate(true); 178 $file = JRequest::getCmd('tmpl', 'index'); 179 180 if ($component == 'com_login') { 181 $file = 'login'; 182 } 183 184 // Safety check for when configuration.php root_user is in use. 185 $config = JFactory::getConfig(); 186 $rootUser = $config->get('root_user'); 187 if (property_exists('JConfig', 'root_user') && 188 (JFactory::getUser()->get('username') == $rootUser || JFactory::getUser()->id === (string) $rootUser)) { 189 JError::raiseNotice(200, JText::sprintf('JWARNING_REMOVE_ROOT_USER', 'index.php?option=com_config&task=application.removeroot&'. JSession::getFormToken() .'=1')); 190 } 191 192 $params = array( 193 'template' => $template->template, 194 'file' => $file.'.php', 195 'directory' => JPATH_THEMES, 196 'params' => $template->params 197 ); 198 199 $document = JFactory::getDocument(); 200 $document->parse($params); 201 $this->triggerEvent('onBeforeRender'); 202 $data = $document->render(false, $params); 203 JResponse::setBody($data); 204 $this->triggerEvent('onAfterRender'); 205 206 } 207 208 /** 209 * Login authentication function 210 * 211 * @param array Array('username' => string, 'password' => string) 212 * @param array Array('remember' => boolean) 213 * 214 * @return boolean True on success. 215 * @see JApplication::login 216 * @since 1.5 217 */ 218 public function login($credentials, $options = array()) 219 { 220 //The minimum group 221 $options['group'] = 'Public Backend'; 222 223 //Make sure users are not autoregistered 224 $options['autoregister'] = false; 225 226 //Set the application login entry point 227 if (!array_key_exists('entry_url', $options)) { 228 $options['entry_url'] = JURI::base().'index.php?option=com_users&task=login'; 229 } 230 231 // Set the access control action to check. 232 $options['action'] = 'core.login.admin'; 233 234 $result = parent::login($credentials, $options); 235 236 if (!($result instanceof Exception)) 237 { 238 $lang = JRequest::getCmd('lang'); 239 $lang = preg_replace('/[^A-Z-]/i', '', $lang); 240 $this->setUserState('application.lang', $lang ); 241 242 JAdministrator::purgeMessages(); 243 } 244 245 return $result; 246 } 247 248 /** 249 * Get the template 250 * 251 * @return string The template name 252 * @since 1.0 253 */ 254 public function getTemplate($params = false) 255 { 256 static $template; 257 258 if (!isset($template)) 259 { 260 $admin_style = JFactory::getUser()->getParam('admin_style'); 261 // Load the template name from the database 262 $db = JFactory::getDbo(); 263 $query = $db->getQuery(true); 264 $query->select('template, s.params'); 265 $query->from('#__template_styles as s'); 266 $query->leftJoin('#__extensions as e ON e.type='.$db->quote('template').' AND e.element=s.template AND e.client_id=s.client_id'); 267 if ($admin_style) 268 { 269 $query->where('s.client_id = 1 AND id = '.(int)$admin_style. ' AND e.enabled = 1', 'OR'); 270 } 271 $query->where('s.client_id = 1 AND home = 1', 'OR'); 272 $query->order('home'); 273 $db->setQuery($query); 274 $template = $db->loadObject(); 275 276 $template->template = JFilterInput::getInstance()->clean($template->template, 'cmd'); 277 $template->params = new JRegistry($template->params); 278 279 if (!file_exists(JPATH_THEMES . '/' . $template->template . '/index.php')) 280 { 281 $template->params = new JRegistry(); 282 $template->template = 'bluestork'; 283 } 284 } 285 if ($params) { 286 return $template; 287 } 288 289 return $template->template; 290 } 291 292 /** 293 * Purge the jos_messages table of old messages 294 * 295 * @return void 296 * @since 1.5 297 */ 298 public static function purgeMessages() 299 { 300 $db = JFactory::getDbo(); 301 $user = JFactory::getUser(); 302 303 $userid = $user->get('id'); 304 305 $query = 'SELECT *' 306 . ' FROM #__messages_cfg' 307 . ' WHERE user_id = ' . (int) $userid 308 . ' AND cfg_name = ' . $db->quote('auto_purge') 309 ; 310 $db->setQuery($query); 311 $config = $db->loadObject(); 312 313 // check if auto_purge value set 314 if (is_object($config) and $config->cfg_name == 'auto_purge') { 315 $purge = $config->cfg_value; 316 } else { 317 // if no value set, default is 7 days 318 $purge = 7; 319 } 320 // calculation of past date 321 322 // if purge value is not 0, then allow purging of old messages 323 if ($purge > 0) { 324 // purge old messages at day set in message configuration 325 $past = JFactory::getDate(time() - $purge * 86400); 326 $pastStamp = $past->toSql(); 327 328 $query = 'DELETE FROM #__messages' 329 . ' WHERE date_time < ' . $db->Quote($pastStamp) 330 . ' AND user_id_to = ' . (int) $userid 331 ; 332 $db->setQuery($query); 333 $db->query(); 334 } 335 } 336 }
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 |