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