Implemeting Jass Tags Into Vbulletin.

Reaction score
341
Ok i searched this site for how to implement jass tags into a vbulletin site and i found a parser?

PHP:
<?php
// Jass Highlighter
// Written by Asger Feldthaus (KaTTaNa)

if(!defined('JASS_HIGHLIGHTER_INCLUDED'))  // Make sure it is only included once.
{
define('JASS_HIGHLIGHTER_INCLUDED', true);

function FixWord($word) {
  $Blocks = 
   " constant native function takes returns endfunction if then else elseif endif loop endloop exitwhen ( ) [ ] ";
   
  $Keywords = 
   " call set local return not and or ";

  $Values = 
   " true false null ";

  $Types = 
   " nothing array string integer real code boolean handle event player widget unit destructable item ability buff ".
   "force group trigger triggercondition triggeraction timer location region rect boolexpr sound conditionfunc filterfunc ".
   "unitpool itempool race alliancetype racepreference gamestate igamestate fgamestate playerstate playergameresult ".
   "unitstate aidifficulty eventid gameevent playerevent playerunitevent unitevent limitop widgetevent dialogevent ".
   "unittype gamespeed gamedifficulty gametype mapflag mapvisibility mapsetting mapdensity mapcontrol playerslotstate ".
   "volumegroup camerafield camerasetup playercolor placement startlocprio raritycontrol blendmode texmapflags effect ".
   "effecttype weathereffect terraindeformation fogstate fogmodifier dialog button quest questitem defeatcondition timerdialog ".
   "leaderboard multiboard multiboarditem trackable gamecache version itemtype texttag playerscore lightning pathingtype image ubersplat ".
   "attacktype damagetype weapontype soundtype ";
   
  if (strpos($Blocks, " ".$word." ")!== false) {
    return "<b>".$word."</b>";
  } 
  elseif (strpos($Keywords, " ".$word." ")!== false) {
    return "<span style=\"color: Navy;\">".$word."</span>";
  }
  elseif (strpos($Values, " ".$word." ")!== false) {
    return "<span style=\"color: Maroon;\">".$word."</span>";
  }
  elseif (strpos($Types, " ".$word." ")!== false) {
    return "<span style=\"color: rgb(50, 100, 200);\">".$word."</span>";
  }
  return $word;
}

function HighlightJass($text, $bb=false) { 
  $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  $special = "[]()";
  $str = "\"'";
  $trans = Array(">" => "&gt;", "<" => "&lt;", "&" => "&amp;");
  if (!$bb)
  {
  	$text = strtr($text, $trans);
  }
  else
  {
  	// Do some backwards working
	$tr = array('(' => '(',
				')' => ')',
				'[' => '[',
				']' => ']',
				'&quot;' => '"');
	$text = strtr($text,$tr);
  }
  
  $result = "";
  $comment = 0;
  $Lines = explode("\n", $text);
  $anchors = array();
  $n = 0;
  // First, find all functions and place an anchor there
  foreach($Lines as $Line) 
  {
  	// Leave anchor here?
	$reg = array();
	$anchors[$n] = '';
  	if (ereg('^ *(constant )? *(function|native)  *([a-zA-Z_][a-zA-Z_0-9]*)  *takes', $Line, $reg))
	{
		$l = max(0, $n-12);
		$anchors[$l] .= '<a name="'.strtolower($reg[3]).'"></a>';
	}
	$n++;
  }
  $n = 0;
  foreach($Lines as $Line) 
  {
    $result .= $anchors[$n];
	$Line = rtrim($Line);
	if ($isString) {
	  $result = $result . "</span>";
	}
    $stop = strpos($Line, "//");
	if ($stop === false) {
	  $stop = strlen($Line);
	  $comment = 0;
	} else {
	  $comment = 1;
	}
    $i = 0;
	$word = "";
	$isString = 0;
	$stringStarter = "";	
	$slashed = 0;
	// Highlight
	while ($i < $stop) {
	  $c = substr($Line, $i, 1);
	  $i += 1;
	  
	  if ($isString) {
	    $result = $result . $c;
	    if ($c == "\\") {
		  $slashed = ($slashed)? 0:1;
		} elseif (($c == $stringStarter) && !($slashed)) {
		  $result = $result . "</span>";
		  $isString = 0;
		} else {
		  $slashed = 0;
		}
	  } else {
	    // If normal character
	    if (strpos($chars, $c) !== false) {
          $word = $word . $c;
		
	    // If bracket
	    } elseif (strpos($special, $c) !== false) {
	      $result = $result . FixWord($word) . FixWord($c);
	    	$word = "";
		
	    // If string
        } elseif (strpos($str, $c) !== false) { 
	      $result = $result . FixWord($word) . "<span style=\"color: blue\">" . $c;
		  $slashed = 0;
		  $word = "";
		  $isString = 1;
		  $stringStarter = $c;
		
	    // If other character
	    } else {
	      $result = $result . FixWord($word) . $c;
		  $word = "";
        }
		
	  } // if ($isString)
	}
	$result = $result . FixWord($word);
	
	// Add comment
	if ($comment) {
	  $result = $result . "<span style=\"color: green;\">".strstr($Line, "//")."</span>";
	}
	// Add linebreak
	$result = $result . '<br />';
	$n++;
  }
  $result = substr($result, 0, strlen($result)-1); // Remove last linebreak
  
  if ($bb)
  {
  	$tr = array('(' => '(',
				')' => ')',
				'[' => '[',
				']' => ']');
	$result = strtr($result, $tr);
  }
  
  return $result;
}

}
?>


how would i use this to implement the jass tags?
 

TFlan

I could change this in my User CP.
Reaction score
64
Exactly.

A simple find and replace will do the trick.

With a condition to only do the find and replace within certain tags.

IE: [ jass] code here [/jass ]

writing the code... gimme a sec

PHP:
$content = "code here";
$content = HighlightJass($content);
$search = array( "[jass]", "[/jass]" );
$replace = array( 
	"<div style='margin:20px; margin-top:5px'>
		<div style='margin-bottom:2px'>Jass:</div>
		<div dir='ltr' style='text-align:left;'>
			<pre style='margin:0px; padding:6px; border:1px inset; width:800px; height:34px; overflow:auto'>",
			"</pre>
		</div>
	</div>" );
str_replace($search, $replace, $content);

I think thats how the Jass Highlighting script works. Send the text to the script using HighlightJass().

Then it searches for [ jass] and [/jass ] in the content and replaces it with what u see on this site prior to the code and after.

PS: i had to put a space ( ' ' ) inside the tags so the site didnt make the <pre> tags around my post.
 
Reaction score
341
thanks ill try that and post back if it works :)


EDIT : Im really confused , what do i do with the code you gave me?
 

TFlan

I could change this in my User CP.
Reaction score
64
... it just repeats the php code

What do you mean?

----

If all else fails, edit the source code of the posts php file to run that script. Could get messy and require alot of trial and error, but this is your last resort option.
 
Reaction score
341
whenever i add the bbcode and u type the "["jass] code.. [/jass"]" it just shows


PHP:
".$word.""; } elseif (strpos($Keywords, " ".$word." ")!== false) { return "".$word.""; } elseif (strpos($Values, " ".$word." ")!== false) { return "".$word.""; } elseif (strpos($Types, " ".$word." ")!== false) { return "".$word.""; } return $word; } function HighlightJass($text, $bb=false) { $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; $special = "[]()"; $str = "\"'"; $trans = Array(">" => ">", "<" => "<", "&" => "&"); if (!$bb) { $text = strtr($text, $trans); } else { // Do some backwards working $tr = array('(' => '(', ')' => ')', '[' => '[', ']' => ']', '"' => '"'); $text = strtr($text,$tr); } $result = ""; $comment = 0; $Lines = explode("\n", $text); $anchors = array(); $n = 0; // First, find all functions and place an anchor there foreach($Lines as $Line) { // Leave anchor here? $reg = array(); $anchors[$n] = ''; if (ereg('^ *(constant )? *(function|native) *([a-zA-Z_][a-zA-Z_0-9]*) *takes', $Line, $reg)) { $l = max(0, $n-12); $anchors[$l] .= ''; } $n++; } $n = 0; foreach($Lines as $Line) { $result .= $anchors[$n]; $Line = rtrim($Line); if ($isString) { $result = $result . ""; } $stop = strpos($Line, "//"); if ($stop === false) { $stop = strlen($Line); $comment = 0; } else { $comment = 1; } $i = 0; $word = ""; $isString = 0; $stringStarter = ""; $slashed = 0; // Highlight while ($i < $stop) { $c = substr($Line, $i, 1); $i += 1; if ($isString) { $result = $result . $c; if ($c == "\\") { $slashed = ($slashed)? 0:1; } elseif (($c == $stringStarter) && !($slashed)) { $result = $result . ""; $isString = 0; } else { $slashed = 0; } } else { // If normal character if (strpos($chars, $c) !== false) { $word = $word . $c; // If bracket } elseif (strpos($special, $c) !== false) { $result = $result . FixWord($word) . FixWord($c); $word = ""; // If string } elseif (strpos($str, $c) !== false) { $result = $result . FixWord($word) . "" . $c; $slashed = 0; $word = ""; $isString = 1; $stringStarter = $c; // If other character } else { $result = $result . FixWord($word) . $c; $word = ""; } } // if ($isString) } $result = $result . FixWord($word); // Add comment if ($comment) { $result = $result . "".strstr($Line, "//").""; } // Add linebreak $result = $result . '
'; $n++; } $result = substr($result, 0, strlen($result)-1); // Remove last linebreak if ($bb) { $tr = array('(' => '(', ')' => ')', '[' => '[', ']' => ']'); $result = strtr($result, $tr); } return $result; } } ?> $content = "code here"; $content = HighlightJass($content); $search = array( "[jass]", "[/jass]" ); $replace = array( "
Jass:
",
            "" ); str_replace($search, $replace, $content);
 

TFlan

I could change this in my User CP.
Reaction score
64
Because you set the replacement text to be the actual script. So you said: Where there is [jass ] asdfasdf [/jass ] replace all of it with <script above>.

Do this, in the replacement textbox have this: HighlightJass({param});

Then add the actual script (without my addition to it) to the BBCode source page.

Try that.

You may need to add the php tags:
<?php HighlightJass( ?>{param}<?php ); ?>
 
Reaction score
341
ill try rite now


EDIT : i did whatever u told me to do ( i think.. ) does the same thing.

PHP:
HighlightJass({param});
<?php 
// Jass Highlighter 
// Written by Asger Feldthaus (KaTTaNa) 

if(!defined('JASS_HIGHLIGHTER_INCLUDED'))  // Make sure it is only included once. 
{ 
define('JASS_HIGHLIGHTER_INCLUDED', true); 

function FixWord($word) { 
  $Blocks =  
   " constant native function takes returns endfunction if then else elseif endif loop endloop exitwhen ( ) [ ] "; 
    
  $Keywords =  
   " call set local return not and or "; 

  $Values =  
   " true false null "; 

  $Types =  
   " nothing array string integer real code boolean handle event player widget unit destructable item ability buff ". 
   "force group trigger triggercondition triggeraction timer location region rect boolexpr sound conditionfunc filterfunc ". 
   "unitpool itempool race alliancetype racepreference gamestate igamestate fgamestate playerstate playergameresult ". 
   "unitstate aidifficulty eventid gameevent playerevent playerunitevent unitevent limitop widgetevent dialogevent ". 
   "unittype gamespeed gamedifficulty gametype mapflag mapvisibility mapsetting mapdensity mapcontrol playerslotstate ". 
   "volumegroup camerafield camerasetup playercolor placement startlocprio raritycontrol blendmode texmapflags effect ". 
   "effecttype weathereffect terraindeformation fogstate fogmodifier dialog button quest questitem defeatcondition timerdialog ". 
   "leaderboard multiboard multiboarditem trackable gamecache version itemtype texttag playerscore lightning pathingtype image ubersplat ". 
   "attacktype damagetype weapontype soundtype "; 
    
  if (strpos($Blocks, " ".$word." ")!== false) { 
    return "<b>".$word."</b>"; 
  }  
  elseif (strpos($Keywords, " ".$word." ")!== false) { 
    return "<span style=\"color: Navy;\">".$word."</span>"; 
  } 
  elseif (strpos($Values, " ".$word." ")!== false) { 
    return "<span style=\"color: Maroon;\">".$word."</span>"; 
  } 
  elseif (strpos($Types, " ".$word." ")!== false) { 
    return "<span style=\"color: rgb(50, 100, 200);\">".$word."</span>"; 
  } 
  return $word; 
} 

function HighlightJass($text, $bb=false) {  
  $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; 
  $special = "[]()"; 
  $str = "\"'"; 
  $trans = Array(">" => "&gt;", "<" => "&lt;", "&" => "&amp;"); 
  if (!$bb) 
  { 
      $text = strtr($text, $trans); 
  } 
  else 
  { 
      // Do some backwards working 
    $tr = array('(' => '(', 
                ')' => ')', 
                '[' => '[', 
                ']' => ']', 
                '&quot;' => '"'); 
    $text = strtr($text,$tr); 
  } 
   
  $result = ""; 
  $comment = 0; 
  $Lines = explode("\n", $text); 
  $anchors = array(); 
  $n = 0; 
  // First, find all functions and place an anchor there 
  foreach($Lines as $Line)  
  { 
      // Leave anchor here? 
    $reg = array(); 
    $anchors[$n] = ''; 
      if (ereg('^ *(constant )? *(function|native)  *([a-zA-Z_][a-zA-Z_0-9]*)  *takes', $Line, $reg)) 
    { 
        $l = max(0, $n-12); 
        $anchors[$l] .= '<a name="'.strtolower($reg[3]).'"></a>'; 
    } 
    $n++; 
  } 
  $n = 0; 
  foreach($Lines as $Line)  
  { 
    $result .= $anchors[$n]; 
    $Line = rtrim($Line); 
    if ($isString) { 
      $result = $result . "</span>"; 
    } 
    $stop = strpos($Line, "//"); 
    if ($stop === false) { 
      $stop = strlen($Line); 
      $comment = 0; 
    } else { 
      $comment = 1; 
    } 
    $i = 0; 
    $word = ""; 
    $isString = 0; 
    $stringStarter = "";     
    $slashed = 0; 
    // Highlight 
    while ($i < $stop) { 
      $c = substr($Line, $i, 1); 
      $i += 1; 
       
      if ($isString) { 
        $result = $result . $c; 
        if ($c == "\\") { 
          $slashed = ($slashed)? 0:1; 
        } elseif (($c == $stringStarter) && !($slashed)) { 
          $result = $result . "</span>"; 
          $isString = 0; 
        } else { 
          $slashed = 0; 
        } 
      } else { 
        // If normal character 
        if (strpos($chars, $c) !== false) { 
          $word = $word . $c; 
         
        // If bracket 
        } elseif (strpos($special, $c) !== false) { 
          $result = $result . FixWord($word) . FixWord($c); 
            $word = ""; 
         
        // If string 
        } elseif (strpos($str, $c) !== false) {  
          $result = $result . FixWord($word) . "<span style=\"color: blue\">" . $c; 
          $slashed = 0; 
          $word = ""; 
          $isString = 1; 
          $stringStarter = $c; 
         
        // If other character 
        } else { 
          $result = $result . FixWord($word) . $c; 
          $word = ""; 
        } 
         
      } // if ($isString) 
    } 
    $result = $result . FixWord($word); 
     
    // Add comment 
    if ($comment) { 
      $result = $result . "<span style=\"color: green;\">".strstr($Line, "//")."</span>"; 
    } 
    // Add linebreak 
    $result = $result . '<br />'; 
    $n++; 
  } 
  $result = substr($result, 0, strlen($result)-1); // Remove last linebreak 
   
  if ($bb) 
  { 
      $tr = array('(' => '(', 
                ')' => ')', 
                '[' => '[', 
                ']' => ']'); 
    $result = strtr($result, $tr); 
  } 
   
  return $result; 
} 

} 
HighlightJass({param});
?>

also i know vbulletin has highlighing because of the php tags and also thehelper.net is vbulletin.


EDIT : isnt the replacement box where u put the code..? if not where do i put it. ( wow i sound like a fucking retard )


Replacement:
This is the HTML code for the BB code replacement. Make sure that you include '{param}' (without the quotes) to insert the text between the opening and closing BB code tags, and '{option}' for the parameter within the BB code tag. You can only use {option} if 'Use Option' is set to yes.
e.g. you would use <b>{param}</b> for tags, <a href="{option}">{param}</a> for . You will always use '{param}', but you will only use '{option}' when "Use Option?" is "yes."
 

TFlan

I could change this in my User CP.
Reaction score
64
-.-'

Stupid pre-made forums... make your own, easier to work with...

---------

On topic:

When i said add the script. I meant go to the php page in your directory associated with BBcodes (idk if this is the path, but IE: /vbulletin/scripts/bbcode/script.php <-- for example, you will have to do some fishing to find the page), find the HTML one. and paste the Jass one under it. I'm assuming here that all the BBcodes are on the same page and loaded and run simultaneously.

For the replace textarea, what did you put in it? Did you add the PHP tags?
 

TFlan

I could change this in my User CP.
Reaction score
64
Instead, you need a vb "product" (a type of plugin).

Here's the one we had here, a long long time ago:

I love you for posting this.

Was about to download the forum and add the script in myself and send it to Trigger...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> does that mean it's not as updated?

Well, I'm not sure all vJASS keywords are actually there...
Though, it's easy enough to add them.


But, yes...

The original KaTTana script was never used here.
I mean... look at that thing? What an insane coding.
Well, it probably works just fine, but I didn't like it just from the looks and style.

Instead, it has seen some replacements.
The limitation would be that it doesn't highlight strings.


However, since then, we moved on to "industrial strength" (famous last words).

Still, after all, this was in production here for at least a year or so.
It's tried and tested :p
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Mind posting the current version and a quick "how to implement", Ace?
Would help me a lot :)

(Currently, I have to post my JASS in simple code tags on another forum...)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top