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'; 22 23/** 24 * The Renderer 25 */ 26class Doku_Renderer_xhtml extends Doku_Renderer { 27 28 var $doc = ''; 29 30 var $headers = array(); 31 32 var $footnotes = array(); 33 34 var $acronyms = array(); 35 var $smileys = array(); 36 var $badwords = array(); 37 var $entities = array(); 38 var $interwiki = array(); 39 40 var $lastsec = 0; 41 42 var $store = ''; 43 44 45 function document_start() { 46 } 47 48 function document_end() { 49 // add button for last section if any and more than one 50 if($this->lastsec > 1) $this->_secedit($this->lastsec,''); 51 52 if ( count ($this->footnotes) > 0 ) { 53 $this->doc .= '<div class="footnotes">'.DOKU_LF; 54 foreach ( $this->footnotes as $footnote ) { 55 $this->doc .= $footnote; 56 } 57 $this->doc .= '</div>'.DOKU_LF; 58 } 59 } 60 61 function toc_open() { 62 global $lang; 63 $this->doc .= '<div class="toc">'.DOKU_LF; 64 $this->doc .= '<div class="tocheader">'; 65 $this->doc .= $lang['toc']; 66 $this->doc .= ' <script type="text/javascript">showTocToggle("+","-")'; 67 $this->doc .= '</script></div>'.DOKU_LF; 68 $this->doc .= '<div id="tocinside">'.DOKU_LF; 69 } 70 71 function tocbranch_open($level) { 72 $this->doc .= '<ul class="toc">'.DOKU_LF; 73 } 74 75 function tocitem_open($level, $empty = FALSE) { 76 if ( !$empty ) { 77 $this->doc .= '<li class="level'.$level.'">'; 78 } else { 79 $this->doc .= '<li class="clear">'; 80 } 81 } 82 83 function tocelement($level, $title) { 84 $this->doc .= '<span class="li"><a href="#'.$this->_headerToLink($title).'" class="toc">'; 85 $this->doc .= $this->_xmlEntities($title); 86 $this->doc .= '</a></span>'; 87 } 88 89 function tocitem_close($level) { 90 $this->doc .= '</li>'.DOKU_LF; 91 } 92 93 function tocbranch_close($level) { 94 $this->doc .= '</ul>'.DOKU_LF; 95 } 96 97 function toc_close() { 98 $this->doc .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 99 } 100 101 function header($text, $level, $pos) { 102 global $conf; 103 //handle section editing 104 if($level <= $conf['maxseclevel']){ 105 // add button for last section if any 106 if($this->lastsec) $this->_secedit($this->lastsec,$pos-1); 107 // remember current position 108 $this->lastsec = $pos; 109 } 110 111 $this->doc .= DOKU_LF.'<a name="'.$this->_headerToLink($text).'"></a><h'.$level.'>'; 112 $this->doc .= $this->_xmlEntities($text); 113 $this->doc .= "</h$level>".DOKU_LF; 114 } 115 116 function section_open($level) { 117 $this->doc .= "<div class=\"level$level\">".DOKU_LF; 118 } 119 120 function section_close() { 121 $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 122 } 123 124 function cdata($text) { 125 $this->doc .= $this->_xmlEntities($text); 126 } 127 128 function p_open() { 129 $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 130 } 131 132 function p_close() { 133 $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 134 } 135 136 function linebreak() { 137 $this->doc .= '<br/>'.DOKU_LF; 138 } 139 140 function hr() { 141 $this->doc .= '<hr noshade="noshade" size="1" />'.DOKU_LF; 142 } 143 144 function strong_open() { 145 $this->doc .= '<strong>'; 146 } 147 148 function strong_close() { 149 $this->doc .= '</strong>'; 150 } 151 152 function emphasis_open() { 153 $this->doc .= '<em>'; 154 } 155 156 function emphasis_close() { 157 $this->doc .= '</em>'; 158 } 159 160 function underline_open() { 161 $this->doc .= '<u>'; 162 } 163 164 function underline_close() { 165 $this->doc .= '</u>'; 166 } 167 168 function monospace_open() { 169 $this->doc .= '<code>'; 170 } 171 172 function monospace_close() { 173 $this->doc .= '</code>'; 174 } 175 176 function subscript_open() { 177 $this->doc .= '<sub>'; 178 } 179 180 function subscript_close() { 181 $this->doc .= '</sub>'; 182 } 183 184 function superscript_open() { 185 $this->doc .= '<sup>'; 186 } 187 188 function superscript_close() { 189 $this->doc .= '</sup>'; 190 } 191 192 function deleted_open() { 193 $this->doc .= '<del>'; 194 } 195 196 function deleted_close() { 197 $this->doc .= '</del>'; 198 } 199 200 /** 201 * Callback for footnote start syntax 202 * 203 * All following content will go to the footnote instead of 204 * the document. To achive this the previous rendered content 205 * is moved to $store and $doc is cleared 206 * 207 * @author Andreas Gohr <andi@splitbrain.org> 208 */ 209 function footnote_open() { 210 $id = $this->_newFootnoteId(); 211 $this->doc .= '<a href="#fn'.$id.'" name="fnt'.$id.'" class="fn_top">'.$id.')</a>'; 212 213 // move current content to store and record footnote 214 $this->store = $this->doc; 215 $this->doc = ''; 216 217 $this->doc .= '<div class="fn">'; 218 $this->doc .= '<a href="#fnt'.$id.'" name="fn'.$id.'" class="fn_bot">'; 219 $this->doc .= $id.')</a> '.DOKU_LF; 220 } 221 222 /** 223 * Callback for footnote end syntax 224 * 225 * All rendered content is moved to the $footnotes array and the old 226 * content is restored from $store again 227 * 228 * @author Andreas Gohr 229 */ 230 function footnote_close() { 231 $this->doc .= '</div>' . DOKU_LF; 232 233 // put recorded footnote into the stack and restore old content 234 $this->footnotes[count($this->footnotes)] = $this->doc; 235 $this->doc = $this->store; 236 $this->store = ''; 237 } 238 239 function listu_open() { 240 $this->doc .= '<ul>'.DOKU_LF; 241 } 242 243 function listu_close() { 244 $this->doc .= '</ul>'.DOKU_LF; 245 } 246 247 function listo_open() { 248 $this->doc .= '<ol>'.DOKU_LF; 249 } 250 251 function listo_close() { 252 $this->doc .= '</ol>'.DOKU_LF; 253 } 254 255 function listitem_open($level) { 256 $this->doc .= '<li class="level'.$level.'">'; 257 } 258 259 function listitem_close() { 260 $this->doc .= '</li>'.DOKU_LF; 261 } 262 263 function listcontent_open() { 264 $this->doc .= '<span class="li">'; 265 } 266 267 function listcontent_close() { 268 $this->doc .= '</span>'.DOKU_LF; 269 } 270 271 function unformatted($text) { 272 $this->doc .= $this->_xmlEntities($text); 273 } 274 275 /** 276 * Execute PHP code if allowed 277 * 278 * @author Andreas Gohr <andi@splitbrain.org> 279 */ 280 function php($text) { 281 global $conf; 282 if($conf['phpok']){ 283 ob_start; 284 eval($text); 285 $this->doc .= ob_get_contents(); 286 ob_end_clean; 287 }else{ 288 $this->file($text); 289 } 290 } 291 292 /** 293 * Insert HTML if allowed 294 * 295 * @author Andreas Gohr <andi@splitbrain.org> 296 */ 297 function html($text) { 298 global $conf; 299 if($conf['htmlok']){ 300 $this->doc .= $text; 301 }else{ 302 $this->file($text); 303 } 304 } 305 306 function preformatted($text) { 307 $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 308 } 309 310 function file($text) { 311 $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 312 } 313 314 function quote_open() { 315 $this->doc .= '<blockquote>'.DOKU_LF; 316 } 317 318 function quote_close() { 319 $this->doc .= '</blockquote>'.DOKU_LF; 320 } 321 322 /** 323 * Callback for code text 324 * 325 * Uses GeSHi to highlight language syntax 326 * 327 * @author Andreas Gohr <andi@splitbrain.org> 328 */ 329 function code($text, $language = NULL) { 330 global $conf; 331 332 if ( is_null($language) ) { 333 $this->preformatted($text); 334 } else { 335 //strip leading blank line 336 $text = preg_replace('/^\s*?\n/','',$text); 337 // Handle with Geshi here 338 require_once(DOKU_INC . 'inc/geshi.php'); 339 $geshi = new GeSHi($text, strtolower($language), DOKU_INC . 'inc/geshi'); 340 $geshi->set_encoding('utf-8'); 341 $geshi->enable_classes(); 342 $geshi->set_header_type(GESHI_HEADER_PRE); 343 $geshi->set_overall_class('code'); 344 $geshi->set_link_target($conf['target']['extern']); 345 346 $text = $geshi->parse_code(); 347 $this->doc .= $text; 348 } 349 } 350 351 function acronym($acronym) { 352 353 if ( array_key_exists($acronym, $this->acronyms) ) { 354 355 $title = $this->_xmlEntities($this->acronyms[$acronym]); 356 357 $this->doc .= '<acronym title="'.$title 358 .'">'.$this->_xmlEntities($acronym).'</acronym>'; 359 360 } else { 361 $this->doc .= $this->_xmlEntities($acronym); 362 } 363 } 364 365 /** 366 */ 367 function smiley($smiley) { 368 if ( array_key_exists($smiley, $this->smileys) ) { 369 $title = $this->_xmlEntities($this->smileys[$smiley]); 370 $this->doc .= '<img src="'.DOKU_BASE.'smileys/'.$this->smileys[$smiley]. 371 '" align="middle" alt="'. 372 $this->_xmlEntities($smiley).'" />'; 373 } else { 374 $this->doc .= $this->_xmlEntities($smiley); 375 } 376 } 377 378 /** 379 * not used 380 function wordblock($word) { 381 if ( array_key_exists($word, $this->badwords) ) { 382 $this->doc .= '** BLEEP **'; 383 } else { 384 $this->doc .= $this->_xmlEntities($word); 385 } 386 } 387 */ 388 389 function entity($entity) { 390 if ( array_key_exists($entity, $this->entities) ) { 391 $this->doc .= $this->entities[$entity]; 392 } else { 393 $this->doc .= $this->_xmlEntities($entity); 394 } 395 } 396 397 function multiplyentity($x, $y) { 398 $this->doc .= "$x×$y"; 399 } 400 401 function singlequoteopening() { 402 $this->doc .= "‘"; 403 } 404 405 function singlequoteclosing() { 406 $this->doc .= "’"; 407 } 408 409 function doublequoteopening() { 410 $this->doc .= "“"; 411 } 412 413 function doublequoteclosing() { 414 $this->doc .= "”"; 415 } 416 417 /** 418 */ 419 function camelcaselink($link) { 420 $this->internallink($link,$link); 421 } 422 423 424 function locallink($hash, $name = NULL){ 425 global $ID; 426 $name = $this->_getLinkTitle($name, $hash, $isImage); 427 $hash = $this->_headerToLink($hash); 428 $title = $ID.' ↵'; 429 $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 430 $this->doc .= $name; 431 $this->doc .= '</a>'; 432 } 433 434 /** 435 * Render an internal Wiki Link 436 * 437 * $search and $returnonly are not for the renderer but are used 438 * elsewhere - no need to implement them in other renderers 439 * 440 * @author Andreas Gohr <andi@splitbrain.org> 441 */ 442 function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 443 global $conf; 444 global $ID; 445 446 // default name is based on $id as given 447 $default = $this->_simpleTitle($id); 448 // now first resolve and clean up the $id 449 resolve_pageid(getNS($ID),$id,$exists); 450 $name = $this->_getLinkTitle($name, $default, $isImage, $id); 451 if ( !$isImage ) { 452 if ( $exists ) { 453 $class='wikilink1'; 454 } else { 455 $class='wikilink2'; 456 } 457 } else { 458 $class='media'; 459 } 460 461 //prepare for formating 462 $link['target'] = $conf['target']['wiki']; 463 $link['style'] = ''; 464 $link['pre'] = ''; 465 $link['suf'] = ''; 466 // highlight link to current page 467 if ($id == $ID) { 468 $link['pre'] = '<span class="curid">'; 469 $link['suf'] = '</span>'; 470 } 471 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 472 $link['class'] = $class; 473 $link['url'] = wl($id); 474 $link['name'] = $name; 475 $link['title'] = $id; 476 477 //add search string 478 if($search){ 479 ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 480 $link['url'] .= urlencode($search); 481 } 482 483 //output formatted 484 if($returnonly){ 485 return $this->_formatLink($link); 486 }else{ 487 $this->doc .= $this->_formatLink($link); 488 } 489 } 490 491 function externallink($url, $name = NULL) { 492 global $conf; 493 494 $name = $this->_getLinkTitle($name, $url, $isImage); 495 496 // add protocol on simple short URLs 497 if(substr($url,0,3) == 'ftp') $url = 'ftp://'.$url; 498 if(substr($url,0,3) == 'www') $url = 'http://'.$url; 499 500 if ( !$isImage ) { 501 $class='urlextern'; 502 } else { 503 $class='media'; 504 } 505 506 //prepare for formating 507 $link['target'] = $conf['target']['extern']; 508 $link['style'] = ''; 509 $link['pre'] = ''; 510 $link['suf'] = ''; 511 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 512 $link['class'] = $class; 513 $link['url'] = $url; 514 $link['name'] = $name; 515 $link['title'] = $this->_xmlEntities($url); 516 if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 517 518 //output formatted 519 $this->doc .= $this->_formatLink($link); 520 } 521 522 /** 523 */ 524 function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 525 global $conf; 526 527 $link = array(); 528 $link['target'] = $conf['target']['interwiki']; 529 $link['pre'] = ''; 530 $link['suf'] = ''; 531 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 532 $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 533 534 if ( !$isImage ) { 535 $link['class'] = 'interwiki'; 536 } else { 537 $link['class'] = 'media'; 538 } 539 540 //get interwiki URL 541 if ( isset($this->interwiki[$wikiName]) ) { 542 $url = $this->interwiki[$wikiName]; 543 } else { 544 // Default to Google I'm feeling lucky 545 $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 546 $wikiName = 'go'; 547 } 548 549 if(!$isImage){ 550 //if ico exists set additional style 551 if(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.png')){ 552 $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.png)'; 553 }elseif(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.gif')){ 554 $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.gif)'; 555 } 556 } 557 558 //do we stay at the same server? Use local target 559 if( strpos($url,DOKU_URL) === 0 ){ 560 $link['target'] = $conf['target']['wiki']; 561 } 562 563 //replace placeholder 564 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 565 //use placeholders 566 $url = str_replace('{URL}',urlencode($wikiUri),$url); 567 $url = str_replace('{NAME}',$wikiUri,$url); 568 $parsed = parse_url($wikiUri); 569 if(!$parsed['port']) $parsed['port'] = 80; 570 $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 571 $url = str_replace('{HOST}',$parsed['host'],$url); 572 $url = str_replace('{PORT}',$parsed['port'],$url); 573 $url = str_replace('{PATH}',$parsed['path'],$url); 574 $url = str_replace('{QUERY}',$parsed['query'],$url); 575 $link['url'] = $url; 576 }else{ 577 //default 578 $link['url'] = $url.urlencode($wikiUri); 579 } 580 581 $link['title'] = htmlspecialchars($link['url']); 582 583 //output formatted 584 $this->doc .= $this->_formatLink($link); 585 } 586 587 /** 588 */ 589 function windowssharelink($url, $name = NULL) { 590 global $conf; 591 global $lang; 592 //simple setup 593 $link['target'] = $conf['target']['windows']; 594 $link['pre'] = ''; 595 $link['suf'] = ''; 596 $link['style'] = ''; 597 //Display error on browsers other than IE 598 $link['more'] = 'onclick="if(document.all == null){alert(\''. 599 $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES). 600 '\');}" onkeypress="if(document.all == null){alert(\''. 601 $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"'; 602 603 $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 604 if ( !$isImage ) { 605 $link['class'] = 'windows'; 606 } else { 607 $link['class'] = 'media'; 608 } 609 610 611 $link['title'] = $this->_xmlEntities($url); 612 $url = str_replace('\\','/',$url); 613 $url = 'file:///'.$url; 614 $link['url'] = $url; 615 616 //output formatted 617 $this->doc .= $this->_formatLink($link); 618 } 619 620 function emaillink($address, $name = NULL) { 621 global $conf; 622 //simple setup 623 $link = array(); 624 $link['target'] = ''; 625 $link['pre'] = ''; 626 $link['suf'] = ''; 627 $link['style'] = ''; 628 $link['more'] = ''; 629 630 //we just test for image here - we need to encode the title our self 631 $this->_getLinkTitle($name, $address, $isImage); 632 if ( !$isImage ) { 633 $link['class']='mail'; 634 } else { 635 $link['class']='media'; 636 } 637 638 //shields up 639 if($conf['mailguard']=='visible'){ 640 //the mail name gets some visible encoding 641 $address = str_replace('@',' [at] ',$address); 642 $address = str_replace('.',' [dot] ',$address); 643 $address = str_replace('-',' [dash] ',$address); 644 645 $title = $this->_xmlEntities($address); 646 if(empty($name)){ 647 $name = $this->_xmlEntities($address); 648 }else{ 649 $name = $this->_xmlEntities($name); 650 } 651 }elseif($conf['mailguard']=='hex'){ 652 //encode every char to a hex entity 653 for ($x=0; $x < strlen($address); $x++) { 654 $encode .= '&#x' . bin2hex($address[$x]).';'; 655 } 656 $address = $encode; 657 $title = $encode; 658 if(empty($name)){ 659 $name = $encode; 660 }else{ 661 $name = $this->_xmlEntities($name); 662 } 663 }else{ 664 //keep address as is 665 $title = $this->_xmlEntities($address); 666 if(empty($name)){ 667 $name = $this->_xmlEntities($address); 668 }else{ 669 $name = $this->_xmlEntities($name); 670 } 671 } 672 673 $link['url'] = 'mailto:'.$address; 674 $link['name'] = $name; 675 $link['title'] = $title; 676 677 //output formatted 678 $this->doc .= $this->_formatLink($link); 679 } 680 681 /** 682 * @todo don't add link for flash 683 */ 684 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 685 $height=NULL, $cache=NULL) { 686 global $conf; 687 global $ID; 688 resolve_mediaid(getNS($ID),$src, $exists); 689 690 $link = array(); 691 $link['class'] = 'media'; 692 $link['style'] = ''; 693 $link['pre'] = ''; 694 $link['suf'] = ''; 695 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 696 $link['target'] = $conf['target']['media']; 697 698 $link['title'] = $this->_xmlEntities($src); 699 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 700 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 701 702 703 //output formatted 704 $this->doc .= $this->_formatLink($link); 705 } 706 707 /** 708 * @todo don't add link for flash 709 */ 710 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 711 $height=NULL, $cache=NULL) { 712 global $conf; 713 714 $link = array(); 715 $link['class'] = 'media'; 716 $link['style'] = ''; 717 $link['pre'] = ''; 718 $link['suf'] = ''; 719 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 720 $link['target'] = $conf['target']['media']; 721 722 $link['title'] = $this->_xmlEntities($src); 723 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 724 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 725 726 727 //output formatted 728 $this->doc .= $this->_formatLink($link); 729 } 730 731 /** 732 * Renders an RSS feed using Magpie 733 * 734 * @author Andreas Gohr <andi@splitbrain.org> 735 */ 736 function rss ($url){ 737 global $lang; 738 define('MAGPIE_CACHE_ON', false); //we do our own caching 739 define('MAGPIE_DIR', DOKU_INC.'inc/magpie/'); 740 define('MAGPIE_OUTPUT_ENCODING','UTF-8'); //return all feeds as UTF-8 741 require_once(MAGPIE_DIR.'/rss_fetch.inc'); 742 743 //disable warning while fetching 744 $elvl = error_reporting(E_ERROR); 745 $rss = fetch_rss($url); 746 error_reporting($elvl); 747 748 $this->doc .= '<ul class="rss">'; 749 if($rss){ 750 foreach ($rss->items as $item ) { 751 $this->doc .= '<li>'; 752 $this->externallink($item['link'],$item['title']); 753 $this->doc .= '</li>'; 754 } 755 }else{ 756 $this->doc .= '<li>'; 757 $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 758 $this->externallink($url); 759 $this->doc .= '</li>'; 760 } 761 $this->doc .= '</ul>'; 762 } 763 764 // $numrows not yet implemented 765 function table_open($maxcols = NULL, $numrows = NULL){ 766 $this->doc .= '<table class="inline">'.DOKU_LF; 767 } 768 769 function table_close(){ 770 $this->doc .= '</table>'.DOKU_LF.'<br />'.DOKU_LF; 771 } 772 773 function tablerow_open(){ 774 $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 775 } 776 777 function tablerow_close(){ 778 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 779 } 780 781 function tableheader_open($colspan = 1, $align = NULL){ 782 $this->doc .= '<th'; 783 if ( !is_null($align) ) { 784 $this->doc .= ' class="'.$align.'align"'; 785 } 786 if ( $colspan > 1 ) { 787 $this->doc .= ' colspan="'.$colspan.'"'; 788 } 789 $this->doc .= '>'; 790 } 791 792 function tableheader_close(){ 793 $this->doc .= '</th>'; 794 } 795 796 function tablecell_open($colspan = 1, $align = NULL){ 797 $this->doc .= '<td'; 798 if ( !is_null($align) ) { 799 $this->doc .= ' class="'.$align.'align"'; 800 } 801 if ( $colspan > 1 ) { 802 $this->doc .= ' colspan="'.$colspan.'"'; 803 } 804 $this->doc .= '>'; 805 } 806 807 function tablecell_close(){ 808 $this->doc .= '</td>'; 809 } 810 811 //---------------------------------------------------------- 812 // Utils 813 814 /** 815 * Build a link 816 * 817 * Assembles all parts defined in $link returns HTML for the link 818 * 819 * @author Andreas Gohr <andi@splitbrain.org> 820 */ 821 function _formatLink($link){ 822 //make sure the url is XHTML compliant (skip mailto) 823 if(substr($link['url'],0,7) != 'mailto:'){ 824 $link['url'] = str_replace('&','&',$link['url']); 825 $link['url'] = str_replace('&amp;','&',$link['url']); 826 } 827 //remove double encodings in titles 828 $link['title'] = str_replace('&amp;','&',$link['title']); 829 830 $ret = ''; 831 $ret .= $link['pre']; 832 $ret .= '<a href="'.$link['url'].'"'; 833 if($link['class']) $ret .= ' class="'.$link['class'].'"'; 834 if($link['target']) $ret .= ' target="'.$link['target'].'"'; 835 if($link['title']) $ret .= ' title="'.$link['title'].'"'; 836 if($link['style']) $ret .= ' style="'.$link['style'].'"'; 837 if($link['more']) $ret .= ' '.$link['more']; 838 $ret .= '>'; 839 $ret .= $link['name']; 840 $ret .= '</a>'; 841 $ret .= $link['suf']; 842 return $ret; 843 } 844 845 /** 846 * Removes any Namespace from the given name but keeps 847 * casing and special chars 848 * 849 * @author Andreas Gohr <andi@splitbrain.org> 850 */ 851 function _simpleTitle($name){ 852 global $conf; 853 854 if($conf['useslash']){ 855 $nssep = '[:;/]'; 856 }else{ 857 $nssep = '[:;]'; 858 } 859 $name = preg_replace('!.*'.$nssep.'!','',$name); 860 //if there is a hash we use the ancor name only 861 $name = preg_replace('!.*#!','',$name); 862 return $name; 863 } 864 865 /** 866 * Renders internal and external media 867 * 868 * @author Andreas Gohr <andi@splitbrain.org> 869 */ 870 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 871 $height=NULL, $cache=NULL) { 872 873 $ret = ''; 874 875 list($ext,$mime) = mimetype($src); 876 if(substr($mime,0,5) == 'image'){ 877 //add image tag 878 $ret .= '<img src="'.DOKU_BASE.'fetch.php?w='.$width.'&h='.$height. 879 '&cache='.$cache.'&media='.urlencode($src).'"'; 880 881 $ret .= ' class="media'.$align.'"'; 882 883 if (!is_null($title)) { 884 $ret .= ' title="'.$this->_xmlEntities($title).'"'; 885 $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 886 }else{ 887 $ret .= ' alt=""'; 888 } 889 890 if ( !is_null($width) ) 891 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 892 893 if ( !is_null($height) ) 894 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 895 896 $ret .= ' />'; 897 898 }elseif($mime == 'application/x-shockwave-flash'){ 899 $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 900 ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 901 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 902 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 903 $ret .= '>'.DOKU_LF; 904 $ret .= '<param name="movie" value="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'" />'.DOKU_LF; 905 $ret .= '<param name="quality" value="high" />'.DOKU_LF; 906 $ret .= '<embed src="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'"'. 907 ' quality="high"'; 908 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 909 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 910 $ret .= ' type="application/x-shockwave-flash"'. 911 ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 912 $ret .= '</object>'.DOKU_LF; 913 914 }elseif(!is_null($title)){ 915 // well at least we have a title to display 916 $ret .= $this->_xmlEntities($title); 917 }else{ 918 // just show the source 919 $ret .= $this->_xmlEntities($src); 920 } 921 922 return $ret; 923 } 924 925 function _newFootnoteId() { 926 static $id = 1; 927 return $id++; 928 } 929 930 function _xmlEntities($string) { 931 return htmlspecialchars($string); 932 } 933 934 function _headerToLink($title) { 935 return str_replace(':','',cleanID($title)); 936 } 937 938 /** 939 * Adds code for section editing button 940 * 941 * This is just aplaceholder and gets replace by the button if 942 * section editing is allowed 943 * 944 * @author Andreas Gohr <andi@splitbrain.org> 945 */ 946 function _secedit($f, $t){ 947 $this->doc .= '<!-- SECTION ['.$f.'-'.$t.'] -->'; 948 } 949 950 /** 951 * Construct a title and handle images in titles 952 * 953 * @author Harry Fuecks <hfuecks@gmail.com> 954 */ 955 function _getLinkTitle($title, $default, & $isImage, $id=NULL) { 956 global $conf; 957 958 $isImage = FALSE; 959 if ( is_null($title) ) { 960 if ($conf['useheading'] && $id) { 961 $heading = p_get_first_heading($id); 962 if ($heading) { 963 return $this->_xmlEntities($heading); 964 } 965 } 966 return $this->_xmlEntities($default); 967 } else if ( is_string($title) ) { 968 return $this->_xmlEntities($title); 969 } else if ( is_array($title) ) { 970 $isImage = TRUE; 971 return $this->_imageTitle($title); 972 } 973 } 974 975 /** 976 * Returns an HTML code for images used in link titles 977 * 978 * @todo Resolve namespace on internal images 979 * @author Andreas Gohr <andi@splitbrain.org> 980 */ 981 function _imageTitle($img) { 982 return $this->_media($img['src'], 983 $img['title'], 984 $img['align'], 985 $img['width'], 986 $img['height'], 987 $img['cache']); 988 } 989} 990 991//Setup VIM: ex: et ts=4 enc=utf-8 : 992