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