xref: /plugin/nodetailsxhtml/renderer.php (revision 5aaee3e1d30decdc4cd3f4b1785148d5be2a9491)
1b07cf47aSGerry Weißbach<?php
2b07cf47aSGerry Weißbach/**
3b07cf47aSGerry Weißbach * Render Plugin for XHTML  without details link for internal images.
4b07cf47aSGerry Weißbach *
5b07cf47aSGerry Weißbach * @author i-net software <tools@inetsoftware.de>
6b07cf47aSGerry Weißbach */
7b07cf47aSGerry Weißbach
8b07cf47aSGerry Weißbachif(!defined('DOKU_INC')) die();
9b07cf47aSGerry Weißbachif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10b07cf47aSGerry Weißbach
11b07cf47aSGerry Weißbachrequire_once DOKU_INC . 'inc/parser/xhtml.php';
12b07cf47aSGerry Weißbach
13b07cf47aSGerry Weißbach/**
14b07cf47aSGerry Weißbach * The Renderer
15b07cf47aSGerry Weißbach */
16b07cf47aSGerry Weißbachclass renderer_plugin_nodetailsxhtml extends Doku_Renderer_xhtml {
17b07cf47aSGerry Weißbach
18b07cf47aSGerry Weißbach    var $acronymsExchanged = null;
19b07cf47aSGerry Weißbach    var $hasSeenHeader = false;
20b07cf47aSGerry Weißbach    var $scriptmode = false;
2165523c28SGerry Weißbach    var $sectionLevel = 0;
22b07cf47aSGerry Weißbach
23b07cf47aSGerry Weißbach    var $startlevel = 0; // level to start with numbered headings (default = 2)
24b07cf47aSGerry Weißbach    var $levels = array( '======'=>1,
25b07cf47aSGerry Weißbach                         '====='=>2,
26b07cf47aSGerry Weißbach                         '===='=>3,
27b07cf47aSGerry Weißbach                         '==='=>4,
28b07cf47aSGerry Weißbach                         '=='=>5);
29b07cf47aSGerry Weißbach
30b07cf47aSGerry Weißbach    var $info = array(
31b07cf47aSGerry Weißbach        'cache'      => true, // may the rendered result cached?
32b07cf47aSGerry Weißbach        'toc'        => true, // render the TOC?
33b07cf47aSGerry Weißbach        'forceTOC'   => false, // shall I force the TOC?
34b07cf47aSGerry Weißbach        'scriptmode' => false, // In scriptmode, some tags will not be encoded => '<%', '%>'
35b07cf47aSGerry Weißbach    );
36b07cf47aSGerry Weißbach
37b07cf47aSGerry Weißbach    var $headingCount =
38b07cf47aSGerry Weißbach    array(  1=>0,
39b07cf47aSGerry Weißbach    2=>0,
40b07cf47aSGerry Weißbach    3=>0,
41b07cf47aSGerry Weißbach    4=>0,
42b07cf47aSGerry Weißbach    5=>0);
43b07cf47aSGerry Weißbach
44b07cf47aSGerry Weißbach    /**
45b07cf47aSGerry Weißbach     * return some info
46b07cf47aSGerry Weißbach     */
47b07cf47aSGerry Weißbach    function getInfo(){
48b07cf47aSGerry Weißbach        if ( method_exists(parent, 'getInfo')) {
49b07cf47aSGerry Weißbach            $info = parent::getInfo();
50b07cf47aSGerry Weißbach        }
51b07cf47aSGerry Weißbach	    return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array(
52b07cf47aSGerry Weißbach
53b07cf47aSGerry Weißbach        ));
54b07cf47aSGerry Weißbach    }
55b07cf47aSGerry Weißbach
56b07cf47aSGerry Weißbach    function canRender($format) {
57b07cf47aSGerry Weißbach        return ($format=='xhtml');
58b07cf47aSGerry Weißbach    }
59b07cf47aSGerry Weißbach
60b07cf47aSGerry Weißbach    function document_start() {
610313ced8SGerry Weißbach        global $TOC, $ID, $INFO, $conf;
62b07cf47aSGerry Weißbach
63b07cf47aSGerry Weißbach        parent::document_start();
64b07cf47aSGerry Weißbach
65b07cf47aSGerry Weißbach        // Cheating in again
660313ced8SGerry Weißbach        $meta = p_get_metadata($ID, null, false); // 2010-10-23 This should be save to use
670313ced8SGerry Weißbach
680313ced8SGerry Weißbach        if (isset($meta['toc']['toptoclevel'])) {
690313ced8SGerry Weißbach            $conf['toptoclevel'] = $meta['toc']['toptoclevel'];
700313ced8SGerry Weißbach        }
710313ced8SGerry Weißbach        if (isset($meta['toc']['maxtoclevel'])) {
720313ced8SGerry Weißbach            $conf['maxtoclevel'] = $meta['toc']['maxtoclevel'];
730313ced8SGerry Weißbach        }
740313ced8SGerry Weißbach        if (isset($meta['toc']['toptoclevel'])||isset($INFO['meta']['toc']['maxtoclevel'])) {
750313ced8SGerry Weißbach            $conf['tocminheads'] = 1;
760313ced8SGerry Weißbach        }
770313ced8SGerry Weißbach
780313ced8SGerry Weißbach        $newMeta = $meta['description']['tableofcontents'];
79b07cf47aSGerry Weißbach        if ( !empty( $newMeta ) && count($newMeta) > 1 ) {
80b07cf47aSGerry Weißbach            // $TOC = $this->toc = $newMeta; // 2010-08-23 doubled the TOC
81b07cf47aSGerry Weißbach            $TOC = $newMeta;
82b07cf47aSGerry Weißbach        }
83b07cf47aSGerry Weißbach    }
84b07cf47aSGerry Weißbach
85b07cf47aSGerry Weißbach    function document_end() {
86b07cf47aSGerry Weißbach
87b07cf47aSGerry Weißbach        parent::document_end();
88b07cf47aSGerry Weißbach
89b07cf47aSGerry Weißbach        // Prepare the TOC
90b07cf47aSGerry Weißbach        global $TOC, $ID;
91b07cf47aSGerry Weißbach        $meta = array();
920313ced8SGerry Weißbach
930313ced8SGerry Weißbach        $forceToc = $this->info['forceTOC'] || p_get_metadata($ID, 'internal forceTOC', false);
94b07cf47aSGerry Weißbach
95b07cf47aSGerry Weißbach        // NOTOC, and no forceTOC
96b84893f2SGerry Weißbach        if ( $this->info['toc'] === false && !$forceToc ) {
97b07cf47aSGerry Weißbach            $TOC = $this->toc = array();
98b07cf47aSGerry Weißbach            $meta['internal']['toc'] = false;
99b07cf47aSGerry Weißbach            $meta['description']['tableofcontents'] = array();
1000313ced8SGerry Weißbach            $meta['internal']['forceTOC'] = false;
101b07cf47aSGerry Weißbach
102b84893f2SGerry Weißbach        } else if ( $forceToc || (utf8_strlen(strip_tags($this->doc)) >= $this->getConf('documentlengthfortoc') && count($this->toc) > 1 ) ) {
103b07cf47aSGerry Weißbach            $TOC = $this->toc;
104b07cf47aSGerry Weißbach            // This is a little bit like cheating ... but this will force the TOC into the metadata
105b07cf47aSGerry Weißbach            $meta = array();
106b07cf47aSGerry Weißbach            $meta['internal']['toc'] = true;
1070313ced8SGerry Weißbach            $meta['internal']['forceTOC'] = $forceToc;
108b07cf47aSGerry Weißbach            $meta['description']['tableofcontents'] = $TOC;
109b07cf47aSGerry Weißbach        }
110b07cf47aSGerry Weißbach
111b07cf47aSGerry Weißbach        // allways write new metadata
112b07cf47aSGerry Weißbach        p_set_metadata($ID, $meta);
113b07cf47aSGerry Weißbach
114b07cf47aSGerry Weißbach        // make sure there are no empty blocks
11515337681SGerry Weißbach        $this->doc = preg_replace('#<(div|section|article) class=".*?level\d.*?">\s*</(div|section|article)>#','',$this->doc);
116b07cf47aSGerry Weißbach    }
117b07cf47aSGerry Weißbach
118b07cf47aSGerry Weißbach    function header($text, $level, $pos) {
119b07cf47aSGerry Weißbach        global $conf;
120b07cf47aSGerry Weißbach        global $ID;
121b07cf47aSGerry Weißbach        global $INFO;
122b07cf47aSGerry Weißbach
123b07cf47aSGerry Weißbach        if($text) {
12465523c28SGerry Weißbach
12565523c28SGerry Weißbach	        // Check Text for hint about a CSS style class
12665523c28SGerry Weißbach	        $class = "";
12765523c28SGerry Weißbach	        if ( preg_match("/^class:(.*?)>(.*?)$/", $text, $matches) ) {
12865523c28SGerry Weißbach		        $class = ' ' . $this->_xmlEntities($matches[1]);
12965523c28SGerry Weißbach		        $text = $matches[2];
13065523c28SGerry Weißbach	        }
13165523c28SGerry Weißbach
132b07cf47aSGerry Weißbach            /* There should be no class for "sectioneditX" if there is no edit perm */
133b07cf47aSGerry Weißbach            $maxLevel = $conf['maxseclevel'];
134b07cf47aSGerry Weißbach            if ( $INFO['perm'] <= AUTH_READ )
135b07cf47aSGerry Weißbach            {
136b07cf47aSGerry Weißbach                $conf['maxseclevel'] = 0;
137b07cf47aSGerry Weißbach            }
138b07cf47aSGerry Weißbach
139b07cf47aSGerry Weißbach            $headingNumber = '';
140b07cf47aSGerry Weißbach            $useNumbered = p_get_metadata($ID, 'usenumberedheading', true); // 2011-02-07 This should be save to use
141b07cf47aSGerry Weißbach            if ( $this->getConf('usenumberedheading') || !empty($useNumbered) || !empty($INFO['meta']['usenumberedheading']) || isset($_REQUEST['usenumberedheading'])) {
142b07cf47aSGerry Weißbach
143b07cf47aSGerry Weißbach                // increment the number of the heading
144b07cf47aSGerry Weißbach                $this->headingCount[$level]++;
145b07cf47aSGerry Weißbach
146b07cf47aSGerry Weißbach                // build the actual number
147b07cf47aSGerry Weißbach                for ($i=1;$i<=5;$i++) {
148b07cf47aSGerry Weißbach
149b07cf47aSGerry Weißbach                    // reset the number of the subheadings
150b07cf47aSGerry Weißbach                    if ($i>$level) {
151b07cf47aSGerry Weißbach                        $this->headingCount[$i] = 0;
152b07cf47aSGerry Weißbach                    }
153b07cf47aSGerry Weißbach
154b07cf47aSGerry Weißbach                    // build the number of the heading
155b07cf47aSGerry Weißbach                    $headingNumber .= $this->headingCount[$i] . '.';
156b07cf47aSGerry Weißbach                }
157b07cf47aSGerry Weißbach
158b07cf47aSGerry Weißbach                $headingNumber = preg_replace("/(\.0)+\.?$/", '', $headingNumber) . ' ';
159b07cf47aSGerry Weißbach            }
160b07cf47aSGerry Weißbach
16165523c28SGerry Weißbach			$doc = $this->doc;
16265523c28SGerry Weißbach			$this->doc = "";
1630313ced8SGerry Weißbach
164f350675fSGerry Weißbach            parent::header($headingNumber . $text, $level, $pos);
16565523c28SGerry Weißbach
16615337681SGerry Weißbach            if ( $this->getConf('useSectionArticle') ) {
16765523c28SGerry Weißbach                $this->doc = $doc . preg_replace("/(<h([1-9]))/", "<".($this->sectionLevel<1?'section':'article')." class=\"level\\2{$class}\">\\1", $this->doc);
16815337681SGerry Weißbach            } else {
16915337681SGerry Weißbach                $this->doc = $doc . $this->doc;
17015337681SGerry Weißbach            }
17165523c28SGerry Weißbach
172f350675fSGerry Weißbach            $conf['maxseclevel'] = $maxLevel;
173b07cf47aSGerry Weißbach
174b07cf47aSGerry Weißbach        } else if ( $INFO['perm'] > AUTH_READ ) {
175b07cf47aSGerry Weißbach
176b07cf47aSGerry Weißbach            if ( $hasSeenHeader ) $this->finishSectionEdit($pos);
177b07cf47aSGerry Weißbach
178b07cf47aSGerry Weißbach            // write the header
17965523c28SGerry Weißbach            $name = $this->startSectionEdit($pos, 'section_empty', rand() . $level);
18015337681SGerry Weißbach            if ( $this->getConf('useSectionArticle') ) {
18165523c28SGerry Weißbach                $this->doc .= '<'.($this->sectionLevel<1?'section':'article').' class="'.$name.'">';
18215337681SGerry Weißbach            }
18365523c28SGerry Weißbach
18465523c28SGerry Weißbach            $this->doc .= DOKU_LF.'<a name="'. $name .'" class="' . $name . '" ></a>'.DOKU_LF;
185b07cf47aSGerry Weißbach        }
186b07cf47aSGerry Weißbach
187b07cf47aSGerry Weißbach        $hasSeenHeader = true;
188b07cf47aSGerry Weißbach    }
189b07cf47aSGerry Weißbach
190b07cf47aSGerry Weißbach    public function finishSectionEdit($end = null) {
191b07cf47aSGerry Weißbach        global $INFO;
192b07cf47aSGerry Weißbach        if ( $INFO['perm'] > AUTH_READ )
193b07cf47aSGerry Weißbach        {
194b07cf47aSGerry Weißbach            return parent::finishSectionEdit($end);
195b07cf47aSGerry Weißbach        }
196b07cf47aSGerry Weißbach    }
197b07cf47aSGerry Weißbach
198b07cf47aSGerry Weißbach    public function startSectionEdit($start, $type, $title = null) {
199b07cf47aSGerry Weißbach        global $INFO;
200b07cf47aSGerry Weißbach        if ( $INFO['perm'] > AUTH_READ )
201b07cf47aSGerry Weißbach        {
202b07cf47aSGerry Weißbach            return parent::startSectionEdit($start, $type, $title);
203b07cf47aSGerry Weißbach        }
204b07cf47aSGerry Weißbach
205b07cf47aSGerry Weißbach        return "";
206b07cf47aSGerry Weißbach    }
207b07cf47aSGerry Weißbach
20865523c28SGerry Weißbach    function section_close() {
20965523c28SGerry Weißbach        $this->sectionLevel--;
21015337681SGerry Weißbach        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
21115337681SGerry Weißbach        if ( $this->getConf('useSectionArticle') ) {
21215337681SGerry Weißbach            $this->doc .= '</'.($this->sectionLevel<1?'section':'article').'>'.DOKU_LF;
21315337681SGerry Weißbach        }
21465523c28SGerry Weißbach    }
21565523c28SGerry Weißbach
21665523c28SGerry Weißbach    function section_open($level) {
21765523c28SGerry Weißbach        $this->sectionLevel++;
21865523c28SGerry Weißbach        return parent::section_open($level);
21965523c28SGerry Weißbach    }
22065523c28SGerry Weißbach
221b84893f2SGerry Weißbach    function internalmedia ($src, $title=null, $align=null, $width=null,
222b84893f2SGerry Weißbach                            $height=null, $cache=null, $linking=null, $return=NULL) {
223b07cf47aSGerry Weißbach        global $ID;
224b07cf47aSGerry Weißbach        list($src,$hash) = explode('#',$src,2);
225b07cf47aSGerry Weißbach        resolve_mediaid(getNS($ID),$src, $exists);
226b07cf47aSGerry Weißbach
227b07cf47aSGerry Weißbach        $noLink = false;
228b07cf47aSGerry Weißbach        $render = ($linking == 'linkonly') ? false : true;
229b07cf47aSGerry Weißbach        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
230b07cf47aSGerry Weißbach
231b07cf47aSGerry Weißbach        list($ext,$mime,$dl) = mimetype($src);
232b07cf47aSGerry Weißbach        if(substr($mime,0,5) == 'image' && $render){
233b07cf47aSGerry Weißbach            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
234b07cf47aSGerry Weißbach            if ( substr($mime,0,5) == 'image' && $linking='details' ) { $noLink = true;}
235b07cf47aSGerry Weißbach        }elseif($mime == 'application/x-shockwave-flash' && $render){
236b07cf47aSGerry Weißbach            // don't link flash movies
237b07cf47aSGerry Weißbach            $noLink = true;
238b07cf47aSGerry Weißbach        }else{
239b07cf47aSGerry Weißbach            // add file icons
240b07cf47aSGerry Weißbach            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
241b07cf47aSGerry Weißbach            $link['class'] .= ' mediafile mf_'.$class;
242b07cf47aSGerry Weißbach            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
243b07cf47aSGerry Weißbach        }
244b07cf47aSGerry Weißbach
245b07cf47aSGerry Weißbach        if($hash) $link['url'] .= '#'.$hash;
246b07cf47aSGerry Weißbach
247b07cf47aSGerry Weißbach        //markup non existing files
248b07cf47aSGerry Weißbach        if (!$exists)
249b07cf47aSGerry Weißbach        $link['class'] .= ' wikilink2';
250b07cf47aSGerry Weißbach
251b07cf47aSGerry Weißbach        //output formatted
252b07cf47aSGerry Weißbach        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
253b07cf47aSGerry Weißbach        else $this->doc .= $this->_formatLink($link);
254b07cf47aSGerry Weißbach    }
255b07cf47aSGerry Weißbach
256b07cf47aSGerry Weißbach    /**
257b07cf47aSGerry Weißbach     * Render an internal Wiki Link
258b07cf47aSGerry Weißbach     *
259b07cf47aSGerry Weißbach     * $search,$returnonly & $linktype are not for the renderer but are used
260b07cf47aSGerry Weißbach     * elsewhere - no need to implement them in other renderers
261b07cf47aSGerry Weißbach     *
262b07cf47aSGerry Weißbach     * @author Andreas Gohr <andi@splitbrain.org>
263b07cf47aSGerry Weißbach     */
264b07cf47aSGerry Weißbach    function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') {
265b07cf47aSGerry Weißbach        global $conf;
266b07cf47aSGerry Weißbach        global $ID;
267b07cf47aSGerry Weißbach        global $INFO;
268b07cf47aSGerry Weißbach
269b07cf47aSGerry Weißbach        $params = '';
270b07cf47aSGerry Weißbach        $parts = explode('?', $id, 2);
271b07cf47aSGerry Weißbach        if (count($parts) === 2) {
272b07cf47aSGerry Weißbach            $id = $parts[0];
273b07cf47aSGerry Weißbach            $params = $parts[1];
274b07cf47aSGerry Weißbach        }
275b07cf47aSGerry Weißbach
276b07cf47aSGerry Weißbach        // For empty $id we need to know the current $ID
277b07cf47aSGerry Weißbach        // We need this check because _simpleTitle needs
278b07cf47aSGerry Weißbach        // correct $id and resolve_pageid() use cleanID($id)
279b07cf47aSGerry Weißbach        // (some things could be lost)
280b07cf47aSGerry Weißbach        if ($id === '') {
281b07cf47aSGerry Weißbach            $id = $ID;
282b07cf47aSGerry Weißbach        }
283b07cf47aSGerry Weißbach
284b07cf47aSGerry Weißbach        // default name is based on $id as given
285b07cf47aSGerry Weißbach        $default = $this->_simpleTitle($id);
286b07cf47aSGerry Weißbach
287b07cf47aSGerry Weißbach        // now first resolve and clean up the $id
288b07cf47aSGerry Weißbach        resolve_pageid(getNS($ID),$id,$exists);
289b07cf47aSGerry Weißbach
290b07cf47aSGerry Weißbach        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
291b07cf47aSGerry Weißbach        if ( !$isImage ) {
292b07cf47aSGerry Weißbach            if ( $exists ) {
293b07cf47aSGerry Weißbach                $class='wikilink1';
294b07cf47aSGerry Weißbach            } else {
295b07cf47aSGerry Weißbach                $class='wikilink2';
296b07cf47aSGerry Weißbach                $link['rel']='nofollow';
297b07cf47aSGerry Weißbach            }
298b07cf47aSGerry Weißbach        } else {
299b07cf47aSGerry Weißbach            $class='media';
300b07cf47aSGerry Weißbach        }
301b07cf47aSGerry Weißbach
302b07cf47aSGerry Weißbach        //keep hash anchor
303b07cf47aSGerry Weißbach        list($id,$hash) = explode('#',$id,2);
304b07cf47aSGerry Weißbach        if(!empty($hash)) $hash = $this->_headerToLink($hash);
305b07cf47aSGerry Weißbach
306b07cf47aSGerry Weißbach        //prepare for formating
307b07cf47aSGerry Weißbach        $link['target'] = $conf['target']['wiki'];
308b07cf47aSGerry Weißbach        $link['style']  = '';
309b07cf47aSGerry Weißbach        $link['pre']    = '';
310b07cf47aSGerry Weißbach        $link['suf']    = '';
311b07cf47aSGerry Weißbach        // highlight link to current page
312b07cf47aSGerry Weißbach        if ($id == $INFO['id']) {
313b07cf47aSGerry Weißbach            $link['pre']    = '<span class="curid">';
314b07cf47aSGerry Weißbach            $link['suf']    = '</span>';
315b07cf47aSGerry Weißbach        }
316b07cf47aSGerry Weißbach        $link['more']   = '';
317b07cf47aSGerry Weißbach        $link['class']  = $class;
318b07cf47aSGerry Weißbach        $link['url']    = wl($id, $params);
319b07cf47aSGerry Weißbach        $link['name']   = $name;
320b07cf47aSGerry Weißbach        $link['title']  = $this->_getLinkTitle(null, $default, $isImage, $id, $linktype);
321b07cf47aSGerry Weißbach        //add search string
322b07cf47aSGerry Weißbach        if($search){
323b07cf47aSGerry Weißbach            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
324b07cf47aSGerry Weißbach            if(is_array($search)){
325b07cf47aSGerry Weißbach                $search = array_map('rawurlencode',$search);
326b07cf47aSGerry Weißbach                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
327b07cf47aSGerry Weißbach            }else{
328b07cf47aSGerry Weißbach                $link['url'] .= 's='.rawurlencode($search);
329b07cf47aSGerry Weißbach            }
330b07cf47aSGerry Weißbach        }
331b07cf47aSGerry Weißbach
332b07cf47aSGerry Weißbach        //keep hash
333b07cf47aSGerry Weißbach        if($hash) $link['url'].='#'.$hash;
334b07cf47aSGerry Weißbach
335b07cf47aSGerry Weißbach        //output formatted
336b07cf47aSGerry Weißbach        if($returnonly){
337b07cf47aSGerry Weißbach            return $this->_formatLink($link);
338b07cf47aSGerry Weißbach        }else{
339b07cf47aSGerry Weißbach            $this->doc .= $this->_formatLink($link);
340b07cf47aSGerry Weißbach        }
341b07cf47aSGerry Weißbach    }
342b07cf47aSGerry Weißbach
343c6a171b3SGerry Weißbach    /**
344c6a171b3SGerry Weißbach     * Render a page local link
345c6a171b3SGerry Weißbach     *
346c6a171b3SGerry Weißbach     * @param string $hash       hash link identifier
347c6a171b3SGerry Weißbach     * @param string $name       name for the link
348c6a171b3SGerry Weißbach     * @param bool   $returnonly whether to return html or write to doc attribute
349c6a171b3SGerry Weißbach     * @return void|string writes to doc attribute or returns html depends on $returnonly
350c6a171b3SGerry Weißbach     */
351c6a171b3SGerry Weißbach    function locallink($hash, $name = null, $returnonly = false) {
352b07cf47aSGerry Weißbach        global $ID;
353b07cf47aSGerry Weißbach        $name  = $this->_getLinkTitle($name, $hash, $isImage);
354b07cf47aSGerry Weißbach        $hash  = $this->_headerToLink($hash);
355b07cf47aSGerry Weißbach        $title = $name;
356c6a171b3SGerry Weißbach
357c6a171b3SGerry Weißbach        $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
358c6a171b3SGerry Weißbach        $doc .= $name;
359c6a171b3SGerry Weißbach        $doc .= '</a>';
360c6a171b3SGerry Weißbach
361c6a171b3SGerry Weißbach        if($returnonly) {
362c6a171b3SGerry Weißbach          return $doc;
363c6a171b3SGerry Weißbach        } else {
364c6a171b3SGerry Weißbach          $this->doc .= $doc;
365c6a171b3SGerry Weißbach        }
366b07cf47aSGerry Weißbach    }
367b07cf47aSGerry Weißbach
368b07cf47aSGerry Weißbach    function acronym($acronym) {
369b07cf47aSGerry Weißbach
370b07cf47aSGerry Weißbach        if ( empty($this->acronymsExchanged) ) {
371b07cf47aSGerry Weißbach            $this->acronymsExchanged = $this->acronyms;
372b07cf47aSGerry Weißbach            $this->acronyms = array();
373b07cf47aSGerry Weißbach
374b07cf47aSGerry Weißbach            foreach( $this->acronymsExchanged as $key => $value ) {
375b07cf47aSGerry Weißbach                $this->acronyms[str_replace('_', ' ', $key)] = $value;
376b07cf47aSGerry Weißbach            }
377b07cf47aSGerry Weißbach        }
378b07cf47aSGerry Weißbach
379b07cf47aSGerry Weißbach        parent::acronym($acronym);
380b07cf47aSGerry Weißbach    }
381b07cf47aSGerry Weißbach
382b07cf47aSGerry Weißbach    function entity($entity) {
383b07cf47aSGerry Weißbach
384b07cf47aSGerry Weißbach        if ( array_key_exists($entity, $this->entities) ) {
385b07cf47aSGerry Weißbach            $entity = $this->entities[$entity];
386b07cf47aSGerry Weißbach        }
387b07cf47aSGerry Weißbach
388b07cf47aSGerry Weißbach        $this->doc .= $this->_xmlEntities($entity);
389b07cf47aSGerry Weißbach    }
390b07cf47aSGerry Weißbach
391b07cf47aSGerry Weißbach    function _xmlEntities($string) {
392b07cf47aSGerry Weißbach
39365523c28SGerry Weißbach        // No double encode ...
39465523c28SGerry Weißbach        $string = htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false);
39565523c28SGerry Weißbach        // $string = parent::_xmlEntities($string);
396b07cf47aSGerry Weißbach        $string = htmlentities($string, 8, 'UTF-8');
397b07cf47aSGerry Weißbach        $string = $this->superentities($string);
398b07cf47aSGerry Weißbach
399b07cf47aSGerry Weißbach        if ( $this->info['scriptmode'] ) {
400b07cf47aSGerry Weißbach            $string = str_replace(	array( "&lt;%", "%&gt;", "&lt;?", "?&gt;"),
401b07cf47aSGerry Weißbach            array( "<%", "%>", "<?", "?>"),
402b07cf47aSGerry Weißbach            $string);
403b07cf47aSGerry Weißbach        }
404b07cf47aSGerry Weißbach
405b07cf47aSGerry Weißbach        return $string;
406b07cf47aSGerry Weißbach    }
407b07cf47aSGerry Weißbach
408b07cf47aSGerry Weißbach	// Unicode-proof htmlentities.
409b07cf47aSGerry Weißbach	// Returns 'normal' chars as chars and weirdos as numeric html entites.
410b07cf47aSGerry Weißbach	function superentities( $str ){
411b07cf47aSGerry Weißbach	    // get rid of existing entities else double-escape
412b84893f2SGerry Weißbach	    $str2 = '';
413b07cf47aSGerry Weißbach	    $str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8');
414b07cf47aSGerry Weißbach	    $ar = preg_split('/(?<!^)(?!$)(?!\n)/u', $str );  // return array of every multi-byte character
415b07cf47aSGerry Weißbach	    foreach ($ar as $c){
416b07cf47aSGerry Weißbach	        $o = ord($c);
417b07cf47aSGerry Weißbach	        if ( // (strlen($c) > 1) || /* multi-byte [unicode] */
418b07cf47aSGerry Weißbach	            ($o > 127) // || /* <- control / latin weirdos -> */
419b07cf47aSGerry Weißbach	            // ($o <32 || $o > 126) || /* <- control / latin weirdos -> */
420b07cf47aSGerry Weißbach	            // ($o >33 && $o < 40) ||/* quotes + ambersand */
421b07cf47aSGerry Weißbach	            // ($o >59 && $o < 63) /* html */
422b07cf47aSGerry Weißbach
423b07cf47aSGerry Weißbach	        ) {
424b07cf47aSGerry Weißbach	            // convert to numeric entity
425b07cf47aSGerry Weißbach	            $c = mb_encode_numericentity($c,array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
426b07cf47aSGerry Weißbach	        }
427b07cf47aSGerry Weißbach	        $str2 .= $c;
428b07cf47aSGerry Weißbach	    }
429b07cf47aSGerry Weißbach	    return $str2;
430b07cf47aSGerry Weißbach	}
431f1772eaaSGerry Weißbach
432f1772eaaSGerry Weißbach    /**
433f1772eaaSGerry Weißbach     * Renders internal and external media
434f1772eaaSGerry Weißbach     *
435f1772eaaSGerry Weißbach     * @author Andreas Gohr <andi@splitbrain.org>
436f1772eaaSGerry Weißbach     * @param string $src       media ID
437f1772eaaSGerry Weißbach     * @param string $title     descriptive text
438f1772eaaSGerry Weißbach     * @param string $align     left|center|right
439f1772eaaSGerry Weißbach     * @param int    $width     width of media in pixel
440f1772eaaSGerry Weißbach     * @param int    $height    height of media in pixel
441f1772eaaSGerry Weißbach     * @param string $cache     cache|recache|nocache
442f1772eaaSGerry Weißbach     * @param bool   $render    should the media be embedded inline or just linked
443f1772eaaSGerry Weißbach     * @return string
444f1772eaaSGerry Weißbach     */
445f1772eaaSGerry Weißbach    function _media($src, $title = null, $align = null, $w = null,
446f1772eaaSGerry Weißbach                    $h = null, $cache = null, $render = true) {
447f1772eaaSGerry Weißbach
448f1772eaaSGerry Weißbach        list($ext, $mime) = mimetype($src);
449f1772eaaSGerry Weißbach        if(substr($mime, 0, 5) == 'image' && !($w && $h) ) {
450f1772eaaSGerry Weißbach
451f1772eaaSGerry Weißbach            $info = @getimagesize(mediaFN($src)); //get original size
452f1772eaaSGerry Weißbach            if($info !== false) {
453*5aaee3e1SGerry Weißbach
454*5aaee3e1SGerry Weißbach                if ( !$w && !$h ) $w = $info[0];
455f1772eaaSGerry Weißbach                if(!$h) $h = round(($w * $info[1]) / $info[0]);
456f1772eaaSGerry Weißbach                if(!$w) $w = round(($h * $info[0]) / $info[1]);
457f1772eaaSGerry Weißbach            }
458b07cf47aSGerry Weißbach        }
459b07cf47aSGerry Weißbach
460f1772eaaSGerry Weißbach        return parent::_media($src, $title, $align, $w, $h, $cache, $render);
461f1772eaaSGerry Weißbach    }
462f1772eaaSGerry Weißbach}
463b07cf47aSGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :
464