3 * Copyright (c) STMicroelectronics, 2007. All Rights Reserved.
5 * Originally written by Mohamed CHAARI, 2007.
7 * This file is a part of codendi.
9 * codendi is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * codendi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 define('CODENDI_PURIFIER_FORUMML', 20);
26 class ForumML_HTMLPurifier extends Codendi_HTMLPurifier {
29 * Hold an instance of the class
31 private static $ForumML_HTMLPurifier_instance;
36 protected function __construct() {
41 * Override parent method
44 public static function instance() {
46 if (!isset(self::$ForumML_HTMLPurifier_instance)) {
48 self::$ForumML_HTMLPurifier_instance = new $c;
50 return self::$ForumML_HTMLPurifier_instance;
54 * No basic HTML markups, no forms, no javascript
55 * Allow urls, auto-magic links, <blockquote> and CSS styles
57 function getForumMLConfig() {
59 $config = $this->getCodendiConfig();
60 // allow <blockquote> html tag, used to display ForumML messages replies
61 $config->set('HTML.AllowedElements', 'blockquote');
63 $config->set('CSS.DefinitionRev', 1);
68 * HTML Purifier configuration factory
70 function getHPConfig($level) {
73 case CODENDI_PURIFIER_FORUMML:
74 $config = $this->getForumMLConfig();
78 $config = parent::getHPConfig($level);
84 * Perform HTML purification depending of level purification required and create links.
86 function purify($html, $level=0, $groupId=0) {
89 case CODENDI_PURIFIER_FORUMML:
90 require_once($GLOBALS['htmlpurifier_dir'].'HTMLPurifier.auto.php');
91 $hp = HTMLPurifier::getInstance();
92 $config = $this->getHPConfig($level);
93 $clean = util_make_links($hp->purify($html, $config), $groupId);
96 $clean = parent::purify($html,$level,$groupId);