Subversion Repositories Applications.papyrus

Rev

Rev 165 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 165 Rev 174
Line 19... Line 19...
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: Wikini.class.php,v 1.1 2004-11-23 17:25:38 jpm Exp $
24
// CVS : $Id: Wikini.class.php,v 1.2 2004-11-25 15:36:41 jpm Exp $
25
/**
25
/**
26
* Classe configurant le formatage pour Wikini.
26
* Classe configurant le formatage pour Wikini.
27
*
27
*
28
* Ce fichier contient une classe configurant les règles de formatage de Wikini.
28
* Ce fichier contient une classe configurant les règles de formatage de Wikini.
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:
Line 34... Line 34...
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.1 $ $Date: 2004-11-23 17:25:38 $
39
*@version       $Revision: 1.2 $ $Date: 2004-11-25 15:36:41 $
40
// +------------------------------------------------------------------------------------------------------+
40
// +------------------------------------------------------------------------------------------------------+
41
*/
41
*/
Line 42... Line 42...
42
 
42
 
43
// +------------------------------------------------------------------------------------------------------+
43
// +------------------------------------------------------------------------------------------------------+
Line 69... Line 69...
69
    * 
69
    * 
70
    * @var array
70
    * @var array
71
    * 
71
    * 
72
    */
72
    */
73
    var $rules = array(
73
    var $rules = array(
-
 
74
        'Table', // Tableaux
74
        'Code', // Inclusion de code avec coloration syntaxique
75
        'Code', // Inclusion de code avec coloration syntaxique
75
        'Delimiter', // Type de retour à la ligne
-
 
76
        'Emphasis', // Italique
76
        'Emphasis', // Italique
77
        'Freelink', // Nom de Page qui ne sont pas au format Wiki
77
        'Freelink', // Nom de Page qui ne sont pas au format Wiki
78
        'Heading', // Titre
78
        'Heading', // Titre
79
        'Horiz', // Ligne horizontale
79
        'Horiz', // Ligne horizontale
80
        'Interwiki', // Affichage de page d'un autre Wiki. Modifié par rapport à l'original de Text_Wiki
80
        'Interwiki', // Affichage de page d'un autre Wiki. Modifié par rapport à l'original de Text_Wiki
Line 82... Line 82...
82
        'Newline', // Nouveau paragraphe.
82
        'Newline', // Nouveau paragraphe.
83
        'Paragraph', // Nouveau paragraphe avec une ligne vide.
83
        'Paragraph', // Nouveau paragraphe avec une ligne vide.
84
        'Tighten', // Réduit les lignes vide si on en a 3 ou plus consécutives
84
        'Tighten', // Réduit les lignes vide si on en a 3 ou plus consécutives
85
        'Raw', // Inclusion de HTML et non traitement du contenu par les règles de formatage. Modifié par rapport à l'original de Text_Wiki
85
        'Raw', // Inclusion de HTML et non traitement du contenu par les règles de formatage. Modifié par rapport à l'original de Text_Wiki
86
        'Revise', // Suppression de texte. Modifié par rapport à l'original de Text_Wiki
86
        'Revise', // Suppression de texte. Modifié par rapport à l'original de Text_Wiki
87
        'Table', // Tableaux
-
 
88
        'Tt', // Texte à espacement fixe
87
        'Tt', // Texte à espacement fixe
89
        'Url', // Inclusion d'url dont les url d'images
88
        'Url', // Inclusion d'url dont les url d'images
90
        'Strong'// Gras
89
        'Strong',// Gras
-
 
90
        'Include'// Action Include
91
    );
91
    );
92
    /**
92
    /**
93
    * 
93
    * 
94
    * The delimiter for token numbers of parsed elements in source text.
94
    * The delimiter for token numbers of parsed elements in source text.
95
    * 
95
    * 
96
    * @access public
96
    * @access public
97
    * 
97
    * 
98
    * @var string
98
    * @var string
99
    * 
99
    * 
100
    */
100
    */
101
    var $delim = "\xFF";
101
    var $delim = 12;
Line 102... Line 102...
102
    
102
    
103
    function Text_Wikini()
103
    function Text_Wikini()
104
    {
104
    {
Line 112... Line 112...
112
        $this->addPath(
112
        $this->addPath(
113
            'render',
113
            'render',
114
            $this->fixPath(dirname(__FILE__)) . 'Render/'
114
            $this->fixPath(dirname(__FILE__)) . 'Render/'
115
        );
115
        );
116
    }
116
    }
-
 
117
    
-
 
118
    /**
-
 
119
    * 
-
 
120
    * Renders tokens back into the source text, based on the requested format.
-
 
121
    * 
-
 
122
    * @access public
-
 
123
    * 
-
 
124
    * @param string $format The target output format, typically 'xhtml'. 
-
 
125
    * If a rule does not support a given format, the output from that
-
 
126
    * rule is rule-specific.
-
 
127
    * 
-
 
128
    * @return string The transformed wiki text.
-
 
129
    * 
-
 
130
    */
-
 
131
    function render($format = 'Xhtml')
-
 
132
    {
-
 
133
        // the rendering method we're going to use from each rule
-
 
134
        $format = ucwords(strtolower($format));
-
 
135
        
-
 
136
        // the eventual output text
-
 
137
        $output = '';
-
 
138
        
-
 
139
        // when passing through the parsed source text, keep track of when
-
 
140
        // we are in a delimited section
-
 
141
        $in_delim = false;
-
 
142
        
-
 
143
        // when in a delimited section, capture the token key number
-
 
144
        $key = '';
-
 
145
        
-
 
146
        // load the format object
-
 
147
        $this->loadFormatObj($format);
-
 
148
        
-
 
149
        // pre-rendering activity
-
 
150
        if (is_object($this->formatObj[$format])) {
-
 
151
            $output .= $this->formatObj[$format]->pre();
-
 
152
        }
-
 
153
        
-
 
154
        // load the render objects
-
 
155
        foreach (array_keys($this->parseObj) as $rule) {
-
 
156
            $this->loadRenderObj($format, $rule);
-
 
157
        }
-
 
158
        
-
 
159
        // pass through the parsed source text character by character
-
 
160
        $k = strlen($this->source);
-
 
161
        for ($i = 0; $i < $k; $i++) {
-
 
162
            
-
 
163
            // the current character
-
 
164
            $char = $this->source{$i};
-
 
165
            
-
 
166
            // are alredy in a delimited section?
-
 
167
            if ($in_delim) {
-
 
168
            
-
 
169
                // yes; are we ending the section?
-
 
170
                if ($char == chr($this->delim)) {
-
 
171
                    
-
 
172
                    // yes, get the replacement text for the delimited
-
 
173
                    // token number and unset the flag.
-
 
174
                    $key = (int)$key;
-
 
175
                    $rule = $this->tokens[$key][0];
-
 
176
                    $opts = $this->tokens[$key][1];
-
 
177
                    $output .= $this->renderObj[$rule]->token($opts);
-
 
178
                    $in_delim = false;
-
 
179
                    
-
 
180
                } else {
-
 
181
                
-
 
182
                    // no, add to the dlimited token key number
-
 
183
                    $key .= $char;
-
 
184
                    
-
 
185
                }
-
 
186
                
-
 
187
            } else {
-
 
188
                
-
 
189
                // not currently in a delimited section.
-
 
190
                // are we starting into a delimited section?
-
 
191
                if ($char == chr($this->delim)) {
-
 
192
                    // yes, reset the previous key and
-
 
193
                    // set the flag.
-
 
194
                    $key = '';
-
 
195
                    $in_delim = true;
-
 
196
                } else {
-
 
197
                    // no, add to the output as-is
-
 
198
                    $output .= $char;
-
 
199
                }
-
 
200
            }
-
 
201
        }
-
 
202
        
-
 
203
        // post-rendering activity
-
 
204
        if (is_object($this->formatObj[$format])) {
-
 
205
            $output .= $this->formatObj[$format]->post();
-
 
206
        }
-
 
207
        
-
 
208
        // return the rendered source text.
-
 
209
        return $output;
-
 
210
    }
-
 
211
    
-
 
212
    /**
-
 
213
    * 
-
 
214
    * Add a token to the Text_Wiki tokens array, and return a delimited
-
 
215
    * token number.
-
 
216
    * 
-
 
217
    * @access public
-
 
218
    * 
-
 
219
    * @param array $options An associative array of options for the new
-
 
220
    * token array element.  The keys and values are specific to the
-
 
221
    * rule, and may or may not be common to other rule options.  Typical
-
 
222
    * options keys are 'text' and 'type' but may include others.
-
 
223
    * 
-
 
224
    * @param boolean $id_only If true, return only the token number, not
-
 
225
    * a delimited token string.
-
 
226
    * 
-
 
227
    * @return string|int By default, return the number of the
-
 
228
    * newly-created token array element with a delimiter prefix and
-
 
229
    * suffix; however, if $id_only is set to true, return only the token
-
 
230
    * number (no delimiters).
-
 
231
    * 
-
 
232
    */
-
 
233
    function addToken($rule, $options = array(), $id_only = false)
-
 
234
    {
-
 
235
        // increment the token ID number.  note that if you parse
-
 
236
        // multiple times with the same Text_Wiki object, the ID number
-
 
237
        // will not reset to zero.
-
 
238
        static $id;
-
 
239
        if (! isset($id)) {
-
 
240
            $id = 0;
-
 
241
        } else {
-
 
242
            $id ++;
-
 
243
        }
-
 
244
        
-
 
245
        // force the options to be an array
-
 
246
        settype($options, 'array');
-
 
247
        
-
 
248
        // add the token
-
 
249
        $this->tokens[$id] = array(
-
 
250
            0 => $rule,
-
 
251
            1 => $options
-
 
252
        );
-
 
253
        
-
 
254
        // return a value
-
 
255
        if ($id_only) {
-
 
256
            // return the last token number
-
 
257
            return $id;
-
 
258
        } else {
-
 
259
            // return the token number with delimiters
-
 
260
            return chr($this->delim) . $id . chr($this->delim);
-
 
261
        }
-
 
262
    }
117
}
263
}
Line 118... Line 264...
118
 
264
 
119
// +------------------------------------------------------------------------------------------------------+
265
// +------------------------------------------------------------------------------------------------------+
120
// |                                            PIED du PROGRAMME                                         |
266
// |                                            PIED du PROGRAMME                                         |
Line 123... Line 269...
123
 
269
 
124
 
270
 
125
/* +--Fin du code ----------------------------------------------------------------------------------------+
271
/* +--Fin du code ----------------------------------------------------------------------------------------+
-
 
272
*
-
 
273
* $Log: not supported by cvs2svn $
-
 
274
* Revision 1.1  2004/11/23 17:25:38  jpm
126
*
275
* Début classe PEAR WIKI pour la syntaxe Wikini.
127
* $Log: not supported by cvs2svn $
276
*
128
*
277
*
129
* +-- Fin du code ----------------------------------------------------------------------------------------+
278
* +-- Fin du code ----------------------------------------------------------------------------------------+
130
*/
279
*/