Use info_parent_def to get parent information, since it may not be present in info...
[htmlpurifier.git] / plugins / modx.txt
blob0763821b50f2e19b69bb27ce97b94c74ab6454d3
2 MODx Plugin
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!
13 1. Credits
15 PaulGregory wrote the overall structure of the code.  I added the
16 slashes hack.
20 2. Install
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
24 number).
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
31 textarea:
33 --------------------------------------------------------------------------------
34 $e = &$modx->Event;
35 if ($e->name == 'OnBeforeDocFormSave') {
36     global $content;
38     include_once '../assets/plugins/htmlpurifier/library/HTMLPurifier.auto.php';
39     $purifier = new HTMLPurifier();
41     static $magic_quotes = null;
42     if ($magic_quotes === null) {
43         // this is an ugly hack because this hook hasn't
44         // had the backslashes removed yet when magic_quotes_gpc is on,
45         // but HTMLPurifier must not have the quotes slashed.
46         $magic_quotes = get_magic_quotes_gpc();
47     }
49     if ($magic_quotes) $content = stripslashes($content);
50     $content = $purifier->purify($content);
51     if ($magic_quotes) $content = addslashes($content);
53 --------------------------------------------------------------------------------
55 Then navigate to the System Events tab and check "OnBeforeDocFormSave".
56 Save the plugin.  HTML Purifier now is integrated!
60 3. Making sure it works
62 You can test HTML Purifier by deliberately putting in crappy HTML and seeing
63 whether or not it gets fixed.  A better way is to put in something like this:
65 <p lang="fr">Il est bon</p>
67 ...and seeing whether or not the content comes out as:
69 <p lang="fr" xml:lang="fr">Il est bon</p>
71 (lang to xml:lang synchronization is one of the many features HTML Purifier
72 has).
76 4. Caveat Emptor
78 This code does not intercept save requests from the QuickEdit plugin, this may
79 be added in a later version.  It also modifies things on save, so there's a
80 slight chance that HTML Purifier may make a boo-boo and accidently mess things
81 up (the original version is not saved).
83 Finally, make sure that MODx is using UTF-8.  If you are using, say, a French
84 localisation, you may be using Latin-1, if that's the case, configure
85 HTML Purifier properly like this:
87 $config = HTMLPurifier_Config::createDefault();
88 $config->set('Core', 'Encoding', 'ISO-8859-1'); // or whatever encoding
89 $purifier = new HTMLPurifier($config);
93 5. Known Bugs
95 'rn' characters sometimes mysteriously appear after purification. We are
96 currently investigating this issue. See: <http://htmlpurifier.org/phorum/read.php?3,1866>
100 6. See Also
102 A modified version of Jot 1.1.3 is available, which integrates with HTML
103 Purifier. You can check it out here: <http://modxcms.com/forums/index.php/topic,25621.msg161970.html>
106 X. Changelog
108 2008-06-16
109 - Updated code to work with 3.1.0 and later
110 - Add Known Bugs and See Also section
112     vim: et sw=4 sts=4