xref: /plugin/nodetailsxhtml/renderer.php (revision b07cf47aad5ddb93ae029a56d6bc78fa317e8817)
1*b07cf47aSGerry Weißbach<?php
2*b07cf47aSGerry Weißbach/**
3*b07cf47aSGerry Weißbach * Render Plugin for XHTML  without details link for internal images.
4*b07cf47aSGerry Weißbach *
5*b07cf47aSGerry Weißbach * @author i-net software <tools@inetsoftware.de>
6*b07cf47aSGerry Weißbach */
7*b07cf47aSGerry Weißbach
8*b07cf47aSGerry Weißbachif(!defined('DOKU_INC')) die();
9*b07cf47aSGerry Weißbachif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10*b07cf47aSGerry Weißbach
11*b07cf47aSGerry Weißbachrequire_once DOKU_INC . 'inc/parser/xhtml.php';
12*b07cf47aSGerry Weißbach
13*b07cf47aSGerry Weißbach/**
14*b07cf47aSGerry Weißbach * The Renderer
15*b07cf47aSGerry Weißbach */
16*b07cf47aSGerry Weißbachclass renderer_plugin_nodetailsxhtml extends Doku_Renderer_xhtml {
17*b07cf47aSGerry Weißbach
18*b07cf47aSGerry Weißbach    var $acronymsExchanged = null;
19*b07cf47aSGerry Weißbach    var $hasSeenHeader = false;
20*b07cf47aSGerry Weißbach    var $scriptmode = false;
21*b07cf47aSGerry Weißbach
22*b07cf47aSGerry Weißbach    var $startlevel = 0; // level to start with numbered headings (default = 2)
23*b07cf47aSGerry Weißbach    var $levels = array( '======'=>1,
24*b07cf47aSGerry Weißbach                         '====='=>2,
25*b07cf47aSGerry Weißbach                         '===='=>3,
26*b07cf47aSGerry Weißbach                         '==='=>4,
27*b07cf47aSGerry Weißbach                         '=='=>5);
28*b07cf47aSGerry Weißbach
29*b07cf47aSGerry Weißbach    var $info = array(
30*b07cf47aSGerry Weißbach        'cache'      => true, // may the rendered result cached?
31*b07cf47aSGerry Weißbach        'toc'        => true, // render the TOC?
32*b07cf47aSGerry Weißbach        'forceTOC'   => false, // shall I force the TOC?
33*b07cf47aSGerry Weißbach        'scriptmode' => false, // In scriptmode, some tags will not be encoded => '<%', '%>'
34*b07cf47aSGerry Weißbach    );
35*b07cf47aSGerry Weißbach
36*b07cf47aSGerry Weißbach    var $headingCount =
37*b07cf47aSGerry Weißbach    array(  1=>0,
38*b07cf47aSGerry Weißbach    2=>0,
39*b07cf47aSGerry Weißbach    3=>0,
40*b07cf47aSGerry Weißbach    4=>0,
41*b07cf47aSGerry Weißbach    5=>0);
42*b07cf47aSGerry Weißbach
43*b07cf47aSGerry Weißbach    /**
44*b07cf47aSGerry Weißbach     * return some info
45*b07cf47aSGerry Weißbach     */
46*b07cf47aSGerry Weißbach    function getInfo(){
47*b07cf47aSGerry Weißbach        if ( method_exists(parent, 'getInfo')) {
48*b07cf47aSGerry Weißbach            $info = parent::getInfo();
49*b07cf47aSGerry Weißbach        }
50*b07cf47aSGerry Weißbach	    return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array(
51*b07cf47aSGerry Weißbach
52*b07cf47aSGerry Weißbach        ));
53*b07cf47aSGerry Weißbach    }
54*b07cf47aSGerry Weißbach
55*b07cf47aSGerry Weißbach    function canRender($format) {
56*b07cf47aSGerry Weißbach        return ($format=='xhtml');
57*b07cf47aSGerry Weißbach    }
58*b07cf47aSGerry Weißbach
59*b07cf47aSGerry Weißbach    function document_start() {
60*b07cf47aSGerry Weißbach        global $TOC, $ID, $INFO;
61*b07cf47aSGerry Weißbach
62*b07cf47aSGerry Weißbach        parent::document_start();
63*b07cf47aSGerry Weißbach
64*b07cf47aSGerry Weißbach        // Cheating in again
65*b07cf47aSGerry Weißbach        $newMeta = p_get_metadata($ID, 'description tableofcontents', false); // 2010-10-23 This should be save to use
66*b07cf47aSGerry Weißbach        if ( !empty( $newMeta ) && count($newMeta) > 1 ) {
67*b07cf47aSGerry Weißbach            // $TOC = $this->toc = $newMeta; // 2010-08-23 doubled the TOC
68*b07cf47aSGerry Weißbach            $TOC = $newMeta;
69*b07cf47aSGerry Weißbach        }
70*b07cf47aSGerry Weißbach    }
71*b07cf47aSGerry Weißbach
72*b07cf47aSGerry Weißbach    function document_end() {
73*b07cf47aSGerry Weißbach
74*b07cf47aSGerry Weißbach        parent::document_end();
75*b07cf47aSGerry Weißbach
76*b07cf47aSGerry Weißbach        // Prepare the TOC
77*b07cf47aSGerry Weißbach        global $TOC, $ID;
78*b07cf47aSGerry Weißbach        $meta = array();
79*b07cf47aSGerry Weißbach
80*b07cf47aSGerry Weißbach        // NOTOC, and no forceTOC
81*b07cf47aSGerry Weißbach        if ( $this->info['toc'] === false && !($this->info['forceTOC'] || $this->meta['forceTOC']) ) {
82*b07cf47aSGerry Weißbach            $TOC = $this->toc = array();
83*b07cf47aSGerry Weißbach            $meta['internal']['toc'] = false;
84*b07cf47aSGerry Weißbach            $meta['description']['tableofcontents'] = array();
85*b07cf47aSGerry Weißbach            $meta['forceTOC'] = false;
86*b07cf47aSGerry Weißbach
87*b07cf47aSGerry Weißbach        } else if ( $this->info['forceTOC'] || $this->meta['forceTOC'] || (utf8_strlen(strip_tags($this->doc)) >= $this->getConf('documentlengthfortoc') && count($this->toc) > 1 ) ) {
88*b07cf47aSGerry Weißbach            $TOC = $this->toc;
89*b07cf47aSGerry Weißbach            // This is a little bit like cheating ... but this will force the TOC into the metadata
90*b07cf47aSGerry Weißbach            $meta = array();
91*b07cf47aSGerry Weißbach            $meta['internal']['toc'] = true;
92*b07cf47aSGerry Weißbach            $meta['forceTOC'] = $this->info['forceTOC'] || $this->meta['forceTOC'];
93*b07cf47aSGerry Weißbach            $meta['description']['tableofcontents'] = $TOC;
94*b07cf47aSGerry Weißbach        }
95*b07cf47aSGerry Weißbach
96*b07cf47aSGerry Weißbach        // allways write new metadata
97*b07cf47aSGerry Weißbach        p_set_metadata($ID, $meta);
98*b07cf47aSGerry Weißbach
99*b07cf47aSGerry Weißbach        // make sure there are no empty blocks
100*b07cf47aSGerry Weißbach        $this->doc = preg_replace('#<div class="level\d">\s*</div>#','',$this->doc);
101*b07cf47aSGerry Weißbach    }
102*b07cf47aSGerry Weißbach
103*b07cf47aSGerry Weißbach    function header($text, $level, $pos) {
104*b07cf47aSGerry Weißbach        global $conf;
105*b07cf47aSGerry Weißbach        global $ID;
106*b07cf47aSGerry Weißbach        global $INFO;
107*b07cf47aSGerry Weißbach
108*b07cf47aSGerry Weißbach        if($text) {
109*b07cf47aSGerry Weißbach            $tmpDoc = $this->doc;
110*b07cf47aSGerry Weißbach            $this->doc = "";
111*b07cf47aSGerry Weißbach
112*b07cf47aSGerry Weißbach            /* There should be no class for "sectioneditX" if there is no edit perm */
113*b07cf47aSGerry Weißbach            $maxLevel = $conf['maxseclevel'];
114*b07cf47aSGerry Weißbach            if ( $INFO['perm'] <= AUTH_READ )
115*b07cf47aSGerry Weißbach            {
116*b07cf47aSGerry Weißbach                $conf['maxseclevel'] = 0;
117*b07cf47aSGerry Weißbach            }
118*b07cf47aSGerry Weißbach            parent::header($text, $level, $pos);
119*b07cf47aSGerry Weißbach            $conf['maxseclevel'] = $maxLevel;
120*b07cf47aSGerry Weißbach
121*b07cf47aSGerry Weißbach            $headingNumber = '';
122*b07cf47aSGerry Weißbach            $useNumbered = p_get_metadata($ID, 'usenumberedheading', true); // 2011-02-07 This should be save to use
123*b07cf47aSGerry Weißbach            if ( $this->getConf('usenumberedheading') || !empty($useNumbered) || !empty($INFO['meta']['usenumberedheading']) || isset($_REQUEST['usenumberedheading'])) {
124*b07cf47aSGerry Weißbach
125*b07cf47aSGerry Weißbach                // increment the number of the heading
126*b07cf47aSGerry Weißbach                $this->headingCount[$level]++;
127*b07cf47aSGerry Weißbach
128*b07cf47aSGerry Weißbach                // build the actual number
129*b07cf47aSGerry Weißbach                for ($i=1;$i<=5;$i++) {
130*b07cf47aSGerry Weißbach
131*b07cf47aSGerry Weißbach                    // reset the number of the subheadings
132*b07cf47aSGerry Weißbach                    if ($i>$level) {
133*b07cf47aSGerry Weißbach                        $this->headingCount[$i] = 0;
134*b07cf47aSGerry Weißbach                    }
135*b07cf47aSGerry Weißbach
136*b07cf47aSGerry Weißbach                    // build the number of the heading
137*b07cf47aSGerry Weißbach                    $headingNumber .= $this->headingCount[$i] . '.';
138*b07cf47aSGerry Weißbach                }
139*b07cf47aSGerry Weißbach
140*b07cf47aSGerry Weißbach                $headingNumber = preg_replace("/(\.0)+\.?$/", '', $headingNumber) . ' ';
141*b07cf47aSGerry Weißbach            }
142*b07cf47aSGerry Weißbach
143*b07cf47aSGerry Weißbach//            $this->doc = $tmpDoc . preg_replace("/<\/?p>/i", '', str_replace($this->_xmlEntities($text) . "</a></h$level>".DOKU_LF, trim(preg_replace("/<\/?(p)>/is", "", p_render('xhtml', p_get_instructions(trim($headingNumber . $text)), $info)))  . "</a></h$level>".DOKU_LF, $this->doc));
144*b07cf47aSGerry Weißbach              $this->doc = $tmpDoc . preg_replace("/<h1(.*?)>/", '<h1 title="' . $this->_xmlEntities($text) . '"$1>', $this->doc);
145*b07cf47aSGerry Weißbach
146*b07cf47aSGerry Weißbach        } else if ( $INFO['perm'] > AUTH_READ ) {
147*b07cf47aSGerry Weißbach
148*b07cf47aSGerry Weißbach            if ( $hasSeenHeader ) $this->finishSectionEdit($pos);
149*b07cf47aSGerry Weißbach
150*b07cf47aSGerry Weißbach            // write the header
151*b07cf47aSGerry Weißbach            $name = rand() . $level;
152*b07cf47aSGerry Weißbach            $this->doc .= DOKU_LF.'<a name="'. $this->startSectionEdit($pos, 'section_empty', $name) .'" class="' . $this->startSectionEdit($pos, 'section_empty', $name) . '" ></a>'.DOKU_LF;
153*b07cf47aSGerry Weißbach        }
154*b07cf47aSGerry Weißbach
155*b07cf47aSGerry Weißbach        $hasSeenHeader = true;
156*b07cf47aSGerry Weißbach    }
157*b07cf47aSGerry Weißbach
158*b07cf47aSGerry Weißbach    public function finishSectionEdit($end = null) {
159*b07cf47aSGerry Weißbach        global $INFO;
160*b07cf47aSGerry Weißbach        if ( $INFO['perm'] > AUTH_READ )
161*b07cf47aSGerry Weißbach        {
162*b07cf47aSGerry Weißbach            return parent::finishSectionEdit($end);
163*b07cf47aSGerry Weißbach        }
164*b07cf47aSGerry Weißbach    }
165*b07cf47aSGerry Weißbach
166*b07cf47aSGerry Weißbach    public function startSectionEdit($start, $type, $title = null) {
167*b07cf47aSGerry Weißbach        global $INFO;
168*b07cf47aSGerry Weißbach        if ( $INFO['perm'] > AUTH_READ )
169*b07cf47aSGerry Weißbach        {
170*b07cf47aSGerry Weißbach            return parent::startSectionEdit($start, $type, $title);
171*b07cf47aSGerry Weißbach        }
172*b07cf47aSGerry Weißbach
173*b07cf47aSGerry Weißbach        return "";
174*b07cf47aSGerry Weißbach    }
175*b07cf47aSGerry Weißbach
176*b07cf47aSGerry Weißbach    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
177*b07cf47aSGerry Weißbach    $height=NULL, $cache=NULL, $linking=NULL) {
178*b07cf47aSGerry Weißbach        global $ID;
179*b07cf47aSGerry Weißbach        list($src,$hash) = explode('#',$src,2);
180*b07cf47aSGerry Weißbach        resolve_mediaid(getNS($ID),$src, $exists);
181*b07cf47aSGerry Weißbach
182*b07cf47aSGerry Weißbach        $noLink = false;
183*b07cf47aSGerry Weißbach        $render = ($linking == 'linkonly') ? false : true;
184*b07cf47aSGerry Weißbach        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
185*b07cf47aSGerry Weißbach
186*b07cf47aSGerry Weißbach        list($ext,$mime,$dl) = mimetype($src);
187*b07cf47aSGerry Weißbach        if(substr($mime,0,5) == 'image' && $render){
188*b07cf47aSGerry Weißbach            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
189*b07cf47aSGerry Weißbach            if ( substr($mime,0,5) == 'image' && $linking='details' ) { $noLink = true;}
190*b07cf47aSGerry Weißbach        }elseif($mime == 'application/x-shockwave-flash' && $render){
191*b07cf47aSGerry Weißbach            // don't link flash movies
192*b07cf47aSGerry Weißbach            $noLink = true;
193*b07cf47aSGerry Weißbach        }else{
194*b07cf47aSGerry Weißbach            // add file icons
195*b07cf47aSGerry Weißbach            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
196*b07cf47aSGerry Weißbach            $link['class'] .= ' mediafile mf_'.$class;
197*b07cf47aSGerry Weißbach            $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
198*b07cf47aSGerry Weißbach        }
199*b07cf47aSGerry Weißbach
200*b07cf47aSGerry Weißbach        if($hash) $link['url'] .= '#'.$hash;
201*b07cf47aSGerry Weißbach
202*b07cf47aSGerry Weißbach        //markup non existing files
203*b07cf47aSGerry Weißbach        if (!$exists)
204*b07cf47aSGerry Weißbach        $link['class'] .= ' wikilink2';
205*b07cf47aSGerry Weißbach
206*b07cf47aSGerry Weißbach        //output formatted
207*b07cf47aSGerry Weißbach        if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
208*b07cf47aSGerry Weißbach        else $this->doc .= $this->_formatLink($link);
209*b07cf47aSGerry Weißbach    }
210*b07cf47aSGerry Weißbach
211*b07cf47aSGerry Weißbach    /**
212*b07cf47aSGerry Weißbach     * Render an internal Wiki Link
213*b07cf47aSGerry Weißbach     *
214*b07cf47aSGerry Weißbach     * $search,$returnonly & $linktype are not for the renderer but are used
215*b07cf47aSGerry Weißbach     * elsewhere - no need to implement them in other renderers
216*b07cf47aSGerry Weißbach     *
217*b07cf47aSGerry Weißbach     * @author Andreas Gohr <andi@splitbrain.org>
218*b07cf47aSGerry Weißbach     */
219*b07cf47aSGerry Weißbach    function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') {
220*b07cf47aSGerry Weißbach        global $conf;
221*b07cf47aSGerry Weißbach        global $ID;
222*b07cf47aSGerry Weißbach        global $INFO;
223*b07cf47aSGerry Weißbach
224*b07cf47aSGerry Weißbach        $params = '';
225*b07cf47aSGerry Weißbach        $parts = explode('?', $id, 2);
226*b07cf47aSGerry Weißbach        if (count($parts) === 2) {
227*b07cf47aSGerry Weißbach            $id = $parts[0];
228*b07cf47aSGerry Weißbach            $params = $parts[1];
229*b07cf47aSGerry Weißbach        }
230*b07cf47aSGerry Weißbach
231*b07cf47aSGerry Weißbach        // For empty $id we need to know the current $ID
232*b07cf47aSGerry Weißbach        // We need this check because _simpleTitle needs
233*b07cf47aSGerry Weißbach        // correct $id and resolve_pageid() use cleanID($id)
234*b07cf47aSGerry Weißbach        // (some things could be lost)
235*b07cf47aSGerry Weißbach        if ($id === '') {
236*b07cf47aSGerry Weißbach            $id = $ID;
237*b07cf47aSGerry Weißbach        }
238*b07cf47aSGerry Weißbach
239*b07cf47aSGerry Weißbach        // default name is based on $id as given
240*b07cf47aSGerry Weißbach        $default = $this->_simpleTitle($id);
241*b07cf47aSGerry Weißbach
242*b07cf47aSGerry Weißbach        // now first resolve and clean up the $id
243*b07cf47aSGerry Weißbach        resolve_pageid(getNS($ID),$id,$exists);
244*b07cf47aSGerry Weißbach
245*b07cf47aSGerry Weißbach        $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
246*b07cf47aSGerry Weißbach        if ( !$isImage ) {
247*b07cf47aSGerry Weißbach            if ( $exists ) {
248*b07cf47aSGerry Weißbach                $class='wikilink1';
249*b07cf47aSGerry Weißbach            } else {
250*b07cf47aSGerry Weißbach                $class='wikilink2';
251*b07cf47aSGerry Weißbach                $link['rel']='nofollow';
252*b07cf47aSGerry Weißbach            }
253*b07cf47aSGerry Weißbach        } else {
254*b07cf47aSGerry Weißbach            $class='media';
255*b07cf47aSGerry Weißbach        }
256*b07cf47aSGerry Weißbach
257*b07cf47aSGerry Weißbach        //keep hash anchor
258*b07cf47aSGerry Weißbach        list($id,$hash) = explode('#',$id,2);
259*b07cf47aSGerry Weißbach        if(!empty($hash)) $hash = $this->_headerToLink($hash);
260*b07cf47aSGerry Weißbach
261*b07cf47aSGerry Weißbach        //prepare for formating
262*b07cf47aSGerry Weißbach        $link['target'] = $conf['target']['wiki'];
263*b07cf47aSGerry Weißbach        $link['style']  = '';
264*b07cf47aSGerry Weißbach        $link['pre']    = '';
265*b07cf47aSGerry Weißbach        $link['suf']    = '';
266*b07cf47aSGerry Weißbach        // highlight link to current page
267*b07cf47aSGerry Weißbach        if ($id == $INFO['id']) {
268*b07cf47aSGerry Weißbach            $link['pre']    = '<span class="curid">';
269*b07cf47aSGerry Weißbach            $link['suf']    = '</span>';
270*b07cf47aSGerry Weißbach        }
271*b07cf47aSGerry Weißbach        $link['more']   = '';
272*b07cf47aSGerry Weißbach        $link['class']  = $class;
273*b07cf47aSGerry Weißbach        $link['url']    = wl($id, $params);
274*b07cf47aSGerry Weißbach        $link['name']   = $name;
275*b07cf47aSGerry Weißbach        $link['title']  = $this->_getLinkTitle(null, $default, $isImage, $id, $linktype);
276*b07cf47aSGerry Weißbach        //add search string
277*b07cf47aSGerry Weißbach        if($search){
278*b07cf47aSGerry Weißbach            ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&amp;';
279*b07cf47aSGerry Weißbach            if(is_array($search)){
280*b07cf47aSGerry Weißbach                $search = array_map('rawurlencode',$search);
281*b07cf47aSGerry Weißbach                $link['url'] .= 's[]='.join('&amp;s[]=',$search);
282*b07cf47aSGerry Weißbach            }else{
283*b07cf47aSGerry Weißbach                $link['url'] .= 's='.rawurlencode($search);
284*b07cf47aSGerry Weißbach            }
285*b07cf47aSGerry Weißbach        }
286*b07cf47aSGerry Weißbach
287*b07cf47aSGerry Weißbach        //keep hash
288*b07cf47aSGerry Weißbach        if($hash) $link['url'].='#'.$hash;
289*b07cf47aSGerry Weißbach
290*b07cf47aSGerry Weißbach        //output formatted
291*b07cf47aSGerry Weißbach        if($returnonly){
292*b07cf47aSGerry Weißbach            return $this->_formatLink($link);
293*b07cf47aSGerry Weißbach        }else{
294*b07cf47aSGerry Weißbach            $this->doc .= $this->_formatLink($link);
295*b07cf47aSGerry Weißbach        }
296*b07cf47aSGerry Weißbach    }
297*b07cf47aSGerry Weißbach
298*b07cf47aSGerry Weißbach	function locallink($hash, $name = null){
299*b07cf47aSGerry Weißbach		global $ID;
300*b07cf47aSGerry Weißbach		$name  = $this->_getLinkTitle($name, $hash, $isImage);
301*b07cf47aSGerry Weißbach		$hash  = $this->_headerToLink($hash);
302*b07cf47aSGerry Weißbach		$title = $name;
303*b07cf47aSGerry Weißbach		$this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">';
304*b07cf47aSGerry Weißbach		$this->doc .= $name;
305*b07cf47aSGerry Weißbach		$this->doc .= '</a>';
306*b07cf47aSGerry Weißbach	}
307*b07cf47aSGerry Weißbach
308*b07cf47aSGerry Weißbach    function acronym($acronym) {
309*b07cf47aSGerry Weißbach
310*b07cf47aSGerry Weißbach        if ( empty($this->acronymsExchanged) ) {
311*b07cf47aSGerry Weißbach            $this->acronymsExchanged = $this->acronyms;
312*b07cf47aSGerry Weißbach            $this->acronyms = array();
313*b07cf47aSGerry Weißbach
314*b07cf47aSGerry Weißbach            foreach( $this->acronymsExchanged as $key => $value ) {
315*b07cf47aSGerry Weißbach                $this->acronyms[str_replace('_', ' ', $key)] = $value;
316*b07cf47aSGerry Weißbach            }
317*b07cf47aSGerry Weißbach        }
318*b07cf47aSGerry Weißbach
319*b07cf47aSGerry Weißbach        parent::acronym($acronym);
320*b07cf47aSGerry Weißbach    }
321*b07cf47aSGerry Weißbach
322*b07cf47aSGerry Weißbach    function entity($entity) {
323*b07cf47aSGerry Weißbach
324*b07cf47aSGerry Weißbach        if ( array_key_exists($entity, $this->entities) ) {
325*b07cf47aSGerry Weißbach            $entity = $this->entities[$entity];
326*b07cf47aSGerry Weißbach        }
327*b07cf47aSGerry Weißbach
328*b07cf47aSGerry Weißbach        $this->doc .= $this->_xmlEntities($entity);
329*b07cf47aSGerry Weißbach    }
330*b07cf47aSGerry Weißbach
331*b07cf47aSGerry Weißbach    function _xmlEntities($string) {
332*b07cf47aSGerry Weißbach
333*b07cf47aSGerry Weißbach        $string = parent::_xmlEntities($string);
334*b07cf47aSGerry Weißbach        $string = htmlentities($string, 8, 'UTF-8');
335*b07cf47aSGerry Weißbach        $string = $this->superentities($string);
336*b07cf47aSGerry Weißbach
337*b07cf47aSGerry Weißbach        if ( $this->info['scriptmode'] ) {
338*b07cf47aSGerry Weißbach            $string = str_replace(	array( "&lt;%", "%&gt;", "&lt;?", "?&gt;"),
339*b07cf47aSGerry Weißbach            array( "<%", "%>", "<?", "?>"),
340*b07cf47aSGerry Weißbach            $string);
341*b07cf47aSGerry Weißbach        }
342*b07cf47aSGerry Weißbach
343*b07cf47aSGerry Weißbach        return $string;
344*b07cf47aSGerry Weißbach    }
345*b07cf47aSGerry Weißbach
346*b07cf47aSGerry Weißbach	// Unicode-proof htmlentities.
347*b07cf47aSGerry Weißbach	// Returns 'normal' chars as chars and weirdos as numeric html entites.
348*b07cf47aSGerry Weißbach	function superentities( $str ){
349*b07cf47aSGerry Weißbach	    // get rid of existing entities else double-escape
350*b07cf47aSGerry Weißbach	    $str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8');
351*b07cf47aSGerry Weißbach	    $ar = preg_split('/(?<!^)(?!$)(?!\n)/u', $str );  // return array of every multi-byte character
352*b07cf47aSGerry Weißbach	    foreach ($ar as $c){
353*b07cf47aSGerry Weißbach	        $o = ord($c);
354*b07cf47aSGerry Weißbach	        if ( // (strlen($c) > 1) || /* multi-byte [unicode] */
355*b07cf47aSGerry Weißbach	            ($o > 127) // || /* <- control / latin weirdos -> */
356*b07cf47aSGerry Weißbach	            // ($o <32 || $o > 126) || /* <- control / latin weirdos -> */
357*b07cf47aSGerry Weißbach	            // ($o >33 && $o < 40) ||/* quotes + ambersand */
358*b07cf47aSGerry Weißbach	            // ($o >59 && $o < 63) /* html */
359*b07cf47aSGerry Weißbach
360*b07cf47aSGerry Weißbach	        ) {
361*b07cf47aSGerry Weißbach	            // convert to numeric entity
362*b07cf47aSGerry Weißbach	            $c = mb_encode_numericentity($c,array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
363*b07cf47aSGerry Weißbach	        }
364*b07cf47aSGerry Weißbach	        $str2 .= $c;
365*b07cf47aSGerry Weißbach	    }
366*b07cf47aSGerry Weißbach	    return $str2;
367*b07cf47aSGerry Weißbach	}
368*b07cf47aSGerry Weißbach}
369*b07cf47aSGerry Weißbach
370*b07cf47aSGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :