+ if ($filter_id) {
+ $this->opml_notice(T_sprintf("Adding filter..."));
+
+ foreach ($filter["rules"] as $rule) {
+ $feed_id = null;
+ $cat_id = null;
+
+ if ($rule["match"]) {
+
+ $match_on = [];
+
+ foreach ($rule["match"] as $match) {
+ list ($name, $is_cat, $is_id) = $match;
+
+ if ($is_id) {
+ array_push($match_on, ($is_cat ? "CAT:" : "") . $name);
+ } else {
+
+ $match_id = false;
+
+ if (!$is_cat) {
+ $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
+ WHERE title = ? AND owner_uid = ?");
+
+ $tsth->execute([$name, $_SESSION['uid']]);
+
+ if ($row = $tsth->fetch()) {
+ $match_id = $row['id'];
+ }
+ } else {
+ $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
+ WHERE title = ? AND owner_uid = ?");
+ $tsth->execute([$name, $_SESSION['uid']]);
+
+ if ($row = $tsth->fetch()) {
+ $match_id = $row['id'];
+ }
+ }
+
+ if ($match_id) array_push($match_on, $match_id);
+ }
+ }
+
+ $reg_exp = $rule["reg_exp"];
+ $filter_type = (int)$rule["filter_type"];
+ $inverse = bool_to_sql_bool($rule["inverse"]);
+ $match_on = json_encode($match_on);
+
+ $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
+ (feed_id,cat_id,match_on,filter_id,filter_type,reg_exp,cat_filter,inverse)
+ VALUES
+ (NULL, NULL, ?, ?, ?, ?, false, ?)");
+ $usth->execute([$match_on, $filter_id, $filter_type, $reg_exp, $inverse]);
+
+ } else {
+
+ if (!$rule["cat_filter"]) {
+ $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
+ WHERE title = ? AND owner_uid = ?");
+
+ $tsth->execute([$rule['feed'], $_SESSION['uid']]);
+
+ if ($row = $tsth->fetch()) {
+ $feed_id = $row['id'];
+ }
+ } else {
+ $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
+ WHERE title = ? AND owner_uid = ?");
+
+ $tsth->execute([$rule['feed'], $_SESSION['uid']]);
+
+ if ($row = $tsth->fetch()) {
+ $feed_id = $row['id'];
+ }
+ }
+
+ $cat_filter = bool_to_sql_bool($rule["cat_filter"]);
+ $reg_exp = $rule["reg_exp"];
+ $filter_type = (int)$rule["filter_type"];
+ $inverse = bool_to_sql_bool($rule["inverse"]);
+
+ $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
+ (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter,inverse)
+ VALUES
+ (?, ?, ?, ?, ?, ?, ?)");
+ $usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]);
+ }
+ }
+
+ foreach ($filter["actions"] as $action) {
+
+ $action_id = (int)$action["action_id"];
+ $action_param = $action["action_param"];
+
+ $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_actions
+ (filter_id,action_id,action_param)
+ VALUES
+ (?, ?, ?)");
+ $usth->execute([$filter_id, $action_id, $action_param]);
+ }