From 249c93a228245c71853542814857ca0045e43052 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 7 Dec 2018 16:00:11 +0300 Subject: initial for js templates --- classes/feeds.php | 74 +++++++++++++++++++++++--------------------- js/Headlines.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 37 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 080d9e80c..aab770fc0 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -230,7 +230,7 @@ class Feeds extends Handler_Protected { } } - $reply['content'] = ''; + $reply['content'] = []; $headlines_count = 0; @@ -240,32 +240,33 @@ class Feeds extends Handler_Protected { if (is_object($result)) { - while ($line = $result->fetch()) { + while ($line = $result->fetch(PDO::FETCH_ASSOC)) { ++$headlines_count; - $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); - - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { - $line = $p->hook_query_headlines($line, 250, false); - } + if (!get_pref('SHOW_CONTENT_PREVIEW')) { + $line["content_preview"] = null; + } else { + $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); - if (get_pref('SHOW_CONTENT_PREVIEW')) { - $content_preview = $line["content_preview"]; - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { + $line = $p->hook_query_headlines($line, 250, false); + } + } $id = $line["id"]; - $feed_id = $line["feed_id"]; - $label_cache = $line["label_cache"]; - $labels = false; // normalize archived feed - if ($feed_id === null) { - $feed_id = 0; + if ($line['feed_id'] === null) { + $line['feed_id'] = 0; $line["feed_title"] = __("Archived articles"); } + $feed_id = $line["feed_id"]; - $mouseover_attrs = "onmouseover='Article.mouseIn($id)' onmouseout='Article.mouseOut($id)'"; + //$mouseover_attrs = "onmouseover='Article.mouseIn($id)' onmouseout='Article.mouseOut($id)'"; + + $label_cache = $line["label_cache"]; + $labels = false; if ($label_cache) { $label_cache = json_decode($label_cache, true); @@ -284,6 +285,9 @@ class Feeds extends Handler_Protected { $labels_str .= Article::format_article_labels($labels); $labels_str .= ""; + $line["labels"] = $labels_str; + unset($line["label_cache"]); + if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); } @@ -296,35 +300,33 @@ class Feeds extends Handler_Protected { } $class .= $line["marked"] ? " marked" : ""; - $marked_pic = "star"; + //$marked_pic = "star"; - $class .= $line["published"] ? " published" : ""; - $published_pic = "rss_feed"; + //$class .= $line["published"] ? " published" : ""; + //$published_pic = "rss_feed"; - $updated_fmt = make_local_datetime($line["updated"], false, false, false, true); - $date_entered_fmt = T_sprintf("Imported at %s", + $line["updated"] = make_local_datetime($line["updated"], false, false, false, true); + $line['imported'] = T_sprintf("Imported at %s", make_local_datetime($line["date_entered"], false)); $score = $line["score"]; - $score_pic = "" . - get_score_pic($score) . ""; - $score_class = get_score_class($score); + $line["score_pic"] = get_score_pic($score); + $line["score_class"] = get_score_class($score); - $entry_author = $line["author"]; + //$entry_author = $line["author"]; - if ($entry_author) { + /* if ($entry_author) { $entry_author = " — $entry_author"; - } + } */ if (feeds::feedHasIcon($feed_id)) { - $feed_icon_img = "\"\""; + $line['feed_icon'] = "\"\""; } else { - $feed_icon_img = "rss_feed"; + $line['feed_icon'] = "rss_feed"; } - $entry_site_url = $line["site_url"]; + //$entry_site_url = $line["site_url"]; //setting feed headline background color, needs to change text color based on dark/light $fav_color = $line['favicon_avg_color']; @@ -335,9 +337,13 @@ class Feeds extends Handler_Protected { if (!isset($rgba_cache[$feed_id])) { $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)); } + + $line['favicon_avg_color_rgba'] = $rgba_cache[$feed_id]; } - if (!get_pref('COMBINED_DISPLAY_MODE')) { + array_push($reply['content'], $line); + + /* if (!get_pref('COMBINED_DISPLAY_MODE')) { if ($vfeed_group_enabled) { if ($feed_id != $vgroup_last_feed) { @@ -413,7 +419,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= ""; $reply['content'] .= ""; - } else { + } else { // HL if ($line["tag_cache"]) $tags = explode(",", $line["tag_cache"]); @@ -628,7 +634,7 @@ class Feeds extends Handler_Protected { } $reply['content'] .= $tmp_content; - } + } // end html */ ++$lnum; } diff --git a/js/Headlines.js b/js/Headlines.js index 2b33ed396..31e72fa3d 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -239,6 +239,86 @@ define(["dojo/_base/declare"], function (declare) { } } }, + renderHeadline: function (headlines, hl) { + let row = null; + + if (App.isCombinedMode()) { + row = `
+
+
+ + star + rss_feed +
+ + + + ${hl.title} + — ${hl.author} + + + + + + ${hl.updated} + +
+ + ${hl.score_icon} + +

Sorry for hijacking this htread, but I have a similar issue.

+

I have a feed category with about 120 unread articles. I toggle headline grouping, but I am not sure if this matters or not.

+

I click on the category on the left pane, and start clicking “ctrl+down” to scroll to read the articles.
+At some point ( I tried to figure it out, but can say exactly after how many articles I read) the page won’t scroll down with “ctrl+down”, so I have to scroll with down key alone.

+

TT-rss says it’s refreshing the content (or something similar), but was it does, is marking as read a bunch of articles, that were supposed to be shown between the last one I actually read, and the first unread it shows, which should not really be the first unread.

+

Last time it happened, I had around 120 unread articles, I could scroll via ctrl+down untill 80 were unread, I scroled manually, and it jumped to 50 unread. The right pane is also refreshed, so I can not scroll up to go through the ones marked as unread.

+

I hope it is somewhat related to this thread, otherwise let me know and I can open a new one.

+

Please let me know if what I wrote is clear.

+

By the way I am running f6e287df110b2046643551aaae70917c61b061c9 on shared hosting, PHP 7 and Mysql.

`; + + + } else { + row = `
+
+ + star + rss_feed +
+ + + ${hl.feed_title} + +
+ ${hl.updated} +
+
+ ${hl.score_pic} + ${hl.feed_icon} +
+
+ `; + } + + const tmp = document.createElement("div"); + tmp.innerHTML = row; + dojo.parser.parse(tmp); + + $("headlines-frame").appendChild(tmp.firstChild); + }, onLoaded: function (transport, offset) { const reply = App.handleRpcJson(transport); @@ -276,7 +356,8 @@ define(["dojo/_base/declare"], function (declare) { $("headlines-frame").addClassName(App.isCombinedMode() ? "cdm" : "normal"); const headlines_count = reply['headlines-info']['count']; - Feeds.infscroll_disabled = parseInt(headlines_count) != 30; + //Feeds.infscroll_disabled = parseInt(headlines_count) != 30; + Feeds.infscroll_disabled = true; // TEMPORARY console.log('received', headlines_count, 'headlines, infscroll disabled=', Feeds.infscroll_disabled); @@ -292,7 +373,11 @@ define(["dojo/_base/declare"], function (declare) { $("headlines-frame").innerHTML = ''; - let tmp = document.createElement("div"); + for (let i = 0; i < reply['headlines']['content'].length; i++) { + this.renderHeadline(reply['headlines'], reply['headlines']['content'][i]); + } + + /* let tmp = document.createElement("div"); tmp.innerHTML = reply['headlines']['content']; dojo.parser.parse(tmp); @@ -304,7 +389,7 @@ define(["dojo/_base/declare"], function (declare) { this.loaded_article_ids.push(row.id); } - } + } */ let hsp = $("headlines-spacer"); -- cgit v1.2.3