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

Star rating visible in outside pages

 
Author Anonymous
Guest
#1 Posted: 6 Dec 2003 05:19:20
Reply 
This is only a trial. This simple hack is not profesional work. I make this without have any knowledges in PHP. The rezult: last rating number is visible in outside pages. Please help made good hack.
This is my attempt:

I make new file cls_rate_outside.php:

<?php
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, $DB_PWD)
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($D
Author Anonymous
Guest
#2 Posted: 6 Dec 2003 20:15:19
Reply 
Sorry, this above my big error. Next is my real hack. Please delete above 2 replies.



I make new file outside_rating.php:

<?php

include_once("config.inc.php");
include_once($RATE_PATH."cls_rate.php");
include_once("cls_fast_template.php");
include_once("$LANG.inc.php");

$db = mysql_connect($DB_HOST, $DB_USR, $DB_PWD)
or die ("Не може да бъде осъществена връзка с базата данни");
mysql_select_db($DB_NAME, $db);
$sql = "SELECT id FROM Rate ";
$sql .= "WHERE Item = '$file'";
$result = mysql_query($sql) or die("Заявката не се изпълни");
$row = mysql_fetch_array($result);

$file=$id;

function Rating($id)
{
$sql = "SELECT Rating FROM Rate ";
$sql .= "WHERE id = '$id' ";
$result = mysql_query($sql) or die("Грешка");
$ar = mysql_fetch_array($result);
$rating = $ar[Rating];
if(empty($rating) || $rating<0) $rating=0;

echo $rating;
}
?>





This is outside page xxx.php

<?include("outside_rating.php");?>

<html>
<head>
<title>Рейтинг</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body>
Rating: <?Rating(1);?>
Rating: <?Rating(2);?>
Rating: <?Rating(3);?>
</body>
</html>


About every other rating you only change id number: 1,2,3. This is id in Rate table in your MySQL. Please test this hack and help make better.

Dimitar Koleshev
Author software
Admin
#3 Posted: 7 Dec 2003 18:59:55
Reply 
OK, we will try to test it and if is helpfull, to include in next release.
Author theprynce
Guest
#4 Posted: 10 Apr 2005 11:27:47
Reply 
Hm... Kinda old code but I like it. Seems to make things simpler, though I'm not very knowledgable of PHP.

Anyone know if it has been included in any releases of Star Rating System?

-=The Prynce
Author software
Admin
#5 Posted: 10 Apr 2005 14:02:39
Reply 
No, it was not inlcluded, we have don it with JavaScript the multiple rating.
Author convinceme
Forums Member
#6 Posted: 16 Apr 2005 03:43:48
Reply 
nice helpful code but its not showing any images of the ranks :S how do i make those visible?
Author software
Admin
#7 Posted: 16 Apr 2005 08:52:04
Reply 
You need to have some PHP knowledge to modify the hacks what is on this forum. We cannot guarantee that people who posted here will help you. Especially because was posted as anonymous and they not get a mail from forum in this case. But is a clue fo your hack anyway :-))
Author convinceme
Forums Member
#8 Posted: 16 Apr 2005 18:12:44
Reply 
oh ok well i got the hack working ... its showing me the the number of rank only.. i thought u could help with telling how to show images too :S
 
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.