Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | <?php /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* # ***** BEGIN LICENSE BLOCK ***** # This file is part of Plume Framework, a simple PHP Application Framework. # Copyright (C) 2001-2007 Loic d'Anterroches and contributors. # # Plume Framework is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Plume Framework is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # ***** END LICENSE BLOCK ***** */ /* * Based on Wiki Renderer copyright (C) 2003-2004 Laurent Jouanneau */ /** * Rendering engine. * * Main class to convert a wiki text into XHTML. * * Usage: * <code> * $ctr = Pluf::factory('Pluf_Text_Wiki_Renderer'); * $xhtml_text = $ctr->render($wiki_text); * </code> */ class Pluf_Text_Wiki_Renderer { /** * HTML version of analysed text. */ private $_newtext ; private $_isBlocOpen =false; /** * Current opened block element. */ private $_currentBloc ; /** * List of available blocks. */ private $_blocList = array (); /** * List of parameters for the engine. */ public $params = array (); /** * Inline parser for the Wiki Inline tags. */ public $inlineParser =null; /** * List of lines with wiki errors. */ public $errors ; /** * Config object to customized the renderer. */ public $config =null; /** * Constructor of the renderer. * * Create the needed objects for the rendering. * * @param Configuration Custom configuration object (null) */ function __construct( $config =null) { if ( is_null ( $config )) { $this ->config = new Pluf_Text_Wiki_Configuration(); } else { $this ->config = $config ; } // Gost block $this ->_currentBloc = new Pluf_Text_Wiki_BlockRenderer( $this ); $this ->inlineParser = new Pluf_Text_Wiki_InlineParser( $this ->config->inlinetags, $this ->config->simpletags, $this ->config->inlineTagSeparator, $this ->config->checkWikiWord, $this ->config->checkWikiWordFunction, $this ->config->escapeSpecialChars ); foreach ( $this ->config->bloctags as $name => $ok ) { if ( $ok ) { $this ->_blocList[] = new $name ( $this ); } } } /** * Main method to convert the wiki text into XHTML. * * @param string Text to be converted. * @return string Converted text into XHTML. */ function render( $text ) { // Split on \r (mac), \n (unix) or \r\n (windows) $lignes = preg_split( "/\015\012|\015|\012/" , $text ); $this ->_newtext = array (); $this ->_isBlocOpen = false; $this ->errors = false; $this ->_currentBloc = new Pluf_Text_Wiki_BlockRenderer( $this ); // Go through all the lines. foreach ( $lignes as $num => $ligne ) { if ( $ligne == '' ) { // pas de trim � cause des pre // ligne vide $this ->_closeBloc(); } else { // detection de debut de bloc (liste, tableau, hr, titre) foreach ( $this ->_blocList as $bloc ) { if ( $bloc ->detect( $ligne )) { break ; } } // c'est le debut d'un bloc (ou ligne d'un bloc en cours) if ( $bloc -> getType () != $this ->_currentBloc-> getType ()) { // on ferme le precedent si c'etait un different $this ->_closeBloc(); $this ->_currentBloc = $bloc ; if ( $this ->_openBloc()) { $this ->_newtext[] = $this ->_currentBloc->getRenderedLine(); } else { $this ->_newtext[] = $this ->_currentBloc->getRenderedLine(); $this ->_newtext[] = $this ->_currentBloc->close(); $this ->_isBlocOpen = false; $this ->_currentBloc = new Pluf_Text_Wiki_BlockRenderer( $this ); } } else { $this ->_currentBloc->setMatch( $bloc ->getMatch()); $this ->_newtext[] = $this ->_currentBloc->getRenderedLine(); } if ( $this ->inlineParser->getError()) { $this ->errors[ $num +1] = $ligne ; } } } $this ->_closeBloc(); return implode( "\n" , $this ->_newtext); } /** * Returns configuration object. * * @return WikiRendererConfig */ function getConfig() { return $this ->config; } /** * Retourne l'objet inlineParser (WikiInlineParser) utilis� dans le moteur * @access public * @see WikiInlineParser * @return WikiInlineParser */ function getInlineParser() { return $this ->inlineParser; } /** * renvoi la liste des erreurs detect�es par le moteur * @access public * @return array */ function getErrors() { return $this ->errors; } /** * renvoi la version de wikirenderer * @access public * @return string version */ function getVersion() { return '2.1' ; } /** * ferme un bloc * @access private */ function _closeBloc() { if ( $this ->_isBlocOpen) { $this ->_isBlocOpen = false; $this ->_newtext[] = $this ->_currentBloc->close(); $this ->_currentBloc = new Pluf_Text_Wiki_BlockRenderer( $this ); } } /** * ouvre un bloc et le referme eventuellement suivant sa nature * @return boolean indique si le bloc reste ouvert ou pas * @access private */ function _openBloc() { if (! $this ->_isBlocOpen) { $this ->_newtext[] = $this ->_currentBloc->open(); $this ->_isBlocOpen = true; return ! $this ->_currentBloc->closeNow(); } else { return true; } } } |