iTx Technologies offre gratuitement
cet espace pour Joomla !

title

Body

[fermer]

/includes/ -> application.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: application.php 10912 2008-09-05 19:45:22Z willebil $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2008 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 JSite 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'] = 0;
  39          parent::__construct($config);
  40      }
  41  
  42      /**
  43      * Initialise the application.
  44      *
  45      * @access public
  46      */
  47  	function initialise( $options = array())
  48      {
  49          // if a language was specified it has priority
  50          // otherwise use user or default language settings
  51          if (empty($options['language']))
  52          {
  53              $user = & JFactory::getUser();
  54              $lang    = $user->getParam( 'language' );
  55  
  56              // Make sure that the user's language exists
  57              if ( $lang && JLanguage::exists($lang) ) {
  58                  $options['language'] = $lang;
  59              } else {
  60                  $params =  JComponentHelper::getParams('com_languages');
  61                  $client    =& JApplicationHelper::getClientInfo($this->getClientId());
  62                  $options['language'] = $params->get($client->name, 'en-GB');
  63              }
  64  
  65          }
  66  
  67          // One last check to make sure we have something
  68          if ( ! JLanguage::exists($options['language']) ) {
  69              $options['language'] = 'en-GB';
  70          }
  71  
  72          parent::initialise($options);
  73      }
  74  
  75      /**
  76      * Route the application
  77      *
  78      * @access public
  79      */
  80  	function route() {
  81          parent::route();
  82      }
  83  
  84      /**
  85      * Dispatch the application
  86      *
  87      * @access public
  88      */
  89  	function dispatch($component)
  90      {
  91          $document    =& JFactory::getDocument();
  92          $user        =& JFactory::getUser();
  93          $router     =& $this->getRouter();
  94          $params     =& $this->getParams();
  95  
  96          switch($document->getType())
  97          {
  98              case 'html':
  99              {
 100                  //set metadata
 101                  $document->setMetaData( 'keywords', $this->getCfg('MetaKeys') );
 102  
 103                  if ( $user->get('id') ) {
 104                      $document->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
 105                  }
 106  
 107                  if($router->getMode() == JROUTER_MODE_SEF) {
 108                      $document->setBase(JURI::current());
 109                  }
 110              } break;
 111  
 112              case 'feed':
 113              {
 114                  $document->setBase(JURI::current());
 115              } break;
 116  
 117              default: break;
 118          }
 119  
 120  
 121          $document->setTitle( $params->get('page_title') );
 122          $document->setDescription( $params->get('page_description') );
 123  
 124          $contents = JComponentHelper::renderComponent($component);
 125          $document->setBuffer( $contents, 'component');
 126      }
 127  
 128      /**
 129      * Display the application.
 130      *
 131      * @access public
 132      */
 133  	function render()
 134      {
 135          $document =& JFactory::getDocument();
 136          $user     =& JFactory::getUser();
 137  
 138          // get the format to render
 139          $format = $document->getType();
 140  
 141          switch($format)
 142          {
 143              case 'feed' :
 144              {
 145                  $params = array();
 146              } break;
 147  
 148              case 'html' :
 149              default     :
 150              {
 151                  $template    = $this->getTemplate();
 152                  $file         = JRequest::getCmd('tmpl', 'index');
 153  
 154                  if ($this->getCfg('offline') && $user->get('gid') < '23' ) {
 155                      $file = 'offline';
 156                  }
 157                  if (!is_dir( JPATH_THEMES.DS.$template ) && !$this->getCfg('offline')) {
 158                      $file = 'component';
 159                  }
 160                  $params = array(
 161                      'template'     => $template,
 162                      'file'        => $file.'.php',
 163                      'directory'    => JPATH_THEMES
 164                  );
 165              } break;
 166           }
 167  
 168          $data = $document->render( $this->getCfg('caching'), $params);
 169          JResponse::setBody($data);
 170      }
 171  
 172     /**
 173      * Login authentication function
 174      *
 175      * @param    array     Array( 'username' => string, 'password' => string )
 176      * @param    array     Array( 'remember' => boolean )
 177      * @access public
 178      * @see JApplication::login
 179      */
 180  	function login($credentials, $options = array())
 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          return parent::login($credentials, $options);
 188      }
 189  
 190      /**
 191      * Check if the user can access the application
 192      *
 193      * @access public
 194      */
 195  	function authorize($itemid)
 196      {
 197          $menus    =& JSite::getMenu();
 198          $user    =& JFactory::getUser();
 199          $aid    = $user->get('aid');
 200  
 201          if(!$menus->authorize($itemid, $aid))
 202          {
 203              if ( ! $aid )
 204              {
 205                  // Redirect to login
 206                  $uri        = JFactory::getURI();
 207                  $return        = $uri->toString();
 208  
 209                  $url  = 'index.php?option=com_user&view=login';
 210                  $url .= '&return='.base64_encode($return);;
 211  
 212                  //$url    = JRoute::_($url, false);
 213                  $this->redirect($url, JText::_('You must login first') );
 214              }
 215              else
 216              {
 217                  JError::raiseError( 403, JText::_('ALERTNOTAUTH') );
 218              }
 219          }
 220      }
 221  
 222      /**
 223       * Get the appliaction parameters
 224       *
 225       * @param    string    The component option
 226       * @return    object    The parameters object
 227       * @since    1.5
 228       */
 229      function &getParams($option = null)
 230      {
 231          static $params = array();
 232          $hash = '__default';
 233          if(!empty($option)) $hash = $option;
 234          if (!isset($params[$hash]))
 235          {
 236              // Get component parameters
 237              if (!$option) {
 238                  $option = JRequest::getCmd('option');
 239              }
 240              $params[$hash] =& JComponentHelper::getParams($option);
 241  
 242              // Get menu parameters
 243              $menus    =& JSite::getMenu();
 244              $menu    = $menus->getActive();
 245  
 246              $title       = htmlspecialchars_decode($this->getCfg('sitename' ));
 247              $description = $this->getCfg('MetaDesc');
 248  
 249              // Lets cascade the parameters if we have menu item parameters
 250              if (is_object($menu))
 251              {
 252                  $params[$hash]->merge(new JParameter($menu->params));
 253                  $title = $menu->name;
 254  
 255              }
 256  
 257              $params[$hash]->def( 'page_title'      , $title );
 258              $params[$hash]->def( 'page_description', $description );
 259          }
 260  
 261          return $params[$hash];
 262      }
 263  
 264      /**
 265       * Get the appliaction parameters
 266       *
 267       * @param    string    The component option
 268       * @return    object    The parameters object
 269       * @since    1.5
 270       */
 271      function &getPageParameters( $option = null )
 272      {
 273          return $this->getParams( $option );
 274      }
 275  
 276      /**
 277       * Get the template
 278       *
 279       * @return string The template name
 280       * @since 1.0
 281       */
 282  	function getTemplate()
 283      {
 284          // Allows for overriding the active template from a component, and caches the result of this function
 285          // e.g. $mainframe->setTemplate('solar-flare-ii');
 286          if ($template = $this->get('setTemplate')) {
 287              return $template;
 288          }
 289  
 290          // Get the id of the active menu item
 291          $menu =& JSite::getMenu();
 292          $item = $menu->getActive();
 293  
 294          $id = 0;
 295          if(is_object($item)) { // valid item retrieved
 296              $id = $item->id;
 297          }
 298  
 299          // Load template entries for the active menuid and the default template
 300          $db =& JFactory::getDBO();
 301          $query = 'SELECT template'
 302              . ' FROM #__templates_menu'
 303              . ' WHERE client_id = 0 AND (menuid = 0 OR menuid = '.(int) $id.')'
 304              . ' ORDER BY menuid DESC'
 305              ;
 306          $db->setQuery($query, 0, 1);
 307          $template = $db->loadResult();
 308  
 309          // Allows for overriding the active template from the request
 310          $template = JRequest::getCmd('template', $template);
 311          $template = JFilterInput::clean($template, 'cmd'); // need to filter the default value as well
 312  
 313          // Fallback template
 314          if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
 315              $template = 'rhuk_milkyway';
 316          }
 317  
 318          // Cache the result
 319          $this->set('setTemplate', $template);
 320          return $template;
 321      }
 322  
 323      /**
 324       * Overrides the default template that would be used
 325       *
 326       * @param string The template name
 327       */
 328  	function setTemplate( $template )
 329      {
 330          if (is_dir(JPATH_THEMES.DS.$template)) {
 331              $this->set('setTemplate', $template);
 332          }
 333      }
 334  
 335      /**
 336       * Return a reference to the JPathway object.
 337       *
 338       * @access public
 339       * @return object JPathway.
 340       * @since 1.5
 341       */
 342      function &getMenu()
 343      {
 344          $options = array();
 345          $menu =& parent::getMenu('site', $options);
 346          return $menu;
 347      }
 348  
 349      /**
 350       * Return a reference to the JPathway object.
 351       *
 352       * @access public
 353       * @return object JPathway.
 354       * @since 1.5
 355       */
 356      function &getPathWay()
 357      {
 358          $options = array();
 359          $pathway =& parent::getPathway('site', $options);
 360          return $pathway;
 361      }
 362  
 363      /**
 364       * Return a reference to the JRouter object.
 365       *
 366       * @access    public
 367       * @return    JRouter.
 368       * @since    1.5
 369       */
 370      function &getRouter()
 371      {
 372          $config =& JFactory::getConfig();
 373          $options['mode'] = $config->getValue('config.sef');
 374          $router =& parent::getRouter('site', $options);
 375          return $router;
 376      }
 377  }


Generé en: Tue Mar 2 18:10:43 2010 | Cross-referenced par PHPXref 0.7