Request for IRC URI Scheme for HTML Purifier 4.2.0

424 views Asked by At

Can someone help me to establish using IRC URI Scheme for HTML Purifier 4.2.0? I can't seem to figure out how to configure or which files to modify so that purified html allows for irc:// links.

Is it possible I can simply modify configuration within the following code block?

require_once "htmlpurifier-4.2.0/library/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set("HTML.Doctype", "XHTML 1.0 Strict");
$purifier = new HTMLPurifier($purifier_config);

Update:

I edited library/standalone/HTMLPurifier/ConfigSchema/schema.ser changing both instances of "4:nntp" to "3:irc" and found error:

Warning: Directory htmlpurifier-4.2.0/library/standalone/HTMLPurifier/DefinitionCache/Serializer/URI not writable, please chmod to 777

I believe this will help to establish support for IRC URI Scheme after making this change. I'll report back in a bit.

Hmm, after making it writable, no error appeared, but no results =\

1

There are 1 answers

2
pinkgothic On

HTML Purifier doesn't seem to have a native support for the IRC scheme. But: Have you tried something like this? Put this in /library/HTMLPurifier/URIScheme, or otherwise make sure that autoloading finds it:

class HTMLPurifier_URIScheme_irc extends HTMLPurifier_URIScheme {

    public $default_port = 6667;
    public $browsable = false;

    public function validate(&$uri, $config, $context) {
        if (parent::validate($uri, $config, $context) === false) {
            return false;
        }
        if (!is_null($uri->path)) {
            // get channel name
            $uri->path = array_shift(explode('/', $uri->path));
        }
        $uri->userinfo = null;
        $uri->query    = null;
        $uri->fragment = null;
        return true;
    }

}

...and change your configuration with...

$purifier->config->set(
    'URI.AllowedSchemes',
    array('irc' => true, /* ... other schemes here ... */)
);

That may not work out of the box, but I'm thinking that should be the right direction...