]> git.wh0rd.org - tt-rss.git/commitdiff
add ability to auto-assign articles to labels (bump schema)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 30 Oct 2012 08:58:35 +0000 (12:58 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 30 Oct 2012 08:58:35 +0000 (12:58 +0400)
classes/feeds.php
include/functions.php
include/rssfuncs.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/98.sql [new file with mode: 0644]
schema/versions/pgsql/98.sql [new file with mode: 0644]

index 8dad16584862034bda6dd2836e0707ec6867d4e2..ed33b30c083b70889ef1f3395f87e37880f1a95c 100644 (file)
@@ -162,7 +162,7 @@ class Feeds extends Handler_Protected {
                                        $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));\r
                                        $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));\r
 \r
-                                       if (!$cache_images && time() - $last_updated > 120) {\r
+                                       if (!$cache_images && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) {\r
                                                include "rssfuncs.php";\r
                                                update_rss_feed($this->link, $feed, true, true);\r
                                        }\r
index 2e230c3c6ef320574ccb316e183cf7ad65fa9786..4d7f61a2bc10faf3e7d99b3a0e1c963cc52d5b31 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 97);
+       define('SCHEMA_VERSION', 98);
 
        $fetch_last_error = false;
 
                }
        }
 
+       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)
index 73323ea31bee8c52f8a1c839370d0d86ace3318a..1e2feb3cba46ed611cdcc548ee35a0bf9d7e3723 100644 (file)
                        }
 
                        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);
                                                }
                                        }
 
+                                       $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;
                                }
 
                                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...");
                                        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");
                                }
                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);
+                               }
+                       }
                }
        }
 ?>
index 8ac8611c97087dabf62db80d9c77b25aeee02d66..4b2a3369db23cf772b9ee7ca0860870a0c6111f9 100644 (file)
@@ -306,7 +306,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (97);
+insert into ttrss_version values (98);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
@@ -448,12 +448,15 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_DEFAULT_INCLUDE_CHILDREN', 1, 'false', '', 1);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3);
+
 update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED',
        'SORT_HEADLINES_BY_FEED_DATE',
        'VFEED_GROUP_BY_FEED',
        'FRESH_ARTICLE_MAX_AGE',
        'CDM_EXPANDED',
        'SHOW_CONTENT_PREVIEW',
+       'AUTO_ASSIGN_LABELS',
        'HIDE_READ_SHOWS_SPECIAL');
 
 create table ttrss_user_prefs (
index 377261dfae50f72bc03c5c1279e16a16cd9eab59..a8a769315c81aa4355491ea23e0319ac18e2bc7b 100644 (file)
@@ -254,7 +254,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (97);
+insert into ttrss_version values (98);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
@@ -388,12 +388,15 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_DEFAULT_INCLUDE_CHILDREN', 1, 'false', '', 1);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3);
+
 update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED',
        'SORT_HEADLINES_BY_FEED_DATE',
        'VFEED_GROUP_BY_FEED',
        'FRESH_ARTICLE_MAX_AGE',
        'CDM_EXPANDED',
        'SHOW_CONTENT_PREVIEW',
+       'AUTO_ASSIGN_LABELS',
        'HIDE_READ_SHOWS_SPECIAL');
 
 create table ttrss_user_prefs (
diff --git a/schema/versions/mysql/98.sql b/schema/versions/mysql/98.sql
new file mode 100644 (file)
index 0000000..1984a43
--- /dev/null
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,access_level) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3, 1);
+
+update ttrss_version set schema_version = 98;
+
+commit;
diff --git a/schema/versions/pgsql/98.sql b/schema/versions/pgsql/98.sql
new file mode 100644 (file)
index 0000000..1984a43
--- /dev/null
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,access_level) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3, 1);
+
+update ttrss_version set schema_version = 98;
+
+commit;