Subversion Repositories Applications.papyrus

Rev

Rev 1133 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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