Initial commit
This commit is contained in:
commit
711f1a1a08
4 changed files with 128 additions and 0 deletions
68
extension.php
Normal file
68
extension.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
class WallabagExtension extends Minz_Extension {
|
||||
const USE_TAGS_DEFAULT = '1';
|
||||
const ADD_TAGS_DEFAULT = 'freshrss';
|
||||
|
||||
public function init(): void {
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue