feedbrowser: PDO

This commit is contained in:
Andrew Dolgov 2017-12-01 14:56:27 +03:00
parent fdda3e4efb
commit 4ff8bdcb00
1 changed files with 16 additions and 16 deletions

View File

@ -3,34 +3,32 @@
if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return; if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
$owner_uid = $_SESSION["uid"];
$rv = ''; $rv = '';
$pdo = Db::pdo();
if ($search) { if ($search) {
$search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR $search = $pdo->quote($search);
$search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
UPPER(title) LIKE UPPER('%$search%'))"; UPPER(title) LIKE UPPER('%$search%'))";
} else { } else {
$search_qpart = ""; $search_qpart = "";
} }
if ($mode == 1) { if ($mode == 1) {
/* $result = db_query("SELECT feed_url, subscribers FROM $sth = $pdo->prepare("SELECT feed_url, site_url, title, SUM(subscribers) AS subscribers FROM
ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
AND owner_uid = '$owner_uid') $search_qpart
ORDER BY subscribers DESC LIMIT $limit"); */
$result = db_query("SELECT feed_url, site_url, title, SUM(subscribers) AS subscribers FROM
(SELECT feed_url, site_url, title, subscribers FROM ttrss_feedbrowser_cache UNION ALL (SELECT feed_url, site_url, title, subscribers FROM ttrss_feedbrowser_cache UNION ALL
SELECT feed_url, site_url, title, subscribers FROM ttrss_linked_feeds) AS qqq SELECT feed_url, site_url, title, subscribers FROM ttrss_linked_feeds) AS qqq
WHERE WHERE
(SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
WHERE tf.feed_url = qqq.feed_url WHERE tf.feed_url = qqq.feed_url
AND owner_uid = '$owner_uid') $search_qpart AND owner_uid = ?) $search_qpart
GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT $limit"); GROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT ?");
$sth->execute([$_SESSION['uid'], $limit]);
} else if ($mode == 2) { } else if ($mode == 2) {
$result = db_query("SELECT *, $sth = $pdo->prepare("SELECT *,
(SELECT COUNT(*) FROM ttrss_user_entries WHERE (SELECT COUNT(*) FROM ttrss_user_entries WHERE
orig_feed_id = ttrss_archived_feeds.id) AS articles_archived orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
FROM FROM
@ -38,14 +36,16 @@
WHERE WHERE
(SELECT COUNT(*) FROM ttrss_feeds (SELECT COUNT(*) FROM ttrss_feeds
WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
owner_uid = '$owner_uid') = 0 AND owner_uid = :uid) = 0 AND
owner_uid = '$owner_uid' $search_qpart owner_uid = :uid $search_qpart
ORDER BY id DESC LIMIT $limit"); ORDER BY id DESC LIMIT :limit");
$sth->execute([":uid" => $_SESSION['uid'], ":limit" => $limit]);
} }
$feedctr = 0; $feedctr = 0;
while ($line = db_fetch_assoc($result)) { while ($line = $sth->fetch()) {
if ($mode == 1) { if ($mode == 1) {