diff options
-rwxr-xr-x | phpBB/bbcode_conversion.php | 205 | ||||
-rw-r--r-- | phpBB/functions/bbcode.php | 25 | ||||
-rw-r--r-- | phpBB/viewtopic.php | 7 |
3 files changed, 227 insertions, 10 deletions
diff --git a/phpBB/bbcode_conversion.php b/phpBB/bbcode_conversion.php new file mode 100755 index 0000000000..a4d62a0325 --- /dev/null +++ b/phpBB/bbcode_conversion.php @@ -0,0 +1,205 @@ +<?php +/*************************************************************************** + * config.php + * ------------------- + * begin : Tuesday, March 20, 2001 + * copyright : (C) 2001 The phpBB Group + * email : support@phpbb.com + * + * $Id: + * + * + ***************************************************************************/ + + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * + ***************************************************************************/ + +include('extension.inc'); +include('config.'.$phpEx); +include('includes/constants.'.$phpEx); +include('functions/functions.'.$phpEx); +include('includes/db.'.$phpEx); +include('functions/bbcode.'.$phpEx); + +set_time_limit(60*60); // Increase maximum execution time to 60 minutes. + + + +$backup_name = "backup_post_text"; +$table_name = POSTS_TEXT_TABLE; +$sql = "CREATE TABLE $backup_name ( + post_id int(10) DEFAULT '0' NOT NULL, + post_text text, + PRIMARY KEY (post_id) +);"; + +echo "<p>Creating backup table.. </p>\n"; +flush(); + +$result = $db->sql_query($sql); +if (!$result) +{ + $db_error = $db->sql_error(); + die("Error doing DB backup table creation. Reason: " . $db_error["message"]); +} + +$sql = "insert into $backup_name select * from $table_name"; + +echo "<p>Populating backup table.. </p>\n"; +flush(); + +$result = $db->sql_query($sql); +if (!$result) +{ + $db_error = $db->sql_error(); + die("Error doing DB backup table data moving. Reason: " . $db_error["message"]); +} + + +$sql = "SELECT p.post_id, t.post_text FROM " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " t WHERE (p.post_id = t.post_id)"; +if(!$result = $db->sql_query($sql)) +{ + die("error getting posts to work on"); +} +if(!$total_rows = $db->sql_numrows($result)) +{ + die("error getting rowcount"); +} + +echo "<p><b>Found $total_rows total rows to work on. </b></p>\n"; +flush(); + +$row = $db->sql_fetchrowset($result); + +for($i = 0; $i < $total_rows; $i++) +{ + $post_id = $row[$i]['post_id']; + $text = $row[$i]['post_text']; + + // undo 1.2.x encoding.. + $text = bbdecode($text); + $text = undo_make_clickable($text); + $text = str_replace("<BR>", "\n", $text); + + // make a uid + $uid = make_bbcode_uid(); + + // do 2.x first-pass encoding.. + $text = bbencode_first_pass($text, $uid); + + $text = addslashes($text); + + // put the uid in the database. + $sql = "UPDATE " . POSTS_TABLE . " SET bbcode_uid='" . $uid . "' WHERE (post_id = $post_id)"; + $result = $db->sql_query($sql); + if (!$result) + { + $db_error = $db->sql_error(); + die("Error doing DB update in posts table. Reason: " . $db_error["message"] . " sql: $sql"); + } + // Put the post text back in the database. + $sql = "UPDATE " . POSTS_TEXT_TABLE . " SET post_text='" . $text . "' WHERE (post_id = $post_id)"; + $result = $db->sql_query($sql); + if (!$result) + { + $db_error = $db->sql_error(); + die("Error doing DB update in post text table. Reason: " . $db_error["message"] . " sql: $sql"); + } + + if (($i % 100) == 0) + { + echo "Done post: <b> $i </b><br>\n"; + flush(); + } + + +} + + + +echo "<p><b>Done.</b></p>\n"; + + + +// ------------------------------------------------------------------------------- +// Everything below here is 1.x BBCode functions. +// ------------------------------------------------------------------------------- + + +function bbdecode($message) { + + // Undo [code] + $code_start_html = "<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>"; + $code_end_html = "</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->"; + $message = str_replace($code_start_html, "[code]", $message); + $message = str_replace($code_end_html, "[/code]", $message); + + // Undo [quote] + $quote_start_html = "<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>"; + $quote_end_html = "</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->"; + $message = str_replace($quote_start_html, "[quote]", $message); + $message = str_replace($quote_end_html, "[/quote]", $message); + + // Undo [b] and [i] + $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message); + $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message); + + // Undo [url] (long form) + $message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message); + + // Undo [url] (short form) + $message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message); + + // Undo [email] + $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message); + + // Undo [img] + $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message); + + // Undo lists (unordered/ordered) + + // <li> tags: + $message = str_replace("<!-- BBCode --><LI>", "[*]", $message); + + // [list] tags: + $message = str_replace("<!-- BBCode ulist Start --><UL>", "[list]", $message); + + // [list=x] tags: + $message = preg_replace("#<!-- BBCode olist Start --><OL TYPE=([A1])>#si", "[list=\\1]", $message); + + // [/list] tags: + $message = str_replace("</UL><!-- BBCode ulist End -->", "[/list]", $message); + $message = str_replace("</OL><!-- BBCode olist End -->", "[/list]", $message); + + return($message); +} + + +/** + * Nathan Codding - Feb 6, 2001 + * Reverses the effects of make_clickable(), for use in editpost. + * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. + * + */ + +function undo_make_clickable($text) { + + $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); + + return $text; + +} + + + + +?>
\ No newline at end of file diff --git a/phpBB/functions/bbcode.php b/phpBB/functions/bbcode.php index 3c895f498a..48fd28c080 100644 --- a/phpBB/functions/bbcode.php +++ b/phpBB/functions/bbcode.php @@ -30,12 +30,12 @@ define("BBCODE_UID_LEN", 10); * a thread. Assumes the message is already first-pass encoded, and has the required * "[uid:...]" tag as the very first thing in the text. */ -function bbencode_second_pass(&$text) +function bbencode_second_pass($text, $uid) { - $uid_tag_length = strpos($text, ']') + 1; - $uid = substr($text, 5, BBCODE_UID_LEN); - $text = substr($text, $uid_tag_length); + //$uid_tag_length = strpos($text, ']') + 1; + //$uid = substr($text, 5, BBCODE_UID_LEN); + //$text = substr($text, $uid_tag_length); // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. @@ -46,7 +46,7 @@ function bbencode_second_pass(&$text) { // Remove padding, return. $text = substr($text, 1); - return TRUE; + return $text; } // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. @@ -108,18 +108,25 @@ function bbencode_second_pass(&$text) // Remove our padding from the string.. $text = substr($text, 1); - return TRUE; + return $text; } // bbencode_second_pass() -function bbencode_first_pass($text) +function make_bbcode_uid() { // Unique ID for this message.. $uid = md5(uniqid(rand())); $uid = substr($uid, 0, BBCODE_UID_LEN); + return $uid; +} + + + +function bbencode_first_pass($text, $uid) +{ // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. $text = " " . $text; @@ -156,7 +163,7 @@ function bbencode_first_pass($text) $text = substr($text, 1); // Add the uid tag to the start of the string.. - $text = '[uid=' . $uid . ']' . $text; + //$text = '[uid=' . $uid . ']' . $text; return $text; @@ -354,7 +361,7 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_ * by this format: [code:1:$uid] ... [/code:1:$uid] * Other tags are in this format: [code:$uid] ... [/code:$uid] */ -function bbencode_second_pass_code(&$text, $uid) +function bbencode_second_pass_code($text, $uid) { $code_start_html = '<TABLE BORDER="0" ALIGN="CENTER" WIDTH="85%"><TR><TD><font size="-1">Code:</font><HR></TD></TR><TR><TD><FONT SIZE="-1"><PRE>'; diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 97a47d82b4..a56c0288bf 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -22,6 +22,7 @@ ***************************************************************************/ include('extension.inc'); include('common.'.$phpEx); +include('functions/bbcode.'.$phpEx); if(!isset($HTTP_GET_VARS['topic'])) // For backward compatibility { @@ -84,7 +85,7 @@ if(!isset($start)) $start = 0; } -$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, r.rank_title, r.rank_image, p.post_time, p.post_id, pt.post_text +$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, r.rank_title, r.rank_image, p.post_time, p.post_id, p.bbcode_uid, pt.post_text FROM ".POSTS_TABLE." p LEFT JOIN ".USERS_TABLE." u ON p.poster_id = u.user_id LEFT JOIN ".RANKS_TABLE." r ON (u.user_rank = r.rank_id) @@ -146,6 +147,7 @@ for($x = 0; $x < $total_posts; $x++) } $message = stripslashes($postrow[$x]["post_text"]); + $bbcode_uid = $postrow[$x]['bbcode_uid']; if(!$allow_html) { @@ -154,8 +156,11 @@ for($x = 0; $x < $total_posts; $x++) if($allow_bbcode) { // do bbcode stuff here + $message = bbencode_second_pass($message, $bbcode_uid); } + $message = str_replace("\n", "<BR>", $message); + if(!($x % 2)) { $color = "#DDDDDD"; |