@@ -89,7 +89,7 @@ |
||
89 | 89 | * |
90 | 90 | * @param string $sTemplate |
91 | 91 | * @param boolean $return |
92 | - * @return mixed |
|
92 | + * @return null|string |
|
93 | 93 | */ |
94 | 94 | public function display($sTemplate, $return = FALSE) { |
95 | 95 | // Start benchmark |
@@ -20,153 +20,153 @@ |
||
20 | 20 | * @uses the dwoo package from http://dwoo.org |
21 | 21 | */ |
22 | 22 | class Dwootemplate extends Dwoo_Core { |
23 | - protected $dwoo_data = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * Constructor for the DwooTemplate engine |
|
27 | - * |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - // Call parents constructor |
|
31 | - parent::__construct(); |
|
32 | - |
|
33 | - // Set the config settings |
|
34 | - $this->initialize(); |
|
35 | - |
|
36 | - // Assign some defaults to dwoo |
|
37 | - $CI = get_instance(); |
|
38 | - $this->dwoo_data = new Dwoo_Data(); |
|
39 | - $this->dwoo_data->js_files = array(); |
|
40 | - $this->dwoo_data->css_files = array(); |
|
41 | - $this->dwoo_data->CI = $CI; |
|
42 | - $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
43 | - $this->dwoo_data->uniqid = uniqid(); |
|
44 | - $this->dwoo_data->timestamp = mktime(); |
|
45 | - |
|
46 | - log_message('debug', "Dwoo Template Class Initialized"); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Assign data to dwoo data object |
|
52 | - * |
|
53 | - * @param string $key |
|
54 | - * @param mixed $value |
|
55 | - */ |
|
56 | - public function assign($key, $value) { |
|
57 | - $this->dwoo_data->$key = $value; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * Add Javascript files to template |
|
63 | - * |
|
64 | - * @param string $js |
|
65 | - */ |
|
66 | - public function add_js($js) { |
|
67 | - $current = $this->dwoo_data->js_files; |
|
68 | - $current[] = $js; |
|
69 | - $this->dwoo_data->js_files = $current; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Add Css stylesheets to template |
|
75 | - * |
|
76 | - * @param string $css |
|
77 | - */ |
|
78 | - public function add_css($css) { |
|
79 | - $current = $this->dwoo_data->css_files; |
|
80 | - $current[] = $css; |
|
81 | - $this->dwoo_data->css_files = $current; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Display or return the compiled template |
|
87 | - * Since we assign the results to the standard CI output module |
|
88 | - * you can also use the helper from CI in your templates!! |
|
89 | - * |
|
90 | - * @param string $sTemplate |
|
91 | - * @param boolean $return |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - public function display($sTemplate, $return = FALSE) { |
|
95 | - // Start benchmark |
|
96 | - $CI = get_instance(); |
|
97 | - $CI->benchmark->mark('dwoo_parse_start'); |
|
98 | - |
|
99 | - // Check if file exists |
|
100 | - if ( !file_exists($this->template_dir . $sTemplate ) ) { |
|
101 | - $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
102 | - show_error($message); |
|
103 | - log_message('error', $message); |
|
104 | - } |
|
105 | - |
|
106 | - // Create new template |
|
107 | - $tpl = new Dwoo_Template_File($this->template_dir . $sTemplate); |
|
108 | - |
|
109 | - // render the template |
|
110 | - $template = $this->get($tpl, $this->dwoo_data); |
|
111 | - |
|
112 | - // Finish benchmark |
|
113 | - $CI->benchmark->mark('dwoo_parse_end'); |
|
114 | - |
|
115 | - // Return results or not ? |
|
116 | - if ($return == FALSE) { |
|
117 | - $CI->output->final_output = $template; |
|
118 | - } else { |
|
119 | - return $template; |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Toggle Codeigniter profiler on/off |
|
126 | - * |
|
127 | - */ |
|
128 | - public function enable_profiler($toggle = TRUE) { |
|
129 | - $CI = get_instance(); |
|
130 | - $CI->output->enable_profiler($toggle); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Set http header |
|
136 | - * |
|
137 | - * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
138 | - * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
139 | - * @param string $header |
|
140 | - */ |
|
141 | - public function set_header($header) { |
|
142 | - $CI = get_instance(); |
|
143 | - $CI->output->set_header($header); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Set status header |
|
149 | - * |
|
150 | - * @example $this->output->set_status_header('401'); |
|
151 | - * @example // Sets the header as: Unauthorized |
|
152 | - * @param string $header |
|
153 | - */ |
|
154 | - public function set_status_header($header) { |
|
155 | - $CI = get_instance(); |
|
156 | - $CI->output->set_status_header($header); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Assign the dwootemplate config items to the instance |
|
162 | - * |
|
163 | - */ |
|
164 | - private function initialize() { |
|
165 | - $CI = get_instance(); |
|
166 | - $CI->config->load('dwootemplate', TRUE); |
|
167 | - $config = $CI->config->item('dwootemplate'); |
|
168 | - foreach ($config as $key => $val) { |
|
169 | - $this->$key = $val; |
|
170 | - } |
|
171 | - } |
|
23 | + protected $dwoo_data = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * Constructor for the DwooTemplate engine |
|
27 | + * |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + // Call parents constructor |
|
31 | + parent::__construct(); |
|
32 | + |
|
33 | + // Set the config settings |
|
34 | + $this->initialize(); |
|
35 | + |
|
36 | + // Assign some defaults to dwoo |
|
37 | + $CI = get_instance(); |
|
38 | + $this->dwoo_data = new Dwoo_Data(); |
|
39 | + $this->dwoo_data->js_files = array(); |
|
40 | + $this->dwoo_data->css_files = array(); |
|
41 | + $this->dwoo_data->CI = $CI; |
|
42 | + $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
43 | + $this->dwoo_data->uniqid = uniqid(); |
|
44 | + $this->dwoo_data->timestamp = mktime(); |
|
45 | + |
|
46 | + log_message('debug', "Dwoo Template Class Initialized"); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Assign data to dwoo data object |
|
52 | + * |
|
53 | + * @param string $key |
|
54 | + * @param mixed $value |
|
55 | + */ |
|
56 | + public function assign($key, $value) { |
|
57 | + $this->dwoo_data->$key = $value; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * Add Javascript files to template |
|
63 | + * |
|
64 | + * @param string $js |
|
65 | + */ |
|
66 | + public function add_js($js) { |
|
67 | + $current = $this->dwoo_data->js_files; |
|
68 | + $current[] = $js; |
|
69 | + $this->dwoo_data->js_files = $current; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Add Css stylesheets to template |
|
75 | + * |
|
76 | + * @param string $css |
|
77 | + */ |
|
78 | + public function add_css($css) { |
|
79 | + $current = $this->dwoo_data->css_files; |
|
80 | + $current[] = $css; |
|
81 | + $this->dwoo_data->css_files = $current; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Display or return the compiled template |
|
87 | + * Since we assign the results to the standard CI output module |
|
88 | + * you can also use the helper from CI in your templates!! |
|
89 | + * |
|
90 | + * @param string $sTemplate |
|
91 | + * @param boolean $return |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + public function display($sTemplate, $return = FALSE) { |
|
95 | + // Start benchmark |
|
96 | + $CI = get_instance(); |
|
97 | + $CI->benchmark->mark('dwoo_parse_start'); |
|
98 | + |
|
99 | + // Check if file exists |
|
100 | + if ( !file_exists($this->template_dir . $sTemplate ) ) { |
|
101 | + $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
102 | + show_error($message); |
|
103 | + log_message('error', $message); |
|
104 | + } |
|
105 | + |
|
106 | + // Create new template |
|
107 | + $tpl = new Dwoo_Template_File($this->template_dir . $sTemplate); |
|
108 | + |
|
109 | + // render the template |
|
110 | + $template = $this->get($tpl, $this->dwoo_data); |
|
111 | + |
|
112 | + // Finish benchmark |
|
113 | + $CI->benchmark->mark('dwoo_parse_end'); |
|
114 | + |
|
115 | + // Return results or not ? |
|
116 | + if ($return == FALSE) { |
|
117 | + $CI->output->final_output = $template; |
|
118 | + } else { |
|
119 | + return $template; |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Toggle Codeigniter profiler on/off |
|
126 | + * |
|
127 | + */ |
|
128 | + public function enable_profiler($toggle = TRUE) { |
|
129 | + $CI = get_instance(); |
|
130 | + $CI->output->enable_profiler($toggle); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Set http header |
|
136 | + * |
|
137 | + * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
138 | + * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
139 | + * @param string $header |
|
140 | + */ |
|
141 | + public function set_header($header) { |
|
142 | + $CI = get_instance(); |
|
143 | + $CI->output->set_header($header); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Set status header |
|
149 | + * |
|
150 | + * @example $this->output->set_status_header('401'); |
|
151 | + * @example // Sets the header as: Unauthorized |
|
152 | + * @param string $header |
|
153 | + */ |
|
154 | + public function set_status_header($header) { |
|
155 | + $CI = get_instance(); |
|
156 | + $CI->output->set_status_header($header); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Assign the dwootemplate config items to the instance |
|
162 | + * |
|
163 | + */ |
|
164 | + private function initialize() { |
|
165 | + $CI = get_instance(); |
|
166 | + $CI->config->load('dwootemplate', TRUE); |
|
167 | + $config = $CI->config->item('dwootemplate'); |
|
168 | + foreach ($config as $key => $val) { |
|
169 | + $this->$key = $val; |
|
170 | + } |
|
171 | + } |
|
172 | 172 | } |
173 | 173 | \ No newline at end of file |
@@ -97,14 +97,14 @@ |
||
97 | 97 | $CI->benchmark->mark('dwoo_parse_start'); |
98 | 98 | |
99 | 99 | // Check if file exists |
100 | - if ( !file_exists($this->template_dir . $sTemplate ) ) { |
|
100 | + if (!file_exists($this->template_dir.$sTemplate)) { |
|
101 | 101 | $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
102 | 102 | show_error($message); |
103 | 103 | log_message('error', $message); |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Create new template |
107 | - $tpl = new Dwoo_Template_File($this->template_dir . $sTemplate); |
|
107 | + $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
108 | 108 | |
109 | 109 | // render the template |
110 | 110 | $template = $this->get($tpl, $this->dwoo_data); |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('BASEPATH')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | |
3 | 5 | require "dwoo/dwooAutoload.php"; |
4 | 6 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | /** |
29 | 29 | * Dwoo_Adapters_ZendFramework_PluginProxy's constructor. |
30 | 30 | * |
31 | - * @param Zend_View_Interface $view |
|
31 | + * @param Dwoo_Adapters_ZendFramework_View $view |
|
32 | 32 | */ |
33 | 33 | public function __construct(Zend_View_Interface $view) { |
34 | 34 | $this->view = $view; |
@@ -59,7 +59,7 @@ |
||
59 | 59 | * @return string |
60 | 60 | */ |
61 | 61 | public function getCode($name, $params) { |
62 | - return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($params).')'; |
|
62 | + return '$this->getPluginProxy()->view->'.$name.'('.Dwoo_Compiler::implode_r($params).')'; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -87,7 +87,6 @@ discard block |
||
87 | 87 | * - type class name or object for engine, dataProvider or compiler |
88 | 88 | * - any set* method (compileDir for setCompileDir ...) |
89 | 89 | * |
90 | - * @param array $options |
|
91 | 90 | * @return Dwoo_Adapters_ZendFramework_View |
92 | 91 | */ |
93 | 92 | public function setOptions(array $opt = array()) |
@@ -272,6 +271,7 @@ discard block |
||
272 | 271 | * Sets Dwoo data object |
273 | 272 | * |
274 | 273 | * @param string|Dwoo_Data Object or name of the class |
274 | + * @param Dwoo_Data $data |
|
275 | 275 | */ |
276 | 276 | public function setDataProvider($data) |
277 | 277 | { |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | /** |
330 | 330 | * Return the Dwoo compiler object |
331 | 331 | * |
332 | - * @return Dwoo_Data |
|
332 | + * @return Dwoo_Compiler |
|
333 | 333 | */ |
334 | 334 | public function getCompiler() |
335 | 335 | { |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * Clears all variables assigned to Zend_View either via {@link assign()} or |
405 | 405 | * property overloading ({@link __get()}/{@link __set()}). |
406 | 406 | * |
407 | - * @return void |
|
407 | + * @return Dwoo_Adapters_ZendFramework_View |
|
408 | 408 | * @return Dwoo_Adapters_ZendFramework_View |
409 | 409 | */ |
410 | 410 | public function clearVars() |
@@ -431,7 +431,6 @@ discard block |
||
431 | 431 | * Processes a view script and outputs it. Output is then |
432 | 432 | * passed through filters. |
433 | 433 | * |
434 | - * @param string $name The script script name to process. |
|
435 | 434 | * @return string The script output. |
436 | 435 | */ |
437 | 436 | public function _run() |
@@ -97,26 +97,26 @@ discard block |
||
97 | 97 | |
98 | 98 | // Setting options to Dwoo objects... |
99 | 99 | foreach ($opt as $type => $settings) { |
100 | - if (!method_exists($this, 'set' . $type)) { |
|
100 | + if (!method_exists($this, 'set'.$type)) { |
|
101 | 101 | throw new Dwoo_Exception("Unknown type $type"); |
102 | 102 | } |
103 | 103 | |
104 | 104 | if (is_string($settings) || is_object($settings)) { |
105 | - call_user_func(array($this, 'set' . $type), $settings); |
|
105 | + call_user_func(array($this, 'set'.$type), $settings); |
|
106 | 106 | } elseif (is_array($settings)) { |
107 | 107 | // Set requested class |
108 | 108 | if (array_key_exists('type', $settings)) { |
109 | - call_user_func(array($this, 'set' . $type), $settings['type']); |
|
109 | + call_user_func(array($this, 'set'.$type), $settings['type']); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | if (in_array($type, $classes)) { |
113 | 113 | // Call get so that the class is initialized |
114 | - $rel = call_user_func(array($this, 'get' . $type)); |
|
114 | + $rel = call_user_func(array($this, 'get'.$type)); |
|
115 | 115 | |
116 | 116 | // Call set*() methods so that all the settings are set. |
117 | 117 | foreach ($settings as $method => $value) { |
118 | - if (method_exists($rel, 'set' . $method)) { |
|
119 | - call_user_func(array($rel, 'set' . $method), $value); |
|
118 | + if (method_exists($rel, 'set'.$method)) { |
|
119 | + call_user_func(array($rel, 'set'.$method), $value); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } elseif ('templateFile' == $type) { |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | foreach ($this->_templateFileSettings as $method => $value) { |
359 | - if (method_exists($dwooTemplateFile, 'set' . $method)) { |
|
360 | - call_user_func(array($dwooTemplateFile, 'set' . $method), $value); |
|
359 | + if (method_exists($dwooTemplateFile, 'set'.$method)) { |
|
360 | + call_user_func(array($dwooTemplateFile, 'set'.$method), $value); |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 |
@@ -248,8 +248,7 @@ discard block |
||
248 | 248 | // |
249 | 249 | elseif (is_subclass_of($engine, 'Dwoo') || 'Dwoo' === $engine) { |
250 | 250 | $this->_engine = new $engine(); |
251 | - } |
|
252 | - else { |
|
251 | + } else { |
|
253 | 252 | throw new Dwoo_Exception("Custom engine must be a subclass of Dwoo"); |
254 | 253 | } |
255 | 254 | } |
@@ -277,11 +276,9 @@ discard block |
||
277 | 276 | { |
278 | 277 | if ($data instanceof Dwoo_IDataProvider) { |
279 | 278 | $this->_dataProvider = $data; |
280 | - } |
|
281 | - elseif (is_subclass_of($data, 'Dwoo_Data') || 'Dwoo_Data' == $data) { |
|
279 | + } elseif (is_subclass_of($data, 'Dwoo_Data') || 'Dwoo_Data' == $data) { |
|
282 | 280 | $this->_dataProvider = new $data(); |
283 | - } |
|
284 | - else { |
|
281 | + } else { |
|
285 | 282 | throw new Dwoo_Exception("Custom data provider must be a subclass of Dwoo_Data or instance of Dwoo_IDataProvider"); |
286 | 283 | } |
287 | 284 | } |
@@ -320,8 +317,7 @@ discard block |
||
320 | 317 | // if param given as a string |
321 | 318 | elseif (is_subclass_of($compiler, 'Dwoo_Compiler') || 'Dwoo_Compiler' == $compiler) { |
322 | 319 | $this->_compiler = new $compiler; |
323 | - } |
|
324 | - else { |
|
320 | + } else { |
|
325 | 321 | throw new Dwoo_Exception("Custom compiler must be a subclass of Dwoo_Compiler or instance of Dwoo_ICompiler"); |
326 | 322 | } |
327 | 323 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** |
271 | 271 | * returns the left and right template delimiters |
272 | 272 | * |
273 | - * @return array containing the left and the right delimiters |
|
273 | + * @return string[] containing the left and the right delimiters |
|
274 | 274 | */ |
275 | 275 | public function getDelimiters() |
276 | 276 | { |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * adds a preprocessor to the compiler, it will be called |
359 | 359 | * before the template is compiled |
360 | 360 | * |
361 | - * @param mixed $callback either a valid callback to the preprocessor or a simple name if the autoload is set to true |
|
361 | + * @param string $callback either a valid callback to the preprocessor or a simple name if the autoload is set to true |
|
362 | 362 | * @param bool $autoload if set to true, the preprocessor is auto-loaded from one of the plugin directories, else you must provide a valid callback |
363 | 363 | */ |
364 | 364 | public function addPreProcessor($callback, $autoload = false) |
@@ -685,7 +685,6 @@ discard block |
||
685 | 685 | /** |
686 | 686 | * compiles the provided string down to php code |
687 | 687 | * |
688 | - * @param string $tpl the template to compile |
|
689 | 688 | * @return string a compiled php string |
690 | 689 | */ |
691 | 690 | public function compile(Dwoo_Core $dwoo, Dwoo_ITemplate $template) |
@@ -1215,7 +1214,7 @@ discard block |
||
1215 | 1214 | * returns the token of each parameter out of the given parameter array |
1216 | 1215 | * |
1217 | 1216 | * @param array $params parameter array |
1218 | - * @return array tokens |
|
1217 | + * @return Dwoo_Compiler tokens |
|
1219 | 1218 | */ |
1220 | 1219 | public function getParamTokens(array $params) |
1221 | 1220 | { |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | } elseif (($index = array_search('Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback), $this->processors['pre'], true)) !== false) { |
394 | 394 | unset($this->processors['pre'][$index]); |
395 | 395 | } else { |
396 | - $class = 'Dwoo_Processor_' . str_replace('Dwoo_Processor_', '', $callback); |
|
396 | + $class = 'Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback); |
|
397 | 397 | foreach ($this->processors['pre'] as $index=>$proc) { |
398 | 398 | if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) { |
399 | 399 | unset($this->processors['pre'][$index]); |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | unset($this->processors['post'][$index]); |
442 | 442 | } elseif (($index = array_search('Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback), $this->processors['post'], true)) !== false) { |
443 | 443 | unset($this->processors['post'][$index]); |
444 | - } else { |
|
445 | - $class = 'Dwoo_Processor_' . str_replace('Dwoo_Processor_', '', $callback); |
|
444 | + } else { |
|
445 | + $class = 'Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback); |
|
446 | 446 | foreach ($this->processors['post'] as $index=>$proc) { |
447 | 447 | if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) { |
448 | 448 | unset($this->processors['post'][$index]); |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | public function setTemplateSource($newSource, $fromPointer = false) |
649 | 649 | { |
650 | 650 | if ($fromPointer === true) { |
651 | - $this->templateSource = substr($this->templateSource, 0, $this->pointer) . $newSource; |
|
651 | + $this->templateSource = substr($this->templateSource, 0, $this->pointer).$newSource; |
|
652 | 652 | } else { |
653 | 653 | $this->templateSource = $newSource; |
654 | 654 | } |
@@ -695,16 +695,16 @@ discard block |
||
695 | 695 | $ptr = 0; |
696 | 696 | $this->dwoo = $dwoo; |
697 | 697 | $this->template = $template; |
698 | - $this->templateSource =& $tpl; |
|
699 | - $this->pointer =& $ptr; |
|
698 | + $this->templateSource = & $tpl; |
|
699 | + $this->pointer = & $ptr; |
|
700 | 700 | |
701 | 701 | while (true) { |
702 | 702 | // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed |
703 | - if ($ptr===0) { |
|
703 | + if ($ptr === 0) { |
|
704 | 704 | // resets variables |
705 | 705 | $this->usedPlugins = array(); |
706 | 706 | $this->data = array(); |
707 | - $this->scope =& $this->data; |
|
707 | + $this->scope = & $this->data; |
|
708 | 708 | $this->scopeTree = array(); |
709 | 709 | $this->stack = array(); |
710 | 710 | $this->line = 1; |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | if (ini_get('short_open_tags')) { |
740 | 740 | $search = array('{<\?.*?\?>}', '{<%.*?%>}'); |
741 | 741 | } |
742 | - switch($this->securityPolicy->getPhpHandling()) { |
|
742 | + switch ($this->securityPolicy->getPhpHandling()) { |
|
743 | 743 | |
744 | 744 | case Dwoo_Security_Policy::PHP_ALLOW: |
745 | 745 | break; |
@@ -759,14 +759,14 @@ discard block |
||
759 | 759 | $this->push(substr($tpl, $ptr), 0); |
760 | 760 | break; |
761 | 761 | } elseif (substr($tpl, $pos-1, 1) === '\\' && substr($tpl, $pos-2, 1) !== '\\') { |
762 | - $this->push(substr($tpl, $ptr, $pos-$ptr-1) . $this->ld); |
|
762 | + $this->push(substr($tpl, $ptr, $pos-$ptr-1).$this->ld); |
|
763 | 763 | $ptr = $pos+strlen($this->ld); |
764 | - } elseif (preg_match('/^'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', substr($tpl, $pos), $litOpen)) { |
|
765 | - if (!preg_match('/'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) { |
|
764 | + } elseif (preg_match('/^'.$this->ldr.($this->allowLooseOpenings ? '\s*' : '').'literal'.($this->allowLooseOpenings ? '\s*' : '').$this->rdr.'/s', substr($tpl, $pos), $litOpen)) { |
|
765 | + if (!preg_match('/'.$this->ldr.($this->allowLooseOpenings ? '\s*' : '').'\/literal'.($this->allowLooseOpenings ? '\s*' : '').$this->rdr.'/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) { |
|
766 | 766 | throw new Dwoo_Compilation_Exception($this, 'The {literal} blocks must be closed explicitly with {/literal}'); |
767 | 767 | } |
768 | 768 | $endpos = $litClose[0][1]; |
769 | - $this->push(substr($tpl, $ptr, $pos-$ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos-$pos-strlen($litOpen[0]))); |
|
769 | + $this->push(substr($tpl, $ptr, $pos-$ptr).substr($tpl, $pos+strlen($litOpen[0]), $endpos-$pos-strlen($litOpen[0]))); |
|
770 | 770 | $ptr = $endpos+strlen($litClose[0][0]); |
771 | 771 | } else { |
772 | 772 | if (substr($tpl, $pos-2, 1) === '\\' && substr($tpl, $pos-1, 1) === '\\') { |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | $pos += strlen($this->ld); |
781 | 781 | if ($this->allowLooseOpenings) { |
782 | 782 | while (substr($tpl, $pos, 1) === ' ') { |
783 | - $pos+=1; |
|
783 | + $pos += 1; |
|
784 | 784 | } |
785 | 785 | } else { |
786 | 786 | if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") { |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | continue 2; |
808 | 808 | } |
809 | 809 | |
810 | - $len = $subptr - $ptr; |
|
810 | + $len = $subptr-$ptr; |
|
811 | 811 | $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n")); |
812 | 812 | $ptr += $len; |
813 | 813 | |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | continue; |
845 | 845 | } |
846 | 846 | |
847 | - switch($type) { |
|
847 | + switch ($type) { |
|
848 | 848 | |
849 | 849 | case Dwoo_Core::BLOCK_PLUGIN: |
850 | 850 | case Dwoo_Core::CLASS_PLUGIN: |
@@ -884,15 +884,15 @@ discard block |
||
884 | 884 | |
885 | 885 | $output .= $compiled."\n?>"; |
886 | 886 | |
887 | - $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output); |
|
888 | - $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output); |
|
887 | + $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/').preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output); |
|
888 | + $output = str_replace(self::PHP_CLOSE.self::PHP_OPEN, "\n", $output); |
|
889 | 889 | |
890 | 890 | // handle <?xml tag at the beginning |
891 | 891 | $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output); |
892 | 892 | |
893 | 893 | // add another line break after PHP closing tags that have a line break following, |
894 | 894 | // as we do not know whether it's intended, and PHP will strip it otherwise |
895 | - $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0' . "\n", $output); |
|
895 | + $output = preg_replace('/(?<!"|<\?xml)\s*\?>\n/', '$0'."\n", $output); |
|
896 | 896 | |
897 | 897 | if ($this->debug) { |
898 | 898 | echo '<hr><pre>'; |
@@ -967,17 +967,17 @@ discard block |
||
967 | 967 | { |
968 | 968 | $old = $this->scopeTree; |
969 | 969 | |
970 | - if ($scope===null) { |
|
970 | + if ($scope === null) { |
|
971 | 971 | unset($this->scope); |
972 | 972 | $this->scope = null; |
973 | 973 | } |
974 | 974 | |
975 | - if (is_array($scope)===false) { |
|
975 | + if (is_array($scope) === false) { |
|
976 | 976 | $scope = explode('.', $scope); |
977 | 977 | } |
978 | 978 | |
979 | - if ($absolute===true) { |
|
980 | - $this->scope =& $this->data; |
|
979 | + if ($absolute === true) { |
|
980 | + $this->scope = & $this->data; |
|
981 | 981 | $this->scopeTree = array(); |
982 | 982 | } |
983 | 983 | |
@@ -985,19 +985,19 @@ discard block |
||
985 | 985 | if ($bit === '_parent' || $bit === '_') { |
986 | 986 | array_pop($this->scopeTree); |
987 | 987 | reset($this->scopeTree); |
988 | - $this->scope =& $this->data; |
|
988 | + $this->scope = & $this->data; |
|
989 | 989 | $cnt = count($this->scopeTree); |
990 | - for ($i=0;$i<$cnt;$i++) |
|
991 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
990 | + for ($i = 0; $i < $cnt; $i++) |
|
991 | + $this->scope = & $this->scope[$this->scopeTree[$i]]; |
|
992 | 992 | } elseif ($bit === '_root' || $bit === '__') { |
993 | - $this->scope =& $this->data; |
|
993 | + $this->scope = & $this->data; |
|
994 | 994 | $this->scopeTree = array(); |
995 | 995 | } elseif (isset($this->scope[$bit])) { |
996 | - $this->scope =& $this->scope[$bit]; |
|
996 | + $this->scope = & $this->scope[$bit]; |
|
997 | 997 | $this->scopeTree[] = $bit; |
998 | 998 | } else { |
999 | 999 | $this->scope[$bit] = array(); |
1000 | - $this->scope =& $this->scope[$bit]; |
|
1000 | + $this->scope = & $this->scope[$bit]; |
|
1001 | 1001 | $this->scopeTree[] = $bit; |
1002 | 1002 | } |
1003 | 1003 | } |
@@ -1023,8 +1023,8 @@ discard block |
||
1023 | 1023 | $params = $this->mapParams($params, array($class, 'init'), $paramtype); |
1024 | 1024 | |
1025 | 1025 | $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); |
1026 | - $this->curBlock =& $this->stack[count($this->stack)-1]; |
|
1027 | - return call_user_func(array($class,'preProcessing'), $this, $params, '', '', $type); |
|
1026 | + $this->curBlock = & $this->stack[count($this->stack)-1]; |
|
1027 | + return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | /** |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | $params = $this->mapParams($params, array($class, 'init'), $paramtype); |
1048 | 1048 | |
1049 | 1049 | $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => true, 'class' => $class, 'buffer' => null); |
1050 | - $this->curBlock =& $this->stack[count($this->stack)-1]; |
|
1051 | - return call_user_func(array($class,'preProcessing'), $this, $params, '', '', $type); |
|
1050 | + $this->curBlock = & $this->stack[count($this->stack)-1]; |
|
1051 | + return call_user_func(array($class, 'preProcessing'), $this, $params, '', '', $type); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | $this->dwoo->getLoader()->loadPlugin($type); |
1067 | 1067 | } |
1068 | 1068 | $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); |
1069 | - $this->curBlock =& $this->stack[count($this->stack)-1]; |
|
1069 | + $this->curBlock = & $this->stack[count($this->stack)-1]; |
|
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | /** |
@@ -1092,11 +1092,11 @@ discard block |
||
1092 | 1092 | $class = 'Dwoo_Plugin_'.$top['type']; |
1093 | 1093 | } |
1094 | 1094 | if (count($this->stack)) { |
1095 | - $this->curBlock =& $this->stack[count($this->stack)-1]; |
|
1095 | + $this->curBlock = & $this->stack[count($this->stack)-1]; |
|
1096 | 1096 | $this->push(call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']), 0); |
1097 | 1097 | } else { |
1098 | 1098 | $null = null; |
1099 | - $this->curBlock =& $null; |
|
1099 | + $this->curBlock = & $null; |
|
1100 | 1100 | $output = call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']); |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1126,9 +1126,9 @@ discard block |
||
1126 | 1126 | */ |
1127 | 1127 | public function &findBlock($type, $closeAlong = false) |
1128 | 1128 | { |
1129 | - if ($closeAlong===true) { |
|
1129 | + if ($closeAlong === true) { |
|
1130 | 1130 | while ($b = end($this->stack)) { |
1131 | - if ($b['type']===$type) { |
|
1131 | + if ($b['type'] === $type) { |
|
1132 | 1132 | return $this->stack[key($this->stack)]; |
1133 | 1133 | } |
1134 | 1134 | $this->push($this->removeTopBlock(), 0); |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | } else { |
1137 | 1137 | end($this->stack); |
1138 | 1138 | while ($b = current($this->stack)) { |
1139 | - if ($b['type']===$type) { |
|
1139 | + if ($b['type'] === $type) { |
|
1140 | 1140 | return $this->stack[key($this->stack)]; |
1141 | 1141 | } |
1142 | 1142 | prev($this->stack); |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | $class = 'Dwoo_Plugin_'.$o['type']; |
1175 | 1175 | } |
1176 | 1176 | |
1177 | - $this->curBlock =& $this->stack[count($this->stack)-1]; |
|
1177 | + $this->curBlock = & $this->stack[count($this->stack)-1]; |
|
1178 | 1178 | |
1179 | 1179 | return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']); |
1180 | 1180 | } |
@@ -1238,7 +1238,7 @@ discard block |
||
1238 | 1238 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
1239 | 1239 | * @return string parsed values |
1240 | 1240 | */ |
1241 | - protected function parse($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
1241 | + protected function parse($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
1242 | 1242 | { |
1243 | 1243 | if ($to === null) { |
1244 | 1244 | $to = strlen($in); |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | throw new Dwoo_Compilation_Exception($this, 'Unexpected EOF, a template tag was not closed'); |
1250 | 1250 | } |
1251 | 1251 | |
1252 | - while ($first===" " || $first==="\n" || $first==="\t" || $first==="\r") { |
|
1252 | + while ($first === " " || $first === "\n" || $first === "\t" || $first === "\r") { |
|
1253 | 1253 | if ($curBlock === 'root' && substr($in, $from, strlen($this->rd)) === $this->rd) { |
1254 | 1254 | // end template tag |
1255 | 1255 | $pointer += strlen($this->rd); |
@@ -1272,12 +1272,12 @@ discard block |
||
1272 | 1272 | |
1273 | 1273 | $substr = substr($in, $from, $to-$from); |
1274 | 1274 | |
1275 | - if ($this->debug) echo '<br />PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer.'<br/>'; |
|
1275 | + if ($this->debug) echo '<br />PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...' : '').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer.'<br/>'; |
|
1276 | 1276 | $parsed = ""; |
1277 | 1277 | |
1278 | 1278 | if ($curBlock === 'root' && $first === '*') { |
1279 | 1279 | $src = $this->getTemplateSource(); |
1280 | - $startpos = $this->getPointer() - strlen($this->ld); |
|
1280 | + $startpos = $this->getPointer()-strlen($this->ld); |
|
1281 | 1281 | if (substr($src, $startpos, strlen($this->ld)) === $this->ld) { |
1282 | 1282 | if ($startpos > 0) { |
1283 | 1283 | do { |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | if (!isset($whitespaceStart)) { |
1294 | 1294 | $startpos = $this->getPointer(); |
1295 | 1295 | } else { |
1296 | - $pointer -= $this->getPointer() - $startpos; |
|
1296 | + $pointer -= $this->getPointer()-$startpos; |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | if ($this->allowNestedComments && strpos($src, $this->ld.'*', $this->getPointer()) !== false) { |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | $comClose = '*'.$this->rd; |
1302 | 1302 | $level = 1; |
1303 | 1303 | $start = $startpos; |
1304 | - $ptr = $this->getPointer() + '*'; |
|
1304 | + $ptr = $this->getPointer()+'*'; |
|
1305 | 1305 | |
1306 | 1306 | while ($level > 0 && $ptr < strlen($src)) { |
1307 | 1307 | $open = strpos($src, $comOpen, $ptr); |
@@ -1309,49 +1309,49 @@ discard block |
||
1309 | 1309 | |
1310 | 1310 | if ($open !== false && $close !== false) { |
1311 | 1311 | if ($open < $close) { |
1312 | - $ptr = $open + strlen($comOpen); |
|
1312 | + $ptr = $open+strlen($comOpen); |
|
1313 | 1313 | $level++; |
1314 | 1314 | } else { |
1315 | - $ptr = $close + strlen($comClose); |
|
1315 | + $ptr = $close+strlen($comClose); |
|
1316 | 1316 | $level--; |
1317 | 1317 | } |
1318 | 1318 | } elseif ($open !== false) { |
1319 | - $ptr = $open + strlen($comOpen); |
|
1319 | + $ptr = $open+strlen($comOpen); |
|
1320 | 1320 | $level++; |
1321 | 1321 | } elseif ($close !== false) { |
1322 | - $ptr = $close + strlen($comClose); |
|
1322 | + $ptr = $close+strlen($comClose); |
|
1323 | 1323 | $level--; |
1324 | 1324 | } else { |
1325 | 1325 | $ptr = strlen($src); |
1326 | 1326 | } |
1327 | 1327 | } |
1328 | - $endpos = $ptr - strlen('*'.$this->rd); |
|
1328 | + $endpos = $ptr-strlen('*'.$this->rd); |
|
1329 | 1329 | } else { |
1330 | 1330 | $endpos = strpos($src, '*'.$this->rd, $startpos); |
1331 | 1331 | if ($endpos == false) { |
1332 | 1332 | throw new Dwoo_Compilation_Exception($this, 'Un-ended comment'); |
1333 | 1333 | } |
1334 | 1334 | } |
1335 | - $pointer += $endpos - $startpos + strlen('*'.$this->rd); |
|
1335 | + $pointer += $endpos-$startpos+strlen('*'.$this->rd); |
|
1336 | 1336 | if (isset($whitespaceStart) && preg_match('#^[\t ]*\r?\n#', substr($src, $endpos+strlen('*'.$this->rd)), $m)) { |
1337 | 1337 | $pointer += strlen($m[0]); |
1338 | - $this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer']) - ($this->getPointer() - $startpos - strlen($this->ld))); |
|
1338 | + $this->curBlock['buffer'] = substr($this->curBlock['buffer'], 0, strlen($this->curBlock['buffer'])-($this->getPointer()-$startpos-strlen($this->ld))); |
|
1339 | 1339 | } |
1340 | 1340 | return false; |
1341 | 1341 | } |
1342 | 1342 | } |
1343 | 1343 | |
1344 | - if ($first==='$') { |
|
1344 | + if ($first === '$') { |
|
1345 | 1345 | // var |
1346 | 1346 | $out = $this->parseVar($in, $from, $to, $parsingParams, $curBlock, $pointer); |
1347 | 1347 | $parsed = 'var'; |
1348 | - } elseif ($first==='%' && preg_match('#^%[a-z_]#i', $substr)) { |
|
1348 | + } elseif ($first === '%' && preg_match('#^%[a-z_]#i', $substr)) { |
|
1349 | 1349 | // const |
1350 | 1350 | $out = $this->parseConst($in, $from, $to, $parsingParams, $curBlock, $pointer); |
1351 | - } elseif (($first==='"' || $first==="'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) { |
|
1351 | + } elseif (($first === '"' || $first === "'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) { |
|
1352 | 1352 | // string |
1353 | 1353 | $out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer); |
1354 | - } 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)) { |
|
1354 | + } 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)) { |
|
1355 | 1355 | // func |
1356 | 1356 | $out = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer); |
1357 | 1357 | $parsed = 'func'; |
@@ -1388,11 +1388,11 @@ discard block |
||
1388 | 1388 | if ($this->debug) echo 'TAG PARSING ENDED<br />'; |
1389 | 1389 | $pointer += strlen($this->rd); |
1390 | 1390 | return false; |
1391 | - } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*='.($curBlock === 'array' ? '>?':'').')(?:\s+|[^=]).*#i', $substr, $match)) { |
|
1391 | + } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*='.($curBlock === 'array' ? '>?' : '').')(?:\s+|[^=]).*#i', $substr, $match)) { |
|
1392 | 1392 | // named parameter |
1393 | 1393 | if ($this->debug) echo 'NAMED PARAM FOUND<br />'; |
1394 | 1394 | $len = strlen($match[1]); |
1395 | - while (substr($in, $from+$len, 1)===' ') { |
|
1395 | + while (substr($in, $from+$len, 1) === ' ') { |
|
1396 | 1396 | $len++; |
1397 | 1397 | } |
1398 | 1398 | if ($pointer !== null) { |
@@ -1413,7 +1413,7 @@ discard block |
||
1413 | 1413 | $out = $match[1]; |
1414 | 1414 | } |
1415 | 1415 | $pointer += strlen($match[1]); |
1416 | - } elseif ($substr!=='' && (is_array($parsingParams) || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'expression')) { |
|
1416 | + } elseif ($substr !== '' && (is_array($parsingParams) || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'expression')) { |
|
1417 | 1417 | // unquoted string, bool or number |
1418 | 1418 | $out = $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer); |
1419 | 1419 | } else { |
@@ -1428,19 +1428,19 @@ discard block |
||
1428 | 1428 | $substr = substr($in, $pointer, $to-$pointer); |
1429 | 1429 | |
1430 | 1430 | // var parsed, check if any var-extension applies |
1431 | - if ($parsed==='var') { |
|
1431 | + if ($parsed === 'var') { |
|
1432 | 1432 | if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) { |
1433 | - if($this->debug) echo 'PARSING POST-VAR EXPRESSION '.$substr.'<br />'; |
|
1433 | + if ($this->debug) echo 'PARSING POST-VAR EXPRESSION '.$substr.'<br />'; |
|
1434 | 1434 | // parse expressions |
1435 | - $pointer += strlen($match[0]) - 1; |
|
1435 | + $pointer += strlen($match[0])-1; |
|
1436 | 1436 | if (is_array($parsingParams)) { |
1437 | 1437 | if ($match[2] == '$') { |
1438 | 1438 | $expr = $this->parseVar($in, $pointer, $to, array(), $curBlock, $pointer); |
1439 | 1439 | } else { |
1440 | 1440 | $expr = $this->parse($in, $pointer, $to, array(), 'expression', $pointer); |
1441 | 1441 | } |
1442 | - $out[count($out)-1][0] .= $match[1] . $expr[0][0]; |
|
1443 | - $out[count($out)-1][1] .= $match[1] . $expr[0][1]; |
|
1442 | + $out[count($out)-1][0] .= $match[1].$expr[0][0]; |
|
1443 | + $out[count($out)-1][1] .= $match[1].$expr[0][1]; |
|
1444 | 1444 | } else { |
1445 | 1445 | if ($match[2] == '$') { |
1446 | 1446 | $expr = $this->parseVar($in, $pointer, $to, false, $curBlock, $pointer); |
@@ -1448,19 +1448,19 @@ discard block |
||
1448 | 1448 | $expr = $this->parse($in, $pointer, $to, false, 'expression', $pointer); |
1449 | 1449 | } |
1450 | 1450 | if (is_array($out) && is_array($expr)) { |
1451 | - $out[0] .= $match[1] . $expr[0]; |
|
1452 | - $out[1] .= $match[1] . $expr[1]; |
|
1451 | + $out[0] .= $match[1].$expr[0]; |
|
1452 | + $out[1] .= $match[1].$expr[1]; |
|
1453 | 1453 | } elseif (is_array($out)) { |
1454 | - $out[0] .= $match[1] . $expr; |
|
1455 | - $out[1] .= $match[1] . $expr; |
|
1454 | + $out[0] .= $match[1].$expr; |
|
1455 | + $out[1] .= $match[1].$expr; |
|
1456 | 1456 | } elseif (is_array($expr)) { |
1457 | - $out .= $match[1] . $expr[0]; |
|
1457 | + $out .= $match[1].$expr[0]; |
|
1458 | 1458 | } else { |
1459 | - $out .= $match[1] . $expr; |
|
1459 | + $out .= $match[1].$expr; |
|
1460 | 1460 | } |
1461 | 1461 | } |
1462 | 1462 | } else if ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) { |
1463 | - if($this->debug) echo 'PARSING POST-VAR ASSIGNMENT '.$substr.'<br />'; |
|
1463 | + if ($this->debug) echo 'PARSING POST-VAR ASSIGNMENT '.$substr.'<br />'; |
|
1464 | 1464 | // parse assignment |
1465 | 1465 | $value = $match[2]; |
1466 | 1466 | $operator = trim($match[1]); |
@@ -1499,7 +1499,7 @@ discard block |
||
1499 | 1499 | if ($this->autoEscape) { |
1500 | 1500 | $out = preg_replace('#\(is_string\(\$tmp=(.+?)\) \? htmlspecialchars\(\$tmp, ENT_QUOTES, \$this->charset\) : \$tmp\)#', '$1', $out); |
1501 | 1501 | } |
1502 | - $out = Dwoo_Compiler::PHP_OPEN. $echo . $out . $operator . implode(' ', $value) . Dwoo_Compiler::PHP_CLOSE; |
|
1502 | + $out = Dwoo_Compiler::PHP_OPEN.$echo.$out.$operator.implode(' ', $value).Dwoo_Compiler::PHP_CLOSE; |
|
1503 | 1503 | } else if ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) { |
1504 | 1504 | // parse namedparam with var as name (only for array) |
1505 | 1505 | if ($this->debug) echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND<br />'; |
@@ -1520,14 +1520,14 @@ discard block |
||
1520 | 1520 | if (is_array($parsingParams)) { |
1521 | 1521 | $tmp = $this->replaceModifiers(array(null, null, $out[count($out)-1][0], $match[0]), $curBlock, $pointer); |
1522 | 1522 | $out[count($out)-1][0] = $tmp; |
1523 | - $out[count($out)-1][1] .= substr($substr, $srcPointer, $srcPointer - $pointer); |
|
1523 | + $out[count($out)-1][1] .= substr($substr, $srcPointer, $srcPointer-$pointer); |
|
1524 | 1524 | } else { |
1525 | 1525 | $out = $this->replaceModifiers(array(null, null, $out, $match[0]), $curBlock, $pointer); |
1526 | 1526 | } |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | // func parsed, check if any func-extension applies |
1530 | - if ($parsed==='func' && preg_match('#^->[a-z0-9_]+(\s*\(.+|->[a-z_].*)?#is', $substr, $match)) { |
|
1530 | + if ($parsed === 'func' && preg_match('#^->[a-z0-9_]+(\s*\(.+|->[a-z_].*)?#is', $substr, $match)) { |
|
1531 | 1531 | // parse method call or property read |
1532 | 1532 | $ptr = 0; |
1533 | 1533 | |
@@ -1544,7 +1544,7 @@ discard block |
||
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | if ($curBlock === 'root' && substr($out, 0, strlen(self::PHP_OPEN)) !== self::PHP_OPEN) { |
1547 | - return self::PHP_OPEN .'echo '.$out.';'. self::PHP_CLOSE; |
|
1547 | + return self::PHP_OPEN.'echo '.$out.';'.self::PHP_CLOSE; |
|
1548 | 1548 | } else { |
1549 | 1549 | return $out; |
1550 | 1550 | } |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
1562 | 1562 | * @return string parsed values |
1563 | 1563 | */ |
1564 | - protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
1564 | + protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
1565 | 1565 | { |
1566 | 1566 | $cmdstr = substr($in, $from, $to-$from); |
1567 | 1567 | preg_match('/^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*(?:::[a-z_][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match); |
@@ -1583,14 +1583,14 @@ discard block |
||
1583 | 1583 | if (is_array($parsingParams) || $curBlock != 'root') { |
1584 | 1584 | $paramspos = strpos($cmdstr, '('); |
1585 | 1585 | $paramsep = ')'; |
1586 | - } elseif(preg_match_all('#^\s*[\\\\:a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) { |
|
1586 | + } elseif (preg_match_all('#^\s*[\\\\:a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) { |
|
1587 | 1587 | $paramspos = $match[1][0][1]; |
1588 | - $paramsep = substr($match[1][0][0], -1) === '(' ? ')':''; |
|
1589 | - if($paramsep === ')') { |
|
1590 | - $paramspos += strlen($match[1][0][0]) - 1; |
|
1591 | - if(substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') { |
|
1588 | + $paramsep = substr($match[1][0][0], -1) === '(' ? ')' : ''; |
|
1589 | + if ($paramsep === ')') { |
|
1590 | + $paramspos += strlen($match[1][0][0])-1; |
|
1591 | + if (substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') { |
|
1592 | 1592 | $paramsep = ''; |
1593 | - if(strlen($match[1][0][0]) > 1) { |
|
1593 | + if (strlen($match[1][0][0]) > 1) { |
|
1594 | 1594 | $paramspos--; |
1595 | 1595 | } |
1596 | 1596 | } |
@@ -1622,7 +1622,7 @@ discard block |
||
1622 | 1622 | $paramstr = substr($paramstr, 0, -1); |
1623 | 1623 | } |
1624 | 1624 | |
1625 | - if (strlen($paramstr)===0) { |
|
1625 | + if (strlen($paramstr) === 0) { |
|
1626 | 1626 | $params = array(); |
1627 | 1627 | $paramstr = ''; |
1628 | 1628 | } else { |
@@ -1692,8 +1692,8 @@ discard block |
||
1692 | 1692 | } |
1693 | 1693 | |
1694 | 1694 | if ($pointer !== null) { |
1695 | - $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0); |
|
1696 | - if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>'; |
|
1695 | + $pointer += (isset($paramstr) ? strlen($paramstr) : 0)+(')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1))+strlen($func)+(isset($whitespace) ? $whitespace : 0); |
|
1696 | + if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0)+(')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1))+strlen($func)).' TO POINTER<br/>'; |
|
1697 | 1697 | } |
1698 | 1698 | |
1699 | 1699 | if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) { |
@@ -1926,12 +1926,12 @@ discard block |
||
1926 | 1926 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
1927 | 1927 | * @return string parsed values |
1928 | 1928 | */ |
1929 | - protected function parseString($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
1929 | + protected function parseString($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
1930 | 1930 | { |
1931 | 1931 | $substr = substr($in, $from, $to-$from); |
1932 | 1932 | $first = $substr[0]; |
1933 | 1933 | |
1934 | - if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')<br />'; |
|
1934 | + if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...' : '').')<br />'; |
|
1935 | 1935 | $strend = false; |
1936 | 1936 | $o = $from+1; |
1937 | 1937 | while ($strend === false) { |
@@ -1993,7 +1993,7 @@ discard block |
||
1993 | 1993 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
1994 | 1994 | * @return string parsed values |
1995 | 1995 | */ |
1996 | - protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
1996 | + protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
1997 | 1997 | { |
1998 | 1998 | $substr = substr($in, $from, $to-$from); |
1999 | 1999 | |
@@ -2054,14 +2054,14 @@ discard block |
||
2054 | 2054 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
2055 | 2055 | * @return string parsed values |
2056 | 2056 | */ |
2057 | - protected function parseVar($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
2057 | + protected function parseVar($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
2058 | 2058 | { |
2059 | 2059 | $substr = substr($in, $from, $to-$from); |
2060 | 2060 | |
2061 | - if (preg_match('#(\$?\.?[a-z0-9_:]*(?:(?:(?:\.|->)(?:[a-z0-9_:]+|(?R))|\[(?:[a-z0-9_:]+|(?R)|(["\'])[^\2]*?\2)\]))*)' . // var key |
|
2062 | - ($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='expression' || $curBlock==='delimited_string' ? '(\(.*)?' : '()') . // method call |
|
2063 | - ($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='delimited_string' ? '((?:(?:[+/*%=-])(?:(?<!=)=?-?[$%][a-z0-9.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9.,]*|[+-]))*)':'()') . // simple math expressions |
|
2064 | - ($curBlock!=='modifier' ? '((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?':'(())') . // modifiers |
|
2061 | + if (preg_match('#(\$?\.?[a-z0-9_:]*(?:(?:(?:\.|->)(?:[a-z0-9_:]+|(?R))|\[(?:[a-z0-9_:]+|(?R)|(["\'])[^\2]*?\2)\]))*)'.// var key |
|
2062 | + ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'expression' || $curBlock === 'delimited_string' ? '(\(.*)?' : '()').// method call |
|
2063 | + ($curBlock === 'root' || $curBlock === 'function' || $curBlock === 'namedparam' || $curBlock === 'condition' || $curBlock === 'variable' || $curBlock === 'delimited_string' ? '((?:(?:[+/*%=-])(?:(?<!=)=?-?[$%][a-z0-9.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9.,]*|[+-]))*)' : '()').// simple math expressions |
|
2064 | + ($curBlock !== 'modifier' ? '((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?' : '(())').// modifiers |
|
2065 | 2065 | '#i', $substr, $match)) { |
2066 | 2066 | $key = substr($match[1], 1); |
2067 | 2067 | |
@@ -2076,9 +2076,9 @@ discard block |
||
2076 | 2076 | } |
2077 | 2077 | |
2078 | 2078 | if ($hasMethodCall) { |
2079 | - $matchedLength -= strlen($match[3]) + strlen(substr($match[1], strrpos($match[1], '->'))); |
|
2079 | + $matchedLength -= strlen($match[3])+strlen(substr($match[1], strrpos($match[1], '->'))); |
|
2080 | 2080 | $key = substr($match[1], 1, strrpos($match[1], '->')-1); |
2081 | - $methodCall = substr($match[1], strrpos($match[1], '->')) . $match[3]; |
|
2081 | + $methodCall = substr($match[1], strrpos($match[1], '->')).$match[3]; |
|
2082 | 2082 | } |
2083 | 2083 | |
2084 | 2084 | if ($hasModifiers) { |
@@ -2102,12 +2102,12 @@ discard block |
||
2102 | 2102 | |
2103 | 2103 | $key = str_replace('"', '\\"', $key); |
2104 | 2104 | |
2105 | - $cnt=substr_count($key, '$'); |
|
2105 | + $cnt = substr_count($key, '$'); |
|
2106 | 2106 | if ($cnt > 0) { |
2107 | 2107 | $uid = 0; |
2108 | 2108 | $parsed = array($uid => ''); |
2109 | - $current =& $parsed; |
|
2110 | - $curTxt =& $parsed[$uid++]; |
|
2109 | + $current = & $parsed; |
|
2110 | + $curTxt = & $parsed[$uid++]; |
|
2111 | 2111 | $tree = array(); |
2112 | 2112 | $chars = str_split($key, 1); |
2113 | 2113 | $inSplittedVar = false; |
@@ -2118,31 +2118,31 @@ discard block |
||
2118 | 2118 | if (count($tree) > 0) { |
2119 | 2119 | $bracketCount++; |
2120 | 2120 | } else { |
2121 | - $tree[] =& $current; |
|
2121 | + $tree[] = & $current; |
|
2122 | 2122 | $current[$uid] = array($uid+1 => ''); |
2123 | - $current =& $current[$uid++]; |
|
2124 | - $curTxt =& $current[$uid++]; |
|
2123 | + $current = & $current[$uid++]; |
|
2124 | + $curTxt = & $current[$uid++]; |
|
2125 | 2125 | continue; |
2126 | 2126 | } |
2127 | 2127 | } elseif ($char === ']') { |
2128 | 2128 | if ($bracketCount > 0) { |
2129 | 2129 | $bracketCount--; |
2130 | 2130 | } else { |
2131 | - $current =& $tree[count($tree)-1]; |
|
2131 | + $current = & $tree[count($tree)-1]; |
|
2132 | 2132 | array_pop($tree); |
2133 | 2133 | if (current($chars) !== '[' && current($chars) !== false && current($chars) !== ']') { |
2134 | 2134 | $current[$uid] = ''; |
2135 | - $curTxt =& $current[$uid++]; |
|
2135 | + $curTxt = & $current[$uid++]; |
|
2136 | 2136 | } |
2137 | 2137 | continue; |
2138 | 2138 | } |
2139 | 2139 | } elseif ($char === '$') { |
2140 | 2140 | if (count($tree) == 0) { |
2141 | - $curTxt =& $current[$uid++]; |
|
2141 | + $curTxt = & $current[$uid++]; |
|
2142 | 2142 | $inSplittedVar = true; |
2143 | 2143 | } |
2144 | 2144 | } elseif (($char === '.' || $char === '-') && count($tree) == 0 && $inSplittedVar) { |
2145 | - $curTxt =& $current[$uid++]; |
|
2145 | + $curTxt = & $current[$uid++]; |
|
2146 | 2146 | $inSplittedVar = false; |
2147 | 2147 | } |
2148 | 2148 | |
@@ -2178,7 +2178,7 @@ discard block |
||
2178 | 2178 | preg_match_all('#(?:([+/*%=-])(=?-?[%$][a-z0-9.[\]>_:-]+(?:\([^)]*\))?|=?-?[0-9.,]+|\1))#i', $match[4], $expMatch); |
2179 | 2179 | |
2180 | 2180 | foreach ($expMatch[1] as $k=>$operator) { |
2181 | - if (substr($expMatch[2][$k], 0, 1)==='=') { |
|
2181 | + if (substr($expMatch[2][$k], 0, 1) === '=') { |
|
2182 | 2182 | $assign = true; |
2183 | 2183 | if ($operator === '=') { |
2184 | 2184 | throw new Dwoo_Compilation_Exception($this, 'Invalid expression <em>'.$substr.'</em>, can not use "==" in expressions'); |
@@ -2190,11 +2190,11 @@ discard block |
||
2190 | 2190 | $expMatch[2][$k] = substr($expMatch[2][$k], 1); |
2191 | 2191 | } |
2192 | 2192 | |
2193 | - if (substr($expMatch[2][$k], 0, 1)==='-' && strlen($expMatch[2][$k]) > 1) { |
|
2193 | + if (substr($expMatch[2][$k], 0, 1) === '-' && strlen($expMatch[2][$k]) > 1) { |
|
2194 | 2194 | $operator .= '-'; |
2195 | 2195 | $expMatch[2][$k] = substr($expMatch[2][$k], 1); |
2196 | 2196 | } |
2197 | - if (($operator==='+'||$operator==='-') && $expMatch[2][$k]===$operator) { |
|
2197 | + if (($operator === '+' || $operator === '-') && $expMatch[2][$k] === $operator) { |
|
2198 | 2198 | $output = '('.$output.$operator.$operator.')'; |
2199 | 2199 | break; |
2200 | 2200 | } elseif (substr($expMatch[2][$k], 0, 1) === '$') { |
@@ -2270,7 +2270,7 @@ discard block |
||
2270 | 2270 | break; |
2271 | 2271 | } |
2272 | 2272 | |
2273 | - if(!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) { |
|
2273 | + if (!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) { |
|
2274 | 2274 | break; |
2275 | 2275 | } |
2276 | 2276 | |
@@ -2286,7 +2286,7 @@ discard block |
||
2286 | 2286 | // method |
2287 | 2287 | if (substr($methMatch[2], 0, 2) === '()') { |
2288 | 2288 | $parsedCall = $methMatch[1].'()'; |
2289 | - $ptr += strlen($methMatch[1]) + 2; |
|
2289 | + $ptr += strlen($methMatch[1])+2; |
|
2290 | 2290 | } else { |
2291 | 2291 | $parsedCall = $this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr); |
2292 | 2292 | } |
@@ -2395,7 +2395,7 @@ discard block |
||
2395 | 2395 | |
2396 | 2396 | while (count($m[1]) && $m[1][0] !== '->') { |
2397 | 2397 | $m[2][0] = preg_replace('/(^\\\([\'"])|\\\([\'"])$)/x', '$2$3', $m[2][0]); |
2398 | - if(substr($m[2][0], 0, 1) == '"' || substr($m[2][0], 0, 1) == "'") { |
|
2398 | + if (substr($m[2][0], 0, 1) == '"' || substr($m[2][0], 0, 1) == "'") { |
|
2399 | 2399 | $output .= '['.$m[2][0].']'; |
2400 | 2400 | } else { |
2401 | 2401 | $output .= '["'.$m[2][0].'"]'; |
@@ -2411,7 +2411,7 @@ discard block |
||
2411 | 2411 | |
2412 | 2412 | if (count($m[2])) { |
2413 | 2413 | unset($m[0]); |
2414 | - $output = '$this->readVarInto('.str_replace("\n", '', var_export($m, true)).', '.$output.', '.($curBlock == 'root' ? 'false': 'true').')'; |
|
2414 | + $output = '$this->readVarInto('.str_replace("\n", '', var_export($m, true)).', '.$output.', '.($curBlock == 'root' ? 'false' : 'true').')'; |
|
2415 | 2415 | } |
2416 | 2416 | } |
2417 | 2417 | } else { |
@@ -2431,16 +2431,16 @@ discard block |
||
2431 | 2431 | * @param bool $recursed leave that to false by default, it is only for internal use |
2432 | 2432 | * @return string flattened tree |
2433 | 2433 | */ |
2434 | - protected function flattenVarTree(array $tree, $recursed=false) |
|
2434 | + protected function flattenVarTree(array $tree, $recursed = false) |
|
2435 | 2435 | { |
2436 | - $out = $recursed ? '".$this->readVarInto(' : ''; |
|
2436 | + $out = $recursed ? '".$this->readVarInto(' : ''; |
|
2437 | 2437 | foreach ($tree as $bit) { |
2438 | 2438 | if (is_array($bit)) { |
2439 | - $out.='.'.$this->flattenVarTree($bit, false); |
|
2439 | + $out .= '.'.$this->flattenVarTree($bit, false); |
|
2440 | 2440 | } else { |
2441 | 2441 | $key = str_replace('"', '\\"', $bit); |
2442 | 2442 | |
2443 | - if (substr($key, 0, 1)==='$') { |
|
2443 | + if (substr($key, 0, 1) === '$') { |
|
2444 | 2444 | $out .= '".'.$this->parseVar($key, 0, strlen($key), false, 'variable').'."'; |
2445 | 2445 | } else { |
2446 | 2446 | $cnt = substr_count($key, '$'); |
@@ -2449,7 +2449,7 @@ discard block |
||
2449 | 2449 | if ($cnt > 0) { |
2450 | 2450 | while (--$cnt >= 0) { |
2451 | 2451 | if (isset($last)) { |
2452 | - $last = strrpos($key, '$', - (strlen($key) - $last + 1)); |
|
2452 | + $last = strrpos($key, '$', - (strlen($key)-$last+1)); |
|
2453 | 2453 | } else { |
2454 | 2454 | $last = strrpos($key, '$'); |
2455 | 2455 | } |
@@ -2504,7 +2504,7 @@ discard block |
||
2504 | 2504 | * @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default |
2505 | 2505 | * @return string parsed values |
2506 | 2506 | */ |
2507 | - protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) |
|
2507 | + protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock = '', &$pointer = null) |
|
2508 | 2508 | { |
2509 | 2509 | $first = $in[$from]; |
2510 | 2510 | $substr = substr($in, $from, $to-$from); |
@@ -2522,7 +2522,7 @@ discard block |
||
2522 | 2522 | } |
2523 | 2523 | |
2524 | 2524 | $breaker = false; |
2525 | - while (list($k,$char) = each($breakChars)) { |
|
2525 | + while (list($k, $char) = each($breakChars)) { |
|
2526 | 2526 | $test = strpos($substr, $char); |
2527 | 2527 | if ($test !== false && $test < $end) { |
2528 | 2528 | $end = $test; |
@@ -2600,7 +2600,7 @@ discard block |
||
2600 | 2600 | * @param string $curBlock the current parser-block being processed |
2601 | 2601 | * @return string the original string with variables replaced |
2602 | 2602 | */ |
2603 | - protected function replaceStringVars($string, $first, $curBlock='') |
|
2603 | + protected function replaceStringVars($string, $first, $curBlock = '') |
|
2604 | 2604 | { |
2605 | 2605 | $pos = 0; |
2606 | 2606 | if ($this->debug) echo 'STRING VAR REPLACEMENT : '.$string.'<br>'; |
@@ -2612,16 +2612,16 @@ discard block |
||
2612 | 2612 | continue; |
2613 | 2613 | } |
2614 | 2614 | |
2615 | - $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); |
|
2615 | + $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string'))); |
|
2616 | 2616 | $len = $var[0]; |
2617 | - $var = $this->parse(str_replace('\\'.$first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); |
|
2617 | + $var = $this->parse(str_replace('\\'.$first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string' : 'string'))); |
|
2618 | 2618 | |
2619 | 2619 | if ($prev === '`' && substr($string, $pos+$len, 1) === '`') { |
2620 | 2620 | $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos-1, $len+2); |
2621 | 2621 | } else { |
2622 | 2622 | $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len); |
2623 | 2623 | } |
2624 | - $pos += strlen($var[1]) + 2; |
|
2624 | + $pos += strlen($var[1])+2; |
|
2625 | 2625 | if ($this->debug) echo 'STRING VAR REPLACEMENT DONE : '.$string.'<br>'; |
2626 | 2626 | } |
2627 | 2627 | |
@@ -2630,7 +2630,7 @@ discard block |
||
2630 | 2630 | $string = preg_replace_callback('#("|\')\.(.+?)\.\1((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').+?\4|:[^`]*))*))+)#i', array($this, 'replaceModifiers'), $string); |
2631 | 2631 | |
2632 | 2632 | // replace escaped dollar operators by unescaped ones if required |
2633 | - if ($first==="'") { |
|
2633 | + if ($first === "'") { |
|
2634 | 2634 | $string = str_replace('\\$', '$', $string); |
2635 | 2635 | } |
2636 | 2636 | |
@@ -2712,7 +2712,7 @@ discard block |
||
2712 | 2712 | if ($paramstr[$ptr] !== '|') { |
2713 | 2713 | $continue = false; |
2714 | 2714 | if ($pointer !== null) { |
2715 | - $pointer -= strlen($paramstr) - $ptr; |
|
2715 | + $pointer -= strlen($paramstr)-$ptr; |
|
2716 | 2716 | } |
2717 | 2717 | } |
2718 | 2718 | $ptr++; |
@@ -2806,7 +2806,7 @@ discard block |
||
2806 | 2806 | if ($pluginType & Dwoo_Core::CLASS_PLUGIN) { |
2807 | 2807 | $callback = array($pluginName, ($pluginType & Dwoo_Core::COMPILABLE_PLUGIN) ? 'compile' : 'process'); |
2808 | 2808 | } else { |
2809 | - $callback = $pluginName . (($pluginType & Dwoo_Core::COMPILABLE_PLUGIN) ? '_compile' : ''); |
|
2809 | + $callback = $pluginName.(($pluginType & Dwoo_Core::COMPILABLE_PLUGIN) ? '_compile' : ''); |
|
2810 | 2810 | } |
2811 | 2811 | } |
2812 | 2812 | |
@@ -2885,7 +2885,7 @@ discard block |
||
2885 | 2885 | } elseif ($curBlock === 'var' || $m[1] === null) { |
2886 | 2886 | return $output; |
2887 | 2887 | } elseif ($curBlock === 'string' || $curBlock === 'root') { |
2888 | - return $m[1].'.'.$output.'.'.$m[1].(isset($add)?$add:null); |
|
2888 | + return $m[1].'.'.$output.'.'.$m[1].(isset($add) ? $add : null); |
|
2889 | 2889 | } |
2890 | 2890 | } |
2891 | 2891 | |
@@ -2960,9 +2960,9 @@ discard block |
||
2960 | 2960 | } elseif (function_exists('smarty_block_'.$name) !== false) { |
2961 | 2961 | $pluginType = Dwoo_Core::SMARTY_BLOCK; |
2962 | 2962 | } else { |
2963 | - if ($pluginType===-1) { |
|
2963 | + if ($pluginType === -1) { |
|
2964 | 2964 | try { |
2965 | - $this->dwoo->getLoader()->loadPlugin($name, isset($phpFunc)===false); |
|
2965 | + $this->dwoo->getLoader()->loadPlugin($name, isset($phpFunc) === false); |
|
2966 | 2966 | } catch (Exception $e) { |
2967 | 2967 | if (isset($phpFunc)) { |
2968 | 2968 | $pluginType = Dwoo_Core::NATIVE_PLUGIN; |
@@ -3019,7 +3019,7 @@ discard block |
||
3019 | 3019 | * @param array $map the parameter map to use, if not provided it will be built from the callback |
3020 | 3020 | * @return array parameters sorted in the correct order with missing optional parameters filled |
3021 | 3021 | */ |
3022 | - protected function mapParams(array $params, $callback, $callType=2, $map = null) |
|
3022 | + protected function mapParams(array $params, $callback, $callType = 2, $map = null) |
|
3023 | 3023 | { |
3024 | 3024 | if (!$map) { |
3025 | 3025 | $map = $this->getParamMap($callback); |
@@ -3038,11 +3038,11 @@ discard block |
||
3038 | 3038 | } |
3039 | 3039 | |
3040 | 3040 | // loops over the param map and assigns values from the template or default value for unset optional params |
3041 | - while (list($k,$v) = each($map)) { |
|
3041 | + while (list($k, $v) = each($map)) { |
|
3042 | 3042 | if ($v[0] === '*') { |
3043 | 3043 | // "rest" array parameter, fill every remaining params in it and then break |
3044 | 3044 | if (count($ps) === 0) { |
3045 | - if ($v[1]===false) { |
|
3045 | + if ($v[1] === false) { |
|
3046 | 3046 | throw new Dwoo_Compilation_Exception($this, 'Rest argument missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', (is_array($callback) ? $callback[0] : $callback))); |
3047 | 3047 | } else { |
3048 | 3048 | break; |
@@ -3068,11 +3068,11 @@ discard block |
||
3068 | 3068 | // parameter is defined as ordered param |
3069 | 3069 | $paramlist[$v[0]] = $ps[$k]; |
3070 | 3070 | unset($ps[$k]); |
3071 | - } elseif ($v[1]===false) { |
|
3071 | + } elseif ($v[1] === false) { |
|
3072 | 3072 | // parameter is not defined and not optional, throw error |
3073 | 3073 | if (is_array($callback)) { |
3074 | 3074 | if (is_object($callback[0])) { |
3075 | - $name = get_class($callback[0]) . '::' . $callback[1]; |
|
3075 | + $name = get_class($callback[0]).'::'.$callback[1]; |
|
3076 | 3076 | } else { |
3077 | 3077 | $name = $callback[0]; |
3078 | 3078 | } |
@@ -3081,7 +3081,7 @@ discard block |
||
3081 | 3081 | } |
3082 | 3082 | |
3083 | 3083 | throw new Dwoo_Compilation_Exception($this, 'Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', $name)); |
3084 | - } elseif ($v[2]===null) { |
|
3084 | + } elseif ($v[2] === null) { |
|
3085 | 3085 | // enforce lowercased null if default value is null (php outputs NULL with var export) |
3086 | 3086 | $paramlist[$v[0]] = array('null', null, self::T_NULL); |
3087 | 3087 | } else { |
@@ -713,9 +713,13 @@ discard block |
||
713 | 713 | $compiled = $this->addBlock('topLevelBlock', array(), 0); |
714 | 714 | $this->stack[0]['buffer'] = ''; |
715 | 715 | |
716 | - if ($this->debug) echo 'COMPILER INIT<br />'; |
|
716 | + if ($this->debug) { |
|
717 | + echo 'COMPILER INIT<br />'; |
|
718 | + } |
|
717 | 719 | |
718 | - if ($this->debug) echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')<br>'; |
|
720 | + if ($this->debug) { |
|
721 | + echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')<br>'; |
|
722 | + } |
|
719 | 723 | |
720 | 724 | // runs preprocessors |
721 | 725 | foreach ($this->processors['pre'] as $preProc) { |
@@ -731,7 +735,9 @@ discard block |
||
731 | 735 | unset($preProc); |
732 | 736 | |
733 | 737 | // show template source if debug |
734 | - if ($this->debug) echo '<pre>'.print_r(htmlentities($tpl), true).'</pre><hr />'; |
|
738 | + if ($this->debug) { |
|
739 | + echo '<pre>'.print_r(htmlentities($tpl), true).'</pre><hr />'; |
|
740 | + } |
|
735 | 741 | |
736 | 742 | // strips php tags if required by the security policy |
737 | 743 | if ($this->securityPolicy !== null) { |
@@ -820,7 +826,9 @@ discard block |
||
820 | 826 | |
821 | 827 | $compiled .= $this->removeBlock('topLevelBlock'); |
822 | 828 | |
823 | - if ($this->debug) echo 'PROCESSING POSTPROCESSORS<br>'; |
|
829 | + if ($this->debug) { |
|
830 | + echo 'PROCESSING POSTPROCESSORS<br>'; |
|
831 | + } |
|
824 | 832 | |
825 | 833 | foreach ($this->processors['post'] as $postProc) { |
826 | 834 | if (is_array($postProc) && isset($postProc['autoload'])) { |
@@ -834,7 +842,9 @@ discard block |
||
834 | 842 | } |
835 | 843 | unset($postProc); |
836 | 844 | |
837 | - if ($this->debug) echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage().'<br>'; |
|
845 | + if ($this->debug) { |
|
846 | + echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage().'<br>'; |
|
847 | + } |
|
838 | 848 | |
839 | 849 | $output = "<?php\n/* template head */\n"; |
840 | 850 | |
@@ -902,7 +912,9 @@ discard block |
||
902 | 912 | echo ($i+1).'. '.$line."\r\n"; |
903 | 913 | } |
904 | 914 | } |
905 | - if ($this->debug) echo '<hr></pre></pre>'; |
|
915 | + if ($this->debug) { |
|
916 | + echo '<hr></pre></pre>'; |
|
917 | + } |
|
906 | 918 | |
907 | 919 | $this->template = $this->dwoo = null; |
908 | 920 | $tpl = null; |
@@ -987,8 +999,9 @@ discard block |
||
987 | 999 | reset($this->scopeTree); |
988 | 1000 | $this->scope =& $this->data; |
989 | 1001 | $cnt = count($this->scopeTree); |
990 | - for ($i=0;$i<$cnt;$i++) |
|
991 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1002 | + for ($i=0;$i<$cnt;$i++) { |
|
1003 | + $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1004 | + } |
|
992 | 1005 | } elseif ($bit === '_root' || $bit === '__') { |
993 | 1006 | $this->scope =& $this->data; |
994 | 1007 | $this->scopeTree = array(); |
@@ -1253,7 +1266,9 @@ discard block |
||
1253 | 1266 | if ($curBlock === 'root' && substr($in, $from, strlen($this->rd)) === $this->rd) { |
1254 | 1267 | // end template tag |
1255 | 1268 | $pointer += strlen($this->rd); |
1256 | - if ($this->debug) echo 'TEMPLATE PARSING ENDED<br />'; |
|
1269 | + if ($this->debug) { |
|
1270 | + echo 'TEMPLATE PARSING ENDED<br />'; |
|
1271 | + } |
|
1257 | 1272 | return false; |
1258 | 1273 | } |
1259 | 1274 | $from++; |
@@ -1272,7 +1287,9 @@ discard block |
||
1272 | 1287 | |
1273 | 1288 | $substr = substr($in, $from, $to-$from); |
1274 | 1289 | |
1275 | - if ($this->debug) echo '<br />PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer.'<br/>'; |
|
1290 | + if ($this->debug) { |
|
1291 | + echo '<br />PARSE CALL : PARSING "<b>'.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').'</b>" @ '.$from.':'.$to.' in '.$curBlock.' : pointer='.$pointer.'<br/>'; |
|
1292 | + } |
|
1276 | 1293 | $parsed = ""; |
1277 | 1294 | |
1278 | 1295 | if ($curBlock === 'root' && $first === '*') { |
@@ -1357,7 +1374,9 @@ discard block |
||
1357 | 1374 | $parsed = 'func'; |
1358 | 1375 | } elseif ($first === ';') { |
1359 | 1376 | // instruction end |
1360 | - if ($this->debug) echo 'END OF INSTRUCTION<br />'; |
|
1377 | + if ($this->debug) { |
|
1378 | + echo 'END OF INSTRUCTION<br />'; |
|
1379 | + } |
|
1361 | 1380 | if ($pointer !== null) { |
1362 | 1381 | $pointer++; |
1363 | 1382 | } |
@@ -1377,20 +1396,28 @@ discard block |
||
1377 | 1396 | if ($this->curBlock['type'] == 'else' || $this->curBlock['type'] == 'elseif') { |
1378 | 1397 | $pointer -= strlen($match[0]); |
1379 | 1398 | } |
1380 | - if ($this->debug) echo 'TOP BLOCK CLOSED<br />'; |
|
1399 | + if ($this->debug) { |
|
1400 | + echo 'TOP BLOCK CLOSED<br />'; |
|
1401 | + } |
|
1381 | 1402 | return $this->removeTopBlock(); |
1382 | 1403 | } else { |
1383 | - if ($this->debug) echo 'BLOCK OF TYPE '.$match[1].' CLOSED<br />'; |
|
1404 | + if ($this->debug) { |
|
1405 | + echo 'BLOCK OF TYPE '.$match[1].' CLOSED<br />'; |
|
1406 | + } |
|
1384 | 1407 | return $this->removeBlock($match[1]); |
1385 | 1408 | } |
1386 | 1409 | } elseif ($curBlock === 'root' && substr($substr, 0, strlen($this->rd)) === $this->rd) { |
1387 | 1410 | // end template tag |
1388 | - if ($this->debug) echo 'TAG PARSING ENDED<br />'; |
|
1411 | + if ($this->debug) { |
|
1412 | + echo 'TAG PARSING ENDED<br />'; |
|
1413 | + } |
|
1389 | 1414 | $pointer += strlen($this->rd); |
1390 | 1415 | return false; |
1391 | 1416 | } elseif (is_array($parsingParams) && preg_match('#^(([\'"]?)[a-z0-9_]+\2\s*='.($curBlock === 'array' ? '>?':'').')(?:\s+|[^=]).*#i', $substr, $match)) { |
1392 | 1417 | // named parameter |
1393 | - if ($this->debug) echo 'NAMED PARAM FOUND<br />'; |
|
1418 | + if ($this->debug) { |
|
1419 | + echo 'NAMED PARAM FOUND<br />'; |
|
1420 | + } |
|
1394 | 1421 | $len = strlen($match[1]); |
1395 | 1422 | while (substr($in, $from+$len, 1)===' ') { |
1396 | 1423 | $len++; |
@@ -1430,7 +1457,9 @@ discard block |
||
1430 | 1457 | // var parsed, check if any var-extension applies |
1431 | 1458 | if ($parsed==='var') { |
1432 | 1459 | if (preg_match('#^\s*([/%+*-])\s*([a-z0-9]|\$)#i', $substr, $match)) { |
1433 | - if($this->debug) echo 'PARSING POST-VAR EXPRESSION '.$substr.'<br />'; |
|
1460 | + if($this->debug) { |
|
1461 | + echo 'PARSING POST-VAR EXPRESSION '.$substr.'<br />'; |
|
1462 | + } |
|
1434 | 1463 | // parse expressions |
1435 | 1464 | $pointer += strlen($match[0]) - 1; |
1436 | 1465 | if (is_array($parsingParams)) { |
@@ -1460,7 +1489,9 @@ discard block |
||
1460 | 1489 | } |
1461 | 1490 | } |
1462 | 1491 | } else if ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) { |
1463 | - if($this->debug) echo 'PARSING POST-VAR ASSIGNMENT '.$substr.'<br />'; |
|
1492 | + if($this->debug) { |
|
1493 | + echo 'PARSING POST-VAR ASSIGNMENT '.$substr.'<br />'; |
|
1494 | + } |
|
1464 | 1495 | // parse assignment |
1465 | 1496 | $value = $match[2]; |
1466 | 1497 | $operator = trim($match[1]); |
@@ -1502,7 +1533,9 @@ discard block |
||
1502 | 1533 | $out = Dwoo_Compiler::PHP_OPEN. $echo . $out . $operator . implode(' ', $value) . Dwoo_Compiler::PHP_CLOSE; |
1503 | 1534 | } else if ($curBlock === 'array' && is_array($parsingParams) && preg_match('#^(\s*=>?\s*)#', $substr, $match)) { |
1504 | 1535 | // parse namedparam with var as name (only for array) |
1505 | - if ($this->debug) echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND<br />'; |
|
1536 | + if ($this->debug) { |
|
1537 | + echo 'VARIABLE NAMED PARAM (FOR ARRAY) FOUND<br />'; |
|
1538 | + } |
|
1506 | 1539 | $len = strlen($match[1]); |
1507 | 1540 | $var = $out[count($out)-1]; |
1508 | 1541 | $pointer += $len; |
@@ -1576,7 +1609,9 @@ discard block |
||
1576 | 1609 | $cmdstr = $match[1]; |
1577 | 1610 | } |
1578 | 1611 | |
1579 | - if ($this->debug) echo 'FUNC FOUND ('.$func.')<br />'; |
|
1612 | + if ($this->debug) { |
|
1613 | + echo 'FUNC FOUND ('.$func.')<br />'; |
|
1614 | + } |
|
1580 | 1615 | |
1581 | 1616 | $paramsep = ''; |
1582 | 1617 | |
@@ -1638,17 +1673,25 @@ discard block |
||
1638 | 1673 | } |
1639 | 1674 | |
1640 | 1675 | if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') { |
1641 | - if ($this->debug) echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1676 | + if ($this->debug) { |
|
1677 | + echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1678 | + } |
|
1642 | 1679 | break 2; |
1643 | 1680 | } elseif ($paramstr[$ptr] === ';') { |
1644 | 1681 | $ptr++; |
1645 | - if ($this->debug) echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1682 | + if ($this->debug) { |
|
1683 | + echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1684 | + } |
|
1646 | 1685 | break 2; |
1647 | 1686 | } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') { |
1648 | - if ($this->debug) echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1687 | + if ($this->debug) { |
|
1688 | + echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1689 | + } |
|
1649 | 1690 | break 2; |
1650 | 1691 | } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { |
1651 | - if ($this->debug) echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1692 | + if ($this->debug) { |
|
1693 | + echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr.'<br/>'; |
|
1694 | + } |
|
1652 | 1695 | break 2; |
1653 | 1696 | } |
1654 | 1697 | |
@@ -1659,7 +1702,9 @@ discard block |
||
1659 | 1702 | } |
1660 | 1703 | } |
1661 | 1704 | |
1662 | - if ($this->debug) echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; |
|
1705 | + if ($this->debug) { |
|
1706 | + echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; |
|
1707 | + } |
|
1663 | 1708 | |
1664 | 1709 | if ($func === 'if' || $func === 'elseif' || $func === 'tif') { |
1665 | 1710 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr); |
@@ -1669,7 +1714,9 @@ discard block |
||
1669 | 1714 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr); |
1670 | 1715 | } |
1671 | 1716 | |
1672 | - if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')<br/>'; |
|
1717 | + if ($this->debug) { |
|
1718 | + echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')<br/>'; |
|
1719 | + } |
|
1673 | 1720 | } |
1674 | 1721 | } |
1675 | 1722 | $paramstr = substr($paramstr, 0, $ptr); |
@@ -1693,7 +1740,9 @@ discard block |
||
1693 | 1740 | |
1694 | 1741 | if ($pointer !== null) { |
1695 | 1742 | $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0); |
1696 | - if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>'; |
|
1743 | + if ($this->debug) { |
|
1744 | + echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>'; |
|
1745 | + } |
|
1697 | 1746 | } |
1698 | 1747 | |
1699 | 1748 | if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) { |
@@ -1931,7 +1980,9 @@ discard block |
||
1931 | 1980 | $substr = substr($in, $from, $to-$from); |
1932 | 1981 | $first = $substr[0]; |
1933 | 1982 | |
1934 | - if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')<br />'; |
|
1983 | + if ($this->debug) { |
|
1984 | + echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')<br />'; |
|
1985 | + } |
|
1935 | 1986 | $strend = false; |
1936 | 1987 | $o = $from+1; |
1937 | 1988 | while ($strend === false) { |
@@ -1944,7 +1995,9 @@ discard block |
||
1944 | 1995 | $strend = false; |
1945 | 1996 | } |
1946 | 1997 | } |
1947 | - if ($this->debug) echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from).'<br/>'; |
|
1998 | + if ($this->debug) { |
|
1999 | + echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from).'<br/>'; |
|
2000 | + } |
|
1948 | 2001 | |
1949 | 2002 | $srcOutput = substr($in, $from, $strend+1-$from); |
1950 | 2003 | |
@@ -2150,11 +2203,15 @@ discard block |
||
2150 | 2203 | } |
2151 | 2204 | unset($uid, $current, $curTxt, $tree, $chars); |
2152 | 2205 | |
2153 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT : '.$key.'<br>'; |
|
2206 | + if ($this->debug) { |
|
2207 | + echo 'RECURSIVE VAR REPLACEMENT : '.$key.'<br>'; |
|
2208 | + } |
|
2154 | 2209 | |
2155 | 2210 | $key = $this->flattenVarTree($parsed); |
2156 | 2211 | |
2157 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key.'<br>'; |
|
2212 | + if ($this->debug) { |
|
2213 | + echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key.'<br>'; |
|
2214 | + } |
|
2158 | 2215 | |
2159 | 2216 | $output = preg_replace('#(^""\.|""\.|\.""$|(\()""\.|\.""(\)))#', '$2$3', '$this->readVar("'.$key.'")'); |
2160 | 2217 | } else { |
@@ -2334,8 +2391,9 @@ discard block |
||
2334 | 2391 | $global = 'COOKIE'; |
2335 | 2392 | } |
2336 | 2393 | $key = '$_'.$global; |
2337 | - foreach (explode('.', ltrim($m[2], '.')) as $part) |
|
2338 | - $key .= '['.var_export($part, true).']'; |
|
2394 | + foreach (explode('.', ltrim($m[2], '.')) as $part) { |
|
2395 | + $key .= '['.var_export($part, true).']'; |
|
2396 | + } |
|
2339 | 2397 | if ($curBlock === 'root') { |
2340 | 2398 | $output = $key; |
2341 | 2399 | } else { |
@@ -2445,7 +2503,9 @@ discard block |
||
2445 | 2503 | } else { |
2446 | 2504 | $cnt = substr_count($key, '$'); |
2447 | 2505 | |
2448 | - if ($this->debug) echo 'PARSING SUBVARS IN : '.$key.'<br>'; |
|
2506 | + if ($this->debug) { |
|
2507 | + echo 'PARSING SUBVARS IN : '.$key.'<br>'; |
|
2508 | + } |
|
2449 | 2509 | if ($cnt > 0) { |
2450 | 2510 | while (--$cnt >= 0) { |
2451 | 2511 | if (isset($last)) { |
@@ -2467,7 +2527,9 @@ discard block |
||
2467 | 2527 | $last, |
2468 | 2528 | $len |
2469 | 2529 | ); |
2470 | - if ($this->debug) echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key.'<br>'; |
|
2530 | + if ($this->debug) { |
|
2531 | + echo 'RECURSIVE VAR REPLACEMENT DONE : '.$key.'<br>'; |
|
2532 | + } |
|
2471 | 2533 | } |
2472 | 2534 | unset($last); |
2473 | 2535 | |
@@ -2548,15 +2610,21 @@ discard block |
||
2548 | 2610 | $substr = trim($substr); |
2549 | 2611 | |
2550 | 2612 | if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') { |
2551 | - if ($this->debug) echo 'BOOLEAN(FALSE) PARSED<br />'; |
|
2613 | + if ($this->debug) { |
|
2614 | + echo 'BOOLEAN(FALSE) PARSED<br />'; |
|
2615 | + } |
|
2552 | 2616 | $substr = 'false'; |
2553 | 2617 | $type = self::T_BOOL; |
2554 | 2618 | } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') { |
2555 | - if ($this->debug) echo 'BOOLEAN(TRUE) PARSED<br />'; |
|
2619 | + if ($this->debug) { |
|
2620 | + echo 'BOOLEAN(TRUE) PARSED<br />'; |
|
2621 | + } |
|
2556 | 2622 | $substr = 'true'; |
2557 | 2623 | $type = self::T_BOOL; |
2558 | 2624 | } elseif ($substr === 'null' || $substr === 'NULL') { |
2559 | - if ($this->debug) echo 'NULL PARSED<br />'; |
|
2625 | + if ($this->debug) { |
|
2626 | + echo 'NULL PARSED<br />'; |
|
2627 | + } |
|
2560 | 2628 | $substr = 'null'; |
2561 | 2629 | $type = self::T_NULL; |
2562 | 2630 | } elseif (is_numeric($substr)) { |
@@ -2565,19 +2633,27 @@ discard block |
||
2565 | 2633 | $substr = (int) $substr; |
2566 | 2634 | } |
2567 | 2635 | $type = self::T_NUMERIC; |
2568 | - if ($this->debug) echo 'NUMBER ('.$substr.') PARSED<br />'; |
|
2636 | + if ($this->debug) { |
|
2637 | + echo 'NUMBER ('.$substr.') PARSED<br />'; |
|
2638 | + } |
|
2569 | 2639 | } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) { |
2570 | - if ($this->debug) echo 'SIMPLE MATH PARSED<br />'; |
|
2640 | + if ($this->debug) { |
|
2641 | + echo 'SIMPLE MATH PARSED<br />'; |
|
2642 | + } |
|
2571 | 2643 | $type = self::T_MATH; |
2572 | 2644 | $substr = '('.$substr.')'; |
2573 | 2645 | } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) { |
2574 | - if ($this->debug) echo 'BREAKCHAR ('.$substr.') PARSED<br />'; |
|
2646 | + if ($this->debug) { |
|
2647 | + echo 'BREAKCHAR ('.$substr.') PARSED<br />'; |
|
2648 | + } |
|
2575 | 2649 | $type = self::T_BREAKCHAR; |
2576 | 2650 | //$substr = '"'.$substr.'"'; |
2577 | 2651 | } else { |
2578 | 2652 | $substr = $this->replaceStringVars('\''.str_replace('\'', '\\\'', $substr).'\'', '\'', $curBlock); |
2579 | 2653 | $type = self::T_UNQUOTED_STRING; |
2580 | - if ($this->debug) echo 'BLABBER ('.$substr.') CASTED AS STRING<br />'; |
|
2654 | + if ($this->debug) { |
|
2655 | + echo 'BLABBER ('.$substr.') CASTED AS STRING<br />'; |
|
2656 | + } |
|
2581 | 2657 | } |
2582 | 2658 | |
2583 | 2659 | if (is_array($parsingParams)) { |
@@ -2603,7 +2679,9 @@ discard block |
||
2603 | 2679 | protected function replaceStringVars($string, $first, $curBlock='') |
2604 | 2680 | { |
2605 | 2681 | $pos = 0; |
2606 | - if ($this->debug) echo 'STRING VAR REPLACEMENT : '.$string.'<br>'; |
|
2682 | + if ($this->debug) { |
|
2683 | + echo 'STRING VAR REPLACEMENT : '.$string.'<br>'; |
|
2684 | + } |
|
2607 | 2685 | // replace vars |
2608 | 2686 | while (($pos = strpos($string, '$', $pos)) !== false) { |
2609 | 2687 | $prev = substr($string, $pos-1, 1); |
@@ -2622,7 +2700,9 @@ discard block |
||
2622 | 2700 | $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len); |
2623 | 2701 | } |
2624 | 2702 | $pos += strlen($var[1]) + 2; |
2625 | - if ($this->debug) echo 'STRING VAR REPLACEMENT DONE : '.$string.'<br>'; |
|
2703 | + if ($this->debug) { |
|
2704 | + echo 'STRING VAR REPLACEMENT DONE : '.$string.'<br>'; |
|
2705 | + } |
|
2626 | 2706 | } |
2627 | 2707 | |
2628 | 2708 | // handle modifiers |
@@ -2646,7 +2726,9 @@ discard block |
||
2646 | 2726 | */ |
2647 | 2727 | protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null) |
2648 | 2728 | { |
2649 | - if ($this->debug) echo 'PARSING MODIFIERS : '.$m[3].'<br />'; |
|
2729 | + if ($this->debug) { |
|
2730 | + echo 'PARSING MODIFIERS : '.$m[3].'<br />'; |
|
2731 | + } |
|
2650 | 2732 | |
2651 | 2733 | if ($pointer !== null) { |
2652 | 2734 | $pointer += strlen($m[3]); |
@@ -2668,7 +2750,9 @@ discard block |
||
2668 | 2750 | continue; |
2669 | 2751 | } |
2670 | 2752 | if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) { |
2671 | - if ($this->debug) echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND<br/>'; |
|
2753 | + if ($this->debug) { |
|
2754 | + echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND<br/>'; |
|
2755 | + } |
|
2672 | 2756 | $continue = false; |
2673 | 2757 | if ($pointer !== null) { |
2674 | 2758 | $pointer -= strlen($cmdstrsrc); |
@@ -2687,7 +2771,9 @@ discard block |
||
2687 | 2771 | if ($paramspos === false) { |
2688 | 2772 | $cmdstrsrc = substr($cmdstrsrc, strlen($func)); |
2689 | 2773 | $params = array(); |
2690 | - if ($this->debug) echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS<br/>'; |
|
2774 | + if ($this->debug) { |
|
2775 | + echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS<br/>'; |
|
2776 | + } |
|
2691 | 2777 | } else { |
2692 | 2778 | $paramstr = substr($cmdstr, $paramspos+1); |
2693 | 2779 | if (substr($paramstr, -1, 1) === $paramsep) { |
@@ -2697,18 +2783,28 @@ discard block |
||
2697 | 2783 | $ptr = 0; |
2698 | 2784 | $params = array(); |
2699 | 2785 | while ($ptr < strlen($paramstr)) { |
2700 | - if ($this->debug) echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; |
|
2701 | - if ($this->debug) echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier<br/>'; |
|
2786 | + if ($this->debug) { |
|
2787 | + echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; |
|
2788 | + } |
|
2789 | + if ($this->debug) { |
|
2790 | + echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier<br/>'; |
|
2791 | + } |
|
2702 | 2792 | $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr); |
2703 | - if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.'<br/>'; |
|
2793 | + if ($this->debug) { |
|
2794 | + echo 'PARAM PARSED, POINTER AT '.$ptr.'<br/>'; |
|
2795 | + } |
|
2704 | 2796 | |
2705 | 2797 | if ($ptr >= strlen($paramstr)) { |
2706 | - if ($this->debug) echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED<br/>'; |
|
2798 | + if ($this->debug) { |
|
2799 | + echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED<br/>'; |
|
2800 | + } |
|
2707 | 2801 | break; |
2708 | 2802 | } |
2709 | 2803 | |
2710 | 2804 | if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { |
2711 | - if ($this->debug) echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
2805 | + if ($this->debug) { |
|
2806 | + echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr.'<br/>'; |
|
2807 | + } |
|
2712 | 2808 | if ($paramstr[$ptr] !== '|') { |
2713 | 2809 | $continue = false; |
2714 | 2810 | if ($pointer !== null) { |
@@ -2769,8 +2865,9 @@ discard block |
||
2769 | 2865 | } |
2770 | 2866 | } elseif ($pluginType & Dwoo_Core::PROXY_PLUGIN) { |
2771 | 2867 | $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); |
2772 | - foreach ($params as &$p) |
|
2773 | - $p = $p[0]; |
|
2868 | + foreach ($params as &$p) { |
|
2869 | + $p = $p[0]; |
|
2870 | + } |
|
2774 | 2871 | $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); |
2775 | 2872 | } elseif ($pluginType & Dwoo_Core::SMARTY_MODIFIER) { |
2776 | 2873 | $params = $this->mapParams($params, null, $state); |
@@ -2812,8 +2909,9 @@ discard block |
||
2812 | 2909 | |
2813 | 2910 | $params = $this->mapParams($params, $callback, $state); |
2814 | 2911 | |
2815 | - foreach ($params as &$p) |
|
2816 | - $p = $p[0]; |
|
2912 | + foreach ($params as &$p) { |
|
2913 | + $p = $p[0]; |
|
2914 | + } |
|
2817 | 2915 | |
2818 | 2916 | if ($pluginType & Dwoo_Core::FUNC_PLUGIN) { |
2819 | 2917 | if ($pluginType & Dwoo_Core::COMPILABLE_PLUGIN) { |
@@ -2904,8 +3002,9 @@ discard block |
||
2904 | 3002 | foreach ($params as $k=>$p) { |
2905 | 3003 | if (is_array($p)) { |
2906 | 3004 | $out2 = 'array('; |
2907 | - foreach ($p as $k2=>$v) |
|
2908 | - $out2 .= var_export($k2, true).' => '.(is_array($v) ? 'array('.self::implode_r($v, true).')' : $v).', '; |
|
3005 | + foreach ($p as $k2=>$v) { |
|
3006 | + $out2 .= var_export($k2, true).' => '.(is_array($v) ? 'array('.self::implode_r($v, true).')' : $v).', '; |
|
3007 | + } |
|
2909 | 3008 | $p = rtrim($out2, ', ').')'; |
2910 | 3009 | } |
2911 | 3010 | if ($recursiveCall) { |
@@ -303,14 +303,14 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * returns the given template rendered using the provided data and optional compiler |
305 | 305 | * |
306 | - * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
306 | + * @param mixed $_tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
307 | 307 | * a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, |
308 | 308 | * especially if you render a template multiple times |
309 | 309 | * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're |
310 | 310 | * rendering the template from cache, it can be left null |
311 | - * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default |
|
311 | + * @param Dwoo_ICompiler $_compiler the compiler that must be used to compile the template, if left empty a default |
|
312 | 312 | * Dwoo_Compiler will be used. |
313 | - * @param bool $output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true) |
|
313 | + * @param bool $_output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true) |
|
314 | 314 | * @return string nothing or the template output if $output is false |
315 | 315 | */ |
316 | 316 | public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
@@ -1462,7 +1462,7 @@ discard block |
||
1462 | 1462 | * |
1463 | 1463 | * @param mixed $value the value to assign |
1464 | 1464 | * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
1465 | - * @return bool true if assigned correctly or false if a problem occured while parsing the var string |
|
1465 | + * @return null|false true if assigned correctly or false if a problem occured while parsing the var string |
|
1466 | 1466 | */ |
1467 | 1467 | public function assignInScope($value, $scope) |
1468 | 1468 | { |
@@ -31,23 +31,23 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class Dwoo_Core |
33 | 33 | { |
34 | - /** |
|
35 | - * current version number |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - const VERSION = '1.2.2'; |
|
40 | - |
|
41 | - /** |
|
42 | - * unique number of this dwoo release |
|
43 | - * |
|
44 | - * this can be used by templates classes to check whether the compiled template |
|
45 | - * has been compiled before this release or not, so that old templates are |
|
46 | - * recompiled automatically when Dwoo is updated |
|
47 | - */ |
|
48 | - const RELEASE_TAG = 17; |
|
49 | - |
|
50 | - /**#@+ |
|
34 | + /** |
|
35 | + * current version number |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + const VERSION = '1.2.2'; |
|
40 | + |
|
41 | + /** |
|
42 | + * unique number of this dwoo release |
|
43 | + * |
|
44 | + * this can be used by templates classes to check whether the compiled template |
|
45 | + * has been compiled before this release or not, so that old templates are |
|
46 | + * recompiled automatically when Dwoo is updated |
|
47 | + */ |
|
48 | + const RELEASE_TAG = 17; |
|
49 | + |
|
50 | + /**#@+ |
|
51 | 51 | * constants that represents all plugin types |
52 | 52 | * |
53 | 53 | * these are bitwise-operation-safe values to allow multiple types |
@@ -55,436 +55,436 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @var int |
57 | 57 | */ |
58 | - const CLASS_PLUGIN = 1; |
|
59 | - const FUNC_PLUGIN = 2; |
|
60 | - const NATIVE_PLUGIN = 4; |
|
61 | - const BLOCK_PLUGIN = 8; |
|
62 | - const COMPILABLE_PLUGIN = 16; |
|
63 | - const CUSTOM_PLUGIN = 32; |
|
64 | - const SMARTY_MODIFIER = 64; |
|
65 | - const SMARTY_BLOCK = 128; |
|
66 | - const SMARTY_FUNCTION = 256; |
|
67 | - const PROXY_PLUGIN = 512; |
|
68 | - const TEMPLATE_PLUGIN = 1024; |
|
69 | - /**#@-*/ |
|
70 | - |
|
71 | - /** |
|
72 | - * character set of the template, used by string manipulation plugins |
|
73 | - * |
|
74 | - * it must be lowercase, but setCharset() will take care of that |
|
75 | - * |
|
76 | - * @see setCharset |
|
77 | - * @see getCharset |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - protected $charset = 'utf-8'; |
|
81 | - |
|
82 | - /** |
|
83 | - * global variables that are accessible through $dwoo.* in the templates |
|
84 | - * |
|
85 | - * default values include: |
|
86 | - * |
|
87 | - * $dwoo.version - current version number |
|
88 | - * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org |
|
89 | - * $dwoo.now - the current time |
|
90 | - * $dwoo.template - the current template filename |
|
91 | - * $dwoo.charset - the character set used by the template |
|
92 | - * |
|
93 | - * on top of that, foreach and other plugins can store special values in there, |
|
94 | - * see their documentation for more details. |
|
95 | - * |
|
96 | - * @private |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - public $globals; |
|
100 | - |
|
101 | - /** |
|
102 | - * directory where the compiled templates are stored |
|
103 | - * |
|
104 | - * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default) |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $compileDir; |
|
109 | - |
|
110 | - /** |
|
111 | - * directory where the cached templates are stored |
|
112 | - * |
|
113 | - * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default) |
|
114 | - * |
|
115 | - * @var string |
|
116 | - */ |
|
117 | - protected $cacheDir; |
|
118 | - |
|
119 | - /** |
|
120 | - * defines how long (in seconds) the cached files must remain valid |
|
121 | - * |
|
122 | - * can be overriden on a per-template basis |
|
123 | - * |
|
124 | - * -1 = never delete |
|
125 | - * 0 = disabled |
|
126 | - * >0 = duration in seconds |
|
127 | - * |
|
128 | - * @var int |
|
129 | - */ |
|
130 | - protected $cacheTime = 0; |
|
131 | - |
|
132 | - /** |
|
133 | - * security policy object |
|
134 | - * |
|
135 | - * @var Dwoo_Security_Policy |
|
136 | - */ |
|
137 | - protected $securityPolicy = null; |
|
138 | - |
|
139 | - /** |
|
140 | - * stores the custom plugins callbacks |
|
141 | - * |
|
142 | - * @see addPlugin |
|
143 | - * @see removePlugin |
|
144 | - * @var array |
|
145 | - */ |
|
146 | - protected $plugins = array(); |
|
147 | - |
|
148 | - /** |
|
149 | - * stores the filter callbacks |
|
150 | - * |
|
151 | - * @see addFilter |
|
152 | - * @see removeFilter |
|
153 | - * @var array |
|
154 | - */ |
|
155 | - protected $filters = array(); |
|
156 | - |
|
157 | - /** |
|
158 | - * stores the resource types and associated |
|
159 | - * classes / compiler classes |
|
160 | - * |
|
161 | - * @var array |
|
162 | - */ |
|
163 | - protected $resources = array |
|
164 | - ( |
|
165 | - 'file' => array |
|
166 | - ( |
|
167 | - 'class' => 'Dwoo_Template_File', |
|
168 | - 'compiler' => null |
|
169 | - ), |
|
170 | - 'string' => array |
|
171 | - ( |
|
172 | - 'class' => 'Dwoo_Template_String', |
|
173 | - 'compiler' => null |
|
174 | - ) |
|
175 | - ); |
|
176 | - |
|
177 | - /** |
|
178 | - * the dwoo loader object used to load plugins by this dwoo instance |
|
179 | - * |
|
180 | - * @var Dwoo_ILoader |
|
181 | - */ |
|
182 | - protected $loader = null; |
|
183 | - |
|
184 | - /** |
|
185 | - * currently rendered template, set to null when not-rendering |
|
186 | - * |
|
187 | - * @var Dwoo_ITemplate |
|
188 | - */ |
|
189 | - protected $template = null; |
|
190 | - |
|
191 | - /** |
|
192 | - * stores the instances of the class plugins during template runtime |
|
193 | - * |
|
194 | - * @var array |
|
195 | - */ |
|
196 | - protected $runtimePlugins; |
|
197 | - |
|
198 | - /** |
|
199 | - * stores the returned values during template runtime |
|
200 | - * |
|
201 | - * @var array |
|
202 | - */ |
|
203 | - protected $returnData; |
|
204 | - |
|
205 | - /** |
|
206 | - * stores the data during template runtime |
|
207 | - * |
|
208 | - * @var array |
|
209 | - * @private |
|
210 | - */ |
|
211 | - public $data; |
|
212 | - |
|
213 | - /** |
|
214 | - * stores the current scope during template runtime |
|
215 | - * |
|
216 | - * this should ideally not be accessed directly from outside template code |
|
217 | - * |
|
218 | - * @var mixed |
|
219 | - * @private |
|
220 | - */ |
|
221 | - public $scope; |
|
222 | - |
|
223 | - /** |
|
224 | - * stores the scope tree during template runtime |
|
225 | - * |
|
226 | - * @var array |
|
227 | - */ |
|
228 | - protected $scopeTree; |
|
58 | + const CLASS_PLUGIN = 1; |
|
59 | + const FUNC_PLUGIN = 2; |
|
60 | + const NATIVE_PLUGIN = 4; |
|
61 | + const BLOCK_PLUGIN = 8; |
|
62 | + const COMPILABLE_PLUGIN = 16; |
|
63 | + const CUSTOM_PLUGIN = 32; |
|
64 | + const SMARTY_MODIFIER = 64; |
|
65 | + const SMARTY_BLOCK = 128; |
|
66 | + const SMARTY_FUNCTION = 256; |
|
67 | + const PROXY_PLUGIN = 512; |
|
68 | + const TEMPLATE_PLUGIN = 1024; |
|
69 | + /**#@-*/ |
|
70 | + |
|
71 | + /** |
|
72 | + * character set of the template, used by string manipulation plugins |
|
73 | + * |
|
74 | + * it must be lowercase, but setCharset() will take care of that |
|
75 | + * |
|
76 | + * @see setCharset |
|
77 | + * @see getCharset |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + protected $charset = 'utf-8'; |
|
81 | + |
|
82 | + /** |
|
83 | + * global variables that are accessible through $dwoo.* in the templates |
|
84 | + * |
|
85 | + * default values include: |
|
86 | + * |
|
87 | + * $dwoo.version - current version number |
|
88 | + * $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org |
|
89 | + * $dwoo.now - the current time |
|
90 | + * $dwoo.template - the current template filename |
|
91 | + * $dwoo.charset - the character set used by the template |
|
92 | + * |
|
93 | + * on top of that, foreach and other plugins can store special values in there, |
|
94 | + * see their documentation for more details. |
|
95 | + * |
|
96 | + * @private |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + public $globals; |
|
100 | + |
|
101 | + /** |
|
102 | + * directory where the compiled templates are stored |
|
103 | + * |
|
104 | + * defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default) |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $compileDir; |
|
109 | + |
|
110 | + /** |
|
111 | + * directory where the cached templates are stored |
|
112 | + * |
|
113 | + * defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default) |
|
114 | + * |
|
115 | + * @var string |
|
116 | + */ |
|
117 | + protected $cacheDir; |
|
118 | + |
|
119 | + /** |
|
120 | + * defines how long (in seconds) the cached files must remain valid |
|
121 | + * |
|
122 | + * can be overriden on a per-template basis |
|
123 | + * |
|
124 | + * -1 = never delete |
|
125 | + * 0 = disabled |
|
126 | + * >0 = duration in seconds |
|
127 | + * |
|
128 | + * @var int |
|
129 | + */ |
|
130 | + protected $cacheTime = 0; |
|
131 | + |
|
132 | + /** |
|
133 | + * security policy object |
|
134 | + * |
|
135 | + * @var Dwoo_Security_Policy |
|
136 | + */ |
|
137 | + protected $securityPolicy = null; |
|
138 | + |
|
139 | + /** |
|
140 | + * stores the custom plugins callbacks |
|
141 | + * |
|
142 | + * @see addPlugin |
|
143 | + * @see removePlugin |
|
144 | + * @var array |
|
145 | + */ |
|
146 | + protected $plugins = array(); |
|
147 | + |
|
148 | + /** |
|
149 | + * stores the filter callbacks |
|
150 | + * |
|
151 | + * @see addFilter |
|
152 | + * @see removeFilter |
|
153 | + * @var array |
|
154 | + */ |
|
155 | + protected $filters = array(); |
|
156 | + |
|
157 | + /** |
|
158 | + * stores the resource types and associated |
|
159 | + * classes / compiler classes |
|
160 | + * |
|
161 | + * @var array |
|
162 | + */ |
|
163 | + protected $resources = array |
|
164 | + ( |
|
165 | + 'file' => array |
|
166 | + ( |
|
167 | + 'class' => 'Dwoo_Template_File', |
|
168 | + 'compiler' => null |
|
169 | + ), |
|
170 | + 'string' => array |
|
171 | + ( |
|
172 | + 'class' => 'Dwoo_Template_String', |
|
173 | + 'compiler' => null |
|
174 | + ) |
|
175 | + ); |
|
176 | + |
|
177 | + /** |
|
178 | + * the dwoo loader object used to load plugins by this dwoo instance |
|
179 | + * |
|
180 | + * @var Dwoo_ILoader |
|
181 | + */ |
|
182 | + protected $loader = null; |
|
183 | + |
|
184 | + /** |
|
185 | + * currently rendered template, set to null when not-rendering |
|
186 | + * |
|
187 | + * @var Dwoo_ITemplate |
|
188 | + */ |
|
189 | + protected $template = null; |
|
190 | + |
|
191 | + /** |
|
192 | + * stores the instances of the class plugins during template runtime |
|
193 | + * |
|
194 | + * @var array |
|
195 | + */ |
|
196 | + protected $runtimePlugins; |
|
197 | + |
|
198 | + /** |
|
199 | + * stores the returned values during template runtime |
|
200 | + * |
|
201 | + * @var array |
|
202 | + */ |
|
203 | + protected $returnData; |
|
204 | + |
|
205 | + /** |
|
206 | + * stores the data during template runtime |
|
207 | + * |
|
208 | + * @var array |
|
209 | + * @private |
|
210 | + */ |
|
211 | + public $data; |
|
212 | + |
|
213 | + /** |
|
214 | + * stores the current scope during template runtime |
|
215 | + * |
|
216 | + * this should ideally not be accessed directly from outside template code |
|
217 | + * |
|
218 | + * @var mixed |
|
219 | + * @private |
|
220 | + */ |
|
221 | + public $scope; |
|
222 | + |
|
223 | + /** |
|
224 | + * stores the scope tree during template runtime |
|
225 | + * |
|
226 | + * @var array |
|
227 | + */ |
|
228 | + protected $scopeTree; |
|
229 | + |
|
230 | + /** |
|
231 | + * stores the block plugins stack during template runtime |
|
232 | + * |
|
233 | + * @var array |
|
234 | + */ |
|
235 | + protected $stack; |
|
236 | + |
|
237 | + /** |
|
238 | + * stores the current block plugin at the top of the stack during template runtime |
|
239 | + * |
|
240 | + * @var Dwoo_Block_Plugin |
|
241 | + */ |
|
242 | + protected $curBlock; |
|
243 | + |
|
244 | + /** |
|
245 | + * stores the output buffer during template runtime |
|
246 | + * |
|
247 | + * @var string |
|
248 | + */ |
|
249 | + protected $buffer; |
|
250 | + |
|
251 | + /** |
|
252 | + * stores plugin proxy |
|
253 | + * |
|
254 | + * @var Dwoo_IPluginProxy |
|
255 | + */ |
|
256 | + protected $pluginProxy; |
|
257 | + |
|
258 | + /** |
|
259 | + * constructor, sets the cache and compile dir to the default values if not provided |
|
260 | + * |
|
261 | + * @param string $compileDir path to the compiled directory, defaults to lib/compiled |
|
262 | + * @param string $cacheDir path to the cache directory, defaults to lib/cache |
|
263 | + */ |
|
264 | + public function __construct($compileDir = null, $cacheDir = null) |
|
265 | + { |
|
266 | + if ($compileDir !== null) { |
|
267 | + $this->setCompileDir($compileDir); |
|
268 | + } |
|
269 | + if ($cacheDir !== null) { |
|
270 | + $this->setCacheDir($cacheDir); |
|
271 | + } |
|
272 | + $this->initGlobals(); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * resets some runtime variables to allow a cloned object to be used to render sub-templates |
|
277 | + */ |
|
278 | + public function __clone() |
|
279 | + { |
|
280 | + $this->template = null; |
|
281 | + unset($this->data); |
|
282 | + unset($this->returnData); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true) |
|
287 | + * |
|
288 | + * @see get |
|
289 | + * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
290 | + * a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, |
|
291 | + * especially if you render a template multiple times |
|
292 | + * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're |
|
293 | + * rendering the template from cache, it can be left null |
|
294 | + * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default |
|
295 | + * Dwoo_Compiler will be used. |
|
296 | + * @return string nothing or the template output if $output is true |
|
297 | + */ |
|
298 | + public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null) |
|
299 | + { |
|
300 | + return $this->get($tpl, $data, $compiler, true); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * returns the given template rendered using the provided data and optional compiler |
|
305 | + * |
|
306 | + * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
307 | + * a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, |
|
308 | + * especially if you render a template multiple times |
|
309 | + * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're |
|
310 | + * rendering the template from cache, it can be left null |
|
311 | + * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default |
|
312 | + * Dwoo_Compiler will be used. |
|
313 | + * @param bool $output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true) |
|
314 | + * @return string nothing or the template output if $output is false |
|
315 | + */ |
|
316 | + public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
317 | + { |
|
318 | + // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one |
|
319 | + if ($this->template instanceof Dwoo_ITemplate) { |
|
320 | + $clone = clone $this; |
|
321 | + return $clone->get($_tpl, $data, $_compiler, $_output); |
|
322 | + } |
|
323 | + |
|
324 | + // auto-create template if required |
|
325 | + if ($_tpl instanceof Dwoo_ITemplate) { |
|
326 | + // valid, skip |
|
327 | + } elseif (is_string($_tpl) && file_exists($_tpl)) { |
|
328 | + $_tpl = new Dwoo_Template_File($_tpl); |
|
329 | + } else { |
|
330 | + throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE); |
|
331 | + } |
|
332 | + |
|
333 | + // save the current template, enters render mode at the same time |
|
334 | + // if another rendering is requested it will be proxied to a new Dwoo_Core(instance |
|
335 | + $this->template = $_tpl; |
|
336 | + |
|
337 | + // load data |
|
338 | + if ($data instanceof Dwoo_IDataProvider) { |
|
339 | + $this->data = $data->getData(); |
|
340 | + } elseif (is_array($data)) { |
|
341 | + $this->data = $data; |
|
342 | + } elseif ($data instanceof ArrayAccess) { |
|
343 | + $this->data = $data; |
|
344 | + } else { |
|
345 | + throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE); |
|
346 | + } |
|
347 | + |
|
348 | + $this->globals['template'] = $_tpl->getName(); |
|
349 | + $this->initRuntimeVars($_tpl); |
|
350 | + |
|
351 | + // try to get cached template |
|
352 | + $file = $_tpl->getCachedTemplate($this); |
|
353 | + $doCache = $file === true; |
|
354 | + $cacheLoaded = is_string($file); |
|
355 | + |
|
356 | + if ($cacheLoaded === true) { |
|
357 | + // cache is present, run it |
|
358 | + if ($_output === true) { |
|
359 | + include $file; |
|
360 | + $this->template = null; |
|
361 | + } else { |
|
362 | + ob_start(); |
|
363 | + include $file; |
|
364 | + $this->template = null; |
|
365 | + return ob_get_clean(); |
|
366 | + } |
|
367 | + } else { |
|
368 | + // no cache present |
|
369 | + if ($doCache === true) { |
|
370 | + $dynamicId = uniqid(); |
|
371 | + } |
|
229 | 372 | |
230 | - /** |
|
231 | - * stores the block plugins stack during template runtime |
|
232 | - * |
|
233 | - * @var array |
|
234 | - */ |
|
235 | - protected $stack; |
|
373 | + // render template |
|
374 | + $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); |
|
375 | + $out = include $compiledTemplate; |
|
236 | 376 | |
237 | - /** |
|
238 | - * stores the current block plugin at the top of the stack during template runtime |
|
239 | - * |
|
240 | - * @var Dwoo_Block_Plugin |
|
241 | - */ |
|
242 | - protected $curBlock; |
|
377 | + // template returned false so it needs to be recompiled |
|
378 | + if ($out === false) { |
|
379 | + $_tpl->forceCompilation(); |
|
380 | + $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); |
|
381 | + $out = include $compiledTemplate; |
|
382 | + } |
|
243 | 383 | |
244 | - /** |
|
245 | - * stores the output buffer during template runtime |
|
246 | - * |
|
247 | - * @var string |
|
248 | - */ |
|
249 | - protected $buffer; |
|
384 | + if ($doCache === true) { |
|
385 | + $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out); |
|
386 | + if (!class_exists('Dwoo_plugin_dynamic', false)) { |
|
387 | + $this->getLoader()->loadPlugin('dynamic'); |
|
388 | + } |
|
389 | + $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate); |
|
390 | + } |
|
250 | 391 | |
251 | - /** |
|
252 | - * stores plugin proxy |
|
253 | - * |
|
254 | - * @var Dwoo_IPluginProxy |
|
255 | - */ |
|
256 | - protected $pluginProxy; |
|
392 | + // process filters |
|
393 | + foreach ($this->filters as $filter) { |
|
394 | + if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) { |
|
395 | + $out = call_user_func($filter, $out); |
|
396 | + } else { |
|
397 | + $out = call_user_func($filter, $this, $out); |
|
398 | + } |
|
399 | + } |
|
257 | 400 | |
258 | - /** |
|
259 | - * constructor, sets the cache and compile dir to the default values if not provided |
|
260 | - * |
|
261 | - * @param string $compileDir path to the compiled directory, defaults to lib/compiled |
|
262 | - * @param string $cacheDir path to the cache directory, defaults to lib/cache |
|
263 | - */ |
|
264 | - public function __construct($compileDir = null, $cacheDir = null) |
|
265 | - { |
|
266 | - if ($compileDir !== null) { |
|
267 | - $this->setCompileDir($compileDir); |
|
268 | - } |
|
269 | - if ($cacheDir !== null) { |
|
270 | - $this->setCacheDir($cacheDir); |
|
271 | - } |
|
272 | - $this->initGlobals(); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * resets some runtime variables to allow a cloned object to be used to render sub-templates |
|
277 | - */ |
|
278 | - public function __clone() |
|
279 | - { |
|
280 | - $this->template = null; |
|
281 | - unset($this->data); |
|
282 | - unset($this->returnData); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true) |
|
287 | - * |
|
288 | - * @see get |
|
289 | - * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
290 | - * a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, |
|
291 | - * especially if you render a template multiple times |
|
292 | - * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're |
|
293 | - * rendering the template from cache, it can be left null |
|
294 | - * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default |
|
295 | - * Dwoo_Compiler will be used. |
|
296 | - * @return string nothing or the template output if $output is true |
|
297 | - */ |
|
298 | - public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null) |
|
299 | - { |
|
300 | - return $this->get($tpl, $data, $compiler, true); |
|
301 | - } |
|
401 | + if ($doCache === true) { |
|
402 | + // building cache |
|
403 | + $file = $_tpl->cache($this, $out); |
|
302 | 404 | |
303 | - /** |
|
304 | - * returns the given template rendered using the provided data and optional compiler |
|
305 | - * |
|
306 | - * @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or |
|
307 | - * a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, |
|
308 | - * especially if you render a template multiple times |
|
309 | - * @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're |
|
310 | - * rendering the template from cache, it can be left null |
|
311 | - * @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default |
|
312 | - * Dwoo_Compiler will be used. |
|
313 | - * @param bool $output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true) |
|
314 | - * @return string nothing or the template output if $output is false |
|
315 | - */ |
|
316 | - public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
317 | - { |
|
318 | - // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one |
|
319 | - if ($this->template instanceof Dwoo_ITemplate) { |
|
320 | - $clone = clone $this; |
|
321 | - return $clone->get($_tpl, $data, $_compiler, $_output); |
|
322 | - } |
|
323 | - |
|
324 | - // auto-create template if required |
|
325 | - if ($_tpl instanceof Dwoo_ITemplate) { |
|
326 | - // valid, skip |
|
327 | - } elseif (is_string($_tpl) && file_exists($_tpl)) { |
|
328 | - $_tpl = new Dwoo_Template_File($_tpl); |
|
329 | - } else { |
|
330 | - throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE); |
|
331 | - } |
|
332 | - |
|
333 | - // save the current template, enters render mode at the same time |
|
334 | - // if another rendering is requested it will be proxied to a new Dwoo_Core(instance |
|
335 | - $this->template = $_tpl; |
|
336 | - |
|
337 | - // load data |
|
338 | - if ($data instanceof Dwoo_IDataProvider) { |
|
339 | - $this->data = $data->getData(); |
|
340 | - } elseif (is_array($data)) { |
|
341 | - $this->data = $data; |
|
342 | - } elseif ($data instanceof ArrayAccess) { |
|
343 | - $this->data = $data; |
|
344 | - } else { |
|
345 | - throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE); |
|
346 | - } |
|
347 | - |
|
348 | - $this->globals['template'] = $_tpl->getName(); |
|
349 | - $this->initRuntimeVars($_tpl); |
|
350 | - |
|
351 | - // try to get cached template |
|
352 | - $file = $_tpl->getCachedTemplate($this); |
|
353 | - $doCache = $file === true; |
|
354 | - $cacheLoaded = is_string($file); |
|
355 | - |
|
356 | - if ($cacheLoaded === true) { |
|
357 | - // cache is present, run it |
|
358 | - if ($_output === true) { |
|
359 | - include $file; |
|
360 | - $this->template = null; |
|
361 | - } else { |
|
362 | - ob_start(); |
|
363 | - include $file; |
|
364 | - $this->template = null; |
|
365 | - return ob_get_clean(); |
|
366 | - } |
|
367 | - } else { |
|
368 | - // no cache present |
|
369 | - if ($doCache === true) { |
|
370 | - $dynamicId = uniqid(); |
|
371 | - } |
|
372 | - |
|
373 | - // render template |
|
374 | - $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); |
|
375 | - $out = include $compiledTemplate; |
|
376 | - |
|
377 | - // template returned false so it needs to be recompiled |
|
378 | - if ($out === false) { |
|
379 | - $_tpl->forceCompilation(); |
|
380 | - $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); |
|
381 | - $out = include $compiledTemplate; |
|
382 | - } |
|
383 | - |
|
384 | - if ($doCache === true) { |
|
385 | - $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out); |
|
386 | - if (!class_exists('Dwoo_plugin_dynamic', false)) { |
|
387 | - $this->getLoader()->loadPlugin('dynamic'); |
|
388 | - } |
|
389 | - $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate); |
|
390 | - } |
|
391 | - |
|
392 | - // process filters |
|
393 | - foreach ($this->filters as $filter) { |
|
394 | - if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) { |
|
395 | - $out = call_user_func($filter, $out); |
|
396 | - } else { |
|
397 | - $out = call_user_func($filter, $this, $out); |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - if ($doCache === true) { |
|
402 | - // building cache |
|
403 | - $file = $_tpl->cache($this, $out); |
|
404 | - |
|
405 | - // run it from the cache to be sure dynamics are rendered |
|
406 | - if ($_output === true) { |
|
407 | - include $file; |
|
408 | - // exit render mode |
|
409 | - $this->template = null; |
|
410 | - } else { |
|
411 | - ob_start(); |
|
412 | - include $file; |
|
413 | - // exit render mode |
|
414 | - $this->template = null; |
|
415 | - return ob_get_clean(); |
|
416 | - } |
|
417 | - } else { |
|
418 | - // no need to build cache |
|
419 | - // exit render mode |
|
420 | - $this->template = null; |
|
421 | - // output |
|
422 | - if ($_output === true) { |
|
423 | - echo $out; |
|
424 | - } |
|
425 | - return $out; |
|
426 | - } |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * re-initializes the globals array before each template run |
|
432 | - * |
|
433 | - * this method is only callede once when the Dwoo object is created |
|
434 | - */ |
|
435 | - protected function initGlobals() |
|
436 | - { |
|
437 | - $this->globals = array |
|
438 | - ( |
|
439 | - 'version' => self::VERSION, |
|
440 | - 'ad' => '<a href="http://dwoo.org/">Powered by Dwoo</a>', |
|
441 | - 'now' => $_SERVER['REQUEST_TIME'], |
|
442 | - 'charset' => $this->charset, |
|
443 | - ); |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * re-initializes the runtime variables before each template run |
|
448 | - * |
|
449 | - * override this method to inject data in the globals array if needed, this |
|
450 | - * method is called before each template execution |
|
451 | - * |
|
452 | - * @param Dwoo_ITemplate $tpl the template that is going to be rendered |
|
453 | - */ |
|
454 | - protected function initRuntimeVars(Dwoo_ITemplate $tpl) |
|
455 | - { |
|
456 | - $this->runtimePlugins = array(); |
|
457 | - $this->scope =& $this->data; |
|
458 | - $this->scopeTree = array(); |
|
459 | - $this->stack = array(); |
|
460 | - $this->curBlock = null; |
|
461 | - $this->buffer = ''; |
|
462 | - $this->returnData = array(); |
|
463 | - } |
|
464 | - |
|
465 | - /* |
|
405 | + // run it from the cache to be sure dynamics are rendered |
|
406 | + if ($_output === true) { |
|
407 | + include $file; |
|
408 | + // exit render mode |
|
409 | + $this->template = null; |
|
410 | + } else { |
|
411 | + ob_start(); |
|
412 | + include $file; |
|
413 | + // exit render mode |
|
414 | + $this->template = null; |
|
415 | + return ob_get_clean(); |
|
416 | + } |
|
417 | + } else { |
|
418 | + // no need to build cache |
|
419 | + // exit render mode |
|
420 | + $this->template = null; |
|
421 | + // output |
|
422 | + if ($_output === true) { |
|
423 | + echo $out; |
|
424 | + } |
|
425 | + return $out; |
|
426 | + } |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * re-initializes the globals array before each template run |
|
432 | + * |
|
433 | + * this method is only callede once when the Dwoo object is created |
|
434 | + */ |
|
435 | + protected function initGlobals() |
|
436 | + { |
|
437 | + $this->globals = array |
|
438 | + ( |
|
439 | + 'version' => self::VERSION, |
|
440 | + 'ad' => '<a href="http://dwoo.org/">Powered by Dwoo</a>', |
|
441 | + 'now' => $_SERVER['REQUEST_TIME'], |
|
442 | + 'charset' => $this->charset, |
|
443 | + ); |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * re-initializes the runtime variables before each template run |
|
448 | + * |
|
449 | + * override this method to inject data in the globals array if needed, this |
|
450 | + * method is called before each template execution |
|
451 | + * |
|
452 | + * @param Dwoo_ITemplate $tpl the template that is going to be rendered |
|
453 | + */ |
|
454 | + protected function initRuntimeVars(Dwoo_ITemplate $tpl) |
|
455 | + { |
|
456 | + $this->runtimePlugins = array(); |
|
457 | + $this->scope =& $this->data; |
|
458 | + $this->scopeTree = array(); |
|
459 | + $this->stack = array(); |
|
460 | + $this->curBlock = null; |
|
461 | + $this->buffer = ''; |
|
462 | + $this->returnData = array(); |
|
463 | + } |
|
464 | + |
|
465 | + /* |
|
466 | 466 | * --------- settings functions --------- |
467 | 467 | */ |
468 | 468 | |
469 | - /** |
|
470 | - * adds a custom plugin that is not in one of the plugin directories |
|
471 | - * |
|
472 | - * @param string $name the plugin name to be used in the templates |
|
473 | - * @param callback $callback the plugin callback, either a function name, |
|
474 | - * a class name or an array containing an object |
|
475 | - * or class name and a method name |
|
476 | - * @param bool $compilable if set to true, the plugin is assumed to be compilable |
|
477 | - */ |
|
478 | - public function addPlugin($name, $callback, $compilable = false) |
|
479 | - { |
|
480 | - $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0; |
|
481 | - if (is_array($callback)) { |
|
482 | - if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) { |
|
483 | - $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0])); |
|
484 | - } else { |
|
485 | - $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]); |
|
486 | - } |
|
487 | - } elseif(is_string($callback)) { |
|
469 | + /** |
|
470 | + * adds a custom plugin that is not in one of the plugin directories |
|
471 | + * |
|
472 | + * @param string $name the plugin name to be used in the templates |
|
473 | + * @param callback $callback the plugin callback, either a function name, |
|
474 | + * a class name or an array containing an object |
|
475 | + * or class name and a method name |
|
476 | + * @param bool $compilable if set to true, the plugin is assumed to be compilable |
|
477 | + */ |
|
478 | + public function addPlugin($name, $callback, $compilable = false) |
|
479 | + { |
|
480 | + $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0; |
|
481 | + if (is_array($callback)) { |
|
482 | + if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) { |
|
483 | + $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0])); |
|
484 | + } else { |
|
485 | + $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]); |
|
486 | + } |
|
487 | + } elseif(is_string($callback)) { |
|
488 | 488 | if (class_exists($callback, false)) { |
489 | 489 | if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) { |
490 | 490 | $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback); |
@@ -499,1120 +499,1120 @@ discard block |
||
499 | 499 | } elseif(is_callable($callback)) { |
500 | 500 | $this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback); |
501 | 501 | } else { |
502 | - throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * removes a custom plugin |
|
508 | - * |
|
509 | - * @param string $name the plugin name |
|
510 | - */ |
|
511 | - public function removePlugin($name) |
|
512 | - { |
|
513 | - if (isset($this->plugins[$name])) { |
|
514 | - unset($this->plugins[$name]); |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this instance |
|
520 | - * |
|
521 | - * @param mixed $callback a callback or a filter name if it is autoloaded from a plugin directory |
|
522 | - * @param bool $autoload if true, the first parameter must be a filter name from one of the plugin directories |
|
523 | - */ |
|
524 | - public function addFilter($callback, $autoload = false) |
|
525 | - { |
|
526 | - if ($autoload) { |
|
527 | - $class = 'Dwoo_Filter_'.$callback; |
|
528 | - |
|
529 | - if (!class_exists($class, false) && !function_exists($class)) { |
|
530 | - try { |
|
531 | - $this->getLoader()->loadPlugin($callback); |
|
532 | - } catch (Dwoo_Exception $e) { |
|
533 | - if (strstr($callback, 'Dwoo_Filter_')) { |
|
534 | - throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"'); |
|
535 | - } else { |
|
536 | - throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); |
|
537 | - } |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - if (class_exists($class, false)) { |
|
542 | - $callback = array(new $class($this), 'process'); |
|
543 | - } elseif (function_exists($class)) { |
|
544 | - $callback = $class; |
|
545 | - } else { |
|
546 | - throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); |
|
547 | - } |
|
548 | - |
|
549 | - $this->filters[] = $callback; |
|
550 | - } else { |
|
551 | - $this->filters[] = $callback; |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * removes a filter |
|
557 | - * |
|
558 | - * @param mixed $callback callback or filter name if it was autoloaded |
|
559 | - */ |
|
560 | - public function removeFilter($callback) |
|
561 | - { |
|
562 | - if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) { |
|
563 | - unset($this->filters[$index]); |
|
564 | - } elseif (($index = array_search($callback, $this->filters, true)) !== false) { |
|
565 | - unset($this->filters[$index]); |
|
566 | - } else { |
|
567 | - $class = 'Dwoo_Filter_' . $callback; |
|
568 | - foreach ($this->filters as $index=>$filter) { |
|
569 | - if (is_array($filter) && $filter[0] instanceof $class) { |
|
570 | - unset($this->filters[$index]); |
|
571 | - break; |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * adds a resource or overrides a default one |
|
579 | - * |
|
580 | - * @param string $name the resource name |
|
581 | - * @param string $class the resource class (which must implement Dwoo_ITemplate) |
|
582 | - * @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance used to compile this resource, if none is provided. by default it will produce a Dwoo_Compiler object |
|
583 | - */ |
|
584 | - public function addResource($name, $class, $compilerFactory = null) |
|
585 | - { |
|
586 | - if (strlen($name) < 2) { |
|
587 | - throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths'); |
|
588 | - } |
|
589 | - |
|
590 | - if (!class_exists($class)) { |
|
591 | - throw new Dwoo_Exception('Resource class does not exist'); |
|
592 | - } |
|
593 | - |
|
594 | - $interfaces = class_implements($class); |
|
595 | - if (in_array('Dwoo_ITemplate', $interfaces) === false) { |
|
596 | - throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate'); |
|
597 | - } |
|
598 | - |
|
599 | - $this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * removes a custom resource |
|
604 | - * |
|
605 | - * @param string $name the resource name |
|
606 | - */ |
|
607 | - public function removeResource($name) |
|
608 | - { |
|
609 | - unset($this->resources[$name]); |
|
610 | - if ($name==='file') { |
|
611 | - $this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null); |
|
612 | - } |
|
613 | - } |
|
614 | - |
|
615 | - /* |
|
616 | - * --------- getters and setters --------- |
|
617 | - */ |
|
618 | - |
|
619 | - /** |
|
620 | - * sets the loader object to use to load plugins |
|
621 | - * |
|
622 | - * @param Dwoo_ILoader $loader loader object |
|
623 | - */ |
|
624 | - public function setLoader(Dwoo_ILoader $loader) |
|
625 | - { |
|
626 | - $this->loader = $loader; |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * returns the current loader object or a default one if none is currently found |
|
631 | - * |
|
632 | - * @param Dwoo_ILoader |
|
633 | - */ |
|
634 | - public function getLoader() |
|
635 | - { |
|
636 | - if ($this->loader === null) { |
|
637 | - $this->loader = new Dwoo_Loader($this->getCompileDir()); |
|
638 | - } |
|
639 | - |
|
640 | - return $this->loader; |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * returns the custom plugins loaded |
|
645 | - * |
|
646 | - * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance |
|
647 | - * |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - public function getCustomPlugins() |
|
651 | - { |
|
652 | - return $this->plugins; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * returns the cache directory with a trailing DIRECTORY_SEPARATOR |
|
657 | - * |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public function getCacheDir() |
|
661 | - { |
|
662 | - if ($this->cacheDir === null) { |
|
663 | - $this->setCacheDir(DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR); |
|
664 | - } |
|
502 | + throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * removes a custom plugin |
|
508 | + * |
|
509 | + * @param string $name the plugin name |
|
510 | + */ |
|
511 | + public function removePlugin($name) |
|
512 | + { |
|
513 | + if (isset($this->plugins[$name])) { |
|
514 | + unset($this->plugins[$name]); |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this instance |
|
520 | + * |
|
521 | + * @param mixed $callback a callback or a filter name if it is autoloaded from a plugin directory |
|
522 | + * @param bool $autoload if true, the first parameter must be a filter name from one of the plugin directories |
|
523 | + */ |
|
524 | + public function addFilter($callback, $autoload = false) |
|
525 | + { |
|
526 | + if ($autoload) { |
|
527 | + $class = 'Dwoo_Filter_'.$callback; |
|
528 | + |
|
529 | + if (!class_exists($class, false) && !function_exists($class)) { |
|
530 | + try { |
|
531 | + $this->getLoader()->loadPlugin($callback); |
|
532 | + } catch (Dwoo_Exception $e) { |
|
533 | + if (strstr($callback, 'Dwoo_Filter_')) { |
|
534 | + throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"'); |
|
535 | + } else { |
|
536 | + throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); |
|
537 | + } |
|
538 | + } |
|
539 | + } |
|
665 | 540 | |
666 | - return $this->cacheDir; |
|
667 | - } |
|
541 | + if (class_exists($class, false)) { |
|
542 | + $callback = array(new $class($this), 'process'); |
|
543 | + } elseif (function_exists($class)) { |
|
544 | + $callback = $class; |
|
545 | + } else { |
|
546 | + throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); |
|
547 | + } |
|
668 | 548 | |
669 | - /** |
|
670 | - * sets the cache directory and automatically appends a DIRECTORY_SEPARATOR |
|
671 | - * |
|
672 | - * @param string $dir the cache directory |
|
673 | - */ |
|
674 | - public function setCacheDir($dir) |
|
675 | - { |
|
676 | - $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; |
|
677 | - if (is_writable($this->cacheDir) === false) { |
|
678 | - throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable'); |
|
679 | - } |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * returns the compile directory with a trailing DIRECTORY_SEPARATOR |
|
684 | - * |
|
685 | - * @return string |
|
549 | + $this->filters[] = $callback; |
|
550 | + } else { |
|
551 | + $this->filters[] = $callback; |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * removes a filter |
|
557 | + * |
|
558 | + * @param mixed $callback callback or filter name if it was autoloaded |
|
559 | + */ |
|
560 | + public function removeFilter($callback) |
|
561 | + { |
|
562 | + if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) { |
|
563 | + unset($this->filters[$index]); |
|
564 | + } elseif (($index = array_search($callback, $this->filters, true)) !== false) { |
|
565 | + unset($this->filters[$index]); |
|
566 | + } else { |
|
567 | + $class = 'Dwoo_Filter_' . $callback; |
|
568 | + foreach ($this->filters as $index=>$filter) { |
|
569 | + if (is_array($filter) && $filter[0] instanceof $class) { |
|
570 | + unset($this->filters[$index]); |
|
571 | + break; |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * adds a resource or overrides a default one |
|
579 | + * |
|
580 | + * @param string $name the resource name |
|
581 | + * @param string $class the resource class (which must implement Dwoo_ITemplate) |
|
582 | + * @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance used to compile this resource, if none is provided. by default it will produce a Dwoo_Compiler object |
|
583 | + */ |
|
584 | + public function addResource($name, $class, $compilerFactory = null) |
|
585 | + { |
|
586 | + if (strlen($name) < 2) { |
|
587 | + throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths'); |
|
588 | + } |
|
589 | + |
|
590 | + if (!class_exists($class)) { |
|
591 | + throw new Dwoo_Exception('Resource class does not exist'); |
|
592 | + } |
|
593 | + |
|
594 | + $interfaces = class_implements($class); |
|
595 | + if (in_array('Dwoo_ITemplate', $interfaces) === false) { |
|
596 | + throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate'); |
|
597 | + } |
|
598 | + |
|
599 | + $this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory); |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * removes a custom resource |
|
604 | + * |
|
605 | + * @param string $name the resource name |
|
606 | + */ |
|
607 | + public function removeResource($name) |
|
608 | + { |
|
609 | + unset($this->resources[$name]); |
|
610 | + if ($name==='file') { |
|
611 | + $this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null); |
|
612 | + } |
|
613 | + } |
|
614 | + |
|
615 | + /* |
|
616 | + * --------- getters and setters --------- |
|
686 | 617 | */ |
687 | - public function getCompileDir() |
|
688 | - { |
|
689 | - if ($this->compileDir === null) { |
|
690 | - $this->setCompileDir(DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR); |
|
691 | - } |
|
692 | - |
|
693 | - return $this->compileDir; |
|
694 | - } |
|
695 | 618 | |
696 | - /** |
|
697 | - * sets the compile directory and automatically appends a DIRECTORY_SEPARATOR |
|
698 | - * |
|
699 | - * @param string $dir the compile directory |
|
700 | - */ |
|
701 | - public function setCompileDir($dir) |
|
702 | - { |
|
703 | - $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; |
|
704 | - if (is_writable($this->compileDir) === false) { |
|
705 | - throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable'); |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * returns the default cache time that is used with templates that do not have a cache time set |
|
711 | - * |
|
712 | - * @return int the duration in seconds |
|
619 | + /** |
|
620 | + * sets the loader object to use to load plugins |
|
621 | + * |
|
622 | + * @param Dwoo_ILoader $loader loader object |
|
623 | + */ |
|
624 | + public function setLoader(Dwoo_ILoader $loader) |
|
625 | + { |
|
626 | + $this->loader = $loader; |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * returns the current loader object or a default one if none is currently found |
|
631 | + * |
|
632 | + * @param Dwoo_ILoader |
|
633 | + */ |
|
634 | + public function getLoader() |
|
635 | + { |
|
636 | + if ($this->loader === null) { |
|
637 | + $this->loader = new Dwoo_Loader($this->getCompileDir()); |
|
638 | + } |
|
639 | + |
|
640 | + return $this->loader; |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * returns the custom plugins loaded |
|
645 | + * |
|
646 | + * used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance |
|
647 | + * |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + public function getCustomPlugins() |
|
651 | + { |
|
652 | + return $this->plugins; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * returns the cache directory with a trailing DIRECTORY_SEPARATOR |
|
657 | + * |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public function getCacheDir() |
|
661 | + { |
|
662 | + if ($this->cacheDir === null) { |
|
663 | + $this->setCacheDir(DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR); |
|
664 | + } |
|
665 | + |
|
666 | + return $this->cacheDir; |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * sets the cache directory and automatically appends a DIRECTORY_SEPARATOR |
|
671 | + * |
|
672 | + * @param string $dir the cache directory |
|
673 | + */ |
|
674 | + public function setCacheDir($dir) |
|
675 | + { |
|
676 | + $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; |
|
677 | + if (is_writable($this->cacheDir) === false) { |
|
678 | + throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable'); |
|
679 | + } |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * returns the compile directory with a trailing DIRECTORY_SEPARATOR |
|
684 | + * |
|
685 | + * @return string |
|
686 | + */ |
|
687 | + public function getCompileDir() |
|
688 | + { |
|
689 | + if ($this->compileDir === null) { |
|
690 | + $this->setCompileDir(DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR); |
|
691 | + } |
|
692 | + |
|
693 | + return $this->compileDir; |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * sets the compile directory and automatically appends a DIRECTORY_SEPARATOR |
|
698 | + * |
|
699 | + * @param string $dir the compile directory |
|
700 | + */ |
|
701 | + public function setCompileDir($dir) |
|
702 | + { |
|
703 | + $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; |
|
704 | + if (is_writable($this->compileDir) === false) { |
|
705 | + throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable'); |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * returns the default cache time that is used with templates that do not have a cache time set |
|
711 | + * |
|
712 | + * @return int the duration in seconds |
|
713 | + */ |
|
714 | + public function getCacheTime() |
|
715 | + { |
|
716 | + return $this->cacheTime; |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * sets the default cache time to use with templates that do not have a cache time set |
|
721 | + * |
|
722 | + * @param int $seconds the duration in seconds |
|
723 | + */ |
|
724 | + public function setCacheTime($seconds) |
|
725 | + { |
|
726 | + $this->cacheTime = (int) $seconds; |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * returns the character set used by the string manipulation plugins |
|
731 | + * |
|
732 | + * the charset is automatically lowercased |
|
733 | + * |
|
734 | + * @return string |
|
735 | + */ |
|
736 | + public function getCharset() |
|
737 | + { |
|
738 | + return $this->charset; |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * sets the character set used by the string manipulation plugins |
|
743 | + * |
|
744 | + * the charset will be automatically lowercased |
|
745 | + * |
|
746 | + * @param string $charset the character set |
|
747 | + */ |
|
748 | + public function setCharset($charset) |
|
749 | + { |
|
750 | + $this->charset = strtolower((string) $charset); |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * returns the current template being rendered, when applicable, or null |
|
755 | + * |
|
756 | + * @return Dwoo_ITemplate|null |
|
757 | + */ |
|
758 | + public function getTemplate() |
|
759 | + { |
|
760 | + return $this->template; |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * sets the current template being rendered |
|
765 | + * |
|
766 | + * @param Dwoo_ITemplate $tpl template object |
|
767 | + */ |
|
768 | + public function setTemplate(Dwoo_ITemplate $tpl) |
|
769 | + { |
|
770 | + $this->template = $tpl; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * sets the default compiler factory function for the given resource name |
|
775 | + * |
|
776 | + * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs |
|
777 | + * |
|
778 | + * @param string $resourceName the resource name (i.e. file, string) |
|
779 | + * @param callback $compilerFactory the compiler factory callback |
|
780 | + */ |
|
781 | + public function setDefaultCompilerFactory($resourceName, $compilerFactory) |
|
782 | + { |
|
783 | + $this->resources[$resourceName]['compiler'] = $compilerFactory; |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * returns the default compiler factory function for the given resource name |
|
788 | + * |
|
789 | + * @param string $resourceName the resource name |
|
790 | + * @return callback the compiler factory callback |
|
791 | + */ |
|
792 | + public function getDefaultCompilerFactory($resourceName) |
|
793 | + { |
|
794 | + return $this->resources[$resourceName]['compiler']; |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * sets the security policy object to enforce some php security settings |
|
799 | + * |
|
800 | + * use this if untrusted persons can modify templates |
|
801 | + * |
|
802 | + * @param Dwoo_Security_Policy $policy the security policy object |
|
803 | + */ |
|
804 | + public function setSecurityPolicy(Dwoo_Security_Policy $policy = null) |
|
805 | + { |
|
806 | + $this->securityPolicy = $policy; |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * returns the current security policy object or null by default |
|
811 | + * |
|
812 | + * @return Dwoo_Security_Policy|null the security policy object if any |
|
813 | + */ |
|
814 | + public function getSecurityPolicy() |
|
815 | + { |
|
816 | + return $this->securityPolicy; |
|
817 | + } |
|
818 | + |
|
819 | + /** |
|
820 | + * sets the object that must be used as a plugin proxy when plugin can't be found |
|
821 | + * by dwoo's loader |
|
822 | + * |
|
823 | + * @param Dwoo_IPluginProxy $pluginProxy the proxy object |
|
824 | + */ |
|
825 | + public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) { |
|
826 | + $this->pluginProxy = $pluginProxy; |
|
827 | + } |
|
828 | + |
|
829 | + /** |
|
830 | + * returns the current plugin proxy object or null by default |
|
831 | + * |
|
832 | + * @param Dwoo_IPluginProxy|null the proxy object if any |
|
833 | + */ |
|
834 | + public function getPluginProxy() { |
|
835 | + return $this->pluginProxy; |
|
836 | + } |
|
837 | + |
|
838 | + /* |
|
839 | + * --------- util functions --------- |
|
713 | 840 | */ |
714 | - public function getCacheTime() |
|
715 | - { |
|
716 | - return $this->cacheTime; |
|
717 | - } |
|
718 | 841 | |
719 | - /** |
|
720 | - * sets the default cache time to use with templates that do not have a cache time set |
|
721 | - * |
|
722 | - * @param int $seconds the duration in seconds |
|
842 | + /** |
|
843 | + * [util function] checks whether the given template is cached or not |
|
844 | + * |
|
845 | + * @param Dwoo_ITemplate $tpl the template object |
|
846 | + * @return bool |
|
847 | + */ |
|
848 | + public function isCached(Dwoo_ITemplate $tpl) |
|
849 | + { |
|
850 | + return is_string($tpl->getCachedTemplate($this)); |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * [util function] clears the cached templates if they are older than the given time |
|
855 | + * |
|
856 | + * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared |
|
857 | + * @return int the amount of templates cleared |
|
858 | + */ |
|
859 | + public function clearCache($olderThan=-1) |
|
860 | + { |
|
861 | + $cacheDirs = new RecursiveDirectoryIterator($this->getCacheDir()); |
|
862 | + $cache = new RecursiveIteratorIterator($cacheDirs); |
|
863 | + $expired = time() - $olderThan; |
|
864 | + $count = 0; |
|
865 | + foreach ($cache as $file) { |
|
866 | + if ($cache->isDot() || $cache->isDir() || substr($file, -5) !== '.html') { |
|
867 | + continue; |
|
868 | + } |
|
869 | + if ($cache->getCTime() < $expired) { |
|
870 | + $count += unlink((string) $file) ? 1 : 0; |
|
871 | + } |
|
872 | + } |
|
873 | + return $count; |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * [util function] fetches a template object of the given resource |
|
878 | + * |
|
879 | + * @param string $resourceName the resource name (i.e. file, string) |
|
880 | + * @param string $resourceId the resource identifier (i.e. file path) |
|
881 | + * @param int $cacheTime the cache time setting for this resource |
|
882 | + * @param string $cacheId the unique cache identifier |
|
883 | + * @param string $compileId the unique compiler identifier |
|
884 | + * @return Dwoo_ITemplate |
|
885 | + */ |
|
886 | + public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null) |
|
887 | + { |
|
888 | + if (isset($this->resources[$resourceName])) { |
|
889 | + // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe |
|
890 | + return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate); |
|
891 | + } else { |
|
892 | + throw new Dwoo_Exception('Unknown resource type : '.$resourceName); |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + /** |
|
897 | + * [util function] checks if the input is an array or arrayaccess object, optionally it can also check if it's empty |
|
898 | + * |
|
899 | + * @param mixed $value the variable to check |
|
900 | + * @param bool $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty, |
|
901 | + * and return true only if it's not empty |
|
902 | + * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true) |
|
903 | + */ |
|
904 | + public function isArray($value, $checkIsEmpty=false) |
|
905 | + { |
|
906 | + if (is_array($value) === true || $value instanceof ArrayAccess) { |
|
907 | + if ($checkIsEmpty === false) { |
|
908 | + return true; |
|
909 | + } else { |
|
910 | + return $this->count($value); |
|
911 | + } |
|
912 | + } |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * [util function] checks if the input is an array or a traversable object, optionally it can also check if it's empty |
|
917 | + * |
|
918 | + * @param mixed $value the variable to check |
|
919 | + * @param bool $checkIsEmpty if true, the function will also check if the array|traversable is empty, |
|
920 | + * and return true only if it's not empty |
|
921 | + * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true) |
|
922 | + */ |
|
923 | + public function isTraversable($value, $checkIsEmpty=false) |
|
924 | + { |
|
925 | + if (is_array($value) === true) { |
|
926 | + if ($checkIsEmpty === false) { |
|
927 | + return true; |
|
928 | + } else { |
|
929 | + return count($value) > 0; |
|
930 | + } |
|
931 | + } elseif ($value instanceof Traversable) { |
|
932 | + if ($checkIsEmpty === false) { |
|
933 | + return true; |
|
934 | + } else { |
|
935 | + return $this->count($value); |
|
936 | + } |
|
937 | + } |
|
938 | + return false; |
|
939 | + } |
|
940 | + |
|
941 | + /** |
|
942 | + * [util function] counts an array or arrayaccess/traversable object |
|
943 | + * @param mixed $value |
|
944 | + * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't, and 0 for empty elements |
|
945 | + */ |
|
946 | + public function count($value) |
|
947 | + { |
|
948 | + if (is_array($value) === true || $value instanceof Countable) { |
|
949 | + return count($value); |
|
950 | + } elseif ($value instanceof ArrayAccess) { |
|
951 | + if ($value->offsetExists(0)) { |
|
952 | + return true; |
|
953 | + } |
|
954 | + } elseif ($value instanceof Iterator) { |
|
955 | + $value->rewind(); |
|
956 | + if ($value->valid()) { |
|
957 | + return true; |
|
958 | + } |
|
959 | + } elseif ($value instanceof Traversable) { |
|
960 | + foreach ($value as $dummy) { |
|
961 | + return true; |
|
962 | + } |
|
963 | + } |
|
964 | + return 0; |
|
965 | + } |
|
966 | + |
|
967 | + /** |
|
968 | + * [util function] triggers a dwoo error |
|
969 | + * |
|
970 | + * @param string $message the error message |
|
971 | + * @param int $level the error level, one of the PHP's E_* constants |
|
972 | + */ |
|
973 | + public function triggerError($message, $level=E_USER_NOTICE) |
|
974 | + { |
|
975 | + if (!($tplIdentifier = $this->template->getResourceIdentifier())) { |
|
976 | + $tplIdentifier = $this->template->getResourceName(); |
|
977 | + } |
|
978 | + trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message, $level); |
|
979 | + } |
|
980 | + |
|
981 | + /* |
|
982 | + * --------- runtime functions --------- |
|
723 | 983 | */ |
724 | - public function setCacheTime($seconds) |
|
725 | - { |
|
726 | - $this->cacheTime = (int) $seconds; |
|
727 | - } |
|
728 | 984 | |
729 | - /** |
|
730 | - * returns the character set used by the string manipulation plugins |
|
731 | - * |
|
732 | - * the charset is automatically lowercased |
|
733 | - * |
|
734 | - * @return string |
|
735 | - */ |
|
736 | - public function getCharset() |
|
737 | - { |
|
738 | - return $this->charset; |
|
739 | - } |
|
985 | + /** |
|
986 | + * [runtime function] adds a block to the block stack |
|
987 | + * |
|
988 | + * @param string $blockName the block name (without Dwoo_Plugin_ prefix) |
|
989 | + * @param array $args the arguments to be passed to the block's init() function |
|
990 | + * @return Dwoo_Block_Plugin the newly created block |
|
991 | + */ |
|
992 | + public function addStack($blockName, array $args=array()) |
|
993 | + { |
|
994 | + if (isset($this->plugins[$blockName])) { |
|
995 | + $class = $this->plugins[$blockName]['class']; |
|
996 | + } else { |
|
997 | + $class = 'Dwoo_Plugin_'.$blockName; |
|
998 | + } |
|
740 | 999 | |
741 | - /** |
|
742 | - * sets the character set used by the string manipulation plugins |
|
743 | - * |
|
744 | - * the charset will be automatically lowercased |
|
745 | - * |
|
746 | - * @param string $charset the character set |
|
747 | - */ |
|
748 | - public function setCharset($charset) |
|
749 | - { |
|
750 | - $this->charset = strtolower((string) $charset); |
|
751 | - } |
|
1000 | + if ($this->curBlock !== null) { |
|
1001 | + $this->curBlock->buffer(ob_get_contents()); |
|
1002 | + ob_clean(); |
|
1003 | + } else { |
|
1004 | + $this->buffer .= ob_get_contents(); |
|
1005 | + ob_clean(); |
|
1006 | + } |
|
1007 | + |
|
1008 | + $block = new $class($this); |
|
1009 | + |
|
1010 | + $cnt = count($args); |
|
1011 | + if ($cnt===0) { |
|
1012 | + $block->init(); |
|
1013 | + } elseif ($cnt===1) { |
|
1014 | + $block->init($args[0]); |
|
1015 | + } elseif ($cnt===2) { |
|
1016 | + $block->init($args[0], $args[1]); |
|
1017 | + } elseif ($cnt===3) { |
|
1018 | + $block->init($args[0], $args[1], $args[2]); |
|
1019 | + } elseif ($cnt===4) { |
|
1020 | + $block->init($args[0], $args[1], $args[2], $args[3]); |
|
1021 | + } else { |
|
1022 | + call_user_func_array(array($block,'init'), $args); |
|
1023 | + } |
|
1024 | + |
|
1025 | + $this->stack[] = $this->curBlock = $block; |
|
1026 | + return $block; |
|
1027 | + } |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * [runtime function] removes the plugin at the top of the block stack |
|
1031 | + * |
|
1032 | + * calls the block buffer() function, followed by a call to end() |
|
1033 | + * and finally a call to process() |
|
1034 | + */ |
|
1035 | + public function delStack() |
|
1036 | + { |
|
1037 | + $args = func_get_args(); |
|
1038 | + |
|
1039 | + $this->curBlock->buffer(ob_get_contents()); |
|
1040 | + ob_clean(); |
|
1041 | + |
|
1042 | + $cnt = count($args); |
|
1043 | + if ($cnt===0) { |
|
1044 | + $this->curBlock->end(); |
|
1045 | + } elseif ($cnt===1) { |
|
1046 | + $this->curBlock->end($args[0]); |
|
1047 | + } elseif ($cnt===2) { |
|
1048 | + $this->curBlock->end($args[0], $args[1]); |
|
1049 | + } elseif ($cnt===3) { |
|
1050 | + $this->curBlock->end($args[0], $args[1], $args[2]); |
|
1051 | + } elseif ($cnt===4) { |
|
1052 | + $this->curBlock->end($args[0], $args[1], $args[2], $args[3]); |
|
1053 | + } else { |
|
1054 | + call_user_func_array(array($this->curBlock, 'end'), $args); |
|
1055 | + } |
|
752 | 1056 | |
753 | - /** |
|
754 | - * returns the current template being rendered, when applicable, or null |
|
755 | - * |
|
756 | - * @return Dwoo_ITemplate|null |
|
757 | - */ |
|
758 | - public function getTemplate() |
|
759 | - { |
|
760 | - return $this->template; |
|
761 | - } |
|
1057 | + $tmp = array_pop($this->stack); |
|
762 | 1058 | |
763 | - /** |
|
764 | - * sets the current template being rendered |
|
765 | - * |
|
766 | - * @param Dwoo_ITemplate $tpl template object |
|
767 | - */ |
|
768 | - public function setTemplate(Dwoo_ITemplate $tpl) |
|
769 | - { |
|
770 | - $this->template = $tpl; |
|
771 | - } |
|
1059 | + if (count($this->stack) > 0) { |
|
1060 | + $this->curBlock = end($this->stack); |
|
1061 | + $this->curBlock->buffer($tmp->process()); |
|
1062 | + } else { |
|
1063 | + if($this->buffer !== '') { |
|
1064 | + echo $this->buffer; |
|
1065 | + $this->buffer = ''; |
|
1066 | + } |
|
1067 | + $this->curBlock = null; |
|
1068 | + echo $tmp->process(); |
|
1069 | + } |
|
1070 | + |
|
1071 | + unset($tmp); |
|
1072 | + } |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * [runtime function] returns the parent block of the given block |
|
1076 | + * |
|
1077 | + * @param Dwoo_Block_Plugin $block |
|
1078 | + * @return Dwoo_Block_Plugin or false if the given block isn't in the stack |
|
1079 | + */ |
|
1080 | + public function getParentBlock(Dwoo_Block_Plugin $block) |
|
1081 | + { |
|
1082 | + $index = array_search($block, $this->stack, true); |
|
1083 | + if ($index !== false && $index > 0) { |
|
1084 | + return $this->stack[$index-1]; |
|
1085 | + } |
|
1086 | + return false; |
|
1087 | + } |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * [runtime function] finds the closest block of the given type, starting at the top of the stack |
|
1091 | + * |
|
1092 | + * @param string $type the type of plugin you want to find |
|
1093 | + * @return Dwoo_Block_Plugin or false if no plugin of such type is in the stack |
|
1094 | + */ |
|
1095 | + public function findBlock($type) |
|
1096 | + { |
|
1097 | + if (isset($this->plugins[$type])) { |
|
1098 | + $type = $this->plugins[$type]['class']; |
|
1099 | + } else { |
|
1100 | + $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type); |
|
1101 | + } |
|
772 | 1102 | |
773 | - /** |
|
774 | - * sets the default compiler factory function for the given resource name |
|
775 | - * |
|
776 | - * a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs |
|
777 | - * |
|
778 | - * @param string $resourceName the resource name (i.e. file, string) |
|
779 | - * @param callback $compilerFactory the compiler factory callback |
|
780 | - */ |
|
781 | - public function setDefaultCompilerFactory($resourceName, $compilerFactory) |
|
782 | - { |
|
783 | - $this->resources[$resourceName]['compiler'] = $compilerFactory; |
|
784 | - } |
|
1103 | + $keys = array_keys($this->stack); |
|
1104 | + while (($key = array_pop($keys)) !== false) { |
|
1105 | + if ($this->stack[$key] instanceof $type) { |
|
1106 | + return $this->stack[$key]; |
|
1107 | + } |
|
1108 | + } |
|
1109 | + return false; |
|
1110 | + } |
|
1111 | + |
|
1112 | + /** |
|
1113 | + * [runtime function] returns a Dwoo_Plugin of the given class |
|
1114 | + * |
|
1115 | + * this is so a single instance of every class plugin is created at each template run, |
|
1116 | + * allowing class plugins to have "per-template-run" static variables |
|
1117 | + * |
|
1118 | + * @private |
|
1119 | + * @param string $class the class name |
|
1120 | + * @return mixed an object of the given class |
|
1121 | + */ |
|
1122 | + public function getObjectPlugin($class) |
|
1123 | + { |
|
1124 | + if (isset($this->runtimePlugins[$class])) { |
|
1125 | + return $this->runtimePlugins[$class]; |
|
1126 | + } |
|
1127 | + return $this->runtimePlugins[$class] = new $class($this); |
|
1128 | + } |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * [runtime function] calls the process() method of the given class-plugin name |
|
1132 | + * |
|
1133 | + * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix) |
|
1134 | + * @param array $params an array of parameters to send to the process() method |
|
1135 | + * @return string the process() return value |
|
1136 | + */ |
|
1137 | + public function classCall($plugName, array $params = array()) |
|
1138 | + { |
|
1139 | + $class = 'Dwoo_Plugin_'.$plugName; |
|
1140 | + |
|
1141 | + $plugin = $this->getObjectPlugin($class); |
|
1142 | + |
|
1143 | + $cnt = count($params); |
|
1144 | + if ($cnt===0) { |
|
1145 | + return $plugin->process(); |
|
1146 | + } elseif ($cnt===1) { |
|
1147 | + return $plugin->process($params[0]); |
|
1148 | + } elseif ($cnt===2) { |
|
1149 | + return $plugin->process($params[0], $params[1]); |
|
1150 | + } elseif ($cnt===3) { |
|
1151 | + return $plugin->process($params[0], $params[1], $params[2]); |
|
1152 | + } elseif ($cnt===4) { |
|
1153 | + return $plugin->process($params[0], $params[1], $params[2], $params[3]); |
|
1154 | + } else { |
|
1155 | + return call_user_func_array(array($plugin, 'process'), $params); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * [runtime function] calls a php function |
|
1161 | + * |
|
1162 | + * @param string $callback the function to call |
|
1163 | + * @param array $params an array of parameters to send to the function |
|
1164 | + * @return mixed the return value of the called function |
|
1165 | + */ |
|
1166 | + public function arrayMap($callback, array $params) |
|
1167 | + { |
|
1168 | + if ($params[0] === $this) { |
|
1169 | + $addThis = true; |
|
1170 | + array_shift($params); |
|
1171 | + } |
|
1172 | + if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) { |
|
1173 | + if (empty($params[0])) { |
|
1174 | + return $params[0]; |
|
1175 | + } |
|
785 | 1176 | |
786 | - /** |
|
787 | - * returns the default compiler factory function for the given resource name |
|
788 | - * |
|
789 | - * @param string $resourceName the resource name |
|
790 | - * @return callback the compiler factory callback |
|
791 | - */ |
|
792 | - public function getDefaultCompilerFactory($resourceName) |
|
793 | - { |
|
794 | - return $this->resources[$resourceName]['compiler']; |
|
795 | - } |
|
1177 | + // array map |
|
1178 | + $out = array(); |
|
1179 | + $cnt = count($params); |
|
1180 | + |
|
1181 | + if (isset($addThis)) { |
|
1182 | + array_unshift($params, $this); |
|
1183 | + $items = $params[1]; |
|
1184 | + $keys = array_keys($items); |
|
1185 | + |
|
1186 | + if (is_string($callback) === false) { |
|
1187 | + while (($i = array_shift($keys)) !== null) { |
|
1188 | + $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1189 | + } |
|
1190 | + } elseif ($cnt===1) { |
|
1191 | + while (($i = array_shift($keys)) !== null) { |
|
1192 | + $out[] = $callback($this, $items[$i]); |
|
1193 | + } |
|
1194 | + } elseif ($cnt===2) { |
|
1195 | + while (($i = array_shift($keys)) !== null) { |
|
1196 | + $out[] = $callback($this, $items[$i], $params[2]); |
|
1197 | + } |
|
1198 | + } elseif ($cnt===3) { |
|
1199 | + while (($i = array_shift($keys)) !== null) { |
|
1200 | + $out[] = $callback($this, $items[$i], $params[2], $params[3]); |
|
1201 | + } |
|
1202 | + } else { |
|
1203 | + while (($i = array_shift($keys)) !== null) { |
|
1204 | + $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1205 | + } |
|
1206 | + } |
|
1207 | + } else { |
|
1208 | + $items = $params[0]; |
|
1209 | + $keys = array_keys($items); |
|
1210 | + |
|
1211 | + if (is_string($callback) === false) { |
|
1212 | + while (($i = array_shift($keys)) !== null) { |
|
1213 | + $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1214 | + } |
|
1215 | + } elseif ($cnt===1) { |
|
1216 | + while (($i = array_shift($keys)) !== null) { |
|
1217 | + $out[] = $callback($items[$i]); |
|
1218 | + } |
|
1219 | + } elseif ($cnt===2) { |
|
1220 | + while (($i = array_shift($keys)) !== null) { |
|
1221 | + $out[] = $callback($items[$i], $params[1]); |
|
1222 | + } |
|
1223 | + } elseif ($cnt===3) { |
|
1224 | + while (($i = array_shift($keys)) !== null) { |
|
1225 | + $out[] = $callback($items[$i], $params[1], $params[2]); |
|
1226 | + } |
|
1227 | + } elseif ($cnt===4) { |
|
1228 | + while (($i = array_shift($keys)) !== null) { |
|
1229 | + $out[] = $callback($items[$i], $params[1], $params[2], $params[3]); |
|
1230 | + } |
|
1231 | + } else { |
|
1232 | + while (($i = array_shift($keys)) !== null) { |
|
1233 | + $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1234 | + } |
|
1235 | + } |
|
1236 | + } |
|
1237 | + return $out; |
|
1238 | + } else { |
|
1239 | + return $params[0]; |
|
1240 | + } |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * [runtime function] reads a variable into the given data array |
|
1245 | + * |
|
1246 | + * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1247 | + * @param mixed $data the data array or object to read from |
|
1248 | + * @param bool $safeRead if true, the function will check whether the index exists to prevent any notices from being output |
|
1249 | + * @return mixed |
|
1250 | + */ |
|
1251 | + public function readVarInto($varstr, $data, $safeRead = false) |
|
1252 | + { |
|
1253 | + if ($data === null) { |
|
1254 | + return null; |
|
1255 | + } |
|
1256 | + |
|
1257 | + if (is_array($varstr) === false) { |
|
1258 | + preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); |
|
1259 | + } else { |
|
1260 | + $m = $varstr; |
|
1261 | + } |
|
1262 | + unset($varstr); |
|
796 | 1263 | |
797 | - /** |
|
798 | - * sets the security policy object to enforce some php security settings |
|
799 | - * |
|
800 | - * use this if untrusted persons can modify templates |
|
801 | - * |
|
802 | - * @param Dwoo_Security_Policy $policy the security policy object |
|
803 | - */ |
|
804 | - public function setSecurityPolicy(Dwoo_Security_Policy $policy = null) |
|
805 | - { |
|
806 | - $this->securityPolicy = $policy; |
|
807 | - } |
|
1264 | + while (list($k, $sep) = each($m[1])) { |
|
1265 | + if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1266 | + // strip enclosing quotes if present |
|
1267 | + $m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]); |
|
808 | 1268 | |
809 | - /** |
|
810 | - * returns the current security policy object or null by default |
|
811 | - * |
|
812 | - * @return Dwoo_Security_Policy|null the security policy object if any |
|
813 | - */ |
|
814 | - public function getSecurityPolicy() |
|
815 | - { |
|
816 | - return $this->securityPolicy; |
|
817 | - } |
|
818 | - |
|
819 | - /** |
|
820 | - * sets the object that must be used as a plugin proxy when plugin can't be found |
|
821 | - * by dwoo's loader |
|
822 | - * |
|
823 | - * @param Dwoo_IPluginProxy $pluginProxy the proxy object |
|
824 | - */ |
|
825 | - public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) { |
|
826 | - $this->pluginProxy = $pluginProxy; |
|
827 | - } |
|
1269 | + if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) { |
|
1270 | + $data = $data[$m[2][$k]]; |
|
1271 | + } else { |
|
1272 | + return null; |
|
1273 | + } |
|
1274 | + } else { |
|
1275 | + if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) { |
|
1276 | + $data = $data->$m[2][$k]; |
|
1277 | + } else { |
|
1278 | + return null; |
|
1279 | + } |
|
1280 | + } |
|
1281 | + } |
|
1282 | + |
|
1283 | + return $data; |
|
1284 | + } |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * [runtime function] reads a variable into the parent scope |
|
1288 | + * |
|
1289 | + * @param int $parentLevels the amount of parent levels to go from the current scope |
|
1290 | + * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1291 | + * @return mixed |
|
1292 | + */ |
|
1293 | + public function readParentVar($parentLevels, $varstr = null) |
|
1294 | + { |
|
1295 | + $tree = $this->scopeTree; |
|
1296 | + $cur = $this->data; |
|
1297 | + |
|
1298 | + while ($parentLevels--!==0) { |
|
1299 | + array_pop($tree); |
|
1300 | + } |
|
1301 | + |
|
1302 | + while (($i = array_shift($tree)) !== null) { |
|
1303 | + if (is_object($cur)) { |
|
1304 | + $cur = $cur->$i; |
|
1305 | + } else { |
|
1306 | + $cur = $cur[$i]; |
|
1307 | + } |
|
1308 | + } |
|
828 | 1309 | |
829 | - /** |
|
830 | - * returns the current plugin proxy object or null by default |
|
831 | - * |
|
832 | - * @param Dwoo_IPluginProxy|null the proxy object if any |
|
833 | - */ |
|
834 | - public function getPluginProxy() { |
|
835 | - return $this->pluginProxy; |
|
836 | - } |
|
1310 | + if ($varstr!==null) { |
|
1311 | + return $this->readVarInto($varstr, $cur); |
|
1312 | + } else { |
|
1313 | + return $cur; |
|
1314 | + } |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * [runtime function] reads a variable into the current scope |
|
1319 | + * |
|
1320 | + * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1321 | + * @return mixed |
|
1322 | + */ |
|
1323 | + public function readVar($varstr) |
|
1324 | + { |
|
1325 | + if (is_array($varstr)===true) { |
|
1326 | + $m = $varstr; |
|
1327 | + unset($varstr); |
|
1328 | + } else { |
|
1329 | + if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) { |
|
1330 | + if ($varstr === 'dwoo') { |
|
1331 | + return $this->globals; |
|
1332 | + } elseif ($varstr === '__' || $varstr === '_root' ) { |
|
1333 | + return $this->data; |
|
1334 | + $varstr = substr($varstr, 6); |
|
1335 | + } elseif ($varstr === '_' || $varstr === '_parent') { |
|
1336 | + $varstr = '.'.$varstr; |
|
1337 | + $tree = $this->scopeTree; |
|
1338 | + $cur = $this->data; |
|
1339 | + array_pop($tree); |
|
1340 | + |
|
1341 | + while (($i = array_shift($tree)) !== null) { |
|
1342 | + if (is_object($cur)) { |
|
1343 | + $cur = $cur->$i; |
|
1344 | + } else { |
|
1345 | + $cur = $cur[$i]; |
|
1346 | + } |
|
1347 | + } |
|
1348 | + |
|
1349 | + return $cur; |
|
1350 | + } |
|
837 | 1351 | |
838 | - /* |
|
839 | - * --------- util functions --------- |
|
840 | - */ |
|
1352 | + $cur = $this->scope; |
|
841 | 1353 | |
842 | - /** |
|
843 | - * [util function] checks whether the given template is cached or not |
|
844 | - * |
|
845 | - * @param Dwoo_ITemplate $tpl the template object |
|
846 | - * @return bool |
|
847 | - */ |
|
848 | - public function isCached(Dwoo_ITemplate $tpl) |
|
849 | - { |
|
850 | - return is_string($tpl->getCachedTemplate($this)); |
|
851 | - } |
|
1354 | + if (isset($cur[$varstr])) { |
|
1355 | + return $cur[$varstr]; |
|
1356 | + } else { |
|
1357 | + return null; |
|
1358 | + } |
|
1359 | + } |
|
852 | 1360 | |
853 | - /** |
|
854 | - * [util function] clears the cached templates if they are older than the given time |
|
855 | - * |
|
856 | - * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared |
|
857 | - * @return int the amount of templates cleared |
|
858 | - */ |
|
859 | - public function clearCache($olderThan=-1) |
|
860 | - { |
|
861 | - $cacheDirs = new RecursiveDirectoryIterator($this->getCacheDir()); |
|
862 | - $cache = new RecursiveIteratorIterator($cacheDirs); |
|
863 | - $expired = time() - $olderThan; |
|
864 | - $count = 0; |
|
865 | - foreach ($cache as $file) { |
|
866 | - if ($cache->isDot() || $cache->isDir() || substr($file, -5) !== '.html') { |
|
867 | - continue; |
|
868 | - } |
|
869 | - if ($cache->getCTime() < $expired) { |
|
870 | - $count += unlink((string) $file) ? 1 : 0; |
|
871 | - } |
|
872 | - } |
|
873 | - return $count; |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * [util function] fetches a template object of the given resource |
|
878 | - * |
|
879 | - * @param string $resourceName the resource name (i.e. file, string) |
|
880 | - * @param string $resourceId the resource identifier (i.e. file path) |
|
881 | - * @param int $cacheTime the cache time setting for this resource |
|
882 | - * @param string $cacheId the unique cache identifier |
|
883 | - * @param string $compileId the unique compiler identifier |
|
884 | - * @return Dwoo_ITemplate |
|
885 | - */ |
|
886 | - public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null) |
|
887 | - { |
|
888 | - if (isset($this->resources[$resourceName])) { |
|
889 | - // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe |
|
890 | - return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate); |
|
891 | - } else { |
|
892 | - throw new Dwoo_Exception('Unknown resource type : '.$resourceName); |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - /** |
|
897 | - * [util function] checks if the input is an array or arrayaccess object, optionally it can also check if it's empty |
|
898 | - * |
|
899 | - * @param mixed $value the variable to check |
|
900 | - * @param bool $checkIsEmpty if true, the function will also check if the array|arrayaccess is empty, |
|
901 | - * and return true only if it's not empty |
|
902 | - * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true) |
|
903 | - */ |
|
904 | - public function isArray($value, $checkIsEmpty=false) |
|
905 | - { |
|
906 | - if (is_array($value) === true || $value instanceof ArrayAccess) { |
|
907 | - if ($checkIsEmpty === false) { |
|
908 | - return true; |
|
909 | - } else { |
|
910 | - return $this->count($value); |
|
911 | - } |
|
912 | - } |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * [util function] checks if the input is an array or a traversable object, optionally it can also check if it's empty |
|
917 | - * |
|
918 | - * @param mixed $value the variable to check |
|
919 | - * @param bool $checkIsEmpty if true, the function will also check if the array|traversable is empty, |
|
920 | - * and return true only if it's not empty |
|
921 | - * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true) |
|
922 | - */ |
|
923 | - public function isTraversable($value, $checkIsEmpty=false) |
|
924 | - { |
|
925 | - if (is_array($value) === true) { |
|
926 | - if ($checkIsEmpty === false) { |
|
927 | - return true; |
|
928 | - } else { |
|
929 | - return count($value) > 0; |
|
930 | - } |
|
931 | - } elseif ($value instanceof Traversable) { |
|
932 | - if ($checkIsEmpty === false) { |
|
933 | - return true; |
|
934 | - } else { |
|
935 | - return $this->count($value); |
|
936 | - } |
|
937 | - } |
|
938 | - return false; |
|
939 | - } |
|
940 | - |
|
941 | - /** |
|
942 | - * [util function] counts an array or arrayaccess/traversable object |
|
943 | - * @param mixed $value |
|
944 | - * @return int|bool the count for arrays and objects that implement countable, true for other objects that don't, and 0 for empty elements |
|
945 | - */ |
|
946 | - public function count($value) |
|
947 | - { |
|
948 | - if (is_array($value) === true || $value instanceof Countable) { |
|
949 | - return count($value); |
|
950 | - } elseif ($value instanceof ArrayAccess) { |
|
951 | - if ($value->offsetExists(0)) { |
|
952 | - return true; |
|
953 | - } |
|
954 | - } elseif ($value instanceof Iterator) { |
|
955 | - $value->rewind(); |
|
956 | - if ($value->valid()) { |
|
957 | - return true; |
|
958 | - } |
|
959 | - } elseif ($value instanceof Traversable) { |
|
960 | - foreach ($value as $dummy) { |
|
961 | - return true; |
|
962 | - } |
|
963 | - } |
|
964 | - return 0; |
|
965 | - } |
|
966 | - |
|
967 | - /** |
|
968 | - * [util function] triggers a dwoo error |
|
969 | - * |
|
970 | - * @param string $message the error message |
|
971 | - * @param int $level the error level, one of the PHP's E_* constants |
|
972 | - */ |
|
973 | - public function triggerError($message, $level=E_USER_NOTICE) |
|
974 | - { |
|
975 | - if (!($tplIdentifier = $this->template->getResourceIdentifier())) { |
|
976 | - $tplIdentifier = $this->template->getResourceName(); |
|
977 | - } |
|
978 | - trigger_error('Dwoo error (in '.$tplIdentifier.') : '.$message, $level); |
|
979 | - } |
|
980 | - |
|
981 | - /* |
|
982 | - * --------- runtime functions --------- |
|
983 | - */ |
|
1361 | + if (substr($varstr, 0, 1) === '.') { |
|
1362 | + $varstr = 'dwoo'.$varstr; |
|
1363 | + } |
|
984 | 1364 | |
985 | - /** |
|
986 | - * [runtime function] adds a block to the block stack |
|
987 | - * |
|
988 | - * @param string $blockName the block name (without Dwoo_Plugin_ prefix) |
|
989 | - * @param array $args the arguments to be passed to the block's init() function |
|
990 | - * @return Dwoo_Block_Plugin the newly created block |
|
991 | - */ |
|
992 | - public function addStack($blockName, array $args=array()) |
|
993 | - { |
|
994 | - if (isset($this->plugins[$blockName])) { |
|
995 | - $class = $this->plugins[$blockName]['class']; |
|
996 | - } else { |
|
997 | - $class = 'Dwoo_Plugin_'.$blockName; |
|
998 | - } |
|
999 | - |
|
1000 | - if ($this->curBlock !== null) { |
|
1001 | - $this->curBlock->buffer(ob_get_contents()); |
|
1002 | - ob_clean(); |
|
1003 | - } else { |
|
1004 | - $this->buffer .= ob_get_contents(); |
|
1005 | - ob_clean(); |
|
1006 | - } |
|
1007 | - |
|
1008 | - $block = new $class($this); |
|
1009 | - |
|
1010 | - $cnt = count($args); |
|
1011 | - if ($cnt===0) { |
|
1012 | - $block->init(); |
|
1013 | - } elseif ($cnt===1) { |
|
1014 | - $block->init($args[0]); |
|
1015 | - } elseif ($cnt===2) { |
|
1016 | - $block->init($args[0], $args[1]); |
|
1017 | - } elseif ($cnt===3) { |
|
1018 | - $block->init($args[0], $args[1], $args[2]); |
|
1019 | - } elseif ($cnt===4) { |
|
1020 | - $block->init($args[0], $args[1], $args[2], $args[3]); |
|
1021 | - } else { |
|
1022 | - call_user_func_array(array($block,'init'), $args); |
|
1023 | - } |
|
1024 | - |
|
1025 | - $this->stack[] = $this->curBlock = $block; |
|
1026 | - return $block; |
|
1027 | - } |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * [runtime function] removes the plugin at the top of the block stack |
|
1031 | - * |
|
1032 | - * calls the block buffer() function, followed by a call to end() |
|
1033 | - * and finally a call to process() |
|
1034 | - */ |
|
1035 | - public function delStack() |
|
1036 | - { |
|
1037 | - $args = func_get_args(); |
|
1038 | - |
|
1039 | - $this->curBlock->buffer(ob_get_contents()); |
|
1040 | - ob_clean(); |
|
1041 | - |
|
1042 | - $cnt = count($args); |
|
1043 | - if ($cnt===0) { |
|
1044 | - $this->curBlock->end(); |
|
1045 | - } elseif ($cnt===1) { |
|
1046 | - $this->curBlock->end($args[0]); |
|
1047 | - } elseif ($cnt===2) { |
|
1048 | - $this->curBlock->end($args[0], $args[1]); |
|
1049 | - } elseif ($cnt===3) { |
|
1050 | - $this->curBlock->end($args[0], $args[1], $args[2]); |
|
1051 | - } elseif ($cnt===4) { |
|
1052 | - $this->curBlock->end($args[0], $args[1], $args[2], $args[3]); |
|
1053 | - } else { |
|
1054 | - call_user_func_array(array($this->curBlock, 'end'), $args); |
|
1055 | - } |
|
1056 | - |
|
1057 | - $tmp = array_pop($this->stack); |
|
1058 | - |
|
1059 | - if (count($this->stack) > 0) { |
|
1060 | - $this->curBlock = end($this->stack); |
|
1061 | - $this->curBlock->buffer($tmp->process()); |
|
1062 | - } else { |
|
1063 | - if($this->buffer !== '') { |
|
1064 | - echo $this->buffer; |
|
1065 | - $this->buffer = ''; |
|
1066 | - } |
|
1067 | - $this->curBlock = null; |
|
1068 | - echo $tmp->process(); |
|
1069 | - } |
|
1070 | - |
|
1071 | - unset($tmp); |
|
1072 | - } |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * [runtime function] returns the parent block of the given block |
|
1076 | - * |
|
1077 | - * @param Dwoo_Block_Plugin $block |
|
1078 | - * @return Dwoo_Block_Plugin or false if the given block isn't in the stack |
|
1079 | - */ |
|
1080 | - public function getParentBlock(Dwoo_Block_Plugin $block) |
|
1081 | - { |
|
1082 | - $index = array_search($block, $this->stack, true); |
|
1083 | - if ($index !== false && $index > 0) { |
|
1084 | - return $this->stack[$index-1]; |
|
1085 | - } |
|
1086 | - return false; |
|
1087 | - } |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * [runtime function] finds the closest block of the given type, starting at the top of the stack |
|
1091 | - * |
|
1092 | - * @param string $type the type of plugin you want to find |
|
1093 | - * @return Dwoo_Block_Plugin or false if no plugin of such type is in the stack |
|
1094 | - */ |
|
1095 | - public function findBlock($type) |
|
1096 | - { |
|
1097 | - if (isset($this->plugins[$type])) { |
|
1098 | - $type = $this->plugins[$type]['class']; |
|
1099 | - } else { |
|
1100 | - $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type); |
|
1101 | - } |
|
1102 | - |
|
1103 | - $keys = array_keys($this->stack); |
|
1104 | - while (($key = array_pop($keys)) !== false) { |
|
1105 | - if ($this->stack[$key] instanceof $type) { |
|
1106 | - return $this->stack[$key]; |
|
1107 | - } |
|
1108 | - } |
|
1109 | - return false; |
|
1110 | - } |
|
1111 | - |
|
1112 | - /** |
|
1113 | - * [runtime function] returns a Dwoo_Plugin of the given class |
|
1114 | - * |
|
1115 | - * this is so a single instance of every class plugin is created at each template run, |
|
1116 | - * allowing class plugins to have "per-template-run" static variables |
|
1117 | - * |
|
1118 | - * @private |
|
1119 | - * @param string $class the class name |
|
1120 | - * @return mixed an object of the given class |
|
1121 | - */ |
|
1122 | - public function getObjectPlugin($class) |
|
1123 | - { |
|
1124 | - if (isset($this->runtimePlugins[$class])) { |
|
1125 | - return $this->runtimePlugins[$class]; |
|
1126 | - } |
|
1127 | - return $this->runtimePlugins[$class] = new $class($this); |
|
1128 | - } |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * [runtime function] calls the process() method of the given class-plugin name |
|
1132 | - * |
|
1133 | - * @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix) |
|
1134 | - * @param array $params an array of parameters to send to the process() method |
|
1135 | - * @return string the process() return value |
|
1136 | - */ |
|
1137 | - public function classCall($plugName, array $params = array()) |
|
1138 | - { |
|
1139 | - $class = 'Dwoo_Plugin_'.$plugName; |
|
1140 | - |
|
1141 | - $plugin = $this->getObjectPlugin($class); |
|
1142 | - |
|
1143 | - $cnt = count($params); |
|
1144 | - if ($cnt===0) { |
|
1145 | - return $plugin->process(); |
|
1146 | - } elseif ($cnt===1) { |
|
1147 | - return $plugin->process($params[0]); |
|
1148 | - } elseif ($cnt===2) { |
|
1149 | - return $plugin->process($params[0], $params[1]); |
|
1150 | - } elseif ($cnt===3) { |
|
1151 | - return $plugin->process($params[0], $params[1], $params[2]); |
|
1152 | - } elseif ($cnt===4) { |
|
1153 | - return $plugin->process($params[0], $params[1], $params[2], $params[3]); |
|
1154 | - } else { |
|
1155 | - return call_user_func_array(array($plugin, 'process'), $params); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * [runtime function] calls a php function |
|
1161 | - * |
|
1162 | - * @param string $callback the function to call |
|
1163 | - * @param array $params an array of parameters to send to the function |
|
1164 | - * @return mixed the return value of the called function |
|
1165 | - */ |
|
1166 | - public function arrayMap($callback, array $params) |
|
1167 | - { |
|
1168 | - if ($params[0] === $this) { |
|
1169 | - $addThis = true; |
|
1170 | - array_shift($params); |
|
1171 | - } |
|
1172 | - if ((is_array($params[0]) || ($params[0] instanceof Iterator && $params[0] instanceof ArrayAccess))) { |
|
1173 | - if (empty($params[0])) { |
|
1174 | - return $params[0]; |
|
1175 | - } |
|
1176 | - |
|
1177 | - // array map |
|
1178 | - $out = array(); |
|
1179 | - $cnt = count($params); |
|
1180 | - |
|
1181 | - if (isset($addThis)) { |
|
1182 | - array_unshift($params, $this); |
|
1183 | - $items = $params[1]; |
|
1184 | - $keys = array_keys($items); |
|
1185 | - |
|
1186 | - if (is_string($callback) === false) { |
|
1187 | - while (($i = array_shift($keys)) !== null) { |
|
1188 | - $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1189 | - } |
|
1190 | - } elseif ($cnt===1) { |
|
1191 | - while (($i = array_shift($keys)) !== null) { |
|
1192 | - $out[] = $callback($this, $items[$i]); |
|
1193 | - } |
|
1194 | - } elseif ($cnt===2) { |
|
1195 | - while (($i = array_shift($keys)) !== null) { |
|
1196 | - $out[] = $callback($this, $items[$i], $params[2]); |
|
1197 | - } |
|
1198 | - } elseif ($cnt===3) { |
|
1199 | - while (($i = array_shift($keys)) !== null) { |
|
1200 | - $out[] = $callback($this, $items[$i], $params[2], $params[3]); |
|
1201 | - } |
|
1202 | - } else { |
|
1203 | - while (($i = array_shift($keys)) !== null) { |
|
1204 | - $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1205 | - } |
|
1206 | - } |
|
1207 | - } else { |
|
1208 | - $items = $params[0]; |
|
1209 | - $keys = array_keys($items); |
|
1210 | - |
|
1211 | - if (is_string($callback) === false) { |
|
1212 | - while (($i = array_shift($keys)) !== null) { |
|
1213 | - $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1214 | - } |
|
1215 | - } elseif ($cnt===1) { |
|
1216 | - while (($i = array_shift($keys)) !== null) { |
|
1217 | - $out[] = $callback($items[$i]); |
|
1218 | - } |
|
1219 | - } elseif ($cnt===2) { |
|
1220 | - while (($i = array_shift($keys)) !== null) { |
|
1221 | - $out[] = $callback($items[$i], $params[1]); |
|
1222 | - } |
|
1223 | - } elseif ($cnt===3) { |
|
1224 | - while (($i = array_shift($keys)) !== null) { |
|
1225 | - $out[] = $callback($items[$i], $params[1], $params[2]); |
|
1226 | - } |
|
1227 | - } elseif ($cnt===4) { |
|
1228 | - while (($i = array_shift($keys)) !== null) { |
|
1229 | - $out[] = $callback($items[$i], $params[1], $params[2], $params[3]); |
|
1230 | - } |
|
1231 | - } else { |
|
1232 | - while (($i = array_shift($keys)) !== null) { |
|
1233 | - $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1234 | - } |
|
1235 | - } |
|
1236 | - } |
|
1237 | - return $out; |
|
1238 | - } else { |
|
1239 | - return $params[0]; |
|
1240 | - } |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * [runtime function] reads a variable into the given data array |
|
1245 | - * |
|
1246 | - * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1247 | - * @param mixed $data the data array or object to read from |
|
1248 | - * @param bool $safeRead if true, the function will check whether the index exists to prevent any notices from being output |
|
1249 | - * @return mixed |
|
1250 | - */ |
|
1251 | - public function readVarInto($varstr, $data, $safeRead = false) |
|
1252 | - { |
|
1253 | - if ($data === null) { |
|
1254 | - return null; |
|
1255 | - } |
|
1256 | - |
|
1257 | - if (is_array($varstr) === false) { |
|
1258 | - preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); |
|
1259 | - } else { |
|
1260 | - $m = $varstr; |
|
1261 | - } |
|
1262 | - unset($varstr); |
|
1263 | - |
|
1264 | - while (list($k, $sep) = each($m[1])) { |
|
1265 | - if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1266 | - // strip enclosing quotes if present |
|
1267 | - $m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]); |
|
1268 | - |
|
1269 | - if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) { |
|
1270 | - $data = $data[$m[2][$k]]; |
|
1271 | - } else { |
|
1272 | - return null; |
|
1273 | - } |
|
1274 | - } else { |
|
1275 | - if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]))) { |
|
1276 | - $data = $data->$m[2][$k]; |
|
1277 | - } else { |
|
1278 | - return null; |
|
1279 | - } |
|
1280 | - } |
|
1281 | - } |
|
1282 | - |
|
1283 | - return $data; |
|
1284 | - } |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * [runtime function] reads a variable into the parent scope |
|
1288 | - * |
|
1289 | - * @param int $parentLevels the amount of parent levels to go from the current scope |
|
1290 | - * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1291 | - * @return mixed |
|
1292 | - */ |
|
1293 | - public function readParentVar($parentLevels, $varstr = null) |
|
1294 | - { |
|
1295 | - $tree = $this->scopeTree; |
|
1296 | - $cur = $this->data; |
|
1297 | - |
|
1298 | - while ($parentLevels--!==0) { |
|
1299 | - array_pop($tree); |
|
1300 | - } |
|
1301 | - |
|
1302 | - while (($i = array_shift($tree)) !== null) { |
|
1303 | - if (is_object($cur)) { |
|
1304 | - $cur = $cur->$i; |
|
1305 | - } else { |
|
1306 | - $cur = $cur[$i]; |
|
1307 | - } |
|
1308 | - } |
|
1309 | - |
|
1310 | - if ($varstr!==null) { |
|
1311 | - return $this->readVarInto($varstr, $cur); |
|
1312 | - } else { |
|
1313 | - return $cur; |
|
1314 | - } |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * [runtime function] reads a variable into the current scope |
|
1319 | - * |
|
1320 | - * @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1321 | - * @return mixed |
|
1322 | - */ |
|
1323 | - public function readVar($varstr) |
|
1324 | - { |
|
1325 | - if (is_array($varstr)===true) { |
|
1326 | - $m = $varstr; |
|
1327 | - unset($varstr); |
|
1328 | - } else { |
|
1329 | - if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) { |
|
1330 | - if ($varstr === 'dwoo') { |
|
1331 | - return $this->globals; |
|
1332 | - } elseif ($varstr === '__' || $varstr === '_root' ) { |
|
1333 | - return $this->data; |
|
1334 | - $varstr = substr($varstr, 6); |
|
1335 | - } elseif ($varstr === '_' || $varstr === '_parent') { |
|
1336 | - $varstr = '.'.$varstr; |
|
1337 | - $tree = $this->scopeTree; |
|
1338 | - $cur = $this->data; |
|
1339 | - array_pop($tree); |
|
1340 | - |
|
1341 | - while (($i = array_shift($tree)) !== null) { |
|
1342 | - if (is_object($cur)) { |
|
1343 | - $cur = $cur->$i; |
|
1344 | - } else { |
|
1345 | - $cur = $cur[$i]; |
|
1346 | - } |
|
1347 | - } |
|
1348 | - |
|
1349 | - return $cur; |
|
1350 | - } |
|
1351 | - |
|
1352 | - $cur = $this->scope; |
|
1353 | - |
|
1354 | - if (isset($cur[$varstr])) { |
|
1355 | - return $cur[$varstr]; |
|
1356 | - } else { |
|
1357 | - return null; |
|
1358 | - } |
|
1359 | - } |
|
1360 | - |
|
1361 | - if (substr($varstr, 0, 1) === '.') { |
|
1362 | - $varstr = 'dwoo'.$varstr; |
|
1363 | - } |
|
1364 | - |
|
1365 | - preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); |
|
1366 | - } |
|
1367 | - |
|
1368 | - $i = $m[2][0]; |
|
1369 | - if ($i === 'dwoo') { |
|
1370 | - $cur = $this->globals; |
|
1371 | - array_shift($m[2]); |
|
1372 | - array_shift($m[1]); |
|
1373 | - switch ($m[2][0]) { |
|
1374 | - |
|
1375 | - case 'get': |
|
1376 | - $cur = $_GET; |
|
1377 | - break; |
|
1378 | - case 'post': |
|
1379 | - $cur = $_POST; |
|
1380 | - break; |
|
1381 | - case 'session': |
|
1382 | - $cur = $_SESSION; |
|
1383 | - break; |
|
1384 | - case 'cookies': |
|
1385 | - case 'cookie': |
|
1386 | - $cur = $_COOKIE; |
|
1387 | - break; |
|
1388 | - case 'server': |
|
1389 | - $cur = $_SERVER; |
|
1390 | - break; |
|
1391 | - case 'env': |
|
1392 | - $cur = $_ENV; |
|
1393 | - break; |
|
1394 | - case 'request': |
|
1395 | - $cur = $_REQUEST; |
|
1396 | - break; |
|
1397 | - case 'const': |
|
1398 | - array_shift($m[2]); |
|
1399 | - if (defined($m[2][0])) { |
|
1400 | - return constant($m[2][0]); |
|
1401 | - } else { |
|
1402 | - return null; |
|
1403 | - } |
|
1404 | - |
|
1405 | - } |
|
1406 | - if ($cur !== $this->globals) { |
|
1407 | - array_shift($m[2]); |
|
1408 | - array_shift($m[1]); |
|
1409 | - } |
|
1410 | - } elseif ($i === '__' || $i === '_root') { |
|
1411 | - $cur = $this->data; |
|
1412 | - array_shift($m[2]); |
|
1413 | - array_shift($m[1]); |
|
1414 | - } elseif ($i === '_' || $i === '_parent') { |
|
1415 | - $tree = $this->scopeTree; |
|
1416 | - $cur = $this->data; |
|
1417 | - |
|
1418 | - while (true) { |
|
1419 | - array_pop($tree); |
|
1420 | - array_shift($m[2]); |
|
1421 | - array_shift($m[1]); |
|
1422 | - if (current($m[2]) === '_' || current($m[2]) === '_parent') { |
|
1423 | - continue; |
|
1424 | - } |
|
1425 | - |
|
1426 | - while (($i = array_shift($tree)) !== null) { |
|
1427 | - if (is_object($cur)) { |
|
1428 | - $cur = $cur->$i; |
|
1429 | - } else { |
|
1430 | - $cur = $cur[$i]; |
|
1431 | - } |
|
1432 | - } |
|
1433 | - break; |
|
1434 | - } |
|
1435 | - } else { |
|
1436 | - $cur = $this->scope; |
|
1437 | - } |
|
1438 | - |
|
1439 | - while (list($k, $sep) = each($m[1])) { |
|
1440 | - if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1441 | - if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) { |
|
1442 | - $cur = $cur[$m[2][$k]]; |
|
1443 | - } else { |
|
1444 | - return null; |
|
1445 | - } |
|
1446 | - } elseif ($sep === '->') { |
|
1447 | - if (is_object($cur)) { |
|
1448 | - $cur = $cur->$m[2][$k]; |
|
1449 | - } else { |
|
1450 | - return null; |
|
1451 | - } |
|
1452 | - } else { |
|
1453 | - return null; |
|
1454 | - } |
|
1455 | - } |
|
1456 | - |
|
1457 | - return $cur; |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * [runtime function] assign the value to the given variable |
|
1462 | - * |
|
1463 | - * @param mixed $value the value to assign |
|
1464 | - * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1465 | - * @return bool true if assigned correctly or false if a problem occured while parsing the var string |
|
1466 | - */ |
|
1467 | - public function assignInScope($value, $scope) |
|
1468 | - { |
|
1469 | - $tree =& $this->scopeTree; |
|
1470 | - $data =& $this->data; |
|
1471 | - |
|
1472 | - if (!is_string($scope)) { |
|
1473 | - return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR); |
|
1474 | - } |
|
1475 | - if (strstr($scope, '.') === false && strstr($scope, '->') === false) { |
|
1476 | - $this->scope[$scope] = $value; |
|
1477 | - } else { |
|
1478 | - // TODO handle _root/_parent scopes ? |
|
1479 | - preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m); |
|
1480 | - |
|
1481 | - $cur =& $this->scope; |
|
1482 | - $last = array(array_pop($m[1]), array_pop($m[2])); |
|
1483 | - |
|
1484 | - while (list($k, $sep) = each($m[1])) { |
|
1485 | - if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1486 | - if (is_array($cur) === false) { |
|
1487 | - $cur = array(); |
|
1488 | - } |
|
1489 | - $cur =& $cur[$m[2][$k]]; |
|
1490 | - } elseif ($sep === '->') { |
|
1491 | - if (is_object($cur) === false) { |
|
1492 | - $cur = new stdClass; |
|
1493 | - } |
|
1494 | - $cur =& $cur->$m[2][$k]; |
|
1495 | - } else { |
|
1496 | - return false; |
|
1497 | - } |
|
1498 | - } |
|
1499 | - |
|
1500 | - if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') { |
|
1501 | - if (is_array($cur) === false) { |
|
1502 | - $cur = array(); |
|
1503 | - } |
|
1504 | - $cur[$last[1]] = $value; |
|
1505 | - } elseif ($last[0] === '->') { |
|
1506 | - if (is_object($cur) === false) { |
|
1507 | - $cur = new stdClass; |
|
1508 | - } |
|
1509 | - $cur->$last[1] = $value; |
|
1510 | - } else { |
|
1511 | - return false; |
|
1512 | - } |
|
1513 | - } |
|
1514 | - } |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * [runtime function] sets the scope to the given scope string or array |
|
1518 | - * |
|
1519 | - * @param mixed $scope a string i.e. "level1.level2" or an array i.e. array("level1", "level2") |
|
1520 | - * @param bool $absolute if true, the scope is set from the top level scope and not from the current scope |
|
1521 | - * @return array the current scope tree |
|
1522 | - */ |
|
1523 | - public function setScope($scope, $absolute = false) |
|
1524 | - { |
|
1525 | - $old = $this->scopeTree; |
|
1526 | - |
|
1527 | - if (is_string($scope)===true) { |
|
1528 | - $scope = explode('.', $scope); |
|
1529 | - } |
|
1530 | - |
|
1531 | - if ($absolute===true) { |
|
1532 | - $this->scope =& $this->data; |
|
1533 | - $this->scopeTree = array(); |
|
1534 | - } |
|
1535 | - |
|
1536 | - while (($bit = array_shift($scope)) !== null) { |
|
1537 | - if ($bit === '_' || $bit === '_parent') { |
|
1538 | - array_pop($this->scopeTree); |
|
1539 | - $this->scope =& $this->data; |
|
1540 | - $cnt = count($this->scopeTree); |
|
1541 | - for ($i=0;$i<$cnt;$i++) |
|
1542 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1543 | - } elseif ($bit === '__' || $bit === '_root') { |
|
1544 | - $this->scope =& $this->data; |
|
1545 | - $this->scopeTree = array(); |
|
1546 | - } elseif (isset($this->scope[$bit])) { |
|
1547 | - if($this->scope instanceof ArrayAccess) { |
|
1548 | - $tmp = $this->scope[$bit]; |
|
1549 | - $this->scope =& $tmp; |
|
1550 | - } else { |
|
1551 | - $this->scope =& $this->scope[$bit]; |
|
1552 | - } |
|
1553 | - $this->scopeTree[] = $bit; |
|
1554 | - } else { |
|
1555 | - unset($this->scope); |
|
1556 | - $this->scope = null; |
|
1557 | - } |
|
1558 | - } |
|
1559 | - |
|
1560 | - return $old; |
|
1561 | - } |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * [runtime function] returns the entire data array |
|
1565 | - * |
|
1566 | - * @return array |
|
1567 | - */ |
|
1568 | - public function getData() |
|
1569 | - { |
|
1570 | - return $this->data; |
|
1571 | - } |
|
1365 | + preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); |
|
1366 | + } |
|
1367 | + |
|
1368 | + $i = $m[2][0]; |
|
1369 | + if ($i === 'dwoo') { |
|
1370 | + $cur = $this->globals; |
|
1371 | + array_shift($m[2]); |
|
1372 | + array_shift($m[1]); |
|
1373 | + switch ($m[2][0]) { |
|
1374 | + |
|
1375 | + case 'get': |
|
1376 | + $cur = $_GET; |
|
1377 | + break; |
|
1378 | + case 'post': |
|
1379 | + $cur = $_POST; |
|
1380 | + break; |
|
1381 | + case 'session': |
|
1382 | + $cur = $_SESSION; |
|
1383 | + break; |
|
1384 | + case 'cookies': |
|
1385 | + case 'cookie': |
|
1386 | + $cur = $_COOKIE; |
|
1387 | + break; |
|
1388 | + case 'server': |
|
1389 | + $cur = $_SERVER; |
|
1390 | + break; |
|
1391 | + case 'env': |
|
1392 | + $cur = $_ENV; |
|
1393 | + break; |
|
1394 | + case 'request': |
|
1395 | + $cur = $_REQUEST; |
|
1396 | + break; |
|
1397 | + case 'const': |
|
1398 | + array_shift($m[2]); |
|
1399 | + if (defined($m[2][0])) { |
|
1400 | + return constant($m[2][0]); |
|
1401 | + } else { |
|
1402 | + return null; |
|
1403 | + } |
|
1572 | 1404 | |
1573 | - /** |
|
1574 | - * [runtime function] sets a return value for the currently running template |
|
1575 | - * |
|
1576 | - * @param string $name var name |
|
1577 | - * @param mixed $value var value |
|
1578 | - */ |
|
1579 | - public function setReturnValue($name, $value) |
|
1580 | - { |
|
1581 | - $this->returnData[$name] = $value; |
|
1582 | - } |
|
1405 | + } |
|
1406 | + if ($cur !== $this->globals) { |
|
1407 | + array_shift($m[2]); |
|
1408 | + array_shift($m[1]); |
|
1409 | + } |
|
1410 | + } elseif ($i === '__' || $i === '_root') { |
|
1411 | + $cur = $this->data; |
|
1412 | + array_shift($m[2]); |
|
1413 | + array_shift($m[1]); |
|
1414 | + } elseif ($i === '_' || $i === '_parent') { |
|
1415 | + $tree = $this->scopeTree; |
|
1416 | + $cur = $this->data; |
|
1417 | + |
|
1418 | + while (true) { |
|
1419 | + array_pop($tree); |
|
1420 | + array_shift($m[2]); |
|
1421 | + array_shift($m[1]); |
|
1422 | + if (current($m[2]) === '_' || current($m[2]) === '_parent') { |
|
1423 | + continue; |
|
1424 | + } |
|
1583 | 1425 | |
1584 | - /** |
|
1585 | - * [runtime function] retrieves the return values set by the template |
|
1586 | - * |
|
1587 | - * @return array |
|
1588 | - */ |
|
1589 | - public function getReturnValues() |
|
1590 | - { |
|
1591 | - return $this->returnData; |
|
1592 | - } |
|
1426 | + while (($i = array_shift($tree)) !== null) { |
|
1427 | + if (is_object($cur)) { |
|
1428 | + $cur = $cur->$i; |
|
1429 | + } else { |
|
1430 | + $cur = $cur[$i]; |
|
1431 | + } |
|
1432 | + } |
|
1433 | + break; |
|
1434 | + } |
|
1435 | + } else { |
|
1436 | + $cur = $this->scope; |
|
1437 | + } |
|
1593 | 1438 | |
1594 | - /** |
|
1595 | - * [runtime function] returns a reference to the current scope |
|
1596 | - * |
|
1597 | - * @return &mixed |
|
1598 | - */ |
|
1599 | - public function &getScope() |
|
1600 | - { |
|
1601 | - return $this->scope; |
|
1602 | - } |
|
1439 | + while (list($k, $sep) = each($m[1])) { |
|
1440 | + if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1441 | + if ((is_array($cur) || $cur instanceof ArrayAccess) && isset($cur[$m[2][$k]])) { |
|
1442 | + $cur = $cur[$m[2][$k]]; |
|
1443 | + } else { |
|
1444 | + return null; |
|
1445 | + } |
|
1446 | + } elseif ($sep === '->') { |
|
1447 | + if (is_object($cur)) { |
|
1448 | + $cur = $cur->$m[2][$k]; |
|
1449 | + } else { |
|
1450 | + return null; |
|
1451 | + } |
|
1452 | + } else { |
|
1453 | + return null; |
|
1454 | + } |
|
1455 | + } |
|
1456 | + |
|
1457 | + return $cur; |
|
1458 | + } |
|
1459 | + |
|
1460 | + /** |
|
1461 | + * [runtime function] assign the value to the given variable |
|
1462 | + * |
|
1463 | + * @param mixed $value the value to assign |
|
1464 | + * @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") |
|
1465 | + * @return bool true if assigned correctly or false if a problem occured while parsing the var string |
|
1466 | + */ |
|
1467 | + public function assignInScope($value, $scope) |
|
1468 | + { |
|
1469 | + $tree =& $this->scopeTree; |
|
1470 | + $data =& $this->data; |
|
1471 | + |
|
1472 | + if (!is_string($scope)) { |
|
1473 | + return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR); |
|
1474 | + } |
|
1475 | + if (strstr($scope, '.') === false && strstr($scope, '->') === false) { |
|
1476 | + $this->scope[$scope] = $value; |
|
1477 | + } else { |
|
1478 | + // TODO handle _root/_parent scopes ? |
|
1479 | + preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m); |
|
1480 | + |
|
1481 | + $cur =& $this->scope; |
|
1482 | + $last = array(array_pop($m[1]), array_pop($m[2])); |
|
1483 | + |
|
1484 | + while (list($k, $sep) = each($m[1])) { |
|
1485 | + if ($sep === '.' || $sep === '[' || $sep === '') { |
|
1486 | + if (is_array($cur) === false) { |
|
1487 | + $cur = array(); |
|
1488 | + } |
|
1489 | + $cur =& $cur[$m[2][$k]]; |
|
1490 | + } elseif ($sep === '->') { |
|
1491 | + if (is_object($cur) === false) { |
|
1492 | + $cur = new stdClass; |
|
1493 | + } |
|
1494 | + $cur =& $cur->$m[2][$k]; |
|
1495 | + } else { |
|
1496 | + return false; |
|
1497 | + } |
|
1498 | + } |
|
1603 | 1499 | |
1604 | - /** |
|
1605 | - * Redirects all calls to unexisting to plugin proxy. |
|
1606 | - * |
|
1607 | - * @param string Method name |
|
1608 | - * @param array List of arguments |
|
1609 | - * @return mixed |
|
1610 | - */ |
|
1611 | - public function __call($method, $args) { |
|
1612 | - $proxy = $this->getPluginProxy(); |
|
1613 | - if (!$proxy) { |
|
1614 | - throw new Dwoo_Exception('Call to undefined method '.__CLASS__.'::'.$method.'()'); |
|
1615 | - } |
|
1616 | - return call_user_func_array($proxy->getCallback($method), $args); |
|
1617 | - } |
|
1500 | + if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') { |
|
1501 | + if (is_array($cur) === false) { |
|
1502 | + $cur = array(); |
|
1503 | + } |
|
1504 | + $cur[$last[1]] = $value; |
|
1505 | + } elseif ($last[0] === '->') { |
|
1506 | + if (is_object($cur) === false) { |
|
1507 | + $cur = new stdClass; |
|
1508 | + } |
|
1509 | + $cur->$last[1] = $value; |
|
1510 | + } else { |
|
1511 | + return false; |
|
1512 | + } |
|
1513 | + } |
|
1514 | + } |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * [runtime function] sets the scope to the given scope string or array |
|
1518 | + * |
|
1519 | + * @param mixed $scope a string i.e. "level1.level2" or an array i.e. array("level1", "level2") |
|
1520 | + * @param bool $absolute if true, the scope is set from the top level scope and not from the current scope |
|
1521 | + * @return array the current scope tree |
|
1522 | + */ |
|
1523 | + public function setScope($scope, $absolute = false) |
|
1524 | + { |
|
1525 | + $old = $this->scopeTree; |
|
1526 | + |
|
1527 | + if (is_string($scope)===true) { |
|
1528 | + $scope = explode('.', $scope); |
|
1529 | + } |
|
1530 | + |
|
1531 | + if ($absolute===true) { |
|
1532 | + $this->scope =& $this->data; |
|
1533 | + $this->scopeTree = array(); |
|
1534 | + } |
|
1535 | + |
|
1536 | + while (($bit = array_shift($scope)) !== null) { |
|
1537 | + if ($bit === '_' || $bit === '_parent') { |
|
1538 | + array_pop($this->scopeTree); |
|
1539 | + $this->scope =& $this->data; |
|
1540 | + $cnt = count($this->scopeTree); |
|
1541 | + for ($i=0;$i<$cnt;$i++) |
|
1542 | + $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1543 | + } elseif ($bit === '__' || $bit === '_root') { |
|
1544 | + $this->scope =& $this->data; |
|
1545 | + $this->scopeTree = array(); |
|
1546 | + } elseif (isset($this->scope[$bit])) { |
|
1547 | + if($this->scope instanceof ArrayAccess) { |
|
1548 | + $tmp = $this->scope[$bit]; |
|
1549 | + $this->scope =& $tmp; |
|
1550 | + } else { |
|
1551 | + $this->scope =& $this->scope[$bit]; |
|
1552 | + } |
|
1553 | + $this->scopeTree[] = $bit; |
|
1554 | + } else { |
|
1555 | + unset($this->scope); |
|
1556 | + $this->scope = null; |
|
1557 | + } |
|
1558 | + } |
|
1559 | + |
|
1560 | + return $old; |
|
1561 | + } |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * [runtime function] returns the entire data array |
|
1565 | + * |
|
1566 | + * @return array |
|
1567 | + */ |
|
1568 | + public function getData() |
|
1569 | + { |
|
1570 | + return $this->data; |
|
1571 | + } |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * [runtime function] sets a return value for the currently running template |
|
1575 | + * |
|
1576 | + * @param string $name var name |
|
1577 | + * @param mixed $value var value |
|
1578 | + */ |
|
1579 | + public function setReturnValue($name, $value) |
|
1580 | + { |
|
1581 | + $this->returnData[$name] = $value; |
|
1582 | + } |
|
1583 | + |
|
1584 | + /** |
|
1585 | + * [runtime function] retrieves the return values set by the template |
|
1586 | + * |
|
1587 | + * @return array |
|
1588 | + */ |
|
1589 | + public function getReturnValues() |
|
1590 | + { |
|
1591 | + return $this->returnData; |
|
1592 | + } |
|
1593 | + |
|
1594 | + /** |
|
1595 | + * [runtime function] returns a reference to the current scope |
|
1596 | + * |
|
1597 | + * @return &mixed |
|
1598 | + */ |
|
1599 | + public function &getScope() |
|
1600 | + { |
|
1601 | + return $this->scope; |
|
1602 | + } |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Redirects all calls to unexisting to plugin proxy. |
|
1606 | + * |
|
1607 | + * @param string Method name |
|
1608 | + * @param array List of arguments |
|
1609 | + * @return mixed |
|
1610 | + */ |
|
1611 | + public function __call($method, $args) { |
|
1612 | + $proxy = $this->getPluginProxy(); |
|
1613 | + if (!$proxy) { |
|
1614 | + throw new Dwoo_Exception('Call to undefined method '.__CLASS__.'::'.$method.'()'); |
|
1615 | + } |
|
1616 | + return call_user_func_array($proxy->getCallback($method), $args); |
|
1617 | + } |
|
1618 | 1618 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!defined('DWOO_DIRECTORY')) { |
4 | - define('DWOO_DIRECTORY', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); |
|
4 | + define('DWOO_DIRECTORY', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR); |
|
5 | 5 | } |
6 | 6 | /** |
7 | 7 | * main dwoo class, allows communication between the compiler, template and data classes |
@@ -160,15 +160,12 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @var array |
162 | 162 | */ |
163 | - protected $resources = array |
|
164 | - ( |
|
165 | - 'file' => array |
|
166 | - ( |
|
163 | + protected $resources = array( |
|
164 | + 'file' => array( |
|
167 | 165 | 'class' => 'Dwoo_Template_File', |
168 | 166 | 'compiler' => null |
169 | 167 | ), |
170 | - 'string' => array |
|
171 | - ( |
|
168 | + 'string' => array( |
|
172 | 169 | 'class' => 'Dwoo_Template_String', |
173 | 170 | 'compiler' => null |
174 | 171 | ) |
@@ -434,8 +431,7 @@ discard block |
||
434 | 431 | */ |
435 | 432 | protected function initGlobals() |
436 | 433 | { |
437 | - $this->globals = array |
|
438 | - ( |
|
434 | + $this->globals = array( |
|
439 | 435 | 'version' => self::VERSION, |
440 | 436 | 'ad' => '<a href="http://dwoo.org/">Powered by Dwoo</a>', |
441 | 437 | 'now' => $_SERVER['REQUEST_TIME'], |
@@ -454,7 +450,7 @@ discard block |
||
454 | 450 | protected function initRuntimeVars(Dwoo_ITemplate $tpl) |
455 | 451 | { |
456 | 452 | $this->runtimePlugins = array(); |
457 | - $this->scope =& $this->data; |
|
453 | + $this->scope = & $this->data; |
|
458 | 454 | $this->scopeTree = array(); |
459 | 455 | $this->stack = array(); |
460 | 456 | $this->curBlock = null; |
@@ -484,7 +480,7 @@ discard block |
||
484 | 480 | } else { |
485 | 481 | $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]); |
486 | 482 | } |
487 | - } elseif(is_string($callback)) { |
|
483 | + } elseif (is_string($callback)) { |
|
488 | 484 | if (class_exists($callback, false)) { |
489 | 485 | if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) { |
490 | 486 | $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback); |
@@ -496,7 +492,7 @@ discard block |
||
496 | 492 | } else { |
497 | 493 | throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); |
498 | 494 | } |
499 | - } elseif(is_callable($callback)) { |
|
495 | + } elseif (is_callable($callback)) { |
|
500 | 496 | $this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback); |
501 | 497 | } else { |
502 | 498 | throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); |
@@ -563,8 +559,8 @@ discard block |
||
563 | 559 | unset($this->filters[$index]); |
564 | 560 | } elseif (($index = array_search($callback, $this->filters, true)) !== false) { |
565 | 561 | unset($this->filters[$index]); |
566 | - } else { |
|
567 | - $class = 'Dwoo_Filter_' . $callback; |
|
562 | + } else { |
|
563 | + $class = 'Dwoo_Filter_'.$callback; |
|
568 | 564 | foreach ($this->filters as $index=>$filter) { |
569 | 565 | if (is_array($filter) && $filter[0] instanceof $class) { |
570 | 566 | unset($this->filters[$index]); |
@@ -607,7 +603,7 @@ discard block |
||
607 | 603 | public function removeResource($name) |
608 | 604 | { |
609 | 605 | unset($this->resources[$name]); |
610 | - if ($name==='file') { |
|
606 | + if ($name === 'file') { |
|
611 | 607 | $this->resources['file'] = array('class'=>'Dwoo_Template_File', 'compiler'=>null); |
612 | 608 | } |
613 | 609 | } |
@@ -856,11 +852,11 @@ discard block |
||
856 | 852 | * @param int $olderThan minimum time (in seconds) required for a cached template to be cleared |
857 | 853 | * @return int the amount of templates cleared |
858 | 854 | */ |
859 | - public function clearCache($olderThan=-1) |
|
855 | + public function clearCache($olderThan = -1) |
|
860 | 856 | { |
861 | 857 | $cacheDirs = new RecursiveDirectoryIterator($this->getCacheDir()); |
862 | 858 | $cache = new RecursiveIteratorIterator($cacheDirs); |
863 | - $expired = time() - $olderThan; |
|
859 | + $expired = time()-$olderThan; |
|
864 | 860 | $count = 0; |
865 | 861 | foreach ($cache as $file) { |
866 | 862 | if ($cache->isDot() || $cache->isDir() || substr($file, -5) !== '.html') { |
@@ -901,7 +897,7 @@ discard block |
||
901 | 897 | * and return true only if it's not empty |
902 | 898 | * @return int|bool true if it's an array|arrayaccess (or the item count if $checkIsEmpty is true) or false if it's not an array|arrayaccess (or 0 if $checkIsEmpty is true) |
903 | 899 | */ |
904 | - public function isArray($value, $checkIsEmpty=false) |
|
900 | + public function isArray($value, $checkIsEmpty = false) |
|
905 | 901 | { |
906 | 902 | if (is_array($value) === true || $value instanceof ArrayAccess) { |
907 | 903 | if ($checkIsEmpty === false) { |
@@ -920,7 +916,7 @@ discard block |
||
920 | 916 | * and return true only if it's not empty |
921 | 917 | * @return int|bool true if it's an array|traversable (or the item count if $checkIsEmpty is true) or false if it's not an array|traversable (or 0 if $checkIsEmpty is true) |
922 | 918 | */ |
923 | - public function isTraversable($value, $checkIsEmpty=false) |
|
919 | + public function isTraversable($value, $checkIsEmpty = false) |
|
924 | 920 | { |
925 | 921 | if (is_array($value) === true) { |
926 | 922 | if ($checkIsEmpty === false) { |
@@ -970,7 +966,7 @@ discard block |
||
970 | 966 | * @param string $message the error message |
971 | 967 | * @param int $level the error level, one of the PHP's E_* constants |
972 | 968 | */ |
973 | - public function triggerError($message, $level=E_USER_NOTICE) |
|
969 | + public function triggerError($message, $level = E_USER_NOTICE) |
|
974 | 970 | { |
975 | 971 | if (!($tplIdentifier = $this->template->getResourceIdentifier())) { |
976 | 972 | $tplIdentifier = $this->template->getResourceName(); |
@@ -989,7 +985,7 @@ discard block |
||
989 | 985 | * @param array $args the arguments to be passed to the block's init() function |
990 | 986 | * @return Dwoo_Block_Plugin the newly created block |
991 | 987 | */ |
992 | - public function addStack($blockName, array $args=array()) |
|
988 | + public function addStack($blockName, array $args = array()) |
|
993 | 989 | { |
994 | 990 | if (isset($this->plugins[$blockName])) { |
995 | 991 | $class = $this->plugins[$blockName]['class']; |
@@ -1008,18 +1004,18 @@ discard block |
||
1008 | 1004 | $block = new $class($this); |
1009 | 1005 | |
1010 | 1006 | $cnt = count($args); |
1011 | - if ($cnt===0) { |
|
1007 | + if ($cnt === 0) { |
|
1012 | 1008 | $block->init(); |
1013 | - } elseif ($cnt===1) { |
|
1009 | + } elseif ($cnt === 1) { |
|
1014 | 1010 | $block->init($args[0]); |
1015 | - } elseif ($cnt===2) { |
|
1011 | + } elseif ($cnt === 2) { |
|
1016 | 1012 | $block->init($args[0], $args[1]); |
1017 | - } elseif ($cnt===3) { |
|
1013 | + } elseif ($cnt === 3) { |
|
1018 | 1014 | $block->init($args[0], $args[1], $args[2]); |
1019 | - } elseif ($cnt===4) { |
|
1015 | + } elseif ($cnt === 4) { |
|
1020 | 1016 | $block->init($args[0], $args[1], $args[2], $args[3]); |
1021 | 1017 | } else { |
1022 | - call_user_func_array(array($block,'init'), $args); |
|
1018 | + call_user_func_array(array($block, 'init'), $args); |
|
1023 | 1019 | } |
1024 | 1020 | |
1025 | 1021 | $this->stack[] = $this->curBlock = $block; |
@@ -1040,15 +1036,15 @@ discard block |
||
1040 | 1036 | ob_clean(); |
1041 | 1037 | |
1042 | 1038 | $cnt = count($args); |
1043 | - if ($cnt===0) { |
|
1039 | + if ($cnt === 0) { |
|
1044 | 1040 | $this->curBlock->end(); |
1045 | - } elseif ($cnt===1) { |
|
1041 | + } elseif ($cnt === 1) { |
|
1046 | 1042 | $this->curBlock->end($args[0]); |
1047 | - } elseif ($cnt===2) { |
|
1043 | + } elseif ($cnt === 2) { |
|
1048 | 1044 | $this->curBlock->end($args[0], $args[1]); |
1049 | - } elseif ($cnt===3) { |
|
1045 | + } elseif ($cnt === 3) { |
|
1050 | 1046 | $this->curBlock->end($args[0], $args[1], $args[2]); |
1051 | - } elseif ($cnt===4) { |
|
1047 | + } elseif ($cnt === 4) { |
|
1052 | 1048 | $this->curBlock->end($args[0], $args[1], $args[2], $args[3]); |
1053 | 1049 | } else { |
1054 | 1050 | call_user_func_array(array($this->curBlock, 'end'), $args); |
@@ -1060,7 +1056,7 @@ discard block |
||
1060 | 1056 | $this->curBlock = end($this->stack); |
1061 | 1057 | $this->curBlock->buffer($tmp->process()); |
1062 | 1058 | } else { |
1063 | - if($this->buffer !== '') { |
|
1059 | + if ($this->buffer !== '') { |
|
1064 | 1060 | echo $this->buffer; |
1065 | 1061 | $this->buffer = ''; |
1066 | 1062 | } |
@@ -1141,15 +1137,15 @@ discard block |
||
1141 | 1137 | $plugin = $this->getObjectPlugin($class); |
1142 | 1138 | |
1143 | 1139 | $cnt = count($params); |
1144 | - if ($cnt===0) { |
|
1140 | + if ($cnt === 0) { |
|
1145 | 1141 | return $plugin->process(); |
1146 | - } elseif ($cnt===1) { |
|
1142 | + } elseif ($cnt === 1) { |
|
1147 | 1143 | return $plugin->process($params[0]); |
1148 | - } elseif ($cnt===2) { |
|
1144 | + } elseif ($cnt === 2) { |
|
1149 | 1145 | return $plugin->process($params[0], $params[1]); |
1150 | - } elseif ($cnt===3) { |
|
1146 | + } elseif ($cnt === 3) { |
|
1151 | 1147 | return $plugin->process($params[0], $params[1], $params[2]); |
1152 | - } elseif ($cnt===4) { |
|
1148 | + } elseif ($cnt === 4) { |
|
1153 | 1149 | return $plugin->process($params[0], $params[1], $params[2], $params[3]); |
1154 | 1150 | } else { |
1155 | 1151 | return call_user_func_array(array($plugin, 'process'), $params); |
@@ -1185,23 +1181,23 @@ discard block |
||
1185 | 1181 | |
1186 | 1182 | if (is_string($callback) === false) { |
1187 | 1183 | while (($i = array_shift($keys)) !== null) { |
1188 | - $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1184 | + $out[] = call_user_func_array($callback, array(1=>$items[$i])+$params); |
|
1189 | 1185 | } |
1190 | - } elseif ($cnt===1) { |
|
1186 | + } elseif ($cnt === 1) { |
|
1191 | 1187 | while (($i = array_shift($keys)) !== null) { |
1192 | 1188 | $out[] = $callback($this, $items[$i]); |
1193 | 1189 | } |
1194 | - } elseif ($cnt===2) { |
|
1190 | + } elseif ($cnt === 2) { |
|
1195 | 1191 | while (($i = array_shift($keys)) !== null) { |
1196 | 1192 | $out[] = $callback($this, $items[$i], $params[2]); |
1197 | 1193 | } |
1198 | - } elseif ($cnt===3) { |
|
1194 | + } elseif ($cnt === 3) { |
|
1199 | 1195 | while (($i = array_shift($keys)) !== null) { |
1200 | 1196 | $out[] = $callback($this, $items[$i], $params[2], $params[3]); |
1201 | 1197 | } |
1202 | 1198 | } else { |
1203 | 1199 | while (($i = array_shift($keys)) !== null) { |
1204 | - $out[] = call_user_func_array($callback, array(1=>$items[$i]) + $params); |
|
1200 | + $out[] = call_user_func_array($callback, array(1=>$items[$i])+$params); |
|
1205 | 1201 | } |
1206 | 1202 | } |
1207 | 1203 | } else { |
@@ -1210,27 +1206,27 @@ discard block |
||
1210 | 1206 | |
1211 | 1207 | if (is_string($callback) === false) { |
1212 | 1208 | while (($i = array_shift($keys)) !== null) { |
1213 | - $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1209 | + $out[] = call_user_func_array($callback, array($items[$i])+$params); |
|
1214 | 1210 | } |
1215 | - } elseif ($cnt===1) { |
|
1211 | + } elseif ($cnt === 1) { |
|
1216 | 1212 | while (($i = array_shift($keys)) !== null) { |
1217 | 1213 | $out[] = $callback($items[$i]); |
1218 | 1214 | } |
1219 | - } elseif ($cnt===2) { |
|
1215 | + } elseif ($cnt === 2) { |
|
1220 | 1216 | while (($i = array_shift($keys)) !== null) { |
1221 | 1217 | $out[] = $callback($items[$i], $params[1]); |
1222 | 1218 | } |
1223 | - } elseif ($cnt===3) { |
|
1219 | + } elseif ($cnt === 3) { |
|
1224 | 1220 | while (($i = array_shift($keys)) !== null) { |
1225 | 1221 | $out[] = $callback($items[$i], $params[1], $params[2]); |
1226 | 1222 | } |
1227 | - } elseif ($cnt===4) { |
|
1223 | + } elseif ($cnt === 4) { |
|
1228 | 1224 | while (($i = array_shift($keys)) !== null) { |
1229 | 1225 | $out[] = $callback($items[$i], $params[1], $params[2], $params[3]); |
1230 | 1226 | } |
1231 | 1227 | } else { |
1232 | 1228 | while (($i = array_shift($keys)) !== null) { |
1233 | - $out[] = call_user_func_array($callback, array($items[$i]) + $params); |
|
1229 | + $out[] = call_user_func_array($callback, array($items[$i])+$params); |
|
1234 | 1230 | } |
1235 | 1231 | } |
1236 | 1232 | } |
@@ -1295,7 +1291,7 @@ discard block |
||
1295 | 1291 | $tree = $this->scopeTree; |
1296 | 1292 | $cur = $this->data; |
1297 | 1293 | |
1298 | - while ($parentLevels--!==0) { |
|
1294 | + while ($parentLevels-- !== 0) { |
|
1299 | 1295 | array_pop($tree); |
1300 | 1296 | } |
1301 | 1297 | |
@@ -1307,7 +1303,7 @@ discard block |
||
1307 | 1303 | } |
1308 | 1304 | } |
1309 | 1305 | |
1310 | - if ($varstr!==null) { |
|
1306 | + if ($varstr !== null) { |
|
1311 | 1307 | return $this->readVarInto($varstr, $cur); |
1312 | 1308 | } else { |
1313 | 1309 | return $cur; |
@@ -1322,14 +1318,14 @@ discard block |
||
1322 | 1318 | */ |
1323 | 1319 | public function readVar($varstr) |
1324 | 1320 | { |
1325 | - if (is_array($varstr)===true) { |
|
1321 | + if (is_array($varstr) === true) { |
|
1326 | 1322 | $m = $varstr; |
1327 | 1323 | unset($varstr); |
1328 | 1324 | } else { |
1329 | 1325 | if (strstr($varstr, '.') === false && strstr($varstr, '[') === false && strstr($varstr, '->') === false) { |
1330 | 1326 | if ($varstr === 'dwoo') { |
1331 | 1327 | return $this->globals; |
1332 | - } elseif ($varstr === '__' || $varstr === '_root' ) { |
|
1328 | + } elseif ($varstr === '__' || $varstr === '_root') { |
|
1333 | 1329 | return $this->data; |
1334 | 1330 | $varstr = substr($varstr, 6); |
1335 | 1331 | } elseif ($varstr === '_' || $varstr === '_parent') { |
@@ -1466,8 +1462,8 @@ discard block |
||
1466 | 1462 | */ |
1467 | 1463 | public function assignInScope($value, $scope) |
1468 | 1464 | { |
1469 | - $tree =& $this->scopeTree; |
|
1470 | - $data =& $this->data; |
|
1465 | + $tree = & $this->scopeTree; |
|
1466 | + $data = & $this->data; |
|
1471 | 1467 | |
1472 | 1468 | if (!is_string($scope)) { |
1473 | 1469 | return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR); |
@@ -1478,7 +1474,7 @@ discard block |
||
1478 | 1474 | // TODO handle _root/_parent scopes ? |
1479 | 1475 | preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m); |
1480 | 1476 | |
1481 | - $cur =& $this->scope; |
|
1477 | + $cur = & $this->scope; |
|
1482 | 1478 | $last = array(array_pop($m[1]), array_pop($m[2])); |
1483 | 1479 | |
1484 | 1480 | while (list($k, $sep) = each($m[1])) { |
@@ -1486,12 +1482,12 @@ discard block |
||
1486 | 1482 | if (is_array($cur) === false) { |
1487 | 1483 | $cur = array(); |
1488 | 1484 | } |
1489 | - $cur =& $cur[$m[2][$k]]; |
|
1485 | + $cur = & $cur[$m[2][$k]]; |
|
1490 | 1486 | } elseif ($sep === '->') { |
1491 | 1487 | if (is_object($cur) === false) { |
1492 | 1488 | $cur = new stdClass; |
1493 | 1489 | } |
1494 | - $cur =& $cur->$m[2][$k]; |
|
1490 | + $cur = & $cur->$m[2][$k]; |
|
1495 | 1491 | } else { |
1496 | 1492 | return false; |
1497 | 1493 | } |
@@ -1524,31 +1520,31 @@ discard block |
||
1524 | 1520 | { |
1525 | 1521 | $old = $this->scopeTree; |
1526 | 1522 | |
1527 | - if (is_string($scope)===true) { |
|
1523 | + if (is_string($scope) === true) { |
|
1528 | 1524 | $scope = explode('.', $scope); |
1529 | 1525 | } |
1530 | 1526 | |
1531 | - if ($absolute===true) { |
|
1532 | - $this->scope =& $this->data; |
|
1527 | + if ($absolute === true) { |
|
1528 | + $this->scope = & $this->data; |
|
1533 | 1529 | $this->scopeTree = array(); |
1534 | 1530 | } |
1535 | 1531 | |
1536 | 1532 | while (($bit = array_shift($scope)) !== null) { |
1537 | 1533 | if ($bit === '_' || $bit === '_parent') { |
1538 | 1534 | array_pop($this->scopeTree); |
1539 | - $this->scope =& $this->data; |
|
1535 | + $this->scope = & $this->data; |
|
1540 | 1536 | $cnt = count($this->scopeTree); |
1541 | - for ($i=0;$i<$cnt;$i++) |
|
1542 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1537 | + for ($i = 0; $i < $cnt; $i++) |
|
1538 | + $this->scope = & $this->scope[$this->scopeTree[$i]]; |
|
1543 | 1539 | } elseif ($bit === '__' || $bit === '_root') { |
1544 | - $this->scope =& $this->data; |
|
1540 | + $this->scope = & $this->data; |
|
1545 | 1541 | $this->scopeTree = array(); |
1546 | 1542 | } elseif (isset($this->scope[$bit])) { |
1547 | - if($this->scope instanceof ArrayAccess) { |
|
1543 | + if ($this->scope instanceof ArrayAccess) { |
|
1548 | 1544 | $tmp = $this->scope[$bit]; |
1549 | - $this->scope =& $tmp; |
|
1545 | + $this->scope = & $tmp; |
|
1550 | 1546 | } else { |
1551 | - $this->scope =& $this->scope[$bit]; |
|
1547 | + $this->scope = & $this->scope[$bit]; |
|
1552 | 1548 | } |
1553 | 1549 | $this->scopeTree[] = $bit; |
1554 | 1550 | } else { |
@@ -1538,8 +1538,9 @@ |
||
1538 | 1538 | array_pop($this->scopeTree); |
1539 | 1539 | $this->scope =& $this->data; |
1540 | 1540 | $cnt = count($this->scopeTree); |
1541 | - for ($i=0;$i<$cnt;$i++) |
|
1542 | - $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1541 | + for ($i=0;$i<$cnt;$i++) { |
|
1542 | + $this->scope =& $this->scope[$this->scopeTree[$i]]; |
|
1543 | + } |
|
1543 | 1544 | } elseif ($bit === '__' || $bit === '_root') { |
1544 | 1545 | $this->scope =& $this->data; |
1545 | 1546 | $this->scopeTree = array(); |
@@ -66,7 +66,6 @@ |
||
66 | 66 | * merges the given array(s) with the current data with array_merge |
67 | 67 | * |
68 | 68 | * @param array $data the array to merge |
69 | - * @param array $data2 $data3 ... other arrays to merge, optional, etc. |
|
70 | 69 | */ |
71 | 70 | public function mergeData(array $data) |
72 | 71 | { |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | if (is_array($name)) { |
92 | 92 | reset($name); |
93 | - while (list($k,$v) = each($name)) |
|
93 | + while (list($k, $v) = each($name)) |
|
94 | 94 | $this->data[$k] = $v; |
95 | 95 | } else { |
96 | 96 | $this->data[$name] = $val; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function assignByRef($name, &$val) |
119 | 119 | { |
120 | - $this->data[$name] =& $val; |
|
120 | + $this->data[$name] = & $val; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | if ($merge === true && is_array($val)) { |
141 | - $this->data[$key] = $val + $this->data[$key]; |
|
141 | + $this->data[$key] = $val+$this->data[$key]; |
|
142 | 142 | } else { |
143 | 143 | $this->data[$key][] = $val; |
144 | 144 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | if ($merge === true && is_array($val)) { |
154 | - $this->data[$name] = $val + $this->data[$name]; |
|
154 | + $this->data[$name] = $val+$this->data[$name]; |
|
155 | 155 | } else { |
156 | 156 | $this->data[$name][] = $val; |
157 | 157 | } |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | |
175 | 175 | if ($merge === true && is_array($val)) { |
176 | 176 | foreach ($val as $key => &$val) { |
177 | - $this->data[$name][$key] =& $val; |
|
177 | + $this->data[$name][$key] = & $val; |
|
178 | 178 | } |
179 | 179 | } else { |
180 | - $this->data[$name][] =& $val; |
|
180 | + $this->data[$name][] = & $val; |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 |
@@ -45,8 +45,9 @@ discard block |
||
45 | 45 | if ($name === null) { |
46 | 46 | $this->data = array(); |
47 | 47 | } elseif (is_array($name)) { |
48 | - foreach ($name as $index) |
|
49 | - unset($this->data[$index]); |
|
48 | + foreach ($name as $index) { |
|
49 | + unset($this->data[$index]); |
|
50 | + } |
|
50 | 51 | } else { |
51 | 52 | unset($this->data[$name]); |
52 | 53 | } |
@@ -90,8 +91,9 @@ discard block |
||
90 | 91 | { |
91 | 92 | if (is_array($name)) { |
92 | 93 | reset($name); |
93 | - while (list($k,$v) = each($name)) |
|
94 | - $this->data[$k] = $v; |
|
94 | + while (list($k,$v) = each($name)) { |
|
95 | + $this->data[$k] = $v; |
|
96 | + } |
|
95 | 97 | } else { |
96 | 98 | $this->data[$name] = $val; |
97 | 99 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * compiles the provided string down to php code |
26 | 26 | * |
27 | - * @param string $templateStr the template to compile |
|
27 | + * @param string $template the template to compile |
|
28 | 28 | * @return string a compiled php code string |
29 | 29 | */ |
30 | 30 | public function compile(Dwoo_Core $dwoo, Dwoo_ITemplate $template); |
@@ -34,6 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @see Dwoo_Core::addPlugin |
36 | 36 | * @param array $customPlugins an array of custom plugins |
37 | + * @return void |
|
37 | 38 | */ |
38 | 39 | public function setCustomPlugins(array $customPlugins); |
39 | 40 | |
@@ -44,6 +45,7 @@ discard block |
||
44 | 45 | * set it on the Dwoo object as it will be passed onto the compiler automatically |
45 | 46 | * |
46 | 47 | * @param Dwoo_Security_Policy $policy the security policy object |
48 | + * @return void |
|
47 | 49 | */ |
48 | 50 | public function setSecurityPolicy(Dwoo_Security_Policy $policy = null); |
49 | 51 | } |
@@ -42,6 +42,9 @@ |
||
42 | 42 | |
43 | 43 | protected $corePluginDir; |
44 | 44 | |
45 | + /** |
|
46 | + * @param string $cacheDir |
|
47 | + */ |
|
45 | 48 | public function __construct($cacheDir) |
46 | 49 | { |
47 | 50 | $this->corePluginDir = DWOO_DIRECTORY . 'plugins'; |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | |
45 | 45 | public function __construct($cacheDir) |
46 | 46 | { |
47 | - $this->corePluginDir = DWOO_DIRECTORY . 'plugins'; |
|
48 | - $this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
47 | + $this->corePluginDir = DWOO_DIRECTORY.'plugins'; |
|
48 | + $this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
49 | 49 | |
50 | 50 | // include class paths or rebuild paths if the cache file isn't there |
51 | 51 | $cacheFile = $this->cacheDir.'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php'; |
52 | 52 | if (file_exists($cacheFile)) { |
53 | 53 | $classpath = file_get_contents($cacheFile); |
54 | - $this->classPath = unserialize($classpath) + $this->classPath; |
|
54 | + $this->classPath = unserialize($classpath)+$this->classPath; |
|
55 | 55 | } else { |
56 | 56 | $this->rebuildClassPathCache($this->corePluginDir, $cacheFile); |
57 | 57 | } |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function rebuildClassPathCache($path, $cacheFile) |
67 | 67 | { |
68 | - if ($cacheFile!==false) { |
|
68 | + if ($cacheFile !== false) { |
|
69 | 69 | $tmp = $this->classPath; |
70 | 70 | $this->classPath = array(); |
71 | 71 | } |
72 | 72 | |
73 | 73 | // iterates over all files/folders |
74 | - $list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'); |
|
74 | + $list = glob(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'*'); |
|
75 | 75 | if (is_array($list)) { |
76 | 76 | foreach ($list as $f) { |
77 | 77 | if (is_dir($f)) { |
78 | 78 | $this->rebuildClassPathCache($f, false); |
79 | 79 | } else { |
80 | - $this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f; |
|
80 | + $this->classPath[str_replace(array('function.', 'block.', 'modifier.', 'outputfilter.', 'filter.', 'prefilter.', 'postfilter.', 'pre.', 'post.', 'output.', 'shared.', 'helper.'), '', basename($f, '.php'))] = $f; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | // save in file if it's the first call (not recursed) |
86 | - if ($cacheFile!==false) { |
|
86 | + if ($cacheFile !== false) { |
|
87 | 87 | if (!file_put_contents($cacheFile, serialize($this->classPath))) { |
88 | 88 | throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'); |
89 | 89 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | !(include $this->classPath[$class])) |
110 | 110 | { |
111 | 111 | if ($forceRehash) { |
112 | - $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php'); |
|
112 | + $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir.'classpath.cache.d'.Dwoo_Core::RELEASE_TAG.'.php'); |
|
113 | 113 | foreach ($this->paths as $path=>$file) { |
114 | 114 | $this->rebuildClassPathCache($path, $file); |
115 | 115 | } |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | if (!$pluginDir) { |
143 | 143 | throw new Dwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory); |
144 | 144 | } |
145 | - $cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo_Core::RELEASE_TAG.'.php'; |
|
145 | + $cacheFile = $this->cacheDir.'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo_Core::RELEASE_TAG.'.php'; |
|
146 | 146 | $this->paths[$pluginDir] = $cacheFile; |
147 | 147 | if (file_exists($cacheFile)) { |
148 | 148 | $classpath = file_get_contents($cacheFile); |
149 | - $this->classPath = unserialize($classpath) + $this->classPath; |
|
149 | + $this->classPath = unserialize($classpath)+$this->classPath; |
|
150 | 150 | } else { |
151 | 151 | $this->rebuildClassPathCache($pluginDir, $cacheFile); |
152 | 152 | } |
@@ -27,7 +27,6 @@ |
||
27 | 27 | * constructor, if you override it, call parent::__construct($dwoo); or assign |
28 | 28 | * the dwoo instance yourself if you need it |
29 | 29 | * |
30 | - * @param Dwoo_Core $dwoo the dwoo instance that runs this plugin |
|
31 | 30 | */ |
32 | 31 | public function __construct(Dwoo_Compiler $compiler) |
33 | 32 | { |