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(
27 public function prepare($config, $context) {
28 parent::prepare($config, $context);
31 public function handleElement(&$token) {
32 if ($token->name == 'object') {
33 $this->objectStack[] = $token;
34 $this->paramStack[] = array();
36 foreach ($this->addParam as $name => $value) {
37 $new[] = new HTMLPurifier_Token_Empty('param', array('name' => $name, 'value' => $value));
40 } elseif ($token->name == 'param') {
41 $nest = count($this->currentNesting) - 1;
42 if ($nest >= 0 && $this->currentNesting[$nest]->name === 'object') {
43 $i = count($this->objectStack) - 1;
44 if (!isset($token->attr['name'])) {
48 $n = $token->attr['name'];
49 // We need this fix because YouTube doesn't supply a data
50 // attribute, which we need if a type is specified. This is
51 // *very* Flash specific.
52 if (!isset($this->objectStack[$i]->attr['data']) &&
53 ($token->attr['name'] == 'movie' || $token->attr['name'] == 'src')) {
54 $this->objectStack[$i]->attr['data'] = $token->attr['value'];
56 // Check if the parameter is the correct value but has not
59 !isset($this->paramStack[$i][$n]) &&
60 isset($this->addParam[$n]) &&
61 $token->attr['name'] === $this->addParam[$n]
63 // keep token, and add to param stack
64 $this->paramStack[$i][$n] = true;
65 } elseif (isset($this->allowedParam[$n])) {
66 // keep token, don't do anything to it
67 // (could possibly check for duplicates here)
72 // not directly inside an object, DENY!
78 public function handleEnd(&$token) {
79 // This is the WRONG way of handling the object and param stacks;
80 // we should be inserting them directly on the relevant object tokens
81 // so that the global stack handling handles it.
82 if ($token->name == 'object') {
83 array_pop($this->objectStack);
84 array_pop($this->paramStack);