Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Ajax Star Rating
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods Completed

Unknown User
2019-08-25 20:17:06
credits to Mvp for Original code

Open up theme/header.php add


<script type="text/javascript" language="javascript" src="<?php echo $site_config["SITEURL"];?>/js/rating.js"></script>
<script type="text/javascript" language="javascript" src="<?php echo $site_config["SITEURL"];?>/js/behavior.js"></script>


now open up your current theme  theme.css add

/*Star Rating css*/
.ratingblock {
display:block;
border-bottom:1px solid #999;
padding-bottom:8px;
margin-bottom:8px;
}

.loading {
height: 30px;
background: url('images/working.gif') 50% 50% no-repeat;
}

.unit-rating { /* the UL */
list-style:none;
margin: 0px;
padding:0px;
height: 30px;
position: relative;
background: url('images/starrating.gif') top left repeat-x;
}

.unit-rating li{
text-indent: -90000px;
padding:0px;
margin:0px;
/**/
float: left;
/* */
}

.unit-rating li a {
outline: none;
display:block;
width:30px;
height: 30px;
text-decoration: none;
text-indent: -9000px;
z-index: 20;
position: absolute;
padding: 0px;
}

.unit-rating li a:hover{
background: url('images/starrating.gif') left center;
z-index: 2;
left: 0px;
}

.unit-rating a.r1-unit{left: 0px;}
.unit-rating a.r1-unit:hover{width:30px;}
.unit-rating a.r2-unit{left:30px;}
.unit-rating a.r2-unit:hover{width: 60px;}
.unit-rating a.r3-unit{left: 60px;}
.unit-rating a.r3-unit:hover{width: 90px;}
.unit-rating a.r4-unit{left: 90px;}
.unit-rating a.r4-unit:hover{width: 120px;}
.unit-rating a.r5-unit{left: 120px;}
.unit-rating a.r5-unit:hover{width: 150px;}
.unit-rating a.r6-unit{left: 150px;}
.unit-rating a.r6-unit:hover{width: 180px;}
.unit-rating a.r7-unit{left: 180px;}
.unit-rating a.r7-unit:hover{width: 210px;}
.unit-rating a.r8-unit{left: 210px;}
.unit-rating a.r8-unit:hover{width: 240px;}
.unit-rating a.r9-unit{left: 240px;}
.unit-rating a.r9-unit:hover{width: 270px;}
.unit-rating a.r10-unit{left: 270px;}
.unit-rating a.r10-unit:hover{width: 300px;}

.unit-rating li.current-rating {
background: url('images/starrating.gif') left bottom;
position: absolute;
height: 30px;
display: block;
text-indent: -9000px;
z-index: 1;
}

.voted {color:#999;}
.thanks {color:#36AA3D;}
.static {color:#5D3126;}
}


now open up torrents-details.php find


//take rating
if ($_GET["takerating"] == 'yes'){
   $rating = (int)$_POST['rating'];

   if ($rating <= 0 || $rating > 5)
       show_error_msg(T_("RATING_ERROR"), T_("INVAILD_RATING"), 1);

   $res = SQL_Query_exec("INSERT INTO ratings (torrent, user, rating, added) VALUES ($id, " . $CURUSER["id"] . ", $rating, '".get_date_time()."')");

   if (!$res) {
       if (mysqli_errno($GLOBALS["DBconnector"]) == 1062)
           show_error_msg(T_("RATING_ERROR"), T_("YOU_ALREADY_RATED_TORRENT"), 1);
       else
           show_error_msg(T_("RATING_ERROR"), T_("A_UNKNOWN_ERROR_CONTACT_STAFF"), 1);
   }

   SQL_Query_exec("UPDATE torrents SET numratings = numratings + 1, ratingsum = ratingsum + $rating WHERE id = $id");
   show_error_msg(T_("RATING_SUCCESS"), T_("RATING_THANK")."<br /><br /><a href='torrents-details.php?id=$id'>" .T_("BACK_TO_TORRENT"). "</a>");
}


Replace with


//take rating
if ($_GET["takerating"] == 'yes'){
$rating = (int)$_GET['j'];

if ($rating <= 0 || $rating > 5)
       show_error_msg(T_("RATING_ERROR"), T_("INVAILD_RATING"), 1);

   $res = SQL_Query_exec("INSERT INTO ratings (torrent, user, rating, added) VALUES ($id, " . $CURUSER["id"] . ", $rating, '".get_date_time()."')");

   if (!$res) {
       if (mysqli_errno($GLOBALS["DBconnector"]) == 1062)
           show_error_msg(T_("RATING_ERROR"), T_("YOU_ALREADY_RATED_TORRENT"), 1);
       else
           show_error_msg(T_("RATING_ERROR"), T_("A_UNKNOWN_ERROR_CONTACT_STAFF"), 1);
   }

   SQL_Query_exec("UPDATE torrents SET numratings = numratings + 1, ratingsum = ratingsum + $rating WHERE id = $id");
   show_error_msg(T_("RATING_ERROR"), T_("RATING_THANK")."<br /><br /><a href='torrents-details.php?id=$id'>" .T_("BACK_TO_TORRENT"). "</a>");
}



now find


// $srating IS RATING VARIABLE
       $srating = "";
       $srating .= "<table class='f-border' cellspacing=\"1\" cellpadding=\"4\" width='100%'><tr><td class='f-title' width='60'><b>".T_("RATINGS").":</b></td><td class='f-title' valign='middle'>";
       if (!isset($row["rating"])) {
               $srating .= "Not Yet Rated";
       }else{
           $rpic = ratingpic($row["rating"]);
           if (!isset($rpic))
               $srating .= "invalid?";
           else
               $srating .= "$rpic (" . $row["rating"] . " ".T_("OUT_OF")." 5) " . $row["numratings"] . " ".T_("USERS_HAVE_RATED");
       }
       $srating .= "\n";
       if (!isset($CURUSER))
           $srating .= "(<a href=\"account-login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;nowarn=1\">Log in</a> to rate it)";
       else {
           $ratings = array(
                   5 => T_("COOL"),
                   4 => T_("PRETTY_GOOD"),
                   3 => T_("DECENT"),
                   2 => T_("PRETTY_BAD"),
                   1 => T_("SUCKS")
           );
           //if (!$owned || $moderator) {
               $xres = SQL_Query_exec("SELECT rating, added FROM ratings WHERE torrent = $id AND user = " . $CURUSER["id"]);
               $xrow = mysqli_fetch_assoc($xres);
               if ($xrow)
                   $srating .= "<br /><i>(".T_("YOU_RATED")." \"" . $xrow["rating"] . " - " . $ratings[$xrow["rating"]] . "\")</i>";
               else {
                   $srating .= "<form style=\"display:inline;\" method=\"post\" action=\"torrents-details.php?id=$id&amp;takerating=yes\"><input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
                   $srating .= "<select name=\"rating\">\n";
                   $srating .= "<option value=\"0\">(".T_("ADD_RATING").")</option>\n";
                   foreach ($ratings as $k => $v) {
                       $srating .= "<option value=\"$k\">$k - $v</option>\n";
                   }
                   $srating .= "</select>\n";
                   $srating .= "<input type=\"submit\" value=\"".T_("VOTE")."\" />";
                   $srating .= "</form>\n";
               }
           //}
       }
       $srating .= "</td></tr></table>";

print("<center>". $srating . "</center>");// rating

//END DEFINE RATING VARIABLE


[color=rgb(204, 204, 204)]DELETE IT[/color]

now find


//end download box


add under


// $srating IS RATING VARIABLE
$total_votes = 0;
$total_value = 0;
$query = SQL_Query_exec("SELECT COUNT(torrent) as total_votes, SUM(rating) as total_value FROM `ratings` WHERE `torrent` = '$id'");
while ($rating = mysqli_fetch_array($query)) {
$total_votes = $rating['total_votes'];
$total_value = $rating['total_value'];
}
$voted = get_row_count("ratings", "WHERE `torrent` = '" . $id . "' AND `user` = '" . $CURUSER["id"] . "'");
if ($total_votes < 1) {
$count = 0;
} else {
$count = $total_votes;
}
$current_rating = $total_value;
$tense = ($count == 1) ? "vote" : "votes";
if (is_numeric($current_rating) && is_numeric($count)) {
$rating_width = @number_format($current_rating / $count, 2) * 30;
//$rating_width = @number_format((floatval).$current_rating / $count, 2) * 30;
$rating_1 = @number_format($current_rating / $count, 1);
$rating_2 = @number_format($current_rating / $count, 2);
}
if (!$voted) {
$rater .= '<div id="unit_long' . $id . '">';
$rater .= '<ul id="unit_ul' . $id . '" class="unit-rating" style="width: ' . 30 * 5 . 'px;">';
$rater .= '<li class="current_rating" style="width: ' . $rating_width . '"px;"> Currently ' . $rating_2 . '/' . 5 . '</li>';
for ($ncount = 1; $ncount <= 5; $ncount++) {
if (!$voted) {
if ($CURUSER)
$rater .='<li><a href="torrents-details.php?id=' . $id . '&takerating=yes&j=' . $ncount . '" title="'.$ncount.' out of 5" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
else
$rater .='<li><a href="account-login.php?returnto="' . urlencode($_SERVER["REQUEST_URI"]) . '&amp;nowarn=1" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
}
}
$ncount = 0;
}
$rater .= '</ul>';
$rater .= '<p>';
if ($voted) {
$static_rater = array();
$static_rater[] .= '<div id="unit_long'.$id.'">';
$static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'. 30*5 .'px;">';
$static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
$static_rater[] .= '</ul>';
$rater .= join("\n", $static_rater);
}
$rater .= '<strong>' . $rating_1 . '</strong>/5 (' . $count . ' ' . $tense . ' cast)';
$rater .= '</p>';
//END DEFINE RATING VARIABLE


Find


print("<tr><td align='left'><b>".T_("HITS").":</b></td><td>" . number_format($row["hits"]) . "</td></tr>\n");

under add

print("<tr><td align='left'><b>".T_("Rating").":</b></td><td>" . $rater . "</td></tr>\n");

upload js files to root/js folder and starrating.gif to themes/your_theme/images
[ATTACH]5151[/ATTACH]
starrating.zip
Download
sample.png
sample.png
2019-09-01 18:20:04
thank you but the page is up to 10 seconds :(
Unknown User
2019-09-01 19:47:48
im not quite sure what you mean the page takes 10 seconds to load ? or ?
2019-09-02 14:47:52
"serph, post: 67141, member: 1398":

im not quite sure what you mean the page takes 10 seconds to load ? or ?

yes it updates (REFRESH) every 10 seconds the page torrents-details
Unknown User
2019-09-02 16:07:28
It's instant on my Dev and main sight ive  just installed it on a fresh install of V3 and it's instant could there be some other code in torrent-details making it slow? Or Server load could someone else install and see if it's the same for them please
Unknown User
2019-10-06 16:51:50
[USER=1398]@serph[/USER] why are you using "@" at functions?

It could be the reason why he has page loading slow. This is a very bad coding habbit to suppress errors instead of fixing them.
2020-01-26 19:41:50
You can reduce server requests by simply including the JS resource(s) on torrents-details.php

Side note:
Doesn't seem to follow mysqli_ requirements, preventing from votes from being retrieved for said ID.
Solution: Change mysqli_fetch_array => mysql_fetch_array

Im sure this violates some hardknox rule book somewhere, but if you want the mod working, thats the case on at least PHP 5.
2020-11-23 17:12:15
Merci fonctionne bien :D
2023-01-14 21:06:10
Still in action, the SQL and the rounding is important - big thanks
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728