Scripting.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. WARNING: THIS MODULE IS EXTREMELY DANGEROUS AS IT ENABLES INLINE SCRIPTING
  4. INSIDE HTML PURIFIER DOCUMENTS. USE ONLY WITH TRUSTED USER INPUT!!!
  5. */
  6. /**
  7. * XHTML 1.1 Scripting module, defines elements that are used to contain
  8. * information pertaining to executable scripts or the lack of support
  9. * for executable scripts.
  10. * @note This module does not contain inline scripting elements
  11. */
  12. class HTMLPurifier_HTMLModule_Scripting extends HTMLPurifier_HTMLModule
  13. {
  14. public $name = 'Scripting';
  15. public $elements = array('script', 'noscript');
  16. public $content_sets = array('Block' => 'script | noscript', 'Inline' => 'script | noscript');
  17. public $safe = false;
  18. public function setup($config) {
  19. // TODO: create custom child-definition for noscript that
  20. // auto-wraps stray #PCDATA in a similar manner to
  21. // blockquote's custom definition (we would use it but
  22. // blockquote's contents are optional while noscript's contents
  23. // are required)
  24. // TODO: convert this to new syntax, main problem is getting
  25. // both content sets working
  26. // In theory, this could be safe, but I don't see any reason to
  27. // allow it.
  28. $this->info['noscript'] = new HTMLPurifier_ElementDef();
  29. $this->info['noscript']->attr = array( 0 => array('Common') );
  30. $this->info['noscript']->content_model = 'Heading | List | Block';
  31. $this->info['noscript']->content_model_type = 'required';
  32. $this->info['script'] = new HTMLPurifier_ElementDef();
  33. $this->info['script']->attr = array(
  34. 'defer' => new HTMLPurifier_AttrDef_Enum(array('defer')),
  35. 'src' => new HTMLPurifier_AttrDef_URI(true),
  36. 'type' => new HTMLPurifier_AttrDef_Enum(array('text/javascript'))
  37. );
  38. $this->info['script']->content_model = '#PCDATA';
  39. $this->info['script']->content_model_type = 'optional';
  40. $this->info['script']->attr_transform_pre['type'] =
  41. $this->info['script']->attr_transform_post['type'] =
  42. new HTMLPurifier_AttrTransform_ScriptRequired();
  43. }
  44. }
  45. // vim: et sw=4 sts=4