[ Index ]

PHP Cross Reference of MyBB 1.8.40

title

Body

[close]

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

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref