зеркало из https://github.com/mozilla/pjs.git
Ability to rate a comment. Currently, this uses GET requests - may be necessary to change it to a POST request to stop abuse of it at a later date
This commit is contained in:
Родитель
ceb038518d
Коммит
ad12bac7aa
|
@ -240,6 +240,9 @@ class AddOn extends AMO_Object
|
|||
CommentNote,
|
||||
CommentDate,
|
||||
CommentVote
|
||||
`helpful-yes` as helpful_yes,
|
||||
`helpful-no` as helpful_no,
|
||||
`helpful-yes` + `helpful-no` as helpful_total
|
||||
FROM
|
||||
feedback
|
||||
WHERE
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* Rate comment for Adddon.
|
||||
*
|
||||
* @package amo
|
||||
* @subpackage docs
|
||||
*/
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// If some of the inputs don't exist, throw an error and exit
|
||||
if (!isset($_GET['aid']) || !isset($_GET['cid']) || !isset($_GET['r'])) {
|
||||
commentError();
|
||||
}
|
||||
|
||||
// Get our addon ID.
|
||||
if (isset($_GET['aid'])) {
|
||||
$clean['aid'] = intval($_GET['aid']);
|
||||
$sql['aid'] =& $clean['aid'];
|
||||
}
|
||||
|
||||
// Get our comment ID.
|
||||
if (isset($_GET['cid'])) {
|
||||
$clean['cid'] = intval($_GET['cid']);
|
||||
$sql['cid'] =& $clean['cid'];
|
||||
}
|
||||
|
||||
// Get whether helpful or not...
|
||||
if (isset($_GET['r'])) {
|
||||
switch ($_GET['r']) {
|
||||
case 'yes':
|
||||
$clean['r'] = 'yes';
|
||||
break;
|
||||
case 'no':
|
||||
$clean['r'] = 'no';
|
||||
break;
|
||||
default:
|
||||
commentError();
|
||||
}
|
||||
}
|
||||
|
||||
// Get addon
|
||||
$addon = new Addon($sql['aid']);
|
||||
|
||||
$success = $db->query("
|
||||
UPDATE
|
||||
feedback
|
||||
SET
|
||||
`helpful-{$clean['r']}` = `helpful-{$clean['r']}` + 1
|
||||
WHERE
|
||||
CommentID = {$sql['cid']}
|
||||
", SQL_NONE);
|
||||
|
||||
$tpl->assign(
|
||||
array( 'title' => 'Rate a Comment for ' . $addon->Name,
|
||||
'content' => 'ratecomment.tpl',
|
||||
'rate' => $success,
|
||||
'addon' => $addon,
|
||||
'sidebar' => 'inc/addon-sidebar.tpl')
|
||||
);
|
||||
|
||||
function commentError() {
|
||||
global $tpl;
|
||||
$tpl->assign(
|
||||
array( 'title' => 'Rate a Comment',
|
||||
'content' => 'ratecomment.tpl',
|
||||
'error' => true)
|
||||
);
|
||||
$tpl->display('inc/wrappers/nonav.tpl');
|
||||
exit;
|
||||
}
|
||||
?>
|
|
@ -36,9 +36,10 @@ Requires: {$addon->AppName} {$addon->MinAppVer} - {$addon->MaxAppVer} <img src="
|
|||
{section name=comments loop=$addon->Comments max=10}
|
||||
<li>
|
||||
<h4>{$addon->Comments[comments].CommentTitle} ({$addon->Comments[comments].CommentVote} rating)</h4>
|
||||
<p class="opinions-info">by {$addon->Comments[comments].CommentName}, {$addon->Comments[comments].CommentDate|date_format}</p>
|
||||
<p class="opinions-info">by {$addon->Comments[comments].CommentName}, {$addon->Comments[comments].CommentDate|date_format}<br>
|
||||
{$addon->Comments[comments].helpful_yes} out of {$addon->Comments[comments].helpful_total} viewers found this comment helpful</p>
|
||||
<p class="opinions-text">{$addon->Comments[comments].CommentNote}</p>
|
||||
<p class="opinions-rating">Was this comment helpful? <a href="./ratecomment.php?id={$addon->Comments[comments].CommentID}&r=yes">Yes</a> | <a href="./ratecomment.php?id={$addon->Comments[comments].CommentID}&r=no">No</a></p>
|
||||
<p class="opinions-rating">Was this comment helpful? <a href="./ratecomment.php?aid={$addon->ID}&cid={$addon->Comments[comments].CommentID}&r=yes">Yes</a> | <a href="./ratecomment.php?aid={$addon->ID}&cid={$addon->Comments[comments].CommentID}&r=no">No</a></p>
|
||||
</li>
|
||||
{/section}
|
||||
</ul>
|
||||
|
|
|
@ -9,9 +9,10 @@ released on {$addon->VersionDateAdded|date_format}
|
|||
{section name=comments loop=$addon->Comments max=10}
|
||||
<li>
|
||||
<h4>{$addon->Comments[comments].CommentTitle} ({$addon->Comments[comments].CommentVote} rating)</h4>
|
||||
<p class="opinions-info">by {$addon->Comments[comments].CommentName}, {$addon->Comments[comments].CommentDate|date_format}</p>
|
||||
<p class="opinions-info">by {$addon->Comments[comments].CommentName}, {$addon->Comments[comments].CommentDate|date_format}<br>
|
||||
{$addon->Comments[comments].helpful_yes} out of {$addon->Comments[comments].helpful_total} viewers found this comment helpful</p>
|
||||
<p class="opinions-text">{$addon->Comments[comments].CommentNote}</p>
|
||||
<p class="opinions-rating">Was this comment helpful? <a href="./ratecomment.php?id={$addon->Comments[comments].CommentID}&r=yes">Yes</a> | <a href="./ratecomment.php?id={$addon->Comments[comments].CommentID}&r=no">No</a></p>
|
||||
<p class="opinions-rating">Was this comment helpful? <a href="./ratecomment.php?aid={$addon->ID}&cid={$addon->Comments[comments].CommentID}&r=yes">Yes</a> | <a href="./ratecomment.php?aid={$addon->ID}&cid={$addon->Comments[comments].CommentID}&r=no">No</a></p>
|
||||
</li>
|
||||
{/section}
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{if $error}
|
||||
<p>Unfortunately, there has been a problem with your submission. Please go back and try again</p>
|
||||
{else}
|
||||
<p class="first">
|
||||
<strong><a href="./addon.php?id={$addon->ID}">{$addon->Name} {$addon->Version}</a></strong>,
|
||||
by <a href="./author.php?id={$addon->UserID}">{$addon->UserName}</a>,
|
||||
released on {$addon->VersionDateAdded|date_format}
|
||||
</p>
|
||||
<h3>Comment for {$addon->Name} Rated {if $rate}Sucessfully{else}Unsucessfully{/if}</h3>
|
||||
{if $rate}
|
||||
<p>You have successfully rated this comment</p>
|
||||
{else}
|
||||
<p>Unfortunately, there was an error rating this comment. If this problem persists, please contact the admins.</p>
|
||||
{/if}
|
||||
{/if}
|
||||
<p><a href="./addon.php?id={$addon->ID}">Return to information about{$addon->Name}</a></p>
|
Загрузка…
Ссылка в новой задаче