4 MODx <http://www.modxcms.com/> is an open source PHP application framework.
5 I first came across them in my referrer logs when tillda asked if anyone
6 could implement an HTML Purifier plugin. This forum thread
7 <http://modxcms.com/forums/index.php/topic,6604.0.html> eventually resulted
8 in the fruition of this plugin that davidm says, "is on top of my favorite
9 list." HTML Purifier goes great with WYSIWYG editors!
15 PaulGregory wrote the overall structure of the code. I added the
22 First, you need to place HTML Purifier library somewhere. The code here
23 assumes that you've placed in MODx's assets/plugins/htmlpurifier (no version
26 Log into the manager, and navigate:
28 Resources > Manage Resources > Plugins tab > New Plugin
30 Type in a name (probably HTML Purifier), and copy paste this code into the
33 --------------------------------------------------------------------------------
35 if ($e->name == 'OnBeforeDocFormSave') {
38 set_include_path('../assets/plugins/htmlpurifier/library/'
39 . PATH_SEPARATOR . get_include_path());
40 include_once 'HTMLPurifier.php';
41 $purifier = new HTMLPurifier();
43 static $magic_quotes = null;
44 if ($magic_quotes === null) {
45 // this is an ugly hack because this hook hasn't
46 // had the backslashes removed yet when magic_quotes_gpc is on,
47 // but HTMLPurifier must not have the quotes slashed.
48 $magic_quotes = get_magic_quotes_gpc();
51 if ($magic_quotes) $content = stripslashes($content);
52 $content = $purifier->purify($content);
53 if ($magic_quotes) $content = addslashes($content);
55 --------------------------------------------------------------------------------
57 Then navigate to the System Events tab and check "OnBeforeDocFormSave".
58 Save the plugin. HTML Purifier now is integrated!
62 3. Making sure it works
64 You can test HTML Purifier by deliberately putting in crappy HTML and seeing
65 whether or not it gets fixed. A better way is to put in something like this:
67 <p lang="fr">Il est bon</p>
69 ...and seeing whether or not the content comes out as:
71 <p lang="fr" xml:lang="fr">Il est bon</p>
73 (lang to xml:lang synchronization is one of the many features HTML Purifier
80 This code does not intercept save requests from the QuickEdit plugin, this may
81 be added in a later version. It also modifies things on save, so there's a
82 slight chance that HTML Purifier may make a boo-boo and accidently mess things
83 up (the original version is not saved).
85 Finally, make sure that MODx is using UTF-8. If you are using, say, a French
86 localisation, you may be using Latin-1, if that's the case, configure
87 HTML Purifier properly like this:
89 $config = HTMLPurifier_Config::createDefault();
90 $config->set('Core', 'Encoding', 'ISO-8859-1'); // or whatever encoding
91 $purifier = new HTMLPurifier($config);