2df81c6adb01f3f4dbcf8c1ccfffcc4c675bdefb
[lhc/web/wiklou.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 //
4 // Copyright (c) 2003 Laurent Bedubourg
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
21 //
22
23 /*
24 * This file:
25 *
26 * - Include PHPTAL dependencies
27 * - Define PHPTAL attributes
28 * - Define PHPTAL aliases
29 * - Define PHPTAL rules
30 *
31 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
32 */
33
34 $__d = dirname(__FILE__);
35 require_once "PEAR.php";
36
37 if (OS_WINDOWS) {
38 define('PHPTAL_PATH_SEP', '\\');
39 } else {
40 define('PHPTAL_PATH_SEP', '/');
41 }
42
43 function _phptal_os_path_join()
44 {
45 $args = func_get_args();
46 return join(PHPTAL_PATH_SEP, $args);
47 }
48
49 require_once 'Types/Errors.php';
50 require_once 'Types/OString.php';
51
52 require_once _phptal_os_path_join($__d, 'PHPTAL', 'Cache.php');
53 require_once _phptal_os_path_join($__d, 'PHPTAL', 'Context.php');
54 require_once _phptal_os_path_join($__d, 'PHPTAL', 'Filter.php');
55 require_once _phptal_os_path_join($__d, 'PHPTAL', 'LoopControler.php');
56 require_once _phptal_os_path_join($__d, 'PHPTAL', 'OutputControl.php');
57 require_once _phptal_os_path_join($__d, 'PHPTAL', 'Template.php');
58 require_once _phptal_os_path_join($__d, 'PHPTAL', 'Macro.php');
59 require_once _phptal_os_path_join($__d, 'PHPTAL', 'I18N.php');
60
61 require_once _phptal_os_path_join($__d, 'PHPTAL', 'SourceResolver.php');
62 require_once _phptal_os_path_join($__d, 'PHPTAL', 'SourceLocator.php');
63
64
65 define('PHPTAL_VERSION', '0.7.0');
66 define('PHPTAL_MARK', str_replace('.', '_', PHPTAL_VERSION) . '_');
67
68 if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") {
69 define('PHPTAL_DEFAULT_CACHE_DIR', 'c:\temp\\');
70 } else {
71 define('PHPTAL_DEFAULT_CACHE_DIR', '/tmp/');
72 }
73
74 /**
75 * This define is used to select the templates output format.
76 *
77 * There's few differences between XHTML and XML but they these differences can
78 * break some browsers output.
79 *
80 * Default PHPTAL output mode is XHTML.
81 */
82 define('PHPTAL_XHTML', 1);
83
84 /**
85 * This define is used to select the templates output format.
86 *
87 * The XML mode does not worry about XHTML specificity and echo every entity
88 * in a <entity></entity> format.
89 */
90 define('PHPTAL_XML', 2);
91
92 /**
93 * @var _phptal_namespaces
94 * @type array
95 *
96 * This array contains the list of all known attribute namespaces, if an
97 * attribute belonging to one of this namespaces is not recognized by PHPTAL,
98 * an exception will be raised.
99 *
100 * These namespaces will be drop from resulting xml/xhtml unless the parser
101 * is told to keep them.
102 *
103 * @access private
104 * @static 1
105 */
106 global $_phptal_namespaces;
107 $_phptal_namespaces = array('TAL', 'METAL', 'I18N', 'PHPTAL');
108
109
110 define('_PHPTAL_SURROUND', 1);
111 define('_PHPTAL_REPLACE', 2);
112 define('_PHPTAL_CONTENT', 3);
113
114 /**
115 * @var _phptal_dictionary
116 * @type hashtable
117 *
118 * This dictionary contains ALL known PHPTAL attributes. Unknown attributes
119 * will be echoed in result as xhtml/xml ones.
120 *
121 * The value define how and when the attribute handler will be called during
122 * code generation.
123 *
124 * @access private
125 * @static 1
126 */
127 global $_phptal_dictionary;
128 $_phptal_dictionary = array(
129 'TAL:DEFINE' => _PHPTAL_REPLACE, // set a context variable
130 'TAL:CONDITION' => _PHPTAL_SURROUND, // print tag content only when condition true
131 'TAL:REPEAT' => _PHPTAL_SURROUND, // repeat over an iterable
132 'TAL:CONTENT' => _PHPTAL_CONTENT, // replace tag content
133 'TAL:REPLACE' => _PHPTAL_REPLACE, // replace entire tag
134 'TAL:ATTRIBUTES' => _PHPTAL_REPLACE, // dynamically set tag attributes
135 'TAL:OMIT-TAG' => _PHPTAL_SURROUND, // omit to print tag but not its content
136 'TAL:COMMENT' => _PHPTAL_SURROUND, // do nothing
137 'TAL:ON-ERROR' => _PHPTAL_SURROUND, // replace content with this if error occurs
138
139 'METAL:DEFINE-MACRO' => _PHPTAL_SURROUND, // define a template macro
140 'METAL:USE-MACRO' => _PHPTAL_REPLACE, // use a template macro
141 'METAL:DEFINE-SLOT' => _PHPTAL_SURROUND, // define a macro slot
142 'METAL:FILL-SLOT' => _PHPTAL_SURROUND, // fill a macro slot
143
144 'PHPTAL:INCLUDE' => _PHPTAL_REPLACE, // include an external template
145 'PHPTAL:SRC-INCLUDE' => _PHPTAL_CONTENT, // include external file without parsing
146
147 'I18N:TRANSLATE' => _PHPTAL_CONTENT, // translate some data using GetText package
148 'I18N:NAME' => _PHPTAL_SURROUND, // prepare a translation name
149 'I18N:ATTRIBUTES' => _PHPTAL_REPLACE, // translate tag attributes values
150 );
151
152 /**
153 * @var _phptal_aliases
154 * @type hashtable
155 *
156 * Create aliases for attributes. If an alias is found during parsing, the
157 * matching phptal attribute will be used.
158 *
159 * @access private
160 * @static 1
161 */
162 global $_phptal_aliases;
163 $_phptal_aliases = array(
164 'TAL:INCLUDE' => 'PHPTAL:INCLUDE',
165 'TAL:SRC-INCLUDE'=> 'PHPTAL:SRC-INCLUDE',
166 );
167
168 /**
169 * @var _phptal_rules_order
170 * @type hashtable
171 *
172 * This rule associative array represents both ordering and exclusion
173 * mecanism for template attributes.
174 *
175 * All known attributes must appear here and must be associated with
176 * an occurence priority.
177 *
178 * When more than one phptal attribute appear in the same tag, they
179 * will execute in following order.
180 *
181 * @access private
182 * @static 1
183 */
184 global $_phptal_rules_order;
185 $_phptal_rules_order = array(
186 'TAL:OMIT-TAG' => 0, // surround -> $tag->disableHeadFootPrint()
187
188 'TAL:ON-ERROR' => 1, // surround
189
190 'METAL:DEFINE-MACRO' => 3, // surround
191 'TAL:DEFINE' => 3, // replace
192 'I18N:NAME' => 3, // replace
193 'I18N:TRANSLATE' => 3, // content
194
195 'TAL:CONDITION' => 4, // surround
196
197 'TAL:REPEAT' => 5, // surround
198
199 'I18N:ATTRIBUTES' => 6, // replace
200 'TAL:ATTRIBUTES' => 6, // replace
201 'TAL:REPLACE' => 6, // replace
202 'METAL:USE-MACRO' => 6, // replace
203 'PHPTAL:SRC-INCLUDE' => 6, // replace
204 'PHPTAL:INCLUDE' => 6, // replace
205 'METAL:DEFINE-SLOT' => 6, // replace
206 'METAL:FILL-SLOT' => 6, // replace
207
208 'TAL:CONTENT' => 7, // content
209
210 'TAL:COMMENT' => 8, // surround
211 );
212
213 /**
214 * @var _phptal_xhtml_content_free_tags
215 * @type array
216 *
217 * This array contains XHTML tags that must be echoed in a &lt;tag/&gt; form
218 * instead of the &lt;tag&gt;&lt;/tag&gt; form.
219 *
220 * In fact, some browsers does not support the later form so PHPTAL
221 * ensure these tags are correctly echoed.
222 */
223 global $_phptal_xhtml_empty_tags;
224 $_phptal_xhtml_empty_tags = array(
225 'AREA',
226 'BASE',
227 'BASEFONT',
228 'BR',
229 'COL',
230 'FRAME',
231 'HR',
232 'IMG',
233 'INPUT',
234 'ISINDEX',
235 'LINK',
236 'META',
237 'PARAM',
238 );
239
240 /**
241 * @var _phptal_xhtml_boolean_attributes
242 * @type array
243 *
244 * This array contains XHTML attributes that must be echoed in a minimized
245 * form. Some browsers (non HTML4 compliants are unable to interpret those
246 * attributes.
247 *
248 * The output will definitively not be an xml document !!
249 * PreFilters should be set to modify xhtml input containing these attributes.
250 */
251 global $_phptal_xhtml_boolean_attributes;
252 $_phptal_xhtml_boolean_attributes = array(
253 'compact',
254 'nowrap',
255 'ismap',
256 'declare',
257 'noshade',
258 'checked',
259 'disabled',
260 'readonly',
261 'multiple',
262 'selected',
263 'noresize',
264 'defer'
265 );
266
267 /**
268 * Shortcut to PHPTAL_Template for lazzy ones (me first).
269 */
270 class PHPTAL extends PHPTAL_Template {}
271
272 /**
273 * PEAR compliant class name.
274 */
275 class HTML_Template_PHPTAL extends PHPTAL_Template {}
276
277 /**
278 * PEAR compliant class name.
279 */
280 class HTML_Template_PHPTAL_Filter extends PHPTAL_Filter {}
281
282 /**
283 * PEAR compliant class name.
284 */
285 class HTML_Template_PHPTAL_SourceLocator extends PHPTAL_SourceLocator {}
286
287 /**
288 * PEAR compliant class name.
289 */
290 class HTML_Template_PHPTAL_SourceResolver extends PHPTAL_SourceResolver {}
291
292
293 ?>