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