JS Comparison in BBcode

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

JS Comparison in BBcode

Post by Zanzazaar »

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
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: JS Comparison in BBcode

Post by 3Di »

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.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Zanzazaar
Registered User
Posts: 57
Joined: Fri Jan 15, 2016 2:14 pm

Re: JS Comparison in BBcode

Post by Zanzazaar »

That didnt help. But this issue occurs event if I create simple comparision with '<' in that direction.
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: JS Comparison in BBcode

Post by JoshyPHP »

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 library that handles markup in phpBB 3.2+.
Post Reply

Return to “Custom BBCode Development and Requests”