diff --git a/controllers/common.php b/controllers/common.php
index 58c1fd9..66b7a88 100644
--- a/controllers/common.php
+++ b/controllers/common.php
@@ -74,12 +74,6 @@ Router\get_action('more', function() {
// Image proxy (avoid SSL mixed content warnings)
Router\get_action('proxy', function() {
- list($content, $type) = Model\Proxy\download(rawurldecode(Request\param('url')));
-
- if (empty($content)) {
- Response\text('Not Found', 404);
- }
-
- Response\content_type($type);
- Response\raw($content);
+ Model\Proxy\download(rawurldecode(Request\param('url')));
+ exit;
});
diff --git a/controllers/feed.php b/controllers/feed.php
index 3521013..6b5745c 100644
--- a/controllers/feed.php
+++ b/controllers/feed.php
@@ -158,9 +158,9 @@ Router\action('subscribe', function() {
}
}
- $values += array('download_content' => 0, 'rtl' => 0);
+ $values += array('download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0);
$url = trim($url);
- $feed_id = Model\Feed\create($url, $values['download_content'], $values['rtl']);
+ $feed_id = Model\Feed\create($url, $values['download_content'], $values['rtl'], $values['cloak_referrer']);
if ($feed_id) {
Session\flash(t('Subscription added successfully.'));
diff --git a/controllers/item.php b/controllers/item.php
index d77e07b..942cbdb 100644
--- a/controllers/item.php
+++ b/controllers/item.php
@@ -66,6 +66,15 @@ Router\get_action('show', function() {
break;
}
+ $image_proxy = Model\Config\get('image_proxy');
+
+ // add the image proxy if requested and required
+ $item['content'] = Model\Proxy\addProxyToTags($item['content'], $item['url'], $image_proxy, $feed['cloak_referrer']);
+
+ if ($image_proxy && strpos($item['enclosure_type'], 'image') === 0) {
+ $item['enclosure'] = Model\Proxy\addProxyToLink($item['enclosure']);
+ }
+
Response\html(Template\layout('show_item', array(
'nb_unread_items' => $nb_unread_items = Model\Item\count_by_status('unread'),
'item' => $item,
@@ -73,7 +82,6 @@ Router\get_action('show', function() {
'item_nav' => isset($nav) ? $nav : null,
'menu' => $menu,
'title' => $item['title'],
- 'image_proxy_enabled' => (bool) Model\Config\get('image_proxy'),
)));
});
@@ -107,8 +115,15 @@ Router\get_action('feed-items', function() {
// Ajax call to download an item (fetch the full content from the original website)
Router\post_action('download-item', function() {
+ $id = Request\param('id');
- Response\json(Model\Item\download_content_id(Request\param('id')));
+ $item = Model\Item\get($id);
+ $feed = Model\Feed\get($item['feed_id']);
+
+ $download = Model\Item\download_content_id($id);
+ $download['content'] = Model\Proxy\addProxyToTags($download['content'], $item['url'], Model\Config\get('image_proxy'), $feed['cloak_referrer']);
+
+ Response\json($download);
});
// Ajax call change item status
diff --git a/locales/cs_CZ/translations.php b/locales/cs_CZ/translations.php
index eb7e743..7ef0db0 100644
--- a/locales/cs_CZ/translations.php
+++ b/locales/cs_CZ/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/locales/de_DE/translations.php b/locales/de_DE/translations.php
index 870b7fd..f1c5571 100644
--- a/locales/de_DE/translations.php
+++ b/locales/de_DE/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/locales/es_ES/translations.php b/locales/es_ES/translations.php
index 5551e71..1ffa690 100644
--- a/locales/es_ES/translations.php
+++ b/locales/es_ES/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php
index cf85347..8347e4a 100644
--- a/locales/fr_FR/translations.php
+++ b/locales/fr_FR/translations.php
@@ -235,4 +235,5 @@ return array(
'Nothing to show. Enable the debug mode to see log messages.' => 'Rien à montrer. Activez le mode debug pour voir les messages de log.',
'Enable debug mode' => 'Activer le mode debug',
'Original link marks article as read' => 'Marquer les articles comme lu lors d\'un clic sur le lien original',
+ 'Cloak the image referrer' => 'Cloak the image referrer',
);
diff --git a/locales/it_IT/translations.php b/locales/it_IT/translations.php
index 690c59a..396c874 100644
--- a/locales/it_IT/translations.php
+++ b/locales/it_IT/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/locales/pt_BR/translations.php b/locales/pt_BR/translations.php
index 229ec57..04e310b 100644
--- a/locales/pt_BR/translations.php
+++ b/locales/pt_BR/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/locales/zh_CN/translations.php b/locales/zh_CN/translations.php
index c6c004d..3aed60c 100644
--- a/locales/zh_CN/translations.php
+++ b/locales/zh_CN/translations.php
@@ -235,4 +235,5 @@ return array(
// 'Nothing to show. Enable the debug mode to see log messages.' => '',
// 'Enable debug mode' => '',
// 'Original link marks article as read' => '',
+ // 'Cloak the image referrer' => '',
);
diff --git a/models/config.php b/models/config.php
index 002c4d6..77f3a9d 100644
--- a/models/config.php
+++ b/models/config.php
@@ -32,10 +32,6 @@ function get_reader_config()
// Filter
$config->setFilterIframeWhitelist(get_iframe_whitelist());
- if ((bool) get('image_proxy')) {
- $config->setFilterImageProxyUrl('?action=proxy&url=%s');
- }
-
if ((bool) get('debug_mode')) {
Logger::enable();
}
diff --git a/models/feed.php b/models/feed.php
index 9142b7c..4606d9a 100644
--- a/models/feed.php
+++ b/models/feed.php
@@ -102,6 +102,7 @@ function update(array $values)
'enabled' => empty($values['enabled']) ? 0 : $values['enabled'],
'rtl' => empty($values['rtl']) ? 0 : $values['rtl'],
'download_content' => empty($values['download_content']) ? 0 : $values['download_content'],
+ 'cloak_referrer' => empty($values['cloak_referrer']) ? 0 : $values['cloak_referrer'],
));
}
@@ -148,7 +149,7 @@ function import_opml($content)
}
// Add a new feed from an URL
-function create($url, $enable_grabber = false, $force_rtl = false)
+function create($url, $enable_grabber = false, $force_rtl = false, $cloak_referrer = false)
{
try {
$db = Database::get('db');
@@ -185,6 +186,7 @@ function create($url, $enable_grabber = false, $force_rtl = false)
'last_modified' => $resource->getLastModified(),
'last_checked' => time(),
'etag' => $resource->getEtag(),
+ 'cloak_referrer' => $cloak_referrer ? 1 : 0,
));
if ($result) {
diff --git a/models/proxy.php b/models/proxy.php
index 8222101..d5459d6 100644
--- a/models/proxy.php
+++ b/models/proxy.php
@@ -3,26 +3,61 @@
namespace Model\Proxy;
use Model\Config;
+use PicoFeed\Config\Config as PicoFeedConfig;
+use PicoFeed\Filter\Filter;
use PicoFeed\Client\Client;
-use PicoFeed\Client\ClientException;
+
+function isSecureConnection()
+{
+ return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
+}
+
+function addProxyToLink($link) {
+
+ if (isSecureConnection() && strpos($link, 'http:') === 0) {
+ $link = '?action=proxy&url='.urlencode($link);
+ }
+
+ return $link;
+}
+
+function addProxyToTags($html, $website, $proxy_images, $cloak_referrer)
+{
+ if ($html === '' // no content, no proxy
+ || (! $cloak_referrer && ! $proxy_images) // neither cloaking nor proxing enabled
+ || (! $cloak_referrer && $proxy_images && ! 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 && 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();
+}
function download($url)
{
- try {
- $client = Client::getInstance();
- $client->setUserAgent(Config\HTTP_USER_AGENT);
- $client->execute($url);
-
- $content = array(
- $client->getContent(),
- $client->getContentType(),
- );
- }
- catch (ClientException $e) {
- $content = array(false, false);
- }
+ $client = Client::getInstance();
+ $client->setUserAgent(Config\HTTP_USER_AGENT);
+ $client->enablePassthroughMode();
+ $client->execute($url);
+ // does not work
Config\write_debug();
-
- return $content;
}
diff --git a/models/schema.php b/models/schema.php
index fd0e731..bd0957b 100644
--- a/models/schema.php
+++ b/models/schema.php
@@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Model\Config;
-const VERSION = 38;
+const VERSION = 39;
+
+function version_39($pdo)
+{
+ $pdo->exec('ALTER TABLE feeds ADD COLUMN cloak_referrer INTEGER DEFAULT 0');
+}
function version_38($pdo)
{
diff --git a/templates/add.php b/templates/add.php
index efeebb1..f76f4e4 100644
--- a/templates/add.php
+++ b/templates/add.php
@@ -19,6 +19,7 @@
= Helper\form_checkbox('rtl', t('Force RTL mode (Right-to-left language)'), 1, isset($values['rtl']) ? $values['rtl'] : false) ?>
= Helper\form_checkbox('download_content', t('Download full content'), 1, isset($values['download_content']) ? $values['download_content'] : false) ?>
+ = Helper\form_checkbox('cloak_referrer', t('Cloak the image referrer'), 1, isset($values['cloak_referrer']) ? $values['cloak_referrer'] : false) ?>
= t('Downloading full content is slower because Miniflux grab the content from the original website. You should use that for subscriptions that display only a summary. This feature doesn\'t work with all websites.') ?>