Remove [img:999:999] bbcode tags from posts

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Anti-Spam Guide
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
User avatar
Tomba
Registered User
Posts: 137
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Remove [img:999:999] bbcode tags from posts

Post by Tomba »

Hi all,

I have locally upgraded my forum to 3.0.RC8 to test and have run into a problem.

Some posts contain the following bbcode:

Code: Select all

[img:50:50]url_to_image[/img]
This is due to a mod I used in 2.0 but it prevents 3.0 to parse the bbcode correctly.
Therefore I tried to work out a script. As a result, the following

Code: Select all

[img:50:50]url[/img]
is converted to

Code: Select all

[img:2k7ai9h5]url[/img:2k7ai9h5]
I do this based on the bbcode_uid field value for that post and with some regex. However, upon display the img tag is still not parsed. Is there maybe something I should do about the bbcode_bitfield value?

Thanks in advance,
Steven
Last edited by Tomba on Sat Dec 15, 2007 12:45 am, edited 1 time in total.
User avatar
ChrisRLG
Former Team Member
Posts: 3420
Joined: Wed Nov 24, 2004 3:18 pm
Location: Essex, UK
Contact:

Re: Remove wrong bbcode after upgrade?

Post by ChrisRLG »

As you are testing - why not try setting up a custom BB code to match the existing code - then try the conversion again.

With luck it might just take that and then convert correctly.

I am not sure if that will work - as I am not sure the custom BB codes are access while doing the conversion.
phpBB: The All Important Rules - Bertie Bear 3.0 - No support via PM system - use the forums please.
phpBB v2: Retirement (1/1/2009) : phpBB v3: Read Me Topic - Custom BBCodes - Support Template
Matthew 7:7"Ask and it will be given to you; seek and you will find; knock and a door will be opened to you."
My Links: MS MVP (Consumer Security) - Malware Removal:University - Own Forum: Custom BBCode testing
User avatar
Tomba
Registered User
Posts: 137
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Remove wrong bbcode after upgrade?

Post by Tomba »

My conversion is already done and I should start from there.

Is there no developer here who could sort this out? :(

BTW, these BBCodes are the result of the following mod in phpbb2.0:
http://www.phpbb.com/community/viewtopi ... 5&t=294443
User avatar
Tomba
Registered User
Posts: 137
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Remove wrong bbcode after upgrade?

Post by Tomba »

Ok well, since no one seems to have the need to do this, I did it myself.

The following quick and dirty script can remove all [img:999:999] tags from your postings (and convert them to simple [img] tags). These tags are the result of a phpbb2 mod to resize images. Since the mod isn't available for phpbb3 and the image tags therefore don't get parsed, they should be removed.

Steps to do:
- upgrade your forum to phpBB3
- put this script in your root phpbb installation directory
- call it through the browser.

It may take a while as it will have to check every single post in your forum and remove the unwanted tags.

Code: Select all

<?php
header('Content-type: text/html; charset=UTF-8');
set_time_limit  (60*60); // 60 minutes

//-------------------------------------------------------

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

/*
function br2nl($string) {
	//$string = preg_replace('/<br.*>$/iU', "\n", $string);
	return preg_replace('/<br.*>/iU', "\n", $string);
}
*/

$table = 'forum_posts';
$username = "name";
$password = "pass";
$hostname = "localhost";
$database = "dbname";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to mysql");
echo "<b>connected to mysql</b><br />\n";
$selected = mysql_select_db($database, $dbh) or die("Could not select database");
echo mysql_error();

// First count number of posts
$query = "SELECT count(*) FROM ".$table;
echo $query.'<br />';
if ($result = mysql_query($query,$dbh)) {
	$row = mysql_fetch_array($result);
	$rows = $row[0];
	echo $rows.' posts found to convert<br/>';
} else {
	echo 'ERROR'.mysql_error();
}
//$rows = 3;
echo "<hr/>\n";

for ($i=2; $i<$rows; $i++) {
	$query = "SELECT post_id, post_text, bbcode_uid, bbcode_bitfield FROM ".$table." LIMIT ".$i.",1";
	//echo $query."<br/><br/>\n";
	if ($result = mysql_query($query,$dbh)) {
		$row = mysql_fetch_array($result);
		$text = $row['post_text'];
		$bbcode = $row['bbcode_uid'];
		$id = $row['post_id'];

		if (preg_match("/\[img:[0-9]+:[0-9]+\]/", $text) > 0) {

			echo "Update post #".$id.'<br/><br/>';
			//echo '<br/>'.$text.'<br/>bbcode_uid='.$row['bbcode_uid'].'<br/>bbcode_bitfield='.$row['bbcode_bitfield'].'<br/>';

			$message_parser = new parse_message();
			$message_parser->bbcode_uid = $row['bbcode_uid'];
			$message_parser->message = $row['post_text'];

			$message_parser->decode_message($row['bbcode_uid']);
			$text = $message_parser->message;

			//$text = preg_replace("/\[img:[0-9]+:[0-9]+\]/", "[img:".$bbcode."]", $text);
			//$text = preg_replace("/\[\/img]/", "[/img:".$bbcode."]", $text);

			//echo '<br/>'.$text.'<br/>';

			$message_parser->message = preg_replace("/\[img:[0-9]+:[0-9]+\]/", "[img]", $message_parser->message);

			//echo '<br/>'.$text.'<br/>';

			$message_parser->parse(true, true, true);
			$text = $message_parser->message;

			//echo '<br/>'.$text.'<br/>bbcode_uid='.$message_parser->bbcode_uid.'<br/>bbcode_bitfield='.$message_parser->bbcode_bitfield.'<br/>';

			$query = "UPDATE ".$table." SET post_text='".addslashes($text)."',bbcode_bitfield='".$message_parser->bbcode_bitfield."' WHERE post_id=".$id;
			echo $query."<br/>\n";
			if (!mysql_query($query,$dbh)) {
				echo 'ERROR'.mysql_error();
			}
			echo '<hr/>'."\n";
		}
	} else {
		echo 'ERROR'.mysql_error();
	}
}

?>

spinx
Registered User
Posts: 3
Joined: Wed Jan 02, 2008 1:39 pm

Re: Remove [img:999:999] bbcode tags from posts

Post by spinx »

hi,
i have the same problem.

i have though to do by a sql query like this

SELECT distinct(
concat("update phpbb_posts SET post_text = REPLACE(REPLACE(post_text, '[/img]', concat('[/img:',bbcode_uid,']')),","'",
substring( substring( post_text, LOCATE( '[img:', post_text ) ) , 1, LOCATE( ']http', substring( post_text, LOCATE( '[img:', post_text ) ) ) ),
"',concat('[img:',bbcode_uid,']'));"))
from phpbb_posts where post_text REGEXP '[[]img:[0-9]*[:][0-9]*[]]';

This produce an output the update for replace the tags in the post BUT I STILL HAVE THE PROBLEM because if the post are not reparsed the tags will not work...i think for the checksum and bitfild

Your scripts fully work for the conversion?

Thank you
User avatar
Tomba
Registered User
Posts: 137
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Remove [img:999:999] bbcode tags from posts

Post by Tomba »

Well my first thought was your solution too, but indeed that doesn't work.

The script I posted did the job perfectly for me ;)

Good luck
spinx
Registered User
Posts: 3
Joined: Wed Jan 02, 2008 1:39 pm

Re: Remove [img:999:999] bbcode tags from posts

Post by spinx »

Many thanks. I've used the script too and fully work. :D
I've modified if (preg_match("/\[img:[0-9]+:[0-9]+\]/i", $text) > 0) { for the case insensitive search img:and IMG:
BartmanNZ
Registered User
Posts: 6
Joined: Tue Aug 17, 2004 5:10 am

Re: Remove [img:999:999] bbcode tags from posts

Post by BartmanNZ »

The script doesn't pick up the case where there isn't any scalling and ends up being parsed as [img::] ;)

It also seems to time out every 5000 or so posts in my forum. I ended up just manually running the loop 5000 posts at a time.
BartmanNZ
Registered User
Posts: 6
Joined: Tue Aug 17, 2004 5:10 am

Re: Remove [img:999:999] bbcode tags from posts

Post by BartmanNZ »

I simplified the reg expression to so that it picks up upper and lower case IMG and also situations where there is img::

Code: Select all

if (preg_match("/\[img:.*?\]/i", $text) > 0)
BigBlockMopar
Registered User
Posts: 90
Joined: Tue Mar 08, 2005 3:15 pm

Re: Remove [img:999:999] bbcode tags from posts

Post by BigBlockMopar »

The script itself might work flawlessly though, but the images on my forum still don't show up.
There's just text (code) where there is supposed to be an image.

How about you guys, do the images show on your forums after running the script?


EDIT:
Ok, after some more looking around on my forum I've noticed only in some topics there are pics showing, other topics just show IMG-code, and even still other topics still have the old [IMG:xxx:xxx]-tags in them.
Signatures are overrated...
Locked

Return to “[3.0.x] Support Forum”