From 012256d7446f8837024670ebe05d0f57d41cf7d1 Mon Sep 17 00:00:00 2001
From: Bart van Bragt
Date: Wed, 21 Mar 2001 23:37:01 +0000
Subject: Moved to /develop/ dir
git-svn-id: file:///svn/phpbb/trunk@123 89ea8834-ac86-4346-8a33-228a782c2dd0
---
phpBB/develop/bbcode_conversion.php | 205 ++++++++++++++++++++++++++++++++++++
1 file changed, 205 insertions(+)
create mode 100644 phpBB/develop/bbcode_conversion.php
(limited to 'phpBB/develop/bbcode_conversion.php')
diff --git a/phpBB/develop/bbcode_conversion.php b/phpBB/develop/bbcode_conversion.php
new file mode 100644
index 0000000000..a4d62a0325
--- /dev/null
+++ b/phpBB/develop/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);
+
+ // [list=x] tags:
+ $message = preg_replace("##si", "[list=\\1]", $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
--
cgit v1.2.1