author | Dan Fuhry <dan@enanocms.org> |
Sun, 18 Sep 2011 02:13:34 -0400 | |
changeset 1354 | eecde44145eb |
parent 1290 | 27ab1b13a783 |
child 1382 | 78fbedb876f3 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents:
801
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Dan Fuhry |
1290
27ab1b13a783
Javascript maintenance. Upgraded jQuery; fixed some gzip bugs; added JavascriptCompressor usage to licenses/.
Dan Fuhry <dan@enanocms.org>
parents:
1227
diff
changeset
|
6 |
* Javascript compression library - used to compact the client-side Javascript code to save some bandwidth |
1 | 7 |
* |
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
* |
|
14 |
* This class was written by Andrea Giammarchi and was downloaded from PHPClasses.org. The information page stated that |
|
15 |
* this class is licensed under the GNU General Public License, the terms of which can be found by reading the file |
|
16 |
* "GPL" included with the Enano package. |
|
17 |
*/ |
|
18 |
||
19 |
/** |
|
20 |
* JavaScriptCompressor class, |
|
21 |
* removes comments or pack JavaScript source[s] code. |
|
22 |
* ______________________________________________________________ |
|
23 |
* JavaScriptCompressor (just 2 public methods) |
|
24 |
* | |
|
25 |
* |________ getClean(jsSource:mixed):string |
|
26 |
* | returns one or more JavaScript code without comments, |
|
27 |
* | by default removes some spaces too |
|
28 |
* | |
|
29 |
* |________ getPacked(jsSource:mixed):string |
|
30 |
* returns one or more JavaScript code packed, |
|
31 |
* using getClean and obfuscating output |
|
32 |
* -------------------------------------------------------------- |
|
33 |
* Note about $jsSource input varible: |
|
34 |
* this var should be a string (i.e. $jsSource = file_get_contents("myFile.js");) |
|
35 |
* should be an array of strings (i.e. array(file_get_contents("1.js"), file_get_contents("2.js"), ... )) |
|
36 |
* should be an array with 1 or 2 keys: |
|
37 |
* (i.e. array('code'=>file_get_contents("mySource.js"))) |
|
38 |
* (i.e. array('code'=>file_get_contents("mySource.js"), 'name'=>'mySource')) |
|
39 |
* ... and should be an array of arrays created with theese rules |
|
40 |
* array( |
|
41 |
* file_get_contents("secret.js"), |
|
42 |
* array('code'=>$anotherJS), |
|
43 |
* array('code'=>$myJSapplication, 'name'=>'JSApplication V 1.0') |
|
44 |
* ) |
|
45 |
* |
|
46 |
* The name used on dedicated key, will be write on parsed source header |
|
47 |
* -------------------------------------------------------------- |
|
48 |
* Note about returned strings: |
|
49 |
* Your browser should wrap very long strings, then don't use |
|
50 |
* cut and paste from your browser, save output into your database or directly |
|
51 |
* in a file or print them only inside <script> and </script> tags |
|
52 |
* -------------------------------------------------------------- |
|
53 |
* Note about parser performance: |
|
54 |
* With pure PHP embed code this class should be slow and not really safe |
|
55 |
* for your server performance then don't parse JavaScript runtime for each |
|
56 |
* file you need and create some "parsed" caching system |
|
57 |
* (at least while i've not created a compiled version of theese class functions). |
|
58 |
* Here there's a caching system example: http://www.phpclasses.org/browse/package/3158.html |
|
59 |
* -------------------------------------------------------------- |
|
60 |
* Note about JavaScript packed compatibility: |
|
61 |
* To be sure about compatibility include before every script JSL Library: |
|
62 |
* http://www.devpro.it/JSL/ |
|
63 |
* JSL library add some features for old or buggy browsers, one of |
|
64 |
* those functions is String.replace with function as second argument, |
|
65 |
* used by JavaScript generated packed code to rebuild original code. |
|
66 |
* |
|
67 |
* Remember that KDE 3.5, Safari and IE5 will not work correctly with packed version |
|
68 |
* if you'll not include JSL. |
|
69 |
* -------------------------------------------------------------- |
|
70 |
* @Compatibility >= PHP 4 |
|
71 |
* @Author Andrea Giammarchi |
|
72 |
* @see http://www.devpro.it/ |
|
73 |
* @since 2006/05/31 |
|
74 |
* @since 2006/08/01 [requires SourceMap.class.php to parse source faster and better (dojo.js.uncompressed.js file (211Kb) successfull cleaned or packed)] |
|
75 |
* @version 0.8 |
|
76 |
* Dependencies: |
|
77 |
* Server: BaseConvert.class.php |
|
78 |
* Server: SourceMap.class.php |
|
79 |
* Client: JSL.js (http://www.devpro.it/JSL/) |
|
80 |
* Convertion is supported by every browser with JSL Library (FF 1+ Opera 8+ and IE5.5+ are supported without JSL too) |
|
81 |
* @copyright Dean Edwards for his originally idea [dean.edwards.name] and his JavaScript packer |
|
82 |
*/ |
|
83 |
class JavaScriptCompressor { |
|
84 |
||
85 |
/** |
|
86 |
* public variables |
|
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
87 |
* stats:string after every compression has some informations |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
88 |
* version:string version of this class |
1 | 89 |
*/ |
90 |
var $stats = '', |
|
91 |
$version = '0.8'; |
|
92 |
||
93 |
/** 'private' variables, any comment sorry */ |
|
94 |
var $__startTime = 0, |
|
95 |
$__sourceLength = 0, |
|
96 |
$__sourceNewLength = 0, |
|
97 |
$__totalSources = 0, |
|
98 |
$__sources = array(), |
|
99 |
$__delimeter = array(), |
|
100 |
$__cleanFinder = array("/(\n|\r)+/", "/( |\t)+/", "/(\n )|( \n)|( \n )/", "/[[:space:]]+(\)|})/", "/(\(|{)[[:space:]]+/", "/[[:space:]]*(;|,|:|<|>|\&|\||\=|\?|\+|\-|\%)[[:space:]]*/", "/\)[[:space:]]+{/", "/}[[:space:]]+\(/"), |
|
101 |
$__cleanReplacer = array("\n", " ", "\n", "\\1", "\\1", "\\1", "){", "}("), |
|
102 |
$__BC = null, |
|
103 |
$__SourceMap = null; |
|
104 |
||
105 |
/** |
|
106 |
* public constructor |
|
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
107 |
* creates a new BaseConvert class variable (base 36) |
1 | 108 |
*/ |
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
109 |
function __construct() { |
1 | 110 |
$this->__SourceMap = new SourceMap(); |
111 |
$this->__BC = new BaseConvert('0123456789abcdefghijklmnopqrstuvwxyz'); |
|
112 |
$this->__delimeter = array( |
|
113 |
array('name'=>'doublequote', 'start'=>'"', 'end'=>'"', 'noslash'=>true), |
|
114 |
array('name'=>'singlequote', 'start'=>"'", 'end'=>"'", 'noslash'=>true), |
|
115 |
array('name'=>'singlelinecomment', 'start'=>'//', 'end'=>array("\n", "\r")), |
|
116 |
array('name'=>'multilinecomment', 'start'=>'/*', 'end'=>'*/'), |
|
117 |
array('name'=>'regexp', 'start'=>'/', 'end'=>'/', 'match'=>"/^\/[^\n\r]+\/$/", 'noslash'=>true) |
|
118 |
); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* public method |
|
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
123 |
* getClean(mixed [, bool]):string |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
124 |
* compress JavaScript removing comments and somespaces (on by default) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
125 |
* @param mixed view example and notes on class comments |
1 | 126 |
*/ |
127 |
function getClean($jsSource) { |
|
128 |
return $this->__commonInitMethods($jsSource, false); |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* public method |
|
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
133 |
* getPacked(mixed):string |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
134 |
* compress JavaScript replaceing words and removing comments and some spaces |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
135 |
* @param mixed view example and notes on class comments |
1 | 136 |
*/ |
137 |
function getPacked($jsSource) { |
|
138 |
return $this->__commonInitMethods($jsSource, true); |
|
139 |
} |
|
140 |
||
141 |
/** 'private' methods, any comment sorry */ |
|
142 |
function __addCleanCode($str) { |
|
143 |
return preg_replace($this->__cleanFinder, $this->__cleanReplacer, trim($str)); |
|
144 |
} |
|
145 |
function __addClean(&$arr, &$str, &$start, &$end, $clean) { |
|
146 |
if($clean) |
|
147 |
array_push($arr, $this->__addCleanCode(substr($str, $start, $end - $start))); |
|
148 |
else |
|
149 |
array_push($arr, substr($str, $start, $end - $start)); |
|
150 |
} |
|
151 |
function __clean(&$str) { |
|
152 |
$len = strlen($str); |
|
153 |
$type = ''; |
|
154 |
$clean = array(); |
|
155 |
$map = $this->__SourceMap->getMap($str, $this->__delimeter); |
|
156 |
for($a = 0, $b = 0, $c = count($map); $a < $c; $a++) { |
|
157 |
$type = &$map[$a]['name']; |
|
158 |
switch($type) { |
|
159 |
case 'code': |
|
160 |
case 'regexp': |
|
161 |
case 'doublequote': |
|
162 |
case 'singlequote': |
|
163 |
$this->__addClean($clean, $str, $map[$a]['start'], $map[$a]['end'], ($type === 'code')); |
|
164 |
if($type !== 'regexp') |
|
165 |
array_push($clean, "\n"); |
|
166 |
break; |
|
167 |
} |
|
168 |
} |
|
169 |
return preg_replace("/(\n)+/", "\n", trim(implode('', $clean))); |
|
170 |
} |
|
171 |
function __commonInitMethods(&$jsSource, $packed) { |
|
172 |
$header = ''; |
|
173 |
$this->__startTime = $this->__getTime(); |
|
174 |
$this->__sourceLength = 0; |
|
175 |
$this->__sourceManager($jsSource); |
|
176 |
for($a = 0, $b = $this->__totalSources; $a < $b; $a++) |
|
177 |
$this->__sources[$a]['code'] = $this->__clean($this->__sources[$a]['code']); |
|
178 |
$header = $this->__getHeader(); |
|
179 |
for($a = 0, $b = $this->__totalSources; $a < $b; $a++) |
|
180 |
$this->__sources[$a] = &$this->__sources[$a]['code']; |
|
181 |
$this->__sources = implode(';', $this->__sources); |
|
182 |
if($packed) |
|
183 |
$this->__sources = $this->__pack($this->__sources); |
|
184 |
$this->__sourceNewLength = strlen($this->__sources); |
|
185 |
$this->__setStats(); |
|
186 |
return $header.$this->__sources; |
|
187 |
} |
|
188 |
function __getHeader() { |
|
189 |
return implode('', array( |
|
190 |
'/* ',$this->__getScriptNames(),'JavaScriptCompressor ',$this->version,' [www.devpro.it], ', |
|
191 |
'thanks to Dean Edwards for idea [dean.edwards.name]', |
|
192 |
" */\r\n" |
|
193 |
)); |
|
194 |
} |
|
195 |
function __getScriptNames() { |
|
196 |
$a = 0; |
|
197 |
$result = array(); |
|
198 |
for($b = $this->__totalSources; $a < $b; $a++) { |
|
199 |
if($this->__sources[$a]['name'] !== '') |
|
200 |
array_push($result, $this->__sources[$a]['name']); |
|
201 |
} |
|
202 |
$a = count($result); |
|
203 |
if($a-- > 0) |
|
204 |
$result[$a] .= ' with '; |
|
205 |
return $a < 0 ? '' : implode(', ', $result); |
|
206 |
} |
|
207 |
function __getSize($size, $dec = 2) { |
|
208 |
$toEval = ''; |
|
209 |
$type = array('bytes', 'Kb', 'Mb', 'Gb'); |
|
210 |
$nsize = $size; |
|
211 |
$times = 0; |
|
212 |
while($nsize > 1024) { |
|
213 |
$nsize = $nsize / 1024; |
|
214 |
$toEval .= '/1024'; |
|
215 |
$times++; |
|
216 |
} |
|
217 |
if($times === 0) |
|
218 |
$fSize = $size.' '.$type[$times]; |
|
219 |
else { |
|
220 |
eval('$size=($size'.$toEval.');'); |
|
221 |
$fSize = number_format($size, $dec, '.', '').' '.$type[$times]; |
|
222 |
} |
|
223 |
return $fSize; |
|
224 |
} |
|
225 |
function __getTime($startTime = null) { |
|
226 |
list($usec, $sec) = explode(' ', microtime()); |
|
227 |
$newtime = (float)$usec + (float)$sec; |
|
228 |
if($startTime !== null) |
|
229 |
$newtime = number_format(($newtime - $startTime), 3); |
|
230 |
return $newtime; |
|
231 |
} |
|
232 |
function __pack(&$str) { |
|
233 |
$container = array(); |
|
234 |
$str = preg_replace("/(\w+)/e", '$this->__BC->toBase($this->__wordsParser("\\1",$container));', $this->__clean($str)); |
|
235 |
$str = str_replace("\n", '\n', addslashes($str)); |
|
236 |
return 'eval(function(A,G){return A.replace(/(\\w+)/g,function(a,b){return G[parseInt(b,36)]})}("'.$str.'","'.implode(',', $container).'".split(",")));'; |
|
237 |
} |
|
238 |
function __setStats() { |
|
239 |
$this->stats = implode(' ', array( |
|
240 |
$this->__getSize($this->__sourceLength), |
|
241 |
'to', |
|
242 |
$this->__getSize($this->__sourceNewLength), |
|
243 |
'in', |
|
244 |
$this->__getTime($this->__startTime), |
|
245 |
'seconds' |
|
246 |
)); |
|
247 |
} |
|
248 |
function __sourceManager(&$jsSource) { |
|
249 |
$b = count($jsSource); |
|
250 |
$this->__sources = array(); |
|
251 |
if(is_string($jsSource)) |
|
252 |
$this->__sourcePusher($jsSource, ''); |
|
253 |
elseif(is_array($jsSource) && $b > 0) { |
|
254 |
if(isset($jsSource['code'])) |
|
255 |
$this->__sourcePusher($jsSource['code'], (isset($jsSource['name']) ? $jsSource['name'] : '')); |
|
256 |
else { |
|
257 |
for($a = 0; $a < $b; $a++) { |
|
258 |
if(is_array($jsSource[$a]) && isset($jsSource[$a]['code'], $jsSource[$a]['name'])) |
|
259 |
$this->__sourcePusher($jsSource[$a]['code'], trim($jsSource[$a]['name'])); |
|
260 |
elseif(is_string($jsSource[$a])) |
|
261 |
$this->__sourcePusher($jsSource[$a], ''); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
$this->__totalSources = count($this->__sources); |
|
266 |
} |
|
267 |
function __sourcePusher(&$code, $name) { |
|
268 |
$this->__sourceLength += strlen($code); |
|
269 |
array_push($this->__sources, array('code'=>$code, 'name'=>$name)); |
|
270 |
} |
|
271 |
function __wordsParser($str, &$d) { |
|
798
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
685
diff
changeset
|
272 |
if(@is_null($key = array_shift($key = array_keys($d,$str)))) |
1 | 273 |
$key = array_push($d, $str) - 1; |
274 |
return $key; |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* BaseConvert class, |
|
280 |
* converts an unsigned base 10 integer to a different base and vice versa. |
|
281 |
* ______________________________________________________________ |
|
282 |
* BaseConvert |
|
283 |
* | |
|
284 |
* |________ constructor(newBase:string) |
|
285 |
* | uses newBase string var for convertion |
|
286 |
* | [i.e. "0123456789abcdef" for an hex convertion] |
|
287 |
* | |
|
288 |
* |________ toBase(unsignedInteger:uint):string |
|
289 |
* | return base value of input |
|
290 |
* | |
|
291 |
* |________ fromBase(baseString:string):uint |
|
292 |
* return base 10 integer value of base input |
|
293 |
* -------------------------------------------------------------- |
|
294 |
* REMEMBER: PHP < 6 doesn't work correctly with integer greater than 2147483647 (2^31 - 1) |
|
295 |
* -------------------------------------------------------------- |
|
296 |
* @Compatibility >= PHP 4 |
|
297 |
* @Author Andrea Giammarchi |
|
298 |
* @Site http://www.devpro.it/ |
|
299 |
* @Date 2006/06/05 |
|
300 |
* @Version 1.0 |
|
301 |
*/ |
|
302 |
||
303 |
class BaseConvert { |
|
304 |
||
305 |
var $base, $baseLength; |
|
306 |
||
307 |
function BaseConvert($base) { |
|
308 |
$this->base = &$base; |
|
309 |
$this->baseLength = strlen($base); |
|
310 |
} |
|
311 |
||
312 |
function toBase($num) { |
|
313 |
$module = 0; $result = ''; |
|
314 |
while($num) { |
|
315 |
$result = $this->base{($module = $num % $this->baseLength)}.$result; |
|
316 |
$num = (int)(($num - $module) / $this->baseLength); |
|
317 |
} |
|
318 |
return $result !== '' ? $result : $this->base{0}; |
|
319 |
} |
|
320 |
||
321 |
function fromBase($str) { |
|
322 |
$pos = 0; $len = strlen($str) - 1; $result = 0; |
|
323 |
while($pos < $len) |
|
324 |
$result += pow($this->baseLength, ($len - $pos)) * strpos($this->base, $str{($pos++)}); |
|
325 |
return $len >= 0 ? $result + strpos($this->base, $str{($pos)}) : null; |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
/** |
|
330 |
* SourceMap class, |
|
331 |
* reads a generic language source code and returns its map. |
|
332 |
* ______________________________________________________________ |
|
333 |
* The SourceMap goals is to create a map of a generic script/program language. |
|
334 |
* The getMap method returns an array/list of arrays/dictionary/objects |
|
335 |
* of source map using delimeters variable to map correctly: |
|
336 |
* - multi line comments |
|
337 |
* - single line comments |
|
338 |
* - double quoted strings |
|
339 |
* - single quoted strings |
|
340 |
* - pure code |
|
341 |
* - everything else (for example regexp [/re/] with javascript), just adding a correct delimeter |
|
342 |
* -------------------------------------------------------------- |
|
343 |
* What about the delimeter |
|
344 |
* It's an array/list of arrays/dictionary/obects with some properties to find what you're looking for. |
|
345 |
* |
|
346 |
* parameters are: |
|
347 |
* - name, the name of the delimeter (i.e. "doublequote") |
|
348 |
* - start, one or mode chars to find as start delimeter (i.e. " for double quoted string) |
|
349 |
* - end, one or mode chars to find as end delimeter (i.e. " for double quoted string) [end should be an array/list too] |
|
350 |
* |
|
351 |
* optional parameters are: |
|
352 |
* - noslash, if true find the end of the delimeter only if last char is not slashed (i.e. "string\"test" find " after test) |
|
353 |
* - match, if choosed language has regexp, verify if string from start to end matches used regexp (i.e. /^\/[^\n\r]+\/$/ for JavaScript regexp) |
|
354 |
* |
|
355 |
* If end parameter is an array, match and noslash are not supported (i.e. ["\n", "\r"] for end delimeter of a single line comment) |
|
356 |
* -------------------------------------------------------------- |
|
357 |
* What about SourceMap usage |
|
358 |
* It should be a good solution to create sintax highlighter, parser, |
|
359 |
* verifier or some other source code parsing procedure |
|
360 |
* -------------------------------------------------------------- |
|
361 |
* What about SourceMap performance script/languages |
|
362 |
* I've created different version of this class to test each script/program language performance too. |
|
363 |
* Python with or without Psyco is actually the faster parser. |
|
364 |
* However with this PHP version this class has mapped "dojo.js.uncompressed.js" file (about 211Kb) in less than 0.5 second. |
|
365 |
* Test has been done with embed class and PHP as module, any accelerator was used for this PHP test. |
|
366 |
* -------------------------------------------------------------- |
|
367 |
* @Compatibility >= PHP 4 |
|
368 |
* @Author Andrea Giammarchi |
|
369 |
* @Site http://www.devpro.it/ |
|
370 |
* @Date 2006/08/01 |
|
371 |
* @LastMOd 2006/08/01 |
|
372 |
* @Version 0.1 |
|
373 |
* @Application Last version of JavaScriptCompressor class use this one to map source code. |
|
374 |
*/ |
|
375 |
class SourceMap { |
|
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
376 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
377 |
/** |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
378 |
* public method |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
379 |
* getMap(&$source:string, &$delimeters:array):array |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
380 |
* Maps the source code using $delimeters rules and returns map as an array |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
381 |
* NOTE: read comments to know more about map and delimeter |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
382 |
* |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
383 |
* @param string generic source code |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
384 |
* @param array array with nested array with code rules |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
385 |
*/ |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
386 |
function getMap(&$source, &$delimeters) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
387 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
388 |
# "unsigned" integer variables |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
389 |
$sourcePosition = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
390 |
$delimetersPosition = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
391 |
$findLength = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
392 |
$len = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
393 |
$tempIndex = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
394 |
$sourceLength = strlen($source); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
395 |
$delimetersLength = count($delimeters); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
396 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
397 |
# integer variables |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
398 |
$tempPosition = -1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
399 |
$endPosition = -1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
400 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
401 |
# array variables |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
402 |
$map = array(); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
403 |
$tempMap = array(); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
404 |
$tempDelimeter = array(); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
405 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
406 |
while($sourcePosition < $sourceLength) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
407 |
$endPosition = -1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
408 |
for($delimetersPosition = 0; $delimetersPosition < $delimetersLength; $delimetersPosition++) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
409 |
$tempPosition = strpos($source, $delimeters[$delimetersPosition]['start'], $sourcePosition); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
410 |
if($tempPosition !== false && ($tempPosition < $endPosition || $endPosition === -1)) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
411 |
$endPosition = $tempPosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
412 |
$tempIndex = $delimetersPosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
413 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
414 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
415 |
if($endPosition !== -1) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
416 |
$sourcePosition = $endPosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
417 |
$tempDelimeter = &$delimeters[$tempIndex]; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
418 |
$findLength = strlen($tempDelimeter['start']); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
419 |
if(is_array($tempDelimeter['end'])) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
420 |
$delimetersPosition = 0; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
421 |
$endPosition = -1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
422 |
for($len = count($tempDelimeter['end']); $delimetersPosition < $len; $delimetersPosition++) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
423 |
$tempPosition = strpos($source, $tempDelimeter['end'][$delimetersPosition], $sourcePosition + $findLength); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
424 |
if($tempPosition !== false && ($tempPosition < $endPosition || $endPosition === -1)) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
425 |
$endPosition = $tempPosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
426 |
$tempIndex = $delimetersPosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
427 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
428 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
429 |
if($endPosition !== -1) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
430 |
$endPosition = $endPosition + strlen($tempDelimeter['end'][$tempIndex]); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
431 |
else |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
432 |
$endPosition = $sourceLength; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
433 |
array_push($map, array('name'=>$tempDelimeter['name'], 'start'=>$sourcePosition, 'end'=>$endPosition)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
434 |
$sourcePosition = $endPosition - 1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
435 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
436 |
elseif(isset($tempDelimeter['match'])) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
437 |
$tempPosition = strpos($source, $tempDelimeter['end'], $sourcePosition + $findLength); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
438 |
$len = strlen($tempDelimeter['end']); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
439 |
if($tempPosition !== false && preg_match($tempDelimeter['match'], substr($source, $sourcePosition, $tempPosition - $sourcePosition + $len))) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
440 |
$endPosition = isset($tempDelimeter['noslash']) ? $this->__endCharNoSlash($source, $sourcePosition, $tempDelimeter['end'], $sourceLength) : $tempPosition + $len; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
441 |
array_push($map, array('name'=>$tempDelimeter['name'], 'start'=>$sourcePosition, 'end'=>$endPosition)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
442 |
$sourcePosition = $endPosition - 1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
443 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
444 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
445 |
else { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
446 |
if(isset($tempDelimeter['noslash'])) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
447 |
$endPosition = $this->__endCharNoSlash($source, $sourcePosition, $tempDelimeter['end'], $sourceLength); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
448 |
else { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
449 |
$tempPosition = strpos($source, $tempDelimeter['end'], $sourcePosition + $findLength); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
450 |
if($tempPosition !== false) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
451 |
$endPosition = $tempPosition + strlen($tempDelimeter['end']); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
452 |
else |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
453 |
$endPosition = $sourceLength; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
454 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
455 |
array_push($map, array('name'=>$tempDelimeter['name'], 'start'=>$sourcePosition, 'end'=>$endPosition)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
456 |
$sourcePosition = $endPosition - 1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
457 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
458 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
459 |
else |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
460 |
$sourcePosition = $sourceLength - 1; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
461 |
++$sourcePosition; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
462 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
463 |
$len = count($map); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
464 |
if($len === 0) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
465 |
array_push($tempMap, array('name'=>'code', 'start'=>0, 'end'=>$sourceLength)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
466 |
else { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
467 |
for($tempIndex = 0; $tempIndex < $len; $tempIndex++) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
468 |
if($tempIndex === 0 && $map[$tempIndex]['start'] > 0) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
469 |
array_push($tempMap, array('name'=>'code', 'start'=>0, 'end'=>$map[$tempIndex]['start'])); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
470 |
elseif($tempIndex > 0 && $map[$tempIndex]['start'] > $map[$tempIndex-1]['end']) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
471 |
array_push($tempMap, array('name'=>'code', 'start'=>$map[$tempIndex-1]['end'], 'end'=>$map[$tempIndex]['start'])); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
472 |
array_push($tempMap, array('name'=>$map[$tempIndex]['name'], 'start'=>$map[$tempIndex]['start'], 'end'=>$map[$tempIndex]['end'])); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
473 |
if($tempIndex + 1 === $len && $map[$tempIndex]['end'] < $sourceLength) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
474 |
array_push($tempMap, array('name'=>'code', 'start'=>$map[$tempIndex]['end'], 'end'=>$sourceLength)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
475 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
476 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
477 |
return $tempMap; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
478 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
479 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
480 |
function __endCharNoSlash(&$source, $position, &$find, &$len) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
481 |
$temp = strlen($find); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
482 |
do { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
483 |
$position = strpos($source, $find, $position + 1); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
484 |
}while($position !== false && !$this->__charNoSlash($source, $position)); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
485 |
if($position === false) $position = $len - $temp; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
486 |
return $position + $temp; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
487 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
488 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
489 |
function __charNoSlash(&$source, &$position) { |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
490 |
$next = 1; $len = $position - $next; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
491 |
while($len > 0 && $source{$len} === '\\') $len = $position - (++$next); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
492 |
return (($next - 1) % 2 === 0); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
493 |
} |
1 | 494 |
} |
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
495 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
496 |
/** |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
497 |
* Wrapper for the JavaScriptCompressor class. |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
498 |
* @param string Javascript code to compact. If this doesn't contain any newline characters, will be treated as a filename. |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
499 |
* @param bool If true, aggressively compresses the code. Otherwise, just strips comments and some whitespace. |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
500 |
* @return string Compressed JS |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
501 |
*/ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
502 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
503 |
function perform_js_compress($text_or_file, $aggressive = false) |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
504 |
{ |
1227
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
505 |
static $compressor = false; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
506 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
507 |
if ( !is_object($compressor) ) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
508 |
$compressor = new JavaScriptCompressor(); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
509 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
510 |
if ( strpos($text_or_file, "\n") ) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
511 |
{ |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
512 |
$text =& $text_or_file; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
513 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
514 |
else if ( file_exists($text_or_file) ) |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
515 |
{ |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
516 |
$text = file_get_contents($text_or_file); |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
517 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
518 |
else |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
519 |
{ |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
520 |
$text =& $text_or_file; |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
521 |
} |
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
522 |
|
bdac73ed481e
Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents:
1081
diff
changeset
|
523 |
return ( $aggressive ) ? $compressor->getPacked($text) : $compressor->getClean($text); |
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
524 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
411
diff
changeset
|
525 |
|
1 | 526 |
?> |