[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/includes/ -> application.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: application.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_JEXEC' ) or die( 'Restricted access' );
  16  
  17  jimport('joomla.application.component.helper');
  18  
  19  /**
  20  * Joomla! Application class
  21  *
  22  * Provide many supporting API functions
  23  *
  24  * @package        Joomla
  25  * @final
  26  */
  27  class JAdministrator extends JApplication
  28  {
  29      /**
  30      * Class constructor
  31      *
  32      * @access protected
  33      * @param    array An optional associative array of configuration settings.
  34      * Recognized key values include 'clientId' (this list is not meant to be comprehensive).
  35      */
  36  	function __construct($config = array())
  37      {
  38          $config['clientId'] = 1;
  39          parent::__construct($config);
  40  
  41          //Set the root in the URI based on the application name
  42          JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true)));
  43      }
  44  
  45      /**
  46      * Initialise the application.
  47      *
  48      * @access public
  49      * @param array An optional associative array of configuration settings.
  50      */
  51  	function initialise($options = array())
  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, 'en-GB');
  67              }
  68          }
  69  
  70          // One last check to make sure we have something
  71          if ( ! JLanguage::exists($options['language']) ) {
  72              $options['language'] = 'en-GB';
  73          }
  74  
  75          parent::initialise($options);
  76      }
  77  
  78      /**
  79      * Route the application
  80      *
  81      * @access public
  82      */
  83  	function route()
  84      {
  85          $uri = JURI::getInstance();
  86  
  87          if($this->getCfg('force_ssl') >= 1 && strtolower($uri->getScheme()) != 'https') {
  88              //forward to https
  89              $uri->setScheme('https');
  90              $this->redirect($uri->toString());
  91          }
  92      }
  93  
  94      /**
  95       * Return a reference to the JRouter object.
  96       *
  97       * @access    public
  98       * @return    JRouter.
  99       * @since    1.5
 100       */
 101      function &getRouter()
 102      {
 103          $router =& parent::getRouter('administrator');
 104          return $router;
 105      }
 106  
 107      /**
 108      * Dispatch the application
 109      *
 110      * @access public
 111      */
 112  	function dispatch($component)
 113      {
 114          $document    =& JFactory::getDocument();
 115          $user        =& JFactory::getUser();
 116  
 117          switch($document->getType())
 118          {
 119              case 'html' :
 120              {
 121                  $document->setMetaData( 'keywords', $this->getCfg('MetaKeys') );
 122  
 123                  if ( $user->get('id') ) {
 124                      $document->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
 125                  }
 126  
 127                  JHTML::_('behavior.mootools');
 128              } break;
 129  
 130              default : break;
 131          }
 132  
 133          $document->setTitle( htmlspecialchars_decode($this->getCfg('sitename' )). ' - ' .JText::_( 'Administration' ));
 134          $document->setDescription( $this->getCfg('MetaDesc') );
 135  
 136          $contents = JComponentHelper::renderComponent($component);
 137          $document->setBuffer($contents, 'component');
 138      }
 139  
 140      /**
 141      * Display the application.
 142      *
 143      * @access public
 144      */
 145  	function render()
 146      {
 147          $component    = JRequest::getCmd('option');
 148          $template    = $this->getTemplate();
 149          $file         = JRequest::getCmd('tmpl', 'index');
 150  
 151          if($component == 'com_login') {
 152              $file = 'login';
 153          }
 154  
 155          $params = array(
 156              'template'     => $template,
 157              'file'        => $file.'.php',
 158              'directory'    => JPATH_THEMES
 159          );
 160  
 161          $document =& JFactory::getDocument();
 162          $data = $document->render($this->getCfg('caching'), $params );
 163          JResponse::setBody($data);
 164      }
 165  
 166      /**
 167      * Login authentication function
 168      *
 169      * @param    array     Array( 'username' => string, 'password' => string )
 170      * @param    array     Array( 'remember' => boolean )
 171      * @access public
 172      * @see JApplication::login
 173      */
 174  	function login($credentials, $options = array())
 175      {
 176          //The minimum group
 177          $options['group'] = 'Public Backend';
 178  
 179           //Make sure users are not autoregistered
 180          $options['autoregister'] = false;
 181  
 182          //Set the application login entry point
 183          if(!array_key_exists('entry_url', $options)) {
 184              $options['entry_url'] = JURI::base().'index.php?option=com_user&task=login';
 185          }
 186  
 187          $result = parent::login($credentials, $options);
 188  
 189          if(!JError::isError($result))
 190          {
 191              $lang = JRequest::getCmd('lang');
 192              $lang = preg_replace( '/[^A-Z-]/i', '', $lang );
 193              $this->setUserState( 'application.lang', $lang  );
 194  
 195              JAdministrator::purgeMessages();
 196          }
 197  
 198          return $result;
 199      }
 200  
 201      /**
 202       * Get the template
 203       *
 204       * @return string The template name
 205       * @since 1.0
 206       */
 207  	function getTemplate()
 208      {
 209          static $template;
 210  
 211          if (!isset($template))
 212          {
 213              // Load the template name from the database
 214              $db =& JFactory::getDBO();
 215              $query = 'SELECT template'
 216                  . ' FROM #__templates_menu'
 217                  . ' WHERE client_id = 1'
 218                  . ' AND menuid = 0'
 219                  ;
 220              $db->setQuery( $query );
 221              $template = $db->loadResult();
 222  
 223              $template = JFilterInput::clean($template, 'cmd');
 224  
 225              if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
 226                  $template = 'khepri';
 227              }
 228          }
 229  
 230          return $template;
 231      }
 232  
 233      /**
 234      * Purge the jos_messages table of old messages
 235      *
 236      * static method
 237      * @since 1.5
 238      */
 239  	function purgeMessages()
 240      {
 241          $db        =& JFactory::getDBO();
 242          $user    =& JFactory::getUser();
 243  
 244          $userid = $user->get('id');
 245  
 246          $query = 'SELECT *'
 247          . ' FROM #__messages_cfg'
 248          . ' WHERE user_id = ' . (int) $userid
 249          . ' AND cfg_name = "auto_purge"'
 250          ;
 251          $db->setQuery( $query );
 252          $config = $db->loadObject( );
 253  
 254          // check if auto_purge value set
 255          if (is_object( $config ) and $config->cfg_name == 'auto_purge' )
 256          {
 257              $purge     = $config->cfg_value;
 258          }
 259          else
 260          {
 261              // if no value set, default is 7 days
 262              $purge     = 7;
 263          }
 264          // calculation of past date
 265  
 266          // if purge value is not 0, then allow purging of old messages
 267          if ($purge > 0)
 268          {
 269              // purge old messages at day set in message configuration
 270              $past =& JFactory::getDate(time() - $purge * 86400);
 271              $pastStamp = $past->toMySQL();
 272  
 273              $query = 'DELETE FROM #__messages'
 274              . ' WHERE date_time < ' . $db->Quote( $pastStamp )
 275              . ' AND user_id_to = ' . (int) $userid
 276              ;
 277              $db->setQuery( $query );
 278              $db->query();
 279          }
 280      }
 281  
 282     /**
 283      * Deprecated, use JURI::root() instead.
 284      *
 285      * @since 1.5
 286      * @deprecated As of version 1.5
 287      * @see JURI::root()
 288      */
 289  	function getSiteURL()
 290      {
 291         return JURI::root();
 292      }
 293  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1