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