Exemple #1
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 testImageProxyLimitedToHTTPSwithHTTPSLink()
 {
     $config = new Config();
     $config->setFilterImageProxyUrl('http://myproxy/?url=%s');
     $config->setFilterImageProxyProtocol('https');
     $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo');
     $f->setConfig($config);
     $this->assertEquals('<p>Image <img src="http://myproxy/?url=' . rawurlencode('https://localhost/image.png') . '" alt="My Image"/></p>', $f->execute());
 }