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

/installation/includes/application.php

https://github.com/joebushi/joomla
PHP | 264 lines | 142 code | 38 blank | 84 comment | 13 complexity | 2f0facfb16fa488d825a8fe4e0fb04ba MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Installation
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('_JEXEC') or die;
  9. /**
  10. * Joomla Application class
  11. *
  12. * Provide many supporting API functions
  13. *
  14. * @package Joomla.Installation
  15. */
  16. class JInstallation extends JApplication
  17. {
  18. /**
  19. * The url of the site
  20. *
  21. * @var string
  22. */
  23. protected $_siteURL = null;
  24. /**
  25. * Class constructor
  26. *
  27. * @access protected
  28. * @param array An optional associative array of configuration settings.
  29. * Recognized key values include 'clientId' (this list is not meant to be comprehensive).
  30. */
  31. public function __construct(array $config = array())
  32. {
  33. $config['clientId'] = 2;
  34. parent::__construct($config);
  35. JError::setErrorHandling(E_ALL, 'Ignore');
  36. $this->_createConfiguration();
  37. // Set the root in the URI based on the application name.
  38. JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true)));
  39. }
  40. /**
  41. * Render the application
  42. *
  43. * @return void
  44. */
  45. public function render()
  46. {
  47. $document = &JFactory::getDocument();
  48. $config = &JFactory::getConfig();
  49. $user = &JFactory::getUser();
  50. switch($document->getType())
  51. {
  52. case 'html' :
  53. // Set metadata
  54. $document->setTitle(JText::_('PAGE_TITLE'));
  55. break;
  56. default :
  57. break;
  58. }
  59. // Define component path
  60. define('JPATH_COMPONENT', JPATH_BASE);
  61. define('JPATH_COMPONENT_SITE', JPATH_SITE);
  62. define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR);
  63. // Start the output buffer.
  64. ob_start();
  65. // Import the controller.
  66. require_once JPATH_COMPONENT.'/controller.php';
  67. // Execute the task.
  68. $controller = &JInstallationController::getInstance();
  69. $controller->execute(JRequest::getVar('task'));
  70. $controller->redirect();
  71. // Get output from the buffer and clean it.
  72. $contents = ob_get_contents();
  73. ob_end_clean();
  74. $params = array(
  75. 'template' => 'template',
  76. 'file' => 'index.php',
  77. 'directory' => JPATH_THEMES,
  78. 'params' => '{}'
  79. );
  80. $document->setBuffer($contents, 'installation');
  81. $document->setTitle(JText::_('PAGE_TITLE'));
  82. $data = $document->render(false, $params);
  83. JResponse::setBody($data);
  84. }
  85. /**
  86. * Initialise the application.
  87. *
  88. * @param $options array
  89. */
  90. public function initialise(array $options = array())
  91. {
  92. //Get the localisation information provided in the localise.xml file.
  93. $forced = $this->getLocalise();
  94. // Check the request data for the language.
  95. if (empty($options['language']))
  96. {
  97. $requestLang = JRequest::getCmd('lang', null);
  98. if (!is_null($requestLang))
  99. {
  100. $options['language'] = $requestLang;
  101. }
  102. }
  103. // Check the session for the language.
  104. if (empty($options['language']))
  105. {
  106. $sessionLang = &JFactory::getSession()->get('setup.language');
  107. if (!is_null($sessionLang))
  108. {
  109. $options['language'] = $sessionLang;
  110. }
  111. }
  112. // This could be a first-time visit - try to determine what the client accepts.
  113. if (empty($options['language']))
  114. {
  115. if (!empty($forced['language']))
  116. {
  117. $options['language'] = $forced['language'];
  118. } else {
  119. jimport('joomla.language.helper');
  120. $options['language'] = JLanguageHelper::detectLanguage();
  121. }
  122. }
  123. // Give the user English
  124. if (empty($options['language']))
  125. {
  126. $options['language'] = 'en-GB';
  127. }
  128. // Set the language in the class
  129. $conf = &JFactory::getConfig();
  130. $conf->setValue('config.language', $options['language']);
  131. $conf->setValue('config.debug_lang', $forced['debug']);
  132. }
  133. /**
  134. * Set configuration values
  135. *
  136. * @param array Array of configuration values
  137. * @param string The namespace
  138. */
  139. public function setCfg(array $vars = array(), $namespace = 'config')
  140. {
  141. $this->_registry->loadArray($vars, $namespace);
  142. }
  143. /**
  144. * Create the configuration registry
  145. */
  146. public function _createConfiguration()
  147. {
  148. jimport('joomla.registry.registry');
  149. // Create the registry with a default namespace of config which is read only
  150. $this->_registry = new JRegistry('config');
  151. }
  152. /**
  153. * Get the template
  154. *
  155. * @return string The template name
  156. */
  157. public function getTemplate($params = false)
  158. {
  159. if ((bool) $params)
  160. {
  161. $template = new stdClass();
  162. $template->template = 'template';
  163. $template->params = new JParameter();
  164. return $template;
  165. }
  166. return 'template';
  167. }
  168. /**
  169. * Create the user session
  170. *
  171. * @param string The sessions name
  172. * @return object JSession
  173. */
  174. public function & _createSession($name)
  175. {
  176. $options = array();
  177. $options['name'] = $name;
  178. $session = &JFactory::getSession($options);
  179. if (!is_a($session->get('registry'), 'JRegistry'))
  180. {
  181. // Registry has been corrupted somehow
  182. $session->set('registry', new JRegistry('session'));
  183. }
  184. return $session;
  185. }
  186. /**
  187. * Returns the langauge code and help url set in the localise.xml file.
  188. * Used for forcing a particular language in localised releases.
  189. *
  190. * @return bool|array False on failure, array on success.
  191. */
  192. public function getLocalise()
  193. {
  194. $xml = JFactory::getXML(JPATH_SITE.DS.'installation'.DS.'localise.xml');
  195. if( ! $xml)
  196. {
  197. return false;
  198. }
  199. // Check that it's a localise file
  200. if ($xml->getName() != 'localise')
  201. {
  202. return false;
  203. }
  204. $ret = array();
  205. $ret['language'] = (string)$xml->forceLang;
  206. $ret['helpurl'] = (string)$xml->helpurl;
  207. $ret['debug'] = (string)$xml->debug;
  208. return $ret;
  209. }
  210. /**
  211. * Returns the installed admin language files in the administrative and
  212. * front-end area.
  213. *
  214. * @return array Array with installed language packs in admin area
  215. */
  216. public function getLocaliseAdmin()
  217. {
  218. jimport('joomla.filesystem.folder');
  219. // Read the files in the admin area
  220. $path = JLanguage::getLanguagePath(JPATH_SITE.DS.'administrator');
  221. $langfiles['admin'] = JFolder::folders($path);
  222. $path = JLanguage::getLanguagePath(JPATH_SITE);
  223. $langfiles['site'] = JFolder::folders($path);
  224. return $langfiles;
  225. }
  226. }