[ Index ]
 

Code source de DokuWiki 2006-11-06

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/inc/parser/ -> xhtml.php (source)

   1  <?php
   2  /**
   3   * Renderer for XHTML output
   4   *
   5   * @author Harry Fuecks <hfuecks@gmail.com>
   6   * @author Andreas Gohr <andi@splitbrain.org>
   7   */
   8  
   9  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
  10  
  11  if ( !defined('DOKU_LF') ) {
  12      // Some whitespace to help View > Source
  13      define ('DOKU_LF',"\n");
  14  }
  15  
  16  if ( !defined('DOKU_TAB') ) {
  17      // Some whitespace to help View > Source
  18      define ('DOKU_TAB',"\t");
  19  }
  20  
  21  require_once  DOKU_INC . 'inc/parser/renderer.php';
  22  require_once  DOKU_INC . 'inc/html.php';
  23  
  24  /**
  25   * The Renderer
  26   */
  27  class Doku_Renderer_xhtml extends Doku_Renderer {
  28  
  29      // @access public
  30      var $doc = '';        // will contain the whole document
  31      var $toc = array();   // will contain the Table of Contents
  32  
  33  
  34      var $headers = array();
  35  
  36      var $footnotes = array();
  37  
  38      var $acronyms = array();
  39      var $smileys = array();
  40      var $badwords = array();
  41      var $entities = array();
  42      var $interwiki = array();
  43  
  44      var $lastsec = 0;
  45  
  46      var $store = '';
  47  
  48      function document_start() {
  49          //reset some internals
  50          $this->toc     = array();
  51          $this->headers = array();
  52      }
  53  
  54      function document_end() {
  55          if ( count ($this->footnotes) > 0 ) {
  56              $this->doc .= '<div class="footnotes">'.DOKU_LF;
  57  
  58              $id = 0;
  59              foreach ( $this->footnotes as $footnote ) {
  60                  $id++;   // the number of the current footnote
  61  
  62                  // check its not a placeholder that indicates actual footnote text is elsewhere
  63                  if (substr($footnote, 0, 5) != "@@FNT") {
  64  
  65                      // open the footnote and set the anchor and backlink
  66                      $this->doc .= '<div class="fn">';
  67                      $this->doc .= '<a href="#fnt__'.$id.'" id="fn__'.$id.'" name="fn__'.$id.'" class="fn_bot">';
  68                      $this->doc .= $id.')</a> '.DOKU_LF;
  69  
  70                      // get any other footnotes that use the same markup
  71                      $alt = array_keys($this->footnotes, "@@FNT$id");
  72  
  73                      if (count($alt)) {
  74                        foreach ($alt as $ref) {
  75                          // set anchor and backlink for the other footnotes
  76                          $this->doc .= ', <a href="#fnt__'.($ref+1).'" id="fn__'.($ref+1).'" name="fn__'.($ref+1).'" class="fn_bot">';
  77                          $this->doc .= ($ref+1).')</a> '.DOKU_LF;
  78                        }
  79                      }
  80  
  81                      // add footnote markup and close this footnote
  82                      $this->doc .= $footnote;
  83                      $this->doc .= '</div>' . DOKU_LF;
  84                  }
  85              }
  86              $this->doc .= '</div>'.DOKU_LF;
  87          }
  88  
  89          // prepend the TOC
  90          if($this->info['toc']){
  91              $this->doc = $this->render_TOC().$this->doc;
  92          }
  93  
  94          // make sure there are no empty paragraphs
  95          $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc);
  96      }
  97  
  98      /**
  99       * Return the TOC rendered to XHTML
 100       *
 101       * @author Andreas Gohr <andi@splitbrain.org>
 102       */
 103      function render_TOC(){
 104          if(count($this->toc) < 3) return '';
 105          global $lang;
 106          $out  = '<div class="toc">'.DOKU_LF;
 107          $out .= '<div class="tocheader toctoggle" id="toc__header">';
 108          $out .= $lang['toc'];
 109          $out .= '</div>'.DOKU_LF;
 110          $out .= '<div id="toc__inside">'.DOKU_LF;
 111          $out .= html_buildlist($this->toc,'toc',array($this,'_tocitem'));
 112          $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
 113          return $out;
 114      }
 115  
 116      /**
 117       * Callback for html_buildlist
 118       */
 119      function _tocitem($item){
 120          return '<span class="li"><a href="#'.$item['hid'].'" class="toc">'.
 121                 $this->_xmlEntities($item['title']).'</a></span>';
 122      }
 123  
 124      function header($text, $level, $pos) {
 125          global $conf;
 126  
 127          // create a unique header id
 128          $hid = $this->_headerToLink($text,'true');
 129  
 130          //handle TOC
 131          if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
 132              // the TOC is one of our standard ul list arrays ;-)
 133              $this->toc[] = array( 'hid'   => $hid,
 134                                    'title' => $text,
 135                                    'type'  => 'ul',
 136                                    'level' => $level-$conf['toptoclevel']+1);
 137          }
 138  
 139          // write the header
 140          $this->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'">';
 141          $this->doc .= $this->_xmlEntities($text);
 142          $this->doc .= "</a></h$level>".DOKU_LF;
 143      }
 144  
 145       /**
 146       * Section edit marker is replaced by an edit button when
 147       * the page is editable. Replacement done in 'inc/html.php#html_secedit'
 148       *
 149       * @author Andreas Gohr <andi@splitbrain.org>
 150       * @author Ben Coburn   <btcoburn@silicodon.net>
 151       */
 152      function section_edit($start, $end, $level, $name) {
 153          global $conf;
 154  
 155          if ($start!=-1 && $level<=$conf['maxseclevel']) {
 156              $name = str_replace('"', '', $name);
 157              $this->doc .= '<!-- SECTION "'.$name.'" ['.$start.'-'.(($end===0)?'':$end).'] -->';
 158          }
 159      }
 160  
 161      function section_open($level) {
 162          $this->doc .= "<div class=\"level$level\">".DOKU_LF;
 163      }
 164  
 165      function section_close() {
 166          $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
 167      }
 168  
 169      function cdata($text) {
 170          $this->doc .= $this->_xmlEntities($text);
 171      }
 172  
 173      function p_open() {
 174          $this->doc .= DOKU_LF.'<p>'.DOKU_LF;
 175      }
 176  
 177      function p_close() {
 178          $this->doc .= DOKU_LF.'</p>'.DOKU_LF;
 179      }
 180  
 181      function linebreak() {
 182          $this->doc .= '<br/>'.DOKU_LF;
 183      }
 184  
 185      function hr() {
 186          $this->doc .= '<hr />'.DOKU_LF;
 187      }
 188  
 189      function strong_open() {
 190          $this->doc .= '<strong>';
 191      }
 192  
 193      function strong_close() {
 194          $this->doc .= '</strong>';
 195      }
 196  
 197      function emphasis_open() {
 198          $this->doc .= '<em>';
 199      }
 200  
 201      function emphasis_close() {
 202          $this->doc .= '</em>';
 203      }
 204  
 205      function underline_open() {
 206          $this->doc .= '<em class="u">';
 207      }
 208  
 209      function underline_close() {
 210          $this->doc .= '</em>';
 211      }
 212  
 213      function monospace_open() {
 214          $this->doc .= '<code>';
 215      }
 216  
 217      function monospace_close() {
 218          $this->doc .= '</code>';
 219      }
 220  
 221      function subscript_open() {
 222          $this->doc .= '<sub>';
 223      }
 224  
 225      function subscript_close() {
 226          $this->doc .= '</sub>';
 227      }
 228  
 229      function superscript_open() {
 230          $this->doc .= '<sup>';
 231      }
 232  
 233      function superscript_close() {
 234          $this->doc .= '</sup>';
 235      }
 236  
 237      function deleted_open() {
 238          $this->doc .= '<del>';
 239      }
 240  
 241      function deleted_close() {
 242          $this->doc .= '</del>';
 243      }
 244  
 245      /**
 246       * Callback for footnote start syntax
 247       *
 248       * All following content will go to the footnote instead of
 249       * the document. To achieve this the previous rendered content
 250       * is moved to $store and $doc is cleared
 251       *
 252       * @author Andreas Gohr <andi@splitbrain.org>
 253       */
 254      function footnote_open() {
 255  
 256          // move current content to store and record footnote
 257          $this->store = $this->doc;
 258          $this->doc   = '';
 259      }
 260  
 261      /**
 262       * Callback for footnote end syntax
 263       *
 264       * All rendered content is moved to the $footnotes array and the old
 265       * content is restored from $store again
 266       *
 267       * @author Andreas Gohr
 268       */
 269      function footnote_close() {
 270  
 271          // recover footnote into the stack and restore old content
 272          $footnote = $this->doc;
 273          $this->doc = $this->store;
 274          $this->store = '';
 275  
 276          // check to see if this footnote has been seen before
 277          $i = array_search($footnote, $this->footnotes);
 278  
 279          if ($i === false) {
 280              // its a new footnote, add it to the $footnotes array
 281              $id = count($this->footnotes)+1;
 282              $this->footnotes[count($this->footnotes)] = $footnote;
 283          } else {
 284              // seen this one before, translate the index to an id and save a placeholder
 285              $i++;
 286              $id = count($this->footnotes)+1;
 287              $this->footnotes[count($this->footnotes)] = "@@FNT".($i);
 288          }
 289  
 290          // output the footnote reference and link, incl. onmouseover for insitu footnote popup
 291          $this->doc .= '<a href="#fn__'.$id.'" name="fnt__'.$id.'" id="fnt__'.$id.'" class="fn_top" onmouseover="fnt(\''.$id.'\', this, event);">'.$id.')</a>';
 292      }
 293  
 294      function listu_open() {
 295          $this->doc .= '<ul>'.DOKU_LF;
 296      }
 297  
 298      function listu_close() {
 299          $this->doc .= '</ul>'.DOKU_LF;
 300      }
 301  
 302      function listo_open() {
 303          $this->doc .= '<ol>'.DOKU_LF;
 304      }
 305  
 306      function listo_close() {
 307          $this->doc .= '</ol>'.DOKU_LF;
 308      }
 309  
 310      function listitem_open($level) {
 311          $this->doc .= '<li class="level'.$level.'">';
 312      }
 313  
 314      function listitem_close() {
 315          $this->doc .= '</li>'.DOKU_LF;
 316      }
 317  
 318      function listcontent_open() {
 319          $this->doc .= '<div class="li">';
 320      }
 321  
 322      function listcontent_close() {
 323          $this->doc .= '</div>'.DOKU_LF;
 324      }
 325  
 326      function unformatted($text) {
 327          $this->doc .= $this->_xmlEntities($text);
 328      }
 329  
 330      /**
 331       * Execute PHP code if allowed
 332       *
 333       * @author Andreas Gohr <andi@splitbrain.org>
 334       */
 335      function php($text) {
 336          global $conf;
 337          if($conf['phpok']){
 338              ob_start();
 339              eval($text);
 340              $this->doc .= ob_get_contents();
 341              ob_end_clean();
 342          }else{
 343              $this->file($text);
 344          }
 345      }
 346  
 347      /**
 348       * Insert HTML if allowed
 349       *
 350       * @author Andreas Gohr <andi@splitbrain.org>
 351       */
 352      function html($text) {
 353          global $conf;
 354          if($conf['htmlok']){
 355            $this->doc .= $text;
 356          }else{
 357            $this->file($text);
 358          }
 359      }
 360  
 361      function preformatted($text) {
 362          $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF;
 363      }
 364  
 365      function file($text) {
 366          $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF;
 367      }
 368  
 369      function quote_open() {
 370          $this->doc .= '<blockquote><div class="no">'.DOKU_LF;
 371      }
 372  
 373      function quote_close() {
 374          $this->doc .= '</div></blockquote>'.DOKU_LF;
 375      }
 376  
 377      /**
 378       * Callback for code text
 379       *
 380       * Uses GeSHi to highlight language syntax
 381       *
 382       * @author Andreas Gohr <andi@splitbrain.org>
 383       */
 384      function code($text, $language = NULL) {
 385          global $conf;
 386  
 387          if ( is_null($language) ) {
 388              $this->preformatted($text);
 389          } else {
 390              //strip leading and trailing blank line
 391              $text = preg_replace('/^\s*?\n/','',$text);
 392              $text = preg_replace('/\s*?\n$/','',$text);
 393              $this->doc .= p_xhtml_cached_geshi($text, $language);
 394          }
 395      }
 396  
 397      function acronym($acronym) {
 398  
 399          if ( array_key_exists($acronym, $this->acronyms) ) {
 400  
 401              $title = $this->_xmlEntities($this->acronyms[$acronym]);
 402  
 403              $this->doc .= '<acronym title="'.$title
 404                  .'">'.$this->_xmlEntities($acronym).'</acronym>';
 405  
 406          } else {
 407              $this->doc .= $this->_xmlEntities($acronym);
 408          }
 409      }
 410  
 411      function smiley($smiley) {
 412          if ( array_key_exists($smiley, $this->smileys) ) {
 413              $title = $this->_xmlEntities($this->smileys[$smiley]);
 414              $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley].
 415                  '" class="middle" alt="'.
 416                      $this->_xmlEntities($smiley).'" />';
 417          } else {
 418              $this->doc .= $this->_xmlEntities($smiley);
 419          }
 420      }
 421  
 422      /*
 423      * not used
 424      function wordblock($word) {
 425          if ( array_key_exists($word, $this->badwords) ) {
 426              $this->doc .= '** BLEEP **';
 427          } else {
 428              $this->doc .= $this->_xmlEntities($word);
 429          }
 430      }
 431      */
 432  
 433      function entity($entity) {
 434          if ( array_key_exists($entity, $this->entities) ) {
 435              $this->doc .= $this->entities[$entity];
 436          } else {
 437              $this->doc .= $this->_xmlEntities($entity);
 438          }
 439      }
 440  
 441      function multiplyentity($x, $y) {
 442          $this->doc .= "$x&times;$y";
 443      }
 444  
 445      function singlequoteopening() {
 446          $this->doc .= "&lsquo;";
 447      }
 448  
 449      function singlequoteclosing() {
 450          $this->doc .= "&rsquo;";
 451      }
 452  
 453      function doublequoteopening() {
 454          $this->doc .= "&ldquo;";
 455      }
 456  
 457      function doublequoteclosing() {
 458          $this->doc .= "&rdquo;";
 459      }
 460  
 461      /**
 462      */
 463      function camelcaselink($link) {
 464        $this->internallink($link,$link);
 465      }
 466  
 467  
 468      function locallink($hash, $name = NULL){
 469          global $ID;
 470          $name  = $this->_getLinkTitle($name, $hash, $isImage);
 471          $hash  = $this->_headerToLink($hash);
 472          $title = $ID.' &crarr;';
 473          $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
 474          $this->doc .= $name;
 475          $this->doc .= '</a>';
 476      }
 477  
 478      /**
 479       * Render an internal Wiki Link
 480       *
 481       * $search and $returnonly are not for the renderer but are used
 482       * elsewhere - no need to implement them in other renderers
 483       *
 484       * @author Andreas Gohr <andi@splitbrain.org>
 485       */
 486      function internallink($id, $name = NULL, $search=NULL,$returnonly=false) {
 487          global $conf;
 488          global $ID;
 489          // default name is based on $id as given
 490          $default = $this->_simpleTitle($id);
 491          // now first resolve and clean up the $id
 492          resolve_pageid(getNS($ID),$id,$exists);
 493          $name = $this->_getLinkTitle($name, $default, $isImage, $id);
 494          if ( !$isImage ) {
 495              if ( $exists ) {
 496                  $class='wikilink1';
 497              } else {
 498                  $class='wikilink2';
 499              }
 500          } else {
 501              $class='media';
 502          }
 503  
 504          //keep hash anchor
 505          list($id,$hash) = explode('#',$id,2);
 506  
 507          //prepare for formating
 508          $link['target'] = $conf['target']['wiki'];
 509          $link['style']  = '';
 510          $link['pre']    = '';
 511          $link['suf']    = '';
 512          // highlight link to current page
 513          if ($id == $ID) {
 514              $link['pre']    = '<span class="curid">';
 515              $link['suf']    = '</span>';
 516          }
 517          $link['more']   = '';
 518          $link['class']  = $class;
 519          $link['url']    = wl($id);
 520          $link['name']   = $name;
 521          $link['title']  = $id;
 522          //add search string
 523          if($search){
 524              ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
 525              $link['url'] .= rawurlencode($search);
 526          }
 527  
 528          //keep hash
 529          if($hash) $link['url'].='#'.$hash;
 530  
 531          //output formatted
 532          if($returnonly){
 533              return $this->_formatLink($link);
 534          }else{
 535              $this->doc .= $this->_formatLink($link);
 536          }
 537      }
 538  
 539      function externallink($url, $name = NULL) {
 540          global $conf;
 541  
 542          $name = $this->_getLinkTitle($name, $url, $isImage);
 543  
 544          // add protocol on simple short URLs
 545          if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')) $url = 'ftp://'.$url;
 546          if(substr($url,0,3) == 'www') $url = 'http://'.$url;
 547  
 548          if ( !$isImage ) {
 549              $class='urlextern';
 550          } else {
 551              $class='media';
 552          }
 553  
 554          //prepare for formating
 555          $link['target'] = $conf['target']['extern'];
 556          $link['style']  = '';
 557          $link['pre']    = '';
 558          $link['suf']    = '';
 559          $link['more']   = '';
 560          $link['class']  = $class;
 561          $link['url']    = $url;
 562  
 563          $link['name']   = $name;
 564          $link['title']  = $this->_xmlEntities($url);
 565          if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
 566  
 567          //output formatted
 568          $this->doc .= $this->_formatLink($link);
 569      }
 570  
 571      /**
 572      */
 573      function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
 574          global $conf;
 575  
 576          $link = array();
 577          $link['target'] = $conf['target']['interwiki'];
 578          $link['pre']    = '';
 579          $link['suf']    = '';
 580          $link['more']   = '';
 581          $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
 582  
 583          //get interwiki URL
 584          if ( isset($this->interwiki[$wikiName]) ) {
 585              $url = $this->interwiki[$wikiName];
 586          } else {
 587              // Default to Google I'm feeling lucky
 588              $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
 589              $wikiName = 'go';
 590          }
 591  
 592          if ( !$isImage ) {
 593              $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
 594              $link['class'] = "interwiki iw_$class";
 595          } else {
 596              $link['class'] = 'media';
 597          }
 598  
 599          //do we stay at the same server? Use local target
 600          if( strpos($url,DOKU_URL) === 0 ){
 601              $link['target'] = $conf['target']['wiki'];
 602          }
 603  
 604          //split into hash and url part
 605          list($wikiUri,$hash) = explode('#',$wikiUri,2);
 606  
 607          //replace placeholder
 608          if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
 609              //use placeholders
 610              $url = str_replace('{URL}',rawurlencode($wikiUri),$url);
 611              $url = str_replace('{NAME}',$wikiUri,$url);
 612              $parsed = parse_url($wikiUri);
 613              if(!$parsed['port']) $parsed['port'] = 80;
 614              $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
 615              $url = str_replace('{HOST}',$parsed['host'],$url);
 616              $url = str_replace('{PORT}',$parsed['port'],$url);
 617              $url = str_replace('{PATH}',$parsed['path'],$url);
 618              $url = str_replace('{QUERY}',$parsed['query'],$url);
 619              $link['url'] = $url;
 620          }else{
 621              //default
 622              $link['url'] = $url.rawurlencode($wikiUri);
 623          }
 624          if($hash) $link['url'] .= '#'.rawurlencode($hash);
 625  
 626          $link['title'] = htmlspecialchars($link['url']);
 627  
 628          //output formatted
 629          $this->doc .= $this->_formatLink($link);
 630      }
 631  
 632      /**
 633       */
 634      function windowssharelink($url, $name = NULL) {
 635          global $conf;
 636          global $lang;
 637          //simple setup
 638          $link['target'] = $conf['target']['windows'];
 639          $link['pre']    = '';
 640          $link['suf']   = '';
 641          $link['style']  = '';
 642          //Display error on browsers other than IE
 643          $link['more'] = 'onclick="if(document.all == null){alert(\''.
 644                          $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).
 645                          '\');}" onkeypress="if(document.all == null){alert(\''.
 646                          $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"';
 647  
 648          $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
 649          if ( !$isImage ) {
 650              $link['class'] = 'windows';
 651          } else {
 652              $link['class'] = 'media';
 653          }
 654  
 655  
 656          $link['title'] = $this->_xmlEntities($url);
 657          $url = str_replace('\\','/',$url);
 658          $url = 'file:///'.$url;
 659          $link['url'] = $url;
 660  
 661          //output formatted
 662          $this->doc .= $this->_formatLink($link);
 663      }
 664  
 665      function emaillink($address, $name = NULL) {
 666          global $conf;
 667          //simple setup
 668          $link = array();
 669          $link['target'] = '';
 670          $link['pre']    = '';
 671          $link['suf']   = '';
 672          $link['style']  = '';
 673          $link['more']   = '';
 674  
 675          $name = $this->_getLinkTitle($name, $address, $isImage);
 676          if ( !$isImage ) {
 677              $link['class']='mail JSnocheck';
 678          } else {
 679              $link['class']='media JSnocheck';
 680          }
 681  
 682          $address = $this->_xmlEntities($address);
 683          $address = obfuscate($address);
 684          $title   = $address;
 685  
 686          if(empty($name)){
 687              $name = $address;
 688          }
 689  #elseif($isImage{
 690  #            $name = $this->_xmlEntities($name);
 691  #        }
 692  
 693          if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
 694  
 695          $link['url']   = 'mailto:'.$address;
 696          $link['name']  = $name;
 697          $link['title'] = $title;
 698  
 699          //output formatted
 700          $this->doc .= $this->_formatLink($link);
 701      }
 702  
 703      function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
 704                              $height=NULL, $cache=NULL, $linking=NULL) {
 705          global $conf;
 706          global $ID;
 707          resolve_mediaid(getNS($ID),$src, $exists);
 708  
 709          $link = array();
 710          $link['class']  = 'media';
 711          $link['style']  = '';
 712          $link['pre']    = '';
 713          $link['suf']    = '';
 714          $link['more']   = '';
 715          $link['target'] = $conf['target']['media'];
 716          $noLink = false;
 717  
 718          $link['title']  = $this->_xmlEntities($src);
 719          list($ext,$mime) = mimetype($src);
 720          if(substr($mime,0,5) == 'image'){
 721               $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
 722           }elseif($mime == 'application/x-shockwave-flash'){
 723               // don't link flash movies
 724               $noLink = TRUE;
 725           }else{
 726               // add file icons
 727               $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
 728               $link['class'] .= ' mediafile mf_'.$class;
 729               $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
 730           }
 731           $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
 732  
 733           //output formatted
 734           if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
 735           else $this->doc .= $this->_formatLink($link);
 736      }
 737  
 738      /**
 739       * @todo don't add link for flash
 740       */
 741      function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
 742                              $height=NULL, $cache=NULL, $linking=NULL) {
 743          global $conf;
 744  
 745          $link = array();
 746          $link['class']  = 'media';
 747          $link['style']  = '';
 748          $link['pre']    = '';
 749          $link['suf']    = '';
 750          $link['more']   = '';
 751          $link['target'] = $conf['target']['media'];
 752  
 753          $link['title']  = $this->_xmlEntities($src);
 754          $link['url']    = ml($src,array('cache'=>$cache));
 755          $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
 756          $noLink = false;
 757  
 758          list($ext,$mime) = mimetype($src);
 759          if(substr($mime,0,5) == 'image'){
 760               // link only jpeg images
 761               // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = TRUE;
 762          }elseif($mime == 'application/x-shockwave-flash'){
 763               // don't link flash movies
 764               $noLink = TRUE;
 765          }else{
 766               // add file icons
 767               $link['class'] .= ' mediafile mf_'.$ext;
 768           }
 769  
 770          //output formatted
 771          if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
 772          else $this->doc .= $this->_formatLink($link);
 773      }
 774  
 775      /**
 776       * Renders an RSS feed
 777       *
 778       * @author Andreas Gohr <andi@splitbrain.org>
 779       */
 780      function rss ($url,$params){
 781          global $lang;
 782          global $conf;
 783  
 784          require_once (DOKU_INC.'inc/FeedParser.php');
 785          $feed = new FeedParser();
 786          $feed->feed_url($url);
 787  
 788          //disable warning while fetching
 789          if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
 790          $rc = $feed->init();
 791          if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
 792  
 793          //decide on start and end
 794          if($params['reverse']){
 795              $mod = -1;
 796              $start = $feed->get_item_quantity()-1;
 797              $end   = $start - ($params['max']);
 798              $end   = ($end < -1) ? -1 : $end;
 799          }else{
 800              $mod   = 1;
 801              $start = 0;
 802              $end   = $feed->get_item_quantity();
 803              $end   = ($end > $params['max']) ? $params['max'] : $end;;
 804          }
 805  
 806          $this->doc .= '<ul class="rss">';
 807          if($rc){
 808              for ($x = $start; $x != $end; $x += $mod) {
 809                  $item = $feed->get_item($x);
 810                  $this->doc .= '<li><div class="li">';
 811                  $this->externallink($item->get_permalink(),
 812                                      $item->get_title());
 813                  if($params['author']){
 814                      $author = $item->get_author(0);
 815                      if($author){
 816                          $name = $author->get_name();
 817                          if(!$name) $name = $author->get_email();
 818                          if($name) $this->doc .= ' '.$lang['by'].' '.$name;
 819                      }
 820                  }
 821                  if($params['date']){
 822                      $this->doc .= ' ('.$item->get_date($conf['dformat']).')';
 823                  }
 824                  if($params['details']){
 825                      $this->doc .= '<div class="detail">';
 826                      if($htmlok){
 827                          $this->doc .= $item->get_description();
 828                      }else{
 829                          $this->doc .= strip_tags($item->get_description());
 830                      }
 831                      $this->doc .= '</div>';
 832                  }
 833  
 834                  $this->doc .= '</div></li>';
 835              }
 836          }else{
 837              $this->doc .= '<li><div class="li">';
 838              $this->doc .= '<em>'.$lang['rssfailed'].'</em>';
 839              $this->externallink($url);
 840              $this->doc .= '</div></li>';
 841          }
 842          $this->doc .= '</ul>';
 843      }
 844  
 845      // $numrows not yet implemented
 846      function table_open($maxcols = NULL, $numrows = NULL){
 847          $this->doc .= '<table class="inline">'.DOKU_LF;
 848      }
 849  
 850      function table_close(){
 851          $this->doc .= '</table>'.DOKU_LF;
 852      }
 853  
 854      function tablerow_open(){
 855          $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
 856      }
 857  
 858      function tablerow_close(){
 859          $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
 860      }
 861  
 862      function tableheader_open($colspan = 1, $align = NULL){
 863          $this->doc .= '<th';
 864          if ( !is_null($align) ) {
 865              $this->doc .= ' class="'.$align.'align"';
 866          }
 867          if ( $colspan > 1 ) {
 868              $this->doc .= ' colspan="'.$colspan.'"';
 869          }
 870          $this->doc .= '>';
 871      }
 872  
 873      function tableheader_close(){
 874          $this->doc .= '</th>';
 875      }
 876  
 877      function tablecell_open($colspan = 1, $align = NULL){
 878          $this->doc .= '<td';
 879          if ( !is_null($align) ) {
 880              $this->doc .= ' class="'.$align.'align"';
 881          }
 882          if ( $colspan > 1 ) {
 883              $this->doc .= ' colspan="'.$colspan.'"';
 884          }
 885          $this->doc .= '>';
 886      }
 887  
 888      function tablecell_close(){
 889          $this->doc .= '</td>';
 890      }
 891  
 892      //----------------------------------------------------------
 893      // Utils
 894  
 895      /**
 896       * Build a link
 897       *
 898       * Assembles all parts defined in $link returns HTML for the link
 899       *
 900       * @author Andreas Gohr <andi@splitbrain.org>
 901       */
 902      function _formatLink($link){
 903          //make sure the url is XHTML compliant (skip mailto)
 904          if(substr($link['url'],0,7) != 'mailto:'){
 905              $link['url'] = str_replace('&','&amp;',$link['url']);
 906              $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
 907          }
 908          //remove double encodings in titles
 909          $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
 910  
 911          // be sure there are no bad chars in url or title
 912          // (we can't do this for name because it can contain an img tag)
 913          $link['url']   = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
 914          $link['title'] = strtr($link['title'],array('>'=>'&gt;','<'=>'&lt;','"'=>'&quot;'));
 915  
 916          $ret  = '';
 917          $ret .= $link['pre'];
 918          $ret .= '<a href="'.$link['url'].'"';
 919          if(!empty($link['class']))  $ret .= ' class="'.$link['class'].'"';
 920          if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"';
 921          if(!empty($link['title']))  $ret .= ' title="'.$link['title'].'"';
 922          if(!empty($link['style']))  $ret .= ' style="'.$link['style'].'"';
 923          if(!empty($link['more']))   $ret .= ' '.$link['more'];
 924          $ret .= '>';
 925          $ret .= $link['name'];
 926          $ret .= '</a>';
 927          $ret .= $link['suf'];
 928          return $ret;
 929      }
 930  
 931      /**
 932       * Removes any Namespace from the given name but keeps
 933       * casing and special chars
 934       *
 935       * @author Andreas Gohr <andi@splitbrain.org>
 936       */
 937      function _simpleTitle($name){
 938          global $conf;
 939  
 940          //if there is a hash we use the ancor name only
 941          list($name,$hash) = explode('#',$name,2);
 942          if($hash) return $hash;
 943  
 944          //trim colons of a namespace link
 945          $name = rtrim($name,':');
 946  
 947          if($conf['useslash']){
 948              $nssep = '[:;/]';
 949          }else{
 950              $nssep = '[:;]';
 951          }
 952          $name = preg_replace('!.*'.$nssep.'!','',$name);
 953  
 954          if(!$name) return $this->_simpleTitle($conf['start']);
 955          return $name;
 956      }
 957  
 958      /**
 959       * Renders internal and external media
 960       *
 961       * @author Andreas Gohr <andi@splitbrain.org>
 962       */
 963      function _media ($src, $title=NULL, $align=NULL, $width=NULL,
 964                        $height=NULL, $cache=NULL) {
 965  
 966          $ret = '';
 967  
 968          list($ext,$mime) = mimetype($src);
 969          if(substr($mime,0,5) == 'image'){
 970              //add image tag
 971              $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"';
 972              $ret .= ' class="media'.$align.'"';
 973  
 974              if (!is_null($title)) {
 975                  $ret .= ' title="'.$this->_xmlEntities($title).'"';
 976                  $ret .= ' alt="'.$this->_xmlEntities($title).'"';
 977              }elseif($ext == 'jpg' || $ext == 'jpeg'){
 978                  //try to use the caption from IPTC/EXIF
 979                  require_once (DOKU_INC.'inc/JpegMeta.php');
 980                  $jpeg =& new JpegMeta(mediaFN($src));
 981                  if($jpeg !== false) $cap = $jpeg->getTitle();
 982                  if($cap){
 983                      $ret .= ' title="'.$this->_xmlEntities($cap).'"';
 984                      $ret .= ' alt="'.$this->_xmlEntities($cap).'"';
 985                  }
 986              }else{
 987                  $ret .= ' alt=""';
 988              }
 989  
 990              if ( !is_null($width) )
 991                  $ret .= ' width="'.$this->_xmlEntities($width).'"';
 992  
 993              if ( !is_null($height) )
 994                  $ret .= ' height="'.$this->_xmlEntities($height).'"';
 995  
 996              $ret .= ' />';
 997  
 998          }elseif($mime == 'application/x-shockwave-flash'){
 999              $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
1000                      ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
1001              if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
1002              if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
1003              $ret .= '>'.DOKU_LF;
1004              $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF;
1005              $ret .= '<param name="quality" value="high" />'.DOKU_LF;
1006              $ret .= '<embed src="'.ml($src).'"'.
1007                      ' quality="high"';
1008              if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
1009              if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
1010              $ret .= ' type="application/x-shockwave-flash"'.
1011                      ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF;
1012              $ret .= '</object>'.DOKU_LF;
1013  
1014          }elseif(!is_null($title)){
1015              // well at least we have a title to display
1016              $ret .= $this->_xmlEntities($title);
1017          }else{
1018              // just show the sourcename
1019              $ret .= $this->_xmlEntities(noNS($src));
1020          }
1021  
1022          return $ret;
1023      }
1024  
1025      function _xmlEntities($string) {
1026          return htmlspecialchars($string);
1027      }
1028  
1029      /**
1030       * Creates a linkid from a headline
1031       *
1032       * @param string  $title   The headline title
1033       * @param boolean $create  Create a new unique ID?
1034       * @author Andreas Gohr <andi@splitbrain.org>
1035       */
1036      function _headerToLink($title,$create=false) {
1037          $title = str_replace(':','',cleanID($title));
1038          $title = ltrim($title,'0123456789._-');
1039          if(empty($title)) $title='section';
1040  
1041          if($create){
1042              // make sure tiles are unique
1043              $num = '';
1044              while(in_array($title.$num,$this->headers)){
1045                  ($num) ? $num++ : $num = 1;
1046              }
1047              $title = $title.$num;
1048              $this->headers[] = $title;
1049          }
1050  
1051          return $title;
1052      }
1053  
1054      /**
1055       * Construct a title and handle images in titles
1056       *
1057       * @author Harry Fuecks <hfuecks@gmail.com>
1058       */
1059      function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
1060          global $conf;
1061  
1062          $isImage = FALSE;
1063          if ( is_null($title) ) {
1064              if ($conf['useheading'] && $id) {
1065                  $heading = p_get_first_heading($id);
1066                  if ($heading) {
1067                      return $this->_xmlEntities($heading);
1068                  }
1069              }
1070              return $this->_xmlEntities($default);
1071          } else if ( is_string($title) ) {
1072              return $this->_xmlEntities($title);
1073          } else if ( is_array($title) ) {
1074              $isImage = TRUE;
1075              return $this->_imageTitle($title);
1076          }
1077      }
1078  
1079      /**
1080       * Returns an HTML code for images used in link titles
1081       *
1082       * @todo Resolve namespace on internal images
1083       * @author Andreas Gohr <andi@splitbrain.org>
1084       */
1085      function _imageTitle($img) {
1086          return $this->_media($img['src'],
1087                                $img['title'],
1088                                $img['align'],
1089                                $img['width'],
1090                                $img['height'],
1091                                $img['cache']);
1092      }
1093  }
1094  
1095  //Setup VIM: ex: et ts=4 enc=utf-8 :


Généré le : Tue Apr 3 20:47:31 2007 par Balluche grâce à PHPXref 0.7