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