ccc94d83baf04496c419d2ec987d05c35ef755f9
[platal.git] / include / platal / page.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
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
22 require_once 'smarty/libs/Smarty.class.php';
23 require_once 'platal/smarty.plugins.inc.php';
24
25 // {{{ class PlatalPage
26
27 class PlatalPage extends Smarty
28 {
29 // {{{ properties
30
31 var $_page_type;
32 var $_tpl;
33 var $_errors;
34 var $_failure;
35
36 // defaults
37 var $caching = false;
38 var $config_overwrite = false;
39 var $use_sub_dirs = false;
40
41 // }}}
42 // {{{ function PlatalPage()
43
44 function PlatalPage($tpl, $type=SKINNED)
45 {
46 global $globals;
47
48 $this->Smarty();
49
50 $this->template_dir = $globals->spoolroot."/templates/";
51 $this->compile_dir = $globals->spoolroot."/spool/templates_c/";
52 array_unshift($this->plugins_dir, $globals->spoolroot."/plugins/");
53 $this->config_dir = $globals->spoolroot."/configs/";
54
55 $this->compile_check = !empty($globals->debug);
56
57 $this->_page_type = $type;
58 $this->_tpl = $tpl;
59 $this->_errors = array();
60 $this->_failure = false;
61
62 $this->register_prefilter('at_to_globals');
63 $this->register_prefilter('trimwhitespace');
64 $this->addJsLink('javascript/xorg.js');
65
66 $this->doAuth();
67 }
68
69 // }}}
70 // {{{ function fakeDiogenes()
71
72 function fakeDiogenes()
73 {
74 require_once 'diogenes/diogenes.core.page.inc.php';
75 $this->register_function("extval","diogenes_func_extval");
76 $this->register_function("flags","diogenes_func_flags");
77 $this->register_function("a","diogenes_func_a");
78 $this->register_function("checkbox","diogenes_func_checkbox");
79 $this->register_function("diff","diogenes_func_diff");
80 $this->register_function("menu_item","diogenes_func_menu_item");
81 $this->register_function("tag","diogenes_func_tag");
82 $this->register_function("toolbar","diogenes_func_toolbar");
83 }
84
85 // }}}
86 // {{{ function changeTpl()
87
88 function changeTpl($tpl, $type=SKINNED)
89 {
90 $this->_tpl = $tpl;
91 $this->_page_type = $type;
92 $this->_page_type = $type;
93 $this->assign('xorg_tpl', $tpl);
94 }
95
96 // }}}
97 // {{{ function _run()
98
99 function _run($skin)
100 {
101 global $globals, $TIME_BEGIN;
102
103 session_write_close();
104
105 $this->assign("xorg_errors", $this->_errors);
106 $this->assign("xorg_failure", $this->_failure);
107
108 if ($this->_page_type == NO_SKIN) {
109 $this->display($this->_tpl);
110 exit;
111 } else {
112 $this->register_modifier('escape_html', 'escape_html');
113 $this->default_modifiers = Array('@escape_html');
114 }
115
116 if (!$globals->debug) {
117 $this->display($skin);
118 exit;
119 }
120
121 if ($globals->debug & 1) {
122 $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl'));
123 }
124
125 $this->assign('validate', true);
126 $result = $this->fetch($skin);
127 $ttime .= sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
128 $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
129
130 if ($globals->debug & 2) {
131
132 $fd = fopen($this->compile_dir."/valid.html","w");
133 fwrite($fd, $result);
134 fclose($fd);
135
136 exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val);
137 foreach ($val as $h) {
138 if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) {
139 $replc = '<span style="color: #080;">HTML OK</span><br />';
140 if ($m[1]) {
141 $replc = "<span class='erreur'><a href='http://validator.w3.org/check?uri={$globals->baseurl}"
142 ."/valid.html&amp;ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />";
143 }
144 break;
145 }
146 }
147 }
148
149 echo str_replace("@HOOK@", $ttime.$replc, $result);
150 exit;
151 }
152
153 // }}}
154 // {{{ function run()
155
156 function run()
157 {
158 die ("implement me");
159 }
160
161 // }}}
162 // {{{ function nb_errs()
163
164 function nb_errs()
165 {
166 return count($this->_errors);
167 }
168
169 // }}}
170 // {{{ function trig()
171
172 function trig($msg)
173 {
174 $this->_errors[] = $msg;
175 }
176
177 // }}}
178 // {{{ function trig()
179
180 function trig_run($msg)
181 {
182 $this->trig($msg);
183 $this->run();
184 }
185
186 // }}}
187 // {{{ function fail()
188
189 function fail($msg)
190 {
191 $this->trig($msg);
192 $this->_failure = true;
193 }
194
195 // }}}
196 // {{{ function kill()
197
198 function kill($msg)
199 {
200 $this->fail($msg);
201 $this->run();
202 }
203
204 // }}}
205 // {{{ function doAuth()
206
207 function doAuth() { }
208
209 // }}}
210 // {{{ function loadModule()
211
212 function loadModule($modname)
213 {
214 require_once("$modname.inc.php");
215 }
216
217 // }}}
218 // {{{ function addJsLink
219
220 function addJsLink($path)
221 {
222 $this->append('xorg_js', $path);
223 }
224
225 // }}}
226 // {{{ function addCssLink
227
228 function addCssLink($path)
229 {
230 $this->append('xorg_css', $path);
231 }
232
233 // }}}
234 // {{{ function gassign
235
236 function gassign($varname)
237 {
238 global $$varname;
239 $this->assign($varname, $$varname);
240 }
241
242 // }}}
243 }
244
245 // }}}
246
247 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
248 ?>