From a740f4b51d4810ea10022915051284a812232c18 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Nov 2010 15:49:26 +0300 Subject: tweak feed-prefs; rework filter prefs to use dijit.Tree --- modules/pref-filters.php | 314 +++++++++++++++++------------------------------ 1 file changed, 113 insertions(+), 201 deletions(-) (limited to 'modules/pref-filters.php') diff --git a/modules/pref-filters.php b/modules/pref-filters.php index 153707f6f..e419fa991 100644 --- a/modules/pref-filters.php +++ b/modules/pref-filters.php @@ -3,6 +3,100 @@ $subop = $_REQUEST["subop"]; $quiet = $_REQUEST["quiet"]; + if ($subop == "getfiltertree") { + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Filters'); + $root['items'] = array(); + + $result = db_query($link, "SELECT + ttrss_filters.id AS id,reg_exp, + ttrss_filter_types.name AS filter_type_name, + ttrss_filter_types.description AS filter_type_descr, + enabled, + inverse, + feed_id, + action_id, + filter_param, + filter_type, + ttrss_filter_actions.description AS action_description, + ttrss_feeds.title AS feed_title, + ttrss_filter_actions.name AS action_name, + ttrss_filters.action_param AS action_param + FROM + ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN + ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) + WHERE + filter_type = ttrss_filter_types.id AND + ttrss_filter_actions.id = action_id AND + ttrss_filters.owner_uid = ".$_SESSION["uid"]." + ORDER by action_description, reg_exp"); + + $cat = false; + $cur_action_description = ""; + + while ($line = db_fetch_assoc($result)) { + if ($cur_action_description != $line['action_description']) { + + if ($cat) + array_push($root['items'], $cat); + + $cat = array(); + $cat['id'] = 'ACTION:' . $line['action_id']; + $cat['name'] = $line['action_description']; + $cat['items'] = array(); + + $cur_action_description = $line['action_description']; + } + + if (array_search($line["action_name"], + array("score", "tag", "label")) === false) { + + $line["action_param"] = ''; + } else { + if ($line['action_name'] == 'label') { + + $tmp_result = db_query($link, "SELECT fg_color, bg_color + FROM ttrss_labels2 WHERE caption = '". + db_escape_string($line["action_param"])."' AND + owner_uid = " . $_SESSION["uid"]); + + $fg_color = db_fetch_result($tmp_result, 0, "fg_color"); + $bg_color = db_fetch_result($tmp_result, 0, "bg_color"); + + $tmp = "α " . $line['action_param']; + + $line['action_param'] = $tmp; + } + } + + $filter = array(); + $filter['id'] = 'FILTER:' . $line['id']; + $filter['bare_id'] = $line['id']; + $filter['name'] = $line['reg_exp']; + $filter['type'] = $line['filter_type']; + $filter['enabled'] = sql_bool_to_bool($line['enabled']); + $filter['param'] = $line['action_param']; + $filter['inverse'] = sql_bool_to_bool($line['inverse']); + $filter['checkbox'] = false; + + if ($line['feed_id']) + $filter['feed'] = $line['feed_title']; + + array_push($cat['items'], $filter); + } + + array_push($root['items'], $cat); + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + return; + } + if ($subop == "edit") { $filter_id = db_escape_string($_REQUEST["id"]); @@ -309,9 +403,9 @@ print "
". "" . __('Select').""; print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; print "
"; @@ -333,205 +427,23 @@ print ""; # toolbar-frame print "
"; - if ($filter_search) { - $filter_search = split(' ', db_escape_string($filter_search)); - - $tokens = array(); - - foreach ($filter_search as $token) { - $token = trim($token); - - array_push($tokens, "( - UPPER(ttrss_filter_actions.description) LIKE UPPER('%$token%') OR - UPPER(reg_exp) LIKE UPPER('%$token%') OR - UPPER(action_param) LIKE UPPER('%$token%') OR - UPPER(ttrss_feeds.title) LIKE UPPER('%$token%') OR - UPPER(ttrss_filter_types.description) LIKE UPPER('%$token%'))"); - } - - $filter_search_query = "(" . join($tokens, " AND ") . ") AND "; - - } else { - $filter_search_query = ""; - } - - $result = db_query($link, "SELECT - ttrss_filters.id AS id,reg_exp, - ttrss_filter_types.name AS filter_type_name, - ttrss_filter_types.description AS filter_type_descr, - enabled, - inverse, - feed_id, - filter_param, - filter_type, - ttrss_filter_actions.description AS action_description, - ttrss_feeds.title AS feed_title, - ttrss_filter_actions.name AS action_name, - ttrss_filters.action_param AS action_param - FROM - ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN - ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) - WHERE - filter_type = ttrss_filter_types.id AND - $filter_search_query - ttrss_filter_actions.id = action_id AND - ttrss_filters.owner_uid = ".$_SESSION["uid"]." - ORDER by action_description, $sort"); - - if (db_num_rows($result) != 0) { - - print "

"; - - print ""; - - print " - - - - - "; - - $lnum = 0; - } - - $class = ($lnum % 2) ? "even" : "odd"; - - print ""; - - $line["reg_exp"] = htmlspecialchars($line["reg_exp"]); - - if (!$line["feed_title"]) $line["feed_title"] = __("All feeds"); - - if (array_search($line["action_name"], - array("score", "tag", "label")) === false) { - - $line["action_param"] = false; - } - - if (!$line["action_param"]) { - $line["action_param"] = "—"; - } else if ($line["action_name"] == "score") { - - $score_pic = theme_image($link, - "images/" . get_score_pic($line["action_param"])); - - $score_pic = ""; - - $line["action_param"] = "$score_pic " . $line["action_param"]; - - } - - $line["feed_title"] = htmlspecialchars($line["feed_title"]); - - print ""; - - $filter_params = array( - "before" => __("before"), - "after" => __("after")); - - if ($line["action_name"] == 'label') { - - $tmp_result = db_query($link, "SELECT fg_color, bg_color - FROM ttrss_labels2 WHERE caption = '". - db_escape_string($line["action_param"])."' AND - owner_uid = " . $_SESSION["uid"]); - - $fg_color = db_fetch_result($tmp_result, 0, "fg_color"); - $bg_color = db_fetch_result($tmp_result, 0, "bg_color"); - - $tmp = "
- α"; - $tmp .= "
"; - - $line["action_param"] = "$tmp " . $line["action_param"]; - } - - if ($line["filter_type"] == 5) { - - if (!strtotime($line["reg_exp"])) { - $line["reg_exp"] = "" . - $line["reg_exp"] . ""; - } - - $line["reg_exp"] = __("Date") . " " . - $filter_params[$line['filter_param']] . " " . - $line["reg_exp"]; - } - - if (!$enabled) { - $line["reg_exp"] = "" . - $line["reg_exp"] . " " . __("(Disabled)").""; - $line["feed_title"] = "" . - $line["feed_title"] . ""; - $line["filter_type_descr"] = "" . - $line["filter_type_descr"] . ""; - $line["action_description"] = "" . - $line["action_description"] . ""; - $line["action_param"] = "" . - $line["action_param"] . ""; - } - - $onclick = "onclick='editFilter($filter_id, event)' title='".__('Click to edit')."'"; - - $inverse_label = ""; - - if ($inverse) { - $inverse_label = " ".__('(Inverse)').""; - } - - print ""; - print ""; - - print ""; - print ""; - - print ""; - - ++$lnum; - } - - print "
- ".__('Select:')." - ".__('All').", - ".__('None')." - "; - - $lnum = 0; - - $cur_action_description = ""; - - while ($line = db_fetch_assoc($result)) { - - $filter_id = $line["id"]; - $edit_filter_id = $_REQUEST["id"]; - - $enabled = sql_bool_to_bool($line["enabled"]); - $inverse = sql_bool_to_bool($line["inverse"]); - - $this_row_id = "id=\"FILRR-$filter_id\""; - - $line["filter_type_descr"] = __($line["filter_type_descr"]); - $line["action_description"] = __($line["action_description"]); - - if ($line["action_description"] != $cur_action_description) { - $cur_action_description = $line["action_description"]; - - print "
$cur_action_description
 ".__('Match')."".__('Feed')."".__('Field')."".__('Params')."
" . $line["reg_exp"] . "$inverse_label" . $line["feed_title"] . "" . $line["filter_type_descr"] . "" . $line["action_param"] . "
"; - - } else { - - print "

"; - if (!$filter_search) { - print_warning(__('No filters defined.')); - } else { - print_warning(__('No matching filters found.')); - } - print "

"; - - } + print "
+ ". + __("Loading, please wait...")."
"; + + print "
+
+
+
+
+ +
"; print "
"; #pane print ""; #container -- cgit v1.2.3