Set image proxy callback.
public setImageProxyCallback ( Closure $callback ) : |
||
$callback | Closure | |
return |
public function testRewriteProxyImageUrl() { $filter = new Attribute(new Url('http://www.la-grange.net')); $url = '/2014/08/03/4668-noisettes'; $this->assertTrue($filter->rewriteImageProxyUrl('a', 'href', $url)); $this->assertEquals('/2014/08/03/4668-noisettes', $url); $filter = new Attribute(new Url('http://www.la-grange.net')); $url = '/2014/08/03/4668-noisettes'; $this->assertTrue($filter->rewriteImageProxyUrl('img', 'alt', $url)); $this->assertEquals('/2014/08/03/4668-noisettes', $url); $filter = new Attribute(new Url('http://www.la-grange.net')); $url = '/2014/08/03/4668-noisettes'; $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); $this->assertEquals('/2014/08/03/4668-noisettes', $url); $filter = new Attribute(new Url('http://www.la-grange.net')); $filter->setImageProxyUrl('https://myproxy/?u=%s'); $url = 'http://example.net/image.png'; $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); $this->assertEquals('https://myproxy/?u=' . rawurlencode('http://example.net/image.png'), $url); $filter = new Attribute(new Url('http://www.la-grange.net')); $filter->setImageProxyCallback(function ($image_url) { $key = hash_hmac('sha1', $image_url, 'secret'); return 'https://mypublicproxy/' . $key . '/' . rawurlencode($image_url); }); $url = 'http://example.net/image.png'; $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); $this->assertEquals('https://mypublicproxy/d9701029b054f6e178ef88fcd3c789365e52a26d/' . rawurlencode('http://example.net/image.png'), $url); }
/** * Set config object. * * @param \PicoFeed\Config\Config $config Config instance * * @return \PicoFeed\Filter\Html */ public function setConfig($config) { $this->config = $config; if ($this->config !== null) { $this->attribute->setImageProxyCallback($this->config->getFilterImageProxyCallback()); $this->attribute->setImageProxyUrl($this->config->getFilterImageProxyUrl()); $this->attribute->setImageProxyProtocol($this->config->getFilterImageProxyProtocol()); $this->attribute->setIframeWhitelist($this->config->getFilterIframeWhitelist(array())); $this->attribute->setIntegerAttributes($this->config->getFilterIntegerAttributes(array())); $this->attribute->setAttributeOverrides($this->config->getFilterAttributeOverrides(array())); $this->attribute->setRequiredAttributes($this->config->getFilterRequiredAttributes(array())); $this->attribute->setMediaBlacklist($this->config->getFilterMediaBlacklist(array())); $this->attribute->setMediaAttributes($this->config->getFilterMediaAttributes(array())); $this->attribute->setSchemeWhitelist($this->config->getFilterSchemeWhitelist(array())); $this->attribute->setWhitelistedAttributes($this->config->getFilterWhitelistedTags(array())); $this->tag->setWhitelistedTags(array_keys($this->config->getFilterWhitelistedTags(array()))); } return $this; }