From 7d4d4e01938033d456d7f938289f1ddec5c3b861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Wed, 24 Dec 2014 15:58:24 -0500 Subject: [PATCH] Add image proxy to avoid https mixed content warnings --- README.markdown | 1 + common.php | 4 +-- composer.json | 1 + controllers/common.php | 12 +++++++++ controllers/config.php | 2 +- controllers/item.php | 3 ++- locales/cs_CZ/translations.php | 5 ++++ locales/de_DE/translations.php | 5 ++++ locales/es_ES/translations.php | 5 ++++ locales/fr_FR/translations.php | 5 ++++ locales/it_IT/translations.php | 5 ++++ locales/pt_BR/translations.php | 5 ++++ locales/zh_CN/translations.php | 5 ++++ models/config.php | 8 ++++-- models/item.php | 6 ----- models/proxy.php | 24 +++++++++++++++++ models/schema.php | 7 +++++ templates/config.php | 26 ++++++++++++------- templates/show_item.php | 6 ++++- vendor/autoload.php | 2 +- vendor/composer/autoload_files.php | 1 + vendor/composer/autoload_real.php | 10 +++---- vendor/composer/installed.json | 8 +++--- .../picofeed/lib/PicoFeed/Client/Grabber.php | 2 +- 24 files changed, 124 insertions(+), 34 deletions(-) create mode 100644 models/proxy.php diff --git a/README.markdown b/README.markdown index 22199e7..5572909 100644 --- a/README.markdown +++ b/README.markdown @@ -45,6 +45,7 @@ Features - Themes - Auto-update from the user interface - Multiple databases (each user has his own database) +- Image proxy to avoid mixed content warnings with HTTPS Requirements ------------ diff --git a/common.php b/common.php index bc4d525..dc055e9 100644 --- a/common.php +++ b/common.php @@ -38,10 +38,10 @@ PicoDb\Database::bootstrap('db', function() { $db = new PicoDb\Database(array( 'driver' => 'sqlite', - 'filename' => \Model\Database\get_path(), + 'filename' => Model\Database\get_path(), )); - if ($db->schema()->check(Model\Config\DB_VERSION)) { + if ($db->schema()->check(Schema\VERSION)) { return $db; } else { diff --git a/composer.json b/composer.json index e636148..21aa290 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "models/user.php", "models/feed.php", "models/item.php", + "models/proxy.php", "models/schema.php", "models/auto_update.php", "models/database.php", diff --git a/controllers/common.php b/controllers/common.php index 762ef3a..ae6016a 100644 --- a/controllers/common.php +++ b/controllers/common.php @@ -78,3 +78,15 @@ Router\get_action('select-db', function() { Response\redirect('?action=login'); }); + +// Image proxy (avoid SSL mixed content warnings) +Router\get_action('proxy', function() { + list($content, $type) = Model\Proxy\download(urldecode(Request\param('url'))); + + if (empty($content)) { + Response\text('Not Found', 404); + } + + Response\content_type($type); + echo $content; +}); diff --git a/controllers/config.php b/controllers/config.php index 465a5e1..6dfd2aa 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -134,7 +134,7 @@ Router\get_action('config', function() { // Update preferences Router\post_action('config', function() { - $values = Request\values() + array('nocontent' => 0); + $values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0); Model\Config\check_csrf_values($values); list($valid, $errors) = Model\Config\validate_modification($values); diff --git a/controllers/item.php b/controllers/item.php index d15c217..cd10ce1 100644 --- a/controllers/item.php +++ b/controllers/item.php @@ -71,7 +71,8 @@ Router\get_action('show', function() { 'feed' => $feed, 'item_nav' => isset($nav) ? $nav : null, 'menu' => $menu, - 'title' => $item['title'] + 'title' => $item['title'], + 'image_proxy_enabled' => (bool) Model\Config\get('image_proxy'), ))); }); diff --git a/locales/cs_CZ/translations.php b/locales/cs_CZ/translations.php index e281cae..9ee3ac4 100644 --- a/locales/cs_CZ/translations.php +++ b/locales/cs_CZ/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/locales/de_DE/translations.php b/locales/de_DE/translations.php index 0632b13..6fa5cf9 100644 --- a/locales/de_DE/translations.php +++ b/locales/de_DE/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/locales/es_ES/translations.php b/locales/es_ES/translations.php index cc3257a..1bd6705 100644 --- a/locales/es_ES/translations.php +++ b/locales/es_ES/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 32b26fd..b8ff433 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -227,4 +227,9 @@ return array( 'Instapaper' => 'Instapaper', 'Pinboard' => 'Pinboard', 'Send bookmarks to Instapaper' => 'Envoyer les favoris vers Instapaper', + 'Authentication' => 'Authentification', + 'Reading' => 'Lecture', + 'Application' => 'Application', + 'Enable image proxy' => 'Activer le proxy pour les images', + 'Avoid mixed content warnings with HTTPS' => 'Évite les alertes du navigateur web en HTTPS', ); diff --git a/locales/it_IT/translations.php b/locales/it_IT/translations.php index 503636c..f6585a4 100644 --- a/locales/it_IT/translations.php +++ b/locales/it_IT/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/locales/pt_BR/translations.php b/locales/pt_BR/translations.php index 3e6cb5e..20a2086 100644 --- a/locales/pt_BR/translations.php +++ b/locales/pt_BR/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/locales/zh_CN/translations.php b/locales/zh_CN/translations.php index a0a5eab..684a07b 100644 --- a/locales/zh_CN/translations.php +++ b/locales/zh_CN/translations.php @@ -227,4 +227,9 @@ return array( // 'Instapaper' => '', // 'Pinboard' => '', // 'Send bookmarks to Instapaper' => '', + // 'Authentication' => '', + // 'Reading' => '', + // 'Application' => '', + // 'Enable image proxy' => '', + // 'Avoid mixed content warnings with HTTPS' => '', ); diff --git a/models/config.php b/models/config.php index b1bf610..6719539 100644 --- a/models/config.php +++ b/models/config.php @@ -9,7 +9,6 @@ use PicoDb\Database; use PicoFeed\Config\Config as ReaderConfig; use PicoFeed\Logging\Logger; -const DB_VERSION = 32; const HTTP_USER_AGENT = 'Miniflux (http://miniflux.net)'; // Get PicoFeed config @@ -32,6 +31,10 @@ function get_reader_config() // Filter $config->setFilterIframeWhitelist(get_iframe_whitelist()); + if ((bool) get('image_proxy')) { + $config->setFilterImageProxyUrl('?action=proxy&url=%s'); + } + // Parser $config->setParserHashAlgo('crc32b'); @@ -306,7 +309,8 @@ function get_all() 'pinboard_tags', 'instapaper_enabled', 'instapaper_username', - 'instapaper_password' + 'instapaper_password', + 'image_proxy' ) ->findOne(); } diff --git a/models/item.php b/models/item.php index 1d72eec..7d77d9d 100644 --- a/models/item.php +++ b/models/item.php @@ -557,12 +557,6 @@ function download_content_url($url) $content = $grabber->getFilteredcontent(); } - if (! empty($content)) { - $filter = Filter::html($content, $url); - $filter->setConfig(Config\get_reader_config()); - $content = $filter->execute(); - } - return $content; } diff --git a/models/proxy.php b/models/proxy.php new file mode 100644 index 0000000..1badb22 --- /dev/null +++ b/models/proxy.php @@ -0,0 +1,24 @@ +setUserAgent(Config\HTTP_USER_AGENT); + $client->execute($url); + + return array( + $client->getContent(), + $client->getContentType(), + ); + } + catch (ClientException $e) { + return array(false, false); + } +} diff --git a/models/schema.php b/models/schema.php index 34bf24e..efbdd3a 100644 --- a/models/schema.php +++ b/models/schema.php @@ -5,6 +5,13 @@ namespace Schema; use PDO; use Model\Config; +const VERSION = 33; + +function version_33($pdo) +{ + $pdo->exec('ALTER TABLE config ADD COLUMN image_proxy INTEGER DEFAULT 0'); +} + function version_32($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN instapaper_enabled INTEGER DEFAULT 0'); diff --git a/templates/config.php b/templates/config.php index cfe3cc2..c298576 100644 --- a/templates/config.php +++ b/templates/config.php @@ -11,8 +11,9 @@
- +

+
@@ -22,12 +23,25 @@
+



+ +
+ + + +
+ + + +
+ +


@@ -46,15 +60,7 @@
- -
- -
- - - -
- +
diff --git a/templates/show_item.php b/templates/show_item.php index 295fa51..dc3a102 100644 --- a/templates/show_item.php +++ b/templates/show_item.php @@ -85,7 +85,11 @@ - enclosure + + enclosure + + enclosure +
diff --git a/vendor/autoload.php b/vendor/autoload.php index 313a8b4..28da304 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85::getLoader(); +return ComposerAutoloaderInit2e47cecea56754de3b457018a8eee985::getLoader(); diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index 8c3b701..e5d4b4d 100644 --- a/vendor/composer/autoload_files.php +++ b/vendor/composer/autoload_files.php @@ -12,6 +12,7 @@ return array( $baseDir . '/models/user.php', $baseDir . '/models/feed.php', $baseDir . '/models/item.php', + $baseDir . '/models/proxy.php', $baseDir . '/models/schema.php', $baseDir . '/models/auto_update.php', $baseDir . '/models/database.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 43e8b5f..757f362 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85 +class ComposerAutoloaderInit2e47cecea56754de3b457018a8eee985 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit2e47cecea56754de3b457018a8eee985', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit2e47cecea56754de3b457018a8eee985', 'loadClassLoader')); $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -42,14 +42,14 @@ class ComposerAutoloaderInite2d22b082480fbe8c7c1ceae6d7cbe85 $includeFiles = require __DIR__ . '/autoload_files.php'; foreach ($includeFiles as $file) { - composerRequiree2d22b082480fbe8c7c1ceae6d7cbe85($file); + composerRequire2e47cecea56754de3b457018a8eee985($file); } return $loader; } } -function composerRequiree2d22b082480fbe8c7c1ceae6d7cbe85($file) +function composerRequire2e47cecea56754de3b457018a8eee985($file) { require $file; } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index b957988..5e89b01 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -162,18 +162,18 @@ "source": { "type": "git", "url": "https://github.com/fguillot/picoFeed.git", - "reference": "eefd3f78268627e07ccf31c71cadd4c5ec0955bd" + "reference": "b3f2202845be5895ce818f1393cdd28b0aa1b8cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/eefd3f78268627e07ccf31c71cadd4c5ec0955bd", - "reference": "eefd3f78268627e07ccf31c71cadd4c5ec0955bd", + "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/b3f2202845be5895ce818f1393cdd28b0aa1b8cb", + "reference": "b3f2202845be5895ce818f1393cdd28b0aa1b8cb", "shasum": "" }, "require": { "php": ">=5.3.0" }, - "time": "2014-12-24 18:41:58", + "time": "2014-12-24 20:46:58", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php index 1bca056..de69590 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php @@ -185,7 +185,7 @@ class Grabber */ public function getFilteredContent() { - $filter = Filter::html($this->content, $this->url); + $filter = Filter::html($this->content, Url::base($this->url)); $filter->setConfig($this->config); return $filter->execute(); }