Applying new BBCodes to old posts

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Get Involved
musikgoat
Registered User
Posts: 34
Joined: Mon May 28, 2007 2:09 am

Re: Applying new BBCodes to old posts

Post by musikgoat »

So I am in very much the same situation as Shanti where after upgrading to phpbb3, the bbcode bitfield had not been calculated and entered for any of my posts. We tried coming up with some method to initate it, but happily found this instead. ;)

The script has seemed to go well in the posts area, which is what I'm concerned about. Except for urls. What I've noticed, is that urls with the following

Code: Select all

[url]http://www.url.tld[/url]
get parsed, but

Code: Select all

[url=http://www.url.tld]URLname[/url]
does not.

Also, either does just the URL without any tags.


I believe for the first issue, because urls are parsed using a different function in the message_parser class, I need to call that function in the script.

Code: Select all

//run url validator for string $var1 optional url parameter for url bbcode: [url(=$var1)]$var2[/url]
	$message_parser->validate_url(___, ___)
I'm not quite sure how to prepare the $var1 and $var2, but I was thinking that preg_match the post_text field with a regex.

I'm not at all good at this, but this looked like something that would work, I found it in the message_parser class on line 118

Code: Select all

'url'	=> array('bbcode_id' => 3, 'regexp' => array('#\[url(=(.*))?\](.*)\[/url\]#iUe' => "\$this->validate_url('\$2', '\$3')")),
so i tried using that for the following bit of added code:

Code: Select all

while ($row = $db->sql_fetchrow($result))
{
	//pseudo: grep [url]http[/url]
	$message_parser->message = &$row['post_text'];

	$regexp = '#\[url(=(.*))?\](.*)\[/url\]#iUe';

	preg_match($regexp, $message_parser->message, $matches);

	echo '<p>1 ' . $matches[0];

	
	//run url validator for string $var1 optional url parameter for url bbcode: [url(=$var1)]$var2[/url]
//	$message_parser->validate_url(
	
   // Convert bbcodes back to their normal form
   if ($row['enable_bbcode'])
I'm doing something wrong because i'm getting this error repeating in the loop (i've commented out the rest of the code to just see if this would work):
1 [phpBB Debug] PHP Notice: in file /bbcode_convert.php on line 98: preg_match() [function.preg-match]: Unknown modifier 'r'
[phpBB Debug] PHP Notice: in file /bbcode_convert.php on line 100: Undefined offset: 0


for the second issue, is there some call at the time of submit that parses the URL plaintext?


any suggestions on what i'm doing wrong?
DarrenSW
Registered User
Posts: 58
Joined: Fri May 11, 2007 11:50 pm
Location: Sweden
Contact:

Re: Applying new BBCodes to old posts

Post by DarrenSW »

Tried again and can't see errors for the [url] and [url=] tags. Plain links however doesn't get parsed as you say.

If you are using the code I showed here in this topic then:

Find all:

Code: Select all

$message_parser->mesage = &$row['post_text'];
After add:

Code: Select all

$row['post_text'] = make_clickable($row['post_text']);
That should parse plain links in your posts.
musikgoat
Registered User
Posts: 34
Joined: Mon May 28, 2007 2:09 am

Re: Applying new BBCodes to old posts

Post by musikgoat »

Ok, you are right, the code should be fine, as long as the uid is tagged on the bbcode. I found that somehow there are just a few posts without uid's appended to the bbcode.

Thank you for the modification of the plain links, i'm going to try that, after the uid's are added on a clean reinstall of the database. :D :D
musikgoat
Registered User
Posts: 34
Joined: Mon May 28, 2007 2:09 am

Re: Applying new BBCodes to old posts

Post by musikgoat »

So the script that was suggested does seem to alter all of the old post_text, but I've noticed that it also seems to break currently working smilies and bbcode. i.e. the old posts that did not have bitfields are parsed and showing correct, but newer posts on the bb3 board, seem to loose all the smilie display.


After some investigating I found these API instructions.
http://www.phpbb.com/mods/documentation ... ting-posts

I was thinking that using the submit_post function with an 'edit' for the mode variable would work.
I found that I would have to add some variables that the example doesn't have, due to the calls for the 'edit' mode.

here is my code thus far. It is running but after about 1050 seconds, firefox flakes out and offers to download the php page, I will attempt to try just a few K posts to see, but does anyone see any problems with this method?

Code: Select all

<?php 

set_time_limit(0);

//setting phpbb defined settings
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_posting.'.$phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

//take out join  TODO
$sql = 
	'SELECT post_id,' . POSTS_TABLE . '.forum_id,' . POSTS_TABLE . '.topic_id,poster_id,forum_name,post_subject,post_text,enable_bbcode,enable_smilies,enable_magic_url,enable_sig,topic_replies_real,topic_first_post_id,topic_last_post_id,post_edit_reason,post_edit_user,post_time
		FROM ' . POSTS_TABLE . ',' . TOPICS_TABLE .
		' WHERE ' . POSTS_TABLE . '.topic_id = ' . TOPICS_TABLE . '.topic_id';
$result = $db->sql_query($sql);
$num = mysql_num_rows($result);


//Output and set variables for query table
if($num > 0){		//as long as there are enties, run the update on the table

	echo '<p>Total Posts:  ' . $num . '</p><p>Running script now (this will take a while)...</p>';
	
	$loopcounter = 0;    // counter to show output
	
	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

		//variables from query
		$my_subject = $row['post_subject'];
		$my_text = $row['post_text'];
		
		// variables to hold the parameters for submit_post
		$poll = $uid = $bitfield = $options = ''; 

		generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
		generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);

		$data = array( 
			'forum_id'		=> $row['forum_id'],
			'icon_id'		=> false,

			'enable_bbcode'		=> $row['enable_bbcode'],
			'enable_smilies'	=> $row['enable_smilies'],
			'enable_urls'		=> $row['enable_magic_url'],
			'enable_sig'		=> $row['enable_sig'],
			'topic_replies_real'	=> $row['topic_replies_real'],
			'poster_id'		=> $row['poster_id'],
			'post_id'		=> $row['post_id'],
			'topic_id'		=> $row['topic_id'],
			'topic_first_post_id'		=> $row['topic_first_post_id'],
			'topic_last_post_id'		=> $row['topic_last_post_id'],


			'post_edit_reason'	=> $row['post_edit_reason'],
			'post_edit_user'	=> $row['post_edit_user'],
			'message'		=> $my_text,
			'message_md5'	=> md5($my_text),
						
			'bbcode_bitfield'	=> $bitfield,
			'bbcode_uid'		=> $uid,

			'post_edit_locked'	=> 0,
			'topic_title'		=> $my_subject,
			'notify_set'		=> false,
			'notify'			=> false,
			'post_time' 		=> $row['post_time'],
			'forum_name'		=> $row['forum_name'],
			'enable_indexing'	=> true,
		);

		submit_post('edit', $my_subject, '', POST_NORMAL, $poll, $data);
	}
	mysql_free_result($result);
}
?>
aelOnn
Registered User
Posts: 6
Joined: Mon May 28, 2007 5:21 pm

Re: Applying new BBCodes to old posts

Post by aelOnn »

musikgoat wrote:So the script that was suggested does seem to alter all of the old post_text, but I've noticed that it also seems to break currently working smilies and bbcode.
Same thing here :(
This problem of reparsing of old posts should be added in the "Requested features", for allow proper conversions, but also when people will change/update some BBcodes, for reparsing the old posts.

Or at least write a big warning before conversion: PLEASE ADD YOUR CUSTOM BBCODES FIRST.
jonli447
Registered User
Posts: 8
Joined: Sun Jul 01, 2007 10:06 pm

Re: Applying new BBCodes to old posts

Post by jonli447 »

Yeah, I'd appreciate an addition to phpbb3 for this as well, however, I think it's wishful thinking. It appears that phpBB3 is feature locked now. Likely will have to wait well after it's at gold status, before such a feature becomes mainline.

However, I think that musikgoat's script is a good idea. Anyone have any thoughts on this? I think the script needs to be fixed so that it does not timeout. There is a function in the search index creator that does something (I think maybe a jscript object?) to handle it so that it does not timeout.

Anyone have any ideas if musikgoat's script would work? I am having the same problem. I tried using DWarren's script, but it screws up posts where bbcode was already parsed. Also, all smilies get disabled.

Thanks in advance.
murnauvsbuñuel
Registered User
Posts: 177
Joined: Mon Jun 20, 2005 9:49 am

Re: Applying new BBCodes to old posts

Post by murnauvsbuñuel »

:? i hope that this mod to phpBB3 BETA1 can be upgrade to this problem
sorry for my bad english i am spanish.
ImagemxBB Portal the best portal to phpBB2
jonli447
Registered User
Posts: 8
Joined: Sun Jul 01, 2007 10:06 pm

Re: Applying new BBCodes to old posts

Post by jonli447 »

murnauvsbuñuel wrote::? i hope that this mod to phpBB3 BETA1 can be upgrade to this problem
I looked at the mod and posted in the startrekguides forums about it. I believe though, that the script that DarrenSW posted is essentially the same thing. I could be completely wrong, but I think that musikgoat's script, with some work, is likely the best solution. Any other opinions?
Shadowtester
Registered User
Posts: 2
Joined: Tue Jul 03, 2007 1:53 am

Re: Applying new BBCodes to old posts

Post by Shadowtester »

Any more information or progress on this problem?
mindbender1
Registered User
Posts: 5
Joined: Tue Jul 03, 2007 12:10 am

Re: Applying new BBCodes to old posts

Post by mindbender1 »

i am also very interested in a solution for this problem....unfortunately my php skills are next to non existent.....
i hope a solution shows up...many will have the problem the moment phpbb3 gets released...
DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Re: Applying new BBCodes to old posts

Post by DonGato »

I think I'm facing the same problem with a couple of phpBB2 bbCodes I had in my old forum.
Anybody made any progress with the script to process old bbCodes yet?

EDIT: I added the code before the conversion and they were properly converted. Did they fix something in RC3?
murnauvsbuñuel
Registered User
Posts: 177
Joined: Mon Jun 20, 2005 9:49 am

Re: Applying new BBCodes to old posts

Post by murnauvsbuñuel »

DonGato wrote:EDIT: I added the code before the conversion and they were properly converted. Did they fix something in RC3?
i think that no because i did this with RC2 and worked too. :D
sorry for my bad english i am spanish.
ImagemxBB Portal the best portal to phpBB2
User avatar
Sr X
Registered User
Posts: 202
Joined: Wed Feb 07, 2007 9:25 am

Re: Applying new BBCodes to old posts

Post by Sr X »

steps:

1) If you allowed tags html in your board with phpBB2 you can search the html tags and replace this by BBCode, is not important that any bbcode is not istall now. the most easy way can do this is from myphpadmin:
thecoalman wrote:You can do this right in phpmyadmin. Google "Mysql search and replace"

Code: Select all

update table_name set table_field = replace(table_field,'search_for_this','replace_with_this');
My suggestion would be to first set up a new testing forum. Set up some new BB code in phpbb3 for the strings you want to replace. Then perform perform the update in phpmyadmin.

The usual warnings apply, Make sure you have a backup. Thoroughly test on a test forum and test database first..
2) install the first forum with phpBB3 and (important) after from ACP add the custom bbcodes

3)Only after that you have add the custom bbcodes in the first phpBB3 then you can convert the old forum phpBB2 to phpBB3 version. Then the bbcode is convert rigth! and your old html tags will be bbcode now!!!
mindbender1
Registered User
Posts: 5
Joined: Tue Jul 03, 2007 12:10 am

Re: Applying new BBCodes to old posts

Post by mindbender1 »

but i have this problem and haven`t used any custom bbcodes?
User avatar
Frodosringfinger
Registered User
Posts: 226
Joined: Mon Oct 16, 2006 1:45 am
Location: Maryland
Contact:

Re: Applying new BBCodes to old posts

Post by Frodosringfinger »

I have a forum dedicated to videos and flash games, so I was scared going into the update. But, I just created the bb codes I needed, and had my entire moderator team help me fixing all the 500+ topics in that specific forum. It only took about 3 hours of work.
Post Reply

Return to “phpBB Discussion”