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