Completed
Push — master ( 751bec...101b9a )
by David
11s
created
lib/Dwoo/Compiler.php 5 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     /**
278 278
      * Returns the left and right template delimiters.
279 279
      *
280
-     * @return array containing the left and the right delimiters
280
+     * @return string[] containing the left and the right delimiters
281 281
      */
282 282
     public function getDelimiters()
283 283
     {
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * Adds a preprocessor to the compiler, it will be called
363 363
      * before the template is compiled.
364 364
      *
365
-     * @param mixed $callback either a valid callback to the preprocessor or a simple name if the autoload is set to
365
+     * @param string $callback either a valid callback to the preprocessor or a simple name if the autoload is set to
366 366
      *                        true
367 367
      * @param bool  $autoload if set to true, the preprocessor is auto-loaded from one of the plugin directories, else
368 368
      *                        you must provide a valid callback
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
      *
1322 1322
      * @param array $params parameter array
1323 1323
      *
1324
-     * @return array tokens
1324
+     * @return Compiler tokens
1325 1325
      */
1326 1326
     public function getParamTokens(array $params)
1327 1327
     {
Please login to merge, or discard this patch.
Switch Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -769,13 +769,13 @@  discard block
 block discarded – undo
769 769
                         $search = array('{<\?.*?\?>}', '{<%.*?%>}');
770 770
                     }
771 771
                     switch ($this->securityPolicy->getPhpHandling()) {
772
-                        case SecurityPolicy::PHP_ALLOW:
773
-                            break;
774
-                        case SecurityPolicy::PHP_ENCODE:
775
-                            $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
776
-                            break;
777
-                        case SecurityPolicy::PHP_REMOVE:
778
-                            $tpl = preg_replace($search, '', $tpl);
772
+                    case SecurityPolicy::PHP_ALLOW:
773
+                        break;
774
+                    case SecurityPolicy::PHP_ENCODE:
775
+                        $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
776
+                        break;
777
+                    case SecurityPolicy::PHP_REMOVE:
778
+                        $tpl = preg_replace($search, '', $tpl);
779 779
                     }
780 780
                 }
781 781
             }
@@ -875,51 +875,51 @@  discard block
 block discarded – undo
875 875
             }
876 876
 
877 877
             switch ($type) {
878
-                case Core::CLASS_PLUGIN:
879
-                case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
880
-                    if (class_exists('Plugin' . $plugin) !== false) {
881
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
882
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
883
-                    } else {
884
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
885
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
886
-                    }
887
-                    break;
888
-                case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
889
-                    if (class_exists('Plugin' . $plugin) !== false) {
890
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
891
-                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
892
-                    } else {
893
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
894
-                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
895
-                    }
896
-                    break;
897
-                case Core::FUNC_PLUGIN:
898
-                    if (function_exists('Plugin' . $plugin) !== false) {
899
-                        $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
878
+            case Core::CLASS_PLUGIN:
879
+            case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
880
+                if (class_exists('Plugin' . $plugin) !== false) {
881
+                    $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
882
+                    "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
883
+                } else {
884
+                    $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
885
+                    "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
886
+                }
887
+                break;
888
+            case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
889
+                if (class_exists('Plugin' . $plugin) !== false) {
890
+                    $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
900 891
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
901
-                    } else {
902
-                        $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
892
+                } else {
893
+                    $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
903 894
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
904
-                    }
905
-                    break;
906
-                case Core::SMARTY_MODIFIER:
907
-                    $output .= "if (function_exists('smarty_modifier_$plugin')===false)".
908
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
909
-                    break;
910
-                case Core::SMARTY_FUNCTION:
911
-                    $output .= "if (function_exists('smarty_function_$plugin')===false)".
912
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
913
-                    break;
914
-                case Core::SMARTY_BLOCK:
915
-                    $output .= "if (function_exists('smarty_block_$plugin')===false)".
916
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
917
-                    break;
918
-                case Core::PROXY_PLUGIN:
919
-                    $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
920
-                    break;
921
-                default:
922
-                    throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
895
+                }
896
+                break;
897
+            case Core::FUNC_PLUGIN:
898
+                if (function_exists('Plugin' . $plugin) !== false) {
899
+                    $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
900
+                    "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
901
+                } else {
902
+                    $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
903
+                    "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
904
+                }
905
+                break;
906
+            case Core::SMARTY_MODIFIER:
907
+                $output .= "if (function_exists('smarty_modifier_$plugin')===false)".
908
+                "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
909
+                break;
910
+            case Core::SMARTY_FUNCTION:
911
+                $output .= "if (function_exists('smarty_function_$plugin')===false)".
912
+                "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
913
+                break;
914
+            case Core::SMARTY_BLOCK:
915
+                $output .= "if (function_exists('smarty_block_$plugin')===false)".
916
+                "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
917
+                break;
918
+            case Core::PROXY_PLUGIN:
919
+                $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
920
+                break;
921
+            default:
922
+                throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
923 923
             }
924 924
         }
925 925
 
Please login to merge, or discard this patch.
Spacing   +381 added lines, -383 removed lines patch added patch discarded remove patch
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public function setNestedCommentsHandling($allow = true)
296 296
     {
297
-        $this->allowNestedComments = (bool)$allow;
297
+        $this->allowNestedComments = (bool) $allow;
298 298
     }
299 299
 
300 300
     /**
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      */
320 320
     public function setLooseOpeningHandling($allow = false)
321 321
     {
322
-        $this->allowLooseOpenings = (bool)$allow;
322
+        $this->allowLooseOpenings = (bool) $allow;
323 323
     }
324 324
 
325 325
     /**
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     public function setAutoEscape($enabled)
346 346
     {
347
-        $this->autoEscape = (bool)$enabled;
347
+        $this->autoEscape = (bool) $enabled;
348 348
     }
349 349
 
350 350
     /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     {
372 372
         if ($autoload) {
373 373
             $name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', Core::toCamelCase($callback));
374
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . $name;
374
+            $class = Core::NAMESPACE_PLUGINS_PROCESSORS.$name;
375 375
 
376 376
             if (class_exists($class)) {
377 377
                 $callback = array(new $class($this), 'process');
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
     {
397 397
         if (($index = array_search($callback, $this->processors['pre'], true)) !== false) {
398 398
             unset($this->processors['pre'][$index]);
399
-        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
399
+        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS.str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
400 400
                     $callback),
401 401
                 $this->processors['pre'], true)) !== false) {
402 402
             unset($this->processors['pre'][$index]);
403 403
         } else {
404
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
404
+            $class = Core::NAMESPACE_PLUGINS_PROCESSORS.str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
405 405
             foreach ($this->processors['pre'] as $index => $proc) {
406 406
                 if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
407 407
                     unset($this->processors['pre'][$index]);
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
     {
425 425
         if ($autoload) {
426 426
             $name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
427
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . Core::toCamelCase($name);
427
+            $class = Core::NAMESPACE_PLUGINS_PROCESSORS.Core::toCamelCase($name);
428 428
 
429 429
             if (class_exists($class)) {
430 430
                 $callback = array(new $class($this), 'process');
@@ -449,12 +449,12 @@  discard block
 block discarded – undo
449 449
     {
450 450
         if (($index = array_search($callback, $this->processors['post'], true)) !== false) {
451 451
             unset($this->processors['post'][$index]);
452
-        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
452
+        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS.str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
453 453
                     $callback),
454 454
                 $this->processors['post'], true)) !== false) {
455 455
             unset($this->processors['post'][$index]);
456 456
         } else {
457
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
457
+            $class = Core::NAMESPACE_PLUGINS_PROCESSORS.str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
458 458
             foreach ($this->processors['post'] as $index => $proc) {
459 459
                 if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
460 460
                     unset($this->processors['post'][$index]);
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                 $this->getCore()->getLoader()->loadPlugin($name);
481 481
             }
482 482
             catch (Exception $e) {
483
-                throw new Exception('Processor ' . $name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $name . '.php in the plugin directory');
483
+                throw new Exception('Processor '.$name.' could not be found in your plugin directories, please ensure it is in a file named '.$name.'.php in the plugin directory');
484 484
             }
485 485
         }
486 486
 
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
     public function setTemplateSource($newSource, $fromPointer = false)
667 667
     {
668 668
         if ($fromPointer === true) {
669
-            $this->templateSource = substr($this->templateSource, 0, $this->pointer) . $newSource;
669
+            $this->templateSource = substr($this->templateSource, 0, $this->pointer).$newSource;
670 670
         } else {
671 671
             $this->templateSource = $newSource;
672 672
         }
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
 
738 738
                 if ($this->debug) {
739 739
                     echo "\n";
740
-                    echo 'COMPILER INIT' . "\n";
740
+                    echo 'COMPILER INIT'."\n";
741 741
                 }
742 742
 
743 743
                 if ($this->debug) {
744
-                    echo 'PROCESSING PREPROCESSORS (' . count($this->processors['pre']) . ')' . "\n";
744
+                    echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')'."\n";
745 745
                 }
746 746
 
747 747
                 // runs preprocessors
@@ -785,23 +785,23 @@  discard block
 block discarded – undo
785 785
             if ($pos === false) {
786 786
                 $this->push(substr($tpl, $ptr), 0);
787 787
                 break;
788
-            } elseif (substr($tpl, $pos - 1, 1) === '\\' && substr($tpl, $pos - 2, 1) !== '\\') {
789
-                $this->push(substr($tpl, $ptr, $pos - $ptr - 1) . $this->ld);
790
-                $ptr = $pos + strlen($this->ld);
791
-            } elseif (preg_match('/^' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', substr($tpl, $pos), $litOpen)) {
792
-                if (!preg_match('/' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
788
+            } elseif (substr($tpl, $pos-1, 1) === '\\' && substr($tpl, $pos-2, 1) !== '\\') {
789
+                $this->push(substr($tpl, $ptr, $pos-$ptr-1).$this->ld);
790
+                $ptr = $pos+strlen($this->ld);
791
+            } elseif (preg_match('/^'.$this->ldr.($this->allowLooseOpenings ? '\s*' : '').'literal'.($this->allowLooseOpenings ? '\s*' : '').$this->rdr.'/s', substr($tpl, $pos), $litOpen)) {
792
+                if (!preg_match('/'.$this->ldr.($this->allowLooseOpenings ? '\s*' : '').'\/literal'.($this->allowLooseOpenings ? '\s*' : '').$this->rdr.'/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
793 793
                     throw new CompilationException($this, 'The {literal} blocks must be closed explicitly with {/literal}');
794 794
                 }
795 795
                 $endpos = $litClose[0][1];
796
-                $this->push(substr($tpl, $ptr, $pos - $ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos - $pos - strlen($litOpen[0])));
797
-                $ptr = $endpos + strlen($litClose[0][0]);
796
+                $this->push(substr($tpl, $ptr, $pos-$ptr).substr($tpl, $pos+strlen($litOpen[0]), $endpos-$pos-strlen($litOpen[0])));
797
+                $ptr = $endpos+strlen($litClose[0][0]);
798 798
             } else {
799
-                if (substr($tpl, $pos - 2, 1) === '\\' && substr($tpl, $pos - 1, 1) === '\\') {
800
-                    $this->push(substr($tpl, $ptr, $pos - $ptr - 1));
799
+                if (substr($tpl, $pos-2, 1) === '\\' && substr($tpl, $pos-1, 1) === '\\') {
800
+                    $this->push(substr($tpl, $ptr, $pos-$ptr-1));
801 801
                     $ptr = $pos;
802 802
                 }
803 803
 
804
-                $this->push(substr($tpl, $ptr, $pos - $ptr));
804
+                $this->push(substr($tpl, $ptr, $pos-$ptr));
805 805
                 $ptr = $pos;
806 806
 
807 807
                 $pos += strlen($this->ld);
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 
820 820
                 // check that there is an end tag present
821 821
                 if (strpos($tpl, $this->rd, $pos) === false) {
822
-                    throw new CompilationException($this, 'A template tag was not closed, started with "' . substr($tpl, $ptr, 30) . '"');
822
+                    throw new CompilationException($this, 'A template tag was not closed, started with "'.substr($tpl, $ptr, 30).'"');
823 823
                 }
824 824
 
825 825
                 $ptr += strlen($this->ld);
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                         continue 2;
834 834
                     }
835 835
 
836
-                    $len = $subptr - $ptr;
836
+                    $len = $subptr-$ptr;
837 837
                     $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n"));
838 838
                     $ptr += $len;
839 839
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
         $compiled .= $this->removeBlock('TopLevelBlock');
848 848
 
849 849
         if ($this->debug) {
850
-            echo 'PROCESSING POSTPROCESSORS' . "\n";
850
+            echo 'PROCESSING POSTPROCESSORS'."\n";
851 851
         }
852 852
 
853 853
         foreach ($this->processors['post'] as $postProc) {
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
         unset($postProc);
864 864
 
865 865
         if ($this->debug) {
866
-            echo 'COMPILATION COMPLETE : MEM USAGE : ' . memory_get_usage() . "\n";
866
+            echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage()."\n";
867 867
         }
868 868
 
869 869
         $output = "<?php\n/* template head */\n";
@@ -876,30 +876,30 @@  discard block
 block discarded – undo
876 876
 
877 877
             switch ($type) {
878 878
                 case Core::CLASS_PLUGIN:
879
-                case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
880
-                    if (class_exists('Plugin' . $plugin) !== false) {
881
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
879
+                case Core::CLASS_PLUGIN+Core::BLOCK_PLUGIN:
880
+                    if (class_exists('Plugin'.$plugin) !== false) {
881
+                        $output .= "if (class_exists('"."Plugin".$plugin."')===false)".
882 882
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
883 883
                     } else {
884
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
884
+                        $output .= "if (class_exists('".Core::NAMESPACE_PLUGINS_BLOCKS."Plugin".$plugin."')===false)".
885 885
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
886 886
                     }
887 887
                     break;
888
-                case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
889
-                    if (class_exists('Plugin' . $plugin) !== false) {
890
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
888
+                case Core::CLASS_PLUGIN+Core::FUNC_PLUGIN:
889
+                    if (class_exists('Plugin'.$plugin) !== false) {
890
+                        $output .= "if (class_exists('"."Plugin".$plugin."')===false)".
891 891
                             "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
892 892
                     } else {
893
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
893
+                        $output .= "if (class_exists('".Core::NAMESPACE_PLUGINS_FUNCTIONS."Plugin".$plugin."')===false)".
894 894
                             "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
895 895
                     }
896 896
                     break;
897 897
                 case Core::FUNC_PLUGIN:
898
-                    if (function_exists('Plugin' . $plugin) !== false) {
899
-                        $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
898
+                    if (function_exists('Plugin'.$plugin) !== false) {
899
+                        $output .= "if (function_exists('"."Plugin".$plugin."')===false)".
900 900
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
901 901
                     } else {
902
-                        $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
902
+                        $output .= "if (function_exists('".Core::NAMESPACE_PLUGINS_FUNCTIONS."Plugin".$plugin."')===false)".
903 903
                         "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
904 904
                     }
905 905
                     break;
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
                     $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
920 920
                     break;
921 921
                 default:
922
-                    throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
922
+                    throw new CompilationException($this, 'Type error for '.$plugin.' with type'.$type);
923 923
             }
924 924
         }
925 925
 
@@ -930,30 +930,30 @@  discard block
 block discarded – undo
930 930
         }
931 931
         foreach ($this->templatePlugins as $function) {
932 932
             if (isset($function['called']) && $function['called'] === true) {
933
-                $output .= $function['body'] . PHP_EOL;
933
+                $output .= $function['body'].PHP_EOL;
934 934
             }
935 935
         }
936 936
 
937
-        $output .= $compiled . "\n?>";
937
+        $output .= $compiled."\n?>";
938 938
 
939
-        $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*' . preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/') . ')/', ";\n", $output);
940
-        $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);
939
+        $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/').preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output);
940
+        $output = str_replace(self::PHP_CLOSE.self::PHP_OPEN, "\n", $output);
941 941
 
942 942
         // handle <?xml tag at the beginning
943 943
         $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output);
944 944
 
945 945
         // add another line break after PHP closing tags that have a line break following,
946 946
         // as we do not know whether it's intended, and PHP will strip it otherwise
947
-        $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output);
947
+        $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0'."\n", $output);
948 948
 
949 949
         if ($this->debug) {
950
-            echo '=============================================================================================' . "\n";
950
+            echo '============================================================================================='."\n";
951 951
             $lines = preg_split('{\r\n|\n|<br />}', $output);
952 952
             array_shift($lines);
953 953
             foreach ($lines as $i => $line) {
954
-                echo ($i + 1) . '. ' . $line . "\r\n";
954
+                echo ($i+1).'. '.$line."\r\n";
955 955
             }
956
-            echo '=============================================================================================' . "\n";
956
+            echo '============================================================================================='."\n";
957 957
         }
958 958
 
959 959
         $this->template = $this->dwoo = null;
@@ -970,13 +970,13 @@  discard block
 block discarded – undo
970 970
     protected function resolveSubTemplateDependencies($function)
971 971
     {
972 972
         if ($this->debug) {
973
-            echo 'Compiler::' . __FUNCTION__ . "\n";
973
+            echo 'Compiler::'.__FUNCTION__."\n";
974 974
         }
975 975
 
976 976
         $body = $this->templatePlugins[$function]['body'];
977 977
         foreach ($this->templatePlugins as $func => $attr) {
978
-            if ($func !== $function && !isset($attr['called']) && strpos($body, Core::NAMESPACE_PLUGINS_FUNCTIONS .
979
-            'Plugin' . Core::toCamelCase($func)) !== false) {
978
+            if ($func !== $function && !isset($attr['called']) && strpos($body, Core::NAMESPACE_PLUGINS_FUNCTIONS.
979
+            'Plugin'.Core::toCamelCase($func)) !== false) {
980 980
                 $this->templatePlugins[$func]['called'] = true;
981 981
                 $this->resolveSubTemplateDependencies($func);
982 982
             }
@@ -1000,14 +1000,14 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
         if ($this->curBlock['buffer'] === null && count($this->stack) > 1) {
1002 1002
             // buffer is not initialized yet (the block has just been created)
1003
-            $this->stack[count($this->stack) - 2]['buffer'] .= (string)$content;
1003
+            $this->stack[count($this->stack)-2]['buffer'] .= (string) $content;
1004 1004
             $this->curBlock['buffer'] = '';
1005 1005
         } else {
1006 1006
             if (!isset($this->curBlock['buffer'])) {
1007 1007
                 throw new CompilationException($this, 'The template has been closed too early, you probably have an extra block-closing tag somewhere');
1008 1008
             }
1009 1009
             // append current content to current block's buffer
1010
-            $this->curBlock['buffer'] .= (string)$content;
1010
+            $this->curBlock['buffer'] .= (string) $content;
1011 1011
         }
1012 1012
         $this->line += $lineCount;
1013 1013
     }
@@ -1077,23 +1077,23 @@  discard block
 block discarded – undo
1077 1077
     public function addBlock($type, array $params, $paramtype)
1078 1078
     {
1079 1079
         if ($this->debug) {
1080
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1080
+            echo 'Compiler::'.__FUNCTION__."\n";
1081 1081
         }
1082 1082
 
1083
-        $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1083
+        $class = Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($type);
1084 1084
         if (class_exists($class) === false) {
1085 1085
             $this->getCore()->getLoader()->loadPlugin($type);
1086 1086
         }
1087 1087
         $params = $this->mapParams($params, array($class, 'init'), $paramtype);
1088 1088
 
1089
-        $this->stack[]  = array(
1089
+        $this->stack[] = array(
1090 1090
             'type'   => $type,
1091 1091
             'params' => $params,
1092 1092
             'custom' => false,
1093 1093
             'class'  => $class,
1094 1094
             'buffer' => null
1095 1095
         );
1096
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1096
+        $this->curBlock = &$this->stack[count($this->stack)-1];
1097 1097
 
1098 1098
         return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1099 1099
     }
@@ -1118,14 +1118,14 @@  discard block
 block discarded – undo
1118 1118
 
1119 1119
         $params = $this->mapParams($params, array($class, 'init'), $paramtype);
1120 1120
 
1121
-        $this->stack[]  = array(
1121
+        $this->stack[] = array(
1122 1122
             'type'   => $type,
1123 1123
             'params' => $params,
1124 1124
             'custom' => true,
1125 1125
             'class'  => $class,
1126 1126
             'buffer' => null
1127 1127
         );
1128
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1128
+        $this->curBlock = &$this->stack[count($this->stack)-1];
1129 1129
 
1130 1130
         return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1131 1131
     }
@@ -1140,21 +1140,21 @@  discard block
 block discarded – undo
1140 1140
     public function injectBlock($type, array $params)
1141 1141
     {
1142 1142
         if ($this->debug) {
1143
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1143
+            echo 'Compiler::'.__FUNCTION__."\n";
1144 1144
         }
1145 1145
 
1146
-        $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1146
+        $class = Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($type);
1147 1147
         if (class_exists($class) === false) {
1148 1148
             $this->getCore()->getLoader()->loadPlugin($type);
1149 1149
         }
1150
-        $this->stack[]  = array(
1150
+        $this->stack[] = array(
1151 1151
             'type'   => $type,
1152 1152
             'params' => $params,
1153 1153
             'custom' => false,
1154 1154
             'class'  => $class,
1155 1155
             'buffer' => null
1156 1156
         );
1157
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1157
+        $this->curBlock = &$this->stack[count($this->stack)-1];
1158 1158
     }
1159 1159
 
1160 1160
     /**
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
     public function removeBlock($type)
1170 1170
     {
1171 1171
         if ($this->debug) {
1172
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1172
+            echo 'Compiler::'.__FUNCTION__."\n";
1173 1173
         }
1174 1174
 
1175 1175
         $output = '';
@@ -1183,10 +1183,10 @@  discard block
 block discarded – undo
1183 1183
                 if ($top['custom']) {
1184 1184
                     $class = $top['class'];
1185 1185
                 } else {
1186
-                    $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($top['type']);
1186
+                    $class = Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($top['type']);
1187 1187
                 }
1188 1188
                 if (count($this->stack)) {
1189
-                    $this->curBlock = &$this->stack[count($this->stack) - 1];
1189
+                    $this->curBlock = &$this->stack[count($this->stack)-1];
1190 1190
                     $this->push(call_user_func(array(
1191 1191
                         $class,
1192 1192
                         'postProcessing'
@@ -1207,7 +1207,7 @@  discard block
 block discarded – undo
1207 1207
                 }
1208 1208
             }
1209 1209
 
1210
-            throw new CompilationException($this, 'Syntax malformation, a block of type "' . $type . '" was closed but was not opened');
1210
+            throw new CompilationException($this, 'Syntax malformation, a block of type "'.$type.'" was closed but was not opened');
1211 1211
         }
1212 1212
 
1213 1213
         return $output;
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
             }
1246 1246
         }
1247 1247
 
1248
-        throw new CompilationException($this, 'A parent block of type "' . $type . '" is required and can not be found');
1248
+        throw new CompilationException($this, 'A parent block of type "'.$type.'" is required and can not be found');
1249 1249
     }
1250 1250
 
1251 1251
     /**
@@ -1268,7 +1268,7 @@  discard block
 block discarded – undo
1268 1268
     public function removeTopBlock()
1269 1269
     {
1270 1270
         if ($this->debug) {
1271
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1271
+            echo 'Compiler::'.__FUNCTION__."\n";
1272 1272
         }
1273 1273
 
1274 1274
         $o = array_pop($this->stack);
@@ -1278,10 +1278,10 @@  discard block
 block discarded – undo
1278 1278
         if ($o['custom']) {
1279 1279
             $class = $o['class'];
1280 1280
         } else {
1281
-            $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($o['type']);
1281
+            $class = Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($o['type']);
1282 1282
         }
1283 1283
 
1284
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1284
+        $this->curBlock = &$this->stack[count($this->stack)-1];
1285 1285
 
1286 1286
         return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']);
1287 1287
     }
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
     protected function parse($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1361 1361
     {
1362 1362
         if ($this->debug) {
1363
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1363
+            echo 'Compiler::'.__FUNCTION__."\n";
1364 1364
         }
1365 1365
 
1366 1366
         if ($to === null) {
@@ -1377,14 +1377,14 @@  discard block
 block discarded – undo
1377 1377
                 // end template tag
1378 1378
                 $pointer += strlen($this->rd);
1379 1379
                 if ($this->debug) {
1380
-                    echo 'TEMPLATE PARSING ENDED' . "\n";
1380
+                    echo 'TEMPLATE PARSING ENDED'."\n";
1381 1381
                 }
1382 1382
 
1383 1383
                 return false;
1384 1384
             }
1385
-            ++ $from;
1385
+            ++$from;
1386 1386
             if ($pointer !== null) {
1387
-                ++ $pointer;
1387
+                ++$pointer;
1388 1388
             }
1389 1389
             if ($from >= $to) {
1390 1390
                 if (is_array($parsingParams)) {
@@ -1396,22 +1396,22 @@  discard block
 block discarded – undo
1396 1396
             $first = $in[$from];
1397 1397
         }
1398 1398
 
1399
-        $substr = substr($in, $from, $to - $from);
1399
+        $substr = substr($in, $from, $to-$from);
1400 1400
 
1401 1401
         if ($this->debug) {
1402
-            echo 'PARSE CALL : PARSING "' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . '" @ ' . $from . ':' . $to . ' in ' . $curBlock . ' : pointer=' . $pointer . "\n";
1402
+            echo 'PARSE CALL : PARSING "'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...' : '').'" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer."\n";
1403 1403
         }
1404 1404
         $parsed = '';
1405 1405
 
1406 1406
         if ($curBlock === 'root' && $first === '*') {
1407 1407
             $src      = $this->getTemplateSource();
1408
-            $startpos = $this->getPointer() - strlen($this->ld);
1408
+            $startpos = $this->getPointer()-strlen($this->ld);
1409 1409
             if (substr($src, $startpos, strlen($this->ld)) === $this->ld) {
1410 1410
                 if ($startpos > 0) {
1411 1411
                     do {
1412 1412
                         $char = substr($src, -- $startpos, 1);
1413 1413
                         if ($char == "\n") {
1414
-                            ++ $startpos;
1414
+                            ++$startpos;
1415 1415
                             $whitespaceStart = true;
1416 1416
                             break;
1417 1417
                         }
@@ -1422,12 +1422,12 @@  discard block
 block discarded – undo
1422 1422
                 if (!isset($whitespaceStart)) {
1423 1423
                     $startpos = $this->getPointer();
1424 1424
                 } else {
1425
-                    $pointer -= $this->getPointer() - $startpos;
1425
+                    $pointer -= $this->getPointer()-$startpos;
1426 1426
                 }
1427 1427
 
1428
-                if ($this->allowNestedComments && strpos($src, $this->ld . '*', $this->getPointer()) !== false) {
1429
-                    $comOpen  = $this->ld . '*';
1430
-                    $comClose = '*' . $this->rd;
1428
+                if ($this->allowNestedComments && strpos($src, $this->ld.'*', $this->getPointer()) !== false) {
1429
+                    $comOpen  = $this->ld.'*';
1430
+                    $comClose = '*'.$this->rd;
1431 1431
                     $level    = 1;
1432 1432
                     $ptr      = $this->getPointer();
1433 1433
 
@@ -1437,33 +1437,33 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
                         if ($open !== false && $close !== false) {
1439 1439
                             if ($open < $close) {
1440
-                                $ptr = $open + strlen($comOpen);
1441
-                                ++ $level;
1440
+                                $ptr = $open+strlen($comOpen);
1441
+                                ++$level;
1442 1442
                             } else {
1443
-                                $ptr = $close + strlen($comClose);
1444
-                                -- $level;
1443
+                                $ptr = $close+strlen($comClose);
1444
+                                --$level;
1445 1445
                             }
1446 1446
                         } elseif ($open !== false) {
1447
-                            $ptr = $open + strlen($comOpen);
1448
-                            ++ $level;
1447
+                            $ptr = $open+strlen($comOpen);
1448
+                            ++$level;
1449 1449
                         } elseif ($close !== false) {
1450
-                            $ptr = $close + strlen($comClose);
1451
-                            -- $level;
1450
+                            $ptr = $close+strlen($comClose);
1451
+                            --$level;
1452 1452
                         } else {
1453 1453
                             $ptr = strlen($src);
1454 1454
                         }
1455 1455
                     }
1456
-                    $endpos = $ptr - strlen('*' . $this->rd);
1456
+                    $endpos = $ptr-strlen('*'.$this->rd);
1457 1457
                 } else {
1458
-                    $endpos = strpos($src, '*' . $this->rd, $startpos);
1458
+                    $endpos = strpos($src, '*'.$this->rd, $startpos);
1459 1459
                     if ($endpos == false) {
1460 1460
                         throw new CompilationException($this, 'Un-ended comment');
1461 1461
                     }
1462 1462
                 }
1463
-                $pointer += $endpos - $startpos + strlen('*' . $this->rd);
1464
-                if (isset($whitespaceStart) && preg_match('#^[\t ]*\r?\n#', substr($src, $endpos + strlen('*' . $this->rd)), $m)) {
1463
+                $pointer += $endpos-$startpos+strlen('*'.$this->rd);
1464
+                if (isset($whitespaceStart) && preg_match('#^[\t ]*\r?\n#', substr($src, $endpos+strlen('*'.$this->rd)), $m)) {
1465 1465
                     $pointer += strlen($m[0]);
1466
-                    $this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer']) - ($this->getPointer() - $startpos - strlen($this->ld)));
1466
+                    $this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer'])-($this->getPointer()-$startpos-strlen($this->ld)));
1467 1467
                 }
1468 1468
 
1469 1469
                 return false;
@@ -1480,20 +1480,20 @@  discard block
 block discarded – undo
1480 1480
         } elseif (($first === '"' || $first === "'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) {
1481 1481
             // string
1482 1482
             $out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
1483
-        } elseif (preg_match('/^\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?(' . (is_array($parsingParams) || $curBlock != 'root' ? '' : '\s+[^(]|') . '\s*\(|\s*' . $this->rdr . '|\s*;)/i', $substr)) {
1483
+        } elseif (preg_match('/^\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?('.(is_array($parsingParams) || $curBlock != 'root' ? '' : '\s+[^(]|').'\s*\(|\s*'.$this->rdr.'|\s*;)/i', $substr)) {
1484 1484
             // func
1485 1485
             $out    = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
1486 1486
             $parsed = 'func';
1487 1487
         } elseif ($first === ';') {
1488 1488
             // instruction end
1489 1489
             if ($this->debug) {
1490
-                echo 'END OF INSTRUCTION' . "\n";
1490
+                echo 'END OF INSTRUCTION'."\n";
1491 1491
             }
1492 1492
             if ($pointer !== null) {
1493
-                ++ $pointer;
1493
+                ++$pointer;
1494 1494
             }
1495 1495
 
1496
-            return $this->parse($in, $from + 1, $to, false, 'root', $pointer);
1496
+            return $this->parse($in, $from+1, $to, false, 'root', $pointer);
1497 1497
         } elseif ($curBlock === 'root' && preg_match('#^/([a-z_][a-z0-9_]*)?#i', $substr, $match)) {
1498 1498
             // close block
1499 1499
             if (!empty($match[1]) && $match[1] == 'else') {
@@ -1510,13 +1510,13 @@  discard block
 block discarded – undo
1510 1510
                     $pointer -= strlen($match[0]);
1511 1511
                 }
1512 1512
                 if ($this->debug) {
1513
-                    echo 'TOP BLOCK CLOSED' . "\n";
1513
+                    echo 'TOP BLOCK CLOSED'."\n";
1514 1514
                 }
1515 1515
 
1516 1516
                 return $this->removeTopBlock();
1517 1517
             } else {
1518 1518
                 if ($this->debug) {
1519
-                    echo 'BLOCK OF TYPE ' . $match[1] . ' CLOSED' . "\n";
1519
+                    echo 'BLOCK OF TYPE '.$match[1].' CLOSED'."\n";
1520 1520
                 }
1521 1521
 
1522 1522
                 return $this->removeBlock($match[1]);
@@ -1524,19 +1524,19 @@  discard block
 block discarded – undo
1524 1524
         } elseif ($curBlock === 'root' && substr($substr, 0, strlen($this->rd)) === $this->rd) {
1525 1525
             // end template tag
1526 1526
             if ($this->debug) {
1527
-                echo 'TAG PARSING ENDED' . "\n";
1527
+                echo 'TAG PARSING ENDED'."\n";
1528 1528
             }
1529 1529
             $pointer += strlen($this->rd);
1530 1530
 
1531 1531
             return false;
1532
-        } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*=' . ($curBlock === 'array' ? '>?' : '') . ')(?:\s+|[^=]).*#i', $substr, $match)) {
1532
+        } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*='.($curBlock === 'array' ? '>?' : '').')(?:\s+|[^=]).*#i', $substr, $match)) {
1533 1533
             // named parameter
1534 1534
             if ($this->debug) {
1535
-                echo 'NAMED PARAM FOUND' . "\n";
1535
+                echo 'NAMED PARAM FOUND'."\n";
1536 1536
             }
1537 1537
             $len = strlen($match[1]);
1538
-            while (substr($in, $from + $len, 1) === ' ') {
1539
-                ++ $len;
1538
+            while (substr($in, $from+$len, 1) === ' ') {
1539
+                ++$len;
1540 1540
             }
1541 1541
             if ($pointer !== null) {
1542 1542
                 $pointer += $len;
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
 
1545 1545
             $output = array(
1546 1546
                 trim($match[1], " \t\r\n=>'\""),
1547
-                $this->parse($in, $from + $len, $to, false, 'namedparam', $pointer)
1547
+                $this->parse($in, $from+$len, $to, false, 'namedparam', $pointer)
1548 1548
             );
1549 1549
 
1550 1550
             $parsingParams[] = $output;
@@ -1565,31 +1565,31 @@  discard block
 block discarded – undo
1565 1565
             $out = $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1566 1566
         } else {
1567 1567
             // parse error
1568
-            throw new CompilationException($this, 'Parse error in "' . substr($in, $from, $to - $from) . '"');
1568
+            throw new CompilationException($this, 'Parse error in "'.substr($in, $from, $to-$from).'"');
1569 1569
         }
1570 1570
 
1571 1571
         if (empty($out)) {
1572 1572
             return '';
1573 1573
         }
1574 1574
 
1575
-        $substr = substr($in, $pointer, $to - $pointer);
1575
+        $substr = substr($in, $pointer, $to-$pointer);
1576 1576
 
1577 1577
         // var parsed, check if any var-extension applies
1578 1578
         if ($parsed === 'var') {
1579 1579
             if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) {
1580 1580
                 if ($this->debug) {
1581
-                    echo 'PARSING POST-VAR EXPRESSION ' . $substr . "\n";
1581
+                    echo 'PARSING POST-VAR EXPRESSION '.$substr."\n";
1582 1582
                 }
1583 1583
                 // parse expressions
1584
-                $pointer += strlen($match[0]) - 1;
1584
+                $pointer += strlen($match[0])-1;
1585 1585
                 if (is_array($parsingParams)) {
1586 1586
                     if ($match[2] == '$') {
1587 1587
                         $expr = $this->parseVar($in, $pointer, $to, array(), $curBlock, $pointer);
1588 1588
                     } else {
1589 1589
                         $expr = $this->parse($in, $pointer, $to, array(), 'expression', $pointer);
1590 1590
                     }
1591
-                    $out[count($out) - 1][0] .= $match[1] . $expr[0][0];
1592
-                    $out[count($out) - 1][1] .= $match[1] . $expr[0][1];
1591
+                    $out[count($out)-1][0] .= $match[1].$expr[0][0];
1592
+                    $out[count($out)-1][1] .= $match[1].$expr[0][1];
1593 1593
                 } else {
1594 1594
                     if ($match[2] == '$') {
1595 1595
                         $expr = $this->parseVar($in, $pointer, $to, false, $curBlock, $pointer);
@@ -1597,26 +1597,26 @@  discard block
 block discarded – undo
1597 1597
                         $expr = $this->parse($in, $pointer, $to, false, 'expression', $pointer);
1598 1598
                     }
1599 1599
                     if (is_array($out) && is_array($expr)) {
1600
-                        $out[0] .= $match[1] . $expr[0];
1601
-                        $out[1] .= $match[1] . $expr[1];
1600
+                        $out[0] .= $match[1].$expr[0];
1601
+                        $out[1] .= $match[1].$expr[1];
1602 1602
                     } elseif (is_array($out)) {
1603
-                        $out[0] .= $match[1] . $expr;
1604
-                        $out[1] .= $match[1] . $expr;
1603
+                        $out[0] .= $match[1].$expr;
1604
+                        $out[1] .= $match[1].$expr;
1605 1605
                     } elseif (is_array($expr)) {
1606
-                        $out .= $match[1] . $expr[0];
1606
+                        $out .= $match[1].$expr[0];
1607 1607
                     } else {
1608
-                        $out .= $match[1] . $expr;
1608
+                        $out .= $match[1].$expr;
1609 1609
                     }
1610 1610
                 }
1611 1611
             } elseif ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) {
1612 1612
                 if ($this->debug) {
1613
-                    echo 'PARSING POST-VAR ASSIGNMENT ' . $substr . "\n";
1613
+                    echo 'PARSING POST-VAR ASSIGNMENT '.$substr."\n";
1614 1614
                 }
1615 1615
                 // parse assignment
1616 1616
                 $value    = $match[2];
1617 1617
                 $operator = trim($match[1]);
1618 1618
                 if (substr($value, 0, 1) == '=') {
1619
-                    throw new CompilationException($this, 'Unexpected "=" in <em>' . $substr . '</em>');
1619
+                    throw new CompilationException($this, 'Unexpected "=" in <em>'.$substr.'</em>');
1620 1620
                 }
1621 1621
 
1622 1622
                 if ($pointer !== null) {
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
                         throw new CompilationException($this, 'Assignments require the "if" plugin to be accessible');
1638 1638
                     }
1639 1639
 
1640
-                    $parts  = $this->mapParams($parts, array(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf', 'init'), 1);
1640
+                    $parts  = $this->mapParams($parts, array(Core::NAMESPACE_PLUGINS_BLOCKS.'PluginIf', 'init'), 1);
1641 1641
                     $tokens = $this->getParamTokens($parts);
1642 1642
                     $parts  = $this->getCompiledParams($parts);
1643 1643
 
@@ -1651,14 +1651,14 @@  discard block
 block discarded – undo
1651 1651
                 if ($this->autoEscape) {
1652 1652
                     $out = preg_replace('#\(is_string\(\$tmp=(.+?)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#', '$1', $out);
1653 1653
                 }
1654
-                $out = self::PHP_OPEN . $echo . $out . $operator . implode(' ', $value) . self::PHP_CLOSE;
1654
+                $out = self::PHP_OPEN.$echo.$out.$operator.implode(' ', $value).self::PHP_CLOSE;
1655 1655
             } elseif ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) {
1656 1656
                 // parse namedparam with var as name (only for array)
1657 1657
                 if ($this->debug) {
1658
-                    echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND' . "\n";
1658
+                    echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND'."\n";
1659 1659
                 }
1660 1660
                 $len = strlen($match[1]);
1661
-                $var = $out[count($out) - 1];
1661
+                $var = $out[count($out)-1];
1662 1662
                 $pointer += $len;
1663 1663
 
1664 1664
                 $output = array($var[0], $this->parse($substr, $len, null, false, 'namedparam', $pointer));
@@ -1673,16 +1673,16 @@  discard block
 block discarded – undo
1673 1673
             // parse modifier on funcs or vars
1674 1674
             $srcPointer = $pointer;
1675 1675
             if (is_array($parsingParams)) {
1676
-                $tmp                     = $this->replaceModifiers(
1676
+                $tmp = $this->replaceModifiers(
1677 1677
                     array(
1678 1678
                     null,
1679 1679
                     null,
1680
-                    $out[count($out) - 1][0],
1680
+                    $out[count($out)-1][0],
1681 1681
                     $match[0]
1682 1682
                     ), $curBlock, $pointer
1683 1683
                 );
1684
-                $out[count($out) - 1][0] = $tmp;
1685
-                $out[count($out) - 1][1] .= substr($substr, $srcPointer, $srcPointer - $pointer);
1684
+                $out[count($out)-1][0] = $tmp;
1685
+                $out[count($out)-1][1] .= substr($substr, $srcPointer, $srcPointer-$pointer);
1686 1686
             } else {
1687 1687
                 $out = $this->replaceModifiers(array(null, null, $out, $match[0]), $curBlock, $pointer);
1688 1688
             }
@@ -1694,10 +1694,10 @@  discard block
 block discarded – undo
1694 1694
             $ptr = 0;
1695 1695
 
1696 1696
             if (is_array($parsingParams)) {
1697
-                $output = $this->parseMethodCall($out[count($out) - 1][1], $match[0], $curBlock, $ptr);
1697
+                $output = $this->parseMethodCall($out[count($out)-1][1], $match[0], $curBlock, $ptr);
1698 1698
 
1699
-                $out[count($out) - 1][0] = $output;
1700
-                $out[count($out) - 1][1] .= substr($match[0], 0, $ptr);
1699
+                $out[count($out)-1][0] = $output;
1700
+                $out[count($out)-1][1] .= substr($match[0], 0, $ptr);
1701 1701
             } else {
1702 1702
                 $out = $this->parseMethodCall($out, $match[0], $curBlock, $ptr);
1703 1703
             }
@@ -1706,7 +1706,7 @@  discard block
 block discarded – undo
1706 1706
         }
1707 1707
 
1708 1708
         if ($curBlock === 'root' && substr($out, 0, strlen(self::PHP_OPEN)) !== self::PHP_OPEN) {
1709
-            return self::PHP_OPEN . 'echo ' . $out . ';' . self::PHP_CLOSE;
1709
+            return self::PHP_OPEN.'echo '.$out.';'.self::PHP_CLOSE;
1710 1710
         }
1711 1711
 
1712 1712
         return $out;
@@ -1732,11 +1732,11 @@  discard block
 block discarded – undo
1732 1732
     protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1733 1733
     {
1734 1734
         $output = '';
1735
-        $cmdstr = substr($in, $from, $to - $from);
1736
-        preg_match('/^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?)(\s*' . $this->rdr . '|\s*;)?/i', $cmdstr, $match);
1735
+        $cmdstr = substr($in, $from, $to-$from);
1736
+        preg_match('/^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match);
1737 1737
 
1738 1738
         if (empty($match[1])) {
1739
-            throw new CompilationException($this, 'Parse error, invalid function name : ' . substr($cmdstr, 0, 15));
1739
+            throw new CompilationException($this, 'Parse error, invalid function name : '.substr($cmdstr, 0, 15));
1740 1740
         }
1741 1741
 
1742 1742
         $func = $match[1];
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
         }
1747 1747
 
1748 1748
         if ($this->debug) {
1749
-            echo 'FUNC FOUND (' . $func . ')' . "\n";
1749
+            echo 'FUNC FOUND ('.$func.')'."\n";
1750 1750
         }
1751 1751
 
1752 1752
         $paramsep = '';
@@ -1758,11 +1758,11 @@  discard block
 block discarded – undo
1758 1758
             $paramspos = $match[1][0][1];
1759 1759
             $paramsep  = substr($match[1][0][0], - 1) === '(' ? ')' : '';
1760 1760
             if ($paramsep === ')') {
1761
-                $paramspos += strlen($match[1][0][0]) - 1;
1761
+                $paramspos += strlen($match[1][0][0])-1;
1762 1762
                 if (substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') {
1763 1763
                     $paramsep = '';
1764 1764
                     if (strlen($match[1][0][0]) > 1) {
1765
-                        -- $paramspos;
1765
+                        --$paramspos;
1766 1766
                     }
1767 1767
                 }
1768 1768
             }
@@ -1787,8 +1787,8 @@  discard block
 block discarded – undo
1787 1787
                     return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1788 1788
                 }
1789 1789
             }
1790
-            $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos - strlen($func)));
1791
-            $paramstr   = substr($cmdstr, $paramspos + 1);
1790
+            $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos-strlen($func)));
1791
+            $paramstr   = substr($cmdstr, $paramspos+1);
1792 1792
             if (substr($paramstr, - 1, 1) === $paramsep) {
1793 1793
                 $paramstr = substr($paramstr, 0, - 1);
1794 1794
             }
@@ -1810,36 +1810,36 @@  discard block
 block discarded – undo
1810 1810
 
1811 1811
                             if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') {
1812 1812
                                 if ($this->debug) {
1813
-                                    echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT ' . $ptr . "\n";
1813
+                                    echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr."\n";
1814 1814
                                 }
1815 1815
                                 break 2;
1816 1816
                             } elseif ($paramstr[$ptr] === ';') {
1817
-                                ++ $ptr;
1817
+                                ++$ptr;
1818 1818
                                 if ($this->debug) {
1819
-                                    echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT ' . $ptr . "\n";
1819
+                                    echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr."\n";
1820 1820
                                 }
1821 1821
                                 break 2;
1822 1822
                             } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') {
1823 1823
                                 if ($this->debug) {
1824
-                                    echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT ' . $ptr . "\n";
1824
+                                    echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr."\n";
1825 1825
                                 }
1826 1826
                                 break 2;
1827 1827
                             } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
1828 1828
                                 if ($this->debug) {
1829
-                                    echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT ' . $ptr . "\n";
1829
+                                    echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr."\n";
1830 1830
                                 }
1831 1831
                                 break 2;
1832 1832
                             }
1833 1833
 
1834 1834
                             if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === ',' || $paramstr[$ptr] === "\r" || $paramstr[$ptr] === "\n" || $paramstr[$ptr] === "\t") {
1835
-                                ++ $ptr;
1835
+                                ++$ptr;
1836 1836
                             } else {
1837 1837
                                 break;
1838 1838
                             }
1839 1839
                         }
1840 1840
 
1841 1841
                         if ($this->debug) {
1842
-                            echo 'FUNC START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
1842
+                            echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr."\n";
1843 1843
                         }
1844 1844
 
1845 1845
                         if ($func === 'if' || $func === 'elseif' || $func === 'tif') {
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
                         }
1852 1852
 
1853 1853
                         if ($this->debug) {
1854
-                            echo 'PARAM PARSED, POINTER AT ' . $ptr . ' (' . substr($paramstr, $ptr - 1, 3) . ')' . "\n";
1854
+                            echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')'."\n";
1855 1855
                         }
1856 1856
                     }
1857 1857
                 }
@@ -1875,16 +1875,16 @@  discard block
 block discarded – undo
1875 1875
         }
1876 1876
 
1877 1877
         if ($pointer !== null) {
1878
-            $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0);
1878
+            $pointer += (isset($paramstr) ? strlen($paramstr) : 0)+(')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1))+strlen($func)+(isset($whitespace) ? $whitespace : 0);
1879 1879
             if ($this->debug) {
1880
-                echo 'FUNC ADDS ' . ((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)) . ' TO POINTER' . "\n";
1880
+                echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0)+(')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1))+strlen($func)).' TO POINTER'."\n";
1881 1881
             }
1882 1882
         }
1883 1883
 
1884 1884
         if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) {
1885 1885
             // handle static method calls with security policy
1886 1886
             if (strstr($func, '::') !== false && $this->securityPolicy !== null && $this->securityPolicy->isMethodAllowed(explode('::', strtolower($func))) !== true) {
1887
-                throw new SecurityException('Call to a disallowed php function : ' . $func);
1887
+                throw new SecurityException('Call to a disallowed php function : '.$func);
1888 1888
             }
1889 1889
             $pluginType = Core::NATIVE_PLUGIN;
1890 1890
         } else {
@@ -1929,19 +1929,19 @@  discard block
 block discarded – undo
1929 1929
                     $this->customPlugins[$func]['function']
1930 1930
                 ), $state);
1931 1931
             } else {
1932
-                if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
1932
+                if (class_exists('Plugin'.Core::toCamelCase($func)) !== false) {
1933 1933
                     $params = $this->mapParams($params, array(
1934
-                        'Plugin' . Core::toCamelCase($func),
1934
+                        'Plugin'.Core::toCamelCase($func),
1935 1935
                         ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1936 1936
                     ), $state);
1937
-                } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
1937
+                } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func)) !== false) {
1938 1938
                     $params = $this->mapParams($params, array(
1939
-                        Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func),
1939
+                        Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func),
1940 1940
                         ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1941 1941
                     ), $state);
1942 1942
                 } else {
1943 1943
                     $params = $this->mapParams($params, array(
1944
-                        Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
1944
+                        Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func),
1945 1945
                         ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1946 1946
                     ), $state);
1947 1947
                 }
@@ -1952,24 +1952,22 @@  discard block
 block discarded – undo
1952 1952
                 $params = $this->mapParams($params, $this->customPlugins[$func]['callback'], $state);
1953 1953
             } else {
1954 1954
                 // Custom plugin
1955
-                if (function_exists('Plugin' . Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ?
1955
+                if (function_exists('Plugin'.Core::toCamelCase($func).(($pluginType & Core::COMPILABLE_PLUGIN) ?
1956 1956
                         'Compile' : '')) !== false) {
1957
-                    $params = $this->mapParams($params, 'Plugin' . Core::toCamelCase($func) . (($pluginType &
1957
+                    $params = $this->mapParams($params, 'Plugin'.Core::toCamelCase($func).(($pluginType &
1958 1958
                             Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1959 1959
                 } // Builtin helper plugin
1960
-                elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . (
1960
+                elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func).(
1961 1961
                     ($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '')) !== false) {
1962
-                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase
1963
-                        ($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1962
+                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func).(($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1964 1963
                 } // Builtin function plugin
1965 1964
                 else {
1966
-                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase
1967
-                        ($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1965
+                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func).(($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1968 1966
                 }
1969 1967
             }
1970 1968
         } // Smarty modifier
1971 1969
         elseif ($pluginType & Core::SMARTY_MODIFIER) {
1972
-            $output = 'smarty_modifier_' . $func . '(' . implode(', ', $params) . ')';
1970
+            $output = 'smarty_modifier_'.$func.'('.implode(', ', $params).')';
1973 1971
         } // Proxy plugin
1974 1972
         elseif ($pluginType & Core::PROXY_PLUGIN) {
1975 1973
             $params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
@@ -2009,19 +2007,19 @@  discard block
 block discarded – undo
2009 2007
             if ($func === 'do') {
2010 2008
                 $output = '';
2011 2009
                 if (isset($params['*'])) {
2012
-                    $output = implode(';', $params['*']) . ';';
2010
+                    $output = implode(';', $params['*']).';';
2013 2011
                 }
2014 2012
 
2015 2013
                 if (is_array($parsingParams) || $curBlock !== 'root') {
2016 2014
                     throw new CompilationException($this, 'Do can not be used inside another function or block');
2017 2015
                 }
2018 2016
 
2019
-                return self::PHP_OPEN . $output . self::PHP_CLOSE;
2017
+                return self::PHP_OPEN.$output.self::PHP_CLOSE;
2020 2018
             } else {
2021 2019
                 if (isset($params['*'])) {
2022
-                    $output = $func . '(' . implode(', ', $params['*']) . ')';
2020
+                    $output = $func.'('.implode(', ', $params['*']).')';
2023 2021
                 } else {
2024
-                    $output = $func . '()';
2022
+                    $output = $func.'()';
2025 2023
                 }
2026 2024
             }
2027 2025
         } // Block class OR Function class
@@ -2031,7 +2029,7 @@  discard block
 block discarded – undo
2031 2029
                     $callback = $this->customPlugins[$func]['callback'];
2032 2030
                     if (!is_array($callback)) {
2033 2031
                         if (!method_exists($callback, 'compile')) {
2034
-                            throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
2032
+                            throw new Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
2035 2033
                         }
2036 2034
                         if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
2037 2035
                             $funcCompiler = array($callback, 'compile');
@@ -2042,13 +2040,13 @@  discard block
 block discarded – undo
2042 2040
                         $funcCompiler = $callback;
2043 2041
                     }
2044 2042
                 } else {
2045
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2046
-                        $funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
2047
-                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2048
-                        $funcCompiler = array(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func), 'compile');
2043
+                    if (class_exists('Plugin'.Core::toCamelCase($func)) !== false) {
2044
+                        $funcCompiler = array('Plugin'.Core::toCamelCase($func), 'compile');
2045
+                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func)) !== false) {
2046
+                        $funcCompiler = array(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func), 'compile');
2049 2047
                     } else {
2050 2048
                         $funcCompiler = array(
2051
-                            Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
2049
+                            Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func),
2052 2050
                             'compile'
2053 2051
                         );
2054 2052
                     }
@@ -2065,34 +2063,34 @@  discard block
 block discarded – undo
2065 2063
                     $callback = $this->customPlugins[$func]['callback'];
2066 2064
                     if (!is_array($callback)) {
2067 2065
                         if (!method_exists($callback, 'process')) {
2068
-                            throw new Exception('Custom plugin ' . $func . ' must implement the "process" method to be usable, or you should provide a full callback to the method to use');
2066
+                            throw new Exception('Custom plugin '.$func.' must implement the "process" method to be usable, or you should provide a full callback to the method to use');
2069 2067
                         }
2070 2068
                         if (is_object($callback)) {
2071 2069
                             $callback = get_class($callback);
2072 2070
                         }
2073 2071
                         if (($ref = new ReflectionMethod($callback, 'process')) && $ref->isStatic()) {
2074
-                            $output = 'call_user_func(array(\'' . $callback . '\', \'process\'), ' . $params . ')';
2072
+                            $output = 'call_user_func(array(\''.$callback.'\', \'process\'), '.$params.')';
2075 2073
                         } else {
2076
-                            $output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback . '\'), \'process\'), ' . $params . ')';
2074
+                            $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback.'\'), \'process\'), '.$params.')';
2077 2075
                         }
2078 2076
                     } elseif (is_object($callback[0])) {
2079
-                        $output = 'call_user_func(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), ' . $params . ')';
2077
+                        $output = 'call_user_func(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), '.$params.')';
2080 2078
                     } elseif (($ref = new ReflectionMethod($callback[0], $callback[1])) && $ref->isStatic()) {
2081
-                        $output = 'call_user_func(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), ' . $params . ')';
2079
+                        $output = 'call_user_func(array(\''.$callback[0].'\', \''.$callback[1].'\'), '.$params.')';
2082 2080
                     } else {
2083
-                        $output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback[0] . '\'), \'' . $callback[1] . '\'), ' . $params . ')';
2081
+                        $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback[0].'\'), \''.$callback[1].'\'), '.$params.')';
2084 2082
                     }
2085 2083
                     if (empty($params)) {
2086
-                        $output = substr($output, 0, - 3) . ')';
2084
+                        $output = substr($output, 0, - 3).')';
2087 2085
                     }
2088 2086
                 } else {
2089
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2090
-                        $output = '$this->classCall(\'Plugin' . $func . '\', array(' . $params . '))';
2091
-                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2092
-                        $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', 
2093
-                        array(' . $params . '))';
2087
+                    if (class_exists('Plugin'.Core::toCamelCase($func)) !== false) {
2088
+                        $output = '$this->classCall(\'Plugin'.$func.'\', array('.$params.'))';
2089
+                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func)) !== false) {
2090
+                        $output = '$this->classCall(\''.Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.$func.'\', 
2091
+                        array(' . $params.'))';
2094 2092
                     } else {
2095
-                        $output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
2093
+                        $output = '$this->classCall(\''.$func.'\', array('.$params.'))';
2096 2094
                     }
2097 2095
                 }
2098 2096
             }
@@ -2103,15 +2101,15 @@  discard block
 block discarded – undo
2103 2101
                     $funcCompiler = $this->customPlugins[$func]['callback'];
2104 2102
                 } else {
2105 2103
                     // Custom plugin
2106
-                    if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2107
-                        $funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
2104
+                    if (function_exists('Plugin'.Core::toCamelCase($func).'Compile') !== false) {
2105
+                        $funcCompiler = 'Plugin'.Core::toCamelCase($func).'Compile';
2108 2106
                     } // Builtin helper plugin
2109
-                    elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2110
-                        $funcCompiler = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) .
2107
+                    elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func).'Compile') !== false) {
2108
+                        $funcCompiler = Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func).
2111 2109
                             'Compile';
2112 2110
                     } // Builtin function plugin
2113 2111
                     else {
2114
-                        $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
2112
+                        $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func).
2115 2113
                             'Compile';
2116 2114
                     }
2117 2115
                 }
@@ -2127,24 +2125,24 @@  discard block
 block discarded – undo
2127 2125
                 if ($pluginType & Core::CUSTOM_PLUGIN) {
2128 2126
                     $callback = $this->customPlugins[$func]['callback'];
2129 2127
                     if ($callback instanceof Closure) {
2130
-                        $output = 'call_user_func($this->getCustomPlugin(\'' . $func . '\'), ' . $params . ')';
2128
+                        $output = 'call_user_func($this->getCustomPlugin(\''.$func.'\'), '.$params.')';
2131 2129
                     } else {
2132
-                        $output = 'call_user_func(\'' . $callback . '\', ' . $params . ')';
2130
+                        $output = 'call_user_func(\''.$callback.'\', '.$params.')';
2133 2131
                     }
2134 2132
                 } else {
2135 2133
                     // Custom plugin
2136
-                    if (function_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2137
-                        $output = 'Plugin' . Core::toCamelCase($func) . '(' . $params .
2134
+                    if (function_exists('Plugin'.Core::toCamelCase($func)) !== false) {
2135
+                        $output = 'Plugin'.Core::toCamelCase($func).'('.$params.
2138 2136
                             ')';
2139 2137
                     } // Builtin helper plugin
2140
-                    elseif(function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !==
2138
+                    elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func)) !==
2141 2139
                         false) {
2142
-                        $output = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . '(' .
2143
-                            $params . ')';
2140
+                        $output = Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($func).'('.
2141
+                            $params.')';
2144 2142
                     } // Builtin function plugin
2145 2143
                     else {
2146
-                        $output = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '(' .
2147
-                            $params . ')';
2144
+                        $output = Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func).'('.
2145
+                            $params.')';
2148 2146
                     }
2149 2147
                 }
2150 2148
             }
@@ -2162,22 +2160,22 @@  discard block
 block discarded – undo
2162 2160
                 $callback = $this->customPlugins[$func]['callback'];
2163 2161
                 if (is_array($callback)) {
2164 2162
                     if (is_object($callback[0])) {
2165
-                        $output = 'call_user_func_array(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2163
+                        $output = 'call_user_func_array(array($this->getCustomPlugin(\''.$func.'\'), \''.$callback[1].'\'), array(array('.$params.'), $this))';
2166 2164
                     } else {
2167
-                        $output = 'call_user_func_array(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2165
+                        $output = 'call_user_func_array(array(\''.$callback[0].'\', \''.$callback[1].'\'), array(array('.$params.'), $this))';
2168 2166
                     }
2169 2167
                 } else {
2170
-                    $output = $callback . '(array(' . $params . '), $this)';
2168
+                    $output = $callback.'(array('.$params.'), $this)';
2171 2169
                 }
2172 2170
             } else {
2173
-                $output = 'smarty_function_' . $func . '(array(' . $params . '), $this)';
2171
+                $output = 'smarty_function_'.$func.'(array('.$params.'), $this)';
2174 2172
             }
2175 2173
         } // Template plugin
2176 2174
         elseif ($pluginType & Core::TEMPLATE_PLUGIN) {
2177 2175
             array_unshift($params, '$this');
2178 2176
             $params                                 = self::implode_r($params);
2179
-            $output                                 = 'Plugin' . Core::toCamelCase($func) .
2180
-                $this->templatePlugins[$func]['uuid'] . '(' . $params . ')';
2177
+            $output                                 = 'Plugin'.Core::toCamelCase($func).
2178
+                $this->templatePlugins[$func]['uuid'].'('.$params.')';
2181 2179
             $this->templatePlugins[$func]['called'] = true;
2182 2180
         }
2183 2181
 
@@ -2209,29 +2207,29 @@  discard block
 block discarded – undo
2209 2207
      */
2210 2208
     protected function parseString($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2211 2209
     {
2212
-        $substr = substr($in, $from, $to - $from);
2210
+        $substr = substr($in, $from, $to-$from);
2213 2211
         $first  = $substr[0];
2214 2212
 
2215 2213
         if ($this->debug) {
2216
-            echo 'STRING FOUND (in ' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . ')' . "\n";
2214
+            echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...' : '').')'."\n";
2217 2215
         }
2218 2216
         $strend = false;
2219
-        $o      = $from + 1;
2217
+        $o      = $from+1;
2220 2218
         while ($strend === false) {
2221 2219
             $strend = strpos($in, $first, $o);
2222 2220
             if ($strend === false) {
2223
-                throw new CompilationException($this, 'Unfinished string, started with ' . substr($in, $from, $to - $from));
2221
+                throw new CompilationException($this, 'Unfinished string, started with '.substr($in, $from, $to-$from));
2224 2222
             }
2225
-            if (substr($in, $strend - 1, 1) === '\\') {
2226
-                $o      = $strend + 1;
2223
+            if (substr($in, $strend-1, 1) === '\\') {
2224
+                $o      = $strend+1;
2227 2225
                 $strend = false;
2228 2226
             }
2229 2227
         }
2230 2228
         if ($this->debug) {
2231
-            echo 'STRING DELIMITED: ' . substr($in, $from, $strend + 1 - $from) . "\n";
2229
+            echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from)."\n";
2232 2230
         }
2233 2231
 
2234
-        $srcOutput = substr($in, $from, $strend + 1 - $from);
2232
+        $srcOutput = substr($in, $from, $strend+1-$from);
2235 2233
 
2236 2234
         if ($pointer !== null) {
2237 2235
             $pointer += strlen($srcOutput);
@@ -2240,13 +2238,13 @@  discard block
 block discarded – undo
2240 2238
         $output = $this->replaceStringVars($srcOutput, $first);
2241 2239
 
2242 2240
         // handle modifiers
2243
-        if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend + 1 - $from), $match)) {
2241
+        if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend+1-$from), $match)) {
2244 2242
             $modstr = $match[1];
2245 2243
 
2246 2244
             if ($curBlock === 'root' && substr($modstr, - 1) === '}') {
2247 2245
                 $modstr = substr($modstr, 0, - 1);
2248 2246
             }
2249
-            $modstr = str_replace('\\' . $first, $first, $modstr);
2247
+            $modstr = str_replace('\\'.$first, $first, $modstr);
2250 2248
             $ptr    = 0;
2251 2249
             $output = $this->replaceModifiers(array(null, null, $output, $modstr), 'string', $ptr);
2252 2250
 
@@ -2254,7 +2252,7 @@  discard block
 block discarded – undo
2254 2252
             if ($pointer !== null) {
2255 2253
                 $pointer += $ptr;
2256 2254
             }
2257
-            $srcOutput .= substr($substr, $strend + 1 - $from, $ptr);
2255
+            $srcOutput .= substr($substr, $strend+1-$from, $ptr);
2258 2256
         }
2259 2257
 
2260 2258
         if (is_array($parsingParams)) {
@@ -2285,10 +2283,10 @@  discard block
 block discarded – undo
2285 2283
      */
2286 2284
     protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2287 2285
     {
2288
-        $substr = substr($in, $from, $to - $from);
2286
+        $substr = substr($in, $from, $to-$from);
2289 2287
 
2290 2288
         if ($this->debug) {
2291
-            echo 'CONST FOUND : ' . $substr . "\n";
2289
+            echo 'CONST FOUND : '.$substr."\n";
2292 2290
         }
2293 2291
 
2294 2292
         if (!preg_match('#^%([\\\\a-z0-9_:]+)#i', $substr, $m)) {
@@ -2329,7 +2327,7 @@  discard block
 block discarded – undo
2329 2327
         }
2330 2328
 
2331 2329
         if ($curBlock !== 'root') {
2332
-            return '(defined("' . $key . '") ? ' . $key . ' : null)';
2330
+            return '(defined("'.$key.'") ? '.$key.' : null)';
2333 2331
         }
2334 2332
 
2335 2333
         return $key;
@@ -2352,7 +2350,7 @@  discard block
 block discarded – undo
2352 2350
      */
2353 2351
     protected function parseVar($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2354 2352
     {
2355
-        $substr = substr($in, $from, $to - $from);
2353
+        $substr = substr($in, $from, $to-$from);
2356 2354
 
2357 2355
         // var key
2358 2356
         $varRegex = '(\\$?\\.?[a-z0-9\\\\_:]*(?:(?:(?:\\.|->)(?:[a-z0-9\\\\_:]+|(?R))|\\[(?:[a-z0-9\\\\_:]+|(?R)|(["\'])[^\\2]*?\\2)\\]))*)';
@@ -2380,13 +2378,13 @@  discard block
 block discarded – undo
2380 2378
 
2381 2379
             if (substr($key, - 1) == '.') {
2382 2380
                 $key = substr($key, 0, - 1);
2383
-                -- $matchedLength;
2381
+                --$matchedLength;
2384 2382
             }
2385 2383
 
2386 2384
             if ($hasMethodCall) {
2387
-                $matchedLength -= strlen($match[3]) + strlen(substr($match[1], strrpos($match[1], '->')));
2388
-                $key        = substr($match[1], 1, strrpos($match[1], '->') - 1);
2389
-                $methodCall = substr($match[1], strrpos($match[1], '->')) . $match[3];
2385
+                $matchedLength -= strlen($match[3])+strlen(substr($match[1], strrpos($match[1], '->')));
2386
+                $key        = substr($match[1], 1, strrpos($match[1], '->')-1);
2387
+                $methodCall = substr($match[1], strrpos($match[1], '->')).$match[3];
2390 2388
             }
2391 2389
 
2392 2390
             if ($hasModifiers) {
@@ -2402,9 +2400,9 @@  discard block
 block discarded – undo
2402 2400
 
2403 2401
             if ($this->debug) {
2404 2402
                 if ($hasMethodCall) {
2405
-                    echo 'METHOD CALL FOUND : $' . $key . substr($methodCall, 0, 30) . "\n";
2403
+                    echo 'METHOD CALL FOUND : $'.$key.substr($methodCall, 0, 30)."\n";
2406 2404
                 } else {
2407
-                    echo 'VAR FOUND : $' . $key . "\n";
2405
+                    echo 'VAR FOUND : $'.$key."\n";
2408 2406
                 }
2409 2407
             }
2410 2408
 
@@ -2415,7 +2413,7 @@  discard block
 block discarded – undo
2415 2413
                 $uid           = 0;
2416 2414
                 $parsed        = array($uid => '');
2417 2415
                 $current       = &$parsed;
2418
-                $curTxt        = &$parsed[$uid ++];
2416
+                $curTxt        = &$parsed[$uid++];
2419 2417
                 $tree          = array();
2420 2418
                 $chars         = str_split($key, 1);
2421 2419
                 $inSplittedVar = false;
@@ -2424,33 +2422,33 @@  discard block
 block discarded – undo
2424 2422
                 while (($char = array_shift($chars)) !== null) {
2425 2423
                     if ($char === '[') {
2426 2424
                         if (count($tree) > 0) {
2427
-                            ++ $bracketCount;
2425
+                            ++$bracketCount;
2428 2426
                         } else {
2429 2427
                             $tree[]        = &$current;
2430
-                            $current[$uid] = array($uid + 1 => '');
2431
-                            $current       = &$current[$uid ++];
2432
-                            $curTxt        = &$current[$uid ++];
2428
+                            $current[$uid] = array($uid+1 => '');
2429
+                            $current       = &$current[$uid++];
2430
+                            $curTxt        = &$current[$uid++];
2433 2431
                             continue;
2434 2432
                         }
2435 2433
                     } elseif ($char === ']') {
2436 2434
                         if ($bracketCount > 0) {
2437
-                            -- $bracketCount;
2435
+                            --$bracketCount;
2438 2436
                         } else {
2439
-                            $current = &$tree[count($tree) - 1];
2437
+                            $current = &$tree[count($tree)-1];
2440 2438
                             array_pop($tree);
2441 2439
                             if (current($chars) !== '[' && current($chars) !== false && current($chars) !== ']') {
2442 2440
                                 $current[$uid] = '';
2443
-                                $curTxt        = &$current[$uid ++];
2441
+                                $curTxt        = &$current[$uid++];
2444 2442
                             }
2445 2443
                             continue;
2446 2444
                         }
2447 2445
                     } elseif ($char === '$') {
2448 2446
                         if (count($tree) == 0) {
2449
-                            $curTxt        = &$current[$uid ++];
2447
+                            $curTxt        = &$current[$uid++];
2450 2448
                             $inSplittedVar = true;
2451 2449
                         }
2452 2450
                     } elseif (($char === '.' || $char === '-') && count($tree) == 0 && $inSplittedVar) {
2453
-                        $curTxt        = &$current[$uid ++];
2451
+                        $curTxt        = &$current[$uid++];
2454 2452
                         $inSplittedVar = false;
2455 2453
                     }
2456 2454
 
@@ -2459,16 +2457,16 @@  discard block
 block discarded – undo
2459 2457
                 unset($uid, $current, $curTxt, $tree, $chars);
2460 2458
 
2461 2459
                 if ($this->debug) {
2462
-                    echo 'RECURSIVE VAR REPLACEMENT : ' . $key . "\n";
2460
+                    echo 'RECURSIVE VAR REPLACEMENT : '.$key."\n";
2463 2461
                 }
2464 2462
 
2465 2463
                 $key = $this->flattenVarTree($parsed);
2466 2464
 
2467 2465
                 if ($this->debug) {
2468
-                    echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2466
+                    echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key."\n";
2469 2467
                 }
2470 2468
 
2471
-                $output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("' . $key . '")');
2469
+                $output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("'.$key.'")');
2472 2470
             } else {
2473 2471
                 $output = $this->parseVarKey($key, $hasModifiers ? 'modifier' : $curBlock);
2474 2472
             }
@@ -2493,10 +2491,10 @@  discard block
 block discarded – undo
2493 2491
                     if (substr($expMatch[2][$k], 0, 1) === '=') {
2494 2492
                         $assign = true;
2495 2493
                         if ($operator === '=') {
2496
-                            throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, can not use "==" in expressions');
2494
+                            throw new CompilationException($this, 'Invalid expression <em>'.$substr.'</em>, can not use "==" in expressions');
2497 2495
                         }
2498 2496
                         if ($curBlock !== 'root') {
2499
-                            throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, assignments can only be used in top level expressions like {$foo+=3} or {$foo="bar"}');
2497
+                            throw new CompilationException($this, 'Invalid expression <em>'.$substr.'</em>, assignments can only be used in top level expressions like {$foo+=3} or {$foo="bar"}');
2500 2498
                         }
2501 2499
                         $operator .= '=';
2502 2500
                         $expMatch[2][$k] = substr($expMatch[2][$k], 1);
@@ -2507,22 +2505,22 @@  discard block
 block discarded – undo
2507 2505
                         $expMatch[2][$k] = substr($expMatch[2][$k], 1);
2508 2506
                     }
2509 2507
                     if (($operator === '+' || $operator === '-') && $expMatch[2][$k] === $operator) {
2510
-                        $output = '(' . $output . $operator . $operator . ')';
2508
+                        $output = '('.$output.$operator.$operator.')';
2511 2509
                         break;
2512 2510
                     } elseif (substr($expMatch[2][$k], 0, 1) === '$') {
2513
-                        $output = '(' . $output . ' ' . $operator . ' ' . $this->parseVar($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2511
+                        $output = '('.$output.' '.$operator.' '.$this->parseVar($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression').')';
2514 2512
                     } elseif (substr($expMatch[2][$k], 0, 1) === '%') {
2515
-                        $output = '(' . $output . ' ' . $operator . ' ' . $this->parseConst($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2513
+                        $output = '('.$output.' '.$operator.' '.$this->parseConst($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression').')';
2516 2514
                     } elseif (!empty($expMatch[2][$k])) {
2517
-                        $output = '(' . $output . ' ' . $operator . ' ' . str_replace(',', '.', $expMatch[2][$k]) . ')';
2515
+                        $output = '('.$output.' '.$operator.' '.str_replace(',', '.', $expMatch[2][$k]).')';
2518 2516
                     } else {
2519
-                        throw new CompilationException($this, 'Unfinished expression <em>' . $substr . '</em>, missing var or number after math operator');
2517
+                        throw new CompilationException($this, 'Unfinished expression <em>'.$substr.'</em>, missing var or number after math operator');
2520 2518
                     }
2521 2519
                 }
2522 2520
             }
2523 2521
 
2524 2522
             if ($this->autoEscape === true && $curBlock !== 'condition') {
2525
-                $output = '(is_string($tmp=' . $output . ') ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)';
2523
+                $output = '(is_string($tmp='.$output.') ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)';
2526 2524
             }
2527 2525
 
2528 2526
             // handle modifiers
@@ -2546,7 +2544,7 @@  discard block
 block discarded – undo
2546 2544
             } elseif ($curBlock === 'expression' || $curBlock === 'variable') {
2547 2545
                 return $output;
2548 2546
             } elseif (isset($assign)) {
2549
-                return self::PHP_OPEN . $output . ';' . self::PHP_CLOSE;
2547
+                return self::PHP_OPEN.$output.';'.self::PHP_CLOSE;
2550 2548
             }
2551 2549
 
2552 2550
             return $output;
@@ -2554,7 +2552,7 @@  discard block
 block discarded – undo
2554 2552
             if ($curBlock === 'string' || $curBlock === 'delimited_string') {
2555 2553
                 return array(0, '');
2556 2554
             }
2557
-            throw new CompilationException($this, 'Invalid variable name <em>' . $substr . '</em>');
2555
+            throw new CompilationException($this, 'Invalid variable name <em>'.$substr.'</em>');
2558 2556
         }
2559 2557
     }
2560 2558
 
@@ -2608,16 +2606,16 @@  discard block
 block discarded – undo
2608 2606
             if (empty($methMatch[2])) {
2609 2607
                 // property
2610 2608
                 if ($curBlock === 'root') {
2611
-                    $output .= '->' . $methMatch[1];
2609
+                    $output .= '->'.$methMatch[1];
2612 2610
                 } else {
2613
-                    $output = '(($tmp = ' . $output . ') ? $tmp->' . $methMatch[1] . ' : null)';
2611
+                    $output = '(($tmp = '.$output.') ? $tmp->'.$methMatch[1].' : null)';
2614 2612
                 }
2615 2613
                 $ptr += strlen($methMatch[1]);
2616 2614
             } else {
2617 2615
                 // method
2618 2616
                 if (substr($methMatch[2], 0, 2) === '()') {
2619
-                    $parsedCall = $methMatch[1] . '()';
2620
-                    $ptr += strlen($methMatch[1]) + 2;
2617
+                    $parsedCall = $methMatch[1].'()';
2618
+                    $ptr += strlen($methMatch[1])+2;
2621 2619
                 } else {
2622 2620
                     $parsedCall = $this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr);
2623 2621
                 }
@@ -2626,15 +2624,15 @@  discard block
 block discarded – undo
2626 2624
                     $method = strtolower(substr($parsedCall, 0, $argPos));
2627 2625
                     $args   = substr($parsedCall, $argPos);
2628 2626
                     if ($curBlock === 'root') {
2629
-                        $output = '$this->getSecurityPolicy()->callMethod($this, ' . $output . ', ' . var_export($method, true) . ', array' . $args . ')';
2627
+                        $output = '$this->getSecurityPolicy()->callMethod($this, '.$output.', '.var_export($method, true).', array'.$args.')';
2630 2628
                     } else {
2631
-                        $output = '(($tmp = ' . $output . ') ? $this->getSecurityPolicy()->callMethod($this, $tmp, ' . var_export($method, true) . ', array' . $args . ') : null)';
2629
+                        $output = '(($tmp = '.$output.') ? $this->getSecurityPolicy()->callMethod($this, $tmp, '.var_export($method, true).', array'.$args.') : null)';
2632 2630
                     }
2633 2631
                 } else {
2634 2632
                     if ($curBlock === 'root') {
2635
-                        $output .= '->' . $parsedCall;
2633
+                        $output .= '->'.$parsedCall;
2636 2634
                     } else {
2637
-                        $output = '(($tmp = ' . $output . ') ? $tmp->' . $parsedCall . ' : null)';
2635
+                        $output = '(($tmp = '.$output.') ? $tmp->'.$parsedCall.' : null)';
2638 2636
                     }
2639 2637
                 }
2640 2638
             }
@@ -2660,21 +2658,21 @@  discard block
 block discarded – undo
2660 2658
             return '$this->scope';
2661 2659
         }
2662 2660
         if (substr($key, 0, 1) === '.') {
2663
-            $key = 'dwoo' . $key;
2661
+            $key = 'dwoo'.$key;
2664 2662
         }
2665 2663
         if (preg_match('#dwoo\.(get|post|server|cookies|session|env|request)((?:\.[a-z0-9_-]+)+)#i', $key, $m)) {
2666 2664
             $global = strtoupper($m[1]);
2667 2665
             if ($global === 'COOKIES') {
2668 2666
                 $global = 'COOKIE';
2669 2667
             }
2670
-            $key = '$_' . $global;
2668
+            $key = '$_'.$global;
2671 2669
             foreach (explode('.', ltrim($m[2], '.')) as $part) {
2672
-                $key .= '[' . var_export($part, true) . ']';
2670
+                $key .= '['.var_export($part, true).']';
2673 2671
             }
2674 2672
             if ($curBlock === 'root') {
2675 2673
                 $output = $key;
2676 2674
             } else {
2677
-                $output = '(isset(' . $key . ')?' . $key . ':null)';
2675
+                $output = '(isset('.$key.')?'.$key.':null)';
2678 2676
             }
2679 2677
         } elseif (preg_match('#dwoo\\.const\\.([a-z0-9\\\\_:]+)#i', $key, $m)) {
2680 2678
             return $this->parseConstKey($m[1], $curBlock);
@@ -2690,9 +2688,9 @@  discard block
 block discarded – undo
2690 2688
                     $output = '$tmp_key';
2691 2689
                 } else {
2692 2690
                     if ($curBlock === 'root') {
2693
-                        $output = '$this->scope["' . $key . '"]';
2691
+                        $output = '$this->scope["'.$key.'"]';
2694 2692
                     } else {
2695
-                        $output = '(isset($this->scope["' . $key . '"]) ? $this->scope["' . $key . '"] : null)';
2693
+                        $output = '(isset($this->scope["'.$key.'"]) ? $this->scope["'.$key.'"] : null)';
2696 2694
                     }
2697 2695
                 }
2698 2696
             } else {
@@ -2703,7 +2701,7 @@  discard block
 block discarded – undo
2703 2701
                     $parentCnt = 0;
2704 2702
 
2705 2703
                     while (true) {
2706
-                        ++ $parentCnt;
2704
+                        ++$parentCnt;
2707 2705
                         array_shift($m[2]);
2708 2706
                         array_shift($m[1]);
2709 2707
                         if (current($m[2]) === '_parent') {
@@ -2712,7 +2710,7 @@  discard block
 block discarded – undo
2712 2710
                         break;
2713 2711
                     }
2714 2712
 
2715
-                    $output = '$this->readParentVar(' . $parentCnt . ')';
2713
+                    $output = '$this->readParentVar('.$parentCnt.')';
2716 2714
                 } else {
2717 2715
                     if ($i === 'dwoo') {
2718 2716
                         $output = '$this->globals';
@@ -2731,28 +2729,28 @@  discard block
 block discarded – undo
2731 2729
                     while (count($m[1]) && $m[1][0] !== '->') {
2732 2730
                         $m[2][0] = preg_replace('/(^\\\([\'"])|\\\([\'"])$)/x', '$2$3', $m[2][0]);
2733 2731
                         if (substr($m[2][0], 0, 1) == '"' || substr($m[2][0], 0, 1) == "'") {
2734
-                            $output .= '[' . $m[2][0] . ']';
2732
+                            $output .= '['.$m[2][0].']';
2735 2733
                         } else {
2736
-                            $output .= '["' . $m[2][0] . '"]';
2734
+                            $output .= '["'.$m[2][0].'"]';
2737 2735
                         }
2738 2736
                         array_shift($m[2]);
2739 2737
                         array_shift($m[1]);
2740 2738
                     }
2741 2739
 
2742 2740
                     if ($curBlock !== 'root') {
2743
-                        $output = '(isset(' . $output . ') ? ' . $output . ':null)';
2741
+                        $output = '(isset('.$output.') ? '.$output.':null)';
2744 2742
                     }
2745 2743
                 }
2746 2744
 
2747 2745
                 if (count($m[2])) {
2748 2746
                     unset($m[0]);
2749
-                    $output = '$this->readVarInto(' . str_replace("\n", '', var_export($m, true)) . ', ' . $output . ', ' . ($curBlock == 'root' ? 'false' : 'true') . ')';
2747
+                    $output = '$this->readVarInto('.str_replace("\n", '', var_export($m, true)).', '.$output.', '.($curBlock == 'root' ? 'false' : 'true').')';
2750 2748
                 }
2751 2749
             }
2752 2750
         } else {
2753 2751
             preg_match_all('#(\[|->|\.)?((?:[a-z0-9_]|-(?!>))+)\]?#i', $key, $m);
2754 2752
             unset($m[0]);
2755
-            $output = '$this->readVar(' . str_replace("\n", '', var_export($m, true)) . ')';
2753
+            $output = '$this->readVar('.str_replace("\n", '', var_export($m, true)).')';
2756 2754
         }
2757 2755
 
2758 2756
         return $output;
@@ -2772,38 +2770,38 @@  discard block
 block discarded – undo
2772 2770
         $out = $recursed ? '".$this->readVarInto(' : '';
2773 2771
         foreach ($tree as $bit) {
2774 2772
             if (is_array($bit)) {
2775
-                $out .= '.' . $this->flattenVarTree($bit, false);
2773
+                $out .= '.'.$this->flattenVarTree($bit, false);
2776 2774
             } else {
2777 2775
                 $key = str_replace('"', '\\"', $bit);
2778 2776
 
2779 2777
                 if (substr($key, 0, 1) === '$') {
2780
-                    $out .= '".' . $this->parseVar($key, 0, strlen($key), false, 'variable') . '."';
2778
+                    $out .= '".'.$this->parseVar($key, 0, strlen($key), false, 'variable').'."';
2781 2779
                 } else {
2782 2780
                     $cnt = substr_count($key, '$');
2783 2781
 
2784 2782
                     if ($this->debug) {
2785
-                        echo 'PARSING SUBVARS IN : ' . $key . "\n";
2783
+                        echo 'PARSING SUBVARS IN : '.$key."\n";
2786 2784
                     }
2787 2785
                     if ($cnt > 0) {
2788
-                        while (-- $cnt >= 0) {
2786
+                        while (--$cnt >= 0) {
2789 2787
                             if (isset($last)) {
2790
-                                $last = strrpos($key, '$', - (strlen($key) - $last + 1));
2788
+                                $last = strrpos($key, '$', - (strlen($key)-$last+1));
2791 2789
                             } else {
2792 2790
                                 $last = strrpos($key, '$');
2793 2791
                             }
2794
-                            preg_match('#\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', substr($key, $last), $submatch);
2792
+                            preg_match('#\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*'.'((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', substr($key, $last), $submatch);
2795 2793
 
2796 2794
                             $len = strlen($submatch[0]);
2797 2795
                             $key = substr_replace(
2798 2796
                                 $key, preg_replace_callback(
2799
-                                    '#(\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*)' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', array(
2797
+                                    '#(\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*)'.'((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', array(
2800 2798
                                         $this,
2801 2799
                                         'replaceVarKeyHelper'
2802 2800
                                     ), substr($key, $last, $len)
2803 2801
                                 ), $last, $len
2804 2802
                             );
2805 2803
                             if ($this->debug) {
2806
-                                echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2804
+                                echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key."\n";
2807 2805
                             }
2808 2806
                         }
2809 2807
                         unset($last);
@@ -2829,7 +2827,7 @@  discard block
 block discarded – undo
2829 2827
      */
2830 2828
     protected function replaceVarKeyHelper($match)
2831 2829
     {
2832
-        return '".' . $this->parseVar($match[0], 0, strlen($match[0]), false, 'variable') . '."';
2830
+        return '".'.$this->parseVar($match[0], 0, strlen($match[0]), false, 'variable').'."';
2833 2831
     }
2834 2832
 
2835 2833
     /**
@@ -2849,7 +2847,7 @@  discard block
 block discarded – undo
2849 2847
      */
2850 2848
     protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2851 2849
     {
2852
-        $substr = substr($in, $from, $to - $from);
2850
+        $substr = substr($in, $from, $to-$from);
2853 2851
 
2854 2852
         $end = strlen($substr);
2855 2853
 
@@ -2923,48 +2921,48 @@  discard block
 block discarded – undo
2923 2921
 
2924 2922
         if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') {
2925 2923
             if ($this->debug) {
2926
-                echo 'BOOLEAN(FALSE) PARSED' . "\n";
2924
+                echo 'BOOLEAN(FALSE) PARSED'."\n";
2927 2925
             }
2928 2926
             $substr = 'false';
2929 2927
             $type   = self::T_BOOL;
2930 2928
         } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') {
2931 2929
             if ($this->debug) {
2932
-                echo 'BOOLEAN(TRUE) PARSED' . "\n";
2930
+                echo 'BOOLEAN(TRUE) PARSED'."\n";
2933 2931
             }
2934 2932
             $substr = 'true';
2935 2933
             $type   = self::T_BOOL;
2936 2934
         } elseif ($substr === 'null' || $substr === 'NULL') {
2937 2935
             if ($this->debug) {
2938
-                echo 'NULL PARSED' . "\n";
2936
+                echo 'NULL PARSED'."\n";
2939 2937
             }
2940 2938
             $substr = 'null';
2941 2939
             $type   = self::T_NULL;
2942 2940
         } elseif (is_numeric($substr)) {
2943
-            $substr = (float)$substr;
2944
-            if ((int)$substr == $substr) {
2945
-                $substr = (int)$substr;
2941
+            $substr = (float) $substr;
2942
+            if ((int) $substr == $substr) {
2943
+                $substr = (int) $substr;
2946 2944
             }
2947 2945
             $type = self::T_NUMERIC;
2948 2946
             if ($this->debug) {
2949
-                echo 'NUMBER (' . $substr . ') PARSED' . "\n";
2947
+                echo 'NUMBER ('.$substr.') PARSED'."\n";
2950 2948
             }
2951 2949
         } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) {
2952 2950
             if ($this->debug) {
2953 2951
                 echo 'SIMPLE MATH PARSED . "\n"';
2954 2952
             }
2955 2953
             $type   = self::T_MATH;
2956
-            $substr = '(' . $substr . ')';
2954
+            $substr = '('.$substr.')';
2957 2955
         } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) {
2958 2956
             if ($this->debug) {
2959
-                echo 'BREAKCHAR (' . $substr . ') PARSED' . "\n";
2957
+                echo 'BREAKCHAR ('.$substr.') PARSED'."\n";
2960 2958
             }
2961 2959
             $type = self::T_BREAKCHAR;
2962 2960
             //$substr = '"'.$substr.'"';
2963 2961
         } else {
2964
-            $substr = $this->replaceStringVars('\'' . str_replace('\'', '\\\'', $substr) . '\'', '\'', $curBlock);
2962
+            $substr = $this->replaceStringVars('\''.str_replace('\'', '\\\'', $substr).'\'', '\'', $curBlock);
2965 2963
             $type   = self::T_UNQUOTED_STRING;
2966 2964
             if ($this->debug) {
2967
-                echo 'BLABBER (' . $substr . ') CASTED AS STRING' . "\n";
2965
+                echo 'BLABBER ('.$substr.') CASTED AS STRING'."\n";
2968 2966
             }
2969 2967
         }
2970 2968
 
@@ -2994,28 +2992,28 @@  discard block
 block discarded – undo
2994 2992
     {
2995 2993
         $pos = 0;
2996 2994
         if ($this->debug) {
2997
-            echo 'STRING VAR REPLACEMENT : ' . $string . "\n";
2995
+            echo 'STRING VAR REPLACEMENT : '.$string."\n";
2998 2996
         }
2999 2997
         // replace vars
3000 2998
         while (($pos = strpos($string, '$', $pos)) !== false) {
3001
-            $prev = substr($string, $pos - 1, 1);
2999
+            $prev = substr($string, $pos-1, 1);
3002 3000
             if ($prev === '\\') {
3003
-                ++ $pos;
3001
+                ++$pos;
3004 3002
                 continue;
3005 3003
             }
3006 3004
 
3007 3005
             $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3008 3006
             $len = $var[0];
3009
-            $var = $this->parse(str_replace('\\' . $first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3007
+            $var = $this->parse(str_replace('\\'.$first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3010 3008
 
3011
-            if ($prev === '`' && substr($string, $pos + $len, 1) === '`') {
3012
-                $string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos - 1, $len + 2);
3009
+            if ($prev === '`' && substr($string, $pos+$len, 1) === '`') {
3010
+                $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos-1, $len+2);
3013 3011
             } else {
3014
-                $string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos, $len);
3012
+                $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len);
3015 3013
             }
3016
-            $pos += strlen($var[1]) + 2;
3014
+            $pos += strlen($var[1])+2;
3017 3015
             if ($this->debug) {
3018
-                echo 'STRING VAR REPLACEMENT DONE : ' . $string . "\n";
3016
+                echo 'STRING VAR REPLACEMENT DONE : '.$string."\n";
3019 3017
             }
3020 3018
         }
3021 3019
 
@@ -3051,7 +3049,7 @@  discard block
 block discarded – undo
3051 3049
     protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null)
3052 3050
     {
3053 3051
         if ($this->debug) {
3054
-            echo 'PARSING MODIFIERS : ' . $m[3] . "\n";
3052
+            echo 'PARSING MODIFIERS : '.$m[3]."\n";
3055 3053
         }
3056 3054
 
3057 3055
         if ($pointer !== null) {
@@ -3075,7 +3073,7 @@  discard block
 block discarded – undo
3075 3073
             }
3076 3074
             if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) {
3077 3075
                 if ($this->debug) {
3078
-                    echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND' . "\n";
3076
+                    echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND'."\n";
3079 3077
                 }
3080 3078
                 $continue = false;
3081 3079
                 if ($pointer !== null) {
@@ -3086,7 +3084,7 @@  discard block
 block discarded – undo
3086 3084
             $cmdstr   = $cmdstrsrc;
3087 3085
             $paramsep = ':';
3088 3086
             if (!preg_match('/^(@{0,2}[a-z_][a-z0-9_]*)(:)?/i', $cmdstr, $match)) {
3089
-                throw new CompilationException($this, 'Invalid modifier name, started with : ' . substr($cmdstr, 0, 10));
3087
+                throw new CompilationException($this, 'Invalid modifier name, started with : '.substr($cmdstr, 0, 10));
3090 3088
             }
3091 3089
             $paramspos = !empty($match[2]) ? strlen($match[1]) : false;
3092 3090
             $func      = $match[1];
@@ -3096,10 +3094,10 @@  discard block
 block discarded – undo
3096 3094
                 $cmdstrsrc = substr($cmdstrsrc, strlen($func));
3097 3095
                 $params    = array();
3098 3096
                 if ($this->debug) {
3099
-                    echo 'MODIFIER (' . $func . ') CALLED WITH NO PARAMS' . "\n";
3097
+                    echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS'."\n";
3100 3098
                 }
3101 3099
             } else {
3102
-                $paramstr = substr($cmdstr, $paramspos + 1);
3100
+                $paramstr = substr($cmdstr, $paramspos+1);
3103 3101
                 if (substr($paramstr, - 1, 1) === $paramsep) {
3104 3102
                     $paramstr = substr($paramstr, 0, - 1);
3105 3103
                 }
@@ -3108,41 +3106,41 @@  discard block
 block discarded – undo
3108 3106
                 $params = array();
3109 3107
                 while ($ptr < strlen($paramstr)) {
3110 3108
                     if ($this->debug) {
3111
-                        echo 'MODIFIER (' . $func . ') START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
3109
+                        echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr."\n";
3112 3110
                     }
3113 3111
                     if ($this->debug) {
3114
-                        echo $paramstr . '--' . $ptr . '--' . strlen($paramstr) . '--modifier' . "\n";
3112
+                        echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier'."\n";
3115 3113
                     }
3116 3114
                     $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr);
3117 3115
                     if ($this->debug) {
3118
-                        echo 'PARAM PARSED, POINTER AT ' . $ptr . "\n";
3116
+                        echo 'PARAM PARSED, POINTER AT '.$ptr."\n";
3119 3117
                     }
3120 3118
 
3121 3119
                     if ($ptr >= strlen($paramstr)) {
3122 3120
                         if ($this->debug) {
3123
-                            echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED' . "\n";
3121
+                            echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED'."\n";
3124 3122
                         }
3125 3123
                         break;
3126 3124
                     }
3127 3125
 
3128 3126
                     if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
3129 3127
                         if ($this->debug) {
3130
-                            echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT ' . $ptr . "\n";
3128
+                            echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr."\n";
3131 3129
                         }
3132 3130
                         if ($paramstr[$ptr] !== '|') {
3133 3131
                             $continue = false;
3134 3132
                             if ($pointer !== null) {
3135
-                                $pointer -= strlen($paramstr) - $ptr;
3133
+                                $pointer -= strlen($paramstr)-$ptr;
3136 3134
                             }
3137 3135
                         }
3138
-                        ++ $ptr;
3136
+                        ++$ptr;
3139 3137
                         break;
3140 3138
                     }
3141 3139
                     if ($ptr < strlen($paramstr) && $paramstr[$ptr] === ':') {
3142
-                        ++ $ptr;
3140
+                        ++$ptr;
3143 3141
                     }
3144 3142
                 }
3145
-                $cmdstrsrc = substr($cmdstrsrc, strlen($func) + 1 + $ptr);
3143
+                $cmdstrsrc = substr($cmdstrsrc, strlen($func)+1+$ptr);
3146 3144
                 foreach ($params as $k => $p) {
3147 3145
                     if (is_array($p) && is_array($p[1])) {
3148 3146
                         $state |= 2;
@@ -3182,9 +3180,9 @@  discard block
 block discarded – undo
3182 3180
                 $params = self::implode_r($params);
3183 3181
 
3184 3182
                 if ($mapped) {
3185
-                    $output = '$this->arrayMap(\'' . $func . '\', array(' . $params . '))';
3183
+                    $output = '$this->arrayMap(\''.$func.'\', array('.$params.'))';
3186 3184
                 } else {
3187
-                    $output = $func . '(' . $params . ')';
3185
+                    $output = $func.'('.$params.')';
3188 3186
                 }
3189 3187
             } elseif ($pluginType & Core::PROXY_PLUGIN) {
3190 3188
                 $params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
@@ -3202,19 +3200,19 @@  discard block
 block discarded – undo
3202 3200
                     $callback = $this->customPlugins[$func]['callback'];
3203 3201
                     if (is_array($callback)) {
3204 3202
                         if (is_object($callback[0])) {
3205
-                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3203
+                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->getCustomPlugin(\''.$func.'\'), \''.$callback[1].'\'), array('.$params.'))';
3206 3204
                         } else {
3207
-                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3205
+                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))';
3208 3206
                         }
3209 3207
                     } elseif ($mapped) {
3210
-                        $output = '$this->arrayMap(\'' . $callback . '\', array(' . $params . '))';
3208
+                        $output = '$this->arrayMap(\''.$callback.'\', array('.$params.'))';
3211 3209
                     } else {
3212
-                        $output = $callback . '(' . $params . ')';
3210
+                        $output = $callback.'('.$params.')';
3213 3211
                     }
3214 3212
                 } elseif ($mapped) {
3215
-                    $output = '$this->arrayMap(\'smarty_modifier_' . $func . '\', array(' . $params . '))';
3213
+                    $output = '$this->arrayMap(\'smarty_modifier_'.$func.'\', array('.$params.'))';
3216 3214
                 } else {
3217
-                    $output = 'smarty_modifier_' . $func . '(' . $params . ')';
3215
+                    $output = 'smarty_modifier_'.$func.'('.$params.')';
3218 3216
                 }
3219 3217
             } else {
3220 3218
                 if ($pluginType & Core::CUSTOM_PLUGIN) {
@@ -3224,17 +3222,17 @@  discard block
 block discarded – undo
3224 3222
                         $callback   = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3225 3223
                     }
3226 3224
                 } else {
3227
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false || function_exists('Plugin' .
3228
-                            Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''))
3225
+                    if (class_exists('Plugin'.Core::toCamelCase($func)) !== false || function_exists('Plugin'.
3226
+                            Core::toCamelCase($func).(($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''))
3229 3227
                         !== false) {
3230
-                        $pluginName = 'Plugin' . Core::toCamelCase($func);
3228
+                        $pluginName = 'Plugin'.Core::toCamelCase($func);
3231 3229
                     } else {
3232
-                        $pluginName = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func);
3230
+                        $pluginName = Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func);
3233 3231
                     }
3234 3232
                     if ($pluginType & Core::CLASS_PLUGIN) {
3235 3233
                         $callback = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3236 3234
                     } else {
3237
-                        $callback = $pluginName . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '');
3235
+                        $callback = $pluginName.(($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '');
3238 3236
                     }
3239 3237
                 }
3240 3238
                 $params = $this->mapParams($params, $callback, $state);
@@ -3252,10 +3250,10 @@  discard block
 block discarded – undo
3252 3250
                         if ($pluginType & Core::CUSTOM_PLUGIN) {
3253 3251
                             $funcCompiler = $this->customPlugins[$func]['callback'];
3254 3252
                         } else {
3255
-                            if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
3256
-                                $funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
3253
+                            if (function_exists('Plugin'.Core::toCamelCase($func).'Compile') !== false) {
3254
+                                $funcCompiler = 'Plugin'.Core::toCamelCase($func).'Compile';
3257 3255
                             } else {
3258
-                                $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
3256
+                                $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func).
3259 3257
                                     'Compile';
3260 3258
                             }
3261 3259
                         }
@@ -3266,9 +3264,9 @@  discard block
 block discarded – undo
3266 3264
 
3267 3265
                         $params = self::implode_r($params);
3268 3266
                         if ($mapped) {
3269
-                            $output = '$this->arrayMap(\'' . $pluginName . '\', array(' . $params . '))';
3267
+                            $output = '$this->arrayMap(\''.$pluginName.'\', array('.$params.'))';
3270 3268
                         } else {
3271
-                            $output = $pluginName . '(' . $params . ')';
3269
+                            $output = $pluginName.'('.$params.')';
3272 3270
                         }
3273 3271
                     }
3274 3272
                 } else {
@@ -3280,7 +3278,7 @@  discard block
 block discarded – undo
3280 3278
                             $callback = $this->customPlugins[$func]['callback'];
3281 3279
                             if (!is_array($callback)) {
3282 3280
                                 if (!method_exists($callback, 'compile')) {
3283
-                                    throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
3281
+                                    throw new Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
3284 3282
                                 }
3285 3283
                                 if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
3286 3284
                                     $funcCompiler = array($callback, 'compile');
@@ -3291,10 +3289,10 @@  discard block
 block discarded – undo
3291 3289
                                 $funcCompiler = $callback;
3292 3290
                             }
3293 3291
                         } else {
3294
-                            if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3295
-                                $funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
3292
+                            if (class_exists('Plugin'.Core::toCamelCase($func)) !== false) {
3293
+                                $funcCompiler = array('Plugin'.Core::toCamelCase($func), 'compile');
3296 3294
                             } else {
3297
-                                $funcCompiler = array(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func), 'compile');
3295
+                                $funcCompiler = array(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func), 'compile');
3298 3296
                             }
3299 3297
                             array_unshift($params, $this);
3300 3298
                         }
@@ -3305,26 +3303,26 @@  discard block
 block discarded – undo
3305 3303
                         if ($pluginType & Core::CUSTOM_PLUGIN) {
3306 3304
                             if (is_object($callback[0])) {
3307 3305
                                 if (is_array($this->getCore()->getCustomPlugin($func))) {
3308
-                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), array(' . $params . '))';
3306
+                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array('.$params.'))';
3309 3307
                                 } else {
3310
-                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3308
+                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->getCustomPlugin(\''.$func.'\'), \''.$callback[1].'\'), array('.$params.'))';
3311 3309
                                 }
3312 3310
                             } else {
3313
-                                $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3311
+                                $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))';
3314 3312
                             }
3315 3313
                         } elseif ($mapped) {
3316 3314
                             $output = '$this->arrayMap(array($this->getObjectPlugin(\''.
3317
-                                Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '\'), 
3318
-                            \'process\'), array(' . $params . '))';
3315
+                                Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func).'\'), 
3316
+                            \'process\'), array(' . $params.'))';
3319 3317
                         } else {
3320
-                            if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3321
-                                $output = '$this->classCall(\'Plugin' . Core::toCamelCase($func) . '\', array(' . $params . '))';
3322
-                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3323
-                                $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . $func . '\', array(' . $params . '))';
3324
-                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3325
-                                $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', array(' . $params . '))';
3318
+                            if (class_exists('Plugin'.Core::toCamelCase($func)) !== false) {
3319
+                                $output = '$this->classCall(\'Plugin'.Core::toCamelCase($func).'\', array('.$params.'))';
3320
+                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($func)) !== false) {
3321
+                                $output = '$this->classCall(\''.Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.$func.'\', array('.$params.'))';
3322
+                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($func)) !== false) {
3323
+                                $output = '$this->classCall(\''.Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.$func.'\', array('.$params.'))';
3326 3324
                             } else {
3327
-                                $output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
3325
+                                $output = '$this->classCall(\''.$func.'\', array('.$params.'))';
3328 3326
                             }
3329 3327
                         }
3330 3328
                     }
@@ -3337,7 +3335,7 @@  discard block
 block discarded – undo
3337 3335
         } elseif ($curBlock === 'var' || $m[1] === null) {
3338 3336
             return $output;
3339 3337
         } elseif ($curBlock === 'string' || $curBlock === 'root') {
3340
-            return $m[1] . '.' . $output . '.' . $m[1] . (isset($add) ? $add : null);
3338
+            return $m[1].'.'.$output.'.'.$m[1].(isset($add) ? $add : null);
3341 3339
         }
3342 3340
 
3343 3341
         return '';
@@ -3360,14 +3358,14 @@  discard block
 block discarded – undo
3360 3358
             if (is_array($p)) {
3361 3359
                 $out2 = 'array(';
3362 3360
                 foreach ($p as $k2 => $v) {
3363
-                    $out2 .= var_export($k2, true) . ' => ' . (is_array($v) ? 'array(' . self::implode_r($v, true) . ')' : $v) . ', ';
3361
+                    $out2 .= var_export($k2, true).' => '.(is_array($v) ? 'array('.self::implode_r($v, true).')' : $v).', ';
3364 3362
                 }
3365
-                $p = rtrim($out2, ', ') . ')';
3363
+                $p = rtrim($out2, ', ').')';
3366 3364
             }
3367 3365
             if ($recursiveCall) {
3368
-                $out .= var_export($k, true) . ' => ' . $p . ', ';
3366
+                $out .= var_export($k, true).' => '.$p.', ';
3369 3367
             } else {
3370
-                $out .= $p . ', ';
3368
+                $out .= $p.', ';
3371 3369
             }
3372 3370
         }
3373 3371
 
@@ -3391,7 +3389,7 @@  discard block
 block discarded – undo
3391 3389
         if (($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty')) || ($this->securityPolicy !== null && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false)) {
3392 3390
             $phpFunc = true;
3393 3391
         } elseif ($this->securityPolicy !== null && function_exists($name) && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) === false) {
3394
-            throw new SecurityException('Call to a disallowed php function : ' . $name);
3392
+            throw new SecurityException('Call to a disallowed php function : '.$name);
3395 3393
         }
3396 3394
 
3397 3395
         while ($pluginType <= 0) {
@@ -3402,58 +3400,58 @@  discard block
 block discarded – undo
3402 3400
             elseif (isset($this->customPlugins[$name])) {
3403 3401
                 $pluginType = $this->customPlugins[$name]['type'] | Core::CUSTOM_PLUGIN;
3404 3402
             } // Class blocks plugin
3405
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3403
+            elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($name)) !== false) {
3406 3404
                 $pluginType = Core::CLASS_PLUGIN;
3407
-                if (is_subclass_of(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name), 'Dwoo\Block\Plugin')) {
3405
+                if (is_subclass_of(Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($name), 'Dwoo\Block\Plugin')) {
3408 3406
                     $pluginType += Core::BLOCK_PLUGIN;
3409 3407
                 }
3410
-                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name));
3408
+                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_BLOCKS.'Plugin'.Core::toCamelCase($name));
3411 3409
                 if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3412 3410
                     $pluginType |= Core::COMPILABLE_PLUGIN;
3413 3411
                 }
3414 3412
             } // Class functions plugin
3415
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3416
-                $pluginType = Core::FUNC_PLUGIN + Core::CLASS_PLUGIN;
3417
-                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name));
3413
+            elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($name)) !== false) {
3414
+                $pluginType = Core::FUNC_PLUGIN+Core::CLASS_PLUGIN;
3415
+                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($name));
3418 3416
                 if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3419 3417
                     $pluginType |= Core::COMPILABLE_PLUGIN;
3420 3418
                 }
3421 3419
             } // Class without namespace
3422
-            elseif (class_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3420
+            elseif (class_exists('Plugin'.Core::toCamelCase($name)) !== false) {
3423 3421
                 $pluginType = Core::CLASS_PLUGIN;
3424
-                $interfaces = class_implements('Plugin' . Core::toCamelCase($name));
3422
+                $interfaces = class_implements('Plugin'.Core::toCamelCase($name));
3425 3423
                 if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3426 3424
                     $pluginType |= Core::COMPILABLE_PLUGIN;
3427 3425
                 }
3428 3426
             } // Function plugin (with/without namespaces)
3429
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase ($name)) !==
3430
-                false || function_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3427
+            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($name)) !==
3428
+                false || function_exists('Plugin'.Core::toCamelCase($name)) !== false) {
3431 3429
                 $pluginType = Core::FUNC_PLUGIN;
3432 3430
             } // Function plugin compile (with/without namespaces)
3433
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name) .
3434
-                    'Compile') !== false || function_exists('Plugin' . Core::toCamelCase($name) . 'Compile') !==
3431
+            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin'.Core::toCamelCase($name).
3432
+                    'Compile') !== false || function_exists('Plugin'.Core::toCamelCase($name).'Compile') !==
3435 3433
                 false) {
3436 3434
                 $pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3437 3435
             } // Helper plugin class compile
3438
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3436
+            elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($name)) !== false) {
3439 3437
                 $pluginType = Core::CLASS_PLUGIN | Core::COMPILABLE_PLUGIN;
3440 3438
             } // Helper plugin function compile
3441
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name) . 'Compile') !== false) {
3439
+            elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS.'Plugin'.Core::toCamelCase($name).'Compile') !== false) {
3442 3440
                 $pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3443 3441
             } // Smarty modifier
3444
-            elseif (function_exists('smarty_modifier_' . $name) !== false) {
3442
+            elseif (function_exists('smarty_modifier_'.$name) !== false) {
3445 3443
                 $pluginType = Core::SMARTY_MODIFIER;
3446 3444
             } // Smarty function
3447
-            elseif (function_exists('smarty_function_' . $name) !== false) {
3445
+            elseif (function_exists('smarty_function_'.$name) !== false) {
3448 3446
                 $pluginType = Core::SMARTY_FUNCTION;
3449 3447
             } // Smarty block
3450
-            elseif (function_exists('smarty_block_' . $name) !== false) {
3448
+            elseif (function_exists('smarty_block_'.$name) !== false) {
3451 3449
                 $pluginType = Core::SMARTY_BLOCK;
3452 3450
             } // Everything else
3453 3451
             else {
3454 3452
                 if ($pluginType === - 1) {
3455 3453
                     try {
3456
-                        $this->getCore()->getLoader()->loadPlugin('Plugin' . Core::toCamelCase($name));
3454
+                        $this->getCore()->getLoader()->loadPlugin('Plugin'.Core::toCamelCase($name));
3457 3455
                     }
3458 3456
                     catch (Exception $e) {
3459 3457
                         if (isset($phpFunc)) {
@@ -3466,9 +3464,9 @@  discard block
 block discarded – undo
3466 3464
                         }
3467 3465
                     }
3468 3466
                 } else {
3469
-                    throw new Exception('Plugin "' . $name . '" could not be found, type:' . $pluginType);
3467
+                    throw new Exception('Plugin "'.$name.'" could not be found, type:'.$pluginType);
3470 3468
                 }
3471
-                ++ $pluginType;
3469
+                ++$pluginType;
3472 3470
             }
3473 3471
         }
3474 3472
 
@@ -3537,15 +3535,15 @@  discard block
 block discarded – undo
3537 3535
         }
3538 3536
 
3539 3537
         // loops over the param map and assigns values from the template or default value for unset optional params
3540
-        foreach ($map as $k => $v){
3538
+        foreach ($map as $k => $v) {
3541 3539
             if ($v[0] === '*') {
3542 3540
                 // "rest" array parameter, fill every remaining params in it and then break
3543 3541
                 if (count($ps) === 0) {
3544 3542
                     if ($v[1] === false) {
3545 3543
                         throw new CompilationException(
3546
-                            $this, 'Rest argument missing for ' . str_replace(
3544
+                            $this, 'Rest argument missing for '.str_replace(
3547 3545
                                 array(
3548
-                                    Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3546
+                                    Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin',
3549 3547
                                 'Compile'
3550 3548
                                 ), '', (is_array($callback) ? $callback[0] : $callback)
3551 3549
                             )
@@ -3578,7 +3576,7 @@  discard block
 block discarded – undo
3578 3576
                 // parameter is not defined and not optional, throw error
3579 3577
                 if (is_array($callback)) {
3580 3578
                     if (is_object($callback[0])) {
3581
-                        $name = get_class($callback[0]) . '::' . $callback[1];
3579
+                        $name = get_class($callback[0]).'::'.$callback[1];
3582 3580
                     } else {
3583 3581
                         $name = $callback[0];
3584 3582
                     }
@@ -3587,9 +3585,9 @@  discard block
 block discarded – undo
3587 3585
                 }
3588 3586
 
3589 3587
                 throw new CompilationException(
3590
-                    $this, 'Argument ' . $k . '/' . $v[0] . ' missing for ' . str_replace(
3588
+                    $this, 'Argument '.$k.'/'.$v[0].' missing for '.str_replace(
3591 3589
                         array(
3592
-                            Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3590
+                            Core::NAMESPACE_PLUGINS_FUNCTIONS.'Plugin',
3593 3591
                         'Compile'
3594 3592
                         ), '', $name
3595 3593
                     )
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -478,8 +478,7 @@  discard block
 block discarded – undo
478 478
         if (!class_exists($class) && !function_exists($class)) {
479 479
             try {
480 480
                 $this->getCore()->getLoader()->loadPlugin($name);
481
-            }
482
-            catch (Exception $e) {
481
+            } catch (Exception $e) {
483 482
                 throw new Exception('Processor ' . $name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $name . '.php in the plugin directory');
484 483
             }
485 484
         }
@@ -1632,8 +1631,7 @@  discard block
 block discarded – undo
1632 1631
                     // load if plugin
1633 1632
                     try {
1634 1633
                         $this->getPluginType('if');
1635
-                    }
1636
-                    catch (Exception $e) {
1634
+                    } catch (Exception $e) {
1637 1635
                         throw new CompilationException($this, 'Assignments require the "if" plugin to be accessible');
1638 1636
                     }
1639 1637
 
@@ -3454,8 +3452,7 @@  discard block
 block discarded – undo
3454 3452
                 if ($pluginType === - 1) {
3455 3453
                     try {
3456 3454
                         $this->getCore()->getLoader()->loadPlugin('Plugin' . Core::toCamelCase($name));
3457
-                    }
3458
-                    catch (Exception $e) {
3455
+                    } catch (Exception $e) {
3459 3456
                         if (isset($phpFunc)) {
3460 3457
                             $pluginType = Core::NATIVE_PLUGIN;
3461 3458
                         } elseif (is_object($this->getCore()->getPluginProxy()) && $this->getCore()->getPluginProxy()->handles($name)) {
Please login to merge, or discard this patch.
Indentation   +3636 added lines, -3636 removed lines patch added patch discarded remove patch
@@ -31,3642 +31,3642 @@
 block discarded – undo
31 31
  */
32 32
 class Compiler implements ICompiler
33 33
 {
34
-    /**
35
-     * Constant that represents a php opening tag.
36
-     * use it in case it needs to be adjusted
37
-     *
38
-     * @var string
39
-     */
40
-    const PHP_OPEN = '<?php ';
41
-
42
-    /**
43
-     * Constant that represents a php closing tag.
44
-     * use it in case it needs to be adjusted
45
-     *
46
-     * @var string
47
-     */
48
-    const PHP_CLOSE = '?>';
49
-
50
-    /**
51
-     * Boolean flag to enable or disable debugging output.
52
-     *
53
-     * @var bool
54
-     */
55
-    public $debug = false;
56
-
57
-    /**
58
-     * Left script delimiter.
59
-     *
60
-     * @var string
61
-     */
62
-    protected $ld = '{';
63
-
64
-    /**
65
-     * Left script delimiter with escaped regex meta characters.
66
-     *
67
-     * @var string
68
-     */
69
-    protected $ldr = '\\{';
70
-
71
-    /**
72
-     * Right script delimiter.
73
-     *
74
-     * @var string
75
-     */
76
-    protected $rd = '}';
77
-
78
-    /**
79
-     * Right script delimiter with escaped regex meta characters.
80
-     *
81
-     * @var string
82
-     */
83
-    protected $rdr = '\\}';
84
-
85
-    /**
86
-     * Defines whether the nested comments should be parsed as nested or not.
87
-     * defaults to false (classic block comment parsing as in all languages)
88
-     *
89
-     * @var bool
90
-     */
91
-    protected $allowNestedComments = false;
92
-
93
-    /**
94
-     * Defines whether opening and closing tags can contain spaces before valid data or not.
95
-     * turn to true if you want to be sloppy with the syntax, but when set to false it allows
96
-     * to skip javascript and css tags as long as they are in the form "{ something", which is
97
-     * nice. default is false.
98
-     *
99
-     * @var bool
100
-     */
101
-    protected $allowLooseOpenings = false;
102
-
103
-    /**
104
-     * Defines whether the compiler will automatically html-escape variables or not.
105
-     * default is false
106
-     *
107
-     * @var bool
108
-     */
109
-    protected $autoEscape = false;
110
-
111
-    /**
112
-     * Security policy object.
113
-     *
114
-     * @var SecurityPolicy
115
-     */
116
-    protected $securityPolicy;
117
-
118
-    /**
119
-     * Stores the custom plugins registered with this compiler.
120
-     *
121
-     * @var array
122
-     */
123
-    protected $customPlugins = array();
124
-
125
-    /**
126
-     * Stores the template plugins registered with this compiler.
127
-     *
128
-     * @var array
129
-     */
130
-    protected $templatePlugins = array();
131
-
132
-    /**
133
-     * Stores the pre- and post-processors callbacks.
134
-     *
135
-     * @var array
136
-     */
137
-    protected $processors = array('pre' => array(), 'post' => array());
138
-
139
-    /**
140
-     * Stores a list of plugins that are used in the currently compiled
141
-     * template, and that are not compilable. these plugins will be loaded
142
-     * during the template's runtime if required.
143
-     * it is a 1D array formatted as key:pluginName value:pluginType
144
-     *
145
-     * @var array
146
-     */
147
-    protected $usedPlugins;
148
-
149
-    /**
150
-     * Stores the template undergoing compilation.
151
-     *
152
-     * @var string
153
-     */
154
-    protected $template;
155
-
156
-    /**
157
-     * Stores the current pointer position inside the template.
158
-     *
159
-     * @var int
160
-     */
161
-    protected $pointer;
162
-
163
-    /**
164
-     * Stores the current line count inside the template for debugging purposes.
165
-     *
166
-     * @var int
167
-     */
168
-    protected $line;
169
-
170
-    /**
171
-     * Stores the current template source while compiling it.
172
-     *
173
-     * @var string
174
-     */
175
-    protected $templateSource;
176
-
177
-    /**
178
-     * Stores the data within which the scope moves.
179
-     *
180
-     * @var array
181
-     */
182
-    protected $data;
183
-
184
-    /**
185
-     * Variable scope of the compiler, set to null if
186
-     * it can not be resolved to a static string (i.e. if some
187
-     * plugin defines a new scope based on a variable array key).
188
-     *
189
-     * @var mixed
190
-     */
191
-    protected $scope;
192
-
193
-    /**
194
-     * Variable scope tree, that allows to rebuild the current
195
-     * scope if required, i.e. when going to a parent level.
196
-     *
197
-     * @var array
198
-     */
199
-    protected $scopeTree;
200
-
201
-    /**
202
-     * Block plugins stack, accessible through some methods.
203
-     *
204
-     * @see findBlock
205
-     * @see getCurrentBlock
206
-     * @see addBlock
207
-     * @see addCustomBlock
208
-     * @see injectBlock
209
-     * @see removeBlock
210
-     * @see removeTopBlock
211
-     * @var array
212
-     */
213
-    protected $stack = array();
214
-
215
-    /**
216
-     * Current block at the top of the block plugins stack,
217
-     * accessible through getCurrentBlock.
218
-     *
219
-     * @see getCurrentBlock
220
-     * @var array
221
-     */
222
-    protected $curBlock;
223
-
224
-    /**
225
-     * Current dwoo object that uses this compiler, or null.
226
-     *
227
-     * @var Core
228
-     */
229
-    public $core;
230
-
231
-    /**
232
-     * Holds an instance of this class, used by getInstance when you don't
233
-     * provide a custom compiler in order to save resources.
234
-     *
235
-     * @var Compiler
236
-     */
237
-    protected static $instance;
238
-
239
-    /**
240
-     * Token types.
241
-     *
242
-     * @var int
243
-     */
244
-    const T_UNQUOTED_STRING = 1;
245
-    const T_NUMERIC         = 2;
246
-    const T_NULL            = 4;
247
-    const T_BOOL            = 8;
248
-    const T_MATH            = 16;
249
-    const T_BREAKCHAR       = 32;
250
-
251
-    /**
252
-     * Compiler constructor.
253
-     * saves the created instance so that child templates get the same one
254
-     */
255
-    public function __construct()
256
-    {
257
-        self::$instance = $this;
258
-    }
259
-
260
-    /**
261
-     * Sets the delimiters to use in the templates.
262
-     * delimiters can be multi-character strings but should not be one of those as they will
263
-     * make it very hard to work with templates or might even break the compiler entirely : "\", "$", "|", ":" and
264
-     * finally "#" only if you intend to use config-vars with the #var# syntax.
265
-     *
266
-     * @param string $left  left delimiter
267
-     * @param string $right right delimiter
268
-     */
269
-    public function setDelimiters($left, $right)
270
-    {
271
-        $this->ld  = $left;
272
-        $this->rd  = $right;
273
-        $this->ldr = preg_quote($left, '/');
274
-        $this->rdr = preg_quote($right, '/');
275
-    }
276
-
277
-    /**
278
-     * Returns the left and right template delimiters.
279
-     *
280
-     * @return array containing the left and the right delimiters
281
-     */
282
-    public function getDelimiters()
283
-    {
284
-        return array($this->ld, $this->rd);
285
-    }
286
-
287
-    /**
288
-     * Sets the way to handle nested comments, if set to true
289
-     * {* foo {* some other *} comment *} will be stripped correctly.
290
-     * if false it will remove {* foo {* some other *} and leave "comment *}" alone,
291
-     * this is the default behavior
292
-     *
293
-     * @param bool $allow allow nested comments or not, defaults to true (but the default internal value is false)
294
-     */
295
-    public function setNestedCommentsHandling($allow = true)
296
-    {
297
-        $this->allowNestedComments = (bool)$allow;
298
-    }
299
-
300
-    /**
301
-     * Returns the nested comments handling setting.
302
-     *
303
-     * @see    setNestedCommentsHandling
304
-     * @return bool true if nested comments are allowed
305
-     */
306
-    public function getNestedCommentsHandling()
307
-    {
308
-        return $this->allowNestedComments;
309
-    }
310
-
311
-    /**
312
-     * Sets the tag openings handling strictness, if set to true, template tags can
313
-     * contain spaces before the first function/string/variable such as { $foo} is valid.
314
-     * if set to false (default setting), { $foo} is invalid but that is however a good thing
315
-     * as it allows css (i.e. #foo { color:red; }) to be parsed silently without triggering
316
-     * an error, same goes for javascript.
317
-     *
318
-     * @param bool $allow true to allow loose handling, false to restore default setting
319
-     */
320
-    public function setLooseOpeningHandling($allow = false)
321
-    {
322
-        $this->allowLooseOpenings = (bool)$allow;
323
-    }
324
-
325
-    /**
326
-     * Returns the tag openings handling strictness setting.
327
-     *
328
-     * @see    setLooseOpeningHandling
329
-     * @return bool true if loose tags are allowed
330
-     */
331
-    public function getLooseOpeningHandling()
332
-    {
333
-        return $this->allowLooseOpenings;
334
-    }
335
-
336
-    /**
337
-     * Changes the auto escape setting.
338
-     * if enabled, the compiler will automatically html-escape variables,
339
-     * unless they are passed through the safe function such as {$var|safe}
340
-     * or {safe $var}
341
-     * default setting is disabled/false
342
-     *
343
-     * @param bool $enabled set to true to enable, false to disable
344
-     */
345
-    public function setAutoEscape($enabled)
346
-    {
347
-        $this->autoEscape = (bool)$enabled;
348
-    }
349
-
350
-    /**
351
-     * Returns the auto escape setting.
352
-     * default setting is disabled/false
353
-     *
354
-     * @return bool
355
-     */
356
-    public function getAutoEscape()
357
-    {
358
-        return $this->autoEscape;
359
-    }
360
-
361
-    /**
362
-     * Adds a preprocessor to the compiler, it will be called
363
-     * before the template is compiled.
364
-     *
365
-     * @param mixed $callback either a valid callback to the preprocessor or a simple name if the autoload is set to
366
-     *                        true
367
-     * @param bool  $autoload if set to true, the preprocessor is auto-loaded from one of the plugin directories, else
368
-     *                        you must provide a valid callback
369
-     */
370
-    public function addPreProcessor($callback, $autoload = false)
371
-    {
372
-        if ($autoload) {
373
-            $name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', Core::toCamelCase($callback));
374
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . $name;
375
-
376
-            if (class_exists($class)) {
377
-                $callback = array(new $class($this), 'process');
378
-            } elseif (function_exists($class)) {
379
-                $callback = $class;
380
-            } else {
381
-                $callback = array('autoload' => true, 'class' => $class, 'name' => $name);
382
-            }
383
-
384
-            $this->processors['pre'][] = $callback;
385
-        } else {
386
-            $this->processors['pre'][] = $callback;
387
-        }
388
-    }
389
-
390
-    /**
391
-     * Removes a preprocessor from the compiler.
392
-     *
393
-     * @param mixed $callback either a valid callback to the preprocessor or a simple name if it was autoloaded
394
-     */
395
-    public function removePreProcessor($callback)
396
-    {
397
-        if (($index = array_search($callback, $this->processors['pre'], true)) !== false) {
398
-            unset($this->processors['pre'][$index]);
399
-        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
400
-                    $callback),
401
-                $this->processors['pre'], true)) !== false) {
402
-            unset($this->processors['pre'][$index]);
403
-        } else {
404
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
405
-            foreach ($this->processors['pre'] as $index => $proc) {
406
-                if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
407
-                    unset($this->processors['pre'][$index]);
408
-                    break;
409
-                }
410
-            }
411
-        }
412
-    }
413
-
414
-    /**
415
-     * Adds a postprocessor to the compiler, it will be called
416
-     * before the template is compiled.
417
-     *
418
-     * @param mixed $callback either a valid callback to the postprocessor or a simple name if the autoload is set to
419
-     *                        true
420
-     * @param bool  $autoload if set to true, the postprocessor is auto-loaded from one of the plugin directories, else
421
-     *                        you must provide a valid callback
422
-     */
423
-    public function addPostProcessor($callback, $autoload = false)
424
-    {
425
-        if ($autoload) {
426
-            $name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
427
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . Core::toCamelCase($name);
428
-
429
-            if (class_exists($class)) {
430
-                $callback = array(new $class($this), 'process');
431
-            } elseif (function_exists($class)) {
432
-                $callback = $class;
433
-            } else {
434
-                $callback = array('autoload' => true, 'class' => $class, 'name' => $name);
435
-            }
436
-
437
-            $this->processors['post'][] = $callback;
438
-        } else {
439
-            $this->processors['post'][] = $callback;
440
-        }
441
-    }
442
-
443
-    /**
444
-     * Removes a postprocessor from the compiler.
445
-     *
446
-     * @param mixed $callback either a valid callback to the postprocessor or a simple name if it was autoloaded
447
-     */
448
-    public function removePostProcessor($callback)
449
-    {
450
-        if (($index = array_search($callback, $this->processors['post'], true)) !== false) {
451
-            unset($this->processors['post'][$index]);
452
-        } elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
453
-                    $callback),
454
-                $this->processors['post'], true)) !== false) {
455
-            unset($this->processors['post'][$index]);
456
-        } else {
457
-            $class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
458
-            foreach ($this->processors['post'] as $index => $proc) {
459
-                if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
460
-                    unset($this->processors['post'][$index]);
461
-                    break;
462
-                }
463
-            }
464
-        }
465
-    }
466
-
467
-    /**
468
-     * Internal function to autoload processors at runtime if required.
469
-     *
470
-     * @param string $class the class/function name
471
-     * @param string $name  the plugin name (without Dwoo_Plugin_ prefix)
472
-     *
473
-     * @return array|string
474
-     * @throws Exception
475
-     */
476
-    protected function loadProcessor($class, $name)
477
-    {
478
-        if (!class_exists($class) && !function_exists($class)) {
479
-            try {
480
-                $this->getCore()->getLoader()->loadPlugin($name);
481
-            }
482
-            catch (Exception $e) {
483
-                throw new Exception('Processor ' . $name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $name . '.php in the plugin directory');
484
-            }
485
-        }
486
-
487
-        if (class_exists($class)) {
488
-            return array(new $class($this), 'process');
489
-        }
490
-
491
-        if (function_exists($class)) {
492
-            return $class;
493
-        }
494
-
495
-        throw new Exception('Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"');
496
-    }
497
-
498
-    /**
499
-     * Adds an used plugin, this is reserved for use by the {template} plugin.
500
-     * this is required so that plugin loading bubbles up from loaded
501
-     * template files to the current one
502
-     *
503
-     * @private
504
-     *
505
-     * @param string $name function name
506
-     * @param int    $type plugin type (Core::*_PLUGIN)
507
-     */
508
-    public function addUsedPlugin($name, $type)
509
-    {
510
-        $this->usedPlugins[$name] = $type;
511
-    }
512
-
513
-    /**
514
-     * Returns all the plugins this template uses.
515
-     *
516
-     * @private
517
-     * @return  array the list of used plugins in the parsed template
518
-     */
519
-    public function getUsedPlugins()
520
-    {
521
-        return $this->usedPlugins;
522
-    }
523
-
524
-    /**
525
-     * Adds a template plugin, this is reserved for use by the {template} plugin.
526
-     * this is required because the template functions are not declared yet
527
-     * during compilation, so we must have a way of validating their argument
528
-     * signature without using the reflection api
529
-     *
530
-     * @private
531
-     *
532
-     * @param string $name   function name
533
-     * @param array  $params parameter array to help validate the function call
534
-     * @param string $uuid   unique id of the function
535
-     * @param string $body   function php code
536
-     */
537
-    public function addTemplatePlugin($name, array $params, $uuid, $body = null)
538
-    {
539
-        $this->templatePlugins[$name] = array('params' => $params, 'body' => $body, 'uuid' => $uuid);
540
-    }
541
-
542
-    /**
543
-     * Returns all the parsed sub-templates.
544
-     *
545
-     * @private
546
-     * @return  array the parsed sub-templates
547
-     */
548
-    public function getTemplatePlugins()
549
-    {
550
-        return $this->templatePlugins;
551
-    }
552
-
553
-    /**
554
-     * Marks a template plugin as being called, which means its source must be included in the compiled template.
555
-     *
556
-     * @param string $name function name
557
-     */
558
-    public function useTemplatePlugin($name)
559
-    {
560
-        $this->templatePlugins[$name]['called'] = true;
561
-    }
562
-
563
-    /**
564
-     * Adds the custom plugins loaded into Dwoo to the compiler so it can load them.
565
-     *
566
-     * @see Core::addPlugin
567
-     *
568
-     * @param array $customPlugins an array of custom plugins
569
-     */
570
-    public function setCustomPlugins(array $customPlugins)
571
-    {
572
-        $this->customPlugins = $customPlugins;
573
-    }
574
-
575
-    /**
576
-     * Sets the security policy object to enforce some php security settings.
577
-     * use this if untrusted persons can modify templates,
578
-     * set it on the Dwoo object as it will be passed onto the compiler automatically
579
-     *
580
-     * @param SecurityPolicy $policy the security policy object
581
-     */
582
-    public function setSecurityPolicy(SecurityPolicy $policy = null)
583
-    {
584
-        $this->securityPolicy = $policy;
585
-    }
586
-
587
-    /**
588
-     * Returns the current security policy object or null by default.
589
-     *
590
-     * @return SecurityPolicy|null the security policy object if any
591
-     */
592
-    public function getSecurityPolicy()
593
-    {
594
-        return $this->securityPolicy;
595
-    }
596
-
597
-    /**
598
-     * Sets the pointer position.
599
-     *
600
-     * @param int  $position the new pointer position
601
-     * @param bool $isOffset if set to true, the position acts as an offset and not an absolute position
602
-     */
603
-    public function setPointer($position, $isOffset = false)
604
-    {
605
-        if ($isOffset) {
606
-            $this->pointer += $position;
607
-        } else {
608
-            $this->pointer = $position;
609
-        }
610
-    }
611
-
612
-    /**
613
-     * Returns the current pointer position, only available during compilation of a template.
614
-     *
615
-     * @return int
616
-     */
617
-    public function getPointer()
618
-    {
619
-        return $this->pointer;
620
-    }
621
-
622
-    /**
623
-     * Sets the line number.
624
-     *
625
-     * @param int  $number   the new line number
626
-     * @param bool $isOffset if set to true, the position acts as an offset and not an absolute position
627
-     */
628
-    public function setLine($number, $isOffset = false)
629
-    {
630
-        if ($isOffset) {
631
-            $this->line += $number;
632
-        } else {
633
-            $this->line = $number;
634
-        }
635
-    }
636
-
637
-    /**
638
-     * Returns the current line number, only available during compilation of a template.
639
-     *
640
-     * @return int
641
-     */
642
-    public function getLine()
643
-    {
644
-        return $this->line;
645
-    }
646
-
647
-    /**
648
-     * Returns the dwoo object that initiated this template compilation, only available during compilation of a
649
-     * template.
650
-     *
651
-     * @return Core
652
-     */
653
-    public function getCore()
654
-    {
655
-        return $this->core;
656
-    }
657
-
658
-    /**
659
-     * Overwrites the template that is being compiled.
660
-     *
661
-     * @param string $newSource   the template source that must replace the current one
662
-     * @param bool   $fromPointer if set to true, only the source from the current pointer position is replaced
663
-     *
664
-     * @return void
665
-     */
666
-    public function setTemplateSource($newSource, $fromPointer = false)
667
-    {
668
-        if ($fromPointer === true) {
669
-            $this->templateSource = substr($this->templateSource, 0, $this->pointer) . $newSource;
670
-        } else {
671
-            $this->templateSource = $newSource;
672
-        }
673
-    }
674
-
675
-    /**
676
-     * Returns the template that is being compiled.
677
-     *
678
-     * @param mixed $fromPointer if set to true, only the source from the current pointer
679
-     *                           position is returned, if a number is given it overrides the current pointer
680
-     *
681
-     * @return string the template or partial template
682
-     */
683
-    public function getTemplateSource($fromPointer = false)
684
-    {
685
-        if ($fromPointer === true) {
686
-            return substr($this->templateSource, $this->pointer);
687
-        } elseif (is_numeric($fromPointer)) {
688
-            return substr($this->templateSource, $fromPointer);
689
-        } else {
690
-            return $this->templateSource;
691
-        }
692
-    }
693
-
694
-    /**
695
-     * Resets the compilation pointer, effectively restarting the compilation process.
696
-     * this is useful if a plugin modifies the template source since it might need to be recompiled
697
-     */
698
-    public function recompile()
699
-    {
700
-        $this->setPointer(0);
701
-    }
702
-
703
-    /**
704
-     * Compiles the provided string down to php code.
705
-     *
706
-     * @param Core      $core
707
-     * @param ITemplate $template the template to compile
708
-     *
709
-     * @return string a compiled php string
710
-     * @throws CompilationException
711
-     */
712
-    public function compile(Core $core, ITemplate $template)
713
-    {
714
-        // init vars
715
-        //		$compiled = '';
716
-        $tpl                  = $template->getSource();
717
-        $ptr                  = 0;
718
-        $this->core           = $core;
719
-        $this->template       = $template;
720
-        $this->templateSource = &$tpl;
721
-        $this->pointer        = &$ptr;
722
-
723
-        while (true) {
724
-            // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed
725
-            if ($ptr === 0) {
726
-                // resets variables
727
-                $this->usedPlugins     = array();
728
-                $this->data            = array();
729
-                $this->scope           = &$this->data;
730
-                $this->scopeTree       = array();
731
-                $this->stack           = array();
732
-                $this->line            = 1;
733
-                $this->templatePlugins = array();
734
-                // add top level block
735
-                $compiled                 = $this->addBlock('TopLevelBlock', array(), 0);
736
-                $this->stack[0]['buffer'] = '';
737
-
738
-                if ($this->debug) {
739
-                    echo "\n";
740
-                    echo 'COMPILER INIT' . "\n";
741
-                }
742
-
743
-                if ($this->debug) {
744
-                    echo 'PROCESSING PREPROCESSORS (' . count($this->processors['pre']) . ')' . "\n";
745
-                }
746
-
747
-                // runs preprocessors
748
-                foreach ($this->processors['pre'] as $preProc) {
749
-                    if (is_array($preProc) && isset($preProc['autoload'])) {
750
-                        $preProc = $this->loadProcessor($preProc['class'], $preProc['name']);
751
-                    }
752
-                    if (is_array($preProc) && $preProc[0] instanceof Processor) {
753
-                        $tpl = call_user_func($preProc, $tpl);
754
-                    } else {
755
-                        $tpl = call_user_func($preProc, $this, $tpl);
756
-                    }
757
-                }
758
-                unset($preProc);
759
-
760
-                // show template source if debug
761
-                if ($this->debug) {
762
-                    echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>'."\n";
763
-                }
764
-
765
-                // strips php tags if required by the security policy
766
-                if ($this->securityPolicy !== null) {
767
-                    $search = array('{<\?php.*?\?>}');
768
-                    if (ini_get('short_open_tags')) {
769
-                        $search = array('{<\?.*?\?>}', '{<%.*?%>}');
770
-                    }
771
-                    switch ($this->securityPolicy->getPhpHandling()) {
772
-                        case SecurityPolicy::PHP_ALLOW:
773
-                            break;
774
-                        case SecurityPolicy::PHP_ENCODE:
775
-                            $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
776
-                            break;
777
-                        case SecurityPolicy::PHP_REMOVE:
778
-                            $tpl = preg_replace($search, '', $tpl);
779
-                    }
780
-                }
781
-            }
782
-
783
-            $pos = strpos($tpl, $this->ld, $ptr);
784
-
785
-            if ($pos === false) {
786
-                $this->push(substr($tpl, $ptr), 0);
787
-                break;
788
-            } elseif (substr($tpl, $pos - 1, 1) === '\\' && substr($tpl, $pos - 2, 1) !== '\\') {
789
-                $this->push(substr($tpl, $ptr, $pos - $ptr - 1) . $this->ld);
790
-                $ptr = $pos + strlen($this->ld);
791
-            } elseif (preg_match('/^' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', substr($tpl, $pos), $litOpen)) {
792
-                if (!preg_match('/' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
793
-                    throw new CompilationException($this, 'The {literal} blocks must be closed explicitly with {/literal}');
794
-                }
795
-                $endpos = $litClose[0][1];
796
-                $this->push(substr($tpl, $ptr, $pos - $ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos - $pos - strlen($litOpen[0])));
797
-                $ptr = $endpos + strlen($litClose[0][0]);
798
-            } else {
799
-                if (substr($tpl, $pos - 2, 1) === '\\' && substr($tpl, $pos - 1, 1) === '\\') {
800
-                    $this->push(substr($tpl, $ptr, $pos - $ptr - 1));
801
-                    $ptr = $pos;
802
-                }
803
-
804
-                $this->push(substr($tpl, $ptr, $pos - $ptr));
805
-                $ptr = $pos;
806
-
807
-                $pos += strlen($this->ld);
808
-                if ($this->allowLooseOpenings) {
809
-                    while (substr($tpl, $pos, 1) === ' ') {
810
-                        $pos += 1;
811
-                    }
812
-                } else {
813
-                    if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") {
814
-                        $ptr = $pos;
815
-                        $this->push($this->ld);
816
-                        continue;
817
-                    }
818
-                }
819
-
820
-                // check that there is an end tag present
821
-                if (strpos($tpl, $this->rd, $pos) === false) {
822
-                    throw new CompilationException($this, 'A template tag was not closed, started with "' . substr($tpl, $ptr, 30) . '"');
823
-                }
824
-
825
-                $ptr += strlen($this->ld);
826
-                $subptr = $ptr;
827
-
828
-                while (true) {
829
-                    $parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr);
830
-
831
-                    // reload loop if the compiler was reset
832
-                    if ($ptr === 0) {
833
-                        continue 2;
834
-                    }
835
-
836
-                    $len = $subptr - $ptr;
837
-                    $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n"));
838
-                    $ptr += $len;
839
-
840
-                    if ($parsed === false) {
841
-                        break;
842
-                    }
843
-                }
844
-            }
845
-        }
846
-
847
-        $compiled .= $this->removeBlock('TopLevelBlock');
848
-
849
-        if ($this->debug) {
850
-            echo 'PROCESSING POSTPROCESSORS' . "\n";
851
-        }
852
-
853
-        foreach ($this->processors['post'] as $postProc) {
854
-            if (is_array($postProc) && isset($postProc['autoload'])) {
855
-                $postProc = $this->loadProcessor($postProc['class'], $postProc['name']);
856
-            }
857
-            if (is_array($postProc) && $postProc[0] instanceof Processor) {
858
-                $compiled = call_user_func($postProc, $compiled);
859
-            } else {
860
-                $compiled = call_user_func($postProc, $this, $compiled);
861
-            }
862
-        }
863
-        unset($postProc);
864
-
865
-        if ($this->debug) {
866
-            echo 'COMPILATION COMPLETE : MEM USAGE : ' . memory_get_usage() . "\n";
867
-        }
868
-
869
-        $output = "<?php\n/* template head */\n";
870
-
871
-        // build plugin preloader
872
-        foreach ($this->getUsedPlugins() as $plugin => $type) {
873
-            if ($type & Core::CUSTOM_PLUGIN) {
874
-                continue;
875
-            }
876
-
877
-            switch ($type) {
878
-                case Core::CLASS_PLUGIN:
879
-                case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
880
-                    if (class_exists('Plugin' . $plugin) !== false) {
881
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
882
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
883
-                    } else {
884
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
885
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
886
-                    }
887
-                    break;
888
-                case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
889
-                    if (class_exists('Plugin' . $plugin) !== false) {
890
-                        $output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
891
-                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
892
-                    } else {
893
-                        $output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
894
-                            "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
895
-                    }
896
-                    break;
897
-                case Core::FUNC_PLUGIN:
898
-                    if (function_exists('Plugin' . $plugin) !== false) {
899
-                        $output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
900
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
901
-                    } else {
902
-                        $output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
903
-                        "\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
904
-                    }
905
-                    break;
906
-                case Core::SMARTY_MODIFIER:
907
-                    $output .= "if (function_exists('smarty_modifier_$plugin')===false)".
908
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
909
-                    break;
910
-                case Core::SMARTY_FUNCTION:
911
-                    $output .= "if (function_exists('smarty_function_$plugin')===false)".
912
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
913
-                    break;
914
-                case Core::SMARTY_BLOCK:
915
-                    $output .= "if (function_exists('smarty_block_$plugin')===false)".
916
-                    "\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
917
-                    break;
918
-                case Core::PROXY_PLUGIN:
919
-                    $output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
920
-                    break;
921
-                default:
922
-                    throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
923
-            }
924
-        }
925
-
926
-        foreach ($this->templatePlugins as $function => $attr) {
927
-            if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) {
928
-                $this->resolveSubTemplateDependencies($function);
929
-            }
930
-        }
931
-        foreach ($this->templatePlugins as $function) {
932
-            if (isset($function['called']) && $function['called'] === true) {
933
-                $output .= $function['body'] . PHP_EOL;
934
-            }
935
-        }
936
-
937
-        $output .= $compiled . "\n?>";
938
-
939
-        $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*' . preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/') . ')/', ";\n", $output);
940
-        $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);
941
-
942
-        // handle <?xml tag at the beginning
943
-        $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output);
944
-
945
-        // add another line break after PHP closing tags that have a line break following,
946
-        // as we do not know whether it's intended, and PHP will strip it otherwise
947
-        $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output);
948
-
949
-        if ($this->debug) {
950
-            echo '=============================================================================================' . "\n";
951
-            $lines = preg_split('{\r\n|\n|<br />}', $output);
952
-            array_shift($lines);
953
-            foreach ($lines as $i => $line) {
954
-                echo ($i + 1) . '. ' . $line . "\r\n";
955
-            }
956
-            echo '=============================================================================================' . "\n";
957
-        }
958
-
959
-        $this->template = $this->dwoo = null;
960
-        $tpl            = null;
961
-
962
-        return $output;
963
-    }
964
-
965
-    /**
966
-     * Checks what sub-templates are used in every sub-template so that we're sure they are all compiled.
967
-     *
968
-     * @param string $function the sub-template name
969
-     */
970
-    protected function resolveSubTemplateDependencies($function)
971
-    {
972
-        if ($this->debug) {
973
-            echo 'Compiler::' . __FUNCTION__ . "\n";
974
-        }
975
-
976
-        $body = $this->templatePlugins[$function]['body'];
977
-        foreach ($this->templatePlugins as $func => $attr) {
978
-            if ($func !== $function && !isset($attr['called']) && strpos($body, Core::NAMESPACE_PLUGINS_FUNCTIONS .
979
-            'Plugin' . Core::toCamelCase($func)) !== false) {
980
-                $this->templatePlugins[$func]['called'] = true;
981
-                $this->resolveSubTemplateDependencies($func);
982
-            }
983
-        }
984
-        $this->templatePlugins[$function]['checked'] = true;
985
-    }
986
-
987
-    /**
988
-     * Adds compiled content to the current block.
989
-     *
990
-     * @param string $content   the content to push
991
-     * @param int    $lineCount newlines count in content, optional
992
-     *
993
-     * @throws CompilationException
994
-     */
995
-    public function push($content, $lineCount = null)
996
-    {
997
-        if ($lineCount === null) {
998
-            $lineCount = substr_count($content, "\n");
999
-        }
1000
-
1001
-        if ($this->curBlock['buffer'] === null && count($this->stack) > 1) {
1002
-            // buffer is not initialized yet (the block has just been created)
1003
-            $this->stack[count($this->stack) - 2]['buffer'] .= (string)$content;
1004
-            $this->curBlock['buffer'] = '';
1005
-        } else {
1006
-            if (!isset($this->curBlock['buffer'])) {
1007
-                throw new CompilationException($this, 'The template has been closed too early, you probably have an extra block-closing tag somewhere');
1008
-            }
1009
-            // append current content to current block's buffer
1010
-            $this->curBlock['buffer'] .= (string)$content;
1011
-        }
1012
-        $this->line += $lineCount;
1013
-    }
1014
-
1015
-    /**
1016
-     * Sets the scope.
1017
-     * set to null if the scope becomes "unstable" (i.e. too variable or unknown) so that
1018
-     * variables are compiled in a more evaluative way than just $this->scope['key']
1019
-     *
1020
-     * @param mixed $scope    a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1021
-     * @param bool  $absolute if true, the scope is set from the top level scope and not from the current scope
1022
-     *
1023
-     * @return array the current scope tree
1024
-     */
1025
-    public function setScope($scope, $absolute = false)
1026
-    {
1027
-        $old = $this->scopeTree;
1028
-
1029
-        if ($scope === null) {
1030
-            unset($this->scope);
1031
-            $this->scope = null;
1032
-        }
1033
-
1034
-        if (is_array($scope) === false) {
1035
-            $scope = explode('.', $scope);
1036
-        }
1037
-
1038
-        if ($absolute === true) {
1039
-            $this->scope     = &$this->data;
1040
-            $this->scopeTree = array();
1041
-        }
1042
-
1043
-        while (($bit = array_shift($scope)) !== null) {
1044
-            if ($bit === '_parent' || $bit === '_') {
1045
-                array_pop($this->scopeTree);
1046
-                reset($this->scopeTree);
1047
-                $this->scope = &$this->data;
1048
-                $cnt         = count($this->scopeTree);
1049
-                for ($i = 0; $i < $cnt; ++ $i) {
1050
-                    $this->scope = &$this->scope[$this->scopeTree[$i]];
1051
-                }
1052
-            } elseif ($bit === '_root' || $bit === '__') {
1053
-                $this->scope     = &$this->data;
1054
-                $this->scopeTree = array();
1055
-            } elseif (isset($this->scope[$bit])) {
1056
-                $this->scope       = &$this->scope[$bit];
1057
-                $this->scopeTree[] = $bit;
1058
-            } else {
1059
-                $this->scope[$bit] = array();
1060
-                $this->scope       = &$this->scope[$bit];
1061
-                $this->scopeTree[] = $bit;
1062
-            }
1063
-        }
1064
-
1065
-        return $old;
1066
-    }
1067
-
1068
-    /**
1069
-     * Adds a block to the top of the block stack.
1070
-     *
1071
-     * @param string $type      block type (name)
1072
-     * @param array  $params    the parameters array
1073
-     * @param int    $paramtype the parameters type (see mapParams), 0, 1 or 2
1074
-     *
1075
-     * @return string the preProcessing() method's output
1076
-     */
1077
-    public function addBlock($type, array $params, $paramtype)
1078
-    {
1079
-        if ($this->debug) {
1080
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1081
-        }
1082
-
1083
-        $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1084
-        if (class_exists($class) === false) {
1085
-            $this->getCore()->getLoader()->loadPlugin($type);
1086
-        }
1087
-        $params = $this->mapParams($params, array($class, 'init'), $paramtype);
1088
-
1089
-        $this->stack[]  = array(
1090
-            'type'   => $type,
1091
-            'params' => $params,
1092
-            'custom' => false,
1093
-            'class'  => $class,
1094
-            'buffer' => null
1095
-        );
1096
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1097
-
1098
-        return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1099
-    }
1100
-
1101
-    /**
1102
-     * Adds a custom block to the top of the block stack.
1103
-     *
1104
-     * @param string $type      block type (name)
1105
-     * @param array  $params    the parameters array
1106
-     * @param int    $paramtype the parameters type (see mapParams), 0, 1 or 2
1107
-     *
1108
-     * @return string the preProcessing() method's output
1109
-     */
1110
-    public function addCustomBlock($type, array $params, $paramtype)
1111
-    {
1112
-        $callback = $this->customPlugins[$type]['callback'];
1113
-        if (is_array($callback)) {
1114
-            $class = is_object($callback[0]) ? get_class($callback[0]) : $callback[0];
1115
-        } else {
1116
-            $class = $callback;
1117
-        }
1118
-
1119
-        $params = $this->mapParams($params, array($class, 'init'), $paramtype);
1120
-
1121
-        $this->stack[]  = array(
1122
-            'type'   => $type,
1123
-            'params' => $params,
1124
-            'custom' => true,
1125
-            'class'  => $class,
1126
-            'buffer' => null
1127
-        );
1128
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1129
-
1130
-        return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1131
-    }
1132
-
1133
-    /**
1134
-     * Injects a block at the top of the plugin stack without calling its preProcessing method.
1135
-     * used by {else} blocks to re-add themselves after having closed everything up to their parent
1136
-     *
1137
-     * @param string $type   block type (name)
1138
-     * @param array  $params parameters array
1139
-     */
1140
-    public function injectBlock($type, array $params)
1141
-    {
1142
-        if ($this->debug) {
1143
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1144
-        }
1145
-
1146
-        $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1147
-        if (class_exists($class) === false) {
1148
-            $this->getCore()->getLoader()->loadPlugin($type);
1149
-        }
1150
-        $this->stack[]  = array(
1151
-            'type'   => $type,
1152
-            'params' => $params,
1153
-            'custom' => false,
1154
-            'class'  => $class,
1155
-            'buffer' => null
1156
-        );
1157
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1158
-    }
1159
-
1160
-    /**
1161
-     * Removes the closest-to-top block of the given type and all other
1162
-     * blocks encountered while going down the block stack.
1163
-     *
1164
-     * @param string $type block type (name)
1165
-     *
1166
-     * @return string the output of all postProcessing() method's return values of the closed blocks
1167
-     * @throws CompilationException
1168
-     */
1169
-    public function removeBlock($type)
1170
-    {
1171
-        if ($this->debug) {
1172
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1173
-        }
1174
-
1175
-        $output = '';
1176
-
1177
-        $pluginType = $this->getPluginType($type);
1178
-        if ($pluginType & Core::SMARTY_BLOCK) {
1179
-            $type = 'Smartyinterface';
1180
-        }
1181
-        while (true) {
1182
-            while ($top = array_pop($this->stack)) {
1183
-                if ($top['custom']) {
1184
-                    $class = $top['class'];
1185
-                } else {
1186
-                    $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($top['type']);
1187
-                }
1188
-                if (count($this->stack)) {
1189
-                    $this->curBlock = &$this->stack[count($this->stack) - 1];
1190
-                    $this->push(call_user_func(array(
1191
-                        $class,
1192
-                        'postProcessing'
1193
-                    ), $this, $top['params'], '', '', $top['buffer']), 0);
1194
-                } else {
1195
-                    $null           = null;
1196
-                    $this->curBlock = &$null;
1197
-                    $output         = call_user_func(
1198
-                        array(
1199
-                        $class,
1200
-                        'postProcessing'
1201
-                        ), $this, $top['params'], '', '', $top['buffer']
1202
-                    );
1203
-                }
1204
-
1205
-                if ($top['type'] === $type) {
1206
-                    break 2;
1207
-                }
1208
-            }
1209
-
1210
-            throw new CompilationException($this, 'Syntax malformation, a block of type "' . $type . '" was closed but was not opened');
1211
-        }
1212
-
1213
-        return $output;
1214
-    }
1215
-
1216
-    /**
1217
-     * Returns a reference to the first block of the given type encountered and
1218
-     * optionally closes all blocks until it finds it
1219
-     * this is mainly used by {else} plugins to close everything that was opened
1220
-     * between their parent and themselves.
1221
-     *
1222
-     * @param string $type       the block type (name)
1223
-     * @param bool   $closeAlong whether to close all blocks encountered while going down the block stack or not
1224
-     *
1225
-     * @return mixed &array the array is as such: array('type'=>pluginName, 'params'=>parameter array,
1226
-     *               'custom'=>bool defining whether it's a custom plugin or not, for internal use)
1227
-     * @throws CompilationException
1228
-     */
1229
-    public function &findBlock($type, $closeAlong = false)
1230
-    {
1231
-        if ($closeAlong === true) {
1232
-            while ($b = end($this->stack)) {
1233
-                if ($b['type'] === $type) {
1234
-                    return $this->stack[key($this->stack)];
1235
-                }
1236
-                $this->push($this->removeTopBlock(), 0);
1237
-            }
1238
-        } else {
1239
-            end($this->stack);
1240
-            while ($b = current($this->stack)) {
1241
-                if ($b['type'] === $type) {
1242
-                    return $this->stack[key($this->stack)];
1243
-                }
1244
-                prev($this->stack);
1245
-            }
1246
-        }
1247
-
1248
-        throw new CompilationException($this, 'A parent block of type "' . $type . '" is required and can not be found');
1249
-    }
1250
-
1251
-    /**
1252
-     * Returns a reference to the current block array.
1253
-     *
1254
-     * @return array the array is as such: array('type'=>pluginName, 'params'=>parameter array,
1255
-     *                'custom'=>bool defining whether it's a custom plugin or not, for internal use)
1256
-     */
1257
-    public function &getCurrentBlock()
1258
-    {
1259
-        return $this->curBlock;
1260
-    }
1261
-
1262
-    /**
1263
-     * Removes the block at the top of the stack and calls its postProcessing() method.
1264
-     *
1265
-     * @return string the postProcessing() method's output
1266
-     * @throws CompilationException
1267
-     */
1268
-    public function removeTopBlock()
1269
-    {
1270
-        if ($this->debug) {
1271
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1272
-        }
1273
-
1274
-        $o = array_pop($this->stack);
1275
-        if ($o === null) {
1276
-            throw new CompilationException($this, 'Syntax malformation, a block of unknown type was closed but was not opened.');
1277
-        }
1278
-        if ($o['custom']) {
1279
-            $class = $o['class'];
1280
-        } else {
1281
-            $class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($o['type']);
1282
-        }
1283
-
1284
-        $this->curBlock = &$this->stack[count($this->stack) - 1];
1285
-
1286
-        return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']);
1287
-    }
1288
-
1289
-    /**
1290
-     * Returns the compiled parameters (for example a variable's compiled parameter will be "$this->scope['key']") out
1291
-     * of the given parameter array.
1292
-     *
1293
-     * @param array $params parameter array
1294
-     *
1295
-     * @return array filtered parameters
1296
-     */
1297
-    public function getCompiledParams(array $params)
1298
-    {
1299
-        foreach ($params as $k => $p) {
1300
-            if (is_array($p)) {
1301
-                $params[$k] = $p[0];
1302
-            }
1303
-        }
1304
-
1305
-        return $params;
1306
-    }
1307
-
1308
-    /**
1309
-     * Returns the real parameters (for example a variable's real parameter will be its key, etc) out of the given
1310
-     * parameter array.
1311
-     *
1312
-     * @param array $params parameter array
1313
-     *
1314
-     * @return array filtered parameters
1315
-     */
1316
-    public function getRealParams(array $params)
1317
-    {
1318
-        foreach ($params as $k => $p) {
1319
-            if (is_array($p)) {
1320
-                $params[$k] = $p[1];
1321
-            }
1322
-        }
1323
-
1324
-        return $params;
1325
-    }
1326
-
1327
-    /**
1328
-     * Returns the token of each parameter out of the given parameter array.
1329
-     *
1330
-     * @param array $params parameter array
1331
-     *
1332
-     * @return array tokens
1333
-     */
1334
-    public function getParamTokens(array $params)
1335
-    {
1336
-        foreach ($params as $k => $p) {
1337
-            if (is_array($p)) {
1338
-                $params[$k] = isset($p[2]) ? $p[2] : 0;
1339
-            }
1340
-        }
1341
-
1342
-        return $params;
1343
-    }
1344
-
1345
-    /**
1346
-     * Entry point of the parser, it redirects calls to other parse* functions.
1347
-     *
1348
-     * @param string $in            the string within which we must parse something
1349
-     * @param int    $from          the starting offset of the parsed area
1350
-     * @param int    $to            the ending offset of the parsed area
1351
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
1352
-     *                              default
1353
-     * @param string $curBlock      the current parser-block being processed
1354
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
1355
-     *                              or null by default
1356
-     *
1357
-     * @return string parsed values
1358
-     * @throws CompilationException
1359
-     */
1360
-    protected function parse($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1361
-    {
1362
-        if ($this->debug) {
1363
-            echo 'Compiler::' . __FUNCTION__ . "\n";
1364
-        }
1365
-
1366
-        if ($to === null) {
1367
-            $to = strlen($in);
1368
-        }
1369
-        $first = substr($in, $from, 1);
1370
-
1371
-        if ($first === false) {
1372
-            throw new CompilationException($this, 'Unexpected EOF, a template tag was not closed');
1373
-        }
1374
-
1375
-        while ($first === ' ' || $first === "\n" || $first === "\t" || $first === "\r") {
1376
-            if ($curBlock === 'root' && substr($in, $from, strlen($this->rd)) === $this->rd) {
1377
-                // end template tag
1378
-                $pointer += strlen($this->rd);
1379
-                if ($this->debug) {
1380
-                    echo 'TEMPLATE PARSING ENDED' . "\n";
1381
-                }
1382
-
1383
-                return false;
1384
-            }
1385
-            ++ $from;
1386
-            if ($pointer !== null) {
1387
-                ++ $pointer;
1388
-            }
1389
-            if ($from >= $to) {
1390
-                if (is_array($parsingParams)) {
1391
-                    return $parsingParams;
1392
-                } else {
1393
-                    return '';
1394
-                }
1395
-            }
1396
-            $first = $in[$from];
1397
-        }
1398
-
1399
-        $substr = substr($in, $from, $to - $from);
1400
-
1401
-        if ($this->debug) {
1402
-            echo 'PARSE CALL : PARSING "' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . '" @ ' . $from . ':' . $to . ' in ' . $curBlock . ' : pointer=' . $pointer . "\n";
1403
-        }
1404
-        $parsed = '';
1405
-
1406
-        if ($curBlock === 'root' && $first === '*') {
1407
-            $src      = $this->getTemplateSource();
1408
-            $startpos = $this->getPointer() - strlen($this->ld);
1409
-            if (substr($src, $startpos, strlen($this->ld)) === $this->ld) {
1410
-                if ($startpos > 0) {
1411
-                    do {
1412
-                        $char = substr($src, -- $startpos, 1);
1413
-                        if ($char == "\n") {
1414
-                            ++ $startpos;
1415
-                            $whitespaceStart = true;
1416
-                            break;
1417
-                        }
1418
-                    }
1419
-                    while ($startpos > 0 && ($char == ' ' || $char == "\t"));
1420
-                }
1421
-
1422
-                if (!isset($whitespaceStart)) {
1423
-                    $startpos = $this->getPointer();
1424
-                } else {
1425
-                    $pointer -= $this->getPointer() - $startpos;
1426
-                }
1427
-
1428
-                if ($this->allowNestedComments && strpos($src, $this->ld . '*', $this->getPointer()) !== false) {
1429
-                    $comOpen  = $this->ld . '*';
1430
-                    $comClose = '*' . $this->rd;
1431
-                    $level    = 1;
1432
-                    $ptr      = $this->getPointer();
1433
-
1434
-                    while ($level > 0 && $ptr < strlen($src)) {
1435
-                        $open  = strpos($src, $comOpen, $ptr);
1436
-                        $close = strpos($src, $comClose, $ptr);
1437
-
1438
-                        if ($open !== false && $close !== false) {
1439
-                            if ($open < $close) {
1440
-                                $ptr = $open + strlen($comOpen);
1441
-                                ++ $level;
1442
-                            } else {
1443
-                                $ptr = $close + strlen($comClose);
1444
-                                -- $level;
1445
-                            }
1446
-                        } elseif ($open !== false) {
1447
-                            $ptr = $open + strlen($comOpen);
1448
-                            ++ $level;
1449
-                        } elseif ($close !== false) {
1450
-                            $ptr = $close + strlen($comClose);
1451
-                            -- $level;
1452
-                        } else {
1453
-                            $ptr = strlen($src);
1454
-                        }
1455
-                    }
1456
-                    $endpos = $ptr - strlen('*' . $this->rd);
1457
-                } else {
1458
-                    $endpos = strpos($src, '*' . $this->rd, $startpos);
1459
-                    if ($endpos == false) {
1460
-                        throw new CompilationException($this, 'Un-ended comment');
1461
-                    }
1462
-                }
1463
-                $pointer += $endpos - $startpos + strlen('*' . $this->rd);
1464
-                if (isset($whitespaceStart) && preg_match('#^[\t ]*\r?\n#', substr($src, $endpos + strlen('*' . $this->rd)), $m)) {
1465
-                    $pointer += strlen($m[0]);
1466
-                    $this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer']) - ($this->getPointer() - $startpos - strlen($this->ld)));
1467
-                }
1468
-
1469
-                return false;
1470
-            }
1471
-        }
1472
-
1473
-        if ($first === '$') {
1474
-            // var
1475
-            $out    = $this->parseVar($in, $from, $to, $parsingParams, $curBlock, $pointer);
1476
-            $parsed = 'var';
1477
-        } elseif ($first === '%' && preg_match('#^%[a-z_\\\\]#i', $substr)) {
1478
-            // Short constant
1479
-            $out = $this->parseConst($in, $from, $to, $parsingParams, $curBlock, $pointer);
1480
-        } elseif (($first === '"' || $first === "'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) {
1481
-            // string
1482
-            $out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
1483
-        } elseif (preg_match('/^\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?(' . (is_array($parsingParams) || $curBlock != 'root' ? '' : '\s+[^(]|') . '\s*\(|\s*' . $this->rdr . '|\s*;)/i', $substr)) {
1484
-            // func
1485
-            $out    = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
1486
-            $parsed = 'func';
1487
-        } elseif ($first === ';') {
1488
-            // instruction end
1489
-            if ($this->debug) {
1490
-                echo 'END OF INSTRUCTION' . "\n";
1491
-            }
1492
-            if ($pointer !== null) {
1493
-                ++ $pointer;
1494
-            }
1495
-
1496
-            return $this->parse($in, $from + 1, $to, false, 'root', $pointer);
1497
-        } elseif ($curBlock === 'root' && preg_match('#^/([a-z_][a-z0-9_]*)?#i', $substr, $match)) {
1498
-            // close block
1499
-            if (!empty($match[1]) && $match[1] == 'else') {
1500
-                throw new CompilationException($this, 'Else blocks must not be closed explicitly, they are automatically closed when their parent block is closed');
1501
-            }
1502
-            if (!empty($match[1]) && $match[1] == 'elseif') {
1503
-                throw new CompilationException($this, 'Elseif blocks must not be closed explicitly, they are automatically closed when their parent block is closed or a new else/elseif block is declared after them');
1504
-            }
1505
-            if ($pointer !== null) {
1506
-                $pointer += strlen($match[0]);
1507
-            }
1508
-            if (empty($match[1])) {
1509
-                if ($this->curBlock['type'] == 'else' || $this->curBlock['type'] == 'elseif') {
1510
-                    $pointer -= strlen($match[0]);
1511
-                }
1512
-                if ($this->debug) {
1513
-                    echo 'TOP BLOCK CLOSED' . "\n";
1514
-                }
1515
-
1516
-                return $this->removeTopBlock();
1517
-            } else {
1518
-                if ($this->debug) {
1519
-                    echo 'BLOCK OF TYPE ' . $match[1] . ' CLOSED' . "\n";
1520
-                }
1521
-
1522
-                return $this->removeBlock($match[1]);
1523
-            }
1524
-        } elseif ($curBlock === 'root' && substr($substr, 0, strlen($this->rd)) === $this->rd) {
1525
-            // end template tag
1526
-            if ($this->debug) {
1527
-                echo 'TAG PARSING ENDED' . "\n";
1528
-            }
1529
-            $pointer += strlen($this->rd);
1530
-
1531
-            return false;
1532
-        } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*=' . ($curBlock === 'array' ? '>?' : '') . ')(?:\s+|[^=]).*#i', $substr, $match)) {
1533
-            // named parameter
1534
-            if ($this->debug) {
1535
-                echo 'NAMED PARAM FOUND' . "\n";
1536
-            }
1537
-            $len = strlen($match[1]);
1538
-            while (substr($in, $from + $len, 1) === ' ') {
1539
-                ++ $len;
1540
-            }
1541
-            if ($pointer !== null) {
1542
-                $pointer += $len;
1543
-            }
1544
-
1545
-            $output = array(
1546
-                trim($match[1], " \t\r\n=>'\""),
1547
-                $this->parse($in, $from + $len, $to, false, 'namedparam', $pointer)
1548
-            );
1549
-
1550
-            $parsingParams[] = $output;
1551
-
1552
-            return $parsingParams;
1553
-        } elseif (preg_match('#^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*::\$[a-z0-9_]+)#i', $substr, $match)) {
1554
-            // static member access
1555
-            $parsed = 'var';
1556
-            if (is_array($parsingParams)) {
1557
-                $parsingParams[] = array($match[1], $match[1]);
1558
-                $out             = $parsingParams;
1559
-            } else {
1560
-                $out = $match[1];
1561
-            }
1562
-            $pointer += strlen($match[1]);
1563
-        } elseif ($substr !== '' && (is_array($parsingParams) || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'expression')) {
1564
-            // unquoted string, bool or number
1565
-            $out = $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1566
-        } else {
1567
-            // parse error
1568
-            throw new CompilationException($this, 'Parse error in "' . substr($in, $from, $to - $from) . '"');
1569
-        }
1570
-
1571
-        if (empty($out)) {
1572
-            return '';
1573
-        }
1574
-
1575
-        $substr = substr($in, $pointer, $to - $pointer);
1576
-
1577
-        // var parsed, check if any var-extension applies
1578
-        if ($parsed === 'var') {
1579
-            if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) {
1580
-                if ($this->debug) {
1581
-                    echo 'PARSING POST-VAR EXPRESSION ' . $substr . "\n";
1582
-                }
1583
-                // parse expressions
1584
-                $pointer += strlen($match[0]) - 1;
1585
-                if (is_array($parsingParams)) {
1586
-                    if ($match[2] == '$') {
1587
-                        $expr = $this->parseVar($in, $pointer, $to, array(), $curBlock, $pointer);
1588
-                    } else {
1589
-                        $expr = $this->parse($in, $pointer, $to, array(), 'expression', $pointer);
1590
-                    }
1591
-                    $out[count($out) - 1][0] .= $match[1] . $expr[0][0];
1592
-                    $out[count($out) - 1][1] .= $match[1] . $expr[0][1];
1593
-                } else {
1594
-                    if ($match[2] == '$') {
1595
-                        $expr = $this->parseVar($in, $pointer, $to, false, $curBlock, $pointer);
1596
-                    } else {
1597
-                        $expr = $this->parse($in, $pointer, $to, false, 'expression', $pointer);
1598
-                    }
1599
-                    if (is_array($out) && is_array($expr)) {
1600
-                        $out[0] .= $match[1] . $expr[0];
1601
-                        $out[1] .= $match[1] . $expr[1];
1602
-                    } elseif (is_array($out)) {
1603
-                        $out[0] .= $match[1] . $expr;
1604
-                        $out[1] .= $match[1] . $expr;
1605
-                    } elseif (is_array($expr)) {
1606
-                        $out .= $match[1] . $expr[0];
1607
-                    } else {
1608
-                        $out .= $match[1] . $expr;
1609
-                    }
1610
-                }
1611
-            } elseif ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) {
1612
-                if ($this->debug) {
1613
-                    echo 'PARSING POST-VAR ASSIGNMENT ' . $substr . "\n";
1614
-                }
1615
-                // parse assignment
1616
-                $value    = $match[2];
1617
-                $operator = trim($match[1]);
1618
-                if (substr($value, 0, 1) == '=') {
1619
-                    throw new CompilationException($this, 'Unexpected "=" in <em>' . $substr . '</em>');
1620
-                }
1621
-
1622
-                if ($pointer !== null) {
1623
-                    $pointer += strlen($match[1]);
1624
-                }
1625
-
1626
-                if ($operator !== '++' && $operator !== '--') {
1627
-                    $parts = array();
1628
-                    $ptr   = 0;
1629
-                    $parts = $this->parse($value, 0, strlen($value), $parts, 'condition', $ptr);
1630
-                    $pointer += $ptr;
1631
-
1632
-                    // load if plugin
1633
-                    try {
1634
-                        $this->getPluginType('if');
1635
-                    }
1636
-                    catch (Exception $e) {
1637
-                        throw new CompilationException($this, 'Assignments require the "if" plugin to be accessible');
1638
-                    }
1639
-
1640
-                    $parts  = $this->mapParams($parts, array(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf', 'init'), 1);
1641
-                    $tokens = $this->getParamTokens($parts);
1642
-                    $parts  = $this->getCompiledParams($parts);
1643
-
1644
-                    $value = PluginIf::replaceKeywords($parts['*'], $tokens['*'], $this);
1645
-                    $echo  = '';
1646
-                } else {
1647
-                    $value = array();
1648
-                    $echo  = 'echo ';
1649
-                }
1650
-
1651
-                if ($this->autoEscape) {
1652
-                    $out = preg_replace('#\(is_string\(\$tmp=(.+?)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#', '$1', $out);
1653
-                }
1654
-                $out = self::PHP_OPEN . $echo . $out . $operator . implode(' ', $value) . self::PHP_CLOSE;
1655
-            } elseif ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) {
1656
-                // parse namedparam with var as name (only for array)
1657
-                if ($this->debug) {
1658
-                    echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND' . "\n";
1659
-                }
1660
-                $len = strlen($match[1]);
1661
-                $var = $out[count($out) - 1];
1662
-                $pointer += $len;
1663
-
1664
-                $output = array($var[0], $this->parse($substr, $len, null, false, 'namedparam', $pointer));
1665
-
1666
-                $parsingParams[] = $output;
1667
-
1668
-                return $parsingParams;
1669
-            }
1670
-        }
1671
-
1672
-        if ($curBlock !== 'modifier' && ($parsed === 'func' || $parsed === 'var') && preg_match('#^(\|@?[a-z0-9_]+(:.*)?)+#i', $substr, $match)) {
1673
-            // parse modifier on funcs or vars
1674
-            $srcPointer = $pointer;
1675
-            if (is_array($parsingParams)) {
1676
-                $tmp                     = $this->replaceModifiers(
1677
-                    array(
1678
-                    null,
1679
-                    null,
1680
-                    $out[count($out) - 1][0],
1681
-                    $match[0]
1682
-                    ), $curBlock, $pointer
1683
-                );
1684
-                $out[count($out) - 1][0] = $tmp;
1685
-                $out[count($out) - 1][1] .= substr($substr, $srcPointer, $srcPointer - $pointer);
1686
-            } else {
1687
-                $out = $this->replaceModifiers(array(null, null, $out, $match[0]), $curBlock, $pointer);
1688
-            }
1689
-        }
1690
-
1691
-        // func parsed, check if any func-extension applies
1692
-        if ($parsed === 'func' && preg_match('#^->[a-z0-9_]+(\s*\(.+|->[a-z_].*)?#is', $substr, $match)) {
1693
-            // parse method call or property read
1694
-            $ptr = 0;
1695
-
1696
-            if (is_array($parsingParams)) {
1697
-                $output = $this->parseMethodCall($out[count($out) - 1][1], $match[0], $curBlock, $ptr);
1698
-
1699
-                $out[count($out) - 1][0] = $output;
1700
-                $out[count($out) - 1][1] .= substr($match[0], 0, $ptr);
1701
-            } else {
1702
-                $out = $this->parseMethodCall($out, $match[0], $curBlock, $ptr);
1703
-            }
1704
-
1705
-            $pointer += $ptr;
1706
-        }
1707
-
1708
-        if ($curBlock === 'root' && substr($out, 0, strlen(self::PHP_OPEN)) !== self::PHP_OPEN) {
1709
-            return self::PHP_OPEN . 'echo ' . $out . ';' . self::PHP_CLOSE;
1710
-        }
1711
-
1712
-        return $out;
1713
-    }
1714
-
1715
-    /**
1716
-     * Parses a function call.
1717
-     *
1718
-     * @param string $in            the string within which we must parse something
1719
-     * @param int    $from          the starting offset of the parsed area
1720
-     * @param int    $to            the ending offset of the parsed area
1721
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
1722
-     *                              default
1723
-     * @param string $curBlock      the current parser-block being processed
1724
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
1725
-     *                              or null by default
1726
-     *
1727
-     * @return string parsed values
1728
-     * @throws CompilationException
1729
-     * @throws Exception
1730
-     * @throws SecurityException
1731
-     */
1732
-    protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1733
-    {
1734
-        $output = '';
1735
-        $cmdstr = substr($in, $from, $to - $from);
1736
-        preg_match('/^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?)(\s*' . $this->rdr . '|\s*;)?/i', $cmdstr, $match);
1737
-
1738
-        if (empty($match[1])) {
1739
-            throw new CompilationException($this, 'Parse error, invalid function name : ' . substr($cmdstr, 0, 15));
1740
-        }
1741
-
1742
-        $func = $match[1];
1743
-
1744
-        if (!empty($match[2])) {
1745
-            $cmdstr = $match[1];
1746
-        }
1747
-
1748
-        if ($this->debug) {
1749
-            echo 'FUNC FOUND (' . $func . ')' . "\n";
1750
-        }
1751
-
1752
-        $paramsep = '';
1753
-
1754
-        if (is_array($parsingParams) || $curBlock != 'root') {
1755
-            $paramspos = strpos($cmdstr, '(');
1756
-            $paramsep  = ')';
1757
-        } elseif (preg_match_all('#^\s*[\\\\:a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) {
1758
-            $paramspos = $match[1][0][1];
1759
-            $paramsep  = substr($match[1][0][0], - 1) === '(' ? ')' : '';
1760
-            if ($paramsep === ')') {
1761
-                $paramspos += strlen($match[1][0][0]) - 1;
1762
-                if (substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') {
1763
-                    $paramsep = '';
1764
-                    if (strlen($match[1][0][0]) > 1) {
1765
-                        -- $paramspos;
1766
-                    }
1767
-                }
1768
-            }
1769
-        } else {
1770
-            $paramspos = false;
1771
-        }
1772
-
1773
-        $state = 0;
1774
-
1775
-        if ($paramspos === false) {
1776
-            $params = array();
1777
-
1778
-            if ($curBlock !== 'root') {
1779
-                return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1780
-            }
1781
-        } else {
1782
-            if ($curBlock === 'condition') {
1783
-                // load if plugin
1784
-                $this->getPluginType('if');
1785
-
1786
-                if (PluginIf::replaceKeywords(array($func), array(self::T_UNQUOTED_STRING), $this) !== array($func)) {
1787
-                    return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1788
-                }
1789
-            }
1790
-            $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos - strlen($func)));
1791
-            $paramstr   = substr($cmdstr, $paramspos + 1);
1792
-            if (substr($paramstr, - 1, 1) === $paramsep) {
1793
-                $paramstr = substr($paramstr, 0, - 1);
1794
-            }
1795
-
1796
-            if (strlen($paramstr) === 0) {
1797
-                $params   = array();
1798
-                $paramstr = '';
1799
-            } else {
1800
-                $ptr    = 0;
1801
-                $params = array();
1802
-                if ($func === 'empty') {
1803
-                    $params = $this->parseVar($paramstr, $ptr, strlen($paramstr), $params, 'root', $ptr);
1804
-                } else {
1805
-                    while ($ptr < strlen($paramstr)) {
1806
-                        while (true) {
1807
-                            if ($ptr >= strlen($paramstr)) {
1808
-                                break 2;
1809
-                            }
1810
-
1811
-                            if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') {
1812
-                                if ($this->debug) {
1813
-                                    echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT ' . $ptr . "\n";
1814
-                                }
1815
-                                break 2;
1816
-                            } elseif ($paramstr[$ptr] === ';') {
1817
-                                ++ $ptr;
1818
-                                if ($this->debug) {
1819
-                                    echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT ' . $ptr . "\n";
1820
-                                }
1821
-                                break 2;
1822
-                            } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') {
1823
-                                if ($this->debug) {
1824
-                                    echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT ' . $ptr . "\n";
1825
-                                }
1826
-                                break 2;
1827
-                            } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
1828
-                                if ($this->debug) {
1829
-                                    echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT ' . $ptr . "\n";
1830
-                                }
1831
-                                break 2;
1832
-                            }
1833
-
1834
-                            if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === ',' || $paramstr[$ptr] === "\r" || $paramstr[$ptr] === "\n" || $paramstr[$ptr] === "\t") {
1835
-                                ++ $ptr;
1836
-                            } else {
1837
-                                break;
1838
-                            }
1839
-                        }
1840
-
1841
-                        if ($this->debug) {
1842
-                            echo 'FUNC START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
1843
-                        }
1844
-
1845
-                        if ($func === 'if' || $func === 'elseif' || $func === 'tif') {
1846
-                            $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr);
1847
-                        } elseif ($func === 'array') {
1848
-                            $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'array', $ptr);
1849
-                        } else {
1850
-                            $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr);
1851
-                        }
1852
-
1853
-                        if ($this->debug) {
1854
-                            echo 'PARAM PARSED, POINTER AT ' . $ptr . ' (' . substr($paramstr, $ptr - 1, 3) . ')' . "\n";
1855
-                        }
1856
-                    }
1857
-                }
1858
-                $paramstr = substr($paramstr, 0, $ptr);
1859
-                $state    = 0;
1860
-                foreach ($params as $k => $p) {
1861
-                    if (is_array($p) && is_array($p[1])) {
1862
-                        $state |= 2;
1863
-                    } else {
1864
-                        if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m) && $func !== 'array') {
1865
-                            $params[$k] = array($m[2], array('true', 'true'));
1866
-                        } else {
1867
-                            if ($state & 2 && $func !== 'array') {
1868
-                                throw new CompilationException($this, 'You can not use an unnamed parameter after a named one');
1869
-                            }
1870
-                            $state |= 1;
1871
-                        }
1872
-                    }
1873
-                }
1874
-            }
1875
-        }
1876
-
1877
-        if ($pointer !== null) {
1878
-            $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0);
1879
-            if ($this->debug) {
1880
-                echo 'FUNC ADDS ' . ((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)) . ' TO POINTER' . "\n";
1881
-            }
1882
-        }
1883
-
1884
-        if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) {
1885
-            // handle static method calls with security policy
1886
-            if (strstr($func, '::') !== false && $this->securityPolicy !== null && $this->securityPolicy->isMethodAllowed(explode('::', strtolower($func))) !== true) {
1887
-                throw new SecurityException('Call to a disallowed php function : ' . $func);
1888
-            }
1889
-            $pluginType = Core::NATIVE_PLUGIN;
1890
-        } else {
1891
-            $pluginType = $this->getPluginType($func);
1892
-        }
1893
-
1894
-        // Blocks plugin
1895
-        if ($pluginType & Core::BLOCK_PLUGIN) {
1896
-            if ($curBlock !== 'root' || is_array($parsingParams)) {
1897
-                throw new CompilationException($this, 'Block plugins can not be used as other plugin\'s arguments');
1898
-            }
1899
-            if ($pluginType & Core::CUSTOM_PLUGIN) {
1900
-                return $this->addCustomBlock($func, $params, $state);
1901
-            } else {
1902
-                return $this->addBlock($func, $params, $state);
1903
-            }
1904
-        } elseif ($pluginType & Core::SMARTY_BLOCK) {
1905
-            if ($curBlock !== 'root' || is_array($parsingParams)) {
1906
-                throw new CompilationException($this, 'Block plugins can not be used as other plugin\'s arguments');
1907
-            }
1908
-
1909
-            if ($state & 2) {
1910
-                array_unshift($params, array('__functype', array($pluginType, $pluginType)));
1911
-                array_unshift($params, array('__funcname', array($func, $func)));
1912
-            } else {
1913
-                array_unshift($params, array($pluginType, $pluginType));
1914
-                array_unshift($params, array($func, $func));
1915
-            }
1916
-
1917
-            return $this->addBlock('smartyinterface', $params, $state);
1918
-        }
1919
-
1920
-        // Native & Smarty plugins
1921
-        if ($pluginType & Core::NATIVE_PLUGIN || $pluginType & Core::SMARTY_FUNCTION || $pluginType & Core::SMARTY_BLOCK) {
1922
-            $params = $this->mapParams($params, null, $state);
1923
-        } // PHP class plugin
1924
-        elseif ($pluginType & Core::CLASS_PLUGIN) {
1925
-            if ($pluginType & Core::CUSTOM_PLUGIN) {
1926
-                $params = $this->mapParams(
1927
-                    $params, array(
1928
-                    $this->customPlugins[$func]['class'],
1929
-                    $this->customPlugins[$func]['function']
1930
-                ), $state);
1931
-            } else {
1932
-                if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
1933
-                    $params = $this->mapParams($params, array(
1934
-                        'Plugin' . Core::toCamelCase($func),
1935
-                        ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1936
-                    ), $state);
1937
-                } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
1938
-                    $params = $this->mapParams($params, array(
1939
-                        Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func),
1940
-                        ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1941
-                    ), $state);
1942
-                } else {
1943
-                    $params = $this->mapParams($params, array(
1944
-                        Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
1945
-                        ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1946
-                    ), $state);
1947
-                }
1948
-            }
1949
-        } // PHP function plugin
1950
-        elseif ($pluginType & Core::FUNC_PLUGIN) {
1951
-            if ($pluginType & Core::CUSTOM_PLUGIN) {
1952
-                $params = $this->mapParams($params, $this->customPlugins[$func]['callback'], $state);
1953
-            } else {
1954
-                // Custom plugin
1955
-                if (function_exists('Plugin' . Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ?
1956
-                        'Compile' : '')) !== false) {
1957
-                    $params = $this->mapParams($params, 'Plugin' . Core::toCamelCase($func) . (($pluginType &
1958
-                            Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1959
-                } // Builtin helper plugin
1960
-                elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . (
1961
-                    ($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '')) !== false) {
1962
-                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase
1963
-                        ($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1964
-                } // Builtin function plugin
1965
-                else {
1966
-                    $params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase
1967
-                        ($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1968
-                }
1969
-            }
1970
-        } // Smarty modifier
1971
-        elseif ($pluginType & Core::SMARTY_MODIFIER) {
1972
-            $output = 'smarty_modifier_' . $func . '(' . implode(', ', $params) . ')';
1973
-        } // Proxy plugin
1974
-        elseif ($pluginType & Core::PROXY_PLUGIN) {
1975
-            $params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
1976
-        } // Template plugin
1977
-        elseif ($pluginType & Core::TEMPLATE_PLUGIN) {
1978
-            // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))
1979
-            $map = array();
1980
-            foreach ($this->templatePlugins[$func]['params'] as $param => $defValue) {
1981
-                if ($param == 'rest') {
1982
-                    $param = '*';
1983
-                }
1984
-                $hasDefault = $defValue !== null;
1985
-                if ($defValue === 'null') {
1986
-                    $defValue = null;
1987
-                } elseif ($defValue === 'false') {
1988
-                    $defValue = false;
1989
-                } elseif ($defValue === 'true') {
1990
-                    $defValue = true;
1991
-                } elseif (preg_match('#^([\'"]).*?\1$#', $defValue)) {
1992
-                    $defValue = substr($defValue, 1, - 1);
1993
-                }
1994
-                $map[] = array($param, $hasDefault, $defValue);
1995
-            }
1996
-
1997
-            $params = $this->mapParams($params, null, $state, $map);
1998
-        }
1999
-
2000
-        // only keep php-syntax-safe values for non-block plugins
2001
-        $tokens = array();
2002
-        foreach ($params as $k => $p) {
2003
-            $tokens[$k] = isset($p[2]) ? $p[2] : 0;
2004
-            $params[$k] = $p[0];
2005
-        }
2006
-
2007
-        // Native plugin
2008
-        if ($pluginType & Core::NATIVE_PLUGIN) {
2009
-            if ($func === 'do') {
2010
-                $output = '';
2011
-                if (isset($params['*'])) {
2012
-                    $output = implode(';', $params['*']) . ';';
2013
-                }
2014
-
2015
-                if (is_array($parsingParams) || $curBlock !== 'root') {
2016
-                    throw new CompilationException($this, 'Do can not be used inside another function or block');
2017
-                }
2018
-
2019
-                return self::PHP_OPEN . $output . self::PHP_CLOSE;
2020
-            } else {
2021
-                if (isset($params['*'])) {
2022
-                    $output = $func . '(' . implode(', ', $params['*']) . ')';
2023
-                } else {
2024
-                    $output = $func . '()';
2025
-                }
2026
-            }
2027
-        } // Block class OR Function class
2028
-        elseif ($pluginType & Core::CLASS_PLUGIN || ($pluginType & Core::FUNC_PLUGIN && $pluginType & Core::CLASS_PLUGIN)) {
2029
-            if ($pluginType & Core::COMPILABLE_PLUGIN) {
2030
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
2031
-                    $callback = $this->customPlugins[$func]['callback'];
2032
-                    if (!is_array($callback)) {
2033
-                        if (!method_exists($callback, 'compile')) {
2034
-                            throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
2035
-                        }
2036
-                        if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
2037
-                            $funcCompiler = array($callback, 'compile');
2038
-                        } else {
2039
-                            $funcCompiler = array(new $callback(), 'compile');
2040
-                        }
2041
-                    } else {
2042
-                        $funcCompiler = $callback;
2043
-                    }
2044
-                } else {
2045
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2046
-                        $funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
2047
-                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2048
-                        $funcCompiler = array(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func), 'compile');
2049
-                    } else {
2050
-                        $funcCompiler = array(
2051
-                            Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
2052
-                            'compile'
2053
-                        );
2054
-                    }
2055
-                    array_unshift($params, $this);
2056
-                }
2057
-                // @TODO: Is it a real fix ?
2058
-                if ($func === 'tif') {
2059
-                    $params[] = $tokens;
2060
-                }
2061
-                $output = call_user_func_array($funcCompiler, $params);
2062
-            } else {
2063
-                $params = self::implode_r($params);
2064
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
2065
-                    $callback = $this->customPlugins[$func]['callback'];
2066
-                    if (!is_array($callback)) {
2067
-                        if (!method_exists($callback, 'process')) {
2068
-                            throw new Exception('Custom plugin ' . $func . ' must implement the "process" method to be usable, or you should provide a full callback to the method to use');
2069
-                        }
2070
-                        if (is_object($callback)) {
2071
-                            $callback = get_class($callback);
2072
-                        }
2073
-                        if (($ref = new ReflectionMethod($callback, 'process')) && $ref->isStatic()) {
2074
-                            $output = 'call_user_func(array(\'' . $callback . '\', \'process\'), ' . $params . ')';
2075
-                        } else {
2076
-                            $output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback . '\'), \'process\'), ' . $params . ')';
2077
-                        }
2078
-                    } elseif (is_object($callback[0])) {
2079
-                        $output = 'call_user_func(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), ' . $params . ')';
2080
-                    } elseif (($ref = new ReflectionMethod($callback[0], $callback[1])) && $ref->isStatic()) {
2081
-                        $output = 'call_user_func(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), ' . $params . ')';
2082
-                    } else {
2083
-                        $output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback[0] . '\'), \'' . $callback[1] . '\'), ' . $params . ')';
2084
-                    }
2085
-                    if (empty($params)) {
2086
-                        $output = substr($output, 0, - 3) . ')';
2087
-                    }
2088
-                } else {
2089
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2090
-                        $output = '$this->classCall(\'Plugin' . $func . '\', array(' . $params . '))';
2091
-                    } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2092
-                        $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', 
34
+	/**
35
+	 * Constant that represents a php opening tag.
36
+	 * use it in case it needs to be adjusted
37
+	 *
38
+	 * @var string
39
+	 */
40
+	const PHP_OPEN = '<?php ';
41
+
42
+	/**
43
+	 * Constant that represents a php closing tag.
44
+	 * use it in case it needs to be adjusted
45
+	 *
46
+	 * @var string
47
+	 */
48
+	const PHP_CLOSE = '?>';
49
+
50
+	/**
51
+	 * Boolean flag to enable or disable debugging output.
52
+	 *
53
+	 * @var bool
54
+	 */
55
+	public $debug = false;
56
+
57
+	/**
58
+	 * Left script delimiter.
59
+	 *
60
+	 * @var string
61
+	 */
62
+	protected $ld = '{';
63
+
64
+	/**
65
+	 * Left script delimiter with escaped regex meta characters.
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $ldr = '\\{';
70
+
71
+	/**
72
+	 * Right script delimiter.
73
+	 *
74
+	 * @var string
75
+	 */
76
+	protected $rd = '}';
77
+
78
+	/**
79
+	 * Right script delimiter with escaped regex meta characters.
80
+	 *
81
+	 * @var string
82
+	 */
83
+	protected $rdr = '\\}';
84
+
85
+	/**
86
+	 * Defines whether the nested comments should be parsed as nested or not.
87
+	 * defaults to false (classic block comment parsing as in all languages)
88
+	 *
89
+	 * @var bool
90
+	 */
91
+	protected $allowNestedComments = false;
92
+
93
+	/**
94
+	 * Defines whether opening and closing tags can contain spaces before valid data or not.
95
+	 * turn to true if you want to be sloppy with the syntax, but when set to false it allows
96
+	 * to skip javascript and css tags as long as they are in the form "{ something", which is
97
+	 * nice. default is false.
98
+	 *
99
+	 * @var bool
100
+	 */
101
+	protected $allowLooseOpenings = false;
102
+
103
+	/**
104
+	 * Defines whether the compiler will automatically html-escape variables or not.
105
+	 * default is false
106
+	 *
107
+	 * @var bool
108
+	 */
109
+	protected $autoEscape = false;
110
+
111
+	/**
112
+	 * Security policy object.
113
+	 *
114
+	 * @var SecurityPolicy
115
+	 */
116
+	protected $securityPolicy;
117
+
118
+	/**
119
+	 * Stores the custom plugins registered with this compiler.
120
+	 *
121
+	 * @var array
122
+	 */
123
+	protected $customPlugins = array();
124
+
125
+	/**
126
+	 * Stores the template plugins registered with this compiler.
127
+	 *
128
+	 * @var array
129
+	 */
130
+	protected $templatePlugins = array();
131
+
132
+	/**
133
+	 * Stores the pre- and post-processors callbacks.
134
+	 *
135
+	 * @var array
136
+	 */
137
+	protected $processors = array('pre' => array(), 'post' => array());
138
+
139
+	/**
140
+	 * Stores a list of plugins that are used in the currently compiled
141
+	 * template, and that are not compilable. these plugins will be loaded
142
+	 * during the template's runtime if required.
143
+	 * it is a 1D array formatted as key:pluginName value:pluginType
144
+	 *
145
+	 * @var array
146
+	 */
147
+	protected $usedPlugins;
148
+
149
+	/**
150
+	 * Stores the template undergoing compilation.
151
+	 *
152
+	 * @var string
153
+	 */
154
+	protected $template;
155
+
156
+	/**
157
+	 * Stores the current pointer position inside the template.
158
+	 *
159
+	 * @var int
160
+	 */
161
+	protected $pointer;
162
+
163
+	/**
164
+	 * Stores the current line count inside the template for debugging purposes.
165
+	 *
166
+	 * @var int
167
+	 */
168
+	protected $line;
169
+
170
+	/**
171
+	 * Stores the current template source while compiling it.
172
+	 *
173
+	 * @var string
174
+	 */
175
+	protected $templateSource;
176
+
177
+	/**
178
+	 * Stores the data within which the scope moves.
179
+	 *
180
+	 * @var array
181
+	 */
182
+	protected $data;
183
+
184
+	/**
185
+	 * Variable scope of the compiler, set to null if
186
+	 * it can not be resolved to a static string (i.e. if some
187
+	 * plugin defines a new scope based on a variable array key).
188
+	 *
189
+	 * @var mixed
190
+	 */
191
+	protected $scope;
192
+
193
+	/**
194
+	 * Variable scope tree, that allows to rebuild the current
195
+	 * scope if required, i.e. when going to a parent level.
196
+	 *
197
+	 * @var array
198
+	 */
199
+	protected $scopeTree;
200
+
201
+	/**
202
+	 * Block plugins stack, accessible through some methods.
203
+	 *
204
+	 * @see findBlock
205
+	 * @see getCurrentBlock
206
+	 * @see addBlock
207
+	 * @see addCustomBlock
208
+	 * @see injectBlock
209
+	 * @see removeBlock
210
+	 * @see removeTopBlock
211
+	 * @var array
212
+	 */
213
+	protected $stack = array();
214
+
215
+	/**
216
+	 * Current block at the top of the block plugins stack,
217
+	 * accessible through getCurrentBlock.
218
+	 *
219
+	 * @see getCurrentBlock
220
+	 * @var array
221
+	 */
222
+	protected $curBlock;
223
+
224
+	/**
225
+	 * Current dwoo object that uses this compiler, or null.
226
+	 *
227
+	 * @var Core
228
+	 */
229
+	public $core;
230
+
231
+	/**
232
+	 * Holds an instance of this class, used by getInstance when you don't
233
+	 * provide a custom compiler in order to save resources.
234
+	 *
235
+	 * @var Compiler
236
+	 */
237
+	protected static $instance;
238
+
239
+	/**
240
+	 * Token types.
241
+	 *
242
+	 * @var int
243
+	 */
244
+	const T_UNQUOTED_STRING = 1;
245
+	const T_NUMERIC         = 2;
246
+	const T_NULL            = 4;
247
+	const T_BOOL            = 8;
248
+	const T_MATH            = 16;
249
+	const T_BREAKCHAR       = 32;
250
+
251
+	/**
252
+	 * Compiler constructor.
253
+	 * saves the created instance so that child templates get the same one
254
+	 */
255
+	public function __construct()
256
+	{
257
+		self::$instance = $this;
258
+	}
259
+
260
+	/**
261
+	 * Sets the delimiters to use in the templates.
262
+	 * delimiters can be multi-character strings but should not be one of those as they will
263
+	 * make it very hard to work with templates or might even break the compiler entirely : "\", "$", "|", ":" and
264
+	 * finally "#" only if you intend to use config-vars with the #var# syntax.
265
+	 *
266
+	 * @param string $left  left delimiter
267
+	 * @param string $right right delimiter
268
+	 */
269
+	public function setDelimiters($left, $right)
270
+	{
271
+		$this->ld  = $left;
272
+		$this->rd  = $right;
273
+		$this->ldr = preg_quote($left, '/');
274
+		$this->rdr = preg_quote($right, '/');
275
+	}
276
+
277
+	/**
278
+	 * Returns the left and right template delimiters.
279
+	 *
280
+	 * @return array containing the left and the right delimiters
281
+	 */
282
+	public function getDelimiters()
283
+	{
284
+		return array($this->ld, $this->rd);
285
+	}
286
+
287
+	/**
288
+	 * Sets the way to handle nested comments, if set to true
289
+	 * {* foo {* some other *} comment *} will be stripped correctly.
290
+	 * if false it will remove {* foo {* some other *} and leave "comment *}" alone,
291
+	 * this is the default behavior
292
+	 *
293
+	 * @param bool $allow allow nested comments or not, defaults to true (but the default internal value is false)
294
+	 */
295
+	public function setNestedCommentsHandling($allow = true)
296
+	{
297
+		$this->allowNestedComments = (bool)$allow;
298
+	}
299
+
300
+	/**
301
+	 * Returns the nested comments handling setting.
302
+	 *
303
+	 * @see    setNestedCommentsHandling
304
+	 * @return bool true if nested comments are allowed
305
+	 */
306
+	public function getNestedCommentsHandling()
307
+	{
308
+		return $this->allowNestedComments;
309
+	}
310
+
311
+	/**
312
+	 * Sets the tag openings handling strictness, if set to true, template tags can
313
+	 * contain spaces before the first function/string/variable such as { $foo} is valid.
314
+	 * if set to false (default setting), { $foo} is invalid but that is however a good thing
315
+	 * as it allows css (i.e. #foo { color:red; }) to be parsed silently without triggering
316
+	 * an error, same goes for javascript.
317
+	 *
318
+	 * @param bool $allow true to allow loose handling, false to restore default setting
319
+	 */
320
+	public function setLooseOpeningHandling($allow = false)
321
+	{
322
+		$this->allowLooseOpenings = (bool)$allow;
323
+	}
324
+
325
+	/**
326
+	 * Returns the tag openings handling strictness setting.
327
+	 *
328
+	 * @see    setLooseOpeningHandling
329
+	 * @return bool true if loose tags are allowed
330
+	 */
331
+	public function getLooseOpeningHandling()
332
+	{
333
+		return $this->allowLooseOpenings;
334
+	}
335
+
336
+	/**
337
+	 * Changes the auto escape setting.
338
+	 * if enabled, the compiler will automatically html-escape variables,
339
+	 * unless they are passed through the safe function such as {$var|safe}
340
+	 * or {safe $var}
341
+	 * default setting is disabled/false
342
+	 *
343
+	 * @param bool $enabled set to true to enable, false to disable
344
+	 */
345
+	public function setAutoEscape($enabled)
346
+	{
347
+		$this->autoEscape = (bool)$enabled;
348
+	}
349
+
350
+	/**
351
+	 * Returns the auto escape setting.
352
+	 * default setting is disabled/false
353
+	 *
354
+	 * @return bool
355
+	 */
356
+	public function getAutoEscape()
357
+	{
358
+		return $this->autoEscape;
359
+	}
360
+
361
+	/**
362
+	 * Adds a preprocessor to the compiler, it will be called
363
+	 * before the template is compiled.
364
+	 *
365
+	 * @param mixed $callback either a valid callback to the preprocessor or a simple name if the autoload is set to
366
+	 *                        true
367
+	 * @param bool  $autoload if set to true, the preprocessor is auto-loaded from one of the plugin directories, else
368
+	 *                        you must provide a valid callback
369
+	 */
370
+	public function addPreProcessor($callback, $autoload = false)
371
+	{
372
+		if ($autoload) {
373
+			$name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', Core::toCamelCase($callback));
374
+			$class = Core::NAMESPACE_PLUGINS_PROCESSORS . $name;
375
+
376
+			if (class_exists($class)) {
377
+				$callback = array(new $class($this), 'process');
378
+			} elseif (function_exists($class)) {
379
+				$callback = $class;
380
+			} else {
381
+				$callback = array('autoload' => true, 'class' => $class, 'name' => $name);
382
+			}
383
+
384
+			$this->processors['pre'][] = $callback;
385
+		} else {
386
+			$this->processors['pre'][] = $callback;
387
+		}
388
+	}
389
+
390
+	/**
391
+	 * Removes a preprocessor from the compiler.
392
+	 *
393
+	 * @param mixed $callback either a valid callback to the preprocessor or a simple name if it was autoloaded
394
+	 */
395
+	public function removePreProcessor($callback)
396
+	{
397
+		if (($index = array_search($callback, $this->processors['pre'], true)) !== false) {
398
+			unset($this->processors['pre'][$index]);
399
+		} elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
400
+					$callback),
401
+				$this->processors['pre'], true)) !== false) {
402
+			unset($this->processors['pre'][$index]);
403
+		} else {
404
+			$class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
405
+			foreach ($this->processors['pre'] as $index => $proc) {
406
+				if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
407
+					unset($this->processors['pre'][$index]);
408
+					break;
409
+				}
410
+			}
411
+		}
412
+	}
413
+
414
+	/**
415
+	 * Adds a postprocessor to the compiler, it will be called
416
+	 * before the template is compiled.
417
+	 *
418
+	 * @param mixed $callback either a valid callback to the postprocessor or a simple name if the autoload is set to
419
+	 *                        true
420
+	 * @param bool  $autoload if set to true, the postprocessor is auto-loaded from one of the plugin directories, else
421
+	 *                        you must provide a valid callback
422
+	 */
423
+	public function addPostProcessor($callback, $autoload = false)
424
+	{
425
+		if ($autoload) {
426
+			$name  = str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
427
+			$class = Core::NAMESPACE_PLUGINS_PROCESSORS . Core::toCamelCase($name);
428
+
429
+			if (class_exists($class)) {
430
+				$callback = array(new $class($this), 'process');
431
+			} elseif (function_exists($class)) {
432
+				$callback = $class;
433
+			} else {
434
+				$callback = array('autoload' => true, 'class' => $class, 'name' => $name);
435
+			}
436
+
437
+			$this->processors['post'][] = $callback;
438
+		} else {
439
+			$this->processors['post'][] = $callback;
440
+		}
441
+	}
442
+
443
+	/**
444
+	 * Removes a postprocessor from the compiler.
445
+	 *
446
+	 * @param mixed $callback either a valid callback to the postprocessor or a simple name if it was autoloaded
447
+	 */
448
+	public function removePostProcessor($callback)
449
+	{
450
+		if (($index = array_search($callback, $this->processors['post'], true)) !== false) {
451
+			unset($this->processors['post'][$index]);
452
+		} elseif (($index = array_search(Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '',
453
+					$callback),
454
+				$this->processors['post'], true)) !== false) {
455
+			unset($this->processors['post'][$index]);
456
+		} else {
457
+			$class = Core::NAMESPACE_PLUGINS_PROCESSORS . str_replace(Core::NAMESPACE_PLUGINS_PROCESSORS, '', $callback);
458
+			foreach ($this->processors['post'] as $index => $proc) {
459
+				if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) {
460
+					unset($this->processors['post'][$index]);
461
+					break;
462
+				}
463
+			}
464
+		}
465
+	}
466
+
467
+	/**
468
+	 * Internal function to autoload processors at runtime if required.
469
+	 *
470
+	 * @param string $class the class/function name
471
+	 * @param string $name  the plugin name (without Dwoo_Plugin_ prefix)
472
+	 *
473
+	 * @return array|string
474
+	 * @throws Exception
475
+	 */
476
+	protected function loadProcessor($class, $name)
477
+	{
478
+		if (!class_exists($class) && !function_exists($class)) {
479
+			try {
480
+				$this->getCore()->getLoader()->loadPlugin($name);
481
+			}
482
+			catch (Exception $e) {
483
+				throw new Exception('Processor ' . $name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $name . '.php in the plugin directory');
484
+			}
485
+		}
486
+
487
+		if (class_exists($class)) {
488
+			return array(new $class($this), 'process');
489
+		}
490
+
491
+		if (function_exists($class)) {
492
+			return $class;
493
+		}
494
+
495
+		throw new Exception('Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"');
496
+	}
497
+
498
+	/**
499
+	 * Adds an used plugin, this is reserved for use by the {template} plugin.
500
+	 * this is required so that plugin loading bubbles up from loaded
501
+	 * template files to the current one
502
+	 *
503
+	 * @private
504
+	 *
505
+	 * @param string $name function name
506
+	 * @param int    $type plugin type (Core::*_PLUGIN)
507
+	 */
508
+	public function addUsedPlugin($name, $type)
509
+	{
510
+		$this->usedPlugins[$name] = $type;
511
+	}
512
+
513
+	/**
514
+	 * Returns all the plugins this template uses.
515
+	 *
516
+	 * @private
517
+	 * @return  array the list of used plugins in the parsed template
518
+	 */
519
+	public function getUsedPlugins()
520
+	{
521
+		return $this->usedPlugins;
522
+	}
523
+
524
+	/**
525
+	 * Adds a template plugin, this is reserved for use by the {template} plugin.
526
+	 * this is required because the template functions are not declared yet
527
+	 * during compilation, so we must have a way of validating their argument
528
+	 * signature without using the reflection api
529
+	 *
530
+	 * @private
531
+	 *
532
+	 * @param string $name   function name
533
+	 * @param array  $params parameter array to help validate the function call
534
+	 * @param string $uuid   unique id of the function
535
+	 * @param string $body   function php code
536
+	 */
537
+	public function addTemplatePlugin($name, array $params, $uuid, $body = null)
538
+	{
539
+		$this->templatePlugins[$name] = array('params' => $params, 'body' => $body, 'uuid' => $uuid);
540
+	}
541
+
542
+	/**
543
+	 * Returns all the parsed sub-templates.
544
+	 *
545
+	 * @private
546
+	 * @return  array the parsed sub-templates
547
+	 */
548
+	public function getTemplatePlugins()
549
+	{
550
+		return $this->templatePlugins;
551
+	}
552
+
553
+	/**
554
+	 * Marks a template plugin as being called, which means its source must be included in the compiled template.
555
+	 *
556
+	 * @param string $name function name
557
+	 */
558
+	public function useTemplatePlugin($name)
559
+	{
560
+		$this->templatePlugins[$name]['called'] = true;
561
+	}
562
+
563
+	/**
564
+	 * Adds the custom plugins loaded into Dwoo to the compiler so it can load them.
565
+	 *
566
+	 * @see Core::addPlugin
567
+	 *
568
+	 * @param array $customPlugins an array of custom plugins
569
+	 */
570
+	public function setCustomPlugins(array $customPlugins)
571
+	{
572
+		$this->customPlugins = $customPlugins;
573
+	}
574
+
575
+	/**
576
+	 * Sets the security policy object to enforce some php security settings.
577
+	 * use this if untrusted persons can modify templates,
578
+	 * set it on the Dwoo object as it will be passed onto the compiler automatically
579
+	 *
580
+	 * @param SecurityPolicy $policy the security policy object
581
+	 */
582
+	public function setSecurityPolicy(SecurityPolicy $policy = null)
583
+	{
584
+		$this->securityPolicy = $policy;
585
+	}
586
+
587
+	/**
588
+	 * Returns the current security policy object or null by default.
589
+	 *
590
+	 * @return SecurityPolicy|null the security policy object if any
591
+	 */
592
+	public function getSecurityPolicy()
593
+	{
594
+		return $this->securityPolicy;
595
+	}
596
+
597
+	/**
598
+	 * Sets the pointer position.
599
+	 *
600
+	 * @param int  $position the new pointer position
601
+	 * @param bool $isOffset if set to true, the position acts as an offset and not an absolute position
602
+	 */
603
+	public function setPointer($position, $isOffset = false)
604
+	{
605
+		if ($isOffset) {
606
+			$this->pointer += $position;
607
+		} else {
608
+			$this->pointer = $position;
609
+		}
610
+	}
611
+
612
+	/**
613
+	 * Returns the current pointer position, only available during compilation of a template.
614
+	 *
615
+	 * @return int
616
+	 */
617
+	public function getPointer()
618
+	{
619
+		return $this->pointer;
620
+	}
621
+
622
+	/**
623
+	 * Sets the line number.
624
+	 *
625
+	 * @param int  $number   the new line number
626
+	 * @param bool $isOffset if set to true, the position acts as an offset and not an absolute position
627
+	 */
628
+	public function setLine($number, $isOffset = false)
629
+	{
630
+		if ($isOffset) {
631
+			$this->line += $number;
632
+		} else {
633
+			$this->line = $number;
634
+		}
635
+	}
636
+
637
+	/**
638
+	 * Returns the current line number, only available during compilation of a template.
639
+	 *
640
+	 * @return int
641
+	 */
642
+	public function getLine()
643
+	{
644
+		return $this->line;
645
+	}
646
+
647
+	/**
648
+	 * Returns the dwoo object that initiated this template compilation, only available during compilation of a
649
+	 * template.
650
+	 *
651
+	 * @return Core
652
+	 */
653
+	public function getCore()
654
+	{
655
+		return $this->core;
656
+	}
657
+
658
+	/**
659
+	 * Overwrites the template that is being compiled.
660
+	 *
661
+	 * @param string $newSource   the template source that must replace the current one
662
+	 * @param bool   $fromPointer if set to true, only the source from the current pointer position is replaced
663
+	 *
664
+	 * @return void
665
+	 */
666
+	public function setTemplateSource($newSource, $fromPointer = false)
667
+	{
668
+		if ($fromPointer === true) {
669
+			$this->templateSource = substr($this->templateSource, 0, $this->pointer) . $newSource;
670
+		} else {
671
+			$this->templateSource = $newSource;
672
+		}
673
+	}
674
+
675
+	/**
676
+	 * Returns the template that is being compiled.
677
+	 *
678
+	 * @param mixed $fromPointer if set to true, only the source from the current pointer
679
+	 *                           position is returned, if a number is given it overrides the current pointer
680
+	 *
681
+	 * @return string the template or partial template
682
+	 */
683
+	public function getTemplateSource($fromPointer = false)
684
+	{
685
+		if ($fromPointer === true) {
686
+			return substr($this->templateSource, $this->pointer);
687
+		} elseif (is_numeric($fromPointer)) {
688
+			return substr($this->templateSource, $fromPointer);
689
+		} else {
690
+			return $this->templateSource;
691
+		}
692
+	}
693
+
694
+	/**
695
+	 * Resets the compilation pointer, effectively restarting the compilation process.
696
+	 * this is useful if a plugin modifies the template source since it might need to be recompiled
697
+	 */
698
+	public function recompile()
699
+	{
700
+		$this->setPointer(0);
701
+	}
702
+
703
+	/**
704
+	 * Compiles the provided string down to php code.
705
+	 *
706
+	 * @param Core      $core
707
+	 * @param ITemplate $template the template to compile
708
+	 *
709
+	 * @return string a compiled php string
710
+	 * @throws CompilationException
711
+	 */
712
+	public function compile(Core $core, ITemplate $template)
713
+	{
714
+		// init vars
715
+		//		$compiled = '';
716
+		$tpl                  = $template->getSource();
717
+		$ptr                  = 0;
718
+		$this->core           = $core;
719
+		$this->template       = $template;
720
+		$this->templateSource = &$tpl;
721
+		$this->pointer        = &$ptr;
722
+
723
+		while (true) {
724
+			// if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed
725
+			if ($ptr === 0) {
726
+				// resets variables
727
+				$this->usedPlugins     = array();
728
+				$this->data            = array();
729
+				$this->scope           = &$this->data;
730
+				$this->scopeTree       = array();
731
+				$this->stack           = array();
732
+				$this->line            = 1;
733
+				$this->templatePlugins = array();
734
+				// add top level block
735
+				$compiled                 = $this->addBlock('TopLevelBlock', array(), 0);
736
+				$this->stack[0]['buffer'] = '';
737
+
738
+				if ($this->debug) {
739
+					echo "\n";
740
+					echo 'COMPILER INIT' . "\n";
741
+				}
742
+
743
+				if ($this->debug) {
744
+					echo 'PROCESSING PREPROCESSORS (' . count($this->processors['pre']) . ')' . "\n";
745
+				}
746
+
747
+				// runs preprocessors
748
+				foreach ($this->processors['pre'] as $preProc) {
749
+					if (is_array($preProc) && isset($preProc['autoload'])) {
750
+						$preProc = $this->loadProcessor($preProc['class'], $preProc['name']);
751
+					}
752
+					if (is_array($preProc) && $preProc[0] instanceof Processor) {
753
+						$tpl = call_user_func($preProc, $tpl);
754
+					} else {
755
+						$tpl = call_user_func($preProc, $this, $tpl);
756
+					}
757
+				}
758
+				unset($preProc);
759
+
760
+				// show template source if debug
761
+				if ($this->debug) {
762
+					echo '<pre>'.print_r(htmlentities($tpl), true).'</pre>'."\n";
763
+				}
764
+
765
+				// strips php tags if required by the security policy
766
+				if ($this->securityPolicy !== null) {
767
+					$search = array('{<\?php.*?\?>}');
768
+					if (ini_get('short_open_tags')) {
769
+						$search = array('{<\?.*?\?>}', '{<%.*?%>}');
770
+					}
771
+					switch ($this->securityPolicy->getPhpHandling()) {
772
+						case SecurityPolicy::PHP_ALLOW:
773
+							break;
774
+						case SecurityPolicy::PHP_ENCODE:
775
+							$tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl);
776
+							break;
777
+						case SecurityPolicy::PHP_REMOVE:
778
+							$tpl = preg_replace($search, '', $tpl);
779
+					}
780
+				}
781
+			}
782
+
783
+			$pos = strpos($tpl, $this->ld, $ptr);
784
+
785
+			if ($pos === false) {
786
+				$this->push(substr($tpl, $ptr), 0);
787
+				break;
788
+			} elseif (substr($tpl, $pos - 1, 1) === '\\' && substr($tpl, $pos - 2, 1) !== '\\') {
789
+				$this->push(substr($tpl, $ptr, $pos - $ptr - 1) . $this->ld);
790
+				$ptr = $pos + strlen($this->ld);
791
+			} elseif (preg_match('/^' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', substr($tpl, $pos), $litOpen)) {
792
+				if (!preg_match('/' . $this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr . '/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) {
793
+					throw new CompilationException($this, 'The {literal} blocks must be closed explicitly with {/literal}');
794
+				}
795
+				$endpos = $litClose[0][1];
796
+				$this->push(substr($tpl, $ptr, $pos - $ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos - $pos - strlen($litOpen[0])));
797
+				$ptr = $endpos + strlen($litClose[0][0]);
798
+			} else {
799
+				if (substr($tpl, $pos - 2, 1) === '\\' && substr($tpl, $pos - 1, 1) === '\\') {
800
+					$this->push(substr($tpl, $ptr, $pos - $ptr - 1));
801
+					$ptr = $pos;
802
+				}
803
+
804
+				$this->push(substr($tpl, $ptr, $pos - $ptr));
805
+				$ptr = $pos;
806
+
807
+				$pos += strlen($this->ld);
808
+				if ($this->allowLooseOpenings) {
809
+					while (substr($tpl, $pos, 1) === ' ') {
810
+						$pos += 1;
811
+					}
812
+				} else {
813
+					if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") {
814
+						$ptr = $pos;
815
+						$this->push($this->ld);
816
+						continue;
817
+					}
818
+				}
819
+
820
+				// check that there is an end tag present
821
+				if (strpos($tpl, $this->rd, $pos) === false) {
822
+					throw new CompilationException($this, 'A template tag was not closed, started with "' . substr($tpl, $ptr, 30) . '"');
823
+				}
824
+
825
+				$ptr += strlen($this->ld);
826
+				$subptr = $ptr;
827
+
828
+				while (true) {
829
+					$parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr);
830
+
831
+					// reload loop if the compiler was reset
832
+					if ($ptr === 0) {
833
+						continue 2;
834
+					}
835
+
836
+					$len = $subptr - $ptr;
837
+					$this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n"));
838
+					$ptr += $len;
839
+
840
+					if ($parsed === false) {
841
+						break;
842
+					}
843
+				}
844
+			}
845
+		}
846
+
847
+		$compiled .= $this->removeBlock('TopLevelBlock');
848
+
849
+		if ($this->debug) {
850
+			echo 'PROCESSING POSTPROCESSORS' . "\n";
851
+		}
852
+
853
+		foreach ($this->processors['post'] as $postProc) {
854
+			if (is_array($postProc) && isset($postProc['autoload'])) {
855
+				$postProc = $this->loadProcessor($postProc['class'], $postProc['name']);
856
+			}
857
+			if (is_array($postProc) && $postProc[0] instanceof Processor) {
858
+				$compiled = call_user_func($postProc, $compiled);
859
+			} else {
860
+				$compiled = call_user_func($postProc, $this, $compiled);
861
+			}
862
+		}
863
+		unset($postProc);
864
+
865
+		if ($this->debug) {
866
+			echo 'COMPILATION COMPLETE : MEM USAGE : ' . memory_get_usage() . "\n";
867
+		}
868
+
869
+		$output = "<?php\n/* template head */\n";
870
+
871
+		// build plugin preloader
872
+		foreach ($this->getUsedPlugins() as $plugin => $type) {
873
+			if ($type & Core::CUSTOM_PLUGIN) {
874
+				continue;
875
+			}
876
+
877
+			switch ($type) {
878
+				case Core::CLASS_PLUGIN:
879
+				case Core::CLASS_PLUGIN + Core::BLOCK_PLUGIN:
880
+					if (class_exists('Plugin' . $plugin) !== false) {
881
+						$output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
882
+						"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
883
+					} else {
884
+						$output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_BLOCKS . "Plugin" . $plugin . "')===false)".
885
+						"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
886
+					}
887
+					break;
888
+				case Core::CLASS_PLUGIN + Core::FUNC_PLUGIN:
889
+					if (class_exists('Plugin' . $plugin) !== false) {
890
+						$output .= "if (class_exists('" . "Plugin" . $plugin . "')===false)".
891
+							"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
892
+					} else {
893
+						$output .= "if (class_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
894
+							"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
895
+					}
896
+					break;
897
+				case Core::FUNC_PLUGIN:
898
+					if (function_exists('Plugin' . $plugin) !== false) {
899
+						$output .= "if (function_exists('" . "Plugin" . $plugin . "')===false)".
900
+						"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
901
+					} else {
902
+						$output .= "if (function_exists('" . Core::NAMESPACE_PLUGINS_FUNCTIONS . "Plugin" . $plugin . "')===false)".
903
+						"\n\t\$this->getLoader()->loadPlugin('Plugin$plugin');\n";
904
+					}
905
+					break;
906
+				case Core::SMARTY_MODIFIER:
907
+					$output .= "if (function_exists('smarty_modifier_$plugin')===false)".
908
+					"\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
909
+					break;
910
+				case Core::SMARTY_FUNCTION:
911
+					$output .= "if (function_exists('smarty_function_$plugin')===false)".
912
+					"\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
913
+					break;
914
+				case Core::SMARTY_BLOCK:
915
+					$output .= "if (function_exists('smarty_block_$plugin')===false)".
916
+					"\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
917
+					break;
918
+				case Core::PROXY_PLUGIN:
919
+					$output .= $this->getCore()->getPluginProxy()->getLoader($plugin);
920
+					break;
921
+				default:
922
+					throw new CompilationException($this, 'Type error for ' . $plugin . ' with type' . $type);
923
+			}
924
+		}
925
+
926
+		foreach ($this->templatePlugins as $function => $attr) {
927
+			if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) {
928
+				$this->resolveSubTemplateDependencies($function);
929
+			}
930
+		}
931
+		foreach ($this->templatePlugins as $function) {
932
+			if (isset($function['called']) && $function['called'] === true) {
933
+				$output .= $function['body'] . PHP_EOL;
934
+			}
935
+		}
936
+
937
+		$output .= $compiled . "\n?>";
938
+
939
+		$output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*' . preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/') . ')/', ";\n", $output);
940
+		$output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output);
941
+
942
+		// handle <?xml tag at the beginning
943
+		$output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output);
944
+
945
+		// add another line break after PHP closing tags that have a line break following,
946
+		// as we do not know whether it's intended, and PHP will strip it otherwise
947
+		$output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output);
948
+
949
+		if ($this->debug) {
950
+			echo '=============================================================================================' . "\n";
951
+			$lines = preg_split('{\r\n|\n|<br />}', $output);
952
+			array_shift($lines);
953
+			foreach ($lines as $i => $line) {
954
+				echo ($i + 1) . '. ' . $line . "\r\n";
955
+			}
956
+			echo '=============================================================================================' . "\n";
957
+		}
958
+
959
+		$this->template = $this->dwoo = null;
960
+		$tpl            = null;
961
+
962
+		return $output;
963
+	}
964
+
965
+	/**
966
+	 * Checks what sub-templates are used in every sub-template so that we're sure they are all compiled.
967
+	 *
968
+	 * @param string $function the sub-template name
969
+	 */
970
+	protected function resolveSubTemplateDependencies($function)
971
+	{
972
+		if ($this->debug) {
973
+			echo 'Compiler::' . __FUNCTION__ . "\n";
974
+		}
975
+
976
+		$body = $this->templatePlugins[$function]['body'];
977
+		foreach ($this->templatePlugins as $func => $attr) {
978
+			if ($func !== $function && !isset($attr['called']) && strpos($body, Core::NAMESPACE_PLUGINS_FUNCTIONS .
979
+			'Plugin' . Core::toCamelCase($func)) !== false) {
980
+				$this->templatePlugins[$func]['called'] = true;
981
+				$this->resolveSubTemplateDependencies($func);
982
+			}
983
+		}
984
+		$this->templatePlugins[$function]['checked'] = true;
985
+	}
986
+
987
+	/**
988
+	 * Adds compiled content to the current block.
989
+	 *
990
+	 * @param string $content   the content to push
991
+	 * @param int    $lineCount newlines count in content, optional
992
+	 *
993
+	 * @throws CompilationException
994
+	 */
995
+	public function push($content, $lineCount = null)
996
+	{
997
+		if ($lineCount === null) {
998
+			$lineCount = substr_count($content, "\n");
999
+		}
1000
+
1001
+		if ($this->curBlock['buffer'] === null && count($this->stack) > 1) {
1002
+			// buffer is not initialized yet (the block has just been created)
1003
+			$this->stack[count($this->stack) - 2]['buffer'] .= (string)$content;
1004
+			$this->curBlock['buffer'] = '';
1005
+		} else {
1006
+			if (!isset($this->curBlock['buffer'])) {
1007
+				throw new CompilationException($this, 'The template has been closed too early, you probably have an extra block-closing tag somewhere');
1008
+			}
1009
+			// append current content to current block's buffer
1010
+			$this->curBlock['buffer'] .= (string)$content;
1011
+		}
1012
+		$this->line += $lineCount;
1013
+	}
1014
+
1015
+	/**
1016
+	 * Sets the scope.
1017
+	 * set to null if the scope becomes "unstable" (i.e. too variable or unknown) so that
1018
+	 * variables are compiled in a more evaluative way than just $this->scope['key']
1019
+	 *
1020
+	 * @param mixed $scope    a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
1021
+	 * @param bool  $absolute if true, the scope is set from the top level scope and not from the current scope
1022
+	 *
1023
+	 * @return array the current scope tree
1024
+	 */
1025
+	public function setScope($scope, $absolute = false)
1026
+	{
1027
+		$old = $this->scopeTree;
1028
+
1029
+		if ($scope === null) {
1030
+			unset($this->scope);
1031
+			$this->scope = null;
1032
+		}
1033
+
1034
+		if (is_array($scope) === false) {
1035
+			$scope = explode('.', $scope);
1036
+		}
1037
+
1038
+		if ($absolute === true) {
1039
+			$this->scope     = &$this->data;
1040
+			$this->scopeTree = array();
1041
+		}
1042
+
1043
+		while (($bit = array_shift($scope)) !== null) {
1044
+			if ($bit === '_parent' || $bit === '_') {
1045
+				array_pop($this->scopeTree);
1046
+				reset($this->scopeTree);
1047
+				$this->scope = &$this->data;
1048
+				$cnt         = count($this->scopeTree);
1049
+				for ($i = 0; $i < $cnt; ++ $i) {
1050
+					$this->scope = &$this->scope[$this->scopeTree[$i]];
1051
+				}
1052
+			} elseif ($bit === '_root' || $bit === '__') {
1053
+				$this->scope     = &$this->data;
1054
+				$this->scopeTree = array();
1055
+			} elseif (isset($this->scope[$bit])) {
1056
+				$this->scope       = &$this->scope[$bit];
1057
+				$this->scopeTree[] = $bit;
1058
+			} else {
1059
+				$this->scope[$bit] = array();
1060
+				$this->scope       = &$this->scope[$bit];
1061
+				$this->scopeTree[] = $bit;
1062
+			}
1063
+		}
1064
+
1065
+		return $old;
1066
+	}
1067
+
1068
+	/**
1069
+	 * Adds a block to the top of the block stack.
1070
+	 *
1071
+	 * @param string $type      block type (name)
1072
+	 * @param array  $params    the parameters array
1073
+	 * @param int    $paramtype the parameters type (see mapParams), 0, 1 or 2
1074
+	 *
1075
+	 * @return string the preProcessing() method's output
1076
+	 */
1077
+	public function addBlock($type, array $params, $paramtype)
1078
+	{
1079
+		if ($this->debug) {
1080
+			echo 'Compiler::' . __FUNCTION__ . "\n";
1081
+		}
1082
+
1083
+		$class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1084
+		if (class_exists($class) === false) {
1085
+			$this->getCore()->getLoader()->loadPlugin($type);
1086
+		}
1087
+		$params = $this->mapParams($params, array($class, 'init'), $paramtype);
1088
+
1089
+		$this->stack[]  = array(
1090
+			'type'   => $type,
1091
+			'params' => $params,
1092
+			'custom' => false,
1093
+			'class'  => $class,
1094
+			'buffer' => null
1095
+		);
1096
+		$this->curBlock = &$this->stack[count($this->stack) - 1];
1097
+
1098
+		return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1099
+	}
1100
+
1101
+	/**
1102
+	 * Adds a custom block to the top of the block stack.
1103
+	 *
1104
+	 * @param string $type      block type (name)
1105
+	 * @param array  $params    the parameters array
1106
+	 * @param int    $paramtype the parameters type (see mapParams), 0, 1 or 2
1107
+	 *
1108
+	 * @return string the preProcessing() method's output
1109
+	 */
1110
+	public function addCustomBlock($type, array $params, $paramtype)
1111
+	{
1112
+		$callback = $this->customPlugins[$type]['callback'];
1113
+		if (is_array($callback)) {
1114
+			$class = is_object($callback[0]) ? get_class($callback[0]) : $callback[0];
1115
+		} else {
1116
+			$class = $callback;
1117
+		}
1118
+
1119
+		$params = $this->mapParams($params, array($class, 'init'), $paramtype);
1120
+
1121
+		$this->stack[]  = array(
1122
+			'type'   => $type,
1123
+			'params' => $params,
1124
+			'custom' => true,
1125
+			'class'  => $class,
1126
+			'buffer' => null
1127
+		);
1128
+		$this->curBlock = &$this->stack[count($this->stack) - 1];
1129
+
1130
+		return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type);
1131
+	}
1132
+
1133
+	/**
1134
+	 * Injects a block at the top of the plugin stack without calling its preProcessing method.
1135
+	 * used by {else} blocks to re-add themselves after having closed everything up to their parent
1136
+	 *
1137
+	 * @param string $type   block type (name)
1138
+	 * @param array  $params parameters array
1139
+	 */
1140
+	public function injectBlock($type, array $params)
1141
+	{
1142
+		if ($this->debug) {
1143
+			echo 'Compiler::' . __FUNCTION__ . "\n";
1144
+		}
1145
+
1146
+		$class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($type);
1147
+		if (class_exists($class) === false) {
1148
+			$this->getCore()->getLoader()->loadPlugin($type);
1149
+		}
1150
+		$this->stack[]  = array(
1151
+			'type'   => $type,
1152
+			'params' => $params,
1153
+			'custom' => false,
1154
+			'class'  => $class,
1155
+			'buffer' => null
1156
+		);
1157
+		$this->curBlock = &$this->stack[count($this->stack) - 1];
1158
+	}
1159
+
1160
+	/**
1161
+	 * Removes the closest-to-top block of the given type and all other
1162
+	 * blocks encountered while going down the block stack.
1163
+	 *
1164
+	 * @param string $type block type (name)
1165
+	 *
1166
+	 * @return string the output of all postProcessing() method's return values of the closed blocks
1167
+	 * @throws CompilationException
1168
+	 */
1169
+	public function removeBlock($type)
1170
+	{
1171
+		if ($this->debug) {
1172
+			echo 'Compiler::' . __FUNCTION__ . "\n";
1173
+		}
1174
+
1175
+		$output = '';
1176
+
1177
+		$pluginType = $this->getPluginType($type);
1178
+		if ($pluginType & Core::SMARTY_BLOCK) {
1179
+			$type = 'Smartyinterface';
1180
+		}
1181
+		while (true) {
1182
+			while ($top = array_pop($this->stack)) {
1183
+				if ($top['custom']) {
1184
+					$class = $top['class'];
1185
+				} else {
1186
+					$class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($top['type']);
1187
+				}
1188
+				if (count($this->stack)) {
1189
+					$this->curBlock = &$this->stack[count($this->stack) - 1];
1190
+					$this->push(call_user_func(array(
1191
+						$class,
1192
+						'postProcessing'
1193
+					), $this, $top['params'], '', '', $top['buffer']), 0);
1194
+				} else {
1195
+					$null           = null;
1196
+					$this->curBlock = &$null;
1197
+					$output         = call_user_func(
1198
+						array(
1199
+						$class,
1200
+						'postProcessing'
1201
+						), $this, $top['params'], '', '', $top['buffer']
1202
+					);
1203
+				}
1204
+
1205
+				if ($top['type'] === $type) {
1206
+					break 2;
1207
+				}
1208
+			}
1209
+
1210
+			throw new CompilationException($this, 'Syntax malformation, a block of type "' . $type . '" was closed but was not opened');
1211
+		}
1212
+
1213
+		return $output;
1214
+	}
1215
+
1216
+	/**
1217
+	 * Returns a reference to the first block of the given type encountered and
1218
+	 * optionally closes all blocks until it finds it
1219
+	 * this is mainly used by {else} plugins to close everything that was opened
1220
+	 * between their parent and themselves.
1221
+	 *
1222
+	 * @param string $type       the block type (name)
1223
+	 * @param bool   $closeAlong whether to close all blocks encountered while going down the block stack or not
1224
+	 *
1225
+	 * @return mixed &array the array is as such: array('type'=>pluginName, 'params'=>parameter array,
1226
+	 *               'custom'=>bool defining whether it's a custom plugin or not, for internal use)
1227
+	 * @throws CompilationException
1228
+	 */
1229
+	public function &findBlock($type, $closeAlong = false)
1230
+	{
1231
+		if ($closeAlong === true) {
1232
+			while ($b = end($this->stack)) {
1233
+				if ($b['type'] === $type) {
1234
+					return $this->stack[key($this->stack)];
1235
+				}
1236
+				$this->push($this->removeTopBlock(), 0);
1237
+			}
1238
+		} else {
1239
+			end($this->stack);
1240
+			while ($b = current($this->stack)) {
1241
+				if ($b['type'] === $type) {
1242
+					return $this->stack[key($this->stack)];
1243
+				}
1244
+				prev($this->stack);
1245
+			}
1246
+		}
1247
+
1248
+		throw new CompilationException($this, 'A parent block of type "' . $type . '" is required and can not be found');
1249
+	}
1250
+
1251
+	/**
1252
+	 * Returns a reference to the current block array.
1253
+	 *
1254
+	 * @return array the array is as such: array('type'=>pluginName, 'params'=>parameter array,
1255
+	 *                'custom'=>bool defining whether it's a custom plugin or not, for internal use)
1256
+	 */
1257
+	public function &getCurrentBlock()
1258
+	{
1259
+		return $this->curBlock;
1260
+	}
1261
+
1262
+	/**
1263
+	 * Removes the block at the top of the stack and calls its postProcessing() method.
1264
+	 *
1265
+	 * @return string the postProcessing() method's output
1266
+	 * @throws CompilationException
1267
+	 */
1268
+	public function removeTopBlock()
1269
+	{
1270
+		if ($this->debug) {
1271
+			echo 'Compiler::' . __FUNCTION__ . "\n";
1272
+		}
1273
+
1274
+		$o = array_pop($this->stack);
1275
+		if ($o === null) {
1276
+			throw new CompilationException($this, 'Syntax malformation, a block of unknown type was closed but was not opened.');
1277
+		}
1278
+		if ($o['custom']) {
1279
+			$class = $o['class'];
1280
+		} else {
1281
+			$class = Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($o['type']);
1282
+		}
1283
+
1284
+		$this->curBlock = &$this->stack[count($this->stack) - 1];
1285
+
1286
+		return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']);
1287
+	}
1288
+
1289
+	/**
1290
+	 * Returns the compiled parameters (for example a variable's compiled parameter will be "$this->scope['key']") out
1291
+	 * of the given parameter array.
1292
+	 *
1293
+	 * @param array $params parameter array
1294
+	 *
1295
+	 * @return array filtered parameters
1296
+	 */
1297
+	public function getCompiledParams(array $params)
1298
+	{
1299
+		foreach ($params as $k => $p) {
1300
+			if (is_array($p)) {
1301
+				$params[$k] = $p[0];
1302
+			}
1303
+		}
1304
+
1305
+		return $params;
1306
+	}
1307
+
1308
+	/**
1309
+	 * Returns the real parameters (for example a variable's real parameter will be its key, etc) out of the given
1310
+	 * parameter array.
1311
+	 *
1312
+	 * @param array $params parameter array
1313
+	 *
1314
+	 * @return array filtered parameters
1315
+	 */
1316
+	public function getRealParams(array $params)
1317
+	{
1318
+		foreach ($params as $k => $p) {
1319
+			if (is_array($p)) {
1320
+				$params[$k] = $p[1];
1321
+			}
1322
+		}
1323
+
1324
+		return $params;
1325
+	}
1326
+
1327
+	/**
1328
+	 * Returns the token of each parameter out of the given parameter array.
1329
+	 *
1330
+	 * @param array $params parameter array
1331
+	 *
1332
+	 * @return array tokens
1333
+	 */
1334
+	public function getParamTokens(array $params)
1335
+	{
1336
+		foreach ($params as $k => $p) {
1337
+			if (is_array($p)) {
1338
+				$params[$k] = isset($p[2]) ? $p[2] : 0;
1339
+			}
1340
+		}
1341
+
1342
+		return $params;
1343
+	}
1344
+
1345
+	/**
1346
+	 * Entry point of the parser, it redirects calls to other parse* functions.
1347
+	 *
1348
+	 * @param string $in            the string within which we must parse something
1349
+	 * @param int    $from          the starting offset of the parsed area
1350
+	 * @param int    $to            the ending offset of the parsed area
1351
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
1352
+	 *                              default
1353
+	 * @param string $curBlock      the current parser-block being processed
1354
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
1355
+	 *                              or null by default
1356
+	 *
1357
+	 * @return string parsed values
1358
+	 * @throws CompilationException
1359
+	 */
1360
+	protected function parse($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1361
+	{
1362
+		if ($this->debug) {
1363
+			echo 'Compiler::' . __FUNCTION__ . "\n";
1364
+		}
1365
+
1366
+		if ($to === null) {
1367
+			$to = strlen($in);
1368
+		}
1369
+		$first = substr($in, $from, 1);
1370
+
1371
+		if ($first === false) {
1372
+			throw new CompilationException($this, 'Unexpected EOF, a template tag was not closed');
1373
+		}
1374
+
1375
+		while ($first === ' ' || $first === "\n" || $first === "\t" || $first === "\r") {
1376
+			if ($curBlock === 'root' && substr($in, $from, strlen($this->rd)) === $this->rd) {
1377
+				// end template tag
1378
+				$pointer += strlen($this->rd);
1379
+				if ($this->debug) {
1380
+					echo 'TEMPLATE PARSING ENDED' . "\n";
1381
+				}
1382
+
1383
+				return false;
1384
+			}
1385
+			++ $from;
1386
+			if ($pointer !== null) {
1387
+				++ $pointer;
1388
+			}
1389
+			if ($from >= $to) {
1390
+				if (is_array($parsingParams)) {
1391
+					return $parsingParams;
1392
+				} else {
1393
+					return '';
1394
+				}
1395
+			}
1396
+			$first = $in[$from];
1397
+		}
1398
+
1399
+		$substr = substr($in, $from, $to - $from);
1400
+
1401
+		if ($this->debug) {
1402
+			echo 'PARSE CALL : PARSING "' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . '" @ ' . $from . ':' . $to . ' in ' . $curBlock . ' : pointer=' . $pointer . "\n";
1403
+		}
1404
+		$parsed = '';
1405
+
1406
+		if ($curBlock === 'root' && $first === '*') {
1407
+			$src      = $this->getTemplateSource();
1408
+			$startpos = $this->getPointer() - strlen($this->ld);
1409
+			if (substr($src, $startpos, strlen($this->ld)) === $this->ld) {
1410
+				if ($startpos > 0) {
1411
+					do {
1412
+						$char = substr($src, -- $startpos, 1);
1413
+						if ($char == "\n") {
1414
+							++ $startpos;
1415
+							$whitespaceStart = true;
1416
+							break;
1417
+						}
1418
+					}
1419
+					while ($startpos > 0 && ($char == ' ' || $char == "\t"));
1420
+				}
1421
+
1422
+				if (!isset($whitespaceStart)) {
1423
+					$startpos = $this->getPointer();
1424
+				} else {
1425
+					$pointer -= $this->getPointer() - $startpos;
1426
+				}
1427
+
1428
+				if ($this->allowNestedComments && strpos($src, $this->ld . '*', $this->getPointer()) !== false) {
1429
+					$comOpen  = $this->ld . '*';
1430
+					$comClose = '*' . $this->rd;
1431
+					$level    = 1;
1432
+					$ptr      = $this->getPointer();
1433
+
1434
+					while ($level > 0 && $ptr < strlen($src)) {
1435
+						$open  = strpos($src, $comOpen, $ptr);
1436
+						$close = strpos($src, $comClose, $ptr);
1437
+
1438
+						if ($open !== false && $close !== false) {
1439
+							if ($open < $close) {
1440
+								$ptr = $open + strlen($comOpen);
1441
+								++ $level;
1442
+							} else {
1443
+								$ptr = $close + strlen($comClose);
1444
+								-- $level;
1445
+							}
1446
+						} elseif ($open !== false) {
1447
+							$ptr = $open + strlen($comOpen);
1448
+							++ $level;
1449
+						} elseif ($close !== false) {
1450
+							$ptr = $close + strlen($comClose);
1451
+							-- $level;
1452
+						} else {
1453
+							$ptr = strlen($src);
1454
+						}
1455
+					}
1456
+					$endpos = $ptr - strlen('*' . $this->rd);
1457
+				} else {
1458
+					$endpos = strpos($src, '*' . $this->rd, $startpos);
1459
+					if ($endpos == false) {
1460
+						throw new CompilationException($this, 'Un-ended comment');
1461
+					}
1462
+				}
1463
+				$pointer += $endpos - $startpos + strlen('*' . $this->rd);
1464
+				if (isset($whitespaceStart) && preg_match('#^[\t ]*\r?\n#', substr($src, $endpos + strlen('*' . $this->rd)), $m)) {
1465
+					$pointer += strlen($m[0]);
1466
+					$this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer']) - ($this->getPointer() - $startpos - strlen($this->ld)));
1467
+				}
1468
+
1469
+				return false;
1470
+			}
1471
+		}
1472
+
1473
+		if ($first === '$') {
1474
+			// var
1475
+			$out    = $this->parseVar($in, $from, $to, $parsingParams, $curBlock, $pointer);
1476
+			$parsed = 'var';
1477
+		} elseif ($first === '%' && preg_match('#^%[a-z_\\\\]#i', $substr)) {
1478
+			// Short constant
1479
+			$out = $this->parseConst($in, $from, $to, $parsingParams, $curBlock, $pointer);
1480
+		} elseif (($first === '"' || $first === "'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) {
1481
+			// string
1482
+			$out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
1483
+		} elseif (preg_match('/^\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?(' . (is_array($parsingParams) || $curBlock != 'root' ? '' : '\s+[^(]|') . '\s*\(|\s*' . $this->rdr . '|\s*;)/i', $substr)) {
1484
+			// func
1485
+			$out    = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
1486
+			$parsed = 'func';
1487
+		} elseif ($first === ';') {
1488
+			// instruction end
1489
+			if ($this->debug) {
1490
+				echo 'END OF INSTRUCTION' . "\n";
1491
+			}
1492
+			if ($pointer !== null) {
1493
+				++ $pointer;
1494
+			}
1495
+
1496
+			return $this->parse($in, $from + 1, $to, false, 'root', $pointer);
1497
+		} elseif ($curBlock === 'root' && preg_match('#^/([a-z_][a-z0-9_]*)?#i', $substr, $match)) {
1498
+			// close block
1499
+			if (!empty($match[1]) && $match[1] == 'else') {
1500
+				throw new CompilationException($this, 'Else blocks must not be closed explicitly, they are automatically closed when their parent block is closed');
1501
+			}
1502
+			if (!empty($match[1]) && $match[1] == 'elseif') {
1503
+				throw new CompilationException($this, 'Elseif blocks must not be closed explicitly, they are automatically closed when their parent block is closed or a new else/elseif block is declared after them');
1504
+			}
1505
+			if ($pointer !== null) {
1506
+				$pointer += strlen($match[0]);
1507
+			}
1508
+			if (empty($match[1])) {
1509
+				if ($this->curBlock['type'] == 'else' || $this->curBlock['type'] == 'elseif') {
1510
+					$pointer -= strlen($match[0]);
1511
+				}
1512
+				if ($this->debug) {
1513
+					echo 'TOP BLOCK CLOSED' . "\n";
1514
+				}
1515
+
1516
+				return $this->removeTopBlock();
1517
+			} else {
1518
+				if ($this->debug) {
1519
+					echo 'BLOCK OF TYPE ' . $match[1] . ' CLOSED' . "\n";
1520
+				}
1521
+
1522
+				return $this->removeBlock($match[1]);
1523
+			}
1524
+		} elseif ($curBlock === 'root' && substr($substr, 0, strlen($this->rd)) === $this->rd) {
1525
+			// end template tag
1526
+			if ($this->debug) {
1527
+				echo 'TAG PARSING ENDED' . "\n";
1528
+			}
1529
+			$pointer += strlen($this->rd);
1530
+
1531
+			return false;
1532
+		} elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*=' . ($curBlock === 'array' ? '>?' : '') . ')(?:\s+|[^=]).*#i', $substr, $match)) {
1533
+			// named parameter
1534
+			if ($this->debug) {
1535
+				echo 'NAMED PARAM FOUND' . "\n";
1536
+			}
1537
+			$len = strlen($match[1]);
1538
+			while (substr($in, $from + $len, 1) === ' ') {
1539
+				++ $len;
1540
+			}
1541
+			if ($pointer !== null) {
1542
+				$pointer += $len;
1543
+			}
1544
+
1545
+			$output = array(
1546
+				trim($match[1], " \t\r\n=>'\""),
1547
+				$this->parse($in, $from + $len, $to, false, 'namedparam', $pointer)
1548
+			);
1549
+
1550
+			$parsingParams[] = $output;
1551
+
1552
+			return $parsingParams;
1553
+		} elseif (preg_match('#^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*::\$[a-z0-9_]+)#i', $substr, $match)) {
1554
+			// static member access
1555
+			$parsed = 'var';
1556
+			if (is_array($parsingParams)) {
1557
+				$parsingParams[] = array($match[1], $match[1]);
1558
+				$out             = $parsingParams;
1559
+			} else {
1560
+				$out = $match[1];
1561
+			}
1562
+			$pointer += strlen($match[1]);
1563
+		} elseif ($substr !== '' && (is_array($parsingParams) || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'expression')) {
1564
+			// unquoted string, bool or number
1565
+			$out = $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1566
+		} else {
1567
+			// parse error
1568
+			throw new CompilationException($this, 'Parse error in "' . substr($in, $from, $to - $from) . '"');
1569
+		}
1570
+
1571
+		if (empty($out)) {
1572
+			return '';
1573
+		}
1574
+
1575
+		$substr = substr($in, $pointer, $to - $pointer);
1576
+
1577
+		// var parsed, check if any var-extension applies
1578
+		if ($parsed === 'var') {
1579
+			if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) {
1580
+				if ($this->debug) {
1581
+					echo 'PARSING POST-VAR EXPRESSION ' . $substr . "\n";
1582
+				}
1583
+				// parse expressions
1584
+				$pointer += strlen($match[0]) - 1;
1585
+				if (is_array($parsingParams)) {
1586
+					if ($match[2] == '$') {
1587
+						$expr = $this->parseVar($in, $pointer, $to, array(), $curBlock, $pointer);
1588
+					} else {
1589
+						$expr = $this->parse($in, $pointer, $to, array(), 'expression', $pointer);
1590
+					}
1591
+					$out[count($out) - 1][0] .= $match[1] . $expr[0][0];
1592
+					$out[count($out) - 1][1] .= $match[1] . $expr[0][1];
1593
+				} else {
1594
+					if ($match[2] == '$') {
1595
+						$expr = $this->parseVar($in, $pointer, $to, false, $curBlock, $pointer);
1596
+					} else {
1597
+						$expr = $this->parse($in, $pointer, $to, false, 'expression', $pointer);
1598
+					}
1599
+					if (is_array($out) && is_array($expr)) {
1600
+						$out[0] .= $match[1] . $expr[0];
1601
+						$out[1] .= $match[1] . $expr[1];
1602
+					} elseif (is_array($out)) {
1603
+						$out[0] .= $match[1] . $expr;
1604
+						$out[1] .= $match[1] . $expr;
1605
+					} elseif (is_array($expr)) {
1606
+						$out .= $match[1] . $expr[0];
1607
+					} else {
1608
+						$out .= $match[1] . $expr;
1609
+					}
1610
+				}
1611
+			} elseif ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) {
1612
+				if ($this->debug) {
1613
+					echo 'PARSING POST-VAR ASSIGNMENT ' . $substr . "\n";
1614
+				}
1615
+				// parse assignment
1616
+				$value    = $match[2];
1617
+				$operator = trim($match[1]);
1618
+				if (substr($value, 0, 1) == '=') {
1619
+					throw new CompilationException($this, 'Unexpected "=" in <em>' . $substr . '</em>');
1620
+				}
1621
+
1622
+				if ($pointer !== null) {
1623
+					$pointer += strlen($match[1]);
1624
+				}
1625
+
1626
+				if ($operator !== '++' && $operator !== '--') {
1627
+					$parts = array();
1628
+					$ptr   = 0;
1629
+					$parts = $this->parse($value, 0, strlen($value), $parts, 'condition', $ptr);
1630
+					$pointer += $ptr;
1631
+
1632
+					// load if plugin
1633
+					try {
1634
+						$this->getPluginType('if');
1635
+					}
1636
+					catch (Exception $e) {
1637
+						throw new CompilationException($this, 'Assignments require the "if" plugin to be accessible');
1638
+					}
1639
+
1640
+					$parts  = $this->mapParams($parts, array(Core::NAMESPACE_PLUGINS_BLOCKS . 'PluginIf', 'init'), 1);
1641
+					$tokens = $this->getParamTokens($parts);
1642
+					$parts  = $this->getCompiledParams($parts);
1643
+
1644
+					$value = PluginIf::replaceKeywords($parts['*'], $tokens['*'], $this);
1645
+					$echo  = '';
1646
+				} else {
1647
+					$value = array();
1648
+					$echo  = 'echo ';
1649
+				}
1650
+
1651
+				if ($this->autoEscape) {
1652
+					$out = preg_replace('#\(is_string\(\$tmp=(.+?)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#', '$1', $out);
1653
+				}
1654
+				$out = self::PHP_OPEN . $echo . $out . $operator . implode(' ', $value) . self::PHP_CLOSE;
1655
+			} elseif ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) {
1656
+				// parse namedparam with var as name (only for array)
1657
+				if ($this->debug) {
1658
+					echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND' . "\n";
1659
+				}
1660
+				$len = strlen($match[1]);
1661
+				$var = $out[count($out) - 1];
1662
+				$pointer += $len;
1663
+
1664
+				$output = array($var[0], $this->parse($substr, $len, null, false, 'namedparam', $pointer));
1665
+
1666
+				$parsingParams[] = $output;
1667
+
1668
+				return $parsingParams;
1669
+			}
1670
+		}
1671
+
1672
+		if ($curBlock !== 'modifier' && ($parsed === 'func' || $parsed === 'var') && preg_match('#^(\|@?[a-z0-9_]+(:.*)?)+#i', $substr, $match)) {
1673
+			// parse modifier on funcs or vars
1674
+			$srcPointer = $pointer;
1675
+			if (is_array($parsingParams)) {
1676
+				$tmp                     = $this->replaceModifiers(
1677
+					array(
1678
+					null,
1679
+					null,
1680
+					$out[count($out) - 1][0],
1681
+					$match[0]
1682
+					), $curBlock, $pointer
1683
+				);
1684
+				$out[count($out) - 1][0] = $tmp;
1685
+				$out[count($out) - 1][1] .= substr($substr, $srcPointer, $srcPointer - $pointer);
1686
+			} else {
1687
+				$out = $this->replaceModifiers(array(null, null, $out, $match[0]), $curBlock, $pointer);
1688
+			}
1689
+		}
1690
+
1691
+		// func parsed, check if any func-extension applies
1692
+		if ($parsed === 'func' && preg_match('#^->[a-z0-9_]+(\s*\(.+|->[a-z_].*)?#is', $substr, $match)) {
1693
+			// parse method call or property read
1694
+			$ptr = 0;
1695
+
1696
+			if (is_array($parsingParams)) {
1697
+				$output = $this->parseMethodCall($out[count($out) - 1][1], $match[0], $curBlock, $ptr);
1698
+
1699
+				$out[count($out) - 1][0] = $output;
1700
+				$out[count($out) - 1][1] .= substr($match[0], 0, $ptr);
1701
+			} else {
1702
+				$out = $this->parseMethodCall($out, $match[0], $curBlock, $ptr);
1703
+			}
1704
+
1705
+			$pointer += $ptr;
1706
+		}
1707
+
1708
+		if ($curBlock === 'root' && substr($out, 0, strlen(self::PHP_OPEN)) !== self::PHP_OPEN) {
1709
+			return self::PHP_OPEN . 'echo ' . $out . ';' . self::PHP_CLOSE;
1710
+		}
1711
+
1712
+		return $out;
1713
+	}
1714
+
1715
+	/**
1716
+	 * Parses a function call.
1717
+	 *
1718
+	 * @param string $in            the string within which we must parse something
1719
+	 * @param int    $from          the starting offset of the parsed area
1720
+	 * @param int    $to            the ending offset of the parsed area
1721
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
1722
+	 *                              default
1723
+	 * @param string $curBlock      the current parser-block being processed
1724
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
1725
+	 *                              or null by default
1726
+	 *
1727
+	 * @return string parsed values
1728
+	 * @throws CompilationException
1729
+	 * @throws Exception
1730
+	 * @throws SecurityException
1731
+	 */
1732
+	protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
1733
+	{
1734
+		$output = '';
1735
+		$cmdstr = substr($in, $from, $to - $from);
1736
+		preg_match('/^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?)(\s*' . $this->rdr . '|\s*;)?/i', $cmdstr, $match);
1737
+
1738
+		if (empty($match[1])) {
1739
+			throw new CompilationException($this, 'Parse error, invalid function name : ' . substr($cmdstr, 0, 15));
1740
+		}
1741
+
1742
+		$func = $match[1];
1743
+
1744
+		if (!empty($match[2])) {
1745
+			$cmdstr = $match[1];
1746
+		}
1747
+
1748
+		if ($this->debug) {
1749
+			echo 'FUNC FOUND (' . $func . ')' . "\n";
1750
+		}
1751
+
1752
+		$paramsep = '';
1753
+
1754
+		if (is_array($parsingParams) || $curBlock != 'root') {
1755
+			$paramspos = strpos($cmdstr, '(');
1756
+			$paramsep  = ')';
1757
+		} elseif (preg_match_all('#^\s*[\\\\:a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) {
1758
+			$paramspos = $match[1][0][1];
1759
+			$paramsep  = substr($match[1][0][0], - 1) === '(' ? ')' : '';
1760
+			if ($paramsep === ')') {
1761
+				$paramspos += strlen($match[1][0][0]) - 1;
1762
+				if (substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') {
1763
+					$paramsep = '';
1764
+					if (strlen($match[1][0][0]) > 1) {
1765
+						-- $paramspos;
1766
+					}
1767
+				}
1768
+			}
1769
+		} else {
1770
+			$paramspos = false;
1771
+		}
1772
+
1773
+		$state = 0;
1774
+
1775
+		if ($paramspos === false) {
1776
+			$params = array();
1777
+
1778
+			if ($curBlock !== 'root') {
1779
+				return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1780
+			}
1781
+		} else {
1782
+			if ($curBlock === 'condition') {
1783
+				// load if plugin
1784
+				$this->getPluginType('if');
1785
+
1786
+				if (PluginIf::replaceKeywords(array($func), array(self::T_UNQUOTED_STRING), $this) !== array($func)) {
1787
+					return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
1788
+				}
1789
+			}
1790
+			$whitespace = strlen(substr($cmdstr, strlen($func), $paramspos - strlen($func)));
1791
+			$paramstr   = substr($cmdstr, $paramspos + 1);
1792
+			if (substr($paramstr, - 1, 1) === $paramsep) {
1793
+				$paramstr = substr($paramstr, 0, - 1);
1794
+			}
1795
+
1796
+			if (strlen($paramstr) === 0) {
1797
+				$params   = array();
1798
+				$paramstr = '';
1799
+			} else {
1800
+				$ptr    = 0;
1801
+				$params = array();
1802
+				if ($func === 'empty') {
1803
+					$params = $this->parseVar($paramstr, $ptr, strlen($paramstr), $params, 'root', $ptr);
1804
+				} else {
1805
+					while ($ptr < strlen($paramstr)) {
1806
+						while (true) {
1807
+							if ($ptr >= strlen($paramstr)) {
1808
+								break 2;
1809
+							}
1810
+
1811
+							if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') {
1812
+								if ($this->debug) {
1813
+									echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT ' . $ptr . "\n";
1814
+								}
1815
+								break 2;
1816
+							} elseif ($paramstr[$ptr] === ';') {
1817
+								++ $ptr;
1818
+								if ($this->debug) {
1819
+									echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT ' . $ptr . "\n";
1820
+								}
1821
+								break 2;
1822
+							} elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') {
1823
+								if ($this->debug) {
1824
+									echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT ' . $ptr . "\n";
1825
+								}
1826
+								break 2;
1827
+							} elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
1828
+								if ($this->debug) {
1829
+									echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT ' . $ptr . "\n";
1830
+								}
1831
+								break 2;
1832
+							}
1833
+
1834
+							if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === ',' || $paramstr[$ptr] === "\r" || $paramstr[$ptr] === "\n" || $paramstr[$ptr] === "\t") {
1835
+								++ $ptr;
1836
+							} else {
1837
+								break;
1838
+							}
1839
+						}
1840
+
1841
+						if ($this->debug) {
1842
+							echo 'FUNC START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
1843
+						}
1844
+
1845
+						if ($func === 'if' || $func === 'elseif' || $func === 'tif') {
1846
+							$params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr);
1847
+						} elseif ($func === 'array') {
1848
+							$params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'array', $ptr);
1849
+						} else {
1850
+							$params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr);
1851
+						}
1852
+
1853
+						if ($this->debug) {
1854
+							echo 'PARAM PARSED, POINTER AT ' . $ptr . ' (' . substr($paramstr, $ptr - 1, 3) . ')' . "\n";
1855
+						}
1856
+					}
1857
+				}
1858
+				$paramstr = substr($paramstr, 0, $ptr);
1859
+				$state    = 0;
1860
+				foreach ($params as $k => $p) {
1861
+					if (is_array($p) && is_array($p[1])) {
1862
+						$state |= 2;
1863
+					} else {
1864
+						if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m) && $func !== 'array') {
1865
+							$params[$k] = array($m[2], array('true', 'true'));
1866
+						} else {
1867
+							if ($state & 2 && $func !== 'array') {
1868
+								throw new CompilationException($this, 'You can not use an unnamed parameter after a named one');
1869
+							}
1870
+							$state |= 1;
1871
+						}
1872
+					}
1873
+				}
1874
+			}
1875
+		}
1876
+
1877
+		if ($pointer !== null) {
1878
+			$pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0);
1879
+			if ($this->debug) {
1880
+				echo 'FUNC ADDS ' . ((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)) . ' TO POINTER' . "\n";
1881
+			}
1882
+		}
1883
+
1884
+		if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) {
1885
+			// handle static method calls with security policy
1886
+			if (strstr($func, '::') !== false && $this->securityPolicy !== null && $this->securityPolicy->isMethodAllowed(explode('::', strtolower($func))) !== true) {
1887
+				throw new SecurityException('Call to a disallowed php function : ' . $func);
1888
+			}
1889
+			$pluginType = Core::NATIVE_PLUGIN;
1890
+		} else {
1891
+			$pluginType = $this->getPluginType($func);
1892
+		}
1893
+
1894
+		// Blocks plugin
1895
+		if ($pluginType & Core::BLOCK_PLUGIN) {
1896
+			if ($curBlock !== 'root' || is_array($parsingParams)) {
1897
+				throw new CompilationException($this, 'Block plugins can not be used as other plugin\'s arguments');
1898
+			}
1899
+			if ($pluginType & Core::CUSTOM_PLUGIN) {
1900
+				return $this->addCustomBlock($func, $params, $state);
1901
+			} else {
1902
+				return $this->addBlock($func, $params, $state);
1903
+			}
1904
+		} elseif ($pluginType & Core::SMARTY_BLOCK) {
1905
+			if ($curBlock !== 'root' || is_array($parsingParams)) {
1906
+				throw new CompilationException($this, 'Block plugins can not be used as other plugin\'s arguments');
1907
+			}
1908
+
1909
+			if ($state & 2) {
1910
+				array_unshift($params, array('__functype', array($pluginType, $pluginType)));
1911
+				array_unshift($params, array('__funcname', array($func, $func)));
1912
+			} else {
1913
+				array_unshift($params, array($pluginType, $pluginType));
1914
+				array_unshift($params, array($func, $func));
1915
+			}
1916
+
1917
+			return $this->addBlock('smartyinterface', $params, $state);
1918
+		}
1919
+
1920
+		// Native & Smarty plugins
1921
+		if ($pluginType & Core::NATIVE_PLUGIN || $pluginType & Core::SMARTY_FUNCTION || $pluginType & Core::SMARTY_BLOCK) {
1922
+			$params = $this->mapParams($params, null, $state);
1923
+		} // PHP class plugin
1924
+		elseif ($pluginType & Core::CLASS_PLUGIN) {
1925
+			if ($pluginType & Core::CUSTOM_PLUGIN) {
1926
+				$params = $this->mapParams(
1927
+					$params, array(
1928
+					$this->customPlugins[$func]['class'],
1929
+					$this->customPlugins[$func]['function']
1930
+				), $state);
1931
+			} else {
1932
+				if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
1933
+					$params = $this->mapParams($params, array(
1934
+						'Plugin' . Core::toCamelCase($func),
1935
+						($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1936
+					), $state);
1937
+				} elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
1938
+					$params = $this->mapParams($params, array(
1939
+						Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func),
1940
+						($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1941
+					), $state);
1942
+				} else {
1943
+					$params = $this->mapParams($params, array(
1944
+						Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
1945
+						($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'
1946
+					), $state);
1947
+				}
1948
+			}
1949
+		} // PHP function plugin
1950
+		elseif ($pluginType & Core::FUNC_PLUGIN) {
1951
+			if ($pluginType & Core::CUSTOM_PLUGIN) {
1952
+				$params = $this->mapParams($params, $this->customPlugins[$func]['callback'], $state);
1953
+			} else {
1954
+				// Custom plugin
1955
+				if (function_exists('Plugin' . Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ?
1956
+						'Compile' : '')) !== false) {
1957
+					$params = $this->mapParams($params, 'Plugin' . Core::toCamelCase($func) . (($pluginType &
1958
+							Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1959
+				} // Builtin helper plugin
1960
+				elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . (
1961
+					($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '')) !== false) {
1962
+					$params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase
1963
+						($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1964
+				} // Builtin function plugin
1965
+				else {
1966
+					$params = $this->mapParams($params, Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase
1967
+						($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''), $state);
1968
+				}
1969
+			}
1970
+		} // Smarty modifier
1971
+		elseif ($pluginType & Core::SMARTY_MODIFIER) {
1972
+			$output = 'smarty_modifier_' . $func . '(' . implode(', ', $params) . ')';
1973
+		} // Proxy plugin
1974
+		elseif ($pluginType & Core::PROXY_PLUGIN) {
1975
+			$params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
1976
+		} // Template plugin
1977
+		elseif ($pluginType & Core::TEMPLATE_PLUGIN) {
1978
+			// transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))
1979
+			$map = array();
1980
+			foreach ($this->templatePlugins[$func]['params'] as $param => $defValue) {
1981
+				if ($param == 'rest') {
1982
+					$param = '*';
1983
+				}
1984
+				$hasDefault = $defValue !== null;
1985
+				if ($defValue === 'null') {
1986
+					$defValue = null;
1987
+				} elseif ($defValue === 'false') {
1988
+					$defValue = false;
1989
+				} elseif ($defValue === 'true') {
1990
+					$defValue = true;
1991
+				} elseif (preg_match('#^([\'"]).*?\1$#', $defValue)) {
1992
+					$defValue = substr($defValue, 1, - 1);
1993
+				}
1994
+				$map[] = array($param, $hasDefault, $defValue);
1995
+			}
1996
+
1997
+			$params = $this->mapParams($params, null, $state, $map);
1998
+		}
1999
+
2000
+		// only keep php-syntax-safe values for non-block plugins
2001
+		$tokens = array();
2002
+		foreach ($params as $k => $p) {
2003
+			$tokens[$k] = isset($p[2]) ? $p[2] : 0;
2004
+			$params[$k] = $p[0];
2005
+		}
2006
+
2007
+		// Native plugin
2008
+		if ($pluginType & Core::NATIVE_PLUGIN) {
2009
+			if ($func === 'do') {
2010
+				$output = '';
2011
+				if (isset($params['*'])) {
2012
+					$output = implode(';', $params['*']) . ';';
2013
+				}
2014
+
2015
+				if (is_array($parsingParams) || $curBlock !== 'root') {
2016
+					throw new CompilationException($this, 'Do can not be used inside another function or block');
2017
+				}
2018
+
2019
+				return self::PHP_OPEN . $output . self::PHP_CLOSE;
2020
+			} else {
2021
+				if (isset($params['*'])) {
2022
+					$output = $func . '(' . implode(', ', $params['*']) . ')';
2023
+				} else {
2024
+					$output = $func . '()';
2025
+				}
2026
+			}
2027
+		} // Block class OR Function class
2028
+		elseif ($pluginType & Core::CLASS_PLUGIN || ($pluginType & Core::FUNC_PLUGIN && $pluginType & Core::CLASS_PLUGIN)) {
2029
+			if ($pluginType & Core::COMPILABLE_PLUGIN) {
2030
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
2031
+					$callback = $this->customPlugins[$func]['callback'];
2032
+					if (!is_array($callback)) {
2033
+						if (!method_exists($callback, 'compile')) {
2034
+							throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
2035
+						}
2036
+						if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
2037
+							$funcCompiler = array($callback, 'compile');
2038
+						} else {
2039
+							$funcCompiler = array(new $callback(), 'compile');
2040
+						}
2041
+					} else {
2042
+						$funcCompiler = $callback;
2043
+					}
2044
+				} else {
2045
+					if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2046
+						$funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
2047
+					} elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2048
+						$funcCompiler = array(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func), 'compile');
2049
+					} else {
2050
+						$funcCompiler = array(
2051
+							Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func),
2052
+							'compile'
2053
+						);
2054
+					}
2055
+					array_unshift($params, $this);
2056
+				}
2057
+				// @TODO: Is it a real fix ?
2058
+				if ($func === 'tif') {
2059
+					$params[] = $tokens;
2060
+				}
2061
+				$output = call_user_func_array($funcCompiler, $params);
2062
+			} else {
2063
+				$params = self::implode_r($params);
2064
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
2065
+					$callback = $this->customPlugins[$func]['callback'];
2066
+					if (!is_array($callback)) {
2067
+						if (!method_exists($callback, 'process')) {
2068
+							throw new Exception('Custom plugin ' . $func . ' must implement the "process" method to be usable, or you should provide a full callback to the method to use');
2069
+						}
2070
+						if (is_object($callback)) {
2071
+							$callback = get_class($callback);
2072
+						}
2073
+						if (($ref = new ReflectionMethod($callback, 'process')) && $ref->isStatic()) {
2074
+							$output = 'call_user_func(array(\'' . $callback . '\', \'process\'), ' . $params . ')';
2075
+						} else {
2076
+							$output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback . '\'), \'process\'), ' . $params . ')';
2077
+						}
2078
+					} elseif (is_object($callback[0])) {
2079
+						$output = 'call_user_func(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), ' . $params . ')';
2080
+					} elseif (($ref = new ReflectionMethod($callback[0], $callback[1])) && $ref->isStatic()) {
2081
+						$output = 'call_user_func(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), ' . $params . ')';
2082
+					} else {
2083
+						$output = 'call_user_func(array($this->getObjectPlugin(\'' . $callback[0] . '\'), \'' . $callback[1] . '\'), ' . $params . ')';
2084
+					}
2085
+					if (empty($params)) {
2086
+						$output = substr($output, 0, - 3) . ')';
2087
+					}
2088
+				} else {
2089
+					if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2090
+						$output = '$this->classCall(\'Plugin' . $func . '\', array(' . $params . '))';
2091
+					} elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
2092
+						$output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', 
2093 2093
                         array(' . $params . '))';
2094
-                    } else {
2095
-                        $output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
2096
-                    }
2097
-                }
2098
-            }
2099
-        } // Function plugin only (cannot be a class)
2100
-        elseif ($pluginType & Core::FUNC_PLUGIN) {
2101
-            if ($pluginType & Core::COMPILABLE_PLUGIN) {
2102
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
2103
-                    $funcCompiler = $this->customPlugins[$func]['callback'];
2104
-                } else {
2105
-                    // Custom plugin
2106
-                    if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2107
-                        $funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
2108
-                    } // Builtin helper plugin
2109
-                    elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2110
-                        $funcCompiler = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) .
2111
-                            'Compile';
2112
-                    } // Builtin function plugin
2113
-                    else {
2114
-                        $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
2115
-                            'Compile';
2116
-                    }
2117
-                }
2118
-                array_unshift($params, $this);
2119
-                // @TODO: Is it a real fix ?
2120
-                if ($func === 'tif') {
2121
-                    $params[] = $tokens;
2122
-                }
2123
-                $output = call_user_func_array($funcCompiler, $params);
2124
-            } else {
2125
-                array_unshift($params, '$this');
2126
-                $params = self::implode_r($params);
2127
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
2128
-                    $callback = $this->customPlugins[$func]['callback'];
2129
-                    if ($callback instanceof Closure) {
2130
-                        $output = 'call_user_func($this->getCustomPlugin(\'' . $func . '\'), ' . $params . ')';
2131
-                    } else {
2132
-                        $output = 'call_user_func(\'' . $callback . '\', ' . $params . ')';
2133
-                    }
2134
-                } else {
2135
-                    // Custom plugin
2136
-                    if (function_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2137
-                        $output = 'Plugin' . Core::toCamelCase($func) . '(' . $params .
2138
-                            ')';
2139
-                    } // Builtin helper plugin
2140
-                    elseif(function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !==
2141
-                        false) {
2142
-                        $output = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . '(' .
2143
-                            $params . ')';
2144
-                    } // Builtin function plugin
2145
-                    else {
2146
-                        $output = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '(' .
2147
-                            $params . ')';
2148
-                    }
2149
-                }
2150
-            }
2151
-        } // Proxy plugin
2152
-        elseif ($pluginType & Core::PROXY_PLUGIN) {
2153
-            $output = call_user_func(array($this->getCore()->getPluginProxy(), 'getCode'), $func, $params);
2154
-        } // Smarty function (@deprecated)
2155
-        elseif ($pluginType & Core::SMARTY_FUNCTION) {
2156
-            $params = '';
2157
-            if (isset($params['*'])) {
2158
-                $params = self::implode_r($params['*'], true);
2159
-            }
2160
-
2161
-            if ($pluginType & Core::CUSTOM_PLUGIN) {
2162
-                $callback = $this->customPlugins[$func]['callback'];
2163
-                if (is_array($callback)) {
2164
-                    if (is_object($callback[0])) {
2165
-                        $output = 'call_user_func_array(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2166
-                    } else {
2167
-                        $output = 'call_user_func_array(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2168
-                    }
2169
-                } else {
2170
-                    $output = $callback . '(array(' . $params . '), $this)';
2171
-                }
2172
-            } else {
2173
-                $output = 'smarty_function_' . $func . '(array(' . $params . '), $this)';
2174
-            }
2175
-        } // Template plugin
2176
-        elseif ($pluginType & Core::TEMPLATE_PLUGIN) {
2177
-            array_unshift($params, '$this');
2178
-            $params                                 = self::implode_r($params);
2179
-            $output                                 = 'Plugin' . Core::toCamelCase($func) .
2180
-                $this->templatePlugins[$func]['uuid'] . '(' . $params . ')';
2181
-            $this->templatePlugins[$func]['called'] = true;
2182
-        }
2183
-
2184
-        if (is_array($parsingParams)) {
2185
-            $parsingParams[] = array($output, $output);
2186
-
2187
-            return $parsingParams;
2188
-        } elseif ($curBlock === 'namedparam') {
2189
-            return array($output, $output);
2190
-        }
2191
-
2192
-        return $output;
2193
-    }
2194
-
2195
-    /**
2196
-     * Parses a string.
2197
-     *
2198
-     * @param string $in            the string within which we must parse something
2199
-     * @param int    $from          the starting offset of the parsed area
2200
-     * @param int    $to            the ending offset of the parsed area
2201
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2202
-     *                              default
2203
-     * @param string $curBlock      the current parser-block being processed
2204
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2205
-     *                              or null by default
2206
-     *
2207
-     * @return string parsed values
2208
-     * @throws CompilationException
2209
-     */
2210
-    protected function parseString($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2211
-    {
2212
-        $substr = substr($in, $from, $to - $from);
2213
-        $first  = $substr[0];
2214
-
2215
-        if ($this->debug) {
2216
-            echo 'STRING FOUND (in ' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . ')' . "\n";
2217
-        }
2218
-        $strend = false;
2219
-        $o      = $from + 1;
2220
-        while ($strend === false) {
2221
-            $strend = strpos($in, $first, $o);
2222
-            if ($strend === false) {
2223
-                throw new CompilationException($this, 'Unfinished string, started with ' . substr($in, $from, $to - $from));
2224
-            }
2225
-            if (substr($in, $strend - 1, 1) === '\\') {
2226
-                $o      = $strend + 1;
2227
-                $strend = false;
2228
-            }
2229
-        }
2230
-        if ($this->debug) {
2231
-            echo 'STRING DELIMITED: ' . substr($in, $from, $strend + 1 - $from) . "\n";
2232
-        }
2233
-
2234
-        $srcOutput = substr($in, $from, $strend + 1 - $from);
2235
-
2236
-        if ($pointer !== null) {
2237
-            $pointer += strlen($srcOutput);
2238
-        }
2239
-
2240
-        $output = $this->replaceStringVars($srcOutput, $first);
2241
-
2242
-        // handle modifiers
2243
-        if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend + 1 - $from), $match)) {
2244
-            $modstr = $match[1];
2245
-
2246
-            if ($curBlock === 'root' && substr($modstr, - 1) === '}') {
2247
-                $modstr = substr($modstr, 0, - 1);
2248
-            }
2249
-            $modstr = str_replace('\\' . $first, $first, $modstr);
2250
-            $ptr    = 0;
2251
-            $output = $this->replaceModifiers(array(null, null, $output, $modstr), 'string', $ptr);
2252
-
2253
-            $strend += $ptr;
2254
-            if ($pointer !== null) {
2255
-                $pointer += $ptr;
2256
-            }
2257
-            $srcOutput .= substr($substr, $strend + 1 - $from, $ptr);
2258
-        }
2259
-
2260
-        if (is_array($parsingParams)) {
2261
-            $parsingParams[] = array($output, substr($srcOutput, 1, - 1));
2262
-
2263
-            return $parsingParams;
2264
-        } elseif ($curBlock === 'namedparam') {
2265
-            return array($output, substr($srcOutput, 1, - 1));
2266
-        }
2267
-
2268
-        return $output;
2269
-    }
2270
-
2271
-    /**
2272
-     * Parses a constant.
2273
-     *
2274
-     * @param string $in            the string within which we must parse something
2275
-     * @param int    $from          the starting offset of the parsed area
2276
-     * @param int    $to            the ending offset of the parsed area
2277
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2278
-     *                              default
2279
-     * @param string $curBlock      the current parser-block being processed
2280
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2281
-     *                              or null by default
2282
-     *
2283
-     * @return string parsed values
2284
-     * @throws CompilationException
2285
-     */
2286
-    protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2287
-    {
2288
-        $substr = substr($in, $from, $to - $from);
2289
-
2290
-        if ($this->debug) {
2291
-            echo 'CONST FOUND : ' . $substr . "\n";
2292
-        }
2293
-
2294
-        if (!preg_match('#^%([\\\\a-z0-9_:]+)#i', $substr, $m)) {
2295
-            throw new CompilationException($this, 'Invalid constant');
2296
-        }
2297
-
2298
-        if ($pointer !== null) {
2299
-            $pointer += strlen($m[0]);
2300
-        }
2301
-
2302
-        $output = $this->parseConstKey($m[1], $curBlock);
2303
-
2304
-        if (is_array($parsingParams)) {
2305
-            $parsingParams[] = array($output, $m[1]);
2306
-
2307
-            return $parsingParams;
2308
-        } elseif ($curBlock === 'namedparam') {
2309
-            return array($output, $m[1]);
2310
-        }
2311
-
2312
-        return $output;
2313
-    }
2314
-
2315
-    /**
2316
-     * Parses a constant.
2317
-     *
2318
-     * @param string $key      the constant to parse
2319
-     * @param string $curBlock the current parser-block being processed
2320
-     *
2321
-     * @return string parsed constant
2322
-     */
2323
-    protected function parseConstKey($key, $curBlock)
2324
-    {
2325
-        $key = str_replace('\\\\', '\\', $key);
2326
-
2327
-        if ($this->securityPolicy !== null && $this->securityPolicy->getConstantHandling() === SecurityPolicy::CONST_DISALLOW) {
2328
-            return 'null';
2329
-        }
2330
-
2331
-        if ($curBlock !== 'root') {
2332
-            return '(defined("' . $key . '") ? ' . $key . ' : null)';
2333
-        }
2334
-
2335
-        return $key;
2336
-    }
2337
-
2338
-    /**
2339
-     * Parses a variable.
2340
-     *
2341
-     * @param string $in            the string within which we must parse something
2342
-     * @param int    $from          the starting offset of the parsed area
2343
-     * @param int    $to            the ending offset of the parsed area
2344
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2345
-     *                              default
2346
-     * @param string $curBlock      the current parser-block being processed
2347
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2348
-     *                              or null by default
2349
-     *
2350
-     * @return string parsed values
2351
-     * @throws CompilationException
2352
-     */
2353
-    protected function parseVar($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2354
-    {
2355
-        $substr = substr($in, $from, $to - $from);
2356
-
2357
-        // var key
2358
-        $varRegex = '(\\$?\\.?[a-z0-9\\\\_:]*(?:(?:(?:\\.|->)(?:[a-z0-9\\\\_:]+|(?R))|\\[(?:[a-z0-9\\\\_:]+|(?R)|(["\'])[^\\2]*?\\2)\\]))*)';
2359
-        // method call
2360
-        $methodCall = ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'expression' || $curBlock === 'delimited_string' ? '(\(.*)?' : '()');
2361
-        // simple math expressions
2362
-        $simpleMathExpressions = ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'delimited_string' ? '((?:(?:[+\/*%=-])(?:(?<!=)=?-?[$%][a-z0-9\\\\.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9\.,]*|[+-]))*)' : '()');
2363
-        // modifiers
2364
-        $modifiers = $curBlock !== 'modifier' ? '((?:\|(?:@?[a-z0-9\\\\_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?' : '(())';
2365
-
2366
-        $regex = '#';
2367
-        $regex .= $varRegex;
2368
-        $regex .= $methodCall;
2369
-        $regex .= $simpleMathExpressions;
2370
-        $regex .= $modifiers;
2371
-        $regex .= '#i';
2372
-
2373
-        if (preg_match($regex, $substr, $match)) {
2374
-            $key = substr($match[1], 1);
2375
-
2376
-            $matchedLength = strlen($match[0]);
2377
-            $hasModifiers  = !empty($match[5]);
2378
-            $hasExpression = !empty($match[4]);
2379
-            $hasMethodCall = !empty($match[3]);
2380
-
2381
-            if (substr($key, - 1) == '.') {
2382
-                $key = substr($key, 0, - 1);
2383
-                -- $matchedLength;
2384
-            }
2385
-
2386
-            if ($hasMethodCall) {
2387
-                $matchedLength -= strlen($match[3]) + strlen(substr($match[1], strrpos($match[1], '->')));
2388
-                $key        = substr($match[1], 1, strrpos($match[1], '->') - 1);
2389
-                $methodCall = substr($match[1], strrpos($match[1], '->')) . $match[3];
2390
-            }
2391
-
2392
-            if ($hasModifiers) {
2393
-                $matchedLength -= strlen($match[5]);
2394
-            }
2395
-
2396
-            if ($pointer !== null) {
2397
-                $pointer += $matchedLength;
2398
-            }
2399
-
2400
-            // replace useless brackets by dot accessed vars and strip enclosing quotes if present
2401
-            $key = preg_replace('#\[(["\']?)([^$%\[.>-]+)\1\]#', '.$2', $key);
2402
-
2403
-            if ($this->debug) {
2404
-                if ($hasMethodCall) {
2405
-                    echo 'METHOD CALL FOUND : $' . $key . substr($methodCall, 0, 30) . "\n";
2406
-                } else {
2407
-                    echo 'VAR FOUND : $' . $key . "\n";
2408
-                }
2409
-            }
2410
-
2411
-            $key = str_replace('"', '\\"', $key);
2412
-
2413
-            $cnt = substr_count($key, '$');
2414
-            if ($cnt > 0) {
2415
-                $uid           = 0;
2416
-                $parsed        = array($uid => '');
2417
-                $current       = &$parsed;
2418
-                $curTxt        = &$parsed[$uid ++];
2419
-                $tree          = array();
2420
-                $chars         = str_split($key, 1);
2421
-                $inSplittedVar = false;
2422
-                $bracketCount  = 0;
2423
-
2424
-                while (($char = array_shift($chars)) !== null) {
2425
-                    if ($char === '[') {
2426
-                        if (count($tree) > 0) {
2427
-                            ++ $bracketCount;
2428
-                        } else {
2429
-                            $tree[]        = &$current;
2430
-                            $current[$uid] = array($uid + 1 => '');
2431
-                            $current       = &$current[$uid ++];
2432
-                            $curTxt        = &$current[$uid ++];
2433
-                            continue;
2434
-                        }
2435
-                    } elseif ($char === ']') {
2436
-                        if ($bracketCount > 0) {
2437
-                            -- $bracketCount;
2438
-                        } else {
2439
-                            $current = &$tree[count($tree) - 1];
2440
-                            array_pop($tree);
2441
-                            if (current($chars) !== '[' && current($chars) !== false && current($chars) !== ']') {
2442
-                                $current[$uid] = '';
2443
-                                $curTxt        = &$current[$uid ++];
2444
-                            }
2445
-                            continue;
2446
-                        }
2447
-                    } elseif ($char === '$') {
2448
-                        if (count($tree) == 0) {
2449
-                            $curTxt        = &$current[$uid ++];
2450
-                            $inSplittedVar = true;
2451
-                        }
2452
-                    } elseif (($char === '.' || $char === '-') && count($tree) == 0 && $inSplittedVar) {
2453
-                        $curTxt        = &$current[$uid ++];
2454
-                        $inSplittedVar = false;
2455
-                    }
2456
-
2457
-                    $curTxt .= $char;
2458
-                }
2459
-                unset($uid, $current, $curTxt, $tree, $chars);
2460
-
2461
-                if ($this->debug) {
2462
-                    echo 'RECURSIVE VAR REPLACEMENT : ' . $key . "\n";
2463
-                }
2464
-
2465
-                $key = $this->flattenVarTree($parsed);
2466
-
2467
-                if ($this->debug) {
2468
-                    echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2469
-                }
2470
-
2471
-                $output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("' . $key . '")');
2472
-            } else {
2473
-                $output = $this->parseVarKey($key, $hasModifiers ? 'modifier' : $curBlock);
2474
-            }
2475
-
2476
-
2477
-            // methods
2478
-            if ($hasMethodCall) {
2479
-                $ptr = 0;
2480
-
2481
-                $output = $this->parseMethodCall($output, $methodCall, $curBlock, $ptr);
2482
-
2483
-                if ($pointer !== null) {
2484
-                    $pointer += $ptr;
2485
-                }
2486
-                $matchedLength += $ptr;
2487
-            }
2488
-
2489
-            if ($hasExpression) {
2490
-                // expressions
2491
-                preg_match_all('#(?:([+/*%=-])(=?-?[%$][a-z0-9\\\\.[\]>_:-]+(?:\([^)]*\))?|=?-?[0-9.,]+|\1))#i', $match[4], $expMatch);
2492
-                foreach ($expMatch[1] as $k => $operator) {
2493
-                    if (substr($expMatch[2][$k], 0, 1) === '=') {
2494
-                        $assign = true;
2495
-                        if ($operator === '=') {
2496
-                            throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, can not use "==" in expressions');
2497
-                        }
2498
-                        if ($curBlock !== 'root') {
2499
-                            throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, assignments can only be used in top level expressions like {$foo+=3} or {$foo="bar"}');
2500
-                        }
2501
-                        $operator .= '=';
2502
-                        $expMatch[2][$k] = substr($expMatch[2][$k], 1);
2503
-                    }
2504
-
2505
-                    if (substr($expMatch[2][$k], 0, 1) === '-' && strlen($expMatch[2][$k]) > 1) {
2506
-                        $operator .= '-';
2507
-                        $expMatch[2][$k] = substr($expMatch[2][$k], 1);
2508
-                    }
2509
-                    if (($operator === '+' || $operator === '-') && $expMatch[2][$k] === $operator) {
2510
-                        $output = '(' . $output . $operator . $operator . ')';
2511
-                        break;
2512
-                    } elseif (substr($expMatch[2][$k], 0, 1) === '$') {
2513
-                        $output = '(' . $output . ' ' . $operator . ' ' . $this->parseVar($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2514
-                    } elseif (substr($expMatch[2][$k], 0, 1) === '%') {
2515
-                        $output = '(' . $output . ' ' . $operator . ' ' . $this->parseConst($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2516
-                    } elseif (!empty($expMatch[2][$k])) {
2517
-                        $output = '(' . $output . ' ' . $operator . ' ' . str_replace(',', '.', $expMatch[2][$k]) . ')';
2518
-                    } else {
2519
-                        throw new CompilationException($this, 'Unfinished expression <em>' . $substr . '</em>, missing var or number after math operator');
2520
-                    }
2521
-                }
2522
-            }
2523
-
2524
-            if ($this->autoEscape === true && $curBlock !== 'condition') {
2525
-                $output = '(is_string($tmp=' . $output . ') ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)';
2526
-            }
2527
-
2528
-            // handle modifiers
2529
-            if ($curBlock !== 'modifier' && $hasModifiers) {
2530
-                $ptr    = 0;
2531
-                $output = $this->replaceModifiers(array(null, null, $output, $match[5]), 'var', $ptr);
2532
-                if ($pointer !== null) {
2533
-                    $pointer += $ptr;
2534
-                }
2535
-                $matchedLength += $ptr;
2536
-            }
2537
-
2538
-            if (is_array($parsingParams)) {
2539
-                $parsingParams[] = array($output, $key);
2540
-
2541
-                return $parsingParams;
2542
-            } elseif ($curBlock === 'namedparam') {
2543
-                return array($output, $key);
2544
-            } elseif ($curBlock === 'string' || $curBlock === 'delimited_string') {
2545
-                return array($matchedLength, $output);
2546
-            } elseif ($curBlock === 'expression' || $curBlock === 'variable') {
2547
-                return $output;
2548
-            } elseif (isset($assign)) {
2549
-                return self::PHP_OPEN . $output . ';' . self::PHP_CLOSE;
2550
-            }
2551
-
2552
-            return $output;
2553
-        } else {
2554
-            if ($curBlock === 'string' || $curBlock === 'delimited_string') {
2555
-                return array(0, '');
2556
-            }
2557
-            throw new CompilationException($this, 'Invalid variable name <em>' . $substr . '</em>');
2558
-        }
2559
-    }
2560
-
2561
-    /**
2562
-     * Parses any number of chained method calls/property reads.
2563
-     *
2564
-     * @param string $output     the variable or whatever upon which the method are called
2565
-     * @param string $methodCall method call source, starting at "->"
2566
-     * @param string $curBlock   the current parser-block being processed
2567
-     * @param int    $pointer    a reference to a pointer that will be increased by the amount of characters parsed
2568
-     *
2569
-     * @return string parsed call(s)/read(s)
2570
-     */
2571
-    protected function parseMethodCall($output, $methodCall, $curBlock, &$pointer)
2572
-    {
2573
-        $ptr = 0;
2574
-        $len = strlen($methodCall);
2575
-
2576
-        while ($ptr < $len) {
2577
-            if (strpos($methodCall, '->', $ptr) === $ptr) {
2578
-                $ptr += 2;
2579
-            }
2580
-
2581
-            if (in_array(
2582
-                $methodCall[$ptr], array(
2583
-                    ';',
2584
-                    ',',
2585
-                    '/',
2586
-                    ' ',
2587
-                    "\t",
2588
-                    "\r",
2589
-                    "\n",
2590
-                    ')',
2591
-                    '+',
2592
-                    '*',
2593
-                    '%',
2594
-                    '=',
2595
-                    '-',
2596
-                    '|'
2597
-                )
2598
-            ) || substr($methodCall, $ptr, strlen($this->rd)) === $this->rd
2599
-            ) {
2600
-                // break char found
2601
-                break;
2602
-            }
2603
-
2604
-            if (!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) {
2605
-                break;
2606
-            }
2607
-
2608
-            if (empty($methMatch[2])) {
2609
-                // property
2610
-                if ($curBlock === 'root') {
2611
-                    $output .= '->' . $methMatch[1];
2612
-                } else {
2613
-                    $output = '(($tmp = ' . $output . ') ? $tmp->' . $methMatch[1] . ' : null)';
2614
-                }
2615
-                $ptr += strlen($methMatch[1]);
2616
-            } else {
2617
-                // method
2618
-                if (substr($methMatch[2], 0, 2) === '()') {
2619
-                    $parsedCall = $methMatch[1] . '()';
2620
-                    $ptr += strlen($methMatch[1]) + 2;
2621
-                } else {
2622
-                    $parsedCall = $this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr);
2623
-                }
2624
-                if ($this->securityPolicy !== null) {
2625
-                    $argPos = strpos($parsedCall, '(');
2626
-                    $method = strtolower(substr($parsedCall, 0, $argPos));
2627
-                    $args   = substr($parsedCall, $argPos);
2628
-                    if ($curBlock === 'root') {
2629
-                        $output = '$this->getSecurityPolicy()->callMethod($this, ' . $output . ', ' . var_export($method, true) . ', array' . $args . ')';
2630
-                    } else {
2631
-                        $output = '(($tmp = ' . $output . ') ? $this->getSecurityPolicy()->callMethod($this, $tmp, ' . var_export($method, true) . ', array' . $args . ') : null)';
2632
-                    }
2633
-                } else {
2634
-                    if ($curBlock === 'root') {
2635
-                        $output .= '->' . $parsedCall;
2636
-                    } else {
2637
-                        $output = '(($tmp = ' . $output . ') ? $tmp->' . $parsedCall . ' : null)';
2638
-                    }
2639
-                }
2640
-            }
2641
-        }
2642
-
2643
-        $pointer += $ptr;
2644
-
2645
-        return $output;
2646
-    }
2647
-
2648
-    /**
2649
-     * Parses a constant variable (a variable that doesn't contain another variable) and preprocesses it to save
2650
-     * runtime processing time.
2651
-     *
2652
-     * @param string $key      the variable to parse
2653
-     * @param string $curBlock the current parser-block being processed
2654
-     *
2655
-     * @return string parsed variable
2656
-     */
2657
-    protected function parseVarKey($key, $curBlock)
2658
-    {
2659
-        if ($key === '') {
2660
-            return '$this->scope';
2661
-        }
2662
-        if (substr($key, 0, 1) === '.') {
2663
-            $key = 'dwoo' . $key;
2664
-        }
2665
-        if (preg_match('#dwoo\.(get|post|server|cookies|session|env|request)((?:\.[a-z0-9_-]+)+)#i', $key, $m)) {
2666
-            $global = strtoupper($m[1]);
2667
-            if ($global === 'COOKIES') {
2668
-                $global = 'COOKIE';
2669
-            }
2670
-            $key = '$_' . $global;
2671
-            foreach (explode('.', ltrim($m[2], '.')) as $part) {
2672
-                $key .= '[' . var_export($part, true) . ']';
2673
-            }
2674
-            if ($curBlock === 'root') {
2675
-                $output = $key;
2676
-            } else {
2677
-                $output = '(isset(' . $key . ')?' . $key . ':null)';
2678
-            }
2679
-        } elseif (preg_match('#dwoo\\.const\\.([a-z0-9\\\\_:]+)#i', $key, $m)) {
2680
-            return $this->parseConstKey($m[1], $curBlock);
2681
-        } elseif ($this->scope !== null) {
2682
-            if (strstr($key, '.') === false && strstr($key, '[') === false && strstr($key, '->') === false) {
2683
-                if ($key === 'dwoo') {
2684
-                    $output = '$this->globals';
2685
-                } elseif ($key === '_root' || $key === '__') {
2686
-                    $output = '$this->data';
2687
-                } elseif ($key === '_parent' || $key === '_') {
2688
-                    $output = '$this->readParentVar(1)';
2689
-                } elseif ($key === '_key') {
2690
-                    $output = '$tmp_key';
2691
-                } else {
2692
-                    if ($curBlock === 'root') {
2693
-                        $output = '$this->scope["' . $key . '"]';
2694
-                    } else {
2695
-                        $output = '(isset($this->scope["' . $key . '"]) ? $this->scope["' . $key . '"] : null)';
2696
-                    }
2697
-                }
2698
-            } else {
2699
-                preg_match_all('#(\[|->|\.)?((?:[a-z0-9_]|-(?!>))+|(\\\?[\'"])[^\3]*?\3)\]?#i', $key, $m);
2700
-
2701
-                $i = $m[2][0];
2702
-                if ($i === '_parent' || $i === '_') {
2703
-                    $parentCnt = 0;
2704
-
2705
-                    while (true) {
2706
-                        ++ $parentCnt;
2707
-                        array_shift($m[2]);
2708
-                        array_shift($m[1]);
2709
-                        if (current($m[2]) === '_parent') {
2710
-                            continue;
2711
-                        }
2712
-                        break;
2713
-                    }
2714
-
2715
-                    $output = '$this->readParentVar(' . $parentCnt . ')';
2716
-                } else {
2717
-                    if ($i === 'dwoo') {
2718
-                        $output = '$this->globals';
2719
-                        array_shift($m[2]);
2720
-                        array_shift($m[1]);
2721
-                    } elseif ($i === '_root' || $i === '__') {
2722
-                        // $output = '$this->data';
2723
-                        $output = '$this->getData()';
2724
-                        array_shift($m[2]);
2725
-                        array_shift($m[1]);
2726
-                    } elseif ($i === '_key') {
2727
-                        $output = '$tmp_key';
2728
-                    } else {
2729
-                        $output = '$this->scope';
2730
-                    }
2731
-
2732
-                    while (count($m[1]) && $m[1][0] !== '->') {
2733
-                        $m[2][0] = preg_replace('/(^\\\([\'"])|\\\([\'"])$)/x', '$2$3', $m[2][0]);
2734
-                        if (substr($m[2][0], 0, 1) == '"' || substr($m[2][0], 0, 1) == "'") {
2735
-                            $output .= '[' . $m[2][0] . ']';
2736
-                        } else {
2737
-                            $output .= '["' . $m[2][0] . '"]';
2738
-                        }
2739
-                        array_shift($m[2]);
2740
-                        array_shift($m[1]);
2741
-                    }
2742
-
2743
-                    if ($curBlock !== 'root') {
2744
-                        $output = '(isset(' . $output . ') ? ' . $output . ':null)';
2745
-                    }
2746
-                }
2747
-
2748
-                if (count($m[2])) {
2749
-                    unset($m[0]);
2750
-                    $output = '$this->readVarInto(' . str_replace("\n", '', var_export($m, true)) . ', ' . $output . ', ' . ($curBlock == 'root' ? 'false' : 'true') . ')';
2751
-                }
2752
-            }
2753
-        } else {
2754
-            preg_match_all('#(\[|->|\.)?((?:[a-z0-9_]|-(?!>))+)\]?#i', $key, $m);
2755
-            unset($m[0]);
2756
-            $output = '$this->readVar(' . str_replace("\n", '', var_export($m, true)) . ')';
2757
-        }
2758
-
2759
-        return $output;
2760
-    }
2761
-
2762
-    /**
2763
-     * Flattens a variable tree, this helps in parsing very complex variables such as $var.foo[$foo.bar->baz].baz,
2764
-     * it computes the contents of the brackets first and works out from there.
2765
-     *
2766
-     * @param array $tree     the variable tree parsed by he parseVar() method that must be flattened
2767
-     * @param bool  $recursed leave that to false by default, it is only for internal use
2768
-     *
2769
-     * @return string flattened tree
2770
-     */
2771
-    protected function flattenVarTree(array $tree, $recursed = false)
2772
-    {
2773
-        $out = $recursed ? '".$this->readVarInto(' : '';
2774
-        foreach ($tree as $bit) {
2775
-            if (is_array($bit)) {
2776
-                $out .= '.' . $this->flattenVarTree($bit, false);
2777
-            } else {
2778
-                $key = str_replace('"', '\\"', $bit);
2779
-
2780
-                if (substr($key, 0, 1) === '$') {
2781
-                    $out .= '".' . $this->parseVar($key, 0, strlen($key), false, 'variable') . '."';
2782
-                } else {
2783
-                    $cnt = substr_count($key, '$');
2784
-
2785
-                    if ($this->debug) {
2786
-                        echo 'PARSING SUBVARS IN : ' . $key . "\n";
2787
-                    }
2788
-                    if ($cnt > 0) {
2789
-                        while (-- $cnt >= 0) {
2790
-                            if (isset($last)) {
2791
-                                $last = strrpos($key, '$', - (strlen($key) - $last + 1));
2792
-                            } else {
2793
-                                $last = strrpos($key, '$');
2794
-                            }
2795
-                            preg_match('#\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', substr($key, $last), $submatch);
2796
-
2797
-                            $len = strlen($submatch[0]);
2798
-                            $key = substr_replace(
2799
-                                $key, preg_replace_callback(
2800
-                                    '#(\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*)' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', array(
2801
-                                        $this,
2802
-                                        'replaceVarKeyHelper'
2803
-                                    ), substr($key, $last, $len)
2804
-                                ), $last, $len
2805
-                            );
2806
-                            if ($this->debug) {
2807
-                                echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2808
-                            }
2809
-                        }
2810
-                        unset($last);
2811
-
2812
-                        $out .= $key;
2813
-                    } else {
2814
-                        $out .= $key;
2815
-                    }
2816
-                }
2817
-            }
2818
-        }
2819
-        $out .= $recursed ? ', true)."' : '';
2820
-
2821
-        return $out;
2822
-    }
2823
-
2824
-    /**
2825
-     * Helper function that parses a variable.
2826
-     *
2827
-     * @param array $match the matched variable, array(1=>"string match")
2828
-     *
2829
-     * @return string parsed variable
2830
-     */
2831
-    protected function replaceVarKeyHelper($match)
2832
-    {
2833
-        return '".' . $this->parseVar($match[0], 0, strlen($match[0]), false, 'variable') . '."';
2834
-    }
2835
-
2836
-    /**
2837
-     * Parses various constants, operators or non-quoted strings.
2838
-     *
2839
-     * @param string $in            the string within which we must parse something
2840
-     * @param int    $from          the starting offset of the parsed area
2841
-     * @param int    $to            the ending offset of the parsed area
2842
-     * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2843
-     *                              default
2844
-     * @param string $curBlock      the current parser-block being processed
2845
-     * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2846
-     *                              or null by default
2847
-     *
2848
-     * @return string parsed values
2849
-     * @throws Exception
2850
-     */
2851
-    protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2852
-    {
2853
-        $substr = substr($in, $from, $to - $from);
2854
-
2855
-        $end = strlen($substr);
2856
-
2857
-        if ($curBlock === 'condition') {
2858
-            $breakChars = array(
2859
-                '(',
2860
-                ')',
2861
-                ' ',
2862
-                '||',
2863
-                '&&',
2864
-                '|',
2865
-                '&',
2866
-                '>=',
2867
-                '<=',
2868
-                '===',
2869
-                '==',
2870
-                '=',
2871
-                '!==',
2872
-                '!=',
2873
-                '<<',
2874
-                '<',
2875
-                '>>',
2876
-                '>',
2877
-                '^',
2878
-                '~',
2879
-                ',',
2880
-                '+',
2881
-                '-',
2882
-                '*',
2883
-                '/',
2884
-                '%',
2885
-                '!',
2886
-                '?',
2887
-                ':',
2888
-                $this->rd,
2889
-                ';'
2890
-            );
2891
-        } elseif ($curBlock === 'modifier') {
2892
-            $breakChars = array(' ', ',', ')', ':', '|', "\r", "\n", "\t", ';', $this->rd);
2893
-        } elseif ($curBlock === 'expression') {
2894
-            $breakChars = array('/', '%', '+', '-', '*', ' ', ',', ')', "\r", "\n", "\t", ';', $this->rd);
2895
-        } else {
2896
-            $breakChars = array(' ', ',', ')', "\r", "\n", "\t", ';', $this->rd);
2897
-        }
2898
-
2899
-        $breaker = false;
2900
-        foreach ($breakChars as $k => $char) {
2901
-            $test = strpos($substr, $char);
2902
-            if ($test !== false && $test < $end) {
2903
-                $end     = $test;
2904
-                $breaker = $k;
2905
-            }
2906
-        }
2907
-
2908
-        if ($curBlock === 'condition') {
2909
-            if ($end === 0 && $breaker !== false) {
2910
-                $end = strlen($breakChars[$breaker]);
2911
-            }
2912
-        }
2913
-
2914
-        if ($end !== false) {
2915
-            $substr = substr($substr, 0, $end);
2916
-        }
2917
-
2918
-        if ($pointer !== null) {
2919
-            $pointer += strlen($substr);
2920
-        }
2921
-
2922
-        $src    = $substr;
2923
-        $substr = trim($substr);
2924
-
2925
-        if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') {
2926
-            if ($this->debug) {
2927
-                echo 'BOOLEAN(FALSE) PARSED' . "\n";
2928
-            }
2929
-            $substr = 'false';
2930
-            $type   = self::T_BOOL;
2931
-        } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') {
2932
-            if ($this->debug) {
2933
-                echo 'BOOLEAN(TRUE) PARSED' . "\n";
2934
-            }
2935
-            $substr = 'true';
2936
-            $type   = self::T_BOOL;
2937
-        } elseif ($substr === 'null' || $substr === 'NULL') {
2938
-            if ($this->debug) {
2939
-                echo 'NULL PARSED' . "\n";
2940
-            }
2941
-            $substr = 'null';
2942
-            $type   = self::T_NULL;
2943
-        } elseif (is_numeric($substr)) {
2944
-            $substr = (float)$substr;
2945
-            if ((int)$substr == $substr) {
2946
-                $substr = (int)$substr;
2947
-            }
2948
-            $type = self::T_NUMERIC;
2949
-            if ($this->debug) {
2950
-                echo 'NUMBER (' . $substr . ') PARSED' . "\n";
2951
-            }
2952
-        } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) {
2953
-            if ($this->debug) {
2954
-                echo 'SIMPLE MATH PARSED . "\n"';
2955
-            }
2956
-            $type   = self::T_MATH;
2957
-            $substr = '(' . $substr . ')';
2958
-        } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) {
2959
-            if ($this->debug) {
2960
-                echo 'BREAKCHAR (' . $substr . ') PARSED' . "\n";
2961
-            }
2962
-            $type = self::T_BREAKCHAR;
2963
-            //$substr = '"'.$substr.'"';
2964
-        } else {
2965
-            $substr = $this->replaceStringVars('\'' . str_replace('\'', '\\\'', $substr) . '\'', '\'', $curBlock);
2966
-            $type   = self::T_UNQUOTED_STRING;
2967
-            if ($this->debug) {
2968
-                echo 'BLABBER (' . $substr . ') CASTED AS STRING' . "\n";
2969
-            }
2970
-        }
2971
-
2972
-        if (is_array($parsingParams)) {
2973
-            $parsingParams[] = array($substr, $src, $type);
2974
-
2975
-            return $parsingParams;
2976
-        } elseif ($curBlock === 'namedparam') {
2977
-            return array($substr, $src, $type);
2978
-        } elseif ($curBlock === 'expression') {
2979
-            return $substr;
2980
-        } else {
2981
-            throw new Exception('Something went wrong');
2982
-        }
2983
-    }
2984
-
2985
-    /**
2986
-     * Replaces variables within a parsed string.
2987
-     *
2988
-     * @param string $string   the parsed string
2989
-     * @param string $first    the first character parsed in the string, which is the string delimiter (' or ")
2990
-     * @param string $curBlock the current parser-block being processed
2991
-     *
2992
-     * @return string the original string with variables replaced
2993
-     */
2994
-    protected function replaceStringVars($string, $first, $curBlock = '')
2995
-    {
2996
-        $pos = 0;
2997
-        if ($this->debug) {
2998
-            echo 'STRING VAR REPLACEMENT : ' . $string . "\n";
2999
-        }
3000
-        // replace vars
3001
-        while (($pos = strpos($string, '$', $pos)) !== false) {
3002
-            $prev = substr($string, $pos - 1, 1);
3003
-            if ($prev === '\\') {
3004
-                ++ $pos;
3005
-                continue;
3006
-            }
3007
-
3008
-            $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3009
-            $len = $var[0];
3010
-            $var = $this->parse(str_replace('\\' . $first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3011
-
3012
-            if ($prev === '`' && substr($string, $pos + $len, 1) === '`') {
3013
-                $string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos - 1, $len + 2);
3014
-            } else {
3015
-                $string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos, $len);
3016
-            }
3017
-            $pos += strlen($var[1]) + 2;
3018
-            if ($this->debug) {
3019
-                echo 'STRING VAR REPLACEMENT DONE : ' . $string . "\n";
3020
-            }
3021
-        }
3022
-
3023
-        // handle modifiers
3024
-        // TODO Obsolete?
3025
-        $string = preg_replace_callback(
3026
-            '#("|\')\.(.+?)\.\1((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').+?\4|:[^`]*))*))+)#i', array(
3027
-            $this,
3028
-            'replaceModifiers'
3029
-            ), $string
3030
-        );
3031
-
3032
-        // replace escaped dollar operators by unescaped ones if required
3033
-        if ($first === "'") {
3034
-            $string = str_replace('\\$', '$', $string);
3035
-        }
3036
-
3037
-        return $string;
3038
-    }
3039
-
3040
-    /**
3041
-     * Replaces the modifiers applied to a string or a variable.
3042
-     *
3043
-     * @param array  $m        the regex matches that must be array(1=>"double or single quotes enclosing a string,
3044
-     *                         when applicable", 2=>"the string or var", 3=>"the modifiers matched")
3045
-     * @param string $curBlock the current parser-block being processed
3046
-     * @param null   $pointer
3047
-     *
3048
-     * @return string the input enclosed with various function calls according to the modifiers found
3049
-     * @throws CompilationException
3050
-     * @throws Exception
3051
-     */
3052
-    protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null)
3053
-    {
3054
-        if ($this->debug) {
3055
-            echo 'PARSING MODIFIERS : ' . $m[3] . "\n";
3056
-        }
3057
-
3058
-        if ($pointer !== null) {
3059
-            $pointer += strlen($m[3]);
3060
-        }
3061
-        // remove first pipe
3062
-        $cmdstrsrc = substr($m[3], 1);
3063
-        // remove last quote if present
3064
-        if (substr($cmdstrsrc, - 1, 1) === $m[1]) {
3065
-            $cmdstrsrc = substr($cmdstrsrc, 0, - 1);
3066
-            $add       = $m[1];
3067
-        }
3068
-
3069
-        $output = $m[2];
3070
-
3071
-        $continue = true;
3072
-        while (strlen($cmdstrsrc) > 0 && $continue) {
3073
-            if ($cmdstrsrc[0] === '|') {
3074
-                $cmdstrsrc = substr($cmdstrsrc, 1);
3075
-                continue;
3076
-            }
3077
-            if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) {
3078
-                if ($this->debug) {
3079
-                    echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND' . "\n";
3080
-                }
3081
-                $continue = false;
3082
-                if ($pointer !== null) {
3083
-                    $pointer -= strlen($cmdstrsrc);
3084
-                }
3085
-                break;
3086
-            }
3087
-            $cmdstr   = $cmdstrsrc;
3088
-            $paramsep = ':';
3089
-            if (!preg_match('/^(@{0,2}[a-z_][a-z0-9_]*)(:)?/i', $cmdstr, $match)) {
3090
-                throw new CompilationException($this, 'Invalid modifier name, started with : ' . substr($cmdstr, 0, 10));
3091
-            }
3092
-            $paramspos = !empty($match[2]) ? strlen($match[1]) : false;
3093
-            $func      = $match[1];
3094
-
3095
-            $state = 0;
3096
-            if ($paramspos === false) {
3097
-                $cmdstrsrc = substr($cmdstrsrc, strlen($func));
3098
-                $params    = array();
3099
-                if ($this->debug) {
3100
-                    echo 'MODIFIER (' . $func . ') CALLED WITH NO PARAMS' . "\n";
3101
-                }
3102
-            } else {
3103
-                $paramstr = substr($cmdstr, $paramspos + 1);
3104
-                if (substr($paramstr, - 1, 1) === $paramsep) {
3105
-                    $paramstr = substr($paramstr, 0, - 1);
3106
-                }
3107
-
3108
-                $ptr    = 0;
3109
-                $params = array();
3110
-                while ($ptr < strlen($paramstr)) {
3111
-                    if ($this->debug) {
3112
-                        echo 'MODIFIER (' . $func . ') START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
3113
-                    }
3114
-                    if ($this->debug) {
3115
-                        echo $paramstr . '--' . $ptr . '--' . strlen($paramstr) . '--modifier' . "\n";
3116
-                    }
3117
-                    $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr);
3118
-                    if ($this->debug) {
3119
-                        echo 'PARAM PARSED, POINTER AT ' . $ptr . "\n";
3120
-                    }
3121
-
3122
-                    if ($ptr >= strlen($paramstr)) {
3123
-                        if ($this->debug) {
3124
-                            echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED' . "\n";
3125
-                        }
3126
-                        break;
3127
-                    }
3128
-
3129
-                    if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
3130
-                        if ($this->debug) {
3131
-                            echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT ' . $ptr . "\n";
3132
-                        }
3133
-                        if ($paramstr[$ptr] !== '|') {
3134
-                            $continue = false;
3135
-                            if ($pointer !== null) {
3136
-                                $pointer -= strlen($paramstr) - $ptr;
3137
-                            }
3138
-                        }
3139
-                        ++ $ptr;
3140
-                        break;
3141
-                    }
3142
-                    if ($ptr < strlen($paramstr) && $paramstr[$ptr] === ':') {
3143
-                        ++ $ptr;
3144
-                    }
3145
-                }
3146
-                $cmdstrsrc = substr($cmdstrsrc, strlen($func) + 1 + $ptr);
3147
-                foreach ($params as $k => $p) {
3148
-                    if (is_array($p) && is_array($p[1])) {
3149
-                        $state |= 2;
3150
-                    } else {
3151
-                        if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) {
3152
-                            $params[$k] = array($m[2], array('true', 'true'));
3153
-                        } else {
3154
-                            if ($state & 2) {
3155
-                                throw new CompilationException($this, 'You can not use an unnamed parameter after a named one');
3156
-                            }
3157
-                            $state |= 1;
3158
-                        }
3159
-                    }
3160
-                }
3161
-            }
3162
-
3163
-            // check if we must use array_map with this plugin or not
3164
-            $mapped = false;
3165
-            if (substr($func, 0, 1) === '@') {
3166
-                $func   = substr($func, 1);
3167
-                $mapped = true;
3168
-            }
3169
-
3170
-            $pluginType = $this->getPluginType($func);
3171
-
3172
-            if ($state & 2) {
3173
-                array_unshift($params, array('value', is_array($output) ? $output : array($output, $output)));
3174
-            } else {
3175
-                array_unshift($params, is_array($output) ? $output : array($output, $output));
3176
-            }
3177
-
3178
-            if ($pluginType & Core::NATIVE_PLUGIN) {
3179
-                $params = $this->mapParams($params, null, $state);
3180
-
3181
-                $params = $params['*'][0];
3182
-
3183
-                $params = self::implode_r($params);
3184
-
3185
-                if ($mapped) {
3186
-                    $output = '$this->arrayMap(\'' . $func . '\', array(' . $params . '))';
3187
-                } else {
3188
-                    $output = $func . '(' . $params . ')';
3189
-                }
3190
-            } elseif ($pluginType & Core::PROXY_PLUGIN) {
3191
-                $params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
3192
-                foreach ($params as &$p) {
3193
-                    $p = $p[0];
3194
-                }
3195
-                $output = call_user_func(array($this->getCore()->getPluginProxy(), 'getCode'), $func, $params);
3196
-            } elseif ($pluginType & Core::SMARTY_MODIFIER) {
3197
-                $params = $this->mapParams($params, null, $state);
3198
-                $params = $params['*'][0];
3199
-
3200
-                $params = self::implode_r($params);
3201
-
3202
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
3203
-                    $callback = $this->customPlugins[$func]['callback'];
3204
-                    if (is_array($callback)) {
3205
-                        if (is_object($callback[0])) {
3206
-                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3207
-                        } else {
3208
-                            $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3209
-                        }
3210
-                    } elseif ($mapped) {
3211
-                        $output = '$this->arrayMap(\'' . $callback . '\', array(' . $params . '))';
3212
-                    } else {
3213
-                        $output = $callback . '(' . $params . ')';
3214
-                    }
3215
-                } elseif ($mapped) {
3216
-                    $output = '$this->arrayMap(\'smarty_modifier_' . $func . '\', array(' . $params . '))';
3217
-                } else {
3218
-                    $output = 'smarty_modifier_' . $func . '(' . $params . ')';
3219
-                }
3220
-            } else {
3221
-                if ($pluginType & Core::CUSTOM_PLUGIN) {
3222
-                    $pluginName = $callback = $this->customPlugins[$func]['callback'];
3223
-                    if (($pluginType & Core::CLASS_PLUGIN) && !is_array($callback)) {
3224
-                        $pluginName = $this->customPlugins[$func]['callback'];
3225
-                        $callback   = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3226
-                    }
3227
-                } else {
3228
-                    if (class_exists('Plugin' . Core::toCamelCase($func)) !== false || function_exists('Plugin' .
3229
-                            Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''))
3230
-                        !== false) {
3231
-                        $pluginName = 'Plugin' . Core::toCamelCase($func);
3232
-                    } else {
3233
-                        $pluginName = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func);
3234
-                    }
3235
-                    if ($pluginType & Core::CLASS_PLUGIN) {
3236
-                        $callback = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3237
-                    } else {
3238
-                        $callback = $pluginName . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '');
3239
-                    }
3240
-                }
3241
-                $params = $this->mapParams($params, $callback, $state);
3242
-
3243
-                foreach ($params as &$p) {
3244
-                    $p = $p[0];
3245
-                }
3246
-
3247
-                // Only for PHP function, who is not a PHP class
3248
-                if ($pluginType & Core::FUNC_PLUGIN && !($pluginType & Core::CLASS_PLUGIN)) {
3249
-                    if ($pluginType & Core::COMPILABLE_PLUGIN) {
3250
-                        if ($mapped) {
3251
-                            throw new CompilationException($this, 'The @ operator can not be used on compiled plugins.');
3252
-                        }
3253
-                        if ($pluginType & Core::CUSTOM_PLUGIN) {
3254
-                            $funcCompiler = $this->customPlugins[$func]['callback'];
3255
-                        } else {
3256
-                            if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
3257
-                                $funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
3258
-                            } else {
3259
-                                $funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
3260
-                                    'Compile';
3261
-                            }
3262
-                        }
3263
-                        array_unshift($params, $this);
3264
-                        $output = call_user_func_array($funcCompiler, $params);
3265
-                    } else {
3266
-                        array_unshift($params, '$this');
3267
-
3268
-                        $params = self::implode_r($params);
3269
-                        if ($mapped) {
3270
-                            $output = '$this->arrayMap(\'' . $pluginName . '\', array(' . $params . '))';
3271
-                        } else {
3272
-                            $output = $pluginName . '(' . $params . ')';
3273
-                        }
3274
-                    }
3275
-                } else {
3276
-                    if ($pluginType & Core::COMPILABLE_PLUGIN) {
3277
-                        if ($mapped) {
3278
-                            throw new CompilationException($this, 'The @ operator can not be used on compiled plugins.');
3279
-                        }
3280
-                        if ($pluginType & Core::CUSTOM_PLUGIN) {
3281
-                            $callback = $this->customPlugins[$func]['callback'];
3282
-                            if (!is_array($callback)) {
3283
-                                if (!method_exists($callback, 'compile')) {
3284
-                                    throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
3285
-                                }
3286
-                                if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
3287
-                                    $funcCompiler = array($callback, 'compile');
3288
-                                } else {
3289
-                                    $funcCompiler = array(new $callback(), 'compile');
3290
-                                }
3291
-                            } else {
3292
-                                $funcCompiler = $callback;
3293
-                            }
3294
-                        } else {
3295
-                            if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3296
-                                $funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
3297
-                            } else {
3298
-                                $funcCompiler = array(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func), 'compile');
3299
-                            }
3300
-                            array_unshift($params, $this);
3301
-                        }
3302
-                        $output = call_user_func_array($funcCompiler, $params);
3303
-                    } else {
3304
-                        $params = self::implode_r($params);
3305
-
3306
-                        if ($pluginType & Core::CUSTOM_PLUGIN) {
3307
-                            if (is_object($callback[0])) {
3308
-                                if (is_array($this->getCore()->getCustomPlugin($func))) {
3309
-                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), array(' . $params . '))';
3310
-                                } else {
3311
-                                    $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3312
-                                }
3313
-                            } else {
3314
-                                $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3315
-                            }
3316
-                        } elseif ($mapped) {
3317
-                            $output = '$this->arrayMap(array($this->getObjectPlugin(\''.
3318
-                                Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '\'), 
2094
+					} else {
2095
+						$output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
2096
+					}
2097
+				}
2098
+			}
2099
+		} // Function plugin only (cannot be a class)
2100
+		elseif ($pluginType & Core::FUNC_PLUGIN) {
2101
+			if ($pluginType & Core::COMPILABLE_PLUGIN) {
2102
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
2103
+					$funcCompiler = $this->customPlugins[$func]['callback'];
2104
+				} else {
2105
+					// Custom plugin
2106
+					if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2107
+						$funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
2108
+					} // Builtin helper plugin
2109
+					elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
2110
+						$funcCompiler = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) .
2111
+							'Compile';
2112
+					} // Builtin function plugin
2113
+					else {
2114
+						$funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
2115
+							'Compile';
2116
+					}
2117
+				}
2118
+				array_unshift($params, $this);
2119
+				// @TODO: Is it a real fix ?
2120
+				if ($func === 'tif') {
2121
+					$params[] = $tokens;
2122
+				}
2123
+				$output = call_user_func_array($funcCompiler, $params);
2124
+			} else {
2125
+				array_unshift($params, '$this');
2126
+				$params = self::implode_r($params);
2127
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
2128
+					$callback = $this->customPlugins[$func]['callback'];
2129
+					if ($callback instanceof Closure) {
2130
+						$output = 'call_user_func($this->getCustomPlugin(\'' . $func . '\'), ' . $params . ')';
2131
+					} else {
2132
+						$output = 'call_user_func(\'' . $callback . '\', ' . $params . ')';
2133
+					}
2134
+				} else {
2135
+					// Custom plugin
2136
+					if (function_exists('Plugin' . Core::toCamelCase($func)) !== false) {
2137
+						$output = 'Plugin' . Core::toCamelCase($func) . '(' . $params .
2138
+							')';
2139
+					} // Builtin helper plugin
2140
+					elseif(function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func)) !==
2141
+						false) {
2142
+						$output = Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($func) . '(' .
2143
+							$params . ')';
2144
+					} // Builtin function plugin
2145
+					else {
2146
+						$output = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '(' .
2147
+							$params . ')';
2148
+					}
2149
+				}
2150
+			}
2151
+		} // Proxy plugin
2152
+		elseif ($pluginType & Core::PROXY_PLUGIN) {
2153
+			$output = call_user_func(array($this->getCore()->getPluginProxy(), 'getCode'), $func, $params);
2154
+		} // Smarty function (@deprecated)
2155
+		elseif ($pluginType & Core::SMARTY_FUNCTION) {
2156
+			$params = '';
2157
+			if (isset($params['*'])) {
2158
+				$params = self::implode_r($params['*'], true);
2159
+			}
2160
+
2161
+			if ($pluginType & Core::CUSTOM_PLUGIN) {
2162
+				$callback = $this->customPlugins[$func]['callback'];
2163
+				if (is_array($callback)) {
2164
+					if (is_object($callback[0])) {
2165
+						$output = 'call_user_func_array(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2166
+					} else {
2167
+						$output = 'call_user_func_array(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(array(' . $params . '), $this))';
2168
+					}
2169
+				} else {
2170
+					$output = $callback . '(array(' . $params . '), $this)';
2171
+				}
2172
+			} else {
2173
+				$output = 'smarty_function_' . $func . '(array(' . $params . '), $this)';
2174
+			}
2175
+		} // Template plugin
2176
+		elseif ($pluginType & Core::TEMPLATE_PLUGIN) {
2177
+			array_unshift($params, '$this');
2178
+			$params                                 = self::implode_r($params);
2179
+			$output                                 = 'Plugin' . Core::toCamelCase($func) .
2180
+				$this->templatePlugins[$func]['uuid'] . '(' . $params . ')';
2181
+			$this->templatePlugins[$func]['called'] = true;
2182
+		}
2183
+
2184
+		if (is_array($parsingParams)) {
2185
+			$parsingParams[] = array($output, $output);
2186
+
2187
+			return $parsingParams;
2188
+		} elseif ($curBlock === 'namedparam') {
2189
+			return array($output, $output);
2190
+		}
2191
+
2192
+		return $output;
2193
+	}
2194
+
2195
+	/**
2196
+	 * Parses a string.
2197
+	 *
2198
+	 * @param string $in            the string within which we must parse something
2199
+	 * @param int    $from          the starting offset of the parsed area
2200
+	 * @param int    $to            the ending offset of the parsed area
2201
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2202
+	 *                              default
2203
+	 * @param string $curBlock      the current parser-block being processed
2204
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2205
+	 *                              or null by default
2206
+	 *
2207
+	 * @return string parsed values
2208
+	 * @throws CompilationException
2209
+	 */
2210
+	protected function parseString($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2211
+	{
2212
+		$substr = substr($in, $from, $to - $from);
2213
+		$first  = $substr[0];
2214
+
2215
+		if ($this->debug) {
2216
+			echo 'STRING FOUND (in ' . htmlentities(substr($in, $from, min($to - $from, 50))) . (($to - $from) > 50 ? '...' : '') . ')' . "\n";
2217
+		}
2218
+		$strend = false;
2219
+		$o      = $from + 1;
2220
+		while ($strend === false) {
2221
+			$strend = strpos($in, $first, $o);
2222
+			if ($strend === false) {
2223
+				throw new CompilationException($this, 'Unfinished string, started with ' . substr($in, $from, $to - $from));
2224
+			}
2225
+			if (substr($in, $strend - 1, 1) === '\\') {
2226
+				$o      = $strend + 1;
2227
+				$strend = false;
2228
+			}
2229
+		}
2230
+		if ($this->debug) {
2231
+			echo 'STRING DELIMITED: ' . substr($in, $from, $strend + 1 - $from) . "\n";
2232
+		}
2233
+
2234
+		$srcOutput = substr($in, $from, $strend + 1 - $from);
2235
+
2236
+		if ($pointer !== null) {
2237
+			$pointer += strlen($srcOutput);
2238
+		}
2239
+
2240
+		$output = $this->replaceStringVars($srcOutput, $first);
2241
+
2242
+		// handle modifiers
2243
+		if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend + 1 - $from), $match)) {
2244
+			$modstr = $match[1];
2245
+
2246
+			if ($curBlock === 'root' && substr($modstr, - 1) === '}') {
2247
+				$modstr = substr($modstr, 0, - 1);
2248
+			}
2249
+			$modstr = str_replace('\\' . $first, $first, $modstr);
2250
+			$ptr    = 0;
2251
+			$output = $this->replaceModifiers(array(null, null, $output, $modstr), 'string', $ptr);
2252
+
2253
+			$strend += $ptr;
2254
+			if ($pointer !== null) {
2255
+				$pointer += $ptr;
2256
+			}
2257
+			$srcOutput .= substr($substr, $strend + 1 - $from, $ptr);
2258
+		}
2259
+
2260
+		if (is_array($parsingParams)) {
2261
+			$parsingParams[] = array($output, substr($srcOutput, 1, - 1));
2262
+
2263
+			return $parsingParams;
2264
+		} elseif ($curBlock === 'namedparam') {
2265
+			return array($output, substr($srcOutput, 1, - 1));
2266
+		}
2267
+
2268
+		return $output;
2269
+	}
2270
+
2271
+	/**
2272
+	 * Parses a constant.
2273
+	 *
2274
+	 * @param string $in            the string within which we must parse something
2275
+	 * @param int    $from          the starting offset of the parsed area
2276
+	 * @param int    $to            the ending offset of the parsed area
2277
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2278
+	 *                              default
2279
+	 * @param string $curBlock      the current parser-block being processed
2280
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2281
+	 *                              or null by default
2282
+	 *
2283
+	 * @return string parsed values
2284
+	 * @throws CompilationException
2285
+	 */
2286
+	protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2287
+	{
2288
+		$substr = substr($in, $from, $to - $from);
2289
+
2290
+		if ($this->debug) {
2291
+			echo 'CONST FOUND : ' . $substr . "\n";
2292
+		}
2293
+
2294
+		if (!preg_match('#^%([\\\\a-z0-9_:]+)#i', $substr, $m)) {
2295
+			throw new CompilationException($this, 'Invalid constant');
2296
+		}
2297
+
2298
+		if ($pointer !== null) {
2299
+			$pointer += strlen($m[0]);
2300
+		}
2301
+
2302
+		$output = $this->parseConstKey($m[1], $curBlock);
2303
+
2304
+		if (is_array($parsingParams)) {
2305
+			$parsingParams[] = array($output, $m[1]);
2306
+
2307
+			return $parsingParams;
2308
+		} elseif ($curBlock === 'namedparam') {
2309
+			return array($output, $m[1]);
2310
+		}
2311
+
2312
+		return $output;
2313
+	}
2314
+
2315
+	/**
2316
+	 * Parses a constant.
2317
+	 *
2318
+	 * @param string $key      the constant to parse
2319
+	 * @param string $curBlock the current parser-block being processed
2320
+	 *
2321
+	 * @return string parsed constant
2322
+	 */
2323
+	protected function parseConstKey($key, $curBlock)
2324
+	{
2325
+		$key = str_replace('\\\\', '\\', $key);
2326
+
2327
+		if ($this->securityPolicy !== null && $this->securityPolicy->getConstantHandling() === SecurityPolicy::CONST_DISALLOW) {
2328
+			return 'null';
2329
+		}
2330
+
2331
+		if ($curBlock !== 'root') {
2332
+			return '(defined("' . $key . '") ? ' . $key . ' : null)';
2333
+		}
2334
+
2335
+		return $key;
2336
+	}
2337
+
2338
+	/**
2339
+	 * Parses a variable.
2340
+	 *
2341
+	 * @param string $in            the string within which we must parse something
2342
+	 * @param int    $from          the starting offset of the parsed area
2343
+	 * @param int    $to            the ending offset of the parsed area
2344
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2345
+	 *                              default
2346
+	 * @param string $curBlock      the current parser-block being processed
2347
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2348
+	 *                              or null by default
2349
+	 *
2350
+	 * @return string parsed values
2351
+	 * @throws CompilationException
2352
+	 */
2353
+	protected function parseVar($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2354
+	{
2355
+		$substr = substr($in, $from, $to - $from);
2356
+
2357
+		// var key
2358
+		$varRegex = '(\\$?\\.?[a-z0-9\\\\_:]*(?:(?:(?:\\.|->)(?:[a-z0-9\\\\_:]+|(?R))|\\[(?:[a-z0-9\\\\_:]+|(?R)|(["\'])[^\\2]*?\\2)\\]))*)';
2359
+		// method call
2360
+		$methodCall = ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'expression' || $curBlock === 'delimited_string' ? '(\(.*)?' : '()');
2361
+		// simple math expressions
2362
+		$simpleMathExpressions = ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'delimited_string' ? '((?:(?:[+\/*%=-])(?:(?<!=)=?-?[$%][a-z0-9\\\\.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9\.,]*|[+-]))*)' : '()');
2363
+		// modifiers
2364
+		$modifiers = $curBlock !== 'modifier' ? '((?:\|(?:@?[a-z0-9\\\\_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?' : '(())';
2365
+
2366
+		$regex = '#';
2367
+		$regex .= $varRegex;
2368
+		$regex .= $methodCall;
2369
+		$regex .= $simpleMathExpressions;
2370
+		$regex .= $modifiers;
2371
+		$regex .= '#i';
2372
+
2373
+		if (preg_match($regex, $substr, $match)) {
2374
+			$key = substr($match[1], 1);
2375
+
2376
+			$matchedLength = strlen($match[0]);
2377
+			$hasModifiers  = !empty($match[5]);
2378
+			$hasExpression = !empty($match[4]);
2379
+			$hasMethodCall = !empty($match[3]);
2380
+
2381
+			if (substr($key, - 1) == '.') {
2382
+				$key = substr($key, 0, - 1);
2383
+				-- $matchedLength;
2384
+			}
2385
+
2386
+			if ($hasMethodCall) {
2387
+				$matchedLength -= strlen($match[3]) + strlen(substr($match[1], strrpos($match[1], '->')));
2388
+				$key        = substr($match[1], 1, strrpos($match[1], '->') - 1);
2389
+				$methodCall = substr($match[1], strrpos($match[1], '->')) . $match[3];
2390
+			}
2391
+
2392
+			if ($hasModifiers) {
2393
+				$matchedLength -= strlen($match[5]);
2394
+			}
2395
+
2396
+			if ($pointer !== null) {
2397
+				$pointer += $matchedLength;
2398
+			}
2399
+
2400
+			// replace useless brackets by dot accessed vars and strip enclosing quotes if present
2401
+			$key = preg_replace('#\[(["\']?)([^$%\[.>-]+)\1\]#', '.$2', $key);
2402
+
2403
+			if ($this->debug) {
2404
+				if ($hasMethodCall) {
2405
+					echo 'METHOD CALL FOUND : $' . $key . substr($methodCall, 0, 30) . "\n";
2406
+				} else {
2407
+					echo 'VAR FOUND : $' . $key . "\n";
2408
+				}
2409
+			}
2410
+
2411
+			$key = str_replace('"', '\\"', $key);
2412
+
2413
+			$cnt = substr_count($key, '$');
2414
+			if ($cnt > 0) {
2415
+				$uid           = 0;
2416
+				$parsed        = array($uid => '');
2417
+				$current       = &$parsed;
2418
+				$curTxt        = &$parsed[$uid ++];
2419
+				$tree          = array();
2420
+				$chars         = str_split($key, 1);
2421
+				$inSplittedVar = false;
2422
+				$bracketCount  = 0;
2423
+
2424
+				while (($char = array_shift($chars)) !== null) {
2425
+					if ($char === '[') {
2426
+						if (count($tree) > 0) {
2427
+							++ $bracketCount;
2428
+						} else {
2429
+							$tree[]        = &$current;
2430
+							$current[$uid] = array($uid + 1 => '');
2431
+							$current       = &$current[$uid ++];
2432
+							$curTxt        = &$current[$uid ++];
2433
+							continue;
2434
+						}
2435
+					} elseif ($char === ']') {
2436
+						if ($bracketCount > 0) {
2437
+							-- $bracketCount;
2438
+						} else {
2439
+							$current = &$tree[count($tree) - 1];
2440
+							array_pop($tree);
2441
+							if (current($chars) !== '[' && current($chars) !== false && current($chars) !== ']') {
2442
+								$current[$uid] = '';
2443
+								$curTxt        = &$current[$uid ++];
2444
+							}
2445
+							continue;
2446
+						}
2447
+					} elseif ($char === '$') {
2448
+						if (count($tree) == 0) {
2449
+							$curTxt        = &$current[$uid ++];
2450
+							$inSplittedVar = true;
2451
+						}
2452
+					} elseif (($char === '.' || $char === '-') && count($tree) == 0 && $inSplittedVar) {
2453
+						$curTxt        = &$current[$uid ++];
2454
+						$inSplittedVar = false;
2455
+					}
2456
+
2457
+					$curTxt .= $char;
2458
+				}
2459
+				unset($uid, $current, $curTxt, $tree, $chars);
2460
+
2461
+				if ($this->debug) {
2462
+					echo 'RECURSIVE VAR REPLACEMENT : ' . $key . "\n";
2463
+				}
2464
+
2465
+				$key = $this->flattenVarTree($parsed);
2466
+
2467
+				if ($this->debug) {
2468
+					echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2469
+				}
2470
+
2471
+				$output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("' . $key . '")');
2472
+			} else {
2473
+				$output = $this->parseVarKey($key, $hasModifiers ? 'modifier' : $curBlock);
2474
+			}
2475
+
2476
+
2477
+			// methods
2478
+			if ($hasMethodCall) {
2479
+				$ptr = 0;
2480
+
2481
+				$output = $this->parseMethodCall($output, $methodCall, $curBlock, $ptr);
2482
+
2483
+				if ($pointer !== null) {
2484
+					$pointer += $ptr;
2485
+				}
2486
+				$matchedLength += $ptr;
2487
+			}
2488
+
2489
+			if ($hasExpression) {
2490
+				// expressions
2491
+				preg_match_all('#(?:([+/*%=-])(=?-?[%$][a-z0-9\\\\.[\]>_:-]+(?:\([^)]*\))?|=?-?[0-9.,]+|\1))#i', $match[4], $expMatch);
2492
+				foreach ($expMatch[1] as $k => $operator) {
2493
+					if (substr($expMatch[2][$k], 0, 1) === '=') {
2494
+						$assign = true;
2495
+						if ($operator === '=') {
2496
+							throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, can not use "==" in expressions');
2497
+						}
2498
+						if ($curBlock !== 'root') {
2499
+							throw new CompilationException($this, 'Invalid expression <em>' . $substr . '</em>, assignments can only be used in top level expressions like {$foo+=3} or {$foo="bar"}');
2500
+						}
2501
+						$operator .= '=';
2502
+						$expMatch[2][$k] = substr($expMatch[2][$k], 1);
2503
+					}
2504
+
2505
+					if (substr($expMatch[2][$k], 0, 1) === '-' && strlen($expMatch[2][$k]) > 1) {
2506
+						$operator .= '-';
2507
+						$expMatch[2][$k] = substr($expMatch[2][$k], 1);
2508
+					}
2509
+					if (($operator === '+' || $operator === '-') && $expMatch[2][$k] === $operator) {
2510
+						$output = '(' . $output . $operator . $operator . ')';
2511
+						break;
2512
+					} elseif (substr($expMatch[2][$k], 0, 1) === '$') {
2513
+						$output = '(' . $output . ' ' . $operator . ' ' . $this->parseVar($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2514
+					} elseif (substr($expMatch[2][$k], 0, 1) === '%') {
2515
+						$output = '(' . $output . ' ' . $operator . ' ' . $this->parseConst($expMatch[2][$k], 0, strlen($expMatch[2][$k]), false, 'expression') . ')';
2516
+					} elseif (!empty($expMatch[2][$k])) {
2517
+						$output = '(' . $output . ' ' . $operator . ' ' . str_replace(',', '.', $expMatch[2][$k]) . ')';
2518
+					} else {
2519
+						throw new CompilationException($this, 'Unfinished expression <em>' . $substr . '</em>, missing var or number after math operator');
2520
+					}
2521
+				}
2522
+			}
2523
+
2524
+			if ($this->autoEscape === true && $curBlock !== 'condition') {
2525
+				$output = '(is_string($tmp=' . $output . ') ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)';
2526
+			}
2527
+
2528
+			// handle modifiers
2529
+			if ($curBlock !== 'modifier' && $hasModifiers) {
2530
+				$ptr    = 0;
2531
+				$output = $this->replaceModifiers(array(null, null, $output, $match[5]), 'var', $ptr);
2532
+				if ($pointer !== null) {
2533
+					$pointer += $ptr;
2534
+				}
2535
+				$matchedLength += $ptr;
2536
+			}
2537
+
2538
+			if (is_array($parsingParams)) {
2539
+				$parsingParams[] = array($output, $key);
2540
+
2541
+				return $parsingParams;
2542
+			} elseif ($curBlock === 'namedparam') {
2543
+				return array($output, $key);
2544
+			} elseif ($curBlock === 'string' || $curBlock === 'delimited_string') {
2545
+				return array($matchedLength, $output);
2546
+			} elseif ($curBlock === 'expression' || $curBlock === 'variable') {
2547
+				return $output;
2548
+			} elseif (isset($assign)) {
2549
+				return self::PHP_OPEN . $output . ';' . self::PHP_CLOSE;
2550
+			}
2551
+
2552
+			return $output;
2553
+		} else {
2554
+			if ($curBlock === 'string' || $curBlock === 'delimited_string') {
2555
+				return array(0, '');
2556
+			}
2557
+			throw new CompilationException($this, 'Invalid variable name <em>' . $substr . '</em>');
2558
+		}
2559
+	}
2560
+
2561
+	/**
2562
+	 * Parses any number of chained method calls/property reads.
2563
+	 *
2564
+	 * @param string $output     the variable or whatever upon which the method are called
2565
+	 * @param string $methodCall method call source, starting at "->"
2566
+	 * @param string $curBlock   the current parser-block being processed
2567
+	 * @param int    $pointer    a reference to a pointer that will be increased by the amount of characters parsed
2568
+	 *
2569
+	 * @return string parsed call(s)/read(s)
2570
+	 */
2571
+	protected function parseMethodCall($output, $methodCall, $curBlock, &$pointer)
2572
+	{
2573
+		$ptr = 0;
2574
+		$len = strlen($methodCall);
2575
+
2576
+		while ($ptr < $len) {
2577
+			if (strpos($methodCall, '->', $ptr) === $ptr) {
2578
+				$ptr += 2;
2579
+			}
2580
+
2581
+			if (in_array(
2582
+				$methodCall[$ptr], array(
2583
+					';',
2584
+					',',
2585
+					'/',
2586
+					' ',
2587
+					"\t",
2588
+					"\r",
2589
+					"\n",
2590
+					')',
2591
+					'+',
2592
+					'*',
2593
+					'%',
2594
+					'=',
2595
+					'-',
2596
+					'|'
2597
+				)
2598
+			) || substr($methodCall, $ptr, strlen($this->rd)) === $this->rd
2599
+			) {
2600
+				// break char found
2601
+				break;
2602
+			}
2603
+
2604
+			if (!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) {
2605
+				break;
2606
+			}
2607
+
2608
+			if (empty($methMatch[2])) {
2609
+				// property
2610
+				if ($curBlock === 'root') {
2611
+					$output .= '->' . $methMatch[1];
2612
+				} else {
2613
+					$output = '(($tmp = ' . $output . ') ? $tmp->' . $methMatch[1] . ' : null)';
2614
+				}
2615
+				$ptr += strlen($methMatch[1]);
2616
+			} else {
2617
+				// method
2618
+				if (substr($methMatch[2], 0, 2) === '()') {
2619
+					$parsedCall = $methMatch[1] . '()';
2620
+					$ptr += strlen($methMatch[1]) + 2;
2621
+				} else {
2622
+					$parsedCall = $this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr);
2623
+				}
2624
+				if ($this->securityPolicy !== null) {
2625
+					$argPos = strpos($parsedCall, '(');
2626
+					$method = strtolower(substr($parsedCall, 0, $argPos));
2627
+					$args   = substr($parsedCall, $argPos);
2628
+					if ($curBlock === 'root') {
2629
+						$output = '$this->getSecurityPolicy()->callMethod($this, ' . $output . ', ' . var_export($method, true) . ', array' . $args . ')';
2630
+					} else {
2631
+						$output = '(($tmp = ' . $output . ') ? $this->getSecurityPolicy()->callMethod($this, $tmp, ' . var_export($method, true) . ', array' . $args . ') : null)';
2632
+					}
2633
+				} else {
2634
+					if ($curBlock === 'root') {
2635
+						$output .= '->' . $parsedCall;
2636
+					} else {
2637
+						$output = '(($tmp = ' . $output . ') ? $tmp->' . $parsedCall . ' : null)';
2638
+					}
2639
+				}
2640
+			}
2641
+		}
2642
+
2643
+		$pointer += $ptr;
2644
+
2645
+		return $output;
2646
+	}
2647
+
2648
+	/**
2649
+	 * Parses a constant variable (a variable that doesn't contain another variable) and preprocesses it to save
2650
+	 * runtime processing time.
2651
+	 *
2652
+	 * @param string $key      the variable to parse
2653
+	 * @param string $curBlock the current parser-block being processed
2654
+	 *
2655
+	 * @return string parsed variable
2656
+	 */
2657
+	protected function parseVarKey($key, $curBlock)
2658
+	{
2659
+		if ($key === '') {
2660
+			return '$this->scope';
2661
+		}
2662
+		if (substr($key, 0, 1) === '.') {
2663
+			$key = 'dwoo' . $key;
2664
+		}
2665
+		if (preg_match('#dwoo\.(get|post|server|cookies|session|env|request)((?:\.[a-z0-9_-]+)+)#i', $key, $m)) {
2666
+			$global = strtoupper($m[1]);
2667
+			if ($global === 'COOKIES') {
2668
+				$global = 'COOKIE';
2669
+			}
2670
+			$key = '$_' . $global;
2671
+			foreach (explode('.', ltrim($m[2], '.')) as $part) {
2672
+				$key .= '[' . var_export($part, true) . ']';
2673
+			}
2674
+			if ($curBlock === 'root') {
2675
+				$output = $key;
2676
+			} else {
2677
+				$output = '(isset(' . $key . ')?' . $key . ':null)';
2678
+			}
2679
+		} elseif (preg_match('#dwoo\\.const\\.([a-z0-9\\\\_:]+)#i', $key, $m)) {
2680
+			return $this->parseConstKey($m[1], $curBlock);
2681
+		} elseif ($this->scope !== null) {
2682
+			if (strstr($key, '.') === false && strstr($key, '[') === false && strstr($key, '->') === false) {
2683
+				if ($key === 'dwoo') {
2684
+					$output = '$this->globals';
2685
+				} elseif ($key === '_root' || $key === '__') {
2686
+					$output = '$this->data';
2687
+				} elseif ($key === '_parent' || $key === '_') {
2688
+					$output = '$this->readParentVar(1)';
2689
+				} elseif ($key === '_key') {
2690
+					$output = '$tmp_key';
2691
+				} else {
2692
+					if ($curBlock === 'root') {
2693
+						$output = '$this->scope["' . $key . '"]';
2694
+					} else {
2695
+						$output = '(isset($this->scope["' . $key . '"]) ? $this->scope["' . $key . '"] : null)';
2696
+					}
2697
+				}
2698
+			} else {
2699
+				preg_match_all('#(\[|->|\.)?((?:[a-z0-9_]|-(?!>))+|(\\\?[\'"])[^\3]*?\3)\]?#i', $key, $m);
2700
+
2701
+				$i = $m[2][0];
2702
+				if ($i === '_parent' || $i === '_') {
2703
+					$parentCnt = 0;
2704
+
2705
+					while (true) {
2706
+						++ $parentCnt;
2707
+						array_shift($m[2]);
2708
+						array_shift($m[1]);
2709
+						if (current($m[2]) === '_parent') {
2710
+							continue;
2711
+						}
2712
+						break;
2713
+					}
2714
+
2715
+					$output = '$this->readParentVar(' . $parentCnt . ')';
2716
+				} else {
2717
+					if ($i === 'dwoo') {
2718
+						$output = '$this->globals';
2719
+						array_shift($m[2]);
2720
+						array_shift($m[1]);
2721
+					} elseif ($i === '_root' || $i === '__') {
2722
+						// $output = '$this->data';
2723
+						$output = '$this->getData()';
2724
+						array_shift($m[2]);
2725
+						array_shift($m[1]);
2726
+					} elseif ($i === '_key') {
2727
+						$output = '$tmp_key';
2728
+					} else {
2729
+						$output = '$this->scope';
2730
+					}
2731
+
2732
+					while (count($m[1]) && $m[1][0] !== '->') {
2733
+						$m[2][0] = preg_replace('/(^\\\([\'"])|\\\([\'"])$)/x', '$2$3', $m[2][0]);
2734
+						if (substr($m[2][0], 0, 1) == '"' || substr($m[2][0], 0, 1) == "'") {
2735
+							$output .= '[' . $m[2][0] . ']';
2736
+						} else {
2737
+							$output .= '["' . $m[2][0] . '"]';
2738
+						}
2739
+						array_shift($m[2]);
2740
+						array_shift($m[1]);
2741
+					}
2742
+
2743
+					if ($curBlock !== 'root') {
2744
+						$output = '(isset(' . $output . ') ? ' . $output . ':null)';
2745
+					}
2746
+				}
2747
+
2748
+				if (count($m[2])) {
2749
+					unset($m[0]);
2750
+					$output = '$this->readVarInto(' . str_replace("\n", '', var_export($m, true)) . ', ' . $output . ', ' . ($curBlock == 'root' ? 'false' : 'true') . ')';
2751
+				}
2752
+			}
2753
+		} else {
2754
+			preg_match_all('#(\[|->|\.)?((?:[a-z0-9_]|-(?!>))+)\]?#i', $key, $m);
2755
+			unset($m[0]);
2756
+			$output = '$this->readVar(' . str_replace("\n", '', var_export($m, true)) . ')';
2757
+		}
2758
+
2759
+		return $output;
2760
+	}
2761
+
2762
+	/**
2763
+	 * Flattens a variable tree, this helps in parsing very complex variables such as $var.foo[$foo.bar->baz].baz,
2764
+	 * it computes the contents of the brackets first and works out from there.
2765
+	 *
2766
+	 * @param array $tree     the variable tree parsed by he parseVar() method that must be flattened
2767
+	 * @param bool  $recursed leave that to false by default, it is only for internal use
2768
+	 *
2769
+	 * @return string flattened tree
2770
+	 */
2771
+	protected function flattenVarTree(array $tree, $recursed = false)
2772
+	{
2773
+		$out = $recursed ? '".$this->readVarInto(' : '';
2774
+		foreach ($tree as $bit) {
2775
+			if (is_array($bit)) {
2776
+				$out .= '.' . $this->flattenVarTree($bit, false);
2777
+			} else {
2778
+				$key = str_replace('"', '\\"', $bit);
2779
+
2780
+				if (substr($key, 0, 1) === '$') {
2781
+					$out .= '".' . $this->parseVar($key, 0, strlen($key), false, 'variable') . '."';
2782
+				} else {
2783
+					$cnt = substr_count($key, '$');
2784
+
2785
+					if ($this->debug) {
2786
+						echo 'PARSING SUBVARS IN : ' . $key . "\n";
2787
+					}
2788
+					if ($cnt > 0) {
2789
+						while (-- $cnt >= 0) {
2790
+							if (isset($last)) {
2791
+								$last = strrpos($key, '$', - (strlen($key) - $last + 1));
2792
+							} else {
2793
+								$last = strrpos($key, '$');
2794
+							}
2795
+							preg_match('#\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', substr($key, $last), $submatch);
2796
+
2797
+							$len = strlen($submatch[0]);
2798
+							$key = substr_replace(
2799
+								$key, preg_replace_callback(
2800
+									'#(\$[a-z0-9_]+((?:(?:\.|->)(?:[a-z0-9_]+|(?R))|\[(?:[a-z0-9_]+|(?R))\]))*)' . '((?:(?:[+/*%-])(?:\$[a-z0-9.[\]>_:-]+(?:\([^)]*\))?|[0-9.,]*))*)#i', array(
2801
+										$this,
2802
+										'replaceVarKeyHelper'
2803
+									), substr($key, $last, $len)
2804
+								), $last, $len
2805
+							);
2806
+							if ($this->debug) {
2807
+								echo 'RECURSIVE VAR REPLACEMENT DONE : ' . $key . "\n";
2808
+							}
2809
+						}
2810
+						unset($last);
2811
+
2812
+						$out .= $key;
2813
+					} else {
2814
+						$out .= $key;
2815
+					}
2816
+				}
2817
+			}
2818
+		}
2819
+		$out .= $recursed ? ', true)."' : '';
2820
+
2821
+		return $out;
2822
+	}
2823
+
2824
+	/**
2825
+	 * Helper function that parses a variable.
2826
+	 *
2827
+	 * @param array $match the matched variable, array(1=>"string match")
2828
+	 *
2829
+	 * @return string parsed variable
2830
+	 */
2831
+	protected function replaceVarKeyHelper($match)
2832
+	{
2833
+		return '".' . $this->parseVar($match[0], 0, strlen($match[0]), false, 'variable') . '."';
2834
+	}
2835
+
2836
+	/**
2837
+	 * Parses various constants, operators or non-quoted strings.
2838
+	 *
2839
+	 * @param string $in            the string within which we must parse something
2840
+	 * @param int    $from          the starting offset of the parsed area
2841
+	 * @param int    $to            the ending offset of the parsed area
2842
+	 * @param mixed  $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by
2843
+	 *                              default
2844
+	 * @param string $curBlock      the current parser-block being processed
2845
+	 * @param mixed  $pointer       a reference to a pointer that will be increased by the amount of characters parsed,
2846
+	 *                              or null by default
2847
+	 *
2848
+	 * @return string parsed values
2849
+	 * @throws Exception
2850
+	 */
2851
+	protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null)
2852
+	{
2853
+		$substr = substr($in, $from, $to - $from);
2854
+
2855
+		$end = strlen($substr);
2856
+
2857
+		if ($curBlock === 'condition') {
2858
+			$breakChars = array(
2859
+				'(',
2860
+				')',
2861
+				' ',
2862
+				'||',
2863
+				'&&',
2864
+				'|',
2865
+				'&',
2866
+				'>=',
2867
+				'<=',
2868
+				'===',
2869
+				'==',
2870
+				'=',
2871
+				'!==',
2872
+				'!=',
2873
+				'<<',
2874
+				'<',
2875
+				'>>',
2876
+				'>',
2877
+				'^',
2878
+				'~',
2879
+				',',
2880
+				'+',
2881
+				'-',
2882
+				'*',
2883
+				'/',
2884
+				'%',
2885
+				'!',
2886
+				'?',
2887
+				':',
2888
+				$this->rd,
2889
+				';'
2890
+			);
2891
+		} elseif ($curBlock === 'modifier') {
2892
+			$breakChars = array(' ', ',', ')', ':', '|', "\r", "\n", "\t", ';', $this->rd);
2893
+		} elseif ($curBlock === 'expression') {
2894
+			$breakChars = array('/', '%', '+', '-', '*', ' ', ',', ')', "\r", "\n", "\t", ';', $this->rd);
2895
+		} else {
2896
+			$breakChars = array(' ', ',', ')', "\r", "\n", "\t", ';', $this->rd);
2897
+		}
2898
+
2899
+		$breaker = false;
2900
+		foreach ($breakChars as $k => $char) {
2901
+			$test = strpos($substr, $char);
2902
+			if ($test !== false && $test < $end) {
2903
+				$end     = $test;
2904
+				$breaker = $k;
2905
+			}
2906
+		}
2907
+
2908
+		if ($curBlock === 'condition') {
2909
+			if ($end === 0 && $breaker !== false) {
2910
+				$end = strlen($breakChars[$breaker]);
2911
+			}
2912
+		}
2913
+
2914
+		if ($end !== false) {
2915
+			$substr = substr($substr, 0, $end);
2916
+		}
2917
+
2918
+		if ($pointer !== null) {
2919
+			$pointer += strlen($substr);
2920
+		}
2921
+
2922
+		$src    = $substr;
2923
+		$substr = trim($substr);
2924
+
2925
+		if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') {
2926
+			if ($this->debug) {
2927
+				echo 'BOOLEAN(FALSE) PARSED' . "\n";
2928
+			}
2929
+			$substr = 'false';
2930
+			$type   = self::T_BOOL;
2931
+		} elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') {
2932
+			if ($this->debug) {
2933
+				echo 'BOOLEAN(TRUE) PARSED' . "\n";
2934
+			}
2935
+			$substr = 'true';
2936
+			$type   = self::T_BOOL;
2937
+		} elseif ($substr === 'null' || $substr === 'NULL') {
2938
+			if ($this->debug) {
2939
+				echo 'NULL PARSED' . "\n";
2940
+			}
2941
+			$substr = 'null';
2942
+			$type   = self::T_NULL;
2943
+		} elseif (is_numeric($substr)) {
2944
+			$substr = (float)$substr;
2945
+			if ((int)$substr == $substr) {
2946
+				$substr = (int)$substr;
2947
+			}
2948
+			$type = self::T_NUMERIC;
2949
+			if ($this->debug) {
2950
+				echo 'NUMBER (' . $substr . ') PARSED' . "\n";
2951
+			}
2952
+		} elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) {
2953
+			if ($this->debug) {
2954
+				echo 'SIMPLE MATH PARSED . "\n"';
2955
+			}
2956
+			$type   = self::T_MATH;
2957
+			$substr = '(' . $substr . ')';
2958
+		} elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) {
2959
+			if ($this->debug) {
2960
+				echo 'BREAKCHAR (' . $substr . ') PARSED' . "\n";
2961
+			}
2962
+			$type = self::T_BREAKCHAR;
2963
+			//$substr = '"'.$substr.'"';
2964
+		} else {
2965
+			$substr = $this->replaceStringVars('\'' . str_replace('\'', '\\\'', $substr) . '\'', '\'', $curBlock);
2966
+			$type   = self::T_UNQUOTED_STRING;
2967
+			if ($this->debug) {
2968
+				echo 'BLABBER (' . $substr . ') CASTED AS STRING' . "\n";
2969
+			}
2970
+		}
2971
+
2972
+		if (is_array($parsingParams)) {
2973
+			$parsingParams[] = array($substr, $src, $type);
2974
+
2975
+			return $parsingParams;
2976
+		} elseif ($curBlock === 'namedparam') {
2977
+			return array($substr, $src, $type);
2978
+		} elseif ($curBlock === 'expression') {
2979
+			return $substr;
2980
+		} else {
2981
+			throw new Exception('Something went wrong');
2982
+		}
2983
+	}
2984
+
2985
+	/**
2986
+	 * Replaces variables within a parsed string.
2987
+	 *
2988
+	 * @param string $string   the parsed string
2989
+	 * @param string $first    the first character parsed in the string, which is the string delimiter (' or ")
2990
+	 * @param string $curBlock the current parser-block being processed
2991
+	 *
2992
+	 * @return string the original string with variables replaced
2993
+	 */
2994
+	protected function replaceStringVars($string, $first, $curBlock = '')
2995
+	{
2996
+		$pos = 0;
2997
+		if ($this->debug) {
2998
+			echo 'STRING VAR REPLACEMENT : ' . $string . "\n";
2999
+		}
3000
+		// replace vars
3001
+		while (($pos = strpos($string, '$', $pos)) !== false) {
3002
+			$prev = substr($string, $pos - 1, 1);
3003
+			if ($prev === '\\') {
3004
+				++ $pos;
3005
+				continue;
3006
+			}
3007
+
3008
+			$var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3009
+			$len = $var[0];
3010
+			$var = $this->parse(str_replace('\\' . $first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string')));
3011
+
3012
+			if ($prev === '`' && substr($string, $pos + $len, 1) === '`') {
3013
+				$string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos - 1, $len + 2);
3014
+			} else {
3015
+				$string = substr_replace($string, $first . '.' . $var[1] . '.' . $first, $pos, $len);
3016
+			}
3017
+			$pos += strlen($var[1]) + 2;
3018
+			if ($this->debug) {
3019
+				echo 'STRING VAR REPLACEMENT DONE : ' . $string . "\n";
3020
+			}
3021
+		}
3022
+
3023
+		// handle modifiers
3024
+		// TODO Obsolete?
3025
+		$string = preg_replace_callback(
3026
+			'#("|\')\.(.+?)\.\1((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').+?\4|:[^`]*))*))+)#i', array(
3027
+			$this,
3028
+			'replaceModifiers'
3029
+			), $string
3030
+		);
3031
+
3032
+		// replace escaped dollar operators by unescaped ones if required
3033
+		if ($first === "'") {
3034
+			$string = str_replace('\\$', '$', $string);
3035
+		}
3036
+
3037
+		return $string;
3038
+	}
3039
+
3040
+	/**
3041
+	 * Replaces the modifiers applied to a string or a variable.
3042
+	 *
3043
+	 * @param array  $m        the regex matches that must be array(1=>"double or single quotes enclosing a string,
3044
+	 *                         when applicable", 2=>"the string or var", 3=>"the modifiers matched")
3045
+	 * @param string $curBlock the current parser-block being processed
3046
+	 * @param null   $pointer
3047
+	 *
3048
+	 * @return string the input enclosed with various function calls according to the modifiers found
3049
+	 * @throws CompilationException
3050
+	 * @throws Exception
3051
+	 */
3052
+	protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null)
3053
+	{
3054
+		if ($this->debug) {
3055
+			echo 'PARSING MODIFIERS : ' . $m[3] . "\n";
3056
+		}
3057
+
3058
+		if ($pointer !== null) {
3059
+			$pointer += strlen($m[3]);
3060
+		}
3061
+		// remove first pipe
3062
+		$cmdstrsrc = substr($m[3], 1);
3063
+		// remove last quote if present
3064
+		if (substr($cmdstrsrc, - 1, 1) === $m[1]) {
3065
+			$cmdstrsrc = substr($cmdstrsrc, 0, - 1);
3066
+			$add       = $m[1];
3067
+		}
3068
+
3069
+		$output = $m[2];
3070
+
3071
+		$continue = true;
3072
+		while (strlen($cmdstrsrc) > 0 && $continue) {
3073
+			if ($cmdstrsrc[0] === '|') {
3074
+				$cmdstrsrc = substr($cmdstrsrc, 1);
3075
+				continue;
3076
+			}
3077
+			if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) {
3078
+				if ($this->debug) {
3079
+					echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND' . "\n";
3080
+				}
3081
+				$continue = false;
3082
+				if ($pointer !== null) {
3083
+					$pointer -= strlen($cmdstrsrc);
3084
+				}
3085
+				break;
3086
+			}
3087
+			$cmdstr   = $cmdstrsrc;
3088
+			$paramsep = ':';
3089
+			if (!preg_match('/^(@{0,2}[a-z_][a-z0-9_]*)(:)?/i', $cmdstr, $match)) {
3090
+				throw new CompilationException($this, 'Invalid modifier name, started with : ' . substr($cmdstr, 0, 10));
3091
+			}
3092
+			$paramspos = !empty($match[2]) ? strlen($match[1]) : false;
3093
+			$func      = $match[1];
3094
+
3095
+			$state = 0;
3096
+			if ($paramspos === false) {
3097
+				$cmdstrsrc = substr($cmdstrsrc, strlen($func));
3098
+				$params    = array();
3099
+				if ($this->debug) {
3100
+					echo 'MODIFIER (' . $func . ') CALLED WITH NO PARAMS' . "\n";
3101
+				}
3102
+			} else {
3103
+				$paramstr = substr($cmdstr, $paramspos + 1);
3104
+				if (substr($paramstr, - 1, 1) === $paramsep) {
3105
+					$paramstr = substr($paramstr, 0, - 1);
3106
+				}
3107
+
3108
+				$ptr    = 0;
3109
+				$params = array();
3110
+				while ($ptr < strlen($paramstr)) {
3111
+					if ($this->debug) {
3112
+						echo 'MODIFIER (' . $func . ') START PARAM PARSING WITH POINTER AT ' . $ptr . "\n";
3113
+					}
3114
+					if ($this->debug) {
3115
+						echo $paramstr . '--' . $ptr . '--' . strlen($paramstr) . '--modifier' . "\n";
3116
+					}
3117
+					$params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr);
3118
+					if ($this->debug) {
3119
+						echo 'PARAM PARSED, POINTER AT ' . $ptr . "\n";
3120
+					}
3121
+
3122
+					if ($ptr >= strlen($paramstr)) {
3123
+						if ($this->debug) {
3124
+							echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED' . "\n";
3125
+						}
3126
+						break;
3127
+					}
3128
+
3129
+					if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) {
3130
+						if ($this->debug) {
3131
+							echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT ' . $ptr . "\n";
3132
+						}
3133
+						if ($paramstr[$ptr] !== '|') {
3134
+							$continue = false;
3135
+							if ($pointer !== null) {
3136
+								$pointer -= strlen($paramstr) - $ptr;
3137
+							}
3138
+						}
3139
+						++ $ptr;
3140
+						break;
3141
+					}
3142
+					if ($ptr < strlen($paramstr) && $paramstr[$ptr] === ':') {
3143
+						++ $ptr;
3144
+					}
3145
+				}
3146
+				$cmdstrsrc = substr($cmdstrsrc, strlen($func) + 1 + $ptr);
3147
+				foreach ($params as $k => $p) {
3148
+					if (is_array($p) && is_array($p[1])) {
3149
+						$state |= 2;
3150
+					} else {
3151
+						if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) {
3152
+							$params[$k] = array($m[2], array('true', 'true'));
3153
+						} else {
3154
+							if ($state & 2) {
3155
+								throw new CompilationException($this, 'You can not use an unnamed parameter after a named one');
3156
+							}
3157
+							$state |= 1;
3158
+						}
3159
+					}
3160
+				}
3161
+			}
3162
+
3163
+			// check if we must use array_map with this plugin or not
3164
+			$mapped = false;
3165
+			if (substr($func, 0, 1) === '@') {
3166
+				$func   = substr($func, 1);
3167
+				$mapped = true;
3168
+			}
3169
+
3170
+			$pluginType = $this->getPluginType($func);
3171
+
3172
+			if ($state & 2) {
3173
+				array_unshift($params, array('value', is_array($output) ? $output : array($output, $output)));
3174
+			} else {
3175
+				array_unshift($params, is_array($output) ? $output : array($output, $output));
3176
+			}
3177
+
3178
+			if ($pluginType & Core::NATIVE_PLUGIN) {
3179
+				$params = $this->mapParams($params, null, $state);
3180
+
3181
+				$params = $params['*'][0];
3182
+
3183
+				$params = self::implode_r($params);
3184
+
3185
+				if ($mapped) {
3186
+					$output = '$this->arrayMap(\'' . $func . '\', array(' . $params . '))';
3187
+				} else {
3188
+					$output = $func . '(' . $params . ')';
3189
+				}
3190
+			} elseif ($pluginType & Core::PROXY_PLUGIN) {
3191
+				$params = $this->mapParams($params, $this->getCore()->getPluginProxy()->getCallback($func), $state);
3192
+				foreach ($params as &$p) {
3193
+					$p = $p[0];
3194
+				}
3195
+				$output = call_user_func(array($this->getCore()->getPluginProxy(), 'getCode'), $func, $params);
3196
+			} elseif ($pluginType & Core::SMARTY_MODIFIER) {
3197
+				$params = $this->mapParams($params, null, $state);
3198
+				$params = $params['*'][0];
3199
+
3200
+				$params = self::implode_r($params);
3201
+
3202
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
3203
+					$callback = $this->customPlugins[$func]['callback'];
3204
+					if (is_array($callback)) {
3205
+						if (is_object($callback[0])) {
3206
+							$output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3207
+						} else {
3208
+							$output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3209
+						}
3210
+					} elseif ($mapped) {
3211
+						$output = '$this->arrayMap(\'' . $callback . '\', array(' . $params . '))';
3212
+					} else {
3213
+						$output = $callback . '(' . $params . ')';
3214
+					}
3215
+				} elseif ($mapped) {
3216
+					$output = '$this->arrayMap(\'smarty_modifier_' . $func . '\', array(' . $params . '))';
3217
+				} else {
3218
+					$output = 'smarty_modifier_' . $func . '(' . $params . ')';
3219
+				}
3220
+			} else {
3221
+				if ($pluginType & Core::CUSTOM_PLUGIN) {
3222
+					$pluginName = $callback = $this->customPlugins[$func]['callback'];
3223
+					if (($pluginType & Core::CLASS_PLUGIN) && !is_array($callback)) {
3224
+						$pluginName = $this->customPlugins[$func]['callback'];
3225
+						$callback   = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3226
+					}
3227
+				} else {
3228
+					if (class_exists('Plugin' . Core::toCamelCase($func)) !== false || function_exists('Plugin' .
3229
+							Core::toCamelCase($func) . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : ''))
3230
+						!== false) {
3231
+						$pluginName = 'Plugin' . Core::toCamelCase($func);
3232
+					} else {
3233
+						$pluginName = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func);
3234
+					}
3235
+					if ($pluginType & Core::CLASS_PLUGIN) {
3236
+						$callback = array($pluginName, ($pluginType & Core::COMPILABLE_PLUGIN) ? 'compile' : 'process');
3237
+					} else {
3238
+						$callback = $pluginName . (($pluginType & Core::COMPILABLE_PLUGIN) ? 'Compile' : '');
3239
+					}
3240
+				}
3241
+				$params = $this->mapParams($params, $callback, $state);
3242
+
3243
+				foreach ($params as &$p) {
3244
+					$p = $p[0];
3245
+				}
3246
+
3247
+				// Only for PHP function, who is not a PHP class
3248
+				if ($pluginType & Core::FUNC_PLUGIN && !($pluginType & Core::CLASS_PLUGIN)) {
3249
+					if ($pluginType & Core::COMPILABLE_PLUGIN) {
3250
+						if ($mapped) {
3251
+							throw new CompilationException($this, 'The @ operator can not be used on compiled plugins.');
3252
+						}
3253
+						if ($pluginType & Core::CUSTOM_PLUGIN) {
3254
+							$funcCompiler = $this->customPlugins[$func]['callback'];
3255
+						} else {
3256
+							if (function_exists('Plugin' . Core::toCamelCase($func) . 'Compile') !== false) {
3257
+								$funcCompiler = 'Plugin' . Core::toCamelCase($func) . 'Compile';
3258
+							} else {
3259
+								$funcCompiler = Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) .
3260
+									'Compile';
3261
+							}
3262
+						}
3263
+						array_unshift($params, $this);
3264
+						$output = call_user_func_array($funcCompiler, $params);
3265
+					} else {
3266
+						array_unshift($params, '$this');
3267
+
3268
+						$params = self::implode_r($params);
3269
+						if ($mapped) {
3270
+							$output = '$this->arrayMap(\'' . $pluginName . '\', array(' . $params . '))';
3271
+						} else {
3272
+							$output = $pluginName . '(' . $params . ')';
3273
+						}
3274
+					}
3275
+				} else {
3276
+					if ($pluginType & Core::COMPILABLE_PLUGIN) {
3277
+						if ($mapped) {
3278
+							throw new CompilationException($this, 'The @ operator can not be used on compiled plugins.');
3279
+						}
3280
+						if ($pluginType & Core::CUSTOM_PLUGIN) {
3281
+							$callback = $this->customPlugins[$func]['callback'];
3282
+							if (!is_array($callback)) {
3283
+								if (!method_exists($callback, 'compile')) {
3284
+									throw new Exception('Custom plugin ' . $func . ' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use');
3285
+								}
3286
+								if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) {
3287
+									$funcCompiler = array($callback, 'compile');
3288
+								} else {
3289
+									$funcCompiler = array(new $callback(), 'compile');
3290
+								}
3291
+							} else {
3292
+								$funcCompiler = $callback;
3293
+							}
3294
+						} else {
3295
+							if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3296
+								$funcCompiler = array('Plugin' . Core::toCamelCase($func), 'compile');
3297
+							} else {
3298
+								$funcCompiler = array(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func), 'compile');
3299
+							}
3300
+							array_unshift($params, $this);
3301
+						}
3302
+						$output = call_user_func_array($funcCompiler, $params);
3303
+					} else {
3304
+						$params = self::implode_r($params);
3305
+
3306
+						if ($pluginType & Core::CUSTOM_PLUGIN) {
3307
+							if (is_object($callback[0])) {
3308
+								if (is_array($this->getCore()->getCustomPlugin($func))) {
3309
+									$output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->plugins[\'' . $func . '\'][\'callback\'][0], \'' . $callback[1] . '\'), array(' . $params . '))';
3310
+								} else {
3311
+									$output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array($this->getCustomPlugin(\'' . $func . '\'), \'' . $callback[1] . '\'), array(' . $params . '))';
3312
+								}
3313
+							} else {
3314
+								$output = ($mapped ? '$this->arrayMap' : 'call_user_func_array') . '(array(\'' . $callback[0] . '\', \'' . $callback[1] . '\'), array(' . $params . '))';
3315
+							}
3316
+						} elseif ($mapped) {
3317
+							$output = '$this->arrayMap(array($this->getObjectPlugin(\''.
3318
+								Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func) . '\'), 
3319 3319
                             \'process\'), array(' . $params . '))';
3320
-                        } else {
3321
-                            if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3322
-                                $output = '$this->classCall(\'Plugin' . Core::toCamelCase($func) . '\', array(' . $params . '))';
3323
-                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3324
-                                $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . $func . '\', array(' . $params . '))';
3325
-                            } elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3326
-                                $output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', array(' . $params . '))';
3327
-                            } else {
3328
-                                $output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
3329
-                            }
3330
-                        }
3331
-                    }
3332
-                }
3333
-            }
3334
-        }
3335
-
3336
-        if ($curBlock === 'namedparam') {
3337
-            return array($output, $output);
3338
-        } elseif ($curBlock === 'var' || $m[1] === null) {
3339
-            return $output;
3340
-        } elseif ($curBlock === 'string' || $curBlock === 'root') {
3341
-            return $m[1] . '.' . $output . '.' . $m[1] . (isset($add) ? $add : null);
3342
-        }
3343
-
3344
-        return '';
3345
-    }
3346
-
3347
-    /**
3348
-     * Recursively implodes an array in a similar manner as var_export() does but with some tweaks
3349
-     * to handle pre-compiled values and the fact that we do not need to enclose everything with
3350
-     * "array" and do not require top-level keys to be displayed.
3351
-     *
3352
-     * @param array $params        the array to implode
3353
-     * @param bool  $recursiveCall if set to true, the function outputs key names for the top level
3354
-     *
3355
-     * @return string the imploded array
3356
-     */
3357
-    public static function implode_r(array $params, $recursiveCall = false)
3358
-    {
3359
-        $out = '';
3360
-        foreach ($params as $k => $p) {
3361
-            if (is_array($p)) {
3362
-                $out2 = 'array(';
3363
-                foreach ($p as $k2 => $v) {
3364
-                    $out2 .= var_export($k2, true) . ' => ' . (is_array($v) ? 'array(' . self::implode_r($v, true) . ')' : $v) . ', ';
3365
-                }
3366
-                $p = rtrim($out2, ', ') . ')';
3367
-            }
3368
-            if ($recursiveCall) {
3369
-                $out .= var_export($k, true) . ' => ' . $p . ', ';
3370
-            } else {
3371
-                $out .= $p . ', ';
3372
-            }
3373
-        }
3374
-
3375
-        return rtrim($out, ', ');
3376
-    }
3377
-
3378
-    /**
3379
-     * Returns the plugin type of a plugin and adds it to the used plugins array if required.
3380
-     *
3381
-     * @param string $name plugin name, as found in the template
3382
-     *
3383
-     * @return int type as a multi bit flag composed of the Dwoo plugin types constants
3384
-     * @throws Exception
3385
-     * @throws SecurityException
3386
-     * @throws Exception
3387
-     */
3388
-    protected function getPluginType($name)
3389
-    {
3390
-        $pluginType = - 1;
3391
-
3392
-        if (($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty')) || ($this->securityPolicy !== null && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false)) {
3393
-            $phpFunc = true;
3394
-        } elseif ($this->securityPolicy !== null && function_exists($name) && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) === false) {
3395
-            throw new SecurityException('Call to a disallowed php function : ' . $name);
3396
-        }
3397
-
3398
-        while ($pluginType <= 0) {
3399
-            // Template plugin compilable
3400
-            if (isset($this->templatePlugins[$name])) {
3401
-                $pluginType = Core::TEMPLATE_PLUGIN | Core::COMPILABLE_PLUGIN;
3402
-            } // Custom plugin
3403
-            elseif (isset($this->customPlugins[$name])) {
3404
-                $pluginType = $this->customPlugins[$name]['type'] | Core::CUSTOM_PLUGIN;
3405
-            } // Class blocks plugin
3406
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3407
-                $pluginType = Core::CLASS_PLUGIN;
3408
-                if (is_subclass_of(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name), 'Dwoo\Block\Plugin')) {
3409
-                    $pluginType += Core::BLOCK_PLUGIN;
3410
-                }
3411
-                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name));
3412
-                if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3413
-                    $pluginType |= Core::COMPILABLE_PLUGIN;
3414
-                }
3415
-            } // Class functions plugin
3416
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3417
-                $pluginType = Core::FUNC_PLUGIN + Core::CLASS_PLUGIN;
3418
-                $interfaces = class_implements(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name));
3419
-                if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3420
-                    $pluginType |= Core::COMPILABLE_PLUGIN;
3421
-                }
3422
-            } // Class without namespace
3423
-            elseif (class_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3424
-                $pluginType = Core::CLASS_PLUGIN;
3425
-                $interfaces = class_implements('Plugin' . Core::toCamelCase($name));
3426
-                if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3427
-                    $pluginType |= Core::COMPILABLE_PLUGIN;
3428
-                }
3429
-            } // Function plugin (with/without namespaces)
3430
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase ($name)) !==
3431
-                false || function_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3432
-                $pluginType = Core::FUNC_PLUGIN;
3433
-            } // Function plugin compile (with/without namespaces)
3434
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name) .
3435
-                    'Compile') !== false || function_exists('Plugin' . Core::toCamelCase($name) . 'Compile') !==
3436
-                false) {
3437
-                $pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3438
-            } // Helper plugin class compile
3439
-            elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3440
-                $pluginType = Core::CLASS_PLUGIN | Core::COMPILABLE_PLUGIN;
3441
-            } // Helper plugin function compile
3442
-            elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name) . 'Compile') !== false) {
3443
-                $pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3444
-            } // Smarty modifier
3445
-            elseif (function_exists('smarty_modifier_' . $name) !== false) {
3446
-                $pluginType = Core::SMARTY_MODIFIER;
3447
-            } // Smarty function
3448
-            elseif (function_exists('smarty_function_' . $name) !== false) {
3449
-                $pluginType = Core::SMARTY_FUNCTION;
3450
-            } // Smarty block
3451
-            elseif (function_exists('smarty_block_' . $name) !== false) {
3452
-                $pluginType = Core::SMARTY_BLOCK;
3453
-            } // Everything else
3454
-            else {
3455
-                if ($pluginType === - 1) {
3456
-                    try {
3457
-                        $this->getCore()->getLoader()->loadPlugin('Plugin' . Core::toCamelCase($name));
3458
-                    }
3459
-                    catch (Exception $e) {
3460
-                        if (isset($phpFunc)) {
3461
-                            $pluginType = Core::NATIVE_PLUGIN;
3462
-                        } elseif (is_object($this->getCore()->getPluginProxy()) && $this->getCore()->getPluginProxy()->handles($name)) {
3463
-                            $pluginType = Core::PROXY_PLUGIN;
3464
-                            break;
3465
-                        } else {
3466
-                            throw $e;
3467
-                        }
3468
-                    }
3469
-                } else {
3470
-                    throw new Exception('Plugin "' . $name . '" could not be found, type:' . $pluginType);
3471
-                }
3472
-                ++ $pluginType;
3473
-            }
3474
-        }
3475
-
3476
-        if (($pluginType & Core::COMPILABLE_PLUGIN) === 0 && ($pluginType & Core::NATIVE_PLUGIN) === 0 && ($pluginType & Core::PROXY_PLUGIN) === 0) {
3477
-            $this->addUsedPlugin(Core::toCamelCase($name), $pluginType);
3478
-        }
3479
-
3480
-        return $pluginType;
3481
-    }
3482
-
3483
-    /**
3484
-     * Allows a plugin to load another one at compile time, this will also mark
3485
-     * it as used by this template so it will be loaded at runtime (which can be
3486
-     * useful for compiled plugins that rely on another plugin when their compiled
3487
-     * code runs).
3488
-     *
3489
-     * @param string $name the plugin name
3490
-     *
3491
-     * @return void
3492
-     */
3493
-    public function loadPlugin($name)
3494
-    {
3495
-        $this->getPluginType($name);
3496
-    }
3497
-
3498
-    /**
3499
-     * Runs htmlentities over the matched <?php ?> blocks when the security policy enforces that.
3500
-     *
3501
-     * @param array $match matched php block
3502
-     *
3503
-     * @return string the htmlentities-converted string
3504
-     */
3505
-    protected function phpTagEncodingHelper($match)
3506
-    {
3507
-        return htmlspecialchars($match[0]);
3508
-    }
3509
-
3510
-    /**
3511
-     * Maps the parameters received from the template onto the parameters required by the given callback.
3512
-     *
3513
-     * @param array    $params   the array of parameters
3514
-     * @param callback $callback the function or method to reflect on to find out the required parameters
3515
-     * @param int      $callType the type of call in the template, 0 = no params, 1 = php-style call, 2 = named
3516
-     *                           parameters call
3517
-     * @param array    $map      the parameter map to use, if not provided it will be built from the callback
3518
-     *
3519
-     * @return array parameters sorted in the correct order with missing optional parameters filled
3520
-     * @throws CompilationException
3521
-     */
3522
-    protected function mapParams(array $params, $callback, $callType = 2, $map = null)
3523
-    {
3524
-        if (!$map) {
3525
-            $map = $this->getParamMap($callback);
3526
-        }
3527
-
3528
-        $paramlist = array();
3529
-
3530
-        // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))
3531
-        $ps = array();
3532
-        foreach ($params as $p) {
3533
-            if (is_array($p[1])) {
3534
-                $ps[$p[0]] = $p[1];
3535
-            } else {
3536
-                $ps[] = $p;
3537
-            }
3538
-        }
3539
-
3540
-        // loops over the param map and assigns values from the template or default value for unset optional params
3541
-        foreach ($map as $k => $v){
3542
-            if ($v[0] === '*') {
3543
-                // "rest" array parameter, fill every remaining params in it and then break
3544
-                if (count($ps) === 0) {
3545
-                    if ($v[1] === false) {
3546
-                        throw new CompilationException(
3547
-                            $this, 'Rest argument missing for ' . str_replace(
3548
-                                array(
3549
-                                    Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3550
-                                'Compile'
3551
-                                ), '', (is_array($callback) ? $callback[0] : $callback)
3552
-                            )
3553
-                        );
3554
-                    } else {
3555
-                        break;
3556
-                    }
3557
-                }
3558
-                $tmp  = array();
3559
-                $tmp2 = array();
3560
-                $tmp3 = array();
3561
-                foreach ($ps as $i => $p) {
3562
-                    $tmp[$i]  = $p[0];
3563
-                    $tmp2[$i] = $p[1];
3564
-                    $tmp3[$i] = isset($p[2]) ? $p[2] : 0;
3565
-                    unset($ps[$i]);
3566
-                }
3567
-                $paramlist[$v[0]] = array($tmp, $tmp2, $tmp3);
3568
-                unset($tmp, $tmp2, $i, $p);
3569
-                break;
3570
-            } elseif (isset($ps[$v[0]])) {
3571
-                // parameter is defined as named param
3572
-                $paramlist[$v[0]] = $ps[$v[0]];
3573
-                unset($ps[$v[0]]);
3574
-            } elseif (isset($ps[$k])) {
3575
-                // parameter is defined as ordered param
3576
-                $paramlist[$v[0]] = $ps[$k];
3577
-                unset($ps[$k]);
3578
-            } elseif ($v[1] === false) {
3579
-                // parameter is not defined and not optional, throw error
3580
-                if (is_array($callback)) {
3581
-                    if (is_object($callback[0])) {
3582
-                        $name = get_class($callback[0]) . '::' . $callback[1];
3583
-                    } else {
3584
-                        $name = $callback[0];
3585
-                    }
3586
-                } else {
3587
-                    $name = $callback;
3588
-                }
3589
-
3590
-                throw new CompilationException(
3591
-                    $this, 'Argument ' . $k . '/' . $v[0] . ' missing for ' . str_replace(
3592
-                        array(
3593
-                            Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3594
-                        'Compile'
3595
-                        ), '', $name
3596
-                    )
3597
-                );
3598
-            } elseif ($v[2] === null) {
3599
-                // enforce lowercased null if default value is null (php outputs NULL with var export)
3600
-                $paramlist[$v[0]] = array('null', null, self::T_NULL);
3601
-            } else {
3602
-                // outputs default value with var_export
3603
-                $paramlist[$v[0]] = array(var_export($v[2], true), $v[2]);
3604
-            }
3605
-        }
3606
-
3607
-        if (count($ps)) {
3608
-            foreach ($ps as $i => $p) {
3609
-                array_push($paramlist, $p);
3610
-            }
3611
-        }
3612
-
3613
-        return $paramlist;
3614
-    }
3615
-
3616
-    /**
3617
-     * Returns the parameter map of the given callback, it filters out entries typed as Dwoo and Compiler and turns the
3618
-     * rest parameter into a "*".
3619
-     *
3620
-     * @param callback $callback the function/method to reflect on
3621
-     *
3622
-     * @return array processed parameter map
3623
-     */
3624
-    protected function getParamMap($callback)
3625
-    {
3626
-        if (is_null($callback)) {
3627
-            return array(array('*', true));
3628
-        }
3629
-        if (is_array($callback)) {
3630
-            $ref = new ReflectionMethod($callback[0], $callback[1]);
3631
-        } else {
3632
-            $ref = new ReflectionFunction($callback);
3633
-        }
3634
-
3635
-        $out = array();
3636
-        foreach ($ref->getParameters() as $param) {
3637
-            if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\Core') {
3638
-                continue;
3639
-            }
3640
-            if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\Compiler') {
3641
-                continue;
3642
-            }
3643
-            if ($param->getName() === 'rest' && $param->isArray() === true) {
3644
-                $out[] = array('*', $param->isOptional(), null);
3645
-                continue;
3646
-            }
3647
-            $out[] = array(
3648
-                $param->getName(),
3649
-                $param->isOptional(),
3650
-                $param->isOptional() ? $param->getDefaultValue() : null
3651
-            );
3652
-        }
3653
-
3654
-        return $out;
3655
-    }
3656
-
3657
-    /**
3658
-     * Returns a default instance of this compiler, used by default by all Dwoo templates that do not have a
3659
-     * specific compiler assigned and when you do not override the default compiler factory function.
3660
-     *
3661
-     * @see    Core::setDefaultCompilerFactory()
3662
-     * @return Compiler
3663
-     */
3664
-    public static function compilerFactory()
3665
-    {
3666
-        if (self::$instance === null) {
3667
-            self::$instance = new self();
3668
-        }
3669
-
3670
-        return self::$instance;
3671
-    }
3320
+						} else {
3321
+							if (class_exists('Plugin' . Core::toCamelCase($func)) !== false) {
3322
+								$output = '$this->classCall(\'Plugin' . Core::toCamelCase($func) . '\', array(' . $params . '))';
3323
+							} elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3324
+								$output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . $func . '\', array(' . $params . '))';
3325
+							} elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($func)) !== false) {
3326
+								$output = '$this->classCall(\'' . Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . $func . '\', array(' . $params . '))';
3327
+							} else {
3328
+								$output = '$this->classCall(\'' . $func . '\', array(' . $params . '))';
3329
+							}
3330
+						}
3331
+					}
3332
+				}
3333
+			}
3334
+		}
3335
+
3336
+		if ($curBlock === 'namedparam') {
3337
+			return array($output, $output);
3338
+		} elseif ($curBlock === 'var' || $m[1] === null) {
3339
+			return $output;
3340
+		} elseif ($curBlock === 'string' || $curBlock === 'root') {
3341
+			return $m[1] . '.' . $output . '.' . $m[1] . (isset($add) ? $add : null);
3342
+		}
3343
+
3344
+		return '';
3345
+	}
3346
+
3347
+	/**
3348
+	 * Recursively implodes an array in a similar manner as var_export() does but with some tweaks
3349
+	 * to handle pre-compiled values and the fact that we do not need to enclose everything with
3350
+	 * "array" and do not require top-level keys to be displayed.
3351
+	 *
3352
+	 * @param array $params        the array to implode
3353
+	 * @param bool  $recursiveCall if set to true, the function outputs key names for the top level
3354
+	 *
3355
+	 * @return string the imploded array
3356
+	 */
3357
+	public static function implode_r(array $params, $recursiveCall = false)
3358
+	{
3359
+		$out = '';
3360
+		foreach ($params as $k => $p) {
3361
+			if (is_array($p)) {
3362
+				$out2 = 'array(';
3363
+				foreach ($p as $k2 => $v) {
3364
+					$out2 .= var_export($k2, true) . ' => ' . (is_array($v) ? 'array(' . self::implode_r($v, true) . ')' : $v) . ', ';
3365
+				}
3366
+				$p = rtrim($out2, ', ') . ')';
3367
+			}
3368
+			if ($recursiveCall) {
3369
+				$out .= var_export($k, true) . ' => ' . $p . ', ';
3370
+			} else {
3371
+				$out .= $p . ', ';
3372
+			}
3373
+		}
3374
+
3375
+		return rtrim($out, ', ');
3376
+	}
3377
+
3378
+	/**
3379
+	 * Returns the plugin type of a plugin and adds it to the used plugins array if required.
3380
+	 *
3381
+	 * @param string $name plugin name, as found in the template
3382
+	 *
3383
+	 * @return int type as a multi bit flag composed of the Dwoo plugin types constants
3384
+	 * @throws Exception
3385
+	 * @throws SecurityException
3386
+	 * @throws Exception
3387
+	 */
3388
+	protected function getPluginType($name)
3389
+	{
3390
+		$pluginType = - 1;
3391
+
3392
+		if (($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty')) || ($this->securityPolicy !== null && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false)) {
3393
+			$phpFunc = true;
3394
+		} elseif ($this->securityPolicy !== null && function_exists($name) && array_key_exists(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) === false) {
3395
+			throw new SecurityException('Call to a disallowed php function : ' . $name);
3396
+		}
3397
+
3398
+		while ($pluginType <= 0) {
3399
+			// Template plugin compilable
3400
+			if (isset($this->templatePlugins[$name])) {
3401
+				$pluginType = Core::TEMPLATE_PLUGIN | Core::COMPILABLE_PLUGIN;
3402
+			} // Custom plugin
3403
+			elseif (isset($this->customPlugins[$name])) {
3404
+				$pluginType = $this->customPlugins[$name]['type'] | Core::CUSTOM_PLUGIN;
3405
+			} // Class blocks plugin
3406
+			elseif (class_exists(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3407
+				$pluginType = Core::CLASS_PLUGIN;
3408
+				if (is_subclass_of(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name), 'Dwoo\Block\Plugin')) {
3409
+					$pluginType += Core::BLOCK_PLUGIN;
3410
+				}
3411
+				$interfaces = class_implements(Core::NAMESPACE_PLUGINS_BLOCKS . 'Plugin' . Core::toCamelCase($name));
3412
+				if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3413
+					$pluginType |= Core::COMPILABLE_PLUGIN;
3414
+				}
3415
+			} // Class functions plugin
3416
+			elseif (class_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3417
+				$pluginType = Core::FUNC_PLUGIN + Core::CLASS_PLUGIN;
3418
+				$interfaces = class_implements(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name));
3419
+				if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3420
+					$pluginType |= Core::COMPILABLE_PLUGIN;
3421
+				}
3422
+			} // Class without namespace
3423
+			elseif (class_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3424
+				$pluginType = Core::CLASS_PLUGIN;
3425
+				$interfaces = class_implements('Plugin' . Core::toCamelCase($name));
3426
+				if (in_array('Dwoo\ICompilable', $interfaces) !== false || in_array('Dwoo\ICompilable\Block', $interfaces) !== false) {
3427
+					$pluginType |= Core::COMPILABLE_PLUGIN;
3428
+				}
3429
+			} // Function plugin (with/without namespaces)
3430
+			elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase ($name)) !==
3431
+				false || function_exists('Plugin' . Core::toCamelCase($name)) !== false) {
3432
+				$pluginType = Core::FUNC_PLUGIN;
3433
+			} // Function plugin compile (with/without namespaces)
3434
+			elseif (function_exists(Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin' . Core::toCamelCase($name) .
3435
+					'Compile') !== false || function_exists('Plugin' . Core::toCamelCase($name) . 'Compile') !==
3436
+				false) {
3437
+				$pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3438
+			} // Helper plugin class compile
3439
+			elseif (class_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name)) !== false) {
3440
+				$pluginType = Core::CLASS_PLUGIN | Core::COMPILABLE_PLUGIN;
3441
+			} // Helper plugin function compile
3442
+			elseif (function_exists(Core::NAMESPACE_PLUGINS_HELPERS . 'Plugin' . Core::toCamelCase($name) . 'Compile') !== false) {
3443
+				$pluginType = Core::FUNC_PLUGIN | Core::COMPILABLE_PLUGIN;
3444
+			} // Smarty modifier
3445
+			elseif (function_exists('smarty_modifier_' . $name) !== false) {
3446
+				$pluginType = Core::SMARTY_MODIFIER;
3447
+			} // Smarty function
3448
+			elseif (function_exists('smarty_function_' . $name) !== false) {
3449
+				$pluginType = Core::SMARTY_FUNCTION;
3450
+			} // Smarty block
3451
+			elseif (function_exists('smarty_block_' . $name) !== false) {
3452
+				$pluginType = Core::SMARTY_BLOCK;
3453
+			} // Everything else
3454
+			else {
3455
+				if ($pluginType === - 1) {
3456
+					try {
3457
+						$this->getCore()->getLoader()->loadPlugin('Plugin' . Core::toCamelCase($name));
3458
+					}
3459
+					catch (Exception $e) {
3460
+						if (isset($phpFunc)) {
3461
+							$pluginType = Core::NATIVE_PLUGIN;
3462
+						} elseif (is_object($this->getCore()->getPluginProxy()) && $this->getCore()->getPluginProxy()->handles($name)) {
3463
+							$pluginType = Core::PROXY_PLUGIN;
3464
+							break;
3465
+						} else {
3466
+							throw $e;
3467
+						}
3468
+					}
3469
+				} else {
3470
+					throw new Exception('Plugin "' . $name . '" could not be found, type:' . $pluginType);
3471
+				}
3472
+				++ $pluginType;
3473
+			}
3474
+		}
3475
+
3476
+		if (($pluginType & Core::COMPILABLE_PLUGIN) === 0 && ($pluginType & Core::NATIVE_PLUGIN) === 0 && ($pluginType & Core::PROXY_PLUGIN) === 0) {
3477
+			$this->addUsedPlugin(Core::toCamelCase($name), $pluginType);
3478
+		}
3479
+
3480
+		return $pluginType;
3481
+	}
3482
+
3483
+	/**
3484
+	 * Allows a plugin to load another one at compile time, this will also mark
3485
+	 * it as used by this template so it will be loaded at runtime (which can be
3486
+	 * useful for compiled plugins that rely on another plugin when their compiled
3487
+	 * code runs).
3488
+	 *
3489
+	 * @param string $name the plugin name
3490
+	 *
3491
+	 * @return void
3492
+	 */
3493
+	public function loadPlugin($name)
3494
+	{
3495
+		$this->getPluginType($name);
3496
+	}
3497
+
3498
+	/**
3499
+	 * Runs htmlentities over the matched <?php ?> blocks when the security policy enforces that.
3500
+	 *
3501
+	 * @param array $match matched php block
3502
+	 *
3503
+	 * @return string the htmlentities-converted string
3504
+	 */
3505
+	protected function phpTagEncodingHelper($match)
3506
+	{
3507
+		return htmlspecialchars($match[0]);
3508
+	}
3509
+
3510
+	/**
3511
+	 * Maps the parameters received from the template onto the parameters required by the given callback.
3512
+	 *
3513
+	 * @param array    $params   the array of parameters
3514
+	 * @param callback $callback the function or method to reflect on to find out the required parameters
3515
+	 * @param int      $callType the type of call in the template, 0 = no params, 1 = php-style call, 2 = named
3516
+	 *                           parameters call
3517
+	 * @param array    $map      the parameter map to use, if not provided it will be built from the callback
3518
+	 *
3519
+	 * @return array parameters sorted in the correct order with missing optional parameters filled
3520
+	 * @throws CompilationException
3521
+	 */
3522
+	protected function mapParams(array $params, $callback, $callType = 2, $map = null)
3523
+	{
3524
+		if (!$map) {
3525
+			$map = $this->getParamMap($callback);
3526
+		}
3527
+
3528
+		$paramlist = array();
3529
+
3530
+		// transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))
3531
+		$ps = array();
3532
+		foreach ($params as $p) {
3533
+			if (is_array($p[1])) {
3534
+				$ps[$p[0]] = $p[1];
3535
+			} else {
3536
+				$ps[] = $p;
3537
+			}
3538
+		}
3539
+
3540
+		// loops over the param map and assigns values from the template or default value for unset optional params
3541
+		foreach ($map as $k => $v){
3542
+			if ($v[0] === '*') {
3543
+				// "rest" array parameter, fill every remaining params in it and then break
3544
+				if (count($ps) === 0) {
3545
+					if ($v[1] === false) {
3546
+						throw new CompilationException(
3547
+							$this, 'Rest argument missing for ' . str_replace(
3548
+								array(
3549
+									Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3550
+								'Compile'
3551
+								), '', (is_array($callback) ? $callback[0] : $callback)
3552
+							)
3553
+						);
3554
+					} else {
3555
+						break;
3556
+					}
3557
+				}
3558
+				$tmp  = array();
3559
+				$tmp2 = array();
3560
+				$tmp3 = array();
3561
+				foreach ($ps as $i => $p) {
3562
+					$tmp[$i]  = $p[0];
3563
+					$tmp2[$i] = $p[1];
3564
+					$tmp3[$i] = isset($p[2]) ? $p[2] : 0;
3565
+					unset($ps[$i]);
3566
+				}
3567
+				$paramlist[$v[0]] = array($tmp, $tmp2, $tmp3);
3568
+				unset($tmp, $tmp2, $i, $p);
3569
+				break;
3570
+			} elseif (isset($ps[$v[0]])) {
3571
+				// parameter is defined as named param
3572
+				$paramlist[$v[0]] = $ps[$v[0]];
3573
+				unset($ps[$v[0]]);
3574
+			} elseif (isset($ps[$k])) {
3575
+				// parameter is defined as ordered param
3576
+				$paramlist[$v[0]] = $ps[$k];
3577
+				unset($ps[$k]);
3578
+			} elseif ($v[1] === false) {
3579
+				// parameter is not defined and not optional, throw error
3580
+				if (is_array($callback)) {
3581
+					if (is_object($callback[0])) {
3582
+						$name = get_class($callback[0]) . '::' . $callback[1];
3583
+					} else {
3584
+						$name = $callback[0];
3585
+					}
3586
+				} else {
3587
+					$name = $callback;
3588
+				}
3589
+
3590
+				throw new CompilationException(
3591
+					$this, 'Argument ' . $k . '/' . $v[0] . ' missing for ' . str_replace(
3592
+						array(
3593
+							Core::NAMESPACE_PLUGINS_FUNCTIONS . 'Plugin',
3594
+						'Compile'
3595
+						), '', $name
3596
+					)
3597
+				);
3598
+			} elseif ($v[2] === null) {
3599
+				// enforce lowercased null if default value is null (php outputs NULL with var export)
3600
+				$paramlist[$v[0]] = array('null', null, self::T_NULL);
3601
+			} else {
3602
+				// outputs default value with var_export
3603
+				$paramlist[$v[0]] = array(var_export($v[2], true), $v[2]);
3604
+			}
3605
+		}
3606
+
3607
+		if (count($ps)) {
3608
+			foreach ($ps as $i => $p) {
3609
+				array_push($paramlist, $p);
3610
+			}
3611
+		}
3612
+
3613
+		return $paramlist;
3614
+	}
3615
+
3616
+	/**
3617
+	 * Returns the parameter map of the given callback, it filters out entries typed as Dwoo and Compiler and turns the
3618
+	 * rest parameter into a "*".
3619
+	 *
3620
+	 * @param callback $callback the function/method to reflect on
3621
+	 *
3622
+	 * @return array processed parameter map
3623
+	 */
3624
+	protected function getParamMap($callback)
3625
+	{
3626
+		if (is_null($callback)) {
3627
+			return array(array('*', true));
3628
+		}
3629
+		if (is_array($callback)) {
3630
+			$ref = new ReflectionMethod($callback[0], $callback[1]);
3631
+		} else {
3632
+			$ref = new ReflectionFunction($callback);
3633
+		}
3634
+
3635
+		$out = array();
3636
+		foreach ($ref->getParameters() as $param) {
3637
+			if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\Core') {
3638
+				continue;
3639
+			}
3640
+			if (($class = $param->getClass()) !== null && $class->name === 'Dwoo\Compiler') {
3641
+				continue;
3642
+			}
3643
+			if ($param->getName() === 'rest' && $param->isArray() === true) {
3644
+				$out[] = array('*', $param->isOptional(), null);
3645
+				continue;
3646
+			}
3647
+			$out[] = array(
3648
+				$param->getName(),
3649
+				$param->isOptional(),
3650
+				$param->isOptional() ? $param->getDefaultValue() : null
3651
+			);
3652
+		}
3653
+
3654
+		return $out;
3655
+	}
3656
+
3657
+	/**
3658
+	 * Returns a default instance of this compiler, used by default by all Dwoo templates that do not have a
3659
+	 * specific compiler assigned and when you do not override the default compiler factory function.
3660
+	 *
3661
+	 * @see    Core::setDefaultCompilerFactory()
3662
+	 * @return Compiler
3663
+	 */
3664
+	public static function compilerFactory()
3665
+	{
3666
+		if (self::$instance === null) {
3667
+			self::$instance = new self();
3668
+		}
3669
+
3670
+		return self::$instance;
3671
+	}
3672 3672
 }
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginDynamic.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -85,8 +85,8 @@
 block discarded – undo
85 85
 
86 86
     /**
87 87
      * @param $output
88
-     * @param $dynamicId
89
-     * @param $compiledFile
88
+     * @param string $dynamicId
89
+     * @param string $compiledFile
90 90
      *
91 91
      * @return mixed|string
92 92
      */
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -28,89 +28,89 @@
 block discarded – undo
28 28
  */
29 29
 class PluginDynamic extends BlockPlugin implements ICompilableBlock
30 30
 {
31
-    /**
32
-     *
33
-     */
34
-    public function init()
35
-    {
36
-    }
31
+	/**
32
+	 *
33
+	 */
34
+	public function init()
35
+	{
36
+	}
37 37
 
38
-    /**
39
-     * @param Compiler $compiler
40
-     * @param array    $params
41
-     * @param string   $prepend
42
-     * @param string   $append
43
-     * @param string   $type
44
-     *
45
-     * @return string
46
-     */
47
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
48
-    {
49
-        return '';
50
-    }
38
+	/**
39
+	 * @param Compiler $compiler
40
+	 * @param array    $params
41
+	 * @param string   $prepend
42
+	 * @param string   $append
43
+	 * @param string   $type
44
+	 *
45
+	 * @return string
46
+	 */
47
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
48
+	{
49
+		return '';
50
+	}
51 51
 
52
-    /**
53
-     * @param Compiler $compiler
54
-     * @param array    $params
55
-     * @param string   $prepend
56
-     * @param string   $append
57
-     * @param string   $content
58
-     *
59
-     * @return string
60
-     */
61
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
62
-    {
63
-        try {
64
-            $compiler->findBlock('dynamic');
52
+	/**
53
+	 * @param Compiler $compiler
54
+	 * @param array    $params
55
+	 * @param string   $prepend
56
+	 * @param string   $append
57
+	 * @param string   $content
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
62
+	{
63
+		try {
64
+			$compiler->findBlock('dynamic');
65 65
 
66
-            return $content;
67
-        }
68
-        catch (CompilationException $e) {
69
-        }
70
-        $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
71
-        if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
72
-            $output .= substr($content, strlen(Compiler::PHP_OPEN));
73
-        } else {
74
-            $output .= Compiler::PHP_CLOSE . $content;
75
-        }
76
-        if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
77
-            $output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
78
-        } else {
79
-            $output .= Compiler::PHP_OPEN;
80
-        }
81
-        $output .= "\n}" . Compiler::PHP_CLOSE;
66
+			return $content;
67
+		}
68
+		catch (CompilationException $e) {
69
+		}
70
+		$output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
71
+		if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
72
+			$output .= substr($content, strlen(Compiler::PHP_OPEN));
73
+		} else {
74
+			$output .= Compiler::PHP_CLOSE . $content;
75
+		}
76
+		if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
77
+			$output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
78
+		} else {
79
+			$output .= Compiler::PHP_OPEN;
80
+		}
81
+		$output .= "\n}" . Compiler::PHP_CLOSE;
82 82
 
83
-        return $output;
84
-    }
83
+		return $output;
84
+	}
85 85
 
86
-    /**
87
-     * @param $output
88
-     * @param $dynamicId
89
-     * @param $compiledFile
90
-     *
91
-     * @return mixed|string
92
-     */
93
-    public static function unescape($output, $dynamicId, $compiledFile)
94
-    {
95
-        $output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array(
96
-            'self',
97
-            'unescapePhp'
98
-        ), $output, - 1, $count);
99
-        // re-add the includes on top of the file
100
-        if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
101
-            $output = '<?php ' . $m[1] . ' ?>' . $output;
102
-        }
86
+	/**
87
+	 * @param $output
88
+	 * @param $dynamicId
89
+	 * @param $compiledFile
90
+	 *
91
+	 * @return mixed|string
92
+	 */
93
+	public static function unescape($output, $dynamicId, $compiledFile)
94
+	{
95
+		$output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array(
96
+			'self',
97
+			'unescapePhp'
98
+		), $output, - 1, $count);
99
+		// re-add the includes on top of the file
100
+		if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
101
+			$output = '<?php ' . $m[1] . ' ?>' . $output;
102
+		}
103 103
 
104
-        return $output;
105
-    }
104
+		return $output;
105
+	}
106 106
 
107
-    /**
108
-     * @param $match
109
-     *
110
-     * @return mixed
111
-     */
112
-    public static function unescapePhp($match)
113
-    {
114
-        return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
115
-    }
107
+	/**
108
+	 * @param $match
109
+	 *
110
+	 * @return mixed
111
+	 */
112
+	public static function unescapePhp($match)
113
+	{
114
+		return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
         }
68 68
         catch (CompilationException $e) {
69 69
         }
70
-        $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
70
+        $output = Compiler::PHP_OPEN.'if($doCache) {'."\n\t".'echo \'<dwoo:dynamic_\'.$dynamicId.\'>'.str_replace('\'', '\\\'', $content).'</dwoo:dynamic_\'.$dynamicId.\'>\';'."\n} else {\n\t";
71 71
         if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
72 72
             $output .= substr($content, strlen(Compiler::PHP_OPEN));
73 73
         } else {
74
-            $output .= Compiler::PHP_CLOSE . $content;
74
+            $output .= Compiler::PHP_CLOSE.$content;
75 75
         }
76 76
         if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
77 77
             $output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
78 78
         } else {
79 79
             $output .= Compiler::PHP_OPEN;
80 80
         }
81
-        $output .= "\n}" . Compiler::PHP_CLOSE;
81
+        $output .= "\n}".Compiler::PHP_CLOSE;
82 82
 
83 83
         return $output;
84 84
     }
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public static function unescape($output, $dynamicId, $compiledFile)
94 94
     {
95
-        $output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array(
95
+        $output = preg_replace_callback('/<dwoo:dynamic_('.$dynamicId.')>(.+?)<\/dwoo:dynamic_'.$dynamicId.'>/s', array(
96 96
             'self',
97 97
             'unescapePhp'
98 98
         ), $output, - 1, $count);
99 99
         // re-add the includes on top of the file
100 100
         if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
101
-            $output = '<?php ' . $m[1] . ' ?>' . $output;
101
+            $output = '<?php '.$m[1].' ?>'.$output;
102 102
         }
103 103
 
104 104
         return $output;
@@ -111,6 +111,6 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public static function unescapePhp($match)
113 113
     {
114
-        return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
114
+        return preg_replace('{<\?php /\*'.$match[1].'\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
115 115
     }
116 116
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@
 block discarded – undo
64 64
             $compiler->findBlock('dynamic');
65 65
 
66 66
             return $content;
67
-        }
68
-        catch (CompilationException $e) {
67
+        } catch (CompilationException $e) {
69 68
         }
70 69
         $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
71 70
         if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Blocks/PluginStrip.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
      * @param string   $append
60 60
      * @param string   $content
61 61
      *
62
-     * @return mixed|string
62
+     * @return string
63 63
      */
64 64
     public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
65 65
     {
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -31,59 +31,59 @@
 block discarded – undo
31 31
  */
32 32
 class PluginStrip extends BlockPlugin implements ICompilableBlock
33 33
 {
34
-    /**
35
-     * @param string $mode
36
-     */
37
-    public function init($mode = 'default')
38
-    {
39
-    }
34
+	/**
35
+	 * @param string $mode
36
+	 */
37
+	public function init($mode = 'default')
38
+	{
39
+	}
40 40
 
41
-    /**
42
-     * @param Compiler $compiler
43
-     * @param array    $params
44
-     * @param string   $prepend
45
-     * @param string   $append
46
-     * @param string   $type
47
-     *
48
-     * @return string
49
-     */
50
-    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
51
-    {
52
-        return '';
53
-    }
41
+	/**
42
+	 * @param Compiler $compiler
43
+	 * @param array    $params
44
+	 * @param string   $prepend
45
+	 * @param string   $append
46
+	 * @param string   $type
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
51
+	{
52
+		return '';
53
+	}
54 54
 
55
-    /**
56
-     * @param Compiler $compiler
57
-     * @param array    $params
58
-     * @param string   $prepend
59
-     * @param string   $append
60
-     * @param string   $content
61
-     *
62
-     * @return mixed|string
63
-     */
64
-    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
65
-    {
66
-        $params = $compiler->getCompiledParams($params);
55
+	/**
56
+	 * @param Compiler $compiler
57
+	 * @param array    $params
58
+	 * @param string   $prepend
59
+	 * @param string   $append
60
+	 * @param string   $content
61
+	 *
62
+	 * @return mixed|string
63
+	 */
64
+	public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
65
+	{
66
+		$params = $compiler->getCompiledParams($params);
67 67
 
68
-        $mode = trim($params['mode'], '"\'');
69
-        switch ($mode) {
70
-            case 'js':
71
-            case 'javascript':
72
-                $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
68
+		$mode = trim($params['mode'], '"\'');
69
+		switch ($mode) {
70
+			case 'js':
71
+			case 'javascript':
72
+				$content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
73 73
 
74
-            case 'default':
75
-            default:
76
-        }
77
-        $content = preg_replace(array(
78
-            "/\n/",
79
-            "/\r/",
80
-            '/(<\?(?:php)?|<%)\s*/'
81
-        ), array(
82
-            '',
83
-            '',
84
-            '$1 '
85
-        ), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
74
+			case 'default':
75
+			default:
76
+		}
77
+		$content = preg_replace(array(
78
+			"/\n/",
79
+			"/\r/",
80
+			'/(<\?(?:php)?|<%)\s*/'
81
+		), array(
82
+			'',
83
+			'',
84
+			'$1 '
85
+		), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
86 86
 
87
-        return $content;
88
-    }
87
+		return $content;
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Switch Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,12 +67,12 @@
 block discarded – undo
67 67
 
68 68
         $mode = trim($params['mode'], '"\'');
69 69
         switch ($mode) {
70
-            case 'js':
71
-            case 'javascript':
72
-                $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
70
+        case 'js':
71
+        case 'javascript':
72
+            $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
73 73
 
74
-            case 'default':
75
-            default:
74
+        case 'default':
75
+        default:
76 76
         }
77 77
         $content = preg_replace(array(
78 78
             "/\n/",
Please login to merge, or discard this patch.
lib/Dwoo/Plugins/Processors/PluginSmartyCompatible.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
     /**
30 30
      * @param string $input
31 31
      *
32
-     * @return mixed
32
+     * @return string
33 33
      */
34 34
     public function process($input)
35 35
     {
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -26,69 +26,69 @@
 block discarded – undo
26 26
  */
27 27
 class PluginSmartyCompatible extends Processor
28 28
 {
29
-    /**
30
-     * @param string $input
31
-     *
32
-     * @return mixed
33
-     */
34
-    public function process($input)
35
-    {
36
-        list($l, $r) = $this->compiler->getDelimiters();
29
+	/**
30
+	 * @param string $input
31
+	 *
32
+	 * @return mixed
33
+	 */
34
+	public function process($input)
35
+	{
36
+		list($l, $r) = $this->compiler->getDelimiters();
37 37
 
38
-        $rl           = preg_quote($l, '/');
39
-        $rr           = preg_quote($r, '/');
40
-        $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*';
41
-        $input        = preg_replace_callback('/' . $rl . '\s*section ' . str_repeat($sectionParam, 6) . '\s*' . $rr . '(.+?)(?:' . $rl . '\s*sectionelse\s*' . $rr . '(.+?))?' . $rl . '\s*\/section\s*' . $rr . '/is', array(
42
-            $this,
43
-            'convertSection'
44
-        ), $input);
45
-        $input        = str_replace('$smarty.section.', '$smarty.for.', $input);
38
+		$rl           = preg_quote($l, '/');
39
+		$rr           = preg_quote($r, '/');
40
+		$sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*';
41
+		$input        = preg_replace_callback('/' . $rl . '\s*section ' . str_repeat($sectionParam, 6) . '\s*' . $rr . '(.+?)(?:' . $rl . '\s*sectionelse\s*' . $rr . '(.+?))?' . $rl . '\s*\/section\s*' . $rr . '/is', array(
42
+			$this,
43
+			'convertSection'
44
+		), $input);
45
+		$input        = str_replace('$smarty.section.', '$smarty.for.', $input);
46 46
 
47
-        $smarty = array(
48
-            '/' . $rl . '\s*ldelim\s*' . $rr . '/',
49
-            '/' . $rl . '\s*rdelim\s*' . $rr . '/',
50
-            '/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/',
51
-            '/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/',
52
-            '/\$smarty\./',
53
-            '/' . $rl . '\s*php\s*' . $rr . '/',
54
-            '/' . $rl . '\s*\/php\s*' . $rr . '/',
55
-            '/\|(@?)strip(\||' . $rr . ')/',
56
-            '/' . $rl . '\s*sectionelse\s*' . $rr . '/',
57
-        );
47
+		$smarty = array(
48
+			'/' . $rl . '\s*ldelim\s*' . $rr . '/',
49
+			'/' . $rl . '\s*rdelim\s*' . $rr . '/',
50
+			'/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/',
51
+			'/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/',
52
+			'/\$smarty\./',
53
+			'/' . $rl . '\s*php\s*' . $rr . '/',
54
+			'/' . $rl . '\s*\/php\s*' . $rr . '/',
55
+			'/\|(@?)strip(\||' . $rr . ')/',
56
+			'/' . $rl . '\s*sectionelse\s*' . $rr . '/',
57
+		);
58 58
 
59
-        $dwoo = array(
60
-            '\\' . $l,
61
-            $r,
62
-            '\\' . $l,
63
-            $r,
64
-            '$dwoo.',
65
-            '<?php ',
66
-            ' ?>',
67
-            '|$1whitespace$2',
68
-            $l . 'else' . $r,
69
-        );
59
+		$dwoo = array(
60
+			'\\' . $l,
61
+			$r,
62
+			'\\' . $l,
63
+			$r,
64
+			'$dwoo.',
65
+			'<?php ',
66
+			' ?>',
67
+			'|$1whitespace$2',
68
+			$l . 'else' . $r,
69
+		);
70 70
 
71
-        if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) {
72
-            trigger_error('The Smarty Compatibility Module has detected that you use |@' . $matches[1] . ' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
73
-        }
71
+		if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) {
72
+			trigger_error('The Smarty Compatibility Module has detected that you use |@' . $matches[1] . ' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
73
+		}
74 74
 
75
-        return preg_replace($smarty, $dwoo, $input);
76
-    }
75
+		return preg_replace($smarty, $dwoo, $input);
76
+	}
77 77
 
78
-    /**
79
-     * @param array $matches
80
-     *
81
-     * @return mixed
82
-     */
83
-    protected function convertSection(array $matches)
84
-    {
85
-        $params = array();
86
-        $index  = 1;
87
-        while (!empty($matches[$index]) && $index < 13) {
88
-            $params[$matches[$index]] = $matches[$index + 1];
89
-            $index += 2;
90
-        }
78
+	/**
79
+	 * @param array $matches
80
+	 *
81
+	 * @return mixed
82
+	 */
83
+	protected function convertSection(array $matches)
84
+	{
85
+		$params = array();
86
+		$index  = 1;
87
+		while (!empty($matches[$index]) && $index < 13) {
88
+			$params[$matches[$index]] = $matches[$index + 1];
89
+			$index += 2;
90
+		}
91 91
 
92
-        return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]);
93
-    }
92
+		return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -38,38 +38,38 @@  discard block
 block discarded – undo
38 38
         $rl           = preg_quote($l, '/');
39 39
         $rr           = preg_quote($r, '/');
40 40
         $sectionParam = '(?:(name|loop|start|step|max|show)\s*=\s*(\S+))?\s*';
41
-        $input        = preg_replace_callback('/' . $rl . '\s*section ' . str_repeat($sectionParam, 6) . '\s*' . $rr . '(.+?)(?:' . $rl . '\s*sectionelse\s*' . $rr . '(.+?))?' . $rl . '\s*\/section\s*' . $rr . '/is', array(
41
+        $input        = preg_replace_callback('/'.$rl.'\s*section '.str_repeat($sectionParam, 6).'\s*'.$rr.'(.+?)(?:'.$rl.'\s*sectionelse\s*'.$rr.'(.+?))?'.$rl.'\s*\/section\s*'.$rr.'/is', array(
42 42
             $this,
43 43
             'convertSection'
44 44
         ), $input);
45
-        $input        = str_replace('$smarty.section.', '$smarty.for.', $input);
45
+        $input = str_replace('$smarty.section.', '$smarty.for.', $input);
46 46
 
47 47
         $smarty = array(
48
-            '/' . $rl . '\s*ldelim\s*' . $rr . '/',
49
-            '/' . $rl . '\s*rdelim\s*' . $rr . '/',
50
-            '/' . $rl . '\s*\$smarty\.ldelim\s*' . $rr . '/',
51
-            '/' . $rl . '\s*\$smarty\.rdelim\s*' . $rr . '/',
48
+            '/'.$rl.'\s*ldelim\s*'.$rr.'/',
49
+            '/'.$rl.'\s*rdelim\s*'.$rr.'/',
50
+            '/'.$rl.'\s*\$smarty\.ldelim\s*'.$rr.'/',
51
+            '/'.$rl.'\s*\$smarty\.rdelim\s*'.$rr.'/',
52 52
             '/\$smarty\./',
53
-            '/' . $rl . '\s*php\s*' . $rr . '/',
54
-            '/' . $rl . '\s*\/php\s*' . $rr . '/',
55
-            '/\|(@?)strip(\||' . $rr . ')/',
56
-            '/' . $rl . '\s*sectionelse\s*' . $rr . '/',
53
+            '/'.$rl.'\s*php\s*'.$rr.'/',
54
+            '/'.$rl.'\s*\/php\s*'.$rr.'/',
55
+            '/\|(@?)strip(\||'.$rr.')/',
56
+            '/'.$rl.'\s*sectionelse\s*'.$rr.'/',
57 57
         );
58 58
 
59 59
         $dwoo = array(
60
-            '\\' . $l,
60
+            '\\'.$l,
61 61
             $r,
62
-            '\\' . $l,
62
+            '\\'.$l,
63 63
             $r,
64 64
             '$dwoo.',
65 65
             '<?php ',
66 66
             ' ?>',
67 67
             '|$1whitespace$2',
68
-            $l . 'else' . $r,
68
+            $l.'else'.$r,
69 69
         );
70 70
 
71 71
         if (preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches)) {
72
-            trigger_error('The Smarty Compatibility Module has detected that you use |@' . $matches[1] . ' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
72
+            trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
73 73
         }
74 74
 
75 75
         return preg_replace($smarty, $dwoo, $input);
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
         $params = array();
86 86
         $index  = 1;
87 87
         while (!empty($matches[$index]) && $index < 13) {
88
-            $params[$matches[$index]] = $matches[$index + 1];
88
+            $params[$matches[$index]] = $matches[$index+1];
89 89
             $index += 2;
90 90
         }
91 91
 
92
-        return str_replace('[' . trim($params['name'], '"\'') . ']', '[$' . trim($params['name'], '"\'') . ']', $matches[0]);
92
+        return str_replace('['.trim($params['name'], '"\'').']', '[$'.trim($params['name'], '"\'').']', $matches[0]);
93 93
     }
94 94
 }
Please login to merge, or discard this patch.
lib/Dwoo/Smarty/Adapter.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -312,7 +312,7 @@
 block discarded – undo
312 312
 
313 313
     /**
314 314
      * @param mixed $_tpl
315
-     * @param array $data
315
+     * @param Data $data
316 316
      * @param null  $_compiler
317 317
      * @param bool  $_output
318 318
      *
Please login to merge, or discard this patch.
Indentation   +657 added lines, -657 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 use Dwoo\Smarty\Processor\Adapter as ProcessorAdapter;
27 27
 
28 28
 if (!defined('DIR_SEP')) {
29
-    define('DIR_SEP', DIRECTORY_SEPARATOR);
29
+	define('DIR_SEP', DIRECTORY_SEPARATOR);
30 30
 }
31 31
 
32 32
 if (!defined('SMARTY_PHP_PASSTHRU')) {
33
-    define('SMARTY_PHP_PASSTHRU', 0);
34
-    define('SMARTY_PHP_QUOTE', 1);
35
-    define('SMARTY_PHP_REMOVE', 2);
36
-    define('SMARTY_PHP_ALLOW', 3);
33
+	define('SMARTY_PHP_PASSTHRU', 0);
34
+	define('SMARTY_PHP_QUOTE', 1);
35
+	define('SMARTY_PHP_REMOVE', 2);
36
+	define('SMARTY_PHP_ALLOW', 3);
37 37
 }
38 38
 
39 39
 /**
@@ -43,656 +43,656 @@  discard block
 block discarded – undo
43 43
  */
44 44
 class Adapter extends Core
45 45
 {
46
-    /**
47
-     * Magic get/set/call functions that handle unsupported features
48
-     *
49
-     * @param string $p
50
-     * @param string $v
51
-     */
52
-    public function __set($p, $v)
53
-    {
54
-        if ($p === 'scope') {
55
-            $this->scope = $v;
56
-
57
-            return;
58
-        }
59
-        if ($p === 'data') {
60
-            $this->data = $v;
61
-
62
-            return;
63
-        }
64
-        if (array_key_exists($p, $this->compat['properties']) !== false) {
65
-            if ($this->show_compat_errors) {
66
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
67
-            }
68
-            $this->compat['properties'][$p] = $v;
69
-        } else {
70
-            if ($this->show_compat_errors) {
71
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
72
-            }
73
-        }
74
-    }
75
-
76
-    /**
77
-     * @param $p
78
-     *
79
-     * @return mixed
80
-     */
81
-    public function __get($p)
82
-    {
83
-        if (array_key_exists($p, $this->compat['properties']) !== false) {
84
-            if ($this->show_compat_errors) {
85
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
86
-            }
87
-
88
-            return $this->compat['properties'][$p];
89
-        } else {
90
-            if ($this->show_compat_errors) {
91
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
92
-            }
93
-        }
94
-    }
95
-
96
-    /**
97
-     * @param string $m
98
-     * @param array  $a
99
-     *
100
-     * @return mixed|void
101
-     */
102
-    public function __call($m, $a)
103
-    {
104
-        if (method_exists($this->dataProvider, $m)) {
105
-            call_user_func_array(
106
-                array(
107
-                $this->dataProvider,
108
-                $m
109
-                ), $a
110
-            );
111
-        } elseif ($this->show_compat_errors) {
112
-            if (array_search($m, $this->compat['methods']) !== false) {
113
-                $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
114
-            } else {
115
-                $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
116
-            }
117
-        }
118
-    }
119
-
120
-    /**
121
-     * List of unsupported properties and methods
122
-     */
123
-    protected $compat = array(
124
-        'methods'    => array(
125
-            'register_resource',
126
-            'unregister_resource',
127
-            'load_filter',
128
-            'clear_compiled_tpl',
129
-            'clear_config',
130
-            'get_config_vars',
131
-            'config_load',
132
-        ),
133
-        'properties' => array(
134
-            'cache_handler_func'            => null,
135
-            'debugging'                     => false,
136
-            'error_reporting'               => null,
137
-            'debugging_ctrl'                => 'NONE',
138
-            'request_vars_order'            => 'EGPCS',
139
-            'request_use_auto_globals'      => true,
140
-            'use_sub_dirs'                  => false,
141
-            'autoload_filters'              => array(),
142
-            'default_template_handler_func' => '',
143
-            'debug_tpl'                     => '',
144
-            'cache_modified_check'          => false,
145
-            'default_modifiers'             => array(),
146
-            'default_resource_type'         => 'file',
147
-            'config_overwrite'              => true,
148
-            'config_booleanize'             => true,
149
-            'config_read_hidden'            => false,
150
-            'config_fix_newlines'           => true,
151
-            'config_class'                  => 'Config_File',
152
-        ),
153
-    );
154
-
155
-    /**
156
-     * Security vars
157
-     */
158
-    public $security          = false;
159
-    public $trusted_dir       = array();
160
-    public $secure_dir        = array();
161
-    public $php_handling      = SMARTY_PHP_PASSTHRU;
162
-    public $security_settings = array(
163
-        'PHP_HANDLING'    => false,
164
-        'IF_FUNCS'        => array(
165
-            'list',
166
-            'empty',
167
-            'count',
168
-            'sizeof',
169
-            'in_array',
170
-            'is_array',
171
-        ),
172
-        'INCLUDE_ANY'     => false,
173
-        'PHP_TAGS'        => false,
174
-        'MODIFIER_FUNCS'  => array(),
175
-        'ALLOW_CONSTANTS' => false,
176
-    );
177
-
178
-    /**
179
-     * Paths
180
-     */
181
-    public $template_dir = 'templates';
182
-    public $compile_dir  = 'templates_c';
183
-    public $config_dir   = 'configs';
184
-    public $cache_dir    = 'cache';
185
-    public $plugins_dir  = array();
186
-
187
-    /**
188
-     * Misc options
189
-     */
190
-    public $left_delimiter  = '{';
191
-    public $right_delimiter = '}';
192
-    public $compile_check   = true;
193
-    public $force_compile   = false;
194
-    public $caching         = 0;
195
-    public $cache_lifetime  = 3600;
196
-    public $compile_id      = null;
197
-    public $compiler_file   = null;
198
-    public $compiler_class  = null;
199
-
200
-    /**
201
-     * Dwoo/Smarty compat layer
202
-     */
203
-    public           $show_compat_errors = false;
204
-    protected        $dataProvider;
205
-    protected        $_filters           = array(
206
-        'pre'    => array(),
207
-        'post'   => array(),
208
-        'output' => array()
209
-    );
210
-    protected static $tplCache           = array();
211
-    protected        $compiler           = null;
212
-
213
-    /**
214
-     * Adapter constructor.
215
-     */
216
-    public function __construct()
217
-    {
218
-        parent::__construct();
219
-        $this->charset      = 'iso-8859-1';
220
-        $this->dataProvider = new Data();
221
-        $this->compiler     = new Compiler();
222
-    }
223
-
224
-    /**
225
-     * @param      $filename
226
-     * @param null $cacheId
227
-     * @param null $compileId
228
-     */
229
-    public function display($filename, $cacheId = null, $compileId = null)
230
-    {
231
-        $this->fetch($filename, $cacheId, $compileId, true);
232
-    }
233
-
234
-    /**
235
-     * @param      $filename
236
-     * @param null $cacheId
237
-     * @param null $compileId
238
-     * @param bool $display
239
-     *
240
-     * @return string|void
241
-     */
242
-    public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
243
-    {
244
-        $this->setCacheDir($this->cache_dir);
245
-        $this->setCompileDir($this->compile_dir);
246
-
247
-        if ($this->security) {
248
-            $policy = new SecurityPolicy();
249
-            $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
250
-
251
-            $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
252
-            if ($this->security_settings['PHP_TAGS']) {
253
-                $phpTags = SMARTY_PHP_ALLOW;
254
-            }
255
-            switch ($phpTags) {
256
-            case SMARTY_PHP_ALLOW:
257
-            case SMARTY_PHP_PASSTHRU:
258
-                $phpTags = SecurityPolicy::PHP_ALLOW;
259
-                break;
260
-            case SMARTY_PHP_QUOTE:
261
-                $phpTags = SecurityPolicy::PHP_ENCODE;
262
-                break;
263
-            case SMARTY_PHP_REMOVE:
264
-            default:
265
-                $phpTags = SecurityPolicy::PHP_REMOVE;
266
-                break;
267
-            }
268
-            $policy->setPhpHandling($phpTags);
269
-
270
-            $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
271
-
272
-            if ($this->security_settings['INCLUDE_ANY']) {
273
-                $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
274
-            } else {
275
-                $policy->allowDirectory($this->secure_dir);
276
-            }
277
-
278
-            $this->setSecurityPolicy($policy);
279
-        }
280
-
281
-        if (!empty($this->plugins_dir)) {
282
-            foreach ($this->plugins_dir as $dir) {
283
-                $this->getLoader()->addDirectory(rtrim($dir, '\\/'));
284
-            }
285
-        }
286
-
287
-        $tpl = $this->makeTemplate($filename, $cacheId, $compileId);
288
-        if ($this->force_compile) {
289
-            $tpl->forceCompilation();
290
-        }
291
-
292
-        if ($this->caching > 0) {
293
-            $this->cacheTime = $this->cache_lifetime;
294
-        } else {
295
-            $this->cacheTime = 0;
296
-        }
297
-
298
-        if ($this->compiler_class !== null) {
299
-            if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
300
-                include $this->compiler_file;
301
-            }
302
-            $this->compiler = new $this->compiler_class();
303
-        } else {
304
-            $this->compiler->addPreProcessor('PluginSmartyCompatible', true);
305
-            $this->compiler->setLooseOpeningHandling(true);
306
-        }
307
-
308
-        $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
309
-
310
-        return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
311
-    }
312
-
313
-    /**
314
-     * @param mixed $_tpl
315
-     * @param array $data
316
-     * @param null  $_compiler
317
-     * @param bool  $_output
318
-     *
319
-     * @return string|void
320
-     */
321
-    public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
322
-    {
323
-        if ($_compiler === null) {
324
-            $_compiler = $this->compiler;
325
-        }
326
-
327
-        return parent::get($_tpl, $data, $_compiler, $_output);
328
-    }
329
-
330
-    /**
331
-     * @param      $name
332
-     * @param      $callback
333
-     * @param bool $cacheable
334
-     * @param null $cache_attrs
335
-     *
336
-     * @throws Exception
337
-     */
338
-    public function register_function($name, $callback, $cacheable = true, $cache_attrs = null)
339
-    {
340
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) {
341
-            throw new Exception('Multiple plugins of different types can not share the same name');
342
-        }
343
-        $this->plugins[$name] = array(
344
-            'type'     => self::SMARTY_FUNCTION,
345
-            'callback' => $callback
346
-        );
347
-    }
348
-
349
-    /**
350
-     * @param $name
351
-     */
352
-    public function unregister_function($name)
353
-    {
354
-        unset($this->plugins[$name]);
355
-    }
356
-
357
-    /**
358
-     * @param      $name
359
-     * @param      $callback
360
-     * @param bool $cacheable
361
-     * @param null $cache_attrs
362
-     *
363
-     * @throws Exception
364
-     */
365
-    public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
366
-    {
367
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
368
-            throw new Exception('Multiple plugins of different types can not share the same name');
369
-        }
370
-        $this->plugins[$name] = array(
371
-            'type'     => self::SMARTY_BLOCK,
372
-            'callback' => $callback
373
-        );
374
-    }
375
-
376
-    /**
377
-     * @param $name
378
-     */
379
-    public function unregister_block($name)
380
-    {
381
-        unset($this->plugins[$name]);
382
-    }
383
-
384
-    /**
385
-     * @param $name
386
-     * @param $callback
387
-     *
388
-     * @throws Exception
389
-     */
390
-    public function register_modifier($name, $callback)
391
-    {
392
-        if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) {
393
-            throw new Exception('Multiple plugins of different types can not share the same name');
394
-        }
395
-        $this->plugins[$name] = array(
396
-            'type'     => self::SMARTY_MODIFIER,
397
-            'callback' => $callback
398
-        );
399
-    }
400
-
401
-    /**
402
-     * @param $name
403
-     */
404
-    public function unregister_modifier($name)
405
-    {
406
-        unset($this->plugins[$name]);
407
-    }
408
-
409
-    /**
410
-     * @param $callback
411
-     */
412
-    public function register_prefilter($callback)
413
-    {
414
-        $processor = new ProcessorAdapter($this->compiler);
415
-        $processor->registerCallback($callback);
416
-        $this->_filters['pre'][] = $processor;
417
-        $this->compiler->addPreProcessor($processor);
418
-    }
419
-
420
-    /**
421
-     * @param $callback
422
-     */
423
-    public function unregister_prefilter($callback)
424
-    {
425
-        foreach ($this->_filters['pre'] as $index => $processor) {
426
-            if ($processor->callback === $callback) {
427
-                $this->compiler->removePostProcessor($processor);
428
-                unset($this->_filters['pre'][$index]);
429
-            }
430
-        }
431
-    }
432
-
433
-    /**
434
-     * @param $callback
435
-     */
436
-    public function register_postfilter($callback)
437
-    {
438
-        $processor = new ProcessorAdapter($this->compiler);
439
-        $processor->registerCallback($callback);
440
-        $this->_filters['post'][] = $processor;
441
-        $this->compiler->addPostProcessor($processor);
442
-    }
443
-
444
-    /**
445
-     * @param $callback
446
-     */
447
-    public function unregister_postfilter($callback)
448
-    {
449
-        foreach ($this->_filters['post'] as $index => $processor) {
450
-            if ($processor->callback === $callback) {
451
-                $this->compiler->removePostProcessor($processor);
452
-                unset($this->_filters['post'][$index]);
453
-            }
454
-        }
455
-    }
456
-
457
-    /**
458
-     * @param $callback
459
-     */
460
-    public function register_outputfilter($callback)
461
-    {
462
-        $filter = new FilterAdapter($this);
463
-        $filter->registerCallback($callback);
464
-        $this->_filters['output'][] = $filter;
465
-        $this->addFilter($filter);
466
-    }
467
-
468
-    /**
469
-     * @param $callback
470
-     */
471
-    public function unregister_outputfilter($callback)
472
-    {
473
-        foreach ($this->_filters['output'] as $index => $filter) {
474
-            if ($filter->callback === $callback) {
475
-                $this->removeOutputFilter($filter);
476
-                unset($this->_filters['output'][$index]);
477
-            }
478
-        }
479
-    }
480
-
481
-    /**
482
-     * @param       $object
483
-     * @param       $object_impl
484
-     * @param array $allowed
485
-     * @param bool  $smarty_args
486
-     * @param array $block_methods
487
-     */
488
-    public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array())
489
-    {
490
-        settype($allowed, 'array');
491
-        settype($block_methods, 'array');
492
-        settype($smarty_args, 'boolean');
493
-
494
-        if (!empty($allowed) && $this->show_compat_errors) {
495
-            $this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE);
496
-        }
497
-
498
-        if ($smarty_args) {
499
-            $this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE);
500
-        }
501
-
502
-        if (!empty($block_methods)) {
503
-            $this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE);
504
-        }
505
-
506
-        $this->dataProvider->assign($object, $object_impl);
507
-    }
508
-
509
-    /**
510
-     * @param $object
511
-     */
512
-    public function unregister_object($object)
513
-    {
514
-        $this->dataProvider->clear($object);
515
-    }
516
-
517
-    /**
518
-     * @param $name
519
-     *
520
-     * @return mixed
521
-     */
522
-    public function get_registered_object($name)
523
-    {
524
-        $data = $this->dataProvider->getData();
525
-        if (isset($data[$name]) && is_object($data[$name])) {
526
-            return $data[$name];
527
-        } else {
528
-            trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR);
529
-        }
530
-    }
531
-
532
-    /**
533
-     * @param $filename
534
-     *
535
-     * @return bool
536
-     */
537
-    public function template_exists($filename)
538
-    {
539
-        if (!is_array($this->template_dir)) {
540
-            return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename);
541
-        } else {
542
-            foreach ($this->template_dir as $tpl_dir) {
543
-                if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) {
544
-                    return true;
545
-                }
546
-            }
547
-
548
-            return false;
549
-        }
550
-    }
551
-
552
-    /**
553
-     * @param      $tpl
554
-     * @param null $cacheId
555
-     * @param null $compileId
556
-     *
557
-     * @return bool
558
-     */
559
-    public function is_cached($tpl, $cacheId = null, $compileId = null)
560
-    {
561
-        return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId));
562
-    }
563
-
564
-    /**
565
-     * @param      $var
566
-     * @param      $value
567
-     * @param bool $merge
568
-     */
569
-    public function append_by_ref($var, &$value, $merge = false)
570
-    {
571
-        $this->dataProvider->appendByRef($var, $value, $merge);
572
-    }
573
-
574
-    /**
575
-     * @param $name
576
-     * @param $val
577
-     */
578
-    public function assign_by_ref($name, &$val)
579
-    {
580
-        $this->dataProvider->assignByRef($name, $val);
581
-    }
582
-
583
-    /**
584
-     * @param $var
585
-     */
586
-    public function clear_assign($var)
587
-    {
588
-        $this->dataProvider->clear($var);
589
-    }
590
-
591
-    /**
592
-     *
593
-     */
594
-    public function clear_all_assign()
595
-    {
596
-        $this->dataProvider->clear();
597
-    }
598
-
599
-    /**
600
-     * @param null $name
601
-     *
602
-     * @return array|null
603
-     */
604
-    public function get_template_vars($name = null)
605
-    {
606
-        if ($this->show_compat_errors) {
607
-            trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE);
608
-        }
609
-
610
-        $data = $this->dataProvider->getData();
611
-        if ($name === null) {
612
-            return $data;
613
-        } elseif (isset($data[$name])) {
614
-            return $data[$name];
615
-        }
616
-
617
-        return null;
618
-    }
619
-
620
-    /**
621
-     * @param int $olderThan
622
-     */
623
-    public function clear_all_cache($olderThan = 0)
624
-    {
625
-        $this->clearCache($olderThan);
626
-    }
627
-
628
-    /**
629
-     * @param      $template
630
-     * @param null $cacheId
631
-     * @param null $compileId
632
-     * @param int  $olderThan
633
-     */
634
-    public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0)
635
-    {
636
-        $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
637
-    }
638
-
639
-    /**
640
-     * @param     $error_msg
641
-     * @param int $error_type
642
-     */
643
-    public function trigger_error($error_msg, $error_type = E_USER_WARNING)
644
-    {
645
-        $this->triggerError($error_msg, $error_type);
646
-    }
647
-
648
-    /**
649
-     *
650
-     */
651
-    protected function initGlobals()
652
-    {
653
-        parent::initGlobals();
654
-        $this->globals['ldelim'] = '{';
655
-        $this->globals['rdelim'] = '}';
656
-    }
657
-
658
-    /**
659
-     * @param $file
660
-     * @param $cacheId
661
-     * @param $compileId
662
-     *
663
-     * @return mixed
664
-     * @throws Exception
665
-     */
666
-    protected function makeTemplate($file, $cacheId, $compileId)
667
-    {
668
-        if ($compileId === null) {
669
-            $compileId = $this->compile_id;
670
-        }
671
-
672
-        $hash = bin2hex(md5($file . $cacheId . $compileId, true));
673
-        if (!isset(self::$tplCache[$hash])) {
674
-            // abs path
675
-            if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
676
-                self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId);
677
-            } elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
678
-                self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir);
679
-            } else {
680
-                throw new Exception('Unable to load "' . $file . '", check the template_dir');
681
-            }
682
-        }
683
-
684
-        return self::$tplCache[$hash];
685
-    }
686
-
687
-    /**
688
-     * @param string $message
689
-     * @param int    $level
690
-     */
691
-    public function triggerError($message, $level = E_USER_NOTICE)
692
-    {
693
-        if (is_object($this->template)) {
694
-            parent::triggerError($message, $level);
695
-        }
696
-        trigger_error('Dwoo error : ' . $message, $level);
697
-    }
46
+	/**
47
+	 * Magic get/set/call functions that handle unsupported features
48
+	 *
49
+	 * @param string $p
50
+	 * @param string $v
51
+	 */
52
+	public function __set($p, $v)
53
+	{
54
+		if ($p === 'scope') {
55
+			$this->scope = $v;
56
+
57
+			return;
58
+		}
59
+		if ($p === 'data') {
60
+			$this->data = $v;
61
+
62
+			return;
63
+		}
64
+		if (array_key_exists($p, $this->compat['properties']) !== false) {
65
+			if ($this->show_compat_errors) {
66
+				$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
67
+			}
68
+			$this->compat['properties'][$p] = $v;
69
+		} else {
70
+			if ($this->show_compat_errors) {
71
+				$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
72
+			}
73
+		}
74
+	}
75
+
76
+	/**
77
+	 * @param $p
78
+	 *
79
+	 * @return mixed
80
+	 */
81
+	public function __get($p)
82
+	{
83
+		if (array_key_exists($p, $this->compat['properties']) !== false) {
84
+			if ($this->show_compat_errors) {
85
+				$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
86
+			}
87
+
88
+			return $this->compat['properties'][$p];
89
+		} else {
90
+			if ($this->show_compat_errors) {
91
+				$this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
92
+			}
93
+		}
94
+	}
95
+
96
+	/**
97
+	 * @param string $m
98
+	 * @param array  $a
99
+	 *
100
+	 * @return mixed|void
101
+	 */
102
+	public function __call($m, $a)
103
+	{
104
+		if (method_exists($this->dataProvider, $m)) {
105
+			call_user_func_array(
106
+				array(
107
+				$this->dataProvider,
108
+				$m
109
+				), $a
110
+			);
111
+		} elseif ($this->show_compat_errors) {
112
+			if (array_search($m, $this->compat['methods']) !== false) {
113
+				$this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
114
+			} else {
115
+				$this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
116
+			}
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * List of unsupported properties and methods
122
+	 */
123
+	protected $compat = array(
124
+		'methods'    => array(
125
+			'register_resource',
126
+			'unregister_resource',
127
+			'load_filter',
128
+			'clear_compiled_tpl',
129
+			'clear_config',
130
+			'get_config_vars',
131
+			'config_load',
132
+		),
133
+		'properties' => array(
134
+			'cache_handler_func'            => null,
135
+			'debugging'                     => false,
136
+			'error_reporting'               => null,
137
+			'debugging_ctrl'                => 'NONE',
138
+			'request_vars_order'            => 'EGPCS',
139
+			'request_use_auto_globals'      => true,
140
+			'use_sub_dirs'                  => false,
141
+			'autoload_filters'              => array(),
142
+			'default_template_handler_func' => '',
143
+			'debug_tpl'                     => '',
144
+			'cache_modified_check'          => false,
145
+			'default_modifiers'             => array(),
146
+			'default_resource_type'         => 'file',
147
+			'config_overwrite'              => true,
148
+			'config_booleanize'             => true,
149
+			'config_read_hidden'            => false,
150
+			'config_fix_newlines'           => true,
151
+			'config_class'                  => 'Config_File',
152
+		),
153
+	);
154
+
155
+	/**
156
+	 * Security vars
157
+	 */
158
+	public $security          = false;
159
+	public $trusted_dir       = array();
160
+	public $secure_dir        = array();
161
+	public $php_handling      = SMARTY_PHP_PASSTHRU;
162
+	public $security_settings = array(
163
+		'PHP_HANDLING'    => false,
164
+		'IF_FUNCS'        => array(
165
+			'list',
166
+			'empty',
167
+			'count',
168
+			'sizeof',
169
+			'in_array',
170
+			'is_array',
171
+		),
172
+		'INCLUDE_ANY'     => false,
173
+		'PHP_TAGS'        => false,
174
+		'MODIFIER_FUNCS'  => array(),
175
+		'ALLOW_CONSTANTS' => false,
176
+	);
177
+
178
+	/**
179
+	 * Paths
180
+	 */
181
+	public $template_dir = 'templates';
182
+	public $compile_dir  = 'templates_c';
183
+	public $config_dir   = 'configs';
184
+	public $cache_dir    = 'cache';
185
+	public $plugins_dir  = array();
186
+
187
+	/**
188
+	 * Misc options
189
+	 */
190
+	public $left_delimiter  = '{';
191
+	public $right_delimiter = '}';
192
+	public $compile_check   = true;
193
+	public $force_compile   = false;
194
+	public $caching         = 0;
195
+	public $cache_lifetime  = 3600;
196
+	public $compile_id      = null;
197
+	public $compiler_file   = null;
198
+	public $compiler_class  = null;
199
+
200
+	/**
201
+	 * Dwoo/Smarty compat layer
202
+	 */
203
+	public           $show_compat_errors = false;
204
+	protected        $dataProvider;
205
+	protected        $_filters           = array(
206
+		'pre'    => array(),
207
+		'post'   => array(),
208
+		'output' => array()
209
+	);
210
+	protected static $tplCache           = array();
211
+	protected        $compiler           = null;
212
+
213
+	/**
214
+	 * Adapter constructor.
215
+	 */
216
+	public function __construct()
217
+	{
218
+		parent::__construct();
219
+		$this->charset      = 'iso-8859-1';
220
+		$this->dataProvider = new Data();
221
+		$this->compiler     = new Compiler();
222
+	}
223
+
224
+	/**
225
+	 * @param      $filename
226
+	 * @param null $cacheId
227
+	 * @param null $compileId
228
+	 */
229
+	public function display($filename, $cacheId = null, $compileId = null)
230
+	{
231
+		$this->fetch($filename, $cacheId, $compileId, true);
232
+	}
233
+
234
+	/**
235
+	 * @param      $filename
236
+	 * @param null $cacheId
237
+	 * @param null $compileId
238
+	 * @param bool $display
239
+	 *
240
+	 * @return string|void
241
+	 */
242
+	public function fetch($filename, $cacheId = null, $compileId = null, $display = false)
243
+	{
244
+		$this->setCacheDir($this->cache_dir);
245
+		$this->setCompileDir($this->compile_dir);
246
+
247
+		if ($this->security) {
248
+			$policy = new SecurityPolicy();
249
+			$policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS']));
250
+
251
+			$phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling;
252
+			if ($this->security_settings['PHP_TAGS']) {
253
+				$phpTags = SMARTY_PHP_ALLOW;
254
+			}
255
+			switch ($phpTags) {
256
+			case SMARTY_PHP_ALLOW:
257
+			case SMARTY_PHP_PASSTHRU:
258
+				$phpTags = SecurityPolicy::PHP_ALLOW;
259
+				break;
260
+			case SMARTY_PHP_QUOTE:
261
+				$phpTags = SecurityPolicy::PHP_ENCODE;
262
+				break;
263
+			case SMARTY_PHP_REMOVE:
264
+			default:
265
+				$phpTags = SecurityPolicy::PHP_REMOVE;
266
+				break;
267
+			}
268
+			$policy->setPhpHandling($phpTags);
269
+
270
+			$policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']);
271
+
272
+			if ($this->security_settings['INCLUDE_ANY']) {
273
+				$policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__));
274
+			} else {
275
+				$policy->allowDirectory($this->secure_dir);
276
+			}
277
+
278
+			$this->setSecurityPolicy($policy);
279
+		}
280
+
281
+		if (!empty($this->plugins_dir)) {
282
+			foreach ($this->plugins_dir as $dir) {
283
+				$this->getLoader()->addDirectory(rtrim($dir, '\\/'));
284
+			}
285
+		}
286
+
287
+		$tpl = $this->makeTemplate($filename, $cacheId, $compileId);
288
+		if ($this->force_compile) {
289
+			$tpl->forceCompilation();
290
+		}
291
+
292
+		if ($this->caching > 0) {
293
+			$this->cacheTime = $this->cache_lifetime;
294
+		} else {
295
+			$this->cacheTime = 0;
296
+		}
297
+
298
+		if ($this->compiler_class !== null) {
299
+			if ($this->compiler_file !== null && !class_exists($this->compiler_class)) {
300
+				include $this->compiler_file;
301
+			}
302
+			$this->compiler = new $this->compiler_class();
303
+		} else {
304
+			$this->compiler->addPreProcessor('PluginSmartyCompatible', true);
305
+			$this->compiler->setLooseOpeningHandling(true);
306
+		}
307
+
308
+		$this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter);
309
+
310
+		return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true);
311
+	}
312
+
313
+	/**
314
+	 * @param mixed $_tpl
315
+	 * @param array $data
316
+	 * @param null  $_compiler
317
+	 * @param bool  $_output
318
+	 *
319
+	 * @return string|void
320
+	 */
321
+	public function get($_tpl, $data = array(), $_compiler = null, $_output = false)
322
+	{
323
+		if ($_compiler === null) {
324
+			$_compiler = $this->compiler;
325
+		}
326
+
327
+		return parent::get($_tpl, $data, $_compiler, $_output);
328
+	}
329
+
330
+	/**
331
+	 * @param      $name
332
+	 * @param      $callback
333
+	 * @param bool $cacheable
334
+	 * @param null $cache_attrs
335
+	 *
336
+	 * @throws Exception
337
+	 */
338
+	public function register_function($name, $callback, $cacheable = true, $cache_attrs = null)
339
+	{
340
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) {
341
+			throw new Exception('Multiple plugins of different types can not share the same name');
342
+		}
343
+		$this->plugins[$name] = array(
344
+			'type'     => self::SMARTY_FUNCTION,
345
+			'callback' => $callback
346
+		);
347
+	}
348
+
349
+	/**
350
+	 * @param $name
351
+	 */
352
+	public function unregister_function($name)
353
+	{
354
+		unset($this->plugins[$name]);
355
+	}
356
+
357
+	/**
358
+	 * @param      $name
359
+	 * @param      $callback
360
+	 * @param bool $cacheable
361
+	 * @param null $cache_attrs
362
+	 *
363
+	 * @throws Exception
364
+	 */
365
+	public function register_block($name, $callback, $cacheable = true, $cache_attrs = null)
366
+	{
367
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) {
368
+			throw new Exception('Multiple plugins of different types can not share the same name');
369
+		}
370
+		$this->plugins[$name] = array(
371
+			'type'     => self::SMARTY_BLOCK,
372
+			'callback' => $callback
373
+		);
374
+	}
375
+
376
+	/**
377
+	 * @param $name
378
+	 */
379
+	public function unregister_block($name)
380
+	{
381
+		unset($this->plugins[$name]);
382
+	}
383
+
384
+	/**
385
+	 * @param $name
386
+	 * @param $callback
387
+	 *
388
+	 * @throws Exception
389
+	 */
390
+	public function register_modifier($name, $callback)
391
+	{
392
+		if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) {
393
+			throw new Exception('Multiple plugins of different types can not share the same name');
394
+		}
395
+		$this->plugins[$name] = array(
396
+			'type'     => self::SMARTY_MODIFIER,
397
+			'callback' => $callback
398
+		);
399
+	}
400
+
401
+	/**
402
+	 * @param $name
403
+	 */
404
+	public function unregister_modifier($name)
405
+	{
406
+		unset($this->plugins[$name]);
407
+	}
408
+
409
+	/**
410
+	 * @param $callback
411
+	 */
412
+	public function register_prefilter($callback)
413
+	{
414
+		$processor = new ProcessorAdapter($this->compiler);
415
+		$processor->registerCallback($callback);
416
+		$this->_filters['pre'][] = $processor;
417
+		$this->compiler->addPreProcessor($processor);
418
+	}
419
+
420
+	/**
421
+	 * @param $callback
422
+	 */
423
+	public function unregister_prefilter($callback)
424
+	{
425
+		foreach ($this->_filters['pre'] as $index => $processor) {
426
+			if ($processor->callback === $callback) {
427
+				$this->compiler->removePostProcessor($processor);
428
+				unset($this->_filters['pre'][$index]);
429
+			}
430
+		}
431
+	}
432
+
433
+	/**
434
+	 * @param $callback
435
+	 */
436
+	public function register_postfilter($callback)
437
+	{
438
+		$processor = new ProcessorAdapter($this->compiler);
439
+		$processor->registerCallback($callback);
440
+		$this->_filters['post'][] = $processor;
441
+		$this->compiler->addPostProcessor($processor);
442
+	}
443
+
444
+	/**
445
+	 * @param $callback
446
+	 */
447
+	public function unregister_postfilter($callback)
448
+	{
449
+		foreach ($this->_filters['post'] as $index => $processor) {
450
+			if ($processor->callback === $callback) {
451
+				$this->compiler->removePostProcessor($processor);
452
+				unset($this->_filters['post'][$index]);
453
+			}
454
+		}
455
+	}
456
+
457
+	/**
458
+	 * @param $callback
459
+	 */
460
+	public function register_outputfilter($callback)
461
+	{
462
+		$filter = new FilterAdapter($this);
463
+		$filter->registerCallback($callback);
464
+		$this->_filters['output'][] = $filter;
465
+		$this->addFilter($filter);
466
+	}
467
+
468
+	/**
469
+	 * @param $callback
470
+	 */
471
+	public function unregister_outputfilter($callback)
472
+	{
473
+		foreach ($this->_filters['output'] as $index => $filter) {
474
+			if ($filter->callback === $callback) {
475
+				$this->removeOutputFilter($filter);
476
+				unset($this->_filters['output'][$index]);
477
+			}
478
+		}
479
+	}
480
+
481
+	/**
482
+	 * @param       $object
483
+	 * @param       $object_impl
484
+	 * @param array $allowed
485
+	 * @param bool  $smarty_args
486
+	 * @param array $block_methods
487
+	 */
488
+	public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array())
489
+	{
490
+		settype($allowed, 'array');
491
+		settype($block_methods, 'array');
492
+		settype($smarty_args, 'boolean');
493
+
494
+		if (!empty($allowed) && $this->show_compat_errors) {
495
+			$this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE);
496
+		}
497
+
498
+		if ($smarty_args) {
499
+			$this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE);
500
+		}
501
+
502
+		if (!empty($block_methods)) {
503
+			$this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE);
504
+		}
505
+
506
+		$this->dataProvider->assign($object, $object_impl);
507
+	}
508
+
509
+	/**
510
+	 * @param $object
511
+	 */
512
+	public function unregister_object($object)
513
+	{
514
+		$this->dataProvider->clear($object);
515
+	}
516
+
517
+	/**
518
+	 * @param $name
519
+	 *
520
+	 * @return mixed
521
+	 */
522
+	public function get_registered_object($name)
523
+	{
524
+		$data = $this->dataProvider->getData();
525
+		if (isset($data[$name]) && is_object($data[$name])) {
526
+			return $data[$name];
527
+		} else {
528
+			trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR);
529
+		}
530
+	}
531
+
532
+	/**
533
+	 * @param $filename
534
+	 *
535
+	 * @return bool
536
+	 */
537
+	public function template_exists($filename)
538
+	{
539
+		if (!is_array($this->template_dir)) {
540
+			return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename);
541
+		} else {
542
+			foreach ($this->template_dir as $tpl_dir) {
543
+				if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) {
544
+					return true;
545
+				}
546
+			}
547
+
548
+			return false;
549
+		}
550
+	}
551
+
552
+	/**
553
+	 * @param      $tpl
554
+	 * @param null $cacheId
555
+	 * @param null $compileId
556
+	 *
557
+	 * @return bool
558
+	 */
559
+	public function is_cached($tpl, $cacheId = null, $compileId = null)
560
+	{
561
+		return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId));
562
+	}
563
+
564
+	/**
565
+	 * @param      $var
566
+	 * @param      $value
567
+	 * @param bool $merge
568
+	 */
569
+	public function append_by_ref($var, &$value, $merge = false)
570
+	{
571
+		$this->dataProvider->appendByRef($var, $value, $merge);
572
+	}
573
+
574
+	/**
575
+	 * @param $name
576
+	 * @param $val
577
+	 */
578
+	public function assign_by_ref($name, &$val)
579
+	{
580
+		$this->dataProvider->assignByRef($name, $val);
581
+	}
582
+
583
+	/**
584
+	 * @param $var
585
+	 */
586
+	public function clear_assign($var)
587
+	{
588
+		$this->dataProvider->clear($var);
589
+	}
590
+
591
+	/**
592
+	 *
593
+	 */
594
+	public function clear_all_assign()
595
+	{
596
+		$this->dataProvider->clear();
597
+	}
598
+
599
+	/**
600
+	 * @param null $name
601
+	 *
602
+	 * @return array|null
603
+	 */
604
+	public function get_template_vars($name = null)
605
+	{
606
+		if ($this->show_compat_errors) {
607
+			trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE);
608
+		}
609
+
610
+		$data = $this->dataProvider->getData();
611
+		if ($name === null) {
612
+			return $data;
613
+		} elseif (isset($data[$name])) {
614
+			return $data[$name];
615
+		}
616
+
617
+		return null;
618
+	}
619
+
620
+	/**
621
+	 * @param int $olderThan
622
+	 */
623
+	public function clear_all_cache($olderThan = 0)
624
+	{
625
+		$this->clearCache($olderThan);
626
+	}
627
+
628
+	/**
629
+	 * @param      $template
630
+	 * @param null $cacheId
631
+	 * @param null $compileId
632
+	 * @param int  $olderThan
633
+	 */
634
+	public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0)
635
+	{
636
+		$this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
637
+	}
638
+
639
+	/**
640
+	 * @param     $error_msg
641
+	 * @param int $error_type
642
+	 */
643
+	public function trigger_error($error_msg, $error_type = E_USER_WARNING)
644
+	{
645
+		$this->triggerError($error_msg, $error_type);
646
+	}
647
+
648
+	/**
649
+	 *
650
+	 */
651
+	protected function initGlobals()
652
+	{
653
+		parent::initGlobals();
654
+		$this->globals['ldelim'] = '{';
655
+		$this->globals['rdelim'] = '}';
656
+	}
657
+
658
+	/**
659
+	 * @param $file
660
+	 * @param $cacheId
661
+	 * @param $compileId
662
+	 *
663
+	 * @return mixed
664
+	 * @throws Exception
665
+	 */
666
+	protected function makeTemplate($file, $cacheId, $compileId)
667
+	{
668
+		if ($compileId === null) {
669
+			$compileId = $this->compile_id;
670
+		}
671
+
672
+		$hash = bin2hex(md5($file . $cacheId . $compileId, true));
673
+		if (!isset(self::$tplCache[$hash])) {
674
+			// abs path
675
+			if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
676
+				self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId);
677
+			} elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
678
+				self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir);
679
+			} else {
680
+				throw new Exception('Unable to load "' . $file . '", check the template_dir');
681
+			}
682
+		}
683
+
684
+		return self::$tplCache[$hash];
685
+	}
686
+
687
+	/**
688
+	 * @param string $message
689
+	 * @param int    $level
690
+	 */
691
+	public function triggerError($message, $level = E_USER_NOTICE)
692
+	{
693
+		if (is_object($this->template)) {
694
+			parent::triggerError($message, $level);
695
+		}
696
+		trigger_error('Dwoo error : ' . $message, $level);
697
+	}
698 698
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
         }
64 64
         if (array_key_exists($p, $this->compat['properties']) !== false) {
65 65
             if ($this->show_compat_errors) {
66
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
66
+                $this->triggerError('Property '.$p.' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
67 67
             }
68 68
             $this->compat['properties'][$p] = $v;
69 69
         } else {
70 70
             if ($this->show_compat_errors) {
71
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
71
+                $this->triggerError('Property '.$p.' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
72 72
             }
73 73
         }
74 74
     }
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
     {
83 83
         if (array_key_exists($p, $this->compat['properties']) !== false) {
84 84
             if ($this->show_compat_errors) {
85
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
85
+                $this->triggerError('Property '.$p.' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
86 86
             }
87 87
 
88 88
             return $this->compat['properties'][$p];
89 89
         } else {
90 90
             if ($this->show_compat_errors) {
91
-                $this->triggerError('Property ' . $p . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
91
+                $this->triggerError('Property '.$p.' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
92 92
             }
93 93
         }
94 94
     }
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
             );
111 111
         } elseif ($this->show_compat_errors) {
112 112
             if (array_search($m, $this->compat['methods']) !== false) {
113
-                $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
113
+                $this->triggerError('Method '.$m.' is not available in the Dwoo\Smarty\Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
114 114
             } else {
115
-                $this->triggerError('Method ' . $m . ' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
115
+                $this->triggerError('Method '.$m.' is not available in the Dwoo\Smarty\Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE);
116 116
             }
117 117
         }
118 118
     }
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         if (isset($data[$name]) && is_object($data[$name])) {
526 526
             return $data[$name];
527 527
         } else {
528
-            trigger_error('Dwoo_Compiler: object "' . $name . '" was not registered or is not an object', E_USER_ERROR);
528
+            trigger_error('Dwoo_Compiler: object "'.$name.'" was not registered or is not an object', E_USER_ERROR);
529 529
         }
530 530
     }
531 531
 
@@ -537,10 +537,10 @@  discard block
 block discarded – undo
537 537
     public function template_exists($filename)
538 538
     {
539 539
         if (!is_array($this->template_dir)) {
540
-            return file_exists($this->template_dir . DIRECTORY_SEPARATOR . $filename);
540
+            return file_exists($this->template_dir.DIRECTORY_SEPARATOR.$filename);
541 541
         } else {
542 542
             foreach ($this->template_dir as $tpl_dir) {
543
-                if (file_exists($tpl_dir . DIRECTORY_SEPARATOR . $filename)) {
543
+                if (file_exists($tpl_dir.DIRECTORY_SEPARATOR.$filename)) {
544 544
                     return true;
545 545
                 }
546 546
             }
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
             $compileId = $this->compile_id;
670 670
         }
671 671
 
672
-        $hash = bin2hex(md5($file . $cacheId . $compileId, true));
672
+        $hash = bin2hex(md5($file.$cacheId.$compileId, true));
673 673
         if (!isset(self::$tplCache[$hash])) {
674 674
             // abs path
675 675
             if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') {
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
             } elseif (is_string($this->template_dir) || is_array($this->template_dir)) {
678 678
                 self::$tplCache[$hash] = new TemplateFile($file, null, $cacheId, $compileId, $this->template_dir);
679 679
             } else {
680
-                throw new Exception('Unable to load "' . $file . '", check the template_dir');
680
+                throw new Exception('Unable to load "'.$file.'", check the template_dir');
681 681
             }
682 682
         }
683 683
 
@@ -693,6 +693,6 @@  discard block
 block discarded – undo
693 693
         if (is_object($this->template)) {
694 694
             parent::triggerError($message, $level);
695 695
         }
696
-        trigger_error('Dwoo error : ' . $message, $level);
696
+        trigger_error('Dwoo error : '.$message, $level);
697 697
     }
698 698
 }
Please login to merge, or discard this patch.
lib/Dwoo/Smarty/Filter/Adapter.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,23 +23,23 @@
 block discarded – undo
23 23
  */
24 24
 class Adapter extends Filter
25 25
 {
26
-    public $callback;
26
+	public $callback;
27 27
 
28
-    /**
29
-     * @param string $input
30
-     *
31
-     * @return mixed
32
-     */
33
-    public function process($input)
34
-    {
35
-        return call_user_func($this->callback, $input);
36
-    }
28
+	/**
29
+	 * @param string $input
30
+	 *
31
+	 * @return mixed
32
+	 */
33
+	public function process($input)
34
+	{
35
+		return call_user_func($this->callback, $input);
36
+	}
37 37
 
38
-    /**
39
-     * @param $callback
40
-     */
41
-    public function registerCallback($callback)
42
-    {
43
-        $this->callback = $callback;
44
-    }
38
+	/**
39
+	 * @param $callback
40
+	 */
41
+	public function registerCallback($callback)
42
+	{
43
+		$this->callback = $callback;
44
+	}
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Dwoo/Smarty/Processor/Adapter.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,23 +23,23 @@
 block discarded – undo
23 23
  */
24 24
 class Adapter extends Processor
25 25
 {
26
-    public $callback;
26
+	public $callback;
27 27
 
28
-    /**
29
-     * @param string $input
30
-     *
31
-     * @return mixed
32
-     */
33
-    public function process($input)
34
-    {
35
-        return call_user_func($this->callback, $input);
36
-    }
28
+	/**
29
+	 * @param string $input
30
+	 *
31
+	 * @return mixed
32
+	 */
33
+	public function process($input)
34
+	{
35
+		return call_user_func($this->callback, $input);
36
+	}
37 37
 
38
-    /**
39
-     * @param $callback
40
-     */
41
-    public function registerCallback($callback)
42
-    {
43
-        $this->callback = $callback;
44
-    }
38
+	/**
39
+	 * @param $callback
40
+	 */
41
+	public function registerCallback($callback)
42
+	{
43
+		$this->callback = $callback;
44
+	}
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Dwoo/IPluginProxy.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -23,52 +23,52 @@
 block discarded – undo
23 23
  */
24 24
 interface IPluginProxy
25 25
 {
26
-    /**
27
-     * Returns true or false to say whether the given plugin is handled by this proxy or not.
28
-     *
29
-     * @param string $name the plugin name
30
-     *
31
-     * @return bool true if the plugin is known and usable, otherwise false
32
-     */
33
-    public function handles($name);
26
+	/**
27
+	 * Returns true or false to say whether the given plugin is handled by this proxy or not.
28
+	 *
29
+	 * @param string $name the plugin name
30
+	 *
31
+	 * @return bool true if the plugin is known and usable, otherwise false
32
+	 */
33
+	public function handles($name);
34 34
 
35
-    /**
36
-     * Returns the code (as a string) to call the plugin
37
-     * (this will be executed at runtime inside the Dwoo class).
38
-     *
39
-     * @param string $name   the plugin name
40
-     * @param array  $params a parameter array, array key "*" is the rest array
41
-     *
42
-     * @return string
43
-     */
44
-    public function getCode($name, $params);
35
+	/**
36
+	 * Returns the code (as a string) to call the plugin
37
+	 * (this will be executed at runtime inside the Dwoo class).
38
+	 *
39
+	 * @param string $name   the plugin name
40
+	 * @param array  $params a parameter array, array key "*" is the rest array
41
+	 *
42
+	 * @return string
43
+	 */
44
+	public function getCode($name, $params);
45 45
 
46
-    /**
47
-     * Returns a callback to the plugin, this is used with the reflection API to
48
-     * find out about the plugin's parameter names etc.
49
-     * should you need a rest array without the possibility to edit the
50
-     * plugin's code, you can provide a callback to some
51
-     * other function with the correct parameter signature, i.e. :
52
-     * <code>
53
-     * return array($this, "callbackHelper");
54
-     * // and callbackHelper would be as such:
55
-     * public function callbackHelper(array $rest=array()){}
56
-     * </code>
57
-     *
58
-     * @param string $name the plugin name
59
-     *
60
-     * @return callback
61
-     */
62
-    public function getCallback($name);
46
+	/**
47
+	 * Returns a callback to the plugin, this is used with the reflection API to
48
+	 * find out about the plugin's parameter names etc.
49
+	 * should you need a rest array without the possibility to edit the
50
+	 * plugin's code, you can provide a callback to some
51
+	 * other function with the correct parameter signature, i.e. :
52
+	 * <code>
53
+	 * return array($this, "callbackHelper");
54
+	 * // and callbackHelper would be as such:
55
+	 * public function callbackHelper(array $rest=array()){}
56
+	 * </code>
57
+	 *
58
+	 * @param string $name the plugin name
59
+	 *
60
+	 * @return callback
61
+	 */
62
+	public function getCallback($name);
63 63
 
64
-    /**
65
-     * Returns some code that will check if the plugin is loaded and if not load it
66
-     * this is optional, if your plugins are autoloaded or whatever, just return an
67
-     * empty string.
68
-     *
69
-     * @param string $name the plugin name
70
-     *
71
-     * @return string
72
-     */
73
-    public function getLoader($name);
64
+	/**
65
+	 * Returns some code that will check if the plugin is loaded and if not load it
66
+	 * this is optional, if your plugins are autoloaded or whatever, just return an
67
+	 * empty string.
68
+	 *
69
+	 * @param string $name the plugin name
70
+	 *
71
+	 * @return string
72
+	 */
73
+	public function getLoader($name);
74 74
 }
Please login to merge, or discard this patch.
lib/Dwoo/Filter.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,30 +23,30 @@
 block discarded – undo
23 23
  */
24 24
 abstract class Filter
25 25
 {
26
-    /**
27
-     * The dwoo instance that runs this filter.
28
-     *
29
-     * @var Core
30
-     */
31
-    protected $dwoo;
26
+	/**
27
+	 * The dwoo instance that runs this filter.
28
+	 *
29
+	 * @var Core
30
+	 */
31
+	protected $dwoo;
32 32
 
33
-    /**
34
-     * Constructor, if you override it, call parent::__construct($dwoo); or assign
35
-     * the dwoo instance yourself if you need it.
36
-     *
37
-     * @param Core $dwoo the dwoo instance that runs this plugin
38
-     */
39
-    public function __construct(Core $dwoo)
40
-    {
41
-        $this->dwoo = $dwoo;
42
-    }
33
+	/**
34
+	 * Constructor, if you override it, call parent::__construct($dwoo); or assign
35
+	 * the dwoo instance yourself if you need it.
36
+	 *
37
+	 * @param Core $dwoo the dwoo instance that runs this plugin
38
+	 */
39
+	public function __construct(Core $dwoo)
40
+	{
41
+		$this->dwoo = $dwoo;
42
+	}
43 43
 
44
-    /**
45
-     * Processes the input and returns it filtered.
46
-     *
47
-     * @param string $input the template to process
48
-     *
49
-     * @return string
50
-     */
51
-    abstract public function process($input);
44
+	/**
45
+	 * Processes the input and returns it filtered.
46
+	 *
47
+	 * @param string $input the template to process
48
+	 *
49
+	 * @return string
50
+	 */
51
+	abstract public function process($input);
52 52
 }
Please login to merge, or discard this patch.