Subversion Repositories Applications.papyrus

Rev

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

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