fixes relative to templates_c move
[platal.git] / include / platal / page.inc.php
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
22 require_once('diogenes/diogenes.core.page.inc.php');
23 require_once('platal/errors.inc.php');
24 require_once('platal/smarty.plugins.inc.php');
25
26 // {{{ class PlatalPage
27
28 class PlatalPage extends DiogenesCorePage
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
48 $this->DiogenesCorePage();
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 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
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 // }}}
74 // {{{ function changeTpl()
75
76 function changeTpl($tpl, $type=SKINNED)
77 {
78 $this->_tpl = $tpl;
79 $this->_page_type = $type;
80 if ($type == SKINNED) {
81 $this->register_modifier('escape_html', 'escape_html');
82 $this->default_modifiers = Array('@escape_html');
83 }
84
85 $this->_page_type = $type;
86 $this->assign('xorg_tpl', $tpl);
87 }
88
89 // }}}
90 // {{{ function _run()
91
92 function _run($skin)
93 {
94 global $globals, $TIME_BEGIN;
95 $this->assign("xorg_error", $this->_errors);
96
97 if ($this->_page_type == NO_SKIN) {
98 $this->display($this->_tpl);
99 exit;
100 }
101
102 if ($globals->debug) {
103
104 if ($globals->debug & 1) {
105 $this->assign('db_trace', $globals->db->trace_format($this, 'database-debug.tpl'));
106 }
107
108 $this->assign('validate', urlencode($globals->baseurl.'/valid.html'));
109 $result = $this->fetch($skin);
110 $ttime = sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
111 $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
112
113 if ($globals->debug & 2) {
114
115 $fd = fopen($this->compile_dir."/valid.html","w");
116 fwrite($fd, $result);
117 fclose($fd);
118
119 exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val);
120 foreach ($val as $h) {
121 if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) {
122 $replc = '<span style="color: #080;">HTML OK</span><br />';
123 if ($m[1]) {
124 $replc = "<span class='erreur'><a href='http://validator.w3.org/check?uri={$globals->baseurl}"
125 ."/valid.html&amp;ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />";
126 }
127 break;
128 }
129 }
130 }
131
132 echo str_replace("@HOOK@", $ttime.$replc, $result);
133 exit;
134 }
135
136 $this->display($skin);
137 exit;
138 }
139
140 // }}}
141 // {{{ function run()
142
143 function run()
144 {
145 die ("implement me");
146 }
147
148 // }}}
149 // {{{ function nb_errs()
150
151 function nb_errs()
152 {
153 return count($this->_errors->errs);
154 }
155
156 // }}}
157 // {{{ function trig()
158
159 function trig($msg)
160 {
161 $this->_errors->trig($msg);
162 }
163
164 // }}}
165 // {{{ function trig()
166
167 function trig_run($msg)
168 {
169 $this->_errors->trig($msg);
170 $this->run();
171 }
172
173 // }}}
174 // {{{ function fail()
175
176 function fail($msg)
177 {
178 $this->_errors->fail($msg);
179 }
180
181 // }}}
182 // {{{ function kill()
183
184 function kill($msg)
185 {
186 $this->fail($msg);
187 $this->run();
188 }
189
190 // }}}
191 // {{{ function doAuth()
192
193 function doAuth() { }
194
195 // }}}
196 // {{{ function loadModule()
197
198 function loadModule($modname)
199 {
200 require_once("$modname.inc.php");
201 }
202
203 // }}}
204 // {{{ function addJsLink
205
206 function addJsLink($path)
207 {
208 $this->append('xorg_js', $path);
209 }
210
211 // }}}
212 // {{{ function addCssLink
213
214 function addCssLink($path)
215 {
216 $this->append('xorg_css', $path);
217 }
218
219 // }}}
220 // {{{ function gassign
221
222 function gassign($varname)
223 {
224 global $$varname;
225 $this->assign($varname, $$varname);
226 }
227
228 // }}}
229 }
230
231 // }}}
232
233 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
234 ?>