From 257efb43c6e32226280d8198acc946a2fc4c454f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 15:52:28 +0300 Subject: [PATCH] article: unify naming --- classes/api.php | 14 ++++---- classes/article.php | 69 +++++++++++-------------------------- classes/digest.php | 4 +-- classes/feeditem.php | 2 +- classes/feeditem/atom.php | 4 +-- classes/feeditem/common.php | 2 +- classes/feeditem/rss.php | 4 +-- classes/feeds.php | 10 +++--- classes/handler/public.php | 18 +++++----- classes/labels.php | 2 +- classes/pluginhost.php | 2 +- classes/rpc.php | 6 ++-- classes/rssutils.php | 8 ++--- js/Article.js | 2 +- js/CommonFilters.js | 2 +- plugins/note/init.php | 2 +- 16 files changed, 62 insertions(+), 89 deletions(-) diff --git a/classes/api.php b/classes/api.php index 73e5c221a..4d1c15598 100755 --- a/classes/api.php +++ b/classes/api.php @@ -316,7 +316,7 @@ class API extends Handler { "guid" => $line["guid"], "title" => $line["title"], "link" => $line["link"], - "labels" => Article::get_article_labels($line['id']), + "labels" => Article::_get_labels($line['id']), "unread" => self::param_to_bool($line["unread"]), "marked" => self::param_to_bool($line["marked"]), "published" => self::param_to_bool($line["published"]), @@ -324,7 +324,7 @@ class API extends Handler { "author" => $line["author"], "updated" => (int) strtotime($line["updated"]), "feed_id" => $line["feed_id"], - "attachments" => Article::get_enclosures($line['id']), + "attachments" => Article::_get_enclosures($line['id']), "score" => (int)$line["score"], "feed_title" => $line["feed_title"], "note" => $line["note"], @@ -417,7 +417,7 @@ class API extends Handler { $sth->execute([$_SESSION['uid']]); if ($article_id) - $article_labels = Article::get_article_labels($article_id); + $article_labels = Article::_get_labels($article_id); else $article_labels = array(); @@ -489,7 +489,7 @@ class API extends Handler { $url = strip_tags(clean($_REQUEST["url"])); $content = strip_tags(clean($_REQUEST["content"])); - if (Article::create_published_article($title, $url, $content, "", $_SESSION["uid"])) { + if (Article::_create_published_article($title, $url, $content, "", $_SESSION["uid"])) { $this->wrap(self::STATUS_OK, array("status" => 'OK')); } else { $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); @@ -718,7 +718,7 @@ class API extends Handler { } } - if (!is_array($labels)) $labels = Article::get_article_labels($line["id"]); + if (!is_array($labels)) $labels = Article::_get_labels($line["id"]); $headline_row = array( "id" => (int)$line["id"], @@ -734,7 +734,7 @@ class API extends Handler { "tags" => $tags, ); - $enclosures = Article::get_enclosures($line['id']); + $enclosures = Article::_get_enclosures($line['id']); if ($include_attachments) $headline_row['attachments'] = $enclosures; @@ -775,7 +775,7 @@ class API extends Handler { if ($show_content) { $hook_object = ["headline" => &$headline_row]; - list ($flavor_image, $flavor_stream, $flavor_kind) = Article::get_article_image($enclosures, + list ($flavor_image, $flavor_stream, $flavor_kind) = Article::_get_image($enclosures, $line["content"], // unsanitized $line["site_url"]); diff --git a/classes/article.php b/classes/article.php index cc5d73b64..d177a8d6d 100755 --- a/classes/article.php +++ b/classes/article.php @@ -27,7 +27,7 @@ class Article extends Handler_Protected { } } - static function create_published_article($title, $url, $content, $labels_str, + static function _create_published_article($title, $url, $content, $labels_str, $owner_uid) { $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash @@ -165,7 +165,7 @@ class Article extends Handler_Protected { $id = (int) clean($_REQUEST['id'] ?? 0); print json_encode(["id" => $id, - "tags" => self::get_article_tags($id)]); + "tags" => self::_get_tags($id)]); } function setScore() { @@ -248,8 +248,8 @@ class Article extends Handler_Protected { $this->pdo->commit(); - $tags = self::get_article_tags($id); - $tags_str = $this->format_tags_string($tags); + $tags = self::_get_tags($id); + $tags_str = $this->_format_tags_html($tags); $tags_str_full = join(", ", $tags); if (!$tags_str_full) $tags_str_full = __("no tags"); @@ -277,14 +277,14 @@ class Article extends Handler_Protected { } function assigntolabel() { - return $this->labelops(true); + return $this->_label_ops(true); } function removefromlabel() { - return $this->labelops(false); + return $this->_label_ops(false); } - private function labelops($assign) { + private function _label_ops($assign) { $reply = array(); $ids = explode(",", clean($_REQUEST["ids"])); @@ -303,10 +303,10 @@ class Article extends Handler_Protected { else Labels::remove_article($id, $label, $_SESSION["uid"]); - $labels = $this->get_article_labels($id, $_SESSION["uid"]); + $labels = $this->_get_labels($id, $_SESSION["uid"]); array_push($reply["info-for-headlines"], - array("id" => $id, "labels" => $this->format_article_labels($labels))); + array("id" => $id, "labels" => $this->_format_labels_html($labels))); } } @@ -316,24 +316,12 @@ class Article extends Handler_Protected { print json_encode($reply); } - function getArticleFeed($id) { - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries - WHERE ref_id = ? AND owner_uid = ?"); - $sth->execute([$id, $_SESSION['uid']]); - - if ($row = $sth->fetch()) { - return $row["feed_id"]; - } else { - return 0; - } - } - - static function format_enclosures($id, + static function _format_enclosures($id, $always_display_enclosures, $article_content, $hide_images = false) { - $enclosures = self::get_enclosures($id); + $enclosures = self::_get_enclosures($id); $rv = []; $enclosures_formatted = ""; @@ -389,7 +377,7 @@ class Article extends Handler_Protected { return $rv; } - static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { + static function _get_tags($id, $owner_uid = 0, $tag_cache = false) { $a_id = $id; @@ -439,7 +427,7 @@ class Article extends Handler_Protected { return $tags; } - static function format_tags_string($tags) { + static function _format_tags_html($tags) { if (!is_array($tags) || count($tags) == 0) { return __("no tags"); } else { @@ -459,7 +447,7 @@ class Article extends Handler_Protected { } } - static function format_article_labels($labels) { + static function _format_labels_html($labels) { if (!is_array($labels)) return ''; @@ -475,8 +463,7 @@ class Article extends Handler_Protected { } - static function format_article_note($id, $note, $allow_edit = true) { - + static function _format_note_html($id, $note, $allow_edit = true) { if ($allow_edit) { $onclick = "onclick='Plugins.Note.edit($id)'"; $note_class = 'editable'; @@ -491,7 +478,7 @@ class Article extends Handler_Protected { "; } - function get_metadata_by_id() { + function getmetadatabyid() { $id = clean($_REQUEST['id']); $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries @@ -506,7 +493,7 @@ class Article extends Handler_Protected { } } - static function get_enclosures($id) { + static function _get_enclosures($id) { $pdo = Db::pdo(); @@ -530,7 +517,7 @@ class Article extends Handler_Protected { return $rv; } - static function purge_orphans() { + static function _purge_orphans() { // purge orphaned posts in main content table @@ -549,7 +536,7 @@ class Article extends Handler_Protected { } } - static function catchupArticlesById($ids, $cmode, $owner_uid = false) { + static function _catchup_by_id($ids, $cmode, $owner_uid = false) { if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -574,21 +561,7 @@ class Article extends Handler_Protected { $sth->execute(array_merge($ids, [$owner_uid])); } - static function getLastArticleId() { - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries - WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1"); - $sth->execute([$_SESSION['uid']]); - - if ($row = $sth->fetch()) { - return $row['id']; - } else { - return -1; - } - } - - static function get_article_labels($id, $owner_uid = false) { + static function _get_labels($id, $owner_uid = false) { $rv = array(); if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -635,7 +608,7 @@ class Article extends Handler_Protected { return $rv; } - static function get_article_image($enclosures, $content, $site_url) { + static function _get_image($enclosures, $content, $site_url) { $article_image = ""; $article_stream = ""; diff --git a/classes/digest.php b/classes/digest.php index 7790424ca..77eb92c54 100644 --- a/classes/digest.php +++ b/classes/digest.php @@ -68,7 +68,7 @@ class Digest if ($rc && $do_catchup) { Debug::log("Marking affected articles as read..."); - Article::catchupArticlesById($affected_ids, 0, $line["id"]); + Article::_catchup_by_id($affected_ids, 0, $line["id"]); } } else { Debug::log("No headlines"); @@ -164,7 +164,7 @@ class Digest $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title']; } - $article_labels = Article::get_article_labels($line["ref_id"], $user_id); + $article_labels = Article::_get_labels($line["ref_id"], $user_id); $article_labels_formatted = ""; if (is_array($article_labels) && count($article_labels) > 0) { diff --git a/classes/feeditem.php b/classes/feeditem.php index 3a5e5dc09..e30df3086 100644 --- a/classes/feeditem.php +++ b/classes/feeditem.php @@ -9,7 +9,7 @@ abstract class FeedItem { abstract function get_comments_url(); abstract function get_comments_count(); abstract function get_categories(); - abstract function get_enclosures(); + abstract function _get_enclosures(); abstract function get_author(); abstract function get_language(); } diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index a03080981..3e092a048 100755 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -119,7 +119,7 @@ class FeedItem_Atom extends FeedItem_Common { return $this->normalize_categories($cats); } - function get_enclosures() { + function _get_enclosures() { $links = $this->elem->getElementsByTagName("link"); $encs = array(); @@ -138,7 +138,7 @@ class FeedItem_Atom extends FeedItem_Common { } } - $encs = array_merge($encs, parent::get_enclosures()); + $encs = array_merge($encs, parent::_get_enclosures()); return $encs; } diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index 1e9d62228..f387e0779 100755 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -78,7 +78,7 @@ abstract class FeedItem_Common extends FeedItem { } // this is common for both Atom and RSS types and deals with various media: elements - function get_enclosures() { + function _get_enclosures() { $encs = []; $enclosures = $this->xpath->query("media:content", $this->elem); diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 1f7953c51..f103ad787 100755 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -112,7 +112,7 @@ class FeedItem_RSS extends FeedItem_Common { return $this->normalize_categories($cats); } - function get_enclosures() { + function _get_enclosures() { $enclosures = $this->elem->getElementsByTagName("enclosure"); $encs = array(); @@ -129,7 +129,7 @@ class FeedItem_RSS extends FeedItem_Common { array_push($encs, $enc); } - $encs = array_merge($encs, parent::get_enclosures()); + $encs = array_merge($encs, parent::_get_enclosures()); return $encs; } diff --git a/classes/feeds.php b/classes/feeds.php index 6bf176261..10873d8ca 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -214,10 +214,10 @@ class Feeds extends Handler_Protected { } } - if (!is_array($labels)) $labels = Article::get_article_labels($id); + if (!is_array($labels)) $labels = Article::_get_labels($id); $labels_str = ""; - $labels_str .= Article::format_article_labels($labels); + $labels_str .= Article::_format_labels_html($labels); $labels_str .= ""; $line["labels"] = $labels_str; @@ -265,7 +265,7 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp(" disk_cache_rewrite"); if ($line['note']) - $line['note'] = Article::format_article_note($id, $line['note']); + $line['note'] = Article::_format_note_html($id, $line['note']); else $line['note'] = ""; @@ -283,7 +283,7 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp(" pre-enclosures"); - $line["enclosures"] = Article::format_enclosures($id, + $line["enclosures"] = Article::_format_enclosures($id, $line["always_display_enclosures"], $line["content"], $line["hide_images"]); @@ -303,7 +303,7 @@ class Feeds extends Handler_Protected { else $tags = false; - $line["tags_str"] = Article::format_tags_string($tags); + $line["tags_str"] = Article::_format_tags_html($tags); $this->_mark_timestamp(" tags"); diff --git a/classes/handler/public.php b/classes/handler/public.php index 98386cbf1..b11c8ba04 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -82,7 +82,7 @@ class Handler_Public extends Handler { while ($line = $result->fetch()) { $line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); - $line["tags"] = Article::get_article_tags($line["id"], $owner_uid); + $line["tags"] = Article::_get_tags($line["id"], $owner_uid); PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES, function ($result) use (&$line) { @@ -131,7 +131,7 @@ class Handler_Public extends Handler { $tpl->addBlock('category'); } - $enclosures = Article::get_enclosures($line["id"]); + $enclosures = Article::_get_enclosures($line["id"]); if (count($enclosures) > 0) { foreach ($enclosures as $e) { @@ -151,7 +151,7 @@ class Handler_Public extends Handler { $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); } - list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); + list ($og_image, $og_stream) = Article::_get_image($enclosures, $line['content'], $feed_site_url); $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); @@ -184,7 +184,7 @@ class Handler_Public extends Handler { while ($line = $result->fetch()) { $line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); - $line["tags"] = Article::get_article_tags($line["id"], $owner_uid); + $line["tags"] = Article::_get_tags($line["id"], $owner_uid); PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES, function ($result) use (&$line) { @@ -218,7 +218,7 @@ class Handler_Public extends Handler { } } - $enclosures = Article::get_enclosures($line["id"]); + $enclosures = Article::_get_enclosures($line["id"]); if (count($enclosures) > 0) { $article['enclosures'] = array(); @@ -341,7 +341,7 @@ class Handler_Public extends Handler { if ($line = $sth->fetch()) { - $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); + $line["tags"] = Article::_get_tags($id, $owner_uid, $line["tag_cache"]); unset($line["tag_cache"]); $line["content"] = Sanitizer::sanitize($line["content"], @@ -390,8 +390,8 @@ class Handler_Public extends Handler { $rv .= ""; - $enclosures = Article::get_enclosures($line["id"]); - list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $line["site_url"]); + $enclosures = Article::_get_enclosures($line["id"]); + list ($og_image, $og_stream) = Article::_get_image($enclosures, $line['content'], $line["site_url"]); if ($og_image) { $rv .= ""; @@ -573,7 +573,7 @@ class Handler_Public extends Handler { $content = strip_tags(clean($_REQUEST["content"])); $labels = strip_tags(clean($_REQUEST["labels"])); - Article::create_published_article($title, $url, $content, $labels, + Article::_create_published_article($title, $url, $content, $labels, $_SESSION["uid"]); print "