Yet another JS problem in bbcode, also token problem

Get help developing custom BBCodes or request one.
Post Reply
Zanzazaar
Registered User
Posts: 57
Joined: Fri Jan 15, 2016 2:14 pm

Yet another JS problem in bbcode, also token problem

Post by Zanzazaar »

Im trying to make another bbcode:

Code: Select all

<xsl:choose>

	<xsl:when test="@typ = 'Walka'">
		<div class="bbrow">
			<div class="bbtitle">
				{INTTEXT}
				{NUMBER}
				<input id="TESTATR{INTTEXT}{SIMPLETEXT}"></input>
			</div>
			<div class="bbcontent">
				<div>text</div>
					
				<div>text</div>

				<div>text</div>

				<div>text</div>
			</div>
		</div>

		<script>
		var n{INTTEXT}{SIMPLETEXT} = {NUMBER};
		var i{INTTEXT}{SIMPLETEXT} = 1;
		var s{INTTEXT}{SIMPLETEXT} = 0;
		while (i{INTTEXT}{SIMPLETEXT} <= n{INTTEXT}{SIMPLETEXT}) s{INTTEXT}{SIMPLETEXT} = s{INTTEXT}{SIMPLETEXT} + i{INTTEXT}{SIMPLETEXT}++;
		document.getElementById('TESTATR{INTTEXT}{SIMPLETEXT}').value = s{INTTEXT}{SIMPLETEXT};
		</script>

	</xsl:when>

	<xsl:when test="@typ = 'test'">
		test
	</xsl:when>


	<xsl:otherwise>
		test2
	</xsl:otherwise>
</xsl:choose>
The issue is, when I put that part in the <script>

Code: Select all

		while (i{INTTEXT}{SIMPLETEXT} <= n{INTTEXT}{SIMPLETEXT}) s{INTTEXT}{SIMPLETEXT} = s{INTTEXT}{SIMPLETEXT} + i{INTTEXT}{SIMPLETEXT}++;
I cannot save the bbcode. I have red warning background but no information about problem and no option to save it anyway.

Also, when I try to use token {TEXT} inside of xsl:when I cannot parse the bbcode with the error "Parse error: syntax error, unexpected 'case' (T_CASE) in /home/p516445/public_html/cache/production/s9e_renderer_6cdda97e804f7c7efb82dbf007ca90019500a785.php on line 342"
As I remember, there was no such issue in the phpbb 3.1.x.
Well I am sure about that, I have still bbcode from the 3.1.x version (I created it before the update)

Code: Select all

	<xsl:when test="@title = 'bar'">
		<div class="bbhead">{TEXT}</div>
	</xsl:when>
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Yet another JS problem in bbcode, also token problem

Post by JoshyPHP »

Zanzazaar wrote: Tue May 18, 2021 6:54 pm The issue is, when I put that part in the <script>
If you use XSL you need to use well-formed XML, apart from requirement of having a single root element. That means no < in text, unless you use CDATA. I actively ignored the rest of the template because I'm deathly allergic to user input in JavaScript. I strongly advise against it, just in case.
Zanzazaar wrote: Tue May 18, 2021 6:54 pm Also, when I try to use token {TEXT} inside of xsl:when I cannot parse the bbcode with the error "Parse error: syntax error, unexpected 'case' (T_CASE) in /home/p516445/public_html/cache/production/s9e_renderer_6cdda97e804f7c7efb82dbf007ca90019500a785.php on line 342"
I'd be interested in looking into this specific error if you're able to provide the specific steps needed to reproduce it on a clean board. Most importantly, the content of the BBCode usage and HTML replacement fields in text form suitable for copy/pasting.
I wrote the library that handles markup in phpBB 3.2+.
Zanzazaar
Registered User
Posts: 57
Joined: Fri Jan 15, 2016 2:14 pm

Re: Yet another JS problem in bbcode, also token problem

Post by Zanzazaar »

I understand your allergy, but in the end, it is play by forum and I need it ;) I am trying to use only NUMBER, INTEXT and SIMPLETEXT when I need to use it.
Thanks for info, I will try to make a little change. Sadly, I don't know anything about CDATA, my forum is just a little hobby but maybe I will be able to do something with that.

About the last problem I tried to create simple bbcode for an example

Code: Select all

[testtext title={TEXT1?}]{TEXT}[/testtext]

Code: Select all

<xsl:choose>

	<xsl:when test="@title = 'bar'">
		<div>{TEXT}</div>
	</xsl:when>

	<xsl:otherwise>
		<div>{TEXT}</div>
	</xsl:otherwise>
</xsl:choose>
Error:
Parse error: syntax error, unexpected 'case' (T_CASE) in /home/p516445/public_html/cache/production/s9e_renderer_cb0cb30bd013c2da1251b40ef23d679c318c8459.php on line 342
As I checked, if there is no other issue, bbcode is created even with that error. But if I want to edit it again, same issue and I need to reload previous page.
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Yet another JS problem in bbcode, also token problem

Post by JoshyPHP »

CDATA is easy to use:

Code: Select all

<script><![CDATA[
// code goes here
]]></script>
But really it would be better handled inside of its own JavaScript file in a custom style. You don't have to use the user input inside of the JavaScript code. You can output it inside of an attribute and retrieve the attribute's value in JavaScript.

Code: Select all

<b data-whatever="{TEXT}">..</b>
<script>alert(document.querySelector('[data-whatever]').dataset.whatever)</script>
Zanzazaar wrote: Tue May 18, 2021 7:57 pm About the last problem I tried to create simple bbcode for an example
That BBCode works fine on my local 3.3 board on PHP 7.3 and 8.0.
Last edited by JoshyPHP on Wed May 19, 2021 6:57 pm, edited 1 time in total.
I wrote the library that handles markup in phpBB 3.2+.
Zanzazaar
Registered User
Posts: 57
Joined: Fri Jan 15, 2016 2:14 pm

Re: Yet another JS problem in bbcode, also token problem

Post by Zanzazaar »

So, it is some local problem, on my side. Thanks.

About that safe method for the JS, thanks! I will try to use that. As I think it could be also easier way to create clear and small JS.
Zanzazaar
Registered User
Posts: 57
Joined: Fri Jan 15, 2016 2:14 pm

Re: Yet another JS problem in bbcode, also token problem

Post by Zanzazaar »

I have a question, if I would like to load JS files but not by the style files but a bbcode, path like "<!-- INCLUDEJS lokacje.js -->" wont help me. Is there a way to load that kind of file with a bbcode, to use that in only one topic?
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Yet another JS problem in bbcode, also token problem

Post by JoshyPHP »

Not as a BBCode, no.
I wrote the library that handles markup in phpBB 3.2+.
Post Reply

Return to “Custom BBCode Development and Requests”