Is there a way to make a BBCode token optional?

Get help developing custom BBCodes or request one.
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Is there a way to make a BBCode token optional?

Post by Bruce Banner »

I'm trying to create a BBCode for a HTML5 video player. I want to give people the option of linking to a poster image for the video but I want to make it optional. So people can link to one if they want or not if they don't. I know I can create two separate BBCodes, one for a video with a poster image and one without, but I'm trying to figure out if there's a way I can create just one that'll do both. So a BBCode with one URL token, URL1, for the address of the video, and another URL token, URL2, for the address of the poster image for the video, but URL2 is optional. Is that possible?
Last edited by HiFiKabin on Sat Aug 15, 2020 4:27 pm, edited 1 time in total.
User avatar
AbaddonOrmuz
Recognised Extension Developer
Posts: 1017
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

Re: Is there a way to make a BBCode token optional?

Post by AbaddonOrmuz »

Sharing the actual code would have be more useful.

Anyways, you can use ? or ;optional just after the token, and that will make it optional.
Some of my phpBB extensions:
Image Imgur | :chart_with_upwards_trend: SEO Metadata | Image Markdown | :lock: Auto-lock Topics
:trophy: Check out all my validated extensions :trophy:

:penguin: Arch Linux user :penguin:
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

AbaddonOrmuz wrote:
Sat Aug 15, 2020 8:15 pm
Sharing the actual code would have be more useful.

Anyways, you can use ? or ;optional just after the token, and that will make it optional.
Usage:

Code: Select all

[player]{URL1},{NUMBER1},{NUMBER2},{URL2?},{URL3?}[/player]
Replacement:

Code: Select all

<div class="container">
<video width="{NUMBER1}" height="{NUMBER2}" controls crossorigin playsinline poster="{URL2}">
		 <source src="{URL1}" type="video/mp4">

			<track kind="captions" label="English" srclang="en" src="{URL3}"
					default>
</video>
</div>
I can't get this to work.

Forgot to mention I also wanna make captions optional.
Last edited by Mick on Sun Aug 16, 2020 8:29 am, edited 1 time in total.
Reason: Swapped [c] for [code] tags for clarity.
User avatar
3Di
Former Team Member
Posts: 16052
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano 🇮🇹 - Frankfurt 🇩🇪
Name: Marco
Contact:

Re: Is there a way to make a BBCode token optional?

Post by 3Di »

Pls use the right BBcode (code) to post your stuff. It is a mess ATM, difficult to read.
To request support for our extensions you can also contact me here: phpBB Studio

Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
🚀 Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
JoshyPHP
Code Contributor
Posts: 1177
Joined: Mon Jul 11, 2011 12:28 am

Re: Is there a way to make a BBCode token optional?

Post by JoshyPHP »

You should most definitely give names to those attributes or anytime you'll change anything the old version will stop working.

Code: Select all

[player url={URL1} poster={URL2?} width={NUMBER1} height={NUMBER2}]
The whole syntax is at https://s9etextformatter.readthedocs.io ... de_syntax/
I wrote the thing that does BBCodes in 3.2+.
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

JoshyPHP wrote:
Sun Aug 16, 2020 6:46 am
You should most definitely give names to those attributes or anytime you'll change anything the old version will stop working.

Code: Select all

[player url={URL1} poster={URL2?} width={NUMBER1} height={NUMBER2}]
The whole syntax is at https://s9etextformatter.readthedocs.io ... de_syntax/
That's way too complicated for me. I don't understand why naming them makes any difference. I can't understand that page about the syntax. I just wanna figure out how to get this BBCode to work. I've never had to worry about "naming" "attributes" before when it comes to creating working BBCodes.
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

So there's no way to make those things optional then?
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

No?
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

Still no?
User avatar
Mick
Support Team Member
Support Team Member
Posts: 22919
Joined: Fri Aug 29, 2008 9:49 am
Location: Watching cricket probably.

Re: Is there a way to make a BBCode token optional?

Post by Mick »

Maybe it can be done with an extension?
"The more connected we get the more alone we become" - Kyle Broflovski©
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

Mick wrote:
Thu Nov 19, 2020 9:37 am
Maybe it can be done with an extension?
I'm hoping that's not necessary because I don't think there's any extension that'd do it. I'm trying to figure out how to write the XSL code but I get a message saying my BBCode's template is invalid.

BBCode usage

Code: Select all

[test2 poster={URL2?}]{URL1}[/test2]
HTML replacement

Code: Select all

<xsl:choose>
	<xsl:when test="@poster">
         <center><video controls poster="{URL2}"><source src="{URL1}" type="video/mp4"></video></center>
	</xsl:when>
	<xsl:otherwise>
         <center><video controls><source src="{URL1}" type="video/mp4"></video></center>
	</xsl:otherwise>
</xsl:choose>
User avatar
EA117
Registered User
Posts: 1858
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Is there a way to make a BBCode token optional?

Post by EA117 »

It appears as though the DOMDocument::loadXML parsing doesn't like two things about your replacement template:
  • Parsing has caught your un-closed <source> tag, and was returning "Invalid XSL: EndTag: '</' not found". Making those into self-closing <source /> tags will eliminate that failure.
  • Parsing seems to "fail" in the presence of the controls attribute on the <video> element. The failure seems to be "aborting" parsing such that the remainder of the document is being declared as "Invalid XSL: Extra content at the end of the document". Removing the controls attribute avoids this, but is not desirable or the right solution.
Unfortunately "the real reason that's failing" is mostly above my pay grade. I suspect that it's XML "every attribute must have a value specified" versus HTML "attributes do not necessarily have to have values specified." You might try using controls="controls" or controls="true" or even simply controls="" to see if this creates a "controls attribute exists" condition that causes the HTML5 video player to show controls, but in a way that also passes the XML parsing.

All I can say for sure is that this doesn't seem like a "legitimate" extra content error, since simply removing the controls attribute avoids the issue, and dumping the XML being passed to DOMDocument::loadXML when the failure occurs doesn't show anything "extra":

Code: Select all

string(413) "<?xml version="1.0" encoding="utf-8" ?><xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:choose>
	<xsl:when test="@poster">
         <center><video controls poster="{URL2}"><source src="{URL1}" type="video/mp4" /></video></center>
	</xsl:when>
	<xsl:otherwise>
         <center><video controls><source src="{URL1}" type="video/mp4" /></video></center>
	</xsl:otherwise>
</xsl:choose></xsl:template>"
JoshyPHP presumably has the best chance of already knowing what's wrong or how a an XSL template might have been expected to specify an attribute without a value for it's HTML output. We could try pinging him back to the discussion for how a value-less attribute might be specified in the XSL template.

Actually I see the MediaEmbed plug-in uses <video controls="">, so rather than bug Joshy I'd say just do that. The built-in templates that utilize <video> don't appear to be expected to pass XML-based template validation, and are instead intended to pass HTML-based template validation. Your conditional template, of course, must pass the XML validation.
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

EA117 wrote:
Thu Nov 19, 2020 9:05 pm
It appears as though...
That's fantastic, thanks! :mrgreen: To be honest, I don't actually understand most of that post because I'm totally new to XML and haven't read anything about it. Just got sample XML code from somewhere and started fiddling around with it, trial and error. It turns out what I need is both controls="" and a closing source tag. Without either I get an invalid template error but with both, it works fine. If I put in a URL for the poster image, the image displays, and if I don't, I get the first frame of the video.

The exact code is,

BBCode usage

Code: Select all

[MP4 poster={URL2?}]{URL1}[/MP4]
HTML replacement

Code: Select all

<xsl:choose>
	<xsl:when test="@poster">
		<center><video controls="" poster="{URL2}"><source src="{URL1}" type="video/mp4"></source></video></center>
	</xsl:when>
	<xsl:otherwise>
		<center><video controls=""><source src="{URL1}" type="video/mp4"></source></video></center>
	</xsl:otherwise>
</xsl:choose>
Now I'm trying to do something which for some reason seems a lot more complicated; trying to add a second option, a subtitle track.

Here's the code I've tried,

Code: Select all

[MP4 poster={URL2?} subtitle={URL3?}]{URL1}[/MP4]
HTML replacement

Code: Select all

<xsl:choose>
	<xsl:when test="@poster">
		<xsl:choose>
			<xsl:when test="@subtitle">
				<center><video controls="" poster="{URL2}"><source src="{URL1}" type="video/mp4"></source><track label="English" kind="subtitles" srclang="en" src="{URL3}"></track></video></center>
			</xsl:when>
			<xsl:otherwise>
				<center><video controls="" poster="{URL2}"><source src="{URL1}" type="video/mp4"></source></video></center>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:when>
	<xsl:otherwise>
		<center><video controls=""><source src="{URL1}" type="video/mp4"></source></video></center>
	</xsl:otherwise>
	<xsl:when test="@subtitle">
		<xsl:choose>
			<xsl:when test="@poster">
				<center><video controls="" poster="{URL2}"><source src="{URL1}" type="video/mp4"></source><track label="English" kind="subtitles" srclang="en" src="{URL3}"></track></video></center>
			</xsl:when>
			<xsl:otherwise>
				<center><video controls=""><source src="{URL1}" type="video/mp4"></source><track label="English" kind="subtitles" srclang="en" src="{URL3}"></track></video></center>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:when>
	<xsl:otherwise>
		<center><video controls=""><source src="{URL1}" type="video/mp4"></source></video></center>
	</xsl:otherwise>
</xsl:choose>
The problem I'm having is the subtitles won't display. I don't know why. They're in the correct format, and I've tested the code four times, with both the poster and subtitle, with the poster but without the subtitle, with the subtitle but without the poster, and with neither. All four times the video displayed fine, and the subtitle button displayed in the video controls when I entered the subtitle URL. By default, it appears crossed out, but when I click it, two options appear, Off, which is blue, and English, which is grey. If I select English, the colours switch, and the button's no longer crossed out, but the damn subtitles still will not display. Could it be something wrong with my code, or something wrong with the subtitle file? Maybe how I've formatted it, or what I've called it, or where I've stored it?
User avatar
EA117
Registered User
Posts: 1858
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Is there a way to make a BBCode token optional?

Post by EA117 »

The fact that you get so many of the correct reactions -- the subtitle button actually displays when a subtitle track has been specified, and the language selection seems to be "working" even though it's just a subtle color change -- makes it seem like you're getting what you're wanting out of the BBCode having correctly (and conditionally) provided the option.

But that yes, you now have a question or issue regarding "how does the HTML5-invoked video player actually work", "is there any CSS I could add which would control the appearance of the language selection", "what different subtitle formats does the player support", and "is there anything wrong with the specific subtitle file that I am supplying."

None of which are phpBB or BBCode questions or issues, until you figure out the answers and decide whether it means you want to modify the HTML replacement code being used for this BBCode. I don't happen to be versed in how the HTML5 player works myself, but that kind of information is probably best learned from somewhere besides phpBB-related support anyway.
Bruce Banner
Registered User
Posts: 834
Joined: Thu Sep 25, 2014 10:36 am

Re: Is there a way to make a BBCode token optional?

Post by Bruce Banner »

EA117 wrote:
Fri Nov 20, 2020 11:34 am
The fact that you...
Hm, no, I wasn't actually asking how the player works or how to style the selection menu so I don't know why you thought I was. I was just describing exactly everything that was happening with my tests. I wasn't talking about blue and grey because I'd like to change those colours; I was only mentioning them because I don't know what's important and what isn't so I just described every single thing.

Anyway, yeah, I'll try learning more about subtitles to see if I can figure out what the problem is. If I can't figure it out, maybe it does have something to do with the code above.
Post Reply

Return to “Custom BBCode Development and Requests”