(2010-05-18, 01:18 PM)RickR86 Wrote: [ -> ]Hi,
I converted my phpbb forum to mybb.
Many links are broken now, they look like this:
<!-- m --><a class="postlink" href="http://www.megaupload.com/?d=IB6RPFUN" onclick="window.open(this.href);return false;">http://www.megaupload.com/?d=IB6RPFUN</a><!-- m -->
Is there a way to change these links at once to normal?
Nobody replied, so I guess I will.
I don't know what caused the problem, but I wrote a script to fix the issue.
Copy the text below into a file called testreplace.php, and upload it to the same place as the root of your forums. (Wherever the forum install is located, along with announcements.php, attachment.php, calander.php, etc)
I'm assuming it's a mostly default install with all of the tables prefixed with mybb_
After you've changed the information, upload it to your server. Visit the file, and it should start processing your posts immediately.
Goodluck!
Note that this is an unoffical fix.
<?php
include ("inc/config.php");
//thanks to [email protected] for the regex script. [php.net]
function escape_string_for_regex($str)
{
$patterns = array('/\//', '/\^/', '/\./', '/\$/', '/\|/',
'/\(/', '/\)/', '/\[/', '/\]/', '/\*/', '/\+/',
'/\?/', '/\{/', '/\}/', '/\,/');
$replace = array('\/', '\^', '\.', '\$', '\|', '\(', '\)',
'\[', '\]', '\*', '\+', '\?', '\{', '\}', '\,');
return preg_replace($patterns,$replace, $str);
}
mysql_connect($config['database']['hostname'], $config['database']['username'], $config['database']['password']);
mysql_select_db($config['database']['database']);
$limit = 100;
$total=0;
$query = mysql_query("SELECT message,pid FROM mybb_posts LIMIT ".$_GET['start'].", ".($_GET['start'] + $limit));
while ($row = mysql_fetch_assoc($query)) :
$post = $row['message'];
$pid = $row['pid'];
if(preg_match_all('/<!-- m --><a class=\"postlink\" href=\"(.*)\" onclick=\"window.open\(this.href\);return false;\">(.*)<\/a><!-- m -->/iU', $post, $result, PREG_SET_ORDER)) :
$altered = 1;
endif;
$max = count($result) - 1;
$count = 0;
while ($count <= $max) {
$post = preg_replace('/(<!-- m --><a class=\"postlink\" href=\"'.escape_string_for_regex($result[$count][1]).'\" onclick=\"window.open\(this.href\);return false;\">(.*)<\/a><!-- m -->)/iU', '[url='.$result[$count][1].']'.$result[$count][2].'[/url]', $post);
$count++;
$total = $total + 1;
}
if ($altered == 1) :
$altered = 0;
mysql_query("UPDATE mybb_posts SET message='".mysql_real_escape_string($post)."' WHERE pid='".$pid."'");
if (mysql_affected_rows() == 0) :
die(":(");
endif;
endif;
endwhile;
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=testreplace.php?start='.($_GET['start']+$limit).'">';
echo "completed posts ".$_GET['start']." to ". ($_GET['start'] + $limit).". moving on."
?>