Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
plugins-topic
BBCode in posts from Imported pphBB3 board - can these tags be output by SP?
Avatar
Azti
Member
Free Members
sp_UserOfflineSmall Offline
Nov 22, 2013 - 5:03 pm

Greetings,

I have innumerable posts with BBCode such as:
[img:2zipfoae]http://farm8.staticflickr.com/7402/10853492303_1b86dd39c1_z.jpg[/img:2zipfoae]

[url:250psi0z]http://www.orgonise-africa.net[/url:250psi0z]

[b:335c7gbv][u:335c7gbv]Our first gifting run in Malaysia May 2006 (Part 1 of 4)[/u:335c7gbv][/b:335c7gbv]

etc.... now that I've imported into SP. Now all instances of BBCode appear "unrendered". Is there any way that SP can parse these? some plugin? or am I going to have to write code to troll through wp_sfposts and convert each of these to html? I have to, at least, get the images working, and then the urls...

Thanks,

--Azti

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 22, 2013 - 5:34 pm

No we don't have an option to correct that I am afraid. The problem is that this is not standard bbCode but something quite peculiar to phpBB - and even then not all versions I believe...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Azti
Member
Free Members
sp_UserOfflineSmall Offline
Nov 22, 2013 - 5:36 pm

ok, I just read this:
https://simple-press.com/suppo.....b3/page-2/

From the above I understand that the problem is in that these tags embed a random string as a pointer to specific, uploaded, media and, as they are unique, your parsers don't handle them. I also believe, from this thread, that whenever SP does parse BBCode such as simple (rather than in my case) <img src="url<img src=" markup code in sp-api-filters.php replaces this with html and stores it in the database.

It looks to me that the changes that were proposed by Yellow Swordfish and Joan Alamo Vallejo are implemented having looked at the code at line 930 of the current version of SP:

# apply any users custom filters for pre-content display processing
$content = apply_filters('sph_display_post_content_pre_filter', $content);

So, do I just need to write a filter in my functions.php and replace the offending BBCode Tags with the simple tags that will then be automatically replaced by SP code with html?

This would save me from a lot of perl regexp DBI hackery...

thanks,

--Azti

PS: Ah... yes, confirmed... If I edit a post with one of these offending tags, and replace them with simple <img src="url" alt="url[img] markup code in sp-api-filters.php replaces this with html and stores it in the database.

PPS: Nope... that didn't work it just displayed [img]url" alt="url" alt="url[img] markup code in sp-api-filters.php replaces this with html and stores it in the database.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 1:22 am

sorry, you have confused me with your edits...

first, even with bbcode (which can be supported), we will store it in the db as html... but it will display properly...

careful if you edit the post as tinymce is wysiwg... it may not 'write' true html unless you do it in the html popup window...

but yes, you can use that filter to replace phpbb specific bbcode tags with the general ones that sp knows...

so, if I have missed something, please elaborate because not sure what you edits were trying to tell me...

Avatar
Azti
Member
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 1:01 pm

Mr Papa,

What I did was to write a quick perl script that edited a database dump to a sql file, then replaced every instance of [img:<randomstr>] with [img] as well as doing the same for the closing tags. This did not work. The Forum showed the bbcode rather than rendering the image. I believe what I would have to do, in a php solution, is to use the same code (or similar) that transforms bbcode to html, and writes it to the database upon an editor submission using bbcode, but do so before the page is displayed, through a functions.php filter.

However, I would rather just clean up the database all at once and so what I am going to do is to perform a global search and replace for these offending tags. I am writing a quick perl script that will take a database dump to a sql file,  do the edits, and then I just drop the db, create it, execute the sql file, and start from there.

I will make it available once I'm done with it.

Thanks again and sorry for the confusion with the edits...

--Azti

 

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 4:11 pm

you should be able edit it fine... works for me - just tried...  but you cant edit the db since its not stored as bbcode in the db - its html...  when read from the db, it will be interpreted as a wp shortcode... 

Avatar
Azti
Member
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 10:05 pm

I wrote a perl script that fixed all my images, and I'm adding more regexps to fix other things. It uses DBI to access the database, edits each record in wp_sfposts, searches for tags, replaces them with html, and writes back to the db. I will go ahead and clean this up, add command line arguments handling of dsn variables, and table names, and post it for others to use...

#!/usr/bin/perl
use strict;
use warnings;
use DBI;

my $user = '<replace with your user>';
my $pass = '<replace with your password>';
my $db = '<replace with your database name>';
my $dsn = "dbi:mysql:database=$db";

my $dbh = DBI->connect($dsn, $user, $pass)
        or die "Unable to connect to database: $DBI::errstr";

my $sth = $dbh->prepare("SELECT post_id, post_content FROM $db.wp_sfposts;");
my $sth_update = $dbh->prepare("UPDATE $db.wp_sfposts SET post_content = ? WHERE post_id = ?");
$sth->execute();

# Regex looks for http or https and looks for [img] or [img:<random string>]. The next regexp looks for the 
# related closing tag
while(my @row = $sth->fetchrow_array()){

    my $id = $row[0];
    my $record = $row[1];
    $record =~ s/\[img(?:\]|:[\w]+\])/<img src="/g;
    $record =~ s/\/?\[\/img(?:\]|:[\w]+\])/"\/>/g;
    print "Processing post_id: $id\n";
   $sth_update->bind_param(1, $record);
   $sth_update->bind_param(2, $id);
   $sth_update->execute() or die $dbh->errstr;
}

--Azti

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 10:27 pm

ah sorry, thought you were converting to bbcode not html... the latter,of course, will work since that's how its stored... cool!

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17363
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625