From 8f8bda7343ad5e6740647f9c9078bb1a2b730bb9 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 23 Apr 2012 10:24:46 +0200 Subject: [PATCH] MDL-32427 fix suport for extra schemes in links in HTML Purifier --- lib/htmlpurifier/locallib.php | 105 +++++++++++++++++++++++++++++ lib/htmlpurifier/readme_moodle.txt | 3 +- lib/weblib.php | 1 + 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 lib/htmlpurifier/locallib.php diff --git a/lib/htmlpurifier/locallib.php b/lib/htmlpurifier/locallib.php new file mode 100644 index 00000000000..66e4e97ef0e --- /dev/null +++ b/lib/htmlpurifier/locallib.php @@ -0,0 +1,105 @@ +. + +/** + * Extra classes needed for HTMLPurifier customisation for Moodle. + * + * @package core + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL 3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + + +/** + * Validates RTSP defined by RFC 2326 + */ +class HTMLPurifier_URIScheme_rtsp extends HTMLPurifier_URIScheme { + + public $browsable = true; + public $hierarchical = true; + + public function doValidate(&$uri, $config, $context) { + $uri->userinfo = null; + return true; + } + +} + + +/** + * Validates IRC defined by IETF Draft + */ +class HTMLPurifier_URIScheme_irc extends HTMLPurifier_URIScheme { + + public $browsable = true; + public $hierarchical = true; + + public function doValidate(&$uri, $config, $context) { + $uri->userinfo = null; + return true; + } + +} + + +/** + * Validates MMS defined by Microsoft + */ +class HTMLPurifier_URIScheme_mms extends HTMLPurifier_URIScheme { + + public $browsable = true; + public $hierarchical = true; + + public function doValidate(&$uri, $config, $context) { + $uri->userinfo = null; + return true; + } + +} + + +/** + * Validates Gopher defined by RFC 4266 + */ +class HTMLPurifier_URIScheme_gopher extends HTMLPurifier_URIScheme { + + public $browsable = true; + public $hierarchical = true; + + public function doValidate(&$uri, $config, $context) { + $uri->userinfo = null; + return true; + } + +} + + +/** + * Validates TeamSpeak defined by TeamSpeak + */ +class HTMLPurifier_URIScheme_teamspeak extends HTMLPurifier_URIScheme { + + public $browsable = true; + public $hierarchical = true; + + public function doValidate(&$uri, $config, $context) { + $uri->userinfo = null; + return true; + } + +} diff --git a/lib/htmlpurifier/readme_moodle.txt b/lib/htmlpurifier/readme_moodle.txt index 7d4c4e8393d..e91a97f7f88 100644 --- a/lib/htmlpurifier/readme_moodle.txt +++ b/lib/htmlpurifier/readme_moodle.txt @@ -1,6 +1,7 @@ Description of HTML Purifier v4.4.0+ library import into Moodle (Includes _blank fix 8c9d461a6259d7b8ac4ae5c9c9e95ab176cfcda3.) -No Changes.. +Changes: +* added locallib.php with Moodle specific extensions skodak diff --git a/lib/weblib.php b/lib/weblib.php index 35e09ebea12..04789834d4b 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1522,6 +1522,7 @@ function purify_html($text, $options = array()) { check_dir_exists($cachedir); require_once $CFG->libdir.'/htmlpurifier/HTMLPurifier.safe-includes.php'; + require_once $CFG->libdir.'/htmlpurifier/locallib.php'; $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.DefinitionID', 'moodlehtml');