PHP Class PicoFeed\Filter\Attribute

Author: Frederic Guillot
Afficher le fichier Open project: fguillot/picofeed Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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

addAttributes() public méthode

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

filter() public méthode

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

filterAllowedAttribute() public méthode

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
Résultat boolean

filterBlacklistResourceAttribute() public méthode

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
Résultat boolean

filterIframeAttribute() public méthode

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
Résultat boolean

filterIntegerAttribute() public méthode

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
Résultat boolean

filterProtocolUrlAttribute() public méthode

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
Résultat boolean

hasRequiredAttributes() public méthode

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

isAllowedProtocol() public méthode

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

isBlacklistedMedia() public méthode

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

isResource() public méthode

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

removeYouTubeAutoplay() public méthode

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
Résultat boolean

rewriteAbsoluteUrl() public méthode

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
Résultat boolean

rewriteImageProxyUrl() public méthode

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
Résultat boolean

secureIframeSrc() public méthode

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
Résultat boolean

setAttributeOverrides() public méthode

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

setIframeWhitelist() public méthode

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

setImageProxyCallback() public méthode

Set image proxy callback.
public setImageProxyCallback ( Closure $callback ) : Attribute
$callback Closure
Résultat Attribute

setImageProxyProtocol() public méthode

Set image proxy protocol restriction.
public setImageProxyProtocol ( string $value ) : Attribute
$value string
Résultat Attribute

setImageProxyUrl() public méthode

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

setIntegerAttributes() public méthode

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

setMediaAttributes() public méthode

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

setMediaBlacklist() public méthode

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

setRequiredAttributes() public méthode

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

setSchemeWhitelist() public méthode

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

setWhitelistedAttributes() public méthode

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

toHtml() public méthode

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