You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Scripting.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /**
  15. * @type string
  16. */
  17. public $name = 'Scripting';
  18. /**
  19. * @type array
  20. */
  21. public $elements = array('script', 'noscript');
  22. /**
  23. * @type array
  24. */
  25. public $content_sets = array('Block' => 'script | noscript', 'Inline' => 'script | noscript');
  26. /**
  27. * @type bool
  28. */
  29. public $safe = false;
  30. /**
  31. * @param HTMLPurifier_Config $config
  32. */
  33. public function setup($config)
  34. {
  35. // TODO: create custom child-definition for noscript that
  36. // auto-wraps stray #PCDATA in a similar manner to
  37. // blockquote's custom definition (we would use it but
  38. // blockquote's contents are optional while noscript's contents
  39. // are required)
  40. // TODO: convert this to new syntax, main problem is getting
  41. // both content sets working
  42. // In theory, this could be safe, but I don't see any reason to
  43. // allow it.
  44. $this->info['noscript'] = new HTMLPurifier_ElementDef();
  45. $this->info['noscript']->attr = array(0 => array('Common'));
  46. $this->info['noscript']->content_model = 'Heading | List | Block';
  47. $this->info['noscript']->content_model_type = 'required';
  48. $this->info['script'] = new HTMLPurifier_ElementDef();
  49. $this->info['script']->attr = array(
  50. 'defer' => new HTMLPurifier_AttrDef_Enum(array('defer')),
  51. 'src' => new HTMLPurifier_AttrDef_URI(true),
  52. 'type' => new HTMLPurifier_AttrDef_Enum(array('text/javascript'))
  53. );
  54. $this->info['script']->content_model = '#PCDATA';
  55. $this->info['script']->content_model_type = 'optional';
  56. $this->info['script']->attr_transform_pre[] =
  57. $this->info['script']->attr_transform_post[] =
  58. new HTMLPurifier_AttrTransform_ScriptRequired();
  59. }
  60. }
  61. // vim: et sw=4 sts=4