]>
git.wh0rd.org - tt-rss.git/blob - classes/pref_filters.php
2 class Pref_Filters
extends Protected_Handler
{
4 function filter_test($filter_type, $reg_exp,
5 $action_id, $action_param, $filter_param, $inverse, $feed_id) {
7 $result = db_query($this->link
, "SELECT name FROM ttrss_filter_types WHERE
8 id = " . $filter_type);
9 $type_name = db_fetch_result($result, 0, "name");
11 $result = db_query($this->link
, "SELECT name FROM ttrss_filter_actions WHERE
13 $action_name = db_fetch_result($result, 0, "name");
15 $filter["reg_exp"] = $reg_exp;
16 $filter["action"] = $action_name;
17 $filter["type"] = $type_name;
18 $filter["action_param"] = $action_param;
19 $filter["filter_param"] = $filter_param;
20 $filter["inverse"] = $inverse;
22 $filters[$type_name] = array($filter);
29 $feed_title = getFeedTitle($this->link
, $feed);
31 $qfh_ret = queryFeedHeadlines($this->link
, $feed,
32 30, "", false, false, false,
33 false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
35 $result = $qfh_ret[0];
40 print __("Articles matching this filter:");
42 print "<div class=\"inactiveFeedHolder\">";
43 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
45 while ($line = db_fetch_assoc($result)) {
47 $entry_timestamp = strtotime($line["updated"]);
48 $entry_tags = get_article_tags($this->link
, $line["id"], $_SESSION["uid"]);
50 $content_preview = truncate_string(
51 strip_tags($line["content_preview"]), 100, '...');
53 if ($line["feed_title"])
54 $feed_title = $line["feed_title"];
58 print "<td width='5%' align='center'><input
59 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
60 disabled=\"1\" type=\"checkbox\"></td>";
65 print "<b>" . $feed_title . "</b>";
67 print "<span class=\"insensitive\">" . $content_preview . "</span>";
68 print " " . mb_substr($line["date_entered"], 0, 16);
76 print "<tr><td align='center'>" .
77 __("No articles matching this filter has been found.") . "</td></tr>";
85 function getfiltertree() {
88 $root['name'] = __('Filters');
89 $root['items'] = array();
91 $result = db_query($this->link
, "SELECT
92 ttrss_filters.id AS id,reg_exp,
93 ttrss_filter_types.name AS filter_type_name,
94 ttrss_filter_types.description AS filter_type_descr,
101 ttrss_filter_actions.description AS action_description,
102 ttrss_feeds.title AS feed_title,
103 ttrss_filter_actions.name AS action_name,
104 ttrss_filters.action_param AS action_param
106 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
107 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
109 filter_type = ttrss_filter_types.id AND
110 ttrss_filter_actions.id = action_id AND
111 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
112 ORDER by action_description, reg_exp");
115 $cur_action_description = "";
117 if (db_num_rows($result) > 0) {
119 while ($line = db_fetch_assoc($result)) {
120 if ($cur_action_description != $line['action_description']) {
123 array_push($root['items'], $cat);
126 $cat['id'] = 'ACTION:' . $line['action_id'];
127 $cat['name'] = $line['action_description'];
128 $cat['items'] = array();
130 $cur_action_description = $line['action_description'];
133 if (array_search($line["action_name"],
134 array("score", "tag", "label")) === false) {
136 $line["action_param"] = '';
138 if ($line['action_name'] == 'label') {
140 $tmp_result = db_query($this->link
, "SELECT fg_color, bg_color
141 FROM ttrss_labels2 WHERE caption = '".
142 db_escape_string($line["action_param"])."' AND
143 owner_uid = " . $_SESSION["uid"]);
145 if (db_num_rows($tmp_result) != 0) {
146 $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
147 $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
149 $tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>α</span> " . $line['action_param'];
151 $line['action_param'] = $tmp;
157 $filter['id'] = 'FILTER:' . $line['id'];
158 $filter['bare_id'] = $line['id'];
159 $filter['name'] = $line['reg_exp'];
160 $filter['type'] = $line['filter_type'];
161 $filter['enabled'] = sql_bool_to_bool($line['enabled']);
162 $filter['param'] = $line['action_param'];
163 $filter['inverse'] = sql_bool_to_bool($line['inverse']);
164 $filter['checkbox'] = false;
166 if ($line['feed_id'])
167 $filter['feed'] = $line['feed_title'];
169 array_push($cat['items'], $filter);
172 array_push($root['items'], $cat);
176 $fl['identifier'] = 'id';
177 $fl['label'] = 'name';
178 $fl['items'] = array($root);
180 print json_encode($fl);
186 $filter_id = db_escape_string($_REQUEST["id"]);
188 $result = db_query($this->link
,
189 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
191 $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
192 $filter_type = db_fetch_result($result, 0, "filter_type");
193 $feed_id = db_fetch_result($result, 0, "feed_id");
194 $action_id = db_fetch_result($result, 0, "action_id");
195 $action_param = db_fetch_result($result, 0, "action_param");
196 $filter_param = db_fetch_result($result, 0, "filter_param");
198 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
199 $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
201 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
203 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
204 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
205 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
207 $result = db_query($this->link
, "SELECT id,description
208 FROM ttrss_filter_types ORDER BY description");
210 $filter_types = array();
212 while ($line = db_fetch_assoc($result)) {
213 //array_push($filter_types, $line["description"]);
214 $filter_types[$line["id"]] = __($line["description"]);
217 print "<div class=\"dlgSec\">".__("Match")."</div>";
219 print "<div class=\"dlgSecCont\">";
221 if ($filter_type != 5) {
222 $date_ops_invisible = 'style="display : none"';
225 print "<span id=\"filterDlg_dateModBox\" $date_ops_invisible>";
226 print __("Date") . " ";
228 $filter_params = array(
229 "before" => __("before"),
230 "after" => __("after"));
232 print_select_hash("filter_date_modifier", $filter_param,
233 $filter_params, 'dojoType="dijit.form.Select"');
235 print " </span>";
237 print "<input dojoType=\"dijit.form.ValidationTextBox\"
239 name=\"reg_exp\" style=\"font-size : 16px;\" value=\"$reg_exp\">";
241 print "<span id=\"filterDlg_dateChkBox\" $date_ops_invisible>";
242 print " <button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">".
243 __('Check it')."</button>";
246 print "<hr/> " . __("on field") . " ";
247 print_select_hash("filter_type", $filter_type, $filter_types,
248 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
252 print __("in") . " ";
253 print_feed_select($this->link
, "feed_id", $feed_id,
254 'dojoType="dijit.form.FilteringSelect"');
258 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
260 print "<div class=\"dlgSecCont\">";
262 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
263 onchange=\"filterDlgCheckAction(this)\">";
265 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
268 while ($line = db_fetch_assoc($result)) {
269 $is_sel = ($line["id"] == $action_id) ?
"selected=\"1\"" : "";
270 printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"]));
275 $param_hidden = ($action_id == 4 ||
$action_id == 6 ||
$action_id == 7) ?
"" : "display : none";
277 print "<span id=\"filterDlg_paramBox\" style=\"$param_hidden\">";
278 print " " . __("with parameters:") . " ";
280 $param_int_hidden = ($action_id != 7) ?
"" : "display : none";
282 print "<input style=\"$param_int_hidden\"
283 dojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\"
284 name=\"action_param\" value=\"$action_param\">";
286 $param_int_hidden = ($action_id == 7) ?
"" : "display : none";
288 print_label_select($this->link
, "action_param_label", $action_param,
289 "style=\"$param_int_hidden\"" .
290 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
294 print " "; // tiny layout hack
298 print "<div class=\"dlgSec\">".__("Options")."</div>";
299 print "<div class=\"dlgSecCont\">";
301 print "<div style=\"line-height : 100%\">";
304 $checked = "checked=\"1\"";
309 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
310 <label for=\"enabled\">".__('Enabled')."</label><hr/>";
313 $checked = "checked=\"1\"";
318 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
319 <label for=\"inverse\">".__('Inverse match')."</label>";
324 print "<div class=\"dlgButtons\">";
326 print "<div style=\"float : left\">";
327 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
328 __('Remove')."</button>";
331 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
332 __('Test')."</button> ";
334 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
335 __('Save')."</button> ";
337 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
338 __('Cancel')."</button>";
343 function editSave() {
347 if ($memcache) $memcache->flush();
349 $savemode = db_escape_string($_REQUEST["savemode"]);
350 $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
351 $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
352 $filter_id = db_escape_string($_REQUEST["id"]);
353 $feed_id = db_escape_string($_REQUEST["feed_id"]);
354 $action_id = db_escape_string($_REQUEST["action_id"]);
355 $action_param = db_escape_string($_REQUEST["action_param"]);
356 $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
357 $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
358 $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
360 # for the time being, no other filters use params anyway...
361 $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
366 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
369 /* When processing 'assign label' filters, action_param_label dropbox
370 * overrides action_param */
372 if ($action_id == 7) {
373 $action_param = $action_param_label;
376 if ($action_id == 6) {
377 $action_param = (int) str_replace("+", "", $action_param);
380 if ($savemode != "test") {
381 $result = db_query($this->link
, "UPDATE ttrss_filters SET
382 reg_exp = '$reg_exp',
384 action_id = '$action_id',
385 filter_type = '$filter_type',
388 action_param = '$action_param',
389 filter_param = '$filter_param'
390 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
393 $this->filter_test($filter_type, $reg_exp,
394 $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
395 (int) $_REQUEST["feed_id"]);
397 print "<div align='center'>";
398 print "<button dojoType=\"dijit.form.Button\"
399 onclick=\"return dijit.byId('filterTestDlg').hide()\">".
400 __('Close this window')."</button>";
408 if ($memcache) $memcache->flush();
410 $ids = split(",", db_escape_string($_REQUEST["ids"]));
412 foreach ($ids as $id) {
413 db_query($this->link
, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
419 if ($memcache) $memcache->flush();
421 $savemode = db_escape_string($_REQUEST["savemode"]);
422 $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
423 $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
424 $feed_id = db_escape_string($_REQUEST["feed_id"]);
425 $action_id = db_escape_string($_REQUEST["action_id"]);
426 $action_param = db_escape_string($_REQUEST["action_param"]);
427 $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
428 $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
430 # for the time being, no other filters use params anyway...
431 $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
433 if (!$regexp) return;
438 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
441 /* When processing 'assign label' filters, action_param_label dropbox
442 * overrides action_param */
444 if ($action_id == 7) {
445 $action_param = $action_param_label;
448 if ($action_id == 6) {
449 $action_param = (int) str_replace("+", "", $action_param);
452 if ($savemode != "test") {
453 $result = db_query($this->link
,
454 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
455 action_id, action_param, inverse, filter_param)
457 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
458 $feed_id, '$action_id', '$action_param', $inverse,
461 if (db_affected_rows($this->link
, $result) != 0) {
462 print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
467 $this->filter_test($filter_type, $regexp,
468 $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
469 (int) $_REQUEST["feed_id"]);
471 print "<div align='center'>";
472 print "<button dojoType=\"dijit.form.Button\"
473 onclick=\"return dijit.byId('filterTestDlg').hide()\">".
474 __('Close this window')."</button>";
482 $sort = db_escape_string($_REQUEST["sort"]);
484 if (!$sort ||
$sort == "undefined") {
488 $result = db_query($this->link
, "SELECT id,description
489 FROM ttrss_filter_types ORDER BY description");
491 $filter_types = array();
493 while ($line = db_fetch_assoc($result)) {
494 //array_push($filter_types, $line["description"]);
495 $filter_types[$line["id"]] = $line["description"];
499 $filter_search = db_escape_string($_REQUEST["search"]);
501 if (array_key_exists("search", $_REQUEST)) {
502 $_SESSION["prefs_filter_search"] = $filter_search;
504 $filter_search = $_SESSION["prefs_filter_search"];
507 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
508 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
509 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
511 print "<div dojoType=\"dijit.form.DropDownButton\">".
512 "<span>" . __('Select')."</span>";
513 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
514 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
515 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
516 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
517 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
518 print "</div></div>";
520 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
521 __('Create filter')."</button> ";
523 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
524 __('Edit')."</button> ";
526 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
527 __('Remove')."</button> ";
529 if (defined('_ENABLE_FEED_DEBUGGING')) {
530 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
531 __('Rescore articles')."</button> ";
534 print "</div>"; # toolbar
535 print "</div>"; # toolbar-frame
536 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
538 print "<div id=\"filterlistLoading\">
539 <img src='images/indicator_tiny.gif'>".
540 __("Loading, please wait...")."</div>";
542 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
543 url=\"backend.php?op=pref-filters&method=getfiltertree\">
545 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
546 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
547 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
549 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
550 model=\"filterModel\" openOnClick=\"true\">
551 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
552 Element.hide(\"filterlistLoading\");
554 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
555 var id = String(item.id);
556 var bare_id = id.substr(id.indexOf(':')+1);
558 if (id.match('FILTER:')) {
565 print "</div>"; #pane
566 print "</div>"; #container