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