source: OWR/Filter.php @ 22257f

Revision 22257f, 2.5 KB checked in by pierre-alain <pierre-alain@…>, 9 years ago (diff)

v0.1a2

  • Property mode set to 100644
Line 
1<?php
2/**
3 * Object used to filter inputs
4 *
5 * PHP 5
6 *
7 * OWR - OpenWebReader
8 *
9 * Copyright (c) 2009, Pierre-Alain Mignot
10 *
11 * Home page: http://openwebreader.org
12 *
13 * E-Mail: contact@openwebreader.org
14 *
15 * All Rights Reserved
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 *
31 * @author Pierre-Alain Mignot <contact@openwebreader.org>
32 * @copyright Copyright (c) 2009, Pierre-Alain Mignot
33 * @license http://www.gnu.org/copyleft/gpl.html
34 * @package OWR
35 */
36namespace OWR;
37/**
38 * This object is the default input filter
39 * @uses Exception the exceptions handler
40 * @uses Singleton implements the singleton pattern
41 * @uses Cache check that the directory htmlpurifier exists
42 * @package OWR
43 */
44class Filter extends Singleton
45{
46    /**
47    * @var mixed the HTMLPurifier instance
48    * @access private
49    */
50    private $_filter;
51
52    /**
53     * Constructor
54     *
55     * @access protected
56     * @author Pierre-Alain Mignot <contact@openwebreader.org>
57     */
58    protected function __construct()
59    {
60        class_exists('\HTMLPurifier', false) || include HOME_PATH.'libs/HTMLPurifier/HTMLPurifier.standalone.php';
61        $config = \HTMLPurifier_Config::createDefault();
62        $config->set('Core.Encoding', 'UTF-8');
63        $config->set('HTML.TidyLevel', 'heavy' );
64        $config->set('Cache.SerializerPath', HOME_PATH.'cache');
65        $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
66        $config->set('HTML.ForbiddenAttributes', '*@style');
67        $config->set('HTML.SafeObject', true);
68        $config->set('HTML.SafeEmbed', true);
69        $this->_filter = new \HTMLPurifier($config);
70    }
71
72    /**
73     * Purify the given value
74     *
75     * @access public
76     * @author Pierre-Alain Mignot <contact@openwebreader.org>
77     * @param string $str the string to purify
78     * @return string the purified string
79     */
80    public function purify($str)
81    {
82        return $this->_filter->purify((string) $str);
83    }
84}
Note: See TracBrowser for help on using the repository browser.