Exemple #1
0
<?php

// overload default configuration schema temporarily
$custom_schema = new HTMLPurifier_ConfigSchema();
$old = HTMLPurifier_ConfigSchema::instance();
$custom_schema =& HTMLPurifier_ConfigSchema::instance($custom_schema);
HTMLPurifier_ConfigSchema::defineNamespace('Element', 'Chemical substances that cannot be further decomposed');
HTMLPurifier_ConfigSchema::define('Element', 'Abbr', 'H', 'string', 'Abbreviation of element name.');
HTMLPurifier_ConfigSchema::define('Element', 'Name', 'hydrogen', 'istring', 'Full name of atoms.');
HTMLPurifier_ConfigSchema::define('Element', 'Number', 1, 'int', 'Atomic number, is identity.');
HTMLPurifier_ConfigSchema::define('Element', 'Mass', 1.00794, 'float', 'Atomic mass.');
HTMLPurifier_ConfigSchema::define('Element', 'Radioactive', false, 'bool', 'Does it have rapid decay?');
HTMLPurifier_ConfigSchema::define('Element', 'Isotopes', array('1' => true, '2' => true, '3' => true), 'lookup', 'What numbers of neutrons for this element have been observed?');
HTMLPurifier_ConfigSchema::define('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', 'What are general properties of the element?');
HTMLPurifier_ConfigSchema::define('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash', 'Lookup hash of neutron counts to formal names.');
HTMLPurifier_ConfigSchema::defineNamespace('Instrument', 'Of the musical type.');
HTMLPurifier_ConfigSchema::define('Instrument', 'Manufacturer', 'Yamaha', 'string', 'Who made it?');
HTMLPurifier_ConfigSchema::defineAllowedValues('Instrument', 'Manufacturer', array('Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other'));
HTMLPurifier_ConfigSchema::defineValueAliases('Instrument', 'Manufacturer', array('Selmer' => 'Conn-Selmer'));
HTMLPurifier_ConfigSchema::define('Instrument', 'Family', 'woodwind', 'istring', 'What family is it?');
HTMLPurifier_ConfigSchema::defineAllowedValues('Instrument', 'Family', array('brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic'));
HTMLPurifier_ConfigSchema::defineValueAliases('Instrument', 'Family', array('synth' => 'electronic'));
HTMLPurifier_ConfigSchema::defineNamespace('ReportCard', 'It is for grades.');
HTMLPurifier_ConfigSchema::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.');
HTMLPurifier_ConfigSchema::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?');
HTMLPurifier_ConfigSchema::defineNamespace('Text', 'This stuff is long, boring, and English.');
HTMLPurifier_ConfigSchema::define('Text', 'AboutUs', 'Nothing much, but this should be decently long so that a textarea would be better', 'text', 'Who are we? What are we up to?');
HTMLPurifier_ConfigSchema::define('Text', 'Hash', "not-case-sensitive\nstill-not-case-sensitive\nsuper-not-case-sensitive", 'itext', 'This is of limited utility, but of course it ends up being used.');
Exemple #2
0
<?php

HTMLPurifier_ConfigSchema::define('Core', 'Encoding', 'utf-8', 'istring', 'If for some reason you are unable to convert all webpages to UTF-8, ' . 'you can use this directive as a stop-gap compatibility change to ' . 'let HTML Purifier deal with non UTF-8 input.  This technique has ' . 'notable deficiencies: absolutely no characters outside of the selected ' . 'character encoding will be preserved, not even the ones that have ' . 'been ampersand escaped (this is due to a UTF-8 specific <em>feature</em> ' . 'that automatically resolves all entities), making it pretty useless ' . 'for anything except the most I18N-blind applications, although ' . '%Core.EscapeNonASCIICharacters offers fixes this trouble with ' . 'another tradeoff. This directive ' . 'only accepts ISO-8859-1 if iconv is not enabled.');
HTMLPurifier_ConfigSchema::define('Core', 'EscapeNonASCIICharacters', false, 'bool', 'This directive overcomes a deficiency in %Core.Encoding by blindly ' . 'converting all non-ASCII characters into decimal numeric entities before ' . 'converting it to its native encoding. This means that even ' . 'characters that can be expressed in the non-UTF-8 encoding will ' . 'be entity-ized, which can be a real downer for encodings like Big5. ' . 'It also assumes that the ASCII repetoire is available, although ' . 'this is the case for almost all encodings. Anyway, use UTF-8! This ' . 'directive has been available since 1.4.0.');
if (!function_exists('iconv')) {
    // only encodings with native PHP support
    HTMLPurifier_ConfigSchema::defineAllowedValues('Core', 'Encoding', array('utf-8', 'iso-8859-1'));
    HTMLPurifier_ConfigSchema::defineValueAliases('Core', 'Encoding', array('iso8859-1' => 'iso-8859-1'));
}
HTMLPurifier_ConfigSchema::define('Test', 'ForceNoIconv', false, 'bool', 'When set to true, HTMLPurifier_Encoder will act as if iconv does not ' . 'exist and use only pure PHP implementations.');
/**
 * A UTF-8 specific character encoder that handles cleaning and transforming.
 * @note All functions in this class should be static.
 */
class HTMLPurifier_Encoder
{
    /**
     * Constructor throws fatal error if you attempt to instantiate class
     */
    private function __construct()
    {
        trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
    }
    /**
     * Cleans a UTF-8 string for well-formedness and SGML validity
     * 
     * It will parse according to UTF-8 and return a valid UTF8 string, with
     * non-SGML codepoints excluded.
     * 
     * @note Just for reference, the non-SGML code points are 0 to 31 and
     *       127 to 159, inclusive.  However, we allow code points 9, 10
require_once 'HTMLPurifier/HTMLModule/Image.php';
require_once 'HTMLPurifier/HTMLModule/StyleAttribute.php';
require_once 'HTMLPurifier/HTMLModule/Legacy.php';
require_once 'HTMLPurifier/HTMLModule/Target.php';
require_once 'HTMLPurifier/HTMLModule/Scripting.php';
require_once 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php';
require_once 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php';
require_once 'HTMLPurifier/HTMLModule/Ruby.php';
require_once 'HTMLPurifier/HTMLModule/Object.php';
// tidy modules
require_once 'HTMLPurifier/HTMLModule/Tidy.php';
require_once 'HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php';
require_once 'HTMLPurifier/HTMLModule/Tidy/XHTML.php';
require_once 'HTMLPurifier/HTMLModule/Tidy/Proprietary.php';
HTMLPurifier_ConfigSchema::define('HTML', 'Doctype', '', 'string', 'Doctype to use during filtering. ' . 'Technically speaking this is not actually a doctype (as it does ' . 'not identify a corresponding DTD), but we are using this name ' . 'for sake of simplicity. When non-blank, this will override any older directives ' . 'like %HTML.XHTML or %HTML.Strict.');
HTMLPurifier_ConfigSchema::defineAllowedValues('HTML', 'Doctype', array('', 'HTML 4.01 Transitional', 'HTML 4.01 Strict', 'XHTML 1.0 Transitional', 'XHTML 1.0 Strict', 'XHTML 1.1'));
HTMLPurifier_ConfigSchema::define('HTML', 'CustomDoctype', null, 'string/null', '
A custom doctype for power-users who defined there own document
type. This directive only applies when %HTML.Doctype is blank.
This directive has been available since 2.0.1.
');
HTMLPurifier_ConfigSchema::define('HTML', 'Trusted', false, 'bool', 'Indicates whether or not the user input is trusted or not. If the ' . 'input is trusted, a more expansive set of allowed tags and attributes ' . 'will be used. This directive has been available since 2.0.0.');
HTMLPurifier_ConfigSchema::define('HTML', 'AllowedModules', null, 'lookup/null', '
<p>
    A doctype comes with a set of usual modules to use. Without having
    to mucking about with the doctypes, you can quickly activate or
    disable these modules by specifying which modules you wish to allow
    with this directive. This is most useful for unit testing specific
    modules, although end users may find it useful for their own ends.
</p>
<p>
Exemple #4
0
There are four allowed values:</p>
<dl>
    <dt>none</dt>
    <dd>No extra tidying should be done</dd>
    <dt>light</dt>
    <dd>Only fix elements that would be discarded otherwise due to
    lack of support in doctype</dd>
    <dt>medium</dt>
    <dd>Enforce best practices</dd>
    <dt>heavy</dt>
    <dd>Transform all deprecated elements and attributes to standards
    compliant equivalents</dd>
</dl>
<p>This directive has been available since 2.0.0</p>
');
HTMLPurifier_ConfigSchema::defineAllowedValues('HTML', 'TidyLevel', array('none', 'light', 'medium', 'heavy'));
HTMLPurifier_ConfigSchema::define('HTML', 'TidyAdd', array(), 'lookup', '
Fixes to add to the default set of Tidy fixes as per your level. This
directive has been available since 2.0.0.
');
HTMLPurifier_ConfigSchema::define('HTML', 'TidyRemove', array(), 'lookup', '
Fixes to remove from the default set of Tidy fixes as per your level. This
directive has been available since 2.0.0.
');
/**
 * Abstract class for a set of proprietary modules that clean up (tidy)
 * poorly written HTML.
 */
class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
{
    /**
Exemple #5
0
<?php

require_once 'HTMLPurifier/AttrTransform.php';
// this MUST be placed in post, as it assumes that any value in dir is valid
HTMLPurifier_ConfigSchema::define('Attr', 'DefaultTextDir', 'ltr', 'string', 'Defines the default text direction (ltr or rtl) of the document ' . 'being parsed.  This generally is the same as the value of the dir ' . 'attribute in HTML, or ltr if that is not specified.');
HTMLPurifier_ConfigSchema::defineAllowedValues('Attr', 'DefaultTextDir', array('ltr', 'rtl'));
/**
 * Post-trasnform that ensures that bdo tags have the dir attribute set.
 */
class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform
{
    function transform($attr, $config, &$context)
    {
        if (isset($attr['dir'])) {
            return $attr;
        }
        $attr['dir'] = $config->get('Attr', 'DefaultTextDir');
        return $attr;
    }
}
<?php

require_once 'HTMLPurifier/DefinitionCache.php';
HTMLPurifier_ConfigSchema::define('Cache', 'DefinitionImpl', 'Serializer', 'string/null', '
This directive defines which method to use when caching definitions,
the complex data-type that makes HTML Purifier tick. Set to null
to disable caching (not recommended, as you will see a definite
performance degradation). This directive has been available since 2.0.0.
');
HTMLPurifier_ConfigSchema::defineAllowedValues('Cache', 'DefinitionImpl', array('Serializer'));
HTMLPurifier_ConfigSchema::defineAlias('Core', 'DefinitionCache', 'Cache', 'DefinitionImpl');
/**
 * Responsible for creating definition caches.
 */
class HTMLPurifier_DefinitionCacheFactory
{
    var $caches = array('Serializer' => array());
    var $decorators = array();
    /**
     * Initialize default decorators
     */
    function setup()
    {
        $this->addDecorator('Cleanup');
    }
    /**
     * Retrieves an instance of global definition cache factory.
     * @static
     */
    static function &instance($prototype = null)
    {