source: temp/test-xoops.ec-cube.net/html/modules/tinyd0/class/tinyd.textsanitizer.php @ 405

Revision 405, 3.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2
3if( ! class_exists( 'TinyDTextSanitizer' ) ) {
4
5include_once( XOOPS_ROOT_PATH . '/class/module.textsanitizer.php' ) ;
6
7class TinyDTextSanitizer extends MyTextSanitizer {
8
9    var $nbsp = 0 ;
10
11    /*
12    * Constructor of this class
13    *
14    * Gets allowed html tags from admin config settings
15    * <br> should not be allowed since nl2br will be used
16    * when storing data.
17    *
18    * @access   private
19    *
20    * @todo Sofar, this does nuttin' ;-)
21    */
22    function TinyDTextSanitizer()
23    {
24        parent::MyTextSanitizer() ;
25    }
26
27    /**
28     * Access the only instance of this class
29     *
30     * @return  object
31     *
32     * @static
33     * @staticvar   object
34     */
35    function &getInstance()
36    {
37        static $instance;
38        if (!isset($instance)) {
39            $instance = new TinyDTextSanitizer();
40        }
41        return $instance;
42    }
43
44    /**
45     * Filters textarea form data in DB for display
46     *
47     * @param   string  $text
48     * @param   bool    $html   allow html?
49     * @param   bool    $smiley allow smileys?
50     * @param   bool    $xcode  allow xoopscode?
51     * @param   bool    $image  allow inline images?
52     * @param   bool    $br     convert linebreaks?
53     * @return  string
54     **/
55    function displayTarea( $text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1 , $nbsp = 0 )
56    {
57        // save "javascript:"
58        $text = preg_replace( "/javascript:/si" , "jjaavvaassccrriipptt::" , $text ) ;
59
60        $this->nbsp = $nbsp ;
61        $text = parent::displayTarea( $text , $html , $smiley , $xcode , $image , $br ) ;
62        // restore "javascript:"
63        $text = preg_replace( "/jjaavvaassccrriipptt::/" , "javascript:" , $text ) ;
64        return $this->tinyDCodeDecode( $text , $nbsp ) ;
65/*      if ($html != 1) {
66            // html not allowed
67            $text =& $this->htmlSpecialChars($text);
68        }
69        $text =& $this->makeClickable($text);
70        if ($smiley != 0) {
71            // process smiley
72            $text =& $this->smiley($text);
73        }
74        if ($xcode != 0) {
75            // decode xcode
76            if ($image != 0) {
77                // image allowed
78                $text =& $this->xoopsCodeDecode($text);
79                    } else {
80                        // image not allowed
81                        $text =& $this->xoopsCodeDecode($text, 0);
82            }
83        }
84        if ($br != 0) {
85            $text =& $this->nl2Br($text);
86        }
87        return $text; */
88    }
89
90
91    /**
92     * Replace TinyDCodes with their equivalent HTML formatting
93     *
94     * @param   string  $text
95     * @return  string
96     **/
97    function tinyDCodeDecode( $text )
98    {
99        $removal_tags = array( '[summary]' , '[/summary]' , '[pagebreak]' ) ;
100        $text = str_replace( $removal_tags , '' , $text ) ;
101
102        $patterns = array();
103        $replacements = array();
104
105        $patterns[] = "/\[siteimg align=(['\"]?)(left|center|right)\\1]([^\"\(\)\?\&'<>]*)\[\/siteimg\]/sU";
106        $replacements[] = '<img src="'.XOOPS_URL.'/\\3" align="\\2" alt="" />';
107
108        $patterns[] = "/\[siteimg]([^\"\(\)\?\&'<>]*)\[\/siteimg\]/sU";
109        $replacements[] = '<img src="'.XOOPS_URL.'/\\1" alt="" />';
110
111        return preg_replace($patterns, $replacements, $text);
112    }
113
114
115    /**
116     * get inside of tags [summary] and [/summary]
117     *
118     * @param   string  $text
119     * @return  string
120     **/
121    function tinyExtractSummary( $text )
122    {
123        $patterns[] = "/^(.*)\[summary\](.*)\[\/summary\](.*)$/sU";
124        $replacements[] = '$2';
125
126        return preg_replace($patterns, $replacements, $text);
127    }
128
129
130    /**
131     * Convert linebreaks to <br /> tags
132     *
133     * @param   string  $text
134     *
135     * @return  string
136     */
137    function nl2Br( $text )
138    {
139        $text = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$text);
140        if( $this->nbsp ) {
141            $patterns = array( '  ' , '\"' ) ;
142            $replaces = array( ' &nbsp;' , '"' ) ;
143            $text = substr(preg_replace('/\>.*\</esU',"str_replace(\$patterns,\$replaces,'\\0')",">$text<"),1,-1);
144        }
145        return $text ;
146    }
147
148
149    /*
150    *  for displaying data in html textbox forms
151    *
152    * @param    string  $text
153    *
154    * @return   string
155    */
156    function htmlSpecialChars($text)
157    {
158        return htmlspecialchars($text, ENT_QUOTES);
159        //return preg_replace("/&amp;/i", '&', htmlspecialchars($text, ENT_QUOTES));
160        // return preg_replace(array("/&amp;/i", "/&nbsp;/i"), array('&', '&amp;nbsp;'), htmlspecialchars($text, ENT_QUOTES));
161    }
162
163
164// The End of Class
165}
166
167}
168
169?>
Note: See TracBrowser for help on using the repository browser.