PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/application.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 377 lines | 203 code | 49 blank | 125 comment | 23 complexity | 11021dd8821ceb19f3bac1511df9d48a MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: application.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  6. * @license GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // no direct access
  14. defined( '_JEXEC' ) or die( 'Restricted access' );
  15. jimport('joomla.application.component.helper');
  16. /**
  17. * Joomla! Application class
  18. *
  19. * Provide many supporting API functions
  20. *
  21. * @package Joomla
  22. * @final
  23. */
  24. class JSite extends JApplication
  25. {
  26. /**
  27. * Class constructor
  28. *
  29. * @access protected
  30. * @param array An optional associative array of configuration settings.
  31. * Recognized key values include 'clientId' (this list is not meant to be comprehensive).
  32. */
  33. function __construct($config = array())
  34. {
  35. $config['clientId'] = 0;
  36. parent::__construct($config);
  37. }
  38. /**
  39. * Initialise the application.
  40. *
  41. * @access public
  42. */
  43. function initialise( $options = array())
  44. {
  45. // if a language was specified it has priority
  46. // otherwise use user or default language settings
  47. if (empty($options['language']))
  48. {
  49. $user = & JFactory::getUser();
  50. $lang = $user->getParam( 'language' );
  51. // Make sure that the user's language exists
  52. if ( $lang && JLanguage::exists($lang) ) {
  53. $options['language'] = $lang;
  54. } else {
  55. $params = JComponentHelper::getParams('com_languages');
  56. $client =& JApplicationHelper::getClientInfo($this->getClientId());
  57. $options['language'] = $params->get($client->name, 'en-GB');
  58. }
  59. }
  60. // One last check to make sure we have something
  61. if ( ! JLanguage::exists($options['language']) ) {
  62. $options['language'] = 'en-GB';
  63. }
  64. parent::initialise($options);
  65. }
  66. /**
  67. * Route the application
  68. *
  69. * @access public
  70. */
  71. function route() {
  72. parent::route();
  73. }
  74. /**
  75. * Dispatch the application
  76. *
  77. * @access public
  78. */
  79. function dispatch($component)
  80. {
  81. $document =& JFactory::getDocument();
  82. $user =& JFactory::getUser();
  83. $router =& $this->getRouter();
  84. $params =& $this->getParams();
  85. switch($document->getType())
  86. {
  87. case 'html':
  88. {
  89. //set metadata
  90. $document->setMetaData( 'keywords', $this->getCfg('MetaKeys') );
  91. if ( $user->get('id') ) {
  92. $document->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
  93. }
  94. if($router->getMode() == JROUTER_MODE_SEF) {
  95. $document->setBase(JURI::current());
  96. }
  97. } break;
  98. case 'feed':
  99. {
  100. $document->setBase(JURI::current());
  101. } break;
  102. default: break;
  103. }
  104. $document->setTitle( $params->get('page_title') );
  105. $document->setDescription( $params->get('page_description') );
  106. $contents = JComponentHelper::renderComponent($component);
  107. $document->setBuffer( $contents, 'component');
  108. }
  109. /**
  110. * Display the application.
  111. *
  112. * @access public
  113. */
  114. function render()
  115. {
  116. $document =& JFactory::getDocument();
  117. $user =& JFactory::getUser();
  118. // get the format to render
  119. $format = $document->getType();
  120. switch($format)
  121. {
  122. case 'feed' :
  123. {
  124. $params = array();
  125. } break;
  126. case 'html' :
  127. default :
  128. {
  129. $template = $this->getTemplate();
  130. $file = JRequest::getCmd('tmpl', 'index');
  131. if ($this->getCfg('offline') && $user->get('gid') < '23' ) {
  132. $file = 'offline';
  133. }
  134. if (!is_dir( JPATH_THEMES.DS.$template ) && !$this->getCfg('offline')) {
  135. $file = 'component';
  136. }
  137. $params = array(
  138. 'template' => $template,
  139. 'file' => $file.'.php',
  140. 'directory' => JPATH_THEMES
  141. );
  142. } break;
  143. }
  144. $data = $document->render( $this->getCfg('caching'), $params);
  145. JResponse::setBody($data);
  146. }
  147. /**
  148. * Login authentication function
  149. *
  150. * @param array Array( 'username' => string, 'password' => string )
  151. * @param array Array( 'remember' => boolean )
  152. * @access public
  153. * @see JApplication::login
  154. */
  155. function login($credentials, $options = array())
  156. {
  157. //Set the application login entry point
  158. if(!array_key_exists('entry_url', $options)) {
  159. $options['entry_url'] = JURI::base().'index.php?option=com_user&task=login';
  160. }
  161. return parent::login($credentials, $options);
  162. }
  163. /**
  164. * Check if the user can access the application
  165. *
  166. * @access public
  167. */
  168. function authorize($itemid)
  169. {
  170. $menus =& JSite::getMenu();
  171. $user =& JFactory::getUser();
  172. $aid = $user->get('aid');
  173. if(!$menus->authorize($itemid, $aid))
  174. {
  175. if ( ! $aid )
  176. {
  177. // Redirect to login
  178. $uri = JFactory::getURI();
  179. $return = $uri->toString();
  180. $url = 'index.php?option=com_user&view=login';
  181. $url .= '&return='.base64_encode($return);;
  182. //$url = JRoute::_($url, false);
  183. $this->redirect($url, JText::_('You must login first') );
  184. }
  185. else
  186. {
  187. JError::raiseError( 403, JText::_('ALERTNOTAUTH') );
  188. }
  189. }
  190. }
  191. /**
  192. * Get the appliaction parameters
  193. *
  194. * @param string The component option
  195. * @return object The parameters object
  196. * @since 1.5
  197. */
  198. function &getParams($option = null)
  199. {
  200. static $params = array();
  201. $hash = '__default';
  202. if(!empty($option)) $hash = $option;
  203. if (!isset($params[$hash]))
  204. {
  205. // Get component parameters
  206. if (!$option) {
  207. $option = JRequest::getCmd('option');
  208. }
  209. $params[$hash] =& JComponentHelper::getParams($option);
  210. // Get menu parameters
  211. $menus =& JSite::getMenu();
  212. $menu = $menus->getActive();
  213. $title = htmlspecialchars_decode($this->getCfg('sitename' ));
  214. $description = $this->getCfg('MetaDesc');
  215. // Lets cascade the parameters if we have menu item parameters
  216. if (is_object($menu))
  217. {
  218. $params[$hash]->merge(new JParameter($menu->params));
  219. $title = $menu->name;
  220. }
  221. $params[$hash]->def( 'page_title' , $title );
  222. $params[$hash]->def( 'page_description', $description );
  223. }
  224. return $params[$hash];
  225. }
  226. /**
  227. * Get the appliaction parameters
  228. *
  229. * @param string The component option
  230. * @return object The parameters object
  231. * @since 1.5
  232. */
  233. function &getPageParameters( $option = null )
  234. {
  235. return $this->getParams( $option );
  236. }
  237. /**
  238. * Get the template
  239. *
  240. * @return string The template name
  241. * @since 1.0
  242. */
  243. function getTemplate()
  244. {
  245. // Allows for overriding the active template from a component, and caches the result of this function
  246. // e.g. $mainframe->setTemplate('solar-flare-ii');
  247. if ($template = $this->get('setTemplate')) {
  248. return $template;
  249. }
  250. // Get the id of the active menu item
  251. $menu =& JSite::getMenu();
  252. $item = $menu->getActive();
  253. $id = 0;
  254. if(is_object($item)) { // valid item retrieved
  255. $id = $item->id;
  256. }
  257. // Load template entries for the active menuid and the default template
  258. $db =& JFactory::getDBO();
  259. $query = 'SELECT template'
  260. . ' FROM #__templates_menu'
  261. . ' WHERE client_id = 0 AND (menuid = 0 OR menuid = '.(int) $id.')'
  262. . ' ORDER BY menuid DESC'
  263. ;
  264. $db->setQuery($query, 0, 1);
  265. $template = $db->loadResult();
  266. // Allows for overriding the active template from the request
  267. $template = JRequest::getCmd('template', $template);
  268. $template = JFilterInput::clean($template, 'cmd'); // need to filter the default value as well
  269. // Fallback template
  270. if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
  271. $template = 'rhuk_milkyway';
  272. }
  273. // Cache the result
  274. $this->set('setTemplate', $template);
  275. return $template;
  276. }
  277. /**
  278. * Overrides the default template that would be used
  279. *
  280. * @param string The template name
  281. */
  282. function setTemplate( $template )
  283. {
  284. if (is_dir(JPATH_THEMES.DS.$template)) {
  285. $this->set('setTemplate', $template);
  286. }
  287. }
  288. /**
  289. * Return a reference to the JPathway object.
  290. *
  291. * @access public
  292. * @return object JPathway.
  293. * @since 1.5
  294. */
  295. function &getMenu()
  296. {
  297. $options = array();
  298. $menu =& parent::getMenu('site', $options);
  299. return $menu;
  300. }
  301. /**
  302. * Return a reference to the JPathway object.
  303. *
  304. * @access public
  305. * @return object JPathway.
  306. * @since 1.5
  307. */
  308. function &getPathWay()
  309. {
  310. $options = array();
  311. $pathway =& parent::getPathway('site', $options);
  312. return $pathway;
  313. }
  314. /**
  315. * Return a reference to the JRouter object.
  316. *
  317. * @access public
  318. * @return JRouter.
  319. * @since 1.5
  320. */
  321. function &getRouter()
  322. {
  323. $config =& JFactory::getConfig();
  324. $options['mode'] = $config->getValue('config.sef');
  325. $router =& parent::getRouter('site', $options);
  326. return $router;
  327. }
  328. }