Custom BBCode problem

Get help developing custom BBCodes or request one.
User avatar
wolfbeast
Registered User
Posts: 80
Joined: Sat Aug 10, 2013 1:24 am

Custom BBCode problem

Post by wolfbeast »

Hey folks,

I'm having a problem with custom BBCodes that were converted from an earlier version of phpBB.
The issue is this:
I used to have two bbcode tags for a similar function. One being [issue] the other [issue=], to link to specific issues in either the default repo or a custom repo of the organization on github.

Code: Select all

<a href="https://github.com/orgname/{SIMPLETEXT}/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER} ({SIMPLETEXT})</a>
versus
<a href="https://github.com/orgname/default-repo/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER}</a>
This worked fine, however with one of the upgrades, the one without the = was folded into the one with the =, and incorrectly so (killing the default repo link name and replacing it with the issue number), and having a new bbcode format I'm not familiar with with <xsl:> and {@issue} and ";useContent" tags in it...
I've tried to repair this by deleting it and recreating it, but I can no longer create a bbcode tag with the same name with and without an =, as phpBB simply refuses.
Since these bbcode tags are used in hundreds of posts, it's now broken as I can't link half of the tagged references.

How do I repair this?
User avatar
JoshyPHP
Code Contributor
Posts: 1291
Joined: Mon Jul 11, 2011 12:28 am

Re: Custom BBCode problem

Post by JoshyPHP »

Post the original BBCode definition and I'll take a look at it.

You're going to have to create a single definition that works for both usages then ideally you would reparse the old posts using the command line interface.

The full syntax for BBCode definitions is at https://s9etextformatter.readthedocs.io ... de_syntax/
I wrote the library that handles markup in phpBB 3.2+.
User avatar
wolfbeast
Registered User
Posts: 80
Joined: Sat Aug 10, 2013 1:24 am

Re: Custom BBCode problem

Post by wolfbeast »

>.< Why was it made this complicated? It used to be very straightforward to create custom bbcodes that any admin could use without needing a crash course in xsl or regex... :/

Anyway, I think I have a solution that works but would appreciate it if you could confirm I'm doing this correctly.

The original codes were:

Code: Select all

[issue]{NUMBER}[/issue]
<a href="https://github.com/orgname/default-repo/issues/{NUMBER}" target="_blank" rel="noreferrer"> Issue #{NUMBER}</a>

[issue={SIMPLETEXT}]{NUMBER}[/issue}
<a href="https://github.com/orgname/{SIMPLETEXT}/issues/{NUMBER}" target="_blank" rel="noreferrer"> Issue #{NUMBER} ({SIMPLETEXT})</a>
I've rewritten it as a single bbcode rule based on the docs and another auto-converted rule that still works, as follows:

Code: Select all

[issue={SIMPLETEXT?}]{NUMBER}[/issue]
<xsl:choose>
  <xsl:when test="@issue">
    <a href="https://github.com/orgname/{@issue}/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER} ({@issue})</a>
  </xsl:when>
  <xsl:otherwise>
    <a href="https://github.com/orgname/default-repo/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER}</a>
  </xsl:otherwise>
</xsl:choose>
Is that right?

What do I need to do to reparse the posts?
User avatar
JoshyPHP
Code Contributor
Posts: 1291
Joined: Mon Jul 11, 2011 12:28 am

Re: Custom BBCode problem

Post by JoshyPHP »

Everything that handles formatting (BBCodes, links, smilies, etc...) has been completely rewritten between phpBB 3.1 and 3.2. You can read about it in this topic from 2013. You have no idea how infuriating it is when somebody randomly asks something like "Why was it made this complicated?" as if someone with too much time on their hands went "oh, this is too easy I'm going to make it unnecessarily harder on myself and everybody."

The old BBCodes worked via basic string replacement. Little did you know, every time you created a custom BBCode, you were actually writing a regexp. That's because the code responsible for it would adjust the BBCode definition so it would become a valid regexp with the proper dynamic replacements. Incidentally, this requires to run generated code. This used to be done via the e pattern modifier. That modifier was deprecated in PHP 5.5 and removed from PHP 7.0 a few years ago.

The new BBCodes work via a PHP parser and a templating language. Most people don't need to know about the details and can keep using their old configuration because BBCode definitions are analysed and used to generate a proper configuration for the parser, while BBCode templates are quietly transformed into XSL templates. When there is more than one definition for a BBCode, an algorithm merges the two definitions into one that hopefully can be used for both usage. There are two strategies for the merge: one that is suitable for BBCodes such as [url] and one that is suitable for those like [quote]. In the case of your [issue] BBCode, the wrong one was selected. I'll see if the algorithm can be improved to better detect that kind of BBCodes.

I looked at your handcrafted definition. It looks fine and I don't think you will have to reparse the old posts. Have you tried displaying old posts to see whether they are correct?
I wrote the library that handles markup in phpBB 3.2+.
User avatar
wolfbeast
Registered User
Posts: 80
Joined: Sat Aug 10, 2013 1:24 am

Re: Custom BBCode problem

Post by wolfbeast »

Thanks, I appreciate your help.
JoshyPHP wrote: Mon Nov 25, 2019 1:45 am You have no idea how infuriating it is when somebody randomly asks something like "Why was it made this complicated?" as if someone with too much time on their hands went "oh, this is too easy I'm going to make it unnecessarily harder on myself and everybody."
That is not at all what I was getting at. But you have to understand that it is equally infuriating for admins who just want to operate a board that their readable, simple bbcode string replacement strings that were written years back are suddenly transformed into some complex parser source in a point update, and look completely like gobbledegook at first glance; as a dev you know how it worked under the hood before but that's never exposed to people running the board (which is generally a good thing!). I held off on updating to 3.2 for a long time, but when finally getting around to doing so after seeing most of the stuff could be made to work in 3.2, I didn't expect this to suddenly break, either. My question was simply WHY this was done, and you've explained it -- please don't read more into it and see it from my point of view.
As an admin, I generally don't read dev forum posts of the software I use when I'm not directly involved in their development -- I don't have the time for that ;)

Would there have been a simpler way to approach this problem in the new system than what I wrote, so I can use that in the future?
JoshyPHP wrote: Mon Nov 25, 2019 1:45 am I looked at your handcrafted definition. It looks fine and I don't think you will have to reparse the old posts. Have you tried displaying old posts to see whether they are correct?
No, it doesn't look like it's correct in old posts, but it does seem it's correct in writing new ones.
The old posts do it wrong by replacing the [issue] tag with the format of the [issue=] tag (and repeating the number in the supposed repo name which doesn't work) so I guess I'll have to re-parse everything because it's stored incorrectly now from the wrongly transformed definition.
User avatar
JoshyPHP
Code Contributor
Posts: 1291
Joined: Mon Jul 11, 2011 12:28 am

Re: Custom BBCode problem

Post by JoshyPHP »

wolfbeast wrote: Mon Nov 25, 2019 8:57 am But you have to understand that it is equally infuriating for admins [..]
I understand that people generally find change annoying but I would object to the idea of being equally infuriating. This is a very lopsided situation where users spend nothing and get a software, while developers spend their time and get nothing for it. You mentioned time twice in your reply, so I know you understand its importance.
wolfbeast wrote: Mon Nov 25, 2019 8:57 am Would there have been a simpler way to approach this problem in the new system than what I wrote, so I can use that in the future?
No, not in this case. The templates for both versions of the BBCode look similar but they contain two differences (the URL for the link and the text content) so that means you'd need two conditionals. It's simpler to have only one conditional with the whole template in each branch.

I tried your old BBCodes on my test board and I this template should work fine without any reparsing:

Code: Select all

<xsl:choose>
  <xsl:when test="@issue">
    <a href="https://github.com/orgname/{SIMPLETEXT}/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER} ({SIMPLETEXT})</a>
  </xsl:when>
  <xsl:otherwise>
    <a href="https://github.com/orgname/default-repo/issues/{NUMBER}" target="_blank" rel="noreferrer">Issue #{NUMBER}</a>
  </xsl:otherwise>
</xsl:choose>
I wrote the library that handles markup in phpBB 3.2+.
User avatar
wolfbeast
Registered User
Posts: 80
Joined: Sat Aug 10, 2013 1:24 am

Re: Custom BBCode problem

Post by wolfbeast »

JoshyPHP wrote: Mon Nov 25, 2019 3:35 pm This is a very lopsided situation where users spend nothing and get a software, while developers spend their time and get nothing for it.
... Then don't make it free.

Seriously, it's sad that you even want to play this card to begin with. It's not just about change and resistance to it; then playing the "we can spring any change on the admins of boards because they aren't paying for it" is displaying a rather worrying lack of consideration for the users of your software who often do not have the time to dedicate days on having to adapt to changes. I understand more now why so many phpBB installations are old and don't update.

Then to the topic at hand:
Would there have been a simpler way to approach this problem
No, not in this case.
So the bottom line is that admins who are not familiar with the template language/parser will have to teach themselves how to use it, instead of being able to have a low threshold and easy to understand string replacement. If you are so aware of the value of time, then you should have come up with a different solution. Please simplify it if you can. It might mean actually not just relying on a 3rd party component.

As for the offered template:
The template does not display correctly in old posts, only in newly-created ones. Neither my solution nor the one you offered.
Please let me know how to re-parse all posts so I can do that in the next maintenance window.
User avatar
JoshyPHP
Code Contributor
Posts: 1291
Joined: Mon Jul 11, 2011 12:28 am

Re: Custom BBCode problem

Post by JoshyPHP »

wolfbeast wrote: Mon Nov 25, 2019 8:40 pm ... Then don't make it free.
You're right. Feel free to post in the Wanted! section next time.
wolfbeast wrote: Mon Nov 25, 2019 8:40 pm Please let me know how to re-parse all posts so I can do that in the next maintenance window.
People like you are a big reason for attrition in FLOSS projects. Self-entitled users who openly admit they don't want to spend any time on even configuring their software, berate developers and in the same breath ask for free support. Anyway, this is my last post in this topic. Good luck.
I wrote the library that handles markup in phpBB 3.2+.
User avatar
wolfbeast
Registered User
Posts: 80
Joined: Sat Aug 10, 2013 1:24 am

Re: Custom BBCode problem

Post by wolfbeast »

Hey guess what? I have very little time to learn arbitrary parser languages because I develop FLOSS software myself.

But I'll leave your triggered self alone, and spend my time finding out how to re-parse posts instead of having pointless discussions with people who create community software based on purely self-serving decisions, then berate people for having critique because "it's free". I think you're in the wrong corner of the software market.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Custom BBCode problem

Post by david63 »

wolfbeast wrote: Mon Nov 25, 2019 10:50 pm Hey guess what? I have very little time to learn arbitrary parser languages because I develop FLOSS software myself.

But I'll leave your triggered self alone, and spend my time finding out how to re-parse posts instead of having pointless discussions with people who create community software based on purely self-serving decisions, then berate people for having critique because "it's free". I think you're in the wrong corner of the software market.
I think that you are overlooking one significant point here. One way or another BBCodes in phpBB had to change due to the change in PHP which is totally outside the control of anyone at phpBB
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
warmweer
Jr. Extension Validator
Posts: 11874
Joined: Fri Jul 04, 2003 6:34 am
Location: somewhere in the space-time continuum

Re: Custom BBCode problem

Post by warmweer »

wolfbeast wrote: Mon Nov 25, 2019 10:50 pm Hey guess what? I have very little time to learn arbitrary parser languages because I develop FLOSS software myself.

But I'll leave your triggered self alone, and spend my time finding out how to re-parse posts instead of having pointless discussions with people who create community software based on purely self-serving decisions, then berate people for having critique because "it's free". I think you're in the wrong corner of the software market.
Just hopped in now.
Since JoshyPHP's solution works for new posts, but not for old posts ...
Why not identify the old posts in the database, and compare them to the new posts?
And then modify those old posts with SQL (based on the new posts).
I would even go further and make 2 new BBcodes, test them on new posts and then modify all posts with the old BBcode to the new format (and then completely remove the old BBcode.

No software developer knowledge necessary, basic SQL search and replace might come in handy though (but examples enough to be found on the net).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.

Return to “Custom BBCode Development and Requests”