]>
Commit | Line | Data |
---|---|---|
8e17d663 | 1 | <?php |
369dbc19 | 2 | class Pref_Filters extends Handler_Protected { |
8e17d663 | 3 | |
8484ce22 | 4 | function csrf_ignore($method) { |
6aff7845 AD |
5 | $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", |
6 | "newaction"); | |
8484ce22 AD |
7 | |
8 | return array_search($method, $csrf_ignored) !== false; | |
9 | } | |
10 | ||
4e02f582 AD |
11 | function testFilter() { |
12 | $filter = array(); | |
8e17d663 | 13 | |
4e02f582 AD |
14 | $filter["enabled"] = true; |
15 | $filter["match_any_rule"] = sql_bool_to_bool( | |
3972bf59 | 16 | checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["match_any_rule"]))); |
a3a896a1 AD |
17 | $filter["inverse"] = sql_bool_to_bool( |
18 | checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["inverse"]))); | |
19 | ||
4e02f582 | 20 | $filter["rules"] = array(); |
8e17d663 | 21 | |
4e02f582 | 22 | $result = db_query($this->link, "SELECT id,name FROM ttrss_filter_types"); |
8e17d663 | 23 | |
4e02f582 AD |
24 | $filter_types = array(); |
25 | while ($line = db_fetch_assoc($result)) { | |
26 | $filter_types[$line["id"]] = $line["name"]; | |
27 | } | |
8e17d663 | 28 | |
4e02f582 AD |
29 | $rctr = 0; |
30 | foreach ($_REQUEST["rule"] AS $r) { | |
31 | $rule = json_decode($r, true); | |
8e17d663 | 32 | |
4e02f582 AD |
33 | if ($rule && $rctr < 5) { |
34 | $rule["type"] = $filter_types[$rule["filter_type"]]; | |
35 | unset($rule["filter_type"]); | |
8e17d663 | 36 | |
4e02f582 AD |
37 | if (strpos($rule["feed_id"], "CAT:") === 0) { |
38 | $rule["cat_id"] = (int) substr($rule["feed_id"], 4); | |
39 | unset($rule["feed_id"]); | |
40 | } | |
8e17d663 | 41 | |
4e02f582 | 42 | array_push($filter["rules"], $rule); |
8e17d663 | 43 | |
4e02f582 AD |
44 | ++$rctr; |
45 | } else { | |
46 | break; | |
47 | } | |
48 | } | |
8e17d663 | 49 | |
4e02f582 | 50 | $feed_title = getFeedTitle($this->link, $feed); |
8e17d663 | 51 | |
4e02f582 | 52 | $qfh_ret = queryFeedHeadlines($this->link, -4, 30, "", false, false, false, |
ca5d9be4 | 53 | "date_entered DESC", 0, $_SESSION["uid"], $filter); |
8e17d663 | 54 | |
4e02f582 | 55 | $result = $qfh_ret[0]; |
8e17d663 | 56 | |
4e02f582 AD |
57 | $articles = array(); |
58 | $found = 0; | |
8e17d663 | 59 | |
4e02f582 | 60 | print __("Articles matching this filter:"); |
8e17d663 | 61 | |
4e02f582 AD |
62 | print "<div class=\"filterTestHolder\">"; |
63 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; | |
8e17d663 | 64 | |
4e02f582 | 65 | while ($line = db_fetch_assoc($result)) { |
8e17d663 | 66 | |
4e02f582 AD |
67 | $entry_timestamp = strtotime($line["updated"]); |
68 | $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]); | |
8e17d663 | 69 | |
4e02f582 AD |
70 | $content_preview = truncate_string( |
71 | strip_tags($line["content_preview"]), 100, '...'); | |
56fbb82c | 72 | |
4e02f582 AD |
73 | if ($line["feed_title"]) |
74 | $feed_title = $line["feed_title"]; | |
56fbb82c | 75 | |
4e02f582 | 76 | print "<tr>"; |
56fbb82c | 77 | |
4e02f582 AD |
78 | print "<td width='5%' align='center'><input |
79 | dojoType=\"dijit.form.CheckBox\" checked=\"1\" | |
80 | disabled=\"1\" type=\"checkbox\"></td>"; | |
81 | print "<td>"; | |
56fbb82c | 82 | |
4e02f582 AD |
83 | print $line["title"]; |
84 | print " ("; | |
85 | print "<b>" . $feed_title . "</b>"; | |
86 | print "): "; | |
87 | print "<span class=\"insensitive\">" . $content_preview . "</span>"; | |
88 | print " " . mb_substr($line["date_entered"], 0, 16); | |
56fbb82c | 89 | |
4e02f582 | 90 | print "</td></tr>"; |
56fbb82c | 91 | |
4e02f582 AD |
92 | $found++; |
93 | } | |
8e17d663 | 94 | |
4e02f582 AD |
95 | if ($found == 0) { |
96 | print "<tr><td align='center'>" . | |
5cb17306 AD |
97 | __("No recent articles matching this filter have been found."); |
98 | ||
99 | print "</td></tr><tr><td class='insensitive' align='center'>"; | |
100 | ||
101 | print __("Complex expressions might not give results while testing due to issues with database server regexp implementation."); | |
102 | ||
103 | print "</td></tr>"; | |
104 | ||
8e17d663 AD |
105 | } |
106 | ||
4e02f582 AD |
107 | print "</table></div>"; |
108 | ||
109 | print "<div style='text-align : center'>"; | |
110 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">". | |
111 | __('Close this window')."</button>"; | |
8e17d663 AD |
112 | print "</div>"; |
113 | ||
4e02f582 AD |
114 | } |
115 | ||
8e17d663 AD |
116 | |
117 | function getfiltertree() { | |
118 | $root = array(); | |
119 | $root['id'] = 'root'; | |
120 | $root['name'] = __('Filters'); | |
121 | $root['items'] = array(); | |
122 | ||
69c6e94d AD |
123 | $filter_search = $_SESSION["prefs_filter_search"]; |
124 | ||
6aff7845 | 125 | $result = db_query($this->link, "SELECT *, |
84d9750e AD |
126 | (SELECT action_param FROM ttrss_filters2_actions |
127 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param, | |
6aff7845 AD |
128 | (SELECT action_id FROM ttrss_filters2_actions |
129 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id, | |
37f78940 AD |
130 | (SELECT description FROM ttrss_filter_actions |
131 | WHERE id = (SELECT action_id FROM ttrss_filters2_actions | |
132 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name, | |
6aff7845 AD |
133 | (SELECT reg_exp FROM ttrss_filters2_rules |
134 | WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp | |
135 | FROM ttrss_filters2 WHERE | |
da46d21e | 136 | owner_uid = ".$_SESSION["uid"]." ORDER BY order_id"); |
8e17d663 | 137 | |
69c6e94d | 138 | |
37f78940 AD |
139 | $action_id = -1; |
140 | $folder = array(); | |
141 | $folder['items'] = array(); | |
142 | ||
6aff7845 | 143 | while ($line = db_fetch_assoc($result)) { |
8e17d663 | 144 | |
da46d21e | 145 | /* if ($action_id != $line["action_id"]) { |
37f78940 | 146 | if (count($folder['items']) > 0) { |
37f78940 AD |
147 | array_push($root['items'], $folder); |
148 | } | |
e8b70387 | 149 | |
37f78940 | 150 | $folder = array(); |
e8b70387 | 151 | $folder['id'] = $line["action_id"]; |
7b28a986 | 152 | $folder['name'] = __($line["action_name"]); |
37f78940 AD |
153 | $folder['items'] = array(); |
154 | $action_id = $line["action_id"]; | |
da46d21e | 155 | } */ |
37f78940 | 156 | |
6aff7845 | 157 | $name = $this->getFilterName($line["id"]); |
8e17d663 | 158 | |
69c6e94d AD |
159 | $match_ok = false; |
160 | if ($filter_search) { | |
161 | $rules_result = db_query($this->link, | |
162 | "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]); | |
163 | ||
164 | while ($rule_line = db_fetch_assoc($rules_result)) { | |
165 | if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) { | |
166 | $match_ok = true; | |
167 | break; | |
168 | } | |
169 | } | |
170 | } | |
171 | ||
84d9750e AD |
172 | if ($line['action_id'] == 7) { |
173 | $label_result = db_query($this->link, "SELECT fg_color, bg_color | |
3972bf59 | 174 | FROM ttrss_labels2 WHERE caption = '".db_escape_string($this->link, $line['action_param'])."' AND |
84d9750e AD |
175 | owner_uid = " . $_SESSION["uid"]); |
176 | ||
177 | if (db_num_rows($label_result) > 0) { | |
178 | $fg_color = db_fetch_result($label_result, 0, "fg_color"); | |
179 | $bg_color = db_fetch_result($label_result, 0, "bg_color"); | |
180 | ||
da46d21e | 181 | $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>α</span>" . $name[1]; |
84d9750e AD |
182 | } |
183 | } | |
184 | ||
6aff7845 AD |
185 | $filter = array(); |
186 | $filter['id'] = 'FILTER:' . $line['id']; | |
187 | $filter['bare_id'] = $line['id']; | |
188 | $filter['name'] = $name[0]; | |
189 | $filter['param'] = $name[1]; | |
190 | $filter['checkbox'] = false; | |
c2ee5846 | 191 | $filter['enabled'] = sql_bool_to_bool($line["enabled"]); |
8e17d663 | 192 | |
69c6e94d AD |
193 | if (!$filter_search || $match_ok) { |
194 | array_push($folder['items'], $filter); | |
195 | } | |
8e17d663 AD |
196 | } |
197 | ||
da46d21e | 198 | /* if (count($folder['items']) > 0) { |
e8b70387 | 199 | array_push($root['items'], $folder); |
da46d21e AD |
200 | } */ |
201 | ||
202 | $root['items'] = $folder['items']; | |
e8b70387 | 203 | |
8e17d663 AD |
204 | $fl = array(); |
205 | $fl['identifier'] = 'id'; | |
206 | $fl['label'] = 'name'; | |
207 | $fl['items'] = array($root); | |
208 | ||
209 | print json_encode($fl); | |
210 | return; | |
211 | } | |
212 | ||
213 | function edit() { | |
214 | ||
3972bf59 | 215 | $filter_id = db_escape_string($this->link, $_REQUEST["id"]); |
8e17d663 AD |
216 | |
217 | $result = db_query($this->link, | |
6aff7845 | 218 | "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
8e17d663 AD |
219 | |
220 | $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); | |
6aff7845 | 221 | $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule")); |
a3a896a1 | 222 | $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); |
18ad09af | 223 | $title = htmlspecialchars(db_fetch_result($result, 0, "title")); |
8e17d663 AD |
224 | |
225 | print "<form id=\"filter_edit_form\" onsubmit='return false'>"; | |
226 | ||
227 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">"; | |
228 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">"; | |
229 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">"; | |
b69a09ea | 230 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">"; |
8e17d663 | 231 | |
18ad09af AD |
232 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; |
233 | ||
234 | print "<input dojoType=\"dijit.form.TextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">"; | |
235 | ||
236 | print "</div>"; | |
237 | ||
8e17d663 AD |
238 | print "<div class=\"dlgSec\">".__("Match")."</div>"; |
239 | ||
6aff7845 | 240 | print "<div dojoType=\"dijit.Toolbar\">"; |
8e17d663 | 241 | |
6aff7845 AD |
242 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
243 | "<span>" . __('Select')."</span>"; | |
244 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
245 | print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" | |
246 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
247 | print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" | |
248 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
249 | print "</div></div>"; | |
8e17d663 | 250 | |
6aff7845 AD |
251 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">". |
252 | __('Add')."</button> "; | |
8e17d663 | 253 | |
6aff7845 AD |
254 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". |
255 | __('Delete')."</button> "; | |
8e17d663 | 256 | |
6aff7845 | 257 | print "</div>"; |
8e17d663 | 258 | |
6aff7845 | 259 | print "<ul id='filterDlg_Matches'>"; |
8e17d663 | 260 | |
6aff7845 | 261 | $rules_result = db_query($this->link, "SELECT * FROM ttrss_filters2_rules |
56b2a409 | 262 | WHERE filter_id = '$filter_id' ORDER BY reg_exp, id"); |
8e17d663 | 263 | |
6aff7845 | 264 | while ($line = db_fetch_assoc($rules_result)) { |
5451903c | 265 | if (sql_bool_to_bool($line["cat_filter"])) { |
6aff7845 | 266 | $line["feed_id"] = "CAT:" . (int)$line["cat_id"]; |
6aff7845 | 267 | } |
8e17d663 | 268 | |
4e02f582 AD |
269 | unset($line["cat_filter"]); |
270 | unset($line["cat_id"]); | |
271 | unset($line["filter_id"]); | |
272 | unset($line["id"]); | |
a3a896a1 | 273 | if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]); |
4e02f582 | 274 | |
6aff7845 | 275 | $data = htmlspecialchars(json_encode($line)); |
8e17d663 | 276 | |
04e41840 | 277 | print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>". |
6aff7845 AD |
278 | "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>". |
279 | "<input type='hidden' name='rule[]' value=\"$data\"/></li>"; | |
280 | } | |
ba975b2e | 281 | |
6aff7845 | 282 | print "</ul>"; |
ba975b2e | 283 | |
8e17d663 AD |
284 | print "</div>"; |
285 | ||
6aff7845 | 286 | print "<div class=\"dlgSec\">".__("Apply actions")."</div>"; |
8e17d663 | 287 | |
6aff7845 | 288 | print "<div dojoType=\"dijit.Toolbar\">"; |
8e17d663 | 289 | |
6aff7845 AD |
290 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
291 | "<span>" . __('Select')."</span>"; | |
292 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
293 | print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" | |
294 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
295 | print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" | |
296 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
297 | print "</div></div>"; | |
8e17d663 | 298 | |
6aff7845 AD |
299 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">". |
300 | __('Add')."</button> "; | |
8e17d663 | 301 | |
6aff7845 AD |
302 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". |
303 | __('Delete')."</button> "; | |
8e17d663 | 304 | |
6aff7845 | 305 | print "</div>"; |
8e17d663 | 306 | |
6aff7845 | 307 | print "<ul id='filterDlg_Actions'>"; |
8e17d663 | 308 | |
6aff7845 AD |
309 | $actions_result = db_query($this->link, "SELECT * FROM ttrss_filters2_actions |
310 | WHERE filter_id = '$filter_id' ORDER BY id"); | |
8e17d663 | 311 | |
6aff7845 AD |
312 | while ($line = db_fetch_assoc($actions_result)) { |
313 | $line["action_param_label"] = $line["action_param"]; | |
4e02f582 AD |
314 | |
315 | unset($line["filter_id"]); | |
316 | unset($line["id"]); | |
317 | ||
6aff7845 | 318 | $data = htmlspecialchars(json_encode($line)); |
8e17d663 | 319 | |
04e41840 | 320 | print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>". |
6aff7845 AD |
321 | "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>". |
322 | "<input type='hidden' name='action[]' value=\"$data\"/></li>"; | |
323 | } | |
8e17d663 | 324 | |
6aff7845 | 325 | print "</ul>"; |
8e17d663 AD |
326 | |
327 | print "</div>"; | |
328 | ||
8e17d663 AD |
329 | if ($enabled) { |
330 | $checked = "checked=\"1\""; | |
331 | } else { | |
332 | $checked = ""; | |
333 | } | |
334 | ||
335 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> | |
6aff7845 | 336 | <label for=\"enabled\">".__('Enabled')."</label>"; |
8e17d663 | 337 | |
6aff7845 | 338 | if ($match_any_rule) { |
8e17d663 AD |
339 | $checked = "checked=\"1\""; |
340 | } else { | |
341 | $checked = ""; | |
342 | } | |
343 | ||
6aff7845 AD |
344 | print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked> |
345 | <label for=\"match_any_rule\">".__('Match any rule')."</label>"; | |
8e17d663 | 346 | |
a3a896a1 AD |
347 | if ($inverse) { |
348 | $checked = "checked=\"1\""; | |
349 | } else { | |
350 | $checked = ""; | |
351 | } | |
352 | ||
353 | print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> | |
354 | <label for=\"inverse\">".__('Inverse matching')."</label>"; | |
355 | ||
6aff7845 | 356 | print "<p/>"; |
8e17d663 AD |
357 | |
358 | print "<div class=\"dlgButtons\">"; | |
359 | ||
360 | print "<div style=\"float : left\">"; | |
361 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">". | |
362 | __('Remove')."</button>"; | |
363 | print "</div>"; | |
364 | ||
4e02f582 AD |
365 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">". |
366 | __('Test')."</button> "; | |
8e17d663 AD |
367 | |
368 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". | |
369 | __('Save')."</button> "; | |
370 | ||
371 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". | |
372 | __('Cancel')."</button>"; | |
373 | ||
374 | print "</div>"; | |
375 | } | |
376 | ||
6aff7845 AD |
377 | private function getRuleName($rule) { |
378 | if (!$rule) $rule = json_decode($_REQUEST["rule"], true); | |
8e17d663 | 379 | |
6aff7845 | 380 | $feed_id = $rule["feed_id"]; |
8e17d663 | 381 | |
4c9d0490 | 382 | if (strpos($feed_id, "CAT:") === 0) { |
6aff7845 AD |
383 | $feed_id = (int) substr($feed_id, 4); |
384 | $feed = getCategoryTitle($this->link, $feed_id); | |
8e17d663 | 385 | } else { |
4c9d0490 | 386 | $feed_id = (int) $feed_id; |
6aff7845 AD |
387 | |
388 | if ($rule["feed_id"]) | |
389 | $feed = getFeedTitle($this->link, (int)$rule["feed_id"]); | |
390 | else | |
391 | $feed = __("All feeds"); | |
8e17d663 AD |
392 | } |
393 | ||
6aff7845 AD |
394 | $result = db_query($this->link, "SELECT description FROM ttrss_filter_types |
395 | WHERE id = ".(int)$rule["filter_type"]); | |
ca5d9be4 | 396 | $filter_type = db_fetch_result($result, 0, "description"); |
4c9d0490 | 397 | |
a3a896a1 AD |
398 | return T_sprintf("%s on %s in %s %s", strip_tags($rule["reg_exp"]), |
399 | $filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : ""); | |
6aff7845 | 400 | } |
ba975b2e | 401 | |
6aff7845 AD |
402 | function printRuleName() { |
403 | print $this->getRuleName(json_decode($_REQUEST["rule"], true)); | |
404 | } | |
8e17d663 | 405 | |
6aff7845 AD |
406 | private function getActionName($action) { |
407 | $result = db_query($this->link, "SELECT description FROM | |
408 | ttrss_filter_actions WHERE id = " .(int)$action["action_id"]); | |
8e17d663 | 409 | |
6aff7845 | 410 | $title = __(db_fetch_result($result, 0, "description")); |
8e17d663 | 411 | |
6aff7845 AD |
412 | if ($action["action_id"] == 4 || $action["action_id"] == 6 || |
413 | $action["action_id"] == 7) | |
414 | $title .= ": " . $action["action_param"]; | |
8e17d663 | 415 | |
6aff7845 AD |
416 | return $title; |
417 | } | |
8e17d663 | 418 | |
6aff7845 AD |
419 | function printActionName() { |
420 | print $this->getActionName(json_decode($_REQUEST["action"], true)); | |
421 | } | |
422 | ||
423 | function editSave() { | |
4e02f582 AD |
424 | if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") { |
425 | return $this->testFilter(); | |
426 | } | |
6aff7845 AD |
427 | |
428 | # print_r($_REQUEST); | |
429 | ||
3972bf59 AD |
430 | $filter_id = db_escape_string($this->link, $_REQUEST["id"]); |
431 | $enabled = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["enabled"])); | |
432 | $match_any_rule = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["match_any_rule"])); | |
a3a896a1 | 433 | $inverse = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["inverse"])); |
18ad09af | 434 | $title = db_escape_string($this->link, $_REQUEST["title"]); |
6aff7845 AD |
435 | |
436 | $result = db_query($this->link, "UPDATE ttrss_filters2 SET enabled = $enabled, | |
a3a896a1 | 437 | match_any_rule = $match_any_rule, |
18ad09af AD |
438 | inverse = $inverse, |
439 | title = '$title' | |
6aff7845 AD |
440 | WHERE id = '$filter_id' |
441 | AND owner_uid = ". $_SESSION["uid"]); | |
442 | ||
443 | $this->saveRulesAndActions($filter_id); | |
8e17d663 | 444 | |
8e17d663 AD |
445 | } |
446 | ||
447 | function remove() { | |
448 | ||
3972bf59 | 449 | $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"])); |
8e17d663 AD |
450 | |
451 | foreach ($ids as $id) { | |
6aff7845 | 452 | db_query($this->link, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); |
8e17d663 AD |
453 | } |
454 | } | |
455 | ||
6aff7845 | 456 | private function saveRulesAndActions($filter_id) { |
8e17d663 | 457 | |
6aff7845 AD |
458 | db_query($this->link, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'"); |
459 | db_query($this->link, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'"); | |
8e17d663 | 460 | |
6aff7845 AD |
461 | if ($filter_id) { |
462 | /* create rules */ | |
8e17d663 | 463 | |
6aff7845 AD |
464 | $rules = array(); |
465 | $actions = array(); | |
8e17d663 | 466 | |
6aff7845 AD |
467 | foreach ($_REQUEST["rule"] as $rule) { |
468 | $rule = json_decode($rule, true); | |
469 | unset($rule["id"]); | |
8e17d663 | 470 | |
6aff7845 AD |
471 | if (array_search($rule, $rules) === false) { |
472 | array_push($rules, $rule); | |
473 | } | |
474 | } | |
4c9d0490 | 475 | |
6aff7845 AD |
476 | foreach ($_REQUEST["action"] as $action) { |
477 | $action = json_decode($action, true); | |
478 | unset($action["id"]); | |
ba975b2e | 479 | |
6aff7845 AD |
480 | if (array_search($action, $actions) === false) { |
481 | array_push($actions, $action); | |
482 | } | |
483 | } | |
8e17d663 | 484 | |
6aff7845 AD |
485 | foreach ($rules as $rule) { |
486 | if ($rule) { | |
8e17d663 | 487 | |
3972bf59 | 488 | $reg_exp = strip_tags(db_escape_string($this->link, trim($rule["reg_exp"]))); |
a3a896a1 AD |
489 | $inverse = isset($rule["inverse"]) ? "true" : "false"; |
490 | ||
3972bf59 AD |
491 | $filter_type = (int) db_escape_string($this->link, trim($rule["filter_type"])); |
492 | $feed_id = db_escape_string($this->link, trim($rule["feed_id"])); | |
6aff7845 AD |
493 | |
494 | if (strpos($feed_id, "CAT:") === 0) { | |
5451903c | 495 | |
6aff7845 AD |
496 | $cat_filter = bool_to_sql_bool(true); |
497 | $cat_id = (int) substr($feed_id, 4); | |
498 | $feed_id = "NULL"; | |
8e17d663 | 499 | |
6aff7845 AD |
500 | if (!$cat_id) $cat_id = "NULL"; // Uncategorized |
501 | } else { | |
502 | $cat_filter = bool_to_sql_bool(false); | |
503 | $feed_id = (int) $feed_id; | |
504 | $cat_id = "NULL"; | |
505 | ||
506 | if (!$feed_id) $feed_id = "NULL"; // Uncategorized | |
507 | } | |
508 | ||
509 | $query = "INSERT INTO ttrss_filters2_rules | |
a3a896a1 AD |
510 | (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES |
511 | ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)"; | |
6aff7845 AD |
512 | |
513 | db_query($this->link, $query); | |
514 | } | |
8e17d663 AD |
515 | } |
516 | ||
6aff7845 AD |
517 | foreach ($actions as $action) { |
518 | if ($action) { | |
519 | ||
3972bf59 AD |
520 | $action_id = (int) db_escape_string($this->link, $action["action_id"]); |
521 | $action_param = db_escape_string($this->link, $action["action_param"]); | |
522 | $action_param_label = db_escape_string($this->link, $action["action_param_label"]); | |
6aff7845 AD |
523 | |
524 | if ($action_id == 7) { | |
525 | $action_param = $action_param_label; | |
526 | } | |
8e17d663 | 527 | |
6aff7845 AD |
528 | if ($action_id == 6) { |
529 | $action_param = (int) str_replace("+", "", $action_param); | |
530 | } | |
8e17d663 | 531 | |
6aff7845 AD |
532 | $query = "INSERT INTO ttrss_filters2_actions |
533 | (filter_id, action_id, action_param) VALUES | |
534 | ('$filter_id', '$action_id', '$action_param')"; | |
8e17d663 | 535 | |
6aff7845 AD |
536 | db_query($this->link, $query); |
537 | } | |
538 | } | |
8e17d663 | 539 | } |
6aff7845 AD |
540 | |
541 | ||
542 | } | |
543 | ||
544 | function add() { | |
4e02f582 AD |
545 | if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") { |
546 | return $this->testFilter(); | |
547 | } | |
548 | ||
6aff7845 AD |
549 | # print_r($_REQUEST); |
550 | ||
551 | $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]); | |
552 | $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]); | |
18ad09af | 553 | $title = db_escape_string($this->link, $_REQUEST["title"]); |
6aff7845 AD |
554 | |
555 | db_query($this->link, "BEGIN"); | |
556 | ||
557 | /* create base filter */ | |
558 | ||
559 | $result = db_query($this->link, "INSERT INTO ttrss_filters2 | |
18ad09af AD |
560 | (owner_uid, match_any_rule, enabled, title) VALUES |
561 | (".$_SESSION["uid"].",$match_any_rule,$enabled, '$title')"); | |
6aff7845 AD |
562 | |
563 | $result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2 | |
564 | WHERE owner_uid = ".$_SESSION["uid"]); | |
565 | ||
566 | $filter_id = db_fetch_result($result, 0, "id"); | |
567 | ||
568 | $this->saveRulesAndActions($filter_id); | |
569 | ||
570 | db_query($this->link, "COMMIT"); | |
8e17d663 AD |
571 | } |
572 | ||
573 | function index() { | |
574 | ||
3972bf59 | 575 | $sort = db_escape_string($this->link, $_REQUEST["sort"]); |
8e17d663 AD |
576 | |
577 | if (!$sort || $sort == "undefined") { | |
578 | $sort = "reg_exp"; | |
579 | } | |
580 | ||
3972bf59 | 581 | $filter_search = db_escape_string($this->link, $_REQUEST["search"]); |
8e17d663 AD |
582 | |
583 | if (array_key_exists("search", $_REQUEST)) { | |
584 | $_SESSION["prefs_filter_search"] = $filter_search; | |
585 | } else { | |
586 | $filter_search = $_SESSION["prefs_filter_search"]; | |
587 | } | |
588 | ||
589 | print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; | |
590 | print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
591 | print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
592 | ||
3972bf59 | 593 | $filter_search = db_escape_string($this->link, $_REQUEST["search"]); |
310fa2dd AD |
594 | |
595 | if (array_key_exists("search", $_REQUEST)) { | |
596 | $_SESSION["prefs_filter_search"] = $filter_search; | |
597 | } else { | |
598 | $filter_search = $_SESSION["prefs_filter_search"]; | |
599 | } | |
600 | ||
601 | print "<div style='float : right; padding-right : 4px;'> | |
602 | <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\" | |
603 | value=\"$filter_search\"> | |
604 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">". | |
605 | __('Search')."</button> | |
606 | </div>"; | |
607 | ||
8e17d663 AD |
608 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
609 | "<span>" . __('Select')."</span>"; | |
610 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
611 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\" | |
612 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
613 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\" | |
614 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
615 | print "</div></div>"; | |
616 | ||
617 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">". | |
618 | __('Create filter')."</button> "; | |
619 | ||
6aff7845 AD |
620 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">". |
621 | __('Combine')."</button> "; | |
622 | ||
8e17d663 AD |
623 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">". |
624 | __('Edit')."</button> "; | |
625 | ||
626 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">". | |
627 | __('Remove')."</button> "; | |
628 | ||
629 | if (defined('_ENABLE_FEED_DEBUGGING')) { | |
630 | print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">". | |
631 | __('Rescore articles')."</button> "; | |
632 | } | |
633 | ||
634 | print "</div>"; # toolbar | |
635 | print "</div>"; # toolbar-frame | |
636 | print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
637 | ||
638 | print "<div id=\"filterlistLoading\"> | |
639 | <img src='images/indicator_tiny.gif'>". | |
640 | __("Loading, please wait...")."</div>"; | |
641 | ||
642 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\" | |
643 | url=\"backend.php?op=pref-filters&method=getfiltertree\"> | |
644 | </div> | |
645 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\" | |
646 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
647 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
648 | </div> | |
649 | <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\" | |
650 | model=\"filterModel\" openOnClick=\"true\"> | |
651 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
652 | Element.hide(\"filterlistLoading\"); | |
653 | </script> | |
654 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
655 | var id = String(item.id); | |
656 | var bare_id = id.substr(id.indexOf(':')+1); | |
657 | ||
658 | if (id.match('FILTER:')) { | |
659 | editFilter(bare_id); | |
660 | } | |
661 | </script> | |
662 | ||
663 | </div>"; | |
664 | ||
665 | print "</div>"; #pane | |
6065f3ad AD |
666 | |
667 | global $pluginhost; | |
668 | $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, | |
669 | "hook_prefs_tab", "prefFilters"); | |
670 | ||
8e17d663 AD |
671 | print "</div>"; #container |
672 | ||
673 | } | |
6aff7845 AD |
674 | |
675 | function newfilter() { | |
676 | ||
677 | print "<form name='filter_new_form' id='filter_new_form'>"; | |
678 | ||
6aff7845 AD |
679 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">"; |
680 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">"; | |
681 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">"; | |
682 | ||
18ad09af AD |
683 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; |
684 | ||
685 | print "<input dojoType=\"dijit.form.TextBox\" style=\"width : 20em;\" name=\"title\" value=\"\">"; | |
686 | ||
6aff7845 AD |
687 | print "<div class=\"dlgSec\">".__("Match")."</div>"; |
688 | ||
689 | print "<div dojoType=\"dijit.Toolbar\">"; | |
690 | ||
691 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
692 | "<span>" . __('Select')."</span>"; | |
693 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
694 | print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\" | |
695 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
696 | print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\" | |
697 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
698 | print "</div></div>"; | |
699 | ||
700 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">". | |
701 | __('Add')."</button> "; | |
702 | ||
703 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">". | |
704 | __('Delete')."</button> "; | |
705 | ||
706 | print "</div>"; | |
707 | ||
708 | print "<ul id='filterDlg_Matches'>"; | |
709 | # print "<li>No rules</li>"; | |
710 | print "</ul>"; | |
711 | ||
712 | print "</div>"; | |
713 | ||
714 | print "<div class=\"dlgSec\">".__("Apply actions")."</div>"; | |
715 | ||
716 | print "<div dojoType=\"dijit.Toolbar\">"; | |
717 | ||
718 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
719 | "<span>" . __('Select')."</span>"; | |
720 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
721 | print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\" | |
722 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
723 | print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\" | |
724 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
725 | print "</div></div>"; | |
726 | ||
727 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">". | |
728 | __('Add')."</button> "; | |
729 | ||
730 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">". | |
731 | __('Delete')."</button> "; | |
732 | ||
733 | print "</div>"; | |
734 | ||
735 | print "<ul id='filterDlg_Actions'>"; | |
736 | # print "<li>No actions</li>"; | |
737 | print "</ul>"; | |
738 | ||
739 | /* print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
740 | print "<div class=\"dlgSecCont\">"; */ | |
741 | ||
742 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\"> | |
743 | <label for=\"enabled\">".__('Enabled')."</label>"; | |
744 | ||
745 | print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\"> | |
746 | <label for=\"match_any_rule\">".__('Match any rule')."</label>"; | |
747 | ||
a3a896a1 AD |
748 | print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\"> |
749 | <label for=\"inverse\">".__('Inverse matching')."</label>"; | |
6aff7845 AD |
750 | |
751 | // print "</div>"; | |
752 | ||
753 | print "<div class=\"dlgButtons\">"; | |
754 | ||
4e02f582 AD |
755 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">". |
756 | __('Test')."</button> "; | |
6aff7845 AD |
757 | |
758 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". | |
759 | __('Create')."</button> "; | |
760 | ||
761 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". | |
762 | __('Cancel')."</button>"; | |
763 | ||
764 | print "</div>"; | |
765 | ||
766 | } | |
767 | ||
768 | function newrule() { | |
769 | $rule = json_decode($_REQUEST["rule"], true); | |
770 | ||
771 | if ($rule) { | |
772 | $reg_exp = htmlspecialchars($rule["reg_exp"]); | |
773 | $filter_type = $rule["filter_type"]; | |
774 | $feed_id = $rule["feed_id"]; | |
a3a896a1 | 775 | $inverse_checked = isset($rule["inverse"]) ? "checked" : ""; |
6aff7845 AD |
776 | } else { |
777 | $reg_exp = ""; | |
778 | $filter_type = 1; | |
779 | $feed_id = 0; | |
a3a896a1 | 780 | $inverse_checked = ""; |
6aff7845 AD |
781 | } |
782 | ||
783 | if (strpos($feed_id, "CAT:") === 0) { | |
784 | $feed_id = substr($feed_id, 4); | |
785 | $cat_filter = true; | |
786 | } else { | |
787 | $cat_filter = false; | |
788 | } | |
789 | ||
790 | ||
791 | print "<form name='filter_new_rule_form' id='filter_new_rule_form'>"; | |
792 | ||
793 | $result = db_query($this->link, "SELECT id,description | |
37f78940 | 794 | FROM ttrss_filter_types WHERE id != 5 ORDER BY description"); |
6aff7845 AD |
795 | |
796 | $filter_types = array(); | |
797 | ||
798 | while ($line = db_fetch_assoc($result)) { | |
799 | $filter_types[$line["id"]] = __($line["description"]); | |
800 | } | |
801 | ||
802 | print "<div class=\"dlgSec\">".__("Match")."</div>"; | |
803 | ||
804 | print "<div class=\"dlgSecCont\">"; | |
805 | ||
806 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
807 | required=\"true\" id=\"filterDlg_regExp\" | |
ff34bac2 | 808 | style=\"font-size : 16px; width : 20em;\" |
6aff7845 AD |
809 | name=\"reg_exp\" value=\"$reg_exp\"/>"; |
810 | ||
ec1f8a3d AD |
811 | print "<hr/>"; |
812 | print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\" | |
813 | name=\"inverse\" $inverse_checked/>"; | |
814 | print "<label for=\"filterDlg_inverse\">".__("Inverse regular expression matching")."</label>"; | |
815 | ||
6aff7845 AD |
816 | print "<hr/>" . __("on field") . " "; |
817 | print_select_hash("filter_type", $filter_type, $filter_types, | |
818 | 'dojoType="dijit.form.Select"'); | |
819 | ||
820 | print "<hr/>"; | |
821 | ||
822 | print __("in") . " "; | |
823 | ||
824 | print "<span id='filterDlg_feeds'>"; | |
825 | print_feed_select($this->link, "feed_id", | |
826 | $cat_filter ? "CAT:$feed_id" : $feed_id, | |
827 | 'dojoType="dijit.form.FilteringSelect"'); | |
828 | print "</span>"; | |
829 | ||
830 | print "</div>"; | |
831 | ||
832 | print "<div class=\"dlgButtons\">"; | |
833 | ||
834 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">". | |
835 | ($rule ? __("Save rule") : __('Add rule'))."</button> "; | |
836 | ||
837 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">". | |
838 | __('Cancel')."</button>"; | |
839 | ||
840 | print "</div>"; | |
841 | ||
842 | print "</form>"; | |
843 | } | |
844 | ||
845 | function newaction() { | |
846 | $action = json_decode($_REQUEST["action"], true); | |
847 | ||
848 | if ($action) { | |
3972bf59 | 849 | $action_param = db_escape_string($this->link, $action["action_param"]); |
6aff7845 AD |
850 | $action_id = (int)$action["action_id"]; |
851 | } else { | |
852 | $action_param = ""; | |
853 | $action_id = 0; | |
854 | } | |
855 | ||
856 | print "<form name='filter_new_action_form' id='filter_new_action_form'>"; | |
857 | ||
858 | print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; | |
859 | ||
860 | print "<div class=\"dlgSecCont\">"; | |
861 | ||
862 | print "<select name=\"action_id\" dojoType=\"dijit.form.Select\" | |
863 | onchange=\"filterDlgCheckAction(this)\">"; | |
864 | ||
865 | $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions | |
866 | ORDER BY name"); | |
867 | ||
868 | while ($line = db_fetch_assoc($result)) { | |
869 | $is_selected = ($line["id"] == $action_id) ? "selected='1'" : ""; | |
870 | printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"])); | |
871 | } | |
872 | ||
873 | print "</select>"; | |
874 | ||
875 | $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6) ? | |
876 | "" : "display : none"; | |
877 | ||
878 | $param_hidden = ($action_id == 4 || $action_id == 6) ? | |
879 | "" : "display : none"; | |
880 | ||
881 | $label_param_hidden = ($action_id == 7) ? "" : "display : none"; | |
882 | ||
883 | print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">"; | |
884 | print " " . __("with parameters:") . " "; | |
885 | print "<input dojoType=\"dijit.form.TextBox\" | |
886 | id=\"filterDlg_actionParam\" style=\"$param_hidden\" | |
887 | name=\"action_param\" value=\"$action_param\">"; | |
888 | ||
889 | print_label_select($this->link, "action_param_label", $action_param, | |
890 | "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\" | |
891 | dojoType=\"dijit.form.Select\""); | |
892 | ||
893 | print "</span>"; | |
894 | ||
895 | print " "; // tiny layout hack | |
896 | ||
897 | print "</div>"; | |
898 | ||
899 | print "<div class=\"dlgButtons\">"; | |
900 | ||
901 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">". | |
902 | ($action ? __("Save action") : __('Add action'))."</button> "; | |
903 | ||
904 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">". | |
905 | __('Cancel')."</button>"; | |
906 | ||
907 | print "</div>"; | |
908 | ||
909 | print "</form>"; | |
910 | } | |
911 | ||
912 | private function getFilterName($id) { | |
18ad09af AD |
913 | |
914 | $result = db_query($this->link, | |
915 | "SELECT title FROM ttrss_filters2 WHERE id = '$id'"); | |
916 | ||
917 | $title = db_fetch_result($result, 0, "title"); | |
918 | ||
da46d21e | 919 | if (!$title) { |
18ad09af | 920 | |
da46d21e AD |
921 | $result = db_query($this->link, |
922 | "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id | |
923 | LIMIT 3"); | |
6aff7845 | 924 | |
da46d21e AD |
925 | $titles = array(); |
926 | $count = 0; | |
6aff7845 | 927 | |
da46d21e | 928 | while ($line = db_fetch_assoc($result)) { |
6aff7845 | 929 | |
da46d21e AD |
930 | if (sql_bool_to_bool($line["cat_filter"])) { |
931 | unset($line["cat_filter"]); | |
932 | $line["feed_id"] = "CAT:" . (int)$line["cat_id"]; | |
933 | unset($line["cat_id"]); | |
934 | } | |
6aff7845 | 935 | |
da46d21e | 936 | if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]); |
bcd4d240 | 937 | |
da46d21e AD |
938 | if ($count < 2) { |
939 | array_push($titles, $this->getRuleName($line)); | |
940 | } else { | |
941 | array_push($titles, "..."); | |
942 | break; | |
943 | } | |
944 | ++$count; | |
6aff7845 | 945 | } |
da46d21e AD |
946 | |
947 | $title = truncate_string(join(", ", $titles), 64, "..."); | |
948 | ||
6aff7845 AD |
949 | } |
950 | ||
951 | $result = db_query($this->link, | |
952 | "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3"); | |
953 | ||
954 | $actions = array(); | |
955 | $count = 0; | |
956 | ||
957 | while ($line = db_fetch_assoc($result)) { | |
958 | if ($count < 2) { | |
959 | array_push($actions, $this->getActionName($line)); | |
960 | } else { | |
961 | array_push($actions, "..."); | |
962 | break; | |
963 | } | |
964 | ++$count; | |
965 | } | |
966 | ||
da46d21e | 967 | return array($title, join(", ", $actions)); |
6aff7845 AD |
968 | } |
969 | ||
970 | function join() { | |
3972bf59 | 971 | $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); |
6aff7845 AD |
972 | |
973 | if (count($ids) > 1) { | |
974 | $base_id = array_shift($ids); | |
975 | $ids_str = join(",", $ids); | |
976 | ||
977 | db_query($this->link, "BEGIN"); | |
978 | db_query($this->link, "UPDATE ttrss_filters2_rules | |
979 | SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)"); | |
980 | db_query($this->link, "UPDATE ttrss_filters2_actions | |
981 | SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)"); | |
982 | ||
983 | db_query($this->link, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)"); | |
984 | db_query($this->link, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'"); | |
985 | ||
986 | db_query($this->link, "COMMIT"); | |
987 | ||
988 | $this->optimizeFilter($base_id); | |
989 | ||
990 | } | |
991 | } | |
992 | ||
993 | private function optimizeFilter($id) { | |
994 | db_query($this->link, "BEGIN"); | |
995 | $result = db_query($this->link, "SELECT * FROM ttrss_filters2_actions | |
996 | WHERE filter_id = '$id'"); | |
997 | ||
998 | $tmp = array(); | |
999 | $dupe_ids = array(); | |
1000 | ||
1001 | while ($line = db_fetch_assoc($result)) { | |
1002 | $id = $line["id"]; | |
1003 | unset($line["id"]); | |
1004 | ||
1005 | if (array_search($line, $tmp) === false) { | |
1006 | array_push($tmp, $line); | |
1007 | } else { | |
1008 | array_push($dupe_ids, $id); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | if (count($dupe_ids) > 0) { | |
1013 | $ids_str = join(",", $dupe_ids); | |
1014 | db_query($this->link, "DELETE FROM ttrss_filters2_actions | |
1015 | WHERE id IN ($ids_str)"); | |
1016 | } | |
1017 | ||
1018 | $result = db_query($this->link, "SELECT * FROM ttrss_filters2_rules | |
1019 | WHERE filter_id = '$id'"); | |
1020 | ||
1021 | $tmp = array(); | |
1022 | $dupe_ids = array(); | |
1023 | ||
1024 | while ($line = db_fetch_assoc($result)) { | |
1025 | $id = $line["id"]; | |
1026 | unset($line["id"]); | |
1027 | ||
1028 | if (array_search($line, $tmp) === false) { | |
1029 | array_push($tmp, $line); | |
1030 | } else { | |
1031 | array_push($dupe_ids, $id); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | if (count($dupe_ids) > 0) { | |
1036 | $ids_str = join(",", $dupe_ids); | |
1037 | db_query($this->link, "DELETE FROM ttrss_filters2_rules | |
1038 | WHERE id IN ($ids_str)"); | |
1039 | } | |
1040 | ||
1041 | db_query($this->link, "COMMIT"); | |
1042 | } | |
8e17d663 AD |
1043 | } |
1044 | ?> |