[request] convert HTML tags phpBB2 to BBcode phpBB3

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Suggested Hosts
Sandra1982
Registered User
Posts: 6
Joined: Sat Aug 02, 2008 4:33 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by Sandra1982 »

Unfortunately I have the same problem. I use phpbb already for 5 years and accepted <img and <a. I've searched for mods to accept <img and <a or to convert it to bbcode, but I couldn't find a usefull one. I've found one whichs accepts html, but it accepts EVERYTHING, also javascript. And there's 1 mod which replaces, but it doesn't work (I've contacted the author) and it can't replace all kind of <a or <img tags.

I'm afraid the only solution is exporting the data to .sql file and change everything with an editor... :( but that will be hours and hours of work....

If somebody found a solution for this, PLEASE post it here....thank you in advance!
User avatar
SAFFLEUR
Registered User
Posts: 323
Joined: Thu Nov 24, 2005 5:56 am
Location: Lenoir NC
Contact:

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by SAFFLEUR »

Sandra1982 wrote:Unfortunately I have the same problem. I use phpbb already for 5 years and accepted <img and <a. I've searched for mods to accept <img and <a or to convert it to bbcode, but I couldn't find a usefull one. I've found one whichs accepts html, but it accepts EVERYTHING, also javascript. And there's 1 mod which replaces, but it doesn't work (I've contacted the author) and it can't replace all kind of <a or <img tags.

I'm afraid the only solution is exporting the data to .sql file and change everything with an editor... :( but that will be hours and hours of work....

If somebody found a solution for this, PLEASE post it here....thank you in advance!
SAFFLEUR wrote:
I've seen no covnersion but EXreaction has made a mod that enables HTML tags again in phpBB3. You can find this on his website Lithium Studios.

You'll need to donate to become a supporter and get the MOD, but what's five bucks?
Sandra1982
Registered User
Posts: 6
Joined: Sat Aug 02, 2008 4:33 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by Sandra1982 »

hi,
Thank you for your advice. I've already found that mod, but when I read his document I saw he warns a lot for problems / hacking what might happen. That's why I decided to search for a mod which replace all the html code with bbcode.
On the dutch phpbb forum one member, Ger, helped me a lot. He knew how you can use preg_replace to find a href or img and replace it with the right bbcodes. I've made a function with explanation. You need to use the script in phpbb2, before you convert the forum to phpbb3.

This is the code:

Code: Select all

<?php
echo html_bbcode('phpbb_posts_text','post_id','post_text');
echo html_bbcode('phpbb_users','user_id','user_sig');
echo html_bbcode('phpbb_privmsgs_text','privmsgs_text_id','privmsgs_text');

function html_bbcode($table,$id,$text) {
    //connect to the database and make query of the text which has to be changed
    $c = mysql_connect("","","");
    mysql_select_db("");
  $DB_query = mysql_query("select * from ".$table." where ".$text." like '%<a href%' or ".$text." like '%<img%' ") or die(mysql_error());
    $DB_aantal = mysql_num_rows($DB_query);
    $n=1;
    while($DB_result = mysql_fetch_array($DB_query)) {
    $message = $DB_result[$text];
      //1. Replace <img.. url...> with [img]url[/img]
    preg_match_all('#\<img(.*?)\>#i',$message, $matchees );
    foreach ($matchees as $totaalimg) {}
    foreach ($matchees[0] as $totaal2img) {
        //search for src="url"
        preg_match_all('#src=\"(.*?)\"#i',$totaal2img, $matches );
        foreach ($matches as $key=>$preimg){}
        $replacement = $preimg[0];
        $aantal=count($preimg);
        //nothing found? search for src='url'
        if ($aantal == 0)  {
            unset ($preimg);
            preg_match_all("#src=\'(.*?)\'#i",$totaal2img, $matches );
            foreach ($matches as $preimg){}
            $replacement = $preimg[0];
            $aantal=count($preimg);
            //nothing found? search for src=''url''
            if ($aantal == 0) {
                unset ($preimg);
                preg_match_all("#src=\'\'(.*?)\'\'#i",$totaal2img, $matches );
                foreach ($matches as $preimg){}
                $replacement = $preimg[0];
            }
        }
            if($replacement!="") {
            //replace the complete img string with [img]url[/url]
            $message = str_replace($totaal2img, '[img_max]'.$replacement.'[/img_max]', $message);
            }
    }
    
    //2. Replace <a href="url"...> with [url=..] and replace </a> with [/url]
    preg_match_all('#\<a(.*?)\>#is',$message, $matchees );
    foreach ($matchees as $totaallink){}
    foreach ($matchees[0] as $totaal2link) {
            //search for href="url"
        preg_match_all('#href=\"(.*?)\"#i',$totaal2link, $matches );
        foreach ($matches as $prelink){}
        unset($matches);
        $aantal=count($prelink);
        //nothing found? search for href='url'
        if ($aantal == 0) {
            unset ($prelink);
            preg_match_all("#href=\'(.*?)\'#i",$totaal2link, $matches );
            foreach ($matches as $prelink){}
            unset ($matches);
            $aantal=count($prelink);
            //nothing found? search for href=''urk''
        if ($aantal == 0) {
                unset ($prelink);
                preg_match_all("#href=\'\'(.*?)\'\'#i",$totaal2link, $matches );
                foreach ($matches as $prelink){}
                unset ($matches);
            }
        }
        //replace the complete Ma string with [url=$url]
            if($prelink[0]!="") {
          $message = str_replace($totaal2link, '[url='.$prelink[0].']', $message);
            $message = preg_replace('#\<\/a\>#i', '[/url]', $message);
            }      
    }
    $message=addslashes($message);
        $DB_update = mysql_query("update $table set $text = '$message' where $id = $DB_result[$id]") or die(mysql_error());
        echo ("$n / $DB_aantal: $table $DB_result[$id] \n ");
        $n=$n+1;
    }
}  
?>
This is my instructions:
1) Make a backup of the database
2) Run this script: you need to change the host/login/password/databasename before you can use it. It only replace a href and img, not other html codes like for example <b>.
3) Install phpbb3
4) Before you convert phpbb2, add this bbcode:

Code: Select all

[img_max]{URL}[/img_max]
<img src="{URL}" maxwidth="350"/ border="0">
Show picture max. 350 pixels
this because img_max is used to replace img, this because at my forum there were often very big pictures.
5) Start converting.

kind regards,
Sandra
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by Peter77sx »

iWisdom wrote:I've already got one written, actually. Working on packaging it right now.
Edit: Tada! ;)
Why did you drop that MOD?
raizen
Registered User
Posts: 67
Joined: Sat Jan 05, 2008 8:34 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by raizen »

Hello, i've the same problem i need a covertor, i've already install phpbb 3.0.5 so i cant use the sql solution from phpbb2. :(

Can anyone halp me? sorry for my english i'm italian.
Many tahnks
Sandra1982
Registered User
Posts: 6
Joined: Sat Aug 02, 2008 4:33 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by Sandra1982 »

Don't you have a backup? Maybe it's an idea to go to your backup with php2, use this script I have posted and install php3 after you have converted the text.
raizen
Registered User
Posts: 67
Joined: Sat Jan 05, 2008 8:34 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by raizen »

Hello thanks for your reply.

I've a backup of phpbb2 but user add many posts in phpbb3 and my forum is very big there are 147 000 posts.
Is there a method to replace html code from database in bbcode? I'm interest for youtube..can you help me?
Sandra1982
Registered User
Posts: 6
Joined: Sat Aug 02, 2008 4:33 pm

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by Sandra1982 »

I'm sorry I don't have so many experience with phpbb and php. It already took a lot of time to convert php2 to make it ready for php3.
WingLion
Registered User
Posts: 1
Joined: Sat May 08, 2010 5:00 am
Location: Russia, St.Petersburg

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by WingLion »

Hello from Russia.

I have a few phpbb2 forums in my web. All used html tags.
Sach as s,b,u,i,pre,sup,sub,br,hr

convert all it's manualy is not really.
The mod for convert html to bbcode is actually need.

Some Ideas:

1. convert not in one time.
Partialy converting by portions of posts (5..100) in one time then admin starts this task.
Time between portions convert start - set in admin panel;
number of posts in portion - set in admin panel.
In big forum that convert need big time, but weak server loading

2. html-tags for convert and his bbcode-analog - mast be set in admin-panel.

3. For more security this convert need made as part of STK-mod.

p.s. Sorry for my bad Einglish. English is not native for me.
Russia - the native land of elephants
pk74
Registered User
Posts: 2
Joined: Thu Sep 01, 2011 2:02 am

Re: [request] convert HTML tags phpBB2 to BBcode phpBB3

Post by pk74 »

Did anyone ever complete a mod or other add-on that did this? I tried the script given, but it didn't work so well for some things.. :/
Locked

Return to “[3.0.x] MOD Requests”