[ 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/inc/ -> wikirenderer_xhtml.conf.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /**
   4   * WikiRenderer Configuration for the xhtml output in Plume CMS.
   5   *
   6   * @author Laurent Jouanneau <jouanneau@netcourrier.com>
   7   * @copyright 2003 Laurent Jouanneau
   8   * @module Wiki Renderer
   9   * @version 2.0RC1
  10   * @since 20/12/2003
  11   *
  12   * @author Loic d'Anterroches
  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   */
  29  
  30  
  31  class WikiRenderXhtmlConfig 
  32  {
  33      /**
  34       * @var array inline tags
  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'), 
  41                                           null),
  42                              'cite' => array('{{', '}}', array('title'), null),
  43                              'acronym' => array('??', '??', array('title'), 
  44                                                 null),
  45                              'link' => array('[', ']', 
  46                                              array('href', 'lang', 'title'),
  47                                              'xhtml_buildlink'),
  48                              'image' => array('((', '))', 
  49                                               array('src', 'alt', 'align',
  50                                                     'longdesc'),
  51                                               'xhtml_wikibuildimage'),
  52                              'anchor' => array('~~', '~~', array('id'), 
  53                                                'xhtml_wikibuildanchor')
  54                              );
  55  
  56      /**
  57       * @var array block tags, the order is important
  58       */
  59      var $bloctags = array(
  60                            'title' => true, 
  61                            'list' => true, 
  62                            'pre' => true,
  63                            'hr' => true, 
  64                            'blockquote' => true, 
  65                            'definition' => true, 
  66                            'tableth' => true, 
  67                            'gallery' => true, 
  68                            'p' => true
  69                            );
  70      
  71      /**
  72       * @var array simple tags, direct replacement
  73       */
  74      var $simpletags = array('%%%' => '<br />');
  75  
  76      /**
  77       * @var integer Minimal level for the titles
  78       */
  79      var $minHeaderLevel = 2;
  80      var $headerOrder = false;
  81      var $blocAttributeTag = '°°';
  82      var $inlineTagSeparator = '|';
  83      var $escapeSpecialChars = true;
  84      var $checkWikiWord = false; //Not used into a wiki
  85      var $checkWikiWordFunction = null;
  86  }
  87  
  88  /** ------------------------------------------------------ *
  89   *  Needed functions for the generations of the XHTML code *
  90   *  ------------------------------------------------------ *
  91   */
  92  
  93  /**
  94   * Generation of the image. It generates also the image in the
  95   * case of the gallery.
  96   */
  97  function xhtml_wikibuildimage($contents, $attr)
  98  {
  99      $baseurl = www::getManagedWebsiteUrl();
 100      $cnt = count($contents);
 101      $attribs = array();
 102      if ($cnt > 4) $cnt=4;
 103      switch ($cnt){
 104      case 4:
 105          $attribs['longdesc'] = $contents[3];
 106      case 3:
 107          // multiple arguments can be passed in any order in the
 108          // the form of "arg1:arg2:arg3" these include alignement,
 109          // type, size of the thumbnail
 110          if (!isset($contents[2])) {
 111              $contents[2] = '';
 112          }
 113          $contents[2] = ':'.$contents[2].':';
 114          // simple alignement put in style.
 115          if (preg_match('/\:(l|g|r|d|c)\:/i',$contents[2],$match)) {
 116              $match[1] = strtolower($match[1]);
 117              if ($match[1]=='l' || $match[1]=='g') {
 118                  $attribs['class'] = 'px-left';
 119              } elseif ($match[1]=='r' ||  $match[1]=='d') {
 120                  $attribs['class'] = 'px-right';
 121              } elseif ($match[1]=='c') {
 122                  $attribs['class'] = 'px-center';
 123              }
 124          } 
 125          // is it a gallery? (need the wrapping div)
 126          if (preg_match('/\:gal/i', $contents[2])) {
 127              $attribs['gallery'] = true;
 128              // default max sizes
 129              $attribs['width'] = 200;
 130              $attribs['height'] = 200;
 131          } 
 132          // is it a link through thumbnail?
 133          if (preg_match('/\:([0-9]+)x([0-9]+)\:/i', $contents[2], $match)) {
 134              $attribs['width'] = (int) $match[1];
 135              $attribs['height'] = (int) $match[2];
 136          }
 137      case 2:
 138          $attribs['alt'] = $contents[1];
 139      case 1:
 140      default:
 141          if (ereg('^/',$contents[0])) {
 142              $attribs['file'] = $contents[0];
 143              $contents[0] = $baseurl.$contents[0];
 144          }
 145          $attribs['src'] = $contents[0];
 146      }
 147  
 148      if (!isset($attribs['alt'])) $attribs['alt'] = '';
 149      if (!isset($attribs['style'])) $attribs['style'] = '';
 150  
 151      // Need to generate the thumbnail if needed, this is done
 152      // only for locale files.
 153      $ok = false;
 154      if (!empty($attribs['width']) && !empty($attribs['file'])) {
 155          include_once dirname(__FILE__).'/class.thumbnail.php';
 156  
 157          $thumbdir = config::f('xmedia_root').'/thumb';
 158          $thumb = new thumbnail($thumbdir);
 159          $thumbfile = $thumb->getPath($attribs['file'], 
 160                                       $attribs['width'], 
 161                                       $attribs['height']);
 162          $thumburl = '';
 163          $thumbsize = array();
 164          $ok = true;
 165          if (!file_exists($thumbfile)) {
 166              // create thumbnail and get url to it
 167              $doc_root = www::getDocumentRoot();
 168              $ok = $thumb->create($doc_root.$attribs['file'], 
 169                                   $thumbfile, $attribs['width'], 
 170                                   $attribs['height']);
 171              if ($ok) {
 172                  $thumburl = config::f('rel_url_files').'/thumb/'
 173                      .$thumb->getName($attribs['file'], 
 174                                       $attribs['width'], 
 175                                       $attribs['height']);
 176                  $thumbsize = $thumb->getSize();
 177              } else {
 178                  return 'Error building thumbnail: '.$attribs['file'].'<br />';
 179              }
 180          } else {
 181              // the thumbnail already exists, get the info from the file
 182              $thumburl = config::f('rel_url_files').'/thumb/'
 183                  .$thumb->getName($attribs['file'], 
 184                                   $attribs['width'], 
 185                                   $attribs['height']);
 186              $thumbsize = getimagesize($thumbfile);
 187          }
 188      }
 189  
 190      // need to generate the HTML depending of the request.
 191  
 192      if (empty($attribs['gallery'])) {
 193          if (empty($attribs['width'])) {
 194              // simple image
 195              $c = ' ';
 196              foreach ($attribs as $k => $v) {
 197                  if ($k != 'file') $c .= $k.'="'.$v.'" ';
 198              }
 199              return '<img'.$c.'/>';
 200          } else {
 201              // thumbnail.
 202              if ($ok) {
 203                  return '<a href="'.$attribs['src'].'" title="'
 204                      .$attribs['alt'].'"><img src="'.$thumburl.'" alt="" '
 205                      .$thumbsize[3].' style="'.$attribs['style'].'"/></a>';
 206              }
 207          }
 208      } else {
 209          // gallery layout
 210          if ($ok) {
 211              return '<div class="gallery-img"><a href="'.$attribs['src']
 212                  .'" title="'.$attribs['alt'].'"><img class="gallery-thumb" '
 213                  .'src="'.$thumburl.'" alt="" '.$thumbsize[3]
 214                  .' /></a><p class="gallery-legend">'.$attribs['longdesc']
 215                  .'</p></div>'."\n";
 216          }
 217      }
 218  }
 219  
 220  function xhtml_wikibuildanchor($contents, $attr){
 221      return '<a id="'.$contents[0].'"></a>';
 222  }
 223  
 224  
 225  
 226  class xhtml_gallery extends WikiRendererBloc
 227  {
 228      var $type = 'gallery';
 229      var $regexp = '/^\$(.*)/';
 230      var $_openTag = "<div class=\"gallery\">\n<div class=\"gallery-top\">\n&nbsp;\n</div>";
 231      var $_closeTag = "<div class=\"gallery-bottom\">\n&nbsp;\n</div></div>";
 232  
 233      function getRenderedLine()
 234      {
 235          return $this->_renderInlineTag($this->_detectMatch[1]);
 236      }
 237  
 238  }
 239  
 240  /**
 241   * traite les signes de types table
 242   */
 243  class xhtml_tableth extends WikiRendererBloc 
 244  {
 245      var $type='table';
 246      var $regexp="/^\| ?(.*)/";
 247      var $_openTag='<table class="wiki-table">';
 248      var $_closeTag='</table>';
 249      var $_colcount=0;
 250  
 251      function open()
 252      {
 253          $this->_colcount=0;
 254          return $this->_openTag;
 255      }
 256      
 257      function getRenderedLine()
 258      {
 259      
 260          $result=explode(' | ',trim($this->_detectMatch[1]));
 261          $str='';
 262          $t='';
 263      
 264          if((count($result) != $this->_colcount) && ($this->_colcount!=0))
 265              $t='</table><table class="wiki-table">';
 266          $this->_colcount=count($result);
 267      
 268          for($i=0; $i < $this->_colcount; $i++){
 269              if (preg_match('/\s*!(.*)!\s*$/', $result[$i], $match)) {
 270                  $str .= '<th>'. $this->_renderInlineTag($match[1]).'</th>';
 271              } else {
 272                  $str.='<td>'. $this->_renderInlineTag($result[$i]).'</td>';
 273              }
 274          }
 275          $str=$t.'<tr>'.$str.'</tr>';
 276      
 277          return $str;
 278      }
 279  
 280  }
 281  
 282  
 283  function xhtml_buildlink($contents, $attr)
 284  {
 285      global $_PX_context;
 286      $baseurl = '';
 287      if (!empty($_PX_context['out'])) {
 288          $baseurl = $_PX_context['out'];
 289      }
 290      $cnt=count($contents);
 291      $attribut='';
 292      if ($cnt>1) {
 293          if (preg_match('#^xlink://(.+)#',$contents[1],$preg)) {
 294              $data = explode('/',$preg[1]);
 295              if (count($data) == 1) {
 296                  $id   = $data[0];
 297                  $type = '';
 298              } elseif (count($data) > 1) {
 299                  $id   = $data[0];
 300                  $type = $data[1];
 301              }
 302              return text::XlinkCreate($id,$type,$contents[0]);
 303          } 
 304          if ($cnt> count($attr))
 305              $cnt=count($attr)+1;
 306          if (strpos($contents[1],'javascript:')!==false) // for security reason
 307              $contents[1]='#';
 308          if (ereg('^/',$contents[1]))
 309              $contents[1] = $baseurl.$contents[1];
 310          if (ereg('^mailto:',$contents[1])) {
 311              $contents[1] = 'mailto:'.text::HexEncode(substr($contents[1],7));
 312              $contents[0] = text::HexEncode($contents[0], true);
 313          }
 314          for ($i=1;$i<$cnt;$i++){
 315              $attribut.=' '.$attr[$i-1].'="'.$contents[$i].'"';
 316          }
 317      } elseif ($cnt == 1) {
 318          if (preg_match('#^xlink://(.+)#',$contents[0],$preg)) {
 319              $data = explode('/',$preg[1]);
 320              if (count($data) == 1) {
 321                  $id   = $data[0];
 322                  $type = '';
 323              } elseif (count($data) > 1) {
 324                  $id   = $data[0];
 325                  $type = $data[1];
 326              }
 327              return text::XlinkCreate($id,$type,'');
 328          }
 329          if (strpos($contents[0],'javascript:')!==false) // for security reason
 330              $contents[0]='#';
 331          if (ereg('^/',$contents[0]))
 332              $contents[0] = $baseurl.$contents[0];
 333      
 334          $attribut=' href="'.$contents[0].'"';
 335          if (strlen($contents[0]) > 40)
 336              $contents[0]=substr($contents[0],0,40).'(..)';
 337      }
 338      if ($cnt >= 1) 
 339          return '<a'.$attribut.'>'.$contents[0].'</a>';
 340      return '';
 341      
 342  }
 343  
 344  
 345  /**
 346   * traite les signes de types liste
 347   */
 348  class xhtml_list extends WikiRendererBloc 
 349  {
 350  
 351      var $_previousTag;
 352      var $_firstItem;
 353      var $_firstTagLen;
 354      var $type='list';
 355      var $regexp="/^([\*#-]+)(.*)/";
 356  
 357      function open()
 358      {
 359          $this->_previousTag = $this->_detectMatch[1];
 360          $this->_firstTagLen = strlen($this->_previousTag);
 361          $this->_firstItem=true;
 362  
 363          if (substr($this->_previousTag,-1,1) == '#')
 364              return "<ol>\n";
 365          else
 366              return "<ul>\n";
 367      }
 368  
 369      function close()
 370      {
 371          $t=$this->_previousTag;
 372          $str='';
 373  
 374          for ($i=strlen($t); $i >= $this->_firstTagLen; $i--){
 375              $str.=($t{$i-1}== '#'?"</li></ol>\n":"</li></ul>\n");
 376          }
 377          return $str;
 378      }
 379  
 380      function getRenderedLine()
 381      {
 382          $t=$this->_previousTag;
 383          $d=strlen($t) - strlen($this->_detectMatch[1]);
 384          $str='';
 385  
 386          if ( $d > 0 ){ // on remonte d'un ou plusieurs cran dans la hierarchie...
 387              $l=strlen($this->_detectMatch[1]);
 388              for($i=strlen($t); $i>$l; $i--){
 389                  $str.=($t{$i-1}== '#'?"</li></ol>\n":"</li></ul>\n");
 390              }
 391              $str.="</li>\n<li>";
 392              $this->_previousTag=substr($this->_previousTag,0,-$d); // pour être sur...
 393  
 394          } elseif ( $d < 0 ){ // un niveau de plus
 395              $c=substr($this->_detectMatch[1],-1,1);
 396              $this->_previousTag.=$c;
 397              $str=($c == '#'?"<ol>\n<li>":"<ul>\n<li>");
 398  
 399          } else {
 400              $str=($this->_firstItem ? '<li>':'</li><li>');
 401          }
 402          $this->_firstItem=false;
 403          return $str.$this->_renderInlineTag($this->_detectMatch[2]);
 404      }
 405  }
 406  
 407  
 408  /**
 409   * traite les signes de types hr
 410   */
 411  class xhtml_hr extends WikiRendererBloc 
 412  {
 413  
 414      var $type='hr';
 415      var $regexp='/^={4,} *$/';
 416      var $_closeNow=true;
 417  
 418      function getRenderedLine(){
 419          return '<hr />';
 420      }
 421  
 422  }
 423  
 424  /**
 425   * traite les signes de types titre
 426   */
 427  class xhtml_title extends WikiRendererBloc 
 428  {
 429      var $type='title';
 430      var $regexp="/^(\!{1,3})(.*)/";
 431      var $_closeNow=true;
 432      var $_minlevel=1;
 433      var $_order=false;
 434  
 435      function WRB_title(&$wr)
 436      {
 437          $this->_minlevel = $wr->config->minHeaderLevel;
 438          $this->_order = $wr->config->headerOrder;
 439          parent::WikiRendererBloc($wr);
 440      }
 441  
 442      function getRenderedLine()
 443      {
 444          if($this->_order)
 445              $hx= $this->_minlevel + strlen($this->_detectMatch[1])-1;
 446          else
 447              $hx= $this->_minlevel + 3-strlen($this->_detectMatch[1]);
 448          return '<h'.$hx.'>'.$this->_renderInlineTag($this->_detectMatch[2]).'</h'.$hx.'>';
 449      }
 450  }
 451  
 452  /**
 453   * traite les signes de type paragraphe
 454   */
 455  class xhtml_p extends WikiRendererBloc 
 456  {
 457      var $type='p';
 458      var $regexp="/(.*)/";
 459      var $_openTag='<p>';
 460      var $_closeTag='</p>';
 461  }
 462  
 463  /**
 464   * traite les signes de types pre (pour afficher du code..)
 465   */
 466  class xhtml_pre extends WikiRendererBloc 
 467  {
 468  
 469      var $type='pre';
 470      var $regexp="/^ (.*)/";
 471      var $_openTag='<pre>';
 472      var $_closeTag='</pre>';
 473  
 474      function getRenderedLine()
 475      {
 476          return $this->_renderInlineTag($this->_detectMatch[1]);
 477      }
 478  
 479  }
 480  
 481  
 482  /**
 483   * traite les signes de type blockquote
 484   */
 485  class xhtml_blockquote extends WikiRendererBloc 
 486  {
 487      var $type='bq';
 488      var $regexp="/^(\>+)(.*)/";
 489  
 490      function open()
 491      {
 492          $this->_previousTag = $this->_detectMatch[1];
 493          $this->_firstTagLen = strlen($this->_previousTag);
 494          $this->_firstLine = true;
 495          return str_repeat('<blockquote>',$this->_firstTagLen).'<p>';
 496      }
 497  
 498      function close()
 499      {
 500          return '</p>'.str_repeat('</blockquote>',strlen($this->_previousTag));
 501      }
 502  
 503  
 504      function getRenderedLine()
 505      {
 506  
 507          $d=strlen($this->_previousTag) - strlen($this->_detectMatch[1]);
 508          $str='';
 509  
 510          if( $d > 0 ){ // on remonte d'un cran dans la hierarchie...
 511              $str='</p>'.str_repeat('</blockquote>',$d).'<p>';
 512              $this->_previousTag=$this->_detectMatch[1];
 513          }elseif( $d < 0 ){ // un niveau de plus
 514              $this->_previousTag=$this->_detectMatch[1];
 515              $str='</p>'.str_repeat('<blockquote>',-$d).'<p>';
 516          }else{
 517              if($this->_firstLine)
 518                  $this->_firstLine=false;
 519              else
 520                  $str='<br />';
 521          }
 522          return $str.$this->_renderInlineTag($this->_detectMatch[2]);
 523      }
 524  }
 525  
 526  /**
 527   * traite les signes de type blockquote
 528   */
 529  class xhtml_definition extends WikiRendererBloc 
 530  {
 531  
 532      var $type='dfn';
 533      var $regexp="/^;(.*) : (.*)/i";
 534      var $_openTag='<dl>';
 535      var $_closeTag='</dl>';
 536  
 537      function getRenderedLine()
 538      {
 539          $dt=$this->_renderInlineTag($this->_detectMatch[1]);
 540          $dd=$this->_renderInlineTag($this->_detectMatch[2]);
 541          return "<dt>$dt</dt>\n<dd>$dd</dd>\n";
 542      }
 543  }
 544  
 545  
 546  ?>


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