]> git.wh0rd.org Git - tt-rss.git/commitdiff
pref-feeds: add action to rescore feeds
authorAndrew Dolgov <fox@bah.spb.su>
Wed, 30 Apr 2008 10:12:41 +0000 (11:12 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Wed, 30 Apr 2008 10:12:41 +0000 (11:12 +0100)
functions.php
modules/pref-feeds.php
prefs.js

index d423168867cd66ebc88cd13fed818f28b2c7621f..cda69bb74f75bb94a3fc0bb0847bc84b8e6b8a4e 100644 (file)
                $text = preg_replace("/\]\]\>/", "", $text);
                return $text;
        }
+
+       function load_filters($link, $feed, $owner_uid, $action_id = false) {
+               $filters = array();
+
+               if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
+
+               $result = db_query($link, "SELECT reg_exp,
+                       ttrss_filter_types.name AS name,
+                       ttrss_filter_actions.name AS action,
+                       inverse,
+                       action_param
+                       FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE                                        
+                               enabled = true AND
+                               $ftype_query_part
+                               owner_uid = $owner_uid AND
+                               ttrss_filter_types.id = filter_type AND
+                               ttrss_filter_actions.id = action_id AND
+                               (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
+
+               while ($line = db_fetch_assoc($result)) {
+                       if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
+                               $filter["reg_exp"] = $line["reg_exp"];
+                               $filter["action"] = $line["action"];
+                               $filter["action_param"] = $line["action_param"];
+                               $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
+                       
+                               array_push($filters[$line["name"]], $filter);
+                       }
+
+               return $filters;
+       }
 ?>
index 6bd6b4aba46d3d967a4feece3022980dde46eff0..d54f2bdb926cbe2c17b9290d3ef5a7c62aa2c794 100644 (file)
                        clear_feed_articles($link, $id);
                }
 
+               if ($subop == "rescore") {
+                       $ids = split(",", db_escape_string($_GET["ids"]));
+
+                       foreach ($ids as $id) {
+
+                               $filters = load_filters($link, $id, $_SESSION["uid"], 6);
+
+                               $result = db_query($link, "SELECT title, content, link, ref_id FROM
+                                               ttrss_user_entries, ttrss_entries 
+                                               WHERE ref_id = id AND feed_id = '$id' AND 
+                                                       owner_uid = " .$_SESSION['uid']."
+                                               ORDER BY updated DESC LIMIT 100");
+
+                               $scores = array();
+
+                               while ($line = db_fetch_assoc($result)) {
+
+                                       $article_filters = get_article_filters($filters, $line['title'], 
+                                               $line['content'], $line['link']);
+                                       
+                                       $new_score = calculate_article_score($article_filters);
+
+                                       if (!$scores[$new_score]) $scores[$new_score] = array();
+
+                                       array_push($scores[$new_score], $line['ref_id']);
+                               }
+
+                               foreach (array_keys($scores) as $s) {
+                                       if ($s > 1000) {
+                                               db_query($link, "UPDATE ttrss_user_entries SET score = '$s', 
+                                                       marked = true WHERE
+                                                       ref_id IN (" . join(',', $scores[$s]) . ")");
+                                       } else {
+                                               db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
+                                                       ref_id IN (" . join(',', $scores[$s]) . ")");
+                                       }
+                               }
+                       }
+
+                       print __("All done.");
+
+               }
+
                if ($subop == "add") {
                
                        if (!WEB_DEMO_MODE) {
                                <option value=\"facEdit\">&nbsp;&nbsp;".__('Edit')."</option>
                                <option value=\"facPurge\">&nbsp;&nbsp;".__('Manual purge')."</option>
                                <option value=\"facClear\">&nbsp;&nbsp;".__('Clear feed data')."</option>
+                               <option value=\"facRescore\">&nbsp;&nbsp;".__('Rescore articles')."</option>
                                <option value=\"facUnsubscribe\">&nbsp;&nbsp;".__('Unsubscribe')."</option>";
 
                                if (get_pref($link, 'ENABLE_FEED_CATS')) {
index 43a554cf2ba02fb2b8045b0c4cd7f06156fb81ab..5b5914ffc637a7dbef8031989ce19c6c2235836b 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -1888,6 +1888,10 @@ function feedActionGo(op) {
                        editFeedCats();
                }
 
+               if (op == "facRescore") {
+                       rescoreSelectedFeeds();
+               }
+
                if (op == "facUnsubscribe") {
                        removeSelectedFeeds();
                }
@@ -1912,4 +1916,31 @@ function clearFeedArticles(feed_id) {
        return false;
 }
 
+function rescoreSelectedFeeds() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       var sel_rows = getSelectedFeeds();
+
+       if (sel_rows.length > 0) {
+
+               var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
+
+               if (ok) {
+                       notify_progress("Rescoring selected labels...");
+       
+                       xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
+                               param_escape(sel_rows.toString()), true);
+                       xmlhttp.onreadystatechange=notify_callback;
+                       xmlhttp.send(null);
+               }
+       } else {
+               alert(__("No feeds are selected."));
+       }
+
+       return false;
+}