Subversion Repositories Applications.papyrus

Rev

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

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