friendica/vendor/ezyang/htmlpurifier/library/HTMLPurifier/ChildDef/Chameleon.php

68 lines
1.9 KiB
PHP
Raw Normal View History

2010-09-09 05:14:17 +02:00
<?php
/**
* Definition that uses different definitions depending on context.
*
* The del and ins tags are notable because they allow different types of
* elements depending on whether or not they're in a block or inline context.
* Chameleon allows this behavior to happen by using two different
* definitions depending on context. While this somewhat generalized,
* it is specifically intended for those two tags.
*/
class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
{
/**
* Instance of the definition object to use when inline. Usually stricter.
2016-02-09 11:06:17 +01:00
* @type HTMLPurifier_ChildDef_Optional
2010-09-09 05:14:17 +02:00
*/
public $inline;
/**
* Instance of the definition object to use when block.
2016-02-09 11:06:17 +01:00
* @type HTMLPurifier_ChildDef_Optional
2010-09-09 05:14:17 +02:00
*/
public $block;
2016-02-09 11:06:17 +01:00
/**
* @type string
*/
2010-09-09 05:14:17 +02:00
public $type = 'chameleon';
/**
2016-02-09 11:06:17 +01:00
* @param array $inline List of elements to allow when inline.
* @param array $block List of elements to allow when block.
2010-09-09 05:14:17 +02:00
*/
2016-02-09 11:06:17 +01:00
public function __construct($inline, $block)
{
2010-09-09 05:14:17 +02:00
$this->inline = new HTMLPurifier_ChildDef_Optional($inline);
2016-02-09 11:06:17 +01:00
$this->block = new HTMLPurifier_ChildDef_Optional($block);
2010-09-09 05:14:17 +02:00
$this->elements = $this->block->elements;
}
2016-02-09 11:06:17 +01:00
/**
* @param HTMLPurifier_Node[] $children
* @param HTMLPurifier_Config $config
* @param HTMLPurifier_Context $context
* @return bool
*/
public function validateChildren($children, $config, $context)
{
2010-09-09 05:14:17 +02:00
if ($context->get('IsInline') === false) {
return $this->block->validateChildren(
2016-02-09 11:06:17 +01:00
$children,
$config,
$context
);
2010-09-09 05:14:17 +02:00
} else {
return $this->inline->validateChildren(
2016-02-09 11:06:17 +01:00
$children,
$config,
$context
);
2010-09-09 05:14:17 +02:00
}
}
}
// vim: et sw=4 sts=4