1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
<?php
/***************************************************************************
* bbcode_conversion.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.
*
*
***************************************************************************/
//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
die("Please read the first lines of this script for instructions on how to enable it");
//
// Do not change anything below this line.
//
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;
}
?>
|