Loading...
 
Features / Usability

Features / Usability


TikiWiki 1.10, HTML Purifier, and target="_blank"

posts: 214

In TikiWiki 1.10, if you use feature HTMLPurifier, then target="_blank" is stripped from links in HTML code.
From reading the forum on http://htmlpurifier.org/ I found I could change lib/tikilib.php so HTML Purifier does not strip the target= from the links.

posts: 214

Modified code to allow target="_blank":

      if ($html && $prefs['feature_purifier'] != 'n') {

            require "HTMLPurifier.auto.php";
            $config = HTMLPurifier_Config::createDefault();
            $config->set('HTML', 'DefinitionID', 'allow attribute target');
            $config->set('HTML', 'DefinitionRev', 1);
            $config->set('HTML', 'Allowed', 'a[href|title|target]');
            $def =& $config->getHTMLDefinition(true);
            $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');
            $purifier = new HTMLPurifier($config);
            $edit_data = $purifier->purify($edit_data);

      }



Make sure you notice that the "$purifier = new HTMLPurifier();" line changed to: "$purifier = new HTMLPurifier($config);"

This change also stops the "title=" from being stripped.

This may not be the best solution. If someone finds a better one, please post it. Thanks.


posts: 214

Sorry, what a mess, I can only get this to post in sections, and now I have a section out of order. Here is the original code part:
Original lib/tikilib.php code:

      if ($html && $prefs['feature_purifier'] != 'n') {

            require "HTMLPurifier.auto.php";
            $purifier = new HTMLPurifier();
            $edit_data = $purifier->purify($edit_data);

      }