]>
git.wh0rd.org - tt-rss.git/blob - plugins/auto_assign_labels/init.php
911adb6b88d98bfa50b4d33ef22a910f24a66993
2 class Auto_Assign_Labels
extends Plugin
{
8 "Assign labels automatically based on article title, content, and tags",
12 function init($host) {
15 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
18 function get_all_labels_filter_format($owner_uid) {
21 $result = db_query("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = " . $owner_uid);
23 while ($line = db_fetch_assoc($result)) {
24 array_push($rv, array(Labels
::label_to_feed_id($line["id"]),
25 $line["caption"], $line["fg_color"], $line["bg_color"]));
32 function hook_article_filter($article) {
34 $owner_uid = $article["owner_uid"];
35 $labels = $this->get_all_labels_filter_format($owner_uid);
36 $tags_str = join(",", $article["tags"]);
38 foreach ($labels as $label) {
39 $caption = preg_quote($label[1]);
41 if ($caption && preg_match("/\b$caption\b/i", "$tags_str " . strip_tags($article["content"]) . " " . $article["title"])) {
43 if (!RSSUtils
::labels_contains_caption($article["labels"], $caption)) {
44 array_push($article["labels"], $label);
52 function api_version() {