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 $id = count($this->footnotes)+1; 212 $this->doc .= '<a href="#fn'.$id.'" name="fnt'.$id.'" class="fn_top">'.$id.')</a>'; 213 214 // move current content to store and record footnote 215 $this->store = $this->doc; 216 $this->doc = ''; 217 218 $this->doc .= '<div class="fn">'; 219 $this->doc .= '<a href="#fnt'.$id.'" name="fn'.$id.'" class="fn_bot">'; 220 $this->doc .= $id.')</a> '.DOKU_LF; 221 } 222 223 /** 224 * Callback for footnote end syntax 225 * 226 * All rendered content is moved to the $footnotes array and the old 227 * content is restored from $store again 228 * 229 * @author Andreas Gohr 230 */ 231 function footnote_close() { 232 $this->doc .= '</div>' . DOKU_LF; 233 234 // put recorded footnote into the stack and restore old content 235 $this->footnotes[count($this->footnotes)] = $this->doc; 236 $this->doc = $this->store; 237 $this->store = ''; 238 } 239 240 function listu_open() { 241 $this->doc .= '<ul>'.DOKU_LF; 242 } 243 244 function listu_close() { 245 $this->doc .= '</ul>'.DOKU_LF; 246 } 247 248 function listo_open() { 249 $this->doc .= '<ol>'.DOKU_LF; 250 } 251 252 function listo_close() { 253 $this->doc .= '</ol>'.DOKU_LF; 254 } 255 256 function listitem_open($level) { 257 $this->doc .= '<li class="level'.$level.'">'; 258 } 259 260 function listitem_close() { 261 $this->doc .= '</li>'.DOKU_LF; 262 } 263 264 function listcontent_open() { 265 $this->doc .= '<span class="li">'; 266 } 267 268 function listcontent_close() { 269 $this->doc .= '</span>'.DOKU_LF; 270 } 271 272 function unformatted($text) { 273 $this->doc .= $this->_xmlEntities($text); 274 } 275 276 /** 277 * Execute PHP code if allowed 278 * 279 * @author Andreas Gohr <andi@splitbrain.org> 280 */ 281 function php($text) { 282 global $conf; 283 if($conf['phpok']){ 284 ob_start; 285 eval($text); 286 $this->doc .= ob_get_contents(); 287 ob_end_clean; 288 }else{ 289 $this->file($text); 290 } 291 } 292 293 /** 294 * Insert HTML if allowed 295 * 296 * @author Andreas Gohr <andi@splitbrain.org> 297 */ 298 function html($text) { 299 global $conf; 300 if($conf['htmlok']){ 301 $this->doc .= $text; 302 }else{ 303 $this->file($text); 304 } 305 } 306 307 function preformatted($text) { 308 $this->doc .= '<pre class="code">' . $this->_xmlEntities($text) . '</pre>'. DOKU_LF; 309 } 310 311 function file($text) { 312 $this->doc .= '<pre class="file">' . $this->_xmlEntities($text). '</pre>'. DOKU_LF; 313 } 314 315 function quote_open() { 316 $this->doc .= '<blockquote>'.DOKU_LF; 317 } 318 319 function quote_close() { 320 $this->doc .= '</blockquote>'.DOKU_LF; 321 } 322 323 /** 324 * Callback for code text 325 * 326 * Uses GeSHi to highlight language syntax 327 * 328 * @author Andreas Gohr <andi@splitbrain.org> 329 */ 330 function code($text, $language = NULL) { 331 global $conf; 332 333 if ( is_null($language) ) { 334 $this->preformatted($text); 335 } else { 336 //strip leading blank line 337 $text = preg_replace('/^\s*?\n/','',$text); 338 // Handle with Geshi here 339 require_once(DOKU_INC . 'inc/geshi.php'); 340 $geshi = new GeSHi($text, strtolower($language), DOKU_INC . 'inc/geshi'); 341 $geshi->set_encoding('utf-8'); 342 $geshi->enable_classes(); 343 $geshi->set_header_type(GESHI_HEADER_PRE); 344 $geshi->set_overall_class('code'); 345 $geshi->set_link_target($conf['target']['extern']); 346 347 $text = $geshi->parse_code(); 348 $this->doc .= $text; 349 } 350 } 351 352 function acronym($acronym) { 353 354 if ( array_key_exists($acronym, $this->acronyms) ) { 355 356 $title = $this->_xmlEntities($this->acronyms[$acronym]); 357 358 $this->doc .= '<acronym title="'.$title 359 .'">'.$this->_xmlEntities($acronym).'</acronym>'; 360 361 } else { 362 $this->doc .= $this->_xmlEntities($acronym); 363 } 364 } 365 366 /** 367 */ 368 function smiley($smiley) { 369 if ( array_key_exists($smiley, $this->smileys) ) { 370 $title = $this->_xmlEntities($this->smileys[$smiley]); 371 $this->doc .= '<img src="'.DOKU_BASE.'smileys/'.$this->smileys[$smiley]. 372 '" align="middle" alt="'. 373 $this->_xmlEntities($smiley).'" />'; 374 } else { 375 $this->doc .= $this->_xmlEntities($smiley); 376 } 377 } 378 379 /** 380 * not used 381 function wordblock($word) { 382 if ( array_key_exists($word, $this->badwords) ) { 383 $this->doc .= '** BLEEP **'; 384 } else { 385 $this->doc .= $this->_xmlEntities($word); 386 } 387 } 388 */ 389 390 function entity($entity) { 391 if ( array_key_exists($entity, $this->entities) ) { 392 $this->doc .= $this->entities[$entity]; 393 } else { 394 $this->doc .= $this->_xmlEntities($entity); 395 } 396 } 397 398 function multiplyentity($x, $y) { 399 $this->doc .= "$x×$y"; 400 } 401 402 function singlequoteopening() { 403 $this->doc .= "‘"; 404 } 405 406 function singlequoteclosing() { 407 $this->doc .= "’"; 408 } 409 410 function doublequoteopening() { 411 $this->doc .= "“"; 412 } 413 414 function doublequoteclosing() { 415 $this->doc .= "”"; 416 } 417 418 /** 419 */ 420 function camelcaselink($link) { 421 $this->internallink($link,$link); 422 } 423 424 425 function locallink($hash, $name = NULL){ 426 global $ID; 427 $name = $this->_getLinkTitle($name, $hash, $isImage); 428 $hash = $this->_headerToLink($hash); 429 $title = $ID.' ↵'; 430 $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 431 $this->doc .= $name; 432 $this->doc .= '</a>'; 433 } 434 435 /** 436 * Render an internal Wiki Link 437 * 438 * $search and $returnonly are not for the renderer but are used 439 * elsewhere - no need to implement them in other renderers 440 * 441 * @author Andreas Gohr <andi@splitbrain.org> 442 */ 443 function internallink($id, $name = NULL, $search=NULL,$returnonly=false) { 444 global $conf; 445 global $ID; 446 447 // default name is based on $id as given 448 $default = $this->_simpleTitle($id); 449 // now first resolve and clean up the $id 450 resolve_pageid(getNS($ID),$id,$exists); 451 $name = $this->_getLinkTitle($name, $default, $isImage, $id); 452 if ( !$isImage ) { 453 if ( $exists ) { 454 $class='wikilink1'; 455 } else { 456 $class='wikilink2'; 457 } 458 } else { 459 $class='media'; 460 } 461 462 //prepare for formating 463 $link['target'] = $conf['target']['wiki']; 464 $link['style'] = ''; 465 $link['pre'] = ''; 466 $link['suf'] = ''; 467 // highlight link to current page 468 if ($id == $ID) { 469 $link['pre'] = '<span class="curid">'; 470 $link['suf'] = '</span>'; 471 } 472 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 473 $link['class'] = $class; 474 $link['url'] = wl($id); 475 $link['name'] = $name; 476 $link['title'] = $id; 477 478 //add search string 479 if($search){ 480 ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&s='; 481 $link['url'] .= urlencode($search); 482 } 483 484 //output formatted 485 if($returnonly){ 486 return $this->_formatLink($link); 487 }else{ 488 $this->doc .= $this->_formatLink($link); 489 } 490 } 491 492 function externallink($url, $name = NULL) { 493 global $conf; 494 495 $name = $this->_getLinkTitle($name, $url, $isImage); 496 497 // add protocol on simple short URLs 498 if(substr($url,0,3) == 'ftp') $url = 'ftp://'.$url; 499 if(substr($url,0,3) == 'www') $url = 'http://'.$url; 500 501 if ( !$isImage ) { 502 $class='urlextern'; 503 } else { 504 $class='media'; 505 } 506 507 //prepare for formating 508 $link['target'] = $conf['target']['extern']; 509 $link['style'] = ''; 510 $link['pre'] = ''; 511 $link['suf'] = ''; 512 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 513 $link['class'] = $class; 514 $link['url'] = $url; 515 $link['name'] = $name; 516 $link['title'] = $this->_xmlEntities($url); 517 if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 518 519 //output formatted 520 $this->doc .= $this->_formatLink($link); 521 } 522 523 /** 524 */ 525 function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { 526 global $conf; 527 528 $link = array(); 529 $link['target'] = $conf['target']['interwiki']; 530 $link['pre'] = ''; 531 $link['suf'] = ''; 532 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 533 $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 534 535 if ( !$isImage ) { 536 $link['class'] = 'interwiki'; 537 } else { 538 $link['class'] = 'media'; 539 } 540 541 //get interwiki URL 542 if ( isset($this->interwiki[$wikiName]) ) { 543 $url = $this->interwiki[$wikiName]; 544 } else { 545 // Default to Google I'm feeling lucky 546 $url = 'http://www.google.com/search?q={URL}&btnI=lucky'; 547 $wikiName = 'go'; 548 } 549 550 if(!$isImage){ 551 //if ico exists set additional style 552 if(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.png')){ 553 $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.png)'; 554 }elseif(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.gif')){ 555 $link['style']='background-image: url('.DOKU_BASE.'interwiki/'.$wikiName.'.gif)'; 556 } 557 } 558 559 //do we stay at the same server? Use local target 560 if( strpos($url,DOKU_URL) === 0 ){ 561 $link['target'] = $conf['target']['wiki']; 562 } 563 564 //replace placeholder 565 if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){ 566 //use placeholders 567 $url = str_replace('{URL}',urlencode($wikiUri),$url); 568 $url = str_replace('{NAME}',$wikiUri,$url); 569 $parsed = parse_url($wikiUri); 570 if(!$parsed['port']) $parsed['port'] = 80; 571 $url = str_replace('{SCHEME}',$parsed['scheme'],$url); 572 $url = str_replace('{HOST}',$parsed['host'],$url); 573 $url = str_replace('{PORT}',$parsed['port'],$url); 574 $url = str_replace('{PATH}',$parsed['path'],$url); 575 $url = str_replace('{QUERY}',$parsed['query'],$url); 576 $link['url'] = $url; 577 }else{ 578 //default 579 $link['url'] = $url.urlencode($wikiUri); 580 } 581 582 $link['title'] = htmlspecialchars($link['url']); 583 584 //output formatted 585 $this->doc .= $this->_formatLink($link); 586 } 587 588 /** 589 */ 590 function windowssharelink($url, $name = NULL) { 591 global $conf; 592 global $lang; 593 //simple setup 594 $link['target'] = $conf['target']['windows']; 595 $link['pre'] = ''; 596 $link['suf'] = ''; 597 $link['style'] = ''; 598 //Display error on browsers other than IE 599 $link['more'] = 'onclick="if(document.all == null){alert(\''. 600 $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES). 601 '\');}" onkeypress="if(document.all == null){alert(\''. 602 $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"'; 603 604 $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 605 if ( !$isImage ) { 606 $link['class'] = 'windows'; 607 } else { 608 $link['class'] = 'media'; 609 } 610 611 612 $link['title'] = $this->_xmlEntities($url); 613 $url = str_replace('\\','/',$url); 614 $url = 'file:///'.$url; 615 $link['url'] = $url; 616 617 //output formatted 618 $this->doc .= $this->_formatLink($link); 619 } 620 621 function emaillink($address, $name = NULL) { 622 global $conf; 623 //simple setup 624 $link = array(); 625 $link['target'] = ''; 626 $link['pre'] = ''; 627 $link['suf'] = ''; 628 $link['style'] = ''; 629 $link['more'] = ''; 630 631 //we just test for image here - we need to encode the title our self 632 $this->_getLinkTitle($name, $address, $isImage); 633 if ( !$isImage ) { 634 $link['class']='mail'; 635 } else { 636 $link['class']='media'; 637 } 638 639 //shields up 640 if($conf['mailguard']=='visible'){ 641 //the mail name gets some visible encoding 642 $address = str_replace('@',' [at] ',$address); 643 $address = str_replace('.',' [dot] ',$address); 644 $address = str_replace('-',' [dash] ',$address); 645 646 $title = $this->_xmlEntities($address); 647 if(empty($name)){ 648 $name = $this->_xmlEntities($address); 649 }else{ 650 $name = $this->_xmlEntities($name); 651 } 652 }elseif($conf['mailguard']=='hex'){ 653 //encode every char to a hex entity 654 for ($x=0; $x < strlen($address); $x++) { 655 $encode .= '&#x' . bin2hex($address[$x]).';'; 656 } 657 $address = $encode; 658 $title = $encode; 659 if(empty($name)){ 660 $name = $encode; 661 }else{ 662 $name = $this->_xmlEntities($name); 663 } 664 }else{ 665 //keep address as is 666 $title = $this->_xmlEntities($address); 667 if(empty($name)){ 668 $name = $this->_xmlEntities($address); 669 }else{ 670 $name = $this->_xmlEntities($name); 671 } 672 } 673 674 $link['url'] = 'mailto:'.$address; 675 $link['name'] = $name; 676 $link['title'] = $title; 677 678 //output formatted 679 $this->doc .= $this->_formatLink($link); 680 } 681 682 /** 683 * @todo don't add link for flash 684 */ 685 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 686 $height=NULL, $cache=NULL) { 687 global $conf; 688 global $ID; 689 resolve_mediaid(getNS($ID),$src, $exists); 690 691 $link = array(); 692 $link['class'] = 'media'; 693 $link['style'] = ''; 694 $link['pre'] = ''; 695 $link['suf'] = ''; 696 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 697 $link['target'] = $conf['target']['media']; 698 699 $link['title'] = $this->_xmlEntities($src); 700 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 701 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 702 703 704 //output formatted 705 $this->doc .= $this->_formatLink($link); 706 } 707 708 /** 709 * @todo don't add link for flash 710 */ 711 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 712 $height=NULL, $cache=NULL) { 713 global $conf; 714 715 $link = array(); 716 $link['class'] = 'media'; 717 $link['style'] = ''; 718 $link['pre'] = ''; 719 $link['suf'] = ''; 720 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 721 $link['target'] = $conf['target']['media']; 722 723 $link['title'] = $this->_xmlEntities($src); 724 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 725 $link['name'] = $this->_media ($src, $title, $align, $width, $height, $cache); 726 727 728 //output formatted 729 $this->doc .= $this->_formatLink($link); 730 } 731 732 /** 733 * Renders an RSS feed using Magpie 734 * 735 * @author Andreas Gohr <andi@splitbrain.org> 736 */ 737 function rss ($url){ 738 global $lang; 739 define('MAGPIE_CACHE_ON', false); //we do our own caching 740 define('MAGPIE_DIR', DOKU_INC.'inc/magpie/'); 741 define('MAGPIE_OUTPUT_ENCODING','UTF-8'); //return all feeds as UTF-8 742 require_once(MAGPIE_DIR.'/rss_fetch.inc'); 743 744 //disable warning while fetching 745 $elvl = error_reporting(E_ERROR); 746 $rss = fetch_rss($url); 747 error_reporting($elvl); 748 749 $this->doc .= '<ul class="rss">'; 750 if($rss){ 751 foreach ($rss->items as $item ) { 752 $this->doc .= '<li>'; 753 $this->externallink($item['link'],$item['title']); 754 $this->doc .= '</li>'; 755 } 756 }else{ 757 $this->doc .= '<li>'; 758 $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 759 $this->externallink($url); 760 $this->doc .= '</li>'; 761 } 762 $this->doc .= '</ul>'; 763 } 764 765 // $numrows not yet implemented 766 function table_open($maxcols = NULL, $numrows = NULL){ 767 $this->doc .= '<table class="inline">'.DOKU_LF; 768 } 769 770 function table_close(){ 771 $this->doc .= '</table>'.DOKU_LF.'<br />'.DOKU_LF; 772 } 773 774 function tablerow_open(){ 775 $this->doc .= DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 776 } 777 778 function tablerow_close(){ 779 $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 780 } 781 782 function tableheader_open($colspan = 1, $align = NULL){ 783 $this->doc .= '<th'; 784 if ( !is_null($align) ) { 785 $this->doc .= ' class="'.$align.'align"'; 786 } 787 if ( $colspan > 1 ) { 788 $this->doc .= ' colspan="'.$colspan.'"'; 789 } 790 $this->doc .= '>'; 791 } 792 793 function tableheader_close(){ 794 $this->doc .= '</th>'; 795 } 796 797 function tablecell_open($colspan = 1, $align = NULL){ 798 $this->doc .= '<td'; 799 if ( !is_null($align) ) { 800 $this->doc .= ' class="'.$align.'align"'; 801 } 802 if ( $colspan > 1 ) { 803 $this->doc .= ' colspan="'.$colspan.'"'; 804 } 805 $this->doc .= '>'; 806 } 807 808 function tablecell_close(){ 809 $this->doc .= '</td>'; 810 } 811 812 //---------------------------------------------------------- 813 // Utils 814 815 /** 816 * Build a link 817 * 818 * Assembles all parts defined in $link returns HTML for the link 819 * 820 * @author Andreas Gohr <andi@splitbrain.org> 821 */ 822 function _formatLink($link){ 823 //make sure the url is XHTML compliant (skip mailto) 824 if(substr($link['url'],0,7) != 'mailto:'){ 825 $link['url'] = str_replace('&','&',$link['url']); 826 $link['url'] = str_replace('&amp;','&',$link['url']); 827 } 828 //remove double encodings in titles 829 $link['title'] = str_replace('&amp;','&',$link['title']); 830 831 $ret = ''; 832 $ret .= $link['pre']; 833 $ret .= '<a href="'.$link['url'].'"'; 834 if($link['class']) $ret .= ' class="'.$link['class'].'"'; 835 if($link['target']) $ret .= ' target="'.$link['target'].'"'; 836 if($link['title']) $ret .= ' title="'.$link['title'].'"'; 837 if($link['style']) $ret .= ' style="'.$link['style'].'"'; 838 if($link['more']) $ret .= ' '.$link['more']; 839 $ret .= '>'; 840 $ret .= $link['name']; 841 $ret .= '</a>'; 842 $ret .= $link['suf']; 843 return $ret; 844 } 845 846 /** 847 * Removes any Namespace from the given name but keeps 848 * casing and special chars 849 * 850 * @author Andreas Gohr <andi@splitbrain.org> 851 */ 852 function _simpleTitle($name){ 853 global $conf; 854 855 if($conf['useslash']){ 856 $nssep = '[:;/]'; 857 }else{ 858 $nssep = '[:;]'; 859 } 860 $name = preg_replace('!.*'.$nssep.'!','',$name); 861 //if there is a hash we use the ancor name only 862 $name = preg_replace('!.*#!','',$name); 863 return $name; 864 } 865 866 /** 867 * Renders internal and external media 868 * 869 * @author Andreas Gohr <andi@splitbrain.org> 870 */ 871 function _media ($src, $title=NULL, $align=NULL, $width=NULL, 872 $height=NULL, $cache=NULL) { 873 874 $ret = ''; 875 876 list($ext,$mime) = mimetype($src); 877 if(substr($mime,0,5) == 'image'){ 878 //add image tag 879 $ret .= '<img src="'.DOKU_BASE.'fetch.php?w='.$width.'&h='.$height. 880 '&cache='.$cache.'&media='.urlencode($src).'"'; 881 882 $ret .= ' class="media'.$align.'"'; 883 884 if (!is_null($title)) { 885 $ret .= ' title="'.$this->_xmlEntities($title).'"'; 886 $ret .= ' alt="'.$this->_xmlEntities($title).'"'; 887 }else{ 888 $ret .= ' alt=""'; 889 } 890 891 if ( !is_null($width) ) 892 $ret .= ' width="'.$this->_xmlEntities($width).'"'; 893 894 if ( !is_null($height) ) 895 $ret .= ' height="'.$this->_xmlEntities($height).'"'; 896 897 $ret .= ' />'; 898 899 }elseif($mime == 'application/x-shockwave-flash'){ 900 $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 901 ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'; 902 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 903 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 904 $ret .= '>'.DOKU_LF; 905 $ret .= '<param name="movie" value="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'" />'.DOKU_LF; 906 $ret .= '<param name="quality" value="high" />'.DOKU_LF; 907 $ret .= '<embed src="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'"'. 908 ' quality="high"'; 909 if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"'; 910 if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; 911 $ret .= ' type="application/x-shockwave-flash"'. 912 ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'.DOKU_LF; 913 $ret .= '</object>'.DOKU_LF; 914 915 }elseif(!is_null($title)){ 916 // well at least we have a title to display 917 $ret .= $this->_xmlEntities($title); 918 }else{ 919 // just show the source 920 $ret .= $this->_xmlEntities($src); 921 } 922 923 return $ret; 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