[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/install/resources/ -> upgrade17.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  /**
  13   * Upgrade Script: 1.4.13 or 1.4.14
  14   */
  15  
  16  
  17  $upgrade_detail = array(
  18      "revert_all_templates" => 0,
  19      "revert_all_themes" => 0,
  20      "revert_all_settings" => 0
  21  );
  22  
  23  @set_time_limit(0);
  24  
  25  function upgrade17_dbchanges()
  26  {
  27      global $db, $output, $mybb, $cache;
  28  
  29      $output->print_header("Performing Queries");
  30  
  31      echo "<p>Performing necessary upgrade queries..</p>";
  32      echo "<p>Adding index to private messages table ... ";
  33      flush();
  34  
  35      if($db->type == "mysql" || $db->type == "mysqli")
  36      {
  37          $db->write_query("ALTER TABLE ".TABLE_PREFIX."privatemessages ADD INDEX ( `toid` )");
  38      }
  39  
  40      global $footer_extra;
  41      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
  42  
  43      $contents .= "Click next to continue with the upgrade process.</p>";
  44      $output->print_contents($contents);
  45      $output->print_footer("17_dbchanges2");
  46  }
  47  
  48  function upgrade17_dbchanges2()
  49  {
  50      global $db, $output, $mybb, $cache;
  51  
  52      $output->print_header("Performing Queries");
  53  
  54      echo "<p>Performing necessary upgrade queries..</p>";
  55      flush();
  56  
  57      // Update our version history first
  58      $version_history = array();
  59      $dh = opendir(INSTALL_ROOT."resources");
  60      while(($file = readdir($dh)) !== false)
  61      {
  62          if(preg_match("#upgrade([0-9]+).php$#i", $file, $match))
  63          {
  64              $version_history[$match[1]] = $match[1];
  65          }
  66      }
  67      sort($version_history, SORT_NUMERIC);
  68  
  69      // This script isn't done yet!
  70      unset($version_history['17']);
  71  
  72      $cache->update("version_history", $version_history);
  73  
  74      if($db->field_exists('prefix', 'threads'))
  75      {
  76          $db->drop_column("threads", "prefix");
  77      }
  78  
  79      if($db->field_exists('loginattempts', "adminoptions"))
  80      {
  81          $db->drop_column("adminoptions", "loginattempts");
  82      }
  83  
  84      if($db->field_exists('loginlockoutexpiry', "adminoptions"))
  85      {
  86          $db->drop_column("adminoptions", "loginlockoutexpiry");
  87      }
  88  
  89      if($db->field_exists('canonlyviewownthreads', "forumpermissions"))
  90      {
  91          $db->drop_column("forumpermissions", "canonlyviewownthreads");
  92      }
  93  
  94      if($db->field_exists('isgroup', 'moderators'))
  95      {
  96          $db->drop_column("moderators", "isgroup");
  97      }
  98  
  99      if($db->field_exists('referrals', 'promotions'))
 100      {
 101          $db->drop_column("promotions", "referrals");
 102      }
 103  
 104      if($db->field_exists('referralstype', 'promotions'))
 105      {
 106          $db->drop_column("promotions", "referralstype");
 107      }
 108  
 109      if($db->field_exists('pid', 'reputation'))
 110      {
 111          $db->drop_column("reputation", "pid");
 112      }
 113  
 114      if($db->field_exists('allowvideocode', 'calendars'))
 115      {
 116          $db->drop_column("calendars", "allowvideocode");
 117      }
 118  
 119      if($db->field_exists('allowvideocode', 'forums'))
 120      {
 121          $db->drop_column("forums", "allowvideocode");
 122      }
 123  
 124      switch($db->type)
 125      {
 126          case "pgsql":
 127              $db->add_column("threads", "prefix", "smallint NOT NULL default '0' AFTER subject");
 128              $db->add_column("adminoptions", "loginattempts", "int NOT NULL default '0'");
 129              $db->add_column("adminoptions", "loginlockoutexpiry", "int NOT NULL default '0'");
 130              $db->add_column("forumpermissions", "canonlyviewownthreads", "int NOT NULL default '0' AFTER canviewthreads");
 131              $db->add_column("moderators", "isgroup", "int NOT NULL default '0'");
 132              $db->add_column("promotions", "referrals", "int NOT NULL default '0' AFTER reputationtype");
 133              $db->add_column("promotions", "referralstype", "char(2) NOT NULL default '' AFTER referrals");
 134              $db->add_column("reputation", "pid", "int NOT NULL default '0'");
 135              $db->add_column("calendars", "allowvideocode", "int NOT NULL default '0' AFTER allowimgcode");
 136              $db->add_column("forums", "allowvideocode", "int NOT NULL default '0' AFTER allowimgcode");
 137              break;
 138          case "sqlite":
 139              $db->add_column("threads", "prefix", "smallint NOT NULL default '0' AFTER subject");
 140              $db->add_column("adminoptions", "loginattempts", "int NOT NULL default '0'");
 141              $db->add_column("adminoptions", "loginlockoutexpiry", "int NOT NULL default '0'");
 142              $db->add_column("forumpermissions", "canonlyviewownthreads", "int NOT NULL default '0' AFTER canviewthreads");
 143              $db->add_column("moderators", "isgroup", "int NOT NULL default '0'");
 144              $db->add_column("promotions", "referrals", "int NOT NULL default '0' AFTER reputationtype");
 145              $db->add_column("promotions", "referralstype", "varchar(2) NOT NULL default '' AFTER referrals");
 146              $db->add_column("reputation", "pid", "int NOT NULL default '0'");
 147              $db->add_column("calendars", "allowvideocode", "int(1) NOT NULL default '0' AFTER allowimgcode");
 148              $db->add_column("forums", "allowvideocode", "int(1) NOT NULL default '0' AFTER allowimgcode");
 149              break;
 150          default:
 151              $db->add_column("threads", "prefix", "smallint unsigned NOT NULL default '0' AFTER subject");
 152              $db->add_column("adminoptions", "loginattempts", "int unsigned NOT NULL default '0'");
 153              $db->add_column("adminoptions", "loginlockoutexpiry", "int unsigned NOT NULL default '0'");
 154              $db->add_column("forumpermissions", "canonlyviewownthreads", "int(1) NOT NULL default '0' AFTER canviewthreads");
 155              $db->add_column("moderators", "isgroup", "int(1) unsigned NOT NULL default '0'");
 156              $db->add_column("promotions", "referrals", "int NOT NULL default '0' AFTER reputationtype");
 157              $db->add_column("promotions", "referralstype", "varchar(2) NOT NULL default '' AFTER referrals");
 158              $db->add_column("reputation", "pid", "int unsigned NOT NULL default '0'");
 159              $db->add_column("calendars", "allowvideocode", "int(1) NOT NULL default '0' AFTER allowimgcode");
 160              $db->add_column("forums", "allowvideocode", "int(1) NOT NULL default '0' AFTER allowimgcode");
 161      }
 162  
 163      $db->update_query("forums", array('allowvideocode' => '1'));
 164      $db->update_query("calendars", array('allowvideocode' => '1'));
 165  
 166      global $footer_extra;
 167      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 168  
 169      $contents .= "Click next to continue with the upgrade process.</p>";
 170      $output->print_contents($contents);
 171      $output->print_footer("17_dbchanges3");
 172  }
 173  
 174  function upgrade17_dbchanges3()
 175  {
 176      global $db, $output, $mybb;
 177  
 178      $output->print_header("Performing Queries");
 179  
 180      echo "<p>Performing necessary upgrade queries..</p>";
 181      flush();
 182  
 183      if($db->field_exists('canundovotes', 'usergroups'))
 184      {
 185          $db->drop_column("usergroups", "canundovotes");
 186      }
 187  
 188      if($db->field_exists('maxreputationsperuser', 'usergroups'))
 189      {
 190          $db->drop_column("usergroups", "maxreputationsperuser");
 191      }
 192  
 193      if($db->field_exists('maxreputationsperthread', 'usergroups'))
 194      {
 195          $db->drop_column("usergroups", "maxreputationsperthread");
 196      }
 197  
 198      if($db->field_exists('receivefrombuddy', 'users'))
 199      {
 200          $db->drop_column("users", "receivefrombuddy");
 201      }
 202  
 203      if($db->field_exists('suspendsignature', 'users'))
 204      {
 205          $db->drop_column("users", "suspendsignature");
 206      }
 207  
 208      if($db->field_exists('suspendsigtime', 'users'))
 209      {
 210          $db->drop_column("users", "suspendsigtime");
 211      }
 212  
 213      if($db->field_exists('loginattempts', 'users'))
 214      {
 215          $db->drop_column("users", "loginattempts");
 216      }
 217  
 218      if($db->field_exists('failedlogin', 'users'))
 219      {
 220          $db->drop_column("users", "failedlogin");
 221      }
 222  
 223      if($db->field_exists('usernotes', "users"))
 224      {
 225          $db->drop_column("users", "usernotes");
 226      }
 227  
 228      if($db->field_exists('referrals', 'users'))
 229      {
 230          $db->drop_column("users", "referrals");
 231      }
 232  
 233      switch($db->type)
 234      {
 235          case "pgsql":
 236              $db->add_column("usergroups", "canundovotes", "int NOT NULL default '0' AFTER canvotepolls");
 237              $db->add_column("usergroups", "maxreputationsperuser", "bigint NOT NULL default '0' AFTER maxreputationsday");
 238              $db->add_column("usergroups", "maxreputationsperthread", "bigint NOT NULL default '0' AFTER maxreputationsperuser");
 239              $db->add_column("users", "receivefrombuddy", "int NOT NULL default '0'");
 240              $db->add_column("users", "suspendsignature", "int NOT NULL default '0'");
 241              $db->add_column("users", "suspendsigtime", "bigint NOT NULL default '0'");
 242              $db->add_column("users", "loginattempts", "smallint NOT NULL default '1'");
 243              $db->add_column("users", "failedlogin", "bigint NOT NULL default '0'");
 244              $db->add_column("users", "usernotes", "text NOT NULL default ''");
 245              $db->add_column("users", "referrals", "int NOT NULL default '0' AFTER referrer");
 246              break;
 247          case "sqlite":
 248              $db->add_column("usergroups", "canundovotes", "int NOT NULL default '0' AFTER canvotepolls");
 249              $db->add_column("usergroups", "maxreputationsperuser", "bigint NOT NULL default '0' AFTER maxreputationsday");
 250              $db->add_column("usergroups", "maxreputationsperthread", "bigint NOT NULL default '0' AFTER maxreputationsperuser");
 251              $db->add_column("users", "receivefrombuddy", "int NOT NULL default '0'");
 252              $db->add_column("users", "suspendsignature", "int NOT NULL default '0'");
 253              $db->add_column("users", "suspendsigtime", "bigint NOT NULL default '0'");
 254              $db->add_column("users", "loginattempts", "tinyint NOT NULL default '1'");
 255              $db->add_column("users", "failedlogin", "bigint NOT NULL default '0'");
 256              $db->add_column("users", "usernotes", "text NOT NULL default ''");
 257              $db->add_column("users", "referrals", "int NOT NULL default '0' AFTER referrer");
 258              break;
 259          default:
 260              $db->add_column("usergroups", "canundovotes", "int(1) NOT NULL default '0' AFTER canvotepolls");
 261              $db->add_column("usergroups", "maxreputationsperuser", "bigint(30) NOT NULL default '0' AFTER maxreputationsday");
 262              $db->add_column("usergroups", "maxreputationsperthread", "bigint(30) NOT NULL default '0' AFTER maxreputationsperuser");
 263              $db->add_column("users", "receivefrombuddy", "int(1) NOT NULL default '0'");
 264              $db->add_column("users", "suspendsignature", "int(1) NOT NULL default '0'");
 265              $db->add_column("users", "suspendsigtime", "bigint(30) NOT NULL default '0'");
 266              $db->add_column("users", "loginattempts", "tinyint(2) NOT NULL default '1'");
 267              $db->add_column("users", "failedlogin", "bigint(30) NOT NULL default '0'");
 268              $db->add_column("users", "usernotes", "text NOT NULL");
 269              $db->add_column("users", "referrals", "int unsigned NOT NULL default '0' AFTER referrer");
 270      }
 271  
 272      $contents .= "Click next to continue with the upgrade process.</p>";
 273      $output->print_contents($contents);
 274  
 275      global $footer_extra;
 276      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 277  
 278      $output->print_footer("17_dbchanges4");
 279  }
 280  
 281  function upgrade17_dbchanges4()
 282  {
 283      global $db, $output, $mybb;
 284  
 285      $output->print_header("Performing Queries");
 286  
 287      echo "<p>Performing necessary upgrade queries..</p>";
 288      flush();
 289  
 290      if($db->field_exists('remember', 'users'))
 291      {
 292          $db->drop_column("users", "remember");
 293      }
 294  
 295      if($db->type != "pgsql")
 296      {
 297          // PgSQL doesn't support longtext
 298          $db->modify_column("searchlog", "threads", "longtext NOT NULL");
 299          $db->modify_column("searchlog", "posts", "longtext NOT NULL");
 300      }
 301  
 302      if($db->field_exists("uid", "moderators") && !$db->field_exists("id", "moderators"))
 303      {
 304          switch($db->type)
 305          {
 306              case "pgsql":
 307                  $db->rename_column("moderators", "uid", "id", "int", true, "'0'");
 308                  break;
 309              default:
 310                  $db->rename_column("moderators", "uid", "id", "int unsigned NOT NULL default '0'");
 311          }
 312      }
 313  
 314      if($db->table_exists("threadprefixes"))
 315      {
 316          $db->drop_table("threadprefixes");
 317      }
 318  
 319      if($db->table_exists("delayedmoderation"))
 320      {
 321          $db->drop_table("delayedmoderation");
 322      }
 323  
 324      switch($db->type)
 325      {
 326          case "sqlite":
 327              $db->write_query("CREATE TABLE ".TABLE_PREFIX."threadprefixes (
 328                  rid INTEGER PRIMARY KEY,
 329                  tid int NOT NULL default '0',
 330                  uid int NOT NULL default '0',
 331                  rating smallint NOT NULL default '0',
 332                  ipaddress varchar(30) NOT NULL default ''
 333              );");
 334              $db->write_query("CREATE TABLE ".TABLE_PREFIX."delayedmoderation (
 335                  did integer PRIMARY KEY,
 336                  type varchar(30) NOT NULL default '',
 337                  delaydateline bigint(30) NOT NULL default '0',
 338                  uid int(10) NOT NULL default '0',
 339                  fid smallint(5) NOT NULL default '0',
 340                  tids text NOT NULL,
 341                  dateline bigint(30) NOT NULL default '0',
 342                  inputs text NOT NULL
 343              );");
 344              break;
 345          case "pgsql":
 346              $db->write_query("CREATE TABLE ".TABLE_PREFIX."threadprefixes (
 347                  pid serial,
 348                  prefix varchar(120) NOT NULL default '',
 349                  displaystyle varchar(200) NOT NULL default '',
 350                  forums text NOT NULL,
 351                  groups text NOT NULL,
 352                  PRIMARY KEY(pid)
 353              );");
 354              $db->write_query("CREATE TABLE ".TABLE_PREFIX."delayedmoderation (
 355                  did serial,
 356                  type varchar(30) NOT NULL default '',
 357                  delaydateline bigint NOT NULL default '0',
 358                  uid int NOT NULL default '0',
 359                  fid smallint NOT NULL default '0',
 360                  tids text NOT NULL,
 361                  dateline bigint NOT NULL default '0',
 362                  inputs text NOT NULL default '',
 363                  PRIMARY KEY (did)
 364              );");
 365              break;
 366          default:
 367              $db->write_query("CREATE TABLE ".TABLE_PREFIX."threadprefixes (
 368                  pid int unsigned NOT NULL auto_increment,
 369                  prefix varchar(120) NOT NULL default '',
 370                  displaystyle varchar(200) NOT NULL default '',
 371                  forums text NOT NULL,
 372                  groups text NOT NULL,
 373                  PRIMARY KEY(pid)
 374              ) ENGINE=MyISAM;");
 375              $db->write_query("CREATE TABLE ".TABLE_PREFIX."delayedmoderation (
 376                  did int unsigned NOT NULL auto_increment,
 377                  type varchar(30) NOT NULL default '',
 378                  delaydateline bigint(30) unsigned NOT NULL default '0',
 379                  uid int(10) unsigned NOT NULL default '0',
 380                  fid smallint(5) unsigned NOT NULL default '0',
 381                  tids text NOT NULL,
 382                  dateline bigint(30) NOT NULL default '0',
 383                  inputs text NOT NULL,
 384                  PRIMARY KEY (did)
 385              ) ENGINE=MyISAM;");
 386      }
 387  
 388      $added_tasks = sync_tasks();
 389  
 390      echo "<p>Added {$added_tasks} new tasks.</p>";
 391  
 392      $contents .= "Click next to continue with the upgrade process.</p>";
 393      $output->print_contents($contents);
 394  
 395      global $footer_extra;
 396      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 397  
 398      $output->print_footer("17_dbchanges5");
 399  }
 400  
 401  function upgrade17_dbchanges5()
 402  {
 403      global $db, $output, $mybb, $cache;
 404  
 405      if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php"))
 406      {
 407          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php";
 408      }
 409      else if(file_exists(MYBB_ROOT."admin/inc/functions.php"))
 410      {
 411          require_once  MYBB_ROOT."admin/inc/functions.php";
 412      }
 413      else
 414      {
 415          $output->print_error("Please make sure your admin directory is uploaded correctly.");
 416      }
 417  
 418      $output->print_header("Performing Queries");
 419  
 420      echo "<p>Performing necessary upgrade queries..</p>";
 421      flush();
 422  
 423      $db->update_query("spiders", array('name' => 'Bing'), "name='MSN Search'");
 424      $db->update_query("spiders", array('useragent' => 'Googlebot', 'name' => 'Google'), "useragent='google'");
 425      $db->update_query("spiders", array('useragent' => 'Teoma', 'name' => 'Ask.com'), "useragent='ask jeeves'");
 426      $db->delete_query("spiders", "name='Hot Bot'");
 427      $db->update_query("spiders", array('useragent' => 'archive_crawler', 'name' => 'Internet Archive'), "name='Archive.org'");
 428      $db->update_query("spiders", array('name' => 'Alexa Internet'), "useragent='ia_archiver'");
 429      $db->delete_query("spiders", "useragent='scooter'");
 430      $db->update_query("spiders", array('useragent' => 'Slurp'), "name='Yahoo!'");
 431  
 432      $query = $db->simple_select("spiders", "COUNT(*) as numexists", "useragent='twiceler'");
 433      if($db->fetch_field($query, "numexists") == 0)
 434      {
 435          $db->insert_query("spiders", array('name' => "Cuil", 'useragent' => 'twiceler'));
 436      }
 437  
 438      $query = $db->simple_select("spiders", "COUNT(*) as numexists", "useragent='Baiduspider'");
 439      if($db->fetch_field($query, "numexists") == 0)
 440      {
 441          $db->insert_query("spiders", array('name' => "Baidu", 'useragent' => 'Baiduspider'));
 442      }
 443  
 444      $db->update_query("attachtypes", array('mimetype' => 'application/x-httpd-php'), "extension='php'");
 445      $db->update_query("attachtypes", array('mimetype' => 'text/html'), "extension='htm'");
 446      $db->update_query("attachtypes", array('mimetype' => 'text/html'), "extension='html'");
 447      $db->update_query("attachtypes", array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), "extension='docx'");
 448      $db->update_query("attachtypes", array('mimetype' => 'application/vnd.ms-excel'), "extension='xls'");
 449      $db->update_query("attachtypes", array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), "extension='xlsx'");
 450      $db->update_query("attachtypes", array('mimetype' => 'application/vnd.ms-powerpoint'), "extension='ppt'");
 451      $db->update_query("attachtypes", array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'), "extension='pptx'");
 452  
 453      $cache->update_moderators();
 454  
 455      $db->update_query("themes", array('allowedgroups' => 'all'), "allowedgroups='' OR allowedgroups IS NULL");
 456  
 457      // Add permissions for all of our new ACP pages
 458      change_admin_permission('config', 'thread_prefixes');
 459      change_admin_permission('tools', 'file_verification');
 460      change_admin_permission('tools', 'statistics');
 461  
 462      $contents .= "Click next to continue with the upgrade process.</p>";
 463      $output->print_contents($contents);
 464  
 465      global $footer_extra;
 466      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 467  
 468      $output->print_footer("17_dbchanges6");
 469  }
 470  
 471  function upgrade17_dbchanges6()
 472  {
 473      global $db, $output;
 474  
 475      $output->print_header("Post IP Repair Conversion");
 476  
 477      if(!$_POST['ipspage'])
 478      {
 479          $ipp = 5000;
 480      }
 481      else
 482      {
 483          $ipp = $_POST['ipspage'];
 484      }
 485  
 486      if($_POST['ipstart'])
 487      {
 488          $startat = $_POST['ipstart'];
 489          $upper = $startat+$ipp;
 490          $lower = $startat;
 491      }
 492      else
 493      {
 494          $startat = 0;
 495          $upper = $ipp;
 496          $lower = 1;
 497      }
 498  
 499      $query = $db->simple_select("posts", "COUNT(pid) AS ipcount");
 500      $cnt = $db->fetch_array($query);
 501  
 502      if($upper > $cnt['ipcount'])
 503      {
 504          $upper = $cnt['ipcount'];
 505      }
 506  
 507      echo "<p>Repairing ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>";
 508      flush();
 509  
 510      $ipaddress = false;
 511  
 512      $query = $db->simple_select("posts", "ipaddress, pid", "", array('limit_start' => $lower, 'limit' => $ipp));
 513      while($post = $db->fetch_array($query))
 514      {
 515          $db->update_query("posts", array('longipaddress' => intval(my_ip2long($post['ipaddress']))), "pid = '{$post['pid']}'");
 516          $ipaddress = true;
 517      }
 518  
 519      $remaining = $upper-$cnt['ipcount'];
 520      if($remaining && $ipaddress)
 521      {
 522          $nextact = "17_dbchanges6";
 523          $startat = $startat+$ipp;
 524          $contents = "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of post ips.</p>";
 525      }
 526      else
 527      {
 528          $nextact = "17_dbchanges7";
 529          $contents = "<p>Done</p><p>All post ips have been succesfully repaired. Click next to continue.</p>";
 530      }
 531      $output->print_contents($contents);
 532  
 533      global $footer_extra;
 534      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 535  
 536      $output->print_footer($nextact);
 537  }
 538  
 539  function upgrade17_dbchanges7()
 540  {
 541      global $db, $output;
 542  
 543      $output->print_header("User IP Repair Conversion");
 544  
 545      if(!$_POST['ipspage'])
 546      {
 547          $ipp = 5000;
 548      }
 549      else
 550      {
 551          $ipp = $_POST['ipspage'];
 552      }
 553  
 554      if($_POST['ipstart'])
 555      {
 556          $startat = $_POST['ipstart'];
 557          $upper = $startat+$ipp;
 558          $lower = $startat;
 559      }
 560      else
 561      {
 562          $startat = 0;
 563          $upper = $ipp;
 564          $lower = 1;
 565      }
 566  
 567      $query = $db->simple_select("users", "COUNT(uid) AS ipcount");
 568      $cnt = $db->fetch_array($query);
 569  
 570      if($upper > $cnt['ipcount'])
 571      {
 572          $upper = $cnt['ipcount'];
 573      }
 574  
 575      $contents .= "<p>Repairing ip {$lower} to {$upper} ({$cnt['ipcount']} Total)</p>";
 576  
 577      $ipaddress = false;
 578      $update_array = array();
 579  
 580      $query = $db->simple_select("users", "regip, lastip, uid", "", array('limit_start' => $lower, 'limit' => $ipp));
 581      while($user = $db->fetch_array($query))
 582      {
 583          $update_array = array(
 584              'longregip' => intval(my_ip2long($user['regip'])),
 585              'longlastip' => intval(my_ip2long($user['lastip']))
 586          );
 587  
 588          $db->update_query("users", $update_array, "uid = '{$user['uid']}'");
 589  
 590          $update_array = array();
 591          $ipaddress = true;
 592      }
 593  
 594      $remaining = $upper-$cnt['ipcount'];
 595      if($remaining && $ipaddress)
 596      {
 597          $nextact = "17_dbchanges7";
 598          $startat = $startat+$ipp;
 599          $contents .= "<p><input type=\"hidden\" name=\"ipspage\" value=\"$ipp\" /><input type=\"hidden\" name=\"ipstart\" value=\"$startat\" />Done. Click Next to move on to the next set of user ips.</p>";
 600      }
 601      else
 602      {
 603          $nextact = "17_redoconfig";
 604          $contents .= "<p>Done</p><p>All user ips have been successfully repaired. Click next to continue.</p>";
 605      }
 606      $output->print_contents($contents);
 607  
 608      global $footer_extra;
 609      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 610  
 611      $output->print_footer($nextact);
 612  }
 613  
 614  function upgrade17_redoconfig()
 615  {
 616      global $db, $output, $orig_config, $mybb;
 617  
 618      $config = $orig_config;
 619  
 620      $output->print_header("Rewriting config.php");
 621  
 622      if(!is_array($config['memcache']))
 623      {
 624          // Backup our old Config file
 625          @copy(MYBB_ROOT."inc/config.php", MYBB_ROOT."inc/config.backup.php");
 626  
 627          $fh = @fopen(MYBB_ROOT."inc/config.php", "w");
 628          if(!$fh)
 629          {
 630              echo "<p><span style=\"color: red; font-weight: bold;\">Unable to open inc/config.php</span><br />Before the upgrade process can continue, you need to changes the permissions of inc/config.php so it is writable.</p>";
 631              $output->print_footer("17_redoconfig");
 632              exit;
 633          }
 634  
 635          if(!$config['memcache_host'])
 636          {
 637              $config['memcache_host'] = "localhost";
 638          }
 639  
 640          if(!$config['memcache_port'])
 641          {
 642              $config['memcache_port'] = 11211;
 643          }
 644  
 645          $comment = "";
 646  
 647          if(!$db->db_encoding || !$config['database']['encoding'])
 648          {
 649              $comment = " // ";
 650          }
 651  
 652          if(!$config['database']['encoding'])
 653          {
 654              $config['database']['encoding'] = "utf8";
 655          }
 656  
 657          // Update SQLite selection. SQLite 2 is depreciated.
 658          if($config['database']['type'] == 'sqlite2' || $config['database']['type'] == 'sqlite3')
 659          {
 660              $config['database']['type'] = 'sqlite';
 661          }
 662  
 663          // Do we have a read or a write database?
 664          if($config['database']['read'])
 665          {
 666              $database_config = "\$config['database']['type'] = '{$config['database']['type']}';";
 667              foreach(array('read', 'write') as $type)
 668              {
 669                  // Multiple read/write databases?
 670                  if($config['database'][$type][0]['database'])
 671                  {
 672                      $i = 0;
 673                      foreach($config['database'][$type] as $database_connection)
 674                      {
 675                          $database_config .= "
 676  \$config['database']['{$type}'][{$i}]['database'] = '{$database_connection['database']}';
 677  \$config['database']['{$type}'][{$i}]['table_prefix'] = '{$database_connection['table_prefix']}';
 678  \$config['database']['{$type}'][{$i}]['hostname'] = '{$database_connection['hostname']}';
 679  \$config['database']['{$type}'][{$i}]['username'] = '{$database_connection['username']}';
 680  \$config['database']['{$type}'][{$i}]['password'] = '{$database_connection['password']}';";
 681                          ++$i;
 682                      }
 683                  }
 684                  // Just a single database read/write connection
 685                  else
 686                  {
 687                      $database_config .= "
 688  \$config['database']['{$type}']['database'] = '{$config['database'][$type]['database']}';
 689  \$config['database']['{$type}']['table_prefix'] = '{$config['database'][$type]['table_prefix']}';
 690  
 691  \$config['database']['{$type}']['hostname'] = '{$config['database'][$type]['hostname']}';
 692  \$config['database']['{$type}']['username'] = '{$config['database'][$type]['username']}';
 693  \$config['database']['{$type}']['password'] = '{$config['database'][$type]['password']}';";
 694                  }
 695              }
 696          }
 697          // Standard database connection stuff
 698          else
 699          {
 700              $database_config = "\$config['database']['type'] = '{$config['database']['type']}';
 701  \$config['database']['database'] = '{$config['database']['database']}';
 702  \$config['database']['table_prefix'] = '{$config['database']['table_prefix']}';
 703  
 704  \$config['database']['hostname'] = '{$config['database']['hostname']}';
 705  \$config['database']['username'] = '{$config['database']['username']}';
 706  \$config['database']['password'] = '{$config['database']['password']}';
 707  ";
 708          }
 709  
 710  
 711          $configdata = "<?php
 712  /**
 713   * Database configuration
 714   *
 715   * Please see the MyBB Docs for advanced
 716   * database configuration for larger installations
 717   * http://docs.mybb.com/
 718   */
 719  
 720  {$database_config}
 721  
 722  /**
 723   * Admin CP directory
 724   *  For security reasons, it is recommended you
 725   *  rename your Admin CP directory. You then need
 726   *  to adjust the value below to point to the
 727   *  new directory.
 728   */
 729  
 730  \$config['admin_dir'] = '{$config['admin_dir']}';
 731  
 732  /**
 733   * Hide all Admin CP links
 734   *  If you wish to hide all Admin CP links
 735   *  on the front end of the board after
 736   *  renaming your Admin CP directory, set this
 737   *  to 1.
 738   */
 739  
 740  \$config['hide_admin_links'] = {$config['hide_admin_links']};
 741  
 742  /**
 743   * Data-cache configuration
 744   *  The data cache is a temporary cache
 745   *  of the most commonly accessed data in MyBB.
 746   *  By default, the database is used to store this data.
 747   *
 748   *  If you wish to use the file system (cache/ directory), MemCache, xcache, or eAccelerator
 749   *  you can change the value below to 'files', 'memcache', 'xcache' or 'eaccelerator' from 'db'.
 750   */
 751  
 752  \$config['cache_store'] = '{$config['cache_store']}';
 753  
 754  /**
 755   * Memcache configuration
 756   *  If you are using memcache as your data-cache,
 757   *  you need to configure the hostname and port
 758   *  of your memcache server below.
 759   *
 760   * If not using memcache, ignore this section.
 761   */
 762  
 763  \$config['memcache']['host'] = '{$config['memcache_host']}';
 764  \$config['memcache']['port'] = {$config['memcache_port']};
 765  
 766  /**
 767   * Super Administrators
 768   *  A comma separated list of user IDs who cannot
 769   *  be edited, deleted or banned in the Admin CP.
 770   *  The administrator permissions for these users
 771   *  cannot be altered either.
 772   */
 773  
 774  \$config['super_admins'] = '{$config['super_admins']}';
 775  
 776  /**
 777   * Database Encoding
 778   *  If you wish to set an encoding for MyBB uncomment
 779   *  the line below (if it isn't already) and change
 780   *  the current value to the mysql charset:
 781   *  http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html
 782   */
 783  
 784  {$comment}\$config['database']['encoding'] = '{$config['database']['encoding']}';
 785  
 786  /**
 787   * Automatic Log Pruning
 788   *  The MyBB task system can automatically prune
 789   *  various log files created by MyBB.
 790   *  To enable this functionality for the logs below, set the
 791   *  the number of days before each log should be pruned.
 792   *  If you set the value to 0, the logs will not be pruned.
 793   */
 794  
 795  \$config['log_pruning'] = array(
 796      'admin_logs' => {$config['log_pruning']['admin_logs']}, // Administrator logs
 797      'mod_logs' => {$config['log_pruning']['mod_logs']}, // Moderator logs
 798      'task_logs' => {$config['log_pruning']['task_logs']}, // Scheduled task logs
 799      'mail_logs' => {$config['log_pruning']['mail_logs']}, // Mail error logs
 800      'user_mail_logs' => {$config['log_pruning']['user_mail_logs']}, // User mail logs
 801      'promotion_logs' => {$config['log_pruning']['promotion_logs']} // Promotion logs
 802  );
 803  
 804  ?".">";
 805          fwrite($fh, $configdata);
 806          fclose($fh);
 807      }
 808      echo "<p>The configuration file has been successfully rewritten.</p>";
 809      echo "<p>Click next to continue with the upgrade process.</p>";
 810  
 811      global $footer_extra;
 812      $footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 813  
 814      $output->print_footer("17_updatecss");
 815  }
 816  function upgrade17_updatecss()
 817  {
 818      global $db, $output, $orig_config, $mybb;
 819  
 820      if(file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"))
 821      {
 822          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php";
 823      }
 824      else if(file_exists(MYBB_ROOT."admin/inc/functions_themes.php"))
 825      {
 826          require_once  MYBB_ROOT."admin/inc/functions_themes.php";
 827      }
 828      else
 829      {
 830          $output->print_error("Please make sure your admin directory is uploaded correctly.");
 831      }
 832  
 833      $output->print_header("Updating CSS");
 834  
 835      $query = $db->simple_select("themestylesheets", "*", "name='global.css' OR name='usercp.css'");
 836      while($theme = $db->fetch_array($query))
 837      {
 838          resync_stylesheet($theme);
 839      }
 840  
 841      $query = $db->simple_select("themestylesheets", "*", "name='global.css' OR name='usercp.css'");
 842      while($theme = $db->fetch_array($query))
 843      {
 844          $theme['stylesheet'] = upgrade_css_140_to_160($theme['name'], $theme['stylesheet']);
 845  
 846          // Create stylesheets
 847          cache_stylesheet($theme['tid'], $theme['cachefile'], $theme['stylesheet']);
 848  
 849          $update_stylesheet = array(
 850              "stylesheet" => $db->escape_string($theme['stylesheet']),
 851              "lastmodified" => TIME_NOW
 852          );
 853          $db->update_query("themestylesheets", $update_stylesheet, "sid='{$theme['sid']}'");
 854      }
 855  
 856      echo "<p>The CSS has been successfully updated.</p>";
 857      echo "<p>Click next to continue with the upgrade process.</p>";
 858  
 859      global $footer_extra;
 860      //$footer_extra = "<script type=\"text/javascript\">window.onload = function() { var button = $$('.submit_button'); if(button[0]) { button[0].value = 'Automatically Redirecting...'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
 861  
 862      $output->print_footer("17_done");
 863  }
 864  
 865  function upgrade_css_140_to_160($name, $css)
 866  {
 867      // Update our CSS to the new stuff in 1.6
 868      $parsed_css = css_to_array($css);
 869  
 870      if($name == "global.css")
 871      {
 872          if(is_array($parsed_css))
 873          {
 874              foreach($parsed_css as $class_id => $array)
 875              {
 876                  switch($array['class_name'])
 877                  {
 878                      case '.navigation .active':
 879                          $parsed_css[$class_id]['values'] = str_replace('font-size: small;', 'font-size: 13px;', $array['values']);
 880                          break;
 881                      case '.highlight':
 882                          $parsed_css[$class_id]['values'] = str_replace('padding: 3px;', "padding-top: 3px;\n\tpadding-bottom: 3px;", $array['values']);
 883                          break;
 884                      case '.pm_alert':
 885                      case '.red_alert':
 886                          $parsed_css[$class_id]['values'] .= "\n\tmargin-bottom: 15px;";
 887                          break;
 888                      case '.pagination .pagination_current':
 889                          $parsed_css[$class_id]['values'] .= "\n\tcolor: #000;";
 890                          break;
 891                      default:
 892                  }
 893              }
 894          }
 895  
 896          $to_add = array(
 897              md5('#panel .remember_me input') => array("class_name" => '#panel .remember_me input', "values" => "vertical-align: middle;\n\tmargin-top: -1px;"),
 898              md5('.hiddenrow') => array("class_name" => '.hiddenrow', "values" => 'display: none;'),
 899              md5('.selectall') => array("class_name" => '.selectall', "values" => "background-color: #FFFBD9;\n\tfont-weight: bold;\n\ttext-align: center;"),
 900              md5('.repbox') => array("class_name" => '.repbox', "values" => "font-size:16px;\n\tfont-weight: bold;\n\tpadding:5px 7px 5px 7px;"),
 901              md5('._neutral') => array("class_name" => '._neutral', "values" => "background-color:#FAFAFA;\n\tcolor: #999999;\n\tborder:1px solid #CCCCCC;"),
 902              md5('._minus') => array("class_name" => '._minus', "values" => "background-color: #FDD2D1;\n\tcolor: #CB0200;\n\tborder:1px solid #980201;"),
 903              md5('._plus') => array("class_name" => '._plus', "values" => "background-color:#E8FCDC;\n\tcolor: #008800;\n\tborder:1px solid #008800;"),
 904              md5('.pagination_breadcrumb') => array("class_name" => '.pagination_breadcrumb', "values" => "background-color: #f5f5f5;\n\tborder: 1px solid #fff;\n\toutline: 1px solid #ccc;\n\tpadding: 5px;\n\tmargin-top: 5px;\n\tfont-weight: normal;"),
 905              md5('.pagination_breadcrumb_link') => array("class_name" => '.pagination_breadcrumb_link', "values" => "vertical-align: middle;\n\tcursor: pointer;"),
 906          );
 907      }
 908      else if($name == "usercp.css")
 909      {
 910          $to_add = array(
 911              md5('.usercp_notepad') => array("class_name" => '.usercp_notepad', "values" => "width: 99%;"),
 912              md5('.usercp_container') => array("class_name" => '.usercp_container', "values" => "margin: 5px;\n\tpadding: 8px;\n\tborder:1px solid #CCCCCC;"),
 913          );
 914      }
 915  
 916      foreach($to_add as $class_id => $array)
 917      {
 918          if($already_parsed[$class_id])
 919          {
 920              $already_parsed[$class_id]++;
 921              $class_id .= "_".$already_parsed[$class_id];
 922          }
 923          else
 924          {
 925              $already_parsed[$class_id] = 1;
 926          }
 927  
 928          $array['name'] = "";
 929          $array['description'] = "";
 930  
 931          $parsed_css[$class_id] = $array;
 932      }
 933  
 934      $css = "";
 935      foreach($parsed_css as $class_id => $array)
 936      {
 937          if($array['name'] || $array['description'])
 938          {
 939              $theme['css'] .= "/* ";
 940              if($array['name'])
 941              {
 942                  $array['css'] .= "Name: {$array['name']}";
 943  
 944                  if($array['description'])
 945                  {
 946                      $array['css'] .= "\n";
 947                  }
 948              }
 949  
 950              if($array['description'])
 951              {
 952                  $array['css'] .= "Description: {$array['description']}";
 953              }
 954  
 955              $array['css'] .= " */\n";
 956          }
 957  
 958          $css .= "{$array['class_name']} {\n\t{$array['values']}\n}\n";
 959      }
 960  
 961      return $css;
 962  }
 963  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1