commit | author | age
|
2207d6
|
1 |
|
W |
2 |
MODx Plugin |
|
3 |
|
|
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! |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
1. Credits |
|
14 |
|
|
15 |
PaulGregory wrote the overall structure of the code. I added the |
|
16 |
slashes hack. |
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
2. Install |
|
21 |
|
|
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). |
|
25 |
|
|
26 |
Log into the manager, and navigate: |
|
27 |
|
|
28 |
Resources > Manage Resources > Plugins tab > New Plugin |
|
29 |
|
|
30 |
Type in a name (probably HTML Purifier), and copy paste this code into the |
|
31 |
textarea: |
|
32 |
|
|
33 |
-------------------------------------------------------------------------------- |
|
34 |
$e = &$modx->Event; |
|
35 |
if ($e->name == 'OnBeforeDocFormSave') { |
|
36 |
global $content; |
|
37 |
|
|
38 |
include_once '../assets/plugins/htmlpurifier/library/HTMLPurifier.auto.php'; |
|
39 |
$purifier = new HTMLPurifier(); |
|
40 |
|
|
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 |
} |
|
48 |
|
|
49 |
if ($magic_quotes) $content = stripslashes($content); |
|
50 |
$content = $purifier->purify($content); |
|
51 |
if ($magic_quotes) $content = addslashes($content); |
|
52 |
} |
|
53 |
-------------------------------------------------------------------------------- |
|
54 |
|
|
55 |
Then navigate to the System Events tab and check "OnBeforeDocFormSave". |
|
56 |
Save the plugin. HTML Purifier now is integrated! |
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
3. Making sure it works |
|
61 |
|
|
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: |
|
64 |
|
|
65 |
<p lang="fr">Il est bon</p> |
|
66 |
|
|
67 |
...and seeing whether or not the content comes out as: |
|
68 |
|
|
69 |
<p lang="fr" xml:lang="fr">Il est bon</p> |
|
70 |
|
|
71 |
(lang to xml:lang synchronization is one of the many features HTML Purifier |
|
72 |
has). |
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
4. Caveat Emptor |
|
77 |
|
|
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). |
|
82 |
|
|
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: |
|
86 |
|
|
87 |
$config = HTMLPurifier_Config::createDefault(); |
|
88 |
$config->set('Core', 'Encoding', 'ISO-8859-1'); // or whatever encoding |
|
89 |
$purifier = new HTMLPurifier($config); |
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
5. Known Bugs |
|
94 |
|
|
95 |
'rn' characters sometimes mysteriously appear after purification. We are |
|
96 |
currently investigating this issue. See: <http://htmlpurifier.org/phorum/read.php?3,1866> |
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
6. See Also |
|
101 |
|
|
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> |
|
104 |
|
|
105 |
|
|
106 |
X. Changelog |
|
107 |
|
|
108 |
2008-06-16 |
|
109 |
- Updated code to work with 3.1.0 and later |
|
110 |
- Add Known Bugs and See Also section |
|
111 |
|
|
112 |
vim: et sw=4 sts=4 |