Forums Sign Up Reply Search Statistics
Hacks And Addons GraFX Software Solutions - Forum / Hacks And Addons /

Star rating hacks

 
Author Anonymous
Guest
#1 Posted: 6 Dec 2003 02:33:01
Reply 
This hack make rate from 10 to 1 instead exellent to poor:

cls_rate.php:

<?php
/*
################# STAR RATING SYSTEM ##################
############################################################
CWB PRO $Name: $
Revision $Revision: 1.3 $
Author $Author: lvalics $
Created 03/01/02 $Date: 2003/08/16 15:43:23 $
Writed by GraFX (it@grafx.ro)
Scripts Home: http://software.grafx.ro
############################################################
File purpose RATEING SCRIPT FILE
############################################################
*/

/*
// Creating a star rating system with PHP and MySQL (Version 1.0.3)
//
// Author: Gregory Boshoff
//
// The latest version of this script is available for download at.
// http://www.developers-resources.com/scripts/rating.zip
//
// Actual version of star rating system with PHP and MySQL (Version 1.3)
// Modified by GraFX http://software.grafx.ro

*/
class Rating{

var $rate;
var $output;
var $result;
var $go;
var $file;
var $file_real;

function Rating($go,$file,$file_real)

{

global $DEFAULT_URL,$DB_HOST,$DB_USR,$DB_PWD,$DB_NAME;
global $notyetrated,$rated,$from,$altrate,$recentrated;
global $ten,$nine,$eight,$seven,$six,$five,$four,$three,$two,$one,$formrate;
global $line1,$line2,$line3,$line4,$line5,$numberof;
global $hasread1,$hasread2;
$this->go=$go;
$this->file=$file;
$this->file_real=$file_real;

$db = mysql_connect($DB_HOST, $DB_USR, $DB_PWD)
or die ("Could not connect to database");
mysql_select_db($DB_NAME, $db);

$sql = "SELECT id FROM Rate ";
$sql .= "WHERE Item = '$file'";

$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);

// getting the id
$id=$row[0];
if (!mysql_num_rows($result)) {

$sql = "INSERT INTO Rate (Item, Rating, Votes, Num_Votes,viewed) VALUES ('$file','','','',0)";
$result = mysql_query($sql) or die(mysql_error());
$id=mysql_insert_id();

} // end if


$ip_address="no use";
$sql = "SELECT Rating, IP,Votes,viewed,Num_Votes FROM Rate ";
$sql .= "WHERE Item = '$file' ";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$this->rate = "<br>";

$isMarked=$this->isMarked($id);

if ($row[0] < 1 && !$isMarked) {

$this->rate .= "$notyetrated";

}

else
{
$i = 0;

While (++$i <= $row[0])
$this->rate .= "<img src=\"".$RATE_URL."graphic/rate.gif\" border=\"0\" alt=\"$altrate\"></a>\n";


$numberofvotes=$row["Num_Votes"];
$viewed=$row["viewed"];


$this->rate .= "<strong>$rated $row[0] $from 10</strong><br>\n";
$this->rate .= "<strong>".$hasread1.$viewed.$hasread2."</strong><br>\n";
$this->rate .= "<strong>$numberof $numberofvotes</strong><br>\n";

} // end else


if ($isMarked)
$this->rate .= "$recentrated";
else
{


if($this->go=="Rate" && !$isMarked )
{
$sql = "UPDATE Rate set viewed=viewed+1 ";
$sql .= "WHERE id =".$id;
$result = mysql_query($sql) or die(mysql_error());

}

// Select box

$options = array("$ten", "$nine", "$eight", "$seven", "$six", "$five", "$four", "$three", "$two", "$one");

$this->rate .= "<form name=\"rate\" action=\"".substr($DEFAULT_URL, 0, strlen($DEFAULT_URL)-1)."/rate.php\" method=\"post\">\n";
$this->rate .= "<select name=\"go\">\n";

for ($i = 0; $i < count($options); $i++)
$this->rate .= "<option name = \"$options[$i]\">$options[$i]</option>\n";

$this->rate .= "</select>\n";
$this->rate .= "<input type=\"hidden\" name=\"file\" value=\"$this->file\">\n";
$this->rate .= "<input type=\"hidden\" name=\"file_real\" value=\"$this->file_real\">\n";
$this->rate .= "<input type=\"submit\" value=\"$formrate\">\n";
$this->rate .= "</form>\n";


} // end else
if ($this->go<>"Rate") {

switch ($this->go) {

case "$ten": $Rate = 10;
break;

case "$nine": $Rate = 9;
break;

case "$eight": $Rate = 8;
break;

case "$seven": $Rate = 7;
break;

case "$six": $Rate = 6;
break;

case "$five": $Rate = 5;
break;

case "$four": $Rate = 4;
break;

case "$three": $Rate = 3;
break;

case "$two": $Rate = 2;
break;

case "$one": $Rate = 1;
break;

}
$sql = "SELECT Item, Rating, Votes, Num_Votes,viewed FROM Rate ";
$sql .= "WHERE Item = '$file' ";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);

$new = $row[3] + 1;
$row[2] = $row[2] + $Rate;
$row[1] = round(($row[2] / $new), 2);

$numberofvotes=$new;
$viewed=$row["viewed"];


// Update Rating

if(!$isMarked)
{
$sql = "UPDATE Rate set Num_Votes='$new', Votes='$row[2]', Rating='$row[1]', IP='$ip_address' ";
$sql .= "WHERE Item = '$file' ";

$retid = mysql_query($sql);
if (!$retid) { echo( mysql_error()); }

$this->setIp($id);
}


$br = "<br><br>";
$redirect_body = "<BODY onLoad=\"redirTimer()\">";

$redirect = "
<SCRIPT LANGUAGE=\"JavaScript\">
<!-- Begin
redirTime = \"5000\";
redirURL = \"".$DEFAULT_URL_MOD."$this->file_real\";
function redirTimer() { self.setTimeout(\"self.location.href = redirURL;\",redirTime); }
// End -->
</script>";
if ($result) {
$this->output = "<html><head>";
$this->output .= "<title>$line1</title>";
$this->output .= "$redirect</head><body>\n";
$this->output .= "<blockquote>$br $line2 $br\n";
$this->output .= "$line3 <strong>$row[1]</strong>$br\n";
$this->output .= "$br $line4 $br\n";
$this->output .= "$numberof $numberofvotes $br\n";
$this->output .= "<br><strong>".$hasread1.$viewed.$hasread2."</strong><br>\n";
$this->output .= "$br <a href=\"$file\">$line5$br</a>\n";
$this->output .= "$br</blockquote>$redirect_body</body></html>\n";
} // end if

} // end if

mysql_close($db);

}// end Rating

function getRating()

{

return $this->rate;

}//end setIdDomenii

function getResult()

{

return $this->output;

}//end setIdDomenii


function setIp($id){
global $DEFAULT_URL,$DB_HOST,$DB_USR,$DB_PWD,$DB_NAME,$TIME_EXPIRE,$datamissi ng;


$remote_addrs = $_SERVER['REMOTE_ADDR'];

if(empty($_SERVER['REMOTE_HOST']))
$remote_host=$remote_addrs;
else
$remote_host=$_SERVER['REMOTE_HOST'];

if(empty($_SERVER['HTTP_USER_AGENT']))
$user_agent=$datamissing;
else
$user_agent=$_SERVER['HTTP_USER_AGENT'];


$db = mysql_connect($DB_HOST, $DB_USR, $
Author Anonymous
Guest
#2 Posted: 6 Dec 2003 02:36:31
Reply 
or die ("Could not connect to database");
mysql_select_db($DB_NAME, $db);

$sql = "Update Logger set viewed=viewed+1 ";
$sql .= "WHERE regtime >= now() AND ";
$sql .= "id=$id AND ";
$sql .= "remote_addrs='$remote_addrs'";

$result = mysql_query($sql) or die(mysql_error());

if(mysql_affected_rows()==0)
{
$sql = "INSERT INTO Logger (id,remote_addrs,remote_host, user_agent,regtime,viewed)";
$sql .= " VALUES ('$id','$remote_addrs','$remote_host','$user_agent',DATE_ADD(now(),INT ERVAL $TIME_EXPIRE SECOND),0)";
$result = mysql_query($sql) or die(mysql_error());
return true;

}
else
return false;


}


function isMarked($id){
global $DEFAULT_URL,$DB_HOST,$DB_USR,$DB_PWD,$DB_NAME,$TIME_EXPIRE;


$remote_addrs = $_SERVER['REMOTE_ADDR'];


$db = mysql_connect($DB_HOST, $DB_USR, $DB_PWD)
or die ("Could not connect to database");
mysql_select_db($DB_NAME, $db);


$sql = "Select count(id) from Logger ";
$sql .= "WHERE regtime >=now() AND ";
$sql .= "id=$id AND ";
$sql .= "remote_addrs='$remote_addrs'";

$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);

if($row[0]!=0)
{

$sql = "Update Logger set viewed=viewed+1 ";
$sql .= "WHERE regtime >= now() AND ";
$sql .= "id=$id AND ";
$sql .= "remote_addrs='$remote_addrs'";

$result = mysql_query($sql) or die(mysql_error());


}

return $row[0];

}



}// end class

?>



en.inc.php:

<?php
/*
################# STAR RATING SYSTEM ##################
############################################################
CWB PRO $Name: $
Revision $Revision: 1.3 $
Author $Author: lvalics $
Created 03/01/02 $Date: 2003/08/16 15:43:23 $
Writed by GraFX (it@grafx.ro)
Scripts Home: http://software.grafx.ro
############################################################
File purpose LANGUAGE FILE ENGLISH
############################################################
*/

$notyetrated = "Not yet rated";
$rated = "Rated:";
$from = "from";
$altrate = "Rate";
$recentrated = "You have recently rated this article.";
$ten = "10";
$nine = "9";
$eight = "8";
$seven = "7";
$six = "6";
$five = "5";
$four = "4";
$three = "3";
$two = "2";
$one = "1";
$formrate = "RATE";
$line1 = "Thank you for your rateing.";
$line2 = "Thank you for your rateing.";
$line3 = "The article now has a rating of";
$line4 = "You will now be redirected back to the article.";
$line5 = "Click here if this does not happen.";
$hasread1 = "This article has been seen ";
$hasread2 =" times.";
$numberof = "Number of Votes: ";
$datamissing="unknown";
?>



Dimitar Koleshev
Author software
Admin
#3 Posted: 7 Dec 2003 18:57:26
Reply 
You have worked on it ... I hope will help a lot of users.
Author mihaitza
Forums Member
#4 Posted: 20 Mar 2004 22:41:09
Reply 
do you have an final php file?
Author Anonymous
Guest
#5 Posted: 22 Jan 2005 19:38:58
Reply 
that didnt work for me but i would also prefer 1-10 instead of excellent etc...

i got this error after copy and pasting this coding.

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/barnesey/public_html/rating/cls_rate.php on line 248

any idea whats wrong?
Author software
Admin
#6 Posted: 22 Jan 2005 19:41:43
Reply 
We do not support this hack, but that parse error can be a line ending ;
Check your code again.
Author theprynce
Guest
#7 Posted: 10 Apr 2005 11:12:27
Reply 
It's probably best to search the code that you already have for terms such as "excellent" and the above code for words like "ten" and just replace them in your own script as needed. That would probably be the safest way. That's how I did it.

-=The Prynce
 
Your Reply

» Username  » Password 
Only registered users are allowed to post here. Please enter your login/password details upon posting a message, or sign up first.