0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
0337d704 |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
f12af8ad |
22 | require_once 'smarty/libs/Smarty.class.php'; |
0337d704 |
23 | |
f12af8ad |
24 | class PlatalPage extends Smarty |
0337d704 |
25 | { |
26 | // {{{ properties |
a3a049fc |
27 | |
0337d704 |
28 | var $_page_type; |
29 | var $_tpl; |
30 | var $_errors; |
860fdaec |
31 | var $_failure; |
0337d704 |
32 | |
33 | // defaults |
34 | var $caching = false; |
35 | var $config_overwrite = false; |
36 | var $use_sub_dirs = false; |
37 | |
38 | // }}} |
39 | // {{{ function PlatalPage() |
40 | |
62a66dfc |
41 | function PlatalPage($tpl, $type = SKINNED) |
0337d704 |
42 | { |
43 | global $globals; |
44 | |
f12af8ad |
45 | $this->Smarty(); |
796aea34 |
46 | |
0337d704 |
47 | $this->template_dir = $globals->spoolroot."/templates/"; |
7faf6e6a |
48 | $this->compile_dir = $globals->spoolroot."/spool/templates_c/"; |
0337d704 |
49 | array_unshift($this->plugins_dir, $globals->spoolroot."/plugins/"); |
50 | $this->config_dir = $globals->spoolroot."/configs/"; |
51 | |
52 | $this->compile_check = !empty($globals->debug); |
53 | |
0337d704 |
54 | $this->_page_type = $type; |
55 | $this->_tpl = $tpl; |
860fdaec |
56 | $this->_errors = array(); |
57 | $this->_failure = false; |
0337d704 |
58 | |
0337d704 |
59 | $this->register_prefilter('at_to_globals'); |
60 | $this->register_prefilter('trimwhitespace'); |
61 | $this->addJsLink('javascript/xorg.js'); |
0337d704 |
62 | } |
63 | |
64 | // }}} |
b4315e15 |
65 | // {{{ function fakeDiogenes() |
a3a049fc |
66 | |
f12af8ad |
67 | function fakeDiogenes() |
68 | { |
69 | require_once 'diogenes/diogenes.core.page.inc.php'; |
70 | $this->register_function("extval","diogenes_func_extval"); |
71 | $this->register_function("flags","diogenes_func_flags"); |
72 | $this->register_function("a","diogenes_func_a"); |
73 | $this->register_function("checkbox","diogenes_func_checkbox"); |
74 | $this->register_function("diff","diogenes_func_diff"); |
75 | $this->register_function("menu_item","diogenes_func_menu_item"); |
76 | $this->register_function("tag","diogenes_func_tag"); |
77 | $this->register_function("toolbar","diogenes_func_toolbar"); |
78 | } |
a3a049fc |
79 | |
f12af8ad |
80 | // }}} |
0337d704 |
81 | // {{{ function changeTpl() |
82 | |
62a66dfc |
83 | function changeTpl($tpl, $type = SKINNED) |
0337d704 |
84 | { |
85 | $this->_tpl = $tpl; |
86 | $this->_page_type = $type; |
0337d704 |
87 | $this->_page_type = $type; |
88 | $this->assign('xorg_tpl', $tpl); |
89 | } |
90 | |
91 | // }}} |
92 | // {{{ function _run() |
93 | |
94 | function _run($skin) |
95 | { |
96 | global $globals, $TIME_BEGIN; |
36f114ef |
97 | |
98 | session_write_close(); |
99 | |
860fdaec |
100 | $this->assign("xorg_errors", $this->_errors); |
101 | $this->assign("xorg_failure", $this->_failure); |
a3a049fc |
102 | |
62a66dfc |
103 | switch ($this->_page_type) { |
104 | case NO_SKIN: |
0337d704 |
105 | $this->display($this->_tpl); |
106 | exit; |
62a66dfc |
107 | |
108 | case SIMPLE: |
c6db254a |
109 | $this->assign('simple', true); |
62a66dfc |
110 | case SKINNED: |
801fcad8 |
111 | $this->register_modifier('escape_html', 'escape_html'); |
112 | $this->default_modifiers = Array('@escape_html'); |
0337d704 |
113 | } |
b4315e15 |
114 | |
115 | if (!$globals->debug) { |
116 | $this->display($skin); |
117 | exit; |
118 | } |
a3a049fc |
119 | |
b4315e15 |
120 | if ($globals->debug & 1) { |
121 | $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl')); |
122 | } |
0337d704 |
123 | |
7da8ef90 |
124 | $this->assign('validate', true); |
b4315e15 |
125 | $result = $this->fetch($skin); |
36f114ef |
126 | $ttime .= sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN); |
b4315e15 |
127 | $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />"; |
0337d704 |
128 | |
b4315e15 |
129 | if ($globals->debug & 2) { |
130 | |
131 | $fd = fopen($this->compile_dir."/valid.html","w"); |
132 | fwrite($fd, $result); |
133 | fclose($fd); |
a3a049fc |
134 | |
b4315e15 |
135 | exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val); |
136 | foreach ($val as $h) { |
137 | if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { |
138 | $replc = '<span style="color: #080;">HTML OK</span><br />'; |
139 | if ($m[1]) { |
140 | $replc = "<span class='erreur'><a href='http://validator.w3.org/check?uri={$globals->baseurl}" |
141 | ."/valid.html&ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />"; |
0337d704 |
142 | } |
b4315e15 |
143 | break; |
0337d704 |
144 | } |
145 | } |
0337d704 |
146 | } |
147 | |
b4315e15 |
148 | echo str_replace("@HOOK@", $ttime.$replc, $result); |
0337d704 |
149 | exit; |
150 | } |
151 | |
152 | // }}} |
153 | // {{{ function run() |
154 | |
155 | function run() |
156 | { |
157 | die ("implement me"); |
158 | } |
159 | |
160 | // }}} |
161 | // {{{ function nb_errs() |
162 | |
163 | function nb_errs() |
164 | { |
860fdaec |
165 | return count($this->_errors); |
0337d704 |
166 | } |
167 | |
168 | // }}} |
169 | // {{{ function trig() |
170 | |
171 | function trig($msg) |
172 | { |
860fdaec |
173 | $this->_errors[] = $msg; |
0337d704 |
174 | } |
175 | |
176 | // }}} |
0337d704 |
177 | // {{{ function kill() |
178 | |
179 | function kill($msg) |
180 | { |
0fcbe8d0 |
181 | $this->trig($msg); |
182 | $this->_failure = true; |
0337d704 |
183 | $this->run(); |
184 | } |
185 | |
186 | // }}} |
0337d704 |
187 | // {{{ function loadModule() |
a3a049fc |
188 | |
0337d704 |
189 | function loadModule($modname) |
190 | { |
191 | require_once("$modname.inc.php"); |
192 | } |
193 | |
194 | // }}} |
195 | // {{{ function addJsLink |
196 | |
197 | function addJsLink($path) |
198 | { |
199 | $this->append('xorg_js', $path); |
200 | } |
201 | |
202 | // }}} |
203 | // {{{ function addCssLink |
204 | |
205 | function addCssLink($path) |
206 | { |
207 | $this->append('xorg_css', $path); |
208 | } |
209 | |
210 | // }}} |
0337d704 |
211 | } |
212 | |
b76f0797 |
213 | // {{{ function escape_html () |
214 | |
215 | /** |
216 | * default smarty plugin, used to auto-escape dangerous html. |
217 | * |
218 | * < --> < |
219 | * > --> > |
220 | * " --> " |
221 | * & not followed by some entity --> & |
222 | */ |
223 | function escape_html($string) |
224 | { |
225 | if (is_string($string)) { |
226 | $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); |
227 | return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); |
228 | } else { |
229 | return $string; |
230 | } |
231 | } |
232 | |
233 | // }}} |
234 | // {{{ function at_to_globals() |
235 | |
236 | /** |
237 | * helper |
238 | */ |
239 | |
240 | function _to_globals($s) { |
241 | global $globals; |
242 | $t = explode('.',$s); |
243 | if (count($t) == 1) { |
244 | return var_export($globals->$t[0],true); |
245 | } else { |
246 | return var_export($globals->$t[0]->$t[1],true); |
247 | } |
248 | } |
249 | |
250 | /** |
251 | * compilation plugin used to import $globals confing through #globals.foo.bar# directives |
252 | */ |
253 | |
254 | function at_to_globals($tpl_source, &$smarty) |
255 | { |
256 | return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source); |
257 | } |
258 | |
259 | // }}} |
260 | // {{{ function trimwhitespace |
261 | |
262 | function trimwhitespace($source, &$smarty) |
263 | { |
264 | $tags = array('script', 'pre', 'textarea'); |
265 | |
266 | foreach ($tags as $tag) { |
267 | preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag}); |
268 | $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source); |
269 | } |
270 | |
271 | // remove all leading spaces, tabs and carriage returns NOT |
272 | // preceeded by a php close tag. |
273 | $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source); |
274 | |
275 | foreach ($tags as $tag) { |
276 | $source = preg_replace("!&&&{$tag}&&&!e", 'array_shift(${$tag}[0])', $source); |
277 | } |
278 | |
279 | return $source; |
280 | } |
281 | |
282 | // }}} |
283 | |
0337d704 |
284 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
285 | ?> |