classes/opml: fix indentation; when importing, don't produce warning

on filters with no rules defined.
This commit is contained in:
Andrew Dolgov 2021-09-08 08:11:51 +03:00
parent 012a9fdee3
commit 78ff7770d1
1 changed files with 79 additions and 79 deletions

View File

@ -204,36 +204,36 @@ class OPML extends Handler_Protected {
$cat_filter = $tmp_line["cat_filter"]; $cat_filter = $tmp_line["cat_filter"];
if (!$tmp_line["match_on"]) { if (!$tmp_line["match_on"]) {
if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) { if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
$tmp_line["feed"] = Feeds::_get_title( $tmp_line["feed"] = Feeds::_get_title(
$cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"], $cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
$cat_filter); $cat_filter);
} else { } else {
$tmp_line["feed"] = ""; $tmp_line["feed"] = "";
} }
} else { } else {
$match = []; $match = [];
foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { foreach (json_decode($tmp_line["match_on"], true) as $feed_id) {
if (strpos($feed_id, "CAT:") === 0) { if (strpos($feed_id, "CAT:") === 0) {
$feed_id = (int)substr($feed_id, 4); $feed_id = (int)substr($feed_id, 4);
if ($feed_id) { if ($feed_id) {
array_push($match, [Feeds::_get_cat_title($feed_id), true, false]); array_push($match, [Feeds::_get_cat_title($feed_id), true, false]);
} else { } else {
array_push($match, [0, true, true]); array_push($match, [0, true, true]);
} }
} else { } else {
if ($feed_id) { if ($feed_id) {
array_push($match, [Feeds::_get_title((int)$feed_id), false, false]); array_push($match, [Feeds::_get_title((int)$feed_id), false, false]);
} else { } else {
array_push($match, [0, false, true]); array_push($match, [0, false, true]);
} }
} }
} }
$tmp_line["match"] = $match; $tmp_line["match"] = $match;
unset($tmp_line["match_on"]); unset($tmp_line["match_on"]);
} }
unset($tmp_line["feed_id"]); unset($tmp_line["feed_id"]);
unset($tmp_line["cat_id"]); unset($tmp_line["cat_id"]);
@ -409,31 +409,31 @@ class OPML extends Handler_Protected {
$feed_id = null; $feed_id = null;
$cat_id = null; $cat_id = null;
if ($rule["match"]) { if ($rule["match"] ?? false) {
$match_on = []; $match_on = [];
foreach ($rule["match"] as $match) { foreach ($rule["match"] as $match) {
list ($name, $is_cat, $is_id) = $match; list ($name, $is_cat, $is_id) = $match;
if ($is_id) { if ($is_id) {
array_push($match_on, ($is_cat ? "CAT:" : "") . $name); array_push($match_on, ($is_cat ? "CAT:" : "") . $name);
} else { } else {
if (!$is_cat) { if (!$is_cat) {
$tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
WHERE title = ? AND owner_uid = ?"); WHERE title = ? AND owner_uid = ?");
$tsth->execute([$name, $_SESSION['uid']]); $tsth->execute([$name, $_SESSION['uid']]);
if ($row = $tsth->fetch()) { if ($row = $tsth->fetch()) {
$match_id = $row['id']; $match_id = $row['id'];
array_push($match_on, $match_id); array_push($match_on, $match_id);
} }
} else { } else {
$tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
WHERE title = ? AND owner_uid = ?"); WHERE title = ? AND owner_uid = ?");
$tsth->execute([$name, $_SESSION['uid']]); $tsth->execute([$name, $_SESSION['uid']]);
if ($row = $tsth->fetch()) { if ($row = $tsth->fetch()) {
@ -441,54 +441,54 @@ class OPML extends Handler_Protected {
array_push($match_on, "CAT:$match_id"); array_push($match_on, "CAT:$match_id");
} }
} }
} }
} }
$reg_exp = $rule["reg_exp"]; $reg_exp = $rule["reg_exp"];
$filter_type = (int)$rule["filter_type"]; $filter_type = (int)$rule["filter_type"];
$inverse = bool_to_sql_bool($rule["inverse"]); $inverse = bool_to_sql_bool($rule["inverse"]);
$match_on = json_encode($match_on); $match_on = json_encode($match_on);
$usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules $usth = $this->pdo->prepare("INSERT INTO ttrss_filters2_rules
(feed_id,cat_id,match_on,filter_id,filter_type,reg_exp,cat_filter,inverse) (feed_id,cat_id,match_on,filter_id,filter_type,reg_exp,cat_filter,inverse)
VALUES VALUES
(NULL, NULL, ?, ?, ?, ?, false, ?)"); (NULL, NULL, ?, ?, ?, ?, false, ?)");
$usth->execute([$match_on, $filter_id, $filter_type, $reg_exp, $inverse]); $usth->execute([$match_on, $filter_id, $filter_type, $reg_exp, $inverse]);
} else { } else {
if (!$rule["cat_filter"]) { if (!$rule["cat_filter"]) {
$tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds $tsth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
WHERE title = ? AND owner_uid = ?"); 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']]); $tsth->execute([$rule['feed'], $_SESSION['uid']]);
if ($row = $tsth->fetch()) { if ($row = $tsth->fetch()) {
$feed_id = $row['id']; $feed_id = $row['id'];
} }
} } else {
$tsth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories
WHERE title = ? AND owner_uid = ?");
$cat_filter = bool_to_sql_bool($rule["cat_filter"]); $tsth->execute([$rule['feed'], $_SESSION['uid']]);
$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 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) (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter,inverse)
VALUES VALUES
(?, ?, ?, ?, ?, ?, ?)"); (?, ?, ?, ?, ?, ?, ?)");
$usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]); $usth->execute([$feed_id, $cat_id, $filter_id, $filter_type, $reg_exp, $cat_filter, $inverse]);
} }
} }
foreach ($filter["actions"] as $action) { foreach ($filter["actions"] as $action) {