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