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 @@ +Creating backup table..

\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 "

Populating backup table..

\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 "

Found $total_rows total rows to work on.

\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("
", "\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: $i
\n"; + flush(); + } + + +} + + + +echo "

Done.

\n"; + + + +// ------------------------------------------------------------------------------- +// Everything below here is 1.x BBCode functions. +// ------------------------------------------------------------------------------- + + +function bbdecode($message) { + + // Undo [code] + $code_start_html = "
Code:
";
+		$code_end_html = "

"; + $message = str_replace($code_start_html, "[code]", $message); + $message = str_replace($code_end_html, "[/code]", $message); + + // Undo [quote] + $quote_start_html = "
Quote:
"; + $quote_end_html = "

"; + $message = str_replace($quote_start_html, "[quote]", $message); + $message = str_replace($quote_end_html, "[/quote]", $message); + + // Undo [b] and [i] + $message = preg_replace("#(.*?)#s", "[b]\\1[/b]", $message); + $message = preg_replace("#(.*?)#s", "[i]\\1[/i]", $message); + + // Undo [url] (long form) + $message = preg_replace("#(.*?)#s", "[url=\\1\\2]\\3[/url]", $message); + + // Undo [url] (short form) + $message = preg_replace("#(.*?)#s", "[url]\\3[/url]", $message); + + // Undo [email] + $message = preg_replace("#(.*?)#s", "[email]\\1[/email]", $message); + + // Undo [img] + $message = preg_replace("##s", "[img]\\1[/img]", $message); + + // Undo lists (unordered/ordered) + + //
  • tags: + $message = str_replace("
  • ", "[*]", $message); + + // [list] tags: + $message = str_replace("", "[/list]", $message); + $message = str_replace("", "[/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("#.*?#i", "\\1", $text); + $text = preg_replace("#.*?#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 = '
    Code:
    ';
    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", "
    ", $message); + if(!($x % 2)) { $color = "#DDDDDD";