| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: upgrade.php 5353 2011-02-15 14:24:00Z Tomm $ 10 */ 11 12 if(function_exists("unicode_decode")) 13 { 14 // Unicode extension introduced in 6.0 15 error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_STRICT); 16 } 17 elseif(defined("E_DEPRECATED")) 18 { 19 // E_DEPRECATED introduced in 5.3 20 error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE); 21 } 22 else 23 { 24 error_reporting(E_ALL & ~E_NOTICE); 25 } 26 27 define('MYBB_ROOT', dirname(dirname(__FILE__))."/"); 28 define("INSTALL_ROOT", dirname(__FILE__)."/"); 29 define("TIME_NOW", time()); 30 define('IN_MYBB', 1); 31 define("IN_UPGRADE", 1); 32 33 if(function_exists('date_default_timezone_set') && !ini_get('date.timezone')) 34 { 35 date_default_timezone_set('GMT'); 36 } 37 38 require_once MYBB_ROOT."inc/class_core.php"; 39 $mybb = new MyBB; 40 41 require_once MYBB_ROOT."inc/config.php"; 42 43 $orig_config = $config; 44 45 if(!is_array($config['database'])) 46 { 47 $config['database'] = array( 48 "type" => $config['dbtype'], 49 "database" => $config['database'], 50 "table_prefix" => $config['table_prefix'], 51 "hostname" => $config['hostname'], 52 "username" => $config['username'], 53 "password" => $config['password'], 54 "encoding" => $config['db_encoding'], 55 ); 56 } 57 $mybb->config = &$config; 58 59 // Include the files necessary for installation 60 require_once MYBB_ROOT."inc/class_timers.php"; 61 require_once MYBB_ROOT."inc/functions.php"; 62 require_once MYBB_ROOT."inc/class_xml.php"; 63 require_once MYBB_ROOT.'inc/class_language.php'; 64 65 $lang = new MyLanguage(); 66 $lang->set_path(MYBB_ROOT.'install/resources/'); 67 $lang->load('language'); 68 69 // If we're upgrading from an SQLite installation, make sure we still work. 70 if($config['database']['type'] == 'sqlite3' || $config['database']['type'] == 'sqlite2') 71 { 72 $config['database']['type'] = 'sqlite'; 73 } 74 75 require_once MYBB_ROOT."inc/db_{$config['database']['type']}.php"; 76 switch($config['database']['type']) 77 { 78 case "sqlite": 79 $db = new DB_SQLite; 80 break; 81 case "pgsql": 82 $db = new DB_PgSQL; 83 break; 84 case "mysqli": 85 $db = new DB_MySQLi; 86 break; 87 default: 88 $db = new DB_MySQL; 89 } 90 91 // Connect to Database 92 define('TABLE_PREFIX', $config['database']['table_prefix']); 93 $db->connect($config['database']); 94 $db->set_table_prefix(TABLE_PREFIX); 95 $db->type = $config['database']['type']; 96 97 // Load Settings 98 if(file_exists(MYBB_ROOT."inc/settings.php")) 99 { 100 require_once MYBB_ROOT."inc/settings.php"; 101 } 102 103 if(!file_exists(MYBB_ROOT."inc/settings.php") || !$settings) 104 { 105 if(function_exists('rebuild_settings')) 106 { 107 rebuild_settings(); 108 } 109 else 110 { 111 $options = array( 112 "order_by" => "title", 113 "order_dir" => "ASC" 114 ); 115 116 $query = $db->simple_select("settings", "value, name", "", $options); 117 while($setting = $db->fetch_array($query)) 118 { 119 $setting['value'] = str_replace("\"", "\\\"", $setting['value']); 120 $settings[$setting['name']] = $setting['value']; 121 } 122 } 123 } 124 125 $settings['wolcutoff'] = $settings['wolcutoffmins']*60; 126 $settings['bbname_orig'] = $settings['bbname']; 127 $settings['bbname'] = strip_tags($settings['bbname']); 128 129 // Fix for people who for some specify a trailing slash on the board URL 130 if(substr($settings['bburl'], -1) == "/") 131 { 132 $settings['bburl'] = my_substr($settings['bburl'], 0, -1); 133 } 134 135 $mybb->settings = &$settings; 136 $mybb->parse_cookies(); 137 138 require_once MYBB_ROOT."inc/class_datacache.php"; 139 $cache = new datacache; 140 141 // Load cache 142 $cache->cache(); 143 144 $mybb->cache = &$cache; 145 146 require_once MYBB_ROOT."inc/class_session.php"; 147 $session = new session; 148 $session->init(); 149 $mybb->session = &$session; 150 151 // Include the necessary contants for installation 152 $grouppermignore = array("gid", "type", "title", "description", "namestyle", "usertitle", "stars", "starimage", "image"); 153 $groupzerogreater = array("pmquota", "maxreputationsday", "attachquota"); 154 $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image"); 155 $fpermfields = array("canview", "candlattachments", "canpostthreads", "canpostreplys", "canpostattachments", "canratethreads", "caneditposts", "candeleteposts", "candeletethreads", "caneditattachments", "canpostpolls", "canvotepolls", "cansearch"); 156 157 // Include the installation resources 158 require_once INSTALL_ROOT."resources/output.php"; 159 $output = new installerOutput; 160 $output->script = "upgrade.php"; 161 $output->title = "MyBB Upgrade Wizard"; 162 163 if(file_exists("lock")) 164 { 165 $output->print_error($lang->locked); 166 } 167 else 168 { 169 if($mybb->input['action'] == "logout" && $mybb->user['uid']) 170 { 171 // Check session ID if we have one 172 if($mybb->input['logoutkey'] != $mybb->user['logoutkey']) 173 { 174 $output->print_error("Your user ID could not be verified to log you out. This may have been because a malicious Javascript was attempting to log you out automatically. If you intended to log out, please click the Log Out button at the top menu."); 175 } 176 177 my_unsetcookie("mybbuser"); 178 my_unsetcookie("sid"); 179 if($mybb->user['uid']) 180 { 181 $time = TIME_NOW; 182 $lastvisit = array( 183 "lastactive" => $time-900, 184 "lastvisit" => $time, 185 ); 186 $db->update_query("users", $lastvisit, "uid='".$mybb->user['uid']."'"); 187 $db->delete_query("sessions", "sid='".$session->sid."'"); 188 } 189 header("Location: upgrade.php"); 190 } 191 else if($mybb->input['action'] == "do_login" && $mybb->request_method == "post") 192 { 193 require_once MYBB_ROOT."inc/functions_user.php"; 194 195 if(!username_exists($mybb->input['username'])) 196 { 197 $output->print_error("The username you have entered appears to be invalid."); 198 } 199 $query = $db->simple_select("users", "uid,username,password,salt,loginkey", "username='".$db->escape_string($mybb->input['username'])."'", array('limit' => 1)); 200 $user = $db->fetch_array($query); 201 if(!$user['uid']) 202 { 203 $output->print_error("The username you have entered appears to be invalid."); 204 } 205 else 206 { 207 $user = validate_password_from_uid($user['uid'], $mybb->input['password'], $user); 208 if(!$user['uid']) 209 { 210 $output->print_error("The password you entered is incorrect. If you have forgotten your password, click <a href=\"../member.php?action=lostpw\">here</a>. Otherwise, go back and try again."); 211 } 212 } 213 214 $db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' AND sid != '".$session->sid."'"); 215 216 $newsession = array( 217 "uid" => $user['uid'] 218 ); 219 220 $db->update_query("sessions", $newsession, "sid='".$session->sid."'"); 221 222 // Temporarily set the cookie remember option for the login cookies 223 $mybb->user['remember'] = $user['remember']; 224 225 my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], null, true); 226 my_setcookie("sid", $session->sid, -1, true); 227 228 header("Location: ./upgrade.php"); 229 } 230 231 $output->steps = array($lang->upgrade); 232 233 if($mybb->user['uid'] == 0) 234 { 235 $output->print_header("Please Login", "errormsg", 0, 1); 236 237 $output->print_contents('<p>Please enter your username and password to begin the upgrade process. You must be a valid forum administrator to perform the upgrade.</p> 238 <form action="upgrade.php" method="post"> 239 <div class="border_wrapper"> 240 <table class="general" cellspacing="0"> 241 <thead> 242 <tr> 243 <th colspan="2" class="first last">Login</th> 244 </tr> 245 </thead> 246 <tbody> 247 <tr class="first"> 248 <td class="first">Username:</td> 249 <td class="last alt_col"><input type="text" class="textbox" name="username" size="25" maxlength="'.$mybb->settings['maxnamelength'].'" style="width: 200px;" /></td> 250 </tr> 251 <tr class="alt_row last"> 252 <td class="first">Password:<br /><small>Please note that passwords are case sensitive.</small></td> 253 <td class="last alt_col"><input type="password" class="textbox" name="password" size="25" style="width: 200px;" /></td> 254 </tr> 255 </tbody> 256 </table> 257 </div> 258 <div id="next_button"> 259 <input type="submit" class="submit_button" name="submit" value="Login" /> 260 <input type="hidden" name="action" value="do_login" /> 261 </div> 262 </form>'); 263 $output->print_footer(""); 264 265 exit; 266 } 267 else if($mybb->usergroup['cancp'] != 1 && $mybb->usergroup['cancp'] != 'yes') 268 { 269 $output->print_error("You do not have permissions to run this process. You need administrator permissions to be able to run the upgrade procedure.<br /><br />If you need to logout, please click <a href=\"upgrade.php?action=logout&logoutkey={$mybb->user['logoutkey']}\">here</a>. From there you will be able to log in again under your administrator account."); 270 } 271 272 if(!$mybb->input['action'] || $mybb->input['action'] == "intro") 273 { 274 $output->print_header(); 275 276 if($db->table_exists("upgrade_data")) 277 { 278 $db->drop_table("upgrade_data"); 279 } 280 $db->write_query("CREATE TABLE ".TABLE_PREFIX."upgrade_data ( 281 title varchar(30) NOT NULL, 282 contents text NOT NULL, 283 UNIQUE (title) 284 );"); 285 286 $dh = opendir(INSTALL_ROOT."resources"); 287 while(($file = readdir($dh)) !== false) 288 { 289 if(preg_match("#upgrade([0-9]+).php$#i", $file, $match)) 290 { 291 $upgradescripts[$match[1]] = $file; 292 $key_order[] = $match[1]; 293 } 294 } 295 closedir($dh); 296 natsort($key_order); 297 $key_order = array_reverse($key_order); 298 299 // Figure out which version we last updated from (as of 1.6) 300 $version_history = $cache->read("version_history"); 301 302 // If array is empty then we must be upgrading to 1.6 since that's when this feature was added 303 if(empty($version_history)) 304 { 305 $next_update_version = 17; // 16+1 306 } 307 else 308 { 309 $next_update_version = intval(end($version_history)+1); 310 } 311 312 foreach($key_order as $k => $key) 313 { 314 $file = $upgradescripts[$key]; 315 $upgradescript = file_get_contents(INSTALL_ROOT."resources/$file"); 316 preg_match("#Upgrade Script:(.*)#i", $upgradescript, $verinfo); 317 preg_match("#upgrade([0-9]+).php$#i", $file, $keynum); 318 if(trim($verinfo[1])) 319 { 320 if($keynum[1] == $next_update_version) 321 { 322 $vers .= "<option value=\"$keynum[1]\" selected=\"selected\">$verinfo[1]</option>\n"; 323 } 324 else 325 { 326 $vers .= "<option value=\"$keynum[1]\">$verinfo[1]</option>\n"; 327 } 328 } 329 } 330 unset($upgradescripts); 331 unset($upgradescript); 332 333 $output->print_contents($lang->sprintf($lang->upgrade_welcome, $mybb->version)."<p><select name=\"from\">$vers</select>".$lang->upgrade_send_stats); 334 $output->print_footer("doupgrade"); 335 } 336 elseif($mybb->input['action'] == "doupgrade") 337 { 338 add_upgrade_store("allow_anonymous_info", intval($mybb->input['allow_anonymous_info'])); 339 require_once INSTALL_ROOT."resources/upgrade".intval($mybb->input['from']).".php"; 340 if($db->table_exists("datacache") && $upgrade_detail['requires_deactivated_plugins'] == 1 && $mybb->input['donewarning'] != "true") 341 { 342 require_once MYBB_ROOT."inc/class_datacache.php"; 343 $cache = new datacache; 344 $plugins = $cache->read('plugins', true); 345 if(!empty($plugins['active'])) 346 { 347 $output->print_header(); 348 $lang->plugin_warning = "<input type=\"hidden\" name=\"from\" value=\"".intval($mybb->input['from'])."\" />\n<input type=\"hidden\" name=\"donewarning\" value=\"true\" />\n<div class=\"error\"><strong><span style=\"color: red\">Warning:</span></strong> <p>There are still ".count($plugins['active'])." plugin(s) active. Active plugins can sometimes cause problems during an upgrade procedure or may break your forum afterward. It is <strong>strongly</strong> reccommended that you deactivate your plugins before continuing.</p></div> <br />"; 349 $output->print_contents($lang->sprintf($lang->plugin_warning, $mybb->version)); 350 $output->print_footer("doupgrade"); 351 } 352 else 353 { 354 add_upgrade_store("startscript", $mybb->input['from']); 355 $runfunction = next_function($mybb->input['from']); 356 } 357 } 358 else 359 { 360 add_upgrade_store("startscript", $mybb->input['from']); 361 $runfunction = next_function($mybb->input['from']); 362 } 363 } 364 $currentscript = get_upgrade_store("currentscript"); 365 $system_upgrade_detail = get_upgrade_store("upgradedetail"); 366 367 if($mybb->input['action'] == "templates") 368 { 369 $runfunction = "upgradethemes"; 370 } 371 elseif($mybb->input['action'] == "rebuildsettings") 372 { 373 $runfunction = "buildsettings"; 374 } 375 elseif($mybb->input['action'] == "buildcaches") 376 { 377 $runfunction = "buildcaches"; 378 } 379 elseif($mybb->input['action'] == "finished") 380 { 381 $runfunction = "upgradedone"; 382 } 383 else // Busy running modules, come back later 384 { 385 $bits = explode("_", $mybb->input['action'], 2); 386 if($bits[1]) // We're still running a module 387 { 388 $from = $bits[0]; 389 $runfunction = next_function($bits[0], $bits[1]); 390 391 } 392 } 393 394 // Fetch current script we're in 395 if(function_exists($runfunction)) 396 { 397 $runfunction(); 398 } 399 } 400 401 function upgradethemes() 402 { 403 global $output, $db, $system_upgrade_detail, $lang, $mybb; 404 405 $output->print_header($lang->upgrade_templates_reverted); 406 407 $charset = $db->build_create_table_collation(); 408 409 if($system_upgrade_detail['revert_all_templates'] > 0) 410 { 411 $db->drop_table("templates"); 412 $db->write_query("CREATE TABLE ".TABLE_PREFIX."templates ( 413 tid int unsigned NOT NULL auto_increment, 414 title varchar(120) NOT NULL default '', 415 template text NOT NULL, 416 sid int(10) NOT NULL default '0', 417 version varchar(20) NOT NULL default '0', 418 status varchar(10) NOT NULL default '', 419 dateline int(10) NOT NULL default '0', 420 PRIMARY KEY (tid) 421 ) ENGINE=MyISAM{$charset};"); 422 } 423 424 if($system_upgrade_detail['revert_all_themes'] > 0) 425 { 426 $db->drop_table("themes"); 427 $db->write_query("CREATE TABLE ".TABLE_PREFIX."themes ( 428 tid smallint unsigned NOT NULL auto_increment, 429 name varchar(100) NOT NULL default '', 430 pid smallint unsigned NOT NULL default '0', 431 def smallint(1) NOT NULL default '0', 432 properties text NOT NULL, 433 stylesheets text NOT NULL, 434 allowedgroups text NOT NULL, 435 PRIMARY KEY (tid) 436 ) ENGINE=MyISAM{$charset};"); 437 438 $db->drop_table("themestylesheets"); 439 $db->write_query("CREATE TABLE ".TABLE_PREFIX."themestylesheets( 440 sid int unsigned NOT NULL auto_increment, 441 name varchar(30) NOT NULL default '', 442 tid int unsigned NOT NULL default '0', 443 attachedto text NOT NULL, 444 stylesheet text NOT NULL, 445 cachefile varchar(100) NOT NULL default '', 446 lastmodified bigint(30) NOT NULL default '0', 447 PRIMARY KEY(sid) 448 ) ENGINE=MyISAM{$charset};"); 449 450 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 451 if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php")) 452 { 453 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"; 454 } 455 else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php")) 456 { 457 require_once MYBB_ROOT."admin/inc/functions_themes.php"; 458 } 459 else 460 { 461 $output->print_error("Please make sure your admin directory is uploaded correctly."); 462 } 463 import_theme_xml($contents, array("templateset" => -2, "no_templates" => 1, "version_compat" => 1)); 464 $tid = build_new_theme("Default", null, 1); 465 466 $db->update_query("themes", array("def" => 1), "tid='{$tid}'"); 467 $db->update_query("users", array('style' => $tid)); 468 $db->update_query("forums", array('style' => 0)); 469 470 $db->drop_table("templatesets"); 471 $db->write_query("CREATE TABLE ".TABLE_PREFIX."templatesets ( 472 sid smallint unsigned NOT NULL auto_increment, 473 title varchar(120) NOT NULL default '', 474 PRIMARY KEY (sid) 475 ) ENGINE=MyISAM{$charset};"); 476 477 $db->insert_query("templatesets", array('title' => 'Default Templates')); 478 } 479 else 480 { 481 // Re-import master 482 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 483 if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php")) 484 { 485 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"; 486 } 487 else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php")) 488 { 489 require_once MYBB_ROOT."admin/inc/functions_themes.php"; 490 } 491 else 492 { 493 $output->print_error(); 494 } 495 496 // Import master theme 497 import_theme_xml($contents, array("tid" => 1, "no_templates" => 1, "version_compat" => 1)); 498 } 499 500 $sid = -2; 501 502 // Now deal with the master templates 503 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 504 $parser = new XMLParser($contents); 505 $tree = $parser->get_tree(); 506 507 $theme = $tree['theme']; 508 509 if(is_array($theme['templates'])) 510 { 511 $templates = $theme['templates']['template']; 512 foreach($templates as $template) 513 { 514 $templatename = $db->escape_string($template['attributes']['name']); 515 $templateversion = intval($template['attributes']['version']); 516 $templatevalue = $db->escape_string($template['value']); 517 $time = TIME_NOW; 518 $query = $db->simple_select("templates", "tid", "sid='-2' AND title='".$db->escape_string($templatename)."'"); 519 $oldtemp = $db->fetch_array($query); 520 if($oldtemp['tid']) 521 { 522 $update_array = array( 523 'template' => $templatevalue, 524 'version' => $templateversion, 525 'dateline' => $time 526 ); 527 $db->update_query("templates", $update_array, "title='".$db->escape_string($templatename)."' AND sid='-2'"); 528 } 529 else 530 { 531 $insert_array = array( 532 'title' => $templatename, 533 'template' => $templatevalue, 534 'sid' => $sid, 535 'version' => $templateversion, 536 'dateline' => $time 537 ); 538 539 $db->insert_query("templates", $insert_array); 540 ++$newcount; 541 } 542 } 543 } 544 545 $output->print_contents($lang->upgrade_templates_reverted_success); 546 $output->print_footer("rebuildsettings"); 547 } 548 549 function buildsettings() 550 { 551 global $db, $output, $system_upgrade_detail, $lang; 552 553 if(!is_writable(MYBB_ROOT."inc/settings.php")) 554 { 555 $output->print_header("Rebuilding Settings"); 556 echo "<p><div class=\"error\"><span style=\"color: red; font-weight: bold;\">Error: Unable to open inc/settings.php</span><h3>Before the upgrade process can continue, you need to changes the permissions of inc/settings.php so it is writable.</h3></div></p>"; 557 $output->print_footer("rebuildsettings"); 558 exit; 559 } 560 $synccount = sync_settings($system_upgrade_detail['revert_all_settings']); 561 562 $output->print_header($lang->upgrade_settings_sync); 563 $output->print_contents($lang->sprintf($lang->upgrade_settings_sync_success, $synccount[1], $synccount[0])); 564 $output->print_footer("buildcaches"); 565 } 566 567 function buildcaches() 568 { 569 global $db, $output, $cache, $lang, $mybb; 570 571 $output->print_header($lang->upgrade_datacache_building); 572 573 $contents .= $lang->upgrade_building_datacache; 574 require_once MYBB_ROOT."inc/class_datacache.php"; 575 $cache = new datacache; 576 $cache->update_version(); 577 $cache->update_attachtypes(); 578 $cache->update_smilies(); 579 $cache->update_badwords(); 580 $cache->update_usergroups(); 581 $cache->update_forumpermissions(); 582 $cache->update_stats(); 583 $cache->update_moderators(); 584 $cache->update_forums(); 585 $cache->update_usertitles(); 586 $cache->update_reportedposts(); 587 $cache->update_mycode(); 588 $cache->update_posticons(); 589 $cache->update_update_check(); 590 $cache->update_tasks(); 591 $cache->update_spiders(); 592 $cache->update_bannedips(); 593 $cache->update_banned(); 594 $cache->update_birthdays(); 595 $cache->update_most_replied_threads(); 596 $cache->update_most_viewed_threads(); 597 $cache->update_groupleaders(); 598 $cache->update_threadprefixes(); 599 $cache->update_forumsdisplay(); 600 601 $contents .= $lang->done."</p>"; 602 603 $output->print_contents("$contents<p>".$lang->upgrade_continue."</p>"); 604 $output->print_footer("finished"); 605 } 606 607 function upgradedone() 608 { 609 global $db, $output, $mybb, $lang, $config; 610 611 ob_start(); 612 $output->print_header("Upgrade Complete"); 613 614 $allow_anonymous_info = get_upgrade_store("allow_anonymous_info"); 615 if($allow_anonymous_info == 1) 616 { 617 require_once MYBB_ROOT."inc/functions_serverstats.php"; 618 $build_server_stats = build_server_stats(0, '', $mybb->version_code, $mybb->config['database']['encoding']); 619 620 if($build_server_stats['info_sent_success'] == false) 621 { 622 echo $build_server_stats['info_image']; 623 } 624 } 625 ob_end_flush(); 626 627 if(is_writable("./")) 628 { 629 $lock = @fopen("./lock", "w"); 630 $written = @fwrite($lock, "1"); 631 @fclose($lock); 632 if($written) 633 { 634 $lock_note = $lang->sprintf($lang->upgrade_locked, $config['admin_dir']); 635 } 636 } 637 if(!$written) 638 { 639 $lock_note = "<p><b><span style=\"color: red;\">".$lang->upgrade_removedir."</span></b></p>"; 640 } 641 642 // Rebuild inc/settings.php at the end of the upgrade 643 if(function_exists('rebuild_settings')) 644 { 645 rebuild_settings(); 646 } 647 else 648 { 649 $options = array( 650 "order_by" => "title", 651 "order_dir" => "ASC" 652 ); 653 654 $query = $db->simple_select("settings", "value, name", "", $options); 655 while($setting = $db->fetch_array($query)) 656 { 657 $setting['value'] = str_replace("\"", "\\\"", $setting['value']); 658 $settings[$setting['name']] = $setting['value']; 659 } 660 } 661 662 $output->print_contents($lang->sprintf($lang->upgrade_congrats, $mybb->version, $lock_note)); 663 $output->print_footer(); 664 } 665 666 function whatsnext() 667 { 668 global $output, $db, $system_upgrade_detail, $lang; 669 670 if($system_upgrade_detail['revert_all_templates'] > 0) 671 { 672 $output->print_header($lang->upgrade_template_reversion); 673 $output->print_contents($lang->upgrade_template_reversion_success); 674 $output->print_footer("templates"); 675 } 676 else 677 { 678 upgradethemes(); 679 } 680 } 681 682 function next_function($from, $func="dbchanges") 683 { 684 global $oldvers, $system_upgrade_detail, $currentscript, $cache; 685 686 load_module("upgrade".$from.".php"); 687 if(function_exists("upgrade".$from."_".$func)) 688 { 689 $function = "upgrade".$from."_".$func; 690 } 691 else 692 { 693 // We're done with our last upgrade script, so add it to the upgrade scripts we've already completed. 694 $version_history = $cache->read("version_history"); 695 $version_history[$from] = $from; 696 $cache->update("version_history", $version_history); 697 698 $from = $from+1; 699 if(file_exists(INSTALL_ROOT."resources/upgrade".$from.".php")) 700 { 701 $function = next_function($from); 702 } 703 } 704 705 if(!$function) 706 { 707 $function = "whatsnext"; 708 } 709 return $function; 710 } 711 712 function load_module($module) 713 { 714 global $system_upgrade_detail, $currentscript, $upgrade_detail; 715 716 require_once INSTALL_ROOT."resources/".$module; 717 if($currentscript != $module) 718 { 719 foreach($upgrade_detail as $key => $val) 720 { 721 if(!$system_upgrade_detail[$key] || $val > $system_upgrade_detail[$key]) 722 { 723 $system_upgrade_detail[$key] = $val; 724 } 725 } 726 add_upgrade_store("upgradedetail", $system_upgrade_detail); 727 add_upgrade_store("currentscript", $module); 728 } 729 } 730 731 function get_upgrade_store($title) 732 { 733 global $db; 734 735 $query = $db->simple_select("upgrade_data", "*", "title='".$db->escape_string($title)."'"); 736 $data = $db->fetch_array($query); 737 return unserialize($data['contents']); 738 } 739 740 function add_upgrade_store($title, $contents) 741 { 742 global $db; 743 744 $replace_array = array( 745 "title" => $db->escape_string($title), 746 "contents" => $db->escape_string(serialize($contents)) 747 ); 748 $db->replace_query("upgrade_data", $replace_array, "title"); 749 } 750 751 function sync_settings($redo=0) 752 { 753 global $db; 754 755 $settingcount = $groupcount = 0; 756 $settings = $settinggroups = array(); 757 if($redo == 2) 758 { 759 $db->drop_table("settinggroups"); 760 switch($db->type) 761 { 762 case "pgsql": 763 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 764 gid serial, 765 name varchar(100) NOT NULL default '', 766 title varchar(220) NOT NULL default '', 767 description text NOT NULL default '', 768 disporder smallint NOT NULL default '0', 769 isdefault int NOT NULL default '0', 770 PRIMARY KEY (gid) 771 );"); 772 break; 773 case "sqlite": 774 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 775 gid INTEGER PRIMARY KEY, 776 name varchar(100) NOT NULL default '', 777 title varchar(220) NOT NULL default '', 778 description TEXT NOT NULL, 779 disporder smallint NOT NULL default '0', 780 isdefault int(1) NOT NULL default '0' 781 );"); 782 break; 783 case "mysql": 784 default: 785 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 786 gid smallint unsigned NOT NULL auto_increment, 787 name varchar(100) NOT NULL default '', 788 title varchar(220) NOT NULL default '', 789 description text NOT NULL, 790 disporder smallint unsigned NOT NULL default '0', 791 isdefault int(1) NOT NULL default '0', 792 PRIMARY KEY (gid) 793 ) ENGINE=MyISAM;"); 794 } 795 796 $db->drop_table("settings"); 797 798 switch($db->type) 799 { 800 case "pgsql": 801 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 802 sid serial, 803 name varchar(120) NOT NULL default '', 804 title varchar(120) NOT NULL default '', 805 description text NOT NULL default '', 806 optionscode text NOT NULL default '', 807 value text NOT NULL default '', 808 disporder smallint NOT NULL default '0', 809 gid smallint NOT NULL default '0', 810 isdefault int NOT NULL default '0', 811 PRIMARY KEY (sid) 812 );"); 813 break; 814 case "sqlite": 815 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 816 sid INTEGER PRIMARY KEY, 817 name varchar(120) NOT NULL default '', 818 title varchar(120) NOT NULL default '', 819 description TEXT NOT NULL, 820 optionscode TEXT NOT NULL, 821 value TEXT NOT NULL, 822 disporder smallint NOT NULL default '0', 823 gid smallint NOT NULL default '0', 824 isdefault int(1) NOT NULL default '0' 825 );"); 826 break; 827 case "mysql": 828 default: 829 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 830 sid smallint unsigned NOT NULL auto_increment, 831 name varchar(120) NOT NULL default '', 832 title varchar(120) NOT NULL default '', 833 description text NOT NULL, 834 optionscode text NOT NULL, 835 value text NOT NULL, 836 disporder smallint unsigned NOT NULL default '0', 837 gid smallint unsigned NOT NULL default '0', 838 isdefault int(1) NOT NULL default '0', 839 PRIMARY KEY (sid) 840 ) ENGINE=MyISAM;"); 841 } 842 } 843 else 844 { 845 if($db->type == "mysql" || $db->type == "mysqli") 846 { 847 $wheresettings = "isdefault='1' OR isdefault='yes'"; 848 } 849 else 850 { 851 $wheresettings = "isdefault='1'"; 852 } 853 854 $query = $db->simple_select("settinggroups", "name,title,gid", $wheresettings); 855 while($group = $db->fetch_array($query)) 856 { 857 $settinggroups[$group['name']] = $group['gid']; 858 } 859 860 // Collect all the user's settings - regardless of 'defaultivity' - we'll check them all 861 // against default settings and insert/update them accordingly 862 $query = $db->simple_select("settings", "name,sid"); 863 while($setting = $db->fetch_array($query)) 864 { 865 $settings[$setting['name']] = $setting['sid']; 866 } 867 } 868 $settings_xml = file_get_contents(INSTALL_ROOT."resources/settings.xml"); 869 $parser = new XMLParser($settings_xml); 870 $parser->collapse_dups = 0; 871 $tree = $parser->get_tree(); 872 $settinggroupnames = array(); 873 $settingnames = array(); 874 875 foreach($tree['settings'][0]['settinggroup'] as $settinggroup) 876 { 877 $settinggroupnames[] = $settinggroup['attributes']['name']; 878 879 $groupdata = array( 880 "name" => $db->escape_string($settinggroup['attributes']['name']), 881 "title" => $db->escape_string($settinggroup['attributes']['title']), 882 "description" => $db->escape_string($settinggroup['attributes']['description']), 883 "disporder" => intval($settinggroup['attributes']['disporder']), 884 "isdefault" => $settinggroup['attributes']['isdefault'] 885 ); 886 if(!$settinggroups[$settinggroup['attributes']['name']] || $redo == 2) 887 { 888 $gid = $db->insert_query("settinggroups", $groupdata); 889 ++$groupcount; 890 } 891 else 892 { 893 $gid = $settinggroups[$settinggroup['attributes']['name']]; 894 $db->update_query("settinggroups", $groupdata, "gid='{$gid}'"); 895 } 896 897 if(!$gid) 898 { 899 continue; 900 } 901 902 foreach($settinggroup['setting'] as $setting) 903 { 904 $settingnames[] = $setting['attributes']['name']; 905 906 $settingdata = array( 907 "name" => $db->escape_string($setting['attributes']['name']), 908 "title" => $db->escape_string($setting['title'][0]['value']), 909 "description" => $db->escape_string($setting['description'][0]['value']), 910 "optionscode" => $db->escape_string($setting['optionscode'][0]['value']), 911 "disporder" => intval($setting['disporder'][0]['value']), 912 "gid" => $gid, 913 "isdefault" => 1 914 ); 915 if(!$settings[$setting['attributes']['name']] || $redo == 2) 916 { 917 $settingdata['value'] = $db->escape_string($setting['settingvalue'][0]['value']); 918 $db->insert_query("settings", $settingdata); 919 $settingcount++; 920 } 921 else 922 { 923 $name = $db->escape_string($setting['attributes']['name']); 924 $db->update_query("settings", $settingdata, "name='{$name}'"); 925 } 926 } 927 } 928 929 if($redo >= 1) 930 { 931 require MYBB_ROOT."inc/settings.php"; 932 foreach($settings as $key => $val) 933 { 934 $db->update_query("settings", array('value' => $db->escape_string($val)), "name='".$db->escape_string($key)."'"); 935 } 936 } 937 unset($settings); 938 $query = $db->simple_select("settings", "*", "", array('order_by' => 'title')); 939 while($setting = $db->fetch_array($query)) 940 { 941 $setting['value'] = str_replace("\"", "\\\"", $setting['value']); 942 $settings .= "\$settings['{$setting['name']}'] = \"".$setting['value']."\";\n"; 943 } 944 $settings = "<?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n?>"; 945 $file = fopen(MYBB_ROOT."inc/settings.php", "w"); 946 fwrite($file, $settings); 947 fclose($file); 948 return array($groupcount, $settingcount); 949 } 950 951 function sync_tasks($redo=0) 952 { 953 global $db; 954 955 $taskcount = 0; 956 $tasks = array(); 957 if($redo == 2) 958 { 959 $db->drop_table("tasks"); 960 switch($db->type) 961 { 962 case "pgsql": 963 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 964 tid serial, 965 title varchar(120) NOT NULL default '', 966 description text NOT NULL default '', 967 file varchar(30) NOT NULL default '', 968 minute varchar(200) NOT NULL default '', 969 hour varchar(200) NOT NULL default '', 970 day varchar(100) NOT NULL default '', 971 month varchar(30) NOT NULL default '', 972 weekday varchar(15) NOT NULL default '', 973 nextrun bigint NOT NULL default '0', 974 lastrun bigint NOT NULL default '0', 975 enabled int NOT NULL default '1', 976 logging int NOT NULL default '0', 977 locked bigint NOT NULL default '0', 978 PRIMARY KEY(tid) 979 );"); 980 break; 981 case "sqlite": 982 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 983 tid INTEGER PRIMARY KEY, 984 title varchar(120) NOT NULL default '', 985 description TEXT NOT NULL, 986 file varchar(30) NOT NULL default '', 987 minute varchar(200) NOT NULL default '', 988 hour varchar(200) NOT NULL default '', 989 day varchar(100) NOT NULL default '', 990 month varchar(30) NOT NULL default '', 991 weekday varchar(15) NOT NULL default '', 992 nextrun bigint(30) NOT NULL default '0', 993 lastrun bigint(30) NOT NULL default '0', 994 enabled int(1) NOT NULL default '1', 995 logging int(1) NOT NULL default '0', 996 locked bigint(30) NOT NULL default '0' 997 );"); 998 break; 999 case "mysql": 1000 default: 1001 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 1002 tid int unsigned NOT NULL auto_increment, 1003 title varchar(120) NOT NULL default '', 1004 description text NOT NULL, 1005 file varchar(30) NOT NULL default '', 1006 minute varchar(200) NOT NULL default '', 1007 hour varchar(200) NOT NULL default '', 1008 day varchar(100) NOT NULL default '', 1009 month varchar(30) NOT NULL default '', 1010 weekday varchar(15) NOT NULL default '', 1011 nextrun bigint(30) NOT NULL default '0', 1012 lastrun bigint(30) NOT NULL default '0', 1013 enabled int(1) NOT NULL default '1', 1014 logging int(1) NOT NULL default '0', 1015 locked bigint(30) NOT NULL default '0', 1016 PRIMARY KEY (tid) 1017 ) ENGINE=MyISAM;"); 1018 } 1019 } 1020 else 1021 { 1022 $query = $db->simple_select("tasks", "file,tid"); 1023 while($task = $db->fetch_array($query)) 1024 { 1025 $tasks[$task['file']] = $task['tid']; 1026 } 1027 } 1028 1029 require_once MYBB_ROOT."inc/functions_task.php"; 1030 $task_file = file_get_contents(INSTALL_ROOT.'resources/tasks.xml'); 1031 $parser = new XMLParser($task_file); 1032 $parser->collapse_dups = 0; 1033 $tree = $parser->get_tree(); 1034 1035 // Resync tasks 1036 foreach($tree['tasks'][0]['task'] as $task) 1037 { 1038 if(!$tasks[$task['file'][0]['value']] || $redo == 2) 1039 { 1040 $new_task = array( 1041 'title' => $db->escape_string($task['title'][0]['value']), 1042 'description' => $db->escape_string($task['description'][0]['value']), 1043 'file' => $db->escape_string($task['file'][0]['value']), 1044 'minute' => $db->escape_string($task['minute'][0]['value']), 1045 'hour' => $db->escape_string($task['hour'][0]['value']), 1046 'day' => $db->escape_string($task['day'][0]['value']), 1047 'weekday' => $db->escape_string($task['weekday'][0]['value']), 1048 'month' => $db->escape_string($task['month'][0]['value']), 1049 'enabled' => $db->escape_string($task['enabled'][0]['value']), 1050 'logging' => $db->escape_string($task['logging'][0]['value']) 1051 ); 1052 1053 $new_task['nextrun'] = fetch_next_run($new_task); 1054 1055 $db->insert_query("tasks", $new_task); 1056 $taskcount++; 1057 } 1058 else 1059 { 1060 $update_task = array( 1061 'title' => $db->escape_string($task['title'][0]['value']), 1062 'description' => $db->escape_string($task['description'][0]['value']), 1063 'file' => $db->escape_string($task['file'][0]['value']), 1064 ); 1065 1066 $db->update_query("tasks", $update_task, "file='".$db->escape_string($task['file'][0]['value'])."'"); 1067 } 1068 } 1069 1070 return $taskcount; 1071 } 1072 1073 function write_settings() 1074 { 1075 global $db; 1076 $query = $db->simple_select("settings", "*", "", array('order_by' => 'title')); 1077 while($setting = $db->fetch_array($query)) 1078 { 1079 $setting['value'] = $db->escape_string($setting['value']); 1080 $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n"; 1081 } 1082 if(!empty($settings)) 1083 { 1084 $settings = "<?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n{$settings}\n?>"; 1085 $file = fopen(MYBB_ROOT."inc/settings.php", "w"); 1086 fwrite($file, $settings); 1087 fclose($file); 1088 } 1089 } 1090 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |