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