4 * Adds important param elements to inside of object in order to make
7 class HTMLPurifier_Injector_SafeObject
extends HTMLPurifier_Injector
9 public $name = 'SafeObject';
10 public $needed = array('object', 'param');
12 protected $objectStack = array();
13 protected $paramStack = array();
15 // Keep this synchronized with AttrTransform/SafeParam.php
16 protected $addParam = array(
17 'allowScriptAccess' => 'never',
18 'allowNetworking' => 'internal',
20 protected $allowedParam = array(
26 public function prepare($config, $context) {
27 parent
::prepare($config, $context);
30 public function handleElement(&$token) {
31 if ($token->name
== 'object') {
32 $this->objectStack
[] = $token;
33 $this->paramStack
[] = array();
35 foreach ($this->addParam
as $name => $value) {
36 $new[] = new HTMLPurifier_Token_Empty('param', array('name' => $name, 'value' => $value));
39 } elseif ($token->name
== 'param') {
40 $nest = count($this->currentNesting
) - 1;
41 if ($nest >= 0 && $this->currentNesting
[$nest]->name
=== 'object') {
42 $i = count($this->objectStack
) - 1;
43 if (!isset($token->attr
['name'])) {
47 $n = $token->attr
['name'];
48 // We need this fix because YouTube doesn't supply a data
49 // attribute, which we need if a type is specified. This is
50 // *very* Flash specific.
51 if (!isset($this->objectStack
[$i]->attr
['data']) && $token->attr
['name'] == 'movie') {
52 $this->objectStack
[$i]->attr
['data'] = $token->attr
['value'];
54 // Check if the parameter is the correct value but has not
57 !isset($this->paramStack
[$i][$n]) &&
58 isset($this->addParam
[$n]) &&
59 $token->attr
['name'] === $this->addParam
[$n]
61 // keep token, and add to param stack
62 $this->paramStack
[$i][$n] = true;
63 } elseif (isset($this->allowedParam
[$n])) {
64 // keep token, don't do anything to it
65 // (could possibly check for duplicates here)
70 // not directly inside an object, DENY!
76 public function handleEnd(&$token) {
77 // This is the WRONG way of handling the object and param stacks;
78 // we should be inserting them directly on the relevant object tokens
79 // so that the global stack handling handles it.
80 if ($token->name
== 'object') {
81 array_pop($this->objectStack
);
82 array_pop($this->paramStack
);