summaryrefslogtreecommitdiff
path: root/classes/article.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/article.php')
-rwxr-xr-xclasses/article.php118
1 files changed, 50 insertions, 68 deletions
diff --git a/classes/article.php b/classes/article.php
index d8ae97257..04855ac9d 100755
--- a/classes/article.php
+++ b/classes/article.php
@@ -5,26 +5,23 @@ class Article extends Handler_Protected {
const ARTICLE_KIND_YOUTUBE = 3;
function redirect() {
- $id = (int) clean($_REQUEST['id'] ?? 0);
-
- $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries
- WHERE id = ? AND id = ref_id AND owner_uid = ?
- LIMIT 1");
- $sth->execute([$id, $_SESSION['uid']]);
+ $article = ORM::for_table('ttrss_entries')
+ ->table_alias('e')
+ ->join('ttrss_user_entries', [ 'ref_id', '=', 'e.id'], 'ue')
+ ->where('ue.owner_uid', $_SESSION['uid'])
+ ->find_one((int)$_REQUEST['id']);
- if ($row = $sth->fetch()) {
- $article_url = UrlHelper::validate(str_replace("\n", "", $row['link']));
+ if ($article) {
+ $article_url = UrlHelper::validate($article->link);
if ($article_url) {
header("Location: $article_url");
- } else {
- header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
- print "URL of article $id is blank.";
+ return;
}
-
- } else {
- print_error(__("Article not found."));
}
+
+ header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
+ print "Article not found or has an empty URL.";
}
static function _create_published_article($title, $url, $content, $labels_str,
@@ -182,19 +179,6 @@ class Article extends Handler_Protected {
print json_encode(["id" => $ids, "score" => $score]);
}
- function getScore() {
- $id = clean($_REQUEST['id']);
-
- $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?");
- $sth->execute([$id, $_SESSION['uid']]);
- $row = $sth->fetch();
-
- $score = $row['score'];
-
- print json_encode(["id" => $id, "score" => (int)$score]);
- }
-
-
function setArticleTags() {
$id = clean($_REQUEST["id"]);
@@ -433,42 +417,39 @@ class Article extends Handler_Protected {
}
function getmetadatabyid() {
- $id = clean($_REQUEST['id']);
-
- $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
- WHERE ref_id = ? AND ref_id = id AND owner_uid = ?");
- $sth->execute([$id, $_SESSION['uid']]);
+ $article = ORM::for_table('ttrss_entries')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where('ue.owner_uid', $_SESSION['uid'])
+ ->find_one((int)$_REQUEST['id']);
- if ($row = $sth->fetch()) {
- $link = $row['link'];
- $title = $row['title'];
-
- echo json_encode(["link" => $link, "title" => $title]);
+ if ($article) {
+ echo json_encode(["link" => $article->link, "title" => $article->title]);
+ } else {
+ echo json_encode([]);
}
}
static function _get_enclosures($id) {
+ $encs = ORM::for_table('ttrss_enclosures')
+ ->where('post_id', $id)
+ ->find_many();
- $pdo = Db::pdo();
-
- $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures
- WHERE post_id = ? AND content_url != ''");
- $sth->execute([$id]);
-
- $rv = array();
+ $rv = [];
$cache = new DiskCache("images");
- while ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($encs as $enc) {
+ $cache_key = sha1($enc->content_url);
- if ($cache->exists(sha1($line["content_url"]))) {
- $line["content_url"] = $cache->get_url(sha1($line["content_url"]));
+ if ($cache->exists($cache_key)) {
+ $enc->content_url = $cache->get_url($cache_key);
}
- array_push($rv, $line);
+ array_push($rv, $enc->as_array());
}
return $rv;
+
}
static function _purge_orphans() {
@@ -562,17 +543,20 @@ class Article extends Handler_Protected {
return $rv;
}
- static function _get_image($enclosures, $content, $site_url) {
+ static function _get_image(array $enclosures, string $content, string $site_url, array $headline) {
$article_image = "";
$article_stream = "";
$article_kind = 0;
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_ARTICLE_IMAGE,
- function ($result) use (&$article_image, &$article_stream, &$content) {
+ function ($result, $plugin) use (&$article_image, &$article_stream, &$content) {
list ($article_image, $article_stream, $content) = $result;
+
+ // run until first hard match
+ return !empty($article_image);
},
- $enclosures, $content, $site_url);
+ $enclosures, $content, $site_url, $headline);
if (!$article_image && !$article_stream) {
$tmpdoc = new DOMDocument();
@@ -645,17 +629,16 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0)
return [];
- $id_qmarks = arr_qmarks($article_ids);
-
- $sth = Db::pdo()->prepare("SELECT DISTINCT label_cache FROM ttrss_entries e, ttrss_user_entries ue
- WHERE ue.ref_id = e.id AND id IN ($id_qmarks)");
-
- $sth->execute($article_ids);
+ $entries = ORM::for_table('ttrss_entries')
+ ->table_alias('e')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where_in('id', $article_ids)
+ ->find_many();
$rv = [];
- while ($row = $sth->fetch()) {
- $labels = json_decode($row["label_cache"]);
+ foreach ($entries as $entry) {
+ $labels = json_decode($entry->label_cache);
if (isset($labels) && is_array($labels)) {
foreach ($labels as $label) {
@@ -672,19 +655,18 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0)
return [];
- $id_qmarks = arr_qmarks($article_ids);
-
- $sth = Db::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue
- WHERE ue.ref_id = e.id AND id IN ($id_qmarks)");
-
- $sth->execute($article_ids);
+ $entries = ORM::for_table('ttrss_entries')
+ ->table_alias('e')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where_in('id', $article_ids)
+ ->find_many();
$rv = [];
- while ($row = $sth->fetch()) {
- array_push($rv, $row["feed_id"]);
+ foreach ($entries as $entry) {
+ array_push($rv, $entry->feed_id);
}
- return $rv;
+ return array_unique($rv);
}
}