SafeParam.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. case 'allowscriptaccess':
  30. $attr['value'] = 'never';
  31. break;
  32. case 'allowNetworking':
  33. case 'allownetworking':
  34. $attr['value'] = 'internal';
  35. break;
  36. case 'allowFullScreen':
  37. case 'allowfullscreen':
  38. if ($config->get('HTML.FlashAllowFullScreen')) {
  39. $attr['value'] = ($attr['value'] == 'true') ? 'true' : 'false';
  40. } else {
  41. $attr['value'] = 'false';
  42. }
  43. break;
  44. case 'wmode':
  45. $attr['value'] = $this->wmode->validate($attr['value'], $config, $context);
  46. break;
  47. case 'movie':
  48. case 'src':
  49. $attr['name'] = "movie";
  50. $attr['value'] = $this->uri->validate($attr['value'], $config, $context);
  51. break;
  52. case 'flashvars':
  53. // we're going to allow arbitrary inputs to the SWF, on
  54. // the reasoning that it could only hack the SWF, not us.
  55. break;
  56. // add other cases to support other param name/value pairs
  57. default:
  58. $attr['name'] = $attr['value'] = null;
  59. }
  60. return $attr;
  61. }
  62. }
  63. // vim: et sw=4 sts=4