| [ Index ] |
PHP Cross Reference of MyBB 1.8.40 |
[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 my_set_time_limit(); 443 444 $runfunction(); 445 } 446 } 447 448 /** 449 * Do the upgrade changes 450 */ 451 function upgradethemes() 452 { 453 global $output, $db, $system_upgrade_detail, $lang, $mybb; 454 455 $output->print_header($lang->upgrade_templates_reverted); 456 457 $charset = $db->build_create_table_collation(); 458 459 if($system_upgrade_detail['revert_all_templates'] > 0) 460 { 461 $db->drop_table("templates"); 462 $db->write_query("CREATE TABLE ".TABLE_PREFIX."templates ( 463 tid int unsigned NOT NULL auto_increment, 464 title varchar(120) NOT NULL default '', 465 template text NOT NULL, 466 sid int(10) NOT NULL default '0', 467 version varchar(20) NOT NULL default '0', 468 status varchar(10) NOT NULL default '', 469 dateline int(10) NOT NULL default '0', 470 PRIMARY KEY (tid) 471 ) ENGINE=MyISAM{$charset};"); 472 } 473 474 if($system_upgrade_detail['revert_all_themes'] > 0) 475 { 476 $db->drop_table("themes"); 477 $db->write_query("CREATE TABLE ".TABLE_PREFIX."themes ( 478 tid smallint unsigned NOT NULL auto_increment, 479 name varchar(100) NOT NULL default '', 480 pid smallint unsigned NOT NULL default '0', 481 def smallint(1) NOT NULL default '0', 482 properties text NOT NULL, 483 stylesheets text NOT NULL, 484 allowedgroups text NOT NULL, 485 PRIMARY KEY (tid) 486 ) ENGINE=MyISAM{$charset};"); 487 488 $db->drop_table("themestylesheets"); 489 $db->write_query("CREATE TABLE ".TABLE_PREFIX."themestylesheets( 490 sid int unsigned NOT NULL auto_increment, 491 name varchar(30) NOT NULL default '', 492 tid int unsigned NOT NULL default '0', 493 attachedto text NOT NULL, 494 stylesheet text NOT NULL, 495 cachefile varchar(100) NOT NULL default '', 496 lastmodified bigint(30) NOT NULL default '0', 497 PRIMARY KEY(sid) 498 ) ENGINE=MyISAM{$charset};"); 499 500 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 501 if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php")) 502 { 503 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"; 504 } 505 else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php")) 506 { 507 require_once MYBB_ROOT."admin/inc/functions_themes.php"; 508 } 509 else 510 { 511 $output->print_error("Please make sure your admin directory is uploaded correctly."); 512 } 513 import_theme_xml($contents, array("templateset" => -2, "no_templates" => 1, "version_compat" => 1)); 514 $tid = build_new_theme("Default", null, 1); 515 516 $db->update_query("themes", array("def" => 1), "tid='{$tid}'"); 517 $db->update_query("users", array('style' => $tid)); 518 $db->update_query("forums", array('style' => 0)); 519 520 $db->drop_table("templatesets"); 521 $db->write_query("CREATE TABLE ".TABLE_PREFIX."templatesets ( 522 sid smallint unsigned NOT NULL auto_increment, 523 title varchar(120) NOT NULL default '', 524 PRIMARY KEY (sid) 525 ) ENGINE=MyISAM{$charset};"); 526 527 $db->insert_query("templatesets", array('title' => 'Default Templates')); 528 } 529 else 530 { 531 // Re-import master 532 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 533 if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php")) 534 { 535 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php"; 536 require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"; 537 } 538 elseif(file_exists(MYBB_ROOT."admin/inc/functions_themes.php")) 539 { 540 require_once MYBB_ROOT."admin/inc/functions.php"; 541 require_once MYBB_ROOT."admin/inc/functions_themes.php"; 542 } 543 else 544 { 545 $output->print_error($lang->no_theme_functions_file); 546 } 547 548 // Import master theme 549 import_theme_xml($contents, array("tid" => 1, "no_templates" => 1, "version_compat" => 1)); 550 } 551 552 $sid = -2; 553 554 // Now deal with the master templates 555 $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml'); 556 $parser = create_xml_parser($contents); 557 $tree = $parser->get_tree(); 558 559 $theme = $tree['theme']; 560 561 if(is_array($theme['templates'])) 562 { 563 $templates = $theme['templates']['template']; 564 foreach($templates as $template) 565 { 566 $templatename = $db->escape_string($template['attributes']['name']); 567 $templateversion = (int)$template['attributes']['version']; 568 $templatevalue = $db->escape_string($template['value']); 569 $time = TIME_NOW; 570 $query = $db->simple_select("templates", "tid", "sid='-2' AND title='".$db->escape_string($templatename)."'"); 571 $oldtemp = $db->fetch_array($query); 572 if($oldtemp) 573 { 574 $update_array = array( 575 'template' => $templatevalue, 576 'version' => $templateversion, 577 'dateline' => $time 578 ); 579 $db->update_query("templates", $update_array, "title='".$db->escape_string($templatename)."' AND sid='-2'"); 580 } 581 else 582 { 583 $insert_array = array( 584 'title' => $templatename, 585 'template' => $templatevalue, 586 'sid' => $sid, 587 'version' => $templateversion, 588 'dateline' => $time 589 ); 590 591 $db->insert_query("templates", $insert_array); 592 ++$newcount; 593 } 594 } 595 } 596 597 $output->print_contents($lang->upgrade_templates_reverted_success); 598 $output->print_footer("rebuildsettings"); 599 } 600 601 /** 602 * Update the settings 603 */ 604 function buildsettings() 605 { 606 global $db, $output, $system_upgrade_detail, $lang; 607 608 if(!is_writable(MYBB_ROOT."inc/settings.php")) 609 { 610 $output->print_header("Rebuilding Settings"); 611 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>"; 612 $output->print_footer("rebuildsettings"); 613 exit; 614 } 615 $synccount = sync_settings($system_upgrade_detail['revert_all_settings']); 616 617 $output->print_header($lang->upgrade_settings_sync); 618 $output->print_contents($lang->sprintf($lang->upgrade_settings_sync_success, $synccount[1], $synccount[0])); 619 $output->print_footer("buildcaches"); 620 } 621 622 /** 623 * Rebuild caches 624 */ 625 function buildcaches() 626 { 627 global $db, $output, $cache, $lang, $mybb; 628 629 $output->print_header($lang->upgrade_datacache_building); 630 631 $contents = $lang->upgrade_building_datacache; 632 633 $cache->update_version(); 634 $cache->update_attachtypes(); 635 $cache->update_smilies(); 636 $cache->update_badwords(); 637 $cache->update_usergroups(); 638 $cache->update_forumpermissions(); 639 $cache->update_stats(); 640 $cache->update_statistics(); 641 $cache->update_moderators(); 642 $cache->update_forums(); 643 $cache->update_usertitles(); 644 $cache->update_reportedcontent(); 645 $cache->update_awaitingactivation(); 646 $cache->update_mycode(); 647 $cache->update_profilefields(); 648 $cache->update_posticons(); 649 $cache->update_update_check(); 650 $cache->update_tasks(); 651 $cache->update_spiders(); 652 $cache->update_bannedips(); 653 $cache->update_birthdays(); 654 $cache->update_most_replied_threads(); 655 $cache->update_most_viewed_threads(); 656 $cache->update_groupleaders(); 657 $cache->update_threadprefixes(); 658 $cache->update_forumsdisplay(); 659 $cache->update_reportreasons(true); 660 661 $contents .= $lang->done."</p>"; 662 663 $output->print_contents("$contents<p>".$lang->upgrade_continue."</p>"); 664 $output->print_footer("finished"); 665 } 666 667 /** 668 * Called as latest function. Send statistics, create lock file etc 669 */ 670 function upgradedone() 671 { 672 global $db, $output, $mybb, $lang, $config, $plugins; 673 674 ob_start(); 675 $output->print_header($lang->upgrade_complete); 676 677 $allow_anonymous_info = get_upgrade_store("allow_anonymous_info"); 678 if($allow_anonymous_info == 1) 679 { 680 require_once MYBB_ROOT."inc/functions_serverstats.php"; 681 $build_server_stats = build_server_stats(0, '', $mybb->version_code, $mybb->config['database']['encoding']); 682 683 if($build_server_stats['info_sent_success'] == false) 684 { 685 echo $build_server_stats['info_image']; 686 } 687 } 688 ob_end_flush(); 689 690 // Attempt to run an update check 691 require_once MYBB_ROOT.'inc/functions_task.php'; 692 $query = $db->simple_select('tasks', 'tid', "file='versioncheck'"); 693 $update_check = $db->fetch_array($query); 694 if($update_check) 695 { 696 // Load plugin system for update check 697 require_once MYBB_ROOT."inc/class_plugins.php"; 698 $plugins = new pluginSystem; 699 700 run_task($update_check['tid']); 701 } 702 703 if(is_writable("./")) 704 { 705 $lock = @fopen("./lock", "w"); 706 $written = @fwrite($lock, "1"); 707 @fclose($lock); 708 if($written) 709 { 710 $lock_note = $lang->sprintf($lang->upgrade_locked, $config['admin_dir']); 711 } 712 } 713 if(empty($written)) 714 { 715 $lock_note = "<p><b><span style=\"color: red;\">".$lang->upgrade_removedir."</span></b></p>"; 716 } 717 718 // Rebuild inc/settings.php at the end of the upgrade 719 if(function_exists('rebuild_settings')) 720 { 721 rebuild_settings(); 722 } 723 else 724 { 725 $options = array( 726 "order_by" => "title", 727 "order_dir" => "ASC" 728 ); 729 730 $query = $db->simple_select("settings", "value, name", "", $options); 731 while($setting = $db->fetch_array($query)) 732 { 733 $setting['value'] = str_replace("\"", "\\\"", $setting['value']); 734 $settings[$setting['name']] = $setting['value']; 735 } 736 } 737 738 $output->print_contents($lang->sprintf($lang->upgrade_congrats, $mybb->version, $lock_note)); 739 $output->print_footer(); 740 } 741 742 /** 743 * Show the finish page 744 */ 745 function whatsnext() 746 { 747 global $output, $db, $system_upgrade_detail, $lang; 748 749 if($system_upgrade_detail['revert_all_templates'] > 0) 750 { 751 $output->print_header($lang->upgrade_template_reversion); 752 $output->print_contents($lang->upgrade_template_reversion_success); 753 $output->print_footer("templates"); 754 } 755 else 756 { 757 upgradethemes(); 758 } 759 } 760 761 /** 762 * Determine the next function we need to call 763 * 764 * @param string $from 765 * @param string $func 766 * 767 * @return string 768 */ 769 function next_function($from, $func="dbchanges") 770 { 771 global $oldvers, $system_upgrade_detail, $currentscript, $cache; 772 773 if(!ctype_alnum($from)) 774 { 775 $from = 0; 776 } 777 778 load_module("upgrade".$from.".php"); 779 if(function_exists("upgrade".$from."_".$func)) 780 { 781 $function = "upgrade".$from."_".$func; 782 } 783 else 784 { 785 // We're done with our last upgrade script, so add it to the upgrade scripts we've already completed. 786 if (ctype_digit($from)) { 787 $from = (int)$from; 788 } 789 790 $version_history = $cache->read("version_history"); 791 $version_history[$from] = $from; 792 $cache->update("version_history", $version_history); 793 794 // Check for standard migrations and old branch patches (1 < 1p1 < 1p2 < 2) 795 $parts = explode('p', $from); 796 797 $candidates = array( 798 (string)((int)$parts[0] + 1), 799 ); 800 801 if(isset($parts[1])) 802 { 803 $candidates[] = $parts[0].'p'.((int)$parts[1] + 1); 804 } 805 else 806 { 807 $candidates[] = $parts[0].'p1'; 808 } 809 810 foreach($candidates as $candidate) 811 { 812 if(file_exists(INSTALL_ROOT."resources/upgrade".$candidate.".php")) 813 { 814 $function = next_function($candidate); 815 break; 816 } 817 } 818 } 819 820 if(empty($function)) 821 { 822 $function = "whatsnext"; 823 } 824 return $function; 825 } 826 827 /** 828 * @param string $module 829 */ 830 function load_module($module) 831 { 832 global $system_upgrade_detail, $currentscript, $upgrade_detail; 833 834 require_once INSTALL_ROOT."resources/".$module; 835 if($currentscript != $module) 836 { 837 foreach($upgrade_detail as $key => $val) 838 { 839 if(empty($system_upgrade_detail[$key]) || $val > $system_upgrade_detail[$key]) 840 { 841 $system_upgrade_detail[$key] = $val; 842 } 843 } 844 add_upgrade_store("upgradedetail", $system_upgrade_detail); 845 add_upgrade_store("currentscript", $module); 846 } 847 } 848 849 /** 850 * Get a value from our upgrade data cache 851 * 852 * @param string $title 853 * 854 * @return mixed 855 */ 856 function get_upgrade_store($title) 857 { 858 global $db; 859 860 $query = $db->simple_select("upgrade_data", "*", "title='".$db->escape_string($title)."'"); 861 $data = $db->fetch_array($query); 862 863 if(!isset($data['contents'])) 864 { 865 return null; 866 } 867 868 return my_unserialize($data['contents']); 869 } 870 871 /** 872 * @param string $title 873 * @param mixed $contents 874 */ 875 function add_upgrade_store($title, $contents) 876 { 877 global $db; 878 879 $replace_array = array( 880 "title" => $db->escape_string($title), 881 "contents" => $db->escape_string(my_serialize($contents)) 882 ); 883 $db->replace_query("upgrade_data", $replace_array, "title"); 884 } 885 886 /** 887 * @param int $redo 2 means that all setting tables will be dropped and recreated 888 * 889 * @return array 890 */ 891 function sync_settings($redo=0) 892 { 893 global $db; 894 895 $settingcount = $groupcount = 0; 896 $settings = $settinggroups = array(); 897 if($redo == 2) 898 { 899 $db->drop_table("settinggroups"); 900 switch($db->type) 901 { 902 case "pgsql": 903 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 904 gid serial, 905 name varchar(100) NOT NULL default '', 906 title varchar(220) NOT NULL default '', 907 description text NOT NULL default '', 908 disporder smallint NOT NULL default '0', 909 isdefault int NOT NULL default '0', 910 PRIMARY KEY (gid) 911 );"); 912 break; 913 case "sqlite": 914 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 915 gid INTEGER PRIMARY KEY, 916 name varchar(100) NOT NULL default '', 917 title varchar(220) NOT NULL default '', 918 description TEXT NOT NULL, 919 disporder smallint NOT NULL default '0', 920 isdefault int(1) NOT NULL default '0' 921 );"); 922 break; 923 case "mysql": 924 default: 925 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settinggroups ( 926 gid smallint unsigned NOT NULL auto_increment, 927 name varchar(100) NOT NULL default '', 928 title varchar(220) NOT NULL default '', 929 description text NOT NULL, 930 disporder smallint unsigned NOT NULL default '0', 931 isdefault int(1) NOT NULL default '0', 932 PRIMARY KEY (gid) 933 ) ENGINE=MyISAM;"); 934 } 935 936 $db->drop_table("settings"); 937 938 switch($db->type) 939 { 940 case "pgsql": 941 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 942 sid serial, 943 name varchar(120) NOT NULL default '', 944 title varchar(120) NOT NULL default '', 945 description text NOT NULL default '', 946 optionscode text NOT NULL default '', 947 value text NOT NULL default '', 948 disporder smallint NOT NULL default '0', 949 gid smallint NOT NULL default '0', 950 isdefault int NOT NULL default '0', 951 PRIMARY KEY (sid) 952 );"); 953 break; 954 case "sqlite": 955 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 956 sid INTEGER PRIMARY KEY, 957 name varchar(120) NOT NULL default '', 958 title varchar(120) NOT NULL default '', 959 description TEXT NOT NULL, 960 optionscode TEXT NOT NULL, 961 value TEXT NOT NULL, 962 disporder smallint NOT NULL default '0', 963 gid smallint NOT NULL default '0', 964 isdefault int(1) NOT NULL default '0' 965 );"); 966 break; 967 case "mysql": 968 default: 969 $db->write_query("CREATE TABLE ".TABLE_PREFIX."settings ( 970 sid smallint unsigned NOT NULL auto_increment, 971 name varchar(120) NOT NULL default '', 972 title varchar(120) NOT NULL default '', 973 description text NOT NULL, 974 optionscode text NOT NULL, 975 value text NOT NULL, 976 disporder smallint unsigned NOT NULL default '0', 977 gid smallint unsigned NOT NULL default '0', 978 isdefault int(1) NOT NULL default '0', 979 PRIMARY KEY (sid) 980 ) ENGINE=MyISAM;"); 981 } 982 } 983 else 984 { 985 if($db->type == "mysql" || $db->type == "mysqli") 986 { 987 $wheresettings = "isdefault='1' OR isdefault='yes'"; 988 } 989 else 990 { 991 $wheresettings = "isdefault='1'"; 992 } 993 994 $query = $db->simple_select("settinggroups", "name,title,gid", $wheresettings); 995 while($group = $db->fetch_array($query)) 996 { 997 $settinggroups[$group['name']] = $group['gid']; 998 } 999 1000 // Collect all the user's settings - regardless of 'defaultivity' - we'll check them all 1001 // against default settings and insert/update them accordingly 1002 $query = $db->simple_select("settings", "name,sid"); 1003 while($setting = $db->fetch_array($query)) 1004 { 1005 $settings[$setting['name']] = $setting['sid']; 1006 } 1007 } 1008 $settings_xml = file_get_contents(INSTALL_ROOT."resources/settings.xml"); 1009 $parser = create_xml_parser($settings_xml); 1010 $parser->collapse_dups = 0; 1011 $tree = $parser->get_tree(); 1012 $settinggroupnames = array(); 1013 $settingnames = array(); 1014 1015 foreach($tree['settings'][0]['settinggroup'] as $settinggroup) 1016 { 1017 $settinggroupnames[] = $settinggroup['attributes']['name']; 1018 1019 $groupdata = array( 1020 "name" => $db->escape_string($settinggroup['attributes']['name']), 1021 "title" => $db->escape_string($settinggroup['attributes']['title']), 1022 "description" => $db->escape_string($settinggroup['attributes']['description']), 1023 "disporder" => (int)$settinggroup['attributes']['disporder'], 1024 "isdefault" => $settinggroup['attributes']['isdefault'] 1025 ); 1026 if(!$settinggroups[$settinggroup['attributes']['name']] || $redo == 2) 1027 { 1028 $gid = $db->insert_query("settinggroups", $groupdata); 1029 ++$groupcount; 1030 } 1031 else 1032 { 1033 $gid = $settinggroups[$settinggroup['attributes']['name']]; 1034 $db->update_query("settinggroups", $groupdata, "gid='{$gid}'"); 1035 } 1036 1037 if(!$gid) 1038 { 1039 continue; 1040 } 1041 1042 foreach($settinggroup['setting'] as $setting) 1043 { 1044 $settingnames[] = $setting['attributes']['name']; 1045 1046 $settingdata = array( 1047 "name" => $db->escape_string($setting['attributes']['name']), 1048 "title" => $db->escape_string($setting['title'][0]['value']), 1049 "description" => $db->escape_string($setting['description'][0]['value']), 1050 "optionscode" => $db->escape_string($setting['optionscode'][0]['value']), 1051 "disporder" => (int)$setting['disporder'][0]['value'], 1052 "gid" => $gid, 1053 "isdefault" => 1 1054 ); 1055 if(!$settings[$setting['attributes']['name']] || $redo == 2) 1056 { 1057 $settingdata['value'] = $db->escape_string($setting['settingvalue'][0]['value']); 1058 $db->insert_query("settings", $settingdata); 1059 $settingcount++; 1060 } 1061 else 1062 { 1063 $name = $db->escape_string($setting['attributes']['name']); 1064 $db->update_query("settings", $settingdata, "name='{$name}'"); 1065 } 1066 } 1067 } 1068 1069 if($redo >= 1) 1070 { 1071 require MYBB_ROOT."inc/settings.php"; 1072 foreach($settings as $key => $val) 1073 { 1074 $db->update_query("settings", array('value' => $db->escape_string($val)), "name='".$db->escape_string($key)."'"); 1075 } 1076 } 1077 unset($settings); 1078 $settings = ''; 1079 $query = $db->simple_select("settings", "*", "", array('order_by' => 'title')); 1080 while($setting = $db->fetch_array($query)) 1081 { 1082 $setting['name'] = addcslashes($setting['name'], "\\'"); 1083 $setting['value'] = addcslashes($setting['value'], '\\"$'); 1084 $settings .= "\$settings['{$setting['name']}'] = \"".$setting['value']."\";\n"; 1085 } 1086 $settings = "<?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n"; 1087 $file = fopen(MYBB_ROOT."inc/settings.php", "w"); 1088 fwrite($file, $settings); 1089 fclose($file); 1090 return array($groupcount, $settingcount); 1091 } 1092 1093 /** 1094 * @param int $redo 2 means that the tasks table will be dropped and recreated 1095 * 1096 * @return int 1097 */ 1098 function sync_tasks($redo=0) 1099 { 1100 global $db; 1101 1102 $taskcount = 0; 1103 $tasks = array(); 1104 if($redo == 2) 1105 { 1106 $db->drop_table("tasks"); 1107 switch($db->type) 1108 { 1109 case "pgsql": 1110 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 1111 tid serial, 1112 title varchar(120) NOT NULL default '', 1113 description text NOT NULL default '', 1114 file varchar(30) NOT NULL default '', 1115 minute varchar(200) NOT NULL default '', 1116 hour varchar(200) NOT NULL default '', 1117 day varchar(100) NOT NULL default '', 1118 month varchar(30) NOT NULL default '', 1119 weekday varchar(15) NOT NULL default '', 1120 nextrun bigint NOT NULL default '0', 1121 lastrun bigint NOT NULL default '0', 1122 enabled int NOT NULL default '1', 1123 logging int NOT NULL default '0', 1124 locked bigint NOT NULL default '0', 1125 PRIMARY KEY(tid) 1126 );"); 1127 break; 1128 case "sqlite": 1129 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 1130 tid INTEGER PRIMARY KEY, 1131 title varchar(120) NOT NULL default '', 1132 description TEXT NOT NULL, 1133 file varchar(30) NOT NULL default '', 1134 minute varchar(200) NOT NULL default '', 1135 hour varchar(200) NOT NULL default '', 1136 day varchar(100) NOT NULL default '', 1137 month varchar(30) NOT NULL default '', 1138 weekday varchar(15) NOT NULL default '', 1139 nextrun bigint(30) NOT NULL default '0', 1140 lastrun bigint(30) NOT NULL default '0', 1141 enabled int(1) NOT NULL default '1', 1142 logging int(1) NOT NULL default '0', 1143 locked bigint(30) NOT NULL default '0' 1144 );"); 1145 break; 1146 case "mysql": 1147 default: 1148 $db->write_query("CREATE TABLE ".TABLE_PREFIX."tasks ( 1149 tid int unsigned NOT NULL auto_increment, 1150 title varchar(120) NOT NULL default '', 1151 description text NOT NULL, 1152 file varchar(30) NOT NULL default '', 1153 minute varchar(200) NOT NULL default '', 1154 hour varchar(200) NOT NULL default '', 1155 day varchar(100) NOT NULL default '', 1156 month varchar(30) NOT NULL default '', 1157 weekday varchar(15) NOT NULL default '', 1158 nextrun bigint(30) NOT NULL default '0', 1159 lastrun bigint(30) NOT NULL default '0', 1160 enabled int(1) NOT NULL default '1', 1161 logging int(1) NOT NULL default '0', 1162 locked bigint(30) NOT NULL default '0', 1163 PRIMARY KEY (tid) 1164 ) ENGINE=MyISAM;"); 1165 } 1166 } 1167 else 1168 { 1169 $query = $db->simple_select("tasks", "file,tid"); 1170 while($task = $db->fetch_array($query)) 1171 { 1172 $tasks[$task['file']] = $task['tid']; 1173 } 1174 } 1175 1176 require_once MYBB_ROOT."inc/functions_task.php"; 1177 $task_file = file_get_contents(INSTALL_ROOT.'resources/tasks.xml'); 1178 $parser = create_xml_parser($task_file); 1179 $parser->collapse_dups = 0; 1180 $tree = $parser->get_tree(); 1181 1182 // Resync tasks 1183 foreach($tree['tasks'][0]['task'] as $task) 1184 { 1185 if(!$tasks[$task['file'][0]['value']] || $redo == 2) 1186 { 1187 $new_task = array( 1188 'title' => $db->escape_string($task['title'][0]['value']), 1189 'description' => $db->escape_string($task['description'][0]['value']), 1190 'file' => $db->escape_string($task['file'][0]['value']), 1191 'minute' => $db->escape_string($task['minute'][0]['value']), 1192 'hour' => $db->escape_string($task['hour'][0]['value']), 1193 'day' => $db->escape_string($task['day'][0]['value']), 1194 'weekday' => $db->escape_string($task['weekday'][0]['value']), 1195 'month' => $db->escape_string($task['month'][0]['value']), 1196 'enabled' => $db->escape_string($task['enabled'][0]['value']), 1197 'logging' => $db->escape_string($task['logging'][0]['value']) 1198 ); 1199 1200 $new_task['nextrun'] = fetch_next_run($new_task); 1201 1202 $db->insert_query("tasks", $new_task); 1203 $taskcount++; 1204 } 1205 else 1206 { 1207 $update_task = array( 1208 'title' => $db->escape_string($task['title'][0]['value']), 1209 'description' => $db->escape_string($task['description'][0]['value']), 1210 'file' => $db->escape_string($task['file'][0]['value']), 1211 ); 1212 1213 $db->update_query("tasks", $update_task, "file='".$db->escape_string($task['file'][0]['value'])."'"); 1214 } 1215 } 1216 1217 return $taskcount; 1218 } 1219 1220 /** 1221 * Write our settings to the settings file 1222 */ 1223 function write_settings() 1224 { 1225 global $db; 1226 $query = $db->simple_select("settings", "*", "", array('order_by' => 'title')); 1227 while($setting = $db->fetch_array($query)) 1228 { 1229 $setting['name'] = addcslashes($setting['name'], "\\'"); 1230 $setting['value'] = addcslashes($setting['value'], '\\"$'); 1231 $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n"; 1232 } 1233 if(!empty($settings)) 1234 { 1235 $settings = "<?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n{$settings}\n"; 1236 $file = fopen(MYBB_ROOT."inc/settings.php", "w"); 1237 fwrite($file, $settings); 1238 fclose($file); 1239 } 1240 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| 2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |