parent
e70432332d
commit
9e08be5676
@ -1,9 +0,0 @@ |
||||
|
||||
CREDITS |
||||
|
||||
Almost everything written by Edward Z. Yang (Ambush Commander). Lots of thanks |
||||
to the DevNetwork Community for their help (see docs/ref-devnetwork.html for |
||||
more details), Feyd especially (namely IPv6 and optimization). Thanks to RSnake |
||||
for letting me package his fantastic XSS cheatsheet for a smoketest. |
||||
|
||||
vim: et sw=4 sts=4 |
||||
File diff suppressed because it is too large
Load Diff
@ -1,373 +0,0 @@ |
||||
|
||||
Install |
||||
How to install HTML Purifier |
||||
|
||||
HTML Purifier is designed to run out of the box, so actually using the |
||||
library is extremely easy. (Although... if you were looking for a |
||||
step-by-step installation GUI, you've downloaded the wrong software!) |
||||
|
||||
While the impatient can get going immediately with some of the sample |
||||
code at the bottom of this library, it's well worth reading this entire |
||||
document--most of the other documentation assumes that you are familiar |
||||
with these contents. |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
1. Compatibility |
||||
|
||||
HTML Purifier is PHP 5 only, and is actively tested from PHP 5.0.5 and |
||||
up. It has no core dependencies with other libraries. PHP |
||||
4 support was deprecated on December 31, 2007 with HTML Purifier 3.0.0. |
||||
|
||||
These optional extensions can enhance the capabilities of HTML Purifier: |
||||
|
||||
* iconv : Converts text to and from non-UTF-8 encodings |
||||
* bcmath : Used for unit conversion and imagecrash protection |
||||
* tidy : Used for pretty-printing HTML |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
2. Reconnaissance |
||||
|
||||
A big plus of HTML Purifier is its inerrant support of standards, so |
||||
your web-pages should be standards-compliant. (They should also use |
||||
semantic markup, but that's another issue altogether, one HTML Purifier |
||||
cannot fix without reading your mind.) |
||||
|
||||
HTML Purifier can process these doctypes: |
||||
|
||||
* XHTML 1.0 Transitional (default) |
||||
* XHTML 1.0 Strict |
||||
* HTML 4.01 Transitional |
||||
* HTML 4.01 Strict |
||||
* XHTML 1.1 |
||||
|
||||
...and these character encodings: |
||||
|
||||
* UTF-8 (default) |
||||
* Any encoding iconv supports (with crippled internationalization support) |
||||
|
||||
These defaults reflect what my choices would be if I were authoring an |
||||
HTML document, however, what you choose depends on the nature of your |
||||
codebase. If you don't know what doctype you are using, you can determine |
||||
the doctype from this identifier at the top of your source code: |
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
|
||||
...and the character encoding from this code: |
||||
|
||||
<meta http-equiv="Content-type" content="text/html;charset=ENCODING"> |
||||
|
||||
If the character encoding declaration is missing, STOP NOW, and |
||||
read 'docs/enduser-utf8.html' (web accessible at |
||||
http://htmlpurifier.org/docs/enduser-utf8.html). In fact, even if it is |
||||
present, read this document anyway, as many websites specify their |
||||
document's character encoding incorrectly. |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
3. Including the library |
||||
|
||||
The procedure is quite simple: |
||||
|
||||
require_once '/path/to/library/HTMLPurifier.auto.php'; |
||||
|
||||
This will setup an autoloader, so the library's files are only included |
||||
when you use them. |
||||
|
||||
Only the contents in the library/ folder are necessary, so you can remove |
||||
everything else when using HTML Purifier in a production environment. |
||||
|
||||
If you installed HTML Purifier via PEAR, all you need to do is: |
||||
|
||||
require_once 'HTMLPurifier.auto.php'; |
||||
|
||||
Please note that the usual PEAR practice of including just the classes you |
||||
want will not work with HTML Purifier's autoloading scheme. |
||||
|
||||
Advanced users, read on; other users can skip to section 4. |
||||
|
||||
Autoload compatibility |
||||
---------------------- |
||||
|
||||
HTML Purifier attempts to be as smart as possible when registering an |
||||
autoloader, but there are some cases where you will need to change |
||||
your own code to accomodate HTML Purifier. These are those cases: |
||||
|
||||
PHP VERSION IS LESS THAN 5.1.2, AND YOU'VE DEFINED __autoload |
||||
Because spl_autoload_register() doesn't exist in early versions |
||||
of PHP 5, HTML Purifier has no way of adding itself to the autoload |
||||
stack. Modify your __autoload function to test |
||||
HTMLPurifier_Bootstrap::autoload($class) |
||||
|
||||
For example, suppose your autoload function looks like this: |
||||
|
||||
function __autoload($class) { |
||||
require str_replace('_', '/', $class) . '.php'; |
||||
return true; |
||||
} |
||||
|
||||
A modified version with HTML Purifier would look like this: |
||||
|
||||
function __autoload($class) { |
||||
if (HTMLPurifier_Bootstrap::autoload($class)) return true; |
||||
require str_replace('_', '/', $class) . '.php'; |
||||
return true; |
||||
} |
||||
|
||||
Note that there *is* some custom behavior in our autoloader; the |
||||
original autoloader in our example would work for 99% of the time, |
||||
but would fail when including language files. |
||||
|
||||
AN __autoload FUNCTION IS DECLARED AFTER OUR AUTOLOADER IS REGISTERED |
||||
spl_autoload_register() has the curious behavior of disabling |
||||
the existing __autoload() handler. Users need to explicitly |
||||
spl_autoload_register('__autoload'). Because we use SPL when it |
||||
is available, __autoload() will ALWAYS be disabled. If __autoload() |
||||
is declared before HTML Purifier is loaded, this is not a problem: |
||||
HTML Purifier will register the function for you. But if it is |
||||
declared afterwards, it will mysteriously not work. This |
||||
snippet of code (after your autoloader is defined) will fix it: |
||||
|
||||
spl_autoload_register('__autoload') |
||||
|
||||
Users should also be on guard if they use a version of PHP previous |
||||
to 5.1.2 without an autoloader--HTML Purifier will define __autoload() |
||||
for you, which can collide with an autoloader that was added by *you* |
||||
later. |
||||
|
||||
|
||||
For better performance |
||||
---------------------- |
||||
|
||||
Opcode caches, which greatly speed up PHP initialization for scripts |
||||
with large amounts of code (HTML Purifier included), don't like |
||||
autoloaders. We offer an include file that includes all of HTML Purifier's |
||||
files in one go in an opcode cache friendly manner: |
||||
|
||||
// If /path/to/library isn't already in your include path, uncomment |
||||
// the below line: |
||||
// require '/path/to/library/HTMLPurifier.path.php'; |
||||
|
||||
require 'HTMLPurifier.includes.php'; |
||||
|
||||
Optional components still need to be included--you'll know if you try to |
||||
use a feature and you get a class doesn't exists error! The autoloader |
||||
can be used in conjunction with this approach to catch classes that are |
||||
missing. Simply add this afterwards: |
||||
|
||||
require 'HTMLPurifier.autoload.php'; |
||||
|
||||
Standalone version |
||||
------------------ |
||||
|
||||
HTML Purifier has a standalone distribution; you can also generate |
||||
a standalone file from the full version by running the script |
||||
maintenance/generate-standalone.php . The standalone version has the |
||||
benefit of having most of its code in one file, so parsing is much |
||||
faster and the library is easier to manage. |
||||
|
||||
If HTMLPurifier.standalone.php exists in the library directory, you |
||||
can use it like this: |
||||
|
||||
require '/path/to/HTMLPurifier.standalone.php'; |
||||
|
||||
This is equivalent to including HTMLPurifier.includes.php, except that |
||||
the contents of standalone/ will be added to your path. To override this |
||||
behavior, specify a new HTMLPURIFIER_PREFIX where standalone files can |
||||
be found (usually, this will be one directory up, the "true" library |
||||
directory in full distributions). Don't forget to set your path too! |
||||
|
||||
The autoloader can be added to the end to ensure the classes are |
||||
loaded when necessary; otherwise you can manually include them. |
||||
To use the autoloader, use this: |
||||
|
||||
require 'HTMLPurifier.autoload.php'; |
||||
|
||||
For advanced users |
||||
------------------ |
||||
|
||||
HTMLPurifier.auto.php performs a number of operations that can be done |
||||
individually. These are: |
||||
|
||||
HTMLPurifier.path.php |
||||
Puts /path/to/library in the include path. For high performance, |
||||
this should be done in php.ini. |
||||
|
||||
HTMLPurifier.autoload.php |
||||
Registers our autoload handler HTMLPurifier_Bootstrap::autoload($class). |
||||
|
||||
You can do these operations by yourself--in fact, you must modify your own |
||||
autoload handler if you are using a version of PHP earlier than PHP 5.1.2 |
||||
(See "Autoload compatibility" above). |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
4. Configuration |
||||
|
||||
HTML Purifier is designed to run out-of-the-box, but occasionally HTML |
||||
Purifier needs to be told what to do. If you answer no to any of these |
||||
questions, read on; otherwise, you can skip to the next section (or, if you're |
||||
into configuring things just for the heck of it, skip to 4.3). |
||||
|
||||
* Am I using UTF-8? |
||||
* Am I using XHTML 1.0 Transitional? |
||||
|
||||
If you answered no to any of these questions, instantiate a configuration |
||||
object and read on: |
||||
|
||||
$config = HTMLPurifier_Config::createDefault(); |
||||
|
||||
|
||||
4.1. Setting a different character encoding |
||||
|
||||
You really shouldn't use any other encoding except UTF-8, especially if you |
||||
plan to support multilingual websites (read section three for more details). |
||||
However, switching to UTF-8 is not always immediately feasible, so we can |
||||
adapt. |
||||
|
||||
HTML Purifier uses iconv to support other character encodings, as such, |
||||
any encoding that iconv supports <http://www.gnu.org/software/libiconv/> |
||||
HTML Purifier supports with this code: |
||||
|
||||
$config->set('Core', 'Encoding', /* put your encoding here */); |
||||
|
||||
An example usage for Latin-1 websites (the most common encoding for English |
||||
websites): |
||||
|
||||
$config->set('Core', 'Encoding', 'ISO-8859-1'); |
||||
|
||||
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 |
||||
dropped, EVEN if it is ampersand escaped. If you want to work around |
||||
this, you are welcome to read docs/enduser-utf8.html for a fix, |
||||
but please be cognizant of the issues the "solution" creates (for this |
||||
reason, I do not include the solution in this document). |
||||
|
||||
|
||||
4.2. Setting a different doctype |
||||
|
||||
For those of you using HTML 4.01 Transitional, you can disable |
||||
XHTML output like this: |
||||
|
||||
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); |
||||
|
||||
Other supported doctypes include: |
||||
|
||||
* HTML 4.01 Strict |
||||
* HTML 4.01 Transitional |
||||
* XHTML 1.0 Strict |
||||
* XHTML 1.0 Transitional |
||||
* XHTML 1.1 |
||||
|
||||
|
||||
4.3. Other settings |
||||
|
||||
There are more configuration directives which can be read about |
||||
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 |
||||
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. |
||||
|
||||
For example, you can fine tune allowed elements and attributes, convert |
||||
relative URLs to absolute ones, and even autoparagraph input text! These |
||||
are, respectively, %HTML.Allowed, %URI.MakeAbsolute and %URI.Base, and |
||||
%AutoFormat.AutoParagraph. The %Namespace.Directive naming convention |
||||
translates to: |
||||
|
||||
$config->set('Namespace', 'Directive', $value); |
||||
|
||||
E.g. |
||||
|
||||
$config->set('HTML', 'Allowed', 'p,b,a[href],i'); |
||||
$config->set('URI', 'Base', 'http://www.example.com'); |
||||
$config->set('URI', 'MakeAbsolute', true); |
||||
$config->set('AutoFormat', 'AutoParagraph', true); |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
5. 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'); |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
6. Using the code |
||||
|
||||
The interface is mind-numbingly simple: |
||||
|
||||
$purifier = new HTMLPurifier(); |
||||
$clean_html = $purifier->purify( $dirty_html ); |
||||
|
||||
...or, if you're using the configuration object: |
||||
|
||||
$purifier = new HTMLPurifier($config); |
||||
$clean_html = $purifier->purify( $dirty_html ); |
||||
|
||||
That's it! For more examples, check out docs/examples/ (they aren't very |
||||
different though). Also, docs/enduser-slow.html gives advice on what to |
||||
do if HTML Purifier is slowing down your application. |
||||
|
||||
|
||||
--------------------------------------------------------------------------- |
||||
7. Quick install |
||||
|
||||
First, make sure library/HTMLPurifier/DefinitionCache/Serializer is |
||||
writable by the webserver (see Section 5: Caching above for details). |
||||
If your website is in UTF-8 and XHTML Transitional, use this code: |
||||
|
||||
<?php |
||||
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php'; |
||||
|
||||
$purifier = new HTMLPurifier(); |
||||
$clean_html = $purifier->purify($dirty_html); |
||||
?> |
||||
|
||||
If your website is in a different encoding or doctype, use this code: |
||||
|
||||
<?php |
||||
require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php'; |
||||
|
||||
$config = HTMLPurifier_Config::createDefault(); |
||||
$config->set('Core', 'Encoding', 'ISO-8859-1'); // replace with your encoding |
||||
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype |
||||
$purifier = new HTMLPurifier($config); |
||||
|
||||
$clean_html = $purifier->purify($dirty_html); |
||||
?> |
||||
|
||||
vim: et sw=4 sts=4 |
||||
@ -1,24 +0,0 @@ |
||||
|
||||
README |
||||
All about HTML Purifier |
||||
|
||||
HTML Purifier is an HTML filtering solution that uses a unique combination |
||||
of robust whitelists and agressive parsing to ensure that not only are |
||||
XSS attacks thwarted, but the resulting HTML is standards compliant. |
||||
|
||||
HTML Purifier is oriented towards richly formatted documents from |
||||
untrusted sources that require CSS and a full tag-set. This library can |
||||
be configured to accept a more restrictive set of tags, but it won't be |
||||
as efficient as more bare-bones parsers. It will, however, do the job |
||||
right, which may be more important. |
||||
|
||||
Places to go: |
||||
|
||||
* See INSTALL for a quick installation guide |
||||
* See docs/ for developer-oriented documentation, code examples and |
||||
an in-depth installation guide. |
||||
* See WYSIWYG for information on editors like TinyMCE and FCKeditor |
||||
|
||||
HTML Purifier can be found on the web at: http://htmlpurifier.org/ |
||||
|
||||
vim: et sw=4 sts=4 |
||||
@ -1 +0,0 @@ |
||||
3.3.0 |
||||
@ -1,20 +0,0 @@ |
||||
|
||||
WYSIWYG - What You See Is What You Get |
||||
HTML Purifier: A Pretty Good Fit for TinyMCE and FCKeditor |
||||
|
||||
Javascript-based WYSIWYG editors, simply stated, are quite amazing. But I've |
||||
always been wary about using them due to security issues: they handle the |
||||
client-side magic, but once you've been served a piping hot load of unfiltered |
||||
HTML, what should be done then? In some situations, you can serve it uncleaned, |
||||
since you only offer these facilities to trusted(?) authors. |
||||
|
||||
Unfortunantely, for blog comments and anonymous input, BBCode, Textile and |
||||
other markup languages still reign supreme. Put simply: filtering HTML is |
||||
hard work, and these WYSIWYG authors don't offer anything to alleviate that |
||||
trouble. Therein lies the solution: |
||||
|
||||
HTML Purifier is perfect for filtering pure-HTML input from WYSIWYG editors. |
||||
|
||||
Enough said. |
||||
|
||||
vim: et sw=4 sts=4 |
||||
@ -1,62 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Generates XML and HTML documents describing configuration. |
||||
* @note PHP 5.2+ only! |
||||
*/ |
||||
|
||||
/* |
||||
TODO: |
||||
- make XML format richer |
||||
- extend XSLT transformation (see the corresponding XSLT file) |
||||
- allow generation of packaged docs that can be easily moved |
||||
- multipage documentation |
||||
- determine how to multilingualize |
||||
- add blurbs to ToC |
||||
*/ |
||||
|
||||
if (version_compare(PHP_VERSION, '5.2', '<')) exit('PHP 5.2+ required.'); |
||||
error_reporting(E_ALL | E_STRICT); |
||||
|
||||
chdir(dirname(__FILE__)); |
||||
|
||||
// load dual-libraries |
||||
require_once '../extras/HTMLPurifierExtras.auto.php'; |
||||
require_once '../library/HTMLPurifier.auto.php'; |
||||
|
||||
// setup HTML Purifier singleton |
||||
HTMLPurifier::getInstance(array( |
||||
'AutoFormat.PurifierLinkify' => true |
||||
)); |
||||
|
||||
$interchange = HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory(); |
||||
$interchange->validate(); |
||||
|
||||
$style = 'plain'; // use $_GET in the future, careful to validate! |
||||
$configdoc_xml = 'configdoc.xml'; |
||||
|
||||
$xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml(); |
||||
$xml_builder->openURI($configdoc_xml); |
||||
$xml_builder->build($interchange); |
||||
unset($xml_builder); // free handle |
||||
|
||||
$xslt = new ConfigDoc_HTMLXSLTProcessor(); |
||||
$xslt->importStylesheet(dirname(__FILE__) . "/styles/$style.xsl"); |
||||
$output = $xslt->transformToHTML($configdoc_xml); |
||||
|
||||
if (!$output) { |
||||
echo "Error in generating files\n"; |
||||
exit(1); |
||||
} |
||||
|
||||
// write out |
||||
file_put_contents("$style.html", $output); |
||||
|
||||
if (php_sapi_name() != 'cli') { |
||||
// output (instant feedback if it's a browser) |
||||
echo $output; |
||||
} else { |
||||
echo 'Files generated successfully.'; |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,44 +0,0 @@ |
||||
|
||||
body {margin:0;padding:0;} |
||||
#content { |
||||
margin:1em auto; |
||||
max-width: 47em; |
||||
width: expression(document.body.clientWidth > |
||||
85 * parseInt(document.body.currentStyle.fontSize) ? |
||||
"54em": "auto"); |
||||
} |
||||
|
||||
table {border-collapse:collapse;} |
||||
table td, table th {padding:0.2em;} |
||||
|
||||
table.constraints {margin:0 0 1em;} |
||||
table.constraints th { |
||||
text-align:right;padding-left:0.4em;padding-right:0.4em;background:#EEE; |
||||
width:8em;vertical-align:top;} |
||||
table.constraints td {padding-right:0.4em; padding-left: 1em;} |
||||
table.constraints td ul {padding:0; margin:0; list-style:none;} |
||||
table.constraints td pre {margin:0;} |
||||
|
||||
#tocContainer {position:relative;} |
||||
#toc {list-style-type:none; font-weight:bold; font-size:1em; margin-bottom:1em;} |
||||
#toc li {position:relative; line-height: 1.2em;} |
||||
#toc .col-2 {margin-left:50%;} |
||||
#toc .col-l {float:left;} |
||||
#toc ul {list-style-type:disc; font-weight:normal; padding-bottom:1.2em;} |
||||
|
||||
.description p {margin-top:0;margin-bottom:1em;} |
||||
|
||||
#library, h1 {text-align:center; font-family:Garamond, serif; |
||||
font-variant:small-caps;} |
||||
#library {font-size:1em;} |
||||
h1 {margin-top:0;} |
||||
h2 {border-bottom:1px solid #CCC; font-family:sans-serif; font-weight:normal; |
||||
font-size:1.3em; clear:both;} |
||||
h3 {font-family:sans-serif; font-size:1.1em; font-weight:bold; } |
||||
h4 {font-family:sans-serif; font-size:0.9em; font-weight:bold; } |
||||
|
||||
.deprecated {color: #CCC;} |
||||
.deprecated table.constraints th {background:#FFF;} |
||||
.deprecated-notice {color: #000; text-align:center; margin-bottom: 1em;} |
||||
|
||||
/* vim: et sw=4 sts=4 */ |
||||
@ -1,235 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<xsl:stylesheet |
||||
version = "1.0" |
||||
xmlns = "http://www.w3.org/1999/xhtml" |
||||
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" |
||||
> |
||||
<xsl:output |
||||
method = "xml" |
||||
encoding = "UTF-8" |
||||
doctype-public = "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||||
doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" |
||||
indent = "no" |
||||
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')/types" /> |
||||
<xsl:variable name="usageLookup" select="document('../usage.xml')/usage" /> |
||||
|
||||
<!-- Twiddle this variable to get the columns as even as possible --> |
||||
<xsl:variable name="maxNumberAdjust" select="2" /> |
||||
|
||||
<xsl:template match="/"> |
||||
<html lang="en" xml:lang="en"> |
||||
<head> |
||||
<title><xsl:value-of select="$title" /> - <xsl:value-of select="/configdoc/title" /></title> |
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> |
||||
<link rel="stylesheet" type="text/css" href="{$css}" /> |
||||
</head> |
||||
<body> |
||||
<div id="content"> |
||||
<div id="library"><xsl:value-of select="/configdoc/title" /></div> |
||||
<h1><xsl:value-of select="$title" /></h1> |
||||
<div id="tocContainer"> |
||||
<h2>Table of Contents</h2> |
||||
<ul id="toc"> |
||||
<xsl:apply-templates mode="toc"> |
||||
<xsl:with-param name="overflowNumber" select="round(count(/configdoc/namespace) div 2) + $maxNumberAdjust" /> |
||||
</xsl:apply-templates> |
||||
</ul> |
||||
</div> |
||||
<xsl:apply-templates /> |
||||
</div> |
||||
</body> |
||||
</html> |
||||
</xsl:template> |
||||
|
||||
<xsl:template match="title" mode="toc" /> |
||||
<xsl:template match="namespace" mode="toc"> |
||||
<xsl:param name="overflowNumber" /> |
||||
<xsl:variable name="number"><xsl:number level="single" /></xsl:variable> |
||||
<xsl:variable name="directiveNumber"><xsl:number level="any" count="directive" /></xsl:variable> |
||||
<xsl:if test="count(directive)>0"> |
||||
<li> |
||||
<!-- BEGIN multicolumn code --> |
||||
<xsl:if test="$number >= $overflowNumber"> |
||||
<xsl:attribute name="class">col-2</xsl:attribute> |
||||
</xsl:if> |
||||
<xsl:if test="$number = $overflowNumber"> |
||||
<xsl:attribute name="style">margin-top:-<xsl:value-of select="($number * 2 + $directiveNumber - 3) * 1.2" />em</xsl:attribute> |
||||
</xsl:if> |
||||
<!-- END multicolumn code --> |
||||
<a href="#{@id}"><xsl:value-of select="name" /></a> |
||||
<ul> |
||||
<xsl:apply-templates select="directive" mode="toc"> |
||||
<xsl:with-param name="overflowNumber" select="$overflowNumber" /> |
||||
</xsl:apply-templates> |
||||
</ul> |
||||
<xsl:if test="$number + 1 = $overflowNumber"> |
||||
<div class="col-l" /> |
||||
</xsl:if> |
||||
</li> |
||||
</xsl:if> |
||||
</xsl:template> |
||||
<xsl:template match="directive" mode="toc"> |
||||
<xsl:variable name="number"> |
||||
<xsl:number level="any" count="directive|namespace" /> |
||||
</xsl:variable> |
||||
<xsl:if test="not(deprecated)"> |
||||
<li> |
||||
<a href="#{@id}"><xsl:value-of select="name" /></a> |
||||
</li> |
||||
</xsl:if> |
||||
</xsl:template> |
||||
|
||||
<xsl:template match="title" /> |
||||
|
||||
<xsl:template match="namespace"> |
||||
<div class="namespace"> |
||||
<xsl:apply-templates /> |
||||
<xsl:if test="count(directive)=0"> |
||||
<p>No configuration directives defined for this namespace.</p> |
||||
</xsl:if> |
||||
</div> |
||||
</xsl:template> |
||||
<xsl:template match="namespace/name"> |
||||
<h2 id="{../@id}"><xsl:value-of select="." /></h2> |
||||
</xsl:template> |
||||
<xsl:template match="namespace/description"> |
||||
<div class="description"> |
||||
<xsl:copy-of xmlns:xhtml="http://www.w3.org/1999/xhtml" select="xhtml:div/node()" /> |
||||
</div> |
||||
</xsl:template> |
||||
|
||||
<xsl:template match="directive"> |
||||
<div> |
||||
<xsl:attribute name="class"><!-- |
||||
-->directive<!-- |
||||
--><xsl:if test="deprecated"> deprecated</xsl:if><!-- |
||||
--></xsl:attribute> |
||||
<xsl:apply-templates> |
||||
<xsl:with-param name="id" select="@id" /> |
||||
</xsl:apply-templates> |
||||
</div> |
||||
</xsl:template> |
||||
<xsl:template match="directive/name"> |
||||
<xsl:param name="id" /> |
||||
<xsl:apply-templates select="../aliases/alias" mode="anchor" /> |
||||
<h3 id="{$id}"><xsl:value-of select="$id" /></h3> |
||||
</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:param name="id" /> |
||||
<table class="constraints"> |
||||
<xsl:apply-templates /> |
||||
<xsl:if test="../aliases/alias"> |
||||
<xsl:apply-templates select="../aliases" mode="constraints" /> |
||||
</xsl:if> |
||||
<xsl:apply-templates select="$usageLookup/directive[@id=$id]" /> |
||||
</table> |
||||
</xsl:template> |
||||
<xsl:template match="directive/aliases" mode="constraints"> |
||||
<tr> |
||||
<th>Aliases</th> |
||||
<td> |
||||
<xsl:for-each select="alias"> |
||||
<xsl:if test="position()>1">, </xsl:if> |
||||
<xsl:value-of select="." /> |
||||
</xsl:for-each> |
||||
</td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="directive/description"> |
||||
<div class="description"> |
||||
<xsl:copy-of xmlns:xhtml="http://www.w3.org/1999/xhtml" select="xhtml:div/node()" /> |
||||
</div> |
||||
</xsl:template> |
||||
<xsl:template match="directive/deprecated"> |
||||
<div class="deprecated-notice"> |
||||
<strong>Warning:</strong> |
||||
This directive was deprecated in version <xsl:value-of select="version" />. |
||||
<a href="#{use}">%<xsl:value-of select="use" /></a> should be used instead. |
||||
</div> |
||||
</xsl:template> |
||||
<xsl:template match="usage/directive"> |
||||
<tr> |
||||
<th>Used in</th> |
||||
<td> |
||||
<ul> |
||||
<xsl:apply-templates /> |
||||
</ul> |
||||
</td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="usage/directive/file"> |
||||
<li> |
||||
<em><xsl:value-of select="@name" /></em> on line<xsl:if test="count(line)>1">s</xsl:if> |
||||
<xsl:text> </xsl:text> |
||||
<xsl:for-each select="line"> |
||||
<xsl:if test="position()>1">, </xsl:if> |
||||
<xsl:value-of select="." /> |
||||
</xsl:for-each> |
||||
</li> |
||||
</xsl:template> |
||||
|
||||
<xsl:template match="constraints/version"> |
||||
<tr> |
||||
<th>Version added</th> |
||||
<td><xsl:value-of select="." /></td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="constraints/type"> |
||||
<tr> |
||||
<th>Type</th> |
||||
<td> |
||||
<xsl:variable name="type" select="text()" /> |
||||
<xsl:attribute name="class">type type-<xsl:value-of select="$type" /></xsl:attribute> |
||||
<xsl:value-of select="$typeLookup/type[@id=$type]/text()" /> |
||||
<xsl:if test="@allow-null='yes'"> |
||||
(or null) |
||||
</xsl:if> |
||||
</td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="constraints/allowed"> |
||||
<tr> |
||||
<th>Allowed values</th> |
||||
<td> |
||||
<xsl:for-each select="value"><!-- |
||||
--><xsl:if test="position()>1">, </xsl:if> |
||||
"<xsl:value-of select="." />"<!-- |
||||
--></xsl:for-each> |
||||
</td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="constraints/default"> |
||||
<tr> |
||||
<th>Default</th> |
||||
<td><pre><xsl:value-of select="." xml:space="preserve" /></pre></td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="constraints/external"> |
||||
<tr> |
||||
<th>External deps</th> |
||||
<td> |
||||
<ul> |
||||
<xsl:apply-templates /> |
||||
</ul> |
||||
</td> |
||||
</tr> |
||||
</xsl:template> |
||||
<xsl:template match="constraints/external/project"> |
||||
<li><xsl:value-of select="." /></li> |
||||
</xsl:template> |
||||
|
||||
</xsl:stylesheet> |
||||
|
||||
<!-- vim: et sw=4 sts=4 --> |
||||
@ -1,16 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<types> |
||||
<type id="string">String</type> |
||||
<type id="istring">Case-insensitive string</type> |
||||
<type id="text">Text</type> |
||||
<type id="itext">Case-insensitive text</type> |
||||
<type id="int">Integer</type> |
||||
<type id="float">Float</type> |
||||
<type id="bool">Boolean</type> |
||||
<type id="lookup">Lookup array</type> |
||||
<type id="list">Array list</type> |
||||
<type id="hash">Associative array</type> |
||||
<type id="mixed">Mixed</type> |
||||
</types> |
||||
|
||||
<!-- vim: et sw=4 sts=4 --> |
||||
@ -1,402 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<usage> |
||||
<directive id="Core.CollectErrors"> |
||||
<file name="HTMLPurifier.php"> |
||||
<line>131</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Lexer.php"> |
||||
<line>81</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Lexer/DirectLex.php"> |
||||
<line>53</line> |
||||
<line>73</line> |
||||
<line>348</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>47</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="CSS.MaxImgLength"> |
||||
<file name="HTMLPurifier/CSSDefinition.php"> |
||||
<line>157</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="CSS.Proprietary"> |
||||
<file name="HTMLPurifier/CSSDefinition.php"> |
||||
<line>214</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="CSS.AllowTricky"> |
||||
<file name="HTMLPurifier/CSSDefinition.php"> |
||||
<line>218</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="CSS.AllowImportant"> |
||||
<file name="HTMLPurifier/CSSDefinition.php"> |
||||
<line>222</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="CSS.AllowedProperties"> |
||||
<file name="HTMLPurifier/CSSDefinition.php"> |
||||
<line>275</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Cache.DefinitionImpl"> |
||||
<file name="HTMLPurifier/DefinitionCacheFactory.php"> |
||||
<line>49</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Doctype"> |
||||
<file name="HTMLPurifier/DoctypeRegistry.php"> |
||||
<line>83</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.CustomDoctype"> |
||||
<file name="HTMLPurifier/DoctypeRegistry.php"> |
||||
<line>85</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.XHTML"> |
||||
<file name="HTMLPurifier/DoctypeRegistry.php"> |
||||
<line>88</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Strict"> |
||||
<file name="HTMLPurifier/DoctypeRegistry.php"> |
||||
<line>93</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.Encoding"> |
||||
<file name="HTMLPurifier/Encoder.php"> |
||||
<line>267</line> |
||||
<line>300</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Test.ForceNoIconv"> |
||||
<file name="HTMLPurifier/Encoder.php"> |
||||
<line>272</line> |
||||
<line>308</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.EscapeNonASCIICharacters"> |
||||
<file name="HTMLPurifier/Encoder.php"> |
||||
<line>304</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Output.CommentScriptContents"> |
||||
<file name="HTMLPurifier/Generator.php"> |
||||
<line>45</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Output.SortAttr"> |
||||
<file name="HTMLPurifier/Generator.php"> |
||||
<line>46</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Output.TidyFormat"> |
||||
<file name="HTMLPurifier/Generator.php"> |
||||
<line>75</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Output.Newline"> |
||||
<file name="HTMLPurifier/Generator.php"> |
||||
<line>89</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.BlockWrapper"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>222</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Parent"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>230</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.AllowedElements"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>247</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.AllowedAttributes"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>248</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Allowed"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>251</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.ForbiddenElements"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>337</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.ForbiddenAttributes"> |
||||
<file name="HTMLPurifier/HTMLDefinition.php"> |
||||
<line>338</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Trusted"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>202</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Lexer.php"> |
||||
<line>258</line> |
||||
</file> |
||||
<file name="HTMLPurifier/HTMLModule/Image.php"> |
||||
<line>27</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Lexer/DirectLex.php"> |
||||
<line>36</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>23</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.AllowedModules"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>209</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.CoreModules"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>210</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.Proprietary"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>221</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.SafeObject"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>226</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.SafeEmbed"> |
||||
<file name="HTMLPurifier/HTMLModuleManager.php"> |
||||
<line>229</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.IDBlacklist"> |
||||
<file name="HTMLPurifier/IDAccumulator.php"> |
||||
<line>26</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.Language"> |
||||
<file name="HTMLPurifier/LanguageFactory.php"> |
||||
<line>88</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.LexerImpl"> |
||||
<file name="HTMLPurifier/Lexer.php"> |
||||
<line>76</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.MaintainLineNumbers"> |
||||
<file name="HTMLPurifier/Lexer.php"> |
||||
<line>80</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Lexer/DirectLex.php"> |
||||
<line>48</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.ConvertDocumentToFragment"> |
||||
<file name="HTMLPurifier/Lexer.php"> |
||||
<line>267</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.Host"> |
||||
<file name="HTMLPurifier/URIDefinition.php"> |
||||
<line>64</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.Base"> |
||||
<file name="HTMLPurifier/URIDefinition.php"> |
||||
<line>65</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.DefaultScheme"> |
||||
<file name="HTMLPurifier/URIDefinition.php"> |
||||
<line>72</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.AllowedSchemes"> |
||||
<file name="HTMLPurifier/URISchemeRegistry.php"> |
||||
<line>42</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.OverrideAllowedSchemes"> |
||||
<file name="HTMLPurifier/URISchemeRegistry.php"> |
||||
<line>43</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.Disable"> |
||||
<file name="HTMLPurifier/AttrDef/URI.php"> |
||||
<line>28</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.ColorKeywords"> |
||||
<file name="HTMLPurifier/AttrDef/CSS/Color.php"> |
||||
<line>12</line> |
||||
</file> |
||||
<file name="HTMLPurifier/AttrDef/HTML/Color.php"> |
||||
<line>12</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.AllowedFrameTargets"> |
||||
<file name="HTMLPurifier/AttrDef/HTML/FrameTarget.php"> |
||||
<line>15</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.EnableID"> |
||||
<file name="HTMLPurifier/AttrDef/HTML/ID.php"> |
||||
<line>20</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.IDPrefix"> |
||||
<file name="HTMLPurifier/AttrDef/HTML/ID.php"> |
||||
<line>26</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.IDPrefixLocal"> |
||||
<file name="HTMLPurifier/AttrDef/HTML/ID.php"> |
||||
<line>28</line> |
||||
<line>31</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.IDBlacklistRegexp"> |
||||
<file name="HTMLPurifier/AttrDef/HTML/ID.php"> |
||||
<line>54</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.DefaultTextDir"> |
||||
<file name="HTMLPurifier/AttrTransform/BdoDir.php"> |
||||
<line>13</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.RemoveInvalidImg"> |
||||
<file name="HTMLPurifier/AttrTransform/ImgRequired.php"> |
||||
<line>18</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>20</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.DefaultInvalidImage"> |
||||
<file name="HTMLPurifier/AttrTransform/ImgRequired.php"> |
||||
<line>19</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.DefaultImageAlt"> |
||||
<file name="HTMLPurifier/AttrTransform/ImgRequired.php"> |
||||
<line>25</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Attr.DefaultInvalidImageAlt"> |
||||
<file name="HTMLPurifier/AttrTransform/ImgRequired.php"> |
||||
<line>32</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.EscapeInvalidChildren"> |
||||
<file name="HTMLPurifier/ChildDef/Required.php"> |
||||
<line>62</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Cache.SerializerPath"> |
||||
<file name="HTMLPurifier/DefinitionCache/Serializer.php"> |
||||
<line>91</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="FilterParam.ExtractStyleBlocksTidyImpl"> |
||||
<file name="HTMLPurifier/Filter/ExtractStyleBlocks.php"> |
||||
<line>41</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="FilterParam.ExtractStyleBlocksScope"> |
||||
<file name="HTMLPurifier/Filter/ExtractStyleBlocks.php"> |
||||
<line>65</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="FilterParam.ExtractStyleBlocksEscaping"> |
||||
<file name="HTMLPurifier/Filter/ExtractStyleBlocks.php"> |
||||
<line>123</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.MaxImgLength"> |
||||
<file name="HTMLPurifier/HTMLModule/Image.php"> |
||||
<line>14</line> |
||||
</file> |
||||
<file name="HTMLPurifier/HTMLModule/SafeEmbed.php"> |
||||
<line>13</line> |
||||
</file> |
||||
<file name="HTMLPurifier/HTMLModule/SafeObject.php"> |
||||
<line>19</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.TidyLevel"> |
||||
<file name="HTMLPurifier/HTMLModule/Tidy.php"> |
||||
<line>45</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.TidyAdd"> |
||||
<file name="HTMLPurifier/HTMLModule/Tidy.php"> |
||||
<line>49</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="HTML.TidyRemove"> |
||||
<file name="HTMLPurifier/HTMLModule/Tidy.php"> |
||||
<line>50</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="AutoFormatParam.PurifierLinkifyDocURL"> |
||||
<file name="HTMLPurifier/Injector/PurifierLinkify.php"> |
||||
<line>15</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.AggressivelyFixLt"> |
||||
<file name="HTMLPurifier/Lexer/DOMLex.php"> |
||||
<line>44</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.DirectLexLineNumberSyncInterval"> |
||||
<file name="HTMLPurifier/Lexer/DirectLex.php"> |
||||
<line>70</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.EscapeInvalidTags"> |
||||
<file name="HTMLPurifier/Strategy/MakeWellFormed.php"> |
||||
<line>45</line> |
||||
</file> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>19</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.RemoveScriptContents"> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>25</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="Core.HiddenElements"> |
||||
<file name="HTMLPurifier/Strategy/RemoveForeignElements.php"> |
||||
<line>26</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.HostBlacklist"> |
||||
<file name="HTMLPurifier/URIFilter/HostBlacklist.php"> |
||||
<line>8</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.MungeResources"> |
||||
<file name="HTMLPurifier/URIFilter/Munge.php"> |
||||
<line>14</line> |
||||
</file> |
||||
</directive> |
||||
<directive id="URI.MungeSecretKey"> |
||||
<file name="HTMLPurifier/URIFilter/Munge.php"> |
||||
<line>15</line> |
||||
</file> |
||||
</directive> |
||||
</usage> |
||||
@ -1,86 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Decorator/extender XSLT processor specifically for HTML documents. |
||||
*/ |
||||
class ConfigDoc_HTMLXSLTProcessor |
||||
{ |
||||
|
||||
/** |
||||
* Instance of XSLTProcessor |
||||
*/ |
||||
protected $xsltProcessor; |
||||
|
||||
public function __construct($proc = false) { |
||||
if ($proc === false) $proc = new XSLTProcessor(); |
||||
$this->xsltProcessor = $proc; |
||||
} |
||||
|
||||
/** |
||||
* @note Allows a string $xsl filename to be passed |
||||
*/ |
||||
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 compatible XHTML based on the stylesheet |
||||
* @param $xml XML DOM tree, or string filename |
||||
* @return string HTML output |
||||
* @todo Rename to transformToXHTML, as transformToHTML is misleading |
||||
*/ |
||||
public function transformToHTML($xml) { |
||||
if (is_string($xml)) { |
||||
$dom = new DOMDocument(); |
||||
$dom->load($xml); |
||||
} else { |
||||
$dom = $xml; |
||||
} |
||||
$out = $this->xsltProcessor->transformToXML($dom); |
||||
|
||||
// fudges for HTML backwards compatibility |
||||
// assumes that document is XHTML |
||||
$out = str_replace('/>', ' />', $out); // <br /> not <br/> |
||||
$out = str_replace(' xmlns=""', '', $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; |
||||
} |
||||
|
||||
/** |
||||
* Bulk sets parameters for the XSL stylesheet |
||||
* @param array $options Associative array of options to set |
||||
*/ |
||||
public function setParameters($options) { |
||||
foreach ($options as $name => $value) { |
||||
$this->xsltProcessor->setParameter('', $name, $value); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Forward any other calls to the XSLT processor |
||||
*/ |
||||
public function __call($name, $arguments) { |
||||
call_user_func_array(array($this->xsltProcessor, $name), $arguments); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,157 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Filesystem tools not provided by default; can recursively create, copy |
||||
* and delete folders. Some template methods are provided for extensibility. |
||||
* |
||||
* @note This class must be instantiated to be used, although it does |
||||
* not maintain state. |
||||
*/ |
||||
class FSTools |
||||
{ |
||||
|
||||
private static $singleton; |
||||
|
||||
/** |
||||
* Returns a global instance of FSTools |
||||
*/ |
||||
static public function singleton() { |
||||
if (empty(FSTools::$singleton)) FSTools::$singleton = new FSTools(); |
||||
return FSTools::$singleton; |
||||
} |
||||
|
||||
/** |
||||
* Sets our global singleton to something else; useful for overloading |
||||
* functions. |
||||
*/ |
||||
static public function setSingleton($singleton) { |
||||
FSTools::$singleton = $singleton; |
||||
} |
||||
|
||||
/** |
||||
* Recursively creates a directory |
||||
* @param string $folder Name of folder to create |
||||
* @note Adapted from the PHP manual comment 76612 |
||||
*/ |
||||
public function mkdirr($folder) { |
||||
$folders = preg_split("#[\\\\/]#", $folder); |
||||
$base = ''; |
||||
for($i = 0, $c = count($folders); $i < $c; $i++) { |
||||
if(empty($folders[$i])) { |
||||
if (!$i) { |
||||
// special case for root level |
||||
$base .= DIRECTORY_SEPARATOR; |
||||
} |
||||
continue; |
||||
} |
||||
$base .= $folders[$i]; |
||||
if(!is_dir($base)){ |
||||
$this->mkdir($base); |
||||
} |
||||
$base .= DIRECTORY_SEPARATOR; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Copy a file, or recursively copy a folder and its contents; modified |
||||
* so that copied files, if PHP, have includes removed |
||||
* @note Adapted from http://aidanlister.com/repos/v/function.copyr.php |
||||
*/ |
||||
public function copyr($source, $dest) { |
||||
// Simple copy for a file |
||||
if (is_file($source)) { |
||||
return $this->copy($source, $dest); |
||||
} |
||||
// Make destination directory |
||||
if (!is_dir($dest)) { |
||||
$this->mkdir($dest); |
||||
} |
||||
// Loop through the folder |
||||
$dir = $this->dir($source); |
||||
while ( false !== ($entry = $dir->read()) ) { |
||||
// Skip pointers |
||||
if ($entry == '.' || $entry == '..') { |
||||
continue; |
||||
} |
||||
if (!$this->copyable($entry)) { |
||||
continue; |
||||
} |
||||
// Deep copy directories |
||||
if ($dest !== "$source/$entry") { |
||||
$this->copyr("$source/$entry", "$dest/$entry"); |
||||
} |
||||
} |
||||
// Clean up |
||||
$dir->close(); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Overloadable function that tests a filename for copyability. By |
||||
* default, everything should be copied; you can restrict things to |
||||
* ignore hidden files, unreadable files, etc. This function |
||||
* applies to copyr(). |
||||
*/ |
||||
public function copyable($file) { |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Delete a file, or a folder and its contents |
||||
* @note Adapted from http://aidanlister.com/repos/v/function.rmdirr.php |
||||
*/ |
||||
public function rmdirr($dirname) |
||||
{ |
||||
// Sanity check |
||||
if (!$this->file_exists($dirname)) { |
||||
return false; |
||||
} |
||||
|
||||
// Simple delete for a file |
||||
if ($this->is_file($dirname) || $this->is_link($dirname)) { |
||||
return $this->unlink($dirname); |
||||
} |
||||
|
||||
// Loop through the folder |
||||
$dir = $this->dir($dirname); |
||||
while (false !== $entry = $dir->read()) { |
||||
// Skip pointers |
||||
if ($entry == '.' || $entry == '..') { |
||||
continue; |
||||
} |
||||
// Recurse |
||||
$this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry); |
||||
} |
||||
|
||||
// Clean up |
||||
$dir->close(); |
||||
return $this->rmdir($dirname); |
||||
} |
||||
|
||||
/** |
||||
* Recursively globs a directory. |
||||
*/ |
||||
public function globr($dir, $pattern, $flags = NULL) { |
||||
$files = $this->glob("$dir/$pattern", $flags); |
||||
if ($files === false) $files = array(); |
||||
$sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR); |
||||
if ($sub_dirs === false) $sub_dirs = array(); |
||||
foreach ($sub_dirs as $sub_dir) { |
||||
$sub_files = $this->globr($sub_dir, $pattern, $flags); |
||||
$files = array_merge($files, $sub_files); |
||||
} |
||||
return $files; |
||||
} |
||||
|
||||
/** |
||||
* Allows for PHP functions to be called and be stubbed. |
||||
* @warning This function will not work for functions that need |
||||
* to pass references; manually define a stub function for those. |
||||
*/ |
||||
public function __call($name, $args) { |
||||
return call_user_func_array($name, $args); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,126 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Represents a file in the filesystem |
||||
* |
||||
* @warning Be sure to distinguish between get() and write() versus |
||||
* read() and put(), the former operates on the entire file, while |
||||
* the latter operates on a handle. |
||||
*/ |
||||
class FSTools_File |
||||
{ |
||||
|
||||
/** Filename of file this object represents */ |
||||
protected $name; |
||||
|
||||
/** Handle for the file */ |
||||
protected $handle = false; |
||||
|
||||
/** Instance of FSTools for interfacing with filesystem */ |
||||
protected $fs; |
||||
|
||||
/** |
||||
* Filename of file you wish to instantiate. |
||||
* @note This file need not exist |
||||
*/ |
||||
public function __construct($name, $fs = false) { |
||||
$this->name = $name; |
||||
$this->fs = $fs ? $fs : FSTools::singleton(); |
||||
} |
||||
|
||||
/** Returns the filename of the file. */ |
||||
public function getName() {return $this->name;} |
||||
|
||||
/** Returns directory of the file without trailing slash */ |
||||
public function getDirectory() {return $this->fs->dirname($this->name);} |
||||
|
||||
/** |
||||
* Retrieves the contents of a file |
||||
* @todo Throw an exception if file doesn't exist |
||||
*/ |
||||
public function get() { |
||||
return $this->fs->file_get_contents($this->name); |
||||
} |
||||
|
||||
/** Writes contents to a file, creates new file if necessary */ |
||||
public function write($contents) { |
||||
return $this->fs->file_put_contents($this->name, $contents); |
||||
} |
||||
|
||||
/** Deletes the file */ |
||||
public function delete() { |
||||
return $this->fs->unlink($this->name); |
||||
} |
||||
|
||||
/** Returns true if file exists and is a file. */ |
||||
public function exists() { |
||||
return $this->fs->is_file($this->name); |
||||
} |
||||
|
||||
/** Returns last file modification time */ |
||||
public function getMTime() { |
||||
return $this->fs->filemtime($this->name); |
||||
} |
||||
|
||||
/** |
||||
* Chmod a file |
||||
* @note We ignore errors because of some weird owner trickery due |
||||
* to SVN duality |
||||
*/ |
||||
public function chmod($octal_code) { |
||||
return @$this->fs->chmod($this->name, $octal_code); |
||||
} |
||||
|
||||
/** Opens file's handle */ |
||||
public function open($mode) { |
||||
if ($this->handle) $this->close(); |
||||
$this->handle = $this->fs->fopen($this->name, $mode); |
||||
return true; |
||||
} |
||||
|
||||
/** Closes file's handle */ |
||||
public function close() { |
||||
if (!$this->handle) return false; |
||||
$status = $this->fs->fclose($this->handle); |
||||
$this->handle = false; |
||||
return $status; |
||||
} |
||||
|
||||
/** Retrieves a line from an open file, with optional max length $length */ |
||||
public function getLine($length = null) { |
||||
if (!$this->handle) $this->open('r'); |
||||
if ($length === null) return $this->fs->fgets($this->handle); |
||||
else return $this->fs->fgets($this->handle, $length); |
||||
} |
||||
|
||||
/** Retrieves a character from an open file */ |
||||
public function getChar() { |
||||
if (!$this->handle) $this->open('r'); |
||||
return $this->fs->fgetc($this->handle); |
||||
} |
||||
|
||||
/** Retrieves an $length bytes of data from an open data */ |
||||
public function read($length) { |
||||
if (!$this->handle) $this->open('r'); |
||||
return $this->fs->fread($this->handle, $length); |
||||
} |
||||
|
||||
/** Writes to an open file */ |
||||
public function put($string) { |
||||
if (!$this->handle) $this->open('a'); |
||||
return $this->fs->fwrite($this->handle, $string); |
||||
} |
||||
|
||||
/** Returns TRUE if the end of the file has been reached */ |
||||
public function eof() { |
||||
if (!$this->handle) return true; |
||||
return $this->fs->feof($this->handle); |
||||
} |
||||
|
||||
public function __destruct() { |
||||
if ($this->handle) $this->close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,11 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This is a stub include that automatically configures the include path. |
||||
*/ |
||||
|
||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); |
||||
require_once 'HTMLPurifierExtras.php'; |
||||
require_once 'HTMLPurifierExtras.autoload.php'; |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,25 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Convenience file that registers autoload handler for HTML Purifier. |
||||
* |
||||
* @warning |
||||
* This autoloader does not contain the compatibility code seen in |
||||
* HTMLPurifier_Bootstrap; the user is expected to make any necessary |
||||
* changes to use this library. |
||||
*/ |
||||
|
||||
if (function_exists('spl_autoload_register')) { |
||||
spl_autoload_register(array('HTMLPurifierExtras', 'autoload')); |
||||
if (function_exists('__autoload')) { |
||||
// Be polite and ensure that userland autoload gets retained |
||||
spl_autoload_register('__autoload'); |
||||
} |
||||
} elseif (!function_exists('__autoload')) { |
||||
function __autoload($class) { |
||||
return HTMLPurifierExtras::autoload($class); |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,29 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Meta-class for HTML Purifier's extra class hierarchies, similar to |
||||
* HTMLPurifier_Bootstrap. |
||||
*/ |
||||
class HTMLPurifierExtras |
||||
{ |
||||
|
||||
public static function autoload($class) { |
||||
$path = HTMLPurifierExtras::getPath($class); |
||||
if (!$path) return false; |
||||
require $path; |
||||
return true; |
||||
} |
||||
|
||||
public static function getPath($class) { |
||||
if ( |
||||
strncmp('FSTools', $class, 7) !== 0 && |
||||
strncmp('ConfigDoc', $class, 9) !== 0 |
||||
) return false; |
||||
// Custom implementations can go here |
||||
// Standard implementation: |
||||
return str_replace('_', '/', $class) . '.php'; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,32 +0,0 @@ |
||||
|
||||
HTML Purifier Extras |
||||
The Method Behind The Madness! |
||||
|
||||
The extras/ folder in HTML Purifier contains--you guessed it--extra things |
||||
for HTML Purifier. Specifically, these are two extra libraries called |
||||
FSTools and ConfigSchema. They're extra for a reason: you don't need them |
||||
if you're using HTML Purifier for normal usage: filtering HTML. However, |
||||
if you're a developer, and would like to test HTML Purifier, or need to |
||||
use one of HTML Purifier's maintenance scripts, chances are they'll need |
||||
these libraries. Who knows: maybe you'll find them useful too! |
||||
|
||||
Here are the libraries: |
||||
|
||||
|
||||
FSTools |
||||
------- |
||||
|
||||
Short for File System Tools, this is a poor-man's object-oriented wrapper for |
||||
the filesystem. It currently consists of two classes: |
||||
|
||||
- FSTools: This is a singleton that contains a manner of useful functions |
||||
such as recursive glob, directory removal, etc, as well as the ability |
||||
to call arbitrary native PHP functions through it like $FS->fopen(...). |
||||
This makes it a lot simpler to mock these filesystem calls for unit testing. |
||||
|
||||
- FSTools_File: This object represents a single file, and has almost any |
||||
method imaginable one would need. |
||||
|
||||
Check the files themselves for more information. |
||||
|
||||
vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,11 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This is a stub include that automatically configures the include path. |
||||
*/ |
||||
|
||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); |
||||
require_once 'HTMLPurifier/Bootstrap.php'; |
||||
require_once 'HTMLPurifier.autoload.php'; |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,21 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Convenience file that registers autoload handler for HTML Purifier. |
||||
*/ |
||||
|
||||
if (function_exists('spl_autoload_register') && function_exists('spl_autoload_unregister')) { |
||||
// We need unregister for our pre-registering functionality |
||||
HTMLPurifier_Bootstrap::registerAutoload(); |
||||
if (function_exists('__autoload')) { |
||||
// Be polite and ensure that userland autoload gets retained |
||||
spl_autoload_register('__autoload'); |
||||
} |
||||
} elseif (!function_exists('__autoload')) { |
||||
function __autoload($class) { |
||||
return HTMLPurifier_Bootstrap::autoload($class); |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,23 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Defines a function wrapper for HTML Purifier for quick use. |
||||
* @note ''HTMLPurifier()'' is NOT the same as ''new HTMLPurifier()'' |
||||
*/ |
||||
|
||||
/** |
||||
* Purify HTML. |
||||
* @param $html String HTML to purify |
||||
* @param $config Configuration to use, can be any value accepted by |
||||
* HTMLPurifier_Config::create() |
||||
*/ |
||||
function HTMLPurifier($html, $config = null) { |
||||
static $purifier = false; |
||||
if (!$purifier) { |
||||
$purifier = new HTMLPurifier(); |
||||
} |
||||
return $purifier->purify($html, $config); |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,206 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* This file was auto-generated by generate-includes.php and includes all of |
||||
* the core files required by HTML Purifier. Use this if performance is a |
||||
* primary concern and you are using an opcode cache. PLEASE DO NOT EDIT THIS |
||||
* FILE, changes will be overwritten the next time the script is run. |
||||
* |
||||
* @version 3.3.0 |
||||
* |
||||
* @warning |
||||
* You must *not* include any other HTML Purifier files before this file, |
||||
* because 'require' not 'require_once' is used. |
||||
* |
||||
* @warning |
||||
* This file requires that the include path contains the HTML Purifier |
||||
* library directory; this is not auto-set. |
||||
*/ |
||||
|
||||
require 'HTMLPurifier.php'; |
||||
require 'HTMLPurifier/AttrCollections.php'; |
||||
require 'HTMLPurifier/AttrDef.php'; |
||||
require 'HTMLPurifier/AttrTransform.php'; |
||||
require 'HTMLPurifier/AttrTypes.php'; |
||||
require 'HTMLPurifier/AttrValidator.php'; |
||||
require 'HTMLPurifier/Bootstrap.php'; |
||||
require 'HTMLPurifier/Definition.php'; |
||||
require 'HTMLPurifier/CSSDefinition.php'; |
||||
require 'HTMLPurifier/ChildDef.php'; |
||||
require 'HTMLPurifier/Config.php'; |
||||
require 'HTMLPurifier/ConfigSchema.php'; |
||||
require 'HTMLPurifier/ContentSets.php'; |
||||
require 'HTMLPurifier/Context.php'; |
||||
require 'HTMLPurifier/DefinitionCache.php'; |
||||
require 'HTMLPurifier/DefinitionCacheFactory.php'; |
||||
require 'HTMLPurifier/Doctype.php'; |
||||
require 'HTMLPurifier/DoctypeRegistry.php'; |
||||
require 'HTMLPurifier/ElementDef.php'; |
||||
require 'HTMLPurifier/Encoder.php'; |
||||
require 'HTMLPurifier/EntityLookup.php'; |
||||
require 'HTMLPurifier/EntityParser.php'; |
||||
require 'HTMLPurifier/ErrorCollector.php'; |
||||
require 'HTMLPurifier/ErrorStruct.php'; |
||||
require 'HTMLPurifier/Exception.php'; |
||||
require 'HTMLPurifier/Filter.php'; |
||||
require 'HTMLPurifier/Generator.php'; |
||||
require 'HTMLPurifier/HTMLDefinition.php'; |
||||
require 'HTMLPurifier/HTMLModule.php'; |
||||
require 'HTMLPurifier/HTMLModuleManager.php'; |
||||
require 'HTMLPurifier/IDAccumulator.php'; |
||||
require 'HTMLPurifier/Injector.php'; |
||||
require 'HTMLPurifier/Language.php'; |
||||
require 'HTMLPurifier/LanguageFactory.php'; |
||||
require 'HTMLPurifier/Length.php'; |
||||
require 'HTMLPurifier/Lexer.php'; |
||||
require 'HTMLPurifier/PercentEncoder.php'; |
||||
require 'HTMLPurifier/PropertyList.php'; |
||||
require 'HTMLPurifier/PropertyListIterator.php'; |
||||
require 'HTMLPurifier/Strategy.php'; |
||||
require 'HTMLPurifier/StringHash.php'; |
||||
require 'HTMLPurifier/StringHashParser.php'; |
||||
require 'HTMLPurifier/TagTransform.php'; |
||||
require 'HTMLPurifier/Token.php'; |
||||
require 'HTMLPurifier/TokenFactory.php'; |
||||
require 'HTMLPurifier/URI.php'; |
||||
require 'HTMLPurifier/URIDefinition.php'; |
||||
require 'HTMLPurifier/URIFilter.php'; |
||||
require 'HTMLPurifier/URIParser.php'; |
||||
require 'HTMLPurifier/URIScheme.php'; |
||||
require 'HTMLPurifier/URISchemeRegistry.php'; |
||||
require 'HTMLPurifier/UnitConverter.php'; |
||||
require 'HTMLPurifier/VarParser.php'; |
||||
require 'HTMLPurifier/VarParserException.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS.php'; |
||||
require 'HTMLPurifier/AttrDef/Enum.php'; |
||||
require 'HTMLPurifier/AttrDef/Integer.php'; |
||||
require 'HTMLPurifier/AttrDef/Lang.php'; |
||||
require 'HTMLPurifier/AttrDef/Switch.php'; |
||||
require 'HTMLPurifier/AttrDef/Text.php'; |
||||
require 'HTMLPurifier/AttrDef/URI.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Number.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/AlphaValue.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Background.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/BackgroundPosition.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Border.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Color.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Composite.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Filter.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Font.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/FontFamily.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/ImportantDecorator.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Length.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/ListStyle.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Multiple.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/Percentage.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/TextDecoration.php'; |
||||
require 'HTMLPurifier/AttrDef/CSS/URI.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/Bool.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/Color.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/FrameTarget.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/ID.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/Pixels.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/Length.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/LinkTypes.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/MultiLength.php'; |
||||
require 'HTMLPurifier/AttrDef/HTML/Nmtokens.php'; |
||||
require 'HTMLPurifier/AttrDef/URI/Email.php'; |
||||
require 'HTMLPurifier/AttrDef/URI/Host.php'; |
||||
require 'HTMLPurifier/AttrDef/URI/IPv4.php'; |
||||
require 'HTMLPurifier/AttrDef/URI/IPv6.php'; |
||||
require 'HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php'; |
||||
require 'HTMLPurifier/AttrTransform/Background.php'; |
||||
require 'HTMLPurifier/AttrTransform/BdoDir.php'; |
||||
require 'HTMLPurifier/AttrTransform/BgColor.php'; |
||||
require 'HTMLPurifier/AttrTransform/BoolToCSS.php'; |
||||
require 'HTMLPurifier/AttrTransform/Border.php'; |
||||
require 'HTMLPurifier/AttrTransform/EnumToCSS.php'; |
||||
require 'HTMLPurifier/AttrTransform/ImgRequired.php'; |
||||
require 'HTMLPurifier/AttrTransform/ImgSpace.php'; |
||||
require 'HTMLPurifier/AttrTransform/Input.php'; |
||||
require 'HTMLPurifier/AttrTransform/Lang.php'; |
||||
require 'HTMLPurifier/AttrTransform/Length.php'; |
||||
require 'HTMLPurifier/AttrTransform/Name.php'; |
||||
require 'HTMLPurifier/AttrTransform/SafeEmbed.php'; |
||||
require 'HTMLPurifier/AttrTransform/SafeObject.php'; |
||||
require 'HTMLPurifier/AttrTransform/SafeParam.php'; |
||||
require 'HTMLPurifier/AttrTransform/ScriptRequired.php'; |
||||
require 'HTMLPurifier/AttrTransform/Textarea.php'; |
||||
require 'HTMLPurifier/ChildDef/Chameleon.php'; |
||||
require 'HTMLPurifier/ChildDef/Custom.php'; |
||||
require 'HTMLPurifier/ChildDef/Empty.php'; |
||||
require 'HTMLPurifier/ChildDef/Required.php'; |
||||
require 'HTMLPurifier/ChildDef/Optional.php'; |
||||
require 'HTMLPurifier/ChildDef/StrictBlockquote.php'; |
||||
require 'HTMLPurifier/ChildDef/Table.php'; |
||||
require 'HTMLPurifier/DefinitionCache/Decorator.php'; |
||||
require 'HTMLPurifier/DefinitionCache/Null.php'; |
||||
require 'HTMLPurifier/DefinitionCache/Serializer.php'; |
||||
require 'HTMLPurifier/DefinitionCache/Decorator/Cleanup.php'; |
||||
require 'HTMLPurifier/DefinitionCache/Decorator/Memory.php'; |
||||
require 'HTMLPurifier/HTMLModule/Bdo.php'; |
||||
require 'HTMLPurifier/HTMLModule/CommonAttributes.php'; |
||||
require 'HTMLPurifier/HTMLModule/Edit.php'; |
||||
require 'HTMLPurifier/HTMLModule/Forms.php'; |
||||
require 'HTMLPurifier/HTMLModule/Hypertext.php'; |
||||
require 'HTMLPurifier/HTMLModule/Image.php'; |
||||
require 'HTMLPurifier/HTMLModule/Legacy.php'; |
||||
require 'HTMLPurifier/HTMLModule/List.php'; |
||||
require 'HTMLPurifier/HTMLModule/Name.php'; |
||||
require 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php'; |
||||
require 'HTMLPurifier/HTMLModule/Object.php'; |
||||
require 'HTMLPurifier/HTMLModule/Presentation.php'; |
||||
require 'HTMLPurifier/HTMLModule/Proprietary.php'; |
||||
require 'HTMLPurifier/HTMLModule/Ruby.php'; |
||||
require 'HTMLPurifier/HTMLModule/SafeEmbed.php'; |
||||
require 'HTMLPurifier/HTMLModule/SafeObject.php'; |
||||
require 'HTMLPurifier/HTMLModule/Scripting.php'; |
||||
require 'HTMLPurifier/HTMLModule/StyleAttribute.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tables.php'; |
||||
require 'HTMLPurifier/HTMLModule/Target.php'; |
||||
require 'HTMLPurifier/HTMLModule/Text.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy.php'; |
||||
require 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/Name.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/Proprietary.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/Strict.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/Transitional.php'; |
||||
require 'HTMLPurifier/HTMLModule/Tidy/XHTML.php'; |
||||
require 'HTMLPurifier/Injector/AutoParagraph.php'; |
||||
require 'HTMLPurifier/Injector/DisplayLinkURI.php'; |
||||
require 'HTMLPurifier/Injector/Linkify.php'; |
||||
require 'HTMLPurifier/Injector/PurifierLinkify.php'; |
||||
require 'HTMLPurifier/Injector/RemoveEmpty.php'; |
||||
require 'HTMLPurifier/Injector/SafeObject.php'; |
||||
require 'HTMLPurifier/Lexer/DOMLex.php'; |
||||
require 'HTMLPurifier/Lexer/DirectLex.php'; |
||||
require 'HTMLPurifier/Strategy/Composite.php'; |
||||
require 'HTMLPurifier/Strategy/Core.php'; |
||||
require 'HTMLPurifier/Strategy/FixNesting.php'; |
||||
require 'HTMLPurifier/Strategy/MakeWellFormed.php'; |
||||
require 'HTMLPurifier/Strategy/RemoveForeignElements.php'; |
||||
require 'HTMLPurifier/Strategy/ValidateAttributes.php'; |
||||
require 'HTMLPurifier/TagTransform/Font.php'; |
||||
require 'HTMLPurifier/TagTransform/Simple.php'; |
||||
require 'HTMLPurifier/Token/Comment.php'; |
||||
require 'HTMLPurifier/Token/Tag.php'; |
||||
require 'HTMLPurifier/Token/Empty.php'; |
||||
require 'HTMLPurifier/Token/End.php'; |
||||
require 'HTMLPurifier/Token/Start.php'; |
||||
require 'HTMLPurifier/Token/Text.php'; |
||||
require 'HTMLPurifier/URIFilter/DisableExternal.php'; |
||||
require 'HTMLPurifier/URIFilter/DisableExternalResources.php'; |
||||
require 'HTMLPurifier/URIFilter/HostBlacklist.php'; |
||||
require 'HTMLPurifier/URIFilter/MakeAbsolute.php'; |
||||
require 'HTMLPurifier/URIFilter/Munge.php'; |
||||
require 'HTMLPurifier/URIScheme/ftp.php'; |
||||
require 'HTMLPurifier/URIScheme/http.php'; |
||||
require 'HTMLPurifier/URIScheme/https.php'; |
||||
require 'HTMLPurifier/URIScheme/mailto.php'; |
||||
require 'HTMLPurifier/URIScheme/news.php'; |
||||
require 'HTMLPurifier/URIScheme/nntp.php'; |
||||
require 'HTMLPurifier/VarParser/Flexible.php'; |
||||
require 'HTMLPurifier/VarParser/Native.php'; |
||||
@ -1,30 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Emulation layer for code that used kses(), substituting in HTML Purifier. |
||||
*/ |
||||
|
||||
require_once dirname(__FILE__) . '/HTMLPurifier.auto.php'; |
||||
|
||||
function kses($string, $allowed_html, $allowed_protocols = null) { |
||||
$config = HTMLPurifier_Config::createDefault(); |
||||
$allowed_elements = array(); |
||||
$allowed_attributes = array(); |
||||
foreach ($allowed_html as $element => $attributes) { |
||||
$allowed_elements[$element] = true; |
||||
foreach ($attributes as $attribute => $x) { |
||||
$allowed_attributes["$element.$attribute"] = true; |
||||
} |
||||
} |
||||
$config->set('HTML', 'AllowedElements', $allowed_elements); |
||||
$config->set('HTML', 'AllowedAttributes', $allowed_attributes); |
||||
$allowed_schemes = array(); |
||||
if ($allowed_protocols !== null) { |
||||
$config->set('URI', 'AllowedSchemes', $allowed_protocols); |
||||
} |
||||
$purifier = new HTMLPurifier($config); |
||||
return $purifier->purify($string); |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,11 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Convenience stub file that adds HTML Purifier's library file to the path |
||||
* without any other side-effects. |
||||
*/ |
||||
|
||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,271 +0,0 @@ |
||||
<?php |
||||
|
||||
/*! @mainpage |
||||
* |
||||
* HTML Purifier is an HTML filter that will take an arbitrary snippet of |
||||
* HTML and rigorously test, validate and filter it into a version that |
||||
* is safe for output onto webpages. It achieves this by: |
||||
* |
||||
* -# Lexing (parsing into tokens) the document, |
||||
* -# Executing various strategies on the tokens: |
||||
* -# Removing all elements not in the whitelist, |
||||
* -# Making the tokens well-formed, |
||||
* -# Fixing the nesting of the nodes, and |
||||
* -# Validating attributes of the nodes; and |
||||
* -# Generating HTML from the purified tokens. |
||||
* |
||||
* However, most users will only need to interface with the HTMLPurifier |
||||
* and HTMLPurifier_Config. |
||||
*/ |
||||
|
||||
/* |
||||
HTML Purifier 3.3.0 - Standards Compliant HTML Filtering |
||||
Copyright (C) 2006-2008 Edward Z. Yang |
||||
|
||||
This library is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU Lesser General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2.1 of the License, or (at your option) any later version. |
||||
|
||||
This library is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
Lesser General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU Lesser General Public |
||||
License along with this library; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/** |
||||
* Facade that coordinates HTML Purifier's subsystems in order to purify HTML. |
||||
* |
||||
* @note There are several points in which configuration can be specified |
||||
* for HTML Purifier. The precedence of these (from lowest to |
||||
* highest) is as follows: |
||||
* -# Instance: new HTMLPurifier($config) |
||||
* -# Invocation: purify($html, $config) |
||||
* These configurations are entirely independent of each other and |
||||
* are *not* merged (this behavior may change in the future). |
||||
* |
||||
* @todo We need an easier way to inject strategies using the configuration |
||||
* object. |
||||
*/ |
||||
class HTMLPurifier |
||||
{ |
||||
|
||||
/** Version of HTML Purifier */ |
||||
public $version = '3.3.0'; |
||||
|
||||
/** Constant with version of HTML Purifier */ |
||||
const VERSION = '3.3.0'; |
||||
|
||||
/** Global configuration object */ |
||||
public $config; |
||||
|
||||
/** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */ |
||||
private $filters = array(); |
||||
|
||||
/** Single instance of HTML Purifier */ |
||||
private static $instance; |
||||
|
||||
protected $strategy, $generator; |
||||
|
||||
/**allow set user status*/ |
||||
public $my_user_status; |
||||
/** |
||||
* Resultant HTMLPurifier_Context of last run purification. Is an array |
||||
* of contexts if the last called method was purifyArray(). |
||||
*/ |
||||
public $context; |
||||
|
||||
/** |
||||
* Initializes the purifier. |
||||
* @param $config Optional HTMLPurifier_Config object for all instances of |
||||
* the purifier, if omitted, a default configuration is |
||||
* supplied (which can be overridden on a per-use basis). |
||||
* The parameter can also be any type that |
||||
* HTMLPurifier_Config::create() supports. |
||||
*/ |
||||
public function __construct($config = null,$user_status) { |
||||
global $charset; |
||||
if ($user_status==COURSEMANAGERLOWSECURITY) { |
||||
//non initialize object htmlpurifier |
||||
$this->my_user_status=COURSEMANAGERLOWSECURITY; |
||||
} else { |
||||
$config = HTMLPurifier_Config::createDefault(); |
||||
$config->set('Core', 'Encoding',$charset); |
||||
$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional'); |
||||
|
||||
if ($user_status==STUDENT) { |
||||
global $tag_student,$attribute_student;//$tag_student |
||||
$config->set('HTML', 'SafeEmbed',true); |
||||
$config->set('Filter', 'YouTube', true); |
||||
$config->set('HTML', 'AllowedElements',$tag_student); |
||||
$config->set('HTML', 'AllowedAttributes',$attribute_student); |
||||
} elseif ($user_status==COURSEMANAGER) { |
||||
//activate in configuration setting |
||||
global $tag_teacher,$attribute_teacher; |
||||
$config->set('HTML', 'SafeEmbed',true); |
||||
$config->set('Filter', 'YouTube', true); |
||||
$config->set('HTML', 'AllowedElements',$tag_teacher); |
||||
$config->set('HTML', 'AllowedAttributes', $attribute_teacher); |
||||
} else { |
||||
global $tag_anonymous,$attribute_anonymous; |
||||
$config->set('HTML', 'AllowedElements', $tag_anonymous); |
||||
$config->set('HTML', 'AllowedAttributes',$attribute_anonymous); |
||||
} |
||||
$config->set('HTML', 'TidyLevel', 'light'); |
||||
$this->config = HTMLPurifier_Config::create($config); |
||||
$this->strategy = new HTMLPurifier_Strategy_Core(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Adds a filter to process the output. First come first serve |
||||
* @param $filter HTMLPurifier_Filter object |
||||
*/ |
||||
public function addFilter($filter) { |
||||
trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING); |
||||
$this->filters[] = $filter; |
||||
} |
||||
|
||||
/** |
||||
* Filters an HTML snippet/document to be XSS-free and standards-compliant. |
||||
* |
||||
* @param $html String of HTML to purify |
||||
* @param $config HTMLPurifier_Config object for this operation, if omitted, |
||||
* defaults to the config object specified during this |
||||
* object's construction. The parameter can also be any type |
||||
* that HTMLPurifier_Config::create() supports. |
||||
* @return Purified HTML |
||||
*/ |
||||
public function purify($html, $config = null) { |
||||
|
||||
if ($this->my_user_status==COURSEMANAGERLOWSECURITY) { |
||||
return $html; |
||||
} else { |
||||
// :TODO: make the config merge in, instead of replace |
||||
$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(); |
||||
|
||||
// setup HTML generator |
||||
$this->generator = new HTMLPurifier_Generator($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); |
||||
} |
||||
|
||||
// setup id_accumulator context, necessary due to the fact that |
||||
// AttrValidator can be called from many places |
||||
$id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context); |
||||
$context->register('IDAccumulator', $id_accumulator); |
||||
|
||||
$html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context); |
||||
|
||||
// setup filters |
||||
$filter_flags = $config->getBatch('Filter'); |
||||
$custom_filters = $filter_flags['Custom']; |
||||
unset($filter_flags['Custom']); |
||||
$filters = array(); |
||||
foreach ($filter_flags as $filter => $flag) { |
||||
if (!$flag) continue; |
||||
$class = "HTMLPurifier_Filter_$filter"; |
||||
$filters[] = new $class; |
||||
} |
||||
foreach ($custom_filters as $filter) { |
||||
// maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat |
||||
$filters[] = $filter; |
||||
} |
||||
$filters = array_merge($filters, $this->filters); |
||||
// maybe prepare(), but later |
||||
|
||||
for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) { |
||||
$html = $filters[$i]->preFilter($html, $config, $context); |
||||
} |
||||
|
||||
// purified HTML |
||||
$html = |
||||
$this->generator->generateFromTokens( |
||||
// list of tokens |
||||
$this->strategy->execute( |
||||
// list of un-purified tokens |
||||
$lexer->tokenizeHTML( |
||||
// un-purified HTML |
||||
$html, $config, $context |
||||
), |
||||
$config, $context |
||||
) |
||||
); |
||||
|
||||
for ($i = $filter_size - 1; $i >= 0; $i--) { |
||||
$html = $filters[$i]->postFilter($html, $config, $context); |
||||
} |
||||
|
||||
$html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context); |
||||
$this->context =& $context; |
||||
return $html; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Filters an array of HTML snippets |
||||
* @param $config Optional HTMLPurifier_Config object for this operation. |
||||
* See HTMLPurifier::purify() for more details. |
||||
* @return Array of purified HTML |
||||
*/ |
||||
public function purifyArray($array_of_html, $config = null) { |
||||
if ($this->my_user_status==COURSEMANAGERLOWSECURITY) { |
||||
return $array_of_html; |
||||
} else { |
||||
$context_array = array(); |
||||
foreach ($array_of_html as $key => $html) { |
||||
$array_of_html[$key] = $this->purify($html, $config); |
||||
$context_array[$key] = $this->context; |
||||
} |
||||
$this->context = $context_array; |
||||
return $array_of_html; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Singleton for enforcing just one HTML Purifier in your system |
||||
* @param $prototype Optional prototype HTMLPurifier instance to |
||||
* overload singleton with, or HTMLPurifier_Config |
||||
* instance to configure the generated version with. |
||||
*/ |
||||
public static function instance($prototype = null) { |
||||
if (!self::$instance || $prototype) { |
||||
if ($prototype instanceof HTMLPurifier) { |
||||
self::$instance = $prototype; |
||||
} elseif ($prototype) { |
||||
self::$instance = new HTMLPurifier($prototype); |
||||
} else { |
||||
self::$instance = new HTMLPurifier(); |
||||
} |
||||
} |
||||
return self::$instance; |
||||
} |
||||
|
||||
/** |
||||
* @note Backwards compatibility, see instance() |
||||
*/ |
||||
public static function getInstance($prototype = null) { |
||||
return HTMLPurifier::instance($prototype); |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,200 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* This file was auto-generated by generate-includes.php and includes all of |
||||
* the core files required by HTML Purifier. This is a convenience stub that |
||||
* includes all files using dirname(__FILE__) and require_once. PLEASE DO NOT |
||||
* EDIT THIS FILE, changes will be overwritten the next time the script is run. |
||||
* |
||||
* Changes to include_path are not necessary. |
||||
*/ |
||||
|
||||
$__dir = dirname(__FILE__); |
||||
|
||||
require_once $__dir . '/HTMLPurifier.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrCollections.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTypes.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrValidator.php'; |
||||
require_once $__dir . '/HTMLPurifier/Bootstrap.php'; |
||||
require_once $__dir . '/HTMLPurifier/Definition.php'; |
||||
require_once $__dir . '/HTMLPurifier/CSSDefinition.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef.php'; |
||||
require_once $__dir . '/HTMLPurifier/Config.php'; |
||||
require_once $__dir . '/HTMLPurifier/ConfigSchema.php'; |
||||
require_once $__dir . '/HTMLPurifier/ContentSets.php'; |
||||
require_once $__dir . '/HTMLPurifier/Context.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCacheFactory.php'; |
||||
require_once $__dir . '/HTMLPurifier/Doctype.php'; |
||||
require_once $__dir . '/HTMLPurifier/DoctypeRegistry.php'; |
||||
require_once $__dir . '/HTMLPurifier/ElementDef.php'; |
||||
require_once $__dir . '/HTMLPurifier/Encoder.php'; |
||||
require_once $__dir . '/HTMLPurifier/EntityLookup.php'; |
||||
require_once $__dir . '/HTMLPurifier/EntityParser.php'; |
||||
require_once $__dir . '/HTMLPurifier/ErrorCollector.php'; |
||||
require_once $__dir . '/HTMLPurifier/ErrorStruct.php'; |
||||
require_once $__dir . '/HTMLPurifier/Exception.php'; |
||||
require_once $__dir . '/HTMLPurifier/Filter.php'; |
||||
require_once $__dir . '/HTMLPurifier/Generator.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLDefinition.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModuleManager.php'; |
||||
require_once $__dir . '/HTMLPurifier/IDAccumulator.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector.php'; |
||||
require_once $__dir . '/HTMLPurifier/Language.php'; |
||||
require_once $__dir . '/HTMLPurifier/LanguageFactory.php'; |
||||
require_once $__dir . '/HTMLPurifier/Length.php'; |
||||
require_once $__dir . '/HTMLPurifier/Lexer.php'; |
||||
require_once $__dir . '/HTMLPurifier/PercentEncoder.php'; |
||||
require_once $__dir . '/HTMLPurifier/PropertyList.php'; |
||||
require_once $__dir . '/HTMLPurifier/PropertyListIterator.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy.php'; |
||||
require_once $__dir . '/HTMLPurifier/StringHash.php'; |
||||
require_once $__dir . '/HTMLPurifier/StringHashParser.php'; |
||||
require_once $__dir . '/HTMLPurifier/TagTransform.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token.php'; |
||||
require_once $__dir . '/HTMLPurifier/TokenFactory.php'; |
||||
require_once $__dir . '/HTMLPurifier/URI.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIDefinition.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIParser.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme.php'; |
||||
require_once $__dir . '/HTMLPurifier/URISchemeRegistry.php'; |
||||
require_once $__dir . '/HTMLPurifier/UnitConverter.php'; |
||||
require_once $__dir . '/HTMLPurifier/VarParser.php'; |
||||
require_once $__dir . '/HTMLPurifier/VarParserException.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/Enum.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/Integer.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/Lang.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/Switch.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/Text.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Number.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/AlphaValue.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Background.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Border.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Color.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Composite.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Filter.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Font.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/FontFamily.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Length.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/ListStyle.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Multiple.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Percentage.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/TextDecoration.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/URI.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/Bool.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/Color.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/FrameTarget.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/ID.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/Pixels.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/Length.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/LinkTypes.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/MultiLength.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/HTML/Nmtokens.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/Email.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/Host.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv4.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/IPv6.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Background.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BdoDir.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BgColor.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/BoolToCSS.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Border.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/EnumToCSS.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/ImgRequired.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/ImgSpace.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Input.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Lang.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Length.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Name.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/SafeEmbed.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/SafeObject.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/SafeParam.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/ScriptRequired.php'; |
||||
require_once $__dir . '/HTMLPurifier/AttrTransform/Textarea.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Chameleon.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Custom.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Empty.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Required.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Optional.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/StrictBlockquote.php'; |
||||
require_once $__dir . '/HTMLPurifier/ChildDef/Table.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache/Decorator.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache/Null.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache/Serializer.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache/Decorator/Cleanup.php'; |
||||
require_once $__dir . '/HTMLPurifier/DefinitionCache/Decorator/Memory.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Bdo.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/CommonAttributes.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Edit.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Forms.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Hypertext.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Image.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Legacy.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/List.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Name.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Object.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Presentation.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Proprietary.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Ruby.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/SafeEmbed.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/SafeObject.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Scripting.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/StyleAttribute.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tables.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Target.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Text.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/XMLCommonAttributes.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Name.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Proprietary.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Strict.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Transitional.php'; |
||||
require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/XHTML.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/AutoParagraph.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/DisplayLinkURI.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/Linkify.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/PurifierLinkify.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/RemoveEmpty.php'; |
||||
require_once $__dir . '/HTMLPurifier/Injector/SafeObject.php'; |
||||
require_once $__dir . '/HTMLPurifier/Lexer/DOMLex.php'; |
||||
require_once $__dir . '/HTMLPurifier/Lexer/DirectLex.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/Composite.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/Core.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/FixNesting.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/MakeWellFormed.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/RemoveForeignElements.php'; |
||||
require_once $__dir . '/HTMLPurifier/Strategy/ValidateAttributes.php'; |
||||
require_once $__dir . '/HTMLPurifier/TagTransform/Font.php'; |
||||
require_once $__dir . '/HTMLPurifier/TagTransform/Simple.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/Comment.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/Tag.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/Empty.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/End.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/Start.php'; |
||||
require_once $__dir . '/HTMLPurifier/Token/Text.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter/DisableExternal.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter/DisableExternalResources.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter/HostBlacklist.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter/MakeAbsolute.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIFilter/Munge.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/ftp.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/http.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/https.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/mailto.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/news.php'; |
||||
require_once $__dir . '/HTMLPurifier/URIScheme/nntp.php'; |
||||
require_once $__dir . '/HTMLPurifier/VarParser/Flexible.php'; |
||||
require_once $__dir . '/HTMLPurifier/VarParser/Native.php'; |
||||
@ -1,128 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Defines common attribute collections that modules reference |
||||
*/ |
||||
|
||||
class HTMLPurifier_AttrCollections |
||||
{ |
||||
|
||||
/** |
||||
* Associative array of attribute collections, indexed by name |
||||
*/ |
||||
public $info = array(); |
||||
|
||||
/** |
||||
* Performs all expansions on internal data for use by other inclusions |
||||
* It also collects all attribute collection extensions from |
||||
* modules |
||||
* @param $attr_types HTMLPurifier_AttrTypes instance |
||||
* @param $modules Hash array of HTMLPurifier_HTMLModule members |
||||
*/ |
||||
public function __construct($attr_types, $modules) { |
||||
// load extensions from the modules |
||||
foreach ($modules as $module) { |
||||
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) { |
||||
if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) { |
||||
// merge in includes |
||||
$this->info[$coll_i][$attr_i] = array_merge( |
||||
$this->info[$coll_i][$attr_i], $attr); |
||||
continue; |
||||
} |
||||
$this->info[$coll_i][$attr_i] = $attr; |
||||
} |
||||
} |
||||
} |
||||
// perform internal expansions and inclusions |
||||
foreach ($this->info as $name => $attr) { |
||||
// merge attribute collections that include others |
||||
$this->performInclusions($this->info[$name]); |
||||
// replace string identifiers with actual attribute objects |
||||
$this->expandIdentifiers($this->info[$name], $attr_types); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Takes a reference to an attribute associative array and performs |
||||
* all inclusions specified by the zero index. |
||||
* @param &$attr Reference to attribute array |
||||
*/ |
||||
public function performInclusions(&$attr) { |
||||
if (!isset($attr[0])) return; |
||||
$merge = $attr[0]; |
||||
$seen = array(); // recursion guard |
||||
// loop through all the inclusions |
||||
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 |
||||
if (!isset($this->info[$merge[$i]])) continue; |
||||
foreach ($this->info[$merge[$i]] as $key => $value) { |
||||
if (isset($attr[$key])) continue; // also catches more inclusions |
||||
$attr[$key] = $value; |
||||
} |
||||
if (isset($this->info[$merge[$i]][0])) { |
||||
// recursion |
||||
$merge = array_merge($merge, $this->info[$merge[$i]][0]); |
||||
} |
||||
} |
||||
unset($attr[0]); |
||||
} |
||||
|
||||
/** |
||||
* Expands all string identifiers in an attribute array by replacing |
||||
* them with the appropriate values inside HTMLPurifier_AttrTypes |
||||
* @param &$attr Reference to attribute array |
||||
* @param $attr_types HTMLPurifier_AttrTypes instance |
||||
*/ |
||||
public 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) { |
||||
// skip inclusions |
||||
if ($def_i === 0) 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) { |
||||
unset($attr[$def_i]); |
||||
continue; |
||||
} |
||||
|
||||
if ($t = $attr_types->get($def)) { |
||||
$attr[$def_i] = $t; |
||||
$attr[$def_i]->required = $required; |
||||
} else { |
||||
unset($attr[$def_i]); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,87 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Base class for all validating attribute definitions. |
||||
* |
||||
* This family of classes forms the core for not only HTML attribute validation, |
||||
* but also any sort of string that needs to be validated or cleaned (which |
||||
* means CSS properties and composite definitions are defined here too). |
||||
* Besides defining (through code) what precisely makes the string valid, |
||||
* subclasses are also responsible for cleaning the code if possible. |
||||
*/ |
||||
|
||||
abstract class HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Tells us whether or not an HTML attribute is minimized. Has no |
||||
* meaning in other contexts. |
||||
*/ |
||||
public $minimized = false; |
||||
|
||||
/** |
||||
* Tells us whether or not an HTML attribute is required. Has no |
||||
* meaning in other contexts |
||||
*/ |
||||
public $required = false; |
||||
|
||||
/** |
||||
* Validates and cleans passed string according to a definition. |
||||
* |
||||
* @param $string String to be validated and cleaned. |
||||
* @param $config Mandatory HTMLPurifier_Config object. |
||||
* @param $context Mandatory HTMLPurifier_AttrContext object. |
||||
*/ |
||||
abstract public function validate($string, $config, $context); |
||||
|
||||
/** |
||||
* Convenience method that parses a string as if it were CDATA. |
||||
* |
||||
* This method process a string in the manner specified at |
||||
* <http://www.w3.org/TR/html4/types.html#h-6.2> by removing |
||||
* leading and trailing whitespace, ignoring line feeds, and replacing |
||||
* carriage returns and tabs with spaces. While most useful for HTML |
||||
* attributes specified as CDATA, it can also be applied to most CSS |
||||
* values. |
||||
* |
||||
* @note This method is not entirely standards compliant, as trim() removes |
||||
* more types of whitespace than specified in the spec. In practice, |
||||
* this is rarely a problem, as those extra characters usually have |
||||
* already been removed by HTMLPurifier_Encoder. |
||||
* |
||||
* @warning This processing is inconsistent with XML's whitespace handling |
||||
* as specified by section 3.3.3 and referenced XHTML 1.0 section |
||||
* 4.7. However, note that we are NOT necessarily |
||||
* parsing XML, thus, this behavior may still be correct. We |
||||
* assume that newlines have been normalized. |
||||
*/ |
||||
public function parseCDATA($string) { |
||||
$string = trim($string); |
||||
$string = str_replace(array("\n", "\t", "\r"), ' ', $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 a flyweight of this object. |
||||
// If $string has an effect on the returned object (i.e. you |
||||
// need to overload this method), it is best |
||||
// to clone or instantiate new copies. (Instantiation is safer.) |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work |
||||
* properly. THIS IS A HACK! |
||||
*/ |
||||
protected function mungeRgb($string) { |
||||
return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,87 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the HTML attribute style, otherwise known as CSS. |
||||
* @note We don't implement the whole CSS specification, so it might be |
||||
* difficult to reuse this component in the context of validating |
||||
* actual stylesheet declarations. |
||||
* @note If we were really serious about validating the CSS, we would |
||||
* tokenize the styles and then parse the tokens. Obviously, we |
||||
* are not doing that. Doing that could seriously harm performance, |
||||
* but would make these components a lot more viable for a CSS |
||||
* filtering solution. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($css, $config, $context) { |
||||
|
||||
$css = $this->parseCDATA($css); |
||||
|
||||
$definition = $config->getCSSDefinition(); |
||||
|
||||
// we're going to break the spec and explode by semicolons. |
||||
// This is because semicolon rarely appears in escaped form |
||||
// Doing this is generally flaky but fast |
||||
// IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI |
||||
// for details |
||||
|
||||
$declarations = explode(';', $css); |
||||
$propvalues = array(); |
||||
|
||||
/** |
||||
* Name of the current CSS property being validated. |
||||
*/ |
||||
$property = false; |
||||
$context->register('CurrentCSSProperty', $property); |
||||
|
||||
foreach ($declarations as $declaration) { |
||||
if (!$declaration) continue; |
||||
if (!strpos($declaration, ':')) continue; |
||||
list($property, $value) = explode(':', $declaration, 2); |
||||
$property = trim($property); |
||||
$value = trim($value); |
||||
$ok = false; |
||||
do { |
||||
if (isset($definition->info[$property])) { |
||||
$ok = true; |
||||
break; |
||||
} |
||||
if (ctype_lower($property)) break; |
||||
$property = strtolower($property); |
||||
if (isset($definition->info[$property])) { |
||||
$ok = true; |
||||
break; |
||||
} |
||||
} while(0); |
||||
if (!$ok) continue; |
||||
// inefficient call, since the validator will do this again |
||||
if (strtolower(trim($value)) !== 'inherit') { |
||||
// inherit works for everything (but only on the base property) |
||||
$result = $definition->info[$property]->validate( |
||||
$value, $config, $context ); |
||||
} else { |
||||
$result = 'inherit'; |
||||
} |
||||
if ($result === false) continue; |
||||
$propvalues[$property] = $result; |
||||
} |
||||
|
||||
$context->destroy('CurrentCSSProperty'); |
||||
|
||||
// procedure does not write the new CSS simultaneously, so it's |
||||
// slightly inefficient, but it's the only way of getting rid of |
||||
// duplicates. Perhaps config to optimize it, but not now. |
||||
|
||||
$new_declarations = ''; |
||||
foreach ($propvalues as $prop => $value) { |
||||
$new_declarations .= "$prop:$value;"; |
||||
} |
||||
|
||||
return $new_declarations ? $new_declarations : false; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,21 +0,0 @@ |
||||
<?php |
||||
|
||||
class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number |
||||
{ |
||||
|
||||
public function __construct() { |
||||
parent::__construct(false); // opacity is non-negative, but we will clamp it |
||||
} |
||||
|
||||
public function validate($number, $config, $context) { |
||||
$result = parent::validate($number, $config, $context); |
||||
if ($result === false) return $result; |
||||
$float = (float) $result; |
||||
if ($float < 0.0) $result = '0'; |
||||
if ($float > 1.0) $result = '1'; |
||||
return $result; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,87 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates shorthand CSS property background. |
||||
* @warning Does not support url tokens that have internal spaces. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Local copy of component validators. |
||||
* @note See HTMLPurifier_AttrDef_Font::$info for a similar impl. |
||||
*/ |
||||
protected $info; |
||||
|
||||
public function __construct($config) { |
||||
$def = $config->getCSSDefinition(); |
||||
$this->info['background-color'] = $def->info['background-color']; |
||||
$this->info['background-image'] = $def->info['background-image']; |
||||
$this->info['background-repeat'] = $def->info['background-repeat']; |
||||
$this->info['background-attachment'] = $def->info['background-attachment']; |
||||
$this->info['background-position'] = $def->info['background-position']; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
// regular pre-processing |
||||
$string = $this->parseCDATA($string); |
||||
if ($string === '') return false; |
||||
|
||||
// munge rgb() decl if necessary |
||||
$string = $this->mungeRgb($string); |
||||
|
||||
// assumes URI doesn't have spaces in it |
||||
$bits = explode(' ', strtolower($string)); // bits to process |
||||
|
||||
$caught = array(); |
||||
$caught['color'] = false; |
||||
$caught['image'] = false; |
||||
$caught['repeat'] = false; |
||||
$caught['attachment'] = false; |
||||
$caught['position'] = false; |
||||
|
||||
$i = 0; // number of catches |
||||
$none = false; |
||||
|
||||
foreach ($bits as $bit) { |
||||
if ($bit === '') continue; |
||||
foreach ($caught as $key => $status) { |
||||
if ($key != 'position') { |
||||
if ($status !== false) continue; |
||||
$r = $this->info['background-' . $key]->validate($bit, $config, $context); |
||||
} else { |
||||
$r = $bit; |
||||
} |
||||
if ($r === false) continue; |
||||
if ($key == 'position') { |
||||
if ($caught[$key] === false) $caught[$key] = ''; |
||||
$caught[$key] .= $r . ' '; |
||||
} else { |
||||
$caught[$key] = $r; |
||||
} |
||||
$i++; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (!$i) return false; |
||||
if ($caught['position'] !== false) { |
||||
$caught['position'] = $this->info['background-position']-> |
||||
validate($caught['position'], $config, $context); |
||||
} |
||||
|
||||
$ret = array(); |
||||
foreach ($caught as $value) { |
||||
if ($value === false) continue; |
||||
$ret[] = $value; |
||||
} |
||||
|
||||
if (empty($ret)) return false; |
||||
return implode(' ', $ret); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,126 +0,0 @@ |
||||
<?php |
||||
|
||||
/* W3C says: |
||||
[ // adjective and number must be in correct order, even if |
||||
// you could switch them without introducing ambiguity. |
||||
// some browsers support that syntax |
||||
[ |
||||
<percentage> | <length> | left | center | right |
||||
] |
||||
[ |
||||
<percentage> | <length> | top | center | bottom |
||||
]? |
||||
] | |
||||
[ // this signifies that the vertical and horizontal adjectives |
||||
// can be arbitrarily ordered, however, there can only be two, |
||||
// one of each, or none at all |
||||
[ |
||||
left | center | right |
||||
] || |
||||
[ |
||||
top | center | bottom |
||||
] |
||||
] |
||||
top, left = 0% |
||||
center, (none) = 50% |
||||
bottom, right = 100% |
||||
*/ |
||||
|
||||
/* QuirksMode says: |
||||
keyword + length/percentage must be ordered correctly, as per W3C |
||||
|
||||
Internet Explorer and Opera, however, support arbitrary ordering. We |
||||
should fix it up. |
||||
|
||||
Minor issue though, not strictly necessary. |
||||
*/ |
||||
|
||||
// control freaks may appreciate the ability to convert these to |
||||
// percentages or something, but it's not necessary |
||||
|
||||
/** |
||||
* Validates the value of background-position. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $length; |
||||
protected $percentage; |
||||
|
||||
public function __construct() { |
||||
$this->length = new HTMLPurifier_AttrDef_CSS_Length(); |
||||
$this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage(); |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$string = $this->parseCDATA($string); |
||||
$bits = explode(' ', $string); |
||||
|
||||
$keywords = array(); |
||||
$keywords['h'] = false; // left, right |
||||
$keywords['v'] = false; // top, bottom |
||||
$keywords['c'] = false; // center |
||||
$measures = array(); |
||||
|
||||
$i = 0; |
||||
|
||||
$lookup = array( |
||||
'top' => 'v', |
||||
'bottom' => 'v', |
||||
'left' => 'h', |
||||
'right' => 'h', |
||||
'center' => 'c' |
||||
); |
||||
|
||||
foreach ($bits as $bit) { |
||||
if ($bit === '') continue; |
||||
|
||||
// test for keyword |
||||
$lbit = ctype_lower($bit) ? $bit : strtolower($bit); |
||||
if (isset($lookup[$lbit])) { |
||||
$status = $lookup[$lbit]; |
||||
$keywords[$status] = $lbit; |
||||
$i++; |
||||
} |
||||
|
||||
// test for length |
||||
$r = $this->length->validate($bit, $config, $context); |
||||
if ($r !== false) { |
||||
$measures[] = $r; |
||||
$i++; |
||||
} |
||||
|
||||
// test for percentage |
||||
$r = $this->percentage->validate($bit, $config, $context); |
||||
if ($r !== false) { |
||||
$measures[] = $r; |
||||
$i++; |
||||
} |
||||
|
||||
} |
||||
|
||||
if (!$i) return false; // no valid values were caught |
||||
|
||||
|
||||
$ret = array(); |
||||
|
||||
// first keyword |
||||
if ($keywords['h']) $ret[] = $keywords['h']; |
||||
elseif (count($measures)) $ret[] = array_shift($measures); |
||||
elseif ($keywords['c']) { |
||||
$ret[] = $keywords['c']; |
||||
$keywords['c'] = false; // prevent re-use: center = center center |
||||
} |
||||
|
||||
if ($keywords['v']) $ret[] = $keywords['v']; |
||||
elseif (count($measures)) $ret[] = array_shift($measures); |
||||
elseif ($keywords['c']) $ret[] = $keywords['c']; |
||||
|
||||
if (empty($ret)) return false; |
||||
return implode(' ', $ret); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,43 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the border property as defined by CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Local copy of properties this property is shorthand for. |
||||
*/ |
||||
protected $info = array(); |
||||
|
||||
public function __construct($config) { |
||||
$def = $config->getCSSDefinition(); |
||||
$this->info['border-width'] = $def->info['border-width']; |
||||
$this->info['border-style'] = $def->info['border-style']; |
||||
$this->info['border-top-color'] = $def->info['border-top-color']; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$string = $this->parseCDATA($string); |
||||
$string = $this->mungeRgb($string); |
||||
$bits = explode(' ', $string); |
||||
$done = array(); // segments we've finished |
||||
$ret = ''; // return value |
||||
foreach ($bits as $bit) { |
||||
foreach ($this->info as $propname => $validator) { |
||||
if (isset($done[$propname])) continue; |
||||
$r = $validator->validate($bit, $config, $context); |
||||
if ($r !== false) { |
||||
$ret .= $r . ' '; |
||||
$done[$propname] = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return rtrim($ret); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,78 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates Color as defined by CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($color, $config, $context) { |
||||
|
||||
static $colors = null; |
||||
if ($colors === null) $colors = $config->get('Core', 'ColorKeywords'); |
||||
|
||||
$color = trim($color); |
||||
if ($color === '') return false; |
||||
|
||||
$lower = strtolower($color); |
||||
if (isset($colors[$lower])) return $colors[$lower]; |
||||
|
||||
if (strpos($color, 'rgb(') !== false) { |
||||
// rgb literal handling |
||||
$length = strlen($color); |
||||
if (strpos($color, ')') !== $length - 1) return false; |
||||
$triad = substr($color, 4, $length - 4 - 1); |
||||
$parts = explode(',', $triad); |
||||
if (count($parts) !== 3) return false; |
||||
$type = false; // to ensure that they're all the same type |
||||
$new_parts = array(); |
||||
foreach ($parts as $part) { |
||||
$part = trim($part); |
||||
if ($part === '') return false; |
||||
$length = strlen($part); |
||||
if ($part[$length - 1] === '%') { |
||||
// handle percents |
||||
if (!$type) { |
||||
$type = 'percentage'; |
||||
} elseif ($type !== 'percentage') { |
||||
return false; |
||||
} |
||||
$num = (float) substr($part, 0, $length - 1); |
||||
if ($num < 0) $num = 0; |
||||
if ($num > 100) $num = 100; |
||||
$new_parts[] = "$num%"; |
||||
} else { |
||||
// handle integers |
||||
if (!$type) { |
||||
$type = 'integer'; |
||||
} elseif ($type !== 'integer') { |
||||
return false; |
||||
} |
||||
$num = (int) $part; |
||||
if ($num < 0) $num = 0; |
||||
if ($num > 255) $num = 255; |
||||
$new_parts[] = (string) $num; |
||||
} |
||||
} |
||||
$new_triad = implode(',', $new_parts); |
||||
$color = "rgb($new_triad)"; |
||||
} else { |
||||
// hexadecimal handling |
||||
if ($color[0] === '#') { |
||||
$hex = substr($color, 1); |
||||
} else { |
||||
$hex = $color; |
||||
$color = '#' . $color; |
||||
} |
||||
$length = strlen($hex); |
||||
if ($length !== 3 && $length !== 6) return false; |
||||
if (!ctype_xdigit($hex)) return false; |
||||
} |
||||
|
||||
return $color; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,38 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Allows multiple validators to attempt to validate attribute. |
||||
* |
||||
* Composite is just what it sounds like: a composite of many validators. |
||||
* This means that multiple HTMLPurifier_AttrDef objects will have a whack |
||||
* at the string. If one of them passes, that's what is returned. This is |
||||
* especially useful for CSS values, which often are a choice between |
||||
* an enumerated set of predefined values or a flexible data type. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Composite extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* List of HTMLPurifier_AttrDef objects that may process strings |
||||
* @todo Make protected |
||||
*/ |
||||
public $defs; |
||||
|
||||
/** |
||||
* @param $defs List of HTMLPurifier_AttrDef objects |
||||
*/ |
||||
public function __construct($defs) { |
||||
$this->defs = $defs; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
foreach ($this->defs as $i => $def) { |
||||
$result = $this->defs[$i]->validate($string, $config, $context); |
||||
if ($result !== false) return $result; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,28 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Decorator which enables CSS properties to be disabled for specific elements. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_DenyElementDecorator extends HTMLPurifier_AttrDef |
||||
{ |
||||
public $def, $element; |
||||
|
||||
/** |
||||
* @param $def Definition to wrap |
||||
* @param $element Element to deny |
||||
*/ |
||||
public function __construct($def, $element) { |
||||
$this->def = $def; |
||||
$this->element = $element; |
||||
} |
||||
/** |
||||
* Checks if CurrentToken is set and equal to $this->element |
||||
*/ |
||||
public function validate($string, $config, $context) { |
||||
$token = $context->get('CurrentToken', true); |
||||
if ($token && $token->name == $this->element) return false; |
||||
return $this->def->validate($string, $config, $context); |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,54 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Microsoft's proprietary filter: CSS property |
||||
* @note Currently supports the alpha filter. In the future, this will |
||||
* probably need an extensible framework |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $intValidator; |
||||
|
||||
public function __construct() { |
||||
$this->intValidator = new HTMLPurifier_AttrDef_Integer(); |
||||
} |
||||
|
||||
public function validate($value, $config, $context) { |
||||
$value = $this->parseCDATA($value); |
||||
if ($value === 'none') return $value; |
||||
// if we looped this we could support multiple filters |
||||
$function_length = strcspn($value, '('); |
||||
$function = trim(substr($value, 0, $function_length)); |
||||
if ($function !== 'alpha' && |
||||
$function !== 'Alpha' && |
||||
$function !== 'progid:DXImageTransform.Microsoft.Alpha' |
||||
) return false; |
||||
$cursor = $function_length + 1; |
||||
$parameters_length = strcspn($value, ')', $cursor); |
||||
$parameters = substr($value, $cursor, $parameters_length); |
||||
$params = explode(',', $parameters); |
||||
$ret_params = array(); |
||||
$lookup = array(); |
||||
foreach ($params as $param) { |
||||
list($key, $value) = explode('=', $param); |
||||
$key = trim($key); |
||||
$value = trim($value); |
||||
if (isset($lookup[$key])) continue; |
||||
if ($key !== 'opacity') continue; |
||||
$value = $this->intValidator->validate($value, $config, $context); |
||||
if ($value === false) continue; |
||||
$int = (int) $value; |
||||
if ($int > 100) $value = '100'; |
||||
if ($int < 0) $value = '0'; |
||||
$ret_params[] = "$key=$value"; |
||||
$lookup[$key] = true; |
||||
} |
||||
$ret_parameters = implode(',', $ret_params); |
||||
$ret_function = "$function($ret_parameters)"; |
||||
return $ret_function; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,149 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates shorthand CSS property font. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Local copy of component validators. |
||||
* |
||||
* @note If we moved specific CSS property definitions to their own |
||||
* classes instead of having them be assembled at run time by |
||||
* CSSDefinition, this wouldn't be necessary. We'd instantiate |
||||
* our own copies. |
||||
*/ |
||||
protected $info = array(); |
||||
|
||||
public function __construct($config) { |
||||
$def = $config->getCSSDefinition(); |
||||
$this->info['font-style'] = $def->info['font-style']; |
||||
$this->info['font-variant'] = $def->info['font-variant']; |
||||
$this->info['font-weight'] = $def->info['font-weight']; |
||||
$this->info['font-size'] = $def->info['font-size']; |
||||
$this->info['line-height'] = $def->info['line-height']; |
||||
$this->info['font-family'] = $def->info['font-family']; |
||||
} |
||||
|
||||
public 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 |
||||
$string = $this->parseCDATA($string); |
||||
if ($string === '') return false; |
||||
|
||||
// check if it's one of the keywords |
||||
$lowercase_string = strtolower($string); |
||||
if (isset($system_fonts[$lowercase_string])) { |
||||
return $lowercase_string; |
||||
} |
||||
|
||||
$bits = explode(' ', $string); // bits to process |
||||
$stage = 0; // this indicates what we're looking for |
||||
$caught = array(); // which stage 0 properties have we caught? |
||||
$stage_1 = array('font-style', 'font-variant', 'font-weight'); |
||||
$final = ''; // output |
||||
|
||||
for ($i = 0, $size = count($bits); $i < $size; $i++) { |
||||
if ($bits[$i] === '') continue; |
||||
switch ($stage) { |
||||
|
||||
// attempting to catch font-style, font-variant or font-weight |
||||
case 0: |
||||
foreach ($stage_1 as $validator_name) { |
||||
if (isset($caught[$validator_name])) continue; |
||||
$r = $this->info[$validator_name]->validate( |
||||
$bits[$i], $config, $context); |
||||
if ($r !== false) { |
||||
$final .= $r . ' '; |
||||
$caught[$validator_name] = true; |
||||
break; |
||||
} |
||||
} |
||||
// all three caught, continue on |
||||
if (count($caught) >= 3) $stage = 1; |
||||
if ($r !== false) break; |
||||
|
||||
// attempting to catch font-size and perhaps line-height |
||||
case 1: |
||||
$found_slash = false; |
||||
if (strpos($bits[$i], '/') !== false) { |
||||
list($font_size, $line_height) = |
||||
explode('/', $bits[$i]); |
||||
if ($line_height === '') { |
||||
// ooh, there's a space after the slash! |
||||
$line_height = false; |
||||
$found_slash = true; |
||||
} |
||||
} else { |
||||
$font_size = $bits[$i]; |
||||
$line_height = false; |
||||
} |
||||
$r = $this->info['font-size']->validate( |
||||
$font_size, $config, $context); |
||||
if ($r !== false) { |
||||
$final .= $r; |
||||
// attempt to catch line-height |
||||
if ($line_height === false) { |
||||
// we need to scroll forward |
||||
for ($j = $i + 1; $j < $size; $j++) { |
||||
if ($bits[$j] === '') continue; |
||||
if ($bits[$j] === '/') { |
||||
if ($found_slash) { |
||||
return false; |
||||
} else { |
||||
$found_slash = true; |
||||
continue; |
||||
} |
||||
} |
||||
$line_height = $bits[$j]; |
||||
break; |
||||
} |
||||
} else { |
||||
// slash already found |
||||
$found_slash = true; |
||||
$j = $i; |
||||
} |
||||
if ($found_slash) { |
||||
$i = $j; |
||||
$r = $this->info['line-height']->validate( |
||||
$line_height, $config, $context); |
||||
if ($r !== false) { |
||||
$final .= '/' . $r; |
||||
} |
||||
} |
||||
$final .= ' '; |
||||
$stage = 2; |
||||
break; |
||||
} |
||||
return false; |
||||
|
||||
// attempting to catch font-family |
||||
case 2: |
||||
$font_family = |
||||
implode(' ', array_slice($bits, $i, $size - $i)); |
||||
$r = $this->info['font-family']->validate( |
||||
$font_family, $config, $context); |
||||
if ($r !== false) { |
||||
$final .= $r . ' '; |
||||
// processing completed successfully |
||||
return rtrim($final); |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,90 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a font family list according to CSS spec |
||||
* @todo whitelisting allowed fonts would be nice |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
static $generic_names = array( |
||||
'serif' => true, |
||||
'sans-serif' => true, |
||||
'monospace' => true, |
||||
'fantasy' => true, |
||||
'cursive' => true |
||||
); |
||||
|
||||
// assume that no font names contain commas in them |
||||
$fonts = explode(',', $string); |
||||
$final = ''; |
||||
foreach($fonts as $font) { |
||||
$font = trim($font); |
||||
if ($font === '') continue; |
||||
// match a generic name |
||||
if (isset($generic_names[$font])) { |
||||
$final .= $font . ', '; |
||||
continue; |
||||
} |
||||
// match a quoted name |
||||
if ($font[0] === '"' || $font[0] === "'") { |
||||
$length = strlen($font); |
||||
if ($length <= 2) continue; |
||||
$quote = $font[0]; |
||||
if ($font[$length - 1] !== $quote) continue; |
||||
$font = substr($font, 1, $length - 2); |
||||
|
||||
$new_font = ''; |
||||
for ($i = 0, $c = strlen($font); $i < $c; $i++) { |
||||
if ($font[$i] === '\\') { |
||||
$i++; |
||||
if ($i >= $c) { |
||||
$new_font .= '\\'; |
||||
break; |
||||
} |
||||
if (ctype_xdigit($font[$i])) { |
||||
$code = $font[$i]; |
||||
for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
||||
if (!ctype_xdigit($font[$i])) break; |
||||
$code .= $font[$i]; |
||||
} |
||||
// We have to be extremely careful when adding |
||||
// new characters, to make sure we're not breaking |
||||
// the encoding. |
||||
$char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
||||
if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue; |
||||
$new_font .= $char; |
||||
if ($i < $c && trim($font[$i]) !== '') $i--; |
||||
continue; |
||||
} |
||||
if ($font[$i] === "\n") continue; |
||||
} |
||||
$new_font .= $font[$i]; |
||||
} |
||||
|
||||
$font = $new_font; |
||||
} |
||||
// $font is a pure representation of the font name |
||||
|
||||
if (ctype_alnum($font) && $font !== '') { |
||||
// very simple font, allow it in unharmed |
||||
$final .= $font . ', '; |
||||
continue; |
||||
} |
||||
|
||||
// complicated font, requires quoting |
||||
|
||||
// armor single quotes and new lines |
||||
$font = str_replace("\\", "\\\\", $font); |
||||
$font = str_replace("'", "\\'", $font); |
||||
$final .= "'$font', "; |
||||
} |
||||
$final = rtrim($final, ', '); |
||||
if ($final === '') return false; |
||||
return $final; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,40 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Decorator which enables !important to be used in CSS values. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef |
||||
{ |
||||
public $def, $allow; |
||||
|
||||
/** |
||||
* @param $def Definition to wrap |
||||
* @param $allow Whether or not to allow !important |
||||
*/ |
||||
public function __construct($def, $allow = false) { |
||||
$this->def = $def; |
||||
$this->allow = $allow; |
||||
} |
||||
/** |
||||
* Intercepts and removes !important if necessary |
||||
*/ |
||||
public function validate($string, $config, $context) { |
||||
// test for ! and important tokens |
||||
$string = trim($string); |
||||
$is_important = false; |
||||
// :TODO: optimization: test directly for !important and ! important |
||||
if (strlen($string) >= 9 && substr($string, -9) === 'important') { |
||||
$temp = rtrim(substr($string, 0, -9)); |
||||
// use a temp, because we might want to restore important |
||||
if (strlen($temp) >= 1 && substr($temp, -1) === '!') { |
||||
$string = rtrim(substr($temp, 0, -1)); |
||||
$is_important = true; |
||||
} |
||||
} |
||||
$string = $this->def->validate($string, $config, $context); |
||||
if ($this->allow && $is_important) $string .= ' !important'; |
||||
return $string; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,47 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Represents a Length as defined by CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $min, $max; |
||||
|
||||
/** |
||||
* @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable. |
||||
* @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable. |
||||
*/ |
||||
public function __construct($min = null, $max = null) { |
||||
$this->min = $min !== null ? HTMLPurifier_Length::make($min) : null; |
||||
$this->max = $max !== null ? HTMLPurifier_Length::make($max) : null; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$string = $this->parseCDATA($string); |
||||
|
||||
// Optimizations |
||||
if ($string === '') return false; |
||||
if ($string === '0') return '0'; |
||||
if (strlen($string) === 1) return false; |
||||
|
||||
$length = HTMLPurifier_Length::make($string); |
||||
if (!$length->isValid()) return false; |
||||
|
||||
if ($this->min) { |
||||
$c = $length->compareTo($this->min); |
||||
if ($c === false) return false; |
||||
if ($c < 0) return false; |
||||
} |
||||
if ($this->max) { |
||||
$c = $length->compareTo($this->max); |
||||
if ($c === false) return false; |
||||
if ($c > 0) return false; |
||||
} |
||||
|
||||
return $length->toString(); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,78 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates shorthand CSS property list-style. |
||||
* @warning Does not support url tokens that have internal spaces. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Local copy of component validators. |
||||
* @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl. |
||||
*/ |
||||
protected $info; |
||||
|
||||
public function __construct($config) { |
||||
$def = $config->getCSSDefinition(); |
||||
$this->info['list-style-type'] = $def->info['list-style-type']; |
||||
$this->info['list-style-position'] = $def->info['list-style-position']; |
||||
$this->info['list-style-image'] = $def->info['list-style-image']; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
// regular pre-processing |
||||
$string = $this->parseCDATA($string); |
||||
if ($string === '') return false; |
||||
|
||||
// assumes URI doesn't have spaces in it |
||||
$bits = explode(' ', strtolower($string)); // bits to process |
||||
|
||||
$caught = array(); |
||||
$caught['type'] = false; |
||||
$caught['position'] = false; |
||||
$caught['image'] = false; |
||||
|
||||
$i = 0; // number of catches |
||||
$none = false; |
||||
|
||||
foreach ($bits as $bit) { |
||||
if ($i >= 3) return; // optimization bit |
||||
if ($bit === '') continue; |
||||
foreach ($caught as $key => $status) { |
||||
if ($status !== false) continue; |
||||
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context); |
||||
if ($r === false) continue; |
||||
if ($r === 'none') { |
||||
if ($none) continue; |
||||
else $none = true; |
||||
if ($key == 'image') continue; |
||||
} |
||||
$caught[$key] = $r; |
||||
$i++; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (!$i) return false; |
||||
|
||||
$ret = array(); |
||||
|
||||
// construct type |
||||
if ($caught['type']) $ret[] = $caught['type']; |
||||
|
||||
// construct image |
||||
if ($caught['image']) $ret[] = $caught['image']; |
||||
|
||||
// construct position |
||||
if ($caught['position']) $ret[] = $caught['position']; |
||||
|
||||
if (empty($ret)) return false; |
||||
return implode(' ', $ret); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,58 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Framework class for strings that involve multiple values. |
||||
* |
||||
* Certain CSS properties such as border-width and margin allow multiple |
||||
* lengths to be specified. This class can take a vanilla border-width |
||||
* definition and multiply it, usually into a max of four. |
||||
* |
||||
* @note Even though the CSS specification isn't clear about it, inherit |
||||
* can only be used alone: it will never manifest as part of a multi |
||||
* shorthand declaration. Thus, this class does not allow inherit. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Instance of component definition to defer validation to. |
||||
* @todo Make protected |
||||
*/ |
||||
public $single; |
||||
|
||||
/** |
||||
* Max number of values allowed. |
||||
* @todo Make protected |
||||
*/ |
||||
public $max; |
||||
|
||||
/** |
||||
* @param $single HTMLPurifier_AttrDef to multiply |
||||
* @param $max Max number of values allowed (usually four) |
||||
*/ |
||||
public function __construct($single, $max = 4) { |
||||
$this->single = $single; |
||||
$this->max = $max; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$string = $this->parseCDATA($string); |
||||
if ($string === '') return false; |
||||
$parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n |
||||
$length = count($parts); |
||||
$final = ''; |
||||
for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) { |
||||
if (ctype_space($parts[$i])) continue; |
||||
$result = $this->single->validate($parts[$i], $config, $context); |
||||
if ($result !== false) { |
||||
$final .= $result . ' '; |
||||
$num++; |
||||
} |
||||
} |
||||
if ($final === '') return false; |
||||
return rtrim($final); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,69 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a number as defined by the CSS spec. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Bool indicating whether or not only positive values allowed. |
||||
*/ |
||||
protected $non_negative = false; |
||||
|
||||
/** |
||||
* @param $non_negative Bool indicating whether negatives are forbidden |
||||
*/ |
||||
public function __construct($non_negative = false) { |
||||
$this->non_negative = $non_negative; |
||||
} |
||||
|
||||
/** |
||||
* @warning Some contexts do not pass $config, $context. These |
||||
* variables should not be used without checking HTMLPurifier_Length |
||||
*/ |
||||
public function validate($number, $config, $context) { |
||||
|
||||
$number = $this->parseCDATA($number); |
||||
|
||||
if ($number === '') return false; |
||||
if ($number === '0') return '0'; |
||||
|
||||
$sign = ''; |
||||
switch ($number[0]) { |
||||
case '-': |
||||
if ($this->non_negative) return false; |
||||
$sign = '-'; |
||||
case '+': |
||||
$number = substr($number, 1); |
||||
} |
||||
|
||||
if (ctype_digit($number)) { |
||||
$number = ltrim($number, '0'); |
||||
return $number ? $sign . $number : '0'; |
||||
} |
||||
|
||||
// Period is the only non-numeric character allowed |
||||
if (strpos($number, '.') === false) return false; |
||||
|
||||
list($left, $right) = explode('.', $number, 2); |
||||
|
||||
if ($left === '' && $right === '') return false; |
||||
if ($left !== '' && !ctype_digit($left)) return false; |
||||
|
||||
$left = ltrim($left, '0'); |
||||
$right = rtrim($right, '0'); |
||||
|
||||
if ($right === '') { |
||||
return $left ? $sign . $left : '0'; |
||||
} elseif (!ctype_digit($right)) { |
||||
return false; |
||||
} |
||||
|
||||
return $sign . $left . '.' . $right; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,40 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a Percentage as defined by the CSS spec. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation |
||||
*/ |
||||
protected $number_def; |
||||
|
||||
/** |
||||
* @param Bool indicating whether to forbid negative values |
||||
*/ |
||||
public function __construct($non_negative = false) { |
||||
$this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative); |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = $this->parseCDATA($string); |
||||
|
||||
if ($string === '') return false; |
||||
$length = strlen($string); |
||||
if ($length === 1) return false; |
||||
if ($string[$length - 1] !== '%') return false; |
||||
|
||||
$number = substr($string, 0, $length - 1); |
||||
$number = $this->number_def->validate($number, $config, $context); |
||||
|
||||
if ($number === false) return false; |
||||
return "$number%"; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,38 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the value for the CSS property text-decoration |
||||
* @note This class could be generalized into a version that acts sort of |
||||
* like Enum except you can compound the allowed values. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
static $allowed_values = array( |
||||
'line-through' => true, |
||||
'overline' => true, |
||||
'underline' => true, |
||||
); |
||||
|
||||
$string = strtolower($this->parseCDATA($string)); |
||||
|
||||
if ($string === 'none') return $string; |
||||
|
||||
$parts = explode(' ', $string); |
||||
$final = ''; |
||||
foreach ($parts as $part) { |
||||
if (isset($allowed_values[$part])) { |
||||
$final .= $part . ' '; |
||||
} |
||||
} |
||||
$final = rtrim($final); |
||||
if ($final === '') return false; |
||||
return $final; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,56 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a URI in CSS syntax, which uses url('http://example.com') |
||||
* @note While theoretically speaking a URI in a CSS document could |
||||
* be non-embedded, as of CSS2 there is no such usage so we're |
||||
* generalizing it. This may need to be changed in the future. |
||||
* @warning Since HTMLPurifier_AttrDef_CSS blindly uses semicolons as |
||||
* the separator, you cannot put a literal semicolon in |
||||
* in the URI. Try percent encoding it, in that case. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI |
||||
{ |
||||
|
||||
public function __construct() { |
||||
parent::__construct(true); // always embedded |
||||
} |
||||
|
||||
public function validate($uri_string, $config, $context) { |
||||
// parse the URI out of the string and then pass it onto |
||||
// the parent object |
||||
|
||||
$uri_string = $this->parseCDATA($uri_string); |
||||
if (strpos($uri_string, 'url(') !== 0) return false; |
||||
$uri_string = substr($uri_string, 4); |
||||
$new_length = strlen($uri_string) - 1; |
||||
if ($uri_string[$new_length] != ')') return false; |
||||
$uri = trim(substr($uri_string, 0, $new_length)); |
||||
|
||||
if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) { |
||||
$quote = $uri[0]; |
||||
$new_length = strlen($uri) - 1; |
||||
if ($uri[$new_length] !== $quote) return false; |
||||
$uri = substr($uri, 1, $new_length - 1); |
||||
} |
||||
|
||||
$keys = array( '(', ')', ',', ' ', '"', "'"); |
||||
$values = array('\\(', '\\)', '\\,', '\\ ', '\\"', "\\'"); |
||||
$uri = str_replace($values, $keys, $uri); |
||||
|
||||
$result = parent::validate($uri, $config, $context); |
||||
|
||||
if ($result === false) return false; |
||||
|
||||
// escape necessary characters according to CSS spec |
||||
// except for the comma, none of these should appear in the |
||||
// URI at all |
||||
$result = str_replace($keys, $values, $result); |
||||
|
||||
return "url($result)"; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,65 +0,0 @@ |
||||
<?php |
||||
|
||||
// Enum = Enumerated |
||||
/** |
||||
* 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 |
||||
{ |
||||
|
||||
/** |
||||
* Lookup table of valid values. |
||||
* @todo Make protected |
||||
*/ |
||||
public $valid_values = array(); |
||||
|
||||
/** |
||||
* Bool indicating whether or not enumeration is case sensitive. |
||||
* @note In general this is always case insensitive. |
||||
*/ |
||||
protected $case_sensitive = false; // values according to W3C spec |
||||
|
||||
/** |
||||
* @param $valid_values List of valid values |
||||
* @param $case_sensitive Bool indicating whether or not case sensitive |
||||
*/ |
||||
public function __construct( |
||||
$valid_values = array(), $case_sensitive = false |
||||
) { |
||||
$this->valid_values = array_flip($valid_values); |
||||
$this->case_sensitive = $case_sensitive; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$string = trim($string); |
||||
if (!$this->case_sensitive) { |
||||
// we may want to do full case-insensitive libraries |
||||
$string = ctype_lower($string) ? $string : strtolower($string); |
||||
} |
||||
$result = isset($this->valid_values[$string]); |
||||
|
||||
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 |
||||
*/ |
||||
public 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); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,28 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a boolean attribute |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_Bool extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $name; |
||||
public $minimized = true; |
||||
|
||||
public function __construct($name = false) {$this->name = $name;} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
if (empty($string)) return false; |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* @param $string Name of attribute |
||||
*/ |
||||
public function make($string) { |
||||
return new HTMLPurifier_AttrDef_HTML_Bool($string); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,32 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a color according to the HTML spec. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public 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"; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,21 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Special-case enum attribute definition that lazy loads allowed frame targets |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum |
||||
{ |
||||
|
||||
public $valid_values = false; // uninitialized value |
||||
protected $case_sensitive = false; |
||||
|
||||
public function __construct() {} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
if ($this->valid_values === false) $this->valid_values = $config->get('Attr', 'AllowedFrameTargets'); |
||||
return parent::validate($string, $config, $context); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,70 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the HTML attribute ID. |
||||
* @warning Even though this is the id processor, it |
||||
* will ignore the directive Attr:IDBlacklist, since it will only |
||||
* go according to the ID accumulator. Since the accumulator is |
||||
* automatically generated, it will have already absorbed the |
||||
* blacklist. If you're hacking around, make sure you use load()! |
||||
*/ |
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
// ref functionality disabled, since we also have to verify |
||||
// whether or not the ID it refers to exists |
||||
|
||||
public function validate($id, $config, $context) { |
||||
|
||||
if (!$config->get('Attr', 'EnableID')) return false; |
||||
|
||||
$id = trim($id); // trim it first |
||||
|
||||
if ($id === '') return false; |
||||
|
||||
$prefix = $config->get('Attr', 'IDPrefix'); |
||||
if ($prefix !== '') { |
||||
$prefix .= $config->get('Attr', 'IDPrefixLocal'); |
||||
// prevent re-appending the prefix |
||||
if (strpos($id, $prefix) !== 0) $id = $prefix . $id; |
||||
} elseif ($config->get('Attr', 'IDPrefixLocal') !== '') { |
||||
trigger_error('%Attr.IDPrefixLocal cannot be used unless '. |
||||
'%Attr.IDPrefix is set', E_USER_WARNING); |
||||
} |
||||
|
||||
//if (!$this->ref) { |
||||
$id_accumulator =& $context->get('IDAccumulator'); |
||||
if (isset($id_accumulator->ids[$id])) return false; |
||||
//} |
||||
|
||||
// we purposely avoid using regex, hopefully this is faster |
||||
|
||||
if (ctype_alpha($id)) { |
||||
$result = true; |
||||
} else { |
||||
if (!ctype_alpha(@$id[0])) return false; |
||||
$trim = trim( // primitive style of regexps, I suppose |
||||
$id, |
||||
'A..Za..z0..9:-._' |
||||
); |
||||
$result = ($trim === ''); |
||||
} |
||||
|
||||
$regexp = $config->get('Attr', 'IDBlacklistRegexp'); |
||||
if ($regexp && preg_match($regexp, $id)) { |
||||
return false; |
||||
} |
||||
|
||||
if (/*!$this->ref && */$result) $id_accumulator->add($id); |
||||
|
||||
// if no change was made to the ID, return the result |
||||
// else, return the new id if stripping whitespace made it |
||||
// valid, or return false. |
||||
return $result ? $id : false; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,41 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the HTML type length (not to be confused with CSS's length). |
||||
* |
||||
* This accepts integer pixels or percentages as lengths for certain |
||||
* HTML attributes. |
||||
*/ |
||||
|
||||
class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = trim($string); |
||||
if ($string === '') return false; |
||||
|
||||
$parent_result = parent::validate($string, $config, $context); |
||||
if ($parent_result !== false) return $parent_result; |
||||
|
||||
$length = strlen($string); |
||||
$last_char = $string[$length - 1]; |
||||
|
||||
if ($last_char !== '%') return false; |
||||
|
||||
$points = substr($string, 0, $length - 1); |
||||
|
||||
if (!is_numeric($points)) return false; |
||||
|
||||
$points = (int) $points; |
||||
|
||||
if ($points < 0) return '0%'; |
||||
if ($points > 100) return '100%'; |
||||
|
||||
return ((string) $points) . '%'; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,53 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* 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. */ |
||||
protected $name; |
||||
|
||||
public function __construct($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]; |
||||
} |
||||
|
||||
public 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; |
||||
$string = implode(' ', array_keys($ret_lookup)); |
||||
|
||||
return $string; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,41 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a MultiLength as defined by the HTML spec. |
||||
* |
||||
* A multilength is either a integer (pixel count), a percentage, or |
||||
* a relative number. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = trim($string); |
||||
if ($string === '') return false; |
||||
|
||||
$parent_result = parent::validate($string, $config, $context); |
||||
if ($parent_result !== false) return $parent_result; |
||||
|
||||
$length = strlen($string); |
||||
$last_char = $string[$length - 1]; |
||||
|
||||
if ($last_char !== '*') return false; |
||||
|
||||
$int = substr($string, 0, $length - 1); |
||||
|
||||
if ($int == '') return '*'; |
||||
if (!is_numeric($int)) return false; |
||||
|
||||
$int = (int) $int; |
||||
|
||||
if ($int < 0) return false; |
||||
if ($int == 0) return '0'; |
||||
if ($int == 1) return '*'; |
||||
return ((string) $int) . '*'; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,48 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates contents based on NMTOKENS attribute type. |
||||
* @note The only current use for this is the class attribute in HTML |
||||
* @note Could have some functionality factored out into Nmtoken class |
||||
* @warning We cannot assume this class will be used only for 'class' |
||||
* attributes. Not sure how to hook in magic behavior, then. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = trim($string); |
||||
|
||||
// early abort: '' and '0' (strings that convert to false) are invalid |
||||
if (!$string) return false; |
||||
|
||||
// OPTIMIZABLE! |
||||
// do the preg_match, capture all subpatterns for reformulation |
||||
|
||||
// we don't support U+00A1 and up codepoints or |
||||
// escaping because I don't know how to do that with regexps |
||||
// and plus it would complicate optimization efforts (you never |
||||
// see that anyway). |
||||
$matches = array(); |
||||
$pattern = '/(?:(?<=\s)|\A)'. // look behind for space or string start |
||||
'((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'. |
||||
'(?:(?=\s)|\z)/'; // look ahead for space or string end |
||||
preg_match_all($pattern, $string, $matches); |
||||
|
||||
if (empty($matches[1])) return false; |
||||
|
||||
// reconstruct string |
||||
$new_string = ''; |
||||
foreach ($matches[1] as $token) { |
||||
$new_string .= $token . ' '; |
||||
} |
||||
$new_string = rtrim($new_string); |
||||
|
||||
return $new_string; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,48 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates an integer representation of pixels according to the HTML spec. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $max; |
||||
|
||||
public function __construct($max = null) { |
||||
$this->max = $max; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = trim($string); |
||||
if ($string === '0') return $string; |
||||
if ($string === '') return false; |
||||
$length = strlen($string); |
||||
if (substr($string, $length - 2) == 'px') { |
||||
$string = substr($string, 0, $length - 2); |
||||
} |
||||
if (!is_numeric($string)) return false; |
||||
$int = (int) $string; |
||||
|
||||
if ($int < 0) return '0'; |
||||
|
||||
// upper-bound value, extremely high values can |
||||
// crash operating systems, see <http://ha.ckers.org/imagecrash.html> |
||||
// WARNING, above link WILL crash you if you're using Windows |
||||
|
||||
if ($this->max !== null && $int > $this->max) return (string) $this->max; |
||||
|
||||
return (string) $int; |
||||
|
||||
} |
||||
|
||||
public function make($string) { |
||||
if ($string === '') $max = null; |
||||
else $max = (int) $string; |
||||
$class = get_class($this); |
||||
return new $class($max); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,73 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates an integer. |
||||
* @note While this class was modeled off the CSS definition, no currently |
||||
* allowed CSS uses this type. The properties that do are: widows, |
||||
* orphans, z-index, counter-increment, counter-reset. Some of the |
||||
* HTML attributes, however, find use for a non-negative version of this. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Bool indicating whether or not negative values are allowed |
||||
*/ |
||||
protected $negative = true; |
||||
|
||||
/** |
||||
* Bool indicating whether or not zero is allowed |
||||
*/ |
||||
protected $zero = true; |
||||
|
||||
/** |
||||
* Bool indicating whether or not positive values are allowed |
||||
*/ |
||||
protected $positive = true; |
||||
|
||||
/** |
||||
* @param $negative Bool indicating whether or not negative values are allowed |
||||
* @param $zero Bool indicating whether or not zero is allowed |
||||
* @param $positive Bool indicating whether or not positive values are allowed |
||||
*/ |
||||
public function __construct( |
||||
$negative = true, $zero = true, $positive = true |
||||
) { |
||||
$this->negative = $negative; |
||||
$this->zero = $zero; |
||||
$this->positive = $positive; |
||||
} |
||||
|
||||
public function validate($integer, $config, $context) { |
||||
|
||||
$integer = $this->parseCDATA($integer); |
||||
if ($integer === '') return false; |
||||
|
||||
// we could possibly simply typecast it to integer, but there are |
||||
// certain fringe cases that must not return an integer. |
||||
|
||||
// clip leading sign |
||||
if ( $this->negative && $integer[0] === '-' ) { |
||||
$digits = substr($integer, 1); |
||||
if ($digits === '0') $integer = '0'; // rm minus sign for zero |
||||
} elseif( $this->positive && $integer[0] === '+' ) { |
||||
$digits = $integer = substr($integer, 1); // rm unnecessary plus |
||||
} else { |
||||
$digits = $integer; |
||||
} |
||||
|
||||
// test if it's numeric |
||||
if (!ctype_digit($digits)) return false; |
||||
|
||||
// perform scope tests |
||||
if (!$this->zero && $integer == 0) return false; |
||||
if (!$this->positive && $integer > 0) return false; |
||||
if (!$this->negative && $integer < 0) return false; |
||||
|
||||
return $integer; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,73 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates the HTML attribute lang, effectively a language code. |
||||
* @note Built according to RFC 3066, which obsoleted RFC 1766 |
||||
*/ |
||||
class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
|
||||
$string = trim($string); |
||||
if (!$string) return false; |
||||
|
||||
$subtags = explode('-', $string); |
||||
$num_subtags = count($subtags); |
||||
|
||||
if ($num_subtags == 0) return false; // sanity check |
||||
|
||||
// process primary subtag : $subtags[0] |
||||
$length = strlen($subtags[0]); |
||||
switch ($length) { |
||||
case 0: |
||||
return false; |
||||
case 1: |
||||
if (! ($subtags[0] == 'x' || $subtags[0] == 'i') ) { |
||||
return false; |
||||
} |
||||
break; |
||||
case 2: |
||||
case 3: |
||||
if (! ctype_alpha($subtags[0]) ) { |
||||
return false; |
||||
} elseif (! ctype_lower($subtags[0]) ) { |
||||
$subtags[0] = strtolower($subtags[0]); |
||||
} |
||||
break; |
||||
default: |
||||
return false; |
||||
} |
||||
|
||||
$new_string = $subtags[0]; |
||||
if ($num_subtags == 1) return $new_string; |
||||
|
||||
// process second subtag : $subtags[1] |
||||
$length = strlen($subtags[1]); |
||||
if ($length == 0 || ($length == 1 && $subtags[1] != 'x') || $length > 8 || !ctype_alnum($subtags[1])) { |
||||
return $new_string; |
||||
} |
||||
if (!ctype_lower($subtags[1])) $subtags[1] = strtolower($subtags[1]); |
||||
|
||||
$new_string .= '-' . $subtags[1]; |
||||
if ($num_subtags == 2) return $new_string; |
||||
|
||||
// process all other subtags, index 2 and up |
||||
for ($i = 2; $i < $num_subtags; $i++) { |
||||
$length = strlen($subtags[$i]); |
||||
if ($length == 0 || $length > 8 || !ctype_alnum($subtags[$i])) { |
||||
return $new_string; |
||||
} |
||||
if (!ctype_lower($subtags[$i])) { |
||||
$subtags[$i] = strtolower($subtags[$i]); |
||||
} |
||||
$new_string .= '-' . $subtags[$i]; |
||||
} |
||||
|
||||
return $new_string; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,34 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Decorator that, depending on a token, switches between two definitions. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_Switch |
||||
{ |
||||
|
||||
protected $tag; |
||||
protected $withTag, $withoutTag; |
||||
|
||||
/** |
||||
* @param string $tag Tag name to switch upon |
||||
* @param HTMLPurifier_AttrDef $with_tag Call if token matches tag |
||||
* @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token |
||||
*/ |
||||
public function __construct($tag, $with_tag, $without_tag) { |
||||
$this->tag = $tag; |
||||
$this->withTag = $with_tag; |
||||
$this->withoutTag = $without_tag; |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$token = $context->get('CurrentToken', true); |
||||
if (!$token || $token->name !== $this->tag) { |
||||
return $this->withoutTag->validate($string, $config, $context); |
||||
} else { |
||||
return $this->withTag->validate($string, $config, $context); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,15 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates arbitrary text according to the HTML spec. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
return $this->parseCDATA($string); |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,77 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a URI as defined by RFC 3986. |
||||
* @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme |
||||
*/ |
||||
class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
protected $parser; |
||||
protected $embedsResource; |
||||
|
||||
/** |
||||
* @param $embeds_resource_resource Does the URI here result in an extra HTTP request? |
||||
*/ |
||||
public function __construct($embeds_resource = false) { |
||||
$this->parser = new HTMLPurifier_URIParser(); |
||||
$this->embedsResource = (bool) $embeds_resource; |
||||
} |
||||
|
||||
public function make($string) { |
||||
$embeds = (bool) $string; |
||||
return new HTMLPurifier_AttrDef_URI($embeds); |
||||
} |
||||
|
||||
public function validate($uri, $config, $context) { |
||||
|
||||
if ($config->get('URI', 'Disable')) return false; |
||||
|
||||
$uri = $this->parseCDATA($uri); |
||||
|
||||
// parse the URI |
||||
$uri = $this->parser->parse($uri); |
||||
if ($uri === false) return false; |
||||
|
||||
// add embedded flag to context for validators |
||||
$context->register('EmbeddedURI', $this->embedsResource); |
||||
|
||||
$ok = false; |
||||
do { |
||||
|
||||
// generic validation |
||||
$result = $uri->validate($config, $context); |
||||
if (!$result) break; |
||||
|
||||
// chained filtering |
||||
$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; |
||||
|
||||
// Post chained filtering |
||||
$result = $uri_def->postFilter($uri, $config, $context); |
||||
if (!$result) break; |
||||
|
||||
// survived gauntlet |
||||
$ok = true; |
||||
|
||||
} while (false); |
||||
|
||||
$context->destroy('EmbeddedURI'); |
||||
if (!$ok) return false; |
||||
|
||||
// back to string |
||||
return $uri->toString(); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,17 +0,0 @@ |
||||
<?php |
||||
|
||||
abstract class HTMLPurifier_AttrDef_URI_Email extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Unpacks a mailbox into its display-name and address |
||||
*/ |
||||
function unpack($string) { |
||||
// needs to be implemented |
||||
} |
||||
|
||||
} |
||||
|
||||
// sub-implementations |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,21 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Primitive email validation class based on the regexp found at |
||||
* http://www.regular-expressions.info/email.html |
||||
*/ |
||||
class HTMLPurifier_AttrDef_URI_Email_SimpleCheck extends HTMLPurifier_AttrDef_URI_Email |
||||
{ |
||||
|
||||
public function validate($string, $config, $context) { |
||||
// no support for named mailboxes i.e. "Bob <bob@example.com>" |
||||
// that needs more percent encoding to be done |
||||
if ($string == '') return false; |
||||
$string = trim($string); |
||||
$result = preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $string); |
||||
return $result ? $string : false; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,62 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates a host according to the IPv4, IPv6 and DNS (future) specifications. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator |
||||
*/ |
||||
protected $ipv4; |
||||
|
||||
/** |
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator |
||||
*/ |
||||
protected $ipv6; |
||||
|
||||
public function __construct() { |
||||
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4(); |
||||
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6(); |
||||
} |
||||
|
||||
public function validate($string, $config, $context) { |
||||
$length = strlen($string); |
||||
if ($string === '') return ''; |
||||
if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') { |
||||
//IPv6 |
||||
$ip = substr($string, 1, $length - 2); |
||||
$valid = $this->ipv6->validate($ip, $config, $context); |
||||
if ($valid === false) return false; |
||||
return '['. $valid . ']'; |
||||
} |
||||
|
||||
// need to do checks on unusual encodings too |
||||
$ipv4 = $this->ipv4->validate($string, $config, $context); |
||||
if ($ipv4 !== false) return $ipv4; |
||||
|
||||
// A regular domain name. |
||||
|
||||
// This breaks I18N domain names, but we don't have proper IRI support, |
||||
// so force users to insert Punycode. If there's complaining we'll |
||||
// try to fix things into an international friendly form. |
||||
|
||||
// The productions describing this are: |
||||
$a = '[a-z]'; // alpha |
||||
$an = '[a-z0-9]'; // alphanum |
||||
$and = '[a-z0-9-]'; // alphanum | "-" |
||||
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum |
||||
$domainlabel = "$an($and*$an)?"; |
||||
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum |
||||
$toplabel = "$a($and*$an)?"; |
||||
// hostname = *( domainlabel "." ) toplabel [ "." ] |
||||
$match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string); |
||||
if (!$match) return false; |
||||
|
||||
return $string; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,39 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates an IPv4 address |
||||
* @author Feyd @ forums.devnetwork.net (public domain) |
||||
*/ |
||||
class HTMLPurifier_AttrDef_URI_IPv4 extends HTMLPurifier_AttrDef |
||||
{ |
||||
|
||||
/** |
||||
* IPv4 regex, protected so that IPv6 can reuse it |
||||
*/ |
||||
protected $ip4; |
||||
|
||||
public function validate($aIP, $config, $context) { |
||||
|
||||
if (!$this->ip4) $this->_loadRegex(); |
||||
|
||||
if (preg_match('#^' . $this->ip4 . '$#s', $aIP)) |
||||
{ |
||||
return $aIP; |
||||
} |
||||
|
||||
return false; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Lazy load function to prevent regex from being stuffed in |
||||
* cache. |
||||
*/ |
||||
protected 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})"; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,99 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates an IPv6 address. |
||||
* @author Feyd @ forums.devnetwork.net (public domain) |
||||
* @note This function requires brackets to have been removed from address |
||||
* in URI. |
||||
*/ |
||||
class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4 |
||||
{ |
||||
|
||||
public function validate($aIP, $config, $context) { |
||||
|
||||
if (!$this->ip4) $this->_loadRegex(); |
||||
|
||||
$original = $aIP; |
||||
|
||||
$hex = '[0-9a-fA-F]'; |
||||
$blk = '(?:' . $hex . '{1,4})'; |
||||
$pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128 |
||||
|
||||
// prefix check |
||||
if (strpos($aIP, '/') !== false) |
||||
{ |
||||
if (preg_match('#' . $pre . '$#s', $aIP, $find)) |
||||
{ |
||||
$aIP = substr($aIP, 0, 0-strlen($find[0])); |
||||
unset($find); |
||||
} |
||||
else |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
// IPv4-compatiblity check |
||||
if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find)) |
||||
{ |
||||
$aIP = substr($aIP, 0, 0-strlen($find[0])); |
||||
$ip = explode('.', $find[0]); |
||||
$ip = array_map('dechex', $ip); |
||||
$aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3]; |
||||
unset($find, $ip); |
||||
} |
||||
|
||||
// compression check |
||||
$aIP = explode('::', $aIP); |
||||
$c = count($aIP); |
||||
if ($c > 2) |
||||
{ |
||||
return false; |
||||
} |
||||
elseif ($c == 2) |
||||
{ |
||||
list($first, $second) = $aIP; |
||||
$first = explode(':', $first); |
||||
$second = explode(':', $second); |
||||
|
||||
if (count($first) + count($second) > 8) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
while(count($first) < 8) |
||||
{ |
||||
array_push($first, '0'); |
||||
} |
||||
|
||||
array_splice($first, 8 - count($second), 8, $second); |
||||
$aIP = $first; |
||||
unset($first,$second); |
||||
} |
||||
else |
||||
{ |
||||
$aIP = explode(':', $aIP[0]); |
||||
} |
||||
$c = count($aIP); |
||||
|
||||
if ($c != 8) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
// All the pieces should be 16-bit hex strings. Are they? |
||||
foreach ($aIP as $piece) |
||||
{ |
||||
if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece))) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return $original; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,56 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Processes an entire attribute array for corrections needing multiple values. |
||||
* |
||||
* Occasionally, a certain attribute will need to be removed and popped onto |
||||
* another value. Instead of creating a complex return syntax for |
||||
* HTMLPurifier_AttrDef, we just pass the whole attribute array to a |
||||
* specialized object and have that do the special work. That is the |
||||
* family of HTMLPurifier_AttrTransform. |
||||
* |
||||
* An attribute transformation can be assigned to run before or after |
||||
* HTMLPurifier_AttrDef validation. See HTMLPurifier_HTMLDefinition for |
||||
* more details. |
||||
*/ |
||||
|
||||
abstract class HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
/** |
||||
* Abstract: makes changes to the attributes dependent on multiple values. |
||||
* |
||||
* @param $attr Assoc array of attributes, usually from |
||||
* HTMLPurifier_Token_Tag::$attr |
||||
* @param $config Mandatory HTMLPurifier_Config object. |
||||
* @param $context Mandatory HTMLPurifier_Context object |
||||
* @returns Processed attribute array. |
||||
*/ |
||||
abstract public function transform($attr, $config, $context); |
||||
|
||||
/** |
||||
* 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 |
||||
*/ |
||||
public 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 |
||||
*/ |
||||
public function confiscateAttr(&$attr, $key) { |
||||
if (!isset($attr[$key])) return null; |
||||
$value = $attr[$key]; |
||||
unset($attr[$key]); |
||||
return $value; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,23 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Pre-transform that changes proprietary background attribute to CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Background extends HTMLPurifier_AttrTransform { |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
|
||||
if (!isset($attr['background'])) return $attr; |
||||
|
||||
$background = $this->confiscateAttr($attr, 'background'); |
||||
// some validation should happen here |
||||
|
||||
$this->prependCSS($attr, "background-image:url($background);"); |
||||
|
||||
return $attr; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,19 +0,0 @@ |
||||
<?php |
||||
|
||||
// this MUST be placed in post, as it assumes that any value in dir is valid |
||||
|
||||
/** |
||||
* Post-trasnform that ensures that bdo tags have the dir attribute set. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
if (isset($attr['dir'])) return $attr; |
||||
$attr['dir'] = $config->get('Attr', 'DefaultTextDir'); |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,23 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Pre-transform that changes deprecated bgcolor attribute to CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_BgColor extends HTMLPurifier_AttrTransform { |
||||
|
||||
public 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; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,36 +0,0 @@ |
||||
<?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 |
||||
*/ |
||||
protected $attr; |
||||
|
||||
/** |
||||
* CSS declarations to add to style, needs trailing semicolon |
||||
*/ |
||||
protected $css; |
||||
|
||||
/** |
||||
* @param $attr string attribute name to convert from |
||||
* @param $css string CSS declarations to add to style (needs semicolon) |
||||
*/ |
||||
public function __construct($attr, $css) { |
||||
$this->attr = $attr; |
||||
$this->css = $css; |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
if (!isset($attr[$this->attr])) return $attr; |
||||
unset($attr[$this->attr]); |
||||
$this->prependCSS($attr, $this->css); |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,18 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Pre-transform that changes deprecated border attribute to CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Border extends HTMLPurifier_AttrTransform { |
||||
|
||||
public 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; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,58 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Generic pre-transform that converts an attribute with a fixed number of |
||||
* values (enumerated) to CSS. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform { |
||||
|
||||
/** |
||||
* Name of attribute to transform from |
||||
*/ |
||||
protected $attr; |
||||
|
||||
/** |
||||
* Lookup array of attribute values to CSS |
||||
*/ |
||||
protected $enumToCSS = array(); |
||||
|
||||
/** |
||||
* Case sensitivity of the matching |
||||
* @warning Currently can only be guaranteed to work with ASCII |
||||
* values. |
||||
*/ |
||||
protected $caseSensitive = false; |
||||
|
||||
/** |
||||
* @param $attr String attribute name to transform from |
||||
* @param $enumToCSS Lookup array of attribute values to CSS |
||||
* @param $case_sensitive Boolean case sensitivity indicator, default false |
||||
*/ |
||||
public function __construct($attr, $enum_to_css, $case_sensitive = false) { |
||||
$this->attr = $attr; |
||||
$this->enumToCSS = $enum_to_css; |
||||
$this->caseSensitive = (bool) $case_sensitive; |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
|
||||
if (!isset($attr[$this->attr])) return $attr; |
||||
|
||||
$value = trim($attr[$this->attr]); |
||||
unset($attr[$this->attr]); |
||||
|
||||
if (!$this->caseSensitive) $value = strtolower($value); |
||||
|
||||
if (!isset($this->enumToCSS[$value])) { |
||||
return $attr; |
||||
} |
||||
|
||||
$this->prependCSS($attr, $this->enumToCSS[$value]); |
||||
|
||||
return $attr; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,42 +0,0 @@ |
||||
<?php |
||||
|
||||
// must be called POST validation |
||||
|
||||
/** |
||||
* Transform that supplies default values for the src and alt attributes |
||||
* in img tags, as well as prevents the img tag from being removed |
||||
* because of a missing alt tag. This needs to be registered as both |
||||
* a pre and post attribute transform. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
|
||||
$src = true; |
||||
if (!isset($attr['src'])) { |
||||
if ($config->get('Core', 'RemoveInvalidImg')) return $attr; |
||||
$attr['src'] = $config->get('Attr', 'DefaultInvalidImage'); |
||||
$src = false; |
||||
} |
||||
|
||||
if (!isset($attr['alt'])) { |
||||
if ($src) { |
||||
$alt = $config->get('Attr', 'DefaultImageAlt'); |
||||
if ($alt === null) { |
||||
$attr['alt'] = basename($attr['src']); |
||||
} else { |
||||
$attr['alt'] = $alt; |
||||
} |
||||
} else { |
||||
$attr['alt'] = $config->get('Attr', 'DefaultInvalidImageAlt'); |
||||
} |
||||
} |
||||
|
||||
return $attr; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,44 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Pre-transform that changes deprecated hspace and vspace attributes to CSS |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform { |
||||
|
||||
protected $attr; |
||||
protected $css = array( |
||||
'hspace' => array('left', 'right'), |
||||
'vspace' => array('top', 'bottom') |
||||
); |
||||
|
||||
public function __construct($attr) { |
||||
$this->attr = $attr; |
||||
if (!isset($this->css[$attr])) { |
||||
trigger_error(htmlspecialchars($attr) . ' is not valid space attribute'); |
||||
} |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
|
||||
if (!isset($attr[$this->attr])) return $attr; |
||||
|
||||
$width = $this->confiscateAttr($attr, $this->attr); |
||||
// some validation could happen here |
||||
|
||||
if (!isset($this->css[$this->attr])) return $attr; |
||||
|
||||
$style = ''; |
||||
foreach ($this->css[$this->attr] as $suffix) { |
||||
$property = "margin-$suffix"; |
||||
$style .= "$property:{$width}px;"; |
||||
} |
||||
|
||||
$this->prependCSS($attr, $style); |
||||
|
||||
return $attr; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,40 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Performs miscellaneous cross attribute validation and filtering for |
||||
* input elements. This is meant to be a post-transform. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform { |
||||
|
||||
protected $pixels; |
||||
|
||||
public function __construct() { |
||||
$this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels(); |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
if (!isset($attr['type'])) $t = 'text'; |
||||
else $t = strtolower($attr['type']); |
||||
if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') { |
||||
unset($attr['checked']); |
||||
} |
||||
if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') { |
||||
unset($attr['maxlength']); |
||||
} |
||||
if (isset($attr['size']) && $t !== 'text' && $t !== 'password') { |
||||
$result = $this->pixels->validate($attr['size'], $config, $context); |
||||
if ($result === false) unset($attr['size']); |
||||
else $attr['size'] = $result; |
||||
} |
||||
if (isset($attr['src']) && $t !== 'image') { |
||||
unset($attr['src']); |
||||
} |
||||
if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) { |
||||
$attr['value'] = ''; |
||||
} |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,28 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Post-transform that copies lang's value to xml:lang (and vice-versa) |
||||
* @note Theoretically speaking, this could be a pre-transform, but putting |
||||
* post is more efficient. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
|
||||
$lang = isset($attr['lang']) ? $attr['lang'] : false; |
||||
$xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false; |
||||
|
||||
if ($lang !== false && $xml_lang === false) { |
||||
$attr['xml:lang'] = $lang; |
||||
} elseif ($xml_lang !== false) { |
||||
$attr['lang'] = $xml_lang; |
||||
} |
||||
|
||||
return $attr; |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,27 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Class for handling width/height length attribute transformations to CSS |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
protected $name; |
||||
protected $cssName; |
||||
|
||||
public function __construct($name, $css_name = null) { |
||||
$this->name = $name; |
||||
$this->cssName = $css_name ? $css_name : $name; |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
if (!isset($attr[$this->name])) return $attr; |
||||
$length = $this->confiscateAttr($attr, $this->name); |
||||
if(ctype_digit($length)) $length .= 'px'; |
||||
$this->prependCSS($attr, $this->cssName . ":$length;"); |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,19 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Pre-transform that changes deprecated name attribute to ID if necessary |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
if (!isset($attr['name'])) return $attr; |
||||
$id = $this->confiscateAttr($attr, 'name'); |
||||
if ( isset($attr['id'])) return $attr; |
||||
$attr['id'] = $id; |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,15 +0,0 @@ |
||||
<?php |
||||
|
||||
class HTMLPurifier_AttrTransform_SafeEmbed extends HTMLPurifier_AttrTransform |
||||
{ |
||||
public $name = "SafeEmbed"; |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
$attr['allowscriptaccess'] = 'never'; |
||||
$attr['allownetworking'] = 'internal'; |
||||
$attr['type'] = 'application/x-shockwave-flash'; |
||||
return $attr; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,16 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Writes default type for all objects. Currently only supports flash. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_SafeObject extends HTMLPurifier_AttrTransform |
||||
{ |
||||
public $name = "SafeObject"; |
||||
|
||||
function transform($attr, $config, $context) { |
||||
if (!isset($attr['type'])) $attr['type'] = 'application/x-shockwave-flash'; |
||||
return $attr; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,50 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Validates name/value pairs in param tags to be used in safe objects. This |
||||
* will only allow name values it recognizes, and pre-fill certain attributes |
||||
* with required values. |
||||
* |
||||
* @note |
||||
* This class only supports Flash. In the future, Quicktime support |
||||
* may be added. |
||||
* |
||||
* @warning |
||||
* This class expects an injector to add the necessary parameters tags. |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_SafeParam extends HTMLPurifier_AttrTransform |
||||
{ |
||||
public $name = "SafeParam"; |
||||
private $uri; |
||||
|
||||
public function __construct() { |
||||
$this->uri = new HTMLPurifier_AttrDef_URI(true); // embedded |
||||
} |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
// If we add support for other objects, we'll need to alter the |
||||
// transforms. |
||||
switch ($attr['name']) { |
||||
// application/x-shockwave-flash |
||||
// Keep this synchronized with Injector/SafeObject.php |
||||
case 'allowScriptAccess': |
||||
$attr['value'] = 'never'; |
||||
break; |
||||
case 'allowNetworking': |
||||
$attr['value'] = 'internal'; |
||||
break; |
||||
case 'wmode': |
||||
$attr['value'] = 'window'; |
||||
break; |
||||
case 'movie': |
||||
$attr['value'] = $this->uri->validate($attr['value'], $config, $context); |
||||
break; |
||||
// add other cases to support other param name/value pairs |
||||
default: |
||||
$attr['name'] = $attr['value'] = null; |
||||
} |
||||
return $attr; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,16 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Implements required attribute stipulation for <script> |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_ScriptRequired extends HTMLPurifier_AttrTransform |
||||
{ |
||||
public function transform($attr, $config, $context) { |
||||
if (!isset($attr['type'])) { |
||||
$attr['type'] = 'text/javascript'; |
||||
} |
||||
return $attr; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,18 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Sets height/width defaults for <textarea> |
||||
*/ |
||||
class HTMLPurifier_AttrTransform_Textarea extends HTMLPurifier_AttrTransform |
||||
{ |
||||
|
||||
public function transform($attr, $config, $context) { |
||||
// Calculated from Firefox |
||||
if (!isset($attr['cols'])) $attr['cols'] = '22'; |
||||
if (!isset($attr['rows'])) $attr['rows'] = '3'; |
||||
return $attr; |
||||
} |
||||
|
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
@ -1,74 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Provides lookup array of attribute types to HTMLPurifier_AttrDef objects |
||||
*/ |
||||
class HTMLPurifier_AttrTypes |
||||
{ |
||||
/** |
||||
* Lookup array of attribute string identifiers to concrete implementations |
||||
*/ |
||||
protected $info = array(); |
||||
|
||||
/** |
||||
* Constructs the info array, supplying default implementations for attribute |
||||
* types. |
||||
*/ |
||||
public function __construct() { |
||||
// pseudo-types, must be instantiated via shorthand |
||||
$this->info['Enum'] = new HTMLPurifier_AttrDef_Enum(); |
||||
$this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool(); |
||||
|
||||
$this->info['CDATA'] = new HTMLPurifier_AttrDef_Text(); |
||||
$this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID(); |
||||
$this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length(); |
||||
$this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength(); |
||||
$this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens(); |
||||
$this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels(); |
||||
$this->info['Text'] = new HTMLPurifier_AttrDef_Text(); |
||||
$this->info['URI'] = new HTMLPurifier_AttrDef_URI(); |
||||
$this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang(); |
||||
$this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color(); |
||||
|
||||
// unimplemented aliases |
||||
$this->info['ContentType'] = new HTMLPurifier_AttrDef_Text(); |
||||
$this->info['ContentTypes'] = new HTMLPurifier_AttrDef_Text(); |
||||
$this->info['Charsets'] = new HTMLPurifier_AttrDef_Text(); |
||||
$this->info['Character'] = new HTMLPurifier_AttrDef_Text(); |
||||
|
||||
// number is really a positive integer (one or more digits) |
||||
// FIXME: ^^ not always, see start and value of list items |
||||
$this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true); |
||||
} |
||||
|
||||
/** |
||||
* Retrieves a type |
||||
* @param $type String type name |
||||
* @return Object AttrDef for type |
||||
*/ |
||||
public function get($type) { |
||||
|
||||
// determine if there is any extra info tacked on |
||||
if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2); |
||||
else $string = ''; |
||||
|
||||
if (!isset($this->info[$type])) { |
||||
trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR); |
||||
return; |
||||
} |
||||
|
||||
return $this->info[$type]->make($string); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Sets a new implementation for a type |
||||
* @param $type String type name |
||||
* @param $impl Object AttrDef for type |
||||
*/ |
||||
public function set($type, $impl) { |
||||
$this->info[$type] = $impl; |
||||
} |
||||
} |
||||
|
||||
// vim: et sw=4 sts=4 |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue