Broken links after convert
#1
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?
Reply
#2
Wrong Section. Post in MyBB Merge Support.
[Image: eyadHiR.png]
Reply
#3
(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."


?>
Reply
#4
That script however only works for MySQL databases. Instead of including config.php you should require global.php and use the $db object for all your database calls.
Reply
#5
(2010-05-22, 02:31 AM)ralgith Wrote: That script however only works for MySQL databases. Instead of including config.php you should require global.php and use the $db object for all your database calls.

Ah. I'm unfamiliar with myBB, so I just went about it for my own purpose. While the whole 'what if they're not using MySQL(/i)?' though did cross my mind, but I like to think it to be a pretty safe bet that a healthy percentage of other users are using MySQL databases, and decided against writing it for other databases.

It is something I could do, though. If you point me in the direction of documentation for the database class, I'll be more than happy to update my script for more general use. I'm just bit confused of the syntax of db->update_query. I did a quick search through global.php, and it looked like update_query("tablename", "valuestoset", "WHEREstatement").
Reply
#6
I just imported from PHPBB3 and had this issue as well using the latest Merge. I tried running the PHP (I updated the script with my details) and it throws these errors:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 15

Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 16

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 16

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 22

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 22

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/kizza42/rcflyingclub.com/parramatta/mybb/testreplace.php on line 24

I can access PHPMyAdmin, what would be the query to run direct from there to resolve this issue?
Reply
#7
Hello. I have the same problem and I'm currently running your script. It is running but I'm not sure if it's doing what you intended it to do, as there are only about 30K posts on my forum and the script just keeps going and going. It's been running for about and hour now and is around 2 million posts?
Reply
#8
(2010-06-24, 11:55 PM)allbordercollies Wrote: Hello. I have the same problem and I'm currently running your script. It is running but I'm not sure if it's doing what you intended it to do, as there are only about 30K posts on my forum and the script just keeps going and going. It's been running for about and hour now and is around 2 million posts?

Ok, you need to run the following script in the PHPMyAdmin site:

Replace mybbdatabase with the right database name for your site:
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '<!-- e --><a href="mailto:', '[email=');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`,'</a><!-- e -->', '[/email]');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '<!-- l --><a class="postlink-local" href="', '[url=');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '</a><!-- l -->', '[/url]');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '<!-- w --><a class="postlink" href="', '[url=');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '</a><!-- w -->', '[/url]');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '<!-- m --><a class="postlink" href="', '[url=');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '</a><!-- m -->', '[/url]');
update `mybbdatabase`.`mybb_posts` SET `message` = REPLACE(`message`, '">', ']');

Then, you need to fix you private message too, and for this you need to run the following script:

update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '<!-- e --><a href="mailto:', '[email=');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`,'</a><!-- e -->', '[/email]');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '<!-- l --><a class="postlink-local" href="', '[url=');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '</a><!-- l -->', '[/url]');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '<!-- w --><a class="postlink" href="', '[url=');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '</a><!-- w -->', '[/url]');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '<!-- m --><a class="postlink" href="', '[url=');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '</a><!-- m -->', '[/url]');
update `mybbdatabase`.`mybb_privatemessages` SET `message` = REPLACE(`message`, '">', ']');

Let me know if it works, I built that for my forum Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)