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