/**
  * Execute Item Processor
  *
  * @access public
  * @param  Feed $feed
  * @param  Item $item
  * @return bool
  */
 public function execute(Feed $feed, Item $item)
 {
     if ($this->config->getContentFiltering(true)) {
         $filter = Filter::html($item->getContent(), $feed->getSiteUrl());
         $filter->setConfig($this->config);
         $item->setContent($filter->execute());
     } else {
         Logger::setMessage(get_called_class() . ': Content filtering disabled');
     }
 }
示例#2
0
文件: FilterTest.php 项目: nrbrt/news
 public function testOverrideFilters()
 {
     $data = '<iframe src="http://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
     $expected = '<iframe src="https://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
     $f = Filter::html($data, 'http://blabla');
     $f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
     $this->assertEquals($expected, $f->execute());
     $data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
     $f = Filter::html($data, 'http://blabla');
     $f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
     $this->assertEmpty($f->execute());
     $config = new Config();
     $config->setFilterWhitelistedTags(array('p' => array('title')));
     $f = Filter::html('<p>Test<strong>boo</strong></p>', 'http://blabla');
     $f->setConfig($config);
     $this->assertEquals('<p>Testboo</p>', $f->execute());
 }
示例#3
0
function addProxyToTags($html, $website, $proxy_images, $cloak_referrer)
{
    if ($html === '' || !$cloak_referrer && !$proxy_images || !$cloak_referrer && $proxy_images && !Helper\isSecureConnection()) {
        // only proxy enabled, but not connected via HTTPS
        return $html;
    }
    $config = new PicoFeedConfig();
    $config->setFilterImageProxyUrl('?action=proxy&url=%s');
    if (!$cloak_referrer && $proxy_images) {
        // image proxy mode only: https links do not need to be proxied, since
        // they do not trigger mixed content warnings.
        $config->setFilterImageProxyProtocol('http');
    } elseif (!$proxy_images && $cloak_referrer && Helper\isSecureConnection()) {
        // cloaking mode only: if a request from a HTTPS connection to a HTTP
        // connection is made, the referrer will be omitted by the browser.
        // Only the referrer for HTTPS to HTTPs requests needs to be cloaked.
        $config->setFilterImageProxyProtocol('https');
    }
    $filter = Filter::html($html, $website);
    $filter->setConfig($config);
    return $filter->execute();
}
 public function testsetFilterImageProxyCallback()
 {
     $config = new Config();
     $config->setFilterImageProxyCallback(function ($image_url) {
         $key = hash_hmac('sha1', $image_url, 'secret');
         return 'https://mypublicproxy/' . $key . '/' . rawurlencode($image_url);
     });
     $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo');
     $f->setConfig($config);
     $this->assertEquals('<p>Image <img src="https://mypublicproxy/4924964043f3119b3cf2b07b1922d491bcc20092/' . rawurlencode('http://foo/image.png') . '" alt="My Image"/></p>', $f->execute());
 }
示例#5
0
 /**
  * Get filtered relevant content.
  *
  * @return string
  */
 public function getFilteredContent()
 {
     $filter = Filter::html($this->content, $this->url);
     $filter->setConfig($this->config);
     return $filter->execute();
 }