phpBB post example for WP shortcode

User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

phpBB post example for WP shortcode

Post by axew3 »

This is huge red text
So i want an image in attach inline
southpcheers.jpg
southpcheers.jpg (21.54 KiB) Viewed 3152 times
then a file inline in attach
phpseclib1.0.19.zip
(273.42 KiB) Downloaded 395 times
then i want this text bold,
and after i like to display a piece of code:

Code: Select all

<?php
function test() {
    $foo = "local variable";

    echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
    echo '$foo in current scope: ' . $foo . "\n";
}

$foo = "Example content";
test();
?>
then i want display a big text without colorize it:
WoW! i like it ... but could be better
and i have some lists to display:
  • The first possible answer
  • The second possible answer
  • The third possible answer
in different format
  1. The first possible answer
  2. The second possible answer
  3. The third possible answer
but i like also to see the underline text
or quoted text:
this text is quite quoted
so a nice image:
Image
then more bad code:

Code: Select all

<test  />$find = array(
		 '~\[img\].*?\[/img\]~si', // if there links/text for the image elsewhere, remove. Done above
    '~(^(\r\n|\r|\n))|^\s*$~m', .........
	);
and an url with text
Visit phpBB!
and an url
https://www.wordpress.org/
and more code for bbcode to be parsed:

Code: Select all

// partial bbcode regex 
$find = array(
		'~\[b\](.*?)\[/b\]~usi',
		'~\[i\](.*?)\[/i\]~usi',
		'~\[u\](.*?)\[/u\]~usi',
		'~\[quote\](.*?)\[/quote\]~usi',
		'~\[size=(.*?)\](.*?)\[/size\]~usi',
	);
and an image link also:

Image

NOTE: on this phpBB example it is not installed the phpBB Media Embed mod, to display video into phpBB posts, but if i add this bbcode into this phpBB post like this:
[media]https://www.youtube.com/watch?v=AYBrtFnHI6g[/media]
it will not be parsed into this phpBB post, because the mod has not been installed in phpBB, but will be parsed into the WP post because recognized and parsed by the WP_w3all plugin code.

you cannot add, expecting it will be parsed: flash or email bbcode tag.
see the result of this post parsed into a WordPress post via Shortcode here: https://www.axew3.com/w3/2017/07/wordpr ... o-wp-post/

you need a more improved version of the function that do this? email me here: me@you.us
As you see was not so important to add email parsing .... (what?)

Cheers to all cool people!
Attachments
phpBB-audio-video-to-post-1.0.4-alpha.zip
(591.26 KiB) Downloaded 399 times
phpseclib-master-3.0.7.zip
(553.16 KiB) Downloaded 395 times
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: phpBB post example for WP shortcode

Post by axew3 »

Check the shortcode in action, that display the above phpBB formatted post, into a WordPress post here:
https://www.axew3.com/w3/2017/07/wordpr ... o-wp-post/
User avatar
kaspir
Moderator
Moderator
Posts: 88
Joined: Mon Mar 20, 2017 2:38 pm
Location: USA
Contact:

Re: phpBB post example for WP shortcode

Post by kaspir »

Nice option to have available! I just tried it out and works nicely. I noticed a custom bbcode on my phpBB didn't show as you explained it wouldn't. Perhaps we can begin a list of the more common bbcodes to be supported in plugin in the future! I'll start of by adding a simple one:

Strike-through [s] [/s], if I learned this correctly from you, it would be added to the bbcode regex array like so:

Code: Select all

'~\[s\](.*?)\[/s\]~usi',
And now that I've seen this, a light bulb just went off! I got to leave now and go re-read my code for my SEO extension I never finished. It's so close to completion, but the hold up was I couldn't rewrite out certain things within a post for the meta description tag. Argh, cleaning up the back burner sucks..

Thanks for the :idea: lightbulb!

EDIT: After a few cups of coffee (a.k.a. about a whole pot, lol), the lightbulb paid off! In case you were wondering what I was thinking about, I posted it here: viewtopic.php?p=2280#p2280
Image
World of Phaos RPG online is making it's come back! Play free now!
Check out phpBB contributions & extension downloads. :P
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: phpBB post example for WP shortcode

Post by axew3 »

Hi Greg! about coffee ... mhh ... hope it was Italian coffee, like Lavazza or Segafredo, or Hilly ... done with Moka Bialetti .... and NOT NESCAFE! :cry: ... how to use a moka properly, to have a good coffee require also some little experienced trick! It require to be washed only with water, and is necessary to make some coffee leaving it on the moka for sometime, that you'll discard after ... than you'll start to have a good aroma, after some day, because the MOKA start to smell of coffee even after washed (EVER with only water!) ... and the moka will give you time by time a better coffee ... that's really nice ... well what i'm writing about in my bad Eng!!! :lol:

about shortcode: you know sometime after you have finish something, you realize that it could be coded in another way. It can be improved and some modifier removed on some regex. I'm not a monster of science about regex, so be sure there is some more to be improved.
str_ireplace() could be used conveniently, that is more fast, in some point maybe (or on all, looking on how the post containing bbcode parsed, is stored on DB by phpBB).
The call to preg_replace_callback can be reduced to one, i've already edit it on local test, so like:

Code: Select all

$text = preg_replace_callback(
            "~<ul>(.*?)</ul>|<ol(.*?)</ol>~sm",
            "self::w3_bbcode_rep0",
            $text);
The returned html tag for code is wrapped into

Code: Select all

<pre><code>....</code></pre>
that should be only

Code: Select all

<code>....</code>
and i've forget to remove it on first 1.7.4 class.wp.w3all-phpbb.php (after patched with some little more) from line:

Code: Select all

$res = str_ireplace('#w3#bbcode#replace#'.$cccc, '<pre><code>'.$v[1].'</code></pre>', $res);
the php code require some little adjustment, in case the query to the post return an unexpected result.
Should be added the

Code: Select all

[attachment]
bbcode even if it after, should imply all about users permissions, to view or not the attachment in WP, that would be not require any important change ...
And an option more on shortcode to, display the post into WP post as text immediately visible, or like a button, that when clicked, so display the phpBB post into the WP post (convenient for stunning presentations maybe, and as showed by someone as example into an old request post).
new lines present some problem maybe, and some little improvement about this, adding corrects

Code: Select all

<br />
tags (or not) on output, should be done.

p.s thank for your appreciation on another post ;)
User avatar
kaspir
Moderator
Moderator
Posts: 88
Joined: Mon Mar 20, 2017 2:38 pm
Location: USA
Contact:

Re: phpBB post example for WP shortcode

Post by kaspir »

axew3 wrote: Sat Aug 05, 2017 4:27 pm Hi Greg! about coffee ... mhh ... hope it was Italian coffee, like Lavazza or Segafredo, or Hilly ... done with Moka Bialetti .... and NOT NESCAFE! :cry: ... how to use a moka properly, to have a good coffee require also some little experienced trick! It require to be washed only with water, and is necessary to make some coffee leaving it on the moka for sometime, that you'll discard after ... than you'll start to have a good aroma, after some day, because the MOKA start to smell of coffee even after washed (EVER with only water!) ... and the moka will give you time by time a better coffee ... that's really nice ... well what i'm writing about in my bad Eng!!! :lol:
Sounds delightful! I need to learn more about your Italian coffee!
axew3 wrote: Sat Aug 05, 2017 4:27 pm about shortcode: you know sometime after you have finish something, you realize that it could be coded in another way.
All the time! Practice makes perfect, PHP7 new classes and objects are teching me more of that, and recently been looking at symphony framework. Always to be less repetitive, repeat code less.
axew3 wrote: Sat Aug 05, 2017 4:27 pm It can be improved and some modifier removed on some regex. I'm not a monster of science about regex, so be sure there is some more to be improved.
Argh regex, another thing I need improving on understanding too. Google has been my friend altering regex.
axew3 wrote: Sat Aug 05, 2017 4:27 pm str_ireplace() could be used conveniently, that is more fast, in some point maybe (or on all, looking on how the post containing bbcode parsed, is stored on DB by phpBB).
...
All very nicely explained Allesio! Nicely done, I'm glad I keep your gears grinding and teaching me new things! :)

About smileys.. argh.. I haven't yet been successful at re-parsing those, I need to remove them into a blank space.
I know you mainly work on WP, but have you seen phpBB's new re-parser? https://area51.phpbb.com/docs/dev/32x/e ... ode-engine
Does wanna make me install symphony on another application. Seems to be a highly qualified framework, and I want to teach myself new things, do you use any framework?
Image
World of Phaos RPG online is making it's come back! Play free now!
Check out phpBB contributions & extension downloads. :P
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: phpBB post example for WP shortcode

Post by axew3 »

:D coffee coffee!! we'll go to add smilies and attachments! And even more.

Smilies can be replaced with easy, and maybe after all the rest has been processed (except eventually founded code blocks re-addition!) , so in class.wp.w3all-phpbb.php JUST AFTER this line:

Code: Select all

$res = self::w3all_bbcodeconvert($res); // convert all bbcode tags except
of function function wp_w3all_get_phpbb_post( $atts )
can be used something like this:

Code: Select all

$bbcode_smilies_on_posts = array( ";)", ":;)", ":(" ); // edit to match and add more
$smilies_replacements = array("urlTosmile1", "urlTosmile2", "urlTosmile3"); // edit to match and add more
$res = str_replace($bbcode_smilies_on_posts, $smilies_replacements, $res);
i've see on WP folder images, there is a folder with smilies.
We can chooose to link those smilies, instead than phpBB smilies, and/or we could copy/paste all phpBB smilies in use to this folder. So the urlTosmile1, urlTosmile2 etc can be URLs pointing to WP avatars of this folder folder (avoiding maybe to change so htaccess for images in phpBB that aren't served out of his directory). But this is merely a choose.
I've not test this but should work fine. We can also add with easy the option disable smiles that can be also added as param for the shortcode, something like:

Code: Select all

[w3allforumpost id="myPid" disablesmiles="1"]
Post Reply