]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/filters.php
add plugin-based filter actions (see example plugin in attic)
[tt-rss.git] / classes / pref / filters.php
index 170c1a5277bedd7fb378c23e27102e3cf019970a..a2a2d0928861be2122983494d0a8b53b3ec383c2 100644 (file)
@@ -54,6 +54,7 @@ class Pref_Filters extends Handler_Protected {
                        checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"])));
 
                $filter["rules"] = array();
+               $filter["actions"] = array("dummy-action");
 
                $result = $this->dbh->query("SELECT id,name FROM ttrss_filter_types");
 
@@ -62,6 +63,8 @@ class Pref_Filters extends Handler_Protected {
                        $filter_types[$line["id"]] = $line["name"];
                }
 
+               $scope_qparts = array();
+
                $rctr = 0;
                foreach ($_REQUEST["rule"] AS $r) {
                        $rule = json_decode($r, true);
@@ -75,6 +78,14 @@ class Pref_Filters extends Handler_Protected {
                                        unset($rule["feed_id"]);
                                }
 
+                               if (isset($rule["feed_id"]) && $rule['feed_id'] > 0) {
+                                       array_push($scope_qparts, "feed_id = " . $rule["feed_id"]);
+                               } else if (isset($rule["cat_id"])) {
+                                       array_push($scope_qparts, "cat_id = " . $rule["cat_id"]);
+                               } else {
+                                       array_push($scope_qparts, "true");
+                               }
+
                                array_push($filter["rules"], $rule);
 
                                ++$rctr;
@@ -83,59 +94,95 @@ class Pref_Filters extends Handler_Protected {
                        }
                }
 
-               $qfh_ret = queryFeedHeadlines(-4, 30, "", false, false, false,
-                       "date_entered DESC", 0, $_SESSION["uid"], $filter);
-
-               $result = $qfh_ret[0];
-
                $found = 0;
+               $offset = 0;
+               $limit = 30;
+               $started = time();
 
                print __("Articles matching this filter:");
 
+               require_once "include/rssfuncs.php";
+
                print "<div class=\"filterTestHolder\">";
                print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
 
-               while ($line = $this->dbh->fetch_assoc($result)) {
-                       $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
+               $glue = $filter['match_any_rule'] ? " OR " :  " AND ";
+               $scope_qpart = join($glue, $scope_qparts);
 
-                       foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
-                                       $line = $p->hook_query_headlines($line, 100);
-                               }
+               if (!$scope_qpart) $scope_qpart = "true";
 
-                       $content_preview = $line["content_preview"];
+               while ($found < $limit && $offset < $limit * 10 && time() - $started < ini_get("max_execution_time") * 0.7) {
 
-                       if ($line["feed_title"])
-                               $feed_title = $line["feed_title"];
+                       $result = db_query("SELECT ttrss_entries.id,
+                                       ttrss_entries.title,
+                                       ttrss_feeds.id AS feed_id,
+                                       ttrss_feeds.title AS feed_title,
+                                       ttrss_feed_categories.id AS cat_id,
+                                       content,
+                                       link,
+                                       author,
+                                       tag_cache
+                               FROM
+                                       ttrss_entries, ttrss_user_entries
+                                               LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)
+                                               LEFT JOIN ttrss_feed_categories ON (ttrss_feeds.cat_id = ttrss_feed_categories.id)
+                               WHERE
+                                       ref_id = ttrss_entries.id AND
+                                       ($scope_qpart) AND
+                                       ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
+                               ORDER BY date_entered DESC LIMIT $limit OFFSET $offset");
 
-                       print "<tr>";
+                       while ($line = db_fetch_assoc($result)) {
 
-                       print "<td width='5%' align='center'><input
-                               dojoType=\"dijit.form.CheckBox\" checked=\"1\"
-                               disabled=\"1\" type=\"checkbox\"></td>";
-                       print "<td>";
+                               $rc = get_article_filters(array($filter), $line['title'], $line['content'], $line['link'],
+                                       false, $line['author'], explode(",", $line['tag_cache']));
 
-                       print $line["title"];
-                       print "&nbsp;(";
-                       print "<b>" . $feed_title . "</b>";
-                       print "):&nbsp;";
-                       print "<span class=\"insensitive\">" . $content_preview . "</span>";
-                       print " " . mb_substr($line["date_entered"], 0, 16);
+                               if (count($rc) > 0) {
 
-                       print "</td></tr>";
+                                       $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
 
-                       $found++;
-               }
+                                       foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                               $line = $p->hook_query_headlines($line, 100);
+                                       }
 
-               if ($found == 0) {
-                       print "<tr><td align='center'>" .
-                               __("No recent articles matching this filter have been found.");
+                                       $content_preview = $line["content_preview"];
+
+                                       if ($line["feed_title"]) $feed_title = "(" . $line["feed_title"] . ")";
+
+                                       print "<tr>";
+
+                                       print "<td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
+                                               checked=\"1\" disabled=\"1\" type=\"checkbox\"></td>";
+                                       print "<td>";
 
-                       print "</td></tr><tr><td class='insensitive' align='center'>";
+                                       /*foreach ($filter['rules'] as $rule) {
+                                               $reg_exp = $rule['reg_exp'];
+                                               $reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
 
-                       print __("Complex expressions might not give results while testing due to issues with database server regexp implementation.");
+                                               $line["title"] = preg_replace("/($reg_exp)/i",
+                                                       "<span class=\"highlight\">$1</span>", $line["title"]);
 
-                       print "</td></tr>";
+                                               $content_preview = preg_replace("/($reg_exp)/i",
+                                                       "<span class=\"highlight\">$1</span>", $content_preview);
+                                       }*/
+
+                                       print $line["title"];
+                                       print "<div class='small' style='float : right'>" . $feed_title . "</div>";
+                                       print "<div class=\"insensitive\">" . $content_preview . "</div>";
+                                       print " " . mb_substr($line["date_entered"], 0, 16);
+
+                                       print "</td></tr>";
+
+                                       $found++;
+                               }
+                       }
 
+                       $offset += $limit;
+               }
+
+               if ($found == 0) {
+                       print "<tr><td align='center'>" .
+                               __("No recent articles matching this filter have been found.");
                }
 
                print "</table></div>";
@@ -472,6 +519,21 @@ class Pref_Filters extends Handler_Protected {
                        $action["action_id"] == 7)
                                $title .= ": " . $action["action_param"];
 
+               if ($action["action_id"] == 9) {
+                       list ($pfclass, $pfaction) = explode(":", $action["action_param"]);
+
+                       $filter_actions = PluginHost::getInstance()->get_filter_actions();
+
+                       foreach ($filter_actions as $fclass => $factions) {
+                               foreach ($factions as $faction) {
+                                       if ($pfaction == $faction["action"] && $pfclass == $fclass) {
+                                               $title .= ": " . $fclass . ": " . $faction["description"];
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
                return $title;
        }
 
@@ -942,16 +1004,18 @@ class Pref_Filters extends Handler_Protected {
 
                print "</select>";
 
-               $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6) ?
+               $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ?
                        "" : "display : none";
 
                $param_hidden = ($action_id == 4 || $action_id == 6) ?
                        "" : "display : none";
 
                $label_param_hidden = ($action_id == 7) ?       "" : "display : none";
+               $plugin_param_hidden = ($action_id == 9) ?      "" : "display : none";
 
                print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
-               print " " . __("with parameters:") . " ";
+               print " ";
+               //print " " . __("with parameters:") . " ";
                print "<input dojoType=\"dijit.form.TextBox\"
                        id=\"filterDlg_actionParam\" style=\"$param_hidden\"
                        name=\"action_param\" value=\"$action_param\">";
@@ -960,6 +1024,22 @@ class Pref_Filters extends Handler_Protected {
                        "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
                        dojoType=\"dijit.form.Select\"");
 
+               $filter_actions = PluginHost::getInstance()->get_filter_actions();
+               $filter_action_hash = array();
+
+               foreach ($filter_actions as $fclass => $factions) {
+                       foreach ($factions as $faction) {
+
+                               $filter_action_hash[$fclass . ":" . $faction["action"]] =
+                                       $fclass . ": " . $faction["description"];
+                       }
+
+               }
+
+               print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash,
+                       "style=\"$plugin_param_hidden\" dojoType=\"dijit.form.Select\"",
+                       "action_param_plugin");
+
                print "</span>";
 
                print "&nbsp;"; // tiny layout hack