PHP Класс PicoFeed\Filter\Attribute

Автор: Frederic Guillot
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный метод

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

addAttributes() публичный метод

Automatically add/override some attributes for specific tags.
public addAttributes ( string $tag, array $attributes ) : array
$tag string Tag name
$attributes array Attributes list
Результат array

filter() публичный метод

Apply filters to the attributes list.
public filter ( string $tag, array $attributes ) : array
$tag string Tag name
$attributes array Attributes dictionary
Результат array Filtered attributes

filterAllowedAttribute() публичный метод

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
Результат boolean

filterBlacklistResourceAttribute() публичный метод

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
Результат boolean

filterIframeAttribute() публичный метод

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
Результат boolean

filterIntegerAttribute() публичный метод

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
Результат boolean

filterProtocolUrlAttribute() публичный метод

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
Результат boolean

hasRequiredAttributes() публичный метод

Return true if all required attributes are present.
public hasRequiredAttributes ( string $tag, array $attributes ) : boolean
$tag string Tag name
$attributes array Attributes list
Результат boolean

isAllowedProtocol() публичный метод

Detect if the protocol is allowed or not.
public isAllowedProtocol ( string $value ) : boolean
$value string Attribute value
Результат boolean

isBlacklistedMedia() публичный метод

Detect if an url is blacklisted.
public isBlacklistedMedia ( string $resource ) : boolean
$resource string Attribute value (URL)
Результат boolean

isResource() публичный метод

Check if an attribute name is an external resource.
public isResource ( string $attribute ) : boolean
$attribute string Attribute name
Результат boolean

removeYouTubeAutoplay() публичный метод

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
Результат boolean

rewriteAbsoluteUrl() публичный метод

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
Результат boolean

rewriteImageProxyUrl() публичный метод

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
Результат boolean

secureIframeSrc() публичный метод

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
Результат boolean

setAttributeOverrides() публичный метод

Set attributes to automatically to specific tags.
public setAttributeOverrides ( array $values ) : Attribute
$values array List of tags: ['a' => 'target="_blank"']
Результат Attribute

setIframeWhitelist() публичный метод

Set allowed iframe resources.
public setIframeWhitelist ( array $values ) : Attribute
$values array List of tags: ['http://www.youtube.com']
Результат Attribute

setImageProxyCallback() публичный метод

Set image proxy callback.
public setImageProxyCallback ( Closure $callback ) : Attribute
$callback Closure
Результат Attribute

setImageProxyProtocol() публичный метод

Set image proxy protocol restriction.
public setImageProxyProtocol ( string $value ) : Attribute
$value string
Результат Attribute

setImageProxyUrl() публичный метод

The original image url will be urlencoded
public setImageProxyUrl ( string $url ) : Attribute
$url string Proxy URL
Результат Attribute

setIntegerAttributes() публичный метод

Set attributes that must be an integer.
public setIntegerAttributes ( array $values ) : Attribute
$values array List of tags: ['width', 'height']
Результат Attribute

setMediaAttributes() публичный метод

Set media attributes (used to load external resources).
public setMediaAttributes ( array $values ) : Attribute
$values array List of values: ['src', 'href']
Результат Attribute

setMediaBlacklist() публичный метод

Set blacklisted external resources.
public setMediaBlacklist ( array $values ) : Attribute
$values array List of tags: ['http://google.com/', '...']
Результат Attribute

setRequiredAttributes() публичный метод

Set mandatory attributes for whitelisted tags.
public setRequiredAttributes ( array $values ) : Attribute
$values array List of tags: ['img' => 'src']
Результат Attribute

setSchemeWhitelist() публичный метод

Set scheme whitelist.
public setSchemeWhitelist ( array $values ) : Attribute
$values array List of scheme: ['http://', 'ftp://']
Результат Attribute

setWhitelistedAttributes() публичный метод

Set whitelisted tags and attributes for each tag.
public setWhitelistedAttributes ( array $values ) : Attribute
$values array List of tags: ['video' => ['src', 'cover'], 'img' => ['src']]
Результат Attribute

toHtml() публичный метод

Convert the attribute list to html.
public toHtml ( array $attributes ) : string
$attributes array Attributes
Результат string