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