178 |
jpm |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.3 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of Papyrus. |
|
|
|
9 |
// | |
|
|
|
10 |
// | Foobar is free software; you can redistribute it and/or modify |
|
|
|
11 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
12 |
// | the Free Software Foundation; either version 2 of the License, or |
|
|
|
13 |
// | (at your option) any later version. |
|
|
|
14 |
// | |
|
|
|
15 |
// | Foobar is distributed in the hope that it will be useful, |
|
|
|
16 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
17 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
18 |
// | GNU General Public License for more details. |
|
|
|
19 |
// | |
|
|
|
20 |
// | You should have received a copy of the GNU General Public License |
|
|
|
21 |
// | along with Foobar; if not, write to the Free Software |
|
|
|
22 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
23 |
// +------------------------------------------------------------------------------------------------------+
|
841 |
ddelon |
24 |
// CVS : $Id: Papyrus.class.php,v 1.8 2006-05-10 16:02:49 ddelon Exp $
|
178 |
jpm |
25 |
/**
|
|
|
26 |
* Classe configurant le formatage pour Papyrus.
|
|
|
27 |
*
|
|
|
28 |
* Ce fichier contient une classe configurant les règles de formatage de Papyrus.
|
|
|
29 |
* Nécessite que l'application appelant ce fichier est précédement inclu le fichier de Pear:
|
|
|
30 |
* 'Text/Wiki.php';
|
|
|
31 |
*
|
|
|
32 |
*@package Text_Wiki
|
|
|
33 |
*@subpackage Papyrus
|
|
|
34 |
//Auteur original :
|
|
|
35 |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
36 |
//Autres auteurs :
|
|
|
37 |
*@author Aucun
|
|
|
38 |
*@copyright Tela-Botanica 2000-2004
|
841 |
ddelon |
39 |
*@version $Revision: 1.8 $ $Date: 2006-05-10 16:02:49 $
|
178 |
jpm |
40 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
41 |
*/
|
|
|
42 |
|
|
|
43 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
44 |
// | ENTETE du PROGRAMME |
|
|
|
45 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
46 |
|
|
|
47 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
48 |
// | CORPS du PROGRAMME |
|
|
|
49 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* Parse structured wiki text and render into arbitrary formats such as XHTML.
|
|
|
53 |
*
|
|
|
54 |
* Cette classe fille permet de configurer les régles de formatage pour Papyrus.
|
|
|
55 |
* Généralement nous avons à faire à des actions.
|
|
|
56 |
*
|
|
|
57 |
* @author Paul M. Jones <pmjones@ciaweb.net>
|
|
|
58 |
* @package Text_Wiki
|
|
|
59 |
* @version 0.23.1
|
|
|
60 |
* @license LGPL
|
|
|
61 |
*/
|
|
|
62 |
class Text_Papyrus extends Text_Wiki {
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
*
|
|
|
66 |
* Liste de règles par défaut du format Papyrs dans leur ordre d'application au texte
|
|
|
67 |
* à transformer.
|
|
|
68 |
*
|
|
|
69 |
* @access public
|
|
|
70 |
*
|
|
|
71 |
* @var array
|
|
|
72 |
*
|
|
|
73 |
*/
|
|
|
74 |
var $rules = array(
|
335 |
jpm |
75 |
'Inclure', // Action Inclure
|
|
|
76 |
'Motcles', // Action Motcles
|
|
|
77 |
'Categorie', // Action Categorie
|
345 |
jpm |
78 |
'Nouveaute', // Action Nouveaute
|
|
|
79 |
'Plan', // Action Plan
|
841 |
ddelon |
80 |
'Lien', // Action Lien
|
345 |
jpm |
81 |
'Syndication', // Action Syndication
|
453 |
ddelon |
82 |
'Redirection' // Action Redirection
|
841 |
ddelon |
83 |
|
178 |
jpm |
84 |
);
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
*
|
|
|
88 |
* The list of rules to not-apply to the source text.
|
|
|
89 |
*
|
|
|
90 |
* @access public
|
|
|
91 |
*
|
|
|
92 |
* @var array
|
|
|
93 |
*
|
|
|
94 |
*/
|
179 |
jpm |
95 |
var $disable = array();
|
178 |
jpm |
96 |
|
|
|
97 |
/**
|
|
|
98 |
*
|
|
|
99 |
* The delimiter for token numbers of parsed elements in source text.
|
|
|
100 |
*
|
|
|
101 |
* @access public
|
|
|
102 |
*
|
|
|
103 |
* @var string
|
|
|
104 |
*
|
|
|
105 |
*/
|
|
|
106 |
var $delim = 12;
|
|
|
107 |
|
247 |
jpm |
108 |
function Text_Papyrus($rules = null)
|
178 |
jpm |
109 |
{
|
247 |
jpm |
110 |
//Text_Wiki::Text_Wiki();
|
|
|
111 |
if (is_array($rules)) {
|
|
|
112 |
$this->rules = $rules;
|
|
|
113 |
}
|
|
|
114 |
// Nous devons sortir les fichiers de Text_Wiki du dépot Pear car la fonction file_exists de PHP utilisée dans
|
|
|
115 |
// la méthode findfile de Text_Wiki renvoie false.
|
|
|
116 |
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Parse/');
|
|
|
117 |
$this->addPath('render', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Render/');
|
|
|
118 |
// Pour les règles spécifiques à Papyrus:
|
|
|
119 |
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) . 'Parse/');
|
|
|
120 |
$this->addPath('render', $this->fixPath(dirname(__FILE__)) . 'Render/');
|
178 |
jpm |
121 |
|
|
|
122 |
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
*
|
|
|
127 |
* Renders tokens back into the source text, based on the requested format.
|
|
|
128 |
*
|
|
|
129 |
* @access public
|
|
|
130 |
*
|
|
|
131 |
* @param string $format The target output format, typically 'xhtml'.
|
|
|
132 |
* If a rule does not support a given format, the output from that
|
|
|
133 |
* rule is rule-specific.
|
|
|
134 |
*
|
|
|
135 |
* @return string The transformed wiki text.
|
|
|
136 |
*
|
|
|
137 |
*/
|
|
|
138 |
function render($format = 'Xhtml')
|
|
|
139 |
{
|
|
|
140 |
// the rendering method we're going to use from each rule
|
|
|
141 |
$format = ucwords(strtolower($format));
|
|
|
142 |
|
|
|
143 |
// the eventual output text
|
|
|
144 |
$output = '';
|
|
|
145 |
|
|
|
146 |
// when passing through the parsed source text, keep track of when
|
|
|
147 |
// we are in a delimited section
|
|
|
148 |
$in_delim = false;
|
|
|
149 |
|
|
|
150 |
// when in a delimited section, capture the token key number
|
|
|
151 |
$key = '';
|
|
|
152 |
|
|
|
153 |
// load the format object
|
|
|
154 |
$this->loadFormatObj($format);
|
|
|
155 |
|
|
|
156 |
// pre-rendering activity
|
224 |
jpm |
157 |
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
|
178 |
jpm |
158 |
$output .= $this->formatObj[$format]->pre();
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
// load the render objects
|
|
|
162 |
foreach (array_keys($this->parseObj) as $rule) {
|
|
|
163 |
$this->loadRenderObj($format, $rule);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
// pass through the parsed source text character by character
|
|
|
167 |
$k = strlen($this->source);
|
|
|
168 |
for ($i = 0; $i < $k; $i++) {
|
|
|
169 |
|
|
|
170 |
// the current character
|
|
|
171 |
$char = $this->source{$i};
|
|
|
172 |
|
|
|
173 |
// are alredy in a delimited section?
|
|
|
174 |
if ($in_delim) {
|
|
|
175 |
|
|
|
176 |
// yes; are we ending the section?
|
|
|
177 |
if ($char == chr($this->delim)) {
|
|
|
178 |
|
|
|
179 |
// yes, get the replacement text for the delimited
|
|
|
180 |
// token number and unset the flag.
|
|
|
181 |
$key = (int)$key;
|
247 |
jpm |
182 |
$rule = null;
|
|
|
183 |
if (isset($this->tokens[$key][0])) {
|
|
|
184 |
$rule = $this->tokens[$key][0];
|
|
|
185 |
}
|
|
|
186 |
$opts = null;
|
|
|
187 |
if (isset($this->tokens[$key][1])) {
|
|
|
188 |
$opts = $this->tokens[$key][1];
|
|
|
189 |
}
|
|
|
190 |
if (isset($this->renderObj[$rule]) && is_object($this->renderObj[$rule])) {
|
|
|
191 |
$output .= $this->renderObj[$rule]->token($opts);
|
|
|
192 |
}
|
178 |
jpm |
193 |
$in_delim = false;
|
|
|
194 |
|
|
|
195 |
} else {
|
|
|
196 |
|
|
|
197 |
// no, add to the dlimited token key number
|
|
|
198 |
$key .= $char;
|
|
|
199 |
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
} else {
|
|
|
203 |
|
|
|
204 |
// not currently in a delimited section.
|
|
|
205 |
// are we starting into a delimited section?
|
|
|
206 |
if ($char == chr($this->delim)) {
|
|
|
207 |
// yes, reset the previous key and
|
|
|
208 |
// set the flag.
|
|
|
209 |
$key = '';
|
|
|
210 |
$in_delim = true;
|
|
|
211 |
} else {
|
|
|
212 |
// no, add to the output as-is
|
|
|
213 |
$output .= $char;
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
// post-rendering activity
|
224 |
jpm |
219 |
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
|
178 |
jpm |
220 |
$output .= $this->formatObj[$format]->post();
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
// return the rendered source text.
|
|
|
224 |
return $output;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/**
|
|
|
228 |
*
|
|
|
229 |
* Add a token to the Text_Wiki tokens array, and return a delimited
|
|
|
230 |
* token number.
|
|
|
231 |
*
|
|
|
232 |
* @access public
|
|
|
233 |
*
|
|
|
234 |
* @param array $options An associative array of options for the new
|
|
|
235 |
* token array element. The keys and values are specific to the
|
|
|
236 |
* rule, and may or may not be common to other rule options. Typical
|
|
|
237 |
* options keys are 'text' and 'type' but may include others.
|
|
|
238 |
*
|
|
|
239 |
* @param boolean $id_only If true, return only the token number, not
|
|
|
240 |
* a delimited token string.
|
|
|
241 |
*
|
|
|
242 |
* @return string|int By default, return the number of the
|
|
|
243 |
* newly-created token array element with a delimiter prefix and
|
|
|
244 |
* suffix; however, if $id_only is set to true, return only the token
|
|
|
245 |
* number (no delimiters).
|
|
|
246 |
*
|
|
|
247 |
*/
|
|
|
248 |
function addToken($rule, $options = array(), $id_only = false)
|
|
|
249 |
{
|
|
|
250 |
// increment the token ID number. note that if you parse
|
|
|
251 |
// multiple times with the same Text_Wiki object, the ID number
|
|
|
252 |
// will not reset to zero.
|
|
|
253 |
static $id;
|
|
|
254 |
if (! isset($id)) {
|
|
|
255 |
$id = 0;
|
|
|
256 |
} else {
|
|
|
257 |
$id ++;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
// force the options to be an array
|
|
|
261 |
settype($options, 'array');
|
|
|
262 |
|
|
|
263 |
// add the token
|
|
|
264 |
$this->tokens[$id] = array(
|
|
|
265 |
|
|
|
266 |
1 => $options
|
|
|
267 |
);
|
|
|
268 |
|
|
|
269 |
// return a value
|
|
|
270 |
if ($id_only) {
|
|
|
271 |
// return the last token number
|
|
|
272 |
return $id;
|
|
|
273 |
} else {
|
|
|
274 |
// return the token number with delimiters
|
|
|
275 |
return chr($this->delim) . $id . chr($this->delim);
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
281 |
// | PIED du PROGRAMME |
|
|
|
282 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
287 |
*
|
|
|
288 |
* $Log: not supported by cvs2svn $
|
841 |
ddelon |
289 |
* Revision 1.7 2005/09/23 13:58:07 ddelon
|
|
|
290 |
* Php5, Projet et Redirection
|
|
|
291 |
*
|
453 |
ddelon |
292 |
* Revision 1.6 2005/04/18 16:41:53 jpm
|
|
|
293 |
* Ajout des actions Plan et Syndication.
|
|
|
294 |
*
|
345 |
jpm |
295 |
* Revision 1.5 2005/04/14 16:35:42 jpm
|
|
|
296 |
* Ajout de nouvelles actions pour Papyrus XHTML.
|
|
|
297 |
*
|
335 |
jpm |
298 |
* Revision 1.4 2005/01/20 19:39:39 jpm
|
|
|
299 |
* Correction bogue du à la fonction file_exists qui renvoie false pour les fichiers présent dans le dossier Pear /usr/local/lib/php/.
|
|
|
300 |
*
|
247 |
jpm |
301 |
* Revision 1.3 2004/12/07 12:17:37 jpm
|
|
|
302 |
* Correction message d'erreur.
|
|
|
303 |
*
|
224 |
jpm |
304 |
* Revision 1.2 2004/11/26 12:13:03 jpm
|
|
|
305 |
* Correction de résidu...
|
|
|
306 |
*
|
179 |
jpm |
307 |
* Revision 1.1 2004/11/26 12:11:49 jpm
|
|
|
308 |
* Ajout des action Papyrus à Text_Wiki.
|
|
|
309 |
*
|
178 |
jpm |
310 |
* Revision 1.2 2004/11/25 15:36:41 jpm
|
|
|
311 |
* Suppression régle Delimiter car problème avec les délimitations de fin de ligne.
|
|
|
312 |
*
|
|
|
313 |
* Revision 1.1 2004/11/23 17:25:38 jpm
|
|
|
314 |
* Début classe PEAR WIKI pour la syntaxe Wikini.
|
|
|
315 |
*
|
|
|
316 |
*
|
|
|
317 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
318 |
*/
|
|
|
319 |
?>
|