From 635e3bb81338e2f7628c39919ca0288bb8733173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Wed, 24 Dec 2014 10:47:24 -0500 Subject: [PATCH] Add Pinboard bookmark sync --- composer.json | 1 + controllers/config.php | 27 +++++++ 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 | 27 ++++--- models/item.php | 5 ++ models/schema.php | 7 ++ models/service.php | 46 +++++++++++ templates/about.php | 1 + templates/api.php | 1 + templates/config.php | 1 + templates/database.php | 3 +- templates/help.php | 1 + templates/services.php | 28 +++++++ vendor/autoload.php | 2 +- vendor/composer/autoload_files.php | 1 + vendor/composer/autoload_real.php | 10 +-- vendor/composer/installed.json | 78 +++++++++---------- ...portal.com.php => rue89.nouvelobs.com.php} | 0 24 files changed, 219 insertions(+), 55 deletions(-) create mode 100644 models/service.php create mode 100644 templates/services.php rename vendor/fguillot/picofeed/lib/PicoFeed/Rules/{rue89.feedsportal.com.php => rue89.nouvelobs.com.php} (100%) diff --git a/composer.json b/composer.json index 974e95f..e636148 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "files": [ "lib/Translator.php", "models/config.php", + "models/service.php", "models/user.php", "models/feed.php", "models/item.php", diff --git a/controllers/config.php b/controllers/config.php index 53e0b8f..f31b50b 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -209,3 +209,30 @@ Router\get_action('api', function() { 'title' => t('API') ))); }); + +// Display bookmark services page +Router\get_action('services', function() { + + Response\html(Template\layout('services', array( + 'errors' => array(), + 'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()), + 'menu' => 'config', + 'title' => t('External services') + ))); +}); + +// Update bookmark services +Router\post_action('services', function() { + + $values = Request\values() + array('pinboard_enabled' => 0); + Model\Config\check_csrf_values($values); + + if (Model\Config\save($values)) { + Session\flash(t('Your preferences are updated.')); + } + else { + Session\flash_error(t('Unable to update your preferences.')); + } + + Response\redirect('?action=services'); +}); diff --git a/locales/cs_CZ/translations.php b/locales/cs_CZ/translations.php index 2fc058a..4ca711f 100644 --- a/locales/cs_CZ/translations.php +++ b/locales/cs_CZ/translations.php @@ -217,4 +217,9 @@ return array( // 'Must be an integer' => '', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/locales/de_DE/translations.php b/locales/de_DE/translations.php index 11b302a..52c2047 100644 --- a/locales/de_DE/translations.php +++ b/locales/de_DE/translations.php @@ -217,4 +217,9 @@ return array( 'Must be an integer' => 'Muss eine Ganzzahl sein', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/locales/es_ES/translations.php b/locales/es_ES/translations.php index 5cb1ecf..5bfe129 100644 --- a/locales/es_ES/translations.php +++ b/locales/es_ES/translations.php @@ -217,4 +217,9 @@ return array( // 'Must be an integer' => '', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index c6178e1..086eddf 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -217,4 +217,9 @@ return array( 'Must be an integer' => 'Must be an integer', 'Remove automatically unread items' => 'Supprimer automatiquement les éléments non lus', 'Toggle RTL mode' => 'Basculer entre le mode RTL', + 'external services' => 'services externes', + 'External services' => 'Services externes', + 'Send bookmarks to Pinboard' => 'Envoyer les favoris vers Pinboard', + 'Pinboard API token' => 'Jeton d\'accès à l\'API de Pinboard', + 'Pinboard tags' => 'Tags Pinboard', ); diff --git a/locales/it_IT/translations.php b/locales/it_IT/translations.php index e843604..2732e2b 100644 --- a/locales/it_IT/translations.php +++ b/locales/it_IT/translations.php @@ -217,4 +217,9 @@ return array( // 'Must be an integer' => '', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/locales/pt_BR/translations.php b/locales/pt_BR/translations.php index 2b10c93..a3f893d 100644 --- a/locales/pt_BR/translations.php +++ b/locales/pt_BR/translations.php @@ -217,4 +217,9 @@ return array( // 'Must be an integer' => '', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/locales/zh_CN/translations.php b/locales/zh_CN/translations.php index 6758552..a753d48 100644 --- a/locales/zh_CN/translations.php +++ b/locales/zh_CN/translations.php @@ -217,4 +217,9 @@ return array( // 'Must be an integer' => '', // 'Remove automatically unread items' => '', // 'Toggle RTL mode' => '', + // 'external services' => '', + // 'External services' => '', + // 'Send bookmarks to Pinboard' => '', + // 'Pinboard API token' => '', + // 'Pinboard tags' => '', ); diff --git a/models/config.php b/models/config.php index 496d91d..80470b8 100644 --- a/models/config.php +++ b/models/config.php @@ -9,7 +9,7 @@ use PicoDb\Database; use PicoFeed\Config\Config as ReaderConfig; use PicoFeed\Logging\Logger; -const DB_VERSION = 30; +const DB_VERSION = 31; const HTTP_USER_AGENT = 'Miniflux (http://miniflux.net)'; // Get PicoFeed config @@ -300,7 +300,10 @@ function get_all() 'items_sorting_direction', 'items_display_mode', 'redirect_nothing_to_read', - 'auto_update_url' + 'auto_update_url', + 'pinboard_enabled', + 'pinboard_token', + 'pinboard_tags' ) ->findOne(); } @@ -349,18 +352,24 @@ function save(array $values) unset($values['confirmation']); - // Reload configuration in session - $_SESSION['config'] = $values; - - // Reload translations for flash session message - \Translator\load($values['language']); - // If the user does not want content of feeds, remove it in previous ones if (isset($values['nocontent']) && (bool) $values['nocontent']) { Database::get('db')->table('items')->update(array('content' => '')); } - return Database::get('db')->table('config')->update($values); + if (Database::get('db')->table('config')->update($values)) { + reload(); + return true; + } + + return false; +} + +// Reload the cache in session +function reload() +{ + $_SESSION['config'] = get_all(); + \Translator\load(get('language')); } // Get the user agent of the connected user diff --git a/models/item.php b/models/item.php index aed1bff..1d72eec 100644 --- a/models/item.php +++ b/models/item.php @@ -2,6 +2,7 @@ namespace Model\Item; +use Model\Service; use Model\Config; use PicoDb\Database; use PicoFeed\Logging\Logger; @@ -300,6 +301,10 @@ function set_status($status, array $items) // Enable/disable bookmark flag function set_bookmark_value($id, $value) { + if ($value == 1) { + Service\push($id); + } + return Database::get('db') ->table('items') ->eq('id', $id) diff --git a/models/schema.php b/models/schema.php index 6666db6..07029d2 100644 --- a/models/schema.php +++ b/models/schema.php @@ -5,6 +5,13 @@ namespace Schema; use PDO; use Model\Config; +function version_31($pdo) +{ + $pdo->exec('ALTER TABLE config ADD COLUMN pinboard_enabled INTEGER DEFAULT 0'); + $pdo->exec('ALTER TABLE config ADD COLUMN pinboard_token TEXT'); + $pdo->exec('ALTER TABLE config ADD COLUMN pinboard_tags TEXT DEFAULT "miniflux"'); +} + function version_30($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN autoflush_unread INTEGER DEFAULT 45'); diff --git a/models/service.php b/models/service.php new file mode 100644 index 0000000..87f3a94 --- /dev/null +++ b/models/service.php @@ -0,0 +1,46 @@ + $item['url'], + 'description' => $item['title'], + 'tags' => Config\get('pinboard_tags'), + )); +} + +// Pinboard API client +function pinboard_api($method, array $params) +{ + try { + $params += array('auth_token' => Config\get('pinboard_token'), 'format' => 'json'); + $url = 'https://api.pinboard.in/v1'.$method.'?'.http_build_query($params); + + $client = Client::getInstance(); + $client->setUserAgent(Config\HTTP_USER_AGENT); + $client->execute($url); + + $response = json_decode($client->getContent(), true); + + return is_array($response) && $response['result_code'] === 'done'; + } + catch (ClientException $e) { + return false; + } +} diff --git a/templates/about.php b/templates/about.php index 5fafe60..372b489 100644 --- a/templates/about.php +++ b/templates/about.php @@ -2,6 +2,7 @@