@@ -16,157 +16,157 @@ |
||
16 | 16 | */ |
17 | 17 | class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer |
18 | 18 | { |
19 | - /** |
|
20 | - * @constant string The directory inside the cache dir where templates will |
|
21 | - * be stored in compiled form. |
|
22 | - */ |
|
23 | - const COMPILE_DIR = 'templates'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @constant string The subdirectory inside the compile dir where templates |
|
27 | - * will be stored in compiled form. |
|
28 | - */ |
|
29 | - const COMPILE_SUBDIR = 'dwoo'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @constant string The directory inside the cache dir where cached content |
|
33 | - * will be stored. |
|
34 | - */ |
|
35 | - const CACHE_DIR = 'dwoo'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var Dwoo Dwoo template engine |
|
39 | - */ |
|
40 | - protected $dwoo = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string A string with the default template file extension, |
|
44 | - * including the dot |
|
45 | - */ |
|
46 | - protected $defaultExtension = '.html'; |
|
47 | - |
|
48 | - /** |
|
49 | - * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
50 | - */ |
|
51 | - protected $plugin_dir = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * Pre-serialization callback. |
|
55 | - * |
|
56 | - * Excludes the Dwoo instance to prevent excessive serialization load. |
|
57 | - */ |
|
58 | - public function __sleep() |
|
59 | - { |
|
60 | - $keys = parent::__sleep(); |
|
61 | - unset($keys[array_search('dwoo', $keys)]); |
|
62 | - |
|
63 | - return $keys; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Initialize this Renderer. |
|
68 | - * |
|
69 | - * @param AgaviContext The current application context |
|
70 | - * @param array An associative array of initialization parameters |
|
71 | - */ |
|
72 | - public function initialize(AgaviContext $context, array $parameters = array()) |
|
73 | - { |
|
74 | - parent::initialize($context, $parameters); |
|
75 | - |
|
76 | - $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * provides a custom compiler to the dwoo renderer with optional settings |
|
81 | - * you can set in the agavi output_types.xml config file. |
|
82 | - * |
|
83 | - * @return Dwoo_Compiler |
|
84 | - */ |
|
85 | - public function compilerFactory() |
|
86 | - { |
|
87 | - $compiler = Dwoo_Compiler::compilerFactory(); |
|
88 | - $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
89 | - |
|
90 | - return $compiler; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Grab a cleaned up dwoo instance. |
|
95 | - * |
|
96 | - * @return Dwoo A Dwoo instance |
|
97 | - */ |
|
98 | - protected function getEngine() |
|
99 | - { |
|
100 | - if ($this->dwoo) { |
|
101 | - return $this->dwoo; |
|
102 | - } |
|
103 | - |
|
104 | - // this triggers Agavi autoload |
|
105 | - if (!class_exists('Dwoo')) { |
|
106 | - if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
107 | - // file was dropped with the entire dwoo package |
|
108 | - include dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
109 | - } else { |
|
110 | - // assume the dwoo package is in the include path |
|
111 | - include 'dwooAutoload.php'; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
116 | - |
|
117 | - $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
118 | - AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
119 | - |
|
120 | - $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
121 | - AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
122 | - |
|
123 | - $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
124 | - |
|
125 | - if (!empty($this->plugin_dir)) { |
|
126 | - foreach ((array) $this->plugin_dir as $dir) { |
|
127 | - $this->dwoo->getLoader()->addDirectory($dir); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
132 | - |
|
133 | - return $this->dwoo; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render the presentation and return the result. |
|
138 | - * |
|
139 | - * @param AgaviTemplateLayer The template layer to render |
|
140 | - * @param array The template variables |
|
141 | - * @param array The slots |
|
142 | - * @param array Associative array of additional assigns |
|
143 | - * |
|
144 | - * @return string A rendered result |
|
145 | - */ |
|
146 | - public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
147 | - { |
|
148 | - $engine = $this->getEngine(); |
|
149 | - |
|
150 | - $data = array(); |
|
151 | - if ($this->extractVars) { |
|
152 | - $data = $attributes; |
|
153 | - } else { |
|
154 | - $data[$this->varName] = &$attributes; |
|
155 | - } |
|
156 | - |
|
157 | - $data[$this->slotsVarName] = &$slots; |
|
158 | - |
|
159 | - foreach ($this->assigns as $key => $getter) { |
|
160 | - $data[$key] = $this->getContext()->$getter(); |
|
161 | - } |
|
162 | - |
|
163 | - foreach ($moreAssigns as $key => &$value) { |
|
164 | - if (isset($this->moreAssignNames[$key])) { |
|
165 | - $key = $this->moreAssignNames[$key]; |
|
166 | - } |
|
167 | - $data[$key] = &$value; |
|
168 | - } |
|
169 | - |
|
170 | - return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
171 | - } |
|
19 | + /** |
|
20 | + * @constant string The directory inside the cache dir where templates will |
|
21 | + * be stored in compiled form. |
|
22 | + */ |
|
23 | + const COMPILE_DIR = 'templates'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @constant string The subdirectory inside the compile dir where templates |
|
27 | + * will be stored in compiled form. |
|
28 | + */ |
|
29 | + const COMPILE_SUBDIR = 'dwoo'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @constant string The directory inside the cache dir where cached content |
|
33 | + * will be stored. |
|
34 | + */ |
|
35 | + const CACHE_DIR = 'dwoo'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var Dwoo Dwoo template engine |
|
39 | + */ |
|
40 | + protected $dwoo = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string A string with the default template file extension, |
|
44 | + * including the dot |
|
45 | + */ |
|
46 | + protected $defaultExtension = '.html'; |
|
47 | + |
|
48 | + /** |
|
49 | + * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
50 | + */ |
|
51 | + protected $plugin_dir = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * Pre-serialization callback. |
|
55 | + * |
|
56 | + * Excludes the Dwoo instance to prevent excessive serialization load. |
|
57 | + */ |
|
58 | + public function __sleep() |
|
59 | + { |
|
60 | + $keys = parent::__sleep(); |
|
61 | + unset($keys[array_search('dwoo', $keys)]); |
|
62 | + |
|
63 | + return $keys; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Initialize this Renderer. |
|
68 | + * |
|
69 | + * @param AgaviContext The current application context |
|
70 | + * @param array An associative array of initialization parameters |
|
71 | + */ |
|
72 | + public function initialize(AgaviContext $context, array $parameters = array()) |
|
73 | + { |
|
74 | + parent::initialize($context, $parameters); |
|
75 | + |
|
76 | + $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * provides a custom compiler to the dwoo renderer with optional settings |
|
81 | + * you can set in the agavi output_types.xml config file. |
|
82 | + * |
|
83 | + * @return Dwoo_Compiler |
|
84 | + */ |
|
85 | + public function compilerFactory() |
|
86 | + { |
|
87 | + $compiler = Dwoo_Compiler::compilerFactory(); |
|
88 | + $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
89 | + |
|
90 | + return $compiler; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Grab a cleaned up dwoo instance. |
|
95 | + * |
|
96 | + * @return Dwoo A Dwoo instance |
|
97 | + */ |
|
98 | + protected function getEngine() |
|
99 | + { |
|
100 | + if ($this->dwoo) { |
|
101 | + return $this->dwoo; |
|
102 | + } |
|
103 | + |
|
104 | + // this triggers Agavi autoload |
|
105 | + if (!class_exists('Dwoo')) { |
|
106 | + if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
107 | + // file was dropped with the entire dwoo package |
|
108 | + include dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
109 | + } else { |
|
110 | + // assume the dwoo package is in the include path |
|
111 | + include 'dwooAutoload.php'; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
116 | + |
|
117 | + $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
118 | + AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
119 | + |
|
120 | + $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
121 | + AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
122 | + |
|
123 | + $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
124 | + |
|
125 | + if (!empty($this->plugin_dir)) { |
|
126 | + foreach ((array) $this->plugin_dir as $dir) { |
|
127 | + $this->dwoo->getLoader()->addDirectory($dir); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
132 | + |
|
133 | + return $this->dwoo; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render the presentation and return the result. |
|
138 | + * |
|
139 | + * @param AgaviTemplateLayer The template layer to render |
|
140 | + * @param array The template variables |
|
141 | + * @param array The slots |
|
142 | + * @param array Associative array of additional assigns |
|
143 | + * |
|
144 | + * @return string A rendered result |
|
145 | + */ |
|
146 | + public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
147 | + { |
|
148 | + $engine = $this->getEngine(); |
|
149 | + |
|
150 | + $data = array(); |
|
151 | + if ($this->extractVars) { |
|
152 | + $data = $attributes; |
|
153 | + } else { |
|
154 | + $data[$this->varName] = &$attributes; |
|
155 | + } |
|
156 | + |
|
157 | + $data[$this->slotsVarName] = &$slots; |
|
158 | + |
|
159 | + foreach ($this->assigns as $key => $getter) { |
|
160 | + $data[$key] = $this->getContext()->$getter(); |
|
161 | + } |
|
162 | + |
|
163 | + foreach ($moreAssigns as $key => &$value) { |
|
164 | + if (isset($this->moreAssignNames[$key])) { |
|
165 | + $key = $this->moreAssignNames[$key]; |
|
166 | + } |
|
167 | + $data[$key] = &$value; |
|
168 | + } |
|
169 | + |
|
170 | + return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
171 | + } |
|
172 | 172 | } |
@@ -16,5 +16,5 @@ |
||
16 | 16 | */ |
17 | 17 | function Dwoo_Plugin_t_compile(Dwoo_Compiler $compiler, $string) |
18 | 18 | { |
19 | - return '$this->data[\'tm\']->_('.$string.')'; |
|
19 | + return '$this->data[\'tm\']->_('.$string.')'; |
|
20 | 20 | } |
@@ -16,24 +16,24 @@ |
||
16 | 16 | */ |
17 | 17 | function Dwoo_Plugin_url_compile(Dwoo_Compiler $compiler, $route = null, $params = null, $options = null, array $rest = array()) |
18 | 18 | { |
19 | - if ($params == 'null') { |
|
20 | - if (count($rest)) { |
|
21 | - $params = array(); |
|
22 | - foreach ($rest as $k => $v) { |
|
23 | - if (is_numeric($k)) { |
|
24 | - $params[] = $k.'=>'.$v; |
|
25 | - } else { |
|
26 | - $params[] = '"'.$k.'"=>'.$v; |
|
27 | - } |
|
28 | - } |
|
29 | - $params = 'array('.implode(', ', $params).')'; |
|
30 | - } else { |
|
31 | - $params = 'array()'; |
|
32 | - } |
|
33 | - } |
|
34 | - if ($options == 'null') { |
|
35 | - $options = 'array()'; |
|
36 | - } |
|
19 | + if ($params == 'null') { |
|
20 | + if (count($rest)) { |
|
21 | + $params = array(); |
|
22 | + foreach ($rest as $k => $v) { |
|
23 | + if (is_numeric($k)) { |
|
24 | + $params[] = $k.'=>'.$v; |
|
25 | + } else { |
|
26 | + $params[] = '"'.$k.'"=>'.$v; |
|
27 | + } |
|
28 | + } |
|
29 | + $params = 'array('.implode(', ', $params).')'; |
|
30 | + } else { |
|
31 | + $params = 'array()'; |
|
32 | + } |
|
33 | + } |
|
34 | + if ($options == 'null') { |
|
35 | + $options = 'array()'; |
|
36 | + } |
|
37 | 37 | |
38 | - return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
38 | + return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
39 | 39 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | |
17 | 17 | class dwoowelcome extends Controller |
18 | 18 | { |
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::Controller(); |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::Controller(); |
|
22 | + } |
|
23 | 23 | |
24 | - public function index() |
|
25 | - { |
|
26 | - $this->load->library('Dwootemplate'); |
|
27 | - $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
28 | - $this->dwootemplate->display('dwoowelcome.tpl'); |
|
29 | - } |
|
24 | + public function index() |
|
25 | + { |
|
26 | + $this->load->library('Dwootemplate'); |
|
27 | + $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
28 | + $this->dwootemplate->display('dwoowelcome.tpl'); |
|
29 | + } |
|
30 | 30 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if (!defined('BASEPATH')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // The name of the directory where templates are located. |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if (!defined('BASEPATH')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | require 'dwoo/dwooAutoload.php'; |
@@ -39,154 +39,154 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class Dwootemplate extends Dwoo_Core |
41 | 41 | { |
42 | - protected $dwoo_data = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * Constructor for the DwooTemplate engine. |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - // Call parents constructor |
|
50 | - parent::__construct(); |
|
51 | - |
|
52 | - // Set the config settings |
|
53 | - $this->initialize(); |
|
54 | - |
|
55 | - // Assign some defaults to dwoo |
|
56 | - $CI = get_instance(); |
|
57 | - $this->dwoo_data = new Dwoo_Data(); |
|
58 | - $this->dwoo_data->js_files = array(); |
|
59 | - $this->dwoo_data->css_files = array(); |
|
60 | - $this->dwoo_data->CI = $CI; |
|
61 | - $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
62 | - $this->dwoo_data->uniqid = uniqid(); |
|
63 | - $this->dwoo_data->timestamp = mktime(); |
|
64 | - |
|
65 | - log_message('debug', 'Dwoo Template Class Initialized'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Assign data to dwoo data object. |
|
70 | - * |
|
71 | - * @param string $key |
|
72 | - * @param mixed $value |
|
73 | - */ |
|
74 | - public function assign($key, $value) |
|
75 | - { |
|
76 | - $this->dwoo_data->$key = $value; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Add Javascript files to template. |
|
81 | - * |
|
82 | - * @param string $js |
|
83 | - */ |
|
84 | - public function add_js($js) |
|
85 | - { |
|
86 | - $current = $this->dwoo_data->js_files; |
|
87 | - $current[] = $js; |
|
88 | - $this->dwoo_data->js_files = $current; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Add Css stylesheets to template. |
|
93 | - * |
|
94 | - * @param string $css |
|
95 | - */ |
|
96 | - public function add_css($css) |
|
97 | - { |
|
98 | - $current = $this->dwoo_data->css_files; |
|
99 | - $current[] = $css; |
|
100 | - $this->dwoo_data->css_files = $current; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Display or return the compiled template |
|
105 | - * Since we assign the results to the standard CI output module |
|
106 | - * you can also use the helper from CI in your templates!! |
|
107 | - * |
|
108 | - * @param string $sTemplate |
|
109 | - * @param bool $return |
|
110 | - * |
|
111 | - * @return mixed |
|
112 | - */ |
|
113 | - public function display($sTemplate, $return = false) |
|
114 | - { |
|
115 | - // Start benchmark |
|
116 | - $CI = get_instance(); |
|
117 | - $CI->benchmark->mark('dwoo_parse_start'); |
|
118 | - |
|
119 | - // Check if file exists |
|
120 | - if (!file_exists($this->template_dir.$sTemplate)) { |
|
121 | - $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
122 | - show_error($message); |
|
123 | - log_message('error', $message); |
|
124 | - } |
|
125 | - |
|
126 | - // Create new template |
|
127 | - $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
128 | - |
|
129 | - // render the template |
|
130 | - $template = $this->get($tpl, $this->dwoo_data); |
|
131 | - |
|
132 | - // Finish benchmark |
|
133 | - $CI->benchmark->mark('dwoo_parse_end'); |
|
134 | - |
|
135 | - // Return results or not ? |
|
136 | - if ($return == false) { |
|
137 | - $CI->output->final_output = $template; |
|
138 | - } else { |
|
139 | - return $template; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Toggle Codeigniter profiler on/off. |
|
145 | - */ |
|
146 | - public function enable_profiler($toggle = true) |
|
147 | - { |
|
148 | - $CI = get_instance(); |
|
149 | - $CI->output->enable_profiler($toggle); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Set http header. |
|
154 | - * |
|
155 | - * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
156 | - * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
157 | - * |
|
158 | - * @param string $header |
|
159 | - */ |
|
160 | - public function set_header($header) |
|
161 | - { |
|
162 | - $CI = get_instance(); |
|
163 | - $CI->output->set_header($header); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Set status header. |
|
168 | - * |
|
169 | - * @example $this->output->set_status_header('401'); |
|
170 | - * @example // Sets the header as: Unauthorized |
|
171 | - * |
|
172 | - * @param string $header |
|
173 | - */ |
|
174 | - public function set_status_header($header) |
|
175 | - { |
|
176 | - $CI = get_instance(); |
|
177 | - $CI->output->set_status_header($header); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Assign the dwootemplate config items to the instance. |
|
182 | - */ |
|
183 | - private function initialize() |
|
184 | - { |
|
185 | - $CI = get_instance(); |
|
186 | - $CI->config->load('dwootemplate', true); |
|
187 | - $config = $CI->config->item('dwootemplate'); |
|
188 | - foreach ($config as $key => $val) { |
|
189 | - $this->$key = $val; |
|
190 | - } |
|
191 | - } |
|
42 | + protected $dwoo_data = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * Constructor for the DwooTemplate engine. |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + // Call parents constructor |
|
50 | + parent::__construct(); |
|
51 | + |
|
52 | + // Set the config settings |
|
53 | + $this->initialize(); |
|
54 | + |
|
55 | + // Assign some defaults to dwoo |
|
56 | + $CI = get_instance(); |
|
57 | + $this->dwoo_data = new Dwoo_Data(); |
|
58 | + $this->dwoo_data->js_files = array(); |
|
59 | + $this->dwoo_data->css_files = array(); |
|
60 | + $this->dwoo_data->CI = $CI; |
|
61 | + $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
62 | + $this->dwoo_data->uniqid = uniqid(); |
|
63 | + $this->dwoo_data->timestamp = mktime(); |
|
64 | + |
|
65 | + log_message('debug', 'Dwoo Template Class Initialized'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Assign data to dwoo data object. |
|
70 | + * |
|
71 | + * @param string $key |
|
72 | + * @param mixed $value |
|
73 | + */ |
|
74 | + public function assign($key, $value) |
|
75 | + { |
|
76 | + $this->dwoo_data->$key = $value; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Add Javascript files to template. |
|
81 | + * |
|
82 | + * @param string $js |
|
83 | + */ |
|
84 | + public function add_js($js) |
|
85 | + { |
|
86 | + $current = $this->dwoo_data->js_files; |
|
87 | + $current[] = $js; |
|
88 | + $this->dwoo_data->js_files = $current; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Add Css stylesheets to template. |
|
93 | + * |
|
94 | + * @param string $css |
|
95 | + */ |
|
96 | + public function add_css($css) |
|
97 | + { |
|
98 | + $current = $this->dwoo_data->css_files; |
|
99 | + $current[] = $css; |
|
100 | + $this->dwoo_data->css_files = $current; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Display or return the compiled template |
|
105 | + * Since we assign the results to the standard CI output module |
|
106 | + * you can also use the helper from CI in your templates!! |
|
107 | + * |
|
108 | + * @param string $sTemplate |
|
109 | + * @param bool $return |
|
110 | + * |
|
111 | + * @return mixed |
|
112 | + */ |
|
113 | + public function display($sTemplate, $return = false) |
|
114 | + { |
|
115 | + // Start benchmark |
|
116 | + $CI = get_instance(); |
|
117 | + $CI->benchmark->mark('dwoo_parse_start'); |
|
118 | + |
|
119 | + // Check if file exists |
|
120 | + if (!file_exists($this->template_dir.$sTemplate)) { |
|
121 | + $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
122 | + show_error($message); |
|
123 | + log_message('error', $message); |
|
124 | + } |
|
125 | + |
|
126 | + // Create new template |
|
127 | + $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
128 | + |
|
129 | + // render the template |
|
130 | + $template = $this->get($tpl, $this->dwoo_data); |
|
131 | + |
|
132 | + // Finish benchmark |
|
133 | + $CI->benchmark->mark('dwoo_parse_end'); |
|
134 | + |
|
135 | + // Return results or not ? |
|
136 | + if ($return == false) { |
|
137 | + $CI->output->final_output = $template; |
|
138 | + } else { |
|
139 | + return $template; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Toggle Codeigniter profiler on/off. |
|
145 | + */ |
|
146 | + public function enable_profiler($toggle = true) |
|
147 | + { |
|
148 | + $CI = get_instance(); |
|
149 | + $CI->output->enable_profiler($toggle); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Set http header. |
|
154 | + * |
|
155 | + * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
156 | + * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
157 | + * |
|
158 | + * @param string $header |
|
159 | + */ |
|
160 | + public function set_header($header) |
|
161 | + { |
|
162 | + $CI = get_instance(); |
|
163 | + $CI->output->set_header($header); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Set status header. |
|
168 | + * |
|
169 | + * @example $this->output->set_status_header('401'); |
|
170 | + * @example // Sets the header as: Unauthorized |
|
171 | + * |
|
172 | + * @param string $header |
|
173 | + */ |
|
174 | + public function set_status_header($header) |
|
175 | + { |
|
176 | + $CI = get_instance(); |
|
177 | + $CI->output->set_status_header($header); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Assign the dwootemplate config items to the instance. |
|
182 | + */ |
|
183 | + private function initialize() |
|
184 | + { |
|
185 | + $CI = get_instance(); |
|
186 | + $CI->config->load('dwootemplate', true); |
|
187 | + $config = $CI->config->item('dwootemplate'); |
|
188 | + foreach ($config as $key => $val) { |
|
189 | + $this->$key = $val; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | */ |
17 | 17 | class Dwoo_Adapters_ZendFramework_Dwoo extends Dwoo_Core |
18 | 18 | { |
19 | - /** |
|
20 | - * Redirects all unknown properties to plugin proxy |
|
21 | - * to support $this->viewVariable from within templates. |
|
22 | - * |
|
23 | - * @param string $name Property name |
|
24 | - * |
|
25 | - * @return mixed |
|
26 | - */ |
|
27 | - public function __get($name) |
|
28 | - { |
|
29 | - if (isset($this->getPluginProxy()->view->$name)) { |
|
30 | - return $this->getPluginProxy()->view->$name; |
|
31 | - } |
|
32 | - $trace = debug_backtrace(); |
|
33 | - trigger_error( |
|
34 | - 'Undefined property via __get(): '.$name. |
|
35 | - ' in '.$trace[0]['file']. |
|
36 | - ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
37 | - ); |
|
19 | + /** |
|
20 | + * Redirects all unknown properties to plugin proxy |
|
21 | + * to support $this->viewVariable from within templates. |
|
22 | + * |
|
23 | + * @param string $name Property name |
|
24 | + * |
|
25 | + * @return mixed |
|
26 | + */ |
|
27 | + public function __get($name) |
|
28 | + { |
|
29 | + if (isset($this->getPluginProxy()->view->$name)) { |
|
30 | + return $this->getPluginProxy()->view->$name; |
|
31 | + } |
|
32 | + $trace = debug_backtrace(); |
|
33 | + trigger_error( |
|
34 | + 'Undefined property via __get(): '.$name. |
|
35 | + ' in '.$trace[0]['file']. |
|
36 | + ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
37 | + ); |
|
38 | 38 | |
39 | - return null; |
|
40 | - } |
|
39 | + return null; |
|
40 | + } |
|
41 | 41 | } |
@@ -23,30 +23,30 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class Processor |
25 | 25 | { |
26 | - /** |
|
27 | - * The compiler instance that runs this processor. |
|
28 | - * |
|
29 | - * @var Core |
|
30 | - */ |
|
31 | - protected $compiler; |
|
26 | + /** |
|
27 | + * The compiler instance that runs this processor. |
|
28 | + * |
|
29 | + * @var Core |
|
30 | + */ |
|
31 | + protected $compiler; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
35 | - * the dwoo instance yourself if you need it. |
|
36 | - * |
|
37 | - * @param Compiler $compiler the compiler class |
|
38 | - */ |
|
39 | - public function __construct(Compiler $compiler) |
|
40 | - { |
|
41 | - $this->compiler = $compiler; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
35 | + * the dwoo instance yourself if you need it. |
|
36 | + * |
|
37 | + * @param Compiler $compiler the compiler class |
|
38 | + */ |
|
39 | + public function __construct(Compiler $compiler) |
|
40 | + { |
|
41 | + $this->compiler = $compiler; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Processes the input and returns it filtered. |
|
46 | - * |
|
47 | - * @param string $input the template to process |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function process($input); |
|
44 | + /** |
|
45 | + * Processes the input and returns it filtered. |
|
46 | + * |
|
47 | + * @param string $input the template to process |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function process($input); |
|
52 | 52 | } |
@@ -29,31 +29,31 @@ |
||
29 | 29 | */ |
30 | 30 | interface ICompiler |
31 | 31 | { |
32 | - /** |
|
33 | - * Compiles the provided string down to php code. |
|
34 | - * |
|
35 | - * @param Core $dwoo |
|
36 | - * @param ITemplate $template the template to compile |
|
37 | - * |
|
38 | - * @return string a compiled php code string |
|
39 | - */ |
|
40 | - public function compile(Core $dwoo, ITemplate $template); |
|
32 | + /** |
|
33 | + * Compiles the provided string down to php code. |
|
34 | + * |
|
35 | + * @param Core $dwoo |
|
36 | + * @param ITemplate $template the template to compile |
|
37 | + * |
|
38 | + * @return string a compiled php code string |
|
39 | + */ |
|
40 | + public function compile(Core $dwoo, ITemplate $template); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
44 | - * |
|
45 | - * @see Core::addPlugin |
|
46 | - * |
|
47 | - * @param array $customPlugins an array of custom plugins |
|
48 | - */ |
|
49 | - public function setCustomPlugins(array $customPlugins); |
|
42 | + /** |
|
43 | + * Adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
44 | + * |
|
45 | + * @see Core::addPlugin |
|
46 | + * |
|
47 | + * @param array $customPlugins an array of custom plugins |
|
48 | + */ |
|
49 | + public function setCustomPlugins(array $customPlugins); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Sets the security policy object to enforce some php security settings. |
|
53 | - * use this if untrusted persons can modify templates, |
|
54 | - * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
55 | - * |
|
56 | - * @param SecurityPolicy $policy the security policy object |
|
57 | - */ |
|
58 | - public function setSecurityPolicy(SecurityPolicy $policy = null); |
|
51 | + /** |
|
52 | + * Sets the security policy object to enforce some php security settings. |
|
53 | + * use this if untrusted persons can modify templates, |
|
54 | + * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
55 | + * |
|
56 | + * @param SecurityPolicy $policy the security policy object |
|
57 | + */ |
|
58 | + public function setSecurityPolicy(SecurityPolicy $policy = null); |
|
59 | 59 | } |