PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/installation/includes/application.php

https://github.com/ot2sen/Tamka
PHP | 363 lines | 213 code | 51 blank | 99 comment | 23 complexity | 203e2691c0e108e043ac6ecbf31b2d63 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: application.php 21376 2011-05-24 17:11:48Z dextercowley $
  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. * @param array $config An optional associative array of configuration settings.
  28. * Recognized key values include 'clientId' (this list is not meant to be comprehensive).
  29. *
  30. * @return void
  31. */
  32. public function __construct(array $config = array())
  33. {
  34. $config['clientId'] = 2;
  35. parent::__construct($config);
  36. JError::setErrorHandling(E_ALL, 'Ignore');
  37. $this->_createConfiguration();
  38. // Set the root in the URI based on the application name.
  39. JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true)));
  40. }
  41. /**
  42. * Render the application
  43. *
  44. * @return void
  45. */
  46. public function render()
  47. {
  48. $document = JFactory::getDocument();
  49. $config = JFactory::getConfig();
  50. $user = JFactory::getUser();
  51. switch($document->getType())
  52. {
  53. case 'html' :
  54. // Set metadata
  55. $document->setTitle(JText::_('INSTL_PAGE_TITLE'));
  56. break;
  57. default :
  58. break;
  59. }
  60. // Define component path
  61. define('JPATH_COMPONENT', JPATH_BASE);
  62. define('JPATH_COMPONENT_SITE', JPATH_SITE);
  63. define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR);
  64. // Start the output buffer.
  65. ob_start();
  66. // Import the controller.
  67. require_once JPATH_COMPONENT.'/controller.php';
  68. // Execute the task.
  69. $controller = JController::getInstance('JInstallation');
  70. $controller->execute(JRequest::getVar('task'));
  71. $controller->redirect();
  72. // Get output from the buffer and clean it.
  73. $contents = ob_get_contents();
  74. ob_end_clean();
  75. $params = array(
  76. 'template' => 'template',
  77. 'file' => 'index.php',
  78. 'directory' => JPATH_THEMES,
  79. 'params' => '{}'
  80. );
  81. $document->setBuffer($contents, 'installation');
  82. $document->setTitle(JText::_('INSTL_PAGE_TITLE'));
  83. $data = $document->render(false, $params);
  84. JResponse::setBody($data);
  85. if (JFactory::getConfig()->get('debug_lang')) {
  86. $this->debugLanguage();
  87. }
  88. }
  89. /**
  90. * Initialise the application.
  91. *
  92. * @param array $options
  93. *
  94. * @return void
  95. */
  96. public function initialise(array $options = array())
  97. {
  98. //Get the localisation information provided in the localise.xml file.
  99. $forced = $this->getLocalise();
  100. // Check the request data for the language.
  101. if (empty($options['language'])) {
  102. $requestLang = JRequest::getCmd('lang', null);
  103. if (!is_null($requestLang)) {
  104. $options['language'] = $requestLang;
  105. }
  106. }
  107. // Check the session for the language.
  108. if (empty($options['language'])) {
  109. $sessionLang = JFactory::getSession()->get('setup.language');
  110. if (!is_null($sessionLang)) {
  111. $options['language'] = $sessionLang;
  112. }
  113. }
  114. // This could be a first-time visit - try to determine what the client accepts.
  115. if (empty($options['language'])) {
  116. if (!empty($forced['language'])) {
  117. $options['language'] = $forced['language'];
  118. } else {
  119. jimport('joomla.language.helper');
  120. $options['language'] = JLanguageHelper::detectLanguage();
  121. if (empty($options['language'])) {
  122. $options['language'] = 'en-GB';
  123. }
  124. }
  125. }
  126. // Give the user English
  127. if (empty($options['language'])) {
  128. $options['language'] = 'en-GB';
  129. }
  130. // Set the language in the class
  131. $conf = JFactory::getConfig();
  132. $conf->set('language', $options['language']);
  133. $conf->set('debug_lang', $forced['debug']);
  134. $conf->set('sampledata', $forced['sampledata']);
  135. }
  136. /**
  137. * @return void
  138. */
  139. public static function debugLanguage()
  140. {
  141. ob_start();
  142. $lang = JFactory::getLanguage();
  143. echo '<h4>Parsing errors in language files</h4>';
  144. $errorfiles = $lang->getErrorFiles();
  145. if (count($errorfiles)) {
  146. echo '<ul>';
  147. foreach ($errorfiles as $file => $error)
  148. {
  149. echo "<li>$error</li>";
  150. }
  151. echo '</ul>';
  152. }
  153. else {
  154. echo '<pre>None</pre>';
  155. }
  156. echo '<h4>Untranslated Strings</h4>';
  157. echo '<pre>';
  158. $orphans = $lang->getOrphans();
  159. if (count($orphans)) {
  160. ksort($orphans, SORT_STRING);
  161. foreach ($orphans as $key => $occurance)
  162. {
  163. $guess = str_replace('_', ' ', $key);
  164. $parts = explode(' ', $guess);
  165. if (count($parts) > 1) {
  166. array_shift($parts);
  167. $guess = implode(' ', $parts);
  168. }
  169. $guess = trim($guess);
  170. $key = trim(strtoupper($key));
  171. $key = preg_replace('#\s+#', '_', $key);
  172. $key = preg_replace('#\W#', '', $key);
  173. // Prepare the text
  174. $guesses[] = $key.'="'.$guess.'"';
  175. }
  176. echo "\n\n# ".$file."\n\n";
  177. echo implode("\n", $guesses);
  178. }
  179. else {
  180. echo 'None';
  181. }
  182. echo '</pre>';
  183. $debug = ob_get_clean();
  184. JResponse::appendBody($debug);
  185. }
  186. /**
  187. * Set configuration values
  188. *
  189. * @param array $vars Array of configuration values
  190. * @param string $namespace The namespace
  191. *
  192. * @return void
  193. */
  194. public function setCfg(array $vars = array(), $namespace = 'config')
  195. {
  196. $this->_registry->loadArray($vars, $namespace);
  197. }
  198. /**
  199. * Create the configuration registry
  200. *
  201. * @return void
  202. */
  203. public function _createConfiguration()
  204. {
  205. jimport('joomla.registry.registry');
  206. // Create the registry with a default namespace of config which is read only
  207. $this->_registry = new JRegistry('config');
  208. }
  209. /**
  210. * Get the template
  211. *
  212. * @return string The template name
  213. */
  214. public function getTemplate($params = false)
  215. {
  216. if ((bool) $params) {
  217. $template = new stdClass();
  218. $template->template = 'template';
  219. $template->params = new JRegistry;
  220. return $template;
  221. }
  222. return 'template';
  223. }
  224. /**
  225. * Create the user session
  226. *
  227. * @param string $name The sessions name
  228. *
  229. * @return object JSession
  230. */
  231. public function & _createSession($name)
  232. {
  233. $options = array();
  234. $options['name'] = $name;
  235. $session = JFactory::getSession($options);
  236. if (!is_a($session->get('registry'), 'JRegistry')) {
  237. // Registry has been corrupted somehow
  238. $session->set('registry', new JRegistry('session'));
  239. }
  240. return $session;
  241. }
  242. /**
  243. * Returns the language code and help url set in the localise.xml file.
  244. * Used for forcing a particular language in localised releases.
  245. *
  246. * @return bool|array False on failure, array on success.
  247. */
  248. public function getLocalise()
  249. {
  250. $xml = JFactory::getXML(JPATH_SITE.DS.'installation'.DS.'localise.xml');
  251. if (!$xml) {
  252. return false;
  253. }
  254. // Check that it's a localise file
  255. if ($xml->getName() != 'localise') {
  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. * @param boolean $db
  270. *
  271. * @return array Array with installed language packs in admin and site area
  272. */
  273. public function getLocaliseAdmin($db=false)
  274. {
  275. jimport('joomla.filesystem.folder');
  276. // Read the files in the admin area
  277. $path = JLanguage::getLanguagePath(JPATH_SITE.DS.'administrator');
  278. $langfiles['admin'] = JFolder::folders($path);
  279. // Read the files in the site area
  280. $path = JLanguage::getLanguagePath(JPATH_SITE);
  281. $langfiles['site'] = JFolder::folders($path);
  282. if ($db) {
  283. $langfiles_disk = $langfiles;
  284. $langfiles = Array();
  285. $langfiles['admin'] = Array();
  286. $langfiles['site'] = Array();
  287. $query = $db->getQuery(true);
  288. $query->select('element,client_id');
  289. $query->from('#__extensions');
  290. $query->where('type = '.$db->quote('language'));
  291. $db->setQuery($query);
  292. $langs = $db->loadObjectList();
  293. foreach ($langs as $lang)
  294. {
  295. switch($lang->client_id)
  296. {
  297. case 0: // site
  298. if (in_array($lang->element, $langfiles_disk['site'])) {
  299. $langfiles['site'][] = $lang->element;
  300. }
  301. break;
  302. case 1: // administrator
  303. if (in_array($lang->element, $langfiles_disk['admin'])) {
  304. $langfiles['admin'][] = $lang->element;
  305. }
  306. break;
  307. }
  308. }
  309. }
  310. return $langfiles;
  311. }
  312. }