Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » [SOLVED] HMTLPurifier

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 692 Views
  • katja
    Avatar
    Community Member
    46 Posts

    [SOLVED] HMTLPurifier Link to this post

    After upgrading to SS3 I am running into problems with loading of HTMLPurifier which I use to clean frontend TinyMCE text entries. I get the following error message:

    [User Error] Uncaught Exception: HTML Purifier autoloader registrar is not compatible with non-static object methods due to PHP Bug #44144; Please do not use HTMLPurifier.autoload.php (or any file that includes this file); instead, place the code: spl_autoload_register(array('HTMLPurifier_Bootstrap', 'autoload')) after your own autoloaders.

    Where would I put that code? I saw that the spl_autoload_register function gets called in the manifest ClassLoader class, but I don't know how to add the other autoloader to that.

    Can anybody help me with this?

    Thanks,
    Katja

  • katja
    Avatar
    Community Member
    46 Posts

    Re: [SOLVED] HMTLPurifier Link to this post

    The answer to this is easy actually, you can avoid the whole autoloader thing if you just get the standalone version. I was just too tired yesterday..

    As there's not much documentation on this topic in general, I though I'd just post my way of implementing HTMLPurifier. Perhaps somebody has a better way.

    I just dropped in HTMLpurifier.standalone.php under mysite/thirdparty/ (it could be anywhere really), then created a class Purifier.php:
    <?php

    class Purifier
    {

    //put your code here

    public static function purify($content)
    {

    $config = HTMLPurifier_Config::createDefault();
    $config->set('HTML.Allowed', 'span,p,br,a,h1,h2,h3,h4,h5,strong,em,u,ul,li,ol,hr,blockquote,sub,sup,p[class],img');
    $config->set('HTML.AllowedElements', array('span','p','br','a','h1','h2','h3','h4','h5','strong','em','u','ul','li','ol','hr','blockquote','sub','sup','img'));
    $config->set('HTML.AllowedAttributes', 'style,target,title,href,class,src,border,alt,width,height,title,name,id,align,valign');
    $config->set('CSS.AllowedProperties', 'text-align,font-weight,text-decoration');
    $config->set('AutoFormat.RemoveEmpty', true);
    $config->set('Attr.ForbiddenClasses', array('MsoNormal'));

    $purifier = new HTMLPurifier($config);
    return $cleanCode = $purifier->purify($content);
    }
    }

    No you can call Purifier::purify($content) from anywhere.

    I also tried the class in the CMS and that worked as well:
    $purifier = HTMLCleaner::inst();
    $cleanhtml = $purifier->cleanHTML($content);
    But this is without the config then.

    692 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.