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),"\n\r") . '</pre>'. DOKU_LF; 362 } 363 364 function file($text) { 365 $this->doc .= '<pre class="file">' . trim($this->_xmlEntities($text),"\n\r"). '</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, '', $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 667 if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 668 669 $link['url'] = 'mailto:'.$address; 670 $link['name'] = $name; 671 $link['title'] = $title; 672 673 //output formatted 674 $this->doc .= $this->_formatLink($link); 675 } 676 677 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 678 $height=NULL, $cache=NULL, $linking=NULL) { 679 global $ID; 680 list($src,$hash) = explode('#',$src,2); 681 resolve_mediaid(getNS($ID),$src, $exists); 682 683 $noLink = false; 684 $render = ($linking == 'linkonly') ? false : true; 685 $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 686 687 list($ext,$mime,$dl) = mimetype($src); 688 if(substr($mime,0,5) == 'image' && $render){ 689 $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct')); 690 }elseif($mime == 'application/x-shockwave-flash' && $render){ 691 // don't link flash movies 692 $noLink = true; 693 }else{ 694 // add file icons 695 $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 696 $link['class'] .= ' mediafile mf_'.$class; 697 $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true); 698 } 699 700 if($hash) $link['url'] .= '#'.$hash; 701 702 //markup non existing files 703 if (!$exists) 704 $link['class'] .= ' wikilink2'; 705 706 //output formatted 707 if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 708 else $this->doc .= $this->_formatLink($link); 709 } 710 711 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 712 $height=NULL, $cache=NULL, $linking=NULL) { 713 list($src,$hash) = explode('#',$src,2); 714 $noLink = false; 715 $render = ($linking == 'linkonly') ? false : true; 716 $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 717 718 $link['url'] = ml($src,array('cache'=>$cache)); 719 720 list($ext,$mime,$dl) = mimetype($src); 721 if(substr($mime,0,5) == 'image' && $render){ 722 // link only jpeg images 723 // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 724 }elseif($mime == 'application/x-shockwave-flash' && $render){ 725 // don't link flash movies 726 $noLink = true; 727 }else{ 728 // add file icons 729 $link['class'] .= ' mediafile mf_'.$ext; 730 } 731 732 if($hash) $link['url'] .= '#'.$hash; 733 734 //output formatted 735 if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 736 else $this->doc .= $this->_formatLink($link); 737 } 738 739 /** 740 * Renders an RSS feed 741 * 742 * @author Andreas Gohr <andi@splitbrain.org> 743 */ 744 function rss ($url,$params){ 745 global $lang; 746 global $conf; 747 748 require_once(DOKU_INC.'inc/FeedParser.php'); 749 $feed = new FeedParser(); 750 $feed->set_feed_url($url); 751 752 //disable warning while fetching 753 if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 754 $rc = $feed->init(); 755 if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 756 757 //decide on start and end 758 if($params['reverse']){ 759 $mod = -1; 760 $start = $feed->get_item_quantity()-1; 761 $end = $start - ($params['max']); 762 $end = ($end < -1) ? -1 : $end; 763 }else{ 764 $mod = 1; 765 $start = 0; 766 $end = $feed->get_item_quantity(); 767 $end = ($end > $params['max']) ? $params['max'] : $end;; 768 } 769 770 $this->doc .= '<ul class="rss">'; 771 if($rc){ 772 for ($x = $start; $x != $end; $x += $mod) { 773 $item = $feed->get_item($x); 774 $this->doc .= '<li><div class="li">'; 775 // support feeds without links 776 $lnkurl = $item->get_permalink(); 777 if($lnkurl){ 778 $this->externallink($item->get_permalink(), 779 $item->get_title()); 780 }else{ 781 $this->doc .= ' '.$item->get_title(); 782 } 783 if($params['author']){ 784 $author = $item->get_author(0); 785 if($author){ 786 $name = $author->get_name(); 787 if(!$name) $name = $author->get_email(); 788 if($name) $this->doc .= ' '.$lang['by'].' '.$name; 789 } 790 } 791 if($params['date']){ 792 $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 793 } 794 if($params['details']){ 795 $this->doc .= '<div class="detail">'; 796 if($conf['htmlok']){ 797 $this->doc .= $item->get_description(); 798 }else{ 799 $this->doc .= strip_tags($item->get_description()); 800 } 801 $this->doc .= '</div>'; 802 } 803 804 $this->doc .= '</div></li>'; 805 } 806 }else{ 807 $this->doc .= '<li><div class="li">'; 808 $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 809 $this->externallink($url); 810 if($conf['allowdebug']){ 811 $this->doc .= '<!--'.hsc($feed->error).'-->'; 812 } 813 $this->doc .= '</div></li>'; 814 } 815 $this->doc .= '</ul>'; 816 } 817 818 // $numrows not yet implemented 819 function table_open($maxcols = NULL, $numrows = NULL){ 820 // initialize the row counter used for classes 821 $this->_counter['row_counter'] = 0; 822 $this->doc .= '<table class="inline">'.DOKU_LF; 823 } 824 825 function table_close(){ 826 $this->doc .= '</table>'.DOKU_LF; 827 } 828 829 function tablerow_open(){ 830 // initialize the cell counter used for classes 831 $this->_counter['cell_counter'] = 0; 832 $class = 'row' . $this->_counter['row_counter']++; 833 $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 834 } 835 836 function tablerow_close(){ 837 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 838 } 839 840 function tableheader_open($colspan = 1, $align = NULL){ 841 $class = 'class="col' . $this->_counter['cell_counter']++; 842 if ( !is_null($align) ) { 843 $class .= ' '.$align.'align'; 844 } 845 $class .= '"'; 846 $this->doc .= '<th ' . $class; 847 if ( $colspan > 1 ) { 848 $this->_counter['cell_counter'] += $colspan-1; 849 $this->doc .= ' colspan="'.$colspan.'"'; 850 } 851 $this->doc .= '>'; 852 } 853 854 function tableheader_close(){ 855 $this->doc .= '</th>'; 856 } 857 858 function tablecell_open($colspan = 1, $align = NULL){ 859 $class = 'class="col' . $this->_counter['cell_counter']++; 860 if ( !is_null($align) ) { 861 $class .= ' '.$align.'align'; 862 } 863 $class .= '"'; 864 $this->doc .= '<td '.$class; 865 if ( $colspan > 1 ) { 866 $this->_counter['cell_counter'] += $colspan-1; 867 $this->doc .= ' colspan="'.$colspan.'"'; 868 } 869 $this->doc .= '>'; 870 } 871 872 function tablecell_close(){ 873 $this->doc .= '</td>'; 874 } 875 876 //---------------------------------------------------------- 877 // Utils 878 879 /** 880 * Build a link 881 * 882 * Assembles all parts defined in $link returns HTML for the link 883 * 884 * @author Andreas Gohr <andi@splitbrain.org> 885 */ 886 function _formatLink($link){ 887 //make sure the url is XHTML compliant (skip mailto) 888 if(substr($link['url'],0,7) != 'mailto:'){ 889 $link['url'] = str_replace('&','&',$link['url']); 890 $link['url'] = str_replace('&amp;','&',$link['url']); 891 } 892 //remove double encodings in titles 893 $link['title'] = str_replace('&amp;','&',$link['title']); 894 895 // be sure there are no bad chars in url or title 896 // (we can't do this for name because it can contain an img tag) 897 $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 898 $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 899 900 $ret = ''; 901 $ret .= $link['pre']; 902 $ret .= '<a href="'.$link['url'].'"'; 903 if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 904 if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 905 if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 906 if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 907 if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 908 if(!empty($link['more'])) $ret .= ' '.$link['more']; 909 $ret .= '>'; 910 $ret .= $link['name']; 911 $ret .= '</a>'; 912 $ret .= $link['suf']; 913 return $ret; 914 } 915 916 /** 917 * Renders internal and external media 918 * 919 * @author Andreas Gohr <andi@splitbrain.org> 920 */ 921 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 922 $height=NULL, $cache=NULL, $render = true) { 923 924 $ret = ''; 925 926 list($ext,$mime,$dl) = mimetype($src); 927 if(substr($mime,0,5) == 'image'){ 928 // first get the $title 929 if (!is_null($title)) { 930 $title = $this->_xmlEntities($title); 931 }elseif($ext == 'jpg' || $ext == 'jpeg'){ 932 //try to use the caption from IPTC/EXIF 933 require_once(DOKU_INC.'inc/JpegMeta.php'); 934 $jpeg =& new JpegMeta(mediaFN($src)); 935 if($jpeg !== false) $cap = $jpeg->getTitle(); 936 if($cap){ 937 $title = $this->_xmlEntities($cap); 938 } 939 } 940 if (!$render) { 941 // if the picture is not supposed to be rendered 942 // return the title of the picture 943 if (!$title) { 944 // just show the sourcename 945 $title = $this->_xmlEntities(basename(noNS($src))); 946 } 947 return $title; 948 } 949 //add image tag 950 $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache)).'"'; 951 $ret .= ' class="media'.$align.'"'; 952 953 // make left/right alignment for no-CSS view work (feeds) 954 if($align == 'right') $ret .= ' align="right"'; 955 if($align == 'left') $ret .= ' align="left"'; 956 957 if ($title) { 958 $ret .= ' title="' . $title . '"'; 959 $ret .= ' alt="' . $title .'"'; 960 }else{ 961 $ret .= ' alt=""'; 962 } 963 964 if ( !is_null($width) ) 965 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 966 967 if ( !is_null($height) ) 968 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 969 970 $ret .= ' />'; 971 972 }elseif($mime == 'application/x-shockwave-flash'){ 973 if (!$render) { 974 // if the flash is not supposed to be rendered 975 // return the title of the flash 976 if (!$title) { 977 // just show the sourcename 978 $title = basename(noNS($src)); 979 } 980 return $this->_xmlEntities($title); 981 } 982 983 $att = array(); 984 $att['class'] = "media$align"; 985 if($align == 'right') $att['align'] = 'right'; 986 if($align == 'left') $att['align'] = 'left'; 987 $ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height, 988 array('quality' => 'high'), 989 null, 990 $att, 991 $this->_xmlEntities($title)); 992 }elseif($title){ 993 // well at least we have a title to display 994 $ret .= $this->_xmlEntities($title); 995 }else{ 996 // just show the sourcename 997 $ret .= $this->_xmlEntities(basename(noNS($src))); 998 } 999 1000 return $ret; 1001 } 1002 1003 function _xmlEntities($string) { 1004 return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 1005 } 1006 1007 /** 1008 * Creates a linkid from a headline 1009 * 1010 * @param string $title The headline title 1011 * @param boolean $create Create a new unique ID? 1012 * @author Andreas Gohr <andi@splitbrain.org> 1013 */ 1014 function _headerToLink($title,$create=false) { 1015 if($create){ 1016 return sectionID($title,$this->headers); 1017 }else{ 1018 $check = false; 1019 return sectionID($title,$check); 1020 } 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, $linktype='content') { 1029 global $conf; 1030 1031 $isImage = false; 1032 if ( is_null($title) || trim($title)=='') { 1033 if (useHeading($linktype) && $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_array($title) ) { 1041 $isImage = true; 1042 return $this->_imageTitle($title); 1043 } else { 1044 return $this->_xmlEntities($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 * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1065 * which returns a basic link to a media. 1066 * 1067 * @author Pierre Spring <pierre.spring@liip.ch> 1068 * @param string $src 1069 * @param string $title 1070 * @param string $align 1071 * @param string $width 1072 * @param string $height 1073 * @param string $cache 1074 * @param string $render 1075 * @access protected 1076 * @return array 1077 */ 1078 function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) 1079 { 1080 global $conf; 1081 1082 $link = array(); 1083 $link['class'] = 'media'; 1084 $link['style'] = ''; 1085 $link['pre'] = ''; 1086 $link['suf'] = ''; 1087 $link['more'] = ''; 1088 $link['target'] = $conf['target']['media']; 1089 $link['title'] = $this->_xmlEntities($src); 1090 $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1091 1092 return $link; 1093 } 1094 1095 1096} 1097 1098//Setup VIM: ex: et ts=4 enc=utf-8 : 1099