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