| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.4 | 6 // +---------------------------------------------------------------------------+ 7 // | install.php | 8 // | | 9 // | Geeklog installation script. | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2000-2006 by the following authors: | 12 // | | 13 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | 14 // | Mark Limburg - mlimburg AT users DOT sourceforge DOT net | 15 // | Jason Whittenburg - jwhitten AT securitygeeks DOT com | 16 // | Dirk Haun - dirk AT haun-online DOT de | 17 // | Randy Kolenko - randy AT nextide DOT ca 18 // +---------------------------------------------------------------------------+ 19 // | | 20 // | This program is free software; you can redistribute it and/or | 21 // | modify it under the terms of the GNU General Public License | 22 // | as published by the Free Software Foundation; either version 2 | 23 // | of the License, or (at your option) any later version. | 24 // | | 25 // | This program is distributed in the hope that it will be useful, | 26 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 27 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 28 // | GNU General Public License for more details. | 29 // | | 30 // | You should have received a copy of the GNU General Public License | 31 // | along with this program; if not, write to the Free Software Foundation, | 32 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 33 // | | 34 // +---------------------------------------------------------------------------+ 35 // | You don't need to change anything in this file. | 36 // | Please read docs/install.html which describes how to install Geeklog. | 37 // +---------------------------------------------------------------------------+ 38 // 39 // $Id: install.php,v 1.92 2006/12/10 09:37:44 dhaun Exp $ 40 41 // this should help expose parse errors (e.g. in config.php) even when 42 // display_errors is set to Off in php.ini 43 if (function_exists ('ini_set')) { 44 ini_set ('display_errors', '1'); 45 } 46 error_reporting (E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR); 47 48 if (!defined ("LB")) { 49 define("LB", "\n"); 50 } 51 if (!defined ('VERSION')) { 52 define('VERSION', '1.4.1'); 53 } 54 55 56 /** 57 * Returns the PHP version 58 * 59 * Note: Removes appendices like 'rc1', etc. 60 * 61 * @return array the 3 separate parts of the PHP version number 62 * 63 */ 64 function php_v () 65 { 66 $phpv = explode ('.', phpversion ()); 67 68 return array ($phpv[0], $phpv[1], (int) $phpv[2]); 69 } 70 71 /** 72 * Returns the MySQL version 73 * 74 * @return array the 3 separate parts of the MySQL version number 75 * 76 */ 77 function mysql_v () 78 { 79 global $_DB_host, $_DB_user, $_DB_pass; 80 81 mysql_connect ($_DB_host, $_DB_user, $_DB_pass); 82 $mysqlv = ''; 83 84 // mysql_get_server_info() is only available as of PHP 4.0.5 85 $phpv = php_v (); 86 if (($phpv[0] > 4) || (($phpv[0] == 4) && ($phpv[1] > 0)) || 87 (($phpv[0] == 4) && ($phpv[1] == 0) && ($phpv[2] > 4))) { 88 $mysqlv = mysql_get_server_info(); 89 } 90 91 if (!empty ($mysqlv)) { 92 preg_match ('/^([0-9]+).([0-9]+).([0-9]+)/', $mysqlv, $match); 93 $mysqlmajorv = $match[1]; 94 $mysqlminorv = $match[2]; 95 $mysqlrev = $match[3]; 96 } else { 97 $mysqlmajorv = 0; 98 $mysqlminorv = 0; 99 $mysqlrev = 0; 100 } 101 mysql_close (); 102 103 return array ($mysqlmajorv, $mysqlminorv, $mysqlrev); 104 } 105 106 function installOption ($option_value, $option_name, $current_option) 107 { 108 $retval = '<option value="' . $option_value . '"'; 109 if ($option_value == $current_option) { 110 $retval .= ' selected="selected"'; 111 } 112 $retval .= '>' . $option_name . '</option>' . LB; 113 114 return $retval; 115 } 116 117 /** 118 * Shows welcome page and gets location of /path/to/geeklog/. NOTE: this 119 * Doesn't use the template class because we need to know the path to geeklog 120 * before we can include it. 121 * 122 */ 123 function INST_welcomePage() 124 { 125 global $_DB_dbms; 126 127 $retval = ''; 128 129 $retval .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . LB; 130 $retval .= '<html>' . LB; 131 $retval .= '<head>' . LB; 132 $retval .= '<title>Geeklog ' . VERSION . ' Installation</title>' . LB; 133 $retval .= '</head>' . LB; 134 $retval .= '<body>' . LB; 135 136 // check the minimum requirements 137 138 $phpv = php_v (); 139 if (($phpv[0] < 4) || (($phpv[0] == 4) && ($phpv[1] < 1))) { 140 $retval .= '<h1>PHP 4.1.0 required</h1>' . LB; 141 $retval .= '<p>Sorry, but Geeklog requires at least PHP 4.1.0 to run. Please upgrade your PHP install or ask your hosting service to do it for you.</p>' . LB; 142 $retval .= '</body>' . LB . '</html>' . LB; 143 144 return $retval; 145 } 146 147 if ($_DB_dbms == 'mysql') { 148 $myv = mysql_v (); 149 if (($myv[0] < 3) || (($myv[0] == 3) && ($myv[1] < 23)) || 150 (($myv[0] == 3) && ($myv[1] == 23) && ($myv[2] < 2))) { 151 $retval .= '<h1>MySQL 3.23.2 required</h1>' . LB; 152 $retval .= '<p>Sorry, but Geeklog requires at least MySQL 3.23.2 to run. Please upgrade your MySQL install or ask your hosting service to do it for you.</p>' . LB; 153 $retval .= '</body>' . LB . '</html>' . LB; 154 155 return $retval; 156 } 157 } 158 159 // prepare some hints about what /path/to/geeklog might be ... 160 $thisFile = __FILE__; 161 $thisFile = strtr ($thisFile, '\\', '/'); // replace all '\' with '/' 162 $glPath = $thisFile; 163 $posted = false; 164 for ($i = 0; $i < 4; $i++) { 165 $remains = strrchr ($glPath, '/'); 166 if ($remains === false) { 167 break; 168 } else { 169 $glPath = substr ($glPath, 0, -strlen ($remains)); 170 } 171 } 172 if (!file_exists ($glPath . '/config.php')) { 173 $glPath = ''; 174 } 175 if (empty ($glPath) && !empty ($_POST['geeklog_path'])) { 176 $glPath = $_POST['geeklog_path']; 177 $posted = true; 178 } 179 180 $retval .= '<h1>Geeklog Installation (Step 1 of 2)</h1>' . LB; 181 $retval .= '<p><strong>Welcome and thank you for choosing Geeklog.</strong> You are only 2 steps away from having Geeklog ' . VERSION . ' running on your system.</p>' . LB; 182 $retval .= "<p>If you haven't already done so, you should <strong>edit config.php prior to running this script</strong>. This script will then apply the database structures for both fresh installations and upgrades.</p>" . LB; 183 184 $retval .= '<h2>Upgrading</h2>' . LB; 185 $retval .= '<p>Before we get started it is important that if you are upgrading an existing Geeklog installation you back up your database AND your file system. <strong>This installation script will alter your Geeklog database.</strong> So if something goes wrong and you have to do the upgrade again, you will need a backup of your original database. <strong>YOU HAVE BEEN WARNED</strong>!</p>' . LB; 186 $retval .= '<p>Please make sure to select the correct Geeklog version you are coming from on the next screen. This script will do incremental upgrades after this version (i.e. you can upgrade directly from any old version to ' . VERSION . ').</p>' . LB; 187 $retval .= '<p>Please note this script will <strong>not upgrade</strong> any beta or release candidate versions of Geeklog.</p>' . LB; 188 189 $globals_off = false; 190 $long_arrays_off = false; 191 $public_html = false; 192 $warn_message = ''; 193 $help_message = ''; 194 195 if (strpos ($_SERVER['PHP_SELF'], 'public_html') !== false) { 196 $public_html = true; 197 } 198 199 if (!ini_get ('register_globals')) { 200 $globals_off = true; 201 $warn_message .= '<code>register_globals = Off</code>'; 202 $help_message .= '<code>register_globals = On</code>'; 203 } 204 205 $phpv = php_v (); 206 if (($phpv[0] >= 5) && !ini_get ('register_long_arrays')) { 207 $long_arrays_off = true; 208 if (!empty ($warn_message)) { 209 $warn_message .= ' and '; 210 } 211 $warn_message .= '<code>register_long_arrays = Off</code>'; 212 if (!empty ($help_message)) { 213 $help_message .= ' and '; 214 } 215 $help_message .= '<code>register_long_arrays = On</code>'; 216 } 217 218 if ($globals_off || $long_arrays_off || $public_html) { 219 $retval .= '<h2>Important Note</h2>' . LB; 220 221 if ($public_html) { 222 $retval .= '<p><strong>Note:</strong> "public_html" should never be part of your site\'s URL. Please read the part about public_html in the <a href="../../docs/install.html#public_html">installation instructions</a> again and change your setup accordingly before you proceed.</p>'; 223 } 224 225 if ($globals_off || $long_arrays_off) { 226 $retval .= '<p><strong>Note:</strong> You have ' 227 . $warn_message .' in your <tt>php.ini</tt>. While Geeklog itself will work just fine with that setting, some of the available plugins and add-ons may not. You may want to set ' 228 . $help_message . ' (and restart your webserver) if you plan to install any of those add-ons.</p>' . LB; 229 $retval .= '<p>If you don\'t know where your <tt>php.ini</tt> file is located, please <a href="info.php">click here</a>.</p>' . LB; 230 } 231 } 232 233 $retval .= '<h2>Installation Options</h2>' . LB; 234 $install_type = ''; 235 if (isset ($_POST['install_type'])) { 236 $install_type = $_POST['install_type']; 237 } 238 $install_options = ''; 239 $install_options .= installOption ('new_db', 'New MySQL Database', $install_type); 240 $install_options .= installOption ('new_mssql_db', 'New Microsoft SQL Server Database', $install_type); 241 $install_options .= installOption ('upgrade_db', 'Upgrade MySQL Database', $install_type); 242 243 $retval .= '<form action="install.php" method="POST">' . LB; 244 $retval .= '<table border="0" cellpadding="0" cellspacing="0" width="100%">' . LB; 245 $retval .= '<tr><td align="right">Installation Type: </td><td><select name="install_type">'. LB; 246 $retval .= $install_options; 247 $retval .= '</select></td></tr>'.LB; 248 $retval .= '<tr><td align="right">Path to Geeklog\'s config.php: </td><td><input type="text" name="geeklog_path" value="' . $glPath . '" size="40"></td></tr>'.LB; 249 $retval .= '<tr><td colspan="2" align="left"><p><br><strong>Hint:</strong> The complete path to this file is <b>' . $thisFile; 250 if (!empty ($glPath) && !$posted) { 251 $retval .= '</b><br>and it appears your Path to Geeklog is <b>' . $glPath; 252 } 253 $retval .= '</b></p></td></tr>'; 254 $retval .= '<tr><td colspan="2" align="center"><input type="submit" value="Next >>"></td></tr>' . LB; 255 $retval .= '</table>' . LB; 256 $retval .= '<input type="hidden" name="page" value="1">' . LB; 257 $retval .= '</form>' . LB; 258 $retval .= '</body>' . LB; 259 $retval .= '</html>' . LB; 260 261 return $retval; 262 } 263 264 function INST_identifyGeeklogVersion () 265 { 266 global $_TABLES, $_DB, $_DB_dbms; 267 268 $_DB->setDisplayError (true); 269 270 // simple tests for the version of the database: 271 // "DESCRIBE sometable somefield", '' 272 // => just test that the field exists 273 // "DESCRIBE sometable somefield", 'somefield,sometype' 274 // => test that the field exists and is of the given type 275 // 276 // Should always include a test for the current version so that we can 277 // warn the user if they try to run the update again. 278 279 $test = array( 280 '1.4.1' => array("SELECT ft_name FROM {$_TABLES['features']} WHERE ft_name = 'syndication.edit'", 'syndication.edit'), 281 '1.4.0' => array("DESCRIBE {$_TABLES['users']} remoteusername",''), 282 '1.3.11' => array("DESCRIBE {$_TABLES['comments']} sid", 'sid,varchar(40)'), 283 '1.3.10' => array("DESCRIBE {$_TABLES['comments']} lft",''), 284 '1.3.9' => array("DESCRIBE {$_TABLES['syndication']} fid",''), 285 '1.3.8' => array("DESCRIBE {$_TABLES['userprefs']} showonline",'') 286 287 // It's hard to (reliably) test for 1.3.7 - let's just hope nobody uses 288 // such an old version any more ... 289 ); 290 291 $version = ''; 292 293 if ($_DB_dbms == 'mysql') { 294 foreach ($test as $v => $qarray) { 295 $result = DB_query ($qarray[0], 1); 296 if ($result === false) { 297 // error - continue with next test 298 } else if (DB_numRows ($result) > 0) { 299 $A = DB_fetchArray ($result); 300 if (empty ($qarray[1])) { 301 // test only for existence of field - succeeded 302 $version = $v; 303 break; 304 } else { 305 if (substr ($qarray[0], 0, 6) == 'SELECT') { 306 // text for a certain value 307 if($A[0] == $qarray[1]) { 308 $version = $v; 309 break; 310 } 311 } else { 312 // test for certain type of field 313 $tst = explode (',', $qarray[1]); 314 315 if (($A['Field'] == $tst[0]) && ($A['Type'] == $tst[1])) { 316 $version = $v; 317 break; 318 } 319 } 320 } 321 } 322 } 323 } 324 325 return $version; 326 } 327 328 function INST_checkTableExists ($table) 329 { 330 global $_TABLES, $_DB_dbms; 331 332 $exists = false; 333 334 if ($_DB_dbms == 'mysql') { 335 $result = DB_query ("SHOW TABLES LIKE '{$_TABLES[$table]}'"); 336 if (DB_numRows ($result) > 0) { 337 $exists = true; 338 339 $display = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . LB; 340 $display .= '<html>' . LB; 341 $display .= '<head><title>Geeklog Installation - Error</title></head>' . LB; 342 $display .= '<body bgcolor="#ffffff">' . LB; 343 $display .= '<h2>Geeklog Installation - Error</h2>' . LB; 344 $display .= '<p>The Geeklog tables already exist in your database. This can be because of one of the following reasons:</p>' . LB; 345 $display .= '<ol>' . LB; 346 $display .= '<li>You already ran the install script before.<br>Please note that you don\'t have to run the install script again if you ran into a problem with your paths or URLs on a previous attempt. If, however, you want to run the install script again now, then please delete the tables from your database first (or drop the database and create it again).</li>' . LB; 347 $display .= '<li>You really want to upgrade your database (for a new Geeklog version) but forgot to select "Upgrade Database" from the drop-down menu on the initial screen.</li>' . LB; 348 $display .= '</ol>' . LB; 349 $display .= '<form action="install.php" method="POST">' . LB; 350 $display .= '<p align="center"><input type="submit" name="action" value="<< Back"><input type="hidden" name="geeklog_path" value="' . $_POST['geeklog_path'] . '"><input type="hidden" name="install_type" value="' . $_POST['install_type'] . '"></p>' . LB . '</form>'; 351 $display .= '</body>' . LB . '</html>'; 352 353 echo $display; 354 } 355 } 356 357 return $exists; 358 } 359 360 function INST_getDatabaseSettings($install_type, $geeklog_path) 361 { 362 global $_CONF, $_TABLES; 363 364 $db_templates = new Template ($_CONF['path_system'] . 'install_templates'); 365 $db_templates->set_file (array ('db' => 'databasesettings.tpl')); 366 $db_templates->set_var ('geeklog_path', $geeklog_path); 367 if (isset ($_POST['install_type'])) { 368 $db_templates->set_var ('install_type', $_POST['install_type']); 369 } else { 370 $db_templates->set_var ('install_type', ''); 371 } 372 373 if ($install_type == 'upgrade_db') { 374 $db_templates->set_var ('upgrade', 1); 375 376 $old_versions = array('1.2.5-1','1.3','1.3.1','1.3.2','1.3.2-1','1.3.3','1.3.4','1.3.5','1.3.6','1.3.7','1.3.8','1.3.9','1.3.10','1.3.11','1.4.0'); 377 378 $curv = INST_identifyGeeklogVersion (); 379 if (empty ($curv)) { 380 $curv = $old_versions[count ($old_versions) - 1]; 381 } 382 if ($curv == VERSION) { 383 $versiondd = '<tr><td align="left"><b>Database already up to date!</b>' . LB 384 . '<p>It looks like your database is already up to date. You probably ran the upgrade before. If you need to run the upgrade again, please re-install your database backup first!</td></tr>'; 385 $nextbutton = ''; 386 } else { 387 $versiondd = '<tr><td align="right"><b>Current Geeklog Version:</b></td><td><select name="version">'; 388 foreach ($old_versions as $version) { 389 $versiondd .= '<option'; 390 if ($version == $curv) { 391 $versiondd .= ' selected="selected"'; 392 } 393 $versiondd .= '>' . $version . '</option>'; 394 } 395 $versiondd .= '</select></td></tr>'; 396 $nextbutton = '<input type="submit" name="action" value="Next >>">'; 397 } 398 $db_templates->set_var ('UPGRADE_OPTIONS', $versiondd); 399 $db_templates->set_var ('DB_TABLE_OPTIONS', ''); 400 $db_templates->set_var ('NEXT_BUTTON', $nextbutton); 401 402 } else { 403 404 // pick off which database we're installing for! 405 if ($install_type == 'new_mssql_db') { 406 // This is a fresh SQL Server installation! 407 $db_templates->set_var ('upgrade', 0); 408 $db_templates->set_var ('UPGRADE_OPTIONS', 409 '<tr><td> </td></tr>'); 410 $nextbutton = '<input type="hidden" name="install_type" value="new_mssql_db"><input type="submit" name="action" value="Next >>">'; 411 $db_templates->set_var ('NEXT_BUTTON', $nextbutton); 412 } else { 413 // This is a fresh MySQL installation 414 $db_templates->set_var ('upgrade', 0); 415 416 if (innodb_supported ()) { 417 $innodb_option = '<tr><td align="left">'; 418 $innodb_option .= '<p>Using InnoDB tables may improve performance on (very) large sites, but makes database backups more complicated. Leave the option unchecked unless you know what you\'re doing.</p>'; 419 $innodb_option .= '<input type="checkbox" name="innodb"> Use InnoDB tables'; 420 $innodb_option .= '</td></tr>'; 421 $db_templates->set_var ('UPGRADE_OPTIONS', $innodb_option); 422 } else { 423 $db_templates->set_var ('UPGRADE_OPTIONS', 424 '<tr><td> </td></tr>'); 425 } 426 $nextbutton = '<input type="submit" name="action" value="Next >>">'; 427 $db_templates->set_var ('NEXT_BUTTON', $nextbutton); 428 } 429 } 430 431 return $db_templates->parse('output','db'); 432 } 433 434 function INST_createDatabaseStructures ($use_innodb = false) 435 { 436 global $_CONF, $_TABLES, $_DB, $_DB_dbms, $_DB_host, $_DB_user, $_DB_pass; 437 438 $_DB->setDisplayError (true); 439 440 // Because the create table syntax can vary from dbms-to-dbms we are 441 // leaving that up to each database driver (e.g. mysql.class.php, 442 // postgresql.class.php, etc) 443 444 // Get DBMS-specific create table array and data array 445 require_once ($_CONF['path'] . 'sql/' . $_DB_dbms . '_tableanddata.php'); 446 447 $progress = ''; 448 449 if (INST_checkTableExists ('access')) { 450 return false; 451 } 452 453 switch($_DB_dbms){ 454 case 'mysql': 455 foreach ($_SQL as $sql) { 456 if ($use_innodb) { 457 $sql = str_replace ('MyISAM', 'InnoDB', $sql); 458 } 459 460 DB_query ($sql); 461 } 462 if ($use_innodb) { 463 DB_query ("INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('database_engine', 'InnoDB')"); 464 } 465 break; 466 case 'mssql'; 467 foreach ($_SQL as $sql) { 468 DB_query ($sql); 469 } 470 break; 471 } 472 473 // Now insert mandatory data and a small subset of initial data 474 foreach ($_DATA as $data) { 475 $progress .= "executing " . $data . "<br>\n"; 476 DB_query ($data); 477 } 478 479 if ($_DB_dbms == 'mysql' || $_DB_dbms == 'mssql' ) { 480 481 // let's try and personalize the Admin account a bit ... 482 483 if (strpos ($_CONF['site_mail'], 'example.com') === false) { 484 DB_query ("UPDATE {$_TABLES['users']} SET email = '" . addslashes ($_CONF['site_mail']) . "' WHERE uid = 2"); 485 } 486 if (strpos ($_CONF['site_url'], 'example.com') === false) { 487 DB_query ("UPDATE {$_TABLES['users']} SET homepage = '" . addslashes ($_CONF['site_url']) . "' WHERE uid = 2"); 488 } 489 } 490 491 return true; 492 } 493 494 /** 495 * Check for InnoDB table support (usually as of MySQL 4.0, but may be 496 * available in earlier versions, e.g. "Max" or custom builds). 497 * 498 * @return true = InnoDB tables supported, false = not supported 499 * 500 */ 501 function innodb_supported() 502 { 503 $result = DB_query ("SHOW VARIABLES LIKE 'have_innodb'"); 504 $A = DB_fetchArray ($result, true); 505 506 if (strcasecmp ($A[1], 'yes') == 0) { 507 $retval = true; 508 } else { 509 $retval = false; 510 } 511 512 return $retval; 513 } 514 515 516 /* 517 * Checks for Static Pages Version 518 * 519 * @return 0 = not installed, 1 = original plugin, 2 = plugin by Phill or Tom, 3 = v1.3 (center block, etc.), 4 = 1.4 ('in block' flag) 520 * 521 */ 522 function get_SP_Ver() 523 { 524 global $_TABLES; 525 526 $retval = 0; 527 528 if (DB_count ($_TABLES['plugins'], 'pi_name', 'staticpages') > 0) { 529 $result = DB_query ("DESCRIBE {$_TABLES['staticpage']}"); 530 $numrows = DB_numRows ($result); 531 532 $retval = 1; // assume v1.1 for now ... 533 534 for ($i = 0; $i < $numrows; $i++) { 535 $A = DB_fetchArray ($result, true); 536 if ($A[0] == 'sp_nf') { 537 $retval = 3; // v1.3 538 } elseif ($A[0] == 'sp_pos') { 539 $retval = 2; // v1.2 540 } elseif ($A[0] == 'sp_inblock') { 541 $retval = 4; // v1.4 542 break; 543 } 544 } 545 } 546 547 return $retval; 548 } 549 550 /** 551 * Check if the SpamX plugin is already installed 552 * 553 * @return int 1 = is installed, 0 = not installed 554 * 555 */ 556 function get_SPX_Ver() 557 { 558 global $_TABLES; 559 560 $retval = 0; 561 562 if (DB_count ($_TABLES['plugins'], 'pi_name', 'spamx') == 1) { 563 $retval = 1; 564 } 565 566 return $retval; 567 } 568 569 function INST_doDatabaseUpgrades($current_gl_version) 570 { 571 global $_TABLES, $_CONF, $_SP_CONF, $_DB, $_DB_dbms, $_DB_table_prefix; 572 573 $_DB->setDisplayError (true); 574 575 // Because the upgrade sql syntax can vary from dbms-to-dbms we are 576 // leaving that up to each Geeklog database driver 577 578 $done = false; 579 $progress = ''; 580 while ($done == false) { 581 switch ($current_gl_version) { 582 case '1.2.5-1': 583 // Get DMBS-specific update sql 584 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.2.5-1_to_1.3.php'); 585 for ($i = 1; $i <= count($_SQL); $i++) { 586 $progress .= "executing " . current($_SQL) . "<br>\n"; 587 DB_query(current($_SQL)); 588 next($_SQL); 589 } 590 // OK, now we need to add all users except anonymous to the All Users group and Logged in users group 591 // I can hard-code these group numbers because the group table was JUST created with these numbers 592 $result = DB_query("SELECT uid FROM {$_TABLES['users']} WHERE uid <> 1"); 593 $nrows = DB_numRows($result); 594 for ($i = 1; $i <= $nrows; $i++) { 595 $U = DB_fetchArray($result); 596 DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES (2, {$U['uid']}, NULL)"); 597 DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES (13, {$U['uid']}, NULL)"); 598 } 599 // Now take care of any orphans off the user table...and let me curse MySQL lack for supporting foreign 600 // keys at this time ;-) 601 $result = DB_query("SELECT MAX(uid) FROM {$_TABLES['users']}"); 602 $ITEM = DB_fetchArray($result); 603 $max_uid = $ITEM[0]; 604 if (!empty($max_uid) AND $max_uid <> 0) { 605 DB_query("DELETE FROM {$_TABLES['userindex']} WHERE uid > $max_uid"); 606 DB_query("DELETE FROM {$_TABLES['userinfo']} WHERE uid > $max_uid"); 607 DB_query("DELETE FROM {$_TABLES['userprefs']} WHERE uid > $max_uid"); 608 DB_query("DELETE FROM {$_TABLES['usercomment']} WHERE uid > $max_uid"); 609 } 610 $current_gl_version = '1.3'; 611 $_SQL = ''; 612 break; 613 case '1.3': 614 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3_to_1.3.1.php'); 615 for ($i = 1; $i <= count($_SQL); $i++) { 616 $progress .= "executing " . current($_SQL) . "<br>\n"; 617 DB_query(current($_SQL)); 618 next($_SQL); 619 } 620 $current_gl_version = '1.3.1'; 621 $_SQL = ''; 622 break; 623 case '1.3.1': 624 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.1_to_1.3.2.php'); 625 for ($i = 1; $i <= count($_SQL); $i++) { 626 $progress .= "executing " . current($_SQL) . "<br>\n"; 627 DB_query(current($_SQL)); 628 next($_SQL); 629 } 630 $current_gl_version = '1.3.2-1'; 631 $_SQL = ''; 632 break; 633 case '1.3.2': 634 case '1.3.2-1': 635 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.2-1_to_1.3.3.php'); 636 for ($i = 1; $i <= count($_SQL); $i++) { 637 $progress .= "executing " . current($_SQL) . "<br>\n"; 638 DB_query(current($_SQL)); 639 next($_SQL); 640 } 641 // Now we need to switch how user blocks are stored. Right now we only store the blocks the 642 // user wants. This will switch it to store the ones they don't want which allows us to add 643 // new blocks and ensure they are shown to the user. 644 $result = DB_query("SELECT {$_TABLES['users']}.uid,boxes FROM {$_TABLES['users']},{$_TABLES['userindex']} WHERE boxes IS NOT NULL AND boxes <> '' AND {$_TABLES['users']}.uid = {$_TABLES['userindex']}.uid"); 645 $nrows = DB_numRows($result); 646 for ($i = 1; $i <= $nrows; $i++) { 647 $row = DB_fetchArray($result); 648 $ublocks = str_replace(' ',',',$row['boxes']); 649 $result2 = DB_query("SELECT bid,name FROM {$_TABLES['blocks']} WHERE bid NOT IN ($ublocks)"); 650 $newblocks = ''; 651 for ($x = 1; $x <= DB_numRows($result2); $x++) { 652 $curblock = DB_fetchArray($result2); 653 if ($curblock['name'] <> 'user_block' AND $curblock['name'] <> 'admin_block' AND $curblock['name'] <> 'section_block') { 654 $newblocks .= $curblock['bid']; 655 if ($x <> DB_numRows($result2)) { 656 $newblocks .= ' '; 657 } 658 } 659 } 660 DB_query("UPDATE {$_TABLES['userindex']} SET boxes = '$newblocks' WHERE uid = {$row['uid']}"); 661 } 662 $current_gl_version = '1.3.3'; 663 $_SQL = ''; 664 break; 665 case '1.3.3': 666 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.3_to_1.3.4.php'); 667 for ($i = 1; $i <= count($_SQL); $i++) { 668 DB_query(current($_SQL)); 669 next($_SQL); 670 } 671 672 $current_gl_version = '1.3.4'; 673 $_SQL = ''; 674 break; 675 case '1.3.4': 676 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.4_to_1.3.5.php'); 677 for ($i = 1; $i <= count($_SQL); $i++) { 678 DB_query(current($_SQL)); 679 next($_SQL); 680 } 681 $result = DB_query("SELECT ft_id FROM {$_TABLES['features']} WHERE ft_name = 'user.mail'"); 682 $row = DB_fetchArray($result); 683 $mail_ft = $row['ft_id']; 684 $result = DB_query("SELECT grp_id FROM {$_TABLES['groups']} WHERE grp_name = 'Mail Admin'"); 685 $row = DB_fetchArray($result); 686 $group_id = $row['grp_id']; 687 DB_query("INSERT INTO {$_TABLES['access']} (acc_grp_id, acc_ft_id) VALUES ($group_id, $mail_ft)"); 688 689 $current_gl_version = '1.3.5'; 690 $_SQL = ''; 691 break; 692 case '1.3.5': 693 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.5_to_1.3.6.php'); 694 for ($i = 1; $i <= count($_SQL); $i++) { 695 DB_query(current($_SQL)); 696 next($_SQL); 697 } 698 699 if (!empty ($_DB_table_prefix)) { 700 DB_query ("RENAME TABLE staticpage TO {$_TABLES['staticpage']}"); 701 } 702 703 $current_gl_version = '1.3.6'; 704 $_SQL = ''; 705 break; 706 case '1.3.6': 707 // fix wrong permissions value 708 DB_query ("UPDATE {$_TABLES['topics']} SET perm_anon = 2 WHERE perm_anon = 3"); 709 710 // check for existence of 'date' field in gl_links table 711 DB_query ("SELECT date FROM {$_TABLES['links']}", 1); 712 $dterr = DB_error (); 713 if (strpos ($dterr, 'date') > 0) { 714 DB_query ("ALTER TABLE {$_TABLES['links']} ADD date datetime default NULL"); 715 } 716 717 // Fix primary key so that more than one user can add an event 718 // to his/her personal calendar. 719 DB_query ("ALTER TABLE {$_TABLES['personal_events']} DROP PRIMARY KEY, ADD PRIMARY KEY (eid,uid)"); 720 721 $current_gl_version = '1.3.7'; 722 $_SQL = ''; 723 break; 724 case '1.3.7': 725 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.7_to_1.3.8.php'); 726 for ($i = 1; $i <= count($_SQL); $i++) { 727 DB_query(current($_SQL)); 728 next($_SQL); 729 } 730 731 // upgrade Static Pages plugin 732 $spversion = get_SP_ver (); 733 if ($spversion == 1) { // original version 734 DB_query ("ALTER TABLE {$_TABLES['staticpage']} " 735 . "ADD COLUMN group_id mediumint(8) unsigned DEFAULT '1'," 736 . "ADD COLUMN owner_id mediumint(8) unsigned DEFAULT '1'," 737 . "ADD COLUMN perm_owner tinyint(1) unsigned DEFAULT '3'," 738 . "ADD COLUMN perm_group tinyint(1) unsigned DEFAULT '2'," 739 . "ADD COLUMN perm_members tinyint(1) unsigned DEFAULT '2'," 740 . "ADD COLUMN perm_anon tinyint(1) unsigned DEFAULT '2'," 741 . "ADD COLUMN sp_php tinyint(1) unsigned DEFAULT '0'," 742 . "ADD COLUMN sp_nf tinyint(1) unsigned DEFAULT '0'," 743 . "ADD COLUMN sp_centerblock tinyint(1) unsigned NOT NULL default '0'," 744 . "ADD COLUMN sp_tid varchar(20) NOT NULL default 'none'," 745 . "ADD COLUMN sp_where tinyint(1) unsigned NOT NULL default '1'"); 746 DB_query ("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) VALUES ('staticpages.PHP','Ability to use PHP in static pages')"); 747 $php_id = DB_insertId (); 748 $group_id = DB_getItem ($_TABLES['groups'], 'grp_id', "grp_name = 'Static Page Admin'"); 749 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($php_id, $group_id)"); 750 } elseif ($spversion == 2) { // extended version by Phill or Tom 751 DB_query ("ALTER TABLE {$_TABLES['staticpage']} " 752 . "DROP COLUMN sp_pos," 753 . "DROP COLUMN sp_search_keywords," 754 . "ADD COLUMN sp_nf tinyint(1) unsigned DEFAULT '0'," 755 . "ADD COLUMN sp_centerblock tinyint(1) unsigned NOT NULL default '0'," 756 . "ADD COLUMN sp_tid varchar(20) NOT NULL default 'none'," 757 . "ADD COLUMN sp_where tinyint(1) unsigned NOT NULL default '1'"); 758 } 759 760 if ($spversion > 0) { 761 // update plugin version number 762 DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '1.3', pi_gl_version = '1.3.8' WHERE pi_name = 'staticpages'"); 763 764 // remove Static Pages 'lock' flag 765 DB_query ("DELETE FROM {$_TABLES['vars']} WHERE name = 'staticpages'"); 766 767 // remove Static Pages Admin group id 768 DB_query ("DELETE FROM {$_TABLES['vars']} WHERE name = 'sp_group_id'"); 769 770 if ($spversion == 1) { 771 $result = DB_query ("SELECT DISTINCT sp_uid FROM {$_TABLES['staticpage']}"); 772 $authors = DB_numRows ($result); 773 for ($i = 0; $i < $authors; $i++) { 774 $A = DB_fetchArray ($result); 775 DB_query ("UPDATE {$_TABLES['staticpage']} SET owner_id = '{$A['sp_uid']}' WHERE sp_uid = '{$A['sp_uid']}'"); 776 } 777 } 778 779 $result = DB_query ("SELECT sp_label FROM {$_TABLES['staticpage']} WHERE sp_title = 'Frontpage'"); 780 if (DB_numRows ($result) > 0) { 781 $A = DB_fetchArray ($result); 782 if ($A['sp_label'] == 'nonews') { 783 DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_centerblock = 1, sp_where = 0 WHERE sp_title = 'Frontpage'"); 784 } else if (!empty ($A['sp_label'])) { 785 DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_centerblock = 1, sp_title = '{$A['sp_label']}' WHERE sp_title = 'Frontpage'"); 786 } else { 787 DB_query ("UPDATE {$_TABLES['staticpage']} SET sp_centerblock = 1 WHERE sp_title = 'Frontpage'"); 788 } 789 } 790 } 791 792 $current_gl_version = '1.3.8'; 793 $_SQL = ''; 794 break; 795 case '1.3.8': 796 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.8_to_1.3.9.php'); 797 for ($i = 1; $i <= count($_SQL); $i++) { 798 DB_query(current($_SQL)); 799 next($_SQL); 800 } 801 802 $pos = strrpos ($_CONF['rdf_file'], '/'); 803 $filename = substr ($_CONF['rdf_file'], $pos + 1); 804 $sitename = addslashes ($_CONF['site_name']); 805 $siteslogan = addslashes ($_CONF['site_slogan']); 806 DB_query ("INSERT INTO {$_TABLES['syndication']} (title, description, limits, content_length, filename, charset, language, is_enabled, updated, update_info) VALUES ('{$sitename}', '{$siteslogan}', '{$_CONF['rdf_limit']}', {$_CONF['rdf_storytext']}, '{$filename}', '{$_CONF['default_charset']}', '{$_CONF['rdf_language']}', {$_CONF['backend']}, '0000-00-00 00:00:00', NULL)"); 807 808 // upgrade static pages plugin 809 $spversion = get_SP_ver (); 810 if ($spversion > 0) { 811 if ($spversion < 4) { 812 if (!isset ($_SP_CONF['in_block'])) { 813 $_SP_CONF['in_block'] = 1; 814 } else if ($_SP_CONF['in_block'] > 1) { 815 $_SP_CONF['in_block'] = 1; 816 } else if ($_SP_CONF['in_block'] < 0) { 817 $_SP_CONF['in_block'] = 0; 818 } 819 DB_query ("ALTER TABLE {$_TABLES['staticpage']} ADD COLUMN sp_inblock tinyint(1) unsigned DEFAULT '{$_SP_CONF['in_block']}'"); 820 } 821 DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '1.4', pi_gl_version = '1.3.9' WHERE pi_name = 'staticpages'"); 822 } 823 824 // recreate 'date' field for old links 825 $result = DB_query ("SELECT lid FROM {$_TABLES['links']} WHERE date IS NULL"); 826 $num = DB_numRows ($result); 827 if ($num > 0) { 828 for ($i = 0; $i < $num; $i++) { 829 $A = DB_fetchArray ($result); 830 831 $myyear = substr ($A['lid'], 0, 4); 832 $mymonth = substr ($A['lid'], 4, 2); 833 $myday = substr ($A['lid'], 6, 2); 834 $myhour = substr ($A['lid'], 8, 2); 835 $mymin = substr ($A['lid'], 10, 2); 836 $mysec = substr ($A['lid'], 12, 2); 837 838 $mtime = mktime ($myhour, $mymin, $mysec, 839 $mymonth, $myday, $myyear); 840 $date = date ("Y-m-d H:i:s", $mtime); 841 DB_query ("UPDATE {$_TABLES['links']} SET date = '$date' WHERE lid = '{$A['lid']}'"); 842 } 843 } 844 845 // remove unused entries left over from deleted groups 846 $result = DB_query ("SELECT grp_id FROM {$_TABLES['groups']}"); 847 $num = DB_numRows ($result); 848 $groups = array (); 849 for ($i = 0; $i < $num; $i++) { 850 $A = DB_fetchArray ($result); 851 $groups[] = $A['grp_id']; 852 } 853 $grouplist = '(' . implode (',', $groups) . ')'; 854 855 DB_query ("DELETE FROM {$_TABLES['group_assignments']} WHERE (ug_main_grp_id NOT IN $grouplist) OR (ug_grp_id NOT IN $grouplist)"); 856 857 $current_gl_version = '1.3.9'; 858 $_SQL = ''; 859 break; 860 case '1.3.9': 861 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.9_to_1.3.10.php'); 862 for ($i = 1; $i <= count($_SQL); $i++) { 863 DB_query(current($_SQL)); 864 next($_SQL); 865 } 866 commentsToPreorderTree(); 867 868 $result = DB_query ("SELECT sid,introtext,bodytext FROM {$_TABLES['stories']}"); 869 $numStories = DB_numRows ($result); 870 for ($i = 0; $i < $numStories; $i++) { 871 $A = DB_fetchArray ($result); 872 $related = addslashes (implode ("\n", UPDATE_extractLinks ($A['introtext'] . ' ' . $A['bodytext']))); 873 if (empty ($related)) { 874 DB_query ("UPDATE {$_TABLES['stories']} SET related = NULL WHERE sid = '{$A['sid']}'"); 875 } else { 876 DB_query ("UPDATE {$_TABLES['stories']} SET related = '$related' WHERE sid = '{$A['sid']}'"); 877 } 878 } 879 880 $spversion = get_SP_ver (); 881 if ($spversion > 0) { 882 // no database changes this time, but set new version number 883 DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '1.4.1', pi_gl_version = '1.3.10' WHERE pi_name = 'staticpages'"); 884 } 885 886 // install SpamX plugin 887 // (also handles updates from version 1.0) 888 install_spamx_plugin (); 889 890 $current_gl_version = '1.3.10'; 891 $_SQL = ''; 892 break; 893 case '1.3.10': 894 require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.10_to_1.3.11.php'); 895 for ($i = 1; $i <= count($_SQL); $i++) { 896 DB_query(current($_SQL)); 897 next($_SQL); 898 } 899 900 $current_gl_version = '1.3.11'; 901 $_SQL = ''; 902 break; 903 904 case '1.3.11': 905 require_once ($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.11_to_1.4.0.php'); 906 for ($i = 0; $i < count ($_SQL); $i++) { 907 DB_query (current ($_SQL)); 908 next ($_SQL); 909 } 910 911 upgrade_addFeature (); 912 upgrade_uniqueGroupNames (); 913 914 $current_gl_version = '1.4.0'; 915 $_SQL = ''; 916 break; 917 918 case '1.4.0': 919 require_once ($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.4.0_to_1.4.1.php'); 920 for ($i = 0; $i < count ($_SQL); $i++) { 921 DB_query (current ($_SQL)); 922 next ($_SQL); 923 } 924 925 upgrade_addSyndicationFeature (); 926 upgrade_ensureLastScheduledRunFlag (); 927 upgrade_plugins_141 (); 928 929 $current_gl_version = '1.4.1'; 930 $_SQL = ''; 931 break; 932 933 default: 934 $done = true; 935 } 936 } 937 938 // delete the security check flag on every update to force the user 939 // to run admin/sectest.php again 940 DB_delete ($_TABLES['vars'], 'name', 'security_check'); 941 942 return true; 943 } 944 945 // Main 946 if (isset ($_POST['page'])) { 947 $page = $_POST['page']; 948 } else { 949 $page = 0; 950 } 951 952 if (isset ($_POST['action']) && ($_POST['action'] == '<< Back')) { 953 $page = 0; 954 } 955 956 // If possible, load the config file so we can get current settings. If we 957 // can't then that means this is a fresh installation OR they want to start 958 // with our system defaults. 959 960 // Include template class if we got it 961 if ($page > 0) { 962 $geeklog_path = trim ($_POST['geeklog_path']); 963 $notapath = false; 964 if (!empty ($geeklog_path)) { 965 // do some sanity checks ... 966 967 if (strpos ($geeklog_path, 'http:') !== false) { 968 $notapath = true; 969 } 970 if (strpos ($geeklog_path, 'config.php') !== false) { 971 $pos = strpos ($geeklog_path, 'config.php'); 972 if ($pos + strlen ('config.php') == strlen ($geeklog_path)) { 973 // strip 'config.php' silently ... 974 $geeklog_path = substr ($geeklog_path, 0, $pos); 975 } 976 } 977 978 // silently fix the usual problems with slashes ... 979 $geeklog_path = str_replace ('\\', '/', $geeklog_path); 980 $geeklog_path = str_replace ('//', '/', $geeklog_path); 981 while (substr ($geeklog_path, -1) == '/') { 982 $geeklog_path = substr ($geeklog_path, 0, -1); 983 } 984 } 985 986 if (!$notapath && !empty ($geeklog_path) && file_exists ($geeklog_path . '/config.php')) { 987 require_once ($geeklog_path . '/system/classes/template.class.php'); 988 require_once ($geeklog_path . '/config.php'); 989 require_once ($geeklog_path . '/system/lib-database.php'); 990 } else { 991 $display = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . LB; 992 $display .= '<html>' . LB; 993 $display .= '<head><title>Geeklog Installation - Error</title></head>' . LB; 994 $display .= '<body bgcolor="#ffffff">' . LB; 995 $display .= '<h2>Geeklog Installation - Error</h2>' . LB; 996 if ($notapath) { 997 $display .= '<p><b>' . $_POST['geeklog_path'] . '</b> is not a path.<br>Please enter the path to where config.php can be found on your webserver\'s file system.</p>'; 998 } else { 999 $display .= '<p>Geeklog could not find config.php in the path you just entered: <b>' . $_POST['geeklog_path'] . '</b><br>' . LB; 1000 $display .= 'Please check this path and try again. Remember that you should be using absolute paths, starting at the root of your file system.</p>' . LB; 1001 } 1002 $display .= '<form action="install.php" method="POST">' . LB; 1003 $display .= '<p align="center"><input type="submit" name="action" value="<< Back"><input type="hidden" name="geeklog_path" value="' . $_POST['geeklog_path'] . '"><input type="hidden" name="install_type" value="' . $_POST['install_type'] . '"></p>' . LB . '</form>'; 1004 $display .= '</body>' . LB . '</html>'; 1005 echo $display; 1006 exit; 1007 } 1008 } 1009 1010 $display = ''; 1011 1012 switch ($page) { 1013 case 1: 1014 if ($_POST['install_type'] == 'complete_upgrade') { 1015 $upgrade = 1; 1016 } else { 1017 $upgrade = 0; 1018 } 1019 $display .= INST_getDatabaseSettings ($_POST['install_type'], 1020 $_POST['geeklog_path']); 1021 break; 1022 1023 case 2: 1024 if (!empty ($_POST['version'])) { 1025 if (INST_doDatabaseUpgrades ($_POST['version'])) { 1026 // Great, installation is complete 1027 // Done with installation...redirect to success page 1028 echo '<html><head><meta http-equiv="refresh" content="0; URL=' . $_CONF['site_admin_url'] . '/install/success.php"></head></html>'; 1029 } 1030 } else { 1031 $use_innodb = false; 1032 if (isset ($_POST['innodb']) && ($_POST['innodb'] == 'on')) { 1033 $use_innodb = true; 1034 } 1035 if ($_POST['install_type'] == 'new_mssql_db') { 1036 $use_innodb = false; 1037 } 1038 1039 if (INST_createDatabaseStructures ($use_innodb)) { 1040 // Done with installation...redirect to success page 1041 echo '<html><head><meta http-equiv="refresh" content="0; URL=' . $_CONF['site_admin_url'] . '/install/success.php"></head></html>'; 1042 // Great, installation is complete 1043 } 1044 } 1045 break; 1046 1047 default: 1048 // Ok, let's display a welcome page 1049 1050 $display .= INST_welcomePage(); 1051 1052 break; 1053 } 1054 1055 echo $display; 1056 1057 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|