Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Filter_DefaultStripTags Class Reference

Extended Zend_Filter_StripTags to preset default-allowed tags/attributes. More...

List of all members.

Public Member Functions

 __construct ($options=null)
 Overwrite parent constructor to set default allowed tags and attributes.
 removeAttributes ($attributes)
 Remove specified attribute(s) from allowed attributes list.
 removeTags ($tags)
 Remove specified tag(s) from allowed tags list.

Protected Member Functions

 _removeTagAttribute ($attribute, $tag=null)
 Removes attribute from (optionaly) given tag.

Protected Attributes

 $_defaultAttributesAllowed
 $_defaultTagsAllowed

Detailed Description

Extended Zend_Filter_StripTags to preset default-allowed tags/attributes.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Filter_DefaultStripTags::__construct ( options = null)

Overwrite parent constructor to set default allowed tags and attributes.

Parameters:
array | null$optionsFilter options (see parent for details).
    {
        // set default allowed tags/attributes
        $this->setTagsAllowed($this->_defaultTagsAllowed);
        $this->setAttributesAllowed($this->_defaultAttributesAllowed);

        parent::__construct($options);
    }

Member Function Documentation

P4Cms_Filter_DefaultStripTags::_removeTagAttribute ( attribute,
tag = null 
) [protected]

Removes attribute from (optionaly) given tag.

If tag is not specified, removes attribute from all currently allowed tags.

Parameters:
string$attributeAttribute to remove (from given tag).
string | null$tagTag to remove attribute from.
    {
        if ($tag) {
            unset($this->_tagsAllowed[$tag][$attribute]);
            return;
        }

        foreach ($this->_tagsAllowed as $tag => $value) {
            unset($this->_tagsAllowed[$tag][$attribute]);
        }
    }
P4Cms_Filter_DefaultStripTags::removeAttributes ( attributes)

Remove specified attribute(s) from allowed attributes list.

Function supports also an option to remove attributes only for certain tags, see examples below.

Examples of parameter values and their meaning:

'attr' removes 'attr' attribute array('attr1', 'attr2') removes 'attr1' and 'attr2' attributes array('tag' => 'attr') removes 'attr' attribute only for 'tag' tag array('tag' => array('attr1', 'attr2') removes 'attr1' and 'attr2' attributes only for 'tag' tag

Parameters:
string | array$attributesList with attributes to remove from allowed attributes.
    {
        if (!is_array($attributes)) {
            $attributes = array($attributes);
        }

        foreach ($attributes as $index => $element) {
            // if attributes were provided without tag, remove them from
            // allowed attributes and also from all allowed tag attributes
            if (is_int($index)) {
                // normalize attribute name
                $attrinuteName = strtolower($element);
                unset($this->_attributesAllowed[$attrinuteName]);
                $this->_removeTagAttribute($attrinuteName);
            } else {
                if (!is_array($element)) {
                    $element = array($element);
                }
                foreach ($element as $attribute) {
                    // normalize attribute/tag names
                    $attributeName = strtolower($attribute);
                    $tagName       = strtolower($index);                    
                    $this->_removeTagAttribute($attributeName, $tagName);
                }
            }
        }
    }
P4Cms_Filter_DefaultStripTags::removeTags ( tags)

Remove specified tag(s) from allowed tags list.

Parameters:
string | array$tagsList of tags to remove from allowed tags.
    {
        if (!is_array($tags)) {
            $tags = array($tags);
        }

        foreach ($tags as $tag) {
            // normalize tag name
            $tagName = strtolower($tag);
            unset($this->_tagsAllowed[$tagName]);
        }
    }

Member Data Documentation

P4Cms_Filter_DefaultStripTags::$_defaultAttributesAllowed [protected]
Initial value:
 array(
        'align',
        'bgcolor',
        'class',
        'height',
        'id',
        'style',
        'width'
    )
P4Cms_Filter_DefaultStripTags::$_defaultTagsAllowed [protected]

The documentation for this class was generated from the following file: