From a2e688fcb2d463a5db700ebd013c783e3a8f4971 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 22:17:13 +0300 Subject: [PATCH] render headline-specific toolbar on the client --- classes/feeds.php | 123 +++++++-------------------------------- classes/pref/feeds.php | 22 +++++-- index.php | 4 +- js/CommonDialogs.js | 13 ++--- js/Headlines.js | 61 ++++++++++++++++++- plugins/mail/init.php | 7 ++- plugins/mailto/init.php | 5 ++ themes/compact.css | 5 +- themes/compact_night.css | 5 +- themes/light.css | 5 +- themes/light/tt-rss.less | 4 +- themes/night.css | 5 +- themes/night_blue.css | 5 +- 13 files changed, 136 insertions(+), 128 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index e6bd1459d..0a3e77a1a 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -16,103 +16,6 @@ class Feeds extends Handler_Protected { return array_search($method, $csrf_ignored) !== false; } - private function format_headline_subtoolbar($feed_site_url, $feed_title, - $feed_id, $is_cat, $search, - $error, $feed_last_updated) { - - $cat_q = $is_cat ? "&is_cat=$is_cat" : ""; - - if ($search) { - $search_q = "&q=$search"; - } else { - $search_q = ""; - } - - $reply = ""; - - $rss_link = htmlspecialchars(get_self_url_prefix() . - "/public.php?op=rss&id=${feed_id}${cat_q}${search_q}"); - - $reply .= ""; - - $reply .= " - rss_feed"; - - $reply .= ""; - - if ($feed_site_url) { - $last_updated = T_sprintf("Last updated: %s", $feed_last_updated); - - $reply .= "". - truncate_string(strip_tags($feed_title), 30).""; - } else { - $reply .= strip_tags($feed_title); - } - - if ($error) - $reply .= " error"; - - $reply .= ""; - $reply .= ""; - $reply .= ""; - - $reply .= ""; - $reply .= ""; - $reply .= " "; - - $reply .= "
- ".__("Select...")." -
-
".__('All')."
-
".__('Unread')."
-
".__('Invert')."
-
".__('None')."
-
-
".__('Toggle unread')."
-
".__('Toggle starred')."
-
".__('Toggle published')."
-
-
".__('Mark as read')."
-
".__('Set score')."
"; - - // TODO: move to mail plugin - if (PluginHost::getInstance()->get_plugin("mail")) { - $reply .= "
".__('Forward by email')."
"; - } - - // TODO: move to mailto plugin - if (PluginHost::getInstance()->get_plugin("mailto")) { - $reply .= "
".__('Forward by email')."
"; - } - - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, - function ($result) use (&$reply) { - $reply .= $result; - }, - $feed_id, $is_cat); - - if ($feed_id == 0 && !$is_cat) { - $reply .= "
-
".__('Delete permanently')."
"; - } - - $reply .= "
"; /* menu */ - - $reply .= "
"; /* dropdown */ - - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON, - function ($result) use (&$reply) { - $reply .= $result; - }, - $feed_id, $is_cat); - - $reply .= "
"; - - return $reply; - } - private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $offset, $override_order = false, $include_children = false, $check_first_id = false, $skip_first_id_check = false, $order_by = false) { @@ -222,10 +125,28 @@ class Feeds extends Handler_Protected { $reply['search_query'] = [$search, $search_language]; $reply['vfeed_group_enabled'] = $vfeed_group_enabled; - $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, - $feed_title, - $feed, $cat_view, $search, - $last_error, $last_updated); + $plugin_menu_items = ""; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, + function ($result) use (&$plugin_menu_items) { + $plugin_menu_items .= $result; + }, + $feed, $cat_view); + + $plugin_buttons = ""; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON, + function ($result) use (&$plugin_buttons) { + $plugin_buttons .= $result; + }, + $feed, $cat_view); + + $reply['toolbar'] = [ + 'site_url' => $feed_site_url, + 'title' => truncate_string(strip_tags($feed_title), 30), + 'error' => $last_error, + 'last_updated' => $last_updated, + 'plugin_menu_items' => $plugin_menu_items, + 'plugin_buttons' => $plugin_buttons, + ]; $reply['content'] = []; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 6b5df0289..e225949f2 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1358,14 +1358,12 @@ class Pref_Feeds extends Handler_Protected { } private function index_shared() { - $rss_url = htmlspecialchars(get_self_url_prefix() . - "/public.php?op=rss&id=-2&view-mode=all_articles"); ?>

@@ -1603,11 +1601,23 @@ class Pref_Feeds extends Handler_Protected { print json_encode(["link" => $new_key]); } - function getFeedKey() { + function getsharedurl() { $feed_id = clean($_REQUEST['id']); - $is_cat = clean($_REQUEST['is_cat']); + $is_cat = clean($_REQUEST['is_cat']) == "true"; + $search = clean($_REQUEST['search']); - print json_encode(["link" => Feeds::get_feed_access_key($feed_id, $is_cat, $_SESSION["uid"])]); + $link = get_self_url_prefix() . "/public.php?" . http_build_query([ + 'op' => 'rss', + 'id' => $feed_id, + 'is_cat' => (int)$is_cat, + 'q' => $search, + 'key' => Feeds::get_feed_access_key($feed_id, $is_cat, $_SESSION["uid"]) + ]); + + print json_encode([ + "title" => Feeds::getFeedTitle($feed_id, $is_cat), + "link" => $link + ]); } private function update_feed_access_key($feed_id, $is_cat, $owner_uid) { diff --git a/index.php b/index.php index 8bfca1af2..d53fb54a8 100644 --- a/index.php +++ b/index.php @@ -176,9 +176,9 @@ }); ?> -
+
- +
diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 5a72f705b..e6b1822c2 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -433,24 +433,19 @@ const CommonDialogs = { } }); }, - generatedFeed: function(feed, is_cat, rss_url, feed_title) { + generatedFeed: function(feed, is_cat, search = "") { Notify.progress("Loading, please wait...", true); - xhrJson("backend.php", {op: "pref-feeds", method: "getFeedKey", id: feed, is_cat: is_cat}, (reply) => { + xhrJson("backend.php", {op: "pref-feeds", method: "getsharedurl", id: feed, is_cat: is_cat, search: search}, (reply) => { try { - if (!feed_title && typeof Feeds != "undefined") - feed_title = Feeds.getName(feed, is_cat); - - const secret_url = rss_url + "&key=" + encodeURIComponent(reply.link); - const dialog = new fox.SingleUseDialog({ title: __("Show as feed"), content: ` -
${__("%s can be accessed via the following secret URL:").replace("%s", feed_title)}
+
${__("%s can be accessed via the following secret URL:").replace("%s", App.escapeHtml(reply.title))}