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->doc .= '<table class="inline">'.DOKU_LF; 852 } 853 854 function table_close(){ 855 $this->doc .= '</table>'.DOKU_LF; 856 } 857 858 function tablerow_open(){ 859 // initialize the cell counter used for classes 860 $this->_counter['cell_counter'] = 0; 861 $class = 'row' . $this->_counter['row_counter']++; 862 $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 863 } 864 865 function tablerow_close(){ 866 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 867 } 868 869 function tableheader_open($colspan = 1, $align = NULL){ 870 $class = 'class="col' . $this->_counter['cell_counter']++; 871 if ( !is_null($align) ) { 872 $class .= ' '.$align.'align'; 873 } 874 $class .= '"'; 875 $this->doc .= '<th ' . $class; 876 if ( $colspan > 1 ) { 877 $this->_counter['cell_counter'] += $colspan-1; 878 $this->doc .= ' colspan="'.$colspan.'"'; 879 } 880 $this->doc .= '>'; 881 } 882 883 function tableheader_close(){ 884 $this->doc .= '</th>'; 885 } 886 887 function tablecell_open($colspan = 1, $align = NULL){ 888 $class = 'class="col' . $this->_counter['cell_counter']++; 889 if ( !is_null($align) ) { 890 $class .= ' '.$align.'align'; 891 } 892 $class .= '"'; 893 $this->doc .= '<td '.$class; 894 if ( $colspan > 1 ) { 895 $this->_counter['cell_counter'] += $colspan-1; 896 $this->doc .= ' colspan="'.$colspan.'"'; 897 } 898 $this->doc .= '>'; 899 } 900 901 function tablecell_close(){ 902 $this->doc .= '</td>'; 903 } 904 905 //---------------------------------------------------------- 906 // Utils 907 908 /** 909 * Build a link 910 * 911 * Assembles all parts defined in $link returns HTML for the link 912 * 913 * @author Andreas Gohr <andi@splitbrain.org> 914 */ 915 function _formatLink($link){ 916 //make sure the url is XHTML compliant (skip mailto) 917 if(substr($link['url'],0,7) != 'mailto:'){ 918 $link['url'] = str_replace('&','&',$link['url']); 919 $link['url'] = str_replace('&amp;','&',$link['url']); 920 } 921 //remove double encodings in titles 922 $link['title'] = str_replace('&amp;','&',$link['title']); 923 924 // be sure there are no bad chars in url or title 925 // (we can't do this for name because it can contain an img tag) 926 $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 927 $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 928 929 $ret = ''; 930 $ret .= $link['pre']; 931 $ret .= '<a href="'.$link['url'].'"'; 932 if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 933 if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 934 if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 935 if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 936 if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 937 if(!empty($link['more'])) $ret .= ' '.$link['more']; 938 $ret .= '>'; 939 $ret .= $link['name']; 940 $ret .= '</a>'; 941 $ret .= $link['suf']; 942 return $ret; 943 } 944 945 /** 946 * Renders internal and external media 947 * 948 * @author Andreas Gohr <andi@splitbrain.org> 949 */ 950 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 951 $height=NULL, $cache=NULL, $render = true) { 952 953 $ret = ''; 954 955 list($ext,$mime,$dl) = mimetype($src); 956 if(substr($mime,0,5) == 'image'){ 957 // first get the $title 958 if (!is_null($title)) { 959 $title = $this->_xmlEntities($title); 960 }elseif($ext == 'jpg' || $ext == 'jpeg'){ 961 //try to use the caption from IPTC/EXIF 962 require_once(DOKU_INC.'inc/JpegMeta.php'); 963 $jpeg =& new JpegMeta(mediaFN($src)); 964 if($jpeg !== false) $cap = $jpeg->getTitle(); 965 if($cap){ 966 $title = $this->_xmlEntities($cap); 967 } 968 } 969 if (!$render) { 970 // if the picture is not supposed to be rendered 971 // return the title of the picture 972 if (!$title) { 973 // just show the sourcename 974 $title = $this->_xmlEntities(basename(noNS($src))); 975 } 976 return $title; 977 } 978 //add image tag 979 $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 980 $ret .= ' class="media'.$align.'"'; 981 982 // make left/right alignment for no-CSS view work (feeds) 983 if($align == 'right') $ret .= ' align="right"'; 984 if($align == 'left') $ret .= ' align="left"'; 985 986 if ($title) { 987 $ret .= ' title="' . $title . '"'; 988 $ret .= ' alt="' . $title .'"'; 989 }else{ 990 $ret .= ' alt=""'; 991 } 992 993 if ( !is_null($width) ) 994 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 995 996 if ( !is_null($height) ) 997 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 998 999 $ret .= ' />'; 1000 1001 }elseif($mime == 'application/x-shockwave-flash'){ 1002 if (!$render) { 1003 // if the flash is not supposed to be rendered 1004 // return the title of the flash 1005 if (!$title) { 1006 // just show the sourcename 1007 $title = basename(noNS($src)); 1008 } 1009 return $this->_xmlEntities($title); 1010 } 1011 1012 $att = array(); 1013 $att['class'] = "media$align"; 1014 if($align == 'right') $att['align'] = 'right'; 1015 if($align == 'left') $att['align'] = 'left'; 1016 $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 1017 array('quality' => 'high'), 1018 null, 1019 $att, 1020 $this->_xmlEntities($title)); 1021 }elseif($title){ 1022 // well at least we have a title to display 1023 $ret .= $this->_xmlEntities($title); 1024 }else{ 1025 // just show the sourcename 1026 $ret .= $this->_xmlEntities(basename(noNS($src))); 1027 } 1028 1029 return $ret; 1030 } 1031 1032 function _xmlEntities($string) { 1033 return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 1034 } 1035 1036 /** 1037 * Creates a linkid from a headline 1038 * 1039 * @param string $title The headline title 1040 * @param boolean $create Create a new unique ID? 1041 * @author Andreas Gohr <andi@splitbrain.org> 1042 */ 1043 function _headerToLink($title,$create=false) { 1044 if($create){ 1045 return sectionID($title,$this->headers); 1046 }else{ 1047 $check = false; 1048 return sectionID($title,$check); 1049 } 1050 } 1051 1052 /** 1053 * Construct a title and handle images in titles 1054 * 1055 * @author Harry Fuecks <hfuecks@gmail.com> 1056 */ 1057 function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') { 1058 global $conf; 1059 1060 $isImage = false; 1061 if ( is_null($title) || trim($title)=='') { 1062 if (useHeading($linktype) && $id) { 1063 $heading = p_get_first_heading($id,true); 1064 if ($heading) { 1065 return $this->_xmlEntities($heading); 1066 } 1067 } 1068 return $this->_xmlEntities($default); 1069 } else if ( is_array($title) ) { 1070 $isImage = true; 1071 return $this->_imageTitle($title); 1072 } else { 1073 return $this->_xmlEntities($title); 1074 } 1075 } 1076 1077 /** 1078 * Returns an HTML code for images used in link titles 1079 * 1080 * @todo Resolve namespace on internal images 1081 * @author Andreas Gohr <andi@splitbrain.org> 1082 */ 1083 function _imageTitle($img) { 1084 return $this->_media($img['src'], 1085 $img['title'], 1086 $img['align'], 1087 $img['width'], 1088 $img['height'], 1089 $img['cache']); 1090 } 1091 1092 /** 1093 * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1094 * which returns a basic link to a media. 1095 * 1096 * @author Pierre Spring <pierre.spring@liip.ch> 1097 * @param string $src 1098 * @param string $title 1099 * @param string $align 1100 * @param string $width 1101 * @param string $height 1102 * @param string $cache 1103 * @param string $render 1104 * @access protected 1105 * @return array 1106 */ 1107 function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1108 { 1109 global $conf; 1110 1111 $link = array(); 1112 $link['class'] = 'media'; 1113 $link['style'] = ''; 1114 $link['pre'] = ''; 1115 $link['suf'] = ''; 1116 $link['more'] = ''; 1117 $link['target'] = $conf['target']['media']; 1118 $link['title'] = $this->_xmlEntities($src); 1119 $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1120 1121 return $link; 1122 } 1123 1124 1125} 1126 1127//Setup VIM: ex: et ts=4 enc=utf-8 : 1128