5 WARNING: THIS MODULE IS EXTREMELY DANGEROUS AS IT ENABLES INLINE SCRIPTING
6 INSIDE HTML PURIFIER DOCUMENTS. USE ONLY WITH TRUSTED USER INPUT!!!
10 require_once 'HTMLPurifier/HTMLModule/Scripting.php';
11 $def =& $config->getHTMLDefinition(true); // get the raw version
12 $def->manager->addModule('Scripting');
14 This must come before any other calls to getHTMLDefinition()
19 * Implements required attribute stipulation for <script>
21 class HTMLPurifier_AttrTransform_ScriptRequired
extends HTMLPurifier_AttrTransform
23 function transform($attr, $config, &$context) {
24 if (!isset($attr['type'])) {
25 $attr['type'] = 'text/javascript';
32 * XHTML 1.1 Scripting module, defines elements that are used to contain
33 * information pertaining to executable scripts or the lack of support
34 * for executable scripts.
35 * @note This module does not contain inline scripting elements
37 class HTMLPurifier_HTMLModule_Scripting
extends HTMLPurifier_HTMLModule
39 var $name = 'Scripting';
40 var $elements = array('script', 'noscript');
41 var $content_sets = array('Block' => 'script | noscript', 'Inline' => 'script | noscript');
43 function HTMLPurifier_HTMLModule_Scripting() {
44 // TODO: create custom child-definition for noscript that
45 // auto-wraps stray #PCDATA in a similar manner to
46 // blockquote's custom definition (we would use it but
47 // blockquote's contents are optional while noscript's contents
49 foreach ($this->elements
as $element) {
50 $this->info
[$element] = new HTMLPurifier_ElementDef();
52 $this->info
['noscript']->attr
= array( 0 => array('Common') );
53 $this->info
['noscript']->content_model
= 'Heading | List | Block';
54 $this->info
['noscript']->content_model_type
= 'required';
55 $this->info
['script']->attr
= array(
56 'defer' => new HTMLPurifier_AttrDef_Enum(array('defer')),
57 'src' => new HTMLPurifier_AttrDef_URI(true),
58 'type' => new HTMLPurifier_AttrDef_Enum(array('text/javascript'))
60 $this->info
['script']->content_model
= '#PCDATA';
61 $this->info
['script']->content_model_type
= 'optional';
62 $this->info
['script']->attr_transform_post
['type'] =
63 new HTMLPurifier_AttrTransform_ScriptRequired();