summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2025-05-01 22:36:33 +0300
committerAndrew Dolgov <fox@fakecake.org>2025-05-01 22:36:33 +0300
commit5f70e4111889ddf4b97a257abd81f94cac7bac8a (patch)
treefc3efcbf8c1854bfafe2dca51fbd25398bdef15a /classes
parent4ae17d0f1c956bfe392653ab847eb2e3da6f7bfc (diff)
add plugin hooks invoked when articles get un/marked or un/published
Diffstat (limited to 'classes')
-rw-r--r--classes/API.php6
-rw-r--r--classes/Plugin.php19
-rw-r--r--classes/PluginHost.php6
-rw-r--r--classes/RPC.php8
-rw-r--r--classes/RSSUtils.php6
5 files changed, 45 insertions, 0 deletions
diff --git a/classes/API.php b/classes/API.php
index 72c65ea54..83eaa22b8 100644
--- a/classes/API.php
+++ b/classes/API.php
@@ -284,6 +284,12 @@ class API extends Handler {
WHERE ref_id IN ($article_qmarks) AND owner_uid = ?");
$sth->execute([...$article_ids, $_SESSION['uid']]);
+ if ($field == 'marked')
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_MARKED, $article_ids);
+
+ if ($field == 'published')
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_PUBLISHED, $article_ids);
+
$num_updated = $sth->rowCount();
return $this->_wrap(self::STATUS_OK, array("status" => "OK",
diff --git a/classes/Plugin.php b/classes/Plugin.php
index 62211f338..b66e2082c 100644
--- a/classes/Plugin.php
+++ b/classes/Plugin.php
@@ -713,4 +713,23 @@ abstract class Plugin {
return false;
}
+ /** Invoked after passed article IDs were either marked (i.e. starred) or unmarked.
+ * **Note** resulting state of the articles is not passed to this function (because
+ * tt-rss may do invert operation on ID range), you will need to get this from the database.
+ * @param array<int> $article_ids ref_ids
+ * @return void
+ */
+ function hook_articles_marked(array $article_ids) {
+ user_error("Dummy method invoked.", E_USER_ERROR);
+ }
+
+ /** Invoked after passed article IDs were either published or unpublished.
+ * **Note** resulting state of the articles is not passed to this function (because
+ * tt-rss may do invert operation on ID range), you will need to get this from the database.
+ * @param array<int> $article_ids ref_ids
+ * @return void
+ */
+ function hook_articles_published(array $article_ids) {
+ user_error("Dummy method invoked.", E_USER_ERROR);
+ }
}
diff --git a/classes/PluginHost.php b/classes/PluginHost.php
index ec47e6249..bfc02318b 100644
--- a/classes/PluginHost.php
+++ b/classes/PluginHost.php
@@ -199,6 +199,12 @@ class PluginHost {
/** @see Plugin::hook_validate_session() */
const HOOK_VALIDATE_SESSION = "hook_validate_session";
+ /** @see Plugin::hook_articles_marked() */
+ const HOOK_ARTICLES_MARKED = "hook_articles_marked";
+
+ /** @see Plugin::hook_articles_published() */
+ const HOOK_ARTICLES_PUBLISHED = "hook_articles_published";
+
const KIND_ALL = 1;
const KIND_SYSTEM = 2;
const KIND_USER = 3;
diff --git a/classes/RPC.php b/classes/RPC.php
index 031bef509..6b6f3e909 100644
--- a/classes/RPC.php
+++ b/classes/RPC.php
@@ -69,6 +69,8 @@ class RPC extends Handler_Protected {
$sth->execute([$mark, $id, $_SESSION['uid']]);
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_MARKED, [$id]);
+
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
@@ -95,6 +97,8 @@ class RPC extends Handler_Protected {
$sth->execute([$pub, $id, $_SESSION['uid']]);
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_PUBLISHED, [$id]);
+
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
@@ -345,6 +349,8 @@ class RPC extends Handler_Protected {
}
$sth->execute([...$ids, $_SESSION['uid']]);
+
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_MARKED, $ids);
}
/**
@@ -369,6 +375,8 @@ class RPC extends Handler_Protected {
}
$sth->execute([...$ids, $_SESSION['uid']]);
+
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_PUBLISHED, $ids);
}
function log(): void {
diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php
index 547cc094b..acf1d14e5 100644
--- a/classes/RSSUtils.php
+++ b/classes/RSSUtils.php
@@ -1132,6 +1132,12 @@ class RSSUtils {
$sth->execute([$ref_id, $feed_obj->owner_uid, $feed, $unread, $last_read_qpart, $marked,
$published, $score]);
+ if ($marked)
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_MARKED, [$ref_id]);
+
+ if ($published)
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_ARTICLES_PUBLISHED, [$ref_id]);
+
$sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
ref_id = ? AND owner_uid = ? AND
feed_id = ? LIMIT 1");