1- <?php
2- /**
3- * Text sanitizing handlers
4- *
5- * @copyright The XOOPS project http://www.xoops.org/
6- * @license http://www.fsf.org/copyleft/gpl.html GNU public license
7- * @author Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
8- * @since 1.00
9- * @version $Id$
10- * @package Frameworks::art
11- */
12- if (!defined ("FRAMEWORKS_ART_FUNCTIONS_SANITIZER " )):
13- define ("FRAMEWORKS_ART_FUNCTIONS_SANITIZER " , true );
14-
15- /*
16- * Filter out possible malicious text
17- * kses project at SF could be a good solution to check
18- *
19- * @param string $text text to filter
20- * @param bool $force flag indicating to force filtering
21- * @return string filtered text
22- */
23- function text_filter (&$ text , $ force = false )
24- {
25- global $ icmsConfig ;
26-
27- if (empty ($ force ) && icms::$ user ->isAdmin ()) {
28- return $ text ;
29- }
30-
31- if (@include_once dirname (dirname (__FILE__ ))."/PEAR/HTML/Safe.php " ) {
32- $ safehtml = new HTML_Safe ();
33- $ text = $ safehtml ->parse ($ text );
34- return $ text ;
35- }
36-
37- // For future applications
38- $ tags = empty ($ icmsConfig ["filter_tags " ]) ? array () : explode (", " , $ icmsConfig ["filter_tags " ]);
39- $ tags = array_map ("trim " , $ tags );
40-
41- // Set embedded tags
42- $ tags [] = "SCRIPT " ;
43- $ tags [] = "VBSCRIPT " ;
44- $ tags [] = "JAVASCRIPT " ;
45- foreach ($ tags as $ tag ) {
46- $ search [] = "/< " .$ tag ."[^>]*?>.*?<\/ " .$ tag .">/si " ;
47- $ replace [] = " [! " .strtoupper ($ tag )." FILTERED!] " ;
48- }
49- // Set meta refresh tag
50- $ search []= "/<META[^>\/]*HTTP-EQUIV=([' \"])?REFRESH( \\1)[^>\/]*?\/>/si " ;
51- $ replace []="" ;
52-
53- // Sanitizing scripts in IMG tag
54- //$search[]= "/(<IMG[\s]+[^>\/]*SOURCE=)(['\"])?(.*)(\\2)([^>\/]*?\/>)/si";
55- //$replace[]="";
56-
57- // Set iframe tag
58- $ search []= "/<IFRAME[^>\/]*SRC=([' \"])?([^>\/]*)( \\1)[^>\/]*?\/>/si " ;
59- $ replace []=" [!IFRAME FILTERED! \\2] " ;
60- $ search []= "/<IFRAME[^>]*?>([^<]*)<\/IFRAME>/si " ;
61- $ replace []=" [!IFRAME FILTERED! \\1] " ;
62- // action
63- $ text = preg_replace ($ search , $ replace , $ text );
64- return $ text ;
65- }
66-
1+ <?php
2+ /**
3+ * Text sanitizing handlers
4+ *
5+ * @copyright The XOOPS project http://www.xoops.org/
6+ * @license http://www.fsf.org/copyleft/gpl.html GNU public license
7+ * @author Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
8+ * @since 1.00
9+ * @version $Id$
10+ * @package Frameworks::art
11+ */
12+ if (!defined ("FRAMEWORKS_ART_FUNCTIONS_SANITIZER " )):
13+ define ("FRAMEWORKS_ART_FUNCTIONS_SANITIZER " , true );
14+
15+ /*
16+ * Filter out possible malicious text
17+ * kses project at SF could be a good solution to check
18+ *
19+ * @param string $text text to filter
20+ * @param bool $force flag indicating to force filtering
21+ * @return string filtered text
22+ */
23+ function text_filter (&$ text , $ force = false )
24+ {
25+ global $ icmsConfig ;
26+
27+ if (empty ($ force ) && icms::$ user ->isAdmin ()) {
28+ return $ text ;
29+ }
30+
31+ if (@include_once dirname (dirname (__FILE__ ))."/PEAR/HTML/Safe.php " ) {
32+ $ safehtml = new HTML_Safe ();
33+ $ text = $ safehtml ->parse ($ text );
34+ return $ text ;
35+ }
36+
37+ // For future applications
38+ $ tags = empty ($ icmsConfig ["filter_tags " ]) ? array () : explode (", " , $ icmsConfig ["filter_tags " ]);
39+ $ tags = array_map ("trim " , $ tags );
40+
41+ // Set embedded tags
42+ $ tags [] = "SCRIPT " ;
43+ $ tags [] = "VBSCRIPT " ;
44+ $ tags [] = "JAVASCRIPT " ;
45+ foreach ($ tags as $ tag ) {
46+ $ search [] = "/< " .$ tag ."[^>]*?>.*?<\/ " .$ tag .">/si " ;
47+ $ replace [] = " [! " .strtoupper ($ tag )." FILTERED!] " ;
48+ }
49+ // Set meta refresh tag
50+ $ search []= "/<META[^>\/]*HTTP-EQUIV=([' \"])?REFRESH( \\1)[^>\/]*?\/>/si " ;
51+ $ replace []="" ;
52+
53+ // Sanitizing scripts in IMG tag
54+ //$search[]= "/(<IMG[\s]+[^>\/]*SOURCE=)(['\"])?(.*)(\\2)([^>\/]*?\/>)/si";
55+ //$replace[]="";
56+
57+ // Set iframe tag
58+ $ search []= "/<IFRAME[^>\/]*SRC=([' \"])?([^>\/]*)( \\1)[^>\/]*?\/>/si " ;
59+ $ replace []=" [!IFRAME FILTERED! \\2] " ;
60+ $ search []= "/<IFRAME[^>]*?>([^<]*)<\/IFRAME>/si " ;
61+ $ replace []=" [!IFRAME FILTERED! \\1] " ;
62+ // action
63+ $ text = preg_replace ($ search , $ replace , $ text );
64+ return $ text ;
65+ }
66+
6767endif ;
0 commit comments