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