]>
git.wh0rd.org - tt-rss.git/blob - plugins/auto_assign_labels/init.php
2 class Auto_Assign_Labels
extends Plugin
{
4 /* @var PluginHost $host */
9 "Assign labels automatically based on article title, content, and tags",
13 function init($host) {
16 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
19 function get_all_labels_filter_format($owner_uid) {
22 $sth = $this->pdo
->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = ?");
23 $sth->execute([$owner_uid]);
25 while ($line = $sth->fetch()) {
26 array_push($rv, array(Labels
::label_to_feed_id($line["id"]),
27 $line["caption"], $line["fg_color"], $line["bg_color"]));
34 function hook_article_filter($article) {
36 $owner_uid = $article["owner_uid"];
37 $labels = $this->get_all_labels_filter_format($owner_uid);
38 $tags_str = join(",", $article["tags"]);
40 foreach ($labels as $label) {
41 $caption = preg_quote($label[1]);
43 if ($caption && preg_match("/\b$caption\b/i", "$tags_str " . strip_tags($article["content"]) . " " . $article["title"])) {
45 if (!RSSUtils
::labels_contains_caption($article["labels"], $caption)) {
46 array_push($article["labels"], $label);
54 function api_version() {