SafeParam.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Validates name/value pairs in param tags to be used in safe objects. This
  4. * will only allow name values it recognizes, and pre-fill certain attributes
  5. * with required values.
  6. *
  7. * @note
  8. * This class only supports Flash. In the future, Quicktime support
  9. * may be added.
  10. *
  11. * @warning
  12. * This class expects an injector to add the necessary parameters tags.
  13. */
  14. class HTMLPurifier_AttrTransform_SafeParam extends HTMLPurifier_AttrTransform
  15. {
  16. public $name = "SafeParam";
  17. private $uri;
  18. public function __construct() {
  19. $this->uri = new HTMLPurifier_AttrDef_URI(true); // embedded
  20. $this->wmode = new HTMLPurifier_AttrDef_Enum(array('window', 'opaque', 'transparent'));
  21. }
  22. public function transform($attr, $config, $context) {
  23. // If we add support for other objects, we'll need to alter the
  24. // transforms.
  25. switch ($attr['name']) {
  26. // application/x-shockwave-flash
  27. // Keep this synchronized with Injector/SafeObject.php
  28. case 'allowScriptAccess':
  29. $attr['value'] = 'never';
  30. break;
  31. case 'allowNetworking':
  32. $attr['value'] = 'internal';
  33. break;
  34. case 'allowFullScreen':
  35. if ($config->get('HTML.FlashAllowFullScreen')) {
  36. $attr['value'] = ($attr['value'] == 'true') ? 'true' : 'false';
  37. } else {
  38. $attr['value'] = 'false';
  39. }
  40. break;
  41. case 'wmode':
  42. $attr['value'] = $this->wmode->validate($attr['value'], $config, $context);
  43. break;
  44. case 'movie':
  45. case 'src':
  46. $attr['name'] = "movie";
  47. $attr['value'] = $this->uri->validate($attr['value'], $config, $context);
  48. break;
  49. case 'flashvars':
  50. // we're going to allow arbitrary inputs to the SWF, on
  51. // the reasoning that it could only hack the SWF, not us.
  52. break;
  53. // add other cases to support other param name/value pairs
  54. default:
  55. $attr['name'] = $attr['value'] = null;
  56. }
  57. return $attr;
  58. }
  59. }
  60. // vim: et sw=4 sts=4