SafeObject.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * A "safe" object module. In theory, objects permitted by this module will
  4. * be safe, and untrusted users can be allowed to embed arbitrary flash objects
  5. * (maybe other types too, but only Flash is supported as of right now).
  6. * Highly experimental.
  7. */
  8. class HTMLPurifier_HTMLModule_SafeObject extends HTMLPurifier_HTMLModule
  9. {
  10. public $name = 'SafeObject';
  11. public function setup($config) {
  12. // These definitions are not intrinsically safe: the attribute transforms
  13. // are a vital part of ensuring safety.
  14. $max = $config->get('HTML.MaxImgLength');
  15. $object = $this->addElement(
  16. 'object',
  17. 'Inline',
  18. 'Optional: param | Flow | #PCDATA',
  19. 'Common',
  20. array(
  21. // While technically not required by the spec, we're forcing
  22. // it to this value.
  23. 'type' => 'Enum#application/x-shockwave-flash',
  24. 'width' => 'Pixels#' . $max,
  25. 'height' => 'Pixels#' . $max,
  26. 'data' => 'URI#embedded',
  27. 'codebase' => new HTMLPurifier_AttrDef_Enum(array(
  28. 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0')),
  29. )
  30. );
  31. $object->attr_transform_post[] = new HTMLPurifier_AttrTransform_SafeObject();
  32. $param = $this->addElement('param', false, 'Empty', false,
  33. array(
  34. 'id' => 'ID',
  35. 'name*' => 'Text',
  36. 'value' => 'Text'
  37. )
  38. );
  39. $param->attr_transform_post[] = new HTMLPurifier_AttrTransform_SafeParam();
  40. $this->info_injector[] = 'SafeObject';
  41. }
  42. }
  43. // vim: et sw=4 sts=4