[ Indice ]

Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4

Servizio fornito da VMItalia
Classe:   Funzione:   Variabile:   Costante:  
Storico Ricerche +

titolo

Corpo

[chiudi]

/libraries/joomla/application/ -> application.php (sorgente)

   1  <?php
   2  /**
   3  * @version        $Id: application.php 11409 2009-01-10 02:27:08Z willebil $
   4  * @package        Joomla.Framework
   5  * @subpackage    Application
   6  * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19  * Base class for a Joomla! application.
  20  *
  21  * Acts as a Factory class for application specific objects and provides many
  22  * supporting API functions. Derived clases should supply the route(), dispatch()
  23  * and render() functions.
  24  *
  25  * @abstract
  26  * @package        Joomla.Framework
  27  * @subpackage    Application
  28  * @since        1.5
  29  */
  30  
  31  class JApplication extends JObject
  32  {
  33      /**
  34       * The client identifier.
  35       *
  36       * @var        integer
  37       * @access    protected
  38       * @since    1.5
  39       */
  40      var $_clientId = null;
  41  
  42      /**
  43       * The application message queue.
  44       *
  45       * @var        array
  46       * @access    protected
  47       */
  48      var $_messageQueue = array();
  49  
  50      /**
  51       * The name of the application
  52       *
  53       * @var        array
  54       * @access    protected
  55       */
  56      var $_name = null;
  57  
  58      /**
  59       * The scope of the application
  60       *
  61       * @var        string
  62       * @access    public
  63       */
  64      var $scope = null;
  65  
  66      /**
  67      * Class constructor.
  68      *
  69      * @param    integer    A client identifier.
  70      */
  71  	function __construct($config = array())
  72      {
  73          jimport('joomla.utilities.utility');
  74  
  75          //set the view name
  76          $this->_name        = $this->getName();
  77          $this->_clientId    = $config['clientId'];
  78  
  79          //Enable sessions by default
  80          if(!isset($config['session'])) {
  81              $config['session'] = true;
  82          }
  83  
  84          //Set the session default name
  85          if(!isset($config['session_name'])) {
  86               $config['session_name'] = $this->_name;
  87          }
  88  
  89          //Set the default configuration file
  90          if(!isset($config['config_file'])) {
  91              $config['config_file'] = 'configuration.php';
  92          }
  93  
  94          //create the configuration object
  95          $this->_createConfiguration(JPATH_CONFIGURATION.DS.$config['config_file']);
  96  
  97          //create the session if a session name is passed
  98          if($config['session'] !== false) {
  99              $this->_createSession(JUtility::getHash($config['session_name']));
 100          }
 101  
 102          $this->set( 'requestTime', gmdate('Y-m-d H:i') );
 103      }
 104  
 105      /**
 106       * Returns a reference to the global JApplication object, only creating it if it
 107       * doesn't already exist.
 108       *
 109       * This method must be invoked as:
 110       *         <pre>  $menu = &JApplication::getInstance();</pre>
 111       *
 112       * @access    public
 113       * @param    mixed    $id         A client identifier or name.
 114       * @param    array    $config     An optional associative array of configuration settings.
 115       * @return    JApplication    The appliction object.
 116       * @since    1.5
 117       */
 118      function &getInstance($client, $config = array(), $prefix = 'J')
 119      {
 120          static $instances;
 121  
 122          if (!isset( $instances )) {
 123              $instances = array();
 124          }
 125  
 126          if (empty($instances[$client]))
 127          {
 128              //Load the router object
 129              jimport('joomla.application.helper');
 130              $info =& JApplicationHelper::getClientInfo($client, true);
 131  
 132              $path = $info->path.DS.'includes'.DS.'application.php';
 133              if(file_exists($path))
 134              {
 135                  require_once $path;
 136  
 137                  // Create a JRouter object
 138                  $classname = $prefix.ucfirst($client);
 139                  $instance = new $classname($config);
 140              }
 141              else
 142              {
 143                  $error = JError::raiseError(500, 'Unable to load application: '.$client);
 144                  return $error;
 145              }
 146  
 147              $instances[$client] =& $instance;
 148          }
 149  
 150          return $instances[$client];
 151      }
 152  
 153      /**
 154      * Initialise the application.
 155      *
 156      * @param    array An optional associative array of configuration settings.
 157      * @access    public
 158      */
 159  	function initialise($options = array())
 160      {
 161          jimport('joomla.plugin.helper');
 162  
 163          //Set the language in the class
 164          $config =& JFactory::getConfig();
 165  
 166          // Check that we were given a language in the array (since by default may be blank)
 167          if(isset($options['language'])) {
 168              $config->setValue('config.language', $options['language']);
 169          }
 170  
 171          // Set user specific editor
 172          $user     =& JFactory::getUser();
 173          $editor     = $user->getParam('editor', $this->getCfg('editor'));
 174          $editor = JPluginHelper::isEnabled('editors', $editor) ? $editor : $this->getCfg('editor');
 175          $config->setValue('config.editor', $editor);
 176      }
 177  
 178      /**
 179      * Route the application.
 180      *
 181      * Routing is the process of examining the request environment to determine which
 182      * component should receive the request. The component optional parameters
 183      * are then set in the request object to be processed when the application is being
 184      * dispatched.
 185      *
 186      * @abstract
 187      * @access    public
 188      */
 189  	function route()
 190       {
 191          // get the full request URI
 192          $uri = clone(JURI::getInstance());
 193  
 194          $router =& $this->getRouter();
 195          $result = $router->parse($uri);
 196  
 197          JRequest::set($result, 'get', false );
 198       }
 199  
 200       /**
 201      * Dispatch the applicaiton.
 202      *
 203      * Dispatching is the process of pulling the option from the request object and
 204      * mapping them to a component. If the component does not exist, it handles
 205      * determining a default component to dispatch.
 206      *
 207      * @abstract
 208      * @access    public
 209      */
 210   	function dispatch($component)
 211       {
 212          $document =& JFactory::getDocument();
 213  
 214          $document->setTitle( $this->getCfg('sitename' ). ' - ' .JText::_( 'Administration' ));
 215          $document->setDescription( $this->getCfg('MetaDesc') );
 216  
 217          $contents = JComponentHelper::renderComponent($component);
 218          $document->setBuffer($contents, 'component');
 219       }
 220  
 221      /**
 222      * Render the application.
 223      *
 224      * Rendering is the process of pushing the document buffers into the template
 225      * placeholders, retrieving data from the document and pushing it into
 226      * the JResponse buffer.
 227      *
 228      * @abstract
 229      * @access    public
 230      */
 231  	function render()
 232      {
 233          $params = array(
 234              'template'     => $this->getTemplate(),
 235              'file'        => 'index.php',
 236              'directory'    => JPATH_THEMES
 237          );
 238  
 239          $document =& JFactory::getDocument();
 240          $data = $document->render($this->getCfg('caching'), $params );
 241          JResponse::setBody($data);
 242      }
 243  
 244      /**
 245      * Exit the application.
 246      *
 247      * @access    public
 248      * @param    int    Exit code
 249      */
 250  	function close( $code = 0 ) {
 251          exit($code);
 252      }
 253  
 254      /**
 255       * Redirect to another URL.
 256       *
 257       * Optionally enqueues a message in the system message queue (which will be displayed
 258       * the next time a page is loaded) using the enqueueMessage method. If the headers have
 259       * not been sent the redirect will be accomplished using a "301 Moved Permanently"
 260       * code in the header pointing to the new location. If the headers have already been
 261       * sent this will be accomplished using a JavaScript statement.
 262       *
 263       * @access    public
 264       * @param    string    $url    The URL to redirect to. Can only be http/https URL
 265       * @param    string    $msg    An optional message to display on redirect.
 266       * @param    string  $msgType An optional message type.
 267       * @return    none; calls exit().
 268       * @since    1.5
 269       * @see        JApplication::enqueueMessage()
 270       */
 271  	function redirect( $url, $msg='', $msgType='message' )
 272      {
 273          // check for relative internal links
 274          if (preg_match( '#^index[2]?.php#', $url )) {
 275              $url = JURI::base() . $url;
 276          }
 277  
 278          // Strip out any line breaks
 279          $url = preg_split("/[\r\n]/", $url);
 280          $url = $url[0];
 281  
 282          // If we don't start with a http we need to fix this before we proceed
 283          // We could validly start with something else (e.g. ftp), though this would
 284          // be unlikely and isn't supported by this API
 285          if(!preg_match( '#^http#i', $url )) {
 286              $uri =& JURI::getInstance();
 287              $prefix = $uri->toString(Array('scheme', 'user', 'pass', 'host', 'port'));
 288              if($url[0] == '/') {
 289                  // we just need the prefix since we have a path relative to the root
 290                  $url = $prefix . $url;
 291              } else {
 292                  // its relative to where we are now, so lets add that
 293                  $parts = explode('/', $uri->toString(Array('path')));
 294                  array_pop($parts);
 295                  $path = implode('/',$parts).'/';
 296                  $url = $prefix . $path . $url;
 297              }
 298          }
 299  
 300  
 301          // If the message exists, enqueue it
 302          if (trim( $msg )) {
 303              $this->enqueueMessage($msg, $msgType);
 304          }
 305  
 306          // Persist messages if they exist
 307          if (count($this->_messageQueue))
 308          {
 309              $session =& JFactory::getSession();
 310              $session->set('application.queue', $this->_messageQueue);
 311          }
 312  
 313          /*
 314           * If the headers have been sent, then we cannot send an additional location header
 315           * so we will output a javascript redirect statement.
 316           */
 317          if (headers_sent()) {
 318              echo "<script>document.location.href='$url';</script>\n";
 319          } else {
 320              //@ob_end_clean(); // clear output buffer
 321              header( 'HTTP/1.1 301 Moved Permanently' );
 322              header( 'Location: ' . $url );
 323          }
 324          $this->close();
 325      }
 326  
 327      /**
 328       * Enqueue a system message.
 329       *
 330       * @access    public
 331       * @param    string     $msg     The message to enqueue.
 332       * @param    string    $type    The message type.
 333       * @return    void
 334       * @since    1.5
 335       */
 336  	function enqueueMessage( $msg, $type = 'message' )
 337      {
 338          // For empty queue, if messages exists in the session, enqueue them first
 339          if (!count($this->_messageQueue))
 340          {
 341              $session =& JFactory::getSession();
 342              $sessionQueue = $session->get('application.queue');
 343              if (count($sessionQueue)) {
 344                  $this->_messageQueue = $sessionQueue;
 345                  $session->set('application.queue', null);
 346              }
 347          }
 348          // Enqueue the message
 349          $this->_messageQueue[] = array('message' => $msg, 'type' => strtolower($type));
 350      }
 351  
 352      /**
 353       * Get the system message queue.
 354       *
 355       * @access    public
 356       * @return    The system message queue.
 357       * @since    1.5
 358       */
 359  	function getMessageQueue()
 360      {
 361          // For empty queue, if messages exists in the session, enqueue them
 362          if (!count($this->_messageQueue))
 363          {
 364              $session =& JFactory::getSession();
 365              $sessionQueue = $session->get('application.queue');
 366              if (count($sessionQueue)) {
 367                  $this->_messageQueue = $sessionQueue;
 368                  $session->set('application.queue', null);
 369              }
 370          }
 371          return $this->_messageQueue;
 372      }
 373  
 374       /**
 375       * Gets a configuration value.
 376       *
 377       * @access    public
 378       * @param    string    The name of the value to get.
 379       * @return    mixed    The user state.
 380       * @example    application/japplication-getcfg.php Getting a configuration value
 381       */
 382  	function getCfg( $varname )
 383      {
 384          $config =& JFactory::getConfig();
 385          return $config->getValue('config.' . $varname);
 386      }
 387  
 388      /**
 389       * Method to get the application name
 390       *
 391       * The dispatcher name by default parsed using the classname, or it can be set
 392       * by passing a $config['name'] in the class constructor
 393       *
 394       * @access    public
 395       * @return    string The name of the dispatcher
 396       * @since    1.5
 397       */
 398  	function getName()
 399      {
 400          $name = $this->_name;
 401  
 402          if (empty( $name ))
 403          {
 404              $r = null;
 405              if ( !preg_match( '/J(.*)/i', get_class( $this ), $r ) ) {
 406                  JError::raiseError(500, "JApplication::getName() : Can\'t get or parse class name.");
 407              }
 408              $name = strtolower( $r[1] );
 409          }
 410  
 411          return $name;
 412      }
 413  
 414      /**
 415       * Gets a user state.
 416       *
 417       * @access    public
 418       * @param    string    The path of the state.
 419       * @return    mixed    The user state.
 420       */
 421  	function getUserState( $key )
 422      {
 423          $session    =& JFactory::getSession();
 424          $registry    =& $session->get('registry');
 425          if(!is_null($registry)) {
 426              return $registry->getValue($key);
 427          }
 428          return null;
 429      }
 430  
 431      /**
 432      * Sets the value of a user state variable.
 433      *
 434      * @access    public
 435      * @param    string    The path of the state.
 436      * @param    string    The value of the variable.
 437      * @return    mixed    The previous state, if one existed.
 438      */
 439  	function setUserState( $key, $value )
 440      {
 441          $session    =& JFactory::getSession();
 442          $registry    =& $session->get('registry');
 443          if(!is_null($registry)) {
 444              return $registry->setValue($key, $value);
 445          }
 446          return null;
 447      }
 448  
 449      /**
 450       * Gets the value of a user state variable.
 451       *
 452       * @access    public
 453       * @param    string    The key of the user state variable.
 454       * @param    string    The name of the variable passed in a request.
 455       * @param    string    The default value for the variable if not found. Optional.
 456       * @param    string    Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
 457       * @return    The request user state.
 458       */
 459  	function getUserStateFromRequest( $key, $request, $default = null, $type = 'none' )
 460      {
 461          $old_state = $this->getUserState( $key );
 462          $cur_state = (!is_null($old_state)) ? $old_state : $default;
 463          $new_state = JRequest::getVar($request, null, 'default', $type);
 464  
 465          // Save the new value only if it was set in this request
 466          if ($new_state !== null) {
 467              $this->setUserState($key, $new_state);
 468          } else {
 469              $new_state = $cur_state;
 470          }
 471  
 472          return $new_state;
 473      }
 474  
 475      /**
 476       * Registers a handler to a particular event group.
 477       *
 478       * @static
 479       * @param    string    The event name.
 480       * @param    mixed    The handler, a function or an instance of a event object.
 481       * @return    void
 482       * @since    1.5
 483       */
 484  	function registerEvent($event, $handler)
 485      {
 486          $dispatcher =& JDispatcher::getInstance();
 487          $dispatcher->register($event, $handler);
 488      }
 489  
 490      /**
 491       * Calls all handlers associated with an event group.
 492       *
 493       * @static
 494       * @param    string    The event name.
 495       * @param    array    An array of arguments.
 496       * @return    array    An array of results from each function call.
 497       * @since    1.5
 498       */
 499  	function triggerEvent($event, $args=null)
 500      {
 501          $dispatcher =& JDispatcher::getInstance();
 502          return $dispatcher->trigger($event, $args);
 503      }
 504  
 505      /**
 506       * Login authentication function.
 507       *
 508       * Username and encoded password are passed the the onLoginUser event which
 509       * is responsible for the user validation. A successful validation updates
 510       * the current session record with the users details.
 511       *
 512       * Username and encoded password are sent as credentials (along with other
 513       * possibilities) to each observer (authentication plugin) for user
 514       * validation.  Successful validation will update the current session with
 515       * the user details.
 516       *
 517       * @param    array     Array( 'username' => string, 'password' => string )
 518       * @param    array     Array( 'remember' => boolean )
 519       * @return    boolean True on success.
 520       * @access    public
 521       * @since    1.5
 522       */
 523  	function login($credentials, $options = array())
 524      {
 525          // Get the global JAuthentication object
 526          jimport( 'joomla.user.authentication');
 527          $authenticate = & JAuthentication::getInstance();
 528          $response      = $authenticate->authenticate($credentials, $options);
 529  
 530          if ($response->status === JAUTHENTICATE_STATUS_SUCCESS)
 531          {
 532              // Import the user plugin group
 533              JPluginHelper::importPlugin('user');
 534  
 535              // OK, the credentials are authenticated.  Lets fire the onLogin event
 536              $results = $this->triggerEvent('onLoginUser', array((array)$response, $options));
 537  
 538              /*
 539               * If any of the user plugins did not successfully complete the login routine
 540               * then the whole method fails.
 541               *
 542               * Any errors raised should be done in the plugin as this provides the ability
 543               * to provide much more information about why the routine may have failed.
 544               */
 545  
 546              if (!in_array(false, $results, true))
 547              {
 548                  // Set the remember me cookie if enabled
 549                  if (isset($options['remember']) && $options['remember'])
 550                  {
 551                      jimport('joomla.utilities.simplecrypt');
 552                      jimport('joomla.utilities.utility');
 553  
 554                      //Create the encryption key, apply extra hardening using the user agent string
 555                      $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
 556  
 557                      $crypt = new JSimpleCrypt($key);
 558                      $rcookie = $crypt->encrypt(serialize($credentials));
 559                      $lifetime = time() + 365*24*60*60;
 560                      setcookie( JUtility::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, '/' );
 561                  }
 562                  return true;
 563              }
 564          }
 565  
 566          // Trigger onLoginFailure Event
 567          $this->triggerEvent('onLoginFailure', array((array)$response));
 568  
 569  
 570          // If silent is set, just return false
 571          if (isset($options['silent']) && $options['silent']) {
 572              return false;
 573          }
 574  
 575          // Return the error
 576          return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_AUTHENTICATE'));
 577      }
 578  
 579      /**
 580       * Logout authentication function.
 581       *
 582       * Passed the current user information to the onLogoutUser event and reverts the current
 583       * session record back to 'anonymous' parameters.
 584       *
 585        * @param     int     $userid   The user to load - Can be an integer or string - If string, it is converted to ID automatically
 586       * @param    array     $options  Array( 'clientid' => array of client id's )
 587       *
 588       * @access public
 589       */
 590  	function logout($userid = null, $options = array())
 591      {
 592          // Initialize variables
 593          $retval = false;
 594  
 595          // Get a user object from the JApplication
 596          $user = &JFactory::getUser($userid);
 597  
 598          // Build the credentials array
 599          $parameters['username']    = $user->get('username');
 600          $parameters['id']        = $user->get('id');
 601  
 602          // Set clientid in the options array if it hasn't been set already
 603          if(empty($options['clientid'])) {
 604              $options['clientid'][] = $this->getClientId();
 605          }
 606  
 607          // Import the user plugin group
 608          JPluginHelper::importPlugin('user');
 609  
 610          // OK, the credentials are built. Lets fire the onLogout event
 611          $results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
 612  
 613          /*
 614           * If any of the authentication plugins did not successfully complete
 615           * the logout routine then the whole method fails.  Any errors raised
 616           * should be done in the plugin as this provides the ability to provide
 617           * much more information about why the routine may have failed.
 618           */
 619          if (!in_array(false, $results, true)) {
 620              setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
 621              return true;
 622          }
 623  
 624          // Trigger onLoginFailure Event
 625          $this->triggerEvent('onLogoutFailure', array($parameters));
 626  
 627          return false;
 628      }
 629  
 630      /**
 631       * Gets the name of the current template.
 632       *
 633       * @return    string
 634       */
 635  	function getTemplate()
 636      {
 637          return 'system';
 638      }
 639  
 640      /**
 641       * Return a reference to the application JRouter object.
 642       *
 643       * @access    public
 644       * @param  array    $options     An optional associative array of configuration settings.
 645       * @return    JRouter.
 646       * @since    1.5
 647       */
 648      function &getRouter($name = null, $options = array())
 649      {
 650          if(!isset($name)) {
 651              $name = $this->_name;
 652          }
 653  
 654          jimport( 'joomla.application.router' );
 655          $router =& JRouter::getInstance($name, $options);
 656          if (JError::isError($router)) {
 657              $null = null;
 658              return $null;
 659          }
 660          return $router;
 661      }
 662  
 663      /**
 664       * Return a reference to the application JPathway object.
 665       *
 666       * @access public
 667       * @param  array    $options     An optional associative array of configuration settings.
 668       * @return object JPathway.
 669       * @since 1.5
 670       */
 671      function &getPathway($name = null, $options = array())
 672      {
 673          if(!isset($name)) {
 674              $name = $this->_name;
 675          }
 676  
 677          jimport( 'joomla.application.pathway' );
 678          $pathway =& JPathway::getInstance($name, $options);
 679          if (JError::isError($pathway)) {
 680              $null = null;
 681              return $null;
 682          }
 683          return $pathway;
 684      }
 685  
 686      /**
 687       * Return a reference to the application JPathway object.
 688       *
 689       * @access public
 690       * @param  array    $options     An optional associative array of configuration settings.
 691       * @return object JMenu.
 692       * @since 1.5
 693       */
 694      function &getMenu($name = null, $options = array())
 695      {
 696          if(!isset($name)) {
 697              $name = $this->_name;
 698          }
 699  
 700          jimport( 'joomla.application.menu' );
 701          $menu =& JMenu::getInstance($name, $options);
 702          if (JError::isError($menu)) {
 703              $null = null;
 704              return $null;
 705          }
 706          return $menu;
 707      }
 708  
 709      /**
 710       * Create the configuration registry
 711       *
 712       * @access    private
 713       * @param    string    $file     The path to the configuration file
 714       * return    JConfig
 715       */
 716      function &_createConfiguration($file)
 717      {
 718          jimport( 'joomla.registry.registry' );
 719  
 720          require_once( $file );
 721  
 722          // Create the JConfig object
 723          $config = new JConfig();
 724  
 725          // Get the global configuration object
 726          $registry =& JFactory::getConfig();
 727  
 728          // Load the configuration values into the registry
 729          $registry->loadObject($config);
 730  
 731          return $config;
 732      }
 733  
 734      /**
 735       * Create the user session.
 736       *
 737       * Old sessions are flushed based on the configuration value for the cookie
 738       * lifetime. If an existing session, then the last access time is updated.
 739       * If a new session, a session id is generated and a record is created in
 740       * the #__sessions table.
 741       *
 742       * @access    private
 743       * @param    string    The sessions name.
 744       * @return    object    JSession on success. May call exit() on database error.
 745       * @since    1.5
 746       */
 747      function &_createSession( $name )
 748      {
 749          $options = array();
 750          $options['name'] = $name;
 751          switch($this->_clientId) {
 752              case 0:
 753                  if($this->getCfg('force_ssl') == 2) {
 754                      $options['force_ssl'] = true;
 755                  }
 756                  break;
 757              case 1:
 758                  if($this->getCfg('force_ssl') >= 1) {
 759                      $options['force_ssl'] = true;
 760                  }
 761                  break;
 762          }
 763  
 764          $session =& JFactory::getSession($options);
 765  
 766          jimport('joomla.database.table');
 767          $storage = & JTable::getInstance('session');
 768          $storage->purge($session->getExpire());
 769  
 770          // Session exists and is not expired, update time in session table
 771          if ($storage->load($session->getId())) {
 772              $storage->update();
 773              return $session;
 774          }
 775  
 776          //Session doesn't exist yet, initalise and store it in the session table
 777          $session->set('registry',    new JRegistry('session'));
 778          $session->set('user',        new JUser());
 779  
 780          if (!$storage->insert( $session->getId(), $this->getClientId())) {
 781              jexit( $storage->getError());
 782          }
 783  
 784          return $session;
 785      }
 786  
 787  
 788      /**
 789       * Gets the client id of the current running application.
 790       *
 791       * @access    public
 792       * @return    int A client identifier.
 793       * @since    1.5
 794       */
 795  	function getClientId( )
 796      {
 797          return $this->_clientId;
 798      }
 799  
 800      /**
 801       * Is admin interface?
 802       *
 803       * @access    public
 804       * @return    boolean        True if this application is administrator.
 805       * @since    1.0.2
 806       */
 807  	function isAdmin()
 808      {
 809          return ($this->_clientId == 1);
 810      }
 811  
 812      /**
 813       * Is site interface?
 814       *
 815       * @access    public
 816       * @return    boolean        True if this application is site.
 817       * @since    1.5
 818       */
 819  	function isSite()
 820      {
 821          return ($this->_clientId == 0);
 822      }
 823  
 824      /**
 825       * Deprecated functions
 826       */
 827  
 828       /**
 829       * Deprecated, use JPathWay->addItem() method instead.
 830       *
 831       * @since 1.0
 832       * @deprecated As of version 1.5
 833       * @see JPathWay::addItem()
 834       */
 835  	function appendPathWay( $name, $link = null )
 836      {
 837          /*
 838           * To provide backward compatability if no second parameter is set
 839           * set it to null
 840           */
 841          if ($link == null) {
 842              $link = '';
 843          }
 844  
 845          $pathway =& $this->getPathway();
 846  
 847          if( defined( '_JLEGACY' ) && $link == '' )
 848          {
 849              $matches = array();
 850  
 851              $links = preg_match_all ( '/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/ui', $name, $matches, PREG_SET_ORDER );
 852  
 853              foreach( $matches AS $match) {
 854                  // Add each item to the pathway object
 855                  if( !$pathway->addItem( $match[2], $match[1] ) ) {
 856                      return false;
 857                  }
 858              }
 859               return true;
 860          }
 861          else
 862          {
 863              // Add item to the pathway object
 864              if ($pathway->addItem($name, $link)) {
 865                  return true;
 866              }
 867          }
 868  
 869          return false;
 870    }
 871  
 872      /**
 873       * Deprecated, use JPathway->getPathWayNames() method instead.
 874       *
 875       * @since 1.0
 876       * @deprecated As of version 1.5
 877       * @see JPathWay::getPathWayNames()
 878       */
 879  	function getCustomPathWay()
 880      {
 881          $pathway = $this->getPathway();
 882          return $pathway->getPathWayNames();
 883      }
 884  
 885      /**
 886       * Deprecated, use JDocument->get( 'head' ) instead.
 887       *
 888       * @since 1.0
 889       * @deprecated As of version 1.5
 890       * @see JDocument
 891       * @see JObject::get()
 892       */
 893  	function getHead()
 894      {
 895          $document=& JFactory::getDocument();
 896          return $document->get('head');
 897      }
 898  
 899      /**
 900       * Deprecated, use JDocument->setMetaData instead.
 901       *
 902       * @since 1.0
 903       * @deprecated As of version 1.5
 904       * @param string Name of the metadata tag
 905       * @param string Content of the metadata tag
 906       * @param string Deprecated, ignored
 907       * @param string Deprecated, ignored
 908       * @see JDocument::setMetaData()
 909       */
 910  	function addMetaTag( $name, $content, $prepend = '', $append = '' )
 911      {
 912          $document=& JFactory::getDocument();
 913          $document->setMetadata($name, $content);
 914      }
 915  
 916      /**
 917       * Deprecated, use JDocument->setMetaData instead.
 918       *
 919       * @since 1.0
 920       * @deprecated As of version 1.5
 921           * @param string Name of the metadata tag
 922           * @param string Content of the metadata tag
 923       * @see JDocument::setMetaData()
 924       */
 925  	function appendMetaTag( $name, $content )
 926      {
 927          $this->addMetaTag($name, $content);
 928      }
 929  
 930      /**
 931       * Deprecated, use JDocument->setMetaData instead
 932       *
 933       * @since 1.0
 934       * @deprecated As of version 1.5
 935           * @param string Name of the metadata tag
 936           * @param string Content of the metadata tag
 937       * @see JDocument::setMetaData()
 938       */
 939  	function prependMetaTag( $name, $content )
 940      {
 941          $this->addMetaTag($name, $content);
 942      }
 943  
 944      /**
 945       * Deprecated, use JDocument->addCustomTag instead (only when document type is HTML).
 946       *
 947       * @since 1.0
 948       * @deprecated As of version 1.5
 949       * @param string Valid HTML
 950       * @see JDocumentHTML::addCustomTag()
 951       */
 952  	function addCustomHeadTag( $html )
 953      {
 954          $document=& JFactory::getDocument();
 955          if($document->getType() == 'html') {
 956              $document->addCustomTag($html);
 957          }
 958      }
 959  
 960      /**
 961       * Deprecated.
 962       *
 963       * @since 1.0
 964       * @deprecated As of version 1.5
 965       */
 966  	function getBlogSectionCount( )
 967      {
 968          $menus = &JSite::getMenu();
 969          return count($menus->getItems('type', 'content_blog_section'));
 970      }
 971  
 972      /**
 973       * Deprecated.
 974       *
 975       * @since 1.0
 976       * @deprecated As of version 1.5
 977       */
 978  	function getBlogCategoryCount( )
 979      {
 980          $menus = &JSite::getMenu();
 981          return count($menus->getItems('type', 'content_blog_category'));
 982      }
 983  
 984      /**
 985       * Deprecated.
 986       *
 987       * @since 1.0
 988       * @deprecated As of version 1.5
 989       */
 990  	function getGlobalBlogSectionCount( )
 991      {
 992          $menus = &JSite::getMenu();
 993          return count($menus->getItems('type', 'content_blog_section'));
 994      }
 995  
 996      /**
 997       * Deprecated.
 998       *
 999       * @since 1.0
1000       * @deprecated As of version 1.5
1001       */
1002  	function getStaticContentCount( )
1003      {
1004          $menus = &JSite::getMenu();
1005          return count($menus->getItems('type', 'content_typed'));
1006      }
1007  
1008      /**
1009       * Deprecated.
1010       *
1011       * @since 1.0
1012       * @deprecated As of version 1.5
1013       */
1014  	function getContentItemLinkCount( )
1015      {
1016          $menus = &JSite::getMenu();
1017          return count($menus->getItems('type', 'content_item_link'));
1018      }
1019  
1020      /**
1021       * Deprecated, use JApplicationHelper::getPath instead.
1022       *
1023       * @since 1.0
1024       * @deprecated As of version 1.5
1025       * @see JApplicationHelper::getPath()
1026       */
1027  	function getPath($varname, $user_option = null)
1028      {
1029          jimport('joomla.application.helper');
1030          return JApplicationHelper::getPath ($varname, $user_option);
1031      }
1032  
1033      /**
1034       * Deprecated, use JURI::base() instead.
1035       *
1036       * @since 1.0
1037       * @deprecated As of version 1.5
1038       * @see JURI::base()
1039       */
1040  	function getBasePath($client=0, $addTrailingSlash = true)
1041      {
1042          return JURI::base();
1043      }
1044  
1045      /**
1046       * Deprecated, use JFactory::getUser instead.
1047       *
1048       * @since 1.0
1049       * @deprecated As of version 1.5
1050       * @see JFactory::getUser()
1051       */
1052      function &getUser()
1053      {
1054          $user =& JFactory::getUser();
1055          return $user;
1056      }
1057  
1058      /**
1059       * Deprecated, use ContentHelper::getItemid instead.
1060       *
1061       * @since 1.0
1062       * @deprecated As of version 1.5
1063       * @see ContentHelperRoute::getArticleRoute()
1064       */
1065  	function getItemid( $id )
1066      {
1067          require_once  JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
1068  
1069          // Load the article data to know what section/category it is in.
1070          $article =& JTable::getInstance('content');
1071          $article->load($id);
1072  
1073          $needles = array(
1074              'article'  => (int) $id,
1075              'category' => (int) $article->catid,
1076              'section'  => (int) $article->sectionid,
1077          );
1078  
1079          $item    = ContentHelperRoute::_findItem($needles);
1080          $return    = is_object($item) ? $item->id : null;
1081  
1082          return $return;
1083      }
1084  
1085      /**
1086       * Deprecated, use JDocument::setTitle instead.
1087       *
1088       * @since 1.0
1089       * @deprecated As of version 1.5
1090       * @see JDocument::setTitle()
1091       */
1092  	function setPageTitle( $title=null )
1093      {
1094          $document=& JFactory::getDocument();
1095          $document->setTitle($title);
1096      }
1097  
1098      /**
1099       * Deprecated, use JDocument::getTitle instead.
1100       *
1101       * @since 1.0
1102       * @deprecated As of version 1.5
1103       * @see JDocument::getTitle()
1104       */
1105  	function getPageTitle()
1106      {
1107          $document=& JFactory::getDocument();
1108          return $document->getTitle();
1109      }
1110  }


Generato il: Mon Oct 19 20:29:27 2009 Generato con PHPXref 0.7