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