Upgrade Script #5 | > Script written by Matt Mecham | > Date started: 10th June 2003 | +-------------------------------------------------------------------------- */ //----------------------------------------------- // USER CONFIGURABLE ELEMENTS //----------------------------------------------- // Root path $root_path = "./"; //----------------------------------------------- // NO USER EDITABLE SECTIONS BELOW //----------------------------------------------- error_reporting (E_ERROR | E_WARNING | E_PARSE); set_magic_quotes_runtime(0); $template = new template; $std = new installer; $VARS = $std->parse_incoming(); //-------------------------------- // Import $INFO, now! //-------------------------------- require $root_path."conf_global.php"; //-------------------------------- // Load the DB driver and such //-------------------------------- $INFO['sql_driver'] = !$INFO['sql_driver'] ? 'mySQL' : $INFO['sql_driver']; $to_require = $root_path."sources/Drivers/".$INFO['sql_driver'].".php"; require ($to_require); $DB = new db_driver; $DB->obj['sql_database'] = $INFO['sql_database']; $DB->obj['sql_user'] = $INFO['sql_user']; $DB->obj['sql_pass'] = $INFO['sql_pass']; $DB->obj['sql_host'] = $INFO['sql_host']; $DB->obj['sql_tbl_prefix'] = $INFO['sql_tbl_prefix']; // Get a DB connection $DB->connect(); // Switch off auto_error $DB->return_die = 1; //--------------------------------------- // Sort out what to do.. //--------------------------------------- switch($VARS['a']) { case 'tables': do_tables(); break; case 'alter': do_alter(); break; case 'index': do_index(); break; case 'insert': do_insert(); break; case 'templates': do_templates(); break; case 'cleanup': do_cleanup(); break; case 'optimize': do_optimize(); break; default: do_intro(); break; } //+--------------------------------------- function do_optimize() { global $std, $template, $root, $DB; run_sql('optimize'); $template->print_top('Optimization Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2 COMPLETE
Your new v1.2 installation has been optimized
The upgrade is now complete and you may go to your board!

PLEASE REMOVE THIS UPGRADE SCRIPT AS SOON AS POSSIBLE
 
"; $template->output(); } //+--------------------------------------- function do_cleanup() { global $std, $template, $root, $DB; // Insert new CSS $css_text = get_main_css(); $DB->query("INSERT INTO ibf_css (css_name, css_text, css_comments) VALUES ('Invision Style Sheet (1.2)', '$css_text', NULL)"); $new_css_id = $DB->get_insert_id(); //--------------------------------------------- // Save new wrapper //--------------------------------------------- $DB->query("INSERT INTO ibf_templates set template='".get_main_wrapper()."', name='IPB 1.2 Wrapper'"); $new_wrap_id = $DB->get_insert_id(); //--------------------------------------------- // Change all old skin sets to hidden //--------------------------------------------- $DB->query("UPDATE ibf_skins SET hidden=1, default_set=0"); // Get a new ID for the new skin set $barney = array( 'sname' => "IPB Skin Set 1.2 (NEW)", 'set_id' => 1, 'tmpl_id' => $new_wrap_id, 'img_dir' => 1, 'css_id' => $new_css_id, 'hidden' => 0, 'default_set'=> 1, 'macro_id' => 1, ); $DB->query("REPLACE INTO ibf_macro_name SET set_id=1, set_name='IPB 1.2 Macro Set'"); $DB->query("SELECT MAX(sid) as new_id FROM ibf_skins"); $row = $DB->fetch_row(); $barney['sid'] = $row['new_id'] + 1; $db_string = $DB->compile_db_insert_string( $barney ); $DB->query("INSERT INTO ibf_skins (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")"); // Change member skins to default $DB->query("UPDATE ibf_members SET skin=NULL"); //--------------------------------------------- // Sort out new forum masks //--------------------------------------------- $oq = $DB->query("SELECT g_id, g_title FROM ibf_groups ORDER BY g_id"); while( $r = $DB->fetch_row($oq) ) { $nq = $DB->query("REPLACE INTO ibf_forum_perms SET perm_id={$r['g_id']}, perm_name='{$r['g_title']} Mask'"); $bq = $DB->query("UPDATE ibf_groups SET g_perm_id={$r['g_id']} WHERE g_id={$r['g_id']}"); } //--------------------------------------------- // Remove old macros //--------------------------------------------- $DB->query("DELETE FROM ibf_macro WHERE macro_value IN ('M_ADDMEM', 'M_DELETE', 'M_REPLY', 'tbl_width', 'tbl_border')"); //--------------------------------------------- // Other stuff //--------------------------------------------- $DB->query("update ibf_members SET restrict_post=0"); $oq = $DB->query("SELECT * FROM ibf_rules"); while ( $r = $DB->fetch_row($oq) ) { $nq = $DB->query("UPDATE ibf_forums SET rules_title='{$r['title']}', rules_text='{$r['body']}' WHERE id={$r['fid']}"); } $DB->query("drop table if exists ibf_rules"); $DB->query("update ibf_messages SET read_state=1 where vid='sent'"); $DB->query("DROP TABLE if exists ibf_attachments"); $template->print_top('Upgrade Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
Upgrade Complete!
The upgrade was successful!

Skin Set Changes
Unfortunately v1.1.X skins are not compatible with this new version. All old skin sets have been set to 'hidden' and all members have been moved onto the new default skin.

The new skin set will use the directory 'style_images/1/' as the image directory. Ensure that all the images in there have been updated from the download zip. If the directory does not exist, create it and upload the contents of the folder 'style_images/1/' from the zip file.

IF YOU DO NOT WISH TO OPTIMIZE PLEASE REMOVE THIS UPGRADE SCRIPT AS SOON AS POSSIBLE

Optimization
Proceed if you wish to complete your IPB upgrade by optimizing the tables - this step can take some time depending on the amount of topics and posts you have. If you have a very large amount of posts (over 500,000) you might want to skip this.

Optimize my IPB installation >>
 
"; $template->output(); } //+--------------------------------------- function do_templates() { global $std, $template, $root, $DB; //----------------------------------- // Lets open the style file //----------------------------------- $style_file = $root.'install_templates.txt'; if ( ! file_exists($style_file) ) { install_error("Could not locate '$style_file'.

Check to ensure that this file exists in the same location as this script.

You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes"); } if ( $fh = fopen( $style_file, 'r' ) ) { $data = fread($fh, filesize($style_file) ); fclose($fh); } else { install_error("Could open '$style_file'"); } if (strlen($data) < 100) { install_error("Err 1:'$style_file' is incomplete, please re-upload a fresh copy over the existing copy on the server'"); } // Chop up the data file. $template_rows = explode( "||~&~||", $data ); $crows = count($template_rows); if ( $crows < 100 ) { install_error("Err2: (Found $crows rows) '$style_file' is incomplete, please re-upload a fresh copy over the existing copy on the server'"); } //----------------------------------- // Delete current skins in #1 //----------------------------------- $DB->query("DELETE FROM ibf_skin_templates WHERE set_id=1"); //----------------------------------- // Lets populate the database! //----------------------------------- foreach( $template_rows as $q ) { $DB->error = ""; $q = trim($q); //print $q; if (strlen($q) < 5) { continue; } $DB->query("INSERT INTO ibf_skin_templates (set_id, group_name, section_content, func_name, func_data, updated, can_remove) VALUES $q"); if ( $DB->error != "" ) { install_error( "mySQL Error: ".$DB->error ); } } //--------------------------------------- $template->print_top('Step 5 Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
The templates have been inserted
You may now proceed to the next step.

Proceed to Step 6: Finishing Up >>
 
"; $template->output(); } //+--------------------------------------- function do_insert() { global $std, $template, $root, $DB; run_sql('insert'); $template->print_top('Step 4 Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
The new data has been inserted
You may now proceed to the next step.

Proceed to Step 5: Insert New Templates >>
 
"; $template->output(); } //+--------------------------------------- function do_index() { global $std, $template, $root, $DB; run_sql('index'); $template->print_top('Step 3 Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
The indexes have been adjusted
You may now proceed to the next step.

Proceed to Step 4: Insert New Data >>
 
"; $template->output(); } //+--------------------------------------- function do_alter() { global $std, $template, $root, $DB; run_sql('alter'); $template->print_top('Step 2 Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
The tables have been altered
You may now proceed to the next step.

Proceed to Step 3: Alter Indexes >>
 
"; $template->output(); } //+--------------------------------------- function do_tables() { global $std, $template, $root, $DB; run_sql('tables'); $template->print_top('Step 1 Complete'); $template->contents .= "
Upgrade from v1.1.X to v1.2
The new tables have been created
You may now proceed to the next step.

Proceed to Step 2: Alter Existing Tables >>
 
"; $template->output(); } //+--------------------------------------- function do_intro() { global $std, $template, $root; $template->print_top('Welcome'); $template->contents .= "
Intro Welcome to IPB

Welcome to the Invision Board Upgrade Utility

Before you run this upgrade tool, please ensure that ALL of the source, language and skin files have been uploaded into the corresponding directories on your server.

This script should be in the root forum directory (the same directory that index.php is in).

This installer will alter the database for the new format and install the skin and macro files.

Please ensure that 'install_templates.txt' is uploaded and in the same directory as this script.

Also, please ensure that all the new skin_*.php files have been uploaded into 'Skin/s1' before starting this upgrader. If you wish to keep the old skin data in that directory, please copy the directory now before proceeding. Running this installer will set all existing skins to 'hidden' and install a new default skin pack "; $style_file = $root."install_templates.txt"; $warnings = array(); if ( ! file_exists($style_file) ) { $warnings[] = "Cannot locate the file 'install_templates.txt'. This should be uploaded into the same directory as this script!"; } if ( count($warnings) > 0 ) { $err_string = "
  • ".implode( "
  • ", $warnings )."
"; $template->contents .= "

Warning! The following errors must be rectified before continuing!

$err_string
"; } else { $template->contents .= "

Proceed to Step 1: Create New Tables >>
"; } $template->output(); } function install_error($msg="") { global $std, $template, $root; $template->print_top('Warning!'); $template->contents .= "
• WARNING!
The following errors must be rectified before continuing!
Please go back and try again!

$msg
"; $template->output(); } //+------------------------------------------------- // GLOBAL ROUTINES //+------------------------------------------------- function fatal_error($message="", $help="") { echo("$message

$help"); exit; } //+-------------------------------------------------------------------------- // CLASSES //+-------------------------------------------------------------------------- class template { var $contents = ""; function output() { echo $this->contents; echo "


© 2002 Invision Board (www.invisionboard.com)
"; exit(); } //-------------------------------------- function print_top($title="") { $this->contents = " Invision Power Board Set Up :: $title
Invision Power Board Installer
 

"; } } class installer { function parse_incoming() { global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR; $return = array(); if( is_array($HTTP_GET_VARS) ) { while( list($k, $v) = each($HTTP_GET_VARS) ) { //$k = $this->clean_key($k); if( is_array($HTTP_GET_VARS[$k]) ) { while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) ) { $return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2); } } else { $return[$k] = $this->clean_value($v); } } } // Overwrite GET data with post data if( is_array($HTTP_POST_VARS) ) { while( list($k, $v) = each($HTTP_POST_VARS) ) { //$k = $this->clean_key($k); if ( is_array($HTTP_POST_VARS[$k]) ) { while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) ) { $return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2); } } else { $return[$k] = $this->clean_value($v); } } } return $return; } function clean_key($key) { if ($key == "") { return ""; } $key = preg_replace( "/\.\./" , "" , $key ); $key = preg_replace( "/\_\_(.+?)\_\_/" , "" , $key ); $key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key ); return $key; } function clean_value($val) { if ($val == "") { return ""; } $val = preg_replace( "/&/" , "&" , $val ); $val = preg_replace( "//" , "-->" , $val ); $val = preg_replace( "/