PHP Class PicoFeed\Filter\Attribute

Author: Frederic Guillot
Exibir arquivo Open project: fguillot/picofeed Class Usage Examples

Public Methods

Method Description
__construct ( PicoFeed\Client\Url $website ) Constructor.
addAttributes ( string $tag, array $attributes ) : array Automatically add/override some attributes for specific tags.
filter ( string $tag, array $attributes ) : array Apply filters to the attributes list.
filterAllowedAttribute ( string $tag, string $attribute, string $value ) : boolean Return true if the value is allowed (remove not allowed attributes).
filterBlacklistResourceAttribute ( string $tag, string $attribute, string $value ) : boolean Return true if the resource is not blacklisted (remove blacklisted resource attributes).
filterIframeAttribute ( string $tag, string $attribute, string $value ) : boolean Return true if the iframe source is allowed (remove not allowed iframe).
filterIntegerAttribute ( string $tag, string $attribute, string $value ) : boolean Return true if the value is not integer (remove attributes that should have an integer value).
filterProtocolUrlAttribute ( string $tag, string $attribute, string $value ) : boolean Return true if the scheme is authorized.
hasRequiredAttributes ( string $tag, array $attributes ) : boolean Return true if all required attributes are present.
isAllowedProtocol ( string $value ) : boolean Detect if the protocol is allowed or not.
isBlacklistedMedia ( string $resource ) : boolean Detect if an url is blacklisted.
isResource ( string $attribute ) : boolean Check if an attribute name is an external resource.
removeYouTubeAutoplay ( string $tag, array $attribute, string &$value ) : boolean Removes YouTube autoplay from iframes.
rewriteAbsoluteUrl ( string $tag, string $attribute, string &$value ) : boolean Convert all relative links to absolute url.
rewriteImageProxyUrl ( string $tag, string $attribute, string &$value ) : boolean Rewrite image url to use with a proxy.
secureIframeSrc ( string $tag, array $attribute, string &$value ) : boolean Turns iframes' src attribute from http to https to prevent mixed active content.
setAttributeOverrides ( array $values ) : Attribute Set attributes to automatically to specific tags.
setIframeWhitelist ( array $values ) : Attribute Set allowed iframe resources.
setImageProxyCallback ( Closure $callback ) : Attribute Set image proxy callback.
setImageProxyProtocol ( string $value ) : Attribute Set image proxy protocol restriction.
setImageProxyUrl ( string $url ) : Attribute Set image proxy URL.
setIntegerAttributes ( array $values ) : Attribute Set attributes that must be an integer.
setMediaAttributes ( array $values ) : Attribute Set media attributes (used to load external resources).
setMediaBlacklist ( array $values ) : Attribute Set blacklisted external resources.
setRequiredAttributes ( array $values ) : Attribute Set mandatory attributes for whitelisted tags.
setSchemeWhitelist ( array $values ) : Attribute Set scheme whitelist.
setWhitelistedAttributes ( array $values ) : Attribute Set whitelisted tags and attributes for each tag.
toHtml ( array $attributes ) : string Convert the attribute list to html.

Method Details

__construct() public method

Constructor.
public __construct ( PicoFeed\Client\Url $website )
$website PicoFeed\Client\Url Website url instance

addAttributes() public method

Automatically add/override some attributes for specific tags.
public addAttributes ( string $tag, array $attributes ) : array
$tag string Tag name
$attributes array Attributes list
return array

filter() public method

Apply filters to the attributes list.
public filter ( string $tag, array $attributes ) : array
$tag string Tag name
$attributes array Attributes dictionary
return array Filtered attributes

filterAllowedAttribute() public method

Return true if the value is allowed (remove not allowed attributes).
public filterAllowedAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

filterBlacklistResourceAttribute() public method

Return true if the resource is not blacklisted (remove blacklisted resource attributes).
public filterBlacklistResourceAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

filterIframeAttribute() public method

Return true if the iframe source is allowed (remove not allowed iframe).
public filterIframeAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

filterIntegerAttribute() public method

Return true if the value is not integer (remove attributes that should have an integer value).
public filterIntegerAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

filterProtocolUrlAttribute() public method

Return true if the scheme is authorized.
public filterProtocolUrlAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

hasRequiredAttributes() public method

Return true if all required attributes are present.
public hasRequiredAttributes ( string $tag, array $attributes ) : boolean
$tag string Tag name
$attributes array Attributes list
return boolean

isAllowedProtocol() public method

Detect if the protocol is allowed or not.
public isAllowedProtocol ( string $value ) : boolean
$value string Attribute value
return boolean

isBlacklistedMedia() public method

Detect if an url is blacklisted.
public isBlacklistedMedia ( string $resource ) : boolean
$resource string Attribute value (URL)
return boolean

isResource() public method

Check if an attribute name is an external resource.
public isResource ( string $attribute ) : boolean
$attribute string Attribute name
return boolean

removeYouTubeAutoplay() public method

Removes YouTube autoplay from iframes.
public removeYouTubeAutoplay ( string $tag, array $attribute, string &$value ) : boolean
$tag string Tag name
$attribute array Atttributes name
$value string Attribute value
return boolean

rewriteAbsoluteUrl() public method

Convert all relative links to absolute url.
public rewriteAbsoluteUrl ( string $tag, string $attribute, string &$value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

rewriteImageProxyUrl() public method

Rewrite image url to use with a proxy.
public rewriteImageProxyUrl ( string $tag, string $attribute, string &$value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
return boolean

secureIframeSrc() public method

Turns iframes' src attribute from http to https to prevent mixed active content.
public secureIframeSrc ( string $tag, array $attribute, string &$value ) : boolean
$tag string Tag name
$attribute array Atttributes name
$value string Attribute value
return boolean

setAttributeOverrides() public method

Set attributes to automatically to specific tags.
public setAttributeOverrides ( array $values ) : Attribute
$values array List of tags: ['a' => 'target="_blank"']
return Attribute

setIframeWhitelist() public method

Set allowed iframe resources.
public setIframeWhitelist ( array $values ) : Attribute
$values array List of tags: ['http://www.youtube.com']
return Attribute

setImageProxyCallback() public method

Set image proxy callback.
public setImageProxyCallback ( Closure $callback ) : Attribute
$callback Closure
return Attribute

setImageProxyProtocol() public method

Set image proxy protocol restriction.
public setImageProxyProtocol ( string $value ) : Attribute
$value string
return Attribute

setImageProxyUrl() public method

The original image url will be urlencoded
public setImageProxyUrl ( string $url ) : Attribute
$url string Proxy URL
return Attribute

setIntegerAttributes() public method

Set attributes that must be an integer.
public setIntegerAttributes ( array $values ) : Attribute
$values array List of tags: ['width', 'height']
return Attribute

setMediaAttributes() public method

Set media attributes (used to load external resources).
public setMediaAttributes ( array $values ) : Attribute
$values array List of values: ['src', 'href']
return Attribute

setMediaBlacklist() public method

Set blacklisted external resources.
public setMediaBlacklist ( array $values ) : Attribute
$values array List of tags: ['http://google.com/', '...']
return Attribute

setRequiredAttributes() public method

Set mandatory attributes for whitelisted tags.
public setRequiredAttributes ( array $values ) : Attribute
$values array List of tags: ['img' => 'src']
return Attribute

setSchemeWhitelist() public method

Set scheme whitelist.
public setSchemeWhitelist ( array $values ) : Attribute
$values array List of scheme: ['http://', 'ftp://']
return Attribute

setWhitelistedAttributes() public method

Set whitelisted tags and attributes for each tag.
public setWhitelistedAttributes ( array $values ) : Attribute
$values array List of tags: ['video' => ['src', 'cover'], 'img' => ['src']]
return Attribute

toHtml() public method

Convert the attribute list to html.
public toHtml ( array $attributes ) : string
$attributes array Attributes
return string