3 * Template Lite plugin converted from Smarty
4 * -------------------------------------------------------------
5 * File: prefilter.jstrip.php
10 * Purpose: dummy compiler to compress javascript
11 * Install: Drop into the plugin directory,
12 * call load_filter('pre','jstrip');
13 * from your application.
14 * -------------------------------------------------------------
17 function template_prefilter_jstrip($tpl_source, &$template_object)
19 return preg_replace_callback("/\{jstrip\}(.*?)\{\/jstrip\}/s","template_prefilter_jstrip_cb", $tpl_source);
22 function template_prefilter_jstrip_one($code)
24 return template_prefilter_jstrip_cb(array("", $code), false);
27 function template_prefilter_jstrip_cb($m, $literal=true)
30 $o=""; //stripped output
31 $comment=0; //comments
32 $string=""; //current string delimiter
33 $last=""; //last char in the output
34 for ($i=0;$i<strlen($c);$i++
)
37 //print_v(array($i,$string,$comment));
39 $s=true; //save the character ?
40 //if we're in a string or phpcode
44 if ($c[$i]==$string OR substr($c,$i,2)==$string)
53 if (substr($c,$i,2)=="//")
58 if (substr($c,$i,2)=="/*")
63 if ($comment==1 AND $c[$i]=="\n")
68 if ($comment==2 AND substr($c,$i-1,2)=="*/")
77 if ($c[$i]=="'" OR $c[$i]=='"')
83 if (substr($c,$i,2)=="<"."?")
89 if ($c[$i]=="\n" OR $c[$i]=="\r")
91 //is the current line finished ?
92 // ")" and "}" is not OK ! (var x=function a() {}.......var )
93 $finishers=array(";","{","(",",","\n",":");
94 if (in_array($last,$finishers))
100 //a space ! can we cut it ?
101 if ($c[$i]==" " OR $c[$i]=="\t")
103 $cutme=array(" ","\t","}","{",")","(","[","]","<",">","=",";","+","-","/","*","\n",":","&");
104 if (in_array($c[$i-1],$cutme) OR in_array($c[$i+
1],$cutme))
109 //todo : rename vars/functions !!
113 if ($s AND $comment==0)
122 return "{literal}".$o."{/literal}";