reduce dependency on Diogenes
[platal.git] / include / platal / page.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2004 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
f12af8ad 22require_once 'smarty/libs/Smarty.class.php';
23require_once 'platal/errors.inc.php';
24require_once 'platal/smarty.plugins.inc.php';
0337d704 25
26// {{{ class PlatalPage
27
f12af8ad 28class PlatalPage extends Smarty
0337d704 29{
30 // {{{ properties
31
32 var $_page_type;
33 var $_tpl;
34 var $_errors;
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
f12af8ad 48 $this->Smarty();
796aea34 49
0337d704 50 $this->template_dir = $globals->spoolroot."/templates/";
7faf6e6a 51 $this->compile_dir = $globals->spoolroot."/spool/templates_c/";
0337d704 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 if ($type == SKINNED) {
58 $this->register_modifier('escape_html', 'escape_html');
59 $this->default_modifiers[] = '@escape_html';
60 }
61
62 $this->_page_type = $type;
63 $this->_tpl = $tpl;
64 $this->_errors = new XOrgErrors;
65
0337d704 66 $this->register_prefilter('at_to_globals');
67 $this->register_prefilter('trimwhitespace');
68 $this->addJsLink('javascript/xorg.js');
69
70 $this->doAuth();
71 }
72
73 // }}}
f12af8ad 74 // {{{
75
76 function fakeDiogenes()
77 {
78 require_once 'diogenes/diogenes.core.page.inc.php';
79 $this->register_function("extval","diogenes_func_extval");
80 $this->register_function("flags","diogenes_func_flags");
81 $this->register_function("a","diogenes_func_a");
82 $this->register_function("checkbox","diogenes_func_checkbox");
83 $this->register_function("diff","diogenes_func_diff");
84 $this->register_function("menu_item","diogenes_func_menu_item");
85 $this->register_function("tag","diogenes_func_tag");
86 $this->register_function("toolbar","diogenes_func_toolbar");
87 }
88
89 // }}}
0337d704 90 // {{{ function changeTpl()
91
92 function changeTpl($tpl, $type=SKINNED)
93 {
94 $this->_tpl = $tpl;
95 $this->_page_type = $type;
96 if ($type == SKINNED) {
97 $this->register_modifier('escape_html', 'escape_html');
98 $this->default_modifiers = Array('@escape_html');
99 }
100
101 $this->_page_type = $type;
102 $this->assign('xorg_tpl', $tpl);
103 }
104
105 // }}}
106 // {{{ function _run()
107
108 function _run($skin)
109 {
110 global $globals, $TIME_BEGIN;
111 $this->assign("xorg_error", $this->_errors);
112
113 if ($this->_page_type == NO_SKIN) {
114 $this->display($this->_tpl);
115 exit;
116 }
117
118 if ($globals->debug) {
119
120 if ($globals->debug & 1) {
121 $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl'));
122 }
123
124 $this->assign('validate', urlencode($globals->baseurl.'/valid.html'));
125 $result = $this->fetch($skin);
126 $ttime = sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
127 $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
128
129 if ($globals->debug & 2) {
130
131 $fd = fopen($this->compile_dir."/valid.html","w");
132 fwrite($fd, $result);
133 fclose($fd);
134
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&amp;ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />";
142 }
143 break;
144 }
145 }
146 }
147
148 echo str_replace("@HOOK@", $ttime.$replc, $result);
149 exit;
150 }
151
152 $this->display($skin);
153 exit;
154 }
155
156 // }}}
157 // {{{ function run()
158
159 function run()
160 {
161 die ("implement me");
162 }
163
164 // }}}
165 // {{{ function nb_errs()
166
167 function nb_errs()
168 {
169 return count($this->_errors->errs);
170 }
171
172 // }}}
173 // {{{ function trig()
174
175 function trig($msg)
176 {
177 $this->_errors->trig($msg);
178 }
179
180 // }}}
181 // {{{ function trig()
182
183 function trig_run($msg)
184 {
185 $this->_errors->trig($msg);
186 $this->run();
187 }
188
189 // }}}
190 // {{{ function fail()
191
192 function fail($msg)
193 {
194 $this->_errors->fail($msg);
195 }
196
197 // }}}
198 // {{{ function kill()
199
200 function kill($msg)
201 {
202 $this->fail($msg);
203 $this->run();
204 }
205
206 // }}}
207 // {{{ function doAuth()
208
209 function doAuth() { }
210
211 // }}}
212 // {{{ function loadModule()
213
214 function loadModule($modname)
215 {
216 require_once("$modname.inc.php");
217 }
218
219 // }}}
220 // {{{ function addJsLink
221
222 function addJsLink($path)
223 {
224 $this->append('xorg_js', $path);
225 }
226
227 // }}}
228 // {{{ function addCssLink
229
230 function addCssLink($path)
231 {
232 $this->append('xorg_css', $path);
233 }
234
235 // }}}
236 // {{{ function gassign
237
238 function gassign($varname)
239 {
240 global $$varname;
241 $this->assign($varname, $$varname);
242 }
243
244 // }}}
245}
246
247// }}}
248
249// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
250?>