mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-04 05:07:55 +02:00
Compare commits
275 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d51d3c127b | ||
|
4f92c0377f | ||
|
c3efafb07d | ||
|
79c18eb781 | ||
|
7b64bc37e2 | ||
|
b3aa5fa0dc | ||
|
350d8301dd | ||
|
a40e16dd2e | ||
|
ee388e86c0 | ||
|
79df79b2fd | ||
|
f5b72c623c | ||
|
7bccc24977 | ||
|
25fe416ab2 | ||
|
a9012f4387 | ||
|
82f8561123 | ||
|
0b743fb2db | ||
|
08e32597df | ||
|
2b82fbacad | ||
|
710820cbe9 | ||
|
22ef52a7f6 | ||
|
4919187fc6 | ||
|
797b899305 | ||
|
8c9dbe142d | ||
|
2a002857ce | ||
|
9d98b45dea | ||
|
b0f3116b9e | ||
|
b03a44abff | ||
|
cf257cabde | ||
|
ab950a1909 | ||
|
a12ea4bb3b | ||
|
f80de908bd | ||
|
349c4de75b | ||
|
89622c964e | ||
|
732fe5cad7 | ||
|
e7e81c0a5b | ||
|
626b2a13c8 | ||
|
35487c02ae | ||
|
4bc1761b12 | ||
|
63f5414f2e | ||
|
88d014706b | ||
|
f6de73d7e7 | ||
|
733868a76d | ||
|
fab6a212c8 | ||
|
ea1362ce5c | ||
|
cff498ef67 | ||
|
1765a7537a | ||
|
d7157d0ccd | ||
|
ed44b5c5ba | ||
|
5e5c0f3aa4 | ||
|
b2ed0aff01 | ||
|
148681d1b0 | ||
|
2e7e411491 | ||
|
02051e465c | ||
|
a96b5bf612 | ||
|
9dd7c8c7dd | ||
|
0c59db1da3 | ||
|
584a1abd15 | ||
|
a6ede3804e | ||
|
4476745003 | ||
|
45748500ec | ||
|
e99520ab96 | ||
|
1e2abb7f8f | ||
|
362c802191 | ||
|
3a1d505b3d | ||
|
a005da8a4c | ||
|
9a66394abb | ||
|
62c0575468 | ||
|
6a95d91a1a | ||
|
275932ec05 | ||
|
ae90bb919d | ||
|
3c734b4c72 | ||
|
3d02a2a7d4 | ||
|
0bfa42f9b7 | ||
|
7a8edc88f9 | ||
|
98b4e70a93 | ||
|
6f5592ae60 | ||
|
9f996b125a | ||
|
96b571d236 | ||
|
0e9904a9ba | ||
|
e66a98c396 | ||
|
728088f2ba | ||
|
8ae2604440 | ||
|
7b087c7bbe | ||
|
58064592ff | ||
|
b19fc32a5a | ||
|
b15cbbb42a | ||
|
5f0663cad7 | ||
|
75e52a12a6 | ||
|
269268b843 | ||
|
62c6d93b6d | ||
|
31704c92f6 | ||
|
291fa4cb29 | ||
|
389fcc9a5d | ||
|
e5191b3ada | ||
|
5d0a992579 | ||
|
ae83bebc98 | ||
|
9191877740 | ||
|
3066ca357a | ||
|
53fd096641 | ||
|
2166246b7e | ||
|
49bb6ec35d | ||
|
401612dc3a | ||
|
dc0fb7d2b4 | ||
|
eee45fed37 | ||
|
03657ad51a | ||
|
dda4038446 | ||
|
996ccdbdda | ||
|
008348db21 | ||
|
b10a380ff4 | ||
|
bf0d659c47 | ||
|
e55551ecdd | ||
|
e9f3fef47b | ||
|
840f9f7434 | ||
|
10c970760d | ||
|
69996acc9e | ||
|
8bbb73e47d | ||
|
cf7a50163c | ||
|
da2ea348fd | ||
|
ab3ebcba6d | ||
|
d399abba50 | ||
|
0b0a505c30 | ||
|
6aa3dfc116 | ||
|
c3094275ef | ||
|
220c150e0a | ||
|
32d30a9181 | ||
|
0e5491b20c | ||
|
7699efd593 | ||
|
4bf15de536 | ||
|
70bcccf54c | ||
|
bf6ce67fc1 | ||
|
bd44105ca9 | ||
|
d1f43636e5 | ||
|
9c7483166c | ||
|
e840564228 | ||
|
7d4b532d6b | ||
|
58f00105c8 | ||
|
8d15d1ce13 | ||
|
9c60eeed04 | ||
|
2e089477a5 | ||
|
b442d09ea6 | ||
|
12f73605a3 | ||
|
e2a951420f | ||
|
002395de09 | ||
|
d1187ed331 | ||
|
426fbd1f97 | ||
|
9c5f01a0cf | ||
|
f985d3cd96 | ||
|
0cb1d85822 | ||
|
073ddb0cb2 | ||
|
889ccb1a92 | ||
|
aec84dc3f6 | ||
|
dea62ffdab | ||
|
8913239b7f | ||
|
e06929c218 | ||
|
aaf4839c34 | ||
|
c113f43440 | ||
|
bd8ecdd268 | ||
|
ef51f8681a | ||
|
ee61ffc0d9 | ||
|
f758f7c534 | ||
|
95499e34da | ||
|
de23201cbb | ||
|
21ab12a6a8 | ||
|
69666e977f | ||
|
fa05319e30 | ||
|
ea46d79b0a | ||
|
a62f8971e4 | ||
|
7a3e06d4d0 | ||
|
e180b7689e | ||
|
7579932948 | ||
|
818d0d7a23 | ||
|
797d3e0393 | ||
|
ff7eec7424 | ||
|
0ea04db559 | ||
|
831db14c79 | ||
|
a470fc5621 | ||
|
2945f6a930 | ||
|
71326abec1 | ||
|
23ef535043 | ||
|
fda2043ace | ||
|
3f06d8316c | ||
|
e4b621eec2 | ||
|
9728be4a52 | ||
|
f1ec05afd0 | ||
|
7481d349d3 | ||
|
086dc9177b | ||
|
4d38c02932 | ||
|
83a50465dc | ||
|
dd62a303eb | ||
|
e4e981b6f1 | ||
|
a846f4e70b | ||
|
a5136b65e4 | ||
|
2d035483dd | ||
|
831a09d455 | ||
|
2cbb3be602 | ||
|
f7eccc0038 | ||
|
65252d6fbd | ||
|
6b9c5ec603 | ||
|
e7b15068c2 | ||
|
53c19552d2 | ||
|
048242004e | ||
|
05e1aca2fa | ||
|
23feb457f2 | ||
|
8f6380d63a | ||
|
3b1c40b2fc | ||
|
da92cb9ff4 | ||
|
bda9167423 | ||
|
cb9c96a2b0 | ||
|
e0cf214c44 | ||
|
ed73fdd5b8 | ||
|
eaea42f827 | ||
|
7f39e1e2c3 | ||
|
b81fb0af90 | ||
|
47fe34ad81 | ||
|
ac50d333a5 | ||
|
ce013e2962 | ||
|
67fab710bf | ||
|
b3a599e8c2 | ||
|
f4e4c1556d | ||
|
c5e33416d3 | ||
|
6c08ca4c16 | ||
|
b1822bb04f | ||
|
893e962890 | ||
|
bd6071cb3b | ||
|
92ea74cba2 | ||
|
a01459c87a | ||
|
fd35c43643 | ||
|
0426985c81 | ||
|
bbea02f55c | ||
|
4e77a1adbd | ||
|
bd58a7ba77 | ||
|
a3ed9196b9 | ||
|
2646f5ea57 | ||
|
424c7ad2e3 | ||
|
234b3085d7 | ||
|
3d978c961d | ||
|
72254cd77a | ||
|
d8a6361244 | ||
|
968dfa2feb | ||
|
114d6841ab | ||
|
1c68d769b5 | ||
|
ac0ca3f15c | ||
|
2d5498b8aa | ||
|
71ccae1a3a | ||
|
cb186dddc4 | ||
|
2ceccc0969 | ||
|
93aa98ad01 | ||
|
c0b38bab85 | ||
|
d6c4473a12 | ||
|
fc06f221d5 | ||
|
ac3ab2a556 | ||
|
2c330cac73 | ||
|
a0d6543b84 | ||
|
e223490a78 | ||
|
2666f067cc | ||
|
826a57a04a | ||
|
e08b5aaa70 | ||
|
b15e8c344e | ||
|
2c9e041b4c | ||
|
e2c3394d70 | ||
|
1532fe703a | ||
|
058f1eba7d | ||
|
1102dc6e27 | ||
|
85374d330f | ||
|
a16d6c4342 | ||
|
9b5e2978ad | ||
|
06468a4157 | ||
|
0167f8aa84 | ||
|
f1a90e684b | ||
|
14d98413fd | ||
|
97a4ec7598 | ||
|
71ed725c5c | ||
|
d4bf41288a | ||
|
365bd78c20 | ||
|
52fa958fb2 |
2
Doxyfile
2
Doxyfile
@@ -4,7 +4,7 @@
|
|||||||
# Project related configuration options
|
# Project related configuration options
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
PROJECT_NAME = HTML Purifier
|
PROJECT_NAME = HTML Purifier
|
||||||
PROJECT_NUMBER = 1.5.0
|
PROJECT_NUMBER = 2.1.1
|
||||||
OUTPUT_DIRECTORY = "C:/Documents and Settings/Edward/My Documents/My Webs/htmlpurifier/docs/doxygen"
|
OUTPUT_DIRECTORY = "C:/Documents and Settings/Edward/My Documents/My Webs/htmlpurifier/docs/doxygen"
|
||||||
CREATE_SUBDIRS = NO
|
CREATE_SUBDIRS = NO
|
||||||
OUTPUT_LANGUAGE = English
|
OUTPUT_LANGUAGE = English
|
||||||
|
98
INSTALL
98
INSTALL
@@ -8,13 +8,11 @@ installation GUI, you've come to the wrong place!) The impatient can scroll
|
|||||||
down to the bottom of this INSTALL document to see the code, but you really
|
down to the bottom of this INSTALL document to see the code, but you really
|
||||||
should make sure a few things are properly done.
|
should make sure a few things are properly done.
|
||||||
|
|
||||||
Todo: Convert to using the array syntax for configuration.
|
|
||||||
|
|
||||||
|
|
||||||
1. Compatibility
|
1. Compatibility
|
||||||
|
|
||||||
HTML Purifier works in both PHP 4 and PHP 5, from PHP 4.3.9 and up. It has no
|
HTML Purifier works in both PHP 4 and PHP 5, from PHP 4.3.2 and up. It has no
|
||||||
core dependencies with other libraries. (Whoopee!)
|
core dependencies with other libraries.
|
||||||
|
|
||||||
Optional extensions are iconv (usually installed) and tidy (also common).
|
Optional extensions are iconv (usually installed) and tidy (also common).
|
||||||
If you use UTF-8 and don't plan on pretty-printing HTML, you can get away with
|
If you use UTF-8 and don't plan on pretty-printing HTML, you can get away with
|
||||||
@@ -47,7 +45,10 @@ HTML Purifier is all about web-standards, so accordingly your webpages should
|
|||||||
be standards compliant. HTML Purifier can deal with these doctypes:
|
be standards compliant. HTML Purifier can deal with these doctypes:
|
||||||
|
|
||||||
* XHTML 1.0 Transitional (default)
|
* XHTML 1.0 Transitional (default)
|
||||||
|
* XHTML 1.0 Strict
|
||||||
* HTML 4.01 Transitional
|
* HTML 4.01 Transitional
|
||||||
|
* HTML 4.01 Strict
|
||||||
|
* XHTML 1.1 (sans Ruby)
|
||||||
|
|
||||||
...and these character encodings:
|
...and these character encodings:
|
||||||
|
|
||||||
@@ -66,11 +67,7 @@ the doctype from this code in your HTML documents:
|
|||||||
<meta http-equiv="Content-type" content="text/html;charset=ENCODING">
|
<meta http-equiv="Content-type" content="text/html;charset=ENCODING">
|
||||||
|
|
||||||
For legacy codebases these declarations may be missing. If that is the case,
|
For legacy codebases these declarations may be missing. If that is the case,
|
||||||
STOP, and read up on character encodings and doctypes (in that order). Here
|
STOP, and read docs/enduser-utf8.html
|
||||||
are some links:
|
|
||||||
|
|
||||||
* http://www.joelonsoftware.com/articles/Unicode.html
|
|
||||||
* http://alistapart.com/stories/doctype/
|
|
||||||
|
|
||||||
You may currently be vulnerable to XSS and other security threats, and HTML
|
You may currently be vulnerable to XSS and other security threats, and HTML
|
||||||
Purifier won't be able to fix that.
|
Purifier won't be able to fix that.
|
||||||
@@ -87,7 +84,7 @@ into configuring things just for the heck of it, skip to 4.3).
|
|||||||
* Am I using UTF-8?
|
* Am I using UTF-8?
|
||||||
* Am I using XHTML 1.0 Transitional?
|
* Am I using XHTML 1.0 Transitional?
|
||||||
|
|
||||||
If you answered yes to any of these questions, instantiate a configuration
|
If you answered no to any of these questions, instantiate a configuration
|
||||||
object and read on:
|
object and read on:
|
||||||
|
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
@@ -114,36 +111,38 @@ websites):
|
|||||||
|
|
||||||
Note that HTML Purifier's support for non-Unicode encodings is crippled by the
|
Note that HTML Purifier's support for non-Unicode encodings is crippled by the
|
||||||
fact that any character not supported by that encoding will be silently
|
fact that any character not supported by that encoding will be silently
|
||||||
dropped, EVEN if it is ampersand escaped. This is a current limitation of
|
dropped, EVEN if it is ampersand escaped. If you want to work around
|
||||||
HTML Purifier that we are NOT actively working to fix. Patches are welcome,
|
this, you are welcome to read docs/enduser-utf8.html for a fix,
|
||||||
but there are so many other gotchas and problems in I18N for non-Unicode
|
but please be cognizant of the issues the "solution" creates (for this
|
||||||
encodings that this functionality is low priority. See
|
reason, I do not include the solution in this document).
|
||||||
<http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html> for a more
|
|
||||||
detailed lowdown on the topic.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
4.2. Setting a different doctype
|
4.2. Setting a different doctype
|
||||||
|
|
||||||
For those of you stuck using HTML 4.01 Transitional, you can disable
|
For those of you using HTML 4.01 Transitional, you can disable
|
||||||
XHTML output like this:
|
XHTML output like this:
|
||||||
|
|
||||||
$config->set('Core', 'XHTML', false);
|
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
|
||||||
|
|
||||||
I recommend that you use XHTML, although not as much as I recommend UTF-8. If
|
Other supported doctypes include:
|
||||||
your HTML 4.01 page validates, good for you!
|
|
||||||
|
|
||||||
Currently, we can only guarantee transitional-complaint output, future
|
* HTML 4.01 Strict
|
||||||
versions will also allow strict-compliant output.
|
* HTML 4.01 Transitional
|
||||||
|
* XHTML 1.0 Strict
|
||||||
|
* XHTML 1.0 Transitional
|
||||||
|
* XHTML 1.1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
4.3. Other settings
|
4.3. Other settings
|
||||||
|
|
||||||
There are more configuration directives which can be read about
|
There are more configuration directives which can be read about
|
||||||
here: <http://hp.jpsband.org/live/configdoc/plain.html> They're a bit boring,
|
here: <http://htmlpurifier.org/live/configdoc/plain.html> They're a bit boring,
|
||||||
but they can help out for those of you who like to exert maximum control over
|
but they can help out for those of you who like to exert maximum control over
|
||||||
your code.
|
your code. Some of the more interesting ones are configurable at the
|
||||||
|
demo <http://htmlpurifier.org/demo.php> and are well worth looking into
|
||||||
|
for your own system.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -160,13 +159,15 @@ The interface is mind-numbingly simple:
|
|||||||
$clean_html = $purifier->purify( $dirty_html );
|
$clean_html = $purifier->purify( $dirty_html );
|
||||||
|
|
||||||
That's it! For more examples, check out docs/examples/ (they aren't very
|
That's it! For more examples, check out docs/examples/ (they aren't very
|
||||||
different though). Also, SLOW gives advice on what to do if HTML Purifier
|
different though). Also, docs/enduser-slow.html gives advice on what to
|
||||||
is slowing down your application.
|
do if HTML Purifier is slowing down your application.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
6. Quick install
|
6. Quick install
|
||||||
|
|
||||||
|
First, make sure library/HTMLPurifier/DefinitionCache/Serializer is
|
||||||
|
writable by the webserver (see Section 7: Caching below for details).
|
||||||
If your website is in UTF-8 and XHTML Transitional, use this code:
|
If your website is in UTF-8 and XHTML Transitional, use this code:
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@@ -182,9 +183,48 @@ If your website is in a different encoding or doctype, use this code:
|
|||||||
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
|
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
$config->set('Core', 'Encoding', 'ISO-8859-1'); //replace with your encoding
|
$config->set('Core', 'Encoding', 'ISO-8859-1'); // replace with your encoding
|
||||||
$config->set('Core', 'XHTML', true); //replace with false if HTML 4.01
|
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
|
||||||
$purifier = new HTMLPurifier($config);
|
$purifier = new HTMLPurifier($config);
|
||||||
|
|
||||||
$clean_html = $purifier->purify($dirty_html);
|
$clean_html = $purifier->purify($dirty_html);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
7. Caching
|
||||||
|
|
||||||
|
HTML Purifier generates some cache files (generally one or two) to speed up
|
||||||
|
its execution. For maximum performance, make sure that
|
||||||
|
library/HTMLPurifier/DefinitionCache/Serializer is writeable by the webserver.
|
||||||
|
|
||||||
|
If you are in the library/ folder of HTML Purifier, you can set the
|
||||||
|
appropriate permissions using:
|
||||||
|
|
||||||
|
chmod -R 0755 HTMLPurifier/DefinitionCache/Serializer
|
||||||
|
|
||||||
|
If the above command doesn't work, you may need to assign write permissions
|
||||||
|
to all. This may be necessary if your webserver runs as nobody, but is
|
||||||
|
not recommended since it means any other user can write files in the
|
||||||
|
directory. Use:
|
||||||
|
|
||||||
|
chmod -R 0777 HTMLPurifier/DefinitionCache/Serializer
|
||||||
|
|
||||||
|
You can also chmod files via your FTP client; this option
|
||||||
|
is usually accessible by right clicking the corresponding directory and
|
||||||
|
then selecting "chmod" or "file permissions".
|
||||||
|
|
||||||
|
Starting with 2.0.1, HTML Purifier will generate friendly error messages
|
||||||
|
that will tell you exactly what you have to chmod the directory to, if in doubt,
|
||||||
|
follow its advice.
|
||||||
|
|
||||||
|
If you are unable or unwilling to give write permissions to the cache
|
||||||
|
directory, you can either disable the cache (and suffer a performance
|
||||||
|
hit):
|
||||||
|
|
||||||
|
$config->set('Core', 'DefinitionCache', null);
|
||||||
|
|
||||||
|
Or move the cache directory somewhere else (no trailing slash):
|
||||||
|
|
||||||
|
$config->set('Cache', 'SerializerPath', '/home/user/absolute/path');
|
||||||
|
|
||||||
|
71
INSTALL.fr.utf8
Normal file
71
INSTALL.fr.utf8
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
Installation
|
||||||
|
Comment installer HTML Purifier
|
||||||
|
|
||||||
|
Attention: Ce document a encode en UTF-8. Si les lettres avec les accents
|
||||||
|
est essoreuse, prenez un mieux editeur de texte.
|
||||||
|
|
||||||
|
À L'Aide: Je ne suis pas un diseur natif de français. Si vous trouvez une
|
||||||
|
erreur dans ce document, racontez-moi! Merci.
|
||||||
|
|
||||||
|
|
||||||
|
L'installation de HTML Purifier est trés simple, parce qu'il ne doit pas
|
||||||
|
la configuration. Dans le pied de de document, les utilisateurs
|
||||||
|
impatient peuvent trouver le code, mais je recommande que vous lisez
|
||||||
|
ce document pour quelques choses.
|
||||||
|
|
||||||
|
|
||||||
|
1. Compatibilité
|
||||||
|
|
||||||
|
HTML Purifier fonctionne dans PHP 4 et PHP 5. PHP 4.3.2 est le dernier
|
||||||
|
version que je le testais. Il ne dépend de les autre librairies.
|
||||||
|
|
||||||
|
Les extensions optionnel est iconv (en général déjà installer) et
|
||||||
|
tidy (répandu aussi). Si vous utilisez UTF-8 et ne voulez pas
|
||||||
|
l'indentation, vous pouvez utiliser HTML Purifier sans ces extensions.
|
||||||
|
|
||||||
|
|
||||||
|
2. Inclure la librarie
|
||||||
|
|
||||||
|
Utilisez:
|
||||||
|
|
||||||
|
require_once '/path/to/library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
|
...quand vous devez utiliser HTML Purifier (ne inclure pas quand vous
|
||||||
|
ne devez pas, parce que HTML Purifier est trés grand.)
|
||||||
|
|
||||||
|
Si vous n'aime pas que HTML Purifier change vos include_path, on peut
|
||||||
|
change vos include_path, et:
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier.php';
|
||||||
|
|
||||||
|
Seuleument les contents dans library/ est essentiel; vous peut enlever
|
||||||
|
les autre fichiers quand vous est dans une atmosphère professionnel.
|
||||||
|
|
||||||
|
|
||||||
|
[En cours de construction]
|
||||||
|
|
||||||
|
|
||||||
|
6. Installation vite
|
||||||
|
|
||||||
|
Si votre site web est en UTF-8 et XHTML Transitional, utilisez:
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
|
$purificateur = new HTMLPurifier();
|
||||||
|
$html_propre = $purificateur->purify($html_salle);
|
||||||
|
?>
|
||||||
|
|
||||||
|
Sinon, utilisez:
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('Core', 'Encoding', 'ISO-8859-1'); //remplacez avec votre encoding
|
||||||
|
$config->set('Core', 'XHTML', true); //remplacez avec false si HTML 4.01
|
||||||
|
$purificateur = new HTMLPurifier($config);
|
||||||
|
|
||||||
|
$html_propre = $purificateur->purify($html_salle);
|
||||||
|
?>
|
215
NEWS
215
NEWS
@@ -9,6 +9,221 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
. Internal change
|
. Internal change
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
2.1.1, released 2007-08-04
|
||||||
|
- Fix show-stopper bug in %URI.MakeAbsolute functionality
|
||||||
|
- Fix PHP4 syntax error in standalone version
|
||||||
|
. Add prefix directory to include path for standalone, this prevents
|
||||||
|
other installations from clobbering the standalone's URI schemes
|
||||||
|
. Single test methods can be invoked by prefixing with __only
|
||||||
|
|
||||||
|
2.1.0, released 2007-08-02
|
||||||
|
# flush-htmldefinition-cache.php superseded in favor of a generic
|
||||||
|
flush-definition-cache.php script, you can clear a specific cache
|
||||||
|
by passing its name as a parameter to the script
|
||||||
|
! Phorum mod implemented for HTML Purifier
|
||||||
|
! With %Core.AggressivelyFixLt, <3 and similar emoticons no longer
|
||||||
|
trigger HTML removal in PHP5 (DOMLex). This directive is not necessary
|
||||||
|
for PHP4 (DirectLex).
|
||||||
|
! Standalone file now available, which greatly reduces the amount of
|
||||||
|
includes (although there are still a few files that reside in the
|
||||||
|
standalone folder)
|
||||||
|
! Relative URIs can now be transformed into their absolute equivalents
|
||||||
|
using %URI.Base and %URI.MakeAbsolute
|
||||||
|
! Ruby implemented for XHTML 1.1
|
||||||
|
! You can now define custom URI filtering behavior, see enduser-uri-filter.html
|
||||||
|
for more details
|
||||||
|
! UTF-8 font names now supported in CSS
|
||||||
|
- AutoFormatters emit friendly error messages if tags or attributes they
|
||||||
|
need are not allowed
|
||||||
|
- ConfigForm's compactification of directive names is now configurable
|
||||||
|
- AutoParagraph autoformatter algorithm refined after field-testing
|
||||||
|
- XHTML 1.1 now applies XHTML 1.0 Strict cleanup routines, namely
|
||||||
|
blockquote wrapping
|
||||||
|
- Contents of <style> tags removed by default when tags are removed
|
||||||
|
. HTMLPurifier_Config->getSerial() implemented, this is extremely useful
|
||||||
|
for output cache invalidation
|
||||||
|
. ConfigForm printer now can retrieve CSS and JS files as strings, in
|
||||||
|
case HTML Purifier's directory is not publically accessible
|
||||||
|
. Introduce new text/itext configuration directive values: these represent
|
||||||
|
longer strings that would be more appropriately edited with a textarea
|
||||||
|
. Allow newlines to act as separators for lists, hashes, lookups and
|
||||||
|
%HTML.Allowed
|
||||||
|
. ConfigForm generates textareas instead of text inputs for lists, hashes,
|
||||||
|
lookups, text and itext fields
|
||||||
|
. Hidden element content removal genericized: %Core.HiddenElements can
|
||||||
|
be used to customize this behavior, by default <script> and <style> are
|
||||||
|
hidden
|
||||||
|
. Added HTMLPURIFIER_PREFIX constant, should be used instead of dirname(__FILE__)
|
||||||
|
. Custom ChildDef added to default include list
|
||||||
|
. URIScheme reflection improved: will not attempt to include file if class
|
||||||
|
already exists. May clobber autoload, so I need to keep an eye on it
|
||||||
|
. ConfigSchema heavily optimized, will only collect information and validate
|
||||||
|
definitions when HTMLPURIFIER_SCHEMA_STRICT is true.
|
||||||
|
. AttrDef_URI unit tests and implementation refactored
|
||||||
|
. benchmarks/ directory now protected from public view with .htaccess file;
|
||||||
|
run the tests via command line
|
||||||
|
. URI scheme is munged off if there is no authority and the scheme is the
|
||||||
|
default one
|
||||||
|
. All unit tests inherit from HTMLPurifier_Harness, not UnitTestCase
|
||||||
|
. Interface for URIScheme changed
|
||||||
|
. Generic URI object to hold components of URI added, most systems involved
|
||||||
|
in URI validation have been migrated to use it
|
||||||
|
. Custom filtering for URIs factored out to URIDefinition interface for
|
||||||
|
maximum extensibility
|
||||||
|
|
||||||
|
2.0.1, released 2007-06-27
|
||||||
|
! Tag auto-closing now based on a ChildDef heuristic rather than a
|
||||||
|
manually set auto_close array; some behavior may change
|
||||||
|
! Experimental AutoFormat functionality added: auto-paragraph and
|
||||||
|
linkify your HTML input by setting %AutoFormat.AutoParagraph and
|
||||||
|
%AutoFormat.Linkify to true
|
||||||
|
! Newlines normalized internally, and then converted back to the
|
||||||
|
value of PHP_EOL. If this is not desired, set your newline format
|
||||||
|
using %Output.Newline.
|
||||||
|
! Beta error collection, messages are implemented for the most generic
|
||||||
|
cases involving Lexing or Strategies
|
||||||
|
- Clean up special case code for <script> tags
|
||||||
|
- Reorder includes for DefinitionCache decorators, fixes a possible
|
||||||
|
missing class error
|
||||||
|
- Fixed bug where manually modified definitions were not saved via cache
|
||||||
|
(mostly harmless, except for the fact that it would be a little slower)
|
||||||
|
- Configuration objects with different serials do not clobber each
|
||||||
|
others when revision numbers are unequal
|
||||||
|
- Improve Serializer DefinitionCache directory permissions checks
|
||||||
|
- DefinitionCache no longer throws errors when it encounters old
|
||||||
|
serial files that do not conform to the current style
|
||||||
|
- Stray xmlns attributes removed from configuration documentation
|
||||||
|
- configForm.php smoketest no longer has XSS vulnerability due to
|
||||||
|
unescaped print_r output
|
||||||
|
- Printer adheres to configuration's directives on output format
|
||||||
|
- Fix improperly named form field in ConfigForm printer
|
||||||
|
. Rewire some test-cases to swallow errors rather than expect them
|
||||||
|
. HTMLDefinition printer updated with some of the new attributes
|
||||||
|
. DefinitionCache keys reordered to reflect precedence: version number,
|
||||||
|
hash, then revision number
|
||||||
|
. %Core.DefinitionCache renamed to %Cache.DefinitionImpl
|
||||||
|
. Interlinking in configuration documentation added using
|
||||||
|
Injector_PurifierLinkify
|
||||||
|
. Directives now keep track of aliases to themselves
|
||||||
|
. Error collector now requires a severity to be passed, use PHP's internal
|
||||||
|
error constants for this
|
||||||
|
. HTMLPurifier_Config::getAllowedDirectivesForForm implemented, allows
|
||||||
|
much easier selective embedding of configuration values
|
||||||
|
. Doctype objects now accept public and system DTD identifiers
|
||||||
|
. %HTML.Doctype is now constrained by specific values, to specify a custom
|
||||||
|
doctype use new %HTML.CustomDoctype
|
||||||
|
. ConfigForm truncates long directives to keep the form small, and does
|
||||||
|
not re-output namespaces
|
||||||
|
|
||||||
|
2.0.0, released 2007-06-20
|
||||||
|
# Completely refactored HTMLModuleManager, decentralizing safety
|
||||||
|
information
|
||||||
|
# Transform modules changed to Tidy modules, which offer more flexibility
|
||||||
|
and better modularization
|
||||||
|
# Configuration object now finalizes itself when a read operation is
|
||||||
|
performed on it, ensuring that its internal state stays consistent.
|
||||||
|
To revert this behavior, you can set the $autoFinalize member variable
|
||||||
|
off, but it's not recommended.
|
||||||
|
# New compact syntax for AttrDef objects that can be used to instantiate
|
||||||
|
new objects via make()
|
||||||
|
# Definitions (esp. HTMLDefinition) are now cached for a significant
|
||||||
|
performance boost. You can disable caching by setting %Core.DefinitionCache
|
||||||
|
to null. You CANNOT edit raw definitions without setting the corresponding
|
||||||
|
DefinitionID directive (%HTML.DefinitionID for HTMLDefinition).
|
||||||
|
# Contents between <script> tags are now completely removed if <script>
|
||||||
|
is not allowed
|
||||||
|
# Prototype-declarations for Lexer removed in favor of configuration
|
||||||
|
determination of Lexer implementations.
|
||||||
|
! HTML Purifier now works in PHP 4.3.2.
|
||||||
|
! Configuration form-editing API makes tweaking HTMLPurifier_Config a
|
||||||
|
breeze!
|
||||||
|
! Configuration directives that accept hashes now allow new string
|
||||||
|
format: key1:value1,key2:value2
|
||||||
|
! ConfigDoc now factored into OOP design
|
||||||
|
! All deprecated elements now natively supported
|
||||||
|
! Implement TinyMCE styled whitelist specification format in
|
||||||
|
%HTML.Allowed
|
||||||
|
! Config object gives more friendly error messages when things go wrong
|
||||||
|
! Advanced API implemented: easy functions for creating elements (addElement)
|
||||||
|
and attributes (addAttribute) on HTMLDefinition
|
||||||
|
! Add native support for required attributes
|
||||||
|
- Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work!
|
||||||
|
- DOMLex will not emit errors when a custom error handler that does not
|
||||||
|
honor error_reporting is used
|
||||||
|
- StrictBlockquote child definition refrains from wrapping whitespace
|
||||||
|
in tags now.
|
||||||
|
- Bug resulting from tag transforms to non-allowed elements fixed
|
||||||
|
- ChildDef_Custom's regex generation has been improved, removing several
|
||||||
|
false positives
|
||||||
|
. Unit test for ElementDef created, ElementDef behavior modified to
|
||||||
|
be more flexible
|
||||||
|
. Added convenience functions for HTMLModule constructors
|
||||||
|
. AttrTypes now has accessor functions that should be used instead
|
||||||
|
of directly manipulating info
|
||||||
|
. TagTransform_Center deprecated in favor of generic TagTransform_Simple
|
||||||
|
. Add extra protection in AttrDef_URI against phantom Schemes
|
||||||
|
. Doctype object added to HTMLDefinition which describes certain aspects
|
||||||
|
of the operational document type
|
||||||
|
. Lexer is now pre-emptively included, with a conditional include for the
|
||||||
|
PHP5 only version.
|
||||||
|
. HTMLDefinition and CSSDefinition have a common parent class: Definition.
|
||||||
|
. DirectLex can now track line-numbers
|
||||||
|
. Preliminary error collector is in place, although no code actually reports
|
||||||
|
errors yet
|
||||||
|
. Factor out most of ValidateAttributes to new AttrValidator class
|
||||||
|
|
||||||
|
1.6.1, released 2007-05-05
|
||||||
|
! Support for more deprecated attributes via transformations:
|
||||||
|
+ hspace and vspace in img
|
||||||
|
+ size and noshade in hr
|
||||||
|
+ nowrap in td
|
||||||
|
+ clear in br
|
||||||
|
+ align in caption, table, img and hr
|
||||||
|
+ type in ul, ol and li
|
||||||
|
! DirectLex now preserves text in which a < bracket is followed by
|
||||||
|
a non-alphanumeric character. This means that certain emoticons
|
||||||
|
are now preserved.
|
||||||
|
! %Core.RemoveInvalidImg is now operational, when set to false invalid
|
||||||
|
images will hang around with an empty src
|
||||||
|
! target attribute in a tag supported, use %Attr.AllowedFrameTargets
|
||||||
|
to enable
|
||||||
|
! CSS property white-space now allows nowrap (supported in all modern
|
||||||
|
browsers) but not others (which have spotty browser implementations)
|
||||||
|
! XHTML 1.1 mode now sort-of works without any fatal errors, and
|
||||||
|
lang is now moved over to xml:lang.
|
||||||
|
! Attribute transformation smoketest available at smoketests/attrTransform.php
|
||||||
|
! Transformation of font's size attribute now handles super-large numbers
|
||||||
|
- Possibly fatal bug with __autoload() fixed in module manager
|
||||||
|
- Invert HTMLModuleManager->addModule() processing order to check
|
||||||
|
prefixes first and then the literal module
|
||||||
|
- Empty strings get converted to empty arrays instead of arrays with
|
||||||
|
an empty string in them.
|
||||||
|
- Merging in attribute lists now works.
|
||||||
|
. Demo script removed: it has been added to the website's repository
|
||||||
|
. Basic.php script modified to work out of the box
|
||||||
|
. Refactor AttrTransform classes to reduce duplication
|
||||||
|
. AttrTransform_TextAlign axed in favor of a more general
|
||||||
|
AttrTransform_EnumToCSS, refer to HTMLModule/TransformToStrict.php to
|
||||||
|
see how the new equivalent is implemented
|
||||||
|
. Unit tests now use exclusively assertIdentical
|
||||||
|
|
||||||
|
1.6.0, released 2007-04-01
|
||||||
|
! Support for most common deprecated attributes via transformations:
|
||||||
|
+ bgcolor in td, th, tr and table
|
||||||
|
+ border in img
|
||||||
|
+ name in a and img
|
||||||
|
+ width in td, th and hr
|
||||||
|
+ height in td, th
|
||||||
|
! Support for CSS attribute 'height' added
|
||||||
|
! Support for rel and rev attributes in a tags added, use %Attr.AllowedRel
|
||||||
|
and %Attr.AllowedRev to activate
|
||||||
|
- You can define ID blacklists using regular expressions via
|
||||||
|
%Attr.IDBlacklistRegexp
|
||||||
|
- Error messages are emitted when you attempt to "allow" elements or
|
||||||
|
attributes that HTML Purifier does not support
|
||||||
|
- Fix segfault in unit test. The problem is not very reproduceable and
|
||||||
|
I don't know what causes it, but a six line patch fixed it.
|
||||||
|
|
||||||
1.5.0, released 2007-03-23
|
1.5.0, released 2007-03-23
|
||||||
! Added a rudimentary I18N and L10N system modeled off MediaWiki. It
|
! Added a rudimentary I18N and L10N system modeled off MediaWiki. It
|
||||||
doesn't actually do anything yet, but keep your eyes peeled.
|
doesn't actually do anything yet, but keep your eyes peeled.
|
||||||
|
2
README
2
README
@@ -19,4 +19,4 @@ Places to go:
|
|||||||
an in-depth installation guide.
|
an in-depth installation guide.
|
||||||
* See WYSIWYG for information on editors like TinyMCE and FCKeditor
|
* See WYSIWYG for information on editors like TinyMCE and FCKeditor
|
||||||
|
|
||||||
HTML Purifier can be found on the web at: http://hp.jpsband.org/
|
HTML Purifier can be found on the web at: http://htmlpurifier.org/
|
||||||
|
81
TODO
81
TODO
@@ -4,33 +4,18 @@ TODO List
|
|||||||
= KEY ====================
|
= KEY ====================
|
||||||
# Flagship
|
# Flagship
|
||||||
- Regular
|
- Regular
|
||||||
? At-risk
|
? Maybe I'll Do It
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
1.6 release
|
If no interest is expressed for a feature that may required a considerable
|
||||||
# Implement all non-essential attribute transforms, configurable
|
amount of effort to implement, it may get endlessly delayed. Do not be
|
||||||
# URI validation routines tighter (see docs/dev-code-quality.html) (COMPLEX)
|
afraid to cast your vote for the next feature to be implemented!
|
||||||
# Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
|
|
||||||
|
2.2 release [Error'ed]
|
||||||
# Error logging for filtering/cleanup procedures
|
# Error logging for filtering/cleanup procedures
|
||||||
- Requires I18N facilities to be created first (COMPLEX)
|
|
||||||
? Configuration profiles: sets of directives that get set with one func call
|
|
||||||
- XSS-attempt detection
|
- XSS-attempt detection
|
||||||
- Implement IDREF support
|
|
||||||
|
|
||||||
1.7 release
|
2.3 release [Do What I Mean, Not What I Say]
|
||||||
# Add pre-packaged "levels" of cleaning (custom behavior already done)
|
|
||||||
- More fine-grained control over escaping behavior
|
|
||||||
- Silently drop content inbetween SCRIPT tags (can be generalized to allow
|
|
||||||
specification of elements that, when detected as foreign, trigger removal
|
|
||||||
of children, although unbalanced tags could wreck havoc (or at least
|
|
||||||
delete the rest of the document)).
|
|
||||||
- Allow specifying global attributes on a tag-by-tag basis in
|
|
||||||
%HTML.AllowAttributes
|
|
||||||
? More user-friendly warnings when %HTML.Allow* attempts to specify a
|
|
||||||
tag or attribute that is not supported
|
|
||||||
- Parse TinyMCE whitelist into our %HTML.Allow* whitelists
|
|
||||||
|
|
||||||
1.8 release
|
|
||||||
# Additional support for poorly written HTML
|
# Additional support for poorly written HTML
|
||||||
- Microsoft Word HTML cleaning (i.e. MsoNormal, but research essential!)
|
- Microsoft Word HTML cleaning (i.e. MsoNormal, but research essential!)
|
||||||
- Friendly strict handling of <address> (block -> <br>)
|
- Friendly strict handling of <address> (block -> <br>)
|
||||||
@@ -45,47 +30,59 @@ TODO List
|
|||||||
- Append something to duplicate IDs so they're still usable (impl. note: the
|
- Append something to duplicate IDs so they're still usable (impl. note: the
|
||||||
dupe detector would also need to detect the suffix as well)
|
dupe detector would also need to detect the suffix as well)
|
||||||
|
|
||||||
2.0 release
|
2.4 release [It's All About Trust] (floating)
|
||||||
|
# Implement untrusted, dangerous elements/attributes
|
||||||
|
# Implement IDREF support (harder than it seems, since you cannot have
|
||||||
|
IDREFs to non-existent IDs)
|
||||||
|
|
||||||
|
3.0 release [Beyond HTML]
|
||||||
# Legit token based CSS parsing (will require revamping almost every
|
# Legit token based CSS parsing (will require revamping almost every
|
||||||
AttrDef class)
|
AttrDef class)
|
||||||
# Formatters for plaintext (COMPLEX)
|
# More control over allowed CSS properties (maybe modularize it in the
|
||||||
- Auto-paragraphing (be sure to leverage fact that we know when things
|
same fashion!)
|
||||||
shouldn't be paragraphed, such as lists and tables).
|
# Formatters for plaintext
|
||||||
- Linkify URLs
|
|
||||||
- Smileys
|
- Smileys
|
||||||
- Linkification for HTML Purifier docs: notably configuration and classes
|
- Standardize token armor for all areas of processing
|
||||||
|
|
||||||
3.0 release
|
|
||||||
- Extended HTML capabilities based on namespacing and tag transforms (COMPLEX)
|
|
||||||
- Hooks for adding custom processors to custom namespaced tags and
|
|
||||||
attributes, offer default implementation
|
|
||||||
- Lots of documentation and samples
|
|
||||||
- Allow tags to be "armored", an internal flag that protects them
|
|
||||||
from validation and passes them out unharmed
|
|
||||||
- XHTML 1.1 support
|
|
||||||
- Fixes for Firefox's inability to handle COL alignment props (Bug 915)
|
- Fixes for Firefox's inability to handle COL alignment props (Bug 915)
|
||||||
- Automatically add non-breaking spaces to empty table cells when
|
- Automatically add non-breaking spaces to empty table cells when
|
||||||
empty-cells:show is applied to have compatibility with Internet Explorer
|
empty-cells:show is applied to have compatibility with Internet Explorer
|
||||||
- Convert RTL/LTR override characters to <bdo> tags, or vice versa on demand.
|
- Convert RTL/LTR override characters to <bdo> tags, or vice versa on demand.
|
||||||
Also, enable disabling of directionality
|
Also, enable disabling of directionality
|
||||||
|
|
||||||
|
4.0 release [To XML and Beyond]
|
||||||
|
- Extended HTML capabilities based on namespacing and tag transforms (COMPLEX)
|
||||||
|
- Hooks for adding custom processors to custom namespaced tags and
|
||||||
|
attributes, offer default implementation
|
||||||
|
- Lots of documentation and samples
|
||||||
|
|
||||||
Ongoing
|
Ongoing
|
||||||
- Lots of profiling, make it faster!
|
- Lots of profiling, make it faster!
|
||||||
- Plugins for major CMSes (COMPLEX)
|
- Plugins for major CMSes (COMPLEX)
|
||||||
- WordPress
|
- phpBB
|
||||||
- eFiction
|
- eFiction
|
||||||
- more! (look for ones that use WYSIWYGs)
|
- more! (look for ones that use WYSIWYGs)
|
||||||
|
- Complete basic smoketests
|
||||||
|
|
||||||
Unknown release (on a scratch-an-itch basis)
|
Unknown release (on a scratch-an-itch basis)
|
||||||
- Have 'lang' attribute be checked against official lists
|
? Semi-lossy dumb alternate character encoding transfor
|
||||||
? Semi-lossy dumb alternate character encoding transformations, achieved by
|
? Have 'lang' attribute be checked against official lists, achieved by
|
||||||
encoding all characters that have string entity equivalents
|
encoding all characters that have string entity equivalents
|
||||||
|
- Abstract ChildDef_BlockQuote to work with all elements that only
|
||||||
|
allow blocks in them, required or optional
|
||||||
|
- Reorganize Unit Tests
|
||||||
|
- Refactor loop tests: Lexer
|
||||||
|
- Reorganize configuration directives (Create more namespaces! Get messy!)
|
||||||
|
- Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
|
||||||
|
- Implement lenient <ruby> child validation
|
||||||
|
- Explain how to use HTML Purifier in non-PHP languages / create
|
||||||
|
a simple command line stub (or complicated?)
|
||||||
|
|
||||||
Requested
|
Requested
|
||||||
? Native content compression, whitespace stripping (don't rely on Tidy, make
|
|
||||||
sure we don't remove from <pre> or related tags)
|
|
||||||
|
|
||||||
Wontfix
|
Wontfix
|
||||||
- Non-lossy smart alternate character encoding transformations (unless
|
- Non-lossy smart alternate character encoding transformations (unless
|
||||||
patch provided)
|
patch provided)
|
||||||
- Pretty-printing HTML, users can use Tidy on the output on entire page
|
- Pretty-printing HTML, users can use Tidy on the output on entire page
|
||||||
|
- Native content compression, whitespace stripping (don't rely on Tidy, make
|
||||||
|
sure we don't remove from <pre> or related tags): use gzip if this is
|
||||||
|
really important
|
||||||
|
10
WHATSNEW
Normal file
10
WHATSNEW
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
In version 2.1, HTML Purifier's URI validation and filtering handling
|
||||||
|
system has been revamped with a new, extensible URIFilter system. Also
|
||||||
|
notable features include preservation of emoticons in PHP5 with
|
||||||
|
%Core.AggressivelyFixLt, standalone and lite download versions,
|
||||||
|
transforming relative URIs to absolute URIs, Ruby in XHTML 1.1, a Phorum
|
||||||
|
mod, and UTF-8 font names. Notable bug-fixes include refinement of
|
||||||
|
the auto-paragraphing algorithm (no longer experimental), better XHTML
|
||||||
|
1.1 support and the removal of the contents of <style> elements. Version
|
||||||
|
2.1.1 amends a few bugs in some of newly introduced features, namely
|
||||||
|
running the standalone download version in PHP4 and %URI.MakeAbsolute.
|
4
WYSIWYG
4
WYSIWYG
@@ -16,7 +16,3 @@ trouble. Therein lies the solution:
|
|||||||
HTML Purifier is perfect for filtering pure-HTML input from WYSIWYG editors.
|
HTML Purifier is perfect for filtering pure-HTML input from WYSIWYG editors.
|
||||||
|
|
||||||
Enough said.
|
Enough said.
|
||||||
|
|
||||||
There is a proof-of-concept integration of HTML Purifier with the Mantis
|
|
||||||
bugtracker at http://hp.jpsband.org/mantis/ You can see notes on how
|
|
||||||
this integration was acheived at http://hp.jpsband.org/mantis_notes.txt
|
|
||||||
|
BIN
art/100cases.png
Normal file
BIN
art/100cases.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
1
benchmarks/.htaccess
Normal file
1
benchmarks/.htaccess
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Deny from all
|
@@ -165,4 +165,4 @@ echo '<div>Random input was: ' .
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@@ -15,5 +15,3 @@ $context = new HTMLPurifier_Context();
|
|||||||
for ($i = 0; $i < 10; $i++) {
|
for ($i = 0; $i < 10; $i++) {
|
||||||
$tokens = $lexer->tokenizeHTML($input, $config, $context);
|
$tokens = $lexer->tokenizeHTML($input, $config, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
12
benchmarks/Trace.php
Normal file
12
benchmarks/Trace.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
ini_set('xdebug.trace_format', 1);
|
||||||
|
ini_set('xdebug.show_mem_delta', true);
|
||||||
|
|
||||||
|
xdebug_start_trace(dirname(__FILE__) . '/Trace');
|
||||||
|
require_once '../library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
|
$purifier = new HTMLPurifier();
|
||||||
|
|
||||||
|
$data = $purifier->purify(file_get_contents('samples/Lexer/4.html'));
|
||||||
|
xdebug_stop_trace();
|
@@ -2,219 +2,44 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates XML and HTML documents describing configuration.
|
* Generates XML and HTML documents describing configuration.
|
||||||
|
* @note PHP 5 only!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
- make XML format richer (see below)
|
- make XML format richer (see XMLSerializer_ConfigSchema)
|
||||||
- extend XSLT transformation (see the corresponding XSLT file)
|
- extend XSLT transformation (see the corresponding XSLT file)
|
||||||
- allow generation of packaged docs that can be easily moved
|
- allow generation of packaged docs that can be easily moved
|
||||||
- multipage documentation
|
- multipage documentation
|
||||||
- determine how to multilingualize
|
- determine how to multilingualize
|
||||||
- factor out code into classes
|
- add blurbs to ToC
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Check and configure environment
|
|
||||||
|
|
||||||
if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.');
|
if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL); // probably not possible to use E_STRICT
|
||||||
|
|
||||||
|
define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// load dual-libraries
|
||||||
// Include HTML Purifier library
|
require_once '../library/HTMLPurifier.auto.php';
|
||||||
|
require_once 'library/ConfigDoc.auto.php';
|
||||||
|
|
||||||
set_include_path('../library' . PATH_SEPARATOR . get_include_path());
|
$purifier = HTMLPurifier::getInstance(array(
|
||||||
require_once 'HTMLPurifier.php';
|
'AutoFormat.PurifierLinkify' => true
|
||||||
|
));
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Setup convenience functions
|
|
||||||
|
|
||||||
function appendHTMLDiv($document, $node, $html) {
|
|
||||||
global $purifier;
|
|
||||||
$html = $purifier->purify($html);
|
|
||||||
$dom_html = $document->createDocumentFragment();
|
|
||||||
$dom_html->appendXML($html);
|
|
||||||
|
|
||||||
$dom_div = $document->createElement('div');
|
|
||||||
$dom_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
||||||
$dom_div->appendChild($dom_html);
|
|
||||||
|
|
||||||
$node->appendChild($dom_div);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Load copies of HTMLPurifier_ConfigDef and HTMLPurifier
|
|
||||||
|
|
||||||
$schema = HTMLPurifier_ConfigSchema::instance();
|
$schema = HTMLPurifier_ConfigSchema::instance();
|
||||||
$purifier = new HTMLPurifier();
|
$style = 'plain'; // use $_GET in the future
|
||||||
|
$configdoc = new ConfigDoc();
|
||||||
|
$output = $configdoc->generate($schema, $style);
|
||||||
|
|
||||||
|
// write out
|
||||||
// ---------------------------------------------------------------------------
|
file_put_contents("$style.html", $output);
|
||||||
// Generate types.xml, a document describing the constraint "type"
|
|
||||||
|
|
||||||
$types_document = new DOMDocument('1.0', 'UTF-8');
|
|
||||||
$types_root = $types_document->createElement('types');
|
|
||||||
$types_document->appendChild($types_root);
|
|
||||||
$types_document->formatOutput = true;
|
|
||||||
foreach ($schema->types as $name => $expanded_name) {
|
|
||||||
$types_type = $types_document->createElement('type', $expanded_name);
|
|
||||||
$types_type->setAttribute('id', $name);
|
|
||||||
$types_root->appendChild($types_type);
|
|
||||||
}
|
|
||||||
$types_document->save('types.xml');
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Generate configdoc.xml, a document documenting configuration directives
|
|
||||||
|
|
||||||
$dom_document = new DOMDocument('1.0', 'UTF-8');
|
|
||||||
$dom_root = $dom_document->createElement('configdoc');
|
|
||||||
$dom_document->appendChild($dom_root);
|
|
||||||
$dom_document->formatOutput = true;
|
|
||||||
|
|
||||||
// add the name of the application
|
|
||||||
$dom_root->appendChild($dom_document->createElement('title', 'HTML Purifier'));
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO for XML format:
|
|
||||||
- create a definition (DTD or other) once interface stabilizes
|
|
||||||
*/
|
|
||||||
|
|
||||||
foreach($schema->info as $namespace_name => $namespace_info) {
|
|
||||||
|
|
||||||
$dom_namespace = $dom_document->createElement('namespace');
|
|
||||||
$dom_root->appendChild($dom_namespace);
|
|
||||||
|
|
||||||
$dom_namespace->setAttribute('id', $namespace_name);
|
|
||||||
$dom_namespace->appendChild(
|
|
||||||
$dom_document->createElement('name', $namespace_name)
|
|
||||||
);
|
|
||||||
$dom_namespace_description = $dom_document->createElement('description');
|
|
||||||
$dom_namespace->appendChild($dom_namespace_description);
|
|
||||||
appendHTMLDiv($dom_document, $dom_namespace_description,
|
|
||||||
$schema->info_namespace[$namespace_name]->description);
|
|
||||||
|
|
||||||
foreach ($namespace_info as $name => $info) {
|
|
||||||
|
|
||||||
if ($info->class == 'alias') continue;
|
|
||||||
|
|
||||||
$dom_directive = $dom_document->createElement('directive');
|
|
||||||
$dom_namespace->appendChild($dom_directive);
|
|
||||||
|
|
||||||
$dom_directive->setAttribute('id', $namespace_name . '.' . $name);
|
|
||||||
$dom_directive->appendChild(
|
|
||||||
$dom_document->createElement('name', $name)
|
|
||||||
);
|
|
||||||
|
|
||||||
$dom_constraints = $dom_document->createElement('constraints');
|
|
||||||
$dom_directive->appendChild($dom_constraints);
|
|
||||||
|
|
||||||
$dom_type = $dom_document->createElement('type', $info->type);
|
|
||||||
if ($info->allow_null) {
|
|
||||||
$dom_type->setAttribute('allow-null', 'yes');
|
|
||||||
}
|
|
||||||
$dom_constraints->appendChild($dom_type);
|
|
||||||
|
|
||||||
if ($info->allowed !== true) {
|
|
||||||
$dom_allowed = $dom_document->createElement('allowed');
|
|
||||||
$dom_constraints->appendChild($dom_allowed);
|
|
||||||
foreach ($info->allowed as $allowed => $bool) {
|
|
||||||
$dom_allowed->appendChild(
|
|
||||||
$dom_document->createElement('value', $allowed)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$raw_default = $schema->defaults[$namespace_name][$name];
|
|
||||||
if (is_bool($raw_default)) {
|
|
||||||
$default = $raw_default ? 'true' : 'false';
|
|
||||||
} elseif (is_string($raw_default)) {
|
|
||||||
$default = "\"$raw_default\"";
|
|
||||||
} elseif (is_null($raw_default)) {
|
|
||||||
$default = 'null';
|
|
||||||
} else {
|
|
||||||
$default = print_r(
|
|
||||||
$schema->defaults[$namespace_name][$name], true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dom_default = $dom_document->createElement('default', $default);
|
|
||||||
|
|
||||||
// remove this once we get a DTD
|
|
||||||
$dom_default->setAttribute('xml:space', 'preserve');
|
|
||||||
|
|
||||||
$dom_constraints->appendChild($dom_default);
|
|
||||||
|
|
||||||
$dom_descriptions = $dom_document->createElement('descriptions');
|
|
||||||
$dom_directive->appendChild($dom_descriptions);
|
|
||||||
|
|
||||||
foreach ($info->descriptions as $file => $file_descriptions) {
|
|
||||||
foreach ($file_descriptions as $line => $description) {
|
|
||||||
$dom_description = $dom_document->createElement('description');
|
|
||||||
$dom_description->setAttribute('file', $file);
|
|
||||||
$dom_description->setAttribute('line', $line);
|
|
||||||
appendHTMLDiv($dom_document, $dom_description, $description);
|
|
||||||
$dom_descriptions->appendChild($dom_description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// print_r($dom_document->saveXML());
|
|
||||||
|
|
||||||
// save a copy of the raw XML
|
|
||||||
$dom_document->save('configdoc.xml');
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Generate final output using XSLT
|
|
||||||
|
|
||||||
// load the stylesheet
|
|
||||||
$xsl_stylesheet_name = 'plain';
|
|
||||||
$xsl_stylesheet = "styles/$xsl_stylesheet_name.xsl";
|
|
||||||
$xsl_dom_stylesheet = new DOMDocument();
|
|
||||||
$xsl_dom_stylesheet->load($xsl_stylesheet);
|
|
||||||
|
|
||||||
// setup the XSLT processor
|
|
||||||
$xsl_processor = new XSLTProcessor();
|
|
||||||
|
|
||||||
// perform the transformation
|
|
||||||
$xsl_processor->importStylesheet($xsl_dom_stylesheet);
|
|
||||||
$html_output = $xsl_processor->transformToXML($dom_document);
|
|
||||||
|
|
||||||
// some slight fudges to preserve backwards compatibility
|
|
||||||
$html_output = str_replace('/>', ' />', $html_output); // <br /> not <br/>
|
|
||||||
$html_output = str_replace(' xmlns=""', '', $html_output); // rm unnecessary xmlns
|
|
||||||
|
|
||||||
if (class_exists('Tidy')) {
|
|
||||||
// cleanup output
|
|
||||||
$config = array(
|
|
||||||
'indent' => true,
|
|
||||||
'output-xhtml' => true,
|
|
||||||
'wrap' => 80
|
|
||||||
);
|
|
||||||
$tidy = new Tidy;
|
|
||||||
$tidy->parseString($html_output, $config, 'utf8');
|
|
||||||
$tidy->cleanRepair();
|
|
||||||
$html_output = (string) $tidy;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write it to a file (todo: parse into seperate pages)
|
|
||||||
file_put_contents("$xsl_stylesheet_name.html", $html_output);
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Output for instant feedback
|
|
||||||
|
|
||||||
if (php_sapi_name() != 'cli') {
|
if (php_sapi_name() != 'cli') {
|
||||||
echo $html_output;
|
// output = instant feedback
|
||||||
|
echo $output;
|
||||||
} else {
|
} else {
|
||||||
echo 'Files generated successfully.';
|
echo 'Files generated successfully.';
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
9
configdoc/library/ConfigDoc.auto.php
Normal file
9
configdoc/library/ConfigDoc.auto.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a stub include that automatically configures the include path.
|
||||||
|
*/
|
||||||
|
|
||||||
|
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
|
||||||
|
require_once 'ConfigDoc.php';
|
||||||
|
|
38
configdoc/library/ConfigDoc.php
Normal file
38
configdoc/library/ConfigDoc.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'ConfigDoc/HTMLXSLTProcessor.php';
|
||||||
|
require_once 'ConfigDoc/XMLSerializer/Types.php';
|
||||||
|
require_once 'ConfigDoc/XMLSerializer/ConfigSchema.php';
|
||||||
|
|
||||||
|
class ConfigDoc
|
||||||
|
{
|
||||||
|
|
||||||
|
function generate($schema, $xsl_stylesheet_name = 'plain', $parameters = array()) {
|
||||||
|
// generate types document, describing type constraints
|
||||||
|
$types_serializer = new ConfigDoc_XMLSerializer_Types();
|
||||||
|
$types_document = $types_serializer->serialize($schema);
|
||||||
|
$types_document->save(dirname(__FILE__) . '/../types.xml'); // only ONE
|
||||||
|
|
||||||
|
// generate configdoc.xml, documents configuration directives
|
||||||
|
$schema_serializer = new ConfigDoc_XMLSerializer_ConfigSchema();
|
||||||
|
$schema_document = $schema_serializer->serialize($schema);
|
||||||
|
$schema_document->save('configdoc.xml');
|
||||||
|
|
||||||
|
// setup transformation
|
||||||
|
$xsl_stylesheet = dirname(__FILE__) . "/../styles/$xsl_stylesheet_name.xsl";
|
||||||
|
$xslt_processor = new ConfigDoc_HTMLXSLTProcessor();
|
||||||
|
$xslt_processor->setParameters($parameters);
|
||||||
|
$xslt_processor->importStylesheet($xsl_stylesheet);
|
||||||
|
|
||||||
|
return $xslt_processor->transformToHTML($schema_document);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any generated files
|
||||||
|
*/
|
||||||
|
function cleanup() {
|
||||||
|
unlink('configdoc.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
62
configdoc/library/ConfigDoc/HTMLXSLTProcessor.php
Normal file
62
configdoc/library/ConfigDoc/HTMLXSLTProcessor.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special XSLTProcessor specifically for HTML documents. Loosely
|
||||||
|
* based off of XSLTProcessor, but not really
|
||||||
|
*/
|
||||||
|
class ConfigDoc_HTMLXSLTProcessor
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $xsltProcessor;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->xsltProcessor = new XSLTProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports stylesheet for processor to use
|
||||||
|
* @param $xsl XSLT DOM tree, or filename of the XSL transformation
|
||||||
|
*/
|
||||||
|
public function importStylesheet($xsl) {
|
||||||
|
if (is_string($xsl)) {
|
||||||
|
$xsl_file = $xsl;
|
||||||
|
$xsl = new DOMDocument();
|
||||||
|
$xsl->load($xsl_file);
|
||||||
|
}
|
||||||
|
return $this->xsltProcessor->importStylesheet($xsl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms an XML file into HTML based on the stylesheet
|
||||||
|
* @param $xml XML DOM tree
|
||||||
|
*/
|
||||||
|
public function transformToHTML($xml) {
|
||||||
|
$out = $this->xsltProcessor->transformToXML($xml);
|
||||||
|
|
||||||
|
// fudges for HTML backwards compatibility
|
||||||
|
$out = str_replace('/>', ' />', $out); // <br /> not <br/>
|
||||||
|
$out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns
|
||||||
|
$out = str_replace(' xmlns="http://www.w3.org/1999/xhtml"', '', $out); // rm unnecessary xmlns
|
||||||
|
if (class_exists('Tidy')) {
|
||||||
|
// cleanup output
|
||||||
|
$config = array(
|
||||||
|
'indent' => true,
|
||||||
|
'output-xhtml' => true,
|
||||||
|
'wrap' => 80
|
||||||
|
);
|
||||||
|
$tidy = new Tidy;
|
||||||
|
$tidy->parseString($out, $config, 'utf8');
|
||||||
|
$tidy->cleanRepair();
|
||||||
|
$out = (string) $tidy;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setParameters($options) {
|
||||||
|
foreach ($options as $name => $value) {
|
||||||
|
$this->xsltProcessor->setParameter('', $name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
25
configdoc/library/ConfigDoc/XMLSerializer.php
Normal file
25
configdoc/library/ConfigDoc/XMLSerializer.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The XMLSerializer hierarchy of classes consist of classes that take
|
||||||
|
* objects and serialize them into XML, specifically DOM, form; this
|
||||||
|
* super-class contains convenience functions for those classes.
|
||||||
|
*/
|
||||||
|
class ConfigDoc_XMLSerializer
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function appendHTMLDiv($document, $node, $html) {
|
||||||
|
$purifier = HTMLPurifier::getInstance();
|
||||||
|
$html = $purifier->purify($html);
|
||||||
|
$dom_html = $document->createDocumentFragment();
|
||||||
|
$dom_html->appendXML($html);
|
||||||
|
|
||||||
|
$dom_div = $document->createElement('div');
|
||||||
|
$dom_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
||||||
|
$dom_div->appendChild($dom_html);
|
||||||
|
|
||||||
|
$node->appendChild($dom_div);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
123
configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php
Normal file
123
configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'ConfigDoc/XMLSerializer.php';
|
||||||
|
|
||||||
|
class ConfigDoc_XMLSerializer_ConfigSchema extends ConfigDoc_XMLSerializer
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a schema into DOM form
|
||||||
|
* @todo Split into sub-serializers
|
||||||
|
* @param $schema HTMLPurifier_ConfigSchema to serialize
|
||||||
|
*/
|
||||||
|
public function serialize($schema) {
|
||||||
|
$dom_document = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
$dom_root = $dom_document->createElement('configdoc');
|
||||||
|
$dom_document->appendChild($dom_root);
|
||||||
|
$dom_document->formatOutput = true;
|
||||||
|
|
||||||
|
// add the name of the application
|
||||||
|
$dom_root->appendChild($dom_document->createElement('title', 'HTML Purifier'));
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO for XML format:
|
||||||
|
- create a definition (DTD or other) once interface stabilizes
|
||||||
|
*/
|
||||||
|
|
||||||
|
foreach($schema->info as $namespace_name => $namespace_info) {
|
||||||
|
|
||||||
|
$dom_namespace = $dom_document->createElement('namespace');
|
||||||
|
$dom_root->appendChild($dom_namespace);
|
||||||
|
|
||||||
|
$dom_namespace->setAttribute('id', $namespace_name);
|
||||||
|
$dom_namespace->appendChild(
|
||||||
|
$dom_document->createElement('name', $namespace_name)
|
||||||
|
);
|
||||||
|
$dom_namespace_description = $dom_document->createElement('description');
|
||||||
|
$dom_namespace->appendChild($dom_namespace_description);
|
||||||
|
$this->appendHTMLDiv($dom_document, $dom_namespace_description,
|
||||||
|
$schema->info_namespace[$namespace_name]->description);
|
||||||
|
|
||||||
|
foreach ($namespace_info as $name => $info) {
|
||||||
|
|
||||||
|
if ($info->class == 'alias') continue;
|
||||||
|
|
||||||
|
$dom_directive = $dom_document->createElement('directive');
|
||||||
|
$dom_namespace->appendChild($dom_directive);
|
||||||
|
|
||||||
|
$dom_directive->setAttribute('id', $namespace_name . '.' . $name);
|
||||||
|
$dom_directive->appendChild(
|
||||||
|
$dom_document->createElement('name', $name)
|
||||||
|
);
|
||||||
|
|
||||||
|
$dom_aliases = $dom_document->createElement('aliases');
|
||||||
|
$dom_directive->appendChild($dom_aliases);
|
||||||
|
foreach ($info->directiveAliases as $alias) {
|
||||||
|
$dom_aliases->appendChild($dom_document->createElement('alias', $alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dom_constraints = $dom_document->createElement('constraints');
|
||||||
|
$dom_directive->appendChild($dom_constraints);
|
||||||
|
|
||||||
|
$dom_type = $dom_document->createElement('type', $info->type);
|
||||||
|
if ($info->allow_null) {
|
||||||
|
$dom_type->setAttribute('allow-null', 'yes');
|
||||||
|
}
|
||||||
|
$dom_constraints->appendChild($dom_type);
|
||||||
|
|
||||||
|
if ($info->allowed !== true) {
|
||||||
|
$dom_allowed = $dom_document->createElement('allowed');
|
||||||
|
$dom_constraints->appendChild($dom_allowed);
|
||||||
|
foreach ($info->allowed as $allowed => $bool) {
|
||||||
|
$dom_allowed->appendChild(
|
||||||
|
$dom_document->createElement('value', $allowed)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw_default = $schema->defaults[$namespace_name][$name];
|
||||||
|
if (is_bool($raw_default)) {
|
||||||
|
$default = $raw_default ? 'true' : 'false';
|
||||||
|
} elseif (is_string($raw_default)) {
|
||||||
|
$default = "\"$raw_default\"";
|
||||||
|
} elseif (is_null($raw_default)) {
|
||||||
|
$default = 'null';
|
||||||
|
} else {
|
||||||
|
$default = print_r(
|
||||||
|
$schema->defaults[$namespace_name][$name], true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dom_default = $dom_document->createElement('default', $default);
|
||||||
|
|
||||||
|
// remove this once we get a DTD
|
||||||
|
$dom_default->setAttribute('xml:space', 'preserve');
|
||||||
|
|
||||||
|
$dom_constraints->appendChild($dom_default);
|
||||||
|
|
||||||
|
$dom_descriptions = $dom_document->createElement('descriptions');
|
||||||
|
$dom_directive->appendChild($dom_descriptions);
|
||||||
|
|
||||||
|
foreach ($info->descriptions as $file => $file_descriptions) {
|
||||||
|
foreach ($file_descriptions as $line => $description) {
|
||||||
|
$dom_description = $dom_document->createElement('description');
|
||||||
|
// refuse to write $file if it's a full path
|
||||||
|
if (str_replace('\\', '/', realpath($file)) != $file) {
|
||||||
|
$dom_description->setAttribute('file', $file);
|
||||||
|
$dom_description->setAttribute('line', $line);
|
||||||
|
}
|
||||||
|
$this->appendHTMLDiv($dom_document, $dom_description, $description);
|
||||||
|
$dom_descriptions->appendChild($dom_description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dom_document;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
26
configdoc/library/ConfigDoc/XMLSerializer/Types.php
Normal file
26
configdoc/library/ConfigDoc/XMLSerializer/Types.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'ConfigDoc/XMLSerializer.php';
|
||||||
|
|
||||||
|
class ConfigDoc_XMLSerializer_Types extends ConfigDoc_XMLSerializer
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes the types in a schema into DOM form
|
||||||
|
* @param $schema HTMLPurifier_ConfigSchema owner of types to serialize
|
||||||
|
*/
|
||||||
|
public function serialize($schema) {
|
||||||
|
$types_document = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
$types_root = $types_document->createElement('types');
|
||||||
|
$types_document->appendChild($types_root);
|
||||||
|
$types_document->formatOutput = true;
|
||||||
|
foreach ($schema->types as $name => $expanded_name) {
|
||||||
|
$types_type = $types_document->createElement('type', $expanded_name);
|
||||||
|
$types_type->setAttribute('id', $name);
|
||||||
|
$types_root->appendChild($types_type);
|
||||||
|
}
|
||||||
|
return $types_document;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -12,19 +12,21 @@
|
|||||||
indent = "no"
|
indent = "no"
|
||||||
media-type = "text/html"
|
media-type = "text/html"
|
||||||
/>
|
/>
|
||||||
|
<xsl:param name="css" select="'styles/plain.css'"/>
|
||||||
|
<xsl:param name="title" select="'Configuration Documentation'"/>
|
||||||
|
|
||||||
<xsl:variable name="typeLookup" select="document('../types.xml')" />
|
<xsl:variable name="typeLookup" select="document('../types.xml')" />
|
||||||
|
|
||||||
<xsl:template match="/">
|
<xsl:template match="/">
|
||||||
<html lang="en" xml:lang="en">
|
<html lang="en" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Configuration Documentation - <xsl:value-of select="/configdoc/title" /></title>
|
<title><xsl:value-of select="$title" /> - <xsl:value-of select="/configdoc/title" /></title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||||
<link rel="stylesheet" type="text/css" href="styles/plain.css" />
|
<link rel="stylesheet" type="text/css" href="{$css}" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="library"><xsl:value-of select="/configdoc/title" /></div>
|
<div id="library"><xsl:value-of select="/configdoc/title" /></div>
|
||||||
<h1>Configuration Documentation</h1>
|
<h1><xsl:value-of select="$title" /></h1>
|
||||||
<h2>Table of Contents</h2>
|
<h2>Table of Contents</h2>
|
||||||
<ul id="toc">
|
<ul id="toc">
|
||||||
<xsl:apply-templates mode="toc" />
|
<xsl:apply-templates mode="toc" />
|
||||||
@@ -70,23 +72,45 @@
|
|||||||
<xsl:apply-templates />
|
<xsl:apply-templates />
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
<xsl:template match="directive/name">
|
<xsl:template match="directive/name">
|
||||||
|
<xsl:apply-templates select="../aliases/alias" mode="anchor" />
|
||||||
<h3 id="{../@id}"><xsl:value-of select="../@id" /></h3>
|
<h3 id="{../@id}"><xsl:value-of select="../@id" /></h3>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
<xsl:template match="alias" mode="anchor">
|
||||||
|
<a id="{.}"></a>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<!-- Do not pass through -->
|
||||||
|
<xsl:template match="alias"></xsl:template>
|
||||||
|
|
||||||
<xsl:template match="directive/constraints">
|
<xsl:template match="directive/constraints">
|
||||||
<table class="constraints">
|
<table class="constraints">
|
||||||
<xsl:apply-templates />
|
<xsl:apply-templates />
|
||||||
<!-- Calculated other values -->
|
<!-- Calculated other values -->
|
||||||
<tr>
|
<xsl:if test="../descriptions/description[@file]">
|
||||||
<th>Used by:</th>
|
<tr>
|
||||||
<td>
|
<th>Used by:</th>
|
||||||
<xsl:for-each select="../descriptions/description">
|
<td>
|
||||||
<xsl:if test="position()>1">, </xsl:if>
|
<xsl:for-each select="../descriptions/description">
|
||||||
<xsl:value-of select="@file" />
|
<xsl:if test="position()>1">, </xsl:if>
|
||||||
</xsl:for-each>
|
<xsl:value-of select="@file" />
|
||||||
</td>
|
</xsl:for-each>
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="../aliases/alias">
|
||||||
|
<xsl:apply-templates select="../aliases" mode="constraints" />
|
||||||
|
</xsl:if>
|
||||||
</table>
|
</table>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
<xsl:template match="directive/aliases" mode="constraints">
|
||||||
|
<th>Aliases:</th>
|
||||||
|
<td>
|
||||||
|
<xsl:for-each select="alias">
|
||||||
|
<xsl:if test="position()>1">, </xsl:if>
|
||||||
|
<xsl:value-of select="." />
|
||||||
|
</xsl:for-each>
|
||||||
|
</td>
|
||||||
|
</xsl:template>
|
||||||
<xsl:template match="directive//description">
|
<xsl:template match="directive//description">
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<xsl:copy-of select="div/node()" />
|
<xsl:copy-of select="div/node()" />
|
||||||
@@ -124,4 +148,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
</xsl:stylesheet>
|
</xsl:stylesheet>
|
||||||
|
@@ -14,11 +14,15 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under Development</div>
|
<div id="filing">Filed under Development</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>It makes no sense to adopt a <q>one-size-fits-all</q> approach to
|
<p>HTML Purifier currently natively supports only a subset of HTML's
|
||||||
filtersets: therefore, users must be able to define their own sets of
|
allowed elements, attributes, and behavior; specifically, this subset
|
||||||
<q>allowed</q> elements, as well as switch in-between doctypes of HTML.</p>
|
is the set of elements that are safe for untrusted users to use.
|
||||||
|
However, HTML Purifier is often utilized to ensure standards-compliance
|
||||||
|
from input that is trusted (making it a sort of Tidy substitute),
|
||||||
|
and often users need to define new elements or attributes. The
|
||||||
|
advanced API is oriented specifically for these use-cases.</p>
|
||||||
|
|
||||||
<p>Our goals are to let the user:</p>
|
<p>Our goals are to let the user:</p>
|
||||||
|
|
||||||
@@ -26,32 +30,28 @@ filtersets: therefore, users must be able to define their own sets of
|
|||||||
<dt>Select</dt>
|
<dt>Select</dt>
|
||||||
<dd><ul>
|
<dd><ul>
|
||||||
<li>Doctype</li>
|
<li>Doctype</li>
|
||||||
<li>Filtersets: Rich / Plain / Full ...</li>
|
<!-- <li>Filterset</li> -->
|
||||||
<li>Mode: Lenient / Correctional</li>
|
<li>Elements / Attributes / Modules</li>
|
||||||
<li>Collections (?): Safe / Unsafe</li>
|
<li>Tidy</li>
|
||||||
<li>Modules / Tags / Attributes</li>
|
|
||||||
</ul></dd>
|
</ul></dd>
|
||||||
<dt>Customize</dt>
|
<dt>Customize</dt>
|
||||||
<dd><ul>
|
<dd><ul>
|
||||||
<li>Tags / Attributes / Attribute Types</li>
|
<li>Attributes</li>
|
||||||
<li>Filtersets</li>
|
<li>Elements</li>
|
||||||
<li>Root Node</li>
|
<!--<li>Doctypes</li>-->
|
||||||
</ul></dd>
|
|
||||||
<dt>Create</dt>
|
|
||||||
<dd><ul>
|
|
||||||
<li>Modules / Tags / Attributes / Attribute Types</li>
|
|
||||||
<li>Filtersets</li>
|
|
||||||
<li>Doctype</li>
|
|
||||||
</ul></dd>
|
</ul></dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h2>Select</h2>
|
<h2>Select</h2>
|
||||||
|
|
||||||
|
<p>For basic use, the user will have to specify some basic parameters. This
|
||||||
|
is not strictly necessary, as HTML Purifier's default setting will always
|
||||||
|
output safe code, but is required for standards-compliant output.</p>
|
||||||
|
|
||||||
<h3>Selecting a Doctype</h3>
|
<h3>Selecting a Doctype</h3>
|
||||||
|
|
||||||
<p>By default, users will use a doctype-based, permissive but secure
|
<p>The first thing to select is the <strong>doctype</strong>. This
|
||||||
whitelist. They must define a <strong>doctype</strong>, and this serves
|
is essential for standards-compliant output.</p>
|
||||||
as the first method of determining a filterset.</p>
|
|
||||||
|
|
||||||
<p class="technical">This identifier is based
|
<p class="technical">This identifier is based
|
||||||
on the name the W3C has given to the document type and <em>not</em>
|
on the name the W3C has given to the document type and <em>not</em>
|
||||||
@@ -61,128 +61,153 @@ the DTD identifier.</p>
|
|||||||
|
|
||||||
<pre>$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');</pre>
|
<pre>$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');</pre>
|
||||||
|
|
||||||
<h3>Selecting a Filterset</h3>
|
<p>Due to historical reasons, the default doctype is XHTML 1.0
|
||||||
|
Transitional, however, we really shouldn't be guessing what the user's
|
||||||
|
doctype is. Fortunantely, people who can't be bothered to set this won't
|
||||||
|
be bothered when their pages stop validating.</p>
|
||||||
|
|
||||||
<p>However, selecting this doctype doesn't mean much, because if we
|
<h3>Selecting Elements / Attributes / Modules</h3>
|
||||||
adhered exactly to the definition we would be letting XSS and other
|
|
||||||
nasties through. HTML Purifier must, in its filterset, allow a subset
|
|
||||||
of the doctype, which we shall call a <strong>filterset</strong>.</p>
|
|
||||||
|
|
||||||
<p>By default, HTML Purifier will use the <strong>Rich</strong>
|
<p>HTML Purifier will, by default, allow as many elements and attributes
|
||||||
filterset, which allows as many elements as possible with untrusted
|
as possible. However, a user may decide to roll their own filterset by
|
||||||
sources. Other possible filtersets could be:</p>
|
selecting modules, elements and attributes to allow for their own
|
||||||
|
specific use-case. This can be done using %HTML.Allowed:</p>
|
||||||
|
|
||||||
<dl>
|
<pre>$config->set('HTML', 'Allowed', 'a[href|title],em,p,blockquote');</pre>
|
||||||
<dt>Full</dt>
|
|
||||||
<dd>Allows the full span of elements in the doctype, good if you want
|
|
||||||
HTML Purifier to work as a Tidy substitute but not to strip
|
|
||||||
anything out.</dd>
|
|
||||||
<dt>Plain</dt>
|
|
||||||
<dd>Provides a minimum set of tags for semantic markup of things
|
|
||||||
like blog comments.</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<p>Extension-authors would be able to define custom filtersets for
|
<p class="technical">The directive %HTML.Allowed is a convenience feature
|
||||||
other users to use.</p>
|
that may be fully expressed with the legacy interface.</p>
|
||||||
|
|
||||||
<p>A possible call to select a filterset would be:</p>
|
<p>We currently support another interface from older versions:</p>
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'Filterset', 'Rich');</pre>
|
<pre>$config->set('HTML', 'AllowedElements', 'a,em,p,blockquote');
|
||||||
|
$config->set('HTML', 'AllowedAttributes', 'a.href,a.title');</pre>
|
||||||
|
|
||||||
<h3>Selecting Mode</h3>
|
<p>A user may also choose to allow modules using a specialized
|
||||||
|
directive:</p>
|
||||||
|
|
||||||
<p>Within filtersets, there are various <strong>modes</strong> of operation.
|
<pre>$config->set('HTML', 'AllowedModules', 'Hypertext,Text,Lists');</pre>
|
||||||
These indicate variant behaviors that, while not strictly changing the
|
|
||||||
allowed set of elements and attributes, will definitely affect the output.
|
|
||||||
Currently, we have two modes, which may be used together:</p>
|
|
||||||
|
|
||||||
<dl>
|
<p>But it is not expected that this feature will be widely used.</p>
|
||||||
<dt>Lenient</dt>
|
|
||||||
<dd>Deprecated elements and attributes will be transformed into
|
|
||||||
standards-compliant alternatives when explicitly disallowed. For
|
|
||||||
example, in the XHTML 1.0 Strict doctype, a <code>center</code>
|
|
||||||
tag would be turned into a <code>div</code> with the CSS property
|
|
||||||
<code>text-align:center;</code>, but in XHTML 1.0 Transitional
|
|
||||||
the tag would be preserved. This mode is on by default.</dd>
|
|
||||||
<dt>Correctional</dt>
|
|
||||||
<dd>Deprecated elements and attributes will be transformed into
|
|
||||||
standards-compliant alternatives whenever possible. Referring
|
|
||||||
back to the previous example, the <code>center</code> tag would
|
|
||||||
be transformed in both cases. However, tags without a
|
|
||||||
reasonable standards-compliant alternative will be preserved
|
|
||||||
in their form. This mode is on by default. It may have
|
|
||||||
various levels of operation.</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<p>A possible call to select modes would be:</p>
|
<p class="technical">Module selection will work slightly differently
|
||||||
|
from the other AllowedElements and AllowedAttributes directives by
|
||||||
|
directly modifying the doctype you are operating in, in the spirit of
|
||||||
|
XHTML 1.1's modularization. We stop users from shooting themselves in the
|
||||||
|
foot by mandating the modules in %HTML.CoreModules be used.</p>
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'Mode', array('correctional', 'lenient'));</pre>
|
<p class="technical">Modules are distinguished from regular elements by the
|
||||||
|
case of their first letter. While XML distinguishes between and allows
|
||||||
|
lower and uppercase letters in element names, XHTML uses only lower-case
|
||||||
|
element names for sake of consistency.</p>
|
||||||
|
|
||||||
<p>If modes have extra parameters, a hash might work well:</p>
|
<h3>Selecting Tidy</h3>
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'Mode', array(
|
<p>The name of this segment of functionality is inspired off of Dave
|
||||||
'correctional' => 9, // strongest level
|
Ragget's program HTML Tidy, which purported to help clean up HTML. In
|
||||||
'lenient' => true // this one's just boolean
|
HTML Purifier, Tidy functionality involves turning unsupported and
|
||||||
));</pre>
|
deprecated elements into standards-compliant ones, maintaining
|
||||||
|
backwards compatibility, and enforcing best practices.</p>
|
||||||
|
|
||||||
<p>Modes may possibly be wrapped up with the filterset declaration:</p>
|
<p>This is a complicated feature, and is explained more in depth at
|
||||||
|
<a href="enduser-tidy.html">the Tidy documentation page</a>.</p>
|
||||||
<pre>$config->set('HTML', 'Filterset', 'Rich: correctional, lenient');</pre>
|
|
||||||
|
|
||||||
<p>Further investigation in this field is necessary.</p>
|
|
||||||
|
|
||||||
<h3>Selecting Modules / Tags / Attributes</h3>
|
|
||||||
|
|
||||||
<p>If this cookie cutter approach doesn't appeal to a user, they may
|
|
||||||
decide to roll their own filterset by selecting modules, tags and
|
|
||||||
attributes to allow.</p>
|
|
||||||
|
|
||||||
<p class="technical">This would make use of the same facilities
|
|
||||||
as a filterset author would use, except that it would go under an
|
|
||||||
<q>anonymous</q> filterset that would be auto-selected if any of the
|
|
||||||
relevant module/tag/attribute selection configuration directives were
|
|
||||||
non-null.</p>
|
|
||||||
|
|
||||||
<p>On the highest level, a user will usually be most interested in
|
|
||||||
directly specifying which elements and attributes are desired. For
|
|
||||||
example:</p>
|
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'AllowedElements', 'a,b,em,p,blockquote,code,i');</pre>
|
|
||||||
|
|
||||||
<p>Attribute declarations could be merged into this declaration as such:</p>
|
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'Allowed', 'a[href,title],b,em,p[class],blockquote[cite],code,i');</pre>
|
|
||||||
|
|
||||||
<p>...or be kept separate:</p>
|
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'AllowedAttributes', 'a.href,a.title,p.class,blockquote.cite');</pre>
|
|
||||||
|
|
||||||
<p class="technical">Considering that, internally speaking, as mandated by
|
|
||||||
the XHTML 1.1 Modularization specification, we have organized our
|
|
||||||
elements around modules, considerable gymnastics will be needed to
|
|
||||||
get this sort of functionality working.</p>
|
|
||||||
|
|
||||||
<p>A user may also specify a module to load a class of elements and attributes
|
|
||||||
into their filterest:</p>
|
|
||||||
|
|
||||||
<pre>$config->set('HTML', 'Allowed', 'Hypertext,Core');</pre>
|
|
||||||
|
|
||||||
<p class="fixme">The granularity of these modules is too coarse for
|
|
||||||
the average user (for example, the core module loads everything from
|
|
||||||
the essential <code>p</code> tag to the not-so-safe <code>h1</code>
|
|
||||||
tag). How do we make this still a viable solution?</p>
|
|
||||||
|
|
||||||
|
<!--
|
||||||
<h3>Unified selector</h3>
|
<h3>Unified selector</h3>
|
||||||
|
|
||||||
<p>Because selecting each and every one of these configuration options
|
<p>Because selecting each and every one of these configuration options
|
||||||
is a chore, we may wish to offer a specialized configuration method
|
is a chore, we may wish to offer a specialized configuration method
|
||||||
for selecting a filterset. Possibility:</p>
|
for selecting a filterset. Possibility:</p>
|
||||||
|
|
||||||
<pre>function selectFilter($doctype, $filterset, $mode)</pre>
|
<pre>function selectFilter($doctype, $filterset, $tidy)</pre>
|
||||||
|
|
||||||
<p>...which is simply a light wrapper over the individual configuration
|
<p>...which is simply a light wrapper over the individual configuration
|
||||||
calls. A custom config file format or text format could also be adopted.</p>
|
calls. A custom config file format or text format could also be adopted.</p>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<h2>Customize</h2>
|
||||||
|
|
||||||
|
<p>By reviewing topic posts in the support forum, we determined that
|
||||||
|
there were two primarily demanded customization features people wanted:
|
||||||
|
to add an attribute to an existing element, and to add an element.
|
||||||
|
Thus, we'll want to create convenience functions for these common
|
||||||
|
use-cases.</p>
|
||||||
|
|
||||||
|
<p>Note that the functions described here are only available if
|
||||||
|
a raw copy of <code>HTMLPurifier_HTMLDefinition</code> was retrieved.
|
||||||
|
Furthermore, caching may prevent your changes from immediately
|
||||||
|
being seen: consult <a href="enduser-customize.html">enduser-customize.html</a> on how
|
||||||
|
to work around this.</p>
|
||||||
|
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
|
||||||
|
<p>An attribute is bound to an element by a name and has a specific
|
||||||
|
<code>AttrDef</code> that validates it. The interface is therefore:</p>
|
||||||
|
|
||||||
|
<pre>function addAttribute($element, $attribute, $attribute_def);</pre>
|
||||||
|
|
||||||
|
<p>Example of the functionality in action:</p>
|
||||||
|
|
||||||
|
<pre>$def->addAttribute('a', 'rel', 'Enum#nofollow');</pre>
|
||||||
|
|
||||||
|
<p>The <code>$attribute_def</code> value is flexible,
|
||||||
|
to make things simpler. It can be a literal object or:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<!--<li>Class name: We'll instantiate it for you</li>
|
||||||
|
<li>Function name: We'll create an <code>HTMLPurifier_AttrDef_Anonymous</code>
|
||||||
|
class with that function registered as a callback.</li>-->
|
||||||
|
<li>String attribute type: We'll use <code>HTMLPurifier_AttrTypes</code>
|
||||||
|
to resolve it for you. Any data that follows a hash mark (#) will
|
||||||
|
be used to customize the attribute type: in the example above,
|
||||||
|
we specify which values for Enum to allow.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Elements</h3>
|
||||||
|
|
||||||
|
<p>An element requires certain information as specified by
|
||||||
|
<code>HTMLPurifier_ElementDef</code>. However, not all of it is necessary,
|
||||||
|
the usual things required are:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Attributes</li>
|
||||||
|
<li>Content model/type</li>
|
||||||
|
<li>Registration in a content set</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>This suggests an API like this:</p>
|
||||||
|
|
||||||
|
<pre>function addElement($element, $type, $contents,
|
||||||
|
$attr_collections = array(); $attributes = array());</pre>
|
||||||
|
|
||||||
|
<p>Each parameter explained in depth:</p>
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
<dt><code>$element</code></dt>
|
||||||
|
<dd>Element name, ex. 'label'</dd>
|
||||||
|
<dt><code>$type</code></dt>
|
||||||
|
<dd>Content set to register in, ex. 'Inline' or 'Flow'</dd>
|
||||||
|
<dt><code>$contents</code></dt>
|
||||||
|
<dd>Description of allowed children. This is a merged form of
|
||||||
|
<code>HTMLPurifier_ElementDef</code>'s member variables
|
||||||
|
<code>$content_model</code> and <code>$content_model_type</code>,
|
||||||
|
where the form is <q>Type: Model</q>, ex. 'Optional: Inline'.
|
||||||
|
There are also a number of predefined templates one may use.</dd>
|
||||||
|
<dt><code>$attr_collections</code></dt>
|
||||||
|
<dd>Array (or string if only one) of attribute collection(s) to
|
||||||
|
merge into the attributes array.</dd>
|
||||||
|
<dt><code>$attributes</code></dt>
|
||||||
|
<dd>Array of attribute names to attribute definitions, much like
|
||||||
|
the above-described attribute customization.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<p>A possible usage:</p>
|
||||||
|
|
||||||
|
<pre>$def->addElement('font', 'Inline', 'Optional: Inline', 'Common',
|
||||||
|
array('color' => 'Color'));</pre>
|
||||||
|
|
||||||
|
<p>See <code>HTMLPurifier/HTMLModule.php</code> for details.</p>
|
||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@@ -1,52 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
<meta name="description" content="Discusses code quality issues and places that need to be refactored in HTML Purifier." />
|
|
||||||
<link rel="stylesheet" type="text/css" href="./style.css" />
|
|
||||||
|
|
||||||
<title>Code Quality Issues - HTML Purifier</title>
|
|
||||||
|
|
||||||
</head><body>
|
|
||||||
|
|
||||||
<h1>Code Quality Issues</h1>
|
|
||||||
|
|
||||||
<div id="filing">Filed under Development</div>
|
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
|
||||||
|
|
||||||
<p>Okay, face it. Programmers can get lazy, cut corners, or make mistakes. They
|
|
||||||
also can do quick prototypes, and then forget to rewrite them later. Well,
|
|
||||||
while I can't list mistakes in here, I can list prototype-like segments
|
|
||||||
of code that should be aggressively refactored. This does not list
|
|
||||||
optimization issues, that needs to be done after intense profiling.</p>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
docs/examples/demo.php - ad hoc HTML/PHP soup to the extreme
|
|
||||||
|
|
||||||
AttrDef
|
|
||||||
Class - doesn't support Unicode characters (fringe); uses regular
|
|
||||||
expressions
|
|
||||||
Lang - code duplication; premature optimization
|
|
||||||
Length - easily mistaken for CSSLength
|
|
||||||
URI - multiple regular expressions; missing validation for parts (?)
|
|
||||||
CSS - parser doesn't accept advanced CSS (fringe)
|
|
||||||
Number - constructor interface inconsistent with Integer
|
|
||||||
ConfigSchema - redefinition is a mess
|
|
||||||
Strategy
|
|
||||||
FixNesting - cannot bubble nodes out of structures, duplicated checks
|
|
||||||
for special-case parent node
|
|
||||||
MakeWellFormed - insufficient automatic closing definitions (check HTML
|
|
||||||
spec for optional end tags, also, closing based on type (block/inline)
|
|
||||||
might be efficient).
|
|
||||||
RemoveForeignElements - should be run in parallel with MakeWellFormed
|
|
||||||
URIScheme - needs to have callable generic checks
|
|
||||||
mailto - doesn't validate emails, doesn't validate querystring
|
|
||||||
news - doesn't validate opaque path
|
|
||||||
nntp - doesn't constrain path
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<div id="version">$Id$</div>
|
|
||||||
|
|
||||||
</body></html>
|
|
28
docs/dev-code-quality.txt
Normal file
28
docs/dev-code-quality.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
Code Quality Issues
|
||||||
|
|
||||||
|
Okay, face it. Programmers can get lazy, cut corners, or make mistakes. They
|
||||||
|
also can do quick prototypes, and then forget to rewrite them later. Well,
|
||||||
|
while I can't list mistakes in here, I can list prototype-like segments
|
||||||
|
of code that should be aggressively refactored. This does not list
|
||||||
|
optimization issues, that needs to be done after intense profiling.
|
||||||
|
|
||||||
|
docs/examples/demo.php - ad hoc HTML/PHP soup to the extreme
|
||||||
|
|
||||||
|
AttrDef - a lot of duplication, more generic classes need to be created;
|
||||||
|
a lot of strtolower() calls, no legit casing
|
||||||
|
Class - doesn't support Unicode characters (fringe); uses regular expressions
|
||||||
|
Lang - code duplication; premature optimization
|
||||||
|
Length - easily mistaken for CSSLength
|
||||||
|
URI - multiple regular expressions; missing validation for parts (?)
|
||||||
|
CSS - parser doesn't accept advanced CSS (fringe)
|
||||||
|
Number - constructor interface inconsistent with Integer
|
||||||
|
ConfigSchema - redefinition is a mess
|
||||||
|
Strategy
|
||||||
|
FixNesting - cannot bubble nodes out of structures, duplicated checks
|
||||||
|
for special-case parent node
|
||||||
|
RemoveForeignElements - should be run in parallel with MakeWellFormed
|
||||||
|
URIScheme - needs to have callable generic checks
|
||||||
|
mailto - doesn't validate emails, doesn't validate querystring
|
||||||
|
news - doesn't validate opaque path
|
||||||
|
nntp - doesn't constrain path
|
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under Development</div>
|
<div id="filing">Filed under Development</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>The classes in this library follow a few naming conventions, which may
|
<p>The classes in this library follow a few naming conventions, which may
|
||||||
help you find the correct functionality more quickly. Here they are:</p>
|
help you find the correct functionality more quickly. Here they are:</p>
|
||||||
@@ -79,4 +79,4 @@ help you find the correct functionality more quickly. Here they are:</p>
|
|||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under Development</div>
|
<div id="filing">Filed under Development</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Here are some possible optimization techniques we can apply to code sections if
|
<p>Here are some possible optimization techniques we can apply to code sections if
|
||||||
they turn out to be slow. Be sure not to prematurely optimize: if you get
|
they turn out to be slow. Be sure not to prematurely optimize: if you get
|
||||||
@@ -30,4 +30,4 @@ that itch, put it here!</p>
|
|||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@@ -32,7 +32,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
|
|
||||||
<div id="filing">Filed under Development</div>
|
<div id="filing">Filed under Development</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<h2>Key</h2>
|
<h2>Key</h2>
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><th colspan="2">Unknown</th></tr>
|
<tr><th colspan="2">Unknown</th></tr>
|
||||||
<tr class="danger css1 impl-yes"><td>background-image</td><td>Dangerous, target milestone 1.3</td></tr>
|
<tr class="danger css1 impl-yes"><td>background-image</td><td>Dangerous</td></tr>
|
||||||
<tr class="css1 impl-yes"><td>background-attachment</td><td>ENUM(scroll, fixed),
|
<tr class="css1 impl-yes"><td>background-attachment</td><td>ENUM(scroll, fixed),
|
||||||
Depends on background-image</td></tr>
|
Depends on background-image</td></tr>
|
||||||
<tr class="css1 impl-yes"><td>background-position</td><td>Depends on background-image</td></tr>
|
<tr class="css1 impl-yes"><td>background-position</td><td>Depends on background-image</td></tr>
|
||||||
@@ -151,7 +151,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
will not implement list-item, run-in (Opera only) or table (no IE);
|
will not implement list-item, run-in (Opera only) or table (no IE);
|
||||||
inline-block has incomplete IE6 support and requires -moz-inline-box
|
inline-block has incomplete IE6 support and requires -moz-inline-box
|
||||||
for Mozilla. Unknown target milestone.</td></tr>
|
for Mozilla. Unknown target milestone.</td></tr>
|
||||||
<tr class="css1"><td>height</td><td>Interesting, why use it? Unknown target milestone.</td></tr>
|
<tr class="css1 impl-yes"><td>height</td><td>Interesting, why use it? Unknown target milestone.</td></tr>
|
||||||
<tr class="danger css1 impl-yes"><td>list-style-image</td><td>Dangerous?</td></tr>
|
<tr class="danger css1 impl-yes"><td>list-style-image</td><td>Dangerous?</td></tr>
|
||||||
<tr class="impl-no"><td>max-height</td><td rowspan="4">No IE 5/6</td></tr>
|
<tr class="impl-no"><td>max-height</td><td rowspan="4">No IE 5/6</td></tr>
|
||||||
<tr class="impl-no"><td>min-height</td></tr>
|
<tr class="impl-no"><td>min-height</td></tr>
|
||||||
@@ -168,9 +168,9 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
<tr class="impl-no"><td>quotes</td><td>May be dropped from CSS2, fairly useless for inline context</td></tr>
|
<tr class="impl-no"><td>quotes</td><td>May be dropped from CSS2, fairly useless for inline context</td></tr>
|
||||||
<tr class="impl-no"><td>visibility</td><td>ENUM(visible, hidden, collapse),
|
<tr class="impl-no"><td>visibility</td><td>ENUM(visible, hidden, collapse),
|
||||||
Dangerous</td></tr>
|
Dangerous</td></tr>
|
||||||
<tr class="css1 feature"><td>white-space</td><td>ENUM(normal, pre, nowrap, pre-wrap,
|
<tr class="css1 feature impl-partial"><td>white-space</td><td>ENUM(normal, pre, nowrap, pre-wrap,
|
||||||
pre-line), Spotty implementation:
|
pre-line), Spotty implementation:
|
||||||
pre (no IE 5/6), nowrap (no IE 5),
|
pre (no IE 5/6), <em>nowrap</em> (no IE 5, supported),
|
||||||
pre-wrap (only Opera), pre-line (no support). Fixable? Unknown target milestone.</td></tr>
|
pre-wrap (only Opera), pre-line (no support). Fixable? Unknown target milestone.</td></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
@@ -238,14 +238,14 @@ Mozilla on inside and needs -moz-outline, no IE support.</td></tr>
|
|||||||
<tr><th colspan="3">Questionable</th></tr>
|
<tr><th colspan="3">Questionable</th></tr>
|
||||||
<tr class="impl-no"><td>accesskey</td><td>A</td><td>May interfere with main interface</td></tr>
|
<tr class="impl-no"><td>accesskey</td><td>A</td><td>May interfere with main interface</td></tr>
|
||||||
<tr class="impl-no"><td>tabindex</td><td>A</td><td>May interfere with main interface</td></tr>
|
<tr class="impl-no"><td>tabindex</td><td>A</td><td>May interfere with main interface</td></tr>
|
||||||
<tr><td>target</td><td>A</td><td>Config enabled, only useful for frame layouts, disallowed in strict</td></tr>
|
<tr class="impl-yes"><td>target</td><td>A</td><td>Config enabled, only useful for frame layouts, disallowed in strict</td></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><th colspan="3">Miscellaneous</th></tr>
|
<tr><th colspan="3">Miscellaneous</th></tr>
|
||||||
<tr><td>datetime</td><td>DEL, INS</td><td>No visible effect, ISO format</td></tr>
|
<tr><td>datetime</td><td>DEL, INS</td><td>No visible effect, ISO format</td></tr>
|
||||||
<tr><td>rel</td><td>A</td><td>Largely user-defined: nofollow, tag (see microformats)</td></tr>
|
<tr class="impl-yes"><td>rel</td><td>A</td><td>Largely user-defined: nofollow, tag (see microformats)</td></tr>
|
||||||
<tr><td>rev</td><td>A</td><td>Largely user-defined: vote-*</td></tr>
|
<tr class="impl-yes"><td>rev</td><td>A</td><td>Largely user-defined: vote-*</td></tr>
|
||||||
<tr class="feature"><td>axis</td><td>TD, TH</td><td>W3C only: No browser implementation</td></tr>
|
<tr class="feature"><td>axis</td><td>TD, TH</td><td>W3C only: No browser implementation</td></tr>
|
||||||
<tr class="feature"><td>char</td><td>COL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, TR</td><td>W3C only: No browser implementation</td></tr>
|
<tr class="feature"><td>char</td><td>COL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, TR</td><td>W3C only: No browser implementation</td></tr>
|
||||||
<tr class="feature"><td>headers</td><td>TD, TH</td><td>W3C only: No browser implementation</td></tr>
|
<tr class="feature"><td>headers</td><td>TD, TH</td><td>W3C only: No browser implementation</td></tr>
|
||||||
@@ -262,41 +262,41 @@ Mozilla on inside and needs -moz-outline, no IE support.</td></tr>
|
|||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><th colspan="3">Transform, target milestone 1.4</th></tr>
|
<tr><th colspan="3">Transform</th></tr>
|
||||||
<tr><td rowspan="5">align</td><td>CAPTION</td><td>Near-equiv style 'caption-side', drop left and right</td></tr>
|
<tr class="impl-yes"><td rowspan="5">align</td><td>CAPTION</td><td>'caption-side' for top/bottom, 'text-align' for left/right</td></tr>
|
||||||
<tr><td>IMG</td><td rowspan="2">Margin-left and margin-right = auto or parent div</td></tr>
|
<tr class="impl-yes"><td>IMG</td><td rowspan="3">See specimens/html-align-to-css.html</td></tr>
|
||||||
<tr><td>TABLE</td></tr>
|
<tr class="impl-yes"><td>TABLE</td></tr>
|
||||||
<tr><td>HR</td><td>Near-equivalent style 'text-align' (Works for IE and Opera, but not Firefox). Also try <code>margin-right:auto; margin-left:0;</code> for left or <code>margin-right:0; margin-left:auto;</code> for right (optionally replacing 0 with the original margin for that side)</td></tr>
|
<tr class="impl-yes"><td>HR</td></tr>
|
||||||
<tr class="impl-yes"><td>H1, H2, H3, H4, H5, H6, P</td><td>Equivalent style 'text-align'</td></tr>
|
<tr class="impl-yes"><td>H1, H2, H3, H4, H5, H6, P</td><td>Equivalent style 'text-align'</td></tr>
|
||||||
<tr class="required impl-yes"><td>alt</td><td>IMG</td><td>Required, insert image filename if src is present or default invalid image text</td></tr>
|
<tr class="required impl-yes"><td>alt</td><td>IMG</td><td>Required, insert image filename if src is present or default invalid image text</td></tr>
|
||||||
<tr><td rowspan="3">bgcolor</td><td>TABLE</td><td>Equivalent style 'background-color'</td></tr>
|
<tr class="impl-yes"><td rowspan="3">bgcolor</td><td>TABLE</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr><td>TR</td><td>Equivalent style 'background-color'</td></tr>
|
<tr class="impl-yes"><td>TR</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr><td>TD, TH</td><td>Equivalent style 'background-color'</td></tr>
|
<tr class="impl-yes"><td>TD, TH</td><td>Superset style 'background-color'</td></tr>
|
||||||
<tr><td>border</td><td>IMG</td><td>Near equivalent style 'border-width', as it only applies when link present</td></tr>
|
<tr class="impl-yes"><td>border</td><td>IMG</td><td>Equivalent style <code>border:[number]px solid</code></td></tr>
|
||||||
<tr><td>clear</td><td>BR</td><td>Near-equiv style 'clear', transform 'all' into 'both'</td></tr>
|
<tr class="impl-yes"><td>clear</td><td>BR</td><td>Near-equiv style 'clear', transform 'all' into 'both'</td></tr>
|
||||||
<tr class="impl-no"><td>compact</td><td>DL, OL, UL</td><td>Boolean, needs custom CSS class; rarely used anyway</td></tr>
|
<tr class="impl-no"><td>compact</td><td>DL, OL, UL</td><td>Boolean, needs custom CSS class; rarely used anyway</td></tr>
|
||||||
<tr class="required impl-yes"><td>dir</td><td>BDO</td><td>Required, insert ltr (or configuration value) if none</td></tr>
|
<tr class="required impl-yes"><td>dir</td><td>BDO</td><td>Required, insert ltr (or configuration value) if none</td></tr>
|
||||||
<tr><td>height</td><td>TD, TH</td><td>Near-equiv style 'height', needs px suffix if original was in pixels</td></tr>
|
<tr class="impl-yes"><td>height</td><td>TD, TH</td><td>Near-equiv style 'height', needs px suffix if original was in pixels</td></tr>
|
||||||
<tr><td>hspace</td><td>IMG</td><td>Near-equiv styles 'margin-top' and 'margin-bottom', needs px suffix</td></tr>
|
<tr class="impl-yes"><td>hspace</td><td>IMG</td><td>Near-equiv styles 'margin-top' and 'margin-bottom', needs px suffix</td></tr>
|
||||||
<tr class="impl-yes"><td>lang</td><td>*</td><td>Copy value to xml:lang</td></tr>
|
<tr class="impl-yes"><td>lang</td><td>*</td><td>Copy value to xml:lang</td></tr>
|
||||||
<tr><td rowspan="2">name</td><td>IMG</td><td>Turn into ID</td></tr>
|
<tr class="impl-yes"><td rowspan="2">name</td><td>IMG</td><td>Turn into ID</td></tr>
|
||||||
<tr><td>A</td><td>Turn into ID? (not deprecated, though in which specs?)</td></tr>
|
<tr class="impl-yes"><td>A</td><td>Turn into ID</td></tr>
|
||||||
<tr><td>noshade</td><td>HR</td><td>Boolean, style 'border-style:solid;'</td></tr>
|
<tr class="impl-yes"><td>noshade</td><td>HR</td><td>Boolean, style 'border-style:solid;'</td></tr>
|
||||||
<tr><td>nowrap</td><td>TD, TH</td><td>Boolean, style 'white-space:nowrap;' (not compat with IE5)</td></tr>
|
<tr class="impl-yes"><td>nowrap</td><td>TD, TH</td><td>Boolean, style 'white-space:nowrap;' (not compat with IE5)</td></tr>
|
||||||
<tr><td>size</td><td>HR</td><td>Near-equiv 'width', needs px suffix if original was pixels</td></tr>
|
<tr class="impl-yes"><td>size</td><td>HR</td><td>Near-equiv 'height', needs px suffix if original was pixels</td></tr>
|
||||||
<tr class="required impl-yes"><td>src</td><td>IMG</td><td>Required, insert blank or default img if not set</td></tr>
|
<tr class="required impl-yes"><td>src</td><td>IMG</td><td>Required, insert blank or default img if not set</td></tr>
|
||||||
<tr class="impl-yes"><td>start</td><td>OL</td><td>Poorly supported 'counter-reset', allowed in loose, dropped in strict</td></tr>
|
<tr class="impl-yes"><td>start</td><td>OL</td><td>Poorly supported 'counter-reset', allowed in loose, dropped in strict</td></tr>
|
||||||
<tr><td rowspan="3">type</td><td>LI</td><td rowspan="3">Equivalent style 'list-style-type', different allowed values though. (needs testing)</td></tr>
|
<tr class="impl-yes"><td rowspan="3">type</td><td>LI</td><td rowspan="3">Equivalent style 'list-style-type', different allowed values though. (needs testing)</td></tr>
|
||||||
<tr><td>OL</td></tr>
|
<tr class="impl-yes"><td>OL</td></tr>
|
||||||
<tr><td>UL</td></tr>
|
<tr class="impl-yes"><td>UL</td></tr>
|
||||||
<tr class="impl-yes"><td>value</td><td>LI</td><td>Poorly supported 'counter-reset', allowed in loose, dropped in strict</td></tr>
|
<tr class="impl-yes"><td>value</td><td>LI</td><td>Poorly supported 'counter-reset', allowed in loose, dropped in strict</td></tr>
|
||||||
<tr><td>vspace</td><td>IMG</td><td>Near-equiv styles 'margin-left' and 'margin-right', needs px suffix, see hspace</td></tr>
|
<tr class="impl-yes"><td>vspace</td><td>IMG</td><td>Near-equiv styles 'margin-left' and 'margin-right', needs px suffix, see hspace</td></tr>
|
||||||
<tr><td rowspan="2">width</td><td>HR</td><td rowspan="2">Near-equiv style 'width', needs px suffix if original was pixels</td></tr>
|
<tr class="impl-yes"><td rowspan="2">width</td><td>HR</td><td rowspan="2">Near-equiv style 'width', needs px suffix if original was pixels</td></tr>
|
||||||
<tr><td>TD, TH</td></tr>
|
<tr class="impl-yes"><td>TD, TH</td></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
786
docs/enduser-customize.html
Normal file
786
docs/enduser-customize.html
Normal file
@@ -0,0 +1,786 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="description" content="Tutorial for customizing HTML Purifier's tag and attribute sets." />
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||||
|
|
||||||
|
<title>Customize - HTML Purifier</title>
|
||||||
|
|
||||||
|
</head><body>
|
||||||
|
|
||||||
|
<h1 class="subtitled">Customize!</h1>
|
||||||
|
<div class="subtitle">HTML Purifier is a Swiss-Army Knife</div>
|
||||||
|
|
||||||
|
<div id="filing">Filed under End-User</div>
|
||||||
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
You may have heard of the <a href="dev-advanced-api.html">Advanced API</a>.
|
||||||
|
If you're interested in reading dry prose and boring functional
|
||||||
|
specifications, feel free to click that link to get a no-nonsense overview
|
||||||
|
on the Advanced API. For the rest of us, there's this tutorial. By the time
|
||||||
|
you're finished reading this, you should have a pretty good idea on
|
||||||
|
how to implement custom tags and attributes that HTML Purifier may not have.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Is it necessary?</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Before we even write any code, it is paramount to consider whether or
|
||||||
|
not the code we're writing is necessary or not. HTML Purifier, by default,
|
||||||
|
contains a large set of elements and attributes: large enough so that
|
||||||
|
<em>any</em> element or attribute in XHTML 1.0 (and its HTML variant)
|
||||||
|
that can be safely used by the general public is implemented.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
So what needs to be implemented? (Feel free to skip this section if
|
||||||
|
you know what you want).
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>XHTML 1.0</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
All of the modules listed below are based off of the
|
||||||
|
<a href="http://www.w3.org/TR/2001/REC-xhtml-modularization-20010410/abstract_modules.html#sec_5.2.">modularization of
|
||||||
|
XHTML</a>, which, while technically for XHTML 1.1, is quite a useful
|
||||||
|
resource.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Structure</li>
|
||||||
|
<li>Frames</li>
|
||||||
|
<li>Applets (deprecated)</li>
|
||||||
|
<li>Forms</li>
|
||||||
|
<li>Image maps</li>
|
||||||
|
<li>Objects</li>
|
||||||
|
<li>Frames</li>
|
||||||
|
<li>Events</li>
|
||||||
|
<li>Meta-information</li>
|
||||||
|
<li>Style sheets</li>
|
||||||
|
<li>Link (not hypertext)</li>
|
||||||
|
<li>Base</li>
|
||||||
|
<li>Name</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you don't recognize it, you probably don't need it. But the curious
|
||||||
|
can look all of these modules up in the above-mentioned document. Note
|
||||||
|
that inline scripting comes packaged with HTML Purifier (more on this
|
||||||
|
later).
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>XHTML 1.1</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
We have not implemented the
|
||||||
|
<a href="http://www.w3.org/TR/2001/REC-ruby-20010531/">Ruby module</a>,
|
||||||
|
which defines a set of tags
|
||||||
|
for publishing short annotations for text, used mostly in Japanese
|
||||||
|
and Chinese school texts.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>XHTML 2.0</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="http://www.w3.org/TR/xhtml2/">XHTML 2.0</a> is still a
|
||||||
|
working draft, so any elements introduced in the
|
||||||
|
specification have not been implemented and will not be implemented
|
||||||
|
until we get a recommendation or proposal. Because XHTML 2.0 is
|
||||||
|
an entirely new markup language, implementing rules for it will be
|
||||||
|
no easy task.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>HTML 5</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="http://www.whatwg.org/specs/web-apps/current-work/">HTML 5</a>
|
||||||
|
is a fork of HTML 4.01 by WHATWG, who believed that XHTML 2.0 was headed
|
||||||
|
in the wrong direction. It too is a working draft, and may change
|
||||||
|
drastically before publication, but it should be noted that the
|
||||||
|
<code>canvas</code> tag has been implemented by many browser vendors.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Proprietary</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There are a number of proprietary tags still in the wild. Many of them
|
||||||
|
have been documented in <a href="ref-proprietary-tags.txt">ref-proprietary-tags.txt</a>,
|
||||||
|
but there is currently no implementation for any of them.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Extensions</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There are also a number of other XML languages out there that can
|
||||||
|
be embedded in HTML documents: two of the most popular are MathML and
|
||||||
|
SVG, and I frequently get requests to implement these. But they are
|
||||||
|
expansive, comprehensive specifications, and it would take far too long
|
||||||
|
to implement them <em>correctly</em> (most systems I've seen go as far
|
||||||
|
as whitelisting tags and no further; come on, what about nesting!)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Word of warning: HTML Purifier is currently <em>not</em> namespace
|
||||||
|
aware.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Giving back</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
As you may imagine from the details above (don't be abashed if you didn't
|
||||||
|
read it all: a glance over would have done), there's quite a bit that
|
||||||
|
HTML Purifier doesn't implement. Recent architectural changes have
|
||||||
|
allowed HTML Purifier to implement elements and attributes that are not
|
||||||
|
safe! Don't worry, they won't be activated unless you set %HTML.Trusted
|
||||||
|
to true, but they certainly help out users who need to put, say, forms
|
||||||
|
on their page and don't want to go through the trouble of reading this
|
||||||
|
and implementing it themself.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
So any of the above that you implement for your own application could
|
||||||
|
help out some other poor sap on the other side of the globe. Help us
|
||||||
|
out, and send back code so that it can be hammered into a module and
|
||||||
|
released with the core. Any code would be greatly appreciated!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>And now...</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Enough philosophical talk, time for some code:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
|
||||||
|
$config->set('HTML', 'DefinitionRev', 1);
|
||||||
|
$def =& $config->getHTMLDefinition(true);</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Assuming that HTML Purifier has already been properly loaded (hint:
|
||||||
|
include <code>HTMLPurifier.auto.php</code>), this code will set up
|
||||||
|
the environment that you need to start customizing the HTML definition.
|
||||||
|
What's going on?
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
The first three lines are regular configuration code:
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
%HTML.DefinitionID is set to a unique identifier for your
|
||||||
|
custom HTML definition. This prevents it from clobbering
|
||||||
|
other custom definitions on the same installation.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
%HTML.DefinitionRev is a revision integer of your HTML
|
||||||
|
definition. Because HTML definitions are cached, you'll need
|
||||||
|
to increment this whenever you make a change in order to flush
|
||||||
|
the cache.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
The fourth line retrieves a raw <code>HTMLPurifier_HTMLDefinition</code>
|
||||||
|
object that we will be tweaking. If the parameter was removed, we
|
||||||
|
would be retrieving a fully formed definition object, which is somewhat
|
||||||
|
useless for customization purposes.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Broken backwards-compatibility</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Those of you who have already been twiddling around with the raw
|
||||||
|
HTML definition object, you'll be noticing that you're getting an error
|
||||||
|
when you attempt to retrieve the raw definition object without specifying
|
||||||
|
a DefinitionID. It is vital to caching (see below) that you make a unique
|
||||||
|
name for your customized definition, so make up something right now and
|
||||||
|
things will operate again.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Turn off caching</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
To make development easier, we're going to temporarily turn off
|
||||||
|
definition caching:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
|
||||||
|
$config->set('HTML', 'DefinitionRev', 1);
|
||||||
|
<strong>$config->set('Core', 'DefinitionCache', null); // remove this later!</strong>
|
||||||
|
$def =& $config->getHTMLDefinition(true);</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
A few things should be mentioned about the caching mechanism before
|
||||||
|
we move on. For performance reasons, HTML Purifier caches generated
|
||||||
|
<code>HTMLPurifier_Definition</code> objects in serialized files
|
||||||
|
stored (by default) in <code>library/HTMLPurifier/DefinitionCache/Serializer</code>.
|
||||||
|
A lot of processing is done in order to create these objects, so it
|
||||||
|
makes little sense to repeat the same processing over and over again
|
||||||
|
whenever HTML Purifier is called.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
In order to identify a cache entry, HTML Purifier uses three variables:
|
||||||
|
the library's version number, the value of %HTML.DefinitionRev and
|
||||||
|
a serial of relevant configuration. Whenever any of these changes,
|
||||||
|
a new HTML definition is generated. Notice that there is no way
|
||||||
|
for the definition object to track changes to customizations: here, it
|
||||||
|
is up to you to supply appropriate information to DefinitionID and
|
||||||
|
DefinitionRev.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2 id="addAttribute">Add an attribute</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
For this example, we're going to implement the <code>target</code> attribute found
|
||||||
|
on <code>a</code> elements. To implement an attribute, we have to
|
||||||
|
ask a few questions:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>What element is it found on?</li>
|
||||||
|
<li>What is its name?</li>
|
||||||
|
<li>Is it required or optional?</li>
|
||||||
|
<li>What are valid values for it?</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The first three are easy: the element is <code>a</code>, the attribute
|
||||||
|
is <code>target</code>, and it is not a required attribute. (If it
|
||||||
|
was required, we'd need to append an asterisk to the attribute name,
|
||||||
|
you'll see an example of this in the addElement() example).
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The last question is a little trickier.
|
||||||
|
Lets allow the special values: _blank, _self, _target and _top.
|
||||||
|
The form of this is called an <strong>enumeration</strong>, a list of
|
||||||
|
valid values, although only one can be used at a time. To translate
|
||||||
|
this into code form, we write:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
|
||||||
|
$config->set('HTML', 'DefinitionRev', 1);
|
||||||
|
$config->set('Core', 'DefinitionCache', null); // remove this later!
|
||||||
|
$def =& $config->getHTMLDefinition(true);
|
||||||
|
<strong>$def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');</strong></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <code>Enum#_blank,_self,_target,_top</code> does all the magic.
|
||||||
|
The string is split into two parts, separated by a hash mark (#):
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>The first part is the name of what we call an <code>AttrDef</code></li>
|
||||||
|
<li>The second part is the parameter of the above-mentioned <code>AttrDef</code></li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If that sounds vague and generic, it's because it is! HTML Purifier defines
|
||||||
|
an assortment of different attribute types one can use, and each of these
|
||||||
|
has their own specialized parameter format. Here are some of the more useful
|
||||||
|
ones:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Format</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Enum</th>
|
||||||
|
<td><em>[s:]</em>value1,value2,...</td>
|
||||||
|
<td>
|
||||||
|
Attribute with a number of valid values, one of which may be used. When
|
||||||
|
s: is present, the enumeration is case sensitive.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Bool</th>
|
||||||
|
<td>attribute_name</td>
|
||||||
|
<td>
|
||||||
|
Boolean attribute, with only one valid value: the name
|
||||||
|
of the attribute.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>CDATA</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute of arbitrary text. Can also be referred to as <strong>Text</strong>
|
||||||
|
(the specification makes a semantic distinction between the two).
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies a unique ID
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Pixels</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies an integer pixel length
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Length</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies a pixel or percentage length
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>NMTOKENS</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies a number of name tokens, example: the
|
||||||
|
<code>class</code> attribute
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>URI</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies a URI, example: the <code>href</code>
|
||||||
|
attribute
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Number</th>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
Attribute that specifies an positive integer number
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
For a complete list, consult
|
||||||
|
<a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/AttrTypes.php"><code>library/HTMLPurifier/AttrTypes.php</code></a>;
|
||||||
|
more information on attributes that accept parameters can be found on their
|
||||||
|
respective includes in
|
||||||
|
<a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/AttrDef/"><code>library/HTMLPurifier/AttrDef</code></a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Sometimes, the restrictive list in AttrTypes just doesn't cut it. Don't
|
||||||
|
sweat: you can also use a fully instantiated object as the value. The
|
||||||
|
equivalent, verbose form of the above example is:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
|
||||||
|
$config->set('HTML', 'DefinitionRev', 1);
|
||||||
|
$config->set('Core', 'DefinitionCache', null); // remove this later!
|
||||||
|
$def =& $config->getHTMLDefinition(true);
|
||||||
|
<strong>$def->addAttribute('a', 'target', new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('_blank','_self','_target','_top')
|
||||||
|
));</strong></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Trust me, you'll learn to love the shorthand.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Add an element</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Adding attributes is really small-fry stuff, though, and it was possible
|
||||||
|
to add them (albeit a bit more wordy) prior to 2.0. The real gem of
|
||||||
|
the Advanced API is adding elements. There are five questions to
|
||||||
|
ask when adding a new element:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>What is the element's name?</li>
|
||||||
|
<li>What content set does this element belong to?</li>
|
||||||
|
<li>What are the allowed children of this element?</li>
|
||||||
|
<li>What attributes does the element allow that are general?</li>
|
||||||
|
<li>What attributes does the element allow that are specific to this element?</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
It's a mouthful, and you'll be slightly lost if your not familiar with
|
||||||
|
the HTML specification, so let's explain them step by step.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Content set</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The HTML specification defines two major content sets: Inline
|
||||||
|
and Block. Each of these
|
||||||
|
content sets contain a list of elements: Inline contains things like
|
||||||
|
<code>span</code> and <code>b</code> while Block contains things like
|
||||||
|
<code>div</code> and <code>blockquote</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
These content sets amount to a macro mechanism for HTML definition. Most
|
||||||
|
elements in HTML are organized into one of these two sets, and most
|
||||||
|
elements in HTML allow elements from one of these sets. If we had
|
||||||
|
to write each element verbatim into each other element's allowed
|
||||||
|
children, we would have ridiculously large lists; instead we use
|
||||||
|
content sets to compactify the declaration.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Practically speaking, there are several useful values you can use here:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Content set</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Inline</th>
|
||||||
|
<td>Character level elements, text</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Block</th>
|
||||||
|
<td>Block-like elements, like paragraphs and lists</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><em>false</em></th>
|
||||||
|
<td>
|
||||||
|
Any element that doesn't fit into the mold, for example <code>li</code>
|
||||||
|
or <code>tr</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
By specifying a valid value here, all other elements that use that
|
||||||
|
content set will also allow your element, without you having to do
|
||||||
|
anything. If you specify <em>false</em>, you'll have to register
|
||||||
|
your element manually.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Allowed children</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Allowed children defines the elements that this element can contain.
|
||||||
|
The allowed values may range from none to a complex regexp depending on
|
||||||
|
your element.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you've ever taken a look at the HTML DTD's before, you may have
|
||||||
|
noticed declarations like this:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><!ELEMENT LI - O (%flow;)* -- list item --></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <code>(%flow;)*</code> indicates the allowed children of the
|
||||||
|
<code>li</code> tag: <code>li</code> allows any number of flow
|
||||||
|
elements as its children. In HTML Purifier, we'd write it like
|
||||||
|
<code>Flow</code> (here's where the content sets we were
|
||||||
|
discussing earlier come into play). There are three shorthand content models you
|
||||||
|
can specify:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Content model</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Empty</th>
|
||||||
|
<td>No children allowed, like <code>br</code> or <code>hr</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Inline</th>
|
||||||
|
<td>Any number of inline elements and text, like <code>span</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Flow</th>
|
||||||
|
<td>Any number of inline elements, block elements and text, like <code>div</code></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This covers 90% of all the cases out there, but what about elements that
|
||||||
|
break the mold like <code>ul</code>? This guy requires at least one
|
||||||
|
child, and the only valid children for it are <code>li</code>. The
|
||||||
|
content model is: <code>Required: li</code>. There are two parts: the
|
||||||
|
first type determines what <code>ChildDef</code> will be used to validate
|
||||||
|
content models. The most common values are:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Required</th>
|
||||||
|
<td>Children must be one or more of the valid elements</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Optional</th>
|
||||||
|
<td>Children can be any number of the valid elements</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Custom</th>
|
||||||
|
<td>Children must follow the DTD-style regex</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
You can also implement your own <code>ChildDef</code>: this was done
|
||||||
|
for a few special cases in HTML Purifier such as <code>Chameleon</code>
|
||||||
|
(for <code>ins</code> and <code>del</code>), <code>StrictBlockquote</code>
|
||||||
|
and <code>Table</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The second part specifies either valid elements or a regular expression.
|
||||||
|
Valid elements are separated with horizontal bars (|), i.e.
|
||||||
|
"<code>a | b | c</code>". Use #PCDATA to represent plain text.
|
||||||
|
Regular expressions are based off of DTD's style:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Parentheses () are used for grouping</li>
|
||||||
|
<li>Commas (,) separate elements that should come one after another</li>
|
||||||
|
<li>Horizontal bars (|) indicate one or the other elements should be used</li>
|
||||||
|
<li>Plus signs (+) are used for a one or more match</li>
|
||||||
|
<li>Asterisks (*) are used for a zero or more match</li>
|
||||||
|
<li>Question marks (?) are used for a zero or one match</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
For example, "<code>a, b?, (c | d), e+, f*</code>" means "In this order,
|
||||||
|
one <code>a</code> element, at most one <code>b</code> element,
|
||||||
|
one <code>c</code> or <code>d</code> element (but not both), one or more
|
||||||
|
<code>e</code> elements, and any number of <code>f</code> elements."
|
||||||
|
Regex veterans should be able to jump right in, and those not so savvy
|
||||||
|
can always copy-paste W3C's content model definitions into HTML Purifier
|
||||||
|
and hope for the best.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
A word of warning: while the regex format is extremely flexible on
|
||||||
|
the developer's side, it is
|
||||||
|
quite unforgiving on the user's side. If the user input does not <em>exactly</em>
|
||||||
|
match the specification, the entire contents of the element will
|
||||||
|
be nuked. This is why there is are specific content model types like
|
||||||
|
Optional and Required: while they could be implemented as <code>Custom:
|
||||||
|
(valid | elements)*</code>, the custom classes contain special recovery
|
||||||
|
measures that make sure as much of the user's original content gets
|
||||||
|
through. HTML Purifier's core, as a rule, does not use Custom.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
One final note: you can also use Content Sets inside your valid elements
|
||||||
|
lists or regular expressions. In fact, the three shorthand content models
|
||||||
|
mentioned above are just that: abbreviations:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Content model</th>
|
||||||
|
<th>Implementation</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Inline</th>
|
||||||
|
<td>Optional: Inline | #PCDATA</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Flow</th>
|
||||||
|
<td>Optional: Flow | #PCDATA</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
When the definition is compiled, Inline will be replaced with a
|
||||||
|
horizontal-bar separated list of inline elements. Also, notice that
|
||||||
|
it does not contain text: you have to specify that yourself.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Common attributes</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Congratulations: you have just gotten over the proverbial hump (Allowed
|
||||||
|
children). Common attributes is much simpler, and boils down to
|
||||||
|
one question: does your element have the <code>id</code>, <code>style</code>,
|
||||||
|
<code>class</code>, <code>title</code> and <code>lang</code> attributes?
|
||||||
|
If so, you'll want to specify the <code>Common</code> attribute collection,
|
||||||
|
which contains these five attributes that are found on almost every
|
||||||
|
HTML element in the specification.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There are a few more collections, but they're really edge cases:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Collection</th>
|
||||||
|
<th>Attributes</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>I18N</th>
|
||||||
|
<td><code>lang</code>, possibly <code>xml:lang</code></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Core</th>
|
||||||
|
<td><code>style</code>, <code>class</code>, <code>id</code> and <code>title</code></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Common is a combination of the above-mentioned collections.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you didn't read the <a href="#addAttribute">previous section on
|
||||||
|
adding attributes</a>, read it now. The last parameter is simply
|
||||||
|
array of attribute names to attribute implementations, in the exact
|
||||||
|
same format as <code>addAttribute()</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Putting it all together</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
We're going to implement <code>form</code>. Before we embark, lets
|
||||||
|
grab a reference implementation from over at the
|
||||||
|
<a href="http://www.w3.org/TR/html4/sgml/loosedtd.html">transitional DTD</a>:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><!ELEMENT FORM - - (%flow;)* -(FORM) -- interactive form -->
|
||||||
|
<!ATTLIST FORM
|
||||||
|
%attrs; -- %coreattrs, %i18n, %events --
|
||||||
|
action %URI; #REQUIRED -- server-side form handler --
|
||||||
|
method (GET|POST) GET -- HTTP method used to submit the form--
|
||||||
|
enctype %ContentType; "application/x-www-form-urlencoded"
|
||||||
|
accept %ContentTypes; #IMPLIED -- list of MIME types for file upload --
|
||||||
|
name CDATA #IMPLIED -- name of form for scripting --
|
||||||
|
onsubmit %Script; #IMPLIED -- the form was submitted --
|
||||||
|
onreset %Script; #IMPLIED -- the form was reset --
|
||||||
|
target %FrameTarget; #IMPLIED -- render in this frame --
|
||||||
|
accept-charset %Charsets; #IMPLIED -- list of supported charsets --
|
||||||
|
></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Juicy! With just this, we can answer four of our five questions:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>What is the element's name? <strong>form</strong></li>
|
||||||
|
<li>What content set does this element belong to? <strong>Block</strong>
|
||||||
|
(this needs a little sleuthing, I find the easiest way is to search
|
||||||
|
the DTD for <code>FORM</code> and determine which set it is in.)</li>
|
||||||
|
<li>What are the allowed children of this element? <strong>One
|
||||||
|
or more flow elements, but no nested <code>form</code>s</strong></li>
|
||||||
|
<li>What attributes does the element allow that are general? <strong>Common</strong></li>
|
||||||
|
<li>What attributes does the element allow that are specific to this element? <strong>A whole bunch, see ATTLIST;
|
||||||
|
we're going to the vital ones: <code>action</code>, <code>method</code> and <code>name</code></strong></li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Time for some code:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
|
||||||
|
$config->set('HTML', 'DefinitionRev', 1);
|
||||||
|
$config->set('Core', 'DefinitionCache', null); // remove this later!
|
||||||
|
$def =& $config->getHTMLDefinition(true);
|
||||||
|
$def->addAttribute('a', 'target', new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('_blank','_self','_target','_top')
|
||||||
|
));
|
||||||
|
<strong>$form =& $def->addElement(
|
||||||
|
'form', // name
|
||||||
|
'Block', // content set
|
||||||
|
'Flow', // allowed children
|
||||||
|
'Common', // attribute collection
|
||||||
|
array( // attributes
|
||||||
|
'action*' => 'URI',
|
||||||
|
'method' => 'Enum#get|post',
|
||||||
|
'name' => 'ID'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$form->excludes = array('form' => true);</strong></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Each of the parameters corresponds to one of the questions we asked.
|
||||||
|
Notice that we added an asterisk to the end of the <code>action</code>
|
||||||
|
attribute to indicate that it is required. If someone specifies a
|
||||||
|
<code>form</code> without that attribute, the tag will be axed.
|
||||||
|
Also, the extra line at the end is a special extra declaration that
|
||||||
|
prevents forms from being nested within each other.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
And that's all there is to it! Implementing the rest of the form
|
||||||
|
module is left as an exercise to the user; to see more examples
|
||||||
|
check the <a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/HTMLModule/"><code>library/HTMLPurifier/HTMLModule/</code></a> directory
|
||||||
|
in your local HTML Purifier installation.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>And beyond...</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Perceptive users may have realized that, to a certain extent, we
|
||||||
|
have simply re-implemented the facilities of XML Schema or the
|
||||||
|
Document Type Definition. What you are seeing here, however, is
|
||||||
|
not just an XML Schema or Document Type Definition: it is a fully
|
||||||
|
expressive method of specifying the definition of HTML that is
|
||||||
|
a portable superset of the capabilities of the two above-mentioned schema
|
||||||
|
languages. What makes HTMLDefinition so powerful is the fact that
|
||||||
|
if we don't have an implementation for a content model or an attribute
|
||||||
|
definition, you can supply it yourself by writing a PHP class.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There are many facets of HTMLDefinition beyond the Advanced API I have
|
||||||
|
walked you through today. To find out more about these, you can
|
||||||
|
check out these source files:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/HTMLModule.php"><code>library/HTMLPurifier/HTMLModule.php</code></a></li>
|
||||||
|
<li><a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/ElementDef.php"><code>library/HTMLPurifier/ElementDef.php</code></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div id="version">$Id: enduser-tidy.html 1158 2007-06-18 19:26:29Z Edward $</div>
|
||||||
|
|
||||||
|
</body></html>
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under End-User</div>
|
<div id="filing">Filed under End-User</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Prior to HTML Purifier 1.2.0, this library blithely accepted user input that
|
<p>Prior to HTML Purifier 1.2.0, this library blithely accepted user input that
|
||||||
looked like this:</p>
|
looked like this:</p>
|
||||||
@@ -144,4 +144,4 @@ anchors is beyond me.</p>
|
|||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -8,15 +8,9 @@ to be effective. Things to remember:
|
|||||||
|
|
||||||
1. Character Encoding: see enduser-utf8.html for more info.
|
1. Character Encoding: see enduser-utf8.html for more info.
|
||||||
|
|
||||||
2. Doctype: document pending feature completion
|
2. IDs: see enduser-id.html for more info
|
||||||
Not strictly necessary, actually. More in-depth discussion once we figure
|
|
||||||
out how to get strict loose mode working.
|
|
||||||
|
|
||||||
3. IDs: see enduser-id.html for more info
|
3. URIs: see enduser-uri-filter.html
|
||||||
|
|
||||||
4. Links: document pending feature completion
|
4. CSS: document pending
|
||||||
Rudimentary blacklisting, we should also allow only relative URIs. We
|
|
||||||
need a doc to explain the stuff.
|
|
||||||
|
|
||||||
5. CSS: document pending
|
|
||||||
Explain which CSS styles we blocked and why.
|
Explain which CSS styles we blocked and why.
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under End-User</div>
|
<div id="filing">Filed under End-User</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>HTML Purifier is a very powerful library. But with power comes great
|
<p>HTML Purifier is a very powerful library. But with power comes great
|
||||||
responsibility, in the form of longer execution times. Remember, this
|
responsibility, in the form of longer execution times. Remember, this
|
||||||
@@ -114,4 +114,4 @@ if you decide to do that! Especially if you port HTML Purifier to C++.
|
|||||||
<tt>;-)</tt></p>
|
<tt>;-)</tt></p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
230
docs/enduser-tidy.html
Normal file
230
docs/enduser-tidy.html
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="description" content="Tutorial for tweaking HTML Purifier's Tidy-like behavior." />
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||||
|
|
||||||
|
<title>Tidy - HTML Purifier</title>
|
||||||
|
|
||||||
|
</head><body>
|
||||||
|
|
||||||
|
<h1>Tidy</h1>
|
||||||
|
|
||||||
|
<div id="filing">Filed under Development</div>
|
||||||
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
|
<p>You've probably heard of HTML Tidy, Dave Raggett's little piece
|
||||||
|
of software that cleans up poorly written HTML. Let me say it straight
|
||||||
|
out:</p>
|
||||||
|
|
||||||
|
<p class="emphasis">This ain't HTML Tidy!</p>
|
||||||
|
|
||||||
|
<p>Rather, Tidy stands for a cool set of Tidy-inspired in HTML Purifier
|
||||||
|
that allows users to submit deprecated elements and attributes and get
|
||||||
|
valid strict markup back. For example:</p>
|
||||||
|
|
||||||
|
<pre><center>Centered</center></pre>
|
||||||
|
|
||||||
|
<p>...becomes:</p>
|
||||||
|
|
||||||
|
<pre><div style="text-align:center;">Centered</div></pre>
|
||||||
|
|
||||||
|
<p>...when this particular fix is run on the HTML. This tutorial will give
|
||||||
|
you down the lowdown of what exactly HTML Purifier will do when Tidy
|
||||||
|
is on, and how to fine tune this behavior. Once again, <strong>you do
|
||||||
|
not need Tidy installed on your PHP to use these features!</strong></p>
|
||||||
|
|
||||||
|
<h2>What does it do?</h2>
|
||||||
|
|
||||||
|
<p>Tidy will do several things to your HTML:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Convert deprecated elements and attributes to standards-compliant
|
||||||
|
alternatives</li>
|
||||||
|
<li>Enforce XHTML compatibility guidelines and other best practices</li>
|
||||||
|
<li>Preserve data that would normally be removed as per W3C</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>What are levels?</h2>
|
||||||
|
|
||||||
|
<p>Levels describe how aggressive the Tidy module should be when
|
||||||
|
cleaning up HTML. There are four levels to pick: none, light, medium
|
||||||
|
and heavy. Each of these levels has a well-defined set of behavior
|
||||||
|
associated with it, although it may change depending on your doctype.</p>
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
<dt>light</dt>
|
||||||
|
<dd>This is the <strong>lenient</strong> level. If a tag or attribute
|
||||||
|
is about to be removed because it isn't supported by the
|
||||||
|
doctype, Tidy will step in and change into an alternative that
|
||||||
|
is supported.</dd>
|
||||||
|
<dt>medium</dt>
|
||||||
|
<dd>This is the <strong>correctional</strong> level. At this level,
|
||||||
|
all the functions of light are performed, as well as some extra,
|
||||||
|
non-essential best practices enforcement. Changes made on this
|
||||||
|
level are very benign and are unlikely to cause problems.</dd>
|
||||||
|
<dt>heavy</dt>
|
||||||
|
<dd>This is the <strong>aggressive</strong> level. If a tag or
|
||||||
|
attribute is deprecated, it will be converted into a non-deprecated
|
||||||
|
version, no ifs ands or buts.</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<p>By default, Tidy operates on the <strong>medium</strong> level. You can
|
||||||
|
change the level of cleaning by setting the %HTML.TidyLevel configuration
|
||||||
|
directive:</p>
|
||||||
|
|
||||||
|
<pre>$config->set('HTML', 'TidyLevel', 'heavy'); // burn baby burn!</pre>
|
||||||
|
|
||||||
|
<h2>Is the light level really light?</h2>
|
||||||
|
|
||||||
|
<p>It depends on what doctype you're using. If your documents are HTML
|
||||||
|
4.01 <em>Transitional</em>, HTML Purifier will be lazy
|
||||||
|
and won't clean up your <code>center</code>
|
||||||
|
or <code>font</code> tags. But if you're using HTML 4.01 <em>Strict</em>,
|
||||||
|
HTML Purifier has no choice: it has to convert them, or they will
|
||||||
|
be nuked out of existence. So while light on Transitional will result
|
||||||
|
in little to no changes, light on Strict will still result in quite
|
||||||
|
a lot of fixes.</p>
|
||||||
|
|
||||||
|
<p>This is different behavior from 1.6 or before, where deprecated
|
||||||
|
tags in transitional documents would
|
||||||
|
always be cleaned up regardless. This is also better behavior.</p>
|
||||||
|
|
||||||
|
<h2>My pages look different!</h2>
|
||||||
|
|
||||||
|
<p>HTML Purifier is tasked with converting deprecated tags and
|
||||||
|
attributes to standards-compliant alternatives, which usually
|
||||||
|
need copious amounts of CSS. It's also not foolproof: sometimes
|
||||||
|
things do get lost in the translation. This is why when HTML Purifier
|
||||||
|
can get away with not doing cleaning, it won't; this is why
|
||||||
|
the default value is <strong>medium</strong> and not heavy.</p>
|
||||||
|
|
||||||
|
<p>Fortunately, only a few attributes have problems with the switch
|
||||||
|
over. They are described below:</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead><tr>
|
||||||
|
<th>Element@Attr</th>
|
||||||
|
<th>Changes</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>caption@align</td>
|
||||||
|
<td>Firefox supports stuffing the caption on the
|
||||||
|
left and right side of the table, a feature that
|
||||||
|
Internet Explorer, understandably, does not have.
|
||||||
|
When align equals right or left, the text will simply
|
||||||
|
be aligned on the left or right side.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>img@align</td>
|
||||||
|
<td>The implementation for align bottom is good, but not
|
||||||
|
perfect. There are a few pixel differences.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>br@clear</td>
|
||||||
|
<td>Clear both gets a little wonky in Internet Explorer. Haven't
|
||||||
|
really been able to figure out why.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>hr@noshade</td>
|
||||||
|
<td>All browsers implement this slightly differently: we've
|
||||||
|
chosen to make noshade horizontal rules gray.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>There are a few more minor, although irritating, bugs.
|
||||||
|
Some older browsers support deprecated attributes,
|
||||||
|
but not CSS. Transformed elements and attributes will look unstyled
|
||||||
|
to said browsers. Also, CSS precedence is slightly different for
|
||||||
|
inline styles versus presentational markup. In increasing precedence:</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>Presentational attributes</li>
|
||||||
|
<li>External style sheets</li>
|
||||||
|
<li>Inline styling</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>This means that styling that may have been masked by external CSS
|
||||||
|
declarations will start showing up (a good thing, perhaps). Finally,
|
||||||
|
if you've turned off the style attribute, almost all of
|
||||||
|
these transformations will not work. Sorry mates.</p>
|
||||||
|
|
||||||
|
<p>You can review the rendering before and after of these transformations
|
||||||
|
by consulting the <a
|
||||||
|
href="http://htmlpurifier.org/live/smoketests/attrTransform.php">attrTransform.php
|
||||||
|
smoketest</a>.</p>
|
||||||
|
|
||||||
|
<h2>I like the general idea, but the specifics bug me!</h2>
|
||||||
|
|
||||||
|
<p>So you want HTML Purifier to clean up your HTML, but you're not
|
||||||
|
so happy about the br@clear implementation. That's perfectly fine!
|
||||||
|
HTML Purifier will make accomodations:</p>
|
||||||
|
|
||||||
|
<pre>$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
|
||||||
|
$config->set('HTML', 'TidyLevel', 'heavy'); // all changes, minus...
|
||||||
|
<strong>$config->set('HTML', 'TidyRemove', 'br@clear');</strong></pre>
|
||||||
|
|
||||||
|
<p>That third line does the magic, removing the br@clear fix
|
||||||
|
from the module, ensuring that <code><br clear="both" /></code>
|
||||||
|
will pass through unharmed. The reverse is possible too:</p>
|
||||||
|
|
||||||
|
<pre>$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
|
||||||
|
$config->set('HTML', 'TidyLevel', 'none'); // no changes, plus...
|
||||||
|
<strong>$config->set('HTML', 'TidyAdd', 'p@align');</strong></pre>
|
||||||
|
|
||||||
|
<p>In this case, all transformations are shut off, except for the p@align
|
||||||
|
one, which you found handy.</p>
|
||||||
|
|
||||||
|
<p>To find out what the names of fixes you want to turn on or off are,
|
||||||
|
you'll have to consult the source code, specifically the files in
|
||||||
|
<code>HTMLPurifier/HTMLModule/Tidy/</code>. There is, however, a
|
||||||
|
general syntax:</p>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Example</th>
|
||||||
|
<th>Interpretation</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>element</td>
|
||||||
|
<td>font</td>
|
||||||
|
<td>Tag transform for <em>element</em></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>element@attr</td>
|
||||||
|
<td>br@clear</td>
|
||||||
|
<td>Attribute transform for <em>attr</em> on <em>element</em></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>@attr</td>
|
||||||
|
<td>@lang</td>
|
||||||
|
<td>Global attribute transform for <em>attr</em></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>e#content_model_type</td>
|
||||||
|
<td>blockquote#content_model_type</td>
|
||||||
|
<td>Change of child processing implementation for <em>e</em></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>So... what's the lowdown?</h2>
|
||||||
|
|
||||||
|
<p>The lowdown is, quite frankly, HTML Purifier's default settings are
|
||||||
|
probably good enough. The next step is to bump the level up to heavy,
|
||||||
|
and if that still doesn't satisfy your appetite, do some fine tuning.
|
||||||
|
Other than that, don't worry about it: this all works silently and
|
||||||
|
effectively in the background.</p>
|
||||||
|
|
||||||
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
|
</body></html>
|
201
docs/enduser-uri-filter.html
Normal file
201
docs/enduser-uri-filter.html
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="description" content="Tutorial for creating custom URI filters." />
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||||
|
|
||||||
|
<title>URI Filters - HTML Purifier</title>
|
||||||
|
|
||||||
|
</head><body>
|
||||||
|
|
||||||
|
<h1>URI Filters</h1>
|
||||||
|
|
||||||
|
<div id="filing">Filed under End-User</div>
|
||||||
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is a quick and dirty document to get you on your way to writing
|
||||||
|
custom URI filters for your own URL filtering needs. Why would you
|
||||||
|
want to write a URI filter? If you need URIs your users put into
|
||||||
|
HTML to magically change into a different URI, this is
|
||||||
|
exactly what you need!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Creating the class</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Any URI filter you make will be a subclass of <code>HTMLPurifier_URIFilter</code>.
|
||||||
|
The scaffolding is thus:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>class HTMLPurifier_URIFilter_<strong>NameOfFilter</strong> extends HTMLPurifier_URIFilter
|
||||||
|
{
|
||||||
|
var $name = '<strong>NameOfFilter</strong>';
|
||||||
|
function prepare($config) {}
|
||||||
|
function filter(&$uri, $config, &$context) {}
|
||||||
|
}</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Fill in the variable <code>$name</code> with the name of your filter, and
|
||||||
|
take a look at the two methods. <code>prepare()</code> is an initialization
|
||||||
|
method that is called only once, before any filtering has been done of the
|
||||||
|
HTML. Use it to perform any costly setup work that only needs to be done
|
||||||
|
once. <code>filter()</code> is the guts and innards of our filter:
|
||||||
|
it takes the URI and does whatever needs to be done to it.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you've worked with HTML Purifier, you'll recognize the <code>$config</code>
|
||||||
|
and <code>$context</code> parameters. On the other hand, <code>$uri</code>
|
||||||
|
is something unique to this section of the application: it's a
|
||||||
|
<code>HTMLPurifier_URI</code> object. The interface is thus:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>class HTMLPurifier_URI
|
||||||
|
{
|
||||||
|
var $scheme, $userinfo, $host, $port, $path, $query, $fragment;
|
||||||
|
function HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
|
||||||
|
function toString();
|
||||||
|
function copy();
|
||||||
|
function getSchemeObj($config, &$context);
|
||||||
|
function validate($config, &$context);
|
||||||
|
}</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The first three methods are fairly self-explanatory: you have a constructor,
|
||||||
|
a serializer, and a cloner. Generally, you won't be using them when
|
||||||
|
you are manipulating the URI objects themselves.
|
||||||
|
<code>getSchemeObj()</code> is a special purpose method that returns
|
||||||
|
a <code>HTMLPurifier_URIScheme</code> object corresponding to the specific
|
||||||
|
URI at hand. <code>validate()</code> performs general-purpose validation
|
||||||
|
on the internal components of a URI. Once again, you don't need to
|
||||||
|
worry about these: they've already been handled for you.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>URI format</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
As a URIFilter, we're interested in the member variables of the URI object.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="quick"><tbody>
|
||||||
|
<tr><th>Scheme</th> <td>The protocol for identifying (and possibly locating) a resource (http, ftp, https)</td></tr>
|
||||||
|
<tr><th>Userinfo</th> <td>User information such as a username (bob)</td></tr>
|
||||||
|
<tr><th>Host</th> <td>Domain name or IP address of the server (example.com, 127.0.0.1)</td></tr>
|
||||||
|
<tr><th>Port</th> <td>Network port number for the server (80, 12345)</td></tr>
|
||||||
|
<tr><th>Path</th> <td>Data that identifies the resource, possibly hierarchical (/path/to, ed@example.com)</td></tr>
|
||||||
|
<tr><th>Query</th> <td>String of information to be interpreted by the resource (?q=search-term)</td></tr>
|
||||||
|
<tr><th>Fragment</th> <td>Additional information for the resource after retrieval (#bookmark)</td></tr>
|
||||||
|
</tbody></table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Because the URI is presented to us in this form, and not
|
||||||
|
<code>http://bob@example.com:8080/foo.php?q=string#hash</code>, it saves us
|
||||||
|
a lot of trouble in having to parse the URI every time we want to filter
|
||||||
|
it. For the record, the above URI has the following components:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="quick"><tbody>
|
||||||
|
<tr><th>Scheme</th> <td>http</td></tr>
|
||||||
|
<tr><th>Userinfo</th> <td>bob</td></tr>
|
||||||
|
<tr><th>Host</th> <td>example.com</td></tr>
|
||||||
|
<tr><th>Port</th> <td>8080</td></tr>
|
||||||
|
<tr><th>Path</th> <td>/foo.php</td></tr>
|
||||||
|
<tr><th>Query</th> <td>q=string</td></tr>
|
||||||
|
<tr><th>Fragment</th> <td>hash</td></tr>
|
||||||
|
</tbody></table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Note that there is no question mark or octothorpe in the query or
|
||||||
|
fragment: these get removed during parsing.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
With this information, you can get straight to implementing your
|
||||||
|
<code>filter()</code> method. But one more thing...
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Return value: Boolean, not URI</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
You may have noticed that the URI is being passed in by reference.
|
||||||
|
This means that whatever changes you make to it, those changes will
|
||||||
|
be reflected in the URI object the callee had. <strong>Do not
|
||||||
|
return the URI object: it is unnecessary and will cause bugs.</strong>
|
||||||
|
Instead, return a boolean value, true if the filtering was successful,
|
||||||
|
or false if the URI is beyond repair and needs to be axed.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Let's suppose I wanted to write a filter that de-internationalized domain
|
||||||
|
names by converting them to <a href="http://en.wikipedia.org/wiki/Punycode">Punycode</a>.
|
||||||
|
Assuming that <code>punycode_encode($input)</code> converts <code>$input</code> to
|
||||||
|
Punycode and returns <code>false</code> on failure:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>class HTMLPurifier_URIFilter_ConvertIDNToPunycode extends HTMLPurifier_URIFilter
|
||||||
|
{
|
||||||
|
var $name = 'ConvertIDNToPunycode';
|
||||||
|
function filter(&$uri, $config, &$context) {
|
||||||
|
if (is_null($uri->host)) return true;
|
||||||
|
if ($uri->host == utf8_decode($uri->host)) {
|
||||||
|
// is ASCII, abort
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$host = punycode_encode($uri->host);
|
||||||
|
if ($host === false) return false;
|
||||||
|
$uri->host = $host;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Notice I did not <code>return $uri;</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Activating your filter</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Having a filter is all well and good, but you need to tell HTML Purifier
|
||||||
|
to use it. Fortunately, this part's simple:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>$uri =& $config->getDefinition('URI');
|
||||||
|
$uri->addFilter(new HTMLPurifier_URIFilter_<strong>NameOfFilter</strong>());</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you want to be really fancy, you can define a configuration directive
|
||||||
|
for your filter and have HTML Purifier automatically manage whether or
|
||||||
|
not your filter gets loaded or not (this is how internal filters manage
|
||||||
|
things):
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>HTMLPurifier_ConfigSchema::define(
|
||||||
|
'URI', '<strong>NameOfFilter</strong>', false, 'bool',
|
||||||
|
'<strong>What your filter does.</strong>'
|
||||||
|
);
|
||||||
|
$uri =& $config->getDefinition('URI', true);
|
||||||
|
$uri->registerFilter(new HTMLPurifier_URIFilter_<strong>NameOfFilter</strong>());
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Now, your filter will only be called when %URI.<strong>NameOfFilter</strong>
|
||||||
|
is set to true.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Examples</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Check the
|
||||||
|
<a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/URIFilter/">URIFilter</a>
|
||||||
|
directory for more implementation examples, and see <a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/docs/proposal-new-directives.txt">the
|
||||||
|
new directives proposal document</a> for ideas on what could be implemented
|
||||||
|
as a filter.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div id="version">$Id$</div>
|
||||||
|
|
||||||
|
</body></html>
|
@@ -23,7 +23,7 @@ own advice for sake of portability. -->
|
|||||||
|
|
||||||
<div id="filing">Filed under End-User</div>
|
<div id="filing">Filed under End-User</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Character encoding and character sets are not that
|
<p>Character encoding and character sets are not that
|
||||||
difficult to understand, but so many people blithely stumble
|
difficult to understand, but so many people blithely stumble
|
||||||
@@ -231,7 +231,7 @@ of your real encoding.</p>
|
|||||||
why the character encoding should be explicitly stated. When the
|
why the character encoding should be explicitly stated. When the
|
||||||
browser isn't told what the character encoding of a text is, it
|
browser isn't told what the character encoding of a text is, it
|
||||||
has to guess: and sometimes the guess is wrong. Hackers can manipulate
|
has to guess: and sometimes the guess is wrong. Hackers can manipulate
|
||||||
this guess in order to slip XSS pass filters and then fool the
|
this guess in order to slip XSS past filters and then fool the
|
||||||
browser into executing it as active code. A great example of this
|
browser into executing it as active code. A great example of this
|
||||||
is the <a href="http://shiflett.org/archive/177">Google UTF-7
|
is the <a href="http://shiflett.org/archive/177">Google UTF-7
|
||||||
exploit</a>.</p>
|
exploit</a>.</p>
|
||||||
@@ -567,10 +567,11 @@ which may be used by POST, and is required when you want to upload
|
|||||||
files.</p>
|
files.</p>
|
||||||
|
|
||||||
<p>The following is a summarization of notes from
|
<p>The following is a summarization of notes from
|
||||||
<a href="http://ppewww.physics.gla.ac.uk/~flavell/charset/form-i18n.html">
|
<a href="http://web.archive.org/web/20060427015200/ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html">
|
||||||
<code>FORM</code> submission and i18n</a>. That document contains lots
|
<code>FORM</code> submission and i18n</a>. That document contains lots
|
||||||
of useful information, but is written in a rambly manner, so
|
of useful information, but is written in a rambly manner, so
|
||||||
here I try to get right to the point.</p>
|
here I try to get right to the point. (Note: the original has
|
||||||
|
disappeared off the web, so I am linking to the Web Archive copy.)</p>
|
||||||
|
|
||||||
<h4 id="whyutf8-forms-urlencoded"><code>application/x-www-form-urlencoded</code></h4>
|
<h4 id="whyutf8-forms-urlencoded"><code>application/x-www-form-urlencoded</code></h4>
|
||||||
|
|
||||||
@@ -1003,7 +1004,11 @@ when dealing with Unicode text:</p>
|
|||||||
</ul></li>
|
</ul></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>...and always think in bytes, not characters. If you use strpos()
|
<p>Note: this list applies to UTF-8 encoded text only: if you have
|
||||||
|
a string that you are 100% sure is ASCII, be my guest and use
|
||||||
|
<code>strtolower</code> (HTML Purifier uses this function.)</p>
|
||||||
|
|
||||||
|
<p>Regardless, always think in bytes, not characters. If you use strpos()
|
||||||
to find the position of a character, it will be in bytes, but this
|
to find the position of a character, it will be in bytes, but this
|
||||||
usually won't matter since substr() also operates with byte indices!</p>
|
usually won't matter since substr() also operates with byte indices!</p>
|
||||||
|
|
||||||
@@ -1039,4 +1044,4 @@ a more in-depth look into character sets and encodings.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under End-User</div>
|
<div id="filing">Filed under End-User</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Clients like their YouTube videos. It gives them a warm fuzzy feeling when
|
<p>Clients like their YouTube videos. It gives them a warm fuzzy feeling when
|
||||||
they see a neat little embedded video player on their websites that can play
|
they see a neat little embedded video player on their websites that can play
|
||||||
@@ -70,7 +70,7 @@ into your documents. YouTube's code goes like this:</p>
|
|||||||
class="embed-youtube">AyPzM5WK8ys</span></code> your
|
class="embed-youtube">AyPzM5WK8ys</span></code> your
|
||||||
application can reconstruct the full object from this small snippet that
|
application can reconstruct the full object from this small snippet that
|
||||||
passes through HTML Purifier <em>unharmed</em>.
|
passes through HTML Purifier <em>unharmed</em>.
|
||||||
<a href="http://hp.jpsband.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/Filter/YouTube.php">Show me the code!</a></p>
|
<a href="http://htmlpurifier.org/svnroot/htmlpurifier/trunk/library/HTMLPurifier/Filter/YouTube.php">Show me the code!</a></p>
|
||||||
|
|
||||||
<p>And the corresponding usage:</p>
|
<p>And the corresponding usage:</p>
|
||||||
|
|
||||||
@@ -149,4 +149,4 @@ like that, for that matter), send it over and it might get included
|
|||||||
with the core!</p>
|
with the core!</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,14 +1,22 @@
|
|||||||
<?php exit;
|
<?php
|
||||||
|
|
||||||
// This file demonstrates basic usage of HTMLPurifier.
|
// This file demonstrates basic usage of HTMLPurifier.
|
||||||
|
|
||||||
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
|
// replace this with the path to the HTML Purifier library
|
||||||
|
require_once '../../library/HTMLPurifier.auto.php';
|
||||||
|
|
||||||
$purifier = new HTMLPurifier();
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
|
||||||
|
// configuration goes here:
|
||||||
|
$config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding
|
||||||
|
$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional'); // replace with your doctype
|
||||||
|
|
||||||
|
$purifier = new HTMLPurifier($config);
|
||||||
|
|
||||||
|
// untrusted input HTML
|
||||||
$html = '<b>Simple and short';
|
$html = '<b>Simple and short';
|
||||||
|
|
||||||
$pure_html = $purifier->purify($html);
|
$pure_html = $purifier->purify($html);
|
||||||
|
|
||||||
echo $pure_html;
|
echo '<pre>' . htmlspecialchars($pure_html) . '</pre>';
|
||||||
|
|
||||||
?>
|
|
@@ -1,136 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// using _REQUEST because we accept GET and POST requests
|
|
||||||
|
|
||||||
$content = empty($_REQUEST['xml']) ? 'text/html' : 'application/xhtml+xml';
|
|
||||||
header("Content-type:$content;charset=UTF-8");
|
|
||||||
|
|
||||||
// prevent PHP versions with shorttags from barfing
|
|
||||||
echo '<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
';
|
|
||||||
|
|
||||||
function getFormMethod() {
|
|
||||||
return (isset($_REQUEST['post'])) ? 'post' : 'get';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($_REQUEST['strict'])) {
|
|
||||||
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<?php
|
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
||||||
<head>
|
|
||||||
<title>HTML Purifier Live Demo</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>HTML Purifier Live Demo</h1>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require_once '../../library/HTMLPurifier.auto.php';
|
|
||||||
|
|
||||||
if (!empty($_REQUEST['html'])) { // start result
|
|
||||||
|
|
||||||
if (strlen($_REQUEST['html']) > 50000) {
|
|
||||||
?>
|
|
||||||
<p>Request exceeds maximum allowed text size of 50kb.</p>
|
|
||||||
<?php
|
|
||||||
} else { // start main processing
|
|
||||||
|
|
||||||
$html = get_magic_quotes_gpc() ? stripslashes($_REQUEST['html']) : $_REQUEST['html'];
|
|
||||||
|
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
|
||||||
$config->set('Core', 'TidyFormat', !empty($_REQUEST['tidy']));
|
|
||||||
$config->set('HTML', 'Strict', !empty($_REQUEST['strict']));
|
|
||||||
$purifier = new HTMLPurifier($config);
|
|
||||||
$pure_html = $purifier->purify($html);
|
|
||||||
|
|
||||||
?>
|
|
||||||
<p>Here is your purified HTML:</p>
|
|
||||||
<div style="border:5px solid #CCC;margin:0 10%;padding:1em;">
|
|
||||||
<?php if(getFormMethod() == 'get') { ?>
|
|
||||||
<div style="float:right;">
|
|
||||||
<a href="http://validator.w3.org/check?uri=referer"><img
|
|
||||||
src="http://www.w3.org/Icons/valid-xhtml10"
|
|
||||||
alt="Valid XHTML 1.0 Transitional" height="31" width="88" style="border:0;" /></a>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
echo $pure_html;
|
|
||||||
|
|
||||||
?>
|
|
||||||
<div style="clear:both;"></div>
|
|
||||||
</div>
|
|
||||||
<p>Here is the source code of the purified HTML:</p>
|
|
||||||
<pre><?php
|
|
||||||
|
|
||||||
echo htmlspecialchars($pure_html, ENT_COMPAT, 'UTF-8');
|
|
||||||
|
|
||||||
?></pre>
|
|
||||||
<?php
|
|
||||||
if (getFormMethod() == 'post') { // start POST validation notice
|
|
||||||
?>
|
|
||||||
<p>If you would like to validate the code with
|
|
||||||
<a href="http://validator.w3.org/#validate-by-input">W3C's
|
|
||||||
validator</a>, copy and paste the <em>entire</em> demo page's source.</p>
|
|
||||||
<?php
|
|
||||||
} // end POST validation notice
|
|
||||||
|
|
||||||
} // end main processing
|
|
||||||
|
|
||||||
// end result
|
|
||||||
} else {
|
|
||||||
|
|
||||||
?>
|
|
||||||
<p>Welcome to the live demo. Enter some HTML and see how HTML Purifier
|
|
||||||
will filter it.</p>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<form id="filter" action="demo.php<?php
|
|
||||||
echo '?' . getFormMethod();
|
|
||||||
if (isset($_REQUEST['profile']) || isset($_REQUEST['XDEBUG_PROFILE'])) {
|
|
||||||
echo '&XDEBUG_PROFILE=1';
|
|
||||||
} ?>" method="<?php echo getFormMethod(); ?>">
|
|
||||||
<fieldset>
|
|
||||||
<legend>HTML Purifier Input (<?php echo getFormMethod(); ?>)</legend>
|
|
||||||
<textarea name="html" cols="60" rows="15"><?php
|
|
||||||
|
|
||||||
if (isset($html)) {
|
|
||||||
echo htmlspecialchars(
|
|
||||||
HTMLPurifier_Encoder::cleanUTF8($html), ENT_COMPAT, 'UTF-8');
|
|
||||||
}
|
|
||||||
?></textarea>
|
|
||||||
<?php if (getFormMethod() == 'get') { ?>
|
|
||||||
<p><strong>Warning:</strong> GET request method can only hold
|
|
||||||
8129 characters (probably less depending on your browser).
|
|
||||||
If you need to test anything
|
|
||||||
larger than that, try the <a href="demo.php?post">POST form</a>.</p>
|
|
||||||
<?php } ?>
|
|
||||||
<?php if (extension_loaded('tidy')) { ?>
|
|
||||||
<div>Nicely format output with Tidy? <input type="checkbox" value="1"
|
|
||||||
name="tidy"<?php if (!empty($_REQUEST['tidy'])) echo ' checked="checked"'; ?> /></div>
|
|
||||||
<?php } ?>
|
|
||||||
<div>XHTML 1.0 Strict output? <input type="checkbox" value="1"
|
|
||||||
name="strict"<?php if (!empty($_REQUEST['strict'])) echo ' checked="checked"'; ?> /></div>
|
|
||||||
<div>Serve as application/xhtml+xml? (not for IE) <input type="checkbox" value="1"
|
|
||||||
name="xml"<?php if (!empty($_REQUEST['xml'])) echo ' checked="checked"'; ?> /></div>
|
|
||||||
<div>
|
|
||||||
<input type="submit" value="Submit" name="submit" class="button" />
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
<p>Return to <a href="http://hp.jpsband.org/">HTML Purifier's home page</a>.
|
|
||||||
Try the form in <a href="demo.php?get">GET</a> and <a href="demo.php?post">POST</a> request
|
|
||||||
flavors (GET is easy to validate with W3C, but POST allows larger inputs).</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<h1>Documentation</h1>
|
<h1>Documentation</h1>
|
||||||
|
|
||||||
<p><strong><a href="http://hp.jpsband.org/">HTML Purifier</a></strong> has documentation for all types of people.
|
<p><strong><a href="http://htmlpurifier.org/">HTML Purifier</a></strong> has documentation for all types of people.
|
||||||
Here is an index of all of them.</p>
|
Here is an index of all of them.</p>
|
||||||
|
|
||||||
<h2>End-user</h2>
|
<h2>End-user</h2>
|
||||||
@@ -34,6 +34,15 @@ information for casual developers using HTML Purifier.</p>
|
|||||||
<dt><a href="enduser-utf8.html">UTF-8: The Secret of Character Encoding</a></dt>
|
<dt><a href="enduser-utf8.html">UTF-8: The Secret of Character Encoding</a></dt>
|
||||||
<dd>Describes the rationale for using UTF-8, the ramifications otherwise, and how to make the switch.</dd>
|
<dd>Describes the rationale for using UTF-8, the ramifications otherwise, and how to make the switch.</dd>
|
||||||
|
|
||||||
|
<dt><a href="enduser-tidy.html">Tidy</a></dt>
|
||||||
|
<dd>Tutorial for tweaking HTML Purifier's Tidy-like behavior.</dd>
|
||||||
|
|
||||||
|
<dt><a href="enduser-customize.html">Customize</a></dt>
|
||||||
|
<dd>Tutorial for customizing HTML Purifier's tag and attribute sets.</dd>
|
||||||
|
|
||||||
|
<dt><a href="enduser-uri-filter.html">URI Filters</a></dt>
|
||||||
|
<dd>Tutorial for creating custom URI filters.</dd>
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h2>Development</h2>
|
<h2>Development</h2>
|
||||||
@@ -42,9 +51,6 @@ conventions.</p>
|
|||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
|
|
||||||
<dt><a href="dev-code-quality.html">Code Quality Issues</a></dt>
|
|
||||||
<dd>Discusses code quality issues and places that need to be refactored.</dd>
|
|
||||||
|
|
||||||
<dt><a href="dev-progress.html">Implementation Progress</a></dt>
|
<dt><a href="dev-progress.html">Implementation Progress</a></dt>
|
||||||
<dd>Tables detailing HTML element and CSS property implementation coverage.</dd>
|
<dd>Tables detailing HTML element and CSS property implementation coverage.</dd>
|
||||||
|
|
||||||
@@ -105,6 +111,12 @@ the code. They may be upgraded to HTML files or stay as TXT scratchpads.</p>
|
|||||||
<td>Common security issues that may still arise (half-baked).</td>
|
<td>Common security issues that may still arise (half-baked).</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Development</td>
|
||||||
|
<td><a href="enduser-code-quality.txt">Code Quality Issues</a></td>
|
||||||
|
<td>Enumerates code quality issues and places that need to be refactored.</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Proposal</td>
|
<td>Proposal</td>
|
||||||
<td><a href="proposal-filter-levels.txt">Filter levels</a></td>
|
<td><a href="proposal-filter-levels.txt">Filter levels</a></td>
|
||||||
@@ -125,8 +137,8 @@ the code. They may be upgraded to HTML files or stay as TXT scratchpads.</p>
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Reference</td>
|
<td>Reference</td>
|
||||||
<td><a href="ref-loose-vs-strict.txt">Loose vs.Strict</a></td>
|
<td><a href="ref-content-models.txt">Handling Content Model Changes</a></td>
|
||||||
<td>Differences between HTML Strict and Transitional versions.</td>
|
<td>Discusses how to tidy up content model changes using custom ChildDef classes.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
@@ -137,14 +149,8 @@ the code. They may be upgraded to HTML files or stay as TXT scratchpads.</p>
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Reference</td>
|
<td>Reference</td>
|
||||||
<td><a href="ref-strictness.txt">Strictness</a></td>
|
<td><a href="ref-html-modularization.txt">Modularization of HTMLDefinition</a></td>
|
||||||
<td>Short essay on how loose definition isn't really loose.</td>
|
<td>Provides a high-level overview of the concepts behind HTMLModules.</td>
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>Reference</td>
|
|
||||||
<td><a href="ref-xhtml-1.1.txt">XHTML 1.1</a></td>
|
|
||||||
<td>What we'd have to do to support XHTML 1.1.</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
@@ -159,4 +165,4 @@ the code. They may be upgraded to HTML files or stay as TXT scratchpads.</p>
|
|||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under Proposals</div>
|
<div id="filing">Filed under Proposals</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Your website probably has a color-scheme.
|
<p>Your website probably has a color-scheme.
|
||||||
<span style="color:#090; background:#FFF;">Green on white</span>,
|
<span style="color:#090; background:#FFF;">Green on white</span>,
|
||||||
|
@@ -12,29 +12,10 @@ the documentation in ConfigDef for more information on these namespaces.
|
|||||||
|
|
||||||
Since configuration is dependant on context, internal classes require a
|
Since configuration is dependant on context, internal classes require a
|
||||||
configuration object to be passed as a parameter. (They also require a
|
configuration object to be passed as a parameter. (They also require a
|
||||||
Context object).
|
Context object). A majority of classes do not need the config object,
|
||||||
|
but for those who do, it is a lifesaver.
|
||||||
|
|
||||||
In relation to HTMLDefinition and CSSDefinition, there could be a special class
|
Definition objects are complex datatypes influenced by their respective
|
||||||
of directives that influence the *construction* of the Definition object.
|
directive namespaces (HTMLDefinition with HTML and CSSDefinition with CSS).
|
||||||
A theoretical call pattern would look like:
|
If any of these directives is updated, HTML Purifier forces the definition
|
||||||
|
to be regenerated.
|
||||||
1. Client calls Config->getHTMLDefinition()
|
|
||||||
2. Config calls HTMLDefinition->createNew(this)
|
|
||||||
3. HTMLDefinition constructs itself with base configuration
|
|
||||||
4. HTMLDefinition calls Config->get('HTML')
|
|
||||||
5. Config returns array of directives
|
|
||||||
6. HTMLDefinition performs operations and changes specified by directives
|
|
||||||
7. HTMLPurifier returns constructed definition
|
|
||||||
8. Config caches definition so it doesn't have to be generated again
|
|
||||||
9. Config returns definition
|
|
||||||
|
|
||||||
You could also override Config's copy of the definition with your own
|
|
||||||
custom copy, which OVERRIDES all directives. Only the base, vanilla copy
|
|
||||||
is the Singleton, the object actually interfaced with is a operated-upon
|
|
||||||
clone of that object. Also, if an update to the directives would update
|
|
||||||
the definition, you'd have to force reconstruction.
|
|
||||||
|
|
||||||
In practice, the pulling directives from the config object are
|
|
||||||
solely need-based, and the flex points are littered throughout the
|
|
||||||
setup() function. Some sort of refactoring is likely in order. See
|
|
||||||
ref-xhtml-1.1.txt for more info.
|
|
||||||
|
@@ -2,23 +2,16 @@
|
|||||||
Filter Levels
|
Filter Levels
|
||||||
When one size *does not* fit all
|
When one size *does not* fit all
|
||||||
|
|
||||||
The more I think about it, the less sense it makes for maintaining one huge
|
It makes little sense to constrain users to one set of HTML elements and
|
||||||
monolithic HTMLDefinition class. There's simply so much variation that
|
attributes and tell them that they are not allowed to mold this in
|
||||||
could go into this definition: the set of HTML good for blog entries is
|
any fashion. Many users demand to be able to custom-select which elements
|
||||||
definitely too large for HTML that would be allowed in blog comments. Going
|
and attributes they want. This is fine: because HTML Purifier keeps close
|
||||||
from Transitional to Strict requires changes to the definition.
|
track of what elements are safe to use, there is no way for them to
|
||||||
|
accidently allow an XSS-able tag.
|
||||||
|
|
||||||
Allowing users to specify their own whitelists is one step (implemented, btw),
|
However, combing through the HTML spec to make your own whitelist can
|
||||||
but I have doubts on only doing this. Simply put, the typical programmer is too
|
be a daunting task. HTML Purifier ought to offer pre-canned filter levels
|
||||||
lazy to actually go through the trouble of investigating which tags, attributes
|
that amateur users can select based on what they think is their use-case.
|
||||||
and properties to allow. HTMLDefinition makes a big part of what HTMLPurifier
|
|
||||||
is.
|
|
||||||
|
|
||||||
The idea, then, is to setup fundamentally different set of definitions, which
|
|
||||||
can further be customized using simpler configuration options. Alternatively,
|
|
||||||
they could be implemented as configuration profiles, which simply load
|
|
||||||
a set of recommended directives to acheive a desired affect (no simpler
|
|
||||||
config options though).
|
|
||||||
|
|
||||||
Here are some fuzzy levels you could set:
|
Here are some fuzzy levels you could set:
|
||||||
|
|
||||||
@@ -39,13 +32,17 @@ Here are some fuzzy levels you could set:
|
|||||||
|
|
||||||
One final note: when you start axing tags that are more commonly used, you
|
One final note: when you start axing tags that are more commonly used, you
|
||||||
run the risk of accidentally destroying user data, especially if the data
|
run the risk of accidentally destroying user data, especially if the data
|
||||||
is incoming from a WYSIWYG eidtor that hasn't been synced accordingly. This may
|
is incoming from a WYSIWYG editor that hasn't been synced accordingly. This may
|
||||||
make forbidden element to text transformations desirable (for example, images).
|
make forbidden element to text transformations desirable (for example, images).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
== Element Risk Analysis ==
|
== Element Risk Analysis ==
|
||||||
|
|
||||||
|
Although none of the currently supported elements presents a security
|
||||||
|
threat per-say, some can cause problems for page layouts or be
|
||||||
|
extremely complicated.
|
||||||
|
|
||||||
Legend:
|
Legend:
|
||||||
[danger level] - regular tags / uncommon tags ~ deprecated tags
|
[danger level] - regular tags / uncommon tags ~ deprecated tags
|
||||||
[danger level]* - rare tags
|
[danger level]* - rare tags
|
||||||
@@ -114,6 +111,10 @@ Partially presentational - table.cellpadding, table.cellspacing,
|
|||||||
|
|
||||||
== CSS Risk Analysis ==
|
== CSS Risk Analysis ==
|
||||||
|
|
||||||
|
Currently, there is no support for fine-grained "allowed CSS" specification,
|
||||||
|
mainly because I'm lazy, partially because no one has asked for it. However,
|
||||||
|
this will be added eventually.
|
||||||
|
|
||||||
There are certain CSS elements that are extremely useful inline, but then
|
There are certain CSS elements that are extremely useful inline, but then
|
||||||
as you get to more presentation oriented styling it may not always be
|
as you get to more presentation oriented styling it may not always be
|
||||||
appropriate to inline them.
|
appropriate to inline them.
|
||||||
@@ -126,6 +127,7 @@ any CSS properties that are not currently implemented (such as position).
|
|||||||
Dangerous, can go outside container - float
|
Dangerous, can go outside container - float
|
||||||
Easy to abuse - font-size, font-family (font), width
|
Easy to abuse - font-size, font-family (font), width
|
||||||
Colored - background-color (background), border-color (border), color
|
Colored - background-color (background), border-color (border), color
|
||||||
|
(see proposal-colors.html)
|
||||||
Dramatic - border, list-style-position (list-style), margin, padding,
|
Dramatic - border, list-style-position (list-style), margin, padding,
|
||||||
text-align, text-indent, text-transform, vertical-align, line-height
|
text-align, text-indent, text-transform, vertical-align, line-height
|
||||||
|
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
Configuration Ideas
|
Configuration Ideas
|
||||||
|
|
||||||
Here are some theoretical configuration ideas that we could implement some
|
Here are some theoretical configuration ideas that we could implement some
|
||||||
time. Note the naming convention: %Namespace.Directive
|
time. Note the naming convention: %Namespace.Directive. If you want one
|
||||||
|
implemented, give us a ring, and we'll move it up the priority chain.
|
||||||
|
|
||||||
%Attr.RewriteFragments - if there's %Attr.IDPrefix we may want to transparently
|
%Attr.RewriteFragments - if there's %Attr.IDPrefix we may want to transparently
|
||||||
rewrite the URLs we parse too. However, we can only do it when it's a pure
|
rewrite the URLs we parse too. However, we can only do it when it's a pure
|
||||||
@@ -22,8 +23,6 @@ time. Note the naming convention: %Namespace.Directive
|
|||||||
%URI.AddRelNofollow - will add rel="nofollow" to all links, preventing the
|
%URI.AddRelNofollow - will add rel="nofollow" to all links, preventing the
|
||||||
spread of ill-gotten pagerank
|
spread of ill-gotten pagerank
|
||||||
|
|
||||||
%URI.RelativeToAbsolute - transforms all relative URIs to absolute form
|
|
||||||
|
|
||||||
%URI.HostBlacklistRegex - regexes that if matching the host are disallowed
|
%URI.HostBlacklistRegex - regexes that if matching the host are disallowed
|
||||||
%URI.HostWhitelist - domain names that are excluded from the host blacklist
|
%URI.HostWhitelist - domain names that are excluded from the host blacklist
|
||||||
%URI.HostPolicy - determines whether or not its reject all and then whitelist
|
%URI.HostPolicy - determines whether or not its reject all and then whitelist
|
||||||
|
48
docs/ref-content-models.txt
Normal file
48
docs/ref-content-models.txt
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
Handling Content Model Changes
|
||||||
|
|
||||||
|
|
||||||
|
1. Context
|
||||||
|
|
||||||
|
The distinction between Transitional and Strict document types is somewhat
|
||||||
|
of an anomaly in the lineage of XHTML document types (following 1.0, no
|
||||||
|
doctypes do not have flavors: instead, modularization is used to let
|
||||||
|
document authors vary their elements). This transition is usually quite
|
||||||
|
straight-forward, as W3C usually deprecates attributes or elements, which
|
||||||
|
are quite easily handled using tag and attribute transforms.
|
||||||
|
|
||||||
|
However, for two elements, <blockquote>, <body> and <address>, W3C elected
|
||||||
|
to also change the content model. <blockquote> and <body> originally
|
||||||
|
accepted both inline and block elements, but in the strict doctype they
|
||||||
|
only allow block elements. With <address>, the situation is inverted:
|
||||||
|
<p> tags were now forbidden from appearing within this tag.
|
||||||
|
|
||||||
|
|
||||||
|
2. Current situation
|
||||||
|
|
||||||
|
Currently, HTML Purifier treats <blockquote> specially during Tidy mode
|
||||||
|
using a custom ChildDef class StrictBlockquote. StrictBlockquote
|
||||||
|
operates similarly to Required, except that when it encounters an inline
|
||||||
|
element, it will wrap it in a block tag (as specified by
|
||||||
|
%HTML.BlockWrapper, the default is <p>). The naming suggests it can
|
||||||
|
only be used for <blockquote>s, although it may be possible to
|
||||||
|
genericize it to work on other cases of this nature (this would be of
|
||||||
|
little practical application, as no other element in XHTML 1.1 or earlier
|
||||||
|
has a block-only content model).
|
||||||
|
|
||||||
|
Tidy currently contains no custom, lenient implementation for <address>.
|
||||||
|
If one were to be written, it would likely operate on the principle that,
|
||||||
|
when a <p> tag were to be encountered, it would be replaced with a
|
||||||
|
leading and trailing <br /> tag (the contents of <p>, being inline, are
|
||||||
|
not an issue). There is no prior work with this sort of operation.
|
||||||
|
|
||||||
|
|
||||||
|
3. Outside applicability
|
||||||
|
|
||||||
|
There are a number of other elements that contain restrictive content
|
||||||
|
models, such as <ul> or <span> (the latter is restrictive in that it
|
||||||
|
does not allow block elements). In the former case, an errant node
|
||||||
|
is eliminated completely, in the latter case, the text of the node
|
||||||
|
would is preserved (as the parent node does allow PCDATA). Custom
|
||||||
|
content model implementations probably are not the best way of handling
|
||||||
|
these cases, instead, node bubbling should be implemented instead.
|
28
docs/ref-css-length.txt
Normal file
28
docs/ref-css-length.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
CSS Length Reference
|
||||||
|
To bound, or not to bound, that is the question
|
||||||
|
|
||||||
|
It's quite a reasonable request, really, and it's already been implemented
|
||||||
|
for HTML. That is, length bounding. It makes little sense to let users
|
||||||
|
define text blocks that have a font-size of 63,360 inches (that's a mile,
|
||||||
|
by the way) or a width of forty-fold the parent container.
|
||||||
|
|
||||||
|
But it's a little more complicated then that. There are multiple units
|
||||||
|
one can use, and we have to a little unit conversion to get things working.
|
||||||
|
Here's what we have:
|
||||||
|
|
||||||
|
Absolute:
|
||||||
|
1 in ~= 2.54 cm
|
||||||
|
1 cm = 10 mm
|
||||||
|
1 pt = 1/72 in
|
||||||
|
1 pc = 12 pt
|
||||||
|
|
||||||
|
Relative:
|
||||||
|
1 em ~= 10.0667 px
|
||||||
|
1 ex ~= 0.5 em, though Mozilla Firefox says 1 ex = 6px
|
||||||
|
1 px ~= 1 pt
|
||||||
|
|
||||||
|
Watch out: font-sizes can also be nested to get successively larger
|
||||||
|
(although I do not relish having to keep track of context font-sizes,
|
||||||
|
this may be necessary, especially for some of the more advanced features
|
||||||
|
for preventing things like white on white).
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<div id="filing">Filed under Reference</div>
|
<div id="filing">Filed under Reference</div>
|
||||||
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
<div id="index">Return to the <a href="index.html">index</a>.</div>
|
||||||
<div id="home"><a href="http://hp.jpsband.org/">HTML Purifier</a> End-User Documentation</div>
|
<div id="home"><a href="http://htmlpurifier.org/">HTML Purifier</a> End-User Documentation</div>
|
||||||
|
|
||||||
<p>Many thanks to the DevNetwork community for answering questions,
|
<p>Many thanks to the DevNetwork community for answering questions,
|
||||||
theorizing about design, and offering encouragement during
|
theorizing about design, and offering encouragement during
|
||||||
@@ -42,4 +42,4 @@ the development of this library in these forum threads:</p>
|
|||||||
|
|
||||||
<div id="version">$Id$</div>
|
<div id="version">$Id$</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
XHTML 1.1 and HTML Purifier
|
The Modularization of HTMLDefinition in HTML Purifier
|
||||||
|
|
||||||
Todo for XHTML 1.1 support <http://www.w3.org/TR/xhtml11/changes.html>
|
Todo for XHTML 1.1 support <http://www.w3.org/TR/xhtml11/changes.html>
|
||||||
1. Scratch lang entirely in favor of xml:lang
|
1. Support Ruby <http://www.w3.org/TR/2001/REC-ruby-20010531/>
|
||||||
2. Scratch name entirely in favor of id (partially-done)
|
|
||||||
3. Support Ruby <http://www.w3.org/TR/2001/REC-ruby-20010531/>
|
|
||||||
|
|
||||||
HTML Purifier uses the modularization of XHTML
|
HTML Purifier uses the modularization of XHTML
|
||||||
<http://www.w3.org/TR/xhtml-modularization/> to organize the internals
|
<http://www.w3.org/TR/xhtml-modularization/> to organize the internals
|
||||||
@@ -12,25 +10,10 @@ of HTMLDefinition into a more manageable and extensible fashion. Rather
|
|||||||
than have one super-object, HTMLDefinition is split into HTMLModules,
|
than have one super-object, HTMLDefinition is split into HTMLModules,
|
||||||
each of which are responsible for defining elements, their attributes,
|
each of which are responsible for defining elements, their attributes,
|
||||||
and other properties (for a more indepth coverage, see
|
and other properties (for a more indepth coverage, see
|
||||||
/library/HTMLPurifier/HTMLModule.php's docblock comments).
|
/library/HTMLPurifier/HTMLModule.php's docblock comments). These modules
|
||||||
|
are managed by HTMLModuleManager.
|
||||||
|
|
||||||
The modules that W3C defines and we support are:
|
Modules that we don't support but could support are:
|
||||||
|
|
||||||
* 5.1. Attribute Collections (technically not a module
|
|
||||||
* 5.2. Core Modules
|
|
||||||
o 5.2.2. Text Module
|
|
||||||
o 5.2.3. Hypertext Module
|
|
||||||
o 5.2.4. List Module
|
|
||||||
* 5.4. Text Extension Modules
|
|
||||||
o 5.4.1. Presentation Module
|
|
||||||
o 5.4.2. Edit Module
|
|
||||||
o 5.4.3. Bi-directional Text Module
|
|
||||||
* 5.6. Table Modules
|
|
||||||
o 5.6.2. Tables Module
|
|
||||||
* 5.7. Image Module
|
|
||||||
* 5.18. Style Attribute Module
|
|
||||||
|
|
||||||
Modules that we don't support but coul support are:
|
|
||||||
|
|
||||||
* 5.6. Table Modules
|
* 5.6. Table Modules
|
||||||
o 5.6.1. Basic Tables Module [?]
|
o 5.6.1. Basic Tables Module [?]
|
||||||
@@ -38,10 +21,8 @@ Modules that we don't support but coul support are:
|
|||||||
* 5.9. Server-side Image Map Module [?]
|
* 5.9. Server-side Image Map Module [?]
|
||||||
* 5.12. Target Module [?]
|
* 5.12. Target Module [?]
|
||||||
* 5.21. Name Identification Module [deprecated]
|
* 5.21. Name Identification Module [deprecated]
|
||||||
* 5.22. Legacy Module [deprecated]
|
|
||||||
|
|
||||||
These modules will not be implemented due to their dangerousness or
|
These modules would be implemented as "unsafe":
|
||||||
inapplicability as an XHTML fragment:
|
|
||||||
|
|
||||||
* 5.2. Core Modules
|
* 5.2. Core Modules
|
||||||
o 5.2.1. Structure Module
|
o 5.2.1. Structure Module
|
||||||
@@ -64,11 +45,7 @@ of robust tools for handling them (the main problem is that all the
|
|||||||
current parsers are usually PHP 5 only and solely-validating, not
|
current parsers are usually PHP 5 only and solely-validating, not
|
||||||
correcting).
|
correcting).
|
||||||
|
|
||||||
The abstraction of the HTMLDefinition creation process will also
|
This system may be generalized and ported over for CSS.
|
||||||
contribute to a need for a caching system. Cache invalidation would be
|
|
||||||
difficult, but could be done by comparing the HTML and Attr config
|
|
||||||
namespaces with a copy that was packaged along with the serialized
|
|
||||||
HTMLDefinition object.
|
|
||||||
|
|
||||||
== General Use-Case ==
|
== General Use-Case ==
|
||||||
|
|
||||||
@@ -91,7 +68,7 @@ like this:
|
|||||||
<?php
|
<?php
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
$def =& $config->getHTMLDefinition(true); // reference to raw
|
$def =& $config->getHTMLDefinition(true); // reference to raw
|
||||||
unset($def->modules['Hypertext']); // rm ''a'' link
|
$def->addElement('marquee', 'Block', 'Flow', 'Common');
|
||||||
$purifier = new HTMLPurifier($config);
|
$purifier = new HTMLPurifier($config);
|
||||||
$purifier->purify($html); // now the definition is finalized
|
$purifier->purify($html); // now the definition is finalized
|
||||||
?>
|
?>
|
||||||
@@ -184,4 +161,4 @@ Content sets can be altered using HTMLModule->content_sets, an associative
|
|||||||
array of content set names to content set contents. If the content set
|
array of content set names to content set contents. If the content set
|
||||||
already exists, your values are appended on to it (great for, say,
|
already exists, your values are appended on to it (great for, say,
|
||||||
registering the font tag as an inline element), otherwise it is
|
registering the font tag as an inline element), otherwise it is
|
||||||
created. They are substituted into content_model.
|
created. They are substituted into content_model.
|
@@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
Loose versus Strict
|
|
||||||
Changes from one doctype to another
|
|
||||||
|
|
||||||
There are changes. Wow, how insightful. Not everything changed is relevant
|
|
||||||
to HTML Purifier, though, so let's take a look:
|
|
||||||
|
|
||||||
== Major incompatibilities ==
|
|
||||||
|
|
||||||
[done] BLOCKQUOTE changes from 'flow' to 'block'
|
|
||||||
current behavior: inline inner contents should not be nuked, block-ify as necessary
|
|
||||||
[partially-done] U, S, STRIKE cut
|
|
||||||
current behavior: removed completely
|
|
||||||
projected behavior: replace with appropriate inline span + CSS
|
|
||||||
[done] ADDRESS from potpourri to Inline (removes p tags)
|
|
||||||
current behavior: block tags silently dropped
|
|
||||||
ideal behavior: replace tags with something like <br>. (not high priority)
|
|
||||||
|
|
||||||
== Things we can loosen up ==
|
|
||||||
|
|
||||||
Tags DIR, MENU, CENTER, ISINDEX, FONT, BASEFONT? allowed in loose
|
|
||||||
current behavior: transform to strict-valid forms
|
|
||||||
Attributes allowed in loose (see attribute transforms in 'dev-progress.html')
|
|
||||||
current behavior: projected to transform into strict-valid forms
|
|
||||||
|
|
||||||
== Periphery issues ==
|
|
||||||
|
|
||||||
A tag's attribute 'target' (for selecting frames) cut
|
|
||||||
current behavior: not allowed at all
|
|
||||||
projected behavior: use loose doctype if needed, needs valid values
|
|
||||||
[done] OL/LI tag's attribute 'start'/'value' (for renumbering lists) cut
|
|
||||||
current behavior: no substitute, just delete when in strict, allow in loose
|
|
||||||
Attribute 'name' deprecated in favor of 'id'
|
|
||||||
current behavior: dropped silently
|
|
||||||
projected behavior: create proper AttrTransform
|
|
||||||
[done] PRE tag allows SUB/SUP? (strict dtd comment vs syntax, loose disallows)
|
|
||||||
current behavior: disallow as usual
|
|
@@ -18,5 +18,7 @@ HTML Purifier context.
|
|||||||
|
|
||||||
<listing>, monospace pre-variant (extremely rare)
|
<listing>, monospace pre-variant (extremely rare)
|
||||||
<plaintext>, escapes all tags to the end of document
|
<plaintext>, escapes all tags to the end of document
|
||||||
<ruby> and friends, (more research needed, appears to be XHTML 1.1 markup)
|
|
||||||
<xmp>, monospace, replace with pre
|
<xmp>, monospace, replace with pre
|
||||||
|
|
||||||
|
These should be put into their own Tidy module, not loaded by default(?). These
|
||||||
|
all qualify as "lenient" transforms.
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
Is HTML Purifier Strict or Transitional?
|
|
||||||
A little bit of helpful guidance
|
|
||||||
|
|
||||||
Despite the fact that HTML Purifier professes to support both transitional and
|
|
||||||
strict HTML, it rejects a lot of attributes and elements that are actually, indeed,
|
|
||||||
valid. You can investigate progress.html to find out precisely what we
|
|
||||||
are doing to these *deprecated* attributes.
|
|
||||||
|
|
||||||
However, users have found that Strict HTML imposes some quite unreasonable
|
|
||||||
restrictions on certain things. The start and value attributes in ol and
|
|
||||||
li (respectively) perhaps are the most contested. There's is currently no
|
|
||||||
widely supported browser method short of JavaScript that can replace these
|
|
||||||
two deprecated elements. It behooves us to allow these deprecated
|
|
||||||
attributes when the output is transitional.
|
|
||||||
|
|
||||||
Fortunantely, that's the only real bugger case. The others have near-perfect
|
|
||||||
CSS equivalents, and were presentational anyway. However, the other question
|
|
||||||
pops up: should we always convert these to the CSS forms when 1. the spec
|
|
||||||
allows them anyway and 2. older browsers support them better? After all, the
|
|
||||||
whole point about CSS is to seperate styling from content, so inline styling
|
|
||||||
doesn't solve that problem.
|
|
||||||
|
|
||||||
It's an icky question, and we'll have to deal with it as more and more
|
|
||||||
transforms get implemented. As of right now, however, we currently support
|
|
||||||
these loose-only constructs in loose mode:
|
|
||||||
|
|
||||||
- <ul start="1">, <li value="1"> attributes
|
|
||||||
- <u>, <strike>, <s> tags
|
|
||||||
- flow children in <blockquote>
|
|
||||||
- mixed children in <address>
|
|
||||||
|
|
||||||
The changed child definitions as well as the ul.start li.value are the most
|
|
||||||
compelling reasons why loose should be used. We may want offer disabling <u>,
|
|
||||||
<strike> and <s> by themselves. We may also want to offer no pre-emptive
|
|
||||||
deprecated conversions. This all must be unified.
|
|
||||||
|
|
@@ -2,8 +2,23 @@
|
|||||||
Web Hypertext Application Technology Working Group
|
Web Hypertext Application Technology Working Group
|
||||||
WHATWG
|
WHATWG
|
||||||
|
|
||||||
I don't think we need to worry about them. Untrusted users shouldn't be
|
== HTML 5 ==
|
||||||
submitting applications, eh? But if some interesting attribute pops up in
|
|
||||||
their spec, and might be worth supporting, stick it here.
|
|
||||||
|
|
||||||
(none so far, as you can see)
|
URL: http://www.whatwg.org/specs/web-apps/current-work/
|
||||||
|
|
||||||
|
HTML 5 defines a kaboodle of new elements and attributes, as well as
|
||||||
|
some well-defined, "quirks mode" HTML parsing. Although WHATWG professes
|
||||||
|
to be targeted towards web applications, many of their semantic additions
|
||||||
|
would be quite useful in regular documents. Eventually, HTML
|
||||||
|
Purifier will need to audit their lists and figure out what changes need
|
||||||
|
to be made. This process is complicated by the fact that the WHATWG
|
||||||
|
doesn't buy into W3C's modularization of XHTML 1.1: we may need
|
||||||
|
to remodularize HTML 5 (probably done by section name). No sense in
|
||||||
|
committing ourselves till the spec stabilizes, though.
|
||||||
|
|
||||||
|
More immediately speaking though, however, is the well-defined parsing
|
||||||
|
behavior that HTML 5 adds. While I have little interest in writing
|
||||||
|
another DirectLex parser, other parsers like ph5p
|
||||||
|
<http://jero.net/lab/ph5p/> can be adapted to DOMLex to support much more
|
||||||
|
flexible HTML parsing (a cool feature I've seen is how they resolve
|
||||||
|
<b>bold<i>both</b>italic</i>).
|
||||||
|
8
docs/specimens/LICENSE
Normal file
8
docs/specimens/LICENSE
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Licensing of Specimens
|
||||||
|
|
||||||
|
Some files in this directory have different licenses:
|
||||||
|
|
||||||
|
windows-live-mail-desktop-beta.html - donated by laacz, public domain
|
||||||
|
img.png - LGPL, from <http://commons.wikimedia.org/wiki/Image:Pastille_chrome.png>
|
||||||
|
|
||||||
|
All other files are by me, and are licensed under LGPL.
|
165
docs/specimens/html-align-to-css.html
Normal file
165
docs/specimens/html-align-to-css.html
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>HTML align attribute to CSS - HTML Purifier Specimen</title>
|
||||||
|
<style type="text/css">
|
||||||
|
div.container {position:relative;height:110px;}
|
||||||
|
div.container.legend .test {text-align:center;line-height:100px;}
|
||||||
|
div.test {width:100px;height:100px;border:1px solid black;
|
||||||
|
position:absolute;top:10px;}
|
||||||
|
div.test.html {left:10px;}
|
||||||
|
div.test.css {left:140px;}
|
||||||
|
table {background:#F00;}
|
||||||
|
img {border:1px solid #000;}
|
||||||
|
hr {width:50px;}
|
||||||
|
div.segment {width:250px; float:left; margin-top:1em;}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>HTML align attribute to CSS</h1>
|
||||||
|
|
||||||
|
<p>Inspect source for methodology.</p>
|
||||||
|
|
||||||
|
<div class="container legend">
|
||||||
|
<div class="test html">
|
||||||
|
HTML
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
CSS
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="segment">
|
||||||
|
|
||||||
|
<h2>table.align</h2>
|
||||||
|
|
||||||
|
<h3>left</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<table align="left"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<table style="float:left;"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>center</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<table align="center"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<table style="margin-left:auto; margin-right:auto;"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>right</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<table align="right"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<table style="float:right;"><tr><td>O</td></tr></table>a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ################################################################## -->
|
||||||
|
|
||||||
|
<div class="segment">
|
||||||
|
<h2>img.align</h2>
|
||||||
|
<h3>left</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<img src="img.png" align="left">a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<img src="img.png" style="float:left;">a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>right</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<img src="img.png" align="right">a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<img src="img.png" style="float:right;">a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>bottom</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<img src="img.png" align="bottom">a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<img src="img.png" style="vertical-align:baseline;">a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>middle</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<img src="img.png" align="middle">a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<img src="img.png" style="vertical-align:middle;">a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>top</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
a<img src="img.png" align="top">a
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
a<img src="img.png" style="vertical-align:top;">a
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ################################################################## -->
|
||||||
|
|
||||||
|
<div class="segment">
|
||||||
|
|
||||||
|
<h2>hr.align</h2>
|
||||||
|
|
||||||
|
<h3>left</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
<hr align="left" />
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
<hr style="margin-right:auto; margin-left:0; text-align:left;" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>center</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
<hr align="center" />
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
<hr style="margin-right:auto; margin-left:auto; text-align:center;" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>right</h3>
|
||||||
|
<div class="container">
|
||||||
|
<div class="test html">
|
||||||
|
<hr align="right" />
|
||||||
|
</div>
|
||||||
|
<div class="test css">
|
||||||
|
<hr style="margin-right:0; margin-left:auto; text-align:right;" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
docs/specimens/img.png
Normal file
BIN
docs/specimens/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
74
docs/specimens/windows-live-mail-desktop-beta.html
Normal file
74
docs/specimens/windows-live-mail-desktop-beta.html
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||||
|
<HTML ChildAreas="4" xmlns:canvas><HEAD>
|
||||||
|
<META http-equiv=Content-Type content=text/html;charset=windows-1257>
|
||||||
|
<STYLE></STYLE>
|
||||||
|
|
||||||
|
<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
|
||||||
|
<BODY id=MailContainerBody
|
||||||
|
style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 10pt; COLOR: #000000; PADDING-TOP: 15px; FONT-FAMILY: Arial"
|
||||||
|
bgColor=#ff6600 leftMargin=0 background="" topMargin=0
|
||||||
|
name="Compose message area" acc_role="text" CanvasTabStop="false">
|
||||||
|
<DIV
|
||||||
|
style="BORDER-TOP: #dddddd 1px solid; FONT-SIZE: 10pt; WIDTH: 100%; MARGIN-RIGHT: 10px; PADDING-TOP: 5px; BORDER-BOTTOM: #dddddd 1px solid; FONT-FAMILY: Verdana; HEIGHT: 25px; BACKGROUND-COLOR: #ffffff"><NOBR><SPAN
|
||||||
|
title="View a slideshow of the pictures in this e-mail message."
|
||||||
|
style="PADDING-RIGHT: 20px"><A style="COLOR: #0088e4"
|
||||||
|
href="http://g.msn.com/5meen_us/171?path=/photomail/{6fc0065f-ffdd-4ca6-9a4c-cc5a93dc122f}&image=47D7B182CFEFB10!127&imagehi=47D7B182CFEFB10!125&CID=323550092004883216">Play
|
||||||
|
slideshow </A></SPAN><SPAN style="COLOR: #909090"><SPAN>|</SPAN><SPAN
|
||||||
|
style="PADDING-LEFT: 20px"> Download the highest quality version of a picture by
|
||||||
|
clicking the + above it </SPAN></SPAN></NOBR></DIV>
|
||||||
|
<DIV
|
||||||
|
style="PADDING-RIGHT: 5px; PADDING-LEFT: 7px; PADDING-BOTTOM: 2px; WIDTH: 100%; PADDING-TOP: 2px">
|
||||||
|
<OL>
|
||||||
|
<LI><IMG title="Angry smile emoticon"
|
||||||
|
style="FLOAT: none; MARGIN: 0px; POSITION: static" tabIndex=-1
|
||||||
|
alt="Angry smile emoticon" src="cid:49F0C856199E4D688D2D740680733D74@wc"
|
||||||
|
MSNNonUserImageOrEmoticon="true">Un ka <FONT style="BACKGROUND-COLOR: #800000"
|
||||||
|
color=#cc99ff><STRONG>Tev</STRONG></FONT> iet, un ko tu dari?
|
||||||
|
<LI>Aha!</LI></OL>
|
||||||
|
|
||||||
|
<UL>
|
||||||
|
<LI>Buletets
|
||||||
|
<LI>
|
||||||
|
<DIV align=justify><A title=http://laacz.lv/blog/
|
||||||
|
href="http://laacz.lv/blog/">http://laacz.lv/blog/</A> un <A
|
||||||
|
title=http://google.com/ href="http://google.com/">gugle</A></DIV>
|
||||||
|
<LI>Sarakstucitis</LI></UL></DIV><SPAN><SPAN xmlns:canvas="canvas-namespace-id"
|
||||||
|
layoutEmptyTextWellFont="Tahoma"><SPAN
|
||||||
|
style="MARGIN-BOTTOM: 15px; OVERFLOW: visible; HEIGHT: 16px"></SPAN><SPAN
|
||||||
|
style="MARGIN-BOTTOM: 25px; VERTICAL-ALIGN: top; OVERFLOW: visible; MARGIN-RIGHT: 25px; HEIGHT: 234px">
|
||||||
|
<TABLE style="DISPLAY: inline">
|
||||||
|
<TBODY>
|
||||||
|
<TR>
|
||||||
|
|
||||||
|
<TD>
|
||||||
|
<DIV
|
||||||
|
style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; FONT-FAMILY: arial; TEXT-ALIGN: center"><A
|
||||||
|
id=HiresARef
|
||||||
|
title="Click here to view or download a high resolution version of this picture"
|
||||||
|
style="COLOR: #0088e4; TEXT-DECORATION: none"
|
||||||
|
href="http://byfiles.storage.msn.com/x1pMvt0I80jTgT6DuaCpEMbprX3nk3jNv_vjigxV_EYVSMyM_PKgEvDEUtuNhQC-F-23mTTcKyqx6eGaeK2e_wMJ0ikwpDdFntk4SY7pfJUv2g2Ck6R2S2vAA?download">+</A></DIV>
|
||||||
|
<DIV
|
||||||
|
title="Click here to view the full image using the online photo viewer."
|
||||||
|
style="DISPLAY: inline; OVERFLOW: hidden; WIDTH: 140px; HEIGHT: 140px"><A
|
||||||
|
href="http://g.msn.com/5meen_us/171?path=/photomail/{6fc0065f-ffdd-4ca6-9a4c-cc5a93dc122f}&image=47D7B182CFEFB10!127&imagehi=47D7B182CFEFB10!125&CID=323550092004883216"
|
||||||
|
border="0"><IMG
|
||||||
|
style="MARGIN-TOP: 15px; DISPLAY: inline-block; MARGIN-LEFT: 0px"
|
||||||
|
height=109 src="cid:006A71303B80404E9FB6184E55D6A446@wc" width=140
|
||||||
|
border=0></A></DIV></TD></TR>
|
||||||
|
<TR>
|
||||||
|
<TD>
|
||||||
|
<DIV
|
||||||
|
style="FONT-SIZE: 10pt; WIDTH: 140px; FONT-FAMILY: verdana; TEXT-ALIGN: center"><EM><STRONG>This
|
||||||
|
<U>is </U></STRONG><U>tit</U>le</EM> fo<STRONG>r <FONT
|
||||||
|
face="Arial Black">t<FONT color=#800000 size=7>h<U>i</U></FONT>s
|
||||||
|
</FONT>picture</STRONG></DIV></TD></TR></TBODY></TABLE></SPAN></SPAN></SPAN>
|
||||||
|
|
||||||
|
<DIV
|
||||||
|
style="PADDING-RIGHT: 5px; PADDING-LEFT: 7px; PADDING-BOTTOM: 2px; WIDTH: 100%; PADDING-TOP: 2px; HEIGHT: 50px">
|
||||||
|
<DIV> </DIV></DIV>
|
||||||
|
<DIV
|
||||||
|
style="BORDER-TOP: #dddddd 1px solid; FONT-SIZE: 10pt; MARGIN-BOTTOM: 10px; WIDTH: 100%; COLOR: #909090; MARGIN-RIGHT: 10px; PADDING-TOP: 9px; FONT-FAMILY: Verdana; HEIGHT: 42px; BACKGROUND-COLOR: #ffffff"><NOBR><SPAN
|
||||||
|
title="Join Windows Live to share photos using Windows Live Photo E-mail.">Online
|
||||||
|
pictures are available for 30 days. <A style="COLOR: #0088e4"
|
||||||
|
href="http://g.msn.com/5meen_us/175">Get Windows Live Mail desktop to create
|
||||||
|
your own photo e-mails. </A></SPAN></NOBR></DIV></BODY></HTML>
|
@@ -25,6 +25,7 @@ h4 {font-family:sans-serif; font-size:0.9em; font-weight:bold; }
|
|||||||
.aside {margin-left:2em; font-family:sans-serif; font-size:0.9em; }
|
.aside {margin-left:2em; font-family:sans-serif; font-size:0.9em; }
|
||||||
blockquote .label {font-weight:bold; font-size:1em; margin:0 0 .1em;
|
blockquote .label {font-weight:bold; font-size:1em; margin:0 0 .1em;
|
||||||
border-bottom:1px solid #CCC;}
|
border-bottom:1px solid #CCC;}
|
||||||
|
.emphasis {font-weight:bold; text-align:center; font-size:1.3em;}
|
||||||
|
|
||||||
/* A regular table */
|
/* A regular table */
|
||||||
.table {border-collapse:collapse; border-bottom:2px solid #888; margin-left:2em; }
|
.table {border-collapse:collapse; border-bottom:2px solid #888; margin-left:2em; }
|
||||||
@@ -32,6 +33,9 @@ blockquote .label {font-weight:bold; font-size:1em; margin:0 0 .1em;
|
|||||||
.table thead th:first-child {-moz-border-radius-topleft:1em;}
|
.table thead th:first-child {-moz-border-radius-topleft:1em;}
|
||||||
.table tbody td {border-bottom:1px solid #CCC; padding-right:0.6em;padding-left:0.6em;}
|
.table tbody td {border-bottom:1px solid #CCC; padding-right:0.6em;padding-left:0.6em;}
|
||||||
|
|
||||||
|
/* A quick table*/
|
||||||
|
table.quick tbody th {text-align:right; padding-right:1em;}
|
||||||
|
|
||||||
/* Category of the file */
|
/* Category of the file */
|
||||||
#filing {font-weight:bold; font-size:smaller; }
|
#filing {font-weight:bold; font-size:smaller; }
|
||||||
|
|
||||||
@@ -66,3 +70,5 @@ q:after {
|
|||||||
/* Marks off sections that are lacking. */
|
/* Marks off sections that are lacking. */
|
||||||
.fixme {margin-left:2em; }
|
.fixme {margin-left:2em; }
|
||||||
.fixme:before {content:"Fix me: "; font-weight:bold; color:#C00; }
|
.fixme:before {content:"Fix me: "; font-weight:bold; color:#C00; }
|
||||||
|
|
||||||
|
#applicability {margin: 1em 5%; font-style:italic;}
|
||||||
|
@@ -7,4 +7,3 @@
|
|||||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
|
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
|
||||||
require_once 'HTMLPurifier.php';
|
require_once 'HTMLPurifier.php';
|
||||||
|
|
||||||
?>
|
|
@@ -18,4 +18,3 @@ function HTMLPurifier($html, $config = null) {
|
|||||||
return $purifier->purify($html, $config);
|
return $purifier->purify($html, $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
HTML Purifier 1.4.1 - Standards Compliant HTML Filtering
|
HTML Purifier 2.1.1 - Standards Compliant HTML Filtering
|
||||||
Copyright (C) 2006 Edward Z. Yang
|
Copyright (C) 2006 Edward Z. Yang
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
@@ -40,9 +40,12 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// constants are slow, but we'll make one exception
|
||||||
|
define('HTMLPURIFIER_PREFIX', dirname(__FILE__));
|
||||||
|
|
||||||
// almost every class has an undocumented dependency to these, so make sure
|
// almost every class has an undocumented dependency to these, so make sure
|
||||||
// they get included
|
// they get included
|
||||||
require_once 'HTMLPurifier/ConfigSchema.php';
|
require_once 'HTMLPurifier/ConfigSchema.php'; // important
|
||||||
require_once 'HTMLPurifier/Config.php';
|
require_once 'HTMLPurifier/Config.php';
|
||||||
require_once 'HTMLPurifier/Context.php';
|
require_once 'HTMLPurifier/Context.php';
|
||||||
|
|
||||||
@@ -51,6 +54,16 @@ require_once 'HTMLPurifier/Generator.php';
|
|||||||
require_once 'HTMLPurifier/Strategy/Core.php';
|
require_once 'HTMLPurifier/Strategy/Core.php';
|
||||||
require_once 'HTMLPurifier/Encoder.php';
|
require_once 'HTMLPurifier/Encoder.php';
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/ErrorCollector.php';
|
||||||
|
require_once 'HTMLPurifier/LanguageFactory.php';
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Core', 'CollectErrors', false, 'bool', '
|
||||||
|
Whether or not to collect errors found while filtering the document. This
|
||||||
|
is a useful way to give feedback to your users. CURRENTLY NOT IMPLEMENTED.
|
||||||
|
This directive has been available since 2.0.0.
|
||||||
|
');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main library execution class.
|
* Main library execution class.
|
||||||
*
|
*
|
||||||
@@ -64,12 +77,12 @@ require_once 'HTMLPurifier/Encoder.php';
|
|||||||
class HTMLPurifier
|
class HTMLPurifier
|
||||||
{
|
{
|
||||||
|
|
||||||
var $version = '1.4.1';
|
var $version = '2.1.1';
|
||||||
|
|
||||||
var $config;
|
var $config;
|
||||||
var $filters;
|
var $filters;
|
||||||
|
|
||||||
var $lexer, $strategy, $generator;
|
var $strategy, $generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Final HTMLPurifier_Context of last run purification. Might be an array.
|
* Final HTMLPurifier_Context of last run purification. Might be an array.
|
||||||
@@ -89,7 +102,6 @@ class HTMLPurifier
|
|||||||
|
|
||||||
$this->config = HTMLPurifier_Config::create($config);
|
$this->config = HTMLPurifier_Config::create($config);
|
||||||
|
|
||||||
$this->lexer = HTMLPurifier_Lexer::create();
|
|
||||||
$this->strategy = new HTMLPurifier_Strategy_Core();
|
$this->strategy = new HTMLPurifier_Strategy_Core();
|
||||||
$this->generator = new HTMLPurifier_Generator();
|
$this->generator = new HTMLPurifier_Generator();
|
||||||
|
|
||||||
@@ -117,7 +129,27 @@ class HTMLPurifier
|
|||||||
|
|
||||||
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;
|
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;
|
||||||
|
|
||||||
|
// implementation is partially environment dependant, partially
|
||||||
|
// configuration dependant
|
||||||
|
$lexer = HTMLPurifier_Lexer::create($config);
|
||||||
|
|
||||||
$context = new HTMLPurifier_Context();
|
$context = new HTMLPurifier_Context();
|
||||||
|
|
||||||
|
// our friendly neighborhood generator, all primed with configuration too!
|
||||||
|
$this->generator->generateFromTokens(array(), $config, $context);
|
||||||
|
$context->register('Generator', $this->generator);
|
||||||
|
|
||||||
|
// set up global context variables
|
||||||
|
if ($config->get('Core', 'CollectErrors')) {
|
||||||
|
// may get moved out if other facilities use it
|
||||||
|
$language_factory = HTMLPurifier_LanguageFactory::instance();
|
||||||
|
$language = $language_factory->create($config, $context);
|
||||||
|
$context->register('Locale', $language);
|
||||||
|
|
||||||
|
$error_collector = new HTMLPurifier_ErrorCollector($context);
|
||||||
|
$context->register('ErrorCollector', $error_collector);
|
||||||
|
}
|
||||||
|
|
||||||
$html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);
|
$html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);
|
||||||
|
|
||||||
for ($i = 0, $size = count($this->filters); $i < $size; $i++) {
|
for ($i = 0, $size = count($this->filters); $i < $size; $i++) {
|
||||||
@@ -130,7 +162,7 @@ class HTMLPurifier
|
|||||||
// list of tokens
|
// list of tokens
|
||||||
$this->strategy->execute(
|
$this->strategy->execute(
|
||||||
// list of un-purified tokens
|
// list of un-purified tokens
|
||||||
$this->lexer->tokenizeHTML(
|
$lexer->tokenizeHTML(
|
||||||
// un-purified HTML
|
// un-purified HTML
|
||||||
$html, $config, $context
|
$html, $config, $context
|
||||||
),
|
),
|
||||||
@@ -164,7 +196,23 @@ class HTMLPurifier
|
|||||||
return $array_of_html;
|
return $array_of_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton for enforcing just one HTML Purifier in your system
|
||||||
|
*/
|
||||||
|
function &getInstance($prototype = null) {
|
||||||
|
static $htmlpurifier;
|
||||||
|
if (!$htmlpurifier || $prototype) {
|
||||||
|
if (is_a($prototype, 'HTMLPurifier')) {
|
||||||
|
$htmlpurifier = $prototype;
|
||||||
|
} elseif ($prototype) {
|
||||||
|
$htmlpurifier = new HTMLPurifier($prototype);
|
||||||
|
} else {
|
||||||
|
$htmlpurifier = new HTMLPurifier();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $htmlpurifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'HTMLPurifier/AttrTypes.php';
|
require_once 'HTMLPurifier/AttrTypes.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/Lang.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines common attribute collections that modules reference
|
* Defines common attribute collections that modules reference
|
||||||
@@ -12,8 +11,6 @@ class HTMLPurifier_AttrCollections
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Associative array of attribute collections, indexed by name
|
* Associative array of attribute collections, indexed by name
|
||||||
* @note Technically, the composition of these is more complicated,
|
|
||||||
* but we bypass it using our own excludes property
|
|
||||||
*/
|
*/
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
@@ -25,27 +22,29 @@ class HTMLPurifier_AttrCollections
|
|||||||
* @param $modules Hash array of HTMLPurifier_HTMLModule members
|
* @param $modules Hash array of HTMLPurifier_HTMLModule members
|
||||||
*/
|
*/
|
||||||
function HTMLPurifier_AttrCollections($attr_types, $modules) {
|
function HTMLPurifier_AttrCollections($attr_types, $modules) {
|
||||||
$info =& $this->info;
|
|
||||||
// load extensions from the modules
|
// load extensions from the modules
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
foreach ($module->attr_collections as $coll_i => $coll) {
|
foreach ($module->attr_collections as $coll_i => $coll) {
|
||||||
|
if (!isset($this->info[$coll_i])) {
|
||||||
|
$this->info[$coll_i] = array();
|
||||||
|
}
|
||||||
foreach ($coll as $attr_i => $attr) {
|
foreach ($coll as $attr_i => $attr) {
|
||||||
if ($attr_i === 0 && isset($info[$coll_i][$attr_i])) {
|
if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) {
|
||||||
// merge in includes
|
// merge in includes
|
||||||
$info[$coll_i][$attr_i] = array_merge(
|
$this->info[$coll_i][$attr_i] = array_merge(
|
||||||
$info[$coll_i][$attr_i], $attr);
|
$this->info[$coll_i][$attr_i], $attr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$info[$coll_i][$attr_i] = $attr;
|
$this->info[$coll_i][$attr_i] = $attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// perform internal expansions and inclusions
|
// perform internal expansions and inclusions
|
||||||
foreach ($info as $name => $attr) {
|
foreach ($this->info as $name => $attr) {
|
||||||
// merge attribute collections that include others
|
// merge attribute collections that include others
|
||||||
$this->performInclusions($info[$name]);
|
$this->performInclusions($this->info[$name]);
|
||||||
// replace string identifiers with actual attribute objects
|
// replace string identifiers with actual attribute objects
|
||||||
$this->expandIdentifiers($info[$name], $attr_types);
|
$this->expandIdentifiers($this->info[$name], $attr_types);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,16 +56,20 @@ class HTMLPurifier_AttrCollections
|
|||||||
function performInclusions(&$attr) {
|
function performInclusions(&$attr) {
|
||||||
if (!isset($attr[0])) return;
|
if (!isset($attr[0])) return;
|
||||||
$merge = $attr[0];
|
$merge = $attr[0];
|
||||||
|
$seen = array(); // recursion guard
|
||||||
// loop through all the inclusions
|
// loop through all the inclusions
|
||||||
for ($i = 0; isset($merge[$i]); $i++) {
|
for ($i = 0; isset($merge[$i]); $i++) {
|
||||||
|
if (isset($seen[$merge[$i]])) continue;
|
||||||
|
$seen[$merge[$i]] = true;
|
||||||
// foreach attribute of the inclusion, copy it over
|
// foreach attribute of the inclusion, copy it over
|
||||||
|
if (!isset($this->info[$merge[$i]])) continue;
|
||||||
foreach ($this->info[$merge[$i]] as $key => $value) {
|
foreach ($this->info[$merge[$i]] as $key => $value) {
|
||||||
if (isset($attr[$key])) continue; // also catches more inclusions
|
if (isset($attr[$key])) continue; // also catches more inclusions
|
||||||
$attr[$key] = $value;
|
$attr[$key] = $value;
|
||||||
}
|
}
|
||||||
if (isset($info[$merge[$i]][0])) {
|
if (isset($this->info[$merge[$i]][0])) {
|
||||||
// recursion
|
// recursion
|
||||||
$merge = array_merge($merge, isset($info[$merge[$i]][0]));
|
$merge = array_merge($merge, $this->info[$merge[$i]][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($attr[0]);
|
unset($attr[0]);
|
||||||
@@ -79,22 +82,48 @@ class HTMLPurifier_AttrCollections
|
|||||||
* @param $attr_types HTMLPurifier_AttrTypes instance
|
* @param $attr_types HTMLPurifier_AttrTypes instance
|
||||||
*/
|
*/
|
||||||
function expandIdentifiers(&$attr, $attr_types) {
|
function expandIdentifiers(&$attr, $attr_types) {
|
||||||
|
|
||||||
|
// because foreach will process new elements we add, make sure we
|
||||||
|
// skip duplicates
|
||||||
|
$processed = array();
|
||||||
|
|
||||||
foreach ($attr as $def_i => $def) {
|
foreach ($attr as $def_i => $def) {
|
||||||
|
// skip inclusions
|
||||||
if ($def_i === 0) continue;
|
if ($def_i === 0) continue;
|
||||||
if (!is_string($def)) continue;
|
|
||||||
|
if (isset($processed[$def_i])) continue;
|
||||||
|
|
||||||
|
// determine whether or not attribute is required
|
||||||
|
if ($required = (strpos($def_i, '*') !== false)) {
|
||||||
|
// rename the definition
|
||||||
|
unset($attr[$def_i]);
|
||||||
|
$def_i = trim($def_i, '*');
|
||||||
|
$attr[$def_i] = $def;
|
||||||
|
}
|
||||||
|
|
||||||
|
$processed[$def_i] = true;
|
||||||
|
|
||||||
|
// if we've already got a literal object, move on
|
||||||
|
if (is_object($def)) {
|
||||||
|
// preserve previous required
|
||||||
|
$attr[$def_i]->required = ($required || $attr[$def_i]->required);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($def === false) {
|
if ($def === false) {
|
||||||
unset($attr[$def_i]);
|
unset($attr[$def_i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isset($attr_types->info[$def])) {
|
|
||||||
$attr[$def_i] = $attr_types->info[$def];
|
if ($t = $attr_types->get($def)) {
|
||||||
|
$attr[$def_i] = $t;
|
||||||
|
$attr[$def_i]->required = $required;
|
||||||
} else {
|
} else {
|
||||||
trigger_error('Attempted to reference undefined attribute type', E_USER_ERROR);
|
|
||||||
unset($attr[$def_i]);
|
unset($attr[$def_i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -14,11 +14,17 @@ class HTMLPurifier_AttrDef
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells us whether or not an HTML attribute is minimized. Only the
|
* Tells us whether or not an HTML attribute is minimized. Has no
|
||||||
* boolean attribute vapourware would use this.
|
* meaning in other contexts.
|
||||||
*/
|
*/
|
||||||
var $minimized = false;
|
var $minimized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells us whether or not an HTML attribute is required. Has no
|
||||||
|
* meaning in other contexts
|
||||||
|
*/
|
||||||
|
var $required = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and cleans passed string according to a definition.
|
* Validates and cleans passed string according to a definition.
|
||||||
*
|
*
|
||||||
@@ -62,6 +68,19 @@ class HTMLPurifier_AttrDef
|
|||||||
$string = str_replace(array("\r", "\t"), ' ', $string);
|
$string = str_replace(array("\r", "\t"), ' ', $string);
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method for creating this class from a string.
|
||||||
|
* @param $string String construction info
|
||||||
|
* @return Created AttrDef object corresponding to $string
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
function make($string) {
|
||||||
|
// default implementation, return flyweight of this object
|
||||||
|
// if overloaded, it is *necessary* for you to clone the
|
||||||
|
// object (usually by instantiating a new copy) and return that
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -66,4 +66,3 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -84,4 +84,3 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -127,4 +127,3 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -42,4 +42,3 @@ class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -2,43 +2,47 @@
|
|||||||
|
|
||||||
require_once 'HTMLPurifier/AttrDef.php';
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Core', 'ColorKeywords', array(
|
||||||
|
'maroon' => '#800000',
|
||||||
|
'red' => '#FF0000',
|
||||||
|
'orange' => '#FFA500',
|
||||||
|
'yellow' => '#FFFF00',
|
||||||
|
'olive' => '#808000',
|
||||||
|
'purple' => '#800080',
|
||||||
|
'fuchsia' => '#FF00FF',
|
||||||
|
'white' => '#FFFFFF',
|
||||||
|
'lime' => '#00FF00',
|
||||||
|
'green' => '#008000',
|
||||||
|
'navy' => '#000080',
|
||||||
|
'blue' => '#0000FF',
|
||||||
|
'aqua' => '#00FFFF',
|
||||||
|
'teal' => '#008080',
|
||||||
|
'black' => '#000000',
|
||||||
|
'silver' => '#C0C0C0',
|
||||||
|
'gray' => '#808080'
|
||||||
|
), 'hash', '
|
||||||
|
Lookup array of color names to six digit hexadecimal number corresponding
|
||||||
|
to color, with preceding hash mark. Used when parsing colors.
|
||||||
|
This directive has been available since 2.0.0.
|
||||||
|
');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates Color as defined by CSS.
|
* Validates Color as defined by CSS.
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Color keyword lookup table.
|
|
||||||
* @todo Extend it to include all usually allowed colors.
|
|
||||||
*/
|
|
||||||
var $colors = array(
|
|
||||||
'maroon' => '#800000',
|
|
||||||
'red' => '#F00',
|
|
||||||
'orange' => '#FFA500',
|
|
||||||
'yellow' => '#FF0',
|
|
||||||
'olive' => '#808000',
|
|
||||||
'purple' => '#800080',
|
|
||||||
'fuchsia' => '#F0F',
|
|
||||||
'white' => '#FFF',
|
|
||||||
'lime' => '#0F0',
|
|
||||||
'green' => '#008000',
|
|
||||||
'navy' => '#000080',
|
|
||||||
'blue' => '#00F',
|
|
||||||
'aqua' => '#0FF',
|
|
||||||
'teal' => '#008080',
|
|
||||||
'black' => '#000',
|
|
||||||
'silver' => '#C0C0C0',
|
|
||||||
'gray' => '#808080'
|
|
||||||
);
|
|
||||||
|
|
||||||
function validate($color, $config, &$context) {
|
function validate($color, $config, &$context) {
|
||||||
|
|
||||||
|
static $colors = null;
|
||||||
|
if ($colors === null) $colors = $config->get('Core', 'ColorKeywords');
|
||||||
|
|
||||||
$color = trim($color);
|
$color = trim($color);
|
||||||
if (!$color) return false;
|
if (!$color) return false;
|
||||||
|
|
||||||
$lower = strtolower($color);
|
$lower = strtolower($color);
|
||||||
if (isset($this->colors[$lower])) return $this->colors[$lower];
|
if (isset($colors[$lower])) return $colors[$lower];
|
||||||
|
|
||||||
if ($color[0] === '#') {
|
if ($color[0] === '#') {
|
||||||
// hexadecimal handling
|
// hexadecimal handling
|
||||||
@@ -94,4 +98,3 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -35,4 +35,3 @@ class HTMLPurifier_AttrDef_CSS_Composite extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -18,18 +18,6 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* System font keywords.
|
|
||||||
*/
|
|
||||||
var $system_fonts = array(
|
|
||||||
'caption' => true,
|
|
||||||
'icon' => true,
|
|
||||||
'menu' => true,
|
|
||||||
'message-box' => true,
|
|
||||||
'small-caption' => true,
|
|
||||||
'status-bar' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_CSS_Font($config) {
|
function HTMLPurifier_AttrDef_CSS_Font($config) {
|
||||||
$def = $config->getCSSDefinition();
|
$def = $config->getCSSDefinition();
|
||||||
$this->info['font-style'] = $def->info['font-style'];
|
$this->info['font-style'] = $def->info['font-style'];
|
||||||
@@ -42,13 +30,22 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
static $system_fonts = array(
|
||||||
|
'caption' => true,
|
||||||
|
'icon' => true,
|
||||||
|
'menu' => true,
|
||||||
|
'message-box' => true,
|
||||||
|
'small-caption' => true,
|
||||||
|
'status-bar' => true
|
||||||
|
);
|
||||||
|
|
||||||
// regular pre-processing
|
// regular pre-processing
|
||||||
$string = $this->parseCDATA($string);
|
$string = $this->parseCDATA($string);
|
||||||
if ($string === '') return false;
|
if ($string === '') return false;
|
||||||
|
|
||||||
// check if it's one of the keywords
|
// check if it's one of the keywords
|
||||||
$lowercase_string = strtolower($string);
|
$lowercase_string = strtolower($string);
|
||||||
if (isset($this->system_fonts[$lowercase_string])) {
|
if (isset($system_fonts[$lowercase_string])) {
|
||||||
return $lowercase_string;
|
return $lowercase_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,4 +148,3 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -10,19 +10,15 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic font family keywords.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
var $generic_names = array(
|
|
||||||
'serif' => true,
|
|
||||||
'sans-serif' => true,
|
|
||||||
'monospace' => true,
|
|
||||||
'fantasy' => true,
|
|
||||||
'cursive' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
|
static $generic_names = array(
|
||||||
|
'serif' => true,
|
||||||
|
'sans-serif' => true,
|
||||||
|
'monospace' => true,
|
||||||
|
'fantasy' => true,
|
||||||
|
'cursive' => true
|
||||||
|
);
|
||||||
|
|
||||||
$string = $this->parseCDATA($string);
|
$string = $this->parseCDATA($string);
|
||||||
// assume that no font names contain commas in them
|
// assume that no font names contain commas in them
|
||||||
$fonts = explode(',', $string);
|
$fonts = explode(',', $string);
|
||||||
@@ -31,7 +27,7 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
$font = trim($font);
|
$font = trim($font);
|
||||||
if ($font === '') continue;
|
if ($font === '') continue;
|
||||||
// match a generic name
|
// match a generic name
|
||||||
if (isset($this->generic_names[$font])) {
|
if (isset($generic_names[$font])) {
|
||||||
$final .= $font . ', ';
|
$final .= $font . ', ';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -42,19 +38,24 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
$quote = $font[0];
|
$quote = $font[0];
|
||||||
if ($font[$length - 1] !== $quote) continue;
|
if ($font[$length - 1] !== $quote) continue;
|
||||||
$font = substr($font, 1, $length - 2);
|
$font = substr($font, 1, $length - 2);
|
||||||
|
// double-backslash processing is buggy
|
||||||
|
$font = str_replace("\\$quote", $quote, $font); // de-escape quote
|
||||||
|
$font = str_replace("\\\n", "\n", $font); // de-escape newlines
|
||||||
}
|
}
|
||||||
// process font
|
// $font is a pure representation of the font name
|
||||||
|
|
||||||
if (ctype_alnum($font)) {
|
if (ctype_alnum($font)) {
|
||||||
// very simple font, allow it in unharmed
|
// very simple font, allow it in unharmed
|
||||||
$final .= $font . ', ';
|
$final .= $font . ', ';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$nospace = str_replace(array(' ', '.', '!'), '', $font);
|
|
||||||
if (ctype_alnum($nospace)) {
|
// complicated font, requires quoting
|
||||||
// font with spaces in it
|
|
||||||
$final .= "'$font', ";
|
// armor single quotes and new lines
|
||||||
continue;
|
$font = str_replace("'", "\\'", $font);
|
||||||
}
|
$font = str_replace("\n", "\\\n", $font);
|
||||||
|
$final .= "'$font', ";
|
||||||
}
|
}
|
||||||
$final = rtrim($final, ', ');
|
$final = rtrim($final, ', ');
|
||||||
if ($final === '') return false;
|
if ($final === '') return false;
|
||||||
@@ -63,4 +64,3 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -53,4 +53,3 @@ class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -77,4 +77,3 @@ class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -55,4 +55,3 @@ class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -58,4 +58,3 @@ class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -40,4 +40,3 @@ class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -10,23 +10,19 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup table of allowed values.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
var $allowed_values = array(
|
|
||||||
'line-through' => true,
|
|
||||||
'overline' => true,
|
|
||||||
'underline' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
static $allowed_values = array(
|
||||||
|
'line-through' => true,
|
||||||
|
'overline' => true,
|
||||||
|
'underline' => true
|
||||||
|
);
|
||||||
|
|
||||||
$string = strtolower($this->parseCDATA($string));
|
$string = strtolower($this->parseCDATA($string));
|
||||||
$parts = explode(' ', $string);
|
$parts = explode(' ', $string);
|
||||||
$final = '';
|
$final = '';
|
||||||
foreach ($parts as $part) {
|
foreach ($parts as $part) {
|
||||||
if (isset($this->allowed_values[$part])) {
|
if (isset($allowed_values[$part])) {
|
||||||
$final .= $part . ' ';
|
$final .= $part . ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,4 +34,3 @@ class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -15,7 +15,7 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
|
|||||||
{
|
{
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_CSS_URI() {
|
function HTMLPurifier_AttrDef_CSS_URI() {
|
||||||
$this->HTMLPurifier_AttrDef_URI(true); // always embedded
|
parent::HTMLPurifier_AttrDef_URI(true); // always embedded
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate($uri_string, $config, &$context) {
|
function validate($uri_string, $config, &$context) {
|
||||||
@@ -29,7 +29,7 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
|
|||||||
if ($uri_string[$new_length] != ')') return false;
|
if ($uri_string[$new_length] != ')') return false;
|
||||||
$uri = trim(substr($uri_string, 0, $new_length));
|
$uri = trim(substr($uri_string, 0, $new_length));
|
||||||
|
|
||||||
if (isset($uri[0]) && ($uri[0] == "'" || $uri[0] == '"')) {
|
if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
|
||||||
$quote = $uri[0];
|
$quote = $uri[0];
|
||||||
$new_length = strlen($uri) - 1;
|
$new_length = strlen($uri) - 1;
|
||||||
if ($uri[$new_length] !== $quote) return false;
|
if ($uri[$new_length] !== $quote) return false;
|
||||||
@@ -55,4 +55,3 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -5,6 +5,9 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
// Enum = Enumerated
|
// Enum = Enumerated
|
||||||
/**
|
/**
|
||||||
* Validates a keyword against a list of valid values.
|
* Validates a keyword against a list of valid values.
|
||||||
|
* @warning The case-insensitive compare of this function uses PHP's
|
||||||
|
* built-in strtolower and ctype_lower functions, which may
|
||||||
|
* cause problems with international comparisons
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
@@ -34,6 +37,7 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
|||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
$string = trim($string);
|
$string = trim($string);
|
||||||
if (!$this->case_sensitive) {
|
if (!$this->case_sensitive) {
|
||||||
|
// we may want to do full case-insensitive libraries
|
||||||
$string = ctype_lower($string) ? $string : strtolower($string);
|
$string = ctype_lower($string) ? $string : strtolower($string);
|
||||||
}
|
}
|
||||||
$result = isset($this->valid_values[$string]);
|
$result = isset($this->valid_values[$string]);
|
||||||
@@ -41,6 +45,21 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
|||||||
return $result ? $string : false;
|
return $result ? $string : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $string In form of comma-delimited list of case-insensitive
|
||||||
|
* valid values. Example: "foo,bar,baz". Prepend "s:" to make
|
||||||
|
* case sensitive
|
||||||
|
*/
|
||||||
|
function make($string) {
|
||||||
|
if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
|
||||||
|
$string = substr($string, 2);
|
||||||
|
$sensitive = true;
|
||||||
|
} else {
|
||||||
|
$sensitive = false;
|
||||||
|
}
|
||||||
|
$values = explode(',', $string);
|
||||||
|
return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
29
library/HTMLPurifier/AttrDef/HTML/Bool.php
Normal file
29
library/HTMLPurifier/AttrDef/HTML/Bool.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a boolean attribute
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrDef_HTML_Bool extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
var $name;
|
||||||
|
var $minimized = true;
|
||||||
|
|
||||||
|
function HTMLPurifier_AttrDef_HTML_Bool($name = false) {$this->name = $name;}
|
||||||
|
|
||||||
|
function validate($string, $config, &$context) {
|
||||||
|
if (empty($string)) return false;
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $string Name of attribute
|
||||||
|
*/
|
||||||
|
function make($string) {
|
||||||
|
return new HTMLPurifier_AttrDef_HTML_Bool($string);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
34
library/HTMLPurifier/AttrDef/HTML/Color.php
Normal file
34
library/HTMLPurifier/AttrDef/HTML/Color.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
require_once 'HTMLPurifier/AttrDef/CSS/Color.php'; // for %Core.ColorKeywords
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a color according to the HTML spec.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
static $colors = null;
|
||||||
|
if ($colors === null) $colors = $config->get('Core', 'ColorKeywords');
|
||||||
|
|
||||||
|
$string = trim($string);
|
||||||
|
|
||||||
|
if (empty($string)) return false;
|
||||||
|
if (isset($colors[$string])) return $colors[$string];
|
||||||
|
if ($string[0] === '#') $hex = substr($string, 1);
|
||||||
|
else $hex = $string;
|
||||||
|
|
||||||
|
$length = strlen($hex);
|
||||||
|
if ($length !== 3 && $length !== 6) return false;
|
||||||
|
if (!ctype_xdigit($hex)) return false;
|
||||||
|
if ($length === 3) $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2];
|
||||||
|
|
||||||
|
return "#$hex";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
33
library/HTMLPurifier/AttrDef/HTML/FrameTarget.php
Normal file
33
library/HTMLPurifier/AttrDef/HTML/FrameTarget.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Attr', 'AllowedFrameTargets', array(), 'lookup',
|
||||||
|
'Lookup table of all allowed link frame targets. Some commonly used '.
|
||||||
|
'link targets include _blank, _self, _parent and _top. Values should '.
|
||||||
|
'be lowercase, as validation will be done in a case-sensitive manner '.
|
||||||
|
'despite W3C\'s recommendation. XHTML 1.0 Strict does not permit '.
|
||||||
|
'the target attribute so this directive will have no effect in that '.
|
||||||
|
'doctype. XHTML 1.1 does not enable the Target module by default, you '.
|
||||||
|
'will have to manually enable it (see the module documentation for more details.)'
|
||||||
|
);
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef/Enum.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special-case enum attribute definition that lazy loads allowed frame targets
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum
|
||||||
|
{
|
||||||
|
|
||||||
|
var $valid_values = false; // uninitialized value
|
||||||
|
var $case_sensitive = false;
|
||||||
|
|
||||||
|
function HTMLPurifier_AttrDef_HTML_FrameTarget() {}
|
||||||
|
|
||||||
|
function validate($string, $config, &$context) {
|
||||||
|
if ($this->valid_values === false) $this->valid_values = $config->get('Attr', 'AllowedFrameTargets');
|
||||||
|
return parent::validate($string, $config, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -43,6 +43,14 @@ HTMLPurifier_ConfigSchema::define(
|
|||||||
'is set to a non-empty value! This directive was available since 1.2.0.'
|
'is set to a non-empty value! This directive was available since 1.2.0.'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Attr', 'IDBlacklistRegexp', null, 'string/null',
|
||||||
|
'PCRE regular expression to be matched against all IDs. If the expression '.
|
||||||
|
'is matches, the ID is rejected. Use this with care: may cause '.
|
||||||
|
'significant degradation. ID matching is done after all other '.
|
||||||
|
'validation. This directive was available since 1.6.0.'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the HTML attribute ID.
|
* Validates the HTML attribute ID.
|
||||||
* @warning Even though this is the id processor, it
|
* @warning Even though this is the id processor, it
|
||||||
@@ -94,6 +102,11 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
|
|||||||
$result = ($trim === '');
|
$result = ($trim === '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$regexp = $config->get('Attr', 'IDBlacklistRegexp');
|
||||||
|
if ($regexp && preg_match($regexp, $id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (/*!$this->ref && */$result) $id_accumulator->add($id);
|
if (/*!$this->ref && */$result) $id_accumulator->add($id);
|
||||||
|
|
||||||
// if no change was made to the ID, return the result
|
// if no change was made to the ID, return the result
|
||||||
@@ -105,4 +118,3 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -41,4 +41,3 @@ class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
72
library/HTMLPurifier/AttrDef/HTML/LinkTypes.php
Normal file
72
library/HTMLPurifier/AttrDef/HTML/LinkTypes.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Attr', 'AllowedRel', array(), 'lookup',
|
||||||
|
'List of allowed forward document relationships in the rel attribute. '.
|
||||||
|
'Common values may be nofollow or print. By default, this is empty, '.
|
||||||
|
'meaning that no document relationships are allowed. This directive '.
|
||||||
|
'was available since 1.6.0.'
|
||||||
|
);
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'Attr', 'AllowedRev', array(), 'lookup',
|
||||||
|
'List of allowed reverse document relationships in the rev attribute. '.
|
||||||
|
'This attribute is a bit of an edge-case; if you don\'t know what it '.
|
||||||
|
'is for, stay away. This directive was available since 1.6.0.'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a rel/rev link attribute against a directive of allowed values
|
||||||
|
* @note We cannot use Enum because link types allow multiple
|
||||||
|
* values.
|
||||||
|
* @note Assumes link types are ASCII text
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Name config attribute to pull. */
|
||||||
|
var $name;
|
||||||
|
|
||||||
|
function HTMLPurifier_AttrDef_HTML_LinkTypes($name) {
|
||||||
|
$configLookup = array(
|
||||||
|
'rel' => 'AllowedRel',
|
||||||
|
'rev' => 'AllowedRev'
|
||||||
|
);
|
||||||
|
if (!isset($configLookup[$name])) {
|
||||||
|
trigger_error('Unrecognized attribute name for link '.
|
||||||
|
'relationship.', E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->name = $configLookup[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
$allowed = $config->get('Attr', $this->name);
|
||||||
|
if (empty($allowed)) return false;
|
||||||
|
|
||||||
|
$string = $this->parseCDATA($string);
|
||||||
|
$parts = explode(' ', $string);
|
||||||
|
|
||||||
|
// lookup to prevent duplicates
|
||||||
|
$ret_lookup = array();
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$part = strtolower(trim($part));
|
||||||
|
if (!isset($allowed[$part])) continue;
|
||||||
|
$ret_lookup[$part] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($ret_lookup)) return false;
|
||||||
|
|
||||||
|
$ret_array = array();
|
||||||
|
foreach ($ret_lookup as $part => $bool) $ret_array[] = $part;
|
||||||
|
$string = implode(' ', $ret_array);
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -41,4 +41,3 @@ class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Le
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -48,4 +48,3 @@ class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -34,4 +34,3 @@ class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -72,4 +72,3 @@ class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -72,4 +72,3 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -14,4 +14,3 @@ class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -1,90 +1,65 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'HTMLPurifier/AttrDef.php';
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
require_once 'HTMLPurifier/URIParser.php';
|
||||||
require_once 'HTMLPurifier/URIScheme.php';
|
require_once 'HTMLPurifier/URIScheme.php';
|
||||||
require_once 'HTMLPurifier/URISchemeRegistry.php';
|
require_once 'HTMLPurifier/URISchemeRegistry.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/URI/Host.php';
|
require_once 'HTMLPurifier/AttrDef/URI/Host.php';
|
||||||
require_once 'HTMLPurifier/PercentEncoder.php';
|
require_once 'HTMLPurifier/PercentEncoder.php';
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
// special case filtering directives
|
||||||
'URI', 'DefaultScheme', 'http', 'string',
|
|
||||||
'Defines through what scheme the output will be served, in order to '.
|
|
||||||
'select the proper object validator when no scheme information is present.'
|
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
HTMLPurifier_ConfigSchema::define(
|
||||||
'URI', 'Host', null, 'string/null',
|
'URI', 'Munge', null, 'string/null', '
|
||||||
'Defines the domain name of the server, so we can determine whether or '.
|
<p>
|
||||||
'an absolute URI is from your website or not. Not strictly necessary, '.
|
Munges all browsable (usually http, https and ftp)
|
||||||
'as users should be using relative URIs to reference resources on your '.
|
absolute URI\'s into another URI, usually a URI redirection service.
|
||||||
'website. It will, however, let you use absolute URIs to link to '.
|
This directive accepts a URI, formatted with a <code>%s</code> where
|
||||||
'subdomains of the domain you post here: i.e. example.com will allow '.
|
the url-encoded original URI should be inserted (sample:
|
||||||
'sub.example.com. However, higher up domains will still be excluded: '.
|
<code>http://www.google.com/url?q=%s</code>).
|
||||||
'if you set %URI.Host to sub.example.com, example.com will be blocked. '.
|
</p>
|
||||||
'This directive has been available since 1.2.0.'
|
<p>
|
||||||
);
|
Uses for this directive:
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Prevent PageRank leaks, while being fairly transparent
|
||||||
|
to users (you may also want to add some client side JavaScript to
|
||||||
|
override the text in the statusbar). <strong>Notice</strong>:
|
||||||
|
Many security experts believe that this form of protection does not deter spam-bots.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Redirect users to a splash page telling them they are leaving your
|
||||||
|
website. While this is poor usability practice, it is often mandated
|
||||||
|
in corporate environments.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
This directive has been available since 1.3.0.
|
||||||
|
</p>
|
||||||
|
');
|
||||||
|
|
||||||
|
// disabling directives
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
HTMLPurifier_ConfigSchema::define(
|
||||||
'URI', 'DisableExternal', false, 'bool',
|
'URI', 'Disable', false, 'bool', '
|
||||||
'Disables links to external websites. This is a highly effective '.
|
<p>
|
||||||
'anti-spam and anti-pagerank-leech measure, but comes at a hefty price: no'.
|
Disables all URIs in all forms. Not sure why you\'d want to do that
|
||||||
'links or images outside of your domain will be allowed. Non-linkified '.
|
(after all, the Internet\'s founded on the notion of a hyperlink).
|
||||||
'URIs will still be preserved. If you want to be able to link to '.
|
This directive has been available since 1.3.0.
|
||||||
'subdomains or use absolute URIs, specify %URI.Host for your website. '.
|
</p>
|
||||||
'This directive has been available since 1.2.0.'
|
');
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
|
||||||
'URI', 'DisableExternalResources', false, 'bool',
|
|
||||||
'Disables the embedding of external resources, preventing users from '.
|
|
||||||
'embedding things like images from other hosts. This prevents '.
|
|
||||||
'access tracking (good for email viewers), bandwidth leeching, '.
|
|
||||||
'cross-site request forging, goatse.cx posting, and '.
|
|
||||||
'other nasties, but also results in '.
|
|
||||||
'a loss of end-user functionality (they can\'t directly post a pic '.
|
|
||||||
'they posted from Flickr anymore). Use it if you don\'t have a '.
|
|
||||||
'robust user-content moderation team. This directive has been '.
|
|
||||||
'available since 1.3.0.'
|
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
|
||||||
'URI', 'DisableResources', false, 'bool',
|
|
||||||
'Disables embedding resources, essentially meaning no pictures. You can '.
|
|
||||||
'still link to them though. See %URI.DisableExternalResources for why '.
|
|
||||||
'this might be a good idea. This directive has been available since 1.3.0.'
|
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
|
||||||
'URI', 'Munge', null, 'string/null',
|
|
||||||
'Munges all browsable (usually http, https and ftp) URI\'s into some URL '.
|
|
||||||
'redirection service. Pass this directive a URI, with %s inserted where '.
|
|
||||||
'the url-encoded original URI should be inserted (sample: '.
|
|
||||||
'<code>http://www.google.com/url?q=%s</code>). '.
|
|
||||||
'This prevents PageRank leaks, while being as transparent as possible '.
|
|
||||||
'to users (you may also want to add some client side JavaScript to '.
|
|
||||||
'override the text in the statusbar). Warning: many security experts '.
|
|
||||||
'believe that this form of protection does not deter spam-bots. '.
|
|
||||||
'You can also use this directive to redirect users to a splash page '.
|
|
||||||
'telling them they are leaving your website. '.
|
|
||||||
'This directive has been available since 1.3.0.'
|
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
|
||||||
'URI', 'HostBlacklist', array(), 'list',
|
|
||||||
'List of strings that are forbidden in the host of any URI. Use it to '.
|
|
||||||
'kill domain names of spam, etc. Note that it will catch anything in '.
|
|
||||||
'the domain, so <tt>moo.com</tt> will catch <tt>moo.com.example.com</tt>. '.
|
|
||||||
'This directive has been available since 1.3.0.'
|
|
||||||
);
|
|
||||||
|
|
||||||
HTMLPurifier_ConfigSchema::define(
|
|
||||||
'URI', 'Disable', false, 'bool',
|
|
||||||
'Disables all URIs in all forms. Not sure why you\'d want to do that '.
|
|
||||||
'(after all, the Internet\'s founded on the notion of a hyperlink). '.
|
|
||||||
'This directive has been available since 1.3.0.'
|
|
||||||
);
|
|
||||||
HTMLPurifier_ConfigSchema::defineAlias('Attr', 'DisableURI', 'URI', 'Disable');
|
HTMLPurifier_ConfigSchema::defineAlias('Attr', 'DisableURI', 'URI', 'Disable');
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define(
|
||||||
|
'URI', 'DisableResources', false, 'bool', '
|
||||||
|
<p>
|
||||||
|
Disables embedding resources, essentially meaning no pictures. You can
|
||||||
|
still link to them though. See %URI.DisableExternalResources for why
|
||||||
|
this might be a good idea. This directive has been available since 1.3.0.
|
||||||
|
</p>
|
||||||
|
');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a URI as defined by RFC 3986.
|
* Validates a URI as defined by RFC 3986.
|
||||||
* @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme
|
* @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme
|
||||||
@@ -92,205 +67,83 @@ HTMLPurifier_ConfigSchema::defineAlias('Attr', 'DisableURI', 'URI', 'Disable');
|
|||||||
class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
var $host;
|
var $parser, $percentEncoder;
|
||||||
var $PercentEncoder;
|
var $embedsResource;
|
||||||
var $embeds_resource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
|
* @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
|
||||||
*/
|
*/
|
||||||
function HTMLPurifier_AttrDef_URI($embeds_resource = false) {
|
function HTMLPurifier_AttrDef_URI($embeds_resource = false) {
|
||||||
$this->host = new HTMLPurifier_AttrDef_URI_Host();
|
$this->parser = new HTMLPurifier_URIParser();
|
||||||
$this->PercentEncoder = new HTMLPurifier_PercentEncoder();
|
$this->percentEncoder = new HTMLPurifier_PercentEncoder();
|
||||||
$this->embeds_resource = (bool) $embeds_resource;
|
$this->embedsResource = (bool) $embeds_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate($uri, $config, &$context) {
|
function validate($uri, $config, &$context) {
|
||||||
|
|
||||||
// We'll write stack-based parsers later, for now, use regexps to
|
|
||||||
// get things working as fast as possible (irony)
|
|
||||||
|
|
||||||
if ($config->get('URI', 'Disable')) return false;
|
if ($config->get('URI', 'Disable')) return false;
|
||||||
|
|
||||||
// parse as CDATA
|
// initial operations
|
||||||
$uri = $this->parseCDATA($uri);
|
$uri = $this->parseCDATA($uri);
|
||||||
|
$uri = $this->percentEncoder->normalize($uri);
|
||||||
|
|
||||||
// fix up percent-encoding
|
// parse the URI
|
||||||
$uri = $this->PercentEncoder->normalize($uri);
|
$uri = $this->parser->parse($uri);
|
||||||
|
if ($uri === false) return false;
|
||||||
|
|
||||||
// while it would be nice to use parse_url(), that's specifically
|
// add embedded flag to context for validators
|
||||||
// for HTTP and thus won't work for our generic URI parsing
|
$context->register('EmbeddedURI', $this->embedsResource);
|
||||||
|
|
||||||
// according to the RFC... (but this cuts corners, i.e. non-validating)
|
$ok = false;
|
||||||
$r_URI = '!'.
|
do {
|
||||||
'(([^:/?#<>\'"]+):)?'. // 2. Scheme
|
|
||||||
'(//([^/?#<>\'"]*))?'. // 4. Authority
|
// generic validation
|
||||||
'([^?#<>\'"]*)'. // 5. Path
|
$result = $uri->validate($config, $context);
|
||||||
'(\?([^#<>\'"]*))?'. // 7. Query
|
if (!$result) break;
|
||||||
'(#([^<>\'"]*))?'. // 8. Fragment
|
|
||||||
'!';
|
// chained validation
|
||||||
|
$uri_def =& $config->getDefinition('URI');
|
||||||
|
$result = $uri_def->filter($uri, $config, $context);
|
||||||
|
if (!$result) break;
|
||||||
|
|
||||||
|
// scheme-specific validation
|
||||||
|
$scheme_obj = $uri->getSchemeObj($config, $context);
|
||||||
|
if (!$scheme_obj) break;
|
||||||
|
if ($this->embedsResource && !$scheme_obj->browsable) break;
|
||||||
|
$result = $scheme_obj->validate($uri, $config, $context);
|
||||||
|
if (!$result) break;
|
||||||
|
|
||||||
|
// survived gauntlet
|
||||||
|
$ok = true;
|
||||||
|
|
||||||
|
} while (false);
|
||||||
|
|
||||||
$matches = array();
|
$context->destroy('EmbeddedURI');
|
||||||
$result = preg_match($r_URI, $uri, $matches);
|
if (!$ok) return false;
|
||||||
|
|
||||||
if (!$result) return false; // invalid URI
|
// munge scheme off if necessary (this must be last)
|
||||||
|
if (!is_null($uri->scheme) && is_null($uri->host)) {
|
||||||
// seperate out parts
|
if ($uri_def->defaultScheme == $uri->scheme) {
|
||||||
$scheme = !empty($matches[1]) ? $matches[2] : null;
|
$uri->scheme = null;
|
||||||
$authority = !empty($matches[3]) ? $matches[4] : null;
|
}
|
||||||
$path = $matches[5]; // always present, can be empty
|
|
||||||
$query = !empty($matches[6]) ? $matches[7] : null;
|
|
||||||
$fragment = !empty($matches[8]) ? $matches[9] : null;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$registry =& HTMLPurifier_URISchemeRegistry::instance();
|
|
||||||
if ($scheme !== null) {
|
|
||||||
// no need to validate the scheme's fmt since we do that when we
|
|
||||||
// retrieve the specific scheme object from the registry
|
|
||||||
$scheme = ctype_lower($scheme) ? $scheme : strtolower($scheme);
|
|
||||||
$scheme_obj = $registry->getScheme($scheme, $config, $context);
|
|
||||||
if (!$scheme_obj) return false; // invalid scheme, clean it out
|
|
||||||
} else {
|
|
||||||
$scheme_obj = $registry->getScheme(
|
|
||||||
$config->get('URI', 'DefaultScheme'), $config, $context
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// back to string
|
||||||
|
$result = $uri->toString();
|
||||||
|
|
||||||
// the URI we're processing embeds_resource a resource in the page, but the URI
|
// munge entire URI if necessary
|
||||||
// it references cannot be located
|
if (
|
||||||
if ($this->embeds_resource && !$scheme_obj->browsable) {
|
!is_null($uri->host) && // indicator for authority
|
||||||
return false;
|
!empty($scheme_obj->browsable) &&
|
||||||
}
|
!is_null($munge = $config->get('URI', 'Munge'))
|
||||||
|
) {
|
||||||
|
$result = str_replace('%s', rawurlencode($result), $munge);
|
||||||
if ($authority !== null) {
|
|
||||||
|
|
||||||
// remove URI if it's absolute and we disabled externals or
|
|
||||||
// if it's absolute and embedded and we disabled external resources
|
|
||||||
unset($our_host);
|
|
||||||
if (
|
|
||||||
$config->get('URI', 'DisableExternal') ||
|
|
||||||
(
|
|
||||||
$config->get('URI', 'DisableExternalResources') &&
|
|
||||||
$this->embeds_resource
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
$our_host = $config->get('URI', 'Host');
|
|
||||||
if ($our_host === null) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$HEXDIG = '[A-Fa-f0-9]';
|
|
||||||
$unreserved = 'A-Za-z0-9-._~'; // make sure you wrap with []
|
|
||||||
$sub_delims = '!$&\'()'; // needs []
|
|
||||||
$pct_encoded = "%$HEXDIG$HEXDIG";
|
|
||||||
$r_userinfo = "(?:[$unreserved$sub_delims:]|$pct_encoded)*";
|
|
||||||
$r_authority = "/^(($r_userinfo)@)?(\[[^\]]+\]|[^:]*)(:(\d*))?/";
|
|
||||||
$matches = array();
|
|
||||||
preg_match($r_authority, $authority, $matches);
|
|
||||||
// overloads regexp!
|
|
||||||
$userinfo = !empty($matches[1]) ? $matches[2] : null;
|
|
||||||
$host = !empty($matches[3]) ? $matches[3] : null;
|
|
||||||
$port = !empty($matches[4]) ? $matches[5] : null;
|
|
||||||
|
|
||||||
// validate port
|
|
||||||
if ($port !== null) {
|
|
||||||
$port = (int) $port;
|
|
||||||
if ($port < 1 || $port > 65535) $port = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$host = $this->host->validate($host, $config, $context);
|
|
||||||
if ($host === false) $host = null;
|
|
||||||
|
|
||||||
if ($this->checkBlacklist($host, $config, $context)) return false;
|
|
||||||
|
|
||||||
// more lenient absolute checking
|
|
||||||
if (isset($our_host)) {
|
|
||||||
$host_parts = array_reverse(explode('.', $host));
|
|
||||||
// could be cached
|
|
||||||
$our_host_parts = array_reverse(explode('.', $our_host));
|
|
||||||
foreach ($our_host_parts as $i => $discard) {
|
|
||||||
if (!isset($host_parts[$i])) return false;
|
|
||||||
if ($host_parts[$i] != $our_host_parts[$i]) return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// userinfo and host are validated within the regexp
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$port = $host = $userinfo = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// query and fragment are quite simple in terms of definition:
|
|
||||||
// *( pchar / "/" / "?" ), so define their validation routines
|
|
||||||
// when we start fixing percent encoding
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// path gets to be validated against a hodge-podge of rules depending
|
|
||||||
// on the status of authority and scheme, but it's not that important,
|
|
||||||
// esp. since it won't be applicable to everyone
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// okay, now we defer execution to the subobject for more processing
|
|
||||||
// note that $fragment is omitted
|
|
||||||
list($userinfo, $host, $port, $path, $query) =
|
|
||||||
$scheme_obj->validateComponents(
|
|
||||||
$userinfo, $host, $port, $path, $query, $config, $context
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// reconstruct authority
|
|
||||||
$authority = null;
|
|
||||||
if (!is_null($userinfo) || !is_null($host) || !is_null($port)) {
|
|
||||||
$authority = '';
|
|
||||||
if($userinfo !== null) $authority .= $userinfo . '@';
|
|
||||||
$authority .= $host;
|
|
||||||
if($port !== null) $authority .= ':' . $port;
|
|
||||||
}
|
|
||||||
|
|
||||||
// reconstruct the result
|
|
||||||
$result = '';
|
|
||||||
if ($scheme !== null) $result .= "$scheme:";
|
|
||||||
if ($authority !== null) $result .= "//$authority";
|
|
||||||
$result .= $path;
|
|
||||||
if ($query !== null) $result .= "?$query";
|
|
||||||
if ($fragment !== null) $result .= "#$fragment";
|
|
||||||
|
|
||||||
// munge if necessary
|
|
||||||
$munge = $config->get('URI', 'Munge');
|
|
||||||
if (!empty($scheme_obj->browsable) && $munge !== null) {
|
|
||||||
if ($authority !== null) {
|
|
||||||
$result = str_replace('%s', rawurlencode($result), $munge);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks a host against an array blacklist
|
|
||||||
* @param $host Host to check
|
|
||||||
* @param $config HTMLPurifier_Config instance
|
|
||||||
* @param $context HTMLPurifier_Context instance
|
|
||||||
* @return bool Is spam?
|
|
||||||
*/
|
|
||||||
function checkBlacklist($host, &$config, &$context) {
|
|
||||||
$blacklist = $config->get('URI', 'HostBlacklist');
|
|
||||||
if (!empty($blacklist)) {
|
|
||||||
foreach($blacklist as $blacklisted_host_fragment) {
|
|
||||||
if (strpos($host, $blacklisted_host_fragment) !== false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
@@ -14,4 +14,3 @@ class HTMLPurifier_AttrDef_URI_Email extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -20,4 +20,3 @@ class HTMLPurifier_AttrDef_URI_Email_SimpleCheck extends HTMLPurifier_AttrDef_UR
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -51,4 +51,3 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -15,13 +15,10 @@ class HTMLPurifier_AttrDef_URI_IPv4 extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
var $ip4;
|
var $ip4;
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_URI_IPv4() {
|
|
||||||
$oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
|
|
||||||
$this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})";
|
|
||||||
}
|
|
||||||
|
|
||||||
function validate($aIP, $config, &$context) {
|
function validate($aIP, $config, &$context) {
|
||||||
|
|
||||||
|
if (!$this->ip4) $this->_loadRegex();
|
||||||
|
|
||||||
if (preg_match('#^' . $this->ip4 . '$#s', $aIP))
|
if (preg_match('#^' . $this->ip4 . '$#s', $aIP))
|
||||||
{
|
{
|
||||||
return $aIP;
|
return $aIP;
|
||||||
@@ -31,6 +28,14 @@ class HTMLPurifier_AttrDef_URI_IPv4 extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lazy load function to prevent regex from being stuffed in
|
||||||
|
* cache.
|
||||||
|
*/
|
||||||
|
function _loadRegex() {
|
||||||
|
$oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
|
||||||
|
$this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -13,6 +13,8 @@ class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
|
|||||||
|
|
||||||
function validate($aIP, $config, &$context) {
|
function validate($aIP, $config, &$context) {
|
||||||
|
|
||||||
|
if (!$this->ip4) $this->_loadRegex();
|
||||||
|
|
||||||
$original = $aIP;
|
$original = $aIP;
|
||||||
|
|
||||||
$hex = '[0-9a-fA-F]';
|
$hex = '[0-9a-fA-F]';
|
||||||
@@ -96,4 +98,3 @@ class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -29,6 +29,29 @@ class HTMLPurifier_AttrTransform
|
|||||||
function transform($attr, $config, &$context) {
|
function transform($attr, $config, &$context) {
|
||||||
trigger_error('Cannot call abstract function', E_USER_ERROR);
|
trigger_error('Cannot call abstract function', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepends CSS properties to the style attribute, creating the
|
||||||
|
* attribute if it doesn't exist.
|
||||||
|
* @param $attr Attribute array to process (passed by reference)
|
||||||
|
* @param $css CSS to prepend
|
||||||
|
*/
|
||||||
|
function prependCSS(&$attr, $css) {
|
||||||
|
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
|
||||||
|
$attr['style'] = $css . $attr['style'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves and removes an attribute
|
||||||
|
* @param $attr Attribute array to process (passed by reference)
|
||||||
|
* @param $key Key of attribute to confiscate
|
||||||
|
*/
|
||||||
|
function confiscateAttr(&$attr, $key) {
|
||||||
|
if (!isset($attr[$key])) return null;
|
||||||
|
$value = $attr[$key];
|
||||||
|
unset($attr[$key]);
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@@ -28,4 +28,3 @@ class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
25
library/HTMLPurifier/AttrTransform/BgColor.php
Normal file
25
library/HTMLPurifier/AttrTransform/BgColor.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes deprecated bgcolor attribute to CSS.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_BgColor
|
||||||
|
extends HTMLPurifier_AttrTransform {
|
||||||
|
|
||||||
|
function transform($attr, $config, &$context) {
|
||||||
|
|
||||||
|
if (!isset($attr['bgcolor'])) return $attr;
|
||||||
|
|
||||||
|
$bgcolor = $this->confiscateAttr($attr, 'bgcolor');
|
||||||
|
// some validation should happen here
|
||||||
|
|
||||||
|
$this->prependCSS($attr, "background-color:$bgcolor;");
|
||||||
|
|
||||||
|
return $attr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
38
library/HTMLPurifier/AttrTransform/BoolToCSS.php
Normal file
38
library/HTMLPurifier/AttrTransform/BoolToCSS.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes converts a boolean attribute to fixed CSS
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_BoolToCSS
|
||||||
|
extends HTMLPurifier_AttrTransform {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of boolean attribute that is trigger
|
||||||
|
*/
|
||||||
|
var $attr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CSS declarations to add to style, needs trailing semicolon
|
||||||
|
*/
|
||||||
|
var $css;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attr string attribute name to convert from
|
||||||
|
* @param $css string CSS declarations to add to style (needs semicolon)
|
||||||
|
*/
|
||||||
|
function HTMLPurifier_AttrTransform_BoolToCSS($attr, $css) {
|
||||||
|
$this->attr = $attr;
|
||||||
|
$this->css = $css;
|
||||||
|
}
|
||||||
|
|
||||||
|
function transform($attr, $config, &$context) {
|
||||||
|
if (!isset($attr[$this->attr])) return $attr;
|
||||||
|
unset($attr[$this->attr]);
|
||||||
|
$this->prependCSS($attr, $this->css);
|
||||||
|
return $attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
19
library/HTMLPurifier/AttrTransform/Border.php
Normal file
19
library/HTMLPurifier/AttrTransform/Border.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes deprecated border attribute to CSS.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_Border extends HTMLPurifier_AttrTransform {
|
||||||
|
|
||||||
|
function transform($attr, $config, &$context) {
|
||||||
|
if (!isset($attr['border'])) return $attr;
|
||||||
|
$border_width = $this->confiscateAttr($attr, 'border');
|
||||||
|
// some validation should happen here
|
||||||
|
$this->prependCSS($attr, "border:{$border_width}px solid;");
|
||||||
|
return $attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user