filters.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. <?php
  2. class Pref_Filters extends Handler_Protected {
  3. function csrf_ignore($method) {
  4. $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
  5. "newaction", "savefilterorder");
  6. return array_search($method, $csrf_ignored) !== false;
  7. }
  8. function filtersortreset() {
  9. $this->dbh->query("UPDATE ttrss_filters2
  10. SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
  11. return;
  12. }
  13. function savefilterorder() {
  14. $data = json_decode($_POST['payload'], true);
  15. #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
  16. #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
  17. if (!is_array($data['items']))
  18. $data['items'] = json_decode($data['items'], true);
  19. $index = 0;
  20. if (is_array($data) && is_array($data['items'])) {
  21. foreach ($data['items'][0]['items'] as $item) {
  22. $filter_id = (int) str_replace("FILTER:", "", $item['_reference']);
  23. if ($filter_id > 0) {
  24. $this->dbh->query("UPDATE ttrss_filters2 SET
  25. order_id = $index WHERE id = '$filter_id' AND
  26. owner_uid = " .$_SESSION["uid"]);
  27. ++$index;
  28. }
  29. }
  30. }
  31. return;
  32. }
  33. function testFilterDo() {
  34. require_once "include/rssfuncs.php";
  35. $offset = (int) db_escape_string($_REQUEST["offset"]);
  36. $limit = (int) db_escape_string($_REQUEST["limit"]);
  37. $filter = array();
  38. $filter["enabled"] = true;
  39. $filter["match_any_rule"] = sql_bool_to_bool(
  40. checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["match_any_rule"])));
  41. $filter["inverse"] = sql_bool_to_bool(
  42. checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"])));
  43. $filter["rules"] = array();
  44. $filter["actions"] = array("dummy-action");
  45. $result = $this->dbh->query("SELECT id,name FROM ttrss_filter_types");
  46. $filter_types = array();
  47. while ($line = $this->dbh->fetch_assoc($result)) {
  48. $filter_types[$line["id"]] = $line["name"];
  49. }
  50. $scope_qparts = array();
  51. $rctr = 0;
  52. foreach ($_REQUEST["rule"] AS $r) {
  53. $rule = json_decode($r, true);
  54. if ($rule && $rctr < 5) {
  55. $rule["type"] = $filter_types[$rule["filter_type"]];
  56. unset($rule["filter_type"]);
  57. if (strpos($rule["feed_id"], "CAT:") === 0) {
  58. $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
  59. unset($rule["feed_id"]);
  60. }
  61. if (isset($rule["feed_id"]) && $rule['feed_id'] > 0) {
  62. array_push($scope_qparts, "feed_id = " . $rule["feed_id"]);
  63. } else if (isset($rule["cat_id"])) {
  64. array_push($scope_qparts, "cat_id = " . $rule["cat_id"]);
  65. } else {
  66. array_push($scope_qparts, "true");
  67. }
  68. array_push($filter["rules"], $rule);
  69. ++$rctr;
  70. } else {
  71. break;
  72. }
  73. }
  74. $glue = $filter['match_any_rule'] ? " OR " : " AND ";
  75. $scope_qpart = join($glue, $scope_qparts);
  76. if (!$scope_qpart) $scope_qpart = "true";
  77. $rv = array();
  78. //while ($found < $limit && $offset < $limit * 1000 && time() - $started < ini_get("max_execution_time") * 0.7) {
  79. $result = db_query("SELECT ttrss_entries.id,
  80. ttrss_entries.title,
  81. ttrss_feeds.id AS feed_id,
  82. ttrss_feeds.title AS feed_title,
  83. ttrss_feed_categories.id AS cat_id,
  84. content,
  85. date_entered,
  86. link,
  87. author,
  88. tag_cache
  89. FROM
  90. ttrss_entries, ttrss_user_entries
  91. LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)
  92. LEFT JOIN ttrss_feed_categories ON (ttrss_feeds.cat_id = ttrss_feed_categories.id)
  93. WHERE
  94. ref_id = ttrss_entries.id AND
  95. ($scope_qpart) AND
  96. ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
  97. ORDER BY date_entered DESC LIMIT $limit OFFSET $offset");
  98. while ($line = db_fetch_assoc($result)) {
  99. $rc = get_article_filters(array($filter), $line['title'], $line['content'], $line['link'],
  100. $line['author'], explode(",", $line['tag_cache']));
  101. if (count($rc) > 0) {
  102. $line["content_preview"] = truncate_string(strip_tags($line["content"]), 200, '&hellip;');
  103. foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
  104. $line = $p->hook_query_headlines($line, 100);
  105. }
  106. $content_preview = $line["content_preview"];
  107. $tmp = "<tr style='margin-top : 5px'>";
  108. #$tmp .= "<td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
  109. # checked=\"1\" disabled=\"1\" type=\"checkbox\"></td>";
  110. $id = $line['id'];
  111. $tmp .= "<td width='5%' align='center'><img style='cursor : pointer' title='".__("Preview article")."'
  112. src='images/information.png' onclick='openArticlePopup($id)'></td><td>";
  113. /*foreach ($filter['rules'] as $rule) {
  114. $reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
  115. $line["title"] = preg_replace("/($reg_exp)/i",
  116. "<span class=\"highlight\">$1</span>", $line["title"]);
  117. $content_preview = preg_replace("/($reg_exp)/i",
  118. "<span class=\"highlight\">$1</span>", $content_preview);
  119. }*/
  120. $tmp .= "<strong>" . $line["title"] . "</strong><br/>";
  121. $tmp .= $line['feed_title'] . ", " . mb_substr($line["date_entered"], 0, 16);
  122. $tmp .= "<div class='insensitive'>" . $content_preview . "</div>";
  123. $tmp .= "</td></tr>";
  124. array_push($rv, $tmp);
  125. /*array_push($rv, array("title" => $line["title"],
  126. "content" => $content_preview,
  127. "date" => $line["date_entered"],
  128. "feed" => $line["feed_title"])); */
  129. }
  130. }
  131. //$offset += $limit;
  132. //}
  133. /*if ($found == 0) {
  134. print "<tr><td align='center'>" .
  135. __("No recent articles matching this filter have been found.");
  136. }*/
  137. print json_encode($rv);
  138. }
  139. function testFilter() {
  140. if (isset($_REQUEST["offset"])) return $this->testFilterDo();
  141. //print __("Articles matching this filter:");
  142. print "<div><img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'>&nbsp;<span id='prefFilterProgressMsg'>Looking for articles...</span></div>";
  143. print "<br/><div class=\"filterTestHolder\">";
  144. print "<table width=\"100%\" cellspacing=\"0\" id=\"prefFilterTestResultList\">";
  145. print "</table></div>";
  146. print "<div style='text-align : center'>";
  147. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
  148. __('Close this window')."</button>";
  149. print "</div>";
  150. }
  151. private function getfilterrules_concise($filter_id) {
  152. $result = $this->dbh->query("SELECT reg_exp,
  153. inverse,
  154. feed_id,
  155. cat_id,
  156. cat_filter,
  157. ttrss_filter_types.description AS field
  158. FROM
  159. ttrss_filters2_rules, ttrss_filter_types
  160. WHERE
  161. filter_id = '$filter_id' AND filter_type = ttrss_filter_types.id
  162. ORDER BY reg_exp");
  163. $rv = "";
  164. while ($line = $this->dbh->fetch_assoc($result)) {
  165. $where = sql_bool_to_bool($line["cat_filter"]) ?
  166. getCategoryTitle($line["cat_id"]) :
  167. ($line["feed_id"] ?
  168. getFeedTitle($line["feed_id"]) : __("All feeds"));
  169. # $where = $line["cat_id"] . "/" . $line["feed_id"];
  170. $inverse = sql_bool_to_bool($line["inverse"]) ? "inverse" : "";
  171. $rv .= "<span class='$inverse'>" . T_sprintf("%s on %s in %s %s",
  172. htmlspecialchars($line["reg_exp"]),
  173. $line["field"],
  174. $where,
  175. sql_bool_to_bool($line["inverse"]) ? __("(inverse)") : "") . "</span>";
  176. }
  177. return $rv;
  178. }
  179. function getfiltertree() {
  180. $root = array();
  181. $root['id'] = 'root';
  182. $root['name'] = __('Filters');
  183. $root['items'] = array();
  184. $filter_search = $_SESSION["prefs_filter_search"];
  185. $result = $this->dbh->query("SELECT *,
  186. (SELECT action_param FROM ttrss_filters2_actions
  187. WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
  188. (SELECT action_id FROM ttrss_filters2_actions
  189. WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
  190. (SELECT description FROM ttrss_filter_actions
  191. WHERE id = (SELECT action_id FROM ttrss_filters2_actions
  192. WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
  193. (SELECT reg_exp FROM ttrss_filters2_rules
  194. WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
  195. FROM ttrss_filters2 WHERE
  196. owner_uid = ".$_SESSION["uid"]." ORDER BY order_id, title");
  197. $folder = array();
  198. $folder['items'] = array();
  199. while ($line = $this->dbh->fetch_assoc($result)) {
  200. $name = $this->getFilterName($line["id"]);
  201. $match_ok = false;
  202. if ($filter_search) {
  203. $rules_result = $this->dbh->query(
  204. "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
  205. while ($rule_line = $this->dbh->fetch_assoc($rules_result)) {
  206. if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
  207. $match_ok = true;
  208. break;
  209. }
  210. }
  211. }
  212. if ($line['action_id'] == 7) {
  213. $label_result = $this->dbh->query("SELECT fg_color, bg_color
  214. FROM ttrss_labels2 WHERE caption = '".$this->dbh->escape_string($line['action_param'])."' AND
  215. owner_uid = " . $_SESSION["uid"]);
  216. if ($this->dbh->num_rows($label_result) > 0) {
  217. $fg_color = $this->dbh->fetch_result($label_result, 0, "fg_color");
  218. $bg_color = $this->dbh->fetch_result($label_result, 0, "bg_color");
  219. $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>&alpha;</span>" . $name[1];
  220. }
  221. }
  222. $filter = array();
  223. $filter['id'] = 'FILTER:' . $line['id'];
  224. $filter['bare_id'] = $line['id'];
  225. $filter['name'] = $name[0];
  226. $filter['param'] = $name[1];
  227. $filter['checkbox'] = false;
  228. $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
  229. $filter['rules'] = $this->getfilterrules_concise($line['id']);
  230. if (!$filter_search || $match_ok) {
  231. array_push($folder['items'], $filter);
  232. }
  233. }
  234. /* if (count($folder['items']) > 0) {
  235. array_push($root['items'], $folder);
  236. } */
  237. $root['items'] = $folder['items'];
  238. $fl = array();
  239. $fl['identifier'] = 'id';
  240. $fl['label'] = 'name';
  241. $fl['items'] = array($root);
  242. print json_encode($fl);
  243. return;
  244. }
  245. function edit() {
  246. $filter_id = $this->dbh->escape_string($_REQUEST["id"]);
  247. $result = $this->dbh->query(
  248. "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
  249. $enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "enabled"));
  250. $match_any_rule = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "match_any_rule"));
  251. $inverse = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "inverse"));
  252. $title = htmlspecialchars($this->dbh->fetch_result($result, 0, "title"));
  253. print "<form id=\"filter_edit_form\" onsubmit='return false'>";
  254. print_hidden("op", "pref-filters");
  255. print_hidden("id", "$filter_id");
  256. print_hidden("method", "editSave");
  257. print_hidden("csrf_token", $_SESSION['csrf_token']);
  258. print "<div class=\"dlgSec\">".__("Caption")."</div>";
  259. print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">";
  260. print "</div>";
  261. print "<div class=\"dlgSec\">".__("Match")."</div>";
  262. print "<div dojoType=\"dijit.Toolbar\">";
  263. print "<div dojoType=\"dijit.form.DropDownButton\">".
  264. "<span>" . __('Select')."</span>";
  265. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  266. print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
  267. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  268. print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
  269. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  270. print "</div></div>";
  271. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
  272. __('Add')."</button> ";
  273. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
  274. __('Delete')."</button> ";
  275. print "</div>";
  276. print "<ul id='filterDlg_Matches'>";
  277. $rules_result = $this->dbh->query("SELECT * FROM ttrss_filters2_rules
  278. WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
  279. while ($line = $this->dbh->fetch_assoc($rules_result)) {
  280. if (sql_bool_to_bool($line["cat_filter"])) {
  281. $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
  282. }
  283. unset($line["cat_filter"]);
  284. unset($line["cat_id"]);
  285. unset($line["filter_id"]);
  286. unset($line["id"]);
  287. if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
  288. $data = htmlspecialchars(json_encode($line));
  289. print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
  290. "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
  291. "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
  292. }
  293. print "</ul>";
  294. print "</div>";
  295. print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
  296. print "<div dojoType=\"dijit.Toolbar\">";
  297. print "<div dojoType=\"dijit.form.DropDownButton\">".
  298. "<span>" . __('Select')."</span>";
  299. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  300. print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
  301. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  302. print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
  303. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  304. print "</div></div>";
  305. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
  306. __('Add')."</button> ";
  307. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
  308. __('Delete')."</button> ";
  309. print "</div>";
  310. print "<ul id='filterDlg_Actions'>";
  311. $actions_result = $this->dbh->query("SELECT * FROM ttrss_filters2_actions
  312. WHERE filter_id = '$filter_id' ORDER BY id");
  313. while ($line = $this->dbh->fetch_assoc($actions_result)) {
  314. $line["action_param_label"] = $line["action_param"];
  315. unset($line["filter_id"]);
  316. unset($line["id"]);
  317. $data = htmlspecialchars(json_encode($line));
  318. print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
  319. "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
  320. "<input type='hidden' name='action[]' value=\"$data\"/></li>";
  321. }
  322. print "</ul>";
  323. print "</div>";
  324. if ($enabled) {
  325. $checked = "checked=\"1\"";
  326. } else {
  327. $checked = "";
  328. }
  329. print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
  330. <label for=\"enabled\">".__('Enabled')."</label>";
  331. if ($match_any_rule) {
  332. $checked = "checked=\"1\"";
  333. } else {
  334. $checked = "";
  335. }
  336. print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
  337. <label for=\"match_any_rule\">".__('Match any rule')."</label>";
  338. if ($inverse) {
  339. $checked = "checked=\"1\"";
  340. } else {
  341. $checked = "";
  342. }
  343. print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
  344. <label for=\"inverse\">".__('Inverse matching')."</label>";
  345. print "<p/>";
  346. print "<div class=\"dlgButtons\">";
  347. print "<div style=\"float : left\">";
  348. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
  349. __('Remove')."</button>";
  350. print "</div>";
  351. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
  352. __('Test')."</button> ";
  353. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
  354. __('Save')."</button> ";
  355. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
  356. __('Cancel')."</button>";
  357. print "</div>";
  358. }
  359. private function getRuleName($rule) {
  360. if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
  361. $feed_id = $rule["feed_id"];
  362. if (strpos($feed_id, "CAT:") === 0) {
  363. $feed_id = (int) substr($feed_id, 4);
  364. $feed = getCategoryTitle($feed_id);
  365. } else {
  366. $feed_id = (int) $feed_id;
  367. if ($rule["feed_id"])
  368. $feed = getFeedTitle((int)$rule["feed_id"]);
  369. else
  370. $feed = __("All feeds");
  371. }
  372. $result = $this->dbh->query("SELECT description FROM ttrss_filter_types
  373. WHERE id = ".(int)$rule["filter_type"]);
  374. $filter_type = $this->dbh->fetch_result($result, 0, "description");
  375. $inverse = isset($rule["inverse"]) ? "inverse" : "";
  376. return "<span class='filterRule $inverse'>" .
  377. T_sprintf("%s on %s in %s %s", htmlspecialchars($rule["reg_exp"]),
  378. $filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "") . "</span>";
  379. }
  380. function printRuleName() {
  381. print $this->getRuleName(json_decode($_REQUEST["rule"], true));
  382. }
  383. private function getActionName($action) {
  384. $result = $this->dbh->query("SELECT description FROM
  385. ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
  386. $title = __($this->dbh->fetch_result($result, 0, "description"));
  387. if ($action["action_id"] == 4 || $action["action_id"] == 6 ||
  388. $action["action_id"] == 7)
  389. $title .= ": " . $action["action_param"];
  390. if ($action["action_id"] == 9) {
  391. list ($pfclass, $pfaction) = explode(":", $action["action_param"]);
  392. $filter_actions = PluginHost::getInstance()->get_filter_actions();
  393. foreach ($filter_actions as $fclass => $factions) {
  394. foreach ($factions as $faction) {
  395. if ($pfaction == $faction["action"] && $pfclass == $fclass) {
  396. $title .= ": " . $fclass . ": " . $faction["description"];
  397. break;
  398. }
  399. }
  400. }
  401. }
  402. return $title;
  403. }
  404. function printActionName() {
  405. print $this->getActionName(json_decode($_REQUEST["action"], true));
  406. }
  407. function editSave() {
  408. if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
  409. return $this->testFilter();
  410. }
  411. # print_r($_REQUEST);
  412. $filter_id = $this->dbh->escape_string($_REQUEST["id"]);
  413. $enabled = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["enabled"]));
  414. $match_any_rule = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["match_any_rule"]));
  415. $inverse = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"]));
  416. $title = $this->dbh->escape_string($_REQUEST["title"]);
  417. $this->dbh->query("UPDATE ttrss_filters2 SET enabled = $enabled,
  418. match_any_rule = $match_any_rule,
  419. inverse = $inverse,
  420. title = '$title'
  421. WHERE id = '$filter_id'
  422. AND owner_uid = ". $_SESSION["uid"]);
  423. $this->saveRulesAndActions($filter_id);
  424. }
  425. function remove() {
  426. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  427. foreach ($ids as $id) {
  428. $this->dbh->query("DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
  429. }
  430. }
  431. private function saveRulesAndActions($filter_id) {
  432. $this->dbh->query("DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
  433. $this->dbh->query("DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
  434. if ($filter_id) {
  435. /* create rules */
  436. $rules = array();
  437. $actions = array();
  438. foreach ($_REQUEST["rule"] as $rule) {
  439. $rule = json_decode($rule, true);
  440. unset($rule["id"]);
  441. if (array_search($rule, $rules) === false) {
  442. array_push($rules, $rule);
  443. }
  444. }
  445. foreach ($_REQUEST["action"] as $action) {
  446. $action = json_decode($action, true);
  447. unset($action["id"]);
  448. if (array_search($action, $actions) === false) {
  449. array_push($actions, $action);
  450. }
  451. }
  452. foreach ($rules as $rule) {
  453. if ($rule) {
  454. $reg_exp = $this->dbh->escape_string(trim($rule["reg_exp"]), false);
  455. $inverse = isset($rule["inverse"]) ? "true" : "false";
  456. $filter_type = (int) $this->dbh->escape_string(trim($rule["filter_type"]));
  457. $feed_id = $this->dbh->escape_string(trim($rule["feed_id"]));
  458. if (strpos($feed_id, "CAT:") === 0) {
  459. $cat_filter = bool_to_sql_bool(true);
  460. $cat_id = (int) substr($feed_id, 4);
  461. $feed_id = "NULL";
  462. if (!$cat_id) $cat_id = "NULL"; // Uncategorized
  463. } else {
  464. $cat_filter = bool_to_sql_bool(false);
  465. $feed_id = (int) $feed_id;
  466. $cat_id = "NULL";
  467. if (!$feed_id) $feed_id = "NULL"; // Uncategorized
  468. }
  469. $query = "INSERT INTO ttrss_filters2_rules
  470. (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
  471. ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
  472. $this->dbh->query($query);
  473. }
  474. }
  475. foreach ($actions as $action) {
  476. if ($action) {
  477. $action_id = (int) $this->dbh->escape_string($action["action_id"]);
  478. $action_param = $this->dbh->escape_string($action["action_param"]);
  479. $action_param_label = $this->dbh->escape_string($action["action_param_label"]);
  480. if ($action_id == 7) {
  481. $action_param = $action_param_label;
  482. }
  483. if ($action_id == 6) {
  484. $action_param = (int) str_replace("+", "", $action_param);
  485. }
  486. $query = "INSERT INTO ttrss_filters2_actions
  487. (filter_id, action_id, action_param) VALUES
  488. ('$filter_id', '$action_id', '$action_param')";
  489. $this->dbh->query($query);
  490. }
  491. }
  492. }
  493. }
  494. function add() {
  495. if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
  496. return $this->testFilter();
  497. }
  498. # print_r($_REQUEST);
  499. $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
  500. $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
  501. $title = $this->dbh->escape_string($_REQUEST["title"]);
  502. $inverse = checkbox_to_sql_bool($_REQUEST["inverse"]);
  503. $this->dbh->query("BEGIN");
  504. /* create base filter */
  505. $result = $this->dbh->query("INSERT INTO ttrss_filters2
  506. (owner_uid, match_any_rule, enabled, title, inverse) VALUES
  507. (".$_SESSION["uid"].",$match_any_rule,$enabled, '$title', $inverse)");
  508. $result = $this->dbh->query("SELECT MAX(id) AS id FROM ttrss_filters2
  509. WHERE owner_uid = ".$_SESSION["uid"]);
  510. $filter_id = $this->dbh->fetch_result($result, 0, "id");
  511. $this->saveRulesAndActions($filter_id);
  512. $this->dbh->query("COMMIT");
  513. }
  514. function index() {
  515. $sort = $this->dbh->escape_string($_REQUEST["sort"]);
  516. if (!$sort || $sort == "undefined") {
  517. $sort = "reg_exp";
  518. }
  519. $filter_search = $this->dbh->escape_string($_REQUEST["search"]);
  520. if (array_key_exists("search", $_REQUEST)) {
  521. $_SESSION["prefs_filter_search"] = $filter_search;
  522. } else {
  523. $filter_search = $_SESSION["prefs_filter_search"];
  524. }
  525. print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
  526. print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
  527. print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
  528. $filter_search = $this->dbh->escape_string($_REQUEST["search"]);
  529. if (array_key_exists("search", $_REQUEST)) {
  530. $_SESSION["prefs_filter_search"] = $filter_search;
  531. } else {
  532. $filter_search = $_SESSION["prefs_filter_search"];
  533. }
  534. print "<div style='float : right; padding-right : 4px;'>
  535. <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
  536. value=\"$filter_search\">
  537. <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
  538. __('Search')."</button>
  539. </div>";
  540. print "<div dojoType=\"dijit.form.DropDownButton\">".
  541. "<span>" . __('Select')."</span>";
  542. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  543. print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
  544. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  545. print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
  546. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  547. print "</div></div>";
  548. print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
  549. __('Create filter')."</button> ";
  550. print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
  551. __('Combine')."</button> ";
  552. print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
  553. __('Edit')."</button> ";
  554. print "<button dojoType=\"dijit.form.Button\" onclick=\"return resetFilterOrder()\">".
  555. __('Reset sort order')."</button> ";
  556. print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
  557. __('Remove')."</button> ";
  558. if (defined('_ENABLE_FEED_DEBUGGING')) {
  559. print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
  560. __('Rescore articles')."</button> ";
  561. }
  562. print "</div>"; # toolbar
  563. print "</div>"; # toolbar-frame
  564. print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
  565. print "<div id=\"filterlistLoading\">
  566. <img src='images/indicator_tiny.gif'>".
  567. __("Loading, please wait...")."</div>";
  568. print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\"
  569. url=\"backend.php?op=pref-filters&method=getfiltertree\">
  570. </div>
  571. <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
  572. query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Filters\"
  573. childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
  574. </div>
  575. <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
  576. dndController=\"dijit.tree.dndSource\"
  577. betweenThreshold=\"5\"
  578. model=\"filterModel\" openOnClick=\"true\">
  579. <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
  580. Element.hide(\"filterlistLoading\");
  581. </script>
  582. <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
  583. var id = String(item.id);
  584. var bare_id = id.substr(id.indexOf(':')+1);
  585. if (id.match('FILTER:')) {
  586. editFilter(bare_id);
  587. }
  588. </script>
  589. </div>";
  590. print "</div>"; #pane
  591. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
  592. "hook_prefs_tab", "prefFilters");
  593. print "</div>"; #container
  594. }
  595. function newfilter() {
  596. print "<form name='filter_new_form' id='filter_new_form'>";
  597. print_hidden("op", "pref-filters");
  598. print_hidden("method", "add");
  599. print_hidden("csrf_token", $_SESSION['csrf_token']);
  600. print "<div class=\"dlgSec\">".__("Caption")."</div>";
  601. print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"\">";
  602. print "<div class=\"dlgSec\">".__("Match")."</div>";
  603. print "<div dojoType=\"dijit.Toolbar\">";
  604. print "<div dojoType=\"dijit.form.DropDownButton\">".
  605. "<span>" . __('Select')."</span>";
  606. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  607. print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
  608. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  609. print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
  610. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  611. print "</div></div>";
  612. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
  613. __('Add')."</button> ";
  614. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
  615. __('Delete')."</button> ";
  616. print "</div>";
  617. print "<ul id='filterDlg_Matches'>";
  618. # print "<li>No rules</li>";
  619. print "</ul>";
  620. print "</div>";
  621. print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
  622. print "<div dojoType=\"dijit.Toolbar\">";
  623. print "<div dojoType=\"dijit.form.DropDownButton\">".
  624. "<span>" . __('Select')."</span>";
  625. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  626. print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
  627. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  628. print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
  629. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  630. print "</div></div>";
  631. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
  632. __('Add')."</button> ";
  633. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
  634. __('Delete')."</button> ";
  635. print "</div>";
  636. print "<ul id='filterDlg_Actions'>";
  637. # print "<li>No actions</li>";
  638. print "</ul>";
  639. /* print "<div class=\"dlgSec\">".__("Options")."</div>";
  640. print "<div class=\"dlgSecCont\">"; */
  641. print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
  642. <label for=\"enabled\">".__('Enabled')."</label>";
  643. print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
  644. <label for=\"match_any_rule\">".__('Match any rule')."</label>";
  645. print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
  646. <label for=\"inverse\">".__('Inverse matching')."</label>";
  647. // print "</div>";
  648. print "<div class=\"dlgButtons\">";
  649. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
  650. __('Test')."</button> ";
  651. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
  652. __('Create')."</button> ";
  653. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
  654. __('Cancel')."</button>";
  655. print "</div>";
  656. }
  657. function newrule() {
  658. $rule = json_decode($_REQUEST["rule"], true);
  659. if ($rule) {
  660. $reg_exp = htmlspecialchars($rule["reg_exp"]);
  661. $filter_type = $rule["filter_type"];
  662. $feed_id = $rule["feed_id"];
  663. $inverse_checked = isset($rule["inverse"]) ? "checked" : "";
  664. } else {
  665. $reg_exp = "";
  666. $filter_type = 1;
  667. $feed_id = 0;
  668. $inverse_checked = "";
  669. }
  670. if (strpos($feed_id, "CAT:") === 0) {
  671. $feed_id = substr($feed_id, 4);
  672. $cat_filter = true;
  673. } else {
  674. $cat_filter = false;
  675. }
  676. print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
  677. $result = $this->dbh->query("SELECT id,description
  678. FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
  679. $filter_types = array();
  680. while ($line = $this->dbh->fetch_assoc($result)) {
  681. $filter_types[$line["id"]] = __($line["description"]);
  682. }
  683. print "<div class=\"dlgSec\">".__("Match")."</div>";
  684. print "<div class=\"dlgSecCont\">";
  685. print "<input dojoType=\"dijit.form.ValidationTextBox\"
  686. required=\"true\" id=\"filterDlg_regExp\"
  687. style=\"font-size : 16px; width : 20em;\"
  688. name=\"reg_exp\" value=\"$reg_exp\"/>";
  689. print "<hr/>";
  690. print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
  691. name=\"inverse\" $inverse_checked/>";
  692. print "<label for=\"filterDlg_inverse\">".__("Inverse regular expression matching")."</label>";
  693. print "<hr/>" . __("on field") . " ";
  694. print_select_hash("filter_type", $filter_type, $filter_types,
  695. 'dojoType="dijit.form.Select"');
  696. print "<hr/>";
  697. print __("in") . " ";
  698. print "<span id='filterDlg_feeds'>";
  699. print_feed_select("feed_id",
  700. $cat_filter ? "CAT:$feed_id" : $feed_id,
  701. 'dojoType="dijit.form.FilteringSelect"');
  702. print "</span>";
  703. print "</div>";
  704. print "<div class=\"dlgButtons\">";
  705. print "<div style=\"float : left\">
  706. <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/ContentFilters\">".__("Wiki: Filters")."</a>
  707. </div>";
  708. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
  709. ($rule ? __("Save rule") : __('Add rule'))."</button> ";
  710. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
  711. __('Cancel')."</button>";
  712. print "</div>";
  713. print "</form>";
  714. }
  715. function newaction() {
  716. $action = json_decode($_REQUEST["action"], true);
  717. if ($action) {
  718. $action_param = $this->dbh->escape_string($action["action_param"]);
  719. $action_id = (int)$action["action_id"];
  720. } else {
  721. $action_param = "";
  722. $action_id = 0;
  723. }
  724. print "<form name='filter_new_action_form' id='filter_new_action_form'>";
  725. print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
  726. print "<div class=\"dlgSecCont\">";
  727. print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
  728. onchange=\"filterDlgCheckAction(this)\">";
  729. $result = $this->dbh->query("SELECT id,description FROM ttrss_filter_actions
  730. ORDER BY name");
  731. while ($line = $this->dbh->fetch_assoc($result)) {
  732. $is_selected = ($line["id"] == $action_id) ? "selected='1'" : "";
  733. printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
  734. }
  735. print "</select>";
  736. $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ?
  737. "" : "display : none";
  738. $param_hidden = ($action_id == 4 || $action_id == 6) ?
  739. "" : "display : none";
  740. $label_param_hidden = ($action_id == 7) ? "" : "display : none";
  741. $plugin_param_hidden = ($action_id == 9) ? "" : "display : none";
  742. print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
  743. print " ";
  744. //print " " . __("with parameters:") . " ";
  745. print "<input dojoType=\"dijit.form.TextBox\"
  746. id=\"filterDlg_actionParam\" style=\"$param_hidden\"
  747. name=\"action_param\" value=\"$action_param\">";
  748. print_label_select("action_param_label", $action_param,
  749. "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
  750. dojoType=\"dijit.form.Select\"");
  751. $filter_actions = PluginHost::getInstance()->get_filter_actions();
  752. $filter_action_hash = array();
  753. foreach ($filter_actions as $fclass => $factions) {
  754. foreach ($factions as $faction) {
  755. $filter_action_hash[$fclass . ":" . $faction["action"]] =
  756. $fclass . ": " . $faction["description"];
  757. }
  758. }
  759. if (count($filter_action_hash) == 0) {
  760. $filter_plugin_disabled = "disabled";
  761. $filter_action_hash["no-data"] = __("No actions available");
  762. } else {
  763. $filter_plugin_disabled = "";
  764. }
  765. print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash,
  766. "style=\"$plugin_param_hidden\" dojoType=\"dijit.form.Select\" $filter_plugin_disabled",
  767. "action_param_plugin");
  768. print "</span>";
  769. print "&nbsp;"; // tiny layout hack
  770. print "</div>";
  771. print "<div class=\"dlgButtons\">";
  772. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
  773. ($action ? __("Save action") : __('Add action'))."</button> ";
  774. print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
  775. __('Cancel')."</button>";
  776. print "</div>";
  777. print "</form>";
  778. }
  779. private function getFilterName($id) {
  780. $result = $this->dbh->query(
  781. "SELECT title,match_any_rule,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions
  782. FROM ttrss_filters2 AS f LEFT JOIN ttrss_filters2_rules AS r
  783. ON (r.filter_id = f.id)
  784. LEFT JOIN ttrss_filters2_actions AS a
  785. ON (a.filter_id = f.id) WHERE f.id = '$id' GROUP BY f.title, f.match_any_rule");
  786. $title = $this->dbh->fetch_result($result, 0, "title");
  787. $num_rules = $this->dbh->fetch_result($result, 0, "num_rules");
  788. $num_actions = $this->dbh->fetch_result($result, 0, "num_actions");
  789. $match_any_rule = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "match_any_rule"));
  790. if (!$title) $title = __("[No caption]");
  791. $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", (int) $num_rules), $title, $num_rules);
  792. $result = $this->dbh->query(
  793. "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 1");
  794. $actions = "";
  795. if ($this->dbh->num_rows($result) > 0) {
  796. $line = $this->dbh->fetch_assoc($result);
  797. $actions = $this->getActionName($line);
  798. $num_actions -= 1;
  799. }
  800. if ($match_any_rule) $title .= " (" . __("matches any rule") . ")";
  801. if ($num_actions > 0)
  802. $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", (int) $num_actions), $actions, $num_actions);
  803. return array($title, $actions);
  804. }
  805. function join() {
  806. $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
  807. if (count($ids) > 1) {
  808. $base_id = array_shift($ids);
  809. $ids_str = join(",", $ids);
  810. $this->dbh->query("BEGIN");
  811. $this->dbh->query("UPDATE ttrss_filters2_rules
  812. SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
  813. $this->dbh->query("UPDATE ttrss_filters2_actions
  814. SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
  815. $this->dbh->query("DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
  816. $this->dbh->query("UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
  817. $this->dbh->query("COMMIT");
  818. $this->optimizeFilter($base_id);
  819. }
  820. }
  821. private function optimizeFilter($id) {
  822. $this->dbh->query("BEGIN");
  823. $result = $this->dbh->query("SELECT * FROM ttrss_filters2_actions
  824. WHERE filter_id = '$id'");
  825. $tmp = array();
  826. $dupe_ids = array();
  827. while ($line = $this->dbh->fetch_assoc($result)) {
  828. $id = $line["id"];
  829. unset($line["id"]);
  830. if (array_search($line, $tmp) === false) {
  831. array_push($tmp, $line);
  832. } else {
  833. array_push($dupe_ids, $id);
  834. }
  835. }
  836. if (count($dupe_ids) > 0) {
  837. $ids_str = join(",", $dupe_ids);
  838. $this->dbh->query("DELETE FROM ttrss_filters2_actions
  839. WHERE id IN ($ids_str)");
  840. }
  841. $result = $this->dbh->query("SELECT * FROM ttrss_filters2_rules
  842. WHERE filter_id = '$id'");
  843. $tmp = array();
  844. $dupe_ids = array();
  845. while ($line = $this->dbh->fetch_assoc($result)) {
  846. $id = $line["id"];
  847. unset($line["id"]);
  848. if (array_search($line, $tmp) === false) {
  849. array_push($tmp, $line);
  850. } else {
  851. array_push($dupe_ids, $id);
  852. }
  853. }
  854. if (count($dupe_ids) > 0) {
  855. $ids_str = join(",", $dupe_ids);
  856. $this->dbh->query("DELETE FROM ttrss_filters2_rules
  857. WHERE id IN ($ids_str)");
  858. }
  859. $this->dbh->query("COMMIT");
  860. }
  861. }