PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/_installation/includes/application.php

https://github.com/rietn/minima
PHP | 366 lines | 227 code | 53 blank | 86 comment | 23 complexity | 991ee779a2e889fd7edb811b18eececd MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: application.php 20478 2011-01-28 17:48:29Z infograf768 $
  4. * @package Joomla.Installation
  5. * @copyright Copyright (C) 2005 - 2011 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::_('INSTL_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 = JController::getInstance('JInstallation');
  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::_('INSTL_PAGE_TITLE'));
  82. $data = $document->render(false, $params);
  83. JResponse::setBody($data);
  84. if (JFactory::getConfig()->get('debug_lang')) {
  85. $this->debugLanguage();
  86. }
  87. }
  88. /**
  89. * Initialise the application.
  90. *
  91. * @param $options array
  92. */
  93. public function initialise(array $options = array())
  94. {
  95. //Get the localisation information provided in the localise.xml file.
  96. $forced = $this->getLocalise();
  97. // Check the request data for the language.
  98. if (empty($options['language']))
  99. {
  100. $requestLang = JRequest::getCmd('lang', null);
  101. if (!is_null($requestLang))
  102. {
  103. $options['language'] = $requestLang;
  104. }
  105. }
  106. // Check the session for the language.
  107. if (empty($options['language']))
  108. {
  109. $sessionLang = JFactory::getSession()->get('setup.language');
  110. if (!is_null($sessionLang))
  111. {
  112. $options['language'] = $sessionLang;
  113. }
  114. }
  115. // This could be a first-time visit - try to determine what the client accepts.
  116. if (empty($options['language']))
  117. {
  118. if (!empty($forced['language']))
  119. {
  120. $options['language'] = $forced['language'];
  121. } else {
  122. jimport('joomla.language.helper');
  123. $options['language'] = JLanguageHelper::detectLanguage();
  124. if (empty($options['language'])) {
  125. $options['language'] = 'en-GB';
  126. }
  127. }
  128. }
  129. // Give the user English
  130. if (empty($options['language']))
  131. {
  132. $options['language'] = 'en-GB';
  133. }
  134. // Set the language in the class
  135. $conf = JFactory::getConfig();
  136. $conf->set('language', $options['language']);
  137. $conf->set('debug_lang', $forced['debug']);
  138. $conf->set('sampledata', $forced['sampledata']);
  139. }
  140. public static function debugLanguage()
  141. {
  142. ob_start();
  143. $lang = JFactory::getLanguage();
  144. echo '<h4>Parsing errors in language files</h4>';
  145. $errorfiles = $lang->getErrorFiles();
  146. if (count($errorfiles)) {
  147. echo '<ul>';
  148. foreach ($errorfiles as $file => $error)
  149. {
  150. echo "<li>$error</li>";
  151. }
  152. echo '</ul>';
  153. }
  154. else {
  155. echo '<pre>None</pre>';
  156. }
  157. echo '<h4>Untranslated Strings</h4>';
  158. echo '<pre>';
  159. $orphans = $lang->getOrphans();
  160. if (count($orphans)) {
  161. ksort($orphans, SORT_STRING);
  162. foreach ($orphans as $key => $occurance)
  163. {
  164. $guess = str_replace('_', ' ', $key);
  165. $parts = explode(' ', $guess);
  166. if (count($parts) > 1) {
  167. array_shift($parts);
  168. $guess = implode(' ', $parts);
  169. }
  170. $guess = trim($guess);
  171. $key = trim(strtoupper($key));
  172. $key = preg_replace('#\s+#', '_', $key);
  173. $key = preg_replace('#\W#', '', $key);
  174. // Prepare the text
  175. $guesses[] = $key.'="'.$guess.'"';
  176. }
  177. echo "\n\n# ".$file."\n\n";
  178. echo implode("\n", $guesses);
  179. }
  180. else {
  181. echo 'None';
  182. }
  183. echo '</pre>';
  184. $debug = ob_get_clean();
  185. JResponse::appendBody($debug);
  186. }
  187. /**
  188. * Set configuration values
  189. *
  190. * @param array Array of configuration values
  191. * @param string The namespace
  192. */
  193. public function setCfg(array $vars = array(), $namespace = 'config')
  194. {
  195. $this->_registry->loadArray($vars, $namespace);
  196. }
  197. /**
  198. * Create the configuration registry
  199. */
  200. public function _createConfiguration()
  201. {
  202. jimport('joomla.registry.registry');
  203. // Create the registry with a default namespace of config which is read only
  204. $this->_registry = new JRegistry('config');
  205. }
  206. /**
  207. * Get the template
  208. *
  209. * @return string The template name
  210. */
  211. public function getTemplate($params = false)
  212. {
  213. if ((bool) $params)
  214. {
  215. $template = new stdClass();
  216. $template->template = 'template';
  217. $template->params = new JRegistry;
  218. return $template;
  219. }
  220. return 'template';
  221. }
  222. /**
  223. * Create the user session
  224. *
  225. * @param string The sessions name
  226. * @return object JSession
  227. */
  228. public function & _createSession($name)
  229. {
  230. $options = array();
  231. $options['name'] = $name;
  232. $session = JFactory::getSession($options);
  233. if (!is_a($session->get('registry'), 'JRegistry'))
  234. {
  235. // Registry has been corrupted somehow
  236. $session->set('registry', new JRegistry('session'));
  237. }
  238. return $session;
  239. }
  240. /**
  241. * Returns the language code and help url set in the localise.xml file.
  242. * Used for forcing a particular language in localised releases.
  243. *
  244. * @return bool|array False on failure, array on success.
  245. */
  246. public function getLocalise()
  247. {
  248. $xml = JFactory::getXML(JPATH_SITE.DS.'installation'.DS.'localise.xml');
  249. if( ! $xml)
  250. {
  251. return false;
  252. }
  253. // Check that it's a localise file
  254. if ($xml->getName() != 'localise')
  255. {
  256. return false;
  257. }
  258. $ret = array();
  259. $ret['language'] = (string)$xml->forceLang;
  260. $ret['helpurl'] = (string)$xml->helpurl;
  261. $ret['debug'] = (string)$xml->debug;
  262. $ret['sampledata'] = (string)$xml->sampledata;
  263. return $ret;
  264. }
  265. /**
  266. * Returns the installed language files in the administrative and
  267. * front-end area.
  268. *
  269. * @return array Array with installed language packs in admin and site area
  270. */
  271. public function getLocaliseAdmin($db=false)
  272. {
  273. jimport('joomla.filesystem.folder');
  274. // Read the files in the admin area
  275. $path = JLanguage::getLanguagePath(JPATH_SITE.DS.'administrator');
  276. $langfiles['admin'] = JFolder::folders($path);
  277. // Read the files in the site area
  278. $path = JLanguage::getLanguagePath(JPATH_SITE);
  279. $langfiles['site'] = JFolder::folders($path);
  280. if($db)
  281. {
  282. $langfiles_disk = $langfiles;
  283. $langfiles = Array();
  284. $langfiles['admin'] = Array();
  285. $langfiles['site'] = Array();
  286. $query = $db->getQuery(true);
  287. $query->select('element,client_id');
  288. $query->from('#__extensions');
  289. $query->where('type = '.$db->quote('language'));
  290. $db->setQuery($query);
  291. $langs = $db->loadObjectList();
  292. foreach($langs as $lang)
  293. {
  294. switch($lang->client_id)
  295. {
  296. case 0: // site
  297. if(in_array($lang->element, $langfiles_disk['site']))
  298. {
  299. $langfiles['site'][] = $lang->element;
  300. }
  301. break;
  302. case 1: // administrator
  303. if(in_array($lang->element, $langfiles_disk['admin']))
  304. {
  305. $langfiles['admin'][] = $lang->element;
  306. }
  307. break;
  308. }
  309. }
  310. }
  311. return $langfiles;
  312. }
  313. }