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 */ 520 function filelink($link, $title = NULL) { 521 echo '<a'; 522 523 $title = $this->__getLinkTitle($title, $link, $isImage); 524 525 if ( !$isImage ) { 526 echo ' class="windows"'; 527 } else { 528 echo ' class="media"'; 529 } 530 531 echo ' href="'.$this->__xmlEntities($link).'"'; 532 533 echo ' style="background: transparent url(http://wiki.splitbrain.org/images/windows.gif) 0px 1px no-repeat;"'; 534 535 echo ' onclick="return svchk()" onkeypress="return svchk()">'; 536 537 echo $title; 538 539 echo '</a>'; 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 /** 571 * @TODO Protect email address from harvesters 572 * @TODO Remove hard coded link to splitbrain.org 573 */ 574 function email($address, $title = NULL) { 575 echo '<a'; 576 577 $title = $this->__getLinkTitle($title, $address, $isImage); 578 579 if ( !$isImage ) { 580 echo ' class="mail"'; 581 } else { 582 echo ' class="media"'; 583 } 584 585 echo ' href="mailto:'.$this->__xmlEntities($address).'"'; 586 587 echo ' style="background: transparent url(http://wiki.splitbrain.org/images/mail_icon.gif) 0px 1px no-repeat;"'; 588 589 echo ' onclick="return svchk()" onkeypress="return svchk()">'; 590 591 echo $title; 592 593 echo '</a>'; 594 595 } 596 597 /** 598 * @todo don't add link for flash 599 */ 600 function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 601 $height=NULL, $cache=NULL) { 602 global $conf; 603 resolve_mediaid($src, $exists); 604 605 $link = array(); 606 $link['class'] = 'media'; 607 $link['style'] = ''; 608 $link['pre'] = ''; 609 $link['suf'] = ''; 610 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 611 $link['target'] = $conf['target']['media']; 612 613 $link['title'] = $this->__xmlEntities($src); 614 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 615 $link['name'] = $this->__media ($src, $title, $align, $width, $height, $cache); 616 617 618 //output formatted 619 echo $this->__formatLink($link); 620 } 621 622 /** 623 * @todo don't add link for flash 624 */ 625 function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, 626 $height=NULL, $cache=NULL) { 627 global $conf; 628 629 $link = array(); 630 $link['class'] = 'media'; 631 $link['style'] = ''; 632 $link['pre'] = ''; 633 $link['suf'] = ''; 634 $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; 635 $link['target'] = $conf['target']['media']; 636 637 $link['title'] = $this->__xmlEntities($src); 638 $link['url'] = DOKU_BASE.'fetch.php?cache='.$cache.'&media='.urlencode($src); 639 $link['name'] = $this->__media ($src, $title, $align, $width, $height, $cache); 640 641 642 //output formatted 643 echo $this->__formatLink($link); 644 } 645 646 /** 647 * Renders an RSS feed using magpie 648 * 649 * @author Andreas Gohr <andi@splitbrain.org> 650 */ 651 function rss ($url){ 652 global $lang; 653 define('MAGPIE_CACHE_ON', false); //we do our own caching 654 define('MAGPIE_DIR', DOKU_INC.'inc/magpie/'); 655 define('MAGPIE_OUTPUT_ENCODING','UTF-8'); //return all feeds as UTF-8 656 require_once(MAGPIE_DIR.'/rss_fetch.inc'); 657 658 //disable warning while fetching 659 $elvl = error_reporting(E_ERROR); 660 $rss = fetch_rss($url); 661 error_reporting($elvl); 662 663 print '<ul class="rss">'; 664 if($rss){ 665 foreach ($rss->items as $item ) { 666 print '<li>'; 667 $this->externallink($item['link'],$item['title']); 668 print '</li>'; 669 } 670 }else{ 671 print '<li>'; 672 print '<em>'.$lang['rssfailed'].'</em>'; 673 $this->externallink($url); 674 print '</li>'; 675 } 676 print '</ul>'; 677 } 678 679 /** 680 * Renders internal and external media 681 * 682 * @author Andreas Gohr <andi@splitbrain.org> 683 * @todo handle center align 684 * @todo move to bottom 685 */ 686 function __media ($src, $title=NULL, $align=NULL, $width=NULL, 687 $height=NULL, $cache=NULL) { 688 689 $ret = ''; 690 691 list($ext,$mime) = mimetype($src); 692 if(substr($mime,0,5) == 'image'){ 693 //add image tag 694 $ret .= '<img src="'.DOKU_BASE.'fetch.php?w='.$width.'&h='.$height. 695 '&cache='.$cache.'&media='.urlencode($src).'"'; 696 697 $ret .= ' class="media'.$align.'"'; 698 699 if (!is_null($title)) 700 $ret .= ' title="'.$this->__xmlEntities($title).'"'; 701 702 if ( !is_null($width) ) 703 $ret .= ' width="'.$this->__xmlEntities($width).'"'; 704 705 if ( !is_null($height) ) 706 $ret .= ' height="'.$this->__xmlEntities($height).'"'; 707 708 $ret .= ' />'; 709 710 }elseif($mime == 'application/x-shockwave-flash'){ 711 //FIXME default to a higher flash version? 712 713 $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'. 714 ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"'; 715 if ( !is_null($width) ) $ret .= ' width="'.$this->__xmlEntities($width).'"'; 716 if ( !is_null($height) ) $ret .= ' height="'.$this->__xmlEntities($height).'"'; 717 $ret .= '>'.DOKU_LF; 718 $ret .= '<param name="movie" value="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'" />'.DOKU_LF; 719 $ret .= '<param name="quality" value="high" />'.DOKU_LF; 720 $ret .= '<embed src="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'"'. 721 ' quality="high" bgcolor="#000000"'; 722 if ( !is_null($width) ) $ret .= ' width="'.$this->__xmlEntities($width).'"'; 723 if ( !is_null($height) ) $ret .= ' height="'.$this->__xmlEntities($height).'"'; 724 $ret .= ' type="application/x-shockwave-flash"'. 725 ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi'. 726 '?P1_Prod_Version=ShockwaveFlash"></embed>'.DOKU_LF; 727 $ret .= '</object>'.DOKU_LF; 728 729 }elseif(!is_null($title)){ 730 // well at least we have a title to display 731 $ret .= $this->__xmlEntities($title); 732 }else{ 733 // just show the source 734 $ret .= $this->__xmlEntities($src); 735 } 736 737 return $ret; 738 } 739 740 // $numrows not yet implemented 741 function table_open($maxcols = NULL, $numrows = NULL){ 742 echo '<table class="inline">'.DOKU_LF; 743 } 744 745 function table_close(){ 746 echo '</table>'.DOKU_LF.'<br />'.DOKU_LF; 747 } 748 749 function tablerow_open(){ 750 echo DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB; 751 } 752 753 function tablerow_close(){ 754 echo DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 755 } 756 757 function tableheader_open($colspan = 1, $align = NULL){ 758 echo '<th'; 759 if ( !is_null($align) ) { 760 echo ' class="'.$align.'align"'; 761 } 762 if ( $colspan > 1 ) { 763 echo ' colspan="'.$colspan.'"'; 764 } 765 echo '>'; 766 } 767 768 function tableheader_close(){ 769 echo '</th>'; 770 } 771 772 function tablecell_open($colspan = 1, $align = NULL){ 773 echo '<td'; 774 if ( !is_null($align) ) { 775 echo ' class="'.$align.'align"'; 776 } 777 if ( $colspan > 1 ) { 778 echo ' colspan="'.$colspan.'"'; 779 } 780 echo '>'; 781 } 782 783 function tablecell_close(){ 784 echo '</td>'; 785 } 786 787 //---------------------------------------------------------- 788 // Utils 789 790 /** 791 * Assembles all parts defined by the link formater below 792 * Returns HTML for the link 793 * 794 * @author Andreas Gohr <andi@splitbrain.org> 795 */ 796 function __formatLink($link){ 797 //make sure the url is XHTML compliant (skip mailto) 798 if(substr($link['url'],0,7) != 'mailto:'){ 799 $link['url'] = str_replace('&','&',$link['url']); 800 $link['url'] = str_replace('&amp;','&',$link['url']); 801 } 802 //remove double encodings in titles 803 $link['title'] = str_replace('&amp;','&',$link['title']); 804 805 $ret = ''; 806 $ret .= $link['pre']; 807 $ret .= '<a href="'.$link['url'].'"'; 808 if($link['class']) $ret .= ' class="'.$link['class'].'"'; 809 if($link['target']) $ret .= ' target="'.$link['target'].'"'; 810 if($link['title']) $ret .= ' title="'.$link['title'].'"'; 811 if($link['style']) $ret .= ' style="'.$link['style'].'"'; 812 if($link['more']) $ret .= ' '.$link['more']; 813 $ret .= '>'; 814 $ret .= $link['name']; 815 $ret .= '</a>'; 816 $ret .= $link['suf']; 817 return $ret; 818 } 819 820 /** 821 * Removes any Namespace from the given name but keeps 822 * casing and special chars 823 * 824 * @author Andreas Gohr <andi@splitbrain.org> 825 */ 826 function __simpleTitle($name){ 827 global $conf; 828 if($conf['useslash']){ 829 $nssep = '[:;/]'; 830 }else{ 831 $nssep = '[:;]'; 832 } 833 return preg_replace('!.*'.$nssep.'!','',$name); 834 } 835 836 837 function __newFootnoteId() { 838 static $id = 1; 839 return $id++; 840 } 841 842 function __xmlEntities($string) { 843 return htmlspecialchars($string); 844 } 845 846 /** 847 * @TODO Tuning needed - e.g. utf8 strtolower ? 848 */ 849 function __headerToLink($title) { 850 return preg_replace('/\W/','_',trim($title)); 851 } 852 853 /** 854 * Adds code for section editing button 855 */ 856 function __secedit($f, $t){ 857 print '<!-- SECTION ['.$f.'-'.$t.'] -->'; 858 } 859 860 function __getLinkTitle($title, $default, & $isImage, $id=NULL) { 861 global $conf; 862 863 $isImage = FALSE; 864 865 if ( is_null($title) ) { 866 if ($conf['useheading'] && $id) { 867 $heading = p_get_first_heading($id); 868 if ($heading) { 869 return $this->__xmlEntities($heading); 870 } 871 } 872 return $this->__xmlEntities($default); 873 874 } else if ( is_string($title) ) { 875 876 return $this->__xmlEntities($title); 877 878 } else if ( is_array($title) ) { 879 880 $isImage = TRUE; 881 return $this->__imageTitle($title); 882 883 } 884 } 885 886 /** 887 * @TODO Resolve namespace on internal images 888 */ 889 function __imageTitle($img) { 890 891 //FIXME resolve internal links 892 893 return $this->__media($img['src'], 894 $img['title'], 895 $img['align'], 896 $img['width'], 897 $img['height'], 898 $img['cache']); 899 900/* 901 if ( $img['type'] == 'internalmedia' ) { 902 903 // Resolve here... 904 if ( strpos($img['src'],':') ) { 905 $src = explode(':',$img['src']); 906 $src = $src[1]; 907 } else { 908 $src = $img['src']; 909 } 910 911 $imgStr = '<img class="media" src="http://wiki.splitbrain.org/media/wiki/'.$this->__xmlEntities($src).'"'; 912 913 } else { 914 915 $imgStr = '<img class="media" src="'.$this->__xmlEntities($img['src']).'"'; 916 917 } 918 919 if ( !is_null($img['title']) ) { 920 $imgStr .= ' alt="'.$this->__xmlEntities($img['title']).'"'; 921 } else { 922 $imgStr .= ' alt=""'; 923 } 924 925 if ( !is_null($img['align']) ) { 926 $imgStr .= ' align="'.$img['align'].'"'; 927 } 928 929 if ( !is_null($img['width']) ) { 930 $imgStr .= ' width="'.$this->__xmlEntities($img['width']).'"'; 931 } 932 933 if ( !is_null($img['height']) ) { 934 $imgStr .= ' height="'.$this->__xmlEntities($img['height']).'"'; 935 } 936 937 $imgStr .= '/>'; 938 939 return $imgStr; 940*/ 941 } 942} 943 944/** 945* Test whether there's an image to display with this interwiki link 946*/ 947function interwikiImgExists($name) { 948 949 static $exists = array(); 950 951 if ( array_key_exists($name,$exists) ) { 952 return $exists[$name]; 953 } 954 955 if( @file_exists( DOKU. 'interwiki/'.$name.'.png') ) { 956 $exists[$name] = 'png'; 957 } else if ( @file_exists( DOKU . 'interwiki/'.$name.'.gif') ) { 958 $exists[$name] = 'gif'; 959 } else { 960 $exists[$name] = FALSE; 961 } 962 963 return $exists[$name]; 964} 965 966/** 967 * For determining whether to use CSS class "wikilink1" or "wikilink2" 968 * @todo use configinstead of DOKU_DATA 969 * @deprecated -> resolve_pagename should be used 970 */ 971function wikiPageExists($name) { 972msg("deprecated wikiPageExists called",-1); 973 static $pages = array(); 974 975 if ( array_key_exists($name,$pages) ) { 976 return $pages[$name]; 977 } 978 979 $file = str_replace(':','/',$name).'.txt'; 980 981 if ( @file_exists( DOKU_DATA . $file ) ) { 982 $pages[$name] = TRUE; 983 } else { 984 $pages[$name] = FALSE; 985 } 986 987 return $pages[$name]; 988} 989 990 991//Setup VIM: ex: et ts=4 enc=utf-8 : 992