From 1271407eea5e4d98968b701025630c03d66ce5d1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 1 Dec 2017 18:57:34 +0300 Subject: [PATCH] public: partial conversion to PDO, misc fixes --- classes/handler/public.php | 139 ++++++++++++++++++++----------------- include/functions.php | 6 +- 2 files changed, 79 insertions(+), 66 deletions(-) diff --git a/classes/handler/public.php b/classes/handler/public.php index a98ea019..56fe59b7 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -55,9 +55,9 @@ class Handler_Public extends Handler { $result = $qfh_ret[0]; - if ($this->dbh->num_rows($result) != 0) { + if (db_num_rows($result) != 0) { - $ts = strtotime($this->dbh->fetch_result($result, 0, $date_check_field)); + $ts = strtotime(db_fetch_result($result, 0, $date_check_field)); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) { @@ -106,7 +106,7 @@ class Handler_Public extends Handler { $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); - while ($line = $this->dbh->fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); @@ -194,7 +194,7 @@ class Handler_Public extends Handler { $feed['articles'] = array(); - while ($line = $this->dbh->fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); @@ -255,13 +255,14 @@ class Handler_Public extends Handler { } function getUnread() { - $login = $this->dbh->escape_string($_REQUEST["login"]); + $login = $_REQUEST["login"]; $fresh = $_REQUEST["fresh"] == "1"; - $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'"); + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); + $sth->execute([$login]); - if ($this->dbh->num_rows($result) == 1) { - $uid = $this->dbh->fetch_result($result, 0, "id"); + if ($row = $sth->fetch()) { + $uid = $row["id"]; print Feeds::getGlobalUnread($uid); @@ -273,20 +274,20 @@ class Handler_Public extends Handler { } else { print "-1;User not found"; } - } function getProfiles() { - $login = $this->dbh->escape_string($_REQUEST["login"]); + $login = $_REQUEST["login"]; - $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users - WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title"); + $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users + WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title"); + $sth->execute([$login]); print "