| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Installation 4 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 5 * @license GNU General Public License version 2 or later; see LICENSE.txt 6 */ 7 8 defined('_JEXEC') or die; 9 10 /** 11 * Joomla Application class 12 * 13 * Provide many supporting API functions 14 * 15 * @package Joomla.Installation 16 */ 17 class JInstallation extends JApplication 18 { 19 /** 20 * The url of the site 21 * 22 * @var string 23 */ 24 protected $_siteURL = null; 25 26 /** 27 * Class constructor 28 * 29 * @param array $config An optional associative array of configuration settings. 30 * Recognized key values include 'clientId' (this list is not meant to be comprehensive). 31 * 32 * @return void 33 */ 34 public function __construct(array $config = array()) 35 { 36 $config['clientId'] = 2; 37 parent::__construct($config); 38 39 $this->_createConfiguration(''); 40 41 // Set the root in the URI based on the application name. 42 JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true))); 43 } 44 45 /** 46 * Render the application 47 * 48 * @return void 49 */ 50 public function render() 51 { 52 $document = JFactory::getDocument(); 53 $config = JFactory::getConfig(); 54 $user = JFactory::getUser(); 55 56 switch($document->getType()) 57 { 58 case 'html' : 59 // Set metadata 60 $document->setTitle(JText::_('INSTL_PAGE_TITLE')); 61 break; 62 default : 63 break; 64 } 65 66 // Define component path 67 define('JPATH_COMPONENT', JPATH_BASE); 68 define('JPATH_COMPONENT_SITE', JPATH_SITE); 69 define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR); 70 71 // Start the output buffer. 72 ob_start(); 73 74 // Import the controller. 75 require_once JPATH_COMPONENT.'/controller.php'; 76 77 // Execute the task. 78 $controller = JController::getInstance('JInstallation'); 79 $controller->execute(JRequest::getVar('task')); 80 $controller->redirect(); 81 82 // Get output from the buffer and clean it. 83 $contents = ob_get_contents(); 84 ob_end_clean(); 85 86 $file = JRequest::getCmd('tmpl', 'index'); 87 88 $params = array( 89 'template' => 'template', 90 'file' => $file.'.php', 91 'directory' => JPATH_THEMES, 92 'params' => '{}' 93 ); 94 95 $document->setBuffer($contents, 'installation'); 96 $document->setTitle(JText::_('INSTL_PAGE_TITLE')); 97 98 $data = $document->render(false, $params); 99 JResponse::setBody($data); 100 if (JFactory::getConfig()->get('debug_lang')) { 101 $this->debugLanguage(); 102 } 103 } 104 105 /** 106 * Initialise the application. 107 * 108 * @param array $options 109 * 110 * @return void 111 */ 112 public function initialise($options = array()) 113 { 114 //Get the localisation information provided in the localise.xml file. 115 $forced = $this->getLocalise(); 116 117 // Check the request data for the language. 118 if (empty($options['language'])) { 119 $requestLang = JRequest::getCmd('lang', null); 120 if (!is_null($requestLang)) { 121 $options['language'] = $requestLang; 122 } 123 } 124 125 // Check the session for the language. 126 if (empty($options['language'])) { 127 $sessionLang = JFactory::getSession()->get('setup.language'); 128 if (!is_null($sessionLang)) { 129 $options['language'] = $sessionLang; 130 } 131 } 132 133 // This could be a first-time visit - try to determine what the client accepts. 134 if (empty($options['language'])) { 135 if (!empty($forced['language'])) { 136 $options['language'] = $forced['language']; 137 } else { 138 $options['language'] = JLanguageHelper::detectLanguage(); 139 if (empty($options['language'])) { 140 $options['language'] = 'en-GB'; 141 } 142 } 143 } 144 145 // Give the user English 146 if (empty($options['language'])) { 147 $options['language'] = 'en-GB'; 148 } 149 150 // Set the language in the class 151 $conf = JFactory::getConfig(); 152 $conf->set('language', $options['language']); 153 $conf->set('debug_lang', $forced['debug']); 154 $conf->set('sampledata', $forced['sampledata']); 155 } 156 157 /** 158 * @return void 159 */ 160 public static function debugLanguage() 161 { 162 ob_start(); 163 $lang = JFactory::getLanguage(); 164 echo '<h4>Parsing errors in language files</h4>'; 165 $errorfiles = $lang->getErrorFiles(); 166 167 if (count($errorfiles)) { 168 echo '<ul>'; 169 170 foreach ($errorfiles as $file => $error) 171 { 172 echo "<li>$error</li>"; 173 } 174 echo '</ul>'; 175 } 176 else { 177 echo '<pre>None</pre>'; 178 } 179 180 echo '<h4>Untranslated Strings</h4>'; 181 echo '<pre>'; 182 $orphans = $lang->getOrphans(); 183 184 if (count($orphans)) { 185 ksort($orphans, SORT_STRING); 186 187 foreach ($orphans as $key => $occurance) 188 { 189 $guess = str_replace('_', ' ', $key); 190 191 $parts = explode(' ', $guess); 192 if (count($parts) > 1) { 193 array_shift($parts); 194 $guess = implode(' ', $parts); 195 } 196 197 $guess = trim($guess); 198 199 200 $key = trim(strtoupper($key)); 201 $key = preg_replace('#\s+#', '_', $key); 202 $key = preg_replace('#\W#', '', $key); 203 204 // Prepare the text 205 $guesses[] = $key.'="'.$guess.'"'; 206 } 207 208 echo "\n\n# ".$file."\n\n"; 209 echo implode("\n", $guesses); 210 } 211 else { 212 echo 'None'; 213 } 214 echo '</pre>'; 215 $debug = ob_get_clean(); 216 JResponse::appendBody($debug); 217 } 218 219 /** 220 * Set configuration values 221 * 222 * @param array $vars Array of configuration values 223 * @param string $namespace The namespace 224 * 225 * @return void 226 */ 227 public function setCfg(array $vars = array(), $namespace = 'config') 228 { 229 $this->_registry->loadArray($vars, $namespace); 230 } 231 232 /** 233 * Create the configuration registry 234 * 235 * @return void 236 */ 237 public function _createConfiguration($file) 238 { 239 // Create the registry with a default namespace of config which is read only 240 $this->_registry = new JRegistry('config'); 241 } 242 243 /** 244 * Get the template 245 * 246 * @return string The template name 247 */ 248 public function getTemplate($params = false) 249 { 250 if ((bool) $params) { 251 $template = new stdClass(); 252 $template->template = 'template'; 253 $template->params = new JRegistry; 254 return $template; 255 } 256 return 'template'; 257 } 258 259 /** 260 * Create the user session 261 * 262 * @param string $name The sessions name 263 * 264 * @return object JSession 265 */ 266 public function & _createSession($name) 267 { 268 $options = array(); 269 $options['name'] = $name; 270 271 $session = JFactory::getSession($options); 272 if (!is_a($session->get('registry'), 'JRegistry')) { 273 // Registry has been corrupted somehow 274 $session->set('registry', new JRegistry('session')); 275 } 276 277 return $session; 278 } 279 280 /** 281 * Returns the language code and help url set in the localise.xml file. 282 * Used for forcing a particular language in localised releases. 283 * 284 * @return bool|array False on failure, array on success. 285 */ 286 public function getLocalise() 287 { 288 $xml = JFactory::getXML(JPATH_SITE . '/installation/localise.xml'); 289 290 if (!$xml) { 291 return false; 292 } 293 294 // Check that it's a localise file 295 if ($xml->getName() != 'localise') { 296 return false; 297 } 298 299 $ret = array(); 300 301 $ret['language'] = (string)$xml->forceLang; 302 $ret['helpurl'] = (string)$xml->helpurl; 303 $ret['debug'] = (string)$xml->debug; 304 $ret['sampledata'] = (string)$xml->sampledata; 305 306 return $ret; 307 } 308 309 /** 310 * Returns the installed language files in the administrative and 311 * front-end area. 312 * 313 * @param boolean $db 314 * 315 * @return array Array with installed language packs in admin and site area 316 */ 317 public function getLocaliseAdmin($db=false) 318 { 319 jimport('joomla.filesystem.folder'); 320 321 // Read the files in the admin area 322 $path = JLanguage::getLanguagePath(JPATH_SITE . '/administrator'); 323 $langfiles['admin'] = JFolder::folders($path); 324 325 // Read the files in the site area 326 $path = JLanguage::getLanguagePath(JPATH_SITE); 327 $langfiles['site'] = JFolder::folders($path); 328 329 if ($db) { 330 $langfiles_disk = $langfiles; 331 $langfiles = array(); 332 $langfiles['admin'] = array(); 333 $langfiles['site'] = array(); 334 $query = $db->getQuery(true); 335 $query->select('element,client_id'); 336 $query->from('#__extensions'); 337 $query->where('type = '.$db->quote('language')); 338 $db->setQuery($query); 339 $langs = $db->loadObjectList(); 340 foreach ($langs as $lang) 341 { 342 switch($lang->client_id) 343 { 344 case 0: // site 345 if (in_array($lang->element, $langfiles_disk['site'])) { 346 $langfiles['site'][] = $lang->element; 347 } 348 break; 349 case 1: // administrator 350 if (in_array($lang->element, $langfiles_disk['admin'])) { 351 $langfiles['admin'][] = $lang->element; 352 } 353 break; 354 } 355 } 356 } 357 358 return $langfiles; 359 } 360 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |