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); 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); 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); 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 $link['class'] .= ' mediafile mf_'.$ext; 756 } 757 758 if($hash) $link['url'] .= '#'.$hash; 759 760 //output formatted 761 if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 762 else $this->doc .= $this->_formatLink($link); 763 } 764 765 /** 766 * Renders an RSS feed 767 * 768 * @author Andreas Gohr <andi@splitbrain.org> 769 */ 770 function rss ($url,$params){ 771 global $lang; 772 global $conf; 773 774 require_once(DOKU_INC.'inc/FeedParser.php'); 775 $feed = new FeedParser(); 776 $feed->set_feed_url($url); 777 778 //disable warning while fetching 779 if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 780 $rc = $feed->init(); 781 if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 782 783 //decide on start and end 784 if($params['reverse']){ 785 $mod = -1; 786 $start = $feed->get_item_quantity()-1; 787 $end = $start - ($params['max']); 788 $end = ($end < -1) ? -1 : $end; 789 }else{ 790 $mod = 1; 791 $start = 0; 792 $end = $feed->get_item_quantity(); 793 $end = ($end > $params['max']) ? $params['max'] : $end;; 794 } 795 796 $this->doc .= '<ul class="rss">'; 797 if($rc){ 798 for ($x = $start; $x != $end; $x += $mod) { 799 $item = $feed->get_item($x); 800 $this->doc .= '<li><div class="li">'; 801 // support feeds without links 802 $lnkurl = $item->get_permalink(); 803 if($lnkurl){ 804 // title is escaped by SimplePie, we unescape here because it 805 // is escaped again in externallink() FS#1705 806 $this->externallink($item->get_permalink(), 807 htmlspecialchars_decode($item->get_title())); 808 }else{ 809 $this->doc .= ' '.$item->get_title(); 810 } 811 if($params['author']){ 812 $author = $item->get_author(0); 813 if($author){ 814 $name = $author->get_name(); 815 if(!$name) $name = $author->get_email(); 816 if($name) $this->doc .= ' '.$lang['by'].' '.$name; 817 } 818 } 819 if($params['date']){ 820 $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 821 } 822 if($params['details']){ 823 $this->doc .= '<div class="detail">'; 824 if($conf['htmlok']){ 825 $this->doc .= $item->get_description(); 826 }else{ 827 $this->doc .= strip_tags($item->get_description()); 828 } 829 $this->doc .= '</div>'; 830 } 831 832 $this->doc .= '</div></li>'; 833 } 834 }else{ 835 $this->doc .= '<li><div class="li">'; 836 $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 837 $this->externallink($url); 838 if($conf['allowdebug']){ 839 $this->doc .= '<!--'.hsc($feed->error).'-->'; 840 } 841 $this->doc .= '</div></li>'; 842 } 843 $this->doc .= '</ul>'; 844 } 845 846 // $numrows not yet implemented 847 function table_open($maxcols = NULL, $numrows = NULL){ 848 // initialize the row counter used for classes 849 $this->_counter['row_counter'] = 0; 850 $this->doc .= '<table class="inline">'.DOKU_LF; 851 } 852 853 function table_close(){ 854 $this->doc .= '</table>'.DOKU_LF; 855 } 856 857 function tablerow_open(){ 858 // initialize the cell counter used for classes 859 $this->_counter['cell_counter'] = 0; 860 $class = 'row' . $this->_counter['row_counter']++; 861 $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 862 } 863 864 function tablerow_close(){ 865 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 866 } 867 868 function tableheader_open($colspan = 1, $align = NULL){ 869 $class = 'class="col' . $this->_counter['cell_counter']++; 870 if ( !is_null($align) ) { 871 $class .= ' '.$align.'align'; 872 } 873 $class .= '"'; 874 $this->doc .= '<th ' . $class; 875 if ( $colspan > 1 ) { 876 $this->_counter['cell_counter'] += $colspan-1; 877 $this->doc .= ' colspan="'.$colspan.'"'; 878 } 879 $this->doc .= '>'; 880 } 881 882 function tableheader_close(){ 883 $this->doc .= '</th>'; 884 } 885 886 function tablecell_open($colspan = 1, $align = NULL){ 887 $class = 'class="col' . $this->_counter['cell_counter']++; 888 if ( !is_null($align) ) { 889 $class .= ' '.$align.'align'; 890 } 891 $class .= '"'; 892 $this->doc .= '<td '.$class; 893 if ( $colspan > 1 ) { 894 $this->_counter['cell_counter'] += $colspan-1; 895 $this->doc .= ' colspan="'.$colspan.'"'; 896 } 897 $this->doc .= '>'; 898 } 899 900 function tablecell_close(){ 901 $this->doc .= '</td>'; 902 } 903 904 //---------------------------------------------------------- 905 // Utils 906 907 /** 908 * Build a link 909 * 910 * Assembles all parts defined in $link returns HTML for the link 911 * 912 * @author Andreas Gohr <andi@splitbrain.org> 913 */ 914 function _formatLink($link){ 915 //make sure the url is XHTML compliant (skip mailto) 916 if(substr($link['url'],0,7) != 'mailto:'){ 917 $link['url'] = str_replace('&','&',$link['url']); 918 $link['url'] = str_replace('&amp;','&',$link['url']); 919 } 920 //remove double encodings in titles 921 $link['title'] = str_replace('&amp;','&',$link['title']); 922 923 // be sure there are no bad chars in url or title 924 // (we can't do this for name because it can contain an img tag) 925 $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 926 $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 927 928 $ret = ''; 929 $ret .= $link['pre']; 930 $ret .= '<a href="'.$link['url'].'"'; 931 if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 932 if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 933 if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 934 if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 935 if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 936 if(!empty($link['more'])) $ret .= ' '.$link['more']; 937 $ret .= '>'; 938 $ret .= $link['name']; 939 $ret .= '</a>'; 940 $ret .= $link['suf']; 941 return $ret; 942 } 943 944 /** 945 * Renders internal and external media 946 * 947 * @author Andreas Gohr <andi@splitbrain.org> 948 */ 949 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 950 $height=NULL, $cache=NULL, $render = true) { 951 952 $ret = ''; 953 954 list($ext,$mime,$dl) = mimetype($src); 955 if(substr($mime,0,5) == 'image'){ 956 // first get the $title 957 if (!is_null($title)) { 958 $title = $this->_xmlEntities($title); 959 }elseif($ext == 'jpg' || $ext == 'jpeg'){ 960 //try to use the caption from IPTC/EXIF 961 require_once(DOKU_INC.'inc/JpegMeta.php'); 962 $jpeg =& new JpegMeta(mediaFN($src)); 963 if($jpeg !== false) $cap = $jpeg->getTitle(); 964 if($cap){ 965 $title = $this->_xmlEntities($cap); 966 } 967 } 968 if (!$render) { 969 // if the picture is not supposed to be rendered 970 // return the title of the picture 971 if (!$title) { 972 // just show the sourcename 973 $title = $this->_xmlEntities(basename(noNS($src))); 974 } 975 return $title; 976 } 977 //add image tag 978 $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 979 $ret .= ' class="media'.$align.'"'; 980 981 // make left/right alignment for no-CSS view work (feeds) 982 if($align == 'right') $ret .= ' align="right"'; 983 if($align == 'left') $ret .= ' align="left"'; 984 985 if ($title) { 986 $ret .= ' title="' . $title . '"'; 987 $ret .= ' alt="' . $title .'"'; 988 }else{ 989 $ret .= ' alt=""'; 990 } 991 992 if ( !is_null($width) ) 993 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 994 995 if ( !is_null($height) ) 996 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 997 998 $ret .= ' />'; 999 1000 }elseif($mime == 'application/x-shockwave-flash'){ 1001 if (!$render) { 1002 // if the flash is not supposed to be rendered 1003 // return the title of the flash 1004 if (!$title) { 1005 // just show the sourcename 1006 $title = basename(noNS($src)); 1007 } 1008 return $this->_xmlEntities($title); 1009 } 1010 1011 $att = array(); 1012 $att['class'] = "media$align"; 1013 if($align == 'right') $att['align'] = 'right'; 1014 if($align == 'left') $att['align'] = 'left'; 1015 $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 1016 array('quality' => 'high'), 1017 null, 1018 $att, 1019 $this->_xmlEntities($title)); 1020 }elseif($title){ 1021 // well at least we have a title to display 1022 $ret .= $this->_xmlEntities($title); 1023 }else{ 1024 // just show the sourcename 1025 $ret .= $this->_xmlEntities(basename(noNS($src))); 1026 } 1027 1028 return $ret; 1029 } 1030 1031 function _xmlEntities($string) { 1032 return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 1033 } 1034 1035 /** 1036 * Creates a linkid from a headline 1037 * 1038 * @param string $title The headline title 1039 * @param boolean $create Create a new unique ID? 1040 * @author Andreas Gohr <andi@splitbrain.org> 1041 */ 1042 function _headerToLink($title,$create=false) { 1043 if($create){ 1044 return sectionID($title,$this->headers); 1045 }else{ 1046 $check = false; 1047 return sectionID($title,$check); 1048 } 1049 } 1050 1051 /** 1052 * Construct a title and handle images in titles 1053 * 1054 * @author Harry Fuecks <hfuecks@gmail.com> 1055 */ 1056 function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1057 global $conf; 1058 1059 $isImage = false; 1060 if ( is_null($title) || trim($title)=='') { 1061 if (useHeading($linktype) && $id) { 1062 $heading = p_get_first_heading($id,true); 1063 if ($heading) { 1064 return $this->_xmlEntities($heading); 1065 } 1066 } 1067 return $this->_xmlEntities($default); 1068 } else if ( is_array($title) ) { 1069 $isImage = true; 1070 return $this->_imageTitle($title); 1071 } else { 1072 return $this->_xmlEntities($title); 1073 } 1074 } 1075 1076 /** 1077 * Returns an HTML code for images used in link titles 1078 * 1079 * @todo Resolve namespace on internal images 1080 * @author Andreas Gohr <andi@splitbrain.org> 1081 */ 1082 function _imageTitle($img) { 1083 return $this->_media($img['src'], 1084 $img['title'], 1085 $img['align'], 1086 $img['width'], 1087 $img['height'], 1088 $img['cache']); 1089 } 1090 1091 /** 1092 * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1093 * which returns a basic link to a media. 1094 * 1095 * @author Pierre Spring <pierre.spring@liip.ch> 1096 * @param string $src 1097 * @param string $title 1098 * @param string $align 1099 * @param string $width 1100 * @param string $height 1101 * @param string $cache 1102 * @param string $render 1103 * @access protected 1104 * @return array 1105 */ 1106 function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1107 { 1108 global $conf; 1109 1110 $link = array(); 1111 $link['class'] = 'media'; 1112 $link['style'] = ''; 1113 $link['pre'] = ''; 1114 $link['suf'] = ''; 1115 $link['more'] = ''; 1116 $link['target'] = $conf['target']['media']; 1117 $link['title'] = $this->_xmlEntities($src); 1118 $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1119 1120 return $link; 1121 } 1122 1123 1124} 1125 1126//Setup VIM: ex: et ts=4 enc=utf-8 : 1127