| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @version $Id: model.php 16385 2010-04-23 10:44:15Z ian $ 5 * @package Joomla 6 * @subpackage Installation 7 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 8 * @license GNU/GPL, see LICENSE.php 9 * Joomla! is free software. This version may have been modified pursuant 10 * to the GNU General Public License, and as distributed it includes or 11 * is derivative of works licensed under the GNU General Public License or 12 * other free or open source software licenses. 13 * See COPYRIGHT.php for copyright notices and details. 14 */ 15 16 // no direct access 17 defined('_JEXEC') or die('Restricted access'); 18 19 /** 20 * @package Joomla 21 * @subpackage Installation 22 */ 23 24 jimport('joomla.application.component.model'); 25 26 class JInstallationModel extends JModel 27 { 28 /** 29 * Array used to store data between model and view 30 * 31 * @var Array 32 * @access protected 33 * @since 1.5 34 */ 35 var $data = array(); 36 37 /** 38 * Array used to store user input created during the installation process 39 * 40 * @var Array 41 * @access protected 42 * @since 1.5 43 */ 44 var $vars = array(); 45 46 /** 47 * Constructor 48 */ 49 function __construct($config = array()) 50 { 51 $this->_state = new JObject(); 52 //set the view name 53 if (empty( $this->_name )) 54 { 55 if (isset($config['name'])) { 56 $this->_name = $config['name']; 57 } 58 else 59 { 60 $r = null; 61 if (!preg_match('/Model(.*)/i', get_class($this), $r)) { 62 JError::raiseError (500, "JModel::__construct() : Can't get or parse class name."); 63 } 64 $this->_name = strtolower( $r[1] ); 65 } 66 } 67 } 68 69 /** 70 * Generate a panel of language choices for the user to select their language 71 * 72 * @return boolean True if successful 73 * @access public 74 * @since 1.5 75 */ 76 function chooseLanguage() 77 { 78 global $mainframe; 79 80 $vars =& $this->getVars(); 81 82 jimport('joomla.language.helper'); 83 $native = JLanguageHelper::detectLanguage(); 84 $forced = $mainframe->getLocalise(); 85 86 if ( !empty( $forced['lang'] ) ){ 87 $native = $forced['lang']; 88 } 89 90 $lists = array (); 91 $lists['langs'] = JLanguageHelper::createLanguageList($native); 92 93 $this->setData('lists', $lists); 94 95 return true; 96 } 97 98 /** 99 * Gets the parameters for database creation 100 * 101 * @return boolean True if successful 102 * @access public 103 * @since 1.5 104 */ 105 function dbConfig() 106 { 107 global $mainframe; 108 109 $vars =& $this->getVars(); 110 111 if (!isset ($vars['DBPrefix'])) { 112 $vars['DBPrefix'] = 'jos_'; 113 } 114 115 $lists = array (); 116 $files = array ('mysql', 'mysqli',); 117 $db = JInstallationHelper::detectDB(); 118 foreach ($files as $file) 119 { 120 $option = array (); 121 $option['text'] = $file; 122 if (strcasecmp($option['text'], $db) == 0) 123 { 124 $option['selected'] = 'selected="true"'; 125 } 126 $lists['dbTypes'][] = $option; 127 } 128 129 $doc =& JFactory::getDocument(); 130 131 $this->setData('lists', $lists); 132 133 return true; 134 } 135 136 /** 137 * Displays the finish screen 138 * 139 * @return boolean True if successful 140 * @access public 141 * @since 1.5 142 */ 143 function finish() 144 { 145 global $mainframe; 146 147 $vars =& $this->getVars(); 148 149 $vars['siteurl'] = JURI::root(); 150 $vars['adminurl'] = $vars['siteurl'].'administrator/'; 151 152 return true; 153 } 154 155 /** 156 * Gets ftp configuration parameters 157 * 158 * @return boolean True if successful 159 * @access public 160 * @since 1.5 161 */ 162 function ftpConfig($DBcreated = '0') 163 { 164 global $mainframe; 165 166 $vars =& $this->getVars(); 167 168 // Require the xajax library 169 require_once( JPATH_BASE.DS.'includes'.DS.'xajax'.DS.'xajax.inc.php' ); 170 171 // Instantiate the xajax object and register the function 172 $xajax = new xajax(JURI::base().'installer/jajax.php'); 173 $xajax->registerFunction(array('getFtpRoot', 'JAJAXHandler', 'ftproot')); 174 $xajax->registerFunction(array('FTPVerify', 'JAJAXHandler', 'ftpverify')); 175 //$xajax->debugOn(); 176 177 $vars['DBcreated'] = JArrayHelper::getValue($vars, 'DBcreated', $DBcreated); 178 $strip = get_magic_quotes_gpc(); 179 180 if (!isset ($vars['ftpEnable'])) { 181 $vars['ftpEnable'] = '1'; 182 } 183 if (!isset ($vars['ftpHost'])) { 184 $vars['ftpHost'] = '127.0.0.1'; 185 } 186 if (!isset ($vars['ftpPort'])) { 187 $vars['ftpPort'] = '21'; 188 } 189 if (!isset ($vars['ftpUser'])) { 190 $vars['ftpUser'] = ''; 191 } 192 if (!isset ($vars['ftpPassword'])) { 193 $vars['ftpPassword'] = ''; 194 } 195 196 $doc =& JFactory::getDocument(); 197 $doc->addCustomTag($xajax->getJavascript('', 'includes/js/xajax.js', 'includes/js/xajax.js')); 198 199 return true; 200 } 201 202 /** 203 * Get data for later use 204 * 205 * @return string 206 * @access public 207 * @since 1.5 208 */ 209 function & getData($key){ 210 211 if ( ! array_key_exists($key, $this->data) ) 212 { 213 $null = null; 214 return $null; 215 } 216 217 return $this->data[$key]; 218 } 219 220 /** 221 * Get the local PHP settings 222 * 223 * @param $val Value to get 224 * @return Mixed 225 * @access protected 226 * @since 1.5 227 */ 228 function getPhpSetting($val) { 229 $r = (ini_get($val) == '1' ? 1 : 0); 230 return $r ? 'ON' : 'OFF'; 231 } 232 233 /** 234 * Get the configuration variables for the installation 235 * 236 * @return Array Configuration variables 237 * @access public 238 * @since 1.5 239 */ 240 function & getVars() 241 { 242 if ( ! $this->vars ) 243 { 244 // get a recursively slash stripped version of post 245 $post = (array) JRequest::get( 'post' ); 246 $postVars = JArrayHelper::getValue( $post, 'vars', array(), 'array' ); 247 $session =& JFactory::getSession(); 248 $registry =& $session->get('registry'); 249 $registry->loadArray($postVars, 'application'); 250 $this->vars = $registry->toArray('application'); 251 } 252 253 return $this->vars; 254 } 255 256 /** 257 * Gets the parameters for database creation 258 * 259 * 260 * @return boolean True if successful 261 * @access public 262 * @since 1.5 263 */ 264 function license() 265 { 266 return true; 267 } 268 269 /** 270 * Gets the parameters for database creation 271 * 272 * @return boolean True if successful 273 * @access public 274 * @since 1.5 275 */ 276 function makeDB($vars = false) 277 { 278 global $mainframe; 279 280 // Initialize variables 281 if ($vars === false) { 282 $vars = $this->getVars(); 283 } 284 285 $errors = null; 286 $lang = JArrayHelper::getValue($vars, 'lang', 'en-GB'); 287 $DBcreated = JArrayHelper::getValue($vars, 'DBcreated', '0'); 288 $DBtype = JArrayHelper::getValue($vars, 'DBtype', 'mysql'); 289 $DBhostname = JArrayHelper::getValue($vars, 'DBhostname', ''); 290 $DBuserName = JArrayHelper::getValue($vars, 'DBuserName', ''); 291 $DBpassword = JArrayHelper::getValue($vars, 'DBpassword', ''); 292 $DBname = JArrayHelper::getValue($vars, 'DBname', ''); 293 $DBPrefix = JArrayHelper::getValue($vars, 'DBPrefix', 'jos_'); 294 $DBOld = JArrayHelper::getValue($vars, 'DBOld', 'bu'); 295 $DBversion = JArrayHelper::getValue($vars, 'DBversion', ''); 296 297 // these 3 errors should be caught by the javascript in dbConfig 298 if ($DBtype == '') 299 { 300 $this->setError(JText::_('validType')); 301 $this->setData('back', 'dbconfig'); 302 $this->setData('errors', $errors); 303 return false; 304 //return JInstallationView::error($vars, JText::_('validType'), 'dbconfig'); 305 } 306 if (!$DBhostname || !$DBuserName || !$DBname) 307 { 308 $this->setError(JText::_('validDBDetails')); 309 $this->setData('back', 'dbconfig'); 310 $this->setData('errors', $errors); 311 return false; 312 //return JInstallationView::error($vars, JText::_('validDBDetails'), 'dbconfig'); 313 } 314 if ($DBname == '') 315 { 316 $this->setError(JText::_('emptyDBName')); 317 $this->setData('back', 'dbconfig'); 318 $this->setData('errors', $errors); 319 return false; 320 //return JInstallationView::error($vars, JText::_('emptyDBName'), 'dbconfig'); 321 } 322 if (!preg_match( '#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $DBPrefix )) { 323 $this->setError(JText::_('MYSQLPREFIXINVALIDCHARS')); 324 $this->setData('back', 'dbconfig'); 325 $this->setData('errors', $errors); 326 return false; 327 } 328 if (strlen($DBPrefix) > 15) { 329 $this->setError(JText::_('MYSQLPREFIXTOOLONG')); 330 $this->setData('back', 'dbconfig'); 331 $this->setData('errors', $errors); 332 return false; 333 } 334 if (strlen($DBname) > 64) { 335 $this->setError(JText::_('MYSQLDBNAMETOOLONG')); 336 $this->setData('back', 'dbconfig'); 337 $this->setData('errors', $errors); 338 return false; 339 } 340 341 if (!$DBcreated) 342 { 343 $DBselect = false; 344 $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, null, $DBPrefix, $DBselect); 345 346 if ( JError::isError($db) ) { 347 // connection failed 348 $this->setError(JText::sprintf('WARNNOTCONNECTDB', $db->toString())); 349 $this->setData('back', 'dbconfig'); 350 $this->setData('errors', $db->toString()); 351 return false; 352 } 353 354 if ($err = $db->getErrorNum()) { 355 // connection failed 356 $this->setError(JText::sprintf('WARNNOTCONNECTDB', $db->getErrorNum())); 357 $this->setData('back', 'dbconfig'); 358 $this->setData('errors', $db->getErrorMsg()); 359 return false; 360 } 361 362 //Check utf8 support of database 363 $DButfSupport = $db->hasUTF(); 364 365 // Try to select the database 366 if ( ! $db->select($DBname) ) 367 { 368 if (JInstallationHelper::createDatabase($db, $DBname, $DButfSupport)) 369 { 370 $db->select($DBname); 371 /* 372 // make the new connection to the new database 373 $db = NULL; 374 $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); 375 */ 376 } else { 377 $this->setError(JText::sprintf('WARNCREATEDB', $DBname)); 378 $this->setData('back', 'dbconfig'); 379 $this->setData('errors', $db->getErrorMsg()); 380 return false; 381 //return JInstallationView::error($vars, array (JText::sprintf('WARNCREATEDB', $DBname)), 'dbconfig', $error); 382 } 383 } else { 384 385 // pre-existing database - need to set character set to utf8 386 // will only affect MySQL 4.1.2 and up 387 JInstallationHelper::setDBCharset($db, $DBname); 388 } 389 390 $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); 391 392 if ($DBOld == 'rm') { 393 if (JInstallationHelper::deleteDatabase($db, $DBname, $DBPrefix, $errors)) { 394 $this->setError(JText::_('WARNDELETEDB')); 395 $this->setData('back', 'dbconfig'); 396 $this->setData('errors', $errors); 397 return false; 398 //return JInstallationView::error($vars, , 'dbconfig', JInstallationHelper::errors2string($errors)); 399 } 400 } 401 else 402 { 403 /* 404 * We assume since we aren't deleting the database that we need 405 * to back it up :) 406 */ 407 if (JInstallationHelper::backupDatabase($db, $DBname, $DBPrefix, $errors)) { 408 $this->setError(JText::_('WARNBACKINGUPDB')); 409 $this->setData('back', 'dbconfig'); 410 $this->setData('errors', JInstallationHelper::errors2string($errors)); 411 return false; 412 //return JInstallationView::error($vars, JText::_('WARNBACKINGUPDB'), 'dbconfig', JInstallationHelper::errors2string($errors)); 413 } 414 } 415 416 $type = $DBtype; 417 if ($type == 'mysqli') { 418 $type = 'mysql'; 419 } 420 421 // set collation and use utf-8 compatibile script if appropriate 422 if ($DButfSupport) { 423 $dbscheme = 'sql'.DS.$type.DS.'joomla.sql'; 424 } else { 425 $dbscheme = 'sql'.DS.$type.DS.'joomla_backward.sql'; 426 } 427 428 if (JInstallationHelper::populateDatabase($db, $dbscheme, $errors) > 0) 429 { 430 $this->setError(JText::_('WARNPOPULATINGDB')); 431 $this->setData('back', 'dbconfig'); 432 $this->setData('errors', JInstallationHelper::errors2string($errors)); 433 return false; 434 //return JInstallationView::error($vars, JText::_('WARNPOPULATINGDB'), 'dbconfig', JInstallationHelper::errors2string($errors)); 435 } 436 437 // Load the localise.sql for translating the data in joomla.sql/joomla_backwards.sql 438 // This feature is available for localized version of Joomla! 1.5 439 jimport('joomla.filesystem.file'); 440 $dblocalise = 'sql'.DS.$type.DS.'localise.sql'; 441 if(JFile::exists($dblocalise)) { 442 if(JInstallationHelper::populateDatabase($db, $dblocalise, $errors) > 0) { 443 $this->setError(JText::_('WARNPOPULATINGDB')); 444 $this->setData('back', 'dbconfig'); 445 $this->setData('errors', JInstallationHelper::errors2string($errors)); 446 return false; 447 } 448 } 449 450 // Handle default backend language setting. This feature is available for 451 // localized versions of Joomla! 1.5. 452 $langfiles = $mainframe->getLocaliseAdmin(); 453 if (in_array($lang, $langfiles['admin']) || in_array($lang, $langfiles['site'])) { 454 // Determine the language settings 455 $param[] = Array(); 456 if (in_array($lang, $langfiles['admin'])) { 457 $langparam[] = "administrator=$lang"; 458 } 459 460 if (in_array($lang, $langfiles['site'])) { 461 $langparam[] = "site=$lang"; 462 } 463 $langparams = implode("\n", $langparam); 464 465 // Because database config has not yet been set we just 466 // do the trick by a plain update of the proper record. 467 $where[] = "`option`='com_languages'"; 468 $where = (count($where) ? ' WHERE '.implode(' AND ', $where) : ''); 469 470 $query = "UPDATE #__components " . 471 "SET params='$langparams'" . 472 $where; 473 474 $db->setQuery($query); 475 if (!$db->query()) { 476 return false; 477 } 478 } 479 } 480 481 return true; 482 } 483 484 /** 485 * Finishes configuration parameters 486 * 487 * @return boolean True if successful 488 * @access public 489 * @since 1.5 490 */ 491 function mainConfig() 492 { 493 global $mainframe; 494 495 $vars =& $this->getVars(); 496 497 // get ftp configuration into registry for use in case of safe mode 498 if($vars['ftpEnable']) { 499 JInstallationHelper::setFTPCfg( $vars ); 500 } 501 502 // Check a few directories are writeable as this may cause issues 503 if(!is_writeable(JPATH_SITE.DS.'tmp') || !is_writeable(JPATH_SITE.DS.'installation'.DS.'sql'.DS.'migration')) { 504 $vars['dircheck'] = JText::_('Some paths may be unwritable'); 505 } 506 507 // Require the xajax library 508 require_once( JPATH_BASE.DS.'includes'.DS.'xajax'.DS.'xajax.inc.php' ); 509 510 // Instantiate the xajax object and register the function 511 $xajax = new xajax(JURI::base().'installer/jajax.php'); 512 $xajax->registerFunction(array('instDefault', 'JAJAXHandler', 'sampledata')); 513 // $xajax->debugOn(); 514 $xajax->errorHandlerOn(); 515 $doc =& JFactory::getDocument(); 516 $doc->addCustomTag($xajax->getJavascript('', 'includes/js/xajax.js', 'includes/js/xajax.js')); 517 518 // Deal with possible sql script uploads from this stage 519 $vars['loadchecked'] = 0; 520 if (JRequest::getVar( 'sqlupload', 0, 'post', 'int' ) == 1) 521 { 522 $vars['sqlresponse'] = JInstallationHelper::uploadSql( $vars ); 523 $vars['dataloaded'] = '1'; 524 $vars['loadchecked'] = 1; 525 } 526 if ((JRequest::getVar( 'migrationupload', 0, 'post', 'int' ) == 1) && (JRequest::getVar( 'migrationUploaded', 0, 'post', 'int' ) == 0)) 527 { 528 jexit(print_r(JRequest::getVar( 'migrationUploaded', 0, 'post', 'int' ))); 529 $vars['migresponse'] = JInstallationHelper::uploadSql( $vars, true ); 530 $vars['dataloaded'] = '1'; 531 $vars['loadchecked'] = 2; 532 } 533 if(JRequest::getVar( 'migrationUploaded',0,'post','int') == 1) { 534 $vars['migresponse'] = JInstallationHelper::findMigration( $vars ); 535 $vars['dataloaded'] = '1'; 536 $vars['loadchecked'] = 2; 537 } 538 539 // $strip = get_magic_quotes_gpc(); 540 541 if (isset ($vars['siteName'])) 542 { 543 $vars['siteName'] = stripslashes(stripslashes($vars['siteName'])); 544 } 545 546 $folders = array ( 547 'administrator/backups', 548 'administrator/cache', 549 'administrator/components', 550 'administrator/language', 551 'administrator/modules', 552 'administrator/templates', 553 'cache', 554 'components', 555 'images', 556 'images/banners', 557 'images/stories', 558 'language', 559 'plugins', 560 'plugins/content', 561 'plugins/editors', 562 'plugins/search', 563 'plugins/system', 564 'tmp', 565 'modules', 566 'templates', 567 ); 568 569 // Now lets make sure we have permissions set on the appropriate folders 570 // foreach ($folders as $folder) 571 // { 572 // if (!JInstallationHelper::setDirPerms( $folder, $vars )) 573 // { 574 // $lists['folderPerms'][] = $folder; 575 // } 576 // } 577 578 return true; 579 } 580 581 /** 582 * Perform a preinstall check 583 * 584 * @return boolean True if successful 585 * @access public 586 * @since 1.5 587 */ 588 function preInstall() 589 { 590 $vars =& $this->getVars(); 591 $lists = array (); 592 593 $phpOptions[] = array ( 594 'label' => JText::_('PHP version').' >= 4.3.10', 595 'state' => phpversion() < '4.3.10' ? 'No' : 'Yes' 596 ); 597 $phpOptions[] = array ( 598 'label' => '- '.JText::_('zlib compression support'), 599 'state' => extension_loaded('zlib') ? 'Yes' : 'No' 600 ); 601 $phpOptions[] = array ( 602 'label' => '- '.JText::_('XML support'), 603 'state' => extension_loaded('xml') ? 'Yes' : 'No', 604 'statetext' => extension_loaded('xml') ? 'Yes' : 'No' 605 ); 606 $phpOptions[] = array ( 607 'label' => '- '.JText::_('MySQL support'), 608 'state' => (function_exists('mysql_connect') || function_exists('mysqli_connect')) ? 'Yes' : 'No' 609 ); 610 if (extension_loaded( 'mbstring' )) { 611 $mbDefLang = strtolower( ini_get( 'mbstring.language' ) ) == 'neutral'; 612 $phpOptions[] = array ( 613 'label' => JText::_( 'MB language is default' ), 614 'state' => $mbDefLang ? 'Yes' : 'No', 615 'notice' => $mbDefLang ? '' : JText::_( 'NOTICEMBLANGNOTDEFAULT' ) 616 ); 617 $mbOvl = ini_get('mbstring.func_overload') != 0; 618 $phpOptions[] = array ( 619 'label' => JText::_('MB string overload off'), 620 'state' => !$mbOvl ? 'Yes' : 'No', 621 'notice' => $mbOvl ? JText::_('NOTICEMBSTRINGOVERLOAD') : '' 622 ); 623 } 624 $sp = ''; 625 /*$phpOptions[] = array ( 626 'label' => JText::_('Session path set'), 627 'state' => ($sp = ini_get('session.save_path')) ? 'Yes' : 'No' 628 ); 629 $phpOptions[] = array ( 630 'label' => JText::_('Session path writable'), 631 'state' => is_writable($sp) ? 'Yes' : 'No' 632 );*/ 633 $cW = (@ file_exists('../configuration.php') && @ is_writable('../configuration.php')) || is_writable('../'); 634 $phpOptions[] = array ( 635 'label' => 'configuration.php '.JText::_('writable'), 636 'state' => $cW ? 'Yes' : 'No', 637 'notice' => $cW ? '' : JText::_('NOTICEYOUCANSTILLINSTALL') 638 ); 639 $lists['phpOptions'] = & $phpOptions; 640 641 $phpRecommended = array ( 642 array ( 643 JText::_('Safe Mode'), 644 'safe_mode', 645 'OFF' 646 ), 647 array ( 648 JText::_('Display Errors'), 649 'display_errors', 650 'OFF' 651 ), 652 array ( 653 JText::_('File Uploads'), 654 'file_uploads', 655 'ON' 656 ), 657 array ( 658 JText::_('Magic Quotes Runtime'), 659 'magic_quotes_runtime', 660 'OFF' 661 ), 662 array ( 663 JText::_('Register Globals'), 664 'register_globals', 665 'OFF' 666 ), 667 array ( 668 JText::_('Output Buffering'), 669 'output_buffering', 670 'OFF' 671 ), 672 array ( 673 JText::_('Session auto start'), 674 'session.auto_start', 675 'OFF' 676 ), 677 ); 678 679 foreach ($phpRecommended as $setting) 680 { 681 $lists['phpSettings'][] = array ( 682 'label' => $setting[0], 683 'setting' => $setting[2], 684 'actual' => $this->getPhpSetting( $setting[1] ), 685 'state' => $this->getPhpSetting($setting[1]) == $setting[2] ? 'Yes' : 'No' 686 ); 687 } 688 689 $this->setData('lists', $lists); 690 691 return true; 692 } 693 694 /** 695 * Remove directory messages 696 * 697 * @return Boolean True if successful 698 * @access public 699 * @since 1.5 700 */ 701 function removedir() 702 { 703 return true; 704 } 705 706 /** 707 * Save the configuration information 708 * 709 * @return boolean True if successful 710 * @access public 711 * @since 1.5 712 */ 713 function saveConfig() 714 { 715 global $mainframe; 716 717 $vars =& $this->getVars(); 718 $lang =& JFactory::getLanguage(); 719 720 // Import authentication library 721 jimport( 'joomla.user.helper' ); 722 723 // Set some needed variables 724 $vars['siteUrl'] = JURI::root(); 725 $vars['secret'] = JUserHelper::genRandomPassword(16); 726 727 $vars['offline'] = JText::_( 'STDOFFLINEMSG' ); 728 $vars['errormsg'] = JText::_( 'STDERRORMSG' ); 729 $vars['metadesc'] = JText::_( 'STDMETADESC' ); 730 $vars['metakeys'] = JText::_( 'STDMETAKEYS' ); 731 $vars['tmp_path'] = JPATH_ROOT.DS.'tmp'; 732 $vars['log_path'] = JPATH_ROOT.DS.'logs'; 733 734 // set default language 735 $forced = $mainframe->getLocalise(); 736 if ( empty($forced['lang']) ) { 737 $vars['deflang'] = 'en-GB'; 738 $vars['bclang'] = 'english'; 739 } else { 740 $vars['deflang'] = $forced['lang']; 741 $vars['bclang'] = $lang->getBackwardLang(); 742 } 743 744 if ( empty( $forced['helpurl'] ) ) { 745 $vars['helpurl'] = 'http://help.joomla.org'; 746 } else { 747 $vars['helpurl'] = $forced['helpurl']; 748 } 749 750 // If FTP has not been enabled, set the value to 0 751 if (!isset($vars['ftpEnable'])) 752 { 753 $vars['ftpEnable'] = 0; 754 } 755 756 /* 757 * Trim the last slash from the FTP root, as the FTP root usually replaces JPATH_ROOT. 758 * If the path had a trailing slash, this would lead to double slashes, like "/joomla//configuration.php" 759 */ 760 if (isset($vars['ftpRoot'])) { 761 $vars['ftpRoot'] = rtrim($vars['ftpRoot'], '/'); 762 } 763 764 switch ($vars['DBtype']) { 765 766 case 'mssql' : 767 $vars['ZERO_DATE'] = '1/01/1990'; 768 break; 769 770 default : 771 $vars['ZERO_DATE'] = '0000-00-00 00:00:00'; 772 break; 773 } 774 775 JInstallationHelper::createAdminUser($vars); 776 777 /** 778 * Write the configuration file 779 */ 780 jimport('joomla.template.template'); 781 782 $tmpl = new JTemplate(); 783 $tmpl->applyInputFilter('ShortModifiers'); 784 785 // load the wrapper and common templates 786 $tmpl->setRoot( JPATH_BASE . DS . 'template' . DS. 'tmpl' ); 787 788 $tmpl->readTemplatesFromFile('configuration.html'); 789 $tmpl->addVars('configuration', $vars, 'var_'); 790 791 if (empty($vars['ftpSavePass'])) { 792 $tmpl->addVar('configuration', 'var_ftpuser', ''); 793 $tmpl->addVar('configuration', 'var_ftppassword', ''); 794 } 795 796 $buffer = $tmpl->getParsedTemplate('configuration'); 797 $path = JPATH_CONFIGURATION.DS.'configuration.php'; 798 799 if (file_exists($path)) { 800 $canWrite = is_writable($path); 801 } else { 802 $canWrite = is_writable(JPATH_CONFIGURATION.DS); 803 } 804 805 /* 806 * If the file exists but isn't writable OR if the file doesn't exist and the parent directory 807 * is not writable we need to use FTP 808 */ 809 $ftpFlag = false; 810 if ((file_exists($path) && !is_writable($path)) || (!file_exists($path) && !is_writable(dirname($path).'/'))) { 811 $ftpFlag = true; 812 } 813 814 // Check for safe mode 815 if (ini_get('safe_mode')) 816 { 817 $ftpFlag = true; 818 } 819 820 // Enable/Disable override 821 if (!isset($vars['ftpEnable']) || ($vars['ftpEnable'] != 1)) 822 { 823 $ftpFlag = false; 824 } 825 826 if ($ftpFlag == true) 827 { 828 // Connect the FTP client 829 jimport('joomla.client.ftp'); 830 jimport('joomla.filesystem.path'); 831 832 $ftp = & JFTP::getInstance($vars['ftpHost'], $vars['ftpPort']); 833 $ftp->login($vars['ftpUser'], $vars['ftpPassword']); 834 835 // Translate path for the FTP account 836 $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $vars['ftpRoot'], $path), '/'); 837 838 // Use FTP write buffer to file 839 if (!$ftp->write($file, $buffer)) { 840 $this->setData('buffer', $buffer); 841 return false; 842 } 843 844 $ftp->quit(); 845 846 } 847 else 848 { 849 if ($canWrite) { 850 file_put_contents($path, $buffer); 851 } else { 852 $this->setData('buffer', $buffer); 853 return true; 854 } 855 } 856 857 return true; 858 } 859 860 /** 861 * Set data for later use 862 * 863 * @param string $key Data key 864 * @param Mixed data 865 * @access public 866 * @since 1.5 867 */ 868 function setData($key, $value){ 869 $this->data[$key] = $value; 870 } 871 872 function dumpLoad() { 873 include (JPATH_BASE . '/includes/bigdump.php'); 874 } 875 876 function checkUpload() { 877 // pie 878 $vars = &$this->getVars(); 879 //print_r($vars); 880 881 $migratePath = JPATH_BASE . DS . 'sql' . DS . 'migration' . DS . 'migrate.sql'; 882 $sqlFile = JRequest::getVar('sqlFile', '', 'files', 'array'); 883 $package = false; 884 if (JRequest::getVar('sqlUploaded', 0, 'post', 'bool') == false) { 885 /* 886 * Move uploaded file 887 */ 888 // Set permissions for tmp dir 889 JInstallationHelper::_chmod(JPATH_SITE . DS . 'tmp', 0777); 890 jimport('joomla.filesystem.file'); 891 $uploaded = JFile::upload( 892 $sqlFile['tmp_name'], JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name'] 893 ); 894 if (!$uploaded) { 895 $this->setError(JText::_('WARNUPLOADFAILURE')); 896 return false; 897 } 898 899 if (preg_match('#\.sql$#i', $sqlFile['name'])) { 900 $script = JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name']; 901 } else { 902 $archive = JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name']; 903 } 904 905 // unpack archived sql files 906 if (isset($archive) && $archive) { 907 $package = JInstallationHelper::unpack($archive, $vars); 908 JFile::delete($archive); 909 if ($package === false) { 910 $this->setError(JText::_('WARNUNPACK')); 911 return false; 912 } 913 $script = $package['folder'] . DS . $package['script']; 914 // The archive has to unpack to a sql file 915 if (!preg_match('#\.sql$#i', $script)) { 916 // Remove the entire unpacked archive 917 JFolder::delete($package['folder']); 918 $this->setError(JText::_('WARNUNPACK')); 919 return false; 920 } 921 } 922 } else { 923 $script = $migratePath; 924 } 925 $migration = JRequest::getVar( 'migration', 0, 'post', 'bool' ); 926 /* 927 * If migration perform manipulations on script file before population 928 */ 929 if ($migration) { 930 $db = &JInstallationHelper::getDBO( 931 $vars['DBtype'], $vars['DBhostname'], $vars['DBuserName'], 932 $vars['DBpassword'], $vars['DBname'], $vars['DBPrefix'] 933 ); 934 $migrated = JInstallationHelper::preMigrate($script, $vars, $db); 935 if (!$migrated) { 936 if ($package) { 937 // Remove the entire unpacked archive 938 JFolder::delete($package['folder']); 939 } else { 940 // Just remove the script 941 JFile::delete($script); 942 } 943 $this->setError(JText::_('Script operations failed')); 944 return false; 945 } 946 $script = $migrated; 947 } // Disable in testing */ 948 // Ensure the script is always in the same location 949 if ($script != $migratePath) { 950 JFile::move($script, $migratePath); 951 } 952 if ($package) { 953 // Remove the entire unpacked archive 954 JFolder::delete($package['folder']); 955 } 956 //$this->setData('scriptpath',$script); 957 $vars['dataloaded'] = '1'; 958 $vars['loadchecked'] = '1'; 959 $vars['migration'] = $migration; 960 return true; 961 } 962 963 964 function postMigrate() { 965 $migErrors = null; 966 $args =& $this->getVars(); 967 $db = & JInstallationHelper::getDBO($args['DBtype'], $args['DBhostname'], $args['DBuserName'], $args['DBpassword'], $args['DBname'], $args['DBPrefix']); 968 $migResult = JInstallationHelper::postMigrate( $db, $migErrors, $args ); 969 // Clean up the migration SQL file 970 $migratePath = JPATH_BASE . DS . 'sql' . DS . 'migration' . DS . 'migrate.sql'; 971 jimport('joomla.filesystem.file'); 972 if (JFile::exists($migratePath)) { 973 JFile::delete($migratePath); 974 } 975 if ($migResult) { 976 echo '<div id="installer">'; 977 echo '<p>'.JText::_('Migration failed').':</p>'; 978 foreach($migErrors as $error) echo '<p>'.$error['msg'].'</p>'; 979 echo '</div>'; 980 } else { 981 echo JText::_("Migration Successful"); 982 } 983 return $migResult; 984 } 985 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |