summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-10-30 12:58:35 +0400
committerAndrew Dolgov <[email protected]>2012-10-30 12:58:35 +0400
commitb24504b121315813939fa5af1963bee93b6d9d4d (patch)
treea9a91c9dfffcdd5e498e6049c5586a89abc0bd7b /include
parent92c14e9d5374dec7940e007dcd9075ac9b42c2ab (diff)
add ability to auto-assign articles to labels (bump schema)
Diffstat (limited to 'include')
-rw-r--r--include/functions.php14
-rw-r--r--include/rssfuncs.php41
2 files changed, 49 insertions, 6 deletions
diff --git a/include/functions.php b/include/functions.php
index 2e230c3c6..4d7f61a2b 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 97);
+ define('SCHEMA_VERSION', 98);
$fetch_last_error = false;
@@ -3923,6 +3923,18 @@
}
}
+ function get_all_labels($link, $owner_uid) {
+ $rv = array();
+
+ $result = db_query($link, "SELECT fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = " . $owner_uid);
+
+ while ($line = db_fetch_assoc($result)) {
+ array_push($rv, $line);
+ }
+
+ return $rv;
+ }
+
function label_update_cache($link, $id, $labels = false, $force = false) {
if ($force)
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index 73323ea31..1e2feb3cb 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -405,10 +405,11 @@
}
if ($debug_enabled) {
- _debug("update_rss_feed: loading filters...");
+ _debug("update_rss_feed: loading filters & labels...");
}
$filters = load_filters($link, $feed, $owner_uid);
+ $labels = get_all_labels($link, $owner_uid);
if ($debug_enabled) {
//print_r($filters);
@@ -874,6 +875,8 @@
}
}
+ $article_labels = get_article_labels($link, $entry_ref_id);
+
if (find_article_filter($article_filters, "filter")) {
db_query($link, "COMMIT"); // close transaction in progress
continue;
@@ -1034,7 +1037,7 @@
}
assign_article_to_label_filters($link, $entry_ref_id, $article_filters,
- $owner_uid);
+ $owner_uid, $article_labels);
if ($debug_enabled) {
_debug("update_rss_feed: looking for enclosures...");
@@ -1207,6 +1210,22 @@
db_query($link, "COMMIT");
}
+ if (get_pref($link, "AUTO_ASSIGN_LABELS", $owner_uid, false)) {
+ if ($debug_enabled) {
+ _debug("update_rss_feed: auto-assigning labels...");
+ }
+
+ foreach ($labels as $label) {
+ $caption = $label["caption"];
+
+ if (preg_match("/\b$caption\b/i", "$tags_str $entry_content $entry_title")) {
+ if (!labels_contains_caption($article_labels, $caption)) {
+ label_add_article($link, $entry_ref_id, $caption, $owner_uid);
+ }
+ }
+ }
+ }
+
if ($debug_enabled) {
_debug("update_rss_feed: article processed");
}
@@ -1437,11 +1456,23 @@
return $score;
}
- function assign_article_to_label_filters($link, $id, $filters, $owner_uid) {
+ function labels_contains_caption($labels, $caption) {
+ foreach ($labels as $label) {
+ if ($label[1] == $caption) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ function assign_article_to_label_filters($link, $id, $filters, $owner_uid, $article_labels) {
foreach ($filters as $f) {
if ($f["type"] == "label") {
- label_add_article($link, $id, $f["param"], $owner_uid);
- };
+ if (!labels_contains_caption($article_labels, $f["param"])) {
+ label_add_article($link, $id, $f["param"], $owner_uid);
+ }
+ }
}
}
?>