[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/extinc/ -> WikiRenderer.conf.php (source)

   1  <?php
   2  
   3  /**
   4   * Bibliotheque d'objets permettant de tranformer un texte, contenant des signes de formatages
   5   * simples de type wiki, en un autre format tel que XHTML 1.0/strict
   6   * @author Laurent Jouanneau <jouanneau@netcourrier.com>
   7   * @copyright 2003-2004 Laurent Jouanneau
   8   * @module Wiki Renderer
   9   * @version 2.0dev-php5
  10   * @since 28/11/2004
  11   * http://ljouanneau.com/softs/wikirenderer/
  12   * Thanks to all users who found bugs : Loic, Edouard Guerin, Sylvain, Ludovic L.
  13   *
  14   * This library is free software; you can redistribute it and/or
  15   * modify it under the terms of the GNU Lesser General Public
  16   * License as published by the Free Software Foundation; either
  17   * version 2.1 of the License, or (at your option) any later version.
  18   *
  19   * This library is distributed in the hope that it will be useful,
  20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22   * Lesser General Public License for more details.
  23   *
  24   * You should have received a copy of the GNU Lesser General Public
  25   * License along with this library; if not, write to the Free Software
  26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  27   * -----------------------------------------------------------------------------
  28   * Adapatation PHP5 : Edouard Guérin <eguerin@icitrus.net>
  29   */
  30  
  31  class WikiRendererConfig {
  32      /**
  33       * @var array   liste des tags inline
  34       */
  35  
  36      var $inlinetags= array(
  37           'strong' =>array('__','__',      null,null),
  38           'em'     =>array('\'\'','\'\'',  null,null),
  39           'code'   =>array('@@','@@',      null,null),
  40           'q'      =>array('^^','^^',      array('lang','cite'),null),
  41           'cite'   =>array('{{','}}',      array('title'),null),
  42           'acronym'=>array('??','??',      array('title'),null),
  43           'link'   =>array('[',']',        array('href','hreflang','title'),'wikibuildlink'),
  44           'image'  =>array('((','))',      array('src','alt','align','longdesc'),'wikibuildimage'),
  45           'anchor' =>array('~~','~~',      array('id'),'wikibuildanchor')
  46      );
  47  
  48      /**
  49       * liste des balises de type bloc autorisées.
  50       * Attention, ordre important (p en dernier, car c'est le bloc par defaut..)
  51       */
  52  
  53      var $bloctags = array(
  54          'title'=>true,
  55          'list'=>true,
  56          'pre'=>true,
  57          'hr'=>true,
  58          'blockquote'=>true,
  59          'definition'=>true,
  60          'table'=>true,
  61          'p'=>true
  62      );
  63  
  64  
  65      var $simpletags = array('%%%'=>'<br />', ':-)'=>'<img src="laugh.png" alt=":-)" />');
  66  
  67      /**
  68       * @var   integer   niveau minimum pour les balises titres
  69       */
  70  
  71      var $minHeaderLevel=3;
  72  
  73  
  74      /**
  75       * indique le sens dans lequel il faut interpreter le nombre de signe de titre
  76       * true -> ! = titre , !! = sous titre, !!! = sous-sous-titre
  77       * false-> !!! = titre , !! = sous titre, ! = sous-sous-titre
  78       */
  79  
  80      var $headerOrder=false;
  81      var $escapeSpecialChars=true;
  82      var $inlineTagSeparator='|';
  83      var $blocAttributeTag='°°';
  84  
  85      var $checkWikiWord = false;
  86      var $checkWikiWordFunction = null;
  87  
  88  }
  89  
  90  // ===================================== fonctions de générateur de code HTML spécifiques à certaines balises inlines
  91  
  92  function wikibuildlink($contents, $attr){
  93     $cnt=count($contents);
  94     $attribut='';
  95  
  96     if($cnt >1){
  97        if($cnt> count($attr))
  98           $cnt=count($attr)+1;
  99        if(strpos($contents[1],'javascript:')!==false) // for security reason
 100           $contents[1]='#';
 101  
 102        for($i=1;$i<$cnt;$i++){
 103           $attribut.=' '.$attr[$i-1].'="'.$contents[$i].'"';
 104        }
 105     }else{
 106        if(strpos($contents[0],'javascript:')!==false) // for security reason
 107           $contents[0]='#';
 108        $attribut=' href="'.$contents[0].'"';
 109        if(strlen($contents[0]) > 40)
 110           $contents[0]=substr($contents[0],0,40).'(..)';
 111     }
 112     return '<a'.$attribut.'>'.$contents[0].'</a>';
 113  }
 114  
 115  function wikibuildanchor($contents, $attr){
 116     return '<a id="'.$contents[0].'"></a>';
 117  }
 118  
 119  function wikibuilddummie($contents, $attr){
 120     return (isset($contents[0])?$contents[0]:'');
 121  }
 122  
 123  function wikibuildimage($contents, $attr){
 124     $cnt=count($contents);
 125     $attribut='';
 126     if($cnt > 4) $cnt=4;
 127     switch($cnt){
 128        case 4:
 129           $attribut.=' longdesc="'.$contents[3].'"';
 130        case 3:
 131           if($contents[2]=='l' ||$contents[2]=='L' || $contents[2]=='g' || $contents[2]=='G')
 132              $attribut.=' style="float:left;"';
 133           elseif($contents[2]=='r' ||$contents[2]=='R' || $contents[2]=='d' || $contents[2]=='D')
 134              $attribut.=' style="float:right;"';
 135        case 2:
 136           $attribut.=' alt="'.$contents[1].'"';
 137        case 1:
 138        default:
 139           $attribut.=' src="'.$contents[0].'"';
 140           if($cnt == 1) $attribut.=' alt=""';
 141     }
 142     return '<img'.$attribut.' />';
 143  
 144  }
 145  
 146  
 147  // ===================================== déclaration des différents bloc wiki
 148  
 149  /**
 150   * traite les signes de types liste
 151   */
 152  class WRB_list extends WikiRendererBloc {
 153  
 154      var $_previousTag;
 155      var $_firstItem;
 156      var $_firstTagLen;
 157  
 158      function WRB_list($wr) {
 159          parent::WikiRendererBloc($wr);
 160          $this->type   = 'list';
 161          $this->regexp = "/^([\*#-]+)(.*)/";
 162      }
 163  
 164      function open() {
 165          $this->_previousTag = $this->_detectMatch[1];
 166          $this->_firstTagLen = strlen($this->_previousTag);
 167          $this->_firstItem=true;
 168  
 169          if(substr($this->_previousTag,-1,1) == '#')
 170              return "<ol>\n";
 171          else
 172              return "<ul>\n";
 173      }
 174  
 175      function close(){
 176          $t=$this->_previousTag;
 177          $str='';
 178  
 179          for($i=strlen($t); $i >= $this->_firstTagLen; $i--) {
 180              $str.=($t{$i-1}== '#'?"</li></ol>\n":"</li></ul>\n");
 181          }
 182          return $str;
 183      }
 184  
 185      function getRenderedLine(){
 186          $t=$this->_previousTag;
 187          $d=strlen($t) - strlen($this->_detectMatch[1]);
 188          $str='';
 189  
 190          if( $d > 0 ){ // on remonte d'un ou plusieurs cran dans la hierarchie...
 191              $l=strlen($this->_detectMatch[1]);
 192              for($i=strlen($t); $i>$l; $i--){
 193                  $str.=($t{$i-1}== '#'?"</li></ol>\n":"</li></ul>\n");
 194              }
 195              $str.="</li>\n<li>";
 196              $this->_previousTag=substr($this->_previousTag,0,-$d); // pour être sur...
 197  
 198          }
 199          elseif( $d < 0 ) { // un niveau de plus
 200              $c=substr($this->_detectMatch[1],-1,1);
 201              $this->_previousTag.=$c;
 202              $str=($c == '#'?"<ol>\n<li>":"<ul>\n<li>");
 203          }
 204          else {
 205              $str=($this->_firstItem ? '<li>':'</li><li>');
 206          }
 207          $this->_firstItem=false;
 208          return $str.$this->_renderInlineTag($this->_detectMatch[2]);
 209      }
 210  
 211  }
 212  
 213  
 214  /**
 215   * traite les signes de types table
 216   */
 217  class WRB_table extends WikiRendererBloc {
 218  
 219      var $_colcount = 0;
 220  
 221      function WRB_table($wr) {
 222          parent::WikiRendererBloc($wr);
 223          $this->type      = 'table';
 224          $this->regexp    = "/^\| ?(.*)/";
 225          $this->_openTag  = '<table class="wiki-table">';
 226          $this->_closeTag = '</table>';
 227      }
 228  
 229      function open() {
 230          $this->_colcount=0;
 231          return $this->_openTag;
 232      }
 233  
 234      function getRenderedLine() {
 235  
 236          $result=explode(' | ',trim($this->_detectMatch[1]));
 237          $str='';
 238          $t='';
 239  
 240          if((count($result) != $this->_colcount) && ($this->_colcount!=0))
 241              $t='</table><table class="wiki-table">';
 242              $this->_colcount=count($result);
 243  
 244          for($i=0; $i < $this->_colcount; $i++) {
 245              $str.='<td>'. $this->_renderInlineTag($result[$i]).'</td>';
 246          }
 247          $str=$t.'<tr>'.$str.'</tr>';
 248  
 249          return $str;
 250      }
 251  
 252  }
 253  
 254  /**
 255   * traite les signes de types hr
 256   */
 257  class WRB_hr extends WikiRendererBloc {
 258  
 259      function WRB_hr($wr) {
 260          parent::WikiRendererBloc($wr);
 261          $this->type      = 'hr';
 262          $this->regexp    = '/^={4,} *$/';
 263          $this->_closeNow = true;
 264      }
 265  
 266      function getRenderedLine(){
 267         return '<hr />';
 268      }
 269  
 270  }
 271  
 272  /**
 273   * traite les signes de types titre
 274   */
 275  class WRB_title extends WikiRendererBloc {
 276  
 277      var $_minlevel = 1;
 278      var $_order = false;
 279  
 280      function WRB_title($wr){
 281          parent::WikiRendererBloc($wr);
 282          $this->type      = 'title';
 283          $this->regexp    = "/^(\!{1,3})(.*)/";
 284          $this->_closeNow  = true;
 285          $cfg = $wr->getConfig();
 286          $this->_minlevel = $cfg->minHeaderLevel;
 287          $this->_order    = $cfg->headerOrder;
 288      }
 289  
 290      function getRenderedLine() {
 291          if($this->_order)
 292              $hx= $this->_minlevel + strlen($this->_detectMatch[1])-1;
 293          else
 294              $hx= $this->_minlevel + 3-strlen($this->_detectMatch[1]);
 295          return '<h'.$hx.'>'.$this->_renderInlineTag($this->_detectMatch[2]).'</h'.$hx.'>';
 296      }
 297  }
 298  
 299  /**
 300   * traite les signes de type paragraphe
 301   */
 302  class WRB_p extends WikiRendererBloc {
 303  
 304      function WRB_p($wr) {
 305          parent::WikiRendererBloc($wr);
 306          $this->type      = 'p';
 307          $this->regexp    = "/(.*)/";
 308          $this->_openTag  = '<p>';
 309          $this->_closeTag ='</p>';
 310      }
 311  }
 312  
 313  /**
 314   * traite les signes de types pre (pour afficher du code..)
 315   */
 316  class WRB_pre extends WikiRendererBloc {
 317  
 318      function WRB_pre($wr) {
 319          parent::WikiRendererBloc($wr);
 320          $this->type      = 'pre';
 321          $this->regexp    = "/^ (.*)/";
 322          $this->_openTag  = '<pre>';
 323          $this->_closeTag ='</pre>';
 324      }
 325  
 326      function getRenderedLine() {
 327          return $this->_renderInlineTag($this->_detectMatch[1]);
 328      }
 329  
 330  }
 331  
 332  
 333  /**
 334   * traite les signes de type blockquote
 335   */
 336  class WRB_blockquote extends WikiRendererBloc {
 337  
 338      var $_previousTag;
 339      var $_firstTagLen;
 340      var $_firstLine;
 341  
 342      function WRB_blockquote($wr) {
 343          parent::WikiRendererBloc($wr);
 344          $this->type   = 'bq';
 345          $this->regexp = "/^(\>+)(.*)/";
 346      }
 347  
 348      function open() {
 349          $this->_previousTag = $this->_detectMatch[1];
 350          $this->_firstTagLen = strlen($this->_previousTag);
 351          $this->_firstLine = true;
 352          return str_repeat('<blockquote>',$this->_firstTagLen).'<p>';
 353     }
 354  
 355      function close() {
 356          return '</p>'.str_repeat('</blockquote>',strlen($this->_previousTag));
 357      }
 358  
 359      function getRenderedLine() {
 360  
 361          $d=strlen($this->_previousTag) - strlen($this->_detectMatch[1]);
 362          $str='';
 363  
 364          if( $d > 0 ){ // on remonte d'un cran dans la hierarchie...
 365              $str='</p>'.str_repeat('</blockquote>',$d).'<p>';
 366              $this->_previousTag=$this->_detectMatch[1];
 367          }
 368          elseif( $d < 0 ) { // un niveau de plus
 369              $this->_previousTag=$this->_detectMatch[1];
 370              $str='</p>'.str_repeat('<blockquote>',-$d).'<p>';
 371          }
 372          else {
 373              if($this->_firstLine)
 374                  $this->_firstLine=false;
 375              else
 376                  $str='<br />';
 377          }
 378          return $str.$this->_renderInlineTag($this->_detectMatch[2]);
 379      }
 380  }
 381  
 382  /**
 383   * traite les signes de type définitions
 384   */
 385  class WRB_definition extends WikiRendererBloc {
 386  
 387      function WRB_definition($wr) {
 388          parent::WikiRendererBloc($wr);
 389          $this->type      = 'dfn';
 390          $this->regexp    = "/^;(.*) : (.*)/i";
 391          $this->_openTag  = '<dl>';
 392          $this->_closeTag ='</dl>';
 393      }
 394  
 395      function getRenderedLine() {
 396          $dt=$this->_renderInlineTag($this->_detectMatch[1]);
 397          $dd=$this->_renderInlineTag($this->_detectMatch[2]);
 398          return "<dt>$dt</dt>\n<dd>$dd</dd>\n";
 399      }
 400  }
 401  
 402  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics