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 /** 351 * Insert HTML if allowed 352 * 353 * @author Andreas Gohr <andi@splitbrain.org> 354 */ 355 function html($text) { 356 global $conf; 357 if($conf['htmlok']){ 358 $this->doc .= $text; 359 }else{ 360 $this->file($text); 361 } 362 } 363 364 function preformatted($text) { 365 $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 366 } 367 368 function file($text) { 369 $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 370 } 371 372 function quote_open() { 373 $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 374 } 375 376 function quote_close() { 377 $this->doc .= '</div></blockquote>'.DOKU_LF; 378 } 379 380 /** 381 * Callback for code text 382 * 383 * Uses GeSHi to highlight language syntax 384 * 385 * @author Andreas Gohr <andi@splitbrain.org> 386 */ 387 function code($text, $language = NULL) { 388 global $conf; 389 390 if ( is_null($language) ) { 391 $this->preformatted($text); 392 } else { 393 //strip leading and trailing blank line 394 $text = preg_replace('/^\s*?\n/','',$text); 395 $text = preg_replace('/\s*?\n$/','',$text); 396 $this->doc .= p_xhtml_cached_geshi($text, $language); 397 } 398 } 399 400 function acronym($acronym) { 401 402 if ( array_key_exists($acronym, $this->acronyms) ) { 403 404 $title = $this->_xmlEntities($this->acronyms[$acronym]); 405 406 $this->doc .= '<acronym title="'.$title 407 .'">'.$this->_xmlEntities($acronym).'</acronym>'; 408 409 } else { 410 $this->doc .= $this->_xmlEntities($acronym); 411 } 412 } 413 414 function smiley($smiley) { 415 if ( array_key_exists($smiley, $this->smileys) ) { 416 $title = $this->_xmlEntities($this->smileys[$smiley]); 417 $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 418 '" class="middle" alt="'. 419 $this->_xmlEntities($smiley).'" />'; 420 } else { 421 $this->doc .= $this->_xmlEntities($smiley); 422 } 423 } 424 425 /* 426 * not used 427 function wordblock($word) { 428 if ( array_key_exists($word, $this->badwords) ) { 429 $this->doc .= '** BLEEP **'; 430 } else { 431 $this->doc .= $this->_xmlEntities($word); 432 } 433 } 434 */ 435 436 function entity($entity) { 437 if ( array_key_exists($entity, $this->entities) ) { 438 $this->doc .= $this->entities[$entity]; 439 } else { 440 $this->doc .= $this->_xmlEntities($entity); 441 } 442 } 443 444 function multiplyentity($x, $y) { 445 $this->doc .= "$x×$y"; 446 } 447 448 function singlequoteopening() { 449 global $lang; 450 $this->doc .= $lang['singlequoteopening']; 451 } 452 453 function singlequoteclosing() { 454 global $lang; 455 $this->doc .= $lang['singlequoteclosing']; 456 } 457 458 function apostrophe() { 459 global $lang; 460 $this->doc .= $lang['apostrophe']; 461 } 462 463 function doublequoteopening() { 464 global $lang; 465 $this->doc .= $lang['doublequoteopening']; 466 } 467 468 function doublequoteclosing() { 469 global $lang; 470 $this->doc .= $lang['doublequoteclosing']; 471 } 472 473 /** 474 */ 475 function camelcaselink($link) { 476 $this->internallink($link,$link); 477 } 478 479 480 function locallink($hash, $name = NULL){ 481 global $ID; 482 $name = $this->_getLinkTitle($name, $hash, $isImage); 483 $hash = $this->_headerToLink($hash); 484 $title = $ID.' ↵'; 485 $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 486 $this->doc .= $name; 487 $this->doc .= '</a>'; 488 } 489 490 /** 491 * Render an internal Wiki Link 492 * 493 * $search and $returnonly are not for the renderer but are used 494 * elsewhere - no need to implement them in other renderers 495 * 496 * @author Andreas Gohr <andi@splitbrain.org> 497 */ 498 function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 499 global $conf; 500 global $ID; 501 // default name is based on $id as given 502 $default = $this->_simpleTitle($id); 503 504 // now first resolve and clean up the $id 505 resolve_pageid(getNS($ID),$id,$exists); 506 $name = $this->_getLinkTitle($name, $default, $isImage, $id); 507 if ( !$isImage ) { 508 if ( $exists ) { 509 $class='wikilink1'; 510 } else { 511 $class='wikilink2'; 512 } 513 } else { 514 $class='media'; 515 } 516 517 //keep hash anchor 518 list($id,$hash) = explode('#',$id,2); 519 $hash = $this->_headerToLink($hash); 520 521 //prepare for formating 522 $link['target'] = $conf['target']['wiki']; 523 $link['style'] = ''; 524 $link['pre'] = ''; 525 $link['suf'] = ''; 526 // highlight link to current page 527 if ($id == $ID) { 528 $link['pre'] = '<span class="curid">'; 529 $link['suf'] = '</span>'; 530 } 531 $link['more'] = ''; 532 $link['class'] = $class; 533 $link['url'] = wl($id); 534 $link['name'] = $name; 535 $link['title'] = $id; 536 //add search string 537 if($search){ 538 ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 539 $link['url'] .= rawurlencode($search); 540 } 541 542 //keep hash 543 if($hash) $link['url'].='#'.$hash; 544 545 //output formatted 546 if($returnonly){ 547 return $this->_formatLink($link); 548 }else{ 549 $this->doc .= $this->_formatLink($link); 550 } 551 } 552 553 function externallink($url, $name = NULL) { 554 global $conf; 555 556 $name = $this->_getLinkTitle($name, $url, $isImage); 557 558 if ( !$isImage ) { 559 $class='urlextern'; 560 } else { 561 $class='media'; 562 } 563 564 //prepare for formating 565 $link['target'] = $conf['target']['extern']; 566 $link['style'] = ''; 567 $link['pre'] = ''; 568 $link['suf'] = ''; 569 $link['more'] = ''; 570 $link['class'] = $class; 571 $link['url'] = $url; 572 573 $link['name'] = $name; 574 $link['title'] = $this->_xmlEntities($url); 575 if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 576 577 //output formatted 578 $this->doc .= $this->_formatLink($link); 579 } 580 581 /** 582 */ 583 function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 584 global $conf; 585 586 $link = array(); 587 $link['target'] = $conf['target']['interwiki']; 588 $link['pre'] = ''; 589 $link['suf'] = ''; 590 $link['more'] = ''; 591 $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 592 593 //get interwiki URL 594 $url = $this-> _resolveInterWiki($wikiName,$wikiUri); 595 596 if ( !$isImage ) { 597 $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 598 $link['class'] = "interwiki iw_$class"; 599 } else { 600 $link['class'] = 'media'; 601 } 602 603 //do we stay at the same server? Use local target 604 if( strpos($url,DOKU_URL) === 0 ){ 605 $link['target'] = $conf['target']['wiki']; 606 } 607 608 $link['url'] = $url; 609 $link['title'] = htmlspecialchars($link['url']); 610 611 //output formatted 612 $this->doc .= $this->_formatLink($link); 613 } 614 615 /** 616 */ 617 function windowssharelink($url, $name = NULL) { 618 global $conf; 619 global $lang; 620 //simple setup 621 $link['target'] = $conf['target']['windows']; 622 $link['pre'] = ''; 623 $link['suf'] = ''; 624 $link['style'] = ''; 625 //Display error on browsers other than IE 626 $link['more'] = 'onclick="if(document.all == null){alert(\''. 627 str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])). 628 '\');}" onkeypress="if(document.all == null){alert(\''. 629 str_replace('\\\\n','\\n',addslashes($lang['nosmblinks'])).'\');}"'; 630 631 $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 632 if ( !$isImage ) { 633 $link['class'] = 'windows'; 634 } else { 635 $link['class'] = 'media'; 636 } 637 638 639 $link['title'] = $this->_xmlEntities($url); 640 $url = str_replace('\\','/',$url); 641 $url = 'file:///'.$url; 642 $link['url'] = $url; 643 644 //output formatted 645 $this->doc .= $this->_formatLink($link); 646 } 647 648 function emaillink($address, $name = NULL) { 649 global $conf; 650 //simple setup 651 $link = array(); 652 $link['target'] = ''; 653 $link['pre'] = ''; 654 $link['suf'] = ''; 655 $link['style'] = ''; 656 $link['more'] = ''; 657 658 $name = $this->_getLinkTitle($name, '', $isImage); 659 if ( !$isImage ) { 660 $link['class']='mail JSnocheck'; 661 } else { 662 $link['class']='media JSnocheck'; 663 } 664 665 $address = $this->_xmlEntities($address); 666 $address = obfuscate($address); 667 $title = $address; 668 669 if(empty($name)){ 670 $name = $address; 671 } 672#elseif($isImage{ 673# $name = $this->_xmlEntities($name); 674# } 675 676 if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 677 678 $link['url'] = 'mailto:'.$address; 679 $link['name'] = $name; 680 $link['title'] = $title; 681 682 //output formatted 683 $this->doc .= $this->_formatLink($link); 684 } 685 686 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 687 $height=NULL, $cache=NULL, $linking=NULL) { 688 global $conf; 689 global $ID; 690 resolve_mediaid(getNS($ID),$src, $exists); 691 692 $link = array(); 693 $link['class'] = 'media'; 694 $link['style'] = ''; 695 $link['pre'] = ''; 696 $link['suf'] = ''; 697 $link['more'] = ''; 698 $link['target'] = $conf['target']['media']; 699 $noLink = false; 700 701 $link['title'] = $this->_xmlEntities($src); 702 list($ext,$mime) = mimetype($src); 703 if(substr($mime,0,5) == 'image'){ 704 $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 705 }elseif($mime == 'application/x-shockwave-flash'){ 706 // don't link flash movies 707 $noLink = true; 708 }else{ 709 // add file icons 710 $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 711 $link['class'] .= ' mediafile mf_'.$class; 712 $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 713 } 714 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 715 716 //output formatted 717 if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 718 else $this->doc .= $this->_formatLink($link); 719 } 720 721 /** 722 * @todo don't add link for flash 723 */ 724 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 725 $height=NULL, $cache=NULL, $linking=NULL) { 726 global $conf; 727 728 $link = array(); 729 $link['class'] = 'media'; 730 $link['style'] = ''; 731 $link['pre'] = ''; 732 $link['suf'] = ''; 733 $link['more'] = ''; 734 $link['target'] = $conf['target']['media']; 735 736 $link['title'] = $this->_xmlEntities($src); 737 $link['url'] = ml($src,array('cache'=>$cache)); 738 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 739 $noLink = false; 740 741 list($ext,$mime) = mimetype($src); 742 if(substr($mime,0,5) == 'image'){ 743 // link only jpeg images 744 // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 745 }elseif($mime == 'application/x-shockwave-flash'){ 746 // don't link flash movies 747 $noLink = true; 748 }else{ 749 // add file icons 750 $link['class'] .= ' mediafile mf_'.$ext; 751 } 752 753 //output formatted 754 if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 755 else $this->doc .= $this->_formatLink($link); 756 } 757 758 /** 759 * Renders an RSS feed 760 * 761 * @author Andreas Gohr <andi@splitbrain.org> 762 */ 763 function rss ($url,$params){ 764 global $lang; 765 global $conf; 766 767 require_once(DOKU_INC.'inc/FeedParser.php'); 768 $feed = new FeedParser(); 769 $feed->feed_url($url); 770 771 //disable warning while fetching 772 if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 773 $rc = $feed->init(); 774 if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 775 776 //decide on start and end 777 if($params['reverse']){ 778 $mod = -1; 779 $start = $feed->get_item_quantity()-1; 780 $end = $start - ($params['max']); 781 $end = ($end < -1) ? -1 : $end; 782 }else{ 783 $mod = 1; 784 $start = 0; 785 $end = $feed->get_item_quantity(); 786 $end = ($end > $params['max']) ? $params['max'] : $end;; 787 } 788 789 $this->doc .= '<ul class="rss">'; 790 if($rc){ 791 for ($x = $start; $x != $end; $x += $mod) { 792 $item = $feed->get_item($x); 793 $this->doc .= '<li><div class="li">'; 794 $this->externallink($item->get_permalink(), 795 $item->get_title()); 796 if($params['author']){ 797 $author = $item->get_author(0); 798 if($author){ 799 $name = $author->get_name(); 800 if(!$name) $name = $author->get_email(); 801 if($name) $this->doc .= ' '.$lang['by'].' '.$name; 802 } 803 } 804 if($params['date']){ 805 $this->doc .= ' ('.$item->get_date($conf['dformat']).')'; 806 } 807 if($params['details']){ 808 $this->doc .= '<div class="detail">'; 809 if($htmlok){ 810 $this->doc .= $item->get_description(); 811 }else{ 812 $this->doc .= strip_tags($item->get_description()); 813 } 814 $this->doc .= '</div>'; 815 } 816 817 $this->doc .= '</div></li>'; 818 } 819 }else{ 820 $this->doc .= '<li><div class="li">'; 821 $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 822 $this->externallink($url); 823 if($conf['allowdebug']){ 824 $this->doc .= '<!--'.hsc($feed->error).'-->'; 825 } 826 $this->doc .= '</div></li>'; 827 } 828 $this->doc .= '</ul>'; 829 } 830 831 // $numrows not yet implemented 832 function table_open($maxcols = NULL, $numrows = NULL){ 833 $this->doc .= '<table class="inline">'.DOKU_LF; 834 } 835 836 function table_close(){ 837 $this->doc .= '</table>'.DOKU_LF; 838 } 839 840 function tablerow_open(){ 841 $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 842 } 843 844 function tablerow_close(){ 845 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 846 } 847 848 function tableheader_open($colspan = 1, $align = NULL){ 849 $this->doc .= '<th'; 850 if ( !is_null($align) ) { 851 $this->doc .= ' class="'.$align.'align"'; 852 } 853 if ( $colspan > 1 ) { 854 $this->doc .= ' colspan="'.$colspan.'"'; 855 } 856 $this->doc .= '>'; 857 } 858 859 function tableheader_close(){ 860 $this->doc .= '</th>'; 861 } 862 863 function tablecell_open($colspan = 1, $align = NULL){ 864 $this->doc .= '<td'; 865 if ( !is_null($align) ) { 866 $this->doc .= ' class="'.$align.'align"'; 867 } 868 if ( $colspan > 1 ) { 869 $this->doc .= ' colspan="'.$colspan.'"'; 870 } 871 $this->doc .= '>'; 872 } 873 874 function tablecell_close(){ 875 $this->doc .= '</td>'; 876 } 877 878 //---------------------------------------------------------- 879 // Utils 880 881 /** 882 * Build a link 883 * 884 * Assembles all parts defined in $link returns HTML for the link 885 * 886 * @author Andreas Gohr <andi@splitbrain.org> 887 */ 888 function _formatLink($link){ 889 //make sure the url is XHTML compliant (skip mailto) 890 if(substr($link['url'],0,7) != 'mailto:'){ 891 $link['url'] = str_replace('&','&',$link['url']); 892 $link['url'] = str_replace('&amp;','&',$link['url']); 893 } 894 //remove double encodings in titles 895 $link['title'] = str_replace('&amp;','&',$link['title']); 896 897 // be sure there are no bad chars in url or title 898 // (we can't do this for name because it can contain an img tag) 899 $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 900 $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 901 902 $ret = ''; 903 $ret .= $link['pre']; 904 $ret .= '<a href="'.$link['url'].'"'; 905 if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 906 if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 907 if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 908 if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 909 if(!empty($link['more'])) $ret .= ' '.$link['more']; 910 $ret .= '>'; 911 $ret .= $link['name']; 912 $ret .= '</a>'; 913 $ret .= $link['suf']; 914 return $ret; 915 } 916 917 /** 918 * Renders internal and external media 919 * 920 * @author Andreas Gohr <andi@splitbrain.org> 921 */ 922 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 923 $height=NULL, $cache=NULL) { 924 925 $ret = ''; 926 927 list($ext,$mime) = mimetype($src); 928 if(substr($mime,0,5) == 'image'){ 929 //add image tag 930 $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 931 $ret .= ' class="media'.$align.'"'; 932 933 if (!is_null($title)) { 934 $ret .= ' title="'.$this->_xmlEntities($title).'"'; 935 $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 936 }elseif($ext == 'jpg' || $ext == 'jpeg'){ 937 //try to use the caption from IPTC/EXIF 938 require_once(DOKU_INC.'inc/JpegMeta.php'); 939 $jpeg =& new JpegMeta(mediaFN($src)); 940 if($jpeg !== false) $cap = $jpeg->getTitle(); 941 if($cap){ 942 $ret .= ' title="'.$this->_xmlEntities($cap).'"'; 943 $ret .= ' alt="'.$this->_xmlEntities($cap).'"'; 944 }else{ 945 $ret .= ' alt=""'; 946 } 947 }else{ 948 $ret .= ' alt=""'; 949 } 950 951 if ( !is_null($width) ) 952 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 953 954 if ( !is_null($height) ) 955 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 956 957 $ret .= ' />'; 958 959 }elseif($mime == 'application/x-shockwave-flash'){ 960 $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 961 ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 962 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 963 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 964 $ret .= '>'.DOKU_LF; 965 $ret .= '<param name="movie" value="'.ml($src).'" />'.DOKU_LF; 966 $ret .= '<param name="quality" value="high" />'.DOKU_LF; 967 $ret .= '<embed src="'.ml($src).'"'. 968 ' quality="high"'; 969 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 970 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 971 $ret .= ' type="application/x-shockwave-flash"'. 972 ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 973 $ret .= '</object>'.DOKU_LF; 974 975 }elseif($title){ 976 // well at least we have a title to display 977 $ret .= $this->_xmlEntities($title); 978 }else{ 979 // just show the sourcename 980 $ret .= $this->_xmlEntities(basename(noNS($src))); 981 } 982 983 return $ret; 984 } 985 986 function _xmlEntities($string) { 987 return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 988 } 989 990 /** 991 * Creates a linkid from a headline 992 * 993 * @param string $title The headline title 994 * @param boolean $create Create a new unique ID? 995 * @author Andreas Gohr <andi@splitbrain.org> 996 */ 997 function _headerToLink($title,$create=false) { 998 $title = str_replace(':','',cleanID($title)); 999 $title = ltrim($title,'0123456789._-'); 1000 if(empty($title)) $title='section'; 1001 1002 if($create){ 1003 // make sure tiles are unique 1004 $num = ''; 1005 while(in_array($title.$num,$this->headers)){ 1006 ($num) ? $num++ : $num = 1; 1007 } 1008 $title = $title.$num; 1009 $this->headers[] = $title; 1010 } 1011 1012 return $title; 1013 } 1014 1015 /** 1016 * Construct a title and handle images in titles 1017 * 1018 * @author Harry Fuecks <hfuecks@gmail.com> 1019 */ 1020 function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 1021 global $conf; 1022 1023 $isImage = false; 1024 if ( is_null($title) ) { 1025 if ($conf['useheading'] && $id) { 1026 $heading = p_get_first_heading($id,true); 1027 if ($heading) { 1028 return $this->_xmlEntities($heading); 1029 } 1030 } 1031 return $this->_xmlEntities($default); 1032 } else if ( is_string($title) ) { 1033 return $this->_xmlEntities($title); 1034 } else if ( is_array($title) ) { 1035 $isImage = true; 1036 return $this->_imageTitle($title); 1037 } 1038 } 1039 1040 /** 1041 * Returns an HTML code for images used in link titles 1042 * 1043 * @todo Resolve namespace on internal images 1044 * @author Andreas Gohr <andi@splitbrain.org> 1045 */ 1046 function _imageTitle($img) { 1047 return $this->_media($img['src'], 1048 $img['title'], 1049 $img['align'], 1050 $img['width'], 1051 $img['height'], 1052 $img['cache']); 1053 } 1054} 1055 1056//Setup VIM: ex: et ts=4 enc=utf-8 : 1057