PicoFeed\Filter\Attribute::filterIframeAttribute PHP Méthode

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
    public function filterIframeAttribute($tag, $attribute, $value)
    {
        if ($tag === 'iframe' && $attribute === 'src') {
            foreach ($this->iframe_whitelist as $url) {
                if (strpos($value, $url) === 0) {
                    return true;
                }
            }
            return false;
        }
        return true;
    }

Usage Example

 public function testFilterIframeAttribute()
 {
     $filter = new Attribute(new Url('http://google.com'));
     $this->assertTrue($filter->filterIframeAttribute('iframe', 'src', 'http://www.youtube.com/test'));
     $this->assertTrue($filter->filterIframeAttribute('iframe', 'src', 'https://www.youtube.com/test'));
     $this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.youtube.com/test'));
     $this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.bidule.com/test'));
     $this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('src' => '//www.youtube.com/test')));
 }