File indexing completed on 2024-12-22 05:36:21

0001 <?php
0002 
0003 /**
0004  * Processes an entire attribute array for corrections needing multiple values.
0005  *
0006  * Occasionally, a certain attribute will need to be removed and popped onto
0007  * another value.  Instead of creating a complex return syntax for
0008  * HTMLPurifier_AttrDef, we just pass the whole attribute array to a
0009  * specialized object and have that do the special work.  That is the
0010  * family of HTMLPurifier_AttrTransform.
0011  *
0012  * An attribute transformation can be assigned to run before or after
0013  * HTMLPurifier_AttrDef validation.  See HTMLPurifier_HTMLDefinition for
0014  * more details.
0015  */
0016 
0017 abstract class HTMLPurifier_AttrTransform
0018 {
0019 
0020     /**
0021      * Abstract: makes changes to the attributes dependent on multiple values.
0022      *
0023      * @param array $attr Assoc array of attributes, usually from
0024      *              HTMLPurifier_Token_Tag::$attr
0025      * @param HTMLPurifier_Config $config Mandatory HTMLPurifier_Config object.
0026      * @param HTMLPurifier_Context $context Mandatory HTMLPurifier_Context object
0027      * @return array Processed attribute array.
0028      */
0029     abstract public function transform($attr, $config, $context);
0030 
0031     /**
0032      * Prepends CSS properties to the style attribute, creating the
0033      * attribute if it doesn't exist.
0034      * @param array &$attr Attribute array to process (passed by reference)
0035      * @param string $css CSS to prepend
0036      */
0037     public function prependCSS(&$attr, $css)
0038     {
0039         $attr['style'] = isset($attr['style']) ? $attr['style'] : '';
0040         $attr['style'] = $css . $attr['style'];
0041     }
0042 
0043     /**
0044      * Retrieves and removes an attribute
0045      * @param array &$attr Attribute array to process (passed by reference)
0046      * @param mixed $key Key of attribute to confiscate
0047      * @return mixed
0048      */
0049     public function confiscateAttr(&$attr, $key)
0050     {
0051         if (!isset($attr[$key])) {
0052             return null;
0053         }
0054         $value = $attr[$key];
0055         unset($attr[$key]);
0056         return $value;
0057     }
0058 }
0059 
0060 // vim: et sw=4 sts=4