Advertisement:

Author Topic: Help regarding Inline Attachments....  (Read 6997 times)

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,423
    • XPtsp.com Community
Help regarding Inline Attachments....
« on: July 20, 2013, 04:49:25 PM »
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:
Code: [Select]
[attachment=0]somefilename.jpg[/attachment]I need to convert it to this:
Code: [Select]
[attachment=1]
Under this line in phpbb3_to_smf.sql:
Code: [Select]
TRUNCATE {$to_prefix}messages;are lines to replace phpbb bbcodes to smf bbcodes.  I have this to replace the above:
Code: [Select]
'~\[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:
Code: [Select]
[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....
« Last Edit: July 20, 2013, 06:57:10 PM by dougiefresh »
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Help regarding Inline Attachments....
« Reply #1 on: July 21, 2013, 05:02:12 AM »
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:
Code: [Select]
'~\[attachment=(\d+?)\]([^\[]*)[/attachment\]~is',
),
array(
....
'[attachment=$1]',
), $row['body']);
That anyway will fail at changing:
Code: [Select]
[attachment=0]...to
Code: [Select]
[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.

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,423
    • XPtsp.com Community
Re: Help regarding Inline Attachments....
« Reply #2 on: July 22, 2013, 04:07:42 PM »
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:
Code: [Select]
$row['body'] = preg_replace('~\[size=(.+?)px\]~is', "[size=" . ('\1' > '99' ? 99 : '"\1"') . "px]", $row['body']);So I added this line beneath it:
Code: [Select]
$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....
« Last Edit: July 25, 2013, 08:24:37 PM by dougiefresh »
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!

Offline dougiefresh

  • SMF Hero
  • ******
  • Posts: 2,423
    • XPtsp.com Community
Re: Help regarding Inline Attachments....
« Reply #3 on: July 27, 2013, 01:00:08 PM »
So I added this line beneath it:
Code: [Select]
$row['body'] = preg_replace('~\[attachment=(\d+?)\]([^\[]*)\[/attachment\]~is', "[attachment=" . ('\1' + 1) . "]", $row['body']);
This doesn't work....  Corrected it to:
Code: [Select]
$row['body'] = preg_replace('~\[attachment=(\d+?)\]([^\[]*)\[/attachment\]~is', "[attachment=" . '\1' . "]", $row['body']);
NOTICE:  My website is back up!

My Free Simple Machines mods on XPtsp.com and Simple Machines Customization Site!
My mods are being uploaded and are available at GitHub as well!