Source for file application.php

Documentation is available at application.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Application
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. JLog::add('JApplication is deprecated.'JLog::WARNING'deprecated');
  13.  
  14. /**
  15.  * Base class for a Joomla! application.
  16.  *
  17.  * Acts as a Factory class for application specific objects and provides many
  18.  * supporting API functions. Derived clases should supply the route(), dispatch()
  19.  * and render() functions.
  20.  *
  21.  * @package     Joomla.Legacy
  22.  * @subpackage  Application
  23.  * @since       11.1
  24.  * @deprecated  4.0  Use JApplicationCms instead unless specified otherwise
  25.  */
  26. {
  27.     /**
  28.      * The client identifier.
  29.      *
  30.      * @var    integer 
  31.      * @since  11.1
  32.      * @deprecated  4.0
  33.      */
  34.     protected $_clientId = null;
  35.  
  36.     /**
  37.      * The application message queue.
  38.      *
  39.      * @var    array 
  40.      * @since  11.1
  41.      * @deprecated  4.0
  42.      */
  43.     protected $_messageQueue = array();
  44.  
  45.     /**
  46.      * The name of the application.
  47.      *
  48.      * @var    array 
  49.      * @since  11.1
  50.      * @deprecated  4.0
  51.      */
  52.     protected $_name = null;
  53.  
  54.     /**
  55.      * The scope of the application.
  56.      *
  57.      * @var    string 
  58.      * @since  11.1
  59.      * @deprecated  4.0
  60.      */
  61.     public $scope = null;
  62.  
  63.     /**
  64.      * The time the request was made.
  65.      *
  66.      * @var    date 
  67.      * @since  11.1
  68.      * @deprecated  4.0
  69.      */
  70.     public $requestTime = null;
  71.  
  72.     /**
  73.      * The time the request was made as Unix timestamp.
  74.      *
  75.      * @var    integer 
  76.      * @since  11.1
  77.      * @deprecated  4.0
  78.      */
  79.     public $startTime = null;
  80.  
  81.     /**
  82.      * @var    JApplicationWebClient  The application client object.
  83.      * @since  12.2
  84.      * @deprecated  4.0
  85.      */
  86.     public $client;
  87.  
  88.     /**
  89.      * @var    array  JApplication instances container.
  90.      * @since  11.3
  91.      * @deprecated  4.0
  92.      */
  93.     protected static $instances array();
  94.  
  95.     /**
  96.      * @var    boolean  Indicates that strong encryption should be used.
  97.      * @since  3.2
  98.      * @note   Default has been changed as of 3.2. If salted md5 is required it must be explictly set.
  99.      * @deprecated  4.0
  100.      */
  101.     protected $useStrongEncryption = false;
  102.  
  103.     /**
  104.      * Class constructor.
  105.      *
  106.      * @param   array  $config  A configuration array including optional elements such as session
  107.      *  session_name, clientId and others. This is not exhaustive.
  108.      *
  109.      * @since   11.1
  110.      * @deprecated  4.0
  111.      */
  112.     public function __construct($config array())
  113.     {
  114.         // Set the view name.
  115.         $this->_name = $this->getName();
  116.  
  117.         // Only set the clientId if available.
  118.         if (isset($config['clientId']))
  119.         {
  120.             $this->_clientId = $config['clientId'];
  121.         }
  122.  
  123.         // Enable sessions by default.
  124.         if (!isset($config['session']))
  125.         {
  126.             $config['session'true;
  127.         }
  128.  
  129.         // Create the input object
  130.         $this->input = new JInput;
  131.  
  132.         $this->client = new JApplicationWebClient;
  133.  
  134.         $this->loadDispatcher();
  135.  
  136.         // Set the session default name.
  137.         if (!isset($config['session_name']))
  138.         {
  139.             $config['session_name'$this->_name;
  140.         }
  141.  
  142.         // Set the default configuration file.
  143.         if (!isset($config['config_file']))
  144.         {
  145.             $config['config_file''configuration.php';
  146.         }
  147.  
  148.         // Create the configuration object.
  149.         if (file_exists(JPATH_CONFIGURATION '/' $config['config_file']))
  150.         {
  151.             $this->_createConfiguration(JPATH_CONFIGURATION '/' $config['config_file']);
  152.         }
  153.  
  154.         // Create the session if a session name is passed.
  155.         if ($config['session'!== false)
  156.         {
  157.             $this->_createSession(self::getHash($config['session_name']));
  158.         }
  159.  
  160.         $this->requestTime = gmdate('Y-m-d H:i');
  161.  
  162.         // Used by task system to ensure that the system doesn't go over time.
  163.         $this->startTime = JProfiler::getmicrotime();
  164.     }
  165.  
  166.     /**
  167.      * Returns the global JApplicationCms object, only creating it if it
  168.      * doesn't already exist.
  169.      *
  170.      * @param   mixed   $client  A client identifier or name.
  171.      * @param   array   $config  An optional associative array of configuration settings.
  172.      * @param   string  $prefix  A prefix for class names
  173.      *
  174.      * @return  JApplicationCms  A JApplicationCms object.
  175.      *
  176.      * @since   11.1
  177.      * @deprecated  4.0  Use JApplicationCms::getInstance() instead
  178.      * @note    As of 3.2, this proxies to JApplicationCms::getInstance()
  179.      */
  180.     public static function getInstance($client$config array()$prefix 'J')
  181.     {
  182.         return JApplicationCms::getInstance($client);
  183.     }
  184.  
  185.     /**
  186.      * Initialise the application.
  187.      *
  188.      * @param   array  $options  An optional associative array of configuration settings.
  189.      *
  190.      * @return  void 
  191.      *
  192.      * @since   11.1
  193.      * @deprecated  4.0
  194.      */
  195.     public function initialise($options array())
  196.     {
  197.         // Set the language in the class.
  198.         $config JFactory::getConfig();
  199.  
  200.         // Check that we were given a language in the array (since by default may be blank).
  201.         if (isset($options['language']))
  202.         {
  203.             $config->set('language'$options['language']);
  204.         }
  205.  
  206.         // Set user specific editor.
  207.         $user JFactory::getUser();
  208.         $editor $user->getParam('editor'$this->getCfg('editor'));
  209.  
  210.         if (!JPluginHelper::isEnabled('editors'$editor))
  211.         {
  212.             $editor $this->getCfg('editor');
  213.  
  214.             if (!JPluginHelper::isEnabled('editors'$editor))
  215.             {
  216.                 $editor 'none';
  217.             }
  218.         }
  219.  
  220.         $config->set('editor'$editor);
  221.  
  222.         // Set the encryption to use. The availability of strong encryption must always be checked separately.
  223.         // Use JCrypt::hasStrongPasswordSupport() to check PHP for this support.
  224.         if (JPluginHelper::isEnabled('user''joomla'))
  225.         {
  226.             $userPlugin JPluginHelper::getPlugin('user''joomla');
  227.             $userPluginParams new JRegistry;
  228.             $userPluginParams->loadString($userPlugin->params);
  229.             $useStrongEncryption $userPluginParams->get('strong_passwords'0);
  230.  
  231.             $config->set('useStrongEncryption'$useStrongEncryption);
  232.         }
  233.  
  234.         // Trigger the onAfterInitialise event.
  235.         JPluginHelper::importPlugin('system');
  236.         $this->triggerEvent('onAfterInitialise');
  237.     }
  238.  
  239.     /**
  240.      * Route the application.
  241.      *
  242.      * Routing is the process of examining the request environment to determine which
  243.      * component should receive the request. The component optional parameters
  244.      * are then set in the request object to be processed when the application is being
  245.      * dispatched.
  246.      *
  247.      * @return  void 
  248.      *
  249.      * @since   11.1
  250.      * @deprecated  4.0
  251.      */
  252.     public function route()
  253.     {
  254.         // Get the full request URI.
  255.         $uri clone JUri::getInstance();
  256.  
  257.         $router $this->getRouter();
  258.         $result $router->parse($uri);
  259.  
  260.         foreach ($result as $key => $value)
  261.         {
  262.             $this->input->def($key$value);
  263.         }
  264.  
  265.         // Trigger the onAfterRoute event.
  266.         JPluginHelper::importPlugin('system');
  267.         $this->triggerEvent('onAfterRoute');
  268.     }
  269.  
  270.     /**
  271.      * Dispatch the application.
  272.      *
  273.      * Dispatching is the process of pulling the option from the request object and
  274.      * mapping them to a component. If the component does not exist, it handles
  275.      * determining a default component to dispatch.
  276.      *
  277.      * @param   string  $component  The component to dispatch.
  278.      *
  279.      * @return  void 
  280.      *
  281.      * @since   11.1
  282.      * @deprecated  4.0
  283.      */
  284.     public function dispatch($component null)
  285.     {
  286.         $document JFactory::getDocument();
  287.  
  288.         $contents JComponentHelper::renderComponent($component);
  289.         $document->setBuffer($contents'component');
  290.  
  291.         // Trigger the onAfterDispatch event.
  292.         JPluginHelper::importPlugin('system');
  293.         $this->triggerEvent('onAfterDispatch');
  294.     }
  295.  
  296.     /**
  297.      * Render the application.
  298.      *
  299.      * Rendering is the process of pushing the document buffers into the template
  300.      * placeholders, retrieving data from the document and pushing it into
  301.      * the JResponse buffer.
  302.      *
  303.      * @return  void 
  304.      *
  305.      * @since   11.1
  306.      * @deprecated  4.0
  307.      */
  308.     public function render()
  309.     {
  310.         $template $this->getTemplate(true);
  311.  
  312.         $params array('template' => $template->template'file' => 'index.php''directory' => JPATH_THEMES'params' => $template->params);
  313.  
  314.         // Parse the document.
  315.         $document JFactory::getDocument();
  316.         $document->parse($params);
  317.  
  318.         // Trigger the onBeforeRender event.
  319.         JPluginHelper::importPlugin('system');
  320.         $this->triggerEvent('onBeforeRender');
  321.  
  322.         // Render the document.
  323.         $caching ($this->getCfg('caching'>= 2true false;
  324.         JResponse::setBody($document->render($caching$params));
  325.  
  326.         // Trigger the onAfterRender event.
  327.         $this->triggerEvent('onAfterRender');
  328.     }
  329.  
  330.     /**
  331.      * Redirect to another URL.
  332.      *
  333.      * Optionally enqueues a message in the system message queue (which will be displayed
  334.      * the next time a page is loaded) using the enqueueMessage method. If the headers have
  335.      * not been sent the redirect will be accomplished using a "301 Moved Permanently"
  336.      * code in the header pointing to the new location. If the headers have already been
  337.      * sent this will be accomplished using a JavaScript statement.
  338.      *
  339.      * @param   string   $url      The URL to redirect to. Can only be http/https URL
  340.      * @param   string   $msg      An optional message to display on redirect.
  341.      * @param   string   $msgType  An optional message type. Defaults to message.
  342.      * @param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
  343.      *
  344.      * @return  void  Calls exit().
  345.      *
  346.      * @since   11.1
  347.      * @deprecated  4.0
  348.      *
  349.      * @see     JApplication::enqueueMessage()
  350.      */
  351.     public function redirect($url$msg ''$msgType 'message'$moved false)
  352.     {
  353.         // Check for relative internal links.
  354.         if (preg_match('#^index2?\.php#'$url))
  355.         {
  356.             $url JUri::base($url;
  357.         }
  358.  
  359.         // Strip out any line breaks.
  360.         $url preg_split("/[\r\n]/"$url);
  361.         $url $url[0];
  362.  
  363.         /*
  364.          * If we don't start with a http we need to fix this before we proceed.
  365.          * We could validly start with something else (e.g. ftp), though this would
  366.          * be unlikely and isn't supported by this API.
  367.          */
  368.         if (!preg_match('#^http#i'$url))
  369.         {
  370.             $uri JUri::getInstance();
  371.             $prefix $uri->toString(array('scheme''user''pass''host''port'));
  372.  
  373.             if ($url[0== '/')
  374.             {
  375.                 // We just need the prefix since we have a path relative to the root.
  376.                 $url $prefix $url;
  377.             }
  378.             else
  379.             {
  380.                 // It's relative to where we are now, so lets add that.
  381.                 $parts explode('/'$uri->toString(array('path')));
  382.                 array_pop($parts);
  383.                 $path implode('/'$parts'/';
  384.                 $url $prefix $path $url;
  385.             }
  386.         }
  387.  
  388.         // If the message exists, enqueue it.
  389.         if (trim($msg))
  390.         {
  391.             $this->enqueueMessage($msg$msgType);
  392.         }
  393.  
  394.         // Persist messages if they exist.
  395.         if (count($this->_messageQueue))
  396.         {
  397.             $session JFactory::getSession();
  398.             $session->set('application.queue'$this->_messageQueue);
  399.         }
  400.  
  401.         // If the headers have been sent, then we cannot send an additional location header
  402.         // so we will output a javascript redirect statement.
  403.         if (headers_sent())
  404.         {
  405.             echo "<script>document.location.href='" str_replace("'""&apos;"$url"';</script>\n";
  406.         }
  407.         else
  408.         {
  409.             $document JFactory::getDocument();
  410.  
  411.             jimport('phputf8.utils.ascii');
  412.  
  413.             if (($this->client->engine == JApplicationWebClient::TRIDENT&& !utf8_is_ascii($url))
  414.             {
  415.                 // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
  416.                 echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' $document->getCharset('" />'
  417.                     . '<script>document.location.href=\'' str_replace("'""&apos;"$url'\';</script></head></html>';
  418.             }
  419.             else
  420.             {
  421.                 // All other browsers, use the more efficient HTTP header method
  422.                 header($moved 'HTTP/1.1 301 Moved Permanently' 'HTTP/1.1 303 See other');
  423.                 header('Location: ' $url);
  424.                 header('Content-Type: text/html; charset=' $document->getCharset());
  425.             }
  426.         }
  427.  
  428.         $this->close();
  429.     }
  430.  
  431.     /**
  432.      * Enqueue a system message.
  433.      *
  434.      * @param   string  $msg   The message to enqueue.
  435.      * @param   string  $type  The message type. Default is message.
  436.      *
  437.      * @return  void 
  438.      *
  439.      * @since   11.1
  440.      * @deprecated  4.0
  441.      */
  442.     public function enqueueMessage($msg$type 'message')
  443.     {
  444.         // For empty queue, if messages exists in the session, enqueue them first.
  445.         if (!count($this->_messageQueue))
  446.         {
  447.             $session JFactory::getSession();
  448.             $sessionQueue $session->get('application.queue');
  449.  
  450.             if (count($sessionQueue))
  451.             {
  452.                 $this->_messageQueue = $sessionQueue;
  453.                 $session->set('application.queue'null);
  454.             }
  455.         }
  456.  
  457.         // Enqueue the message.
  458.         $this->_messageQueue[array('message' => $msg'type' => strtolower($type));
  459.     }
  460.  
  461.     /**
  462.      * Get the system message queue.
  463.      *
  464.      * @return  array  The system message queue.
  465.      *
  466.      * @since   11.1
  467.      * @deprecated  4.0
  468.      */
  469.     public function getMessageQueue()
  470.     {
  471.         // For empty queue, if messages exists in the session, enqueue them.
  472.         if (!count($this->_messageQueue))
  473.         {
  474.             $session JFactory::getSession();
  475.             $sessionQueue $session->get('application.queue');
  476.  
  477.             if (count($sessionQueue))
  478.             {
  479.                 $this->_messageQueue = $sessionQueue;
  480.                 $session->set('application.queue'null);
  481.             }
  482.         }
  483.  
  484.         return $this->_messageQueue;
  485.     }
  486.  
  487.     /**
  488.      * Gets a configuration value.
  489.      *
  490.      * An example is in application/japplication-getcfg.php Getting a configuration
  491.      *
  492.      * @param   string  $varname  The name of the value to get.
  493.      * @param   string  $default  Default value to return
  494.      *
  495.      * @return  mixed  The user state.
  496.      *
  497.      * @since   11.1
  498.      * @deprecated  4.0
  499.      */
  500.     public function getCfg($varname$default null)
  501.     {
  502.         $config JFactory::getConfig();
  503.  
  504.         return $config->get('' $varname$default);
  505.     }
  506.  
  507.     /**
  508.      * Method to get the application name.
  509.      *
  510.      * The dispatcher name is by default parsed using the classname, or it can be set
  511.      * by passing a $config['name'] in the class constructor.
  512.      *
  513.      * @return  string  The name of the dispatcher.
  514.      *
  515.      * @since   11.1
  516.      * @deprecated  4.0
  517.      */
  518.     public function getName()
  519.     {
  520.         $name $this->_name;
  521.  
  522.         if (empty($name))
  523.         {
  524.             $r null;
  525.  
  526.             if (!preg_match('/J(.*)/i'get_class($this)$r))
  527.             {
  528.                 JLog::add(JText::_('JLIB_APPLICATION_ERROR_APPLICATION_GET_NAME')JLog::WARNING'jerror');
  529.             }
  530.  
  531.             $name strtolower($r[1]);
  532.         }
  533.  
  534.         return $name;
  535.     }
  536.  
  537.     /**
  538.      * Gets a user state.
  539.      *
  540.      * @param   string  $key      The path of the state.
  541.      * @param   mixed   $default  Optional default value, returned if the internal value is null.
  542.      *
  543.      * @return  mixed  The user state or null.
  544.      *
  545.      * @since   11.1
  546.      * @deprecated  4.0
  547.      */
  548.     public function getUserState($key$default null)
  549.     {
  550.         $session JFactory::getSession();
  551.         $registry $session->get('registry');
  552.  
  553.         if (!is_null($registry))
  554.         {
  555.             return $registry->get($key$default);
  556.         }
  557.  
  558.         return $default;
  559.     }
  560.  
  561.     /**
  562.      * Sets the value of a user state variable.
  563.      *
  564.      * @param   string  $key    The path of the state.
  565.      * @param   string  $value  The value of the variable.
  566.      *
  567.      * @return  mixed  The previous state, if one existed.
  568.      *
  569.      * @since   11.1
  570.      * @deprecated  4.0
  571.      */
  572.     public function setUserState($key$value)
  573.     {
  574.         $session JFactory::getSession();
  575.         $registry $session->get('registry');
  576.  
  577.         if (!is_null($registry))
  578.         {
  579.             return $registry->set($key$value);
  580.         }
  581.  
  582.         return null;
  583.     }
  584.  
  585.     /**
  586.      * Gets the value of a user state variable.
  587.      *
  588.      * @param   string  $key      The key of the user state variable.
  589.      * @param   string  $request  The name of the variable passed in a request.
  590.      * @param   string  $default  The default value for the variable if not found. Optional.
  591.      * @param   string  $type     Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
  592.      *
  593.      * @return  The request user state.
  594.      *
  595.      * @since   11.1
  596.      * @deprecated  4.0
  597.      */
  598.     public function getUserStateFromRequest($key$request$default null$type 'none')
  599.     {
  600.         $cur_state $this->getUserState($key$default);
  601.         $new_state $this->input->get($requestnull$type);
  602.  
  603.         // Save the new value only if it was set in this request.
  604.         if ($new_state !== null)
  605.         {
  606.             $this->setUserState($key$new_state);
  607.         }
  608.         else
  609.         {
  610.             $new_state $cur_state;
  611.         }
  612.  
  613.         return $new_state;
  614.     }
  615.  
  616.     /**
  617.      * Login authentication function.
  618.      *
  619.      * Username and encoded password are passed the onUserLogin event which
  620.      * is responsible for the user validation. A successful validation updates
  621.      * the current session record with the user's details.
  622.      *
  623.      * Username and encoded password are sent as credentials (along with other
  624.      * possibilities) to each observer (authentication plugin) for user
  625.      * validation.  Successful validation will update the current session with
  626.      * the user details.
  627.      *
  628.      * @param   array  $credentials  Array('username' => string, 'password' => string)
  629.      * @param   array  $options      Array('remember' => boolean)
  630.      *
  631.      * @return  boolean  True on success.
  632.      *
  633.      * @since   11.1
  634.      * @deprecated  4.0
  635.      */
  636.     public function login($credentials$options array())
  637.     {
  638.         // Get the global JAuthentication object.
  639.         jimport('joomla.user.authentication');
  640.  
  641.         $authenticate JAuthentication::getInstance();
  642.         $response $authenticate->authenticate($credentials$options);
  643.  
  644.         if ($response->status === JAuthentication::STATUS_SUCCESS)
  645.         {
  646.             // Validate that the user should be able to login (different to being authenticated).
  647.             // This permits authentication plugins blocking the user
  648.             $authorisations $authenticate->authorise($response$options);
  649.  
  650.             foreach ($authorisations as $authorisation)
  651.             {
  652.                 $denied_states array(JAuthentication::STATUS_EXPIREDJAuthentication::STATUS_DENIED);
  653.  
  654.                 if (in_array($authorisation->status$denied_states))
  655.                 {
  656.                     // Trigger onUserAuthorisationFailure Event.
  657.                     $this->triggerEvent('onUserAuthorisationFailure'array((array) $authorisation));
  658.  
  659.                     // If silent is set, just return false.
  660.                     if (isset($options['silent']&& $options['silent'])
  661.                     {
  662.                         return false;
  663.                     }
  664.  
  665.                     // Return the error.
  666.                     switch ($authorisation->status)
  667.                     {
  668.                         case JAuthentication::STATUS_EXPIRED:
  669.                             return JError::raiseWarning('102002'JText::_('JLIB_LOGIN_EXPIRED'));
  670.                             break;
  671.  
  672.                         case JAuthentication::STATUS_DENIED:
  673.                             return JError::raiseWarning('102003'JText::_('JLIB_LOGIN_DENIED'));
  674.                             break;
  675.  
  676.                         default:
  677.                             return JError::raiseWarning('102004'JText::_('JLIB_LOGIN_AUTHORISATION'));
  678.                             break;
  679.                     }
  680.                 }
  681.             }
  682.  
  683.             // Import the user plugin group.
  684.             JPluginHelper::importPlugin('user');
  685.  
  686.             // OK, the credentials are authenticated and user is authorised.  Let's fire the onLogin event.
  687.             $results $this->triggerEvent('onUserLogin'array((array) $response$options));
  688.  
  689.             /*
  690.              * If any of the user plugins did not successfully complete the login routine
  691.              * then the whole method fails.
  692.              *
  693.              * Any errors raised should be done in the plugin as this provides the ability
  694.              * to provide much more information about why the routine may have failed.
  695.              */
  696.             $user JFactory::getUser();
  697.  
  698.             if ($response->type == 'Cookie')
  699.             {
  700.                 $user->set('cookieLogin'true);
  701.             }
  702.  
  703.             if (in_array(false$resultstrue== false)
  704.             {
  705.                 $options['user'$user;
  706.                 $options['responseType'$response->type;
  707.  
  708.                 if (isset($response->length&& isset($response->secure&& isset($response->lifetime))
  709.                 {
  710.                     $options['length'$response->length;
  711.                     $options['secure'$response->secure;
  712.                     $options['lifetime'$response->lifetime;
  713.                 }
  714.  
  715.                 // The user is successfully logged in. Run the after login events
  716.                 $this->triggerEvent('onUserAfterLogin'array($options));
  717.             }
  718.  
  719.             return true;
  720.         }
  721.  
  722.         // Trigger onUserLoginFailure Event.
  723.         $this->triggerEvent('onUserLoginFailure'array((array) $response));
  724.  
  725.         // If silent is set, just return false.
  726.         if (isset($options['silent']&& $options['silent'])
  727.         {
  728.             return false;
  729.         }
  730.  
  731.         // If status is success, any error will have been raised by the user plugin
  732.         if ($response->status !== JAuthentication::STATUS_SUCCESS)
  733.         {
  734.             JLog::add($response->error_messageJLog::WARNING'jerror');
  735.         }
  736.  
  737.         return false;
  738.     }
  739.  
  740.     /**
  741.      * Logout authentication function.
  742.      *
  743.      * Passed the current user information to the onUserLogout event and reverts the current
  744.      * session record back to 'anonymous' parameters.
  745.      * If any of the authentication plugins did not successfully complete
  746.      * the logout routine then the whole method fails. Any errors raised
  747.      * should be done in the plugin as this provides the ability to give
  748.      * much more information about why the routine may have failed.
  749.      *
  750.      * @param   integer  $userid   The user to load - Can be an integer or string - If string, it is converted to ID automatically
  751.      * @param   array    $options  Array('clientid' => array of client id's)
  752.      *
  753.      * @return  boolean  True on success
  754.      *
  755.      * @since   11.1
  756.      * @deprecated  4.0
  757.      */
  758.     public function logout($userid null$options array())
  759.     {
  760.         // Get a user object from the JApplication.
  761.         $user JFactory::getUser($userid);
  762.  
  763.         // Build the credentials array.
  764.         $parameters['username'$user->get('username');
  765.         $parameters['id'$user->get('id');
  766.  
  767.         // Set clientid in the options array if it hasn't been set already.
  768.         if (!isset($options['clientid']))
  769.         {
  770.             $options['clientid'$this->getClientId();
  771.         }
  772.  
  773.         // Import the user plugin group.
  774.         JPluginHelper::importPlugin('user');
  775.  
  776.         // OK, the credentials are built. Lets fire the onLogout event.
  777.         $results $this->triggerEvent('onUserLogout'array($parameters$options));
  778.  
  779.         if (!in_array(false$resultstrue))
  780.         {
  781.                 $options['username'$user->get('username');
  782.                 $results $this->triggerEvent('onUserAfterLogout'array($options));
  783.  
  784.             return true;
  785.         }
  786.  
  787.         // Trigger onUserLoginFailure Event.
  788.         $this->triggerEvent('onUserLogoutFailure'array($parameters));
  789.  
  790.         return false;
  791.     }
  792.  
  793.     /**
  794.      * Gets the name of the current template.
  795.      *
  796.      * @param   boolean  $params  An optional associative array of configuration settings
  797.      *
  798.      * @return  mixed  System is the fallback.
  799.      *
  800.      * @since   11.1
  801.      * @deprecated  4.0
  802.      */
  803.     public function getTemplate($params false)
  804.     {
  805.         $template new stdClass;
  806.  
  807.         $template->template 'system';
  808.         $template->params   new JRegistry;
  809.  
  810.         if ($params)
  811.         {
  812.             return $template;
  813.         }
  814.  
  815.         return $template->template;
  816.     }
  817.  
  818.     /**
  819.      * Returns the application JRouter object.
  820.      *
  821.      * @param   string  $name     The name of the application.
  822.      * @param   array   $options  An optional associative array of configuration settings.
  823.      *
  824.      * @return  JRouter  A JRouter object
  825.      *
  826.      * @since   11.1
  827.      * @deprecated  4.0
  828.      */
  829.     static public function getRouter($name nullarray $options array())
  830.     {
  831.         if (!isset($name))
  832.         {
  833.             $app JFactory::getApplication();
  834.             $name $app->getName();
  835.         }
  836.  
  837.         try
  838.         {
  839.             $router JRouter::getInstance($name$options);
  840.         }
  841.         catch (Exception $e)
  842.         {
  843.             return null;
  844.         }
  845.  
  846.         return $router;
  847.     }
  848.  
  849.     /**
  850.      * This method transliterates a string into an URL
  851.      * safe string or returns a URL safe UTF-8 string
  852.      * based on the global configuration
  853.      *
  854.      * @param   string  $string  String to process
  855.      *
  856.      * @return  string  Processed string
  857.      *
  858.      * @since   11.1
  859.      * @deprecated  4.0  Use JApplicationHelper::stringURLSafe instead
  860.      */
  861.     static public function stringURLSafe($string)
  862.     {
  863.         return JApplicationHelper::stringURLSafe($string);
  864.     }
  865.  
  866.     /**
  867.      * Returns the application JPathway object.
  868.      *
  869.      * @param   string  $name     The name of the application.
  870.      * @param   array   $options  An optional associative array of configuration settings.
  871.      *
  872.      * @return  JPathway  A JPathway object
  873.      *
  874.      * @since   11.1
  875.      * @deprecated  4.0
  876.      */
  877.     public function getPathway($name null$options array())
  878.     {
  879.         if (!isset($name))
  880.         {
  881.             $name $this->_name;
  882.         }
  883.  
  884.         try
  885.         {
  886.             $pathway JPathway::getInstance($name$options);
  887.         }
  888.         catch (Exception $e)
  889.         {
  890.             return null;
  891.         }
  892.  
  893.         return $pathway;
  894.     }
  895.  
  896.     /**
  897.      * Returns the application JPathway object.
  898.      *
  899.      * @param   string  $name     The name of the application/client.
  900.      * @param   array   $options  An optional associative array of configuration settings.
  901.      *
  902.      * @return  JMenu  JMenu object.
  903.      *
  904.      * @since   11.1
  905.      * @deprecated  4.0
  906.      */
  907.     public function getMenu($name null$options array())
  908.     {
  909.         if (!isset($name))
  910.         {
  911.             $name $this->_name;
  912.         }
  913.  
  914.         try
  915.         {
  916.             $menu JMenu::getInstance($name$options);
  917.         }
  918.         catch (Exception $e)
  919.         {
  920.             return null;
  921.         }
  922.  
  923.         return $menu;
  924.     }
  925.  
  926.     /**
  927.      * Provides a secure hash based on a seed
  928.      *
  929.      * @param   string  $seed  Seed string.
  930.      *
  931.      * @return  string  A secure hash
  932.      *
  933.      * @since   11.1
  934.      * @deprecated  4.0  Use JApplicationHelper::getHash instead
  935.      */
  936.     public static function getHash($seed)
  937.     {
  938.         return JApplicationHelper::getHash($seed);
  939.     }
  940.  
  941.     /**
  942.      * Create the configuration registry.
  943.      *
  944.      * @param   string  $file  The path to the configuration file
  945.      *
  946.      * @return  JConfig  A JConfig object
  947.      *
  948.      * @since   11.1
  949.      * @deprecated  4.0
  950.      */
  951.     protected function _createConfiguration($file)
  952.     {
  953.         JLoader::register('JConfig'$file);
  954.  
  955.         // Create the JConfig object.
  956.         $config new JConfig;
  957.  
  958.         // Get the global configuration object.
  959.         $registry JFactory::getConfig();
  960.  
  961.         // Load the configuration values into the registry.
  962.         $registry->loadObject($config);
  963.  
  964.         return $config;
  965.     }
  966.  
  967.     /**
  968.      * Create the user session.
  969.      *
  970.      * Old sessions are flushed based on the configuration value for the cookie
  971.      * lifetime. If an existing session, then the last access time is updated.
  972.      * If a new session, a session id is generated and a record is created in
  973.      * the #__sessions table.
  974.      *
  975.      * @param   string  $name  The sessions name.
  976.      *
  977.      * @return  JSession  JSession on success. May call exit() on database error.
  978.      *
  979.      * @since   11.1
  980.      * @deprecated  4.0
  981.      */
  982.     protected function _createSession($name)
  983.     {
  984.         $options array();
  985.         $options['name'$name;
  986.  
  987.         switch ($this->_clientId)
  988.         {
  989.             case 0:
  990.                 if ($this->getCfg('force_ssl'== 2)
  991.                 {
  992.                     $options['force_ssl'true;
  993.                 }
  994.                 break;
  995.  
  996.             case 1:
  997.                 if ($this->getCfg('force_ssl'>= 1)
  998.                 {
  999.                     $options['force_ssl'true;
  1000.                 }
  1001.                 break;
  1002.         }
  1003.  
  1004.         $this->registerEvent('onAfterSessionStart'array($this'afterSessionStart'));
  1005.  
  1006.         $session JFactory::getSession($options);
  1007.         $session->initialise($this->input$this->dispatcher);
  1008.         $session->start();
  1009.  
  1010.         // TODO: At some point we need to get away from having session data always in the db.
  1011.  
  1012.         $db JFactory::getDbo();
  1013.  
  1014.         // Remove expired sessions from the database.
  1015.         $time time();
  1016.  
  1017.         if ($time 2)
  1018.         {
  1019.             // The modulus introduces a little entropy, making the flushing less accurate
  1020.             // but fires the query less than half the time.
  1021.             $query $db->getQuery(true)
  1022.                 ->delete($db->quoteName('#__session'))
  1023.                 ->where($db->quoteName('time'' < ' $db->quote((int) ($time $session->getExpire())));
  1024.  
  1025.             $db->setQuery($query);
  1026.             $db->execute();
  1027.         }
  1028.  
  1029.         // Check to see the the session already exists.
  1030.         $handler $this->getCfg('session_handler');
  1031.  
  1032.         if (($handler != 'database' && ($time || $session->isNew()))
  1033.             || ($handler == 'database' && $session->isNew()))
  1034.         {
  1035.             $this->checkSession();
  1036.         }
  1037.  
  1038.         return $session;
  1039.     }
  1040.  
  1041.     /**
  1042.      * Checks the user session.
  1043.      *
  1044.      * If the session record doesn't exist, initialise it.
  1045.      * If session is new, create session variables
  1046.      *
  1047.      * @return  void 
  1048.      *
  1049.      * @since   11.1
  1050.      * @deprecated  4.0
  1051.      */
  1052.     public function checkSession()
  1053.     {
  1054.         $db JFactory::getDbo();
  1055.         $session JFactory::getSession();
  1056.         $user JFactory::getUser();
  1057.  
  1058.         $query $db->getQuery(true)
  1059.             ->select($db->quoteName('session_id'))
  1060.             ->from($db->quoteName('#__session'))
  1061.             ->where($db->quoteName('session_id'' = ' $db->quote($session->getId()));
  1062.  
  1063.         $db->setQuery($query01);
  1064.         $exists $db->loadResult();
  1065.  
  1066.         // If the session record doesn't exist initialise it.
  1067.         if (!$exists)
  1068.         {
  1069.             $query->clear();
  1070.  
  1071.             if ($session->isNew())
  1072.             {
  1073.                 $query->insert($db->quoteName('#__session'))
  1074.                     ->columns($db->quoteName('session_id'', ' $db->quoteName('client_id'', ' $db->quoteName('time'))
  1075.                     ->values($db->quote($session->getId()) ', ' . (int) $this->getClientId(', ' $db->quote((int) time()));
  1076.                 $db->setQuery($query);
  1077.             }
  1078.             else
  1079.             {
  1080.                 $query->insert($db->quoteName('#__session'))
  1081.                     ->columns(
  1082.                         $db->quoteName('session_id'', ' $db->quoteName('client_id'', ' $db->quoteName('guest'', ' .
  1083.                         $db->quoteName('time'', ' $db->quoteName('userid'', ' $db->quoteName('username')
  1084.                     )
  1085.                     ->values(
  1086.                         $db->quote($session->getId()) ', ' . (int) $this->getClientId(', ' . (int) $user->get('guest'', ' .
  1087.                         $db->quote((int) $session->get('session.timer.start')) ', ' . (int) $user->get('id'', ' $db->quote($user->get('username'))
  1088.                     );
  1089.  
  1090.                 $db->setQuery($query);
  1091.             }
  1092.  
  1093.             // If the insert failed, exit the application.
  1094.             try
  1095.             {
  1096.                 $db->execute();
  1097.             }
  1098.             catch (RuntimeException $e)
  1099.             {
  1100.                 jexit($e->getMessage());
  1101.             }
  1102.         }
  1103.     }
  1104.  
  1105.     /**
  1106.      * After the session has been started we need to populate it with some default values.
  1107.      *
  1108.      * @return  void 
  1109.      *
  1110.      * @since   12.2
  1111.      * @deprecated  4.0
  1112.      */
  1113.     public function afterSessionStart()
  1114.     {
  1115.         $session JFactory::getSession();
  1116.  
  1117.         if ($session->isNew())
  1118.         {
  1119.             $session->set('registry'new JRegistry('session'));
  1120.             $session->set('user'new JUser);
  1121.         }
  1122.     }
  1123.  
  1124.     /**
  1125.      * Gets the client id of the current running application.
  1126.      *
  1127.      * @return  integer  A client identifier.
  1128.      *
  1129.      * @since   11.1
  1130.      * @deprecated  4.0
  1131.      */
  1132.     public function getClientId()
  1133.     {
  1134.         return $this->_clientId;
  1135.     }
  1136.  
  1137.     /**
  1138.      * Is admin interface?
  1139.      *
  1140.      * @return  boolean  True if this application is administrator.
  1141.      *
  1142.      * @since   11.1
  1143.      * @deprecated  4.0
  1144.      */
  1145.     public function isAdmin()
  1146.     {
  1147.         return ($this->_clientId == 1);
  1148.     }
  1149.  
  1150.     /**
  1151.      * Is site interface?
  1152.      *
  1153.      * @return  boolean  True if this application is site.
  1154.      *
  1155.      * @since   11.1
  1156.      * @deprecated  4.0
  1157.      */
  1158.     public function isSite()
  1159.     {
  1160.         return ($this->_clientId == 0);
  1161.     }
  1162.  
  1163.     /**
  1164.      * Method to determine if the host OS is  Windows
  1165.      *
  1166.      * @return  boolean  True if Windows OS
  1167.      *
  1168.      * @since   11.1
  1169.      * @deprecated  13.3 (Platform) & 4.0 (CMS) Use the IS_WIN constant instead.
  1170.      */
  1171.     public static function isWinOS()
  1172.     {
  1173.         JLog::add('JApplication::isWinOS() is deprecated. Use the IS_WIN constant instead.'JLog::WARNING'deprecated');
  1174.  
  1175.         return IS_WIN;
  1176.     }
  1177.  
  1178.     /**
  1179.      * Determine if we are using a secure (SSL) connection.
  1180.      *
  1181.      * @return  boolean  True if using SSL, false if not.
  1182.      *
  1183.      * @since   12.2
  1184.      * @deprecated  4.0
  1185.      */
  1186.     public function isSSLConnection()
  1187.     {
  1188.         return ((isset($_SERVER['HTTPS']&& ($_SERVER['HTTPS'== 'on')) || getenv('SSL_PROTOCOL_VERSION'));
  1189.     }
  1190.  
  1191.     /**
  1192.      * Returns the response as a string.
  1193.      *
  1194.      * @return  string  The response
  1195.      *
  1196.      * @since   11.1
  1197.      * @deprecated  4.0
  1198.      */
  1199.     public function __toString()
  1200.     {
  1201.         $compress $this->getCfg('gzip'false);
  1202.  
  1203.         return JResponse::toString($compress);
  1204.     }
  1205. }

Documentation generated on Tue, 19 Nov 2013 14:53:46 +0100 by phpDocumentor 1.4.3