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