root/afridex/plugins/Flutter/RCCWP_HTML_Purifier.php @ 21

Revision 21, 2.1 kB (checked in by admin, 18 years ago)
RevLine 
[21]1<?php
2class RCCWP_HTML_Purifier
3{
4        function ApplyHTMLPurifier($data)
5        {
6                include_once('RCCWP_Options.php');
7                if (0 == RCCWP_Options::Get('enable-HTMLPurifier')) return $data;
8               
9                // We need to handle <!-- manually because HTMLPurifier removes it
10                $MORE_TAG = "<!--more-->";
11
12                $purifier = RCCWP_HTML_Purifier::get_purifier ();
13               
14                $pos = strpos($data, $MORE_TAG);
15                if ($pos === false){
16                        $data =  addslashes ($purifier->purify (stripslashes ($data)));
17                }
18                else{
19                        $before_more = addslashes ($purifier->purify (stripslashes (substr($data,0,$pos))));
20                        $after_more = addslashes ($purifier->purify (stripslashes (substr($data,$pos+strlen($MORE_TAG)))));
21                        $data = $before_more.$MORE_TAG.$after_more;
22                }
23
24                return $data;
25        }
26
27        /**
28         * Get an HTML Purifier object with all settings already configured
29         *
30         * @return HTMLPurifier
31         **/
32       
33        function get_purifier ()
34        {
35                require_once('purifier_lib/HTMLPurifier.auto.php');
36                include_once('RCCWP_Options.php');
37
38                $config = HTMLPurifier_Config::createDefault();
39
40                // Set base options
41                $config->set ('HTML',   'Doctype', "HTML 4.01 Transitional");
42                $config->set ('Core',   'Encoding', get_option ('blog_charset'));
43                $config->set ('HTML',   'TidyLevel', RCCWP_Options::Get('tidy-level'));
44                $config->set ('Output', 'TidyFormat', true);
45               
46               
47                // If we can write to the cache directory then set it (directory is same as used by WP-Cache and WP object cache)
48                if (is_writeable (dirname (RCCWP_HTML_Purifier::cache_directory ())))
49                {
50                        if (!file_exists (RCCWP_HTML_Purifier::cache_directory ()))
51                                @mkdir (RCCWP_HTML_Purifier::cache_directory ());
52                                die('here');
53                        $config->set ('Cache', 'SerializerPath', RCCWP_HTML_Purifier::cache_directory ());     
54                }
55                else{
56                        $config->set ('Cache', 'DefinitionImpl', null);
57                        $config->set ('Cache', 'SerializerPath', null); 
58                }
59               
60               
61                return new HTMLPurifier ($config);
62        }
63
64
65        /**
66         * Return the cache directory
67         *
68         * @return string
69         **/
70       
71        function cache_directory ()
72        {
73                return realpath (dirname (__FILE__).'/../../cache/html-purified');
74        }
75
76}
77?>
Note: See TracBrowser for help on using the browser.