[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_admin/ -> update_routines.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_admin/update_routines.php,v $
  14  |     $Revision: 1.193 $
  15  |     $Date: 2006/12/05 10:50:24 $
  16  |     $Author: mrpete $
  17  +----------------------------------------------------------------------------+
  18  */
  19  
  20  require_once ("../class2.php");
  21  
  22  if (isset($pref['signup_options'])) // CONVERT 0.6 STYLE SIGNUP OPTIONS
  23  {
  24      $tmp = explode(".", $pref['signup_options']);
  25      $pref['signup_option_realname']  = $tmp[0];
  26      $pref['signup_option_signature'] = $tmp[7];
  27      $pref['signup_option_image']     = $tmp[8];
  28      $pref['signup_option_timezone']  = $tmp[9];
  29      $pref['signup_option_class']     = $tmp[10];
  30      unset($pref['signup_options']);
  31      save_prefs();
  32  }
  33  
  34  if (!$pref['displayname_maxlength'])
  35  {
  36    $pref['displayname_maxlength'] = 15;
  37    save_prefs();
  38  }
  39  
  40  if (!defined("LAN_UPDATE_8")) { define("LAN_UPDATE_8", ""); }
  41  if (!defined("LAN_UPDATE_9")) { define("LAN_UPDATE_9", ""); }
  42  
  43  if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'forum' AND plugin_installflag='1' ")) {
  44      if(file_exists(e_PLUGIN.'forum/forum_update_check.php'))
  45      {
  46          include_once(e_PLUGIN.'forum/forum_update_check.php');
  47      }
  48  }
  49  if (mysql_table_exists("stat_info") && $sql -> db_Select("plugin", "*", "plugin_path = 'log' AND plugin_installflag='1'")) {
  50      if(file_exists(e_PLUGIN.'log/log_update_check.php'))
  51      {
  52          include_once(e_PLUGIN.'log/log_update_check.php');
  53      }
  54  }
  55  
  56  //content
  57  if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'content' AND plugin_installflag='1' "))
  58  {
  59      if(file_exists(e_PLUGIN.'content/content_update_check.php'))
  60      {
  61          include_once(e_PLUGIN.'content/content_update_check.php');
  62      }
  63  }
  64  
  65  if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'pm' AND plugin_installflag='1' "))
  66  {
  67      if(file_exists(e_PLUGIN.'pm/pm_update_check.php'))
  68      {
  69          include_once(e_PLUGIN.'pm/pm_update_check.php');
  70      }
  71  }
  72  
  73  // $dbupdate["701_to_702"] = LAN_UPDATE_8." .7.1 ".LAN_UPDATE_9." .7.2";
  74  $dbupdate["70x_to_706"] = LAN_UPDATE_8." .70x ".LAN_UPDATE_9." .706";
  75  $dbupdate["617_to_700"] = LAN_UPDATE_8." .617 ".LAN_UPDATE_9." .7";
  76  $dbupdate["616_to_617"] = LAN_UPDATE_8." .616 ".LAN_UPDATE_9." .617";
  77  $dbupdate["615_to_616"] = LAN_UPDATE_8." .615 ".LAN_UPDATE_9." .616";
  78  $dbupdate["614_to_615"] = LAN_UPDATE_8." .614 ".LAN_UPDATE_9." .615";
  79  $dbupdate["611_to_612"] = LAN_UPDATE_8." .611 ".LAN_UPDATE_9." .612";
  80  $dbupdate["603_to_604"] = LAN_UPDATE_8." .603 ".LAN_UPDATE_9." .604";
  81  
  82  function update_check() {
  83      global $ns, $dbupdate, $dbupdatep;
  84      foreach($dbupdate as $func => $rmks) {
  85          if (function_exists("update_".$func)) {
  86              if (!call_user_func("update_".$func, FALSE)) {
  87                  $update_needed = TRUE;
  88                  continue;
  89              }
  90          }
  91      }
  92  
  93      foreach($dbupdatep as $func => $rmks) {
  94          if (function_exists("update_".$func)) {
  95              if (!call_user_func("update_".$func, FALSE)) {
  96                  $update_needed = TRUE;
  97                  continue;
  98              }
  99          }
 100      }
 101  
 102      if ($update_needed === TRUE) {
 103          $txt = "<div style='text-align:center;'>".ADLAN_120;
 104          $txt .= "<br /><form method='post' action='".e_ADMIN."e107_update.php'>
 105          <input class='button' type='submit' value='".LAN_UPDATE."' />
 106          </form></div>";
 107          $ns->tablerender(LAN_UPDATE, $txt);
 108      }
 109  }
 110  /*
 111  // ------------------------------- .7.1 to .7.2 etc ----------------------------------
 112  function update_701_to_702($type='') {
 113  
 114  //  $sql->db_Query_all() must be used for all mysql queries to avoid serious multi-language issues.
 115  
 116  
 117  }
 118  */
 119  
 120  function update_70x_to_706($type='') {
 121      global $sql,$ns;
 122  
 123      if ($type == "do")
 124      {
 125          //rename plugin_rss field
 126          if($sql->db_Field("plugin",5) == "plugin_rss")
 127          {
 128              mysql_query("ALTER TABLE `".MPREFIX."plugin` CHANGE `plugin_rss` `plugin_addons` TEXT NOT NULL;");
 129              catch_error();
 130          }
 131  
 132          if(!$sql->db_Field("plugin",5))  // not plugin_rss so just add the new one.
 133          {
 134              mysql_query("ALTER TABLE `".MPREFIX."plugin` ADD `plugin_addons` TEXT NOT NULL ;");
 135              catch_error();
 136          }
 137  
 138          if($sql->db_Field("dblog",5) == "dblog_query")
 139          {
 140              mysql_query("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_query` `dblog_title` VARCHAR( 255 ) NOT NULL DEFAULT '';");
 141              catch_error();
 142              mysql_query("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_remarks` `dblog_remarks` TEXT NOT NULL;");
 143              catch_error();
 144          }
 145  
 146          if(!$sql->db_Field("plugin","plugin_path","UNIQUE"))
 147          {
 148              if(!mysql_query("ALTER TABLE `".MPREFIX."plugin` ADD UNIQUE (`plugin_path`);"))
 149              {
 150                  $mes = "<div style='text-align:center'>".LAN_UPDATE_12." : <a href='".e_ADMIN."db.php?plugin'>".ADLAN_145."</a>.</div>";
 151                  $ns -> tablerender(LAN_ERROR,$mes);
 152                  catch_error();
 153              }
 154  
 155          }
 156  
 157          if ($sql -> db_Query("SHOW INDEX FROM ".MPREFIX."tmp")) 
 158          {
 159              $row = $sql -> db_Fetch();
 160              if (!in_array('tmp_ip', $row)) {
 161                  mysql_query("ALTER TABLE `".MPREFIX."tmp` ADD INDEX `tmp_ip` (`tmp_ip`);");
 162                  mysql_query("ALTER TABLE `".MPREFIX."upload` ADD INDEX `upload_active` (`upload_active`);");
 163                  mysql_query("ALTER TABLE `".MPREFIX."generic` ADD INDEX `gen_type` (`gen_type`);");
 164              }
 165          }
 166  
 167  
 168          // update new fields
 169          require_once(e_HANDLER."plugin_class.php");
 170          $ep = new e107plugin;
 171          $ep->update_plugins_table();
 172          $ep->save_addon_prefs();
 173  
 174          if(!$sql->db_Field("online",6)) // online_active field
 175          {
 176              mysql_query("ALTER TABLE ".MPREFIX."online ADD online_active INT(10) UNSIGNED NOT NULL DEFAULT '0'");
 177              catch_error();
 178          }
 179  
 180          return '';
 181  
 182      }
 183      else
 184      {
 185  
 186          if($sql->db_Field("plugin",5) == "plugin_rss")
 187          {
 188              return update_needed();
 189          }
 190  
 191          if($sql->db_Field("dblog",5) == "dblog_query")
 192          {
 193              return update_needed();
 194          }
 195  
 196          if(!$sql->db_Field("plugin",5))
 197          {
 198              return update_needed();
 199          }
 200  
 201          if(!$sql->db_Field("plugin","plugin_path","UNIQUE"))
 202          {
 203              return update_needed();
 204          }
 205  
 206          if(!$sql->db_Field("online",6)) // online_active field
 207          {
 208              return update_needed();
 209          }
 210          
 211          if ($sql -> db_Query("SHOW INDEX FROM ".MPREFIX."tmp")) 
 212          {
 213              $row = $sql -> db_Fetch();
 214              if (!in_array('tmp_ip', $row)) {
 215                  return update_needed();
 216              }
 217          }
 218  
 219          // No updates needed
 220           return TRUE;
 221      }
 222  }
 223  
 224  // ------------------------------- .6 to .7 ----------------------------------
 225  function update_617_to_700($type='') {
 226      global $sql, $ns, $mySQLdefaultdb, $pref, $tp, $sysprefs, $eArrayStorage;
 227      if ($type == "do") {
 228  
 229          set_time_limit(400);
 230          $s_prefs = FALSE;
 231  
 232          // Lets build an array with all the table names.
 233          $result = mysql_query("SHOW tables");
 234          while($row = mysql_fetch_row($result))
 235          {
 236              $tablenames[]=$row[0];
 237          }
 238  
 239          // Switch 0.6xx upgraders back to standard English pack ========================
 240          if ($pref['sitelanguage'] == 'English-iso') {
 241              $pref['sitelanguage'] = 'English';
 242              $s_prefs = TRUE;
 243          }
 244  
 245          if ($sql -> db_Select("link_category", "link_category_id")){
 246              if (is_dir(e_LANGUAGEDIR.e_LANGUAGE."-iso")) {
 247                  $pref['sitelanguage'] = $pref['sitelanguage']."-iso";
 248                  $s_prefs = TRUE;
 249              }
 250          }
 251  
 252          // ==============================================================
 253  
 254          // add an index on user_ban - speeds up page render time massively on large user tables.
 255          mysql_query("ALTER TABLE `".MPREFIX."user` ADD INDEX `user_ban_index`(`user_ban`);");
 256          catch_error();
 257  
 258          if(!$sql -> db_Select("userclass_classes", "*", "userclass_editclass='254' ")){
 259              $sql->db_Update("userclass_classes", "userclass_editclass='254' WHERE userclass_editclass ='0' ");
 260              catch_error();
 261          }
 262  
 263          /*
 264          changes by jalist 19/01/05:
 265          altered structure of news table
 266          */
 267              mysql_query("ALTER TABLE ".MPREFIX."news ADD news_comment_total int(10) unsigned NOT NULL default '0'");
 268              catch_error();
 269              $sql->db_Select_gen("SELECT comment_item_id AS id, COUNT(*) AS amount FROM #comments GROUP BY comment_item_id");
 270              $commentArray = $sql->db_getList();
 271              foreach($commentArray as $comments) {
 272                  extract($comments);
 273                  $sql->db_Update("news", "news_comment_total=$amount WHERE news_id=$id");
 274                  catch_error();
 275              }
 276              mysql_query("ALTER TABLE `".MPREFIX."content` CHANGE `content_content` `content_content` LONGTEXT NOT NULL");
 277              catch_error();
 278          /* end */
 279  
 280          /* start poll update */
 281              $query = "CREATE TABLE ".MPREFIX."polls (
 282              poll_id int(10) unsigned NOT NULL auto_increment,
 283              poll_datestamp int(10) unsigned NOT NULL default '0',
 284              poll_start_datestamp int(10) unsigned NOT NULL default '0',
 285              poll_end_datestamp int(10) unsigned NOT NULL default '0',
 286              poll_admin_id int(10) unsigned NOT NULL default '0',
 287              poll_title varchar(250) NOT NULL default '',
 288              poll_options text NOT NULL,
 289              poll_votes text NOT NULL,
 290              poll_ip text NOT NULL,
 291              poll_type tinyint(1) unsigned NOT NULL default '0',
 292              poll_comment tinyint(1) unsigned NOT NULL default '1',
 293              poll_allow_multiple tinyint(1) unsigned NOT NULL default '0',
 294              poll_result_type tinyint(2) unsigned NOT NULL default '0',
 295              poll_vote_userclass tinyint(3) unsigned NOT NULL default '0',
 296              poll_storage_method tinyint(1) unsigned NOT NULL default '0',
 297              PRIMARY KEY  (poll_id)
 298              ) TYPE=MyISAM;";
 299              $sql->db_Select_gen($query);
 300              catch_error();
 301              if($sql -> db_Select("poll"))
 302              {
 303                  $polls = $sql -> db_getList();
 304                  foreach($polls as $row)
 305                  {
 306                      extract($row);
 307                      $poll_options = "";
 308                      $poll_votes = "";
 309                      for($count=1; $count <= 10; $count++)
 310                      {
 311                          $var = "poll_option_".$count;
 312                          $var2 = "poll_votes_".$count;
 313                          if($$var)
 314                          {
 315                              $poll_options .= $$var.chr(1);
 316                              $poll_votes .= $$var2.chr(1);
 317                          }
 318                      }
 319                      $poll_type = (strlen($poll_datestamp) > 9 ? 1 : 2);
 320                      $sql->db_Insert("polls", "$poll_id, $poll_datestamp, 0, $poll_end_datestamp, $poll_admin_id, '$poll_title', '$poll_options', '$poll_votes', '$poll_ip', $poll_type, $poll_comment, 0, 0, 255, 1");
 321                      catch_error();
 322                  }
 323                  $sql -> db_Select("polls", "poll_id", "poll_type=1 ORDER BY poll_datestamp DESC LIMIT 0,1");
 324                  $row = $sql -> db_Fetch();
 325                  $sql -> db_Update("polls", "poll_vote_userclass=0 WHERE poll_id=".$row['poll_id']);
 326                  $sql->db_Select_gen("DROP TABLE ".MPREFIX."poll");
 327                  catch_error();
 328              }
 329          /* end poll update */
 330  
 331          /* general table structure changes */
 332              mysql_query("ALTER TABLE `".MPREFIX."user` CHANGE `user_sess` `user_sess` varchar(100) NOT NULL default ''");
 333              catch_error();
 334          /*    end    */
 335  
 336  
 337          /* start newsfeed update */
 338          if (!mysql_table_exists('newsfeed')) {
 339              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."newsfeed (
 340              newsfeed_id int(10) unsigned NOT NULL auto_increment,
 341              newsfeed_name varchar(150) NOT NULL default '',
 342              newsfeed_url varchar(150) NOT NULL default '',
 343              newsfeed_data longtext NOT NULL,
 344              newsfeed_timestamp int(10) unsigned NOT NULL default '0',
 345              newsfeed_description text NOT NULL,
 346              newsfeed_image varchar(100) NOT NULL default '',
 347              newsfeed_active tinyint(1) unsigned NOT NULL default '0',
 348              newsfeed_updateint int(10) unsigned NOT NULL default '0',
 349              PRIMARY KEY  (newsfeed_id)
 350              ) TYPE=MyISAM;");
 351              catch_error();
 352          }
 353  
 354          if (mysql_table_exists('newsfeed')) {
 355              mysql_query("ALTER TABLE `".MPREFIX."newsfeed` CHANGE `newsfeed_data` `newsfeed_data` LONGTEXT NOT NULL");
 356              catch_error();
 357              $sql -> db_Update("newsfeed", "newsfeed_timestamp='0' ");
 358              catch_error();
 359          }
 360          /*    end     */
 361  
 362          /* start emote update */
 363              $tmp =
 364              'a:28:{s:9:"alien!png";s:6:"!alien";s:10:"amazed!png";s:7:"!amazed";s:9:"angry!png";s:11:"!grr !angry";s:12:"biglaugh!png";s:4:"!lol";s:11:"cheesey!png";s:10:":D :oD :-D";s:12:"confused!png";s:10:":? :o? :-?";s:7:"cry!png";s:19:"&| &-| &o| :(( !cry";s:8:"dead!png";s:21:"x) xo) x-) x( xo( x-(";s:9:"dodge!png";s:6:"!dodge";s:9:"frown!png";s:10:":( :o( :-(";s:7:"gah!png";s:10:":@ :o@ :o@";s:8:"grin!png";s:10:":D :oD :-D";s:9:"heart!png";s:6:"!heart";s:8:"idea!png";s:10:":! :o! :-!";s:7:"ill!png";s:4:"!ill";s:7:"mad!png";s:13:"~:( ~:o( ~:-(";s:12:"mistrust!png";s:9:"!mistrust";s:11:"neutral!png";s:10:":| :o| :-|";s:12:"question!png";s:2:"?!";s:12:"rolleyes!png";s:10:"B) Bo) B-)";s:7:"sad!png";s:4:"!sad";s:10:"shades!png";s:10:"8) 8o) 8-)";s:7:"shy!png";s:4:"!shy";s:9:"smile!png";s:10:":) :o) :-)";s:11:"special!png";s:3:"%-6";s:12:"suprised!png";s:10:":O :oO :-O";s:10:"tongue!png";s:21:":p :op :-p :P :oP :-P";s:8:"wink!png";s:10:";) ;o) ;-)";}';
 365              $sql->db_Insert("core", "'emote_default', '$tmp' ");
 366              catch_error();
 367  
 368              if(!$pref['emotepack']){
 369                      $pref['emotepack'] = "default";
 370              }
 371              mysql_query("ALTER TABLE ".MPREFIX."core CHANGE e107_name e107_name varchar(100) NOT NULL default ''");
 372              catch_error();
 373          /*    end     */
 374  
 375          /* start download updates */
 376          if (!mysql_table_exists("download_mirror")) {
 377              $query = "CREATE TABLE ".MPREFIX."download_mirror (
 378              mirror_id int(10) unsigned NOT NULL auto_increment,
 379              mirror_name varchar(200) NOT NULL default '',
 380              mirror_url varchar(200) NOT NULL default '',
 381              mirror_image varchar(200) NOT NULL default '',
 382              mirror_location varchar(100) NOT NULL default '',
 383              mirror_description text NOT NULL,
 384              mirror_count int(10) unsigned NOT NULL default '0',
 385              PRIMARY KEY  (mirror_id)
 386              ) TYPE=MyISAM;";
 387              $sql->db_Select_gen($query);
 388              catch_error();
 389              mysql_query("ALTER TABLE ".MPREFIX."download ADD download_class TINYINT ( 3 ) UNSIGNED NOT NULL");
 390              catch_error();
 391              mysql_query("ALTER TABLE ".MPREFIX."download_category ADD download_category_order int(10) unsigned NOT NULL default '0'");
 392              catch_error();
 393              mysql_query("ALTER TABLE `".MPREFIX."download` ADD `download_mirror` TEXT NOT NULL , ADD `download_mirror_type` tinyint(1) unsigned NOT NULL default '0' ");
 394              catch_error();
 395          }
 396          /*    end    */
 397  
 398  
 399          /* start user update */
 400              mysql_query("ALTER TABLE ".MPREFIX."user ADD user_loginname varchar(100) NOT NULL default '' AFTER user_name");
 401              catch_error();
 402              mysql_query("ALTER TABLE ".MPREFIX."user ADD user_xup varchar(100) NOT NULL default ''");
 403              catch_error();
 404              $sql->db_Update("user", "user_loginname=user_name WHERE user_loginname=''");
 405              catch_error();
 406          /* end */
 407  
 408          /* start page update */
 409          if (!mysql_table_exists("page")) {
 410              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."page (
 411                page_id int(10) unsigned NOT NULL auto_increment,
 412                page_title varchar(250) NOT NULL default '',
 413                page_text mediumtext NOT NULL,
 414                page_author int(10) unsigned NOT NULL default '0',
 415                page_datestamp int(10) unsigned NOT NULL default '0',
 416                page_rating_flag tinyint(1) unsigned NOT NULL default '0',
 417                page_comment_flag tinyint(1) unsigned NOT NULL default '0',
 418                page_password varchar(50) NOT NULL default '',
 419                page_class varchar(250) NOT NULL default '',
 420                page_ip_restrict text NOT NULL,
 421                page_theme varchar(50) NOT NULL default '',
 422                PRIMARY KEY  (page_id)
 423              ) TYPE=MyISAM;");
 424              catch_error();
 425              mysql_query("ALTER TABLE ".MPREFIX."page CHANGE page_class page_class varchar(250) NOT NULL default ''");
 426              catch_error();
 427          }
 428          /*    end     */
 429  
 430  
 431          // start links update -------------------------------------------------------------------------------------------
 432              if (mysql_table_exists("link_category")) {
 433                  global $IMAGES_DIRECTORY, $PLUGINS_DIRECTORY;
 434  
 435                  $sql->db_Select_gen("CREATE TABLE ".MPREFIX."links_page_cat (
 436                  link_category_id int(10) unsigned NOT NULL auto_increment,
 437                  link_category_name varchar(100) NOT NULL default '',
 438                  link_category_description varchar(250) NOT NULL default '',
 439                  link_category_icon varchar(100) NOT NULL default '',
 440                  PRIMARY KEY  (link_category_id)
 441                  ) TYPE=MyISAM;");
 442                  catch_error();
 443                  $sql->db_Select_gen("CREATE TABLE ".MPREFIX."links_page (
 444                  link_id int(10) unsigned NOT NULL auto_increment,
 445                  link_name varchar(100) NOT NULL default '',
 446                  link_url varchar(200) NOT NULL default '',
 447                  link_description text NOT NULL,
 448                  link_button varchar(100) NOT NULL default '',
 449                  link_category tinyint(3) unsigned NOT NULL default '0',
 450                  link_order int(10) unsigned NOT NULL default '0',
 451                  link_refer int(10) unsigned NOT NULL default '0',
 452                  link_open tinyint(1) unsigned NOT NULL default '0',
 453                  link_class tinyint(3) unsigned NOT NULL default '0',
 454                  PRIMARY KEY  (link_id)
 455                  ) TYPE=MyISAM;");
 456                  catch_error();
 457                  $new_cat_id = 1;
 458                  $sql->db_Select("link_category", "*", "link_category_id!=1 ORDER BY link_category_id");
 459                  while ($row = $sql->db_Fetch()) {
 460                      $link_cat_id[$row['link_category_id']] = $new_cat_id;
 461                      if ($row['link_category_icon']) {
 462                          $link_category_icon = strstr($row['link_category_icon'], "/") ? $row['link_category_icon'] : $IMAGES_DIRECTORY."link_icons/".$row['link_category_icon'];
 463                      } else {
 464                          $link_category_icon = "";
 465                      }
 466                      $link_cat_export[] = "'0', '".$row['link_category_name']."', '".$row['link_category_description']."', '".$link_category_icon."'";
 467                      $link_cat_del[] = $row['link_category_id'];
 468                      $new_cat_id++;
 469                  }
 470  
 471                  foreach ($link_cat_export as $link_cat_export_commit) {
 472                      if (!$sql->db_Insert("links_page_cat", $link_cat_export_commit)) {
 473                          $links_upd_failed = TRUE;
 474                      }
 475                  }
 476  
 477                  $sql->db_Select("links", "*", "link_category!=1 ORDER BY link_category");
 478                  while ($row = $sql->db_Fetch()) {
 479                      if ($row['link_button']) {
 480                          $link_button = strstr($row['link_button'], "/") ? $row['link_button'] : $IMAGES_DIRECTORY."link_icons/".$row['link_button'];
 481                      } else {
 482                          $link_button = "";
 483                      }
 484                      $link_export[] = "'0', '".$row['link_name']."', '".$row['link_url']."', '".$row['link_description']."', '".$link_button."', '".$link_cat_id[$row['link_category']]."', '".$row['link_order']."', '".$row['link_refer']."', '".$row['link_open']."', '".$row['link_class']."'";
 485                      $link_del[] = $row['link_id'];
 486                  }
 487  
 488                  foreach ($link_export as $link_export_commit) {
 489                      if (!$sql->db_Insert("links_page", $link_export_commit)) {
 490                          $links_upd_failed = TRUE;
 491                      }
 492                  }
 493  
 494                  if (!$links_upd_failed) {
 495                      $sql->db_Select_gen("DROP TABLE ".MPREFIX."link_category");
 496  
 497                      foreach ($link_del as $link_del_commit) {
 498                          $sql->db_Delete("links", "link_id='".$link_del_commit."'");
 499                      }
 500                  }
 501                  $sql->db_Insert("plugin", "0, 'Links Page', '1.0', 'links_page', 1");
 502                  $sql->db_Update("links", "link_url = '".$PLUGINS_DIRECTORY."links_page/links.php' WHERE link_url = 'links.php'");
 503  
 504                  $s_prefs = TRUE;
 505              }
 506          // end links update -------------------------------------------------------------------------------------------
 507  
 508          //  #########  McFly's 0.7 Updates ############
 509  
 510          // parse table obsolete
 511          if(mysql_table_exists("parser")){
 512              mysql_query('DROP TABLE `'.MPREFIX.'parser`');
 513              catch_error();
 514          }
 515              mysql_query("ALTER TABLE ".MPREFIX."menus ADD menu_path varchar(100) NOT NULL default ''");
 516              catch_error();
 517  
 518              $sql -> db_Update("menus", "menu_path='poll/' WHERE menu_name='poll_menu' ");
 519              catch_error();
 520  
 521              mysql_query("UPDATE ".MPREFIX."menus SET menu_path = 'custom', menu_name = substring(menu_name,8) WHERE substring(menu_name,1,6) = 'custom'");
 522              catch_error();
 523  
 524              mysql_query("UPDATE ".MPREFIX."menus SET menu_path = menu_name  WHERE menu_path = ''");
 525              catch_error();
 526  
 527          // New dblog table for logging db calls (admin log)
 528          if (!mysql_table_exists("dblog")) {
 529              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."dblog (
 530              dblog_id int(10) unsigned NOT NULL auto_increment,
 531              dblog_type varchar(60) NOT NULL default '',
 532              dblog_datestamp int(10) unsigned NOT NULL default '0',
 533              dblog_user_id int(10) unsigned NOT NULL default '0',
 534              dblog_ip varchar(80) NOT NULL default '',
 535              dblog_query text NOT NULL,
 536              dblog_remarks varchar(255) NOT NULL default '',
 537              PRIMARY KEY  (dblog_id)
 538              ) TYPE=MyISAM;");
 539              catch_error();
 540          }
 541  
 542          // New generic table for storing any miscellaneous data
 543          if (!mysql_table_exists("generic")) {
 544              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."generic (
 545              gen_id int(10) unsigned NOT NULL auto_increment,
 546              gen_type varchar(80) NOT NULL default '',
 547              gen_datestamp int(10) unsigned NOT NULL default '0',
 548              gen_user_id int(10) unsigned NOT NULL default '0',
 549              gen_ip varchar(80) NOT NULL default '',
 550              gen_intdata int(10) unsigned NOT NULL default '0',
 551              gen_chardata text NOT NULL,
 552              PRIMARY KEY  (gen_id)
 553              ) TYPE=MyISAM;");
 554              catch_error();
 555          }
 556  
 557          if (!mysql_table_exists("user_extended")) {
 558              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."user_extended (
 559              user_extended_id int(10) unsigned NOT NULL default '0',
 560              PRIMARY KEY  (user_extended_id)
 561              ) TYPE=MyISAM;");
 562              catch_error();
 563  
 564              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."user_extended_struct (
 565              user_extended_struct_id int(10) unsigned NOT NULL auto_increment,
 566              user_extended_struct_name varchar(255) NOT NULL default '',
 567              user_extended_struct_text varchar(255) NOT NULL default '',
 568              user_extended_struct_type tinyint(3) unsigned NOT NULL default '0',
 569              user_extended_struct_parms varchar(255) NOT NULL default '',
 570              user_extended_struct_values text NOT NULL,
 571              user_extended_struct_default varchar(255) NOT NULL default '',
 572              user_extended_struct_read tinyint(3) unsigned NOT NULL default '0',
 573              user_extended_struct_write tinyint(3) unsigned NOT NULL default '0',
 574              user_extended_struct_required tinyint(3) unsigned NOT NULL default '0',
 575              user_extended_struct_signup tinyint(3) unsigned NOT NULL default '0',
 576              PRIMARY KEY  (user_extended_struct_id)
 577              ) TYPE=MyISAM;");
 578              catch_error();
 579  
 580              $sql->db_Select_gen("ALTER TABLE #user_extended_struct ADD user_extended_struct_applicable tinyint(3) unsigned NOT NULL default '0'");
 581              catch_error();
 582  
 583              $sql->db_Select_gen("ALTER TABLE #user_extended_struct ADD user_extended_struct_order int(10) unsigned NOT NULL default '0'");
 584              catch_error();
 585  
 586              $sql->db_Select_gen("ALTER TABLE #user_extended_struct ADD user_extended_struct_icon VARCHAR( 255 ) NOT NULL");
 587              catch_error();
 588  
 589  
 590              //Begin Extended user field conversion
 591              require_once(e_HANDLER."user_extended_class.php");
 592              $ue = new e107_user_extended;
 593  
 594              if($sql->db_Select("core", " e107_value", " e107_name='user_entended'", 'default'))
 595              {
 596                  $row = $sql->db_Fetch();
 597  
 598                  $user_extended = unserialize($row['e107_value']);
 599                  $new_types = array('text' => 1, 'radio' => 2, 'dropdown' => 3, 'table' => 4);
 600  
 601                  foreach($user_extended as $key => $val)
 602                  {
 603                      unset($new_field);
 604                      $parms = explode("|", $val);
 605                      $ext_name['ue_'.$key] = 'user_'.preg_replace("#\W#","",$parms[0]);
 606                      $new_field['name'] = preg_replace("#\W#","",$parms[0]);
 607                      $new_field['text'] = str_replace('_',' ',$parms[0]); // Spaces are ok now
 608                      $new_field['type'] = $new_types[$parms[1]];
 609                      $new_field['values'] = $parms[2];
 610                      $new_field['default'] = $parms[3];
 611                      $new_field['applicable'] = $parms[4];
 612                      $new_field['read'] = $parms[5];
 613                      $new_field['write'] = e_UC_MEMBER;
 614                      $new_field['signup'] = $pref['signup_ext'.$key];
 615                      $new_field['parms'] = "";
 616                      $new_field['required'] = 0;
 617                      unset($pref['signup_ext'.$key]);
 618                      unset($pref['signup_ext_req'.$key]);
 619                      $ue->user_extended_add($new_field);
 620                  }
 621                  $s_prefs = TRUE;
 622                  if($sql->db_Select('user','user_id, user_prefs',"1 ORDER BY user_id"))
 623                  {
 624                      $sql2 = new db;
 625                      while($row = $sql->db_Fetch())
 626                      {
 627                          $user_pref = unserialize($row['user_prefs']);
 628                          $new_values = "";
 629                          foreach($user_pref as $key => $val)
 630                          {
 631                              if(array_key_exists($key, $ext_name))
 632                              {
 633                                  unset($user_pref[$key]);
 634                                  if($val)
 635                                  {
 636                                      if($new_values)
 637                                      {
 638                                          $new_values .= ", ";
 639                                      }
 640                                      $new_values .= "`".$ext_name[$key]."`='".$val."'";
 641                                  }
 642                              }
 643                          }
 644                          foreach ($user_pref as $key => $prefvalue)
 645                          {
 646                              $user_pref[$key] = $tp->toDB($prefvalue);
 647                          }
 648                          $tmp=addslashes(serialize($user_pref));
 649                          $sql2->db_Update("user", "user_prefs='$tmp' WHERE user_id='{$row['user_id']}'");
 650                          if($new_values)
 651                          {
 652  //                            echo $new_values."<br />";
 653                              $sql2->db_Select_gen("INSERT INTO #user_extended (user_extended_id) values ('{$row['user_id']}')");
 654                              $sql2->db_Update('user_extended', $new_values." WHERE user_extended_id = '{$row['user_id']}'");
 655                          }
 656                      }
 657                  }
 658              }
 659              $sql->db_Select_gen("DELETE FROM #core WHERE e107_name='user_entended'");
 660          }
 661          //End Extended user field conversion
 662  
 663  
 664          // Update user_class field to use #,#,# instead of #.#.#. notation
 665              if ($sql->db_Select('user', 'user_id, user_class')) {
 666                  $sql2 = new db;
 667                  while ($row = $sql->db_Fetch()) {
 668                      $carray = explode('.', $row['user_class']);
 669                      $carray = array_unique(array_diff($carray, array('')));
 670                      if (count($carray) > 1) {
 671                          $new_userclass = implode(',', $carray);
 672                          } else {
 673                          $new_userclass = $carray[0];
 674                      }
 675                      $sql2->db_Update('user', "user_class = '{$new_userclass}' WHERE user_id={$row['user_id']}");
 676                      catch_error();
 677                  }
 678              }
 679  
 680              mysql_query("ALTER TABLE ".MPREFIX."generic CHANGE gen_chardata gen_chardata TEXT NOT NULL");
 681              catch_error();
 682  
 683              mysql_query("ALTER TABLE ".MPREFIX."banner CHANGE banner_active banner_active TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'");
 684              catch_error();
 685  
 686          if ($sql->db_Field("cache",0) == "cache_url") {
 687  
 688              mysql_query('DROP TABLE `'.MPREFIX.'cache`'); // db cache is no longer an available option..
 689              catch_error();
 690          }
 691          $sql->db_Update("banner", "banner_active='255' WHERE banner_active = '0' ");
 692          $sql->db_Update("banner", "banner_active='0' WHERE banner_active = '1' ");
 693          $pref['wm_enclose'] = 1;
 694          $s_prefs = TRUE;
 695          /*
 696          Changes by McFly 2/12/2005
 697          Moving forum rules from wmessage table to generic table
 698          */
 699              if($sql -> db_Select("wmessage"))
 700              {
 701                  while($row = $sql->db_Fetch())
 702                  {
 703                      $wmList[] = $row;
 704                  }
 705                  foreach($wmList as $wm)
 706                  {
 707                      $fieldlist = "";
 708                      $gen_type='wmessage';
 709  
 710                      if($wm['wm_id'] == '1') { $wm_class = $wm['wm_active'] ? e_UC_GUEST : '255'; }
 711                      if($wm['wm_id'] == '2') { $wm_class = $wm['wm_active'] ? e_UC_MEMBER : '255'; }
 712                      if($wm['wm_id'] == '3') { $wm_class = $wm['wm_active'] ? e_UC_ADMIN : '255'; }
 713                      if($wm['wm_id'] == '4') { $gen_type = 'forum_rules_guest'; $wm_class = $wm['wm_active'] ? e_UC_GUEST : '255'; }
 714                      if($wm['wm_id'] == '5') { $gen_type = 'forum_rules_member'; $wm_class = $wm['wm_active'] ? e_UC_MEMBER : '255'; }
 715                      if($wm['wm_id'] == '6') { $gen_type = 'forum_rules_admin'; $wm_class = $wm['wm_active'] ? e_UC_ADMIN : '255'; }
 716  
 717                      if($gen_type != "wmessage")
 718                      {
 719                          $exists = $sql->db_Count('generic','(*)',"WHERE gen_type = '{$gen_type}'");
 720                          if(!$exists)
 721                          {
 722                              $fieldlist = "0,'$gen_type','".time()."','".USERID."','',{$wm_class},'{$wm['wm_text']}'";
 723                          }
 724                      }
 725                      else
 726                      {
 727                          $exists = $sql->db_Count('generic','(*)',"WHERE gen_type = 'wmessage' AND gen_user_id = '".$wm['wm_id']."'");
 728                          if(!$exists)
 729                          {
 730                              $fieldlist = "0,'wmessage','".time()."','".$wm['wm_id']."','',{$wm_class},'{$wm['wm_text']}'";
 731                          }
 732                      }
 733                      if($fieldlist)
 734                      {
 735                          $sql->db_Insert('generic',$fieldlist);
 736                      }
 737                  }
 738                  $sql -> db_Select_gen("DROP TABLE ".MPREFIX."wmessage");
 739                  catch_error();
 740              }
 741  
 742          // ############# END McFly's Updates  ##############
 743  
 744          // start chatbox update -------------------------------------------------------------------------------------------
 745              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='chatbox_menu'")) {
 746                  $sql->db_Insert("plugin", "0, 'Chatbox', '1.0', 'chatbox_menu', 1");
 747                  catch_error();
 748              }
 749          // end chatbox update -------------------------------------------------------------------------------------------
 750  
 751          // Cam's new PRESET Table. -------------------------------------------------------------------------------------------
 752          if (!mysql_table_exists("preset")) {
 753              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."preset (
 754              preset_id int(10) unsigned NOT NULL auto_increment,
 755              preset_name varchar(80) NOT NULL default '',
 756              preset_field varchar(80) NOT NULL default '',
 757              preset_value varchar(255) NOT NULL default '',
 758              PRIMARY KEY  (preset_id)
 759              ) TYPE=MyISAM;");
 760              catch_error();
 761          }
 762  
 763          // News Updates -----------------
 764  
 765              $field1 = $sql->db_Field("news",13);
 766              $field2 = $sql->db_Field("news",14);
 767              $field3 = $sql->db_Field("news",15);
 768  
 769              if($field1 != "news_summary" && $field1 != "news_thumbnail" && $field3 != "news_sticky"){
 770                  mysql_query("ALTER TABLE `".MPREFIX."news` ADD `news_summary` text NOT NULL");
 771                  catch_error();
 772                  mysql_query("ALTER TABLE `".MPREFIX."news` ADD `news_thumbnail` text NOT NULL");
 773                  catch_error();
 774                  mysql_query("ALTER TABLE ".MPREFIX."news ADD news_sticky tinyint(3) unsigned NOT NULL default '0'");
 775                  catch_error();
 776              }
 777  
 778          // Downloads updates - Added March 1, 2005 by McFly
 779  
 780          if (!mysql_table_exists("download_requests")) {
 781              $sql->db_Select_gen("CREATE TABLE ".MPREFIX."download_requests (
 782              download_request_id int(10) unsigned NOT NULL auto_increment,
 783              download_request_userid int(10) unsigned NOT NULL default '0',
 784              download_request_ip varchar(30) NOT NULL default '',
 785              download_request_download_id int(10) unsigned NOT NULL default '0',
 786              download_request_datestamp int(10) unsigned NOT NULL default '0',
 787              PRIMARY KEY  (download_request_id)
 788              ) TYPE=MyISAM;");
 789              catch_error();
 790          }
 791  
 792  
 793  
 794           // fix for the the moving of the stats.php file in 0.7.
 795              if($sql -> db_Select("links", "*", "link_url = 'stats.php'")){
 796                  $sql -> db_Update("links", "link_url='{"."e_PLUGIN"."}log/stats.php' WHERE link_url='stats.php' ");
 797                  catch_error();
 798              }
 799  
 800          // Missing Forum upgrade stuff by Cam.
 801  
 802              global $PLUGINS_DIRECTORY;
 803              if($sql -> db_Select("links", "*", "link_url = 'forum.php'")){
 804                  $sql -> db_Insert("plugin", "0, 'Forum', '1.1', 'forum', '1' ");
 805                  catch_error();
 806                  $sql -> db_Update("links", "link_url='{"."e_PLUGIN"."}forum/forum.php' WHERE link_url='forum.php' ");
 807                  catch_error();
 808              }
 809  
 810              if($sql -> db_Select("menus", "*", "menu_name = 'newforumposts_menu' and menu_path='newforumposts_menu' ")){
 811                  $sql -> db_Update("menus", "menu_path='forum' WHERE menu_name = 'newforumposts_menu' ");
 812                  catch_error();
 813              }
 814  
 815          if($pref['cb_linkreplace'] && !$pref['link_replace']){
 816              $pref['link_text'] = "[link]";
 817              $pref['link_replace'] = 1;
 818              $pref['make_clickable'] = 1;
 819              $pref['cb_linkreplace'] = "";
 820              $s_prefs = TRUE;
 821          }
 822  
 823          // db verify fixes
 824              // Are these needed? To facilitate for users that upgraded to the cvs during development, or?
 825              mysql_query("ALTER TABLE `".MPREFIX."user_extended_struct` DROP `user_extended_struct_signup_show` , DROP `user_extended_struct_signup_required`;");
 826              catch_error();
 827              mysql_query("ALTER TABLE `".MPREFIX."user_extended_struct` ADD `user_extended_struct_signup` TINYINT( 3 ) UNSIGNED DEFAULT '0' NOT NULL AFTER `user_extended_struct_required`;");
 828              catch_error();
 829              mysql_query("ALTER TABLE `".MPREFIX."user_extended_struct` DROP `user_extended_struct_icon`;");
 830              catch_error();
 831              mysql_query("ALTER TABLE `".MPREFIX."user_extended_struct` ADD `user_extended_struct_parent` int(10) unsigned NOT NULL default '0'");
 832              catch_error();
 833              mysql_query("ALTER TABLE `".MPREFIX."user_extended` ADD `user_hidden_fields` TEXT NOT NULL AFTER `user_extended_id`");
 834              catch_error();
 835  
 836  
 837              mysql_query("ALTER TABLE `".MPREFIX."download_category` CHANGE `download_category_class` `download_category_class` TINYINT( 3 ) UNSIGNED DEFAULT '0' NOT NULL");
 838              catch_error();
 839  
 840  
 841              mysql_query("ALTER TABLE `".MPREFIX."generic` CHANGE `gen_chardata` `gen_chardata` TEXT NOT NULL");
 842              catch_error();
 843  
 844              mysql_query("ALTER TABLE `".MPREFIX."news` CHANGE `news_class` `news_class` VARCHAR( 255 ) DEFAULT '0' NOT NULL");
 845              catch_error();
 846              // news_attach removal / field structure changes / 'thumb:' prefix removal
 847              mysql_query("ALTER TABLE `".MPREFIX."news` CHANGE `news_attach` `news_thumbnail` TEXT NOT NULL;");
 848              catch_error();
 849              mysql_query("ALTER TABLE `".MPREFIX."news` CHANGE `news_summary` `news_summary` TEXT NOT NULL;");
 850              catch_error();
 851              if ($sql -> db_Select("news", "news_id, news_thumbnail", "news_thumbnail LIKE '%thumb:%'")) {
 852                  while ($row = $sql -> db_Fetch()) {
 853                      $thumbnail = trim(str_replace('thumb:', '', $row['news_thumbnail']));
 854                      $sql2 -> db_Update("news", "news_thumbnail='".$thumbnail."' WHERE news_id='".$row['news_id']."'");
 855                      catch_error();
 856                  }
 857              }
 858  
 859              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='log'") && !mysql_table_exists("logstats")) {
 860                  $sql->db_Select_gen("CREATE TABLE ".MPREFIX."logstats (
 861                  log_uniqueid int(11) NOT NULL auto_increment,
 862                  log_id varchar(50) NOT NULL default '',
 863                  log_data longtext NOT NULL,
 864                  PRIMARY KEY  (log_uniqueid),
 865                  UNIQUE KEY log_id (log_id)
 866                  ) TYPE=MyISAM;");
 867                  catch_error();
 868              }
 869  
 870          if (isset($pref['log_activate'])) {
 871              if ($pref['log_activate']) {
 872                  $pref['statActivate'] = 1;
 873                  $pref['statCountAdmin'] = 0;
 874                  $pref['statBrowser'] = 1;
 875                  $pref['statOs'] = 1;
 876                  $pref['statScreen'] = 1;
 877                  $pref['statDomain'] = 1;
 878                  $pref['statRefer'] = 1;
 879                  $pref['statQuery'] = 1;
 880                  $pref['statRecent'] = 1;
 881              } else {
 882                  $pref['statActivate'] = 0;
 883              }
 884              unset($pref['log_activate']);
 885              $s_prefs = TRUE;
 886          }
 887  
 888  
 889              // start poll update -------------------------------------------------------------------------------------------
 890              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='poll'")) {
 891                  $sql->db_Insert("plugin", "0, 'Poll', '2.0', 'poll', 1");
 892                  $s_prefs = TRUE;
 893              }
 894              // end poll update -------------------------------------------------------------------------------------------
 895  
 896              // start newsfeed update -------------------------------------------------------------------------------------------
 897              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='newsfeed'")) {
 898                  $sql->db_Insert("plugin", "0, 'Newsfeeds', '2.0', 'newsfeed', 1");
 899                  $s_prefs = TRUE;
 900              }
 901              // end newsfeed update -------------------------------------------------------------------------------------------
 902  
 903              // start stats update -------------------------------------------------------------------------------------------
 904              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='log'")) {
 905                  $sql->db_Insert("plugin", "0, 'Statistic Logging', '2.0', 'log', 1");
 906                  $s_prefs = TRUE;
 907              }
 908              // end stats update -------------------------------------------------------------------------------------------
 909  
 910              // start content update -------------------------------------------------------------------------------------------
 911              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='content'")) {
 912                  $sql->db_Insert("plugin", "0, 'Content Management', '1.0', 'content', 1");
 913                  $s_prefs = TRUE;
 914              }
 915              // end content update -------------------------------------------------------------------------------------------
 916  
 917              // start list_new update -------------------------------------------------------------------------------------------
 918              if (!$sql->db_Select("plugin", "plugin_path", "plugin_path='list_new'")) {
 919                  $sql->db_Insert("plugin", "0, 'List', '1.0', 'list_new', 1");
 920                  $s_prefs = TRUE;
 921              }
 922              // end list_new update -------------------------------------------------------------------------------------------
 923  
 924  
 925          // Truncate logstats table if log_id = pageTotal not found
 926          /* log update - previous log entries are not compatible with later versions, sorry but we have to clear the table :\ */
 927          if (mysql_table_exists("logstats")) {
 928                  if(!$sql->db_Select("logstats","log_id","log_id = 'pageTotal'")){
 929                      mysql_query("TRUNCATE TABLE `".MPREFIX."logstats");
 930                      catch_error();
 931                  }
 932          }
 933          // -----------------------------------------------------
 934  
 935          // Fix corrupted Plugin Table.
 936          $sql -> db_Delete("plugin", " plugin_installflag='0' ");
 937  
 938          // Notify
 939          if (!$sql -> db_Select("core", "e107_name", "e107_name = 'notify_prefs'")) {
 940              $serial_prefs = "a:1:{s:5:\"event\";a:9:{s:7:\"usersup\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:8:\"userveri\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:5:\"flood\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:7:\"subnews\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:5:\"login\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:6:\"logout\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:8:\"newspost\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:7:\"newsupd\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}s:7:\"newsdel\";a:3:{s:4:\"type\";s:3:\"off\";s:5:\"class\";s:3:\"254\";s:5:\"email\";s:0:\"\";}}}";
 941              $notify_prefs = unserialize(stripslashes($serial_prefs));
 942              $handle = opendir(e_PLUGIN);
 943              while (false !== ($file = readdir($handle))) {
 944                  if ($file != "." && $file != ".." && is_dir(e_PLUGIN.$file)) {
 945                      $plugin_handle = opendir(e_PLUGIN.$file."/");
 946                      while (false !== ($file2 = readdir($plugin_handle))) {
 947                          if ($file2 == "e_notify.php") {
 948                              if ($sql -> db_Select("plugin", "plugin_path", "plugin_path='".$file."' AND plugin_installflag='1'")) {
 949                                  $notify_prefs['plugins'][$file] = TRUE;
 950                                  require_once(e_PLUGIN.$file.'/e_notify.php');
 951                                  foreach ($config_events as $event_id => $event_text) {
 952                                      $notify_prefs['event'][$event_id] = array('type' => 'off', 'class' => '254', 'email' => '');
 953                                  }
 954                              }
 955                          }
 956                      }
 957                  }
 958              }
 959              $n_prefs = $tp -> toDB($notify_prefs);
 960              $n_prefs = $eArrayStorage -> WriteArray($n_prefs);
 961              $sql -> db_Insert("core", "'notify_prefs', '".$n_prefs."'");
 962              $pref['notify'] = FALSE;
 963              $s_prefs = TRUE;
 964          }
 965  
 966          // Admin Password Change Menu Display
 967  
 968          if (!isset($pref['adminpwordchange'])) {
 969              $pref['adminpwordchange'] = TRUE;
 970              $s_prefs = TRUE;
 971          }
 972  
 973          // Front Page Upgrade
 974  
 975          if (!is_array($pref['frontpage'])) {
 976              if (!$pref['frontpage']) {
 977                  $up_pref = 'news.php';
 978              } else if ($pref['frontpage'] == 'links') {
 979                  $up_pref = $PLUGINS_DIRECTORY.'links_page/links.php';
 980              } else if ($pref['frontpage'] == 'forum') {
 981                  $up_pref = $PLUGINS_DIRECTORY.'forum/forum.php';
 982              } else if (is_numeric($pref['frontpage'])) {
 983                  $up_pref = $PLUGINS_DIRECTORY.'content/content.php?content.'.$pref['frontpage'];
 984              } else if (substr($pref['frontpage'], -1) != '/' && strpos($pref['frontpage'], '.') === FALSE) {
 985                  $up_pref = $pref['frontpage'].'.php';
 986              } else {
 987                  $up_pref = $pref['frontpage'];
 988              }
 989              unset($pref['frontpage']);
 990              $pref['frontpage']['all'] = $up_pref;
 991              $s_prefs = TRUE;
 992          }
 993  
 994  
 995  
 996          // convert notify prefs from serialised to eArrayStorage
 997          $notify_prefs = $sysprefs -> getArray('notify_prefs');
 998          if (is_array($notify_prefs)) {
 999              $s_prefs = $tp -> toDB($notify_prefs);
1000              $s_prefs = $eArrayStorage -> WriteArray($s_prefs);
1001              $sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs' ");
1002          }
1003  
1004          // New Downloads visibility field.
1005              if($sql->db_Field("download",18) != "download_visible"){
1006                  mysql_query("ALTER TABLE `".MPREFIX."download` ADD `download_visible` varchar(255) NOT NULL default '0';");
1007                  catch_error();
1008                  mysql_query("UPDATE `".MPREFIX."download` SET download_visible = download_class");
1009                  catch_error();
1010                  mysql_query("ALTER TABLE `".MPREFIX."download` CHANGE `download_class` `download_class` varchar(255) NOT NULL default '0'");
1011                  catch_error();
1012              }
1013              mysql_query("ALTER TABLE `".MPREFIX."download_category` CHANGE `download_category_class` `download_category_class` varchar(255) NOT NULL default '0'");
1014              catch_error();
1015  
1016          // Links Update for using Link_Parent. .
1017              if($sql->db_Field("links",7) != "link_parent"){
1018                  mysql_query("ALTER TABLE `".MPREFIX."links` CHANGE `link_refer` `link_parent` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL");
1019                  catch_error();
1020                  $sql -> db_Select("links", "link_id,link_name", "link_name NOT LIKE 'submenu.%' ORDER BY link_name");
1021                  while($row = $sql-> db_Fetch()){
1022                      $name = $row['link_name'];
1023                      $parent[$name] = $row['link_id']; // Possible top level parents
1024                  }
1025                  $sql -> db_Select("links", "link_id,link_name", "link_name LIKE 'submenu.%' ORDER BY link_name");
1026                  while($row = $sql-> db_Fetch()){
1027                      $tmp = explode(".",$row['link_name']);
1028                      if (count($tmp) == 3) {
1029                          $name = $tmp[2]; // submenu.topname.midname
1030                          $parent[$name] = $row['link_id']; // Possible mid-level parents
1031                      }
1032                  }
1033          if(!is_object($sql2)){
1034              $sql2 = new db;
1035                  }
1036                  $sql -> db_Select("links", "link_id,link_name", "link_name LIKE 'submenu.%' ORDER BY link_name");
1037                  while($row = $sql-> db_Fetch()){
1038                      $tmp = explode(".",$row['link_name']);
1039                      $nm = $tmp[1];
1040                      $id = $row['link_id'];
1041                      $sql2 -> db_Update("links", "link_parent='".$parent[$nm]."' WHERE link_id ='$id' ");
1042                      catch_error();
1043                  }
1044                  $sql -> db_Select("links", "link_id,link_name", "link_name LIKE '%.child.%' ORDER BY link_name");
1045                  while($row = $sql-> db_Fetch()){
1046                      $tmp = explode(".",$row['link_name']);
1047                      $nm = $tmp[2]; // submenu.topname.midname.child.finalname
1048                      $id = $row['link_id'];
1049                      $sql2 -> db_Update("links", "link_parent='".$parent[$nm]."' WHERE link_id ='$id' ");
1050                      catch_error();
1051                  }
1052        }
1053  
1054          //20050626 : update links_page_cat and links_page
1055              $field1 = $sql->db_Field("links_page_cat",4);
1056              $field2 = $sql->db_Field("links_page_cat",5);
1057              $field3 = $sql->db_Field("links_page_cat",6);
1058  
1059              if($field1 != "link_category_order" && $field2 != "link_category_class" && $field3 != "link_category_datestamp"){
1060                  mysql_query("ALTER TABLE ".MPREFIX."links_page_cat ADD link_category_order VARCHAR ( 100 ) NOT NULL DEFAULT '0';");
1061                  catch_error();
1062                  mysql_query("ALTER TABLE ".MPREFIX."links_page_cat ADD link_category_class VARCHAR ( 100 ) NOT NULL DEFAULT '0';");
1063                  catch_error();
1064                  mysql_query("ALTER TABLE ".MPREFIX."links_page_cat ADD link_category_datestamp INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0';");
1065                  catch_error();
1066              }
1067              if($sql->db_Field("links_page",10) != "link_datestamp"){
1068                  mysql_query("ALTER TABLE ".MPREFIX."links_page ADD link_datestamp INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0';");
1069                  catch_error();
1070              }
1071  
1072          // Search Update
1073              $search_prefs = $sysprefs -> getArray('search_prefs');
1074              if ((!$sql -> db_Select("core", "e107_name", "e107_name='search_prefs'")) || !isset($pref['search_highlight'])) {
1075                  $serial_prefs = "a:11:{s:11:\"user_select\";s:1:\"1\";s:9:\"time_secs\";s:2:\"60\";s:13:\"time_restrict\";s:1:\"0\";s:8:\"selector\";i:2;s:9:\"relevance\";i:0;s:13:\"plug_handlers\";N;s:10:\"mysql_sort\";i:0;s:11:\"multisearch\";s:1:\"1\";s:6:\"google\";s:1:\"0\";s:13:\"core_handlers\";a:4:{s:4:\"news\";a:5:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";}s:8:\"comments\";a:5:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";}s:5:\"users\";a:5:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";}s:9:\"downloads\";a:5:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";}}s:17:\"comments_handlers\";a:2:{s:4:\"news\";a:3:{s:2:\"id\";i:0;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}s:8:\"download\";a:3:{s:2:\"id\";i:2;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}}}";
1076                  $search_prefs = unserialize(stripslashes($serial_prefs));
1077                  $handle = opendir(e_PLUGIN);
1078                  while (false !== ($file = readdir($handle))) {
1079                      if ($file != "." && $file != ".." && is_dir(e_PLUGIN.$file)) {
1080                          if ($sql -> db_Select("plugin", "plugin_path", "plugin_path='".$file."' AND plugin_installflag='1'") || $file == 'content' || $file == 'forum' || $file == 'links_page' || $file == 'chatbox_menu') {
1081                              $plugin_handle = opendir(e_PLUGIN.$file."/");
1082                              while (false !== ($file2 = readdir($plugin_handle))) {
1083                                  if ($file2 == "e_search.php") {
1084                                      $search_prefs['plug_handlers'][$file] = array('class' => 0, 'pre_title' => 1, 'pre_title_alt' => '', 'chars' => 150, 'results' => 10);
1085                                  }
1086                                  if ($file2 == "search" && is_readable(e_PLUGIN.$file.'/search/search_comments.php')) {
1087                                      require_once(e_PLUGIN.$file.'/search/search_comments.php');
1088                                      $search_prefs['comments_handlers'][$file] = array('id' => $comments_type_id, 'class' => '0', 'dir' => $file);
1089                                      unset($comments_type_id);
1090                                  }
1091                              }
1092                          }
1093                      }
1094                  }
1095                  preg_match("/^(.*?)($|-)/", mysql_get_server_info(), $mysql_version);
1096                  if (version_compare($mysql_version[1], '4.0.1', '<')) {
1097                      $search_prefs['mysql_sort'] = FALSE;
1098                  } else {
1099                      $search_prefs['mysql_sort'] = TRUE;
1100                  }
1101                  $serial_prefs = addslashes(serialize($search_prefs));
1102                  if (!$sql -> db_Select("core", "e107_name", "e107_name='search_prefs'")) {
1103                      $sql -> db_Insert("core", "'search_prefs', '".$serial_prefs."'");
1104                  } else {
1105                      $sql -> db_Update("core", "e107_value='".$serial_prefs."' WHERE e107_name='search_prefs' ");
1106                  }
1107                  if ($pref['search_restrict']) {
1108                      $pref['search_restrict'] = 253;
1109                      } else {
1110                      $pref['search_restrict'] = 0;
1111                  }
1112                  $pref['search_highlight'] = TRUE;
1113                  $s_prefs = TRUE;
1114              }
1115  
1116              // search sort method and search selector updates
1117              if (!isset($search_prefs['selector'])) {
1118                  preg_match("/^(.*?)($|-)/", mysql_get_server_info(), $mysql_version);
1119                  if (version_compare($mysql_version[1], '4.0.1', '<')) {
1120                      $search_prefs['mysql_sort'] = FALSE;
1121                  } else {
1122                      $search_prefs['mysql_sort'] = TRUE;
1123                  }
1124                  $search_prefs['selector'] = 2;
1125                  $search_prefs['multisearch'] = 1;
1126                  unset($search_prefs['search_sort']);
1127              }
1128  
1129              // search content plugin comments id change
1130              if ($search_prefs['comments_handlers']['content']['id'] == '1') {
1131                  $search_prefs['comments_handlers']['content']['id'] = 'pcontent';
1132              }
1133  
1134              // custom pages search added
1135              if (!isset($search_prefs['core_handlers']['pages'])) {
1136                  $search_prefs['core_handlers']['pages'] = array('class' => 0, 'chars' => 150, 'results' => 10, 'pre_title' => 1, 'pre_title_alt' => '', 'order' => 13);
1137              }
1138  
1139          if(!is_array($pref['meta_tag'])){
1140              $pref['meta_tag'] = array($pref['sitelanguage']=>$pref['meta_tag']);
1141          }
1142  
1143              $serial_prefs = addslashes(serialize($search_prefs));
1144              $sql -> db_Update("core", "e107_value='".$serial_prefs."' WHERE e107_name='search_prefs'");
1145  
1146          // end search updates
1147  
1148              $result = mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
1149              catch_error();
1150  
1151              $qry = "SHOW CREATE TABLE `".MPREFIX."links`";
1152              $res = mysql_query($qry);
1153              catch_error();
1154  
1155              if ($res) {
1156                  $row = mysql_fetch_row($res);
1157                  $lines = explode("\n", $row[1]);
1158                  if(strpos($lines[10],"tinyint")){
1159                      mysql_query("ALTER TABLE `".MPREFIX."links` CHANGE `link_class` `link_class` VARCHAR( 255 ) DEFAULT '0' NOT NULL ");
1160                      catch_error();
1161                      mysql_query("ALTER TABLE `".MPREFIX."menus` CHANGE `menu_class` `menu_class` VARCHAR( 255 ) DEFAULT '0' NOT NULL ");
1162                      catch_error();
1163                  }
1164              }
1165  
1166  
1167              if (!function_exists("update_70x_to_706")) {
1168                  if($sql->db_Field("plugin",5) != "plugin_rss"){
1169                      mysql_query("ALTER TABLE `".MPREFIX."plugin` ADD `plugin_rss` varchar(255) NOT NULL default ''");
1170                      catch_error();
1171                  }
1172              }
1173  
1174          //20050630: added comment_lock to comments
1175              if($sql->db_Field("comments",11) != "comment_lock"){
1176                  mysql_query("ALTER TABLE `".MPREFIX."comments` ADD `comment_lock` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';");
1177                  catch_error();
1178              }
1179  
1180              if($sql->db_Field("links_page",11) != "link_author"){
1181                  mysql_query("ALTER TABLE `".MPREFIX."links_page` ADD `link_author` VARCHAR( 255 ) NOT NULL DEFAULT '';");
1182                  catch_error();
1183              }
1184  
1185              if($sql->db_Field("user", 8) == "user_icq")
1186              {
1187                  require_once(e_HANDLER."user_extended_class.php");
1188                  $ue = new e107_user_extended;
1189                  $ue->convert_old_fields();
1190              }
1191  
1192              if (mysql_table_exists("links_page_cat") && $sql -> db_Query("SHOW COLUMNS FROM ".MPREFIX."links_page_cat")) {
1193                  while ($row = $sql -> db_Fetch()) {
1194                      if ($row['Field'] == 'link_category_order' && strpos($row['Type'], 'int') === FALSE) {
1195                          mysql_query("ALTER TABLE `".MPREFIX."links_page_cat` CHANGE `link_category_order` `link_category_order` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL;");
1196                          catch_error();
1197                      }
1198                  }
1199              }
1200  
1201          if (!isset($pref['track_online'])) {
1202              $pref['track_online'] = 1;
1203              $s_prefs = TRUE;
1204          }
1205  
1206          // custom menus / pages update
1207  
1208              unset($type);
1209              global $tp, $ns, $sql;
1210              require_once(e_HANDLER."file_class.php");
1211              $file = new e_file;
1212              $reject = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*', 'Readme.txt');
1213              $cpages = $file -> get_files(e_PLUGIN."custompages", "", $reject);
1214              $cmenus = $file -> get_files(e_PLUGIN."custom", "", $reject);
1215  
1216              $customs = array_merge($cpages, $cmenus);
1217  
1218              $count = 0;
1219              foreach($customs as $p)
1220              {
1221                  $type = (strstr($p['path'], "custompages") ? "" : str_replace(".php", "", $p['fname']));
1222                  $filename = $p['path'].$p['fname'];
1223                  $handle = fopen ($filename, "r");
1224                  $contents = fread ($handle, filesize ($filename));
1225                  fclose ($handle);
1226                  $contents = str_replace("'", "&#039;", $contents);
1227                  if(!preg_match('#\$caption = "(.*?)";#si', $contents, $match))
1228                  {
1229                      preg_match('#<CAPTION(.*?)CAPTION#si', $contents, $match);
1230                  }
1231                  $page_title = $tp -> toDB(trim($match[1]));
1232  
1233                  if(!preg_match('#\$text = "(.*?)";#si', $contents, $match))
1234                  {
1235                      preg_match('#TEXT(.*?)TEXT#si', $contents, $match);
1236                  }
1237  
1238                  $page_text = $tp -> toDB(trim($match[1]));
1239                  $filetime = filemtime($filename);
1240  
1241                  if(!$sql -> db_Select("page", "*", "page_title='$page_title' "))
1242                  {
1243                      $sql -> db_Insert("page", "0, '$page_title', '$page_text', '".USERID."', '".$filetime."', '0', '0', '', '', '', '$type' ");
1244                      $text .= "<b>Inserting: </b> '".$page_title."' <br />";
1245                      $count ++;
1246                  }
1247  
1248                  $iid = mysql_insert_id();
1249  
1250                  if($type)
1251                  {
1252                      if(!$sql -> db_Select("menus", "*", "menu_path='$iid' "))
1253                      {
1254                          mysql_query("UPDATE ".MPREFIX."menus SET menu_pages = '', menu_path='".$iid."' WHERE menu_name = '".$type."'");
1255                      }
1256                  }
1257                  if (strstr($p['path'], "custompages")) {
1258                      if ($sql -> db_Select("links", "*", "link_url LIKE '%custompages/".$p['fname']."%'")) {
1259                          $sql -> db_Update("links", "link_url='page.php?".$iid."' WHERE link_url LIKE '%custompages/".$p['fname']."%'");
1260                      }
1261                  }
1262              }
1263              catch_error();
1264  
1265              if($sql -> db_Select("menus", "*", "menu_pages='dbcustom'")) {
1266                  mysql_query("UPDATE ".MPREFIX."menus SET menu_pages = '' WHERE menu_pages='dbcustom'");
1267              }
1268  
1269              mysql_query("ALTER TABLE `".MPREFIX."news` CHANGE `news_thumbnail` `news_thumbnail` TEXT NOT NULL;");
1270  
1271              // Add forum indexes, remove any extras
1272              if (mysql_table_exists('forum_t') && $sql -> db_Query("SHOW INDEX FROM ".MPREFIX."forum_t"))
1273              {
1274                  $a = array("PRIMARY", "thread_id", "thread_parent", "thread_datestamp", "thread_forum_id");
1275                  while ($row = $sql -> db_Fetch())
1276                  {
1277                      if(!in_array($row['Key_name'], $a))
1278                      {
1279                          mysql_query("ALTER TABLE `".MPREFIX."forum_t` DROP INDEX `".$row['Key_name']."`");
1280                          catch_error();
1281                      }
1282                      $index_list[] = $row['Key_name'];
1283                  }
1284                  $a = array("thread_parent", "thread_datestamp", "thread_forum_id");
1285                  foreach($a as $f)
1286                  {
1287                      if(!in_array($f, $index_list))
1288                      {
1289                          mysql_query("ALTER TABLE `".MPREFIX."forum_t` ADD INDEX ( `{$f}` );");
1290                          catch_error();
1291                      }
1292                  }
1293              }
1294  
1295              if (!isset($pref['download_email'])) {
1296                  $pref['download_email'] = $pref['reported_post_email'];
1297                  $s_prefs = TRUE;
1298              }
1299  
1300          if (!isset($pref['mailer'])) {
1301              $pref['mailer'] = $pref['smtp_enable'] ? 'smtp' : 'php';
1302              $s_prefs = TRUE;
1303          }
1304  
1305          //calendar_menu
1306              if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'calendar_menu' AND plugin_installflag='1' ")) {
1307                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_class int(10) unsigned NOT NULL default '0';");
1308                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_subs tinyint(3) unsigned NOT NULL default '0';");
1309                  // mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_force tinyint(3) unsigned NOT NULL default '0';");
1310                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_ahead tinyint(3) unsigned NOT NULL default '0';");
1311                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_msg1 text;");
1312                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_msg2 text;");
1313                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_notify  tinyint(3) unsigned NOT NULL default '0';");
1314                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_last int(10) unsigned NOT NULL default '0';");
1315                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_today int(10) unsigned NOT NULL default '0';");
1316                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_lastupdate int(10) unsigned NOT NULL default '0';");
1317                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_addclass int(10) unsigned NOT NULL default '0';");
1318  // 2 lines added for V3.6 event calendar
1319                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_description text");
1320                  mysql_query("ALTER TABLE ".MPREFIX."event_cat ADD event_cat_force_class int(10) unsigned NOT NULL default '0';");
1321  
1322                  mysql_query("CREATE TABLE ".MPREFIX."event_subs (
1323                      event_subid int(10) unsigned NOT NULL auto_increment,
1324                      event_userid int(10) unsigned NOT NULL default '0',
1325                      event_cat int(10) unsigned NOT NULL default '0',
1326                      PRIMARY KEY (event_subid)
1327                      ) TYPE=MyISAM;");
1328  
1329                  $row = $sql->db_Fetch();
1330                  if($row['plugin_version'] != '3.5'){
1331                      $sql -> db_Update("plugin", "plugin_version='3.5' WHERE plugin_path = 'calendar_menu' ");
1332                  }
1333              }
1334          // end calendar_menu
1335  
1336          //update plugin_version : links_page
1337          if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'links_page' AND plugin_installflag='1' ")) {
1338              $row = $sql->db_Fetch();
1339              if($row['plugin_version'] != '1.12'){
1340                  $sql -> db_Update("plugin", "plugin_version='1.12' WHERE plugin_path = 'links_page' ");
1341              }
1342          }
1343  
1344          // install new private message plugin if old plugin is installed
1345          if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'pm_menu' AND plugin_installflag='1' "))
1346          {
1347              $sql->db_Insert("plugin", "0, 'Private Messenger', '3.0', 'pm', 1, ''");
1348              catch_error();
1349          }
1350  
1351          if(!array_key_exists('ue_upgrade', $pref)){
1352              $pref['ue_upgrade'] = 1;
1353              $s_prefs = TRUE;
1354          }
1355  
1356          // Add default pref for Max IP signups.
1357          if(!isset($pref['signup_maxip'])){
1358              $pref['signup_maxip'] = 3;
1359              $s_prefs = TRUE;
1360          }
1361  
1362          // -----------------------------------------------------
1363  
1364          // Save all prefs that were set in above update routines
1365          if ($s_prefs == TRUE) {
1366              save_prefs();
1367          }
1368  
1369          return '';
1370  
1371      } else {
1372  
1373          // Check if update is needed to 0.7. -----------------------------------------------
1374          global $pref;
1375          if (!mysql_table_exists("user_extended")) {
1376              return update_needed();
1377          }
1378  
1379          if ($pref['sitelanguage'] == 'English-iso') {
1380              return update_needed();
1381          }
1382  
1383          if (!isset($pref['download_email'])) {
1384              return update_needed();
1385          }
1386  
1387          if($sql -> db_Select("menus", "*", "menu_pages='dbcustom'")) {
1388              return update_needed();
1389          }
1390  
1391          if (mysql_table_exists('forum_t') && $sql->db_Query("SHOW INDEX FROM ".MPREFIX."forum_t"))
1392          {
1393              $a = array("PRIMARY", "thread_parent", "thread_datestamp", "thread_forum_id");
1394              while ($row = $sql->db_Fetch())
1395              {
1396                  if(!in_array($row['Key_name'], $a))
1397                  {
1398                      return update_needed();
1399                  }
1400                  $index_list[] = $row['Key_name'];
1401              }
1402              if(!in_array("thread_parent", $index_list) || !in_array("thread_datestamp", $index_list) || !in_array("thread_forum_id", $index_list))
1403              {
1404                  return update_needed();
1405              }
1406          }
1407  
1408          if (mysql_table_exists('news') && $sql -> db_Query("SHOW COLUMNS FROM ".MPREFIX."news")) {
1409              while ($row = $sql -> db_Fetch()) {
1410                  if ($row['Field'] == 'news_thumbnail' && strpos($row['Null'], 'YES') !== FALSE) {
1411                      return update_needed();
1412                  }
1413              }
1414          }
1415  
1416          if (mysql_table_exists('links_page_cat') && $sql -> db_Query("SHOW COLUMNS FROM ".MPREFIX."links_page_cat")) {
1417              while ($row = $sql -> db_Fetch()) {
1418                  if ($row['Field'] == 'link_category_order' && strpos($row['Type'], 'int') === FALSE) {
1419                      return update_needed();
1420                  }
1421              }
1422          }
1423  
1424        $result = mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
1425          $qry = "SHOW CREATE TABLE `".MPREFIX."links`";
1426          $res = mysql_query($qry);
1427          if ($res) {
1428              $row = mysql_fetch_row($res);
1429              $lines = explode("\n", $row[1]);
1430              if(strpos($lines[10],"tinyint")){
1431                    return update_needed();
1432              }
1433          }
1434  
1435          if($pref['meta_tag']!="" && !is_array($pref['meta_tag'])){
1436              return update_needed();
1437          }
1438  
1439          if(!array_key_exists('ue_upgrade', $pref)){
1440              return update_needed();
1441          }
1442  
1443          if (!function_exists("update_70x_to_706")) {
1444              if($sql->db_Field("plugin",5) != "plugin_rss"){
1445                  return update_needed();
1446              }
1447          }
1448  
1449          if($sql->db_Field("links",7) != "link_parent"){
1450              return update_needed();
1451          }
1452  
1453          if($sql->db_Field("user", 8) == "user_icq")
1454          {
1455              return update_needed();
1456          }
1457  
1458          if($sql->db_Field("user",36) != "user_xup" && $sql->db_Field("user", 30) != "user_xup"){
1459               return update_needed();
1460          }
1461  
1462          if($sql->db_Field("download",18) != "download_visible"){
1463               return update_needed();
1464          }
1465  
1466          if (!$sql -> db_Select("core", "e107_name", "e107_name = 'notify_prefs'")) {
1467               return update_needed();
1468          }
1469  
1470          // search content plugin comments id change
1471          $search_prefs = $sysprefs -> getArray('search_prefs');
1472          if ($search_prefs['comments_handlers']['content']['id'] == '1') {
1473               return update_needed();
1474          }
1475  
1476          // custom pages search added
1477          if (is_array($search_prefs) && !isset($search_prefs['core_handlers']['pages'])) {
1478               return update_needed();
1479          }
1480  
1481          $result = mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
1482          $qry = "SHOW CREATE TABLE `".MPREFIX."user`";
1483          $res = mysql_query($qry);
1484          if ($res) {
1485              $row = mysql_fetch_row($res);
1486              if(!strstr($row[1], "KEY `user_ban_index` (`user_ban`)")) {
1487                   return update_needed();
1488              }
1489          }
1490  
1491          global $pref;
1492          if (!is_array($pref['frontpage'])) {
1493               return update_needed();
1494          }
1495  
1496          if ((!$sql -> db_Select("core", "e107_name", "e107_name='search_prefs'")) || !isset($pref['search_highlight'])) {
1497               return update_needed();
1498          }
1499  
1500          if($sql->db_Field("comments",11) != "comment_lock"){
1501               return update_needed();
1502          }
1503  
1504          if(mysql_table_exists("links_page") && $sql->db_Field("links_page",11) != "link_author"){
1505                return update_needed();
1506          }
1507  
1508          if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'calendar_menu' AND plugin_installflag='1' ")) {
1509              if($sql->db_Field("event_cat",3) != "event_cat_class"){
1510                   return update_needed();
1511              }
1512          }
1513  
1514          // No updates needed
1515           return TRUE;
1516      }
1517  }
1518  
1519  
1520  function update_616_to_617($type='') {
1521      global $sql;
1522  
1523      if ($type == "do") {
1524          mysql_query("ALTER TABLE  ".MPREFIX."poll ADD poll_comment TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL ");
1525          mysql_query("ALTER TABLE  ".MPREFIX."menus ADD menu_pages TEXT NOT NULL ");
1526          $sql2 = new db;
1527          $sql2->db_Update("poll", "poll_comment='1' WHERE poll_id!='0'");
1528          } else {
1529              if($sql->db_Field("menus",5) == "menu_pages"){
1530                  return TRUE;
1531              }
1532  
1533           return update_needed();
1534      }
1535  }
1536  
1537  function update_615_to_616($type='') {
1538      global $sql;
1539      if ($type == "do") {
1540          mysql_query("INSERT INTO ".MPREFIX."wmessage VALUES (4, 'This text (if activated) will appear on a page when \"Forum Rules\" link is clicked on.', '0')");
1541          mysql_query("INSERT INTO ".MPREFIX."wmessage VALUES (5, 'Member rules ----- This text (if activated) will appear on a page when \"Forum Rules\" link is clicked on - only logged in members will see this.', '0')");
1542          mysql_query("INSERT INTO ".MPREFIX."wmessage VALUES (6, 'Administrator rules ----- This text (if activated) will appear on a page when \"Forum Rules\" link is clicked on - only logged in administrators will see this.', '0')");
1543          mysql_query("ALTER TABLE ".MPREFIX."download ADD download_comment TINYINT( 3 ) UNSIGNED NOT NULL ");
1544          mysql_query("ALTER TABLE ".MPREFIX."chatbox CHANGE cb_nick cb_nick VARCHAR( 30 ) NOT NULL default ''");
1545          mysql_query("ALTER TABLE ".MPREFIX."comments CHANGE comment_type comment_type VARCHAR( 10 ) DEFAULT '0' NOT NULL ");
1546          mysql_query("ALTER TABLE ".MPREFIX."comments ADD comment_pid INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL AFTER comment_id ");
1547          mysql_query("ALTER TABLE ".MPREFIX."comments ADD comment_subject VARCHAR( 100 ) NOT NULL AFTER comment_item_id ");
1548          mysql_query("ALTER TABLE ".MPREFIX."user ADD user_customtitle VARCHAR( 100 ) NOT NULL AFTER user_name ");
1549          mysql_query("ALTER TABLE ".MPREFIX."parser ADD UNIQUE (parser_regexp)");
1550          mysql_query("ALTER TABLE ".MPREFIX."userclass_classes ADD userclass_editclass TINYINT( 3 ) UNSIGNED NOT NULL ");
1551          update_extended_616();
1552          } else {
1553  
1554          if($sql->db_Field("userclass_classes",3) == "userclass_editclass"){
1555              return TRUE;
1556          }
1557  
1558           return update_needed();
1559      }
1560  }
1561  
1562  function update_614_to_615($type='') {
1563      global $sql;
1564      if ($type == "do") {
1565          mysql_query("ALTER TABLE ".MPREFIX."submitnews ADD submitnews_category TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER submitnews_title");
1566          mysql_query("ALTER TABLE ".MPREFIX."upload ADD upload_category TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'");
1567          mysql_query("ALTER TABLE ".MPREFIX."online ADD online_pagecount tinyint(3) unsigned NOT NULL default '0'");
1568          mysql_query("ALTER TABLE ".MPREFIX."submitnews ADD submitnews_file VARCHAR(100) NOT NULL default '' ");
1569  
1570          global $DOWNLOADS_DIRECTORY;
1571          $sql2 = new db;
1572          $sql->db_Select("download", "download_id, download_url", "download_filesize=0");
1573          while ($row = $sql->db_Fetch()) {
1574              extract($row);
1575              $sql2->db_Update("download", "download_filesize='".filesize(e_BASE.$DOWNLOADS_DIRECTORY.$download_url)."' WHERE download_id='".$download_id."'");
1576          }
1577          } else {
1578          global $mySQLdefaultdb;
1579  
1580          if($sql->db_Field("submitnews",9) == "submitnews_file"){
1581              return TRUE;
1582          }
1583  
1584               return update_needed();
1585      }
1586  }
1587  
1588  function update_611_to_612($type='') {
1589      global $sql;
1590      if ($type == "do") {
1591          mysql_query("ALTER TABLE ".MPREFIX."news ADD news_render_type TINYINT UNSIGNED NOT NULL ");
1592          mysql_query("ALTER TABLE ".MPREFIX."content CHANGE content_parent content_parent INT UNSIGNED DEFAULT '0' NOT NULL ");
1593          } else {
1594          global $mySQLdefaultdb;
1595  
1596          if($sql->db_Field("news",11) == "news_render_type"){
1597              return TRUE;
1598          }
1599  
1600          return FALSE;
1601      }
1602  }
1603  
1604  function update_603_to_604($type='') {
1605      global $sql;
1606      if ($type == "do") {
1607          mysql_query("ALTER TABLE ".MPREFIX."link_category ADD link_category_icon VARCHAR( 100 ) NOT NULL");
1608          mysql_query("ALTER TABLE ".MPREFIX."headlines ADD headline_image VARCHAR( 100 ) NOT NULL AFTER headline_description");
1609          mysql_query("ALTER TABLE ".MPREFIX."content CHANGE content_page content_parent TINYINT( 3 ) UNSIGNED DEFAULT '0' NOT NULL");
1610          mysql_query("ALTER TABLE ".MPREFIX."content ADD content_review_score TINYINT UNSIGNED NOT NULL AFTER content_type");
1611          mysql_query("ALTER TABLE ".MPREFIX."content CHANGE content_author content_author VARCHAR( 200 ) NOT NULL");
1612          mysql_query("ALTER TABLE ".MPREFIX."content ADD content_pe_icon TINYINT( 1 ) UNSIGNED NOT NULL AFTER content_review_score");
1613          } else {
1614             global $mySQLdefaultdb;
1615          if (mysql_table_exists("link_category")) {
1616              $fields = mysql_list_fields($mySQLdefaultdb, MPREFIX."link_category");
1617              $columns = mysql_num_fields($fields);
1618              for ($i = 0; $i < $columns; $i++) {
1619                  if ("link_category_icon" == mysql_field_name($fields, $i)) {
1620                      return TRUE;
1621                  }
1622              }
1623               return update_needed();
1624              } else {
1625              return TRUE;
1626          }
1627      }
1628  }
1629  
1630  function update_extended_616() {
1631      global $sql, $ns;
1632      $sql2 = new db;
1633      if ($sql2->db_Select("core", " e107_value", " e107_name='user_entended'")) {
1634          $row = $sql2->db_Fetch();
1635          $user_extended = unserialize($row[0]);
1636          if (count($user_extended)) {
1637              if ($sql->db_Select("user", "user_id,user_prefs")) {
1638                  while ($row = $sql->db_Fetch()) {
1639                      $uid = $row[0];
1640                      $user_pref = unserialize($row[1]);
1641                      foreach($user_extended as $key => $v) {
1642                          list($fname, $null) = explode("|", $v, 2);
1643                          $fname = $v;
1644                          if (isset($user_pref[$fname])) {
1645                              $user_pref["ue_{$key}"] = $user_pref[$fname];
1646                              unset($user_pref[$fname]);
1647                          }
1648                      }
1649                      $tmp = addslashes(serialize($user_pref));
1650                      $sql2->db_Update("user", "user_prefs='$tmp' WHERE user_id=$uid");
1651                  }
1652              }
1653          }
1654      }
1655      $ns->tablerender("Extended Users", "Updated extended user field data");
1656  }
1657  
1658  function update_needed()
1659  {
1660      global $ns;
1661      if(E107_DEBUG_LEVEL)
1662      {
1663          $tmp = debug_backtrace();
1664          $ns->tablerender("", "<div style='text-align:center'>Update required in ".basename(__FILE__)." on line ".$tmp[0]['line']."</div>");
1665      }
1666      return FALSE;
1667  }
1668  
1669  function mysql_table_exists($table){
1670       $exists = mysql_query("SELECT 1 FROM ".MPREFIX."$table LIMIT 0");
1671       if ($exists) return TRUE;
1672       return FALSE;
1673  }
1674  
1675  
1676  function catch_error(){
1677      if (mysql_error()!='' && E107_DEBUG_LEVEL != 0) {
1678          $tmp2 = debug_backtrace();
1679          $tmp = mysql_error();
1680          echo $tmp." [ ".basename(__FILE__)." on line ".$tmp2[0]['line']."] <br />";
1681      }
1682      return;
1683  }
1684  
1685  
1686  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7