- $feed_id = "NULL";
- $cat_id = "NULL";
-
- if (!$rule["cat_filter"]) {
- $tmp_result = db_query($this->link, "SELECT id FROM ttrss_feeds
- WHERE title = '".db_escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
- if (db_num_rows($tmp_result) > 0) {
- $feed_id = db_fetch_result($tmp_result, 0, "id");
- }
- } else {
- $tmp_result = db_query($this->link, "SELECT id FROM ttrss_feed_categories
- WHERE title = '".db_escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
-
- if (db_num_rows($tmp_result) > 0) {
- $cat_id = db_fetch_result($tmp_result, 0, "id");
- }
- }
-
- $cat_filter = bool_to_sql_bool($rule["cat_filter"]);
- $reg_exp = db_escape_string($rule["reg_exp"]);
- $filter_type = (int)$rule["filter_type"];
-
- db_query($this->link, "INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter)
- VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter)");
+ $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]);
+ }