1 | <?php |
---|
2 | |
---|
3 | App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php')); |
---|
4 | |
---|
5 | /** |
---|
6 | * Dwoo adapter for CakePHP |
---|
7 | * |
---|
8 | * Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com> |
---|
9 | * |
---|
10 | * This software is provided 'as-is', without any express or implied warranty. |
---|
11 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
12 | * |
---|
13 | * This file is released under the LGPL |
---|
14 | * "GNU Lesser General Public License" |
---|
15 | * More information can be found here: |
---|
16 | * {@link http://www.gnu.org/copyleft/lesser.html} |
---|
17 | * |
---|
18 | * @author Mark John S. Buenconsejo <mjwork@simpleteq.com> |
---|
19 | * @author Giangi <giangi@qwerg.com> |
---|
20 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
21 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
22 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
---|
23 | * @link http://dwoo.org/ |
---|
24 | * @version 1.1.0 |
---|
25 | * @date 2009-07-18 |
---|
26 | * @package Dwoo |
---|
27 | */ |
---|
28 | class DwooView extends View |
---|
29 | { |
---|
30 | protected $_sv_template_dir; |
---|
31 | protected $_sv_layout_dir; |
---|
32 | protected $_sv_compile_dir; |
---|
33 | protected $_sv_cache_dir; |
---|
34 | protected $_sv_compile_id; |
---|
35 | |
---|
36 | protected $_dwoo; |
---|
37 | |
---|
38 | public $sv_processedTpl; |
---|
39 | |
---|
40 | public function __construct(&$controller) |
---|
41 | { |
---|
42 | parent::__construct($controller); |
---|
43 | |
---|
44 | $this->ext = '.tpl'; |
---|
45 | |
---|
46 | $this->_sv_template_dir = array |
---|
47 | ( |
---|
48 | VIEWS . $this->viewPath . DS . $this->subDir, |
---|
49 | VIEWS . $this->viewPath, |
---|
50 | VIEWS |
---|
51 | ); |
---|
52 | |
---|
53 | $this->_sv_layout_dir = array |
---|
54 | ( |
---|
55 | LAYOUTS . $this->subDir, |
---|
56 | VIEWS |
---|
57 | ); |
---|
58 | |
---|
59 | $this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile'; |
---|
60 | $this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache'; |
---|
61 | |
---|
62 | $this->_dwoo = new Dwoo_Core($this->_sv_compile_dir, $this->_sv_cache_dir); |
---|
63 | |
---|
64 | $this->_sv_compile_id = $controller->name; |
---|
65 | |
---|
66 | $this->_dwoo->sv_this = $this; |
---|
67 | $this->_dwoo->setSecurityPolicy(); |
---|
68 | |
---|
69 | return; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * changes the template directory |
---|
74 | */ |
---|
75 | public function setTemplateDir($path = VIEW) { |
---|
76 | $old = $this->_sv_template_dir; |
---|
77 | $this->_sv_template_dir = $path; |
---|
78 | |
---|
79 | return $old; |
---|
80 | } |
---|
81 | |
---|
82 | public function getTemplateDir() { |
---|
83 | return $this->_sv_template_dir ; |
---|
84 | } |
---|
85 | |
---|
86 | public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true) |
---|
87 | { |
---|
88 | // let's determine if this is a layout call or a template call |
---|
89 | // and change the template dir accordingly |
---|
90 | $layout = false; |
---|
91 | if(isset($___data_for_view['content_for_layout'])) { |
---|
92 | $this->_sv_template_dir = $this->_sv_layout_dir; |
---|
93 | $layout = true; |
---|
94 | } |
---|
95 | |
---|
96 | $tpl = new Dwoo_Template_File($___viewFn); |
---|
97 | $data = $___data_for_view; |
---|
98 | |
---|
99 | $data['view'] = $this; |
---|
100 | |
---|
101 | if ($this->helpers != false && $loadHelpers === true) { |
---|
102 | $loadedHelpers = array(); |
---|
103 | $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); |
---|
104 | |
---|
105 | foreach (array_keys($loadedHelpers) as $helper) { |
---|
106 | $camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1); |
---|
107 | |
---|
108 | ${$camelBackedHelper} = $loadedHelpers[$helper]; |
---|
109 | |
---|
110 | if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) { |
---|
111 | $subHelpers = ${$camelBackedHelper}->helpers; |
---|
112 | foreach ($subHelpers as $subHelper) { |
---|
113 | ${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper]; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | if(isset($this->passedArgs)) { |
---|
118 | ${$camelBackedHelper}->passedArgs = $this->passedArgs; |
---|
119 | } |
---|
120 | |
---|
121 | $this->loaded[$camelBackedHelper] = ${$camelBackedHelper}; |
---|
122 | |
---|
123 | $data[$camelBackedHelper] = ${$camelBackedHelper}; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | if ($this->helpers != false && $loadHelpers === true) { |
---|
128 | foreach ($loadedHelpers as $helper) { |
---|
129 | if (is_object($helper)) { |
---|
130 | if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) { |
---|
131 | $helper->beforeRender(); |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | return $this->_dwoo->get($tpl, $data); |
---|
138 | } |
---|
139 | |
---|
140 | public function get(){ |
---|
141 | return $this->_dwoo; |
---|
142 | } |
---|
143 | } |
---|