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