MyBB Community Forums

Full Version: Thread Rating
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've created a few custom pages that I'm linking to topics in the forum (views & thread ratings only). I've got the views to work as needed, and the thread ratings are almost where I need them to be. There's just one thing it's not doing. When you go to rate a thread in the forum, it'll tell you that either you cannot rate the thread, that you rated the thread, or that you already rated it. When using the thread ratings outside of the forum on a custom page, it does not do the notifications via JavaScript.

In the while statement that pulls the scripts from the database, the code that pulls the thread rating information, has somehow messed up the while statement. The while statement stops after it completes its first loop, even though there are multiple entries in the database. If I remove the lines that pull the thread rating information, then it goes back to normal.

Template:
<html>
 <head>
<title>Dota 2 Reborn.Net</title>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='description' content='Dota 2 Reborn.Net Gaming Community'>
<meta name='author' content='Tyler Engelhardt'>
<link type="text/css" rel="stylesheet" href="https://www.dota2reborn.net/forum/cache/themes/theme3/star_ratings.css" />
{$headerinclude}
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/rating.js"></script>
<script type="text/javascript" src="https://www.dota2reborn.net/forum/jscripts/report.js?ver=1804"></script>
<script src="https://www.dota2reborn.net/forum/jscripts/jeditable/jeditable.min.js"></script>
<script type="text/javascript" src="https://www.dota2reborn.net/forum/jscripts/thread.js?ver=1804"></script>

<script type="text/javascript">
<!--
lang.ratings_update_error = "";
// -->
</script>
</head>
<body>
{$header}

<table border='0' cellspacing='0' cellpadding='10' class='tborder' style='width: 1024px;'>
<tr>
<td class='trow_sticky' colspan='8'><i style='font-size: 14px;' class='fa fa-trophy'></i> &nbsp;Tournaments</td>
</tr>
<tr align='left' class='trow1 forumdisplay_sticky'>
{$tournaments}
</tr>
</table>

<br /><br />

<table border='0' cellspacing='0' cellpadding='10' class='tborder' style='width: 1024px;'>
<tr>
<td class='trow_sticky' colspan='8'><i style='font-size: 14px;' class='fa fa-pencil-square-o'></i> &nbsp;Scripts</td>
</tr>
{$scripts}
</table>

<br class='clear' />
{$usersbrowsing}
{$footer}
</body>
</html>

PHP
define('IN_MYBB', 1);
require "./forum/global.php";
global $db;
date_default_timezone_set('America/New_York');
$lang->load("showthread");
$lang->load("ratethread");

$query = $db->simple_select("scripts", "*", "", array('order_by' => 'sid'));

while ($field = $db->fetch_array($query)) {
 if ($field['lang'] == "PHP") {
$language = "<span style='color: #E53427;'>[PHP]</span>";
} else if ($field['lang'] == "JavaScript") {
$language = "<span style='color: #F2701C;'>[JavaScript]</span>";
}

$thread = get_thread($field['tid']);

if ($mybb->settings['allowthreadratings'] != 0) {
$rated = 0;
if ($thread['numratings'] <= 0) {
$thread['width'] = 0;
$thread['averagerating'] = 0;
$thread['numratings'] = 0;
} else {
$thread['averagerating'] = (float)round($thread['totalratings']/$thread['numratings'], 2);
$thread['width'] = (int)round($thread['averagerating'])*20;
$thread['numratings'] = (int)$thread['numratings'];
}

if ($thread['numratings']) {
$query = $db->simple_select("threadratings", "uid", "tid='{$tid}' AND uid='{$mybb->user['uid']}'");
$rated = $db->fetch_field($query, 'uid');
}

$not_rated = '';
if (!$rated) {
$not_rated = ' star_rating_notrated';
}
}

if ($thread['views'] == 1) {
$views = $thread['views'] . " View";
} else {
$views = $thread['views'] . " Views";
}

$scripts .= "<tr class='inline_row'>
<td align='left' class='trow1 forumdisplay_sticky borderedRow' style='width: 80%;'>
<span class='subject_editable subject_old'>" . $language . " <a href='https://www.dota2reborn.net/scripts/" . $field['url'] . "'>" . $field['name'] . "</a></span><br />
<span class='smalltext'>" . $field['description'] . "</span>
</td>
<td align='right' class='trow1 forumdisplay_sticky borderedRow'>
<span>
" . $views . "<br />
<span class='inline_rating smalltext' style='float: right;'>
<ul class='star_rating" . $not_rated . "' id='rating_thread_" . $thread['tid'] . "'>
<li style='width: " . $thread['width'] . "%;' class='current_rating' id='current_rating_" . $thread['tid']. "'></li>
<li><a class='one_star' title='" . $lang->one_star . "' href='https://www.dota2reborn.net/forum/ratethread.php?tid=" . $thread['tid'] . "&amp;rating=1&amp;my_post_key=" . $mybb->post_code . "'></a></li>
<li><a class='two_stars' title='" . $lang->two_stars . "' href='https://www.dota2reborn.net/forum/ratethread.php?tid=" . $thread['tid'] . "&amp;rating=2&amp;my_post_key=" . $mybb->post_code . "'></a></li>
<li><a class='three_stars' title='" . $lang->three_stars . "' href='https://www.dota2reborn.net/forum/ratethread.php?tid=" . $thread['tid'] . "&amp;rating=3&amp;my_post_key=" . $mybb->post_code . "'></a></li>
<li><a class='four_stars' title='" . $lang->four_stars . "' href='https://www.dota2reborn.net/forum/ratethread.php?tid=" . $thread['tid'] . "&amp;rating=4&amp;my_post_key=" . $mybb->post_code . "'></a></li>
<li><a class='five_stars' title='" . $lang->five_stars . "' href='https://www.dota2reborn.net/forum/ratethread.php?tid=" . $thread['tid'] . "&amp;rating=5&amp;my_post_key=" . $mybb->post_code . "'></a></li>
</ul>
</span>
</span><br />
</td>
</tr>";
}

eval("\$indexPage = \"".$templates->get("indexPage")."\";");
output_page($indexPage);
[/php]
Moved to Plugin Support.