2005-09-20 05:36:35 +00:00
|
|
|
<?php
|
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once('../inc/sanitize_html.inc');
|
|
|
|
db_init();
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
set_time_limit(0);
|
2005-09-20 05:36:35 +00:00
|
|
|
|
|
|
|
function image_as_bb($text){
|
2005-09-25 05:47:48 +00:00
|
|
|
// This function depends on sanitized HTML
|
|
|
|
|
|
|
|
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
|
|
|
|
$replacement = '[img]$2[/img]';
|
2005-09-20 05:36:35 +00:00
|
|
|
$text = preg_replace($pattern, $replacement, $text);
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
|
|
|
|
$replacement = '[img]$2[/img]';
|
2005-09-20 05:36:35 +00:00
|
|
|
$text = preg_replace($pattern, $replacement, $text);
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function link_as_bb($text){
|
|
|
|
/* This function depends on sanitized HTML */
|
|
|
|
// Build some regex (should be a *lot* faster)
|
2005-09-25 05:47:48 +00:00
|
|
|
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
|
|
|
|
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
|
2005-09-20 05:36:35 +00:00
|
|
|
$text = preg_replace($pattern, $replacement, $text);
|
2005-09-25 05:47:48 +00:00
|
|
|
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
|
|
|
|
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
|
2005-09-20 05:36:35 +00:00
|
|
|
$text = preg_replace($pattern, $replacement, $text);
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
$pattern = "@</a>@si";
|
|
|
|
$replacement = '[/url]';
|
2005-09-20 05:36:35 +00:00
|
|
|
$text = preg_replace($pattern, $replacement, $text);
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatting_as_bb($text){
|
|
|
|
/* This function depends on sanitized HTML */
|
|
|
|
$in[]="<b>";$out[]="[b]";
|
|
|
|
$in[]="</b>";$out[]="[/b]";
|
|
|
|
|
|
|
|
$in[]="<i>";$out[]="[i]";
|
|
|
|
$in[]="</i>";$out[]="[/i]";
|
|
|
|
|
|
|
|
$in[]="<u>";$out[]="[u]";
|
|
|
|
$in[]="</u>";$out[]="[/u]";
|
|
|
|
|
|
|
|
$in[]="<b>";$out[]="[b]";
|
|
|
|
$in[]="</b>";$out[]="[/b]";
|
|
|
|
|
|
|
|
$in[]="<ul>";$out[]="[list]";
|
|
|
|
$in[]="</ul>";$out[]="[/list]";
|
|
|
|
|
|
|
|
$in[]="<ol>";$out[]="[list=1]";
|
|
|
|
$in[]="</ol>";$out[]="[/list]";
|
|
|
|
|
|
|
|
$in[]="<pre>";$out[]="[pre]";
|
|
|
|
$in[]="</pre>";$out[]="[/pre]";
|
|
|
|
|
2005-09-30 01:29:58 +00:00
|
|
|
$in[]="</br>";$out[]="\n";
|
|
|
|
$in[]="<br/>";$out[]="\n";
|
2005-09-20 05:36:35 +00:00
|
|
|
$in[]="<br>";$out[]="\n";
|
2005-09-25 05:47:48 +00:00
|
|
|
$in[]=">";$out[]=">";
|
|
|
|
$in[]="<";$out[]="<";
|
|
|
|
$in[]="&";$out[]="&";
|
2005-09-20 05:36:35 +00:00
|
|
|
|
|
|
|
return str_replace($in, $out, $text);
|
|
|
|
}
|
|
|
|
|
2005-09-20 17:54:52 +00:00
|
|
|
function fix_text($text) {
|
|
|
|
$text = sanitize_html($text);
|
|
|
|
$text = image_as_bb($text);
|
|
|
|
$text = link_as_bb($text);
|
|
|
|
$text = formatting_as_bb($text);
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
function fix_post($post) {
|
|
|
|
$text = fix_text($post->content);
|
|
|
|
if ($text != $post->content) {
|
|
|
|
$query = "update post set content = '".mysql_escape_string($text)."' where id=".$post->id;
|
|
|
|
//echo "$post->content\n\n";
|
|
|
|
//echo "$post->thread $query\n\n";
|
|
|
|
$retval = mysql_query($query);
|
|
|
|
if (!$retval) {
|
|
|
|
echo mysql_error();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 17:54:52 +00:00
|
|
|
function fix_posts() {
|
|
|
|
$start_id = 0; //Set this to something else if you like
|
|
|
|
$posts = mysql_query("select * from post where id>$start_id order by id");
|
|
|
|
echo mysql_error();
|
|
|
|
$i=0;
|
2005-09-25 05:47:48 +00:00
|
|
|
while ($post = mysql_fetch_object($posts)){
|
2005-09-20 17:54:52 +00:00
|
|
|
$i++;
|
|
|
|
if ($i%100 == 0) { //For every 100 posts
|
2005-09-25 05:47:48 +00:00
|
|
|
echo $post->id.". "; flush(); // print out where we are
|
|
|
|
//usleep(200000);
|
2005-09-20 17:54:52 +00:00
|
|
|
}
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
if ($post->id > $start_id){
|
|
|
|
fix_post($post);
|
2005-09-20 17:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
// use this to patch problem cases; hand-edit
|
|
|
|
function fix_fix() {
|
|
|
|
$posts = mysql_query("select * from post where id=99");
|
|
|
|
$post = mysql_fetch_object($posts);
|
|
|
|
fix_post($post);
|
|
|
|
}
|
|
|
|
|
2005-09-20 17:54:53 +00:00
|
|
|
fix_posts();
|
2005-09-25 05:47:48 +00:00
|
|
|
//fix_fix();
|
2005-09-20 05:36:35 +00:00
|
|
|
|
|
|
|
?>
|