News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Help regarding Inline Attachments....

Started by dougiefresh, July 20, 2013, 04:49:25 PM

Previous topic - Next topic

dougiefresh

I have a mod installed (or maybe it's a feature of phpBB, not sure, don't care) on my phpBB install to allow the user to insert an attachment into the post, like to use it like a picture.  To include the first attachment in the post, the bbcode ends up being something like:
[attachment=0]somefilename.jpg[/attachment]
I need to convert it to this:
[attachment=1]

Under this line in phpbb3_to_smf.sql:
TRUNCATE {$to_prefix}messages;
are lines to replace phpbb bbcodes to smf bbcodes.  I have this to replace the above:
'~\[attachment=(.+?):(.+?)?\]~is',
'~\[/attachment:(.+?)?\]~is',
),
array(
....
'[attachment=$1]',
'[/attachment]',
), $row['body']);

But this still leaves the filename and the closing attachment bracket.  How do I rewrite this to eliminate both of those, since I don't need either one in the post?  Thanks in advance for your time and help!

EDIT: The Attachments Positioning mod I'm using to implement Inline Attachments uses this form to include tags:
[attachment=1]

EDIT2: The above code works to convert the phpbb bbcodes to smf, however, the closing tag isn't necessary and everything between the opening & closing tag isn't necessary, in case I didn't make this clear....  Thanks in advance....

emanuele

I'm a bit confused by your second edit...are you still having the issue or did you fix it?

I would use something like this:
'~\[attachment=(\d+?)\]([^\[]*)[/attachment\]~is',
),
array(
....
'[attachment=$1]',
), $row['body']);

That anyway will fail at changing:
[attachment=0]...
to
[attachment=1]
But that's something you may workaround from the mod.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

dougiefresh

#2
Thanks, Emanuele!  I tried replacing the stuff converting the phpbb attachment bbcodes to what you suggested to remove the unnecessary content between the opening/closing tag and the closing tag itself....  Didn't work.....  Restored my code back....

So underneath the very long preg_replace array, I found this:
$row['body'] = preg_replace('~\[size=(.+?)px\]~is', "[size=" . ('\1' > '99' ? 99 : '"\1"') . "px]", $row['body']);
So I added this line beneath it:
$row['body'] = preg_replace('~\[attachment=(\d+?)\]([^\[]*)\[/attachment\]~is', "[attachment=" . ('\1' + 1) . "]", $row['body']);
So the preg_replace function replaces the phpbb bbcodes to match SMF's style, then this statement eliminates the unnecessary closing tag and everything between the opening and closing tag....  Tested it, and it works almost right off the bat!!!!

Very cool!  You saved me from pulling out my hair trying to figure out that danged expression!  Thanks very much, Emanuele!

EDIT: Corrected double commas in second code statement....

dougiefresh

Quote from: dougiefresh on July 22, 2013, 04:07:42 PM
So I added this line beneath it:
$row['body'] = preg_replace('~\[attachment=(\d+?)\]([^\[]*)\[/attachment\]~is', "[attachment=" . ('\1' + 1) . "]", $row['body']);
This doesn't work....  Corrected it to:
$row['body'] = preg_replace('~\[attachment=(\d+?)\]([^\[]*)\[/attachment\]~is', "[attachment=" . '\1' . "]", $row['body']);

Advertisement: