Subversion Repositories Applications.papyrus

Rev

Rev 1133 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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