xref: /dokuwiki/inc/parser/xhtml.php (revision 723d78db98a03f01d49b69501be9dc9cf2c52b50)
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 and more than one
50        if($this->lastsec > 1) $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, $search=NULL) {
392        global $conf;
393
394        $name = $this->_getLinkTitle($name, $this->_simpleTitle($id), $isImage, $id);
395        resolve_pageid($id,$exists);
396
397        if ( !$isImage ) {
398            if ( $exists ) {
399                $class='wikilink1';
400            } else {
401                $class='wikilink2';
402            }
403        } else {
404            $class='media';
405        }
406
407        //prepare for formating
408        $link['target'] = $conf['target']['wiki'];
409        $link['style']  = '';
410        $link['pre']    = '';
411        $link['suf']    = '';
412        $link['more']   = 'onclick="return svchk()" onkeypress="return svchk()"';
413        $link['class']  = $class;
414        $link['url']    = wl($id);
415        $link['name']   = $name;
416        $link['title']  = $id;
417
418        //add search string
419        if($search){
420            ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
421            $link['url'] .= urlencode($search);
422        }
423
424        //output formatted
425        echo $this->_formatLink($link);
426    }
427
428    function externallink($url, $name = NULL) {
429        global $conf;
430
431        $name = $this->_getLinkTitle($name, $url, $isImage);
432
433        if ( !$isImage ) {
434            $class='urlextern';
435        } else {
436            $class='media';
437        }
438
439        //prepare for formating
440        $link['target'] = $conf['target']['extern'];
441        $link['style']  = '';
442        $link['pre']    = '';
443        $link['suf']    = '';
444        $link['more']   = 'onclick="return svchk()" onkeypress="return svchk()"';
445        $link['class']  = $class;
446        $link['url']    = $url;
447        $link['name']   = $name;
448        $link['title']  = $this->_xmlEntities($url);
449        if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
450
451        //output formatted
452        echo $this->_formatLink($link);
453    }
454
455    /**
456    */
457    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
458        global $conf;
459
460        $link = array();
461        $link['target'] = $conf['target']['interwiki'];
462        $link['pre']    = '';
463        $link['suf']    = '';
464        $link['more']   = 'onclick="return svchk()" onkeypress="return svchk()"';
465        $link['name']   = $this->_getLinkTitle($name, $wikiUri, $isImage);
466
467        if ( !$isImage ) {
468            $link['class'] = 'interwiki';
469        } else {
470            $link['class'] = 'media';
471        }
472
473        //get interwiki URL
474        if ( isset($this->interwiki[$wikiName]) ) {
475            $url = $this->interwiki[$wikiName];
476        } else {
477            // Default to Google I'm feeling lucky
478            $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
479            $wikiName = 'go';
480        }
481
482        if(!$isImage){
483            //if ico exists set additional style
484            if(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.png')){
485                $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$wikiName.'.png) 0px 1px no-repeat;';
486            }elseif(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.gif')){
487                $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$wikiName.'.gif) 0px 1px no-repeat;';
488            }
489        }
490
491        //do we stay at the same server? Use local target
492        if( strpos($url,DOKU_URL) === 0 ){
493            $link['target'] = $conf['target']['wiki'];
494        }
495
496        //replace placeholder
497        if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
498            //use placeholders
499            $url = str_replace('{URL}',urlencode($wikiUri),$url);
500            $url = str_replace('{NAME}',$wikiUri,$url);
501            $parsed = parse_url($wikiUri);
502            if(!$parsed['port']) $parsed['port'] = 80;
503            $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
504            $url = str_replace('{HOST}',$parsed['host'],$url);
505            $url = str_replace('{PORT}',$parsed['port'],$url);
506            $url = str_replace('{PATH}',$parsed['path'],$url);
507            $url = str_replace('{QUERY}',$parsed['query'],$url);
508            $link['url'] = $url;
509        }else{
510            //default
511            $link['url'] = $url.urlencode($wikiUri);
512        }
513
514        $link['title'] = htmlspecialchars($link['url']);
515
516        //output formatted
517        echo $this->_formatLink($link);
518    }
519
520    /*
521     * @deprecated not used!!!
522     * @TODO Correct the CSS class for files? (not windows)
523     * @TODO Remove hard coded URL to splitbrain.org
524    function filelink($link, $title = NULL) {
525        echo '<a';
526
527        $title = $this->_getLinkTitle($title, $link, $isImage);
528
529        if ( !$isImage ) {
530            echo ' class="windows"';
531        } else {
532            echo ' class="media"';
533        }
534
535        echo ' href="'.$this->_xmlEntities($link).'"';
536
537        echo ' style="background: transparent url(http://wiki.splitbrain.org/images/windows.gif) 0px 1px no-repeat;"';
538
539        echo ' onclick="return svchk()" onkeypress="return svchk()">';
540
541        echo $title;
542
543        echo '</a>';
544    }
545    */
546
547    /**
548    */
549    function windowssharelink($url, $name = NULL) {
550        global $conf;
551        global $lang;
552        //simple setup
553        $link['target'] = $conf['target']['windows'];
554        $link['pre']    = '';
555        $link['suf']   = '';
556        $link['style']  = '';
557        //Display error on browsers other than IE
558        $link['more'] = 'onclick="if(document.all == null){alert(\''.
559                        $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).
560                        '\');}" onkeypress="if(document.all == null){alert(\''.
561                        $this->_xmlEntities($lang['nosmblinks'],ENT_QUOTES).'\');}"';
562
563        $link['name'] = $this->_getLinkTitle($name, $url, $isImage);
564        if ( !$isImage ) {
565            $link['class'] = 'windows';
566        } else {
567            $link['class'] = 'media';
568        }
569
570
571        $link['title'] = $this->_xmlEntities($url);
572        $url = str_replace('\\','/',$url);
573        $url = 'file:///'.$url;
574        $link['url'] = $url;
575
576        //output formatted
577        echo $this->_formatLink($link);
578    }
579
580    function emaillink($address, $name = NULL) {
581        global $conf;
582        //simple setup
583        $link = array();
584        $link['target'] = '';
585        $link['pre']    = '';
586        $link['suf']   = '';
587        $link['style']  = '';
588        $link['more']   = '';
589
590        //we just test for image here - we need to encode the title our self
591        $this->_getLinkTitle($name, $address, $isImage);
592        if ( !$isImage ) {
593            $link['class']='mail';
594        } else {
595            $link['class']='media';
596        }
597
598        //shields up
599        if($conf['mailguard']=='visible'){
600            //the mail name gets some visible encoding
601            $address = str_replace('@',' [at] ',$address);
602            $address = str_replace('.',' [dot] ',$address);
603            $address = str_replace('-',' [dash] ',$address);
604
605            $title   = $this->_xmlEntities($address);
606            if(empty($name)){
607                $name = $this->_xmlEntities($address);
608            }else{
609                $name = $this->_xmlEntities($name);
610            }
611        }elseif($conf['mailguard']=='hex'){
612            //encode every char to a hex entity
613            for ($x=0; $x < strlen($address); $x++) {
614                $encode .= '&#x' . bin2hex($address[$x]).';';
615            }
616            $address = $encode;
617            $title   = $encode;
618            if(empty($name)){
619                $name = $encode;
620            }else{
621                $name = $this->_xmlEntities($name);
622            }
623        }else{
624            //keep address as is
625            $title   = $this->_xmlEntities($address);
626            if(empty($name)){
627                $name = $this->_xmlEntities($address);
628            }else{
629                $name = $this->_xmlEntities($name);
630            }
631        }
632
633        $link['url']   = 'mailto:'.$address;
634        $link['name']  = $name;
635        $link['title'] = $title;
636
637        //output formatted
638        echo $this->_formatLink($link);
639    }
640
641    /**
642     * @todo don't add link for flash
643     */
644    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
645                            $height=NULL, $cache=NULL) {
646        global $conf;
647        resolve_mediaid($src, $exists);
648
649        $link = array();
650        $link['class']  = 'media';
651        $link['style']  = '';
652        $link['pre']    = '';
653        $link['suf']    = '';
654        $link['more']   = 'onclick="return svchk()" onkeypress="return svchk()"';
655        $link['target'] = $conf['target']['media'];
656
657        $link['title']  = $this->_xmlEntities($src);
658        $link['url']    = DOKU_BASE.'fetch.php?cache='.$cache.'&amp;media='.urlencode($src);
659        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
660
661
662        //output formatted
663        echo $this->_formatLink($link);
664    }
665
666    /**
667     * @todo don't add link for flash
668     */
669    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
670                            $height=NULL, $cache=NULL) {
671        global $conf;
672
673        $link = array();
674        $link['class']  = 'media';
675        $link['style']  = '';
676        $link['pre']    = '';
677        $link['suf']    = '';
678        $link['more']   = 'onclick="return svchk()" onkeypress="return svchk()"';
679        $link['target'] = $conf['target']['media'];
680
681        $link['title']  = $this->_xmlEntities($src);
682        $link['url']    = DOKU_BASE.'fetch.php?cache='.$cache.'&amp;media='.urlencode($src);
683        $link['name']   = $this->_media ($src, $title, $align, $width, $height, $cache);
684
685
686        //output formatted
687        echo $this->_formatLink($link);
688    }
689
690    /**
691     * Renders an RSS feed using magpie
692     *
693     * @author Andreas Gohr <andi@splitbrain.org>
694     */
695    function rss ($url){
696        global $lang;
697        define('MAGPIE_CACHE_ON', false); //we do our own caching
698        define('MAGPIE_DIR', DOKU_INC.'inc/magpie/');
699        define('MAGPIE_OUTPUT_ENCODING','UTF-8'); //return all feeds as UTF-8
700        require_once(MAGPIE_DIR.'/rss_fetch.inc');
701
702        //disable warning while fetching
703        $elvl = error_reporting(E_ERROR);
704        $rss  = fetch_rss($url);
705        error_reporting($elvl);
706
707        print '<ul class="rss">';
708        if($rss){
709            foreach ($rss->items as $item ) {
710                print '<li>';
711                $this->externallink($item['link'],$item['title']);
712                print '</li>';
713            }
714        }else{
715            print '<li>';
716            print '<em>'.$lang['rssfailed'].'</em>';
717            $this->externallink($url);
718            print '</li>';
719        }
720        print '</ul>';
721    }
722
723    /**
724     * Renders internal and external media
725     *
726     * @author Andreas Gohr <andi@splitbrain.org>
727     * @todo   handle center align
728     * @todo   move to bottom
729     */
730    function _media ($src, $title=NULL, $align=NULL, $width=NULL,
731                      $height=NULL, $cache=NULL) {
732
733        $ret = '';
734
735        list($ext,$mime) = mimetype($src);
736        if(substr($mime,0,5) == 'image'){
737            //add image tag
738            $ret .= '<img src="'.DOKU_BASE.'fetch.php?w='.$width.'&amp;h='.$height.
739                    '&amp;cache='.$cache.'&amp;media='.urlencode($src).'"';
740
741            $ret .= ' class="media'.$align.'"';
742
743            if (!is_null($title))
744                $ret .= ' title="'.$this->_xmlEntities($title).'"';
745
746            if ( !is_null($width) )
747                $ret .= ' width="'.$this->_xmlEntities($width).'"';
748
749            if ( !is_null($height) )
750                $ret .= ' height="'.$this->_xmlEntities($height).'"';
751
752            $ret .= ' />';
753
754        }elseif($mime == 'application/x-shockwave-flash'){
755            //FIXME default to a higher flash version?
756
757            $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'.
758                    ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"';
759            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
760            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
761            $ret .= '>'.DOKU_LF;
762            $ret .= '<param name="movie" value="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'" />'.DOKU_LF;
763            $ret .= '<param name="quality" value="high" />'.DOKU_LF;
764            $ret .= '<embed src="'.DOKU_BASE.'fetch.php?media='.urlencode($src).'"'.
765                    ' quality="high" bgcolor="#000000"';
766            if ( !is_null($width) ) $ret .= ' width="'.$this->_xmlEntities($width).'"';
767            if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"';
768            $ret .= ' type="application/x-shockwave-flash"'.
769                    ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi'.
770                    '?P1_Prod_Version=ShockwaveFlash"></embed>'.DOKU_LF;
771            $ret .= '</object>'.DOKU_LF;
772
773        }elseif(!is_null($title)){
774            // well at least we have a title to display
775            $ret .= $this->_xmlEntities($title);
776        }else{
777            // just show the source
778            $ret .= $this->_xmlEntities($src);
779        }
780
781        return $ret;
782    }
783
784    // $numrows not yet implemented
785    function table_open($maxcols = NULL, $numrows = NULL){
786        echo '<table class="inline">'.DOKU_LF;
787    }
788
789    function table_close(){
790        echo '</table>'.DOKU_LF.'<br />'.DOKU_LF;
791    }
792
793    function tablerow_open(){
794        echo DOKU_TAB . '<tr>' . DOKU_LF . DOKU_TAB . DOKU_TAB;
795    }
796
797    function tablerow_close(){
798        echo DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF;
799    }
800
801    function tableheader_open($colspan = 1, $align = NULL){
802        echo '<th';
803        if ( !is_null($align) ) {
804            echo ' class="'.$align.'align"';
805        }
806        if ( $colspan > 1 ) {
807            echo ' colspan="'.$colspan.'"';
808        }
809        echo '>';
810    }
811
812    function tableheader_close(){
813        echo '</th>';
814    }
815
816    function tablecell_open($colspan = 1, $align = NULL){
817        echo '<td';
818        if ( !is_null($align) ) {
819            echo ' class="'.$align.'align"';
820        }
821        if ( $colspan > 1 ) {
822            echo ' colspan="'.$colspan.'"';
823        }
824        echo '>';
825    }
826
827    function tablecell_close(){
828        echo '</td>';
829    }
830
831    //----------------------------------------------------------
832    // Utils
833
834    /**
835     * Assembles all parts defined by the link formater below
836     * Returns HTML for the link
837     *
838     * @author Andreas Gohr <andi@splitbrain.org>
839     */
840    function _formatLink($link){
841        //make sure the url is XHTML compliant (skip mailto)
842        if(substr($link['url'],0,7) != 'mailto:'){
843            $link['url'] = str_replace('&','&amp;',$link['url']);
844            $link['url'] = str_replace('&amp;amp;','&amp;',$link['url']);
845        }
846        //remove double encodings in titles
847        $link['title'] = str_replace('&amp;amp;','&amp;',$link['title']);
848
849        $ret  = '';
850        $ret .= $link['pre'];
851        $ret .= '<a href="'.$link['url'].'"';
852        if($link['class'])  $ret .= ' class="'.$link['class'].'"';
853        if($link['target']) $ret .= ' target="'.$link['target'].'"';
854        if($link['title'])  $ret .= ' title="'.$link['title'].'"';
855        if($link['style'])  $ret .= ' style="'.$link['style'].'"';
856        if($link['more'])   $ret .= ' '.$link['more'];
857        $ret .= '>';
858        $ret .= $link['name'];
859        $ret .= '</a>';
860        $ret .= $link['suf'];
861        return $ret;
862    }
863
864    /**
865     * Removes any Namespace from the given name but keeps
866     * casing and special chars
867     *
868     * @author Andreas Gohr <andi@splitbrain.org>
869     */
870    function _simpleTitle($name){
871        global $conf;
872        if($conf['useslash']){
873            $nssep = '[:;/]';
874        }else{
875            $nssep = '[:;]';
876        }
877        return preg_replace('!.*'.$nssep.'!','',$name);
878    }
879
880
881    function _newFootnoteId() {
882        static $id = 1;
883        return $id++;
884    }
885
886    function _xmlEntities($string) {
887        return htmlspecialchars($string);
888    }
889
890    /**
891    * @TODO Tuning needed - e.g. utf8 strtolower ?
892    */
893    function _headerToLink($title) {
894        return preg_replace('/\W/','_',trim($title));
895    }
896
897    /**
898     * Adds code for section editing button
899     */
900    function _secedit($f, $t){
901        print '<!-- SECTION ['.$f.'-'.$t.'] -->';
902    }
903
904    function _getLinkTitle($title, $default, & $isImage, $id=NULL) {
905        global $conf;
906
907        $isImage = FALSE;
908
909        if ( is_null($title) ) {
910	  if ($conf['useheading'] && $id) {
911	    $heading = p_get_first_heading($id);
912	    if ($heading) {
913	      return $this->_xmlEntities($heading);
914	    }
915	  }
916	  return $this->_xmlEntities($default);
917
918        } else if ( is_string($title) ) {
919
920            return $this->_xmlEntities($title);
921
922        } else if ( is_array($title) ) {
923
924            $isImage = TRUE;
925            return $this->_imageTitle($title);
926
927        }
928    }
929
930    /**
931     * @TODO Resolve namespace on internal images
932     */
933    function _imageTitle($img) {
934
935        //FIXME resolve internal links
936
937        return $this->_media($img['src'],
938                              $img['title'],
939                              $img['align'],
940                              $img['width'],
941                              $img['height'],
942                              $img['cache']);
943
944/*
945        if ( $img['type'] == 'internalmedia' ) {
946
947            // Resolve here...
948            if ( strpos($img['src'],':') ) {
949                $src = explode(':',$img['src']);
950                $src = $src[1];
951            } else {
952                $src = $img['src'];
953            }
954
955            $imgStr = '<img class="media" src="http://wiki.splitbrain.org/media/wiki/'.$this->_xmlEntities($src).'"';
956
957        } else {
958
959            $imgStr = '<img class="media" src="'.$this->_xmlEntities($img['src']).'"';
960
961        }
962
963        if ( !is_null($img['title']) ) {
964            $imgStr .= ' alt="'.$this->_xmlEntities($img['title']).'"';
965        } else {
966            $imgStr .= ' alt=""';
967        }
968
969        if ( !is_null($img['align']) ) {
970            $imgStr .= ' align="'.$img['align'].'"';
971        }
972
973        if ( !is_null($img['width']) ) {
974            $imgStr .= ' width="'.$this->_xmlEntities($img['width']).'"';
975        }
976
977        if ( !is_null($img['height']) ) {
978            $imgStr .= ' height="'.$this->_xmlEntities($img['height']).'"';
979        }
980
981        $imgStr .= '/>';
982
983        return $imgStr;
984*/
985    }
986}
987
988/**
989* Test whether there's an image to display with this interwiki link
990*/
991function interwikiImgExists($name) {
992
993    static $exists = array();
994
995    if ( array_key_exists($name,$exists) ) {
996        return $exists[$name];
997    }
998
999    if( @file_exists( DOKU. 'interwiki/'.$name.'.png') ) {
1000        $exists[$name] = 'png';
1001    } else if ( @file_exists( DOKU . 'interwiki/'.$name.'.gif') ) {
1002        $exists[$name] = 'gif';
1003    } else {
1004        $exists[$name] = FALSE;
1005    }
1006
1007    return $exists[$name];
1008}
1009
1010/**
1011 * For determining whether to use CSS class "wikilink1" or "wikilink2"
1012 * @todo use configinstead of DOKU_DATA
1013 * @deprecated -> resolve_pagename should be used
1014 */
1015function wikiPageExists($name) {
1016msg("deprecated wikiPageExists called",-1);
1017    static $pages = array();
1018
1019    if ( array_key_exists($name,$pages) ) {
1020        return $pages[$name];
1021    }
1022
1023    $file = str_replace(':','/',$name).'.txt';
1024
1025    if ( @file_exists( DOKU_DATA . $file ) ) {
1026        $pages[$name] = TRUE;
1027    } else {
1028        $pages[$name] = FALSE;
1029    }
1030
1031    return $pages[$name];
1032}
1033
1034
1035//Setup VIM: ex: et ts=4 enc=utf-8 :
1036