Subversion Repositories Applications.papyrus

Rev

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

Rev 1160 Rev 1166
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.14 2006-12-13 10:53:09 jp_milcent Exp $
24
// CVS : $Id: Papyrus.class.php,v 1.15 2006-12-13 17:14:00 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.14 $ $Date: 2006-12-13 10:53:09 $
39
*@version       $Revision: 1.15 $ $Date: 2006-12-13 17:14:00 $
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
        'Syndication' // Action Syndication
-
 
76
    );
-
 
77
    
75
    
78
    /**
76
    /**
79
    * 
77
    * 
80
    * The list of rules to not-apply to the source text.
78
    * The list of rules to not-apply to the source text.
81
    * 
79
    * 
82
    * @access public
80
    * @access public
83
    * 
81
    * 
84
    * @var array
82
    * @var array
85
    * 
83
    * 
86
    */
84
    */
87
    var $disable = array();
85
    var $disable = array();
88
    
86
    
89
    /**
87
    /**
90
    * 
88
    * 
91
    * The delimiter for token numbers of parsed elements in source text.
89
    * The delimiter for token numbers of parsed elements in source text.
92
    * 
90
    * 
93
    * @access public
91
    * @access public
94
    * 
92
    * 
95
    * @var string
93
    * @var string
96
    * 
94
    * 
97
    */
95
    */
98
    var $delim = 12;
96
    var $delim = 12;
99
    
97
    
100
    function Text_Papyrus($rules = null)
98
    function Text_Papyrus($rules = null)
101
    {
99
    {
102
        //Text_Wiki::Text_Wiki();
100
        //Text_Wiki::Text_Wiki();
103
        if (is_array($rules)) {
101
        if (is_array($rules)) {
104
            $this->rules = $rules;
102
            $this->rules = $rules;
105
        }
103
        }
106
        // Nous devons sortir les fichiers de Text_Wiki du dépot Pear car la fonction file_exists de PHP utilisée dans
104
        // Nous devons sortir les fichiers de Text_Wiki du dépot Pear car la fonction file_exists de PHP utilisée dans
107
        // la méthode findfile de Text_Wiki renvoie false.
105
        // la méthode findfile de Text_Wiki renvoie false.
108
        $this->addPath('parse', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Parse/');
106
        $this->addPath('parse', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Parse/');
109
        $this->addPath('render', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Render/');
107
        $this->addPath('render', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Render/');
110
        // Pour les règles spécifiques à Papyrus:
108
        // Pour les règles spécifiques à Papyrus:
111
        $this->addPath('parse', $this->fixPath(dirname(__FILE__)) . 'Parse/');
109
        $this->addPath('parse', $this->fixPath(dirname(__FILE__)) . 'Parse/');
112
        $this->addPath('render', $this->fixPath(dirname(__FILE__)) . 'Render/');
110
        $this->addPath('render', $this->fixPath(dirname(__FILE__)) . 'Render/');
113
        
111
        
114
        
112
        
115
    }
113
    }
116
    
114
    
117
    /**
115
    /**
118
    * 
116
    * 
119
    * Renders tokens back into the source text, based on the requested format.
117
    * Renders tokens back into the source text, based on the requested format.
120
    * 
118
    * 
121
    * @access public
119
    * @access public
122
    * 
120
    * 
123
    * @param string $format The target output format, typically 'xhtml'. 
121
    * @param string $format The target output format, typically 'xhtml'. 
124
    * If a rule does not support a given format, the output from that
122
    * If a rule does not support a given format, the output from that
125
    * rule is rule-specific.
123
    * rule is rule-specific.
126
    * 
124
    * 
127
    * @return string The transformed wiki text.
125
    * @return string The transformed wiki text.
128
    * 
126
    * 
129
    */
127
    */
130
    function render($format = 'Xhtml')
128
    function render($format = 'Xhtml')
131
    {
129
    {
132
        // the rendering method we're going to use from each rule
130
        // the rendering method we're going to use from each rule
133
        $format = ucwords(strtolower($format));
131
        $format = ucwords(strtolower($format));
134
        
132
        
135
        // the eventual output text
133
        // the eventual output text
136
        $output = '';
134
        $output = '';
137
        
135
        
138
        // when passing through the parsed source text, keep track of when
136
        // when passing through the parsed source text, keep track of when
139
        // we are in a delimited section
137
        // we are in a delimited section
140
        $in_delim = false;
138
        $in_delim = false;
141
        
139
        
142
        // when in a delimited section, capture the token key number
140
        // when in a delimited section, capture the token key number
143
        $key = '';
141
        $key = '';
144
        
142
        
145
        // load the format object
143
        // load the format object
146
        $this->loadFormatObj($format);
144
        $this->loadFormatObj($format);
147
        
145
        
148
        // pre-rendering activity
146
        // pre-rendering activity
149
        if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
147
        if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
150
            $output .= $this->formatObj[$format]->pre();
148
            $output .= $this->formatObj[$format]->pre();
151
        }
149
        }
152
        
150
        
153
        // load the render objects
151
        // load the render objects
154
        foreach (array_keys($this->parseObj) as $rule) {
152
        foreach (array_keys($this->parseObj) as $rule) {
155
            $this->loadRenderObj($format, $rule);
153
            $this->loadRenderObj($format, $rule);
156
        }
154
        }
157
        
155
        
158
        // pass through the parsed source text character by character
156
        // pass through the parsed source text character by character
159
        $k = strlen($this->source);
157
        $k = strlen($this->source);
160
        for ($i = 0; $i < $k; $i++) {
158
        for ($i = 0; $i < $k; $i++) {
161
            
159
            
162
            // the current character
160
            // the current character
163
            $char = $this->source{$i};
161
            $char = $this->source{$i};
164
            
162
            
165
            // are alredy in a delimited section?
163
            // are alredy in a delimited section?
166
            if ($in_delim) {
164
            if ($in_delim) {
167
            
165
            
168
                // yes; are we ending the section?
166
                // yes; are we ending the section?
169
                if ($char == chr($this->delim)) {
167
                if ($char == chr($this->delim)) {
170
                    
168
                    
171
                    // yes, get the replacement text for the delimited
169
                    // yes, get the replacement text for the delimited
172
                    // token number and unset the flag.
170
                    // token number and unset the flag.
173
                    $key = (int)$key;
171
                    $key = (int)$key;
174
                    $rule = null;
172
                    $rule = null;
175
                    if (isset($this->tokens[$key][0])) {
173
                    if (isset($this->tokens[$key][0])) {
176
                        $rule = $this->tokens[$key][0];
174
                        $rule = $this->tokens[$key][0];
177
                    }
175
                    }
178
                    $opts = null;
176
                    $opts = null;
179
                    if (isset($this->tokens[$key][1])) {
177
                    if (isset($this->tokens[$key][1])) {
180
                        $opts = $this->tokens[$key][1];
178
                        $opts = $this->tokens[$key][1];
181
                    }
179
                    }
182
                    if (isset($this->renderObj[$rule]) && is_object($this->renderObj[$rule])) {
180
                    if (isset($this->renderObj[$rule]) && is_object($this->renderObj[$rule])) {
183
                        $output .= $this->renderObj[$rule]->token($opts);
181
                        $output .= $this->renderObj[$rule]->token($opts);
184
                    }
182
                    }
185
                    $in_delim = false;
183
                    $in_delim = false;
186
                    
184
                    
187
                } else {
185
                } else {
188
                
186
                
189
                    // no, add to the dlimited token key number
187
                    // no, add to the dlimited token key number
190
                    $key .= $char;
188
                    $key .= $char;
191
                    
189
                    
192
                }
190
                }
193
                
191
                
194
            } else {
192
            } else {
195
                
193
                
196
                // not currently in a delimited section.
194
                // not currently in a delimited section.
197
                // are we starting into a delimited section?
195
                // are we starting into a delimited section?
198
                if ($char == chr($this->delim)) {
196
                if ($char == chr($this->delim)) {
199
                    // yes, reset the previous key and
197
                    // yes, reset the previous key and
200
                    // set the flag.
198
                    // set the flag.
201
                    $key = '';
199
                    $key = '';
202
                    $in_delim = true;
200
                    $in_delim = true;
203
                } else {
201
                } else {
204
                    // no, add to the output as-is
202
                    // no, add to the output as-is
205
                    $output .= $char;
203
                    $output .= $char;
206
                }
204
                }
207
            }
205
            }
208
        }
206
        }
209
        
207
        
210
        // post-rendering activity
208
        // post-rendering activity
211
        if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
209
        if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
212
            $output .= $this->formatObj[$format]->post();
210
            $output .= $this->formatObj[$format]->post();
213
        }
211
        }
214
        
212
        
215
        // return the rendered source text.
213
        // return the rendered source text.
216
        return $output;
214
        return $output;
217
    }
215
    }
218
    
216
    
219
    /**
217
    /**
220
    * 
218
    * 
221
    * Add a token to the Text_Wiki tokens array, and return a delimited
219
    * Add a token to the Text_Wiki tokens array, and return a delimited
222
    * token number.
220
    * token number.
223
    * 
221
    * 
224
    * @access public
222
    * @access public
225
    * 
223
    * 
226
    * @param array $options An associative array of options for the new
224
    * @param array $options An associative array of options for the new
227
    * token array element.  The keys and values are specific to the
225
    * token array element.  The keys and values are specific to the
228
    * rule, and may or may not be common to other rule options.  Typical
226
    * rule, and may or may not be common to other rule options.  Typical
229
    * options keys are 'text' and 'type' but may include others.
227
    * options keys are 'text' and 'type' but may include others.
230
    * 
228
    * 
231
    * @param boolean $id_only If true, return only the token number, not
229
    * @param boolean $id_only If true, return only the token number, not
232
    * a delimited token string.
230
    * a delimited token string.
233
    * 
231
    * 
234
    * @return string|int By default, return the number of the
232
    * @return string|int By default, return the number of the
235
    * newly-created token array element with a delimiter prefix and
233
    * newly-created token array element with a delimiter prefix and
236
    * suffix; however, if $id_only is set to true, return only the token
234
    * suffix; however, if $id_only is set to true, return only the token
237
    * number (no delimiters).
235
    * number (no delimiters).
238
    * 
236
    * 
239
    */
237
    */
240
    function addToken($rule, $options = array(), $id_only = false)
238
    function addToken($rule, $options = array(), $id_only = false)
241
    {
239
    {
242
        // increment the token ID number.  note that if you parse
240
        // increment the token ID number.  note that if you parse
243
        // multiple times with the same Text_Wiki object, the ID number
241
        // multiple times with the same Text_Wiki object, the ID number
244
        // will not reset to zero.
242
        // will not reset to zero.
245
        static $id;
243
        static $id;
246
        if (! isset($id)) {
244
        if (! isset($id)) {
247
            $id = 0;
245
            $id = 0;
248
        } else {
246
        } else {
249
            $id ++;
247
            $id ++;
250
        }
248
        }
251
        
249
        
252
        // force the options to be an array
250
        // force the options to be an array
253
        settype($options, 'array');
251
        settype($options, 'array');
254
        
252
        
255
        // add the token
253
        // add the token
256
        $this->tokens[$id] = array(
254
        $this->tokens[$id] = array(
257
            0 => $rule,
255
            0 => $rule,
258
            1 => $options
256
            1 => $options
259
        );
257
        );
260
        
258
        
261
        // return a value
259
        // return a value
262
        if ($id_only) {
260
        if ($id_only) {
263
            // return the last token number
261
            // return the last token number
264
            return $id;
262
            return $id;
265
        } else {
263
        } else {
266
            // return the token number with delimiters
264
            // return the token number with delimiters
267
            return chr($this->delim) . $id . chr($this->delim);
265
            return chr($this->delim) . $id . chr($this->delim);
268
        }
266
        }
269
    }
267
    }
270
}
268
}
271
 
269
 
272
// +------------------------------------------------------------------------------------------------------+
270
// +------------------------------------------------------------------------------------------------------+
273
// |                                            PIED du PROGRAMME                                         |
271
// |                                            PIED du PROGRAMME                                         |
274
// +------------------------------------------------------------------------------------------------------+
272
// +------------------------------------------------------------------------------------------------------+
275
 
273
 
276
 
274
 
277
 
275
 
278
/* +--Fin du code ----------------------------------------------------------------------------------------+
276
/* +--Fin du code ----------------------------------------------------------------------------------------+
279
*
277
*
280
* $Log: not supported by cvs2svn $
278
* $Log: not supported by cvs2svn $
-
 
279
* Revision 1.14  2006/12/13 10:53:09  jp_milcent
-
 
280
* Suppression de l'action Redirection transformée en Applette.
-
 
281
*
281
* Revision 1.13  2006/12/13 09:43:13  jp_milcent
282
* Revision 1.13  2006/12/13 09:43:13  jp_milcent
282
* Suppression de l'action Plan transformée en Applette.
283
* Suppression de l'action Plan transformée en Applette.
283
*
284
*
284
* Revision 1.12  2006/12/12 17:16:52  jp_milcent
285
* Revision 1.12  2006/12/12 17:16:52  jp_milcent
285
* Suppression de l'action Nouveaute transformée en Applette.
286
* Suppression de l'action Nouveaute transformée en Applette.
286
*
287
*
287
* Revision 1.11  2006/12/12 13:33:57  jp_milcent
288
* Revision 1.11  2006/12/12 13:33:57  jp_milcent
288
* Suppression de l'action MotCles transformée en Applette.
289
* Suppression de l'action MotCles transformée en Applette.
289
*
290
*
290
* Revision 1.10  2006/12/08 20:16:27  jp_milcent
291
* Revision 1.10  2006/12/08 20:16:27  jp_milcent
291
* Suppression de l'action Lien remplacée par une applette.
292
* Suppression de l'action Lien remplacée par une applette.
292
*
293
*
293
* Revision 1.9  2006/12/08 15:29:33  jp_milcent
294
* Revision 1.9  2006/12/08 15:29:33  jp_milcent
294
* Suppression des actions transformées en applette.
295
* Suppression des actions transformées en applette.
295
*
296
*
296
* Revision 1.8  2006/05/10 16:02:49  ddelon
297
* Revision 1.8  2006/05/10 16:02:49  ddelon
297
* Finition multilinguise et schizo flo
298
* Finition multilinguise et schizo flo
298
*
299
*
299
* Revision 1.7  2005/09/23 13:58:07  ddelon
300
* Revision 1.7  2005/09/23 13:58:07  ddelon
300
* Php5, Projet et Redirection
301
* Php5, Projet et Redirection
301
*
302
*
302
* Revision 1.6  2005/04/18 16:41:53  jpm
303
* Revision 1.6  2005/04/18 16:41:53  jpm
303
* Ajout des actions Plan et Syndication.
304
* Ajout des actions Plan et Syndication.
304
*
305
*
305
* Revision 1.5  2005/04/14 16:35:42  jpm
306
* Revision 1.5  2005/04/14 16:35:42  jpm
306
* Ajout de nouvelles actions pour Papyrus XHTML.
307
* Ajout de nouvelles actions pour Papyrus XHTML.
307
*
308
*
308
* Revision 1.4  2005/01/20 19:39:39  jpm
309
* Revision 1.4  2005/01/20 19:39:39  jpm
309
* Correction bogue du à la fonction file_exists qui renvoie false pour les fichiers présent dans le dossier Pear /usr/local/lib/php/.
310
* Correction bogue du à la fonction file_exists qui renvoie false pour les fichiers présent dans le dossier Pear /usr/local/lib/php/.
310
*
311
*
311
* Revision 1.3  2004/12/07 12:17:37  jpm
312
* Revision 1.3  2004/12/07 12:17:37  jpm
312
* Correction message d'erreur.
313
* Correction message d'erreur.
313
*
314
*
314
* Revision 1.2  2004/11/26 12:13:03  jpm
315
* Revision 1.2  2004/11/26 12:13:03  jpm
315
* Correction de résidu...
316
* Correction de résidu...
316
*
317
*
317
* Revision 1.1  2004/11/26 12:11:49  jpm
318
* Revision 1.1  2004/11/26 12:11:49  jpm
318
* Ajout des action Papyrus à Text_Wiki.
319
* Ajout des action Papyrus à Text_Wiki.
319
*
320
*
320
* Revision 1.2  2004/11/25 15:36:41  jpm
321
* Revision 1.2  2004/11/25 15:36:41  jpm
321
* Suppression régle Delimiter car problème avec les délimitations de fin de ligne.
322
* Suppression régle Delimiter car problème avec les délimitations de fin de ligne.
322
*
323
*
323
* Revision 1.1  2004/11/23 17:25:38  jpm
324
* Revision 1.1  2004/11/23 17:25:38  jpm
324
* Début classe PEAR WIKI pour la syntaxe Wikini.
325
* Début classe PEAR WIKI pour la syntaxe Wikini.
325
*
326
*
326
*
327
*
327
* +-- Fin du code ----------------------------------------------------------------------------------------+
328
* +-- Fin du code ----------------------------------------------------------------------------------------+
328
*/
329
*/
329
?>
330
?>