From 711f1a1a0891d2c46b5fea938f98cf9c7f3eae3c Mon Sep 17 00:00:00 2001 From: Leon Haag-Fank Date: Fri, 10 Nov 2023 15:34:18 +0100 Subject: [PATCH] Initial commit --- configure.phtml | 41 +++++++++++++++++++++++++++++ extension.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ i18n/en/ext.php | 11 ++++++++ metadata.json | 8 ++++++ 4 files changed, 128 insertions(+) create mode 100644 configure.phtml create mode 100644 extension.php create mode 100644 i18n/en/ext.php create mode 100644 metadata.json diff --git a/configure.phtml b/configure.phtml new file mode 100644 index 0000000..4396869 --- /dev/null +++ b/configure.phtml @@ -0,0 +1,41 @@ +
+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ wallabag_use_tags ? 'checked' : ''); ?>> +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+
diff --git a/extension.php b/extension.php new file mode 100644 index 0000000..aff5bc4 --- /dev/null +++ b/extension.php @@ -0,0 +1,68 @@ +registerHook('entry_before_insert', [$this, 'wallabag']); + + $save = false; + if (is_null(FreshRSS_Context::$user_conf->wallabag_use_tags)) { + FreshRSS_Context::$user_conf->wallabag_use_tags = self::USE_TAGS_DEFAULT; + $save = true; + } + if (is_null(FreshRSS_Context::$user_conf->wallabag_add_tags)) { + FreshRSS_Context::$user_conf->wallabag_add_tags = self::ADD_TAGS_DEFAULT; + $save = true; + } + if ($save) { + FreshRSS_Context::$user_conf->save(); + } + } + + public function handleConfigureAction() { + if (Minz_Request::isPost()) { + FreshRSS_Context::$user_conf->wallabag_endpoint = Minz_Request::param('wallabag_endpoint'); + FreshRSS_Context::$user_conf->wallabag_token = Minz_Request::param('wallabag_token'); + FreshRSS_Context::$user_conf->wallabag_feeds = Minz_Request::param('wallabag_feeds', ''); + FreshRSS_Context::$user_conf->wallabag_use_tags = Minz_Request::param('wallabag_use_tags', ''); + FreshRSS_Context::$user_conf->wallabag_add_tags = Minz_Request::param('wallabag_add_tags', ''); + FreshRSS_Context::$user_conf->save(); + } + } + + public function wallabag(FreshRSS_Entry $entry): FreshRSS_Entry { + $endpoint = FreshRSS_Context::$user_conf->wallabag_endpoint; + $token = FreshRSS_Context::$user_conf->wallabag_token; + $feeds = explode(',', FreshRSS_Context::$user_conf->wallabag_feeds); + $use_tags = FreshRSS_Context::$user_conf->wallabag_use_tags; + $add_tags = explode(',', FreshRSS_Context::$user_conf->wallabag_add_tags); + if (is_null($endpoint) || is_null($token)) { + return $entry; + } + + if (in_array($entry->feedId(), $feeds)) { + $tags = $add_tags; + if ($use_tags) { + $tags = array_merge($tags, $entry->tags()); + } + $link = $entry->link(); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, join_path($endpoint, 'api/entries')); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + "Authorization:Bearer $token", + ]); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([ + 'url' => $link, + 'tags' => join(',', $tags), + ])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + curl_close($ch); + } + return $entry; + } +} diff --git a/i18n/en/ext.php b/i18n/en/ext.php new file mode 100644 index 0000000..ade1a7d --- /dev/null +++ b/i18n/en/ext.php @@ -0,0 +1,11 @@ + array( + 'endpoint' => 'Wallabag Endpoint', + 'token' => 'Wallabag API Token', + 'feeds' => 'Feed IDs (comma seperated)', + 'use_tags' => 'Use tags?', + 'add_tags' => 'Additional tags (comma seperated)', + ), +); diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..655f8f9 --- /dev/null +++ b/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Wallabag", + "author": "Leon Haag-Fank", + "description": "Automatically post entries to Wallabag.", + "version": "0.1.0", + "entrypoint": "Wallabag", + "type": "user" +}