This script is part of an import series, designed to remove Invision Board (v2.3.x)'s awful BBcode translation from the database and emit it as an SQL script capable of being imported into an ElkArte database. The amount of IP Board code which this requires to run is minimal, and seems to run fine on PHP 5.5. So, if you have a lingering forum on an old server, feel free to mysqldump the database, and feed the script files and database to a newer server.
Last active
December 26, 2015 08:56
-
-
Save kode54/a6e4117e81c329534966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( 'IPB_THIS_SCRIPT', 'public' ); | |
define( 'IPB_LOAD_SQL' , 'queries' ); | |
require_once( '/var/www/path/to/ipb/init.php' ); | |
require_once ROOT_PATH . "sources/ipsclass.php"; | |
require_once KERNEL_PATH . "class_converge.php"; | |
if ( file_exists( ROOT_PATH . "conf_global.php" ) ) | |
{ | |
require_once ROOT_PATH . "conf_global.php"; | |
} | |
require_once ROOT_PATH . "sources/handlers/han_parse_bbcode.php"; | |
/* Check if a string is valid UTF-8 */ | |
function is_utf8($str) { | |
return (bool) preg_match('//u', $str); | |
} | |
/* This block of callbacks and function convert quotes from IP Board syntax | |
to ElkArte syntax */ | |
function cb_fix_quotes_inner($matches) | |
{ | |
$v = substr($matches[2], 1, -1); | |
switch ($matches[1]) | |
{ | |
case 'name': | |
return 'author=' . $v; | |
case 'post': | |
return 'link=msg=' . $v; | |
case 'date': | |
return 'date=' . strtotime( str_replace( ':', ':', $v ) ); | |
} | |
} | |
function cb_fix_quotes_outer($matches) | |
{ | |
return preg_replace_callback( | |
"/([^= ]*)=('(?:\\\\.|[^'\\\\]+)*'|[^ ']*)/", | |
'cb_fix_quotes_inner', | |
$matches[0] | |
); | |
} | |
function fix_quotes($line) | |
{ | |
return preg_replace_callback( | |
'|\[quote (.*)\]|', | |
'cb_fix_quotes_outer', | |
$line | |
); | |
} | |
function cb_fix_urls($matches) | |
{ | |
return '[url=' . substr( $matches[1], 1, -1 ) . ']'; | |
} | |
function fix_urls($line) | |
{ | |
return preg_replace_callback( | |
'/\[url=("(?:\\\\.|[^"\\\\]+)*"|[^ "]*)\]/', | |
'cb_fix_urls', | |
$line | |
); | |
} | |
$ipsclass = new ipsclass(); | |
$ipsclass->vars = $INFO; | |
$parser = new parse_bbcode(); | |
$parser->ipsclass =& $ipsclass; | |
$parser->allow_update_caches = 0; | |
$parser->bypass_badwords = 1; | |
$parser->parse_bbcode = 1; | |
$parser->parse_nl2br = 1; | |
$ipsclass->init_db_connection(); | |
$first_post = 0; | |
while (1) | |
{ | |
$ipsclass->DB->build_query( array( 'select' => '*', 'from' => 'posts', 'limit' => array($first_post, '200') ) ); | |
$ipsclass->DB->simple_exec(); | |
if ( ! $ipsclass->DB->get_num_rows() ) break; | |
$posts = array(); | |
while ( $row = $ipsclass->DB->fetch_row() ) | |
{ | |
$posts[] = $row; | |
} | |
$ipsclass->DB->free_result(); | |
foreach ( $posts as $row ) | |
{ | |
$row['post_htmlstate'] = isset($row['post_htmlstate']) ? $row['post_htmlstate'] : 0; | |
$parser->parse_html = intval($row['post_htmlstate']); | |
$parser->parse_smilies = intval($row['use_emo']); | |
if ( $parser->parse_html ) | |
{ | |
$row['post'] = str_replace( "<#EMO_DIR#>", "<#EMO_DIR>", $row['post'] ); | |
$row['post'] = preg_replace( "#(\s)?<([^>]+?)emoid=\"(.+?)\"([^>]*?)".">(\s)?#is", "\\1\\3\\5", $row['post'] ); | |
$row['post'] = str_replace( "<#EMO_DIR>", "<#EMO_DIR#>", $row['post'] ); | |
$row['post'] = $parser->convert_ipb_html_to_html( $row['post'] ); | |
$row['post'] = htmlspecialchars( $row['post'] ); | |
if ( $parser->parse_nl2br ) | |
{ | |
$row['post'] = str_replace( '<br>', "\n", $row['post'] ); | |
$row['post'] = str_replace( '<br />', "\n", $row['post'] ); | |
} | |
} | |
$row['post'] = $parser->pre_edit_parse( $row['post'] ); | |
$row['post'] = fix_quotes($row['post']); | |
$row['post'] = fix_urls($row['post']); | |
$row['post'] = str_replace( | |
array("\000", "\r", "\n" , "'" ), | |
array('' , '' , '<br>', '''), | |
$row['post'] | |
); | |
echo 'UPDATE `elkarte_messages` SET `body` = \'' . $row['post'] . '\' WHERE `id_msg` = ' . intval($row['pid']) . ';' . "\n"; | |
} | |
$first_post += 200; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment