From d64bf7953b0e4e793d7f75ec50bf6e42652560b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 22 Nov 2016 14:56:53 +0100 Subject: [PATCH] Added internal setting to enable/disable articles with paywall --- .../Version20161122144743.php | 45 +++++++++++++++++++ .../translations/CraueConfigBundle.en.yml | 1 + .../CoreBundle/Command/InstallCommand.php | 5 +++ .../DataFixtures/ORM/LoadSettingData.php | 5 +++ .../CoreBundle/Helper/HttpClientFactory.php | 12 ++++- .../CoreBundle/Resources/config/services.yml | 1 + 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 app/DoctrineMigrations/Version20161122144743.php diff --git a/app/DoctrineMigrations/Version20161122144743.php b/app/DoctrineMigrations/Version20161122144743.php new file mode 100644 index 00000000..ec80c48e --- /dev/null +++ b/app/DoctrineMigrations/Version20161122144743.php @@ -0,0 +1,45 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('restricted_access', 0, 'entry')"); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'restricted_access';"); + } +} diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml index 23de7a43..52cb8e20 100644 --- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml +++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml @@ -32,3 +32,4 @@ demo_mode_enabled: "Enable demo mode ? (only used for the wallabag public demo)" demo_mode_username: "Demo user" share_public: Allow public url for entries download_images_enabled: Download images locally +restricted_access: Enable authentication for websites with paywall diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index e95c3a7b..f0738b91 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -432,6 +432,11 @@ class InstallCommand extends ContainerAwareCommand 'value' => '0', 'section' => 'misc', ], + [ + 'name' => 'restricted_access', + 'value' => '0', + 'section' => 'entry', + ], ]; foreach ($settings as $setting) { diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php index 1f74891a..a723656e 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php @@ -155,6 +155,11 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface 'value' => '0', 'section' => 'misc', ], + [ + 'name' => 'restricted_access', + 'value' => '0', + 'section' => 'entry', + ], ]; foreach ($settings as $setting) { diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 161a5e9f..ca84c8da 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -18,23 +18,31 @@ class HttpClientFactory /** @var \GuzzleHttp\Cookie\CookieJar */ private $cookieJar; + private $restrictedAccess; + /** * HttpClientFactory constructor. * * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber * @param \GuzzleHttp\Cookie\CookieJar $cookieJar + * @param string $restrictedAccess */ - public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar) + public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar, $restrictedAccess) { $this->authenticatorSubscriber = $authenticatorSubscriber; $this->cookieJar = $cookieJar; + $this->restrictedAccess = $restrictedAccess; } /** - * @return \GuzzleHttp\Client + * @return \GuzzleHttp\Client|null */ public function buildHttpClient() { + if (0 === (int) $this->restrictedAccess) { + return null; + } + // we clear the cookie to avoid websites who use cookies for analytics $this->cookieJar->clear(); // need to set the (shared) cookie jar diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 1b7f39fc..bcf0c9ca 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -73,6 +73,7 @@ services: arguments: - "@bd_guzzle_site_authenticator.authenticator_subscriber" - "@wallabag_core.guzzle.cookie_jar" + - '@=service(''craue_config'').get(''restricted_access'')' wallabag_core.guzzle.cookie_jar: class: GuzzleHttp\Cookie\FileCookieJar -- 2.41.0