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!
Scam Warning
Shanti
Registered User
Posts: 131
Joined: Fri Apr 12, 2002 3:47 pm
Location: Wisconsin, USA
Contact:

Applying new BBCodes to old posts

Post by Shanti »

I couldn't find anything related to my question when searching, but I'm still hoping there's some easy way to accomplish what I'm after. I just installed RC1 and converted my 2.0.x db over...everything went very smoothly, but I noticed that the custom BBCode mods I had installed on my old boards were no longer recognized. No worries I thought, I'll just add them with the nifty control panel screen! And I did, and it's working great...but only in new posts. Is there any way to "refresh" or somehow update the all of my 90,000+ old posts so that whatever previous BBCode hacks I had manually installed before will work with the shiny new system? *hopes* :)

By the way, now that I'm starting to get my test install of RC1 working the way I'd like, ideally I'd like to close my live 2.0.x boards, resync the new install with the live boards, change the script path to my /forum directory and move the files over, then reopen everything. Is that a good route to go, and if so, what's the best way to perform the sync? Thanks!
Shanti
It is better to light one candle...
http://www.RealmsofKaos.com

User avatar
Marshalrusty
Project Manager
Project Manager
Posts: 29257
Joined: Mon Nov 22, 2004 10:45 pm
Location: New York City
Name: Yuriy Rusko
Contact:

Re: Applying new BBCodes to old posts

Post by Marshalrusty »

You would need to write a script that goes through every post in the database and runs the post contents through the new bbcode functions. It wouldn't be a very difficult script to write.
Shanti wrote:By the way, now that I'm starting to get my test install of RC1 working the way I'd like, ideally I'd like to close my live 2.0.x boards, resync the new install with the live boards, change the script path to my /forum directory and move the files over, then reopen everything. Is that a good route to go, and if so, what's the best way to perform the sync? Thanks!
You would have to convert the 2.0.x board, then reapply any changes you have made. The conversion mechanism is quite complex, so it wouldn't be easy to only convert certain parts.
Have comments/praise/complaints/suggestions? Please feel free to PM me.

Need private help? Hire me for all your phpBB and web development needs

VinDuv
Registered User
Posts: 17
Joined: Thu May 04, 2006 6:03 pm
Location: France

Re: Applying new BBCodes to old posts

Post by VinDuv »

I think that if you create the custom BBCodes you need on the new 3.0 board before conversion, they will be correctly used in for all converted posts of the former 2.0 board (phpBB 3 doesn't handle BBCodes like phpBB 2, so I think the converter needs to re-parse all BBCodes in posts, including custom ones).
Sorry for my bad English...

Shanti
Registered User
Posts: 131
Joined: Fri Apr 12, 2002 3:47 pm
Location: Wisconsin, USA
Contact:

Re: Applying new BBCodes to old posts

Post by Shanti »

Ahh, thanks for both your replies. It sounds like I'll need to reconvert anyway, so it won't be a big deal to get the BBCodes set up before I start the conversion. It's certainly not a burden to reconfigure the boards with the new ACP. I'm really loving phpBB3! :)
Shanti
It is better to light one candle...
http://www.RealmsofKaos.com

User avatar
Eelke
QA Team
Posts: 2903
Joined: Thu Dec 20, 2001 8:00 am
Location: NL, Bussum
Name: Eelke Blok
Contact:

Re: Applying new BBCodes to old posts

Post by Eelke »

Incidentally, if it doesn't work to set up the custom codes before converting, you might want to add this to the bug tracker. Not that I would consider it a bug - in all honesty, dare I say it, this would be a feature request - but the developers might find it a good suggestion; it would make the converter even nicer, potentially without having to make a lot of changes.

Either way, don't get your hopes up too high. It wouldn't surprise me if this didn't work, to be honest. The converter really is only specified to handle standard phpBB 2 functionality, the attachment mod and the birthday mod, not bbcodes other than the standard ones (since those would qualify as mods for phpBB 2). [However, ] definately worth a try, because, if the posts from phpBB 2 were passed through the regular post processing routines of phpBB 3, this would be a side-effect.
Last edited by Eelke on Thu Jun 07, 2007 1:34 pm, edited 2 times in total.

Shanti
Registered User
Posts: 131
Joined: Fri Apr 12, 2002 3:47 pm
Location: Wisconsin, USA
Contact:

Re: Applying new BBCodes to old posts

Post by Shanti »

Thanks for the input! Once my custom style is developed I'll be ready to reinstall and convert again so I'll post back here on my results, if someone else hasn't already tried it in the mean time. :)
Shanti
It is better to light one candle...
http://www.RealmsofKaos.com

arod-1
Registered User
Posts: 1327
Joined: Mon Sep 20, 2004 1:33 pm

Re: Applying new BBCodes to old posts

Post by arod-1 »

Marshalrusty wrote:You would need to write a script that goes through every post in the database and runs the post contents through the new bbcode functions. It wouldn't be a very difficult script to write.
you are right in your assertion that such a script would be required. however, you are wrong in saying that Shanti would need to write one.
a script that does exactly that already exists in the "develop" directory of the code. i believe it was developed some time around beta-2, to help convert the handling of bbcode which was radically changed.

note: this directory is not included in the RC1 or even the beta distributions. it is included in the cvs repository, as well as in the daily cvs snapshots.

note #2: i never actually used this script, so i can't personally attest to its suitability for the job, i only wanted to draw your attention to the fact that the script you describe was already written by acydburn. (btw: this script also does something you omitted: in addition to the posts' text, it also converts the signatures, which are kept in a different table).
standard disclaimer:
backup your db and files before you do anything.
absolutely no guarantee.
if you do what i advise and it blows in your face, all you'll hear from me is: "ah... sorry, i guess"

tfinry
Registered User
Posts: 32
Joined: Sat Jun 10, 2006 10:20 pm
Contact:

Re: Applying new BBCodes to old posts

Post by tfinry »

unfortunately revonvert the forum didnt help me
the old posts still the same

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 »

No reconvert will not help you to fix that. As arod-1 wrote, you need to get a latest cvs version of phpBB and use adjust_bbcodes.php file that you find there. Howerver a slightly modification needs to be done on that file to make it work.

Or if you are lazy try this one:
(as always, try it localy first and be sure to make backup)

Code: Select all

<?php
/**
* Only adjust bitfields, do not rewrite text...
* All new parsings have the img, flash and quote modes set to true
*
* You should make a backup from your users, posts and privmsgs table in case something goes wrong
* Forum descriptions and rules need to be re-submitted manually.
*/
//die("Please read the first lines of this script for instructions on how to enable it");

set_time_limit(0);

define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

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


$echos = 0;

// Adjust user signatures
$message_parser = new parse_message();
$message_parser->mode = 'sig';
$message_parser->bbcode_init();

$sql = 'SELECT user_id, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield
	FROM ' . USERS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['user_sig_bbcode_uid'] && $row['user_sig'])
	{
		decode_message($row['user_sig'], $row['user_sig_bbcode_uid']);

		$message_parser->message = &$row['user_sig'];
		$bbcodeId = $message_parser->bbcode_uid;

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . USERS_TABLE . " SET user_sig = '" . $db->sql_escape($row['user_sig']) . "', user_sig_bbcode_uid = '" . $db->sql_escape($bbcodeId) . "', user_sig_bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE user_id = " . $row['user_id'];
		$db->sql_query($sql);

		if ($echos > 100)
		{
			echo '<br />' . "\n <strong>USER_ID = " . $row['user_id'] . "</strong>";
			$echos = 0;
		}

		echo $row['user_id'] . '.';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . USERS_TABLE . " SET user_sig_bbcode_bitfield = ''
			WHERE user_id = " . $row['user_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);


echo "<br>Finished with signatures...<br>";

// Now adjust posts

$message_parser = new parse_message();
$message_parser->mode = 'post';
$message_parser->bbcode_init();

// Update posts
$sql = "SELECT post_id, post_text, bbcode_uid, enable_bbcode, enable_smilies, enable_sig
	FROM " . POSTS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['enable_bbcode'])
	{
		decode_message($row['post_text'], $row['bbcode_uid']);

		$message_parser->message = &$row['post_text'];
		$bbcodeId = $message_parser->bbcode_uid;

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . POSTS_TABLE . " SET post_text = '". $db->sql_escape($row['post_text']) ."', bbcode_uid = '". $db->sql_escape($bbcodeId) ."', bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE post_id = " . $row['post_id'];
		$db->sql_query($sql);

		if ($echos > 100)
		{
			echo '<br />' . "\n <strong>POST_ID = " . $row['post_id'] . "</strong>";
			$echos = 0;
		}

		echo $row['post_id'] . '.';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . POSTS_TABLE . " SET bbcode_bitfield = ''
			WHERE post_id = " . $row['post_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);

echo "<br>Finished with topics...<br>";

// Now to the private messages
$message_parser = new parse_message();
$message_parser->mode = 'post';
$message_parser->bbcode_init();

// Update pms
$sql = 'SELECT msg_id, message_text, bbcode_uid, enable_bbcode
	FROM ' . PRIVMSGS_TABLE;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
	// Convert bbcodes back to their normal form
	if ($row['enable_bbcode'])
	{
		decode_message($row['message_text'], $row['bbcode_uid']);

		$message_parser->message = &$row['message_text'];
		$bbcodeId = $message_parser->bbcode_uid;

		$message_parser->prepare_bbcodes();
		$message_parser->parse_bbcode();

		$bitfield = $message_parser->bbcode_bitfield;

		$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET message_text = '" . $db->sql_escape($row['message_text']) . "', bbcode_uid = '" . $db->sql_escape($bbcodeId) . "', bbcode_bitfield = '" . $db->sql_escape($bitfield) . "'
			WHERE msg_id = " . $row['msg_id'];
		$db->sql_query($sql);

		if ($echos > 100)
		{
			echo '<br />' . "\n <strong>MESSAGE_ID = " . $row['msg_id'] . "</strong>";
			$echos = 0;
		}

		echo $row['msg_id'] . '...';
		$echos++;

		flush();
	}
	else
	{
		$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET bbcode_bitfield = ''
			WHERE msg_id = " . $row['msg_id'];
		$db->sql_query($sql);
	}
}
$db->sql_freeresult($result);

echo "<br>Finished with private messages...<br>";

// Done
$db->sql_close();
?>

tfinry
Registered User
Posts: 32
Joined: Sat Jun 10, 2006 10:20 pm
Contact:

Re: Applying new BBCodes to old posts

Post by tfinry »

thanks DarrenSW for your replay

i tried this code and the adjust_bbcodes.php code

both of them loading and counting ...

but did nothing :mrgreen:

as you said they need to be modified

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 »

Code I gave you is modified. However you need to add your custom bb-tags to your phpBB3 instalation before you run the file.

Tried on my own backup and it's working.

ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Applying new BBCodes to old posts

Post by ToonArmy »

Don't leave this file hanging around on your server ;)
Chris SmithGitHub

tfinry
Registered User
Posts: 32
Joined: Sat Jun 10, 2006 10:20 pm
Contact:

Re: Applying new BBCodes to old posts

Post by tfinry »

DarrenSW wrote:Code I gave you is modified. However you need to add your custom bb-tags to your phpBB3 instalation before you run the file.

Tried on my own backup and it's working.

i added the bb-tags b4 i run the file .. but as i said nothing changed!! ..
i think because i have Hoteditor mod

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 »

What's the bb-code you are trying to add and what's the html-replacement for that code? Have you tryed purging the cache on your forum?

tfinry
Registered User
Posts: 32
Joined: Sat Jun 10, 2006 10:20 pm
Contact:

Re: Applying new BBCodes to old posts

Post by tfinry »

DarrenSW wrote:What's the bb-code you are trying to add and what's the html-replacement for that code? Have you tryed purging the cache on your forum?

i have a forum with hoteditor mod what mean a lot of modified bb-tags
i didn't add them and their html-replacement in the forum
i just want to check the script with simple tags like [center]
i add the bb-code and html-replacement for Center tag but the script didn't work for it
i think i must do that again with fresh copy

Post Reply

Return to “phpBB Discussion”