@@ -48,157 +48,157 @@ |
||
48 | 48 | */ |
49 | 49 | class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer |
50 | 50 | { |
51 | - /** |
|
52 | - * @constant string The directory inside the cache dir where templates will |
|
53 | - * be stored in compiled form. |
|
54 | - */ |
|
55 | - const COMPILE_DIR = 'templates'; |
|
56 | - |
|
57 | - /** |
|
58 | - * @constant string The subdirectory inside the compile dir where templates |
|
59 | - * will be stored in compiled form. |
|
60 | - */ |
|
61 | - const COMPILE_SUBDIR = 'dwoo'; |
|
62 | - |
|
63 | - /** |
|
64 | - * @constant string The directory inside the cache dir where cached content |
|
65 | - * will be stored. |
|
66 | - */ |
|
67 | - const CACHE_DIR = 'dwoo'; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var Dwoo Dwoo template engine |
|
71 | - */ |
|
72 | - protected $dwoo = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var string A string with the default template file extension, |
|
76 | - * including the dot |
|
77 | - */ |
|
78 | - protected $defaultExtension = '.html'; |
|
79 | - |
|
80 | - /** |
|
81 | - * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
82 | - */ |
|
83 | - protected $plugin_dir = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * Pre-serialization callback. |
|
87 | - * |
|
88 | - * Excludes the Dwoo instance to prevent excessive serialization load. |
|
89 | - */ |
|
90 | - public function __sleep() |
|
91 | - { |
|
92 | - $keys = parent::__sleep(); |
|
93 | - unset($keys[array_search('dwoo', $keys)]); |
|
94 | - |
|
95 | - return $keys; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Initialize this Renderer. |
|
100 | - * |
|
101 | - * @param AgaviContext The current application context |
|
102 | - * @param array An associative array of initialization parameters |
|
103 | - */ |
|
104 | - public function initialize(AgaviContext $context, array $parameters = array()) |
|
105 | - { |
|
106 | - parent::initialize($context, $parameters); |
|
107 | - |
|
108 | - $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * provides a custom compiler to the dwoo renderer with optional settings |
|
113 | - * you can set in the agavi output_types.xml config file. |
|
114 | - * |
|
115 | - * @return Dwoo_Compiler |
|
116 | - */ |
|
117 | - public function compilerFactory() |
|
118 | - { |
|
119 | - $compiler = Dwoo_Compiler::compilerFactory(); |
|
120 | - $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
121 | - |
|
122 | - return $compiler; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Grab a cleaned up dwoo instance. |
|
127 | - * |
|
128 | - * @return Dwoo A Dwoo instance |
|
129 | - */ |
|
130 | - protected function getEngine() |
|
131 | - { |
|
132 | - if ($this->dwoo) { |
|
133 | - return $this->dwoo; |
|
134 | - } |
|
135 | - |
|
136 | - // this triggers Agavi autoload |
|
137 | - if (!class_exists('Dwoo')) { |
|
138 | - if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
139 | - // file was dropped with the entire dwoo package |
|
140 | - require dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
141 | - } else { |
|
142 | - // assume the dwoo package is in the include path |
|
143 | - require 'dwooAutoload.php'; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
148 | - |
|
149 | - $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
150 | - AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
151 | - |
|
152 | - $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
153 | - AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
154 | - |
|
155 | - $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
156 | - |
|
157 | - if (!empty($this->plugin_dir)) { |
|
158 | - foreach ((array) $this->plugin_dir as $dir) { |
|
159 | - $this->dwoo->getLoader()->addDirectory($dir); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
164 | - |
|
165 | - return $this->dwoo; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Render the presentation and return the result. |
|
170 | - * |
|
171 | - * @param AgaviTemplateLayer The template layer to render |
|
172 | - * @param array The template variables |
|
173 | - * @param array The slots |
|
174 | - * @param array Associative array of additional assigns |
|
175 | - * |
|
176 | - * @return string A rendered result |
|
177 | - */ |
|
178 | - public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
179 | - { |
|
180 | - $engine = $this->getEngine(); |
|
181 | - |
|
182 | - $data = array(); |
|
183 | - if ($this->extractVars) { |
|
184 | - $data = $attributes; |
|
185 | - } else { |
|
186 | - $data[$this->varName] = &$attributes; |
|
187 | - } |
|
188 | - |
|
189 | - $data[$this->slotsVarName] = &$slots; |
|
190 | - |
|
191 | - foreach ($this->assigns as $key => $getter) { |
|
192 | - $data[$key] = $this->getContext()->$getter(); |
|
193 | - } |
|
194 | - |
|
195 | - foreach ($moreAssigns as $key => &$value) { |
|
196 | - if (isset($this->moreAssignNames[$key])) { |
|
197 | - $key = $this->moreAssignNames[$key]; |
|
198 | - } |
|
199 | - $data[$key] = &$value; |
|
200 | - } |
|
201 | - |
|
202 | - return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
203 | - } |
|
51 | + /** |
|
52 | + * @constant string The directory inside the cache dir where templates will |
|
53 | + * be stored in compiled form. |
|
54 | + */ |
|
55 | + const COMPILE_DIR = 'templates'; |
|
56 | + |
|
57 | + /** |
|
58 | + * @constant string The subdirectory inside the compile dir where templates |
|
59 | + * will be stored in compiled form. |
|
60 | + */ |
|
61 | + const COMPILE_SUBDIR = 'dwoo'; |
|
62 | + |
|
63 | + /** |
|
64 | + * @constant string The directory inside the cache dir where cached content |
|
65 | + * will be stored. |
|
66 | + */ |
|
67 | + const CACHE_DIR = 'dwoo'; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var Dwoo Dwoo template engine |
|
71 | + */ |
|
72 | + protected $dwoo = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var string A string with the default template file extension, |
|
76 | + * including the dot |
|
77 | + */ |
|
78 | + protected $defaultExtension = '.html'; |
|
79 | + |
|
80 | + /** |
|
81 | + * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
82 | + */ |
|
83 | + protected $plugin_dir = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * Pre-serialization callback. |
|
87 | + * |
|
88 | + * Excludes the Dwoo instance to prevent excessive serialization load. |
|
89 | + */ |
|
90 | + public function __sleep() |
|
91 | + { |
|
92 | + $keys = parent::__sleep(); |
|
93 | + unset($keys[array_search('dwoo', $keys)]); |
|
94 | + |
|
95 | + return $keys; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Initialize this Renderer. |
|
100 | + * |
|
101 | + * @param AgaviContext The current application context |
|
102 | + * @param array An associative array of initialization parameters |
|
103 | + */ |
|
104 | + public function initialize(AgaviContext $context, array $parameters = array()) |
|
105 | + { |
|
106 | + parent::initialize($context, $parameters); |
|
107 | + |
|
108 | + $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * provides a custom compiler to the dwoo renderer with optional settings |
|
113 | + * you can set in the agavi output_types.xml config file. |
|
114 | + * |
|
115 | + * @return Dwoo_Compiler |
|
116 | + */ |
|
117 | + public function compilerFactory() |
|
118 | + { |
|
119 | + $compiler = Dwoo_Compiler::compilerFactory(); |
|
120 | + $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
121 | + |
|
122 | + return $compiler; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Grab a cleaned up dwoo instance. |
|
127 | + * |
|
128 | + * @return Dwoo A Dwoo instance |
|
129 | + */ |
|
130 | + protected function getEngine() |
|
131 | + { |
|
132 | + if ($this->dwoo) { |
|
133 | + return $this->dwoo; |
|
134 | + } |
|
135 | + |
|
136 | + // this triggers Agavi autoload |
|
137 | + if (!class_exists('Dwoo')) { |
|
138 | + if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
139 | + // file was dropped with the entire dwoo package |
|
140 | + require dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
141 | + } else { |
|
142 | + // assume the dwoo package is in the include path |
|
143 | + require 'dwooAutoload.php'; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
148 | + |
|
149 | + $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
150 | + AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
151 | + |
|
152 | + $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
153 | + AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
154 | + |
|
155 | + $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
156 | + |
|
157 | + if (!empty($this->plugin_dir)) { |
|
158 | + foreach ((array) $this->plugin_dir as $dir) { |
|
159 | + $this->dwoo->getLoader()->addDirectory($dir); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
164 | + |
|
165 | + return $this->dwoo; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Render the presentation and return the result. |
|
170 | + * |
|
171 | + * @param AgaviTemplateLayer The template layer to render |
|
172 | + * @param array The template variables |
|
173 | + * @param array The slots |
|
174 | + * @param array Associative array of additional assigns |
|
175 | + * |
|
176 | + * @return string A rendered result |
|
177 | + */ |
|
178 | + public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
179 | + { |
|
180 | + $engine = $this->getEngine(); |
|
181 | + |
|
182 | + $data = array(); |
|
183 | + if ($this->extractVars) { |
|
184 | + $data = $attributes; |
|
185 | + } else { |
|
186 | + $data[$this->varName] = &$attributes; |
|
187 | + } |
|
188 | + |
|
189 | + $data[$this->slotsVarName] = &$slots; |
|
190 | + |
|
191 | + foreach ($this->assigns as $key => $getter) { |
|
192 | + $data[$key] = $this->getContext()->$getter(); |
|
193 | + } |
|
194 | + |
|
195 | + foreach ($moreAssigns as $key => &$value) { |
|
196 | + if (isset($this->moreAssignNames[$key])) { |
|
197 | + $key = $this->moreAssignNames[$key]; |
|
198 | + } |
|
199 | + $data[$key] = &$value; |
|
200 | + } |
|
201 | + |
|
202 | + return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
203 | + } |
|
204 | 204 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | if (!defined('BASEPATH')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | // The name of the directory where templates are located. |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!defined('BASEPATH')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | require 'dwoo/dwooAutoload.php'; |
@@ -26,154 +26,154 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class Dwootemplate extends Dwoo_Core |
28 | 28 | { |
29 | - protected $dwoo_data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Constructor for the DwooTemplate engine. |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - // Call parents constructor |
|
37 | - parent::__construct(); |
|
38 | - |
|
39 | - // Set the config settings |
|
40 | - $this->initialize(); |
|
41 | - |
|
42 | - // Assign some defaults to dwoo |
|
43 | - $CI = get_instance(); |
|
44 | - $this->dwoo_data = new Dwoo_Data(); |
|
45 | - $this->dwoo_data->js_files = array(); |
|
46 | - $this->dwoo_data->css_files = array(); |
|
47 | - $this->dwoo_data->CI = $CI; |
|
48 | - $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
49 | - $this->dwoo_data->uniqid = uniqid(); |
|
50 | - $this->dwoo_data->timestamp = mktime(); |
|
51 | - |
|
52 | - log_message('debug', 'Dwoo Template Class Initialized'); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Assign data to dwoo data object. |
|
57 | - * |
|
58 | - * @param string $key |
|
59 | - * @param mixed $value |
|
60 | - */ |
|
61 | - public function assign($key, $value) |
|
62 | - { |
|
63 | - $this->dwoo_data->$key = $value; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Add Javascript files to template. |
|
68 | - * |
|
69 | - * @param string $js |
|
70 | - */ |
|
71 | - public function add_js($js) |
|
72 | - { |
|
73 | - $current = $this->dwoo_data->js_files; |
|
74 | - $current[] = $js; |
|
75 | - $this->dwoo_data->js_files = $current; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Add Css stylesheets to template. |
|
80 | - * |
|
81 | - * @param string $css |
|
82 | - */ |
|
83 | - public function add_css($css) |
|
84 | - { |
|
85 | - $current = $this->dwoo_data->css_files; |
|
86 | - $current[] = $css; |
|
87 | - $this->dwoo_data->css_files = $current; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Display or return the compiled template |
|
92 | - * Since we assign the results to the standard CI output module |
|
93 | - * you can also use the helper from CI in your templates!! |
|
94 | - * |
|
95 | - * @param string $sTemplate |
|
96 | - * @param bool $return |
|
97 | - * |
|
98 | - * @return mixed |
|
99 | - */ |
|
100 | - public function display($sTemplate, $return = false) |
|
101 | - { |
|
102 | - // Start benchmark |
|
103 | - $CI = get_instance(); |
|
104 | - $CI->benchmark->mark('dwoo_parse_start'); |
|
105 | - |
|
106 | - // Check if file exists |
|
107 | - if (!file_exists($this->template_dir.$sTemplate)) { |
|
108 | - $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
109 | - show_error($message); |
|
110 | - log_message('error', $message); |
|
111 | - } |
|
112 | - |
|
113 | - // Create new template |
|
114 | - $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
115 | - |
|
116 | - // render the template |
|
117 | - $template = $this->get($tpl, $this->dwoo_data); |
|
118 | - |
|
119 | - // Finish benchmark |
|
120 | - $CI->benchmark->mark('dwoo_parse_end'); |
|
121 | - |
|
122 | - // Return results or not ? |
|
123 | - if ($return == false) { |
|
124 | - $CI->output->final_output = $template; |
|
125 | - } else { |
|
126 | - return $template; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Toggle Codeigniter profiler on/off. |
|
132 | - */ |
|
133 | - public function enable_profiler($toggle = true) |
|
134 | - { |
|
135 | - $CI = get_instance(); |
|
136 | - $CI->output->enable_profiler($toggle); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Set http header. |
|
141 | - * |
|
142 | - * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
143 | - * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
144 | - * |
|
145 | - * @param string $header |
|
146 | - */ |
|
147 | - public function set_header($header) |
|
148 | - { |
|
149 | - $CI = get_instance(); |
|
150 | - $CI->output->set_header($header); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Set status header. |
|
155 | - * |
|
156 | - * @example $this->output->set_status_header('401'); |
|
157 | - * @example // Sets the header as: Unauthorized |
|
158 | - * |
|
159 | - * @param string $header |
|
160 | - */ |
|
161 | - public function set_status_header($header) |
|
162 | - { |
|
163 | - $CI = get_instance(); |
|
164 | - $CI->output->set_status_header($header); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Assign the dwootemplate config items to the instance. |
|
169 | - */ |
|
170 | - private function initialize() |
|
171 | - { |
|
172 | - $CI = get_instance(); |
|
173 | - $CI->config->load('dwootemplate', true); |
|
174 | - $config = $CI->config->item('dwootemplate'); |
|
175 | - foreach ($config as $key => $val) { |
|
176 | - $this->$key = $val; |
|
177 | - } |
|
178 | - } |
|
29 | + protected $dwoo_data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Constructor for the DwooTemplate engine. |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + // Call parents constructor |
|
37 | + parent::__construct(); |
|
38 | + |
|
39 | + // Set the config settings |
|
40 | + $this->initialize(); |
|
41 | + |
|
42 | + // Assign some defaults to dwoo |
|
43 | + $CI = get_instance(); |
|
44 | + $this->dwoo_data = new Dwoo_Data(); |
|
45 | + $this->dwoo_data->js_files = array(); |
|
46 | + $this->dwoo_data->css_files = array(); |
|
47 | + $this->dwoo_data->CI = $CI; |
|
48 | + $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
49 | + $this->dwoo_data->uniqid = uniqid(); |
|
50 | + $this->dwoo_data->timestamp = mktime(); |
|
51 | + |
|
52 | + log_message('debug', 'Dwoo Template Class Initialized'); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Assign data to dwoo data object. |
|
57 | + * |
|
58 | + * @param string $key |
|
59 | + * @param mixed $value |
|
60 | + */ |
|
61 | + public function assign($key, $value) |
|
62 | + { |
|
63 | + $this->dwoo_data->$key = $value; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Add Javascript files to template. |
|
68 | + * |
|
69 | + * @param string $js |
|
70 | + */ |
|
71 | + public function add_js($js) |
|
72 | + { |
|
73 | + $current = $this->dwoo_data->js_files; |
|
74 | + $current[] = $js; |
|
75 | + $this->dwoo_data->js_files = $current; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Add Css stylesheets to template. |
|
80 | + * |
|
81 | + * @param string $css |
|
82 | + */ |
|
83 | + public function add_css($css) |
|
84 | + { |
|
85 | + $current = $this->dwoo_data->css_files; |
|
86 | + $current[] = $css; |
|
87 | + $this->dwoo_data->css_files = $current; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Display or return the compiled template |
|
92 | + * Since we assign the results to the standard CI output module |
|
93 | + * you can also use the helper from CI in your templates!! |
|
94 | + * |
|
95 | + * @param string $sTemplate |
|
96 | + * @param bool $return |
|
97 | + * |
|
98 | + * @return mixed |
|
99 | + */ |
|
100 | + public function display($sTemplate, $return = false) |
|
101 | + { |
|
102 | + // Start benchmark |
|
103 | + $CI = get_instance(); |
|
104 | + $CI->benchmark->mark('dwoo_parse_start'); |
|
105 | + |
|
106 | + // Check if file exists |
|
107 | + if (!file_exists($this->template_dir.$sTemplate)) { |
|
108 | + $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
109 | + show_error($message); |
|
110 | + log_message('error', $message); |
|
111 | + } |
|
112 | + |
|
113 | + // Create new template |
|
114 | + $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
115 | + |
|
116 | + // render the template |
|
117 | + $template = $this->get($tpl, $this->dwoo_data); |
|
118 | + |
|
119 | + // Finish benchmark |
|
120 | + $CI->benchmark->mark('dwoo_parse_end'); |
|
121 | + |
|
122 | + // Return results or not ? |
|
123 | + if ($return == false) { |
|
124 | + $CI->output->final_output = $template; |
|
125 | + } else { |
|
126 | + return $template; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Toggle Codeigniter profiler on/off. |
|
132 | + */ |
|
133 | + public function enable_profiler($toggle = true) |
|
134 | + { |
|
135 | + $CI = get_instance(); |
|
136 | + $CI->output->enable_profiler($toggle); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Set http header. |
|
141 | + * |
|
142 | + * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
143 | + * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
144 | + * |
|
145 | + * @param string $header |
|
146 | + */ |
|
147 | + public function set_header($header) |
|
148 | + { |
|
149 | + $CI = get_instance(); |
|
150 | + $CI->output->set_header($header); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Set status header. |
|
155 | + * |
|
156 | + * @example $this->output->set_status_header('401'); |
|
157 | + * @example // Sets the header as: Unauthorized |
|
158 | + * |
|
159 | + * @param string $header |
|
160 | + */ |
|
161 | + public function set_status_header($header) |
|
162 | + { |
|
163 | + $CI = get_instance(); |
|
164 | + $CI->output->set_status_header($header); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Assign the dwootemplate config items to the instance. |
|
169 | + */ |
|
170 | + private function initialize() |
|
171 | + { |
|
172 | + $CI = get_instance(); |
|
173 | + $CI->config->load('dwootemplate', true); |
|
174 | + $config = $CI->config->item('dwootemplate'); |
|
175 | + foreach ($config as $key => $val) { |
|
176 | + $this->$key = $val; |
|
177 | + } |
|
178 | + } |
|
179 | 179 | } |
@@ -20,243 +20,243 @@ |
||
20 | 20 | */ |
21 | 21 | class Dwoo_Data implements Dwoo_IDataProvider |
22 | 22 | { |
23 | - /** |
|
24 | - * data array. |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $data = array(); |
|
23 | + /** |
|
24 | + * data array. |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $data = array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * returns the data array. |
|
32 | - * |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function getData() |
|
36 | - { |
|
37 | - return $this->data; |
|
38 | - } |
|
30 | + /** |
|
31 | + * returns the data array. |
|
32 | + * |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function getData() |
|
36 | + { |
|
37 | + return $this->data; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * clears a the entire data or only the given key. |
|
42 | - * |
|
43 | - * @param array|string $name clears only one value if you give a name, multiple values if |
|
44 | - * you give an array of names, or the entire data if left null |
|
45 | - */ |
|
46 | - public function clear($name = null) |
|
47 | - { |
|
48 | - if ($name === null) { |
|
49 | - $this->data = array(); |
|
50 | - } elseif (is_array($name)) { |
|
51 | - foreach ($name as $index) { |
|
52 | - unset($this->data[$index]); |
|
53 | - } |
|
54 | - } else { |
|
55 | - unset($this->data[$name]); |
|
56 | - } |
|
57 | - } |
|
40 | + /** |
|
41 | + * clears a the entire data or only the given key. |
|
42 | + * |
|
43 | + * @param array|string $name clears only one value if you give a name, multiple values if |
|
44 | + * you give an array of names, or the entire data if left null |
|
45 | + */ |
|
46 | + public function clear($name = null) |
|
47 | + { |
|
48 | + if ($name === null) { |
|
49 | + $this->data = array(); |
|
50 | + } elseif (is_array($name)) { |
|
51 | + foreach ($name as $index) { |
|
52 | + unset($this->data[$index]); |
|
53 | + } |
|
54 | + } else { |
|
55 | + unset($this->data[$name]); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * overwrites the entire data with the given array. |
|
61 | - * |
|
62 | - * @param array $data the new data array to use |
|
63 | - */ |
|
64 | - public function setData(array $data) |
|
65 | - { |
|
66 | - $this->data = $data; |
|
67 | - } |
|
59 | + /** |
|
60 | + * overwrites the entire data with the given array. |
|
61 | + * |
|
62 | + * @param array $data the new data array to use |
|
63 | + */ |
|
64 | + public function setData(array $data) |
|
65 | + { |
|
66 | + $this->data = $data; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * merges the given array(s) with the current data with array_merge. |
|
71 | - * |
|
72 | - * @param array $data the array to merge |
|
73 | - * @param array $data2 $data3 ... other arrays to merge, optional, etc |
|
74 | - */ |
|
75 | - public function mergeData(array $data) |
|
76 | - { |
|
77 | - $args = func_get_args(); |
|
78 | - while (list(, $v) = each($args)) { |
|
79 | - if (is_array($v)) { |
|
80 | - $this->data = array_merge($this->data, $v); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
69 | + /** |
|
70 | + * merges the given array(s) with the current data with array_merge. |
|
71 | + * |
|
72 | + * @param array $data the array to merge |
|
73 | + * @param array $data2 $data3 ... other arrays to merge, optional, etc |
|
74 | + */ |
|
75 | + public function mergeData(array $data) |
|
76 | + { |
|
77 | + $args = func_get_args(); |
|
78 | + while (list(, $v) = each($args)) { |
|
79 | + if (is_array($v)) { |
|
80 | + $this->data = array_merge($this->data, $v); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * assigns a value or an array of values to the data object. |
|
87 | - * |
|
88 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
89 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
90 | - * accessible in the template through {$foo} |
|
91 | - * @param mixed $val the value to assign, or null if $name was an array |
|
92 | - */ |
|
93 | - public function assign($name, $val = null) |
|
94 | - { |
|
95 | - if (is_array($name)) { |
|
96 | - reset($name); |
|
97 | - while (list($k, $v) = each($name)) { |
|
98 | - $this->data[$k] = $v; |
|
99 | - } |
|
100 | - } else { |
|
101 | - $this->data[$name] = $val; |
|
102 | - } |
|
103 | - } |
|
85 | + /** |
|
86 | + * assigns a value or an array of values to the data object. |
|
87 | + * |
|
88 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
89 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
90 | + * accessible in the template through {$foo} |
|
91 | + * @param mixed $val the value to assign, or null if $name was an array |
|
92 | + */ |
|
93 | + public function assign($name, $val = null) |
|
94 | + { |
|
95 | + if (is_array($name)) { |
|
96 | + reset($name); |
|
97 | + while (list($k, $v) = each($name)) { |
|
98 | + $this->data[$k] = $v; |
|
99 | + } |
|
100 | + } else { |
|
101 | + $this->data[$name] = $val; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * allows to assign variables using the object syntax. |
|
107 | - * |
|
108 | - * @param string $name the variable name |
|
109 | - * @param string $value the value to assign to it |
|
110 | - */ |
|
111 | - public function __set($name, $value) |
|
112 | - { |
|
113 | - $this->assign($name, $value); |
|
114 | - } |
|
105 | + /** |
|
106 | + * allows to assign variables using the object syntax. |
|
107 | + * |
|
108 | + * @param string $name the variable name |
|
109 | + * @param string $value the value to assign to it |
|
110 | + */ |
|
111 | + public function __set($name, $value) |
|
112 | + { |
|
113 | + $this->assign($name, $value); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * assigns a value by reference to the data object. |
|
118 | - * |
|
119 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
120 | - * accessible in the template through {$foo} |
|
121 | - * @param mixed $val the value to assign by reference |
|
122 | - */ |
|
123 | - public function assignByRef($name, &$val) |
|
124 | - { |
|
125 | - $this->data[$name] = &$val; |
|
126 | - } |
|
116 | + /** |
|
117 | + * assigns a value by reference to the data object. |
|
118 | + * |
|
119 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
120 | + * accessible in the template through {$foo} |
|
121 | + * @param mixed $val the value to assign by reference |
|
122 | + */ |
|
123 | + public function assignByRef($name, &$val) |
|
124 | + { |
|
125 | + $this->data[$name] = &$val; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * appends values or an array of values to the data object. |
|
130 | - * |
|
131 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
132 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
133 | - * accessible in the template through {$foo} |
|
134 | - * @param mixed $val the value to assign, or null if $name was an array |
|
135 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
136 | - */ |
|
137 | - public function append($name, $val = null, $merge = false) |
|
138 | - { |
|
139 | - if (is_array($name)) { |
|
140 | - foreach ($name as $key => $val) { |
|
141 | - if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
142 | - settype($this->data[$key], 'array'); |
|
143 | - } |
|
128 | + /** |
|
129 | + * appends values or an array of values to the data object. |
|
130 | + * |
|
131 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
132 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
133 | + * accessible in the template through {$foo} |
|
134 | + * @param mixed $val the value to assign, or null if $name was an array |
|
135 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
136 | + */ |
|
137 | + public function append($name, $val = null, $merge = false) |
|
138 | + { |
|
139 | + if (is_array($name)) { |
|
140 | + foreach ($name as $key => $val) { |
|
141 | + if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
142 | + settype($this->data[$key], 'array'); |
|
143 | + } |
|
144 | 144 | |
145 | - if ($merge === true && is_array($val)) { |
|
146 | - $this->data[$key] = $val + $this->data[$key]; |
|
147 | - } else { |
|
148 | - $this->data[$key][] = $val; |
|
149 | - } |
|
150 | - } |
|
151 | - } elseif ($val !== null) { |
|
152 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
153 | - settype($this->data[$name], 'array'); |
|
154 | - } elseif (!isset($this->data[$name])) { |
|
155 | - $this->data[$name] = array(); |
|
156 | - } |
|
145 | + if ($merge === true && is_array($val)) { |
|
146 | + $this->data[$key] = $val + $this->data[$key]; |
|
147 | + } else { |
|
148 | + $this->data[$key][] = $val; |
|
149 | + } |
|
150 | + } |
|
151 | + } elseif ($val !== null) { |
|
152 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
153 | + settype($this->data[$name], 'array'); |
|
154 | + } elseif (!isset($this->data[$name])) { |
|
155 | + $this->data[$name] = array(); |
|
156 | + } |
|
157 | 157 | |
158 | - if ($merge === true && is_array($val)) { |
|
159 | - $this->data[$name] = $val + $this->data[$name]; |
|
160 | - } else { |
|
161 | - $this->data[$name][] = $val; |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
158 | + if ($merge === true && is_array($val)) { |
|
159 | + $this->data[$name] = $val + $this->data[$name]; |
|
160 | + } else { |
|
161 | + $this->data[$name][] = $val; |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * appends a value by reference to the data object. |
|
168 | - * |
|
169 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
170 | - * accessible in the template through {$foo} |
|
171 | - * @param mixed $val the value to append by reference |
|
172 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
173 | - */ |
|
174 | - public function appendByRef($name, &$val, $merge = false) |
|
175 | - { |
|
176 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
177 | - settype($this->data[$name], 'array'); |
|
178 | - } |
|
166 | + /** |
|
167 | + * appends a value by reference to the data object. |
|
168 | + * |
|
169 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
170 | + * accessible in the template through {$foo} |
|
171 | + * @param mixed $val the value to append by reference |
|
172 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
173 | + */ |
|
174 | + public function appendByRef($name, &$val, $merge = false) |
|
175 | + { |
|
176 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
177 | + settype($this->data[$name], 'array'); |
|
178 | + } |
|
179 | 179 | |
180 | - if ($merge === true && is_array($val)) { |
|
181 | - foreach ($val as $key => &$value) { |
|
182 | - $this->data[$name][$key] = &$value; |
|
183 | - } |
|
184 | - } else { |
|
185 | - $this->data[$name][] = &$val; |
|
186 | - } |
|
187 | - } |
|
180 | + if ($merge === true && is_array($val)) { |
|
181 | + foreach ($val as $key => &$value) { |
|
182 | + $this->data[$name][$key] = &$value; |
|
183 | + } |
|
184 | + } else { |
|
185 | + $this->data[$name][] = &$val; |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * returns true if the variable has been assigned already, false otherwise. |
|
191 | - * |
|
192 | - * @param string $name the variable name |
|
193 | - * |
|
194 | - * @return bool |
|
195 | - */ |
|
196 | - public function isAssigned($name) |
|
197 | - { |
|
198 | - return isset($this->data[$name]); |
|
199 | - } |
|
189 | + /** |
|
190 | + * returns true if the variable has been assigned already, false otherwise. |
|
191 | + * |
|
192 | + * @param string $name the variable name |
|
193 | + * |
|
194 | + * @return bool |
|
195 | + */ |
|
196 | + public function isAssigned($name) |
|
197 | + { |
|
198 | + return isset($this->data[$name]); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * supports calls to isset($dwooData->var). |
|
203 | - * |
|
204 | - * @param string $name the variable name |
|
205 | - * |
|
206 | - * @return bool |
|
207 | - */ |
|
208 | - public function __isset($name) |
|
209 | - { |
|
210 | - return isset($this->data[$name]); |
|
211 | - } |
|
201 | + /** |
|
202 | + * supports calls to isset($dwooData->var). |
|
203 | + * |
|
204 | + * @param string $name the variable name |
|
205 | + * |
|
206 | + * @return bool |
|
207 | + */ |
|
208 | + public function __isset($name) |
|
209 | + { |
|
210 | + return isset($this->data[$name]); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * unassigns/removes a variable. |
|
215 | - * |
|
216 | - * @param string $name the variable name |
|
217 | - */ |
|
218 | - public function unassign($name) |
|
219 | - { |
|
220 | - unset($this->data[$name]); |
|
221 | - } |
|
213 | + /** |
|
214 | + * unassigns/removes a variable. |
|
215 | + * |
|
216 | + * @param string $name the variable name |
|
217 | + */ |
|
218 | + public function unassign($name) |
|
219 | + { |
|
220 | + unset($this->data[$name]); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * supports unsetting variables using the object syntax. |
|
225 | - * |
|
226 | - * @param string $name the variable name |
|
227 | - */ |
|
228 | - public function __unset($name) |
|
229 | - { |
|
230 | - unset($this->data[$name]); |
|
231 | - } |
|
223 | + /** |
|
224 | + * supports unsetting variables using the object syntax. |
|
225 | + * |
|
226 | + * @param string $name the variable name |
|
227 | + */ |
|
228 | + public function __unset($name) |
|
229 | + { |
|
230 | + unset($this->data[$name]); |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * returns a variable if it was assigned. |
|
235 | - * |
|
236 | - * @param string $name the variable name |
|
237 | - * |
|
238 | - * @return mixed |
|
239 | - */ |
|
240 | - public function get($name) |
|
241 | - { |
|
242 | - return $this->__get($name); |
|
243 | - } |
|
233 | + /** |
|
234 | + * returns a variable if it was assigned. |
|
235 | + * |
|
236 | + * @param string $name the variable name |
|
237 | + * |
|
238 | + * @return mixed |
|
239 | + */ |
|
240 | + public function get($name) |
|
241 | + { |
|
242 | + return $this->__get($name); |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * allows to read variables using the object syntax. |
|
247 | - * |
|
248 | - * @param string $name the variable name |
|
249 | - * |
|
250 | - * @return mixed |
|
251 | - * |
|
252 | - * @throws Dwoo_Exception |
|
253 | - */ |
|
254 | - public function __get($name) |
|
255 | - { |
|
256 | - if (isset($this->data[$name])) { |
|
257 | - return $this->data[$name]; |
|
258 | - } else { |
|
259 | - throw new Dwoo_Exception('Tried to read a value that was not assigned yet : "'.$name.'"'); |
|
260 | - } |
|
261 | - } |
|
245 | + /** |
|
246 | + * allows to read variables using the object syntax. |
|
247 | + * |
|
248 | + * @param string $name the variable name |
|
249 | + * |
|
250 | + * @return mixed |
|
251 | + * |
|
252 | + * @throws Dwoo_Exception |
|
253 | + */ |
|
254 | + public function __get($name) |
|
255 | + { |
|
256 | + if (isset($this->data[$name])) { |
|
257 | + return $this->data[$name]; |
|
258 | + } else { |
|
259 | + throw new Dwoo_Exception('Tried to read a value that was not assigned yet : "'.$name.'"'); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | } |
@@ -18,30 +18,30 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class Dwoo_Processor |
20 | 20 | { |
21 | - /** |
|
22 | - * The compiler instance that runs this processor. |
|
23 | - * |
|
24 | - * @var Dwoo |
|
25 | - */ |
|
26 | - protected $compiler; |
|
21 | + /** |
|
22 | + * The compiler instance that runs this processor. |
|
23 | + * |
|
24 | + * @var Dwoo |
|
25 | + */ |
|
26 | + protected $compiler; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
30 | - * the dwoo instance yourself if you need it. |
|
31 | - * |
|
32 | - * @param Dwoo_Compiler $compiler the compiler class |
|
33 | - */ |
|
34 | - public function __construct(Dwoo_Compiler $compiler) |
|
35 | - { |
|
36 | - $this->compiler = $compiler; |
|
37 | - } |
|
28 | + /** |
|
29 | + * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
30 | + * the dwoo instance yourself if you need it. |
|
31 | + * |
|
32 | + * @param Dwoo_Compiler $compiler the compiler class |
|
33 | + */ |
|
34 | + public function __construct(Dwoo_Compiler $compiler) |
|
35 | + { |
|
36 | + $this->compiler = $compiler; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Processes the input and returns it filtered. |
|
41 | - * |
|
42 | - * @param string $input the template to process |
|
43 | - * |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - abstract public function process($input); |
|
39 | + /** |
|
40 | + * Processes the input and returns it filtered. |
|
41 | + * |
|
42 | + * @param string $input the template to process |
|
43 | + * |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + abstract public function process($input); |
|
47 | 47 | } |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!defined('DIR_SEP')) { |
4 | - define('DIR_SEP', DIRECTORY_SEPARATOR); |
|
4 | + define('DIR_SEP', DIRECTORY_SEPARATOR); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if (!defined('SMARTY_PHP_PASSTHRU')) { |
8 | - define('SMARTY_PHP_PASSTHRU', 0); |
|
9 | - define('SMARTY_PHP_QUOTE', 1); |
|
10 | - define('SMARTY_PHP_REMOVE', 2); |
|
11 | - define('SMARTY_PHP_ALLOW', 3); |
|
8 | + define('SMARTY_PHP_PASSTHRU', 0); |
|
9 | + define('SMARTY_PHP_QUOTE', 1); |
|
10 | + define('SMARTY_PHP_REMOVE', 2); |
|
11 | + define('SMARTY_PHP_ALLOW', 3); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -30,499 +30,499 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class Dwoo_Smarty__Adapter extends Dwoo_Core |
32 | 32 | { |
33 | - // magic get/set/call functions that handle unsupported features |
|
34 | - public function __set($p, $v) |
|
35 | - { |
|
36 | - if ($p === 'scope') { |
|
37 | - $this->scope = $v; |
|
38 | - |
|
39 | - return; |
|
40 | - } |
|
41 | - if ($p === 'data') { |
|
42 | - $this->data = $v; |
|
43 | - |
|
44 | - return; |
|
45 | - } |
|
46 | - if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
47 | - if ($this->show_compat_errors) { |
|
48 | - $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
49 | - } |
|
50 | - $this->compat['properties'][$p] = $v; |
|
51 | - } else { |
|
52 | - if ($this->show_compat_errors) { |
|
53 | - $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
54 | - } |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - public function __get($p) |
|
59 | - { |
|
60 | - if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
61 | - if ($this->show_compat_errors) { |
|
62 | - $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
63 | - } |
|
64 | - |
|
65 | - return $this->compat['properties'][$p]; |
|
66 | - } else { |
|
67 | - if ($this->show_compat_errors) { |
|
68 | - $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - public function __call($m, $a) |
|
74 | - { |
|
75 | - if (method_exists($this->dataProvider, $m)) { |
|
76 | - call_user_func_array(array($this->dataProvider, $m), $a); |
|
77 | - } elseif ($this->show_compat_errors) { |
|
78 | - if (array_search($m, $this->compat['methods']) !== false) { |
|
79 | - $this->triggerError('Method '.$m.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
80 | - } else { |
|
81 | - $this->triggerError('Method '.$m.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - // list of unsupported properties and methods |
|
87 | - protected $compat = array( |
|
88 | - 'methods' => array( |
|
89 | - 'register_resource', 'unregister_resource', 'load_filter', 'clear_compiled_tpl', |
|
90 | - 'clear_config', 'get_config_vars', 'config_load', |
|
91 | - ), |
|
92 | - 'properties' => array( |
|
93 | - 'cache_handler_func' => null, |
|
94 | - 'debugging' => false, |
|
95 | - 'error_reporting' => null, |
|
96 | - 'debugging_ctrl' => 'NONE', |
|
97 | - 'request_vars_order' => 'EGPCS', |
|
98 | - 'request_use_auto_globals' => true, |
|
99 | - 'use_sub_dirs' => false, |
|
100 | - 'autoload_filters' => array(), |
|
101 | - 'default_template_handler_func' => '', |
|
102 | - 'debug_tpl' => '', |
|
103 | - 'cache_modified_check' => false, |
|
104 | - 'default_modifiers' => array(), |
|
105 | - 'default_resource_type' => 'file', |
|
106 | - 'config_overwrite' => true, |
|
107 | - 'config_booleanize' => true, |
|
108 | - 'config_read_hidden' => false, |
|
109 | - 'config_fix_newlines' => true, |
|
110 | - 'config_class' => 'Config_File', |
|
111 | - ), |
|
112 | - ); |
|
113 | - |
|
114 | - // security vars |
|
115 | - public $security = false; |
|
116 | - public $trusted_dir = array(); |
|
117 | - public $secure_dir = array(); |
|
118 | - public $php_handling = SMARTY_PHP_PASSTHRU; |
|
119 | - public $security_settings = array( |
|
120 | - 'PHP_HANDLING' => false, |
|
121 | - 'IF_FUNCS' => array( |
|
122 | - 'list', 'empty', 'count', 'sizeof', |
|
123 | - 'in_array', 'is_array', |
|
124 | - ), |
|
125 | - 'INCLUDE_ANY' => false, |
|
126 | - 'PHP_TAGS' => false, |
|
127 | - 'MODIFIER_FUNCS' => array(), |
|
128 | - 'ALLOW_CONSTANTS' => false, |
|
129 | - ); |
|
130 | - |
|
131 | - // paths |
|
132 | - public $template_dir = 'templates'; |
|
133 | - public $compile_dir = 'templates_c'; |
|
134 | - public $config_dir = 'configs'; |
|
135 | - public $cache_dir = 'cache'; |
|
136 | - public $plugins_dir = array(); |
|
137 | - |
|
138 | - // misc options |
|
139 | - public $left_delimiter = '{'; |
|
140 | - public $right_delimiter = '}'; |
|
141 | - public $compile_check = true; |
|
142 | - public $force_compile = false; |
|
143 | - public $caching = 0; |
|
144 | - public $cache_lifetime = 3600; |
|
145 | - public $compile_id = null; |
|
146 | - public $compiler_file = null; |
|
147 | - public $compiler_class = null; |
|
148 | - |
|
149 | - // dwoo/smarty compat layer |
|
150 | - public $show_compat_errors = false; |
|
151 | - protected $dataProvider; |
|
152 | - protected $_filters = array('pre' => array(), 'post' => array(), 'output' => array()); |
|
153 | - protected static $tplCache = array(); |
|
154 | - protected $compiler = null; |
|
155 | - |
|
156 | - public function __construct() |
|
157 | - { |
|
158 | - parent::__construct(); |
|
159 | - $this->charset = 'iso-8859-1'; |
|
160 | - $this->dataProvider = new Dwoo_Data(); |
|
161 | - $this->compiler = new Dwoo_Compiler(); |
|
162 | - } |
|
163 | - |
|
164 | - public function display($filename, $cacheId = null, $compileId = null) |
|
165 | - { |
|
166 | - $this->fetch($filename, $cacheId, $compileId, true); |
|
167 | - } |
|
168 | - |
|
169 | - public function fetch($filename, $cacheId = null, $compileId = null, $display = false) |
|
170 | - { |
|
171 | - $this->setCacheDir($this->cache_dir); |
|
172 | - $this->setCompileDir($this->compile_dir); |
|
173 | - |
|
174 | - if ($this->security) { |
|
175 | - $policy = new Dwoo_Security_Policy(); |
|
176 | - $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS'])); |
|
177 | - |
|
178 | - $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling; |
|
179 | - if ($this->security_settings['PHP_TAGS']) { |
|
180 | - $phpTags = SMARTY_PHP_ALLOW; |
|
181 | - } |
|
182 | - switch ($phpTags) { |
|
183 | - case SMARTY_PHP_ALLOW: |
|
184 | - case SMARTY_PHP_PASSTHRU: |
|
185 | - $phpTags = Dwoo_Security_Policy::PHP_ALLOW; |
|
186 | - break; |
|
187 | - case SMARTY_PHP_QUOTE: |
|
188 | - $phpTags = Dwoo_Security_Policy::PHP_ENCODE; |
|
189 | - break; |
|
190 | - case SMARTY_PHP_REMOVE: |
|
191 | - default: |
|
192 | - $phpTags = Dwoo_Security_Policy::PHP_REMOVE; |
|
193 | - break; |
|
194 | - } |
|
195 | - $policy->setPhpHandling($phpTags); |
|
196 | - |
|
197 | - $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']); |
|
198 | - |
|
199 | - if ($this->security_settings['INCLUDE_ANY']) { |
|
200 | - $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__)); |
|
201 | - } else { |
|
202 | - $policy->allowDirectory($this->secure_dir); |
|
203 | - } |
|
204 | - |
|
205 | - $this->setSecurityPolicy($policy); |
|
206 | - } |
|
207 | - |
|
208 | - if (!empty($this->plugins_dir)) { |
|
209 | - foreach ($this->plugins_dir as $dir) { |
|
210 | - $this->getLoader()->addDirectory(rtrim($dir, '\\/')); |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - $tpl = $this->makeTemplate($filename, $cacheId, $compileId); |
|
215 | - if ($this->force_compile) { |
|
216 | - $tpl->forceCompilation(); |
|
217 | - } |
|
218 | - |
|
219 | - if ($this->caching > 0) { |
|
220 | - $this->cacheTime = $this->cache_lifetime; |
|
221 | - } else { |
|
222 | - $this->cacheTime = 0; |
|
223 | - } |
|
224 | - |
|
225 | - if ($this->compiler_class !== null) { |
|
226 | - if ($this->compiler_file !== null && !class_exists($this->compiler_class)) { |
|
227 | - include $this->compiler_file; |
|
228 | - } |
|
229 | - $this->compiler = new $this->compiler_class(); |
|
230 | - } else { |
|
231 | - $this->compiler->addPreProcessor('smarty_compat', true); |
|
232 | - $this->compiler->setLooseOpeningHandling(true); |
|
233 | - } |
|
234 | - |
|
235 | - $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter); |
|
236 | - |
|
237 | - return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true); |
|
238 | - } |
|
239 | - |
|
240 | - public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
241 | - { |
|
242 | - if ($_compiler === null) { |
|
243 | - $_compiler = $this->compiler; |
|
244 | - } |
|
245 | - |
|
246 | - return parent::get($_tpl, $data, $_compiler, $_output); |
|
247 | - } |
|
248 | - |
|
249 | - public function register_function($name, $callback, $cacheable = true, $cache_attrs = null) |
|
250 | - { |
|
251 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) { |
|
252 | - throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
253 | - } |
|
254 | - $this->plugins[$name] = array('type' => self::SMARTY_FUNCTION, 'callback' => $callback); |
|
255 | - } |
|
256 | - |
|
257 | - public function unregister_function($name) |
|
258 | - { |
|
259 | - unset($this->plugins[$name]); |
|
260 | - } |
|
261 | - |
|
262 | - public function register_block($name, $callback, $cacheable = true, $cache_attrs = null) |
|
263 | - { |
|
264 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) { |
|
265 | - throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
266 | - } |
|
267 | - $this->plugins[$name] = array('type' => self::SMARTY_BLOCK, 'callback' => $callback); |
|
268 | - } |
|
269 | - |
|
270 | - public function unregister_block($name) |
|
271 | - { |
|
272 | - unset($this->plugins[$name]); |
|
273 | - } |
|
274 | - |
|
275 | - public function register_modifier($name, $callback) |
|
276 | - { |
|
277 | - if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) { |
|
278 | - throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
279 | - } |
|
280 | - $this->plugins[$name] = array('type' => self::SMARTY_MODIFIER, 'callback' => $callback); |
|
281 | - } |
|
282 | - |
|
283 | - public function unregister_modifier($name) |
|
284 | - { |
|
285 | - unset($this->plugins[$name]); |
|
286 | - } |
|
287 | - |
|
288 | - public function register_prefilter($callback) |
|
289 | - { |
|
290 | - $processor = new Dwoo_SmartyProcessorAdapter($this->compiler); |
|
291 | - $processor->registerCallback($callback); |
|
292 | - $this->_filters['pre'][] = $processor; |
|
293 | - $this->compiler->addPreProcessor($processor); |
|
294 | - } |
|
295 | - |
|
296 | - public function unregister_prefilter($callback) |
|
297 | - { |
|
298 | - foreach ($this->_filters['pre'] as $index => $processor) { |
|
299 | - if ($processor->callback === $callback) { |
|
300 | - $this->compiler->removePostProcessor($processor); |
|
301 | - unset($this->_filters['pre'][$index]); |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - public function register_postfilter($callback) |
|
307 | - { |
|
308 | - $processor = new Dwoo_SmartyProcessorAdapter($this->compiler); |
|
309 | - $processor->registerCallback($callback); |
|
310 | - $this->_filters['post'][] = $processor; |
|
311 | - $this->compiler->addPostProcessor($processor); |
|
312 | - } |
|
313 | - |
|
314 | - public function unregister_postfilter($callback) |
|
315 | - { |
|
316 | - foreach ($this->_filters['post'] as $index => $processor) { |
|
317 | - if ($processor->callback === $callback) { |
|
318 | - $this->compiler->removePostProcessor($processor); |
|
319 | - unset($this->_filters['post'][$index]); |
|
320 | - } |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - public function register_outputfilter($callback) |
|
325 | - { |
|
326 | - $filter = new Dwoo_SmartyFilterAdapter($this); |
|
327 | - $filter->registerCallback($callback); |
|
328 | - $this->_filters['output'][] = $filter; |
|
329 | - $this->addFilter($filter); |
|
330 | - } |
|
331 | - |
|
332 | - public function unregister_outputfilter($callback) |
|
333 | - { |
|
334 | - foreach ($this->_filters['output'] as $index => $filter) { |
|
335 | - if ($filter->callback === $callback) { |
|
336 | - $this->removeOutputFilter($filter); |
|
337 | - unset($this->_filters['output'][$index]); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array()) |
|
343 | - { |
|
344 | - settype($allowed, 'array'); |
|
345 | - settype($block_methods, 'array'); |
|
346 | - settype($smarty_args, 'boolean'); |
|
347 | - |
|
348 | - if (!empty($allowed) && $this->show_compat_errors) { |
|
349 | - $this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE); |
|
350 | - } |
|
351 | - |
|
352 | - if ($smarty_args) { |
|
353 | - $this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE); |
|
354 | - } |
|
355 | - |
|
356 | - if (!empty($block_methods)) { |
|
357 | - $this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE); |
|
358 | - } |
|
359 | - |
|
360 | - $this->dataProvider->assign($object, $object_impl); |
|
361 | - } |
|
362 | - |
|
363 | - public function unregister_object($object) |
|
364 | - { |
|
365 | - $this->dataProvider->clear($object); |
|
366 | - } |
|
367 | - |
|
368 | - public function get_registered_object($name) |
|
369 | - { |
|
370 | - $data = $this->dataProvider->getData(); |
|
371 | - if (isset($data[$name]) && is_object($data[$name])) { |
|
372 | - return $data[$name]; |
|
373 | - } else { |
|
374 | - trigger_error('Dwoo_Compiler: object "'.$name.'" was not registered or is not an object', E_USER_ERROR); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - public function template_exists($filename) |
|
379 | - { |
|
380 | - if (!is_array($this->template_dir)) { |
|
381 | - return file_exists($this->template_dir.DIRECTORY_SEPARATOR.$filename); |
|
382 | - } else { |
|
383 | - foreach ($this->template_dir as $tpl_dir) { |
|
384 | - if (file_exists($tpl_dir.DIRECTORY_SEPARATOR.$filename)) { |
|
385 | - return true; |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - return false; |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - public function is_cached($tpl, $cacheId = null, $compileId = null) |
|
394 | - { |
|
395 | - return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId)); |
|
396 | - } |
|
397 | - |
|
398 | - public function append_by_ref($var, &$value, $merge = false) |
|
399 | - { |
|
400 | - $this->dataProvider->appendByRef($var, $value, $merge); |
|
401 | - } |
|
402 | - |
|
403 | - public function assign_by_ref($name, &$val) |
|
404 | - { |
|
405 | - $this->dataProvider->assignByRef($name, $val); |
|
406 | - } |
|
407 | - |
|
408 | - public function clear_assign($var) |
|
409 | - { |
|
410 | - $this->dataProvider->clear($var); |
|
411 | - } |
|
412 | - |
|
413 | - public function clear_all_assign() |
|
414 | - { |
|
415 | - $this->dataProvider->clear(); |
|
416 | - } |
|
417 | - |
|
418 | - public function get_template_vars($name = null) |
|
419 | - { |
|
420 | - if ($this->show_compat_errors) { |
|
421 | - trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE); |
|
422 | - } |
|
423 | - |
|
424 | - $data = $this->dataProvider->getData(); |
|
425 | - if ($name === null) { |
|
426 | - return $data; |
|
427 | - } elseif (isset($data[$name])) { |
|
428 | - return $data[$name]; |
|
429 | - } |
|
430 | - |
|
431 | - return null; |
|
432 | - } |
|
433 | - |
|
434 | - public function clear_all_cache($olderThan = 0) |
|
435 | - { |
|
436 | - $this->clearCache($olderThan); |
|
437 | - } |
|
438 | - |
|
439 | - public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0) |
|
440 | - { |
|
441 | - $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan); |
|
442 | - } |
|
443 | - |
|
444 | - public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
445 | - { |
|
446 | - $this->triggerError($error_msg, $error_type); |
|
447 | - } |
|
448 | - |
|
449 | - protected function initGlobals() |
|
450 | - { |
|
451 | - parent::initGlobals(); |
|
452 | - $this->globals['ldelim'] = '{'; |
|
453 | - $this->globals['rdelim'] = '}'; |
|
454 | - } |
|
455 | - |
|
456 | - protected function makeTemplate($file, $cacheId, $compileId) |
|
457 | - { |
|
458 | - if ($compileId === null) { |
|
459 | - $compileId = $this->compile_id; |
|
460 | - } |
|
461 | - |
|
462 | - $hash = bin2hex(md5($file.$cacheId.$compileId, true)); |
|
463 | - if (!isset(self::$tplCache[$hash])) { |
|
464 | - // abs path |
|
465 | - if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') { |
|
466 | - self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId); |
|
467 | - } elseif (is_string($this->template_dir) || is_array($this->template_dir)) { |
|
468 | - self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId, $this->template_dir); |
|
469 | - } else { |
|
470 | - throw new Exception('Unable to load "'.$file.'", check the template_dir'); |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - return self::$tplCache[$hash]; |
|
475 | - } |
|
476 | - |
|
477 | - public function triggerError($message, $level = E_USER_NOTICE) |
|
478 | - { |
|
479 | - if (is_object($this->template)) { |
|
480 | - return parent::triggerError($message, $level); |
|
481 | - } |
|
482 | - trigger_error('Dwoo error : '.$message, $level); |
|
483 | - } |
|
33 | + // magic get/set/call functions that handle unsupported features |
|
34 | + public function __set($p, $v) |
|
35 | + { |
|
36 | + if ($p === 'scope') { |
|
37 | + $this->scope = $v; |
|
38 | + |
|
39 | + return; |
|
40 | + } |
|
41 | + if ($p === 'data') { |
|
42 | + $this->data = $v; |
|
43 | + |
|
44 | + return; |
|
45 | + } |
|
46 | + if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
47 | + if ($this->show_compat_errors) { |
|
48 | + $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
49 | + } |
|
50 | + $this->compat['properties'][$p] = $v; |
|
51 | + } else { |
|
52 | + if ($this->show_compat_errors) { |
|
53 | + $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
54 | + } |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + public function __get($p) |
|
59 | + { |
|
60 | + if (array_key_exists($p, $this->compat['properties']) !== false) { |
|
61 | + if ($this->show_compat_errors) { |
|
62 | + $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
63 | + } |
|
64 | + |
|
65 | + return $this->compat['properties'][$p]; |
|
66 | + } else { |
|
67 | + if ($this->show_compat_errors) { |
|
68 | + $this->triggerError('Property '.$p.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + public function __call($m, $a) |
|
74 | + { |
|
75 | + if (method_exists($this->dataProvider, $m)) { |
|
76 | + call_user_func_array(array($this->dataProvider, $m), $a); |
|
77 | + } elseif ($this->show_compat_errors) { |
|
78 | + if (array_search($m, $this->compat['methods']) !== false) { |
|
79 | + $this->triggerError('Method '.$m.' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE); |
|
80 | + } else { |
|
81 | + $this->triggerError('Method '.$m.' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at [email protected]', E_USER_NOTICE); |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + // list of unsupported properties and methods |
|
87 | + protected $compat = array( |
|
88 | + 'methods' => array( |
|
89 | + 'register_resource', 'unregister_resource', 'load_filter', 'clear_compiled_tpl', |
|
90 | + 'clear_config', 'get_config_vars', 'config_load', |
|
91 | + ), |
|
92 | + 'properties' => array( |
|
93 | + 'cache_handler_func' => null, |
|
94 | + 'debugging' => false, |
|
95 | + 'error_reporting' => null, |
|
96 | + 'debugging_ctrl' => 'NONE', |
|
97 | + 'request_vars_order' => 'EGPCS', |
|
98 | + 'request_use_auto_globals' => true, |
|
99 | + 'use_sub_dirs' => false, |
|
100 | + 'autoload_filters' => array(), |
|
101 | + 'default_template_handler_func' => '', |
|
102 | + 'debug_tpl' => '', |
|
103 | + 'cache_modified_check' => false, |
|
104 | + 'default_modifiers' => array(), |
|
105 | + 'default_resource_type' => 'file', |
|
106 | + 'config_overwrite' => true, |
|
107 | + 'config_booleanize' => true, |
|
108 | + 'config_read_hidden' => false, |
|
109 | + 'config_fix_newlines' => true, |
|
110 | + 'config_class' => 'Config_File', |
|
111 | + ), |
|
112 | + ); |
|
113 | + |
|
114 | + // security vars |
|
115 | + public $security = false; |
|
116 | + public $trusted_dir = array(); |
|
117 | + public $secure_dir = array(); |
|
118 | + public $php_handling = SMARTY_PHP_PASSTHRU; |
|
119 | + public $security_settings = array( |
|
120 | + 'PHP_HANDLING' => false, |
|
121 | + 'IF_FUNCS' => array( |
|
122 | + 'list', 'empty', 'count', 'sizeof', |
|
123 | + 'in_array', 'is_array', |
|
124 | + ), |
|
125 | + 'INCLUDE_ANY' => false, |
|
126 | + 'PHP_TAGS' => false, |
|
127 | + 'MODIFIER_FUNCS' => array(), |
|
128 | + 'ALLOW_CONSTANTS' => false, |
|
129 | + ); |
|
130 | + |
|
131 | + // paths |
|
132 | + public $template_dir = 'templates'; |
|
133 | + public $compile_dir = 'templates_c'; |
|
134 | + public $config_dir = 'configs'; |
|
135 | + public $cache_dir = 'cache'; |
|
136 | + public $plugins_dir = array(); |
|
137 | + |
|
138 | + // misc options |
|
139 | + public $left_delimiter = '{'; |
|
140 | + public $right_delimiter = '}'; |
|
141 | + public $compile_check = true; |
|
142 | + public $force_compile = false; |
|
143 | + public $caching = 0; |
|
144 | + public $cache_lifetime = 3600; |
|
145 | + public $compile_id = null; |
|
146 | + public $compiler_file = null; |
|
147 | + public $compiler_class = null; |
|
148 | + |
|
149 | + // dwoo/smarty compat layer |
|
150 | + public $show_compat_errors = false; |
|
151 | + protected $dataProvider; |
|
152 | + protected $_filters = array('pre' => array(), 'post' => array(), 'output' => array()); |
|
153 | + protected static $tplCache = array(); |
|
154 | + protected $compiler = null; |
|
155 | + |
|
156 | + public function __construct() |
|
157 | + { |
|
158 | + parent::__construct(); |
|
159 | + $this->charset = 'iso-8859-1'; |
|
160 | + $this->dataProvider = new Dwoo_Data(); |
|
161 | + $this->compiler = new Dwoo_Compiler(); |
|
162 | + } |
|
163 | + |
|
164 | + public function display($filename, $cacheId = null, $compileId = null) |
|
165 | + { |
|
166 | + $this->fetch($filename, $cacheId, $compileId, true); |
|
167 | + } |
|
168 | + |
|
169 | + public function fetch($filename, $cacheId = null, $compileId = null, $display = false) |
|
170 | + { |
|
171 | + $this->setCacheDir($this->cache_dir); |
|
172 | + $this->setCompileDir($this->compile_dir); |
|
173 | + |
|
174 | + if ($this->security) { |
|
175 | + $policy = new Dwoo_Security_Policy(); |
|
176 | + $policy->addPhpFunction(array_merge($this->security_settings['IF_FUNCS'], $this->security_settings['MODIFIER_FUNCS'])); |
|
177 | + |
|
178 | + $phpTags = $this->security_settings['PHP_HANDLING'] ? SMARTY_PHP_ALLOW : $this->php_handling; |
|
179 | + if ($this->security_settings['PHP_TAGS']) { |
|
180 | + $phpTags = SMARTY_PHP_ALLOW; |
|
181 | + } |
|
182 | + switch ($phpTags) { |
|
183 | + case SMARTY_PHP_ALLOW: |
|
184 | + case SMARTY_PHP_PASSTHRU: |
|
185 | + $phpTags = Dwoo_Security_Policy::PHP_ALLOW; |
|
186 | + break; |
|
187 | + case SMARTY_PHP_QUOTE: |
|
188 | + $phpTags = Dwoo_Security_Policy::PHP_ENCODE; |
|
189 | + break; |
|
190 | + case SMARTY_PHP_REMOVE: |
|
191 | + default: |
|
192 | + $phpTags = Dwoo_Security_Policy::PHP_REMOVE; |
|
193 | + break; |
|
194 | + } |
|
195 | + $policy->setPhpHandling($phpTags); |
|
196 | + |
|
197 | + $policy->setConstantHandling($this->security_settings['ALLOW_CONSTANTS']); |
|
198 | + |
|
199 | + if ($this->security_settings['INCLUDE_ANY']) { |
|
200 | + $policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__)); |
|
201 | + } else { |
|
202 | + $policy->allowDirectory($this->secure_dir); |
|
203 | + } |
|
204 | + |
|
205 | + $this->setSecurityPolicy($policy); |
|
206 | + } |
|
207 | + |
|
208 | + if (!empty($this->plugins_dir)) { |
|
209 | + foreach ($this->plugins_dir as $dir) { |
|
210 | + $this->getLoader()->addDirectory(rtrim($dir, '\\/')); |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + $tpl = $this->makeTemplate($filename, $cacheId, $compileId); |
|
215 | + if ($this->force_compile) { |
|
216 | + $tpl->forceCompilation(); |
|
217 | + } |
|
218 | + |
|
219 | + if ($this->caching > 0) { |
|
220 | + $this->cacheTime = $this->cache_lifetime; |
|
221 | + } else { |
|
222 | + $this->cacheTime = 0; |
|
223 | + } |
|
224 | + |
|
225 | + if ($this->compiler_class !== null) { |
|
226 | + if ($this->compiler_file !== null && !class_exists($this->compiler_class)) { |
|
227 | + include $this->compiler_file; |
|
228 | + } |
|
229 | + $this->compiler = new $this->compiler_class(); |
|
230 | + } else { |
|
231 | + $this->compiler->addPreProcessor('smarty_compat', true); |
|
232 | + $this->compiler->setLooseOpeningHandling(true); |
|
233 | + } |
|
234 | + |
|
235 | + $this->compiler->setDelimiters($this->left_delimiter, $this->right_delimiter); |
|
236 | + |
|
237 | + return $this->get($tpl, $this->dataProvider, $this->compiler, $display === true); |
|
238 | + } |
|
239 | + |
|
240 | + public function get($_tpl, $data = array(), $_compiler = null, $_output = false) |
|
241 | + { |
|
242 | + if ($_compiler === null) { |
|
243 | + $_compiler = $this->compiler; |
|
244 | + } |
|
245 | + |
|
246 | + return parent::get($_tpl, $data, $_compiler, $_output); |
|
247 | + } |
|
248 | + |
|
249 | + public function register_function($name, $callback, $cacheable = true, $cache_attrs = null) |
|
250 | + { |
|
251 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_FUNCTION) { |
|
252 | + throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
253 | + } |
|
254 | + $this->plugins[$name] = array('type' => self::SMARTY_FUNCTION, 'callback' => $callback); |
|
255 | + } |
|
256 | + |
|
257 | + public function unregister_function($name) |
|
258 | + { |
|
259 | + unset($this->plugins[$name]); |
|
260 | + } |
|
261 | + |
|
262 | + public function register_block($name, $callback, $cacheable = true, $cache_attrs = null) |
|
263 | + { |
|
264 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_BLOCK) { |
|
265 | + throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
266 | + } |
|
267 | + $this->plugins[$name] = array('type' => self::SMARTY_BLOCK, 'callback' => $callback); |
|
268 | + } |
|
269 | + |
|
270 | + public function unregister_block($name) |
|
271 | + { |
|
272 | + unset($this->plugins[$name]); |
|
273 | + } |
|
274 | + |
|
275 | + public function register_modifier($name, $callback) |
|
276 | + { |
|
277 | + if (isset($this->plugins[$name]) && $this->plugins[$name][0] !== self::SMARTY_MODIFIER) { |
|
278 | + throw new Dwoo_Exception('Multiple plugins of different types can not share the same name'); |
|
279 | + } |
|
280 | + $this->plugins[$name] = array('type' => self::SMARTY_MODIFIER, 'callback' => $callback); |
|
281 | + } |
|
282 | + |
|
283 | + public function unregister_modifier($name) |
|
284 | + { |
|
285 | + unset($this->plugins[$name]); |
|
286 | + } |
|
287 | + |
|
288 | + public function register_prefilter($callback) |
|
289 | + { |
|
290 | + $processor = new Dwoo_SmartyProcessorAdapter($this->compiler); |
|
291 | + $processor->registerCallback($callback); |
|
292 | + $this->_filters['pre'][] = $processor; |
|
293 | + $this->compiler->addPreProcessor($processor); |
|
294 | + } |
|
295 | + |
|
296 | + public function unregister_prefilter($callback) |
|
297 | + { |
|
298 | + foreach ($this->_filters['pre'] as $index => $processor) { |
|
299 | + if ($processor->callback === $callback) { |
|
300 | + $this->compiler->removePostProcessor($processor); |
|
301 | + unset($this->_filters['pre'][$index]); |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + public function register_postfilter($callback) |
|
307 | + { |
|
308 | + $processor = new Dwoo_SmartyProcessorAdapter($this->compiler); |
|
309 | + $processor->registerCallback($callback); |
|
310 | + $this->_filters['post'][] = $processor; |
|
311 | + $this->compiler->addPostProcessor($processor); |
|
312 | + } |
|
313 | + |
|
314 | + public function unregister_postfilter($callback) |
|
315 | + { |
|
316 | + foreach ($this->_filters['post'] as $index => $processor) { |
|
317 | + if ($processor->callback === $callback) { |
|
318 | + $this->compiler->removePostProcessor($processor); |
|
319 | + unset($this->_filters['post'][$index]); |
|
320 | + } |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + public function register_outputfilter($callback) |
|
325 | + { |
|
326 | + $filter = new Dwoo_SmartyFilterAdapter($this); |
|
327 | + $filter->registerCallback($callback); |
|
328 | + $this->_filters['output'][] = $filter; |
|
329 | + $this->addFilter($filter); |
|
330 | + } |
|
331 | + |
|
332 | + public function unregister_outputfilter($callback) |
|
333 | + { |
|
334 | + foreach ($this->_filters['output'] as $index => $filter) { |
|
335 | + if ($filter->callback === $callback) { |
|
336 | + $this->removeOutputFilter($filter); |
|
337 | + unset($this->_filters['output'][$index]); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = false, $block_methods = array()) |
|
343 | + { |
|
344 | + settype($allowed, 'array'); |
|
345 | + settype($block_methods, 'array'); |
|
346 | + settype($smarty_args, 'boolean'); |
|
347 | + |
|
348 | + if (!empty($allowed) && $this->show_compat_errors) { |
|
349 | + $this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE); |
|
350 | + } |
|
351 | + |
|
352 | + if ($smarty_args) { |
|
353 | + $this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE); |
|
354 | + } |
|
355 | + |
|
356 | + if (!empty($block_methods)) { |
|
357 | + $this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE); |
|
358 | + } |
|
359 | + |
|
360 | + $this->dataProvider->assign($object, $object_impl); |
|
361 | + } |
|
362 | + |
|
363 | + public function unregister_object($object) |
|
364 | + { |
|
365 | + $this->dataProvider->clear($object); |
|
366 | + } |
|
367 | + |
|
368 | + public function get_registered_object($name) |
|
369 | + { |
|
370 | + $data = $this->dataProvider->getData(); |
|
371 | + if (isset($data[$name]) && is_object($data[$name])) { |
|
372 | + return $data[$name]; |
|
373 | + } else { |
|
374 | + trigger_error('Dwoo_Compiler: object "'.$name.'" was not registered or is not an object', E_USER_ERROR); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + public function template_exists($filename) |
|
379 | + { |
|
380 | + if (!is_array($this->template_dir)) { |
|
381 | + return file_exists($this->template_dir.DIRECTORY_SEPARATOR.$filename); |
|
382 | + } else { |
|
383 | + foreach ($this->template_dir as $tpl_dir) { |
|
384 | + if (file_exists($tpl_dir.DIRECTORY_SEPARATOR.$filename)) { |
|
385 | + return true; |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + return false; |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + public function is_cached($tpl, $cacheId = null, $compileId = null) |
|
394 | + { |
|
395 | + return $this->isCached($this->makeTemplate($tpl, $cacheId, $compileId)); |
|
396 | + } |
|
397 | + |
|
398 | + public function append_by_ref($var, &$value, $merge = false) |
|
399 | + { |
|
400 | + $this->dataProvider->appendByRef($var, $value, $merge); |
|
401 | + } |
|
402 | + |
|
403 | + public function assign_by_ref($name, &$val) |
|
404 | + { |
|
405 | + $this->dataProvider->assignByRef($name, $val); |
|
406 | + } |
|
407 | + |
|
408 | + public function clear_assign($var) |
|
409 | + { |
|
410 | + $this->dataProvider->clear($var); |
|
411 | + } |
|
412 | + |
|
413 | + public function clear_all_assign() |
|
414 | + { |
|
415 | + $this->dataProvider->clear(); |
|
416 | + } |
|
417 | + |
|
418 | + public function get_template_vars($name = null) |
|
419 | + { |
|
420 | + if ($this->show_compat_errors) { |
|
421 | + trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE); |
|
422 | + } |
|
423 | + |
|
424 | + $data = $this->dataProvider->getData(); |
|
425 | + if ($name === null) { |
|
426 | + return $data; |
|
427 | + } elseif (isset($data[$name])) { |
|
428 | + return $data[$name]; |
|
429 | + } |
|
430 | + |
|
431 | + return null; |
|
432 | + } |
|
433 | + |
|
434 | + public function clear_all_cache($olderThan = 0) |
|
435 | + { |
|
436 | + $this->clearCache($olderThan); |
|
437 | + } |
|
438 | + |
|
439 | + public function clear_cache($template, $cacheId = null, $compileId = null, $olderThan = 0) |
|
440 | + { |
|
441 | + $this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan); |
|
442 | + } |
|
443 | + |
|
444 | + public function trigger_error($error_msg, $error_type = E_USER_WARNING) |
|
445 | + { |
|
446 | + $this->triggerError($error_msg, $error_type); |
|
447 | + } |
|
448 | + |
|
449 | + protected function initGlobals() |
|
450 | + { |
|
451 | + parent::initGlobals(); |
|
452 | + $this->globals['ldelim'] = '{'; |
|
453 | + $this->globals['rdelim'] = '}'; |
|
454 | + } |
|
455 | + |
|
456 | + protected function makeTemplate($file, $cacheId, $compileId) |
|
457 | + { |
|
458 | + if ($compileId === null) { |
|
459 | + $compileId = $this->compile_id; |
|
460 | + } |
|
461 | + |
|
462 | + $hash = bin2hex(md5($file.$cacheId.$compileId, true)); |
|
463 | + if (!isset(self::$tplCache[$hash])) { |
|
464 | + // abs path |
|
465 | + if (substr($file, 0, 1) === '/' || substr($file, 1, 1) === ':') { |
|
466 | + self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId); |
|
467 | + } elseif (is_string($this->template_dir) || is_array($this->template_dir)) { |
|
468 | + self::$tplCache[$hash] = new Dwoo_Template_File($file, null, $cacheId, $compileId, $this->template_dir); |
|
469 | + } else { |
|
470 | + throw new Exception('Unable to load "'.$file.'", check the template_dir'); |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + return self::$tplCache[$hash]; |
|
475 | + } |
|
476 | + |
|
477 | + public function triggerError($message, $level = E_USER_NOTICE) |
|
478 | + { |
|
479 | + if (is_object($this->template)) { |
|
480 | + return parent::triggerError($message, $level); |
|
481 | + } |
|
482 | + trigger_error('Dwoo error : '.$message, $level); |
|
483 | + } |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | class Dwoo_Smarty_Filter_Adapter extends Dwoo_Filter |
487 | 487 | { |
488 | - public $callback; |
|
488 | + public $callback; |
|
489 | 489 | |
490 | - public function process($input) |
|
491 | - { |
|
492 | - return call_user_func($this->callback, $input); |
|
493 | - } |
|
490 | + public function process($input) |
|
491 | + { |
|
492 | + return call_user_func($this->callback, $input); |
|
493 | + } |
|
494 | 494 | |
495 | - public function registerCallback($callback) |
|
496 | - { |
|
497 | - $this->callback = $callback; |
|
498 | - } |
|
495 | + public function registerCallback($callback) |
|
496 | + { |
|
497 | + $this->callback = $callback; |
|
498 | + } |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | class Dwoo_Smarty_Processor_Adapter extends Dwoo_Processor |
502 | 502 | { |
503 | - public $callback; |
|
503 | + public $callback; |
|
504 | 504 | |
505 | - public function process($input) |
|
506 | - { |
|
507 | - return call_user_func($this->callback, $input); |
|
508 | - } |
|
505 | + public function process($input) |
|
506 | + { |
|
507 | + return call_user_func($this->callback, $input); |
|
508 | + } |
|
509 | 509 | |
510 | - public function registerCallback($callback) |
|
511 | - { |
|
512 | - $this->callback = $callback; |
|
513 | - } |
|
510 | + public function registerCallback($callback) |
|
511 | + { |
|
512 | + $this->callback = $callback; |
|
513 | + } |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | // cloaks the adapter if possible with the smarty name to fool type-hinted plugins |
517 | 517 | if (class_exists('Smarty') === false) { |
518 | - interface Smarty |
|
519 | - { |
|
520 | - } |
|
521 | - class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter implements Smarty |
|
522 | - { |
|
523 | - } |
|
518 | + interface Smarty |
|
519 | + { |
|
520 | + } |
|
521 | + class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter implements Smarty |
|
522 | + { |
|
523 | + } |
|
524 | 524 | } else { |
525 | - class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter |
|
526 | - { |
|
527 | - } |
|
525 | + class Dwoo_Smarty_Adapter extends Dwoo_Smarty__Adapter |
|
526 | + { |
|
527 | + } |
|
528 | 528 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Dwoo_Security_Policy |
21 | 21 | { |
22 | - /**#@+ |
|
22 | + /**#@+ |
|
23 | 23 | * php handling constants, defaults to PHP_REMOVE |
24 | 24 | * |
25 | 25 | * PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template |
@@ -28,296 +28,296 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @var int |
30 | 30 | */ |
31 | - const PHP_ENCODE = 1; |
|
32 | - const PHP_REMOVE = 2; |
|
33 | - const PHP_ALLOW = 3; |
|
34 | - /**#@-*/ |
|
31 | + const PHP_ENCODE = 1; |
|
32 | + const PHP_REMOVE = 2; |
|
33 | + const PHP_ALLOW = 3; |
|
34 | + /**#@-*/ |
|
35 | 35 | |
36 | - /**#@+ |
|
36 | + /**#@+ |
|
37 | 37 | * constant handling constants, defaults to CONST_DISALLOW |
38 | 38 | * |
39 | 39 | * CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template |
40 | 40 | * CONST_ALLOW : allow {$dwoo.const.*} calls |
41 | 41 | */ |
42 | - const CONST_DISALLOW = false; |
|
43 | - const CONST_ALLOW = true; |
|
44 | - /**#@-*/ |
|
42 | + const CONST_DISALLOW = false; |
|
43 | + const CONST_ALLOW = true; |
|
44 | + /**#@-*/ |
|
45 | 45 | |
46 | - /** |
|
47 | - * php functions that are allowed to be used within the template. |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - protected $allowedPhpFunctions = array( |
|
52 | - 'str_repeat' => true, |
|
53 | - 'number_format' => true, |
|
54 | - 'htmlentities' => true, |
|
55 | - 'htmlspecialchars' => true, |
|
56 | - 'long2ip' => true, |
|
57 | - 'strlen' => true, |
|
58 | - 'list' => true, |
|
59 | - 'empty' => true, |
|
60 | - 'count' => true, |
|
61 | - 'sizeof' => true, |
|
62 | - 'in_array' => true, |
|
63 | - 'is_array' => true, |
|
64 | - ); |
|
46 | + /** |
|
47 | + * php functions that are allowed to be used within the template. |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + protected $allowedPhpFunctions = array( |
|
52 | + 'str_repeat' => true, |
|
53 | + 'number_format' => true, |
|
54 | + 'htmlentities' => true, |
|
55 | + 'htmlspecialchars' => true, |
|
56 | + 'long2ip' => true, |
|
57 | + 'strlen' => true, |
|
58 | + 'list' => true, |
|
59 | + 'empty' => true, |
|
60 | + 'count' => true, |
|
61 | + 'sizeof' => true, |
|
62 | + 'in_array' => true, |
|
63 | + 'is_array' => true, |
|
64 | + ); |
|
65 | 65 | |
66 | - /** |
|
67 | - * methods that are allowed to be used within the template. |
|
68 | - * |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - protected $allowedMethods = array(); |
|
66 | + /** |
|
67 | + * methods that are allowed to be used within the template. |
|
68 | + * |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + protected $allowedMethods = array(); |
|
72 | 72 | |
73 | - /** |
|
74 | - * paths that are safe to use with include or other file-access plugins. |
|
75 | - * |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $allowedDirectories = array(); |
|
73 | + /** |
|
74 | + * paths that are safe to use with include or other file-access plugins. |
|
75 | + * |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $allowedDirectories = array(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * stores the php handling level. |
|
82 | - * |
|
83 | - * defaults to Dwoo_Security_Policy::PHP_REMOVE |
|
84 | - * |
|
85 | - * @var int |
|
86 | - */ |
|
87 | - protected $phpHandling = self::PHP_REMOVE; |
|
80 | + /** |
|
81 | + * stores the php handling level. |
|
82 | + * |
|
83 | + * defaults to Dwoo_Security_Policy::PHP_REMOVE |
|
84 | + * |
|
85 | + * @var int |
|
86 | + */ |
|
87 | + protected $phpHandling = self::PHP_REMOVE; |
|
88 | 88 | |
89 | - /** |
|
90 | - * stores the constant handling level. |
|
91 | - * |
|
92 | - * defaults to Dwoo_Security_Policy::CONST_DISALLOW |
|
93 | - * |
|
94 | - * @var bool |
|
95 | - */ |
|
96 | - protected $constHandling = self::CONST_DISALLOW; |
|
89 | + /** |
|
90 | + * stores the constant handling level. |
|
91 | + * |
|
92 | + * defaults to Dwoo_Security_Policy::CONST_DISALLOW |
|
93 | + * |
|
94 | + * @var bool |
|
95 | + */ |
|
96 | + protected $constHandling = self::CONST_DISALLOW; |
|
97 | 97 | |
98 | - /** |
|
99 | - * adds a php function to the allowed list. |
|
100 | - * |
|
101 | - * @param mixed $func function name or array of function names |
|
102 | - */ |
|
103 | - public function allowPhpFunction($func) |
|
104 | - { |
|
105 | - if (is_array($func)) { |
|
106 | - foreach ($func as $fname) { |
|
107 | - $this->allowedPhpFunctions[strtolower($fname)] = true; |
|
108 | - } |
|
109 | - } else { |
|
110 | - $this->allowedPhpFunctions[strtolower($func)] = true; |
|
111 | - } |
|
112 | - } |
|
98 | + /** |
|
99 | + * adds a php function to the allowed list. |
|
100 | + * |
|
101 | + * @param mixed $func function name or array of function names |
|
102 | + */ |
|
103 | + public function allowPhpFunction($func) |
|
104 | + { |
|
105 | + if (is_array($func)) { |
|
106 | + foreach ($func as $fname) { |
|
107 | + $this->allowedPhpFunctions[strtolower($fname)] = true; |
|
108 | + } |
|
109 | + } else { |
|
110 | + $this->allowedPhpFunctions[strtolower($func)] = true; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * removes a php function from the allowed list. |
|
116 | - * |
|
117 | - * @param mixed $func function name or array of function names |
|
118 | - */ |
|
119 | - public function disallowPhpFunction($func) |
|
120 | - { |
|
121 | - if (is_array($func)) { |
|
122 | - foreach ($func as $fname) { |
|
123 | - unset($this->allowedPhpFunctions[strtolower($fname)]); |
|
124 | - } |
|
125 | - } else { |
|
126 | - unset($this->allowedPhpFunctions[strtolower($func)]); |
|
127 | - } |
|
128 | - } |
|
114 | + /** |
|
115 | + * removes a php function from the allowed list. |
|
116 | + * |
|
117 | + * @param mixed $func function name or array of function names |
|
118 | + */ |
|
119 | + public function disallowPhpFunction($func) |
|
120 | + { |
|
121 | + if (is_array($func)) { |
|
122 | + foreach ($func as $fname) { |
|
123 | + unset($this->allowedPhpFunctions[strtolower($fname)]); |
|
124 | + } |
|
125 | + } else { |
|
126 | + unset($this->allowedPhpFunctions[strtolower($func)]); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * returns the list of php functions allowed to run, note that the function names |
|
132 | - * are stored in the array keys and not values. |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function getAllowedPhpFunctions() |
|
137 | - { |
|
138 | - return $this->allowedPhpFunctions; |
|
139 | - } |
|
130 | + /** |
|
131 | + * returns the list of php functions allowed to run, note that the function names |
|
132 | + * are stored in the array keys and not values. |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function getAllowedPhpFunctions() |
|
137 | + { |
|
138 | + return $this->allowedPhpFunctions; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * adds a class method to the allowed list, this must be used for |
|
143 | - * both static and non static method by providing the class name |
|
144 | - * and method name to use. |
|
145 | - * |
|
146 | - * @param mixed $class class name or array of array('class', 'method') couples |
|
147 | - * @param string $method method name |
|
148 | - */ |
|
149 | - public function allowMethod($class, $method = null) |
|
150 | - { |
|
151 | - if (is_array($class)) { |
|
152 | - foreach ($class as $elem) { |
|
153 | - $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true; |
|
154 | - } |
|
155 | - } else { |
|
156 | - $this->allowedMethods[strtolower($class)][strtolower($method)] = true; |
|
157 | - } |
|
158 | - } |
|
141 | + /** |
|
142 | + * adds a class method to the allowed list, this must be used for |
|
143 | + * both static and non static method by providing the class name |
|
144 | + * and method name to use. |
|
145 | + * |
|
146 | + * @param mixed $class class name or array of array('class', 'method') couples |
|
147 | + * @param string $method method name |
|
148 | + */ |
|
149 | + public function allowMethod($class, $method = null) |
|
150 | + { |
|
151 | + if (is_array($class)) { |
|
152 | + foreach ($class as $elem) { |
|
153 | + $this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])] = true; |
|
154 | + } |
|
155 | + } else { |
|
156 | + $this->allowedMethods[strtolower($class)][strtolower($method)] = true; |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * removes a class method from the allowed list. |
|
162 | - * |
|
163 | - * @param mixed $class class name or array of array('class', 'method') couples |
|
164 | - * @param string $method method name |
|
165 | - */ |
|
166 | - public function disallowMethod($class, $method = null) |
|
167 | - { |
|
168 | - if (is_array($class)) { |
|
169 | - foreach ($class as $elem) { |
|
170 | - unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]); |
|
171 | - } |
|
172 | - } else { |
|
173 | - unset($this->allowedMethods[strtolower($class)][strtolower($method)]); |
|
174 | - } |
|
175 | - } |
|
160 | + /** |
|
161 | + * removes a class method from the allowed list. |
|
162 | + * |
|
163 | + * @param mixed $class class name or array of array('class', 'method') couples |
|
164 | + * @param string $method method name |
|
165 | + */ |
|
166 | + public function disallowMethod($class, $method = null) |
|
167 | + { |
|
168 | + if (is_array($class)) { |
|
169 | + foreach ($class as $elem) { |
|
170 | + unset($this->allowedMethods[strtolower($elem[0])][strtolower($elem[1])]); |
|
171 | + } |
|
172 | + } else { |
|
173 | + unset($this->allowedMethods[strtolower($class)][strtolower($method)]); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * returns the list of class methods allowed to run, note that the class names |
|
179 | - * and method names are stored in the array keys and not values. |
|
180 | - * |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - public function getAllowedMethods() |
|
184 | - { |
|
185 | - return $this->allowedMethods; |
|
186 | - } |
|
177 | + /** |
|
178 | + * returns the list of class methods allowed to run, note that the class names |
|
179 | + * and method names are stored in the array keys and not values. |
|
180 | + * |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + public function getAllowedMethods() |
|
184 | + { |
|
185 | + return $this->allowedMethods; |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * adds a directory to the safelist for includes and other file-access plugins. |
|
190 | - * |
|
191 | - * note that all the includePath directories you provide to the Dwoo_Template_File class |
|
192 | - * are automatically marked as safe |
|
193 | - * |
|
194 | - * @param mixed $path a path name or an array of paths |
|
195 | - */ |
|
196 | - public function allowDirectory($path) |
|
197 | - { |
|
198 | - if (is_array($path)) { |
|
199 | - foreach ($path as $dir) { |
|
200 | - $this->allowedDirectories[realpath($dir)] = true; |
|
201 | - } |
|
202 | - } else { |
|
203 | - $this->allowedDirectories[realpath($path)] = true; |
|
204 | - } |
|
205 | - } |
|
188 | + /** |
|
189 | + * adds a directory to the safelist for includes and other file-access plugins. |
|
190 | + * |
|
191 | + * note that all the includePath directories you provide to the Dwoo_Template_File class |
|
192 | + * are automatically marked as safe |
|
193 | + * |
|
194 | + * @param mixed $path a path name or an array of paths |
|
195 | + */ |
|
196 | + public function allowDirectory($path) |
|
197 | + { |
|
198 | + if (is_array($path)) { |
|
199 | + foreach ($path as $dir) { |
|
200 | + $this->allowedDirectories[realpath($dir)] = true; |
|
201 | + } |
|
202 | + } else { |
|
203 | + $this->allowedDirectories[realpath($path)] = true; |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * removes a directory from the safelist. |
|
209 | - * |
|
210 | - * @param mixed $path a path name or an array of paths |
|
211 | - */ |
|
212 | - public function disallowDirectory($path) |
|
213 | - { |
|
214 | - if (is_array($path)) { |
|
215 | - foreach ($path as $dir) { |
|
216 | - unset($this->allowedDirectories[realpath($dir)]); |
|
217 | - } |
|
218 | - } else { |
|
219 | - unset($this->allowedDirectories[realpath($path)]); |
|
220 | - } |
|
221 | - } |
|
207 | + /** |
|
208 | + * removes a directory from the safelist. |
|
209 | + * |
|
210 | + * @param mixed $path a path name or an array of paths |
|
211 | + */ |
|
212 | + public function disallowDirectory($path) |
|
213 | + { |
|
214 | + if (is_array($path)) { |
|
215 | + foreach ($path as $dir) { |
|
216 | + unset($this->allowedDirectories[realpath($dir)]); |
|
217 | + } |
|
218 | + } else { |
|
219 | + unset($this->allowedDirectories[realpath($path)]); |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * returns the list of safe paths, note that the paths are stored in the array |
|
225 | - * keys and not values. |
|
226 | - * |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function getAllowedDirectories() |
|
230 | - { |
|
231 | - return $this->allowedDirectories; |
|
232 | - } |
|
223 | + /** |
|
224 | + * returns the list of safe paths, note that the paths are stored in the array |
|
225 | + * keys and not values. |
|
226 | + * |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function getAllowedDirectories() |
|
230 | + { |
|
231 | + return $this->allowedDirectories; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * sets the php handling level, defaults to REMOVE. |
|
236 | - * |
|
237 | - * @param int $level one of the Dwoo_Security_Policy::PHP_* constants |
|
238 | - */ |
|
239 | - public function setPhpHandling($level = self::PHP_REMOVE) |
|
240 | - { |
|
241 | - $this->phpHandling = $level; |
|
242 | - } |
|
234 | + /** |
|
235 | + * sets the php handling level, defaults to REMOVE. |
|
236 | + * |
|
237 | + * @param int $level one of the Dwoo_Security_Policy::PHP_* constants |
|
238 | + */ |
|
239 | + public function setPhpHandling($level = self::PHP_REMOVE) |
|
240 | + { |
|
241 | + $this->phpHandling = $level; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * returns the php handling level. |
|
246 | - * |
|
247 | - * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants |
|
248 | - */ |
|
249 | - public function getPhpHandling() |
|
250 | - { |
|
251 | - return $this->phpHandling; |
|
252 | - } |
|
244 | + /** |
|
245 | + * returns the php handling level. |
|
246 | + * |
|
247 | + * @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants |
|
248 | + */ |
|
249 | + public function getPhpHandling() |
|
250 | + { |
|
251 | + return $this->phpHandling; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * sets the constant handling level, defaults to CONST_DISALLOW. |
|
256 | - * |
|
257 | - * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants |
|
258 | - */ |
|
259 | - public function setConstantHandling($level = self::CONST_DISALLOW) |
|
260 | - { |
|
261 | - $this->constHandling = $level; |
|
262 | - } |
|
254 | + /** |
|
255 | + * sets the constant handling level, defaults to CONST_DISALLOW. |
|
256 | + * |
|
257 | + * @param bool $level one of the Dwoo_Security_Policy::CONST_* constants |
|
258 | + */ |
|
259 | + public function setConstantHandling($level = self::CONST_DISALLOW) |
|
260 | + { |
|
261 | + $this->constHandling = $level; |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * returns the constant handling level. |
|
266 | - * |
|
267 | - * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants |
|
268 | - */ |
|
269 | - public function getConstantHandling() |
|
270 | - { |
|
271 | - return $this->constHandling; |
|
272 | - } |
|
264 | + /** |
|
265 | + * returns the constant handling level. |
|
266 | + * |
|
267 | + * @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants |
|
268 | + */ |
|
269 | + public function getConstantHandling() |
|
270 | + { |
|
271 | + return $this->constHandling; |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * this is used at run time to check whether method calls are allowed or not. |
|
276 | - * |
|
277 | - * @param Dwoo_Core $dwoo dwoo instance that calls this |
|
278 | - * @param object $obj any object on which the method must be called |
|
279 | - * @param string $method lowercased method name |
|
280 | - * @param array $args arguments array |
|
281 | - * |
|
282 | - * @return mixed result of method call or unll + E_USER_NOTICE if not allowed |
|
283 | - */ |
|
284 | - public function callMethod(Dwoo_Core $dwoo, $obj, $method, $args) |
|
285 | - { |
|
286 | - foreach ($this->allowedMethods as $class => $methods) { |
|
287 | - if (!isset($methods[$method])) { |
|
288 | - continue; |
|
289 | - } |
|
290 | - if ($obj instanceof $class) { |
|
291 | - return call_user_func_array(array($obj, $method), $args); |
|
292 | - } |
|
293 | - } |
|
294 | - $dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()'); |
|
274 | + /** |
|
275 | + * this is used at run time to check whether method calls are allowed or not. |
|
276 | + * |
|
277 | + * @param Dwoo_Core $dwoo dwoo instance that calls this |
|
278 | + * @param object $obj any object on which the method must be called |
|
279 | + * @param string $method lowercased method name |
|
280 | + * @param array $args arguments array |
|
281 | + * |
|
282 | + * @return mixed result of method call or unll + E_USER_NOTICE if not allowed |
|
283 | + */ |
|
284 | + public function callMethod(Dwoo_Core $dwoo, $obj, $method, $args) |
|
285 | + { |
|
286 | + foreach ($this->allowedMethods as $class => $methods) { |
|
287 | + if (!isset($methods[$method])) { |
|
288 | + continue; |
|
289 | + } |
|
290 | + if ($obj instanceof $class) { |
|
291 | + return call_user_func_array(array($obj, $method), $args); |
|
292 | + } |
|
293 | + } |
|
294 | + $dwoo->triggerError('The current security policy prevents you from calling '.get_class($obj).'::'.$method.'()'); |
|
295 | 295 | |
296 | - return null; |
|
297 | - } |
|
296 | + return null; |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * this is used at compile time to check whether static method calls are allowed or not. |
|
301 | - * |
|
302 | - * @param mixed $class lowercased class name or array('class', 'method') couple |
|
303 | - * @param string $method lowercased method name |
|
304 | - * |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - public function isMethodAllowed($class, $method = null) |
|
308 | - { |
|
309 | - if (is_array($class)) { |
|
310 | - list($class, $method) = $class; |
|
311 | - } |
|
312 | - foreach ($this->allowedMethods as $allowedClass => $methods) { |
|
313 | - if (!isset($methods[$method])) { |
|
314 | - continue; |
|
315 | - } |
|
316 | - if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) { |
|
317 | - return true; |
|
318 | - } |
|
319 | - } |
|
299 | + /** |
|
300 | + * this is used at compile time to check whether static method calls are allowed or not. |
|
301 | + * |
|
302 | + * @param mixed $class lowercased class name or array('class', 'method') couple |
|
303 | + * @param string $method lowercased method name |
|
304 | + * |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + public function isMethodAllowed($class, $method = null) |
|
308 | + { |
|
309 | + if (is_array($class)) { |
|
310 | + list($class, $method) = $class; |
|
311 | + } |
|
312 | + foreach ($this->allowedMethods as $allowedClass => $methods) { |
|
313 | + if (!isset($methods[$method])) { |
|
314 | + continue; |
|
315 | + } |
|
316 | + if ($class === $allowedClass || is_subclass_of($class, $allowedClass)) { |
|
317 | + return true; |
|
318 | + } |
|
319 | + } |
|
320 | 320 | |
321 | - return false; |
|
322 | - } |
|
321 | + return false; |
|
322 | + } |
|
323 | 323 | } |
@@ -24,31 +24,31 @@ |
||
24 | 24 | */ |
25 | 25 | interface Dwoo_ICompiler |
26 | 26 | { |
27 | - /** |
|
28 | - * compiles the provided string down to php code. |
|
29 | - * |
|
30 | - * @param string $templateStr the template to compile |
|
31 | - * |
|
32 | - * @return string a compiled php code string |
|
33 | - */ |
|
34 | - public function compile(Dwoo_Core $dwoo, Dwoo_ITemplate $template); |
|
27 | + /** |
|
28 | + * compiles the provided string down to php code. |
|
29 | + * |
|
30 | + * @param string $templateStr the template to compile |
|
31 | + * |
|
32 | + * @return string a compiled php code string |
|
33 | + */ |
|
34 | + public function compile(Dwoo_Core $dwoo, Dwoo_ITemplate $template); |
|
35 | 35 | |
36 | - /** |
|
37 | - * adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
38 | - * |
|
39 | - * @see Dwoo_Core::addPlugin |
|
40 | - * |
|
41 | - * @param array $customPlugins an array of custom plugins |
|
42 | - */ |
|
43 | - public function setCustomPlugins(array $customPlugins); |
|
36 | + /** |
|
37 | + * adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
38 | + * |
|
39 | + * @see Dwoo_Core::addPlugin |
|
40 | + * |
|
41 | + * @param array $customPlugins an array of custom plugins |
|
42 | + */ |
|
43 | + public function setCustomPlugins(array $customPlugins); |
|
44 | 44 | |
45 | - /** |
|
46 | - * sets the security policy object to enforce some php security settings. |
|
47 | - * |
|
48 | - * use this if untrusted persons can modify templates, |
|
49 | - * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
50 | - * |
|
51 | - * @param Dwoo_Security_Policy $policy the security policy object |
|
52 | - */ |
|
53 | - public function setSecurityPolicy(Dwoo_Security_Policy $policy = null); |
|
45 | + /** |
|
46 | + * sets the security policy object to enforce some php security settings. |
|
47 | + * |
|
48 | + * use this if untrusted persons can modify templates, |
|
49 | + * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
50 | + * |
|
51 | + * @param Dwoo_Security_Policy $policy the security policy object |
|
52 | + */ |
|
53 | + public function setSecurityPolicy(Dwoo_Security_Policy $policy = null); |
|
54 | 54 | } |
@@ -19,140 +19,140 @@ |
||
19 | 19 | */ |
20 | 20 | interface Dwoo_ITemplate |
21 | 21 | { |
22 | - /** |
|
23 | - * returns the cache duration for this template. |
|
24 | - * |
|
25 | - * defaults to null if it was not provided |
|
26 | - * |
|
27 | - * @return int|null |
|
28 | - */ |
|
29 | - public function getCacheTime(); |
|
22 | + /** |
|
23 | + * returns the cache duration for this template. |
|
24 | + * |
|
25 | + * defaults to null if it was not provided |
|
26 | + * |
|
27 | + * @return int|null |
|
28 | + */ |
|
29 | + public function getCacheTime(); |
|
30 | 30 | |
31 | - /** |
|
32 | - * sets the cache duration for this template. |
|
33 | - * |
|
34 | - * can be used to set it after the object is created if you did not provide |
|
35 | - * it in the constructor |
|
36 | - * |
|
37 | - * @param int $seconds duration of the cache validity for this template, if |
|
38 | - * null it defaults to the Dwoo instance's cache time. 0 = disable and |
|
39 | - * -1 = infinite cache |
|
40 | - */ |
|
41 | - public function setCacheTime($seconds = null); |
|
31 | + /** |
|
32 | + * sets the cache duration for this template. |
|
33 | + * |
|
34 | + * can be used to set it after the object is created if you did not provide |
|
35 | + * it in the constructor |
|
36 | + * |
|
37 | + * @param int $seconds duration of the cache validity for this template, if |
|
38 | + * null it defaults to the Dwoo instance's cache time. 0 = disable and |
|
39 | + * -1 = infinite cache |
|
40 | + */ |
|
41 | + public function setCacheTime($seconds = null); |
|
42 | 42 | |
43 | - /** |
|
44 | - * returns the cached template output file name, true if it's cache-able but not cached |
|
45 | - * or false if it's not cached. |
|
46 | - * |
|
47 | - * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
48 | - * |
|
49 | - * @return string|bool |
|
50 | - */ |
|
51 | - public function getCachedTemplate(Dwoo_Core $dwoo); |
|
43 | + /** |
|
44 | + * returns the cached template output file name, true if it's cache-able but not cached |
|
45 | + * or false if it's not cached. |
|
46 | + * |
|
47 | + * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
48 | + * |
|
49 | + * @return string|bool |
|
50 | + */ |
|
51 | + public function getCachedTemplate(Dwoo_Core $dwoo); |
|
52 | 52 | |
53 | - /** |
|
54 | - * caches the provided output into the cache file. |
|
55 | - * |
|
56 | - * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
57 | - * @param string $output the template output |
|
58 | - * |
|
59 | - * @return mixed full path of the cached file or false upon failure |
|
60 | - */ |
|
61 | - public function cache(Dwoo_Core $dwoo, $output); |
|
53 | + /** |
|
54 | + * caches the provided output into the cache file. |
|
55 | + * |
|
56 | + * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
57 | + * @param string $output the template output |
|
58 | + * |
|
59 | + * @return mixed full path of the cached file or false upon failure |
|
60 | + */ |
|
61 | + public function cache(Dwoo_Core $dwoo, $output); |
|
62 | 62 | |
63 | - /** |
|
64 | - * clears the cached template if it's older than the given time. |
|
65 | - * |
|
66 | - * @param Dwoo_Core $dwoo the dwoo instance that was used to cache that template |
|
67 | - * @param int $olderThan minimum time (in seconds) required for the cache to be cleared |
|
68 | - * |
|
69 | - * @return bool true if the cache was not present or if it was deleted, false if it remains there |
|
70 | - */ |
|
71 | - public function clearCache(Dwoo_Core $dwoo, $olderThan = -1); |
|
63 | + /** |
|
64 | + * clears the cached template if it's older than the given time. |
|
65 | + * |
|
66 | + * @param Dwoo_Core $dwoo the dwoo instance that was used to cache that template |
|
67 | + * @param int $olderThan minimum time (in seconds) required for the cache to be cleared |
|
68 | + * |
|
69 | + * @return bool true if the cache was not present or if it was deleted, false if it remains there |
|
70 | + */ |
|
71 | + public function clearCache(Dwoo_Core $dwoo, $olderThan = -1); |
|
72 | 72 | |
73 | - /** |
|
74 | - * returns the compiled template file name. |
|
75 | - * |
|
76 | - * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
77 | - * @param Dwoo_ICompiler $compiler the compiler that must be used |
|
78 | - * |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler = null); |
|
73 | + /** |
|
74 | + * returns the compiled template file name. |
|
75 | + * |
|
76 | + * @param Dwoo_Core $dwoo the dwoo instance that requests it |
|
77 | + * @param Dwoo_ICompiler $compiler the compiler that must be used |
|
78 | + * |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler = null); |
|
82 | 82 | |
83 | - /** |
|
84 | - * returns the template name. |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getName(); |
|
83 | + /** |
|
84 | + * returns the template name. |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getName(); |
|
89 | 89 | |
90 | - /** |
|
91 | - * returns the resource name for this template class. |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getResourceName(); |
|
90 | + /** |
|
91 | + * returns the resource name for this template class. |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getResourceName(); |
|
96 | 96 | |
97 | - /** |
|
98 | - * returns the resource identifier for this template or false if it has no identifier. |
|
99 | - * |
|
100 | - * @return string|false |
|
101 | - */ |
|
102 | - public function getResourceIdentifier(); |
|
97 | + /** |
|
98 | + * returns the resource identifier for this template or false if it has no identifier. |
|
99 | + * |
|
100 | + * @return string|false |
|
101 | + */ |
|
102 | + public function getResourceIdentifier(); |
|
103 | 103 | |
104 | - /** |
|
105 | - * returns the template source of this template. |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getSource(); |
|
104 | + /** |
|
105 | + * returns the template source of this template. |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getSource(); |
|
110 | 110 | |
111 | - /** |
|
112 | - * returns an unique string identifying the current version of this template, |
|
113 | - * for example a timestamp of the last modified date or a hash of the template source. |
|
114 | - * |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function getUid(); |
|
111 | + /** |
|
112 | + * returns an unique string identifying the current version of this template, |
|
113 | + * for example a timestamp of the last modified date or a hash of the template source. |
|
114 | + * |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function getUid(); |
|
118 | 118 | |
119 | - /** |
|
120 | - * returns the compiler used by this template, if it was just compiled, or null. |
|
121 | - * |
|
122 | - * @return Dwoo_ICompiler |
|
123 | - */ |
|
124 | - public function getCompiler(); |
|
119 | + /** |
|
120 | + * returns the compiler used by this template, if it was just compiled, or null. |
|
121 | + * |
|
122 | + * @return Dwoo_ICompiler |
|
123 | + */ |
|
124 | + public function getCompiler(); |
|
125 | 125 | |
126 | - /** |
|
127 | - * returns some php code that will check if this template has been modified or not. |
|
128 | - * |
|
129 | - * if the function returns null, the template will be instanciated and then the Uid checked |
|
130 | - * |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getIsModifiedCode(); |
|
126 | + /** |
|
127 | + * returns some php code that will check if this template has been modified or not. |
|
128 | + * |
|
129 | + * if the function returns null, the template will be instanciated and then the Uid checked |
|
130 | + * |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getIsModifiedCode(); |
|
134 | 134 | |
135 | - /** |
|
136 | - * returns a new template object from the given resource identifier, null if no include is |
|
137 | - * possible (resource not found), or false if include is not permitted by this resource type. |
|
138 | - * |
|
139 | - * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the |
|
140 | - * necessary permission checks if required, if the security policy prevents the template |
|
141 | - * generation it should throw a new Dwoo_Security_Exception with a relevant message |
|
142 | - * |
|
143 | - * @param mixed $resourceId the resource identifier |
|
144 | - * @param int $cacheTime duration of the cache validity for this template, |
|
145 | - * if null it defaults to the Dwoo instance that will |
|
146 | - * render this template |
|
147 | - * @param string $cacheId the unique cache identifier of this page or anything else that |
|
148 | - * makes this template's content unique, if null it defaults |
|
149 | - * to the current url |
|
150 | - * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
151 | - * template from others, if null it defaults to the filename+bits of the path |
|
152 | - * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through |
|
153 | - * an include, extends or any other plugin) |
|
154 | - * |
|
155 | - * @return Dwoo_ITemplate|null|false |
|
156 | - */ |
|
157 | - public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null); |
|
135 | + /** |
|
136 | + * returns a new template object from the given resource identifier, null if no include is |
|
137 | + * possible (resource not found), or false if include is not permitted by this resource type. |
|
138 | + * |
|
139 | + * this method should also check if $dwoo->getSecurityPolicy() is null or not and do the |
|
140 | + * necessary permission checks if required, if the security policy prevents the template |
|
141 | + * generation it should throw a new Dwoo_Security_Exception with a relevant message |
|
142 | + * |
|
143 | + * @param mixed $resourceId the resource identifier |
|
144 | + * @param int $cacheTime duration of the cache validity for this template, |
|
145 | + * if null it defaults to the Dwoo instance that will |
|
146 | + * render this template |
|
147 | + * @param string $cacheId the unique cache identifier of this page or anything else that |
|
148 | + * makes this template's content unique, if null it defaults |
|
149 | + * to the current url |
|
150 | + * @param string $compileId the unique compiled identifier, which is used to distinguish this |
|
151 | + * template from others, if null it defaults to the filename+bits of the path |
|
152 | + * @param Dwoo_ITemplate $parentTemplate the template that is requesting a new template object (through |
|
153 | + * an include, extends or any other plugin) |
|
154 | + * |
|
155 | + * @return Dwoo_ITemplate|null|false |
|
156 | + */ |
|
157 | + public static function templateFactory(Dwoo_Core $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null); |
|
158 | 158 | } |