Merge pull request '[I35] Add episode comment tally' (#36) from I35_Add-comment-tally into main

Reviewed-on: #36
This commit is contained in:
Roan Horning 2022-09-01 01:08:45 +00:00
commit c1a83f8baf
2 changed files with 88 additions and 12 deletions

View File

@ -45,11 +45,12 @@
%-->
<!--% episode_result = query_episodes.execute(id, id, id, id, id) %-->
<!--% FOREACH episode IN episode_result %-->
<!--% episode_navigation = step_navigation(baseurl,episode) %-->
<article>
<header>
<h1>hpr<!--% episode.id %--> :: <!--% episode.title %--></h1>
<h3><!--% episode.summary %--></h3>
<p class="meta"><!--% step_navigation(baseurl,episode) %-->
<p class="meta"><!--% episode_navigation %-->
</p>
<p><!--% IF get_avatar(episode.hostid) != 'hpr_logo.png' %-->
<img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(episode.hostid) %-->" height="80" width="80" alt="" /></a><br><!--% END %-->
@ -58,3 +59,69 @@ Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pa
<div><!--% episode.notes %--></div>
</article>
<!--% END %-->
<hr />
<h1>Comments</h1>
<p id="comments">
Subscribe to the comments <a href="https://www.hackerpublicradio.org/comments_rss.php">RSS</a> feed.
</p>
<!--% query_comments = DBI.prepare('
SELECT
comment_timestamp,
comment_author_name,
comment_title,
comment_text
FROM comments
WHERE eps_id = ?
')
%-->
<!--% comment_index = 1 %-->
<!--% comments_result = query_comments.execute(id) %-->
<!--% FOREACH comment IN comments_result %-->
<h5 id="1">Comment #<!--% comment_index %--> posted on <!--% comment.comment_timestamp %--> by <!--% comment.comment_author_name %--></h5>
<h4><!--% comment.comment_title %--></h4>
<!--% comment.comment_text %-->
<!--% comment_index = comment_index + 1 %-->
<!--% END %-->
<p>
<!--% episode_navigation %-->
</p>
<h2>Leave Comment</h2>
<p>
<strong>Note to Verbose Commenters</strong><br />
If you can't fit everything you want to say in the comment below then you really should <a href="/contribute.php">record</a> a response show instead.
</p>
<p>
<strong>Note to Spammers</strong><br />
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to <a href="/contribute.php">record</a> a show about yourself, or your industry, or any other topic we may find interesting. <em>We also check shows for spam :)</em>.
</p>
<form method="POST" action="comment_confirm.php">
<fieldset>
<legend>Provide feedback</legend>
<table>
<tr>
<td>Your Name/Handle:</td>
<td><input required type="text" name="comment_author_name" size="40" maxlength="40" placeholder="Enter your name" ></td>
</tr>
<tr>
<td>Title:</td>
<td><input required type="text" name="comment_title" size="50" maxlength="100" placeholder="What is your comment about ?"></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea required name="comment_text" maxlength="2000" rows="10" cols="50" placeholder="Place the comment here."></textarea></td>
</tr>
<tr>
<td>Anti Spam Question:</td>
<td>
What does the <strong>P</strong> in <em>HPR</em> stand for ? <br />
<input required type="text" name="anti_spam_question" size="50" maxlength="100" placeholder="Type out what the P in HPR stands for."></td>
</tr>
<input type="hidden" name="spammer" value="No">
<input type="hidden" name="hostid" value="406">
<input type="hidden" name="justification" value="No justification is asked for or required.">
<input type="hidden" name="eps_id" value="3665 ">
</table>
<input type="submit" value="Next">
</fieldset>
</form>

View File

@ -21,19 +21,28 @@
<h1>Latest Shows</h1>
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH latest_episodes IN DBI.query('
WITH comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY date DESC
LIMIT 10
@ -49,7 +58,7 @@
<br>Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(latest_episodes.hostid) %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% display_explicit(latest_episodes.explicit) %--> and released under a <!--% latest_episodes.license %--> license. <br>
<strong>Tags:</strong> <!--% latest_episodes.tags %--><em></em>.<br>
<small>listen in <a href="local/hpr<!--% latest_episodes.id %-->.ogg">ogg</a>, <a href="local/hpr<!--% latest_episodes.id %-->.spx">spx</a>, or <a href="local/hpr<!--% latest_episodes.id %-->.mp3">mp3</a> format. <!--% show_series(latest_episodes.series, latest_episodes.seriesid) %-->
<a href="<!--% absolute_path(baseurl) %-->eps/hpr<!--% zero_pad_left(latest_episodes.id) %-->/index.html#comments">View comments.</a></small>
<a href="<!--% absolute_path(baseurl) %-->eps/hpr<!--% zero_pad_left(latest_episodes.id) %-->/index.html#comments">Comments (<!--% latest_episodes.eps_tally %-->)</a>.</small>
</p>
</header>
<!--% latest_episodes.notes %-->