filters.php 37 KB

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