| [ Index ] |
PHP Cross Reference of Joomla 1.5.25 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: jajax.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @subpackage Installation 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 define( '_JEXEC', 1 ); 16 17 //Global definitions 18 define( 'DS', DIRECTORY_SEPARATOR ); 19 20 //Joomla framework path definitions 21 $parts = explode( DS, dirname(__FILE__) ); 22 23 array_pop( $parts ); 24 define( 'JPATH_BASE', implode( DS, $parts ) ); 25 array_pop( $parts ); 26 27 define( 'JPATH_ROOT', implode( DS, $parts ) ); 28 define( 'JPATH_SITE', JPATH_ROOT ); 29 define( 'JPATH_CONFIGURATION', JPATH_ROOT ); 30 define( 'JPATH_LIBRARIES', JPATH_ROOT . DS . 'libraries' ); 31 32 define( 'JXPATH_BASE', JPATH_BASE.DS.'includes' ); 33 34 // Make sure that Joomla! is not yet installed 35 if (file_exists(JPATH_CONFIGURATION.DS.'configuration.php') && (filesize(JPATH_CONFIGURATION.DS.'configuration.php') > 10)) { 36 header( 'Location: ../../index.php' ); 37 exit(); 38 } 39 40 // System includes 41 require_once( JPATH_LIBRARIES .DS.'joomla'.DS.'import.php'); 42 43 require_once( JPATH_BASE . DS. 'installer' . DS . 'helper.php' ); 44 // Require the xajax library 45 require_once (JXPATH_BASE.DS.'xajax'.DS.'xajax.inc.php'); 46 $xajax = new xajax(); 47 $xajax->errorHandlerOn(); 48 49 $xajax->registerFunction(array('getFtpRoot', 'JAJAXHandler', 'ftproot')); 50 $xajax->registerFunction(array('FTPVerify', 'JAJAXHandler', 'ftpverify')); 51 $xajax->registerFunction(array('instDefault', 'JAJAXHandler', 'sampledata')); 52 53 JError::setErrorHandling(E_ERROR, 'callback', array('JAJAXHandler','handleError')); 54 JError::setErrorHandling(E_WARNING, 'callback', array('JAJAXHandler','handleError')); 55 JError::setErrorHandling(E_NOTICE, 'callback', array('JAJAXHandler','handleError')); 56 require_once (JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'utilities'.DS.'compat'.DS.'compat.php'); 57 58 /** 59 * AJAX Task handler class 60 * 61 * @static 62 * @package Joomla 63 * @subpackage Installer 64 * @since 1.5 65 */ 66 class JAJAXHandler 67 { 68 /** 69 * Method to get the path from the FTP root to the Joomla root directory 70 */ 71 function ftproot($args) 72 { 73 jimport( 'joomla.application.application' ); 74 jimport( 'joomla.registry.registry' ); 75 76 $lang = new JAJAXLang($args['lang']); 77 // $lang->setDebug(true); 78 79 $objResponse = new xajaxResponse(); 80 $args = $args['vars']; 81 82 $root = JInstallationHelper::findFtpRoot($args['ftpUser'], $args['ftpPassword'], $args['ftpHost'], $args['ftpPort']); 83 if (JError::isError($root)) { 84 $objResponse->addScript('document.getElementById(\'ftpdisable\').checked = true;'); 85 $objResponse->addAlert($lang->_($root->get('message'))); 86 } else { 87 $objResponse->addAssign('ftproot', 'value', $root); 88 $objResponse->addAssign('rootPath', 'style.display', ''); 89 $objResponse->addScript('document.getElementById(\'verifybutton\').click();'); 90 } 91 92 return $objResponse; 93 } 94 95 /** 96 * Method to verify the ftp values are valid 97 */ 98 function ftpverify($args) 99 { 100 jimport( 'joomla.application.application' ); 101 jimport( 'joomla.registry.registry' ); 102 103 $lang = new JAJAXLang($args['lang']); 104 // $lang->setDebug(true); 105 106 $objResponse = new xajaxResponse(); 107 $args = $args['vars']; 108 109 $status = JInstallationHelper::FTPVerify($args['ftpUser'], $args['ftpPassword'], $args['ftpRoot'], $args['ftpHost'], $args['ftpPort']); 110 if (JError::isError($status)) { 111 if (($msg = $status->get('message')) != 'INVALIDROOT') { 112 $msg = $lang->_('INVALIDFTP') ."\n". $lang->_($msg); 113 } else { 114 $msg = $lang->_($msg); 115 } 116 $objResponse->addScript('document.getElementById(\'ftpdisable\').checked = true;'); 117 $objResponse->addAlert($msg); 118 } else { 119 $objResponse->addScript('document.getElementById(\'ftpenable\').checked = true;'); 120 $objResponse->addAlert($lang->_('VALIDFTP')); 121 } 122 123 return $objResponse; 124 } 125 126 /** 127 * Method to load and execute a sql script 128 */ 129 function sampledata($args) 130 { 131 jimport( 'joomla.database.database'); 132 jimport( 'joomla.language.language'); 133 jimport( 'joomla.registry.registry'); 134 135 136 $errors = null; 137 $msg = ''; 138 $objResponse = new xajaxResponse(); 139 $lang = new JAJAXLang($args['lang']); 140 // $lang->setDebug(true); 141 142 /* 143 * execute the default sample data file 144 */ 145 $type = $args['DBtype']; 146 if ($type == 'mysqli') { 147 $type = 'mysql'; 148 } 149 $dbsample = '../sql'.DS.$type.DS.'sample_data.sql'; 150 151 $db = & JInstallationHelper::getDBO($args['DBtype'], $args['DBhostname'], $args['DBuserName'], $args['DBpassword'], $args['DBname'], $args['DBPrefix']); 152 $result = JInstallationHelper::populateDatabase($db, $dbsample, $errors); 153 154 /* 155 * prepare sql error messages if returned from populate 156 */ 157 if (!is_null($errors)){ 158 foreach($errors as $error){ 159 $msg .= stripslashes( $error['msg'] ); 160 $msg .= chr(13)."-------------".chr(13); 161 $txt = '<textarea cols="35" rows="5" name="instDefault" readonly="readonly" >'.$lang->_('Database Errors Reported').chr(13).$msg.'</textarea>'; 162 } 163 } else { 164 // consider other possible errors from populate 165 $msg = $result == 0 ? $lang->_("Sample data installed successfully") : $lang->_("Error installing SQL script") ; 166 $txt = '<input size="35" name="instDefault" value="'.$msg.'" readonly="readonly" />'; 167 } 168 169 $objResponse->addAssign("theDefault", "innerHTML", $txt); 170 return $objResponse; 171 } 172 173 /** 174 * Handle a raised error : for now just silently return 175 * 176 * @access private 177 * @param object $error JError object 178 * @return object $error JError object 179 * @since 1.5 180 */ 181 function &handleError(&$error) 182 { 183 return $error; 184 } 185 } 186 187 188 /** 189 * Languages/translation handler class 190 * 191 * @package Joomla.Framework 192 * @subpackage I18N 193 * @since 1.5 194 */ 195 class JAJAXLang extends JObject 196 { 197 /** 198 * Debug language, If true, highlights if string isn't found 199 * 200 * @var boolean 201 * @access protected 202 */ 203 var $_debug = false; 204 205 /** 206 * Identifying string of the language 207 * 208 * @var string 209 * @access protected 210 */ 211 var $_identifyer = null; 212 213 /** 214 * The language to load 215 * 216 * @var string 217 * @access protected 218 */ 219 var $_lang = null; 220 221 /** 222 * Transaltions 223 * 224 * @var array 225 * @access protected 226 */ 227 var $_strings = null; 228 229 /** 230 * Constructor activating the default information of the language 231 * 232 * @access protected 233 */ 234 function __construct($lang = null) 235 { 236 $this->_strings = array (); 237 238 if ($lang == null) { 239 $lang = 'en-GB'; 240 } 241 242 $this->_lang= $lang; 243 244 $this->load(); 245 } 246 247 /** 248 * Translator function, mimics the php gettext (alias _) function 249 * 250 * @access public 251 * @param string $string The string to translate 252 * @param boolean $jsSafe Make the result javascript safe 253 * @return string The translation of the string 254 */ 255 function _($string, $jsSafe = false) 256 { 257 //$key = str_replace( ' ', '_', strtoupper( trim( $string ) ) );echo '<br />'.$key; 258 $key = strtoupper($string); 259 $key = substr($key, 0, 1) == '_' ? substr($key, 1) : $key; 260 if (isset ($this->_strings[$key])) { 261 $string = $this->_debug ? "•".$this->_strings[$key]."•" : $this->_strings[$key]; 262 } else { 263 if (defined($string)) { 264 $string = $this->_debug ? "!!".constant($string)."!!" : constant($string); 265 } else { 266 $string = $this->_debug ? "??".$string."??" : $string; 267 } 268 } 269 if ($jsSafe) { 270 $string = addslashes($string); 271 } 272 return $string; 273 } 274 275 /** 276 * Loads a single language file and appends the results to the existing strings 277 * 278 * @access public 279 * @param string $prefix The prefix 280 * @param string $basePath The basepath to use 281 * $return boolean True, if the file has successfully loaded. 282 */ 283 function load( $prefix = '', $basePath = JPATH_BASE ) 284 { 285 $path = JAJAXLang::getLanguagePath( $basePath, $this->_lang); 286 287 $filename = empty( $prefix ) ? $this->_lang : $this->_lang . '.' . $prefix ; 288 289 $result = false; 290 291 $newStrings = $this->_load( $path.DS.$filename.'.ini' ); 292 293 if (is_array($newStrings)) { 294 $this->_strings = array_merge( $this->_strings, $newStrings); 295 $result = true; 296 } 297 298 return $result; 299 300 } 301 302 /** 303 * Loads a language file and returns the parsed values 304 * 305 * @access private 306 * @param string The name of the file 307 * @return mixed Array of parsed values if successful, boolean False if failed 308 */ 309 function _load( $filename ) 310 { 311 if ($content = @file_get_contents( $filename )) { 312 if( $this->_identifyer === null ) { 313 $this->_identifyer = basename( $filename, '.ini' ); 314 } 315 316 $registry = new JRegistry(); 317 $registry->loadINI($content); 318 return $registry->toArray( ); 319 } 320 321 return false; 322 } 323 324 /** 325 * Set the Debug property 326 * 327 * @access public 328 */ 329 function setDebug($debug) { 330 $this->_debug = $debug; 331 } 332 333 /** 334 * Determines is a key exists 335 * 336 * @access public 337 * @param key $key The key to check 338 * @return boolean True, if the key exists 339 */ 340 function hasKey($key) { 341 return isset ($this->_strings[strtoupper($key)]); 342 } 343 344 /** 345 * Get the path to a language 346 * 347 * @access public 348 * @param string $basePath The basepath to use 349 * @param string $language The language tag 350 * @return string language related path or null 351 */ 352 function getLanguagePath($basePath = JPATH_BASE, $language = null ) 353 { 354 $dir = $basePath.DS.'language'; 355 if (isset ($language)) { 356 $dir .= DS.$language; 357 } 358 return $dir; 359 } 360 } 361 362 363 364 /* 365 * Process the AJAX requests 366 */ 367 $xajax->cleanBufferOff(); //Needed for suPHP compilance 368 $xajax->processRequests();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 14 16:47:20 2011 | Cross-referenced by PHPXref 0.7.1 |