JS Comparison in BBcode

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

JS Comparison in BBcode

Post by Zanzazaar » Fri Jun 01, 2018 2:47 am

So I just found funny problem. I can use in JS comparison '>' and '>=' or '==' but I cant use '<' and '<=', if I do bbcode wont parse. Like:
'x / y > 5' will work, but 'x / y < 5' wont. Values of 'x' and 'y' does not matter, I checked that. Well I can do my current bbcode with only > and >=, but this makes the whole thing mess and stopgap. Do you know something about this problem? Is there a way to use < and <=? My code is:

Code: Select all

[atab title={TEXT2} dobro={NUMBER1?} zlo={NUMBER2?} praworzadnosc={NUMBER3?} chaos={NUMBER4?}]{TEXT}[/atab]

Code: Select all

<xsl:choose>
	<xsl:when test="@title = 'REPUTACJA'">
<div id="{TEXT2}" class="tabcontent">
  {TEXT}
</div> 
<script type="text/javascript">

	var maxmod = 2;
	var minmod = 0.5;
	var dob = "{NUMBER1}";
	var zlo = "{NUMBER2}";
	var pra = "{NUMBER3}";
	var cha = "{NUMBER4}";
 
	
	if (pra / cha > maxmod && dob / zlo > maxmod ) {
			alert("praworzadny dobry");
		} 
	else if (pra / cha > maxmod && dob / zlo <= maxmod && dob / zlo >= minmod) {
			alert("praworzadny neutralny");
		} 
	else if (pra / cha > maxmod && dob / zlo < minmod ) {
			alert("praworzadny zly");
		} 
	else if (pra / cha <= maxmod && pra / cha >= minmod && dob / zlo > maxmod ) {
			alert("neutralny dobry");
		} 
	else if (pra / cha <= maxmod && pra / cha >= minmod && dob / zlo <= maxmod && dob / zlo >= minmod) {
			alert("neutralny");
		} 
	else if (pra / cha <= maxmod && pra / cha >= minmod && dob / zlo < minmod ) {
			alert("neutralny zly");
		} 
	else if (pra / cha < minmod && dob / zlo > maxmod ) {
			alert("chaotyczny dobry");
		} 
	else if (pra / cha < minmod && dob / zlo <= maxmod && dob / zlo >= minmod) {
			alert("chaotyczny neutralny");
		} 
	else {
			alert("chaotyczny zly");
		}
	
	var node = document.createElement("BUTTON");
	var textnode = document.createTextNode("{TEXT2}");
	node.appendChild(textnode);
	document.getElementById("tab").appendChild(node);
	var att1 = document.createAttribute("class");
	att1.value = "tablinks";
	var att2 = document.createAttribute("onclick");
	att2.value = "openAkcept(event, '{TEXT2}')";
	node.setAttributeNode(att1);
	node.setAttributeNode(att2);
</script>
	</xsl:when>
		
	<xsl:when test="@title">
<div id="{TEXT2}" class="tabcontent">
  {TEXT}
</div> 
<script type="text/javascript">
	var node = document.createElement("BUTTON");
	var textnode = document.createTextNode("{TEXT2}");
	node.appendChild(textnode);
	document.getElementById("tab").appendChild(node);
	var att1 = document.createAttribute("class");
	att1.value = "tablinks";
	var att2 = document.createAttribute("onclick");
	att2.value = "openAkcept(event, '{TEXT2}')";
	node.setAttributeNode(att1);
	node.setAttributeNode(att2);
</script>
	</xsl:when>
	<xsl:otherwise>
		Brak tytułu zakładki.
	</xsl:otherwise>
</xsl:choose>
Last edited by Zanzazaar on Fri Jun 01, 2018 2:05 pm, edited 3 times in total.

User avatar
3Di
Registered User
Posts: 13151
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: JS Comparison in BBcode

Post by 3Di » Fri Jun 01, 2018 5:47 am

not an expert really but, try, change
else if (pra / cha > maxmod && dob / zlo <= maxmod && dob / zlo >= minmod) {
to
if (((pra / cha) > maxmod) && ((dob / zlo) <= maxmod) && ((dob / zlo) >= minmod)) {

Code: Select all

if ...
if ...
if ...
Each condition per se and take care of comparisons precedences.
:game_die: The new Dice Roller extension for phpBB 3.2 is out! :game_die:

Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Zanzazaar
Registered User
Posts: 45
Joined: Fri Jan 15, 2016 2:14 pm

Re: JS Comparison in BBcode

Post by Zanzazaar » Fri Jun 01, 2018 9:35 am

That didnt help. But this issue occurs event if I create simple comparision with '<' in that direction.

User avatar
JoshyPHP
Code Contributor
Posts: 974
Joined: Mon Jul 11, 2011 12:28 am

Re: JS Comparison in BBcode

Post by JoshyPHP » Fri Jun 01, 2018 6:08 pm

If you use XSL elements you need to follow XSL rules and put the script content in a CDATA node: <script><![CDATA[...]]></script>

With that said, that BBCode is clearly unsafe and should never be used.

By the way, I'd like to point out that a > b is equivalent to b < a.
I wrote the thing that does BBCodes in 3.2.

Post Reply

Return to “Custom BBCode Development and Requests”

Who is online

Users browsing this forum: No registered users and 3 guests