Gossamer Forum
Home : Products : Links 2.0 : Customization :

Help Needed - Multiple "Rate It" possible??

Quote Reply
Help Needed - Multiple "Rate It" possible??
Hi!
I need help customizing the rate process.
I would like to allow visitors to make a multiple-rate with the same "click".
I will own 2 different databases, but many of the URLs will be displayed at both, so instead of having 2 different "Rate It" I would offer the owners of the URLs a unique "Rate It" with which the visitors post their vote on both databases... even if for each owner I have to create the html code individually.
I´m not a newbie in Perl... I´m just a LAMMER, so I would thank any kind of help... :)
Thank you very much.

Quote Reply
Re: Help Needed - Multiple "Rate It" possible?? In reply to
Copy the original rate.cgi and rename it to rate2.cgi for instance:

Then replace the sub rate it with the following:


sub rate_it {
# --------------------------------------------------------
my $id = $in{$db_key};
my $delim = quotemeta($db_delim);
my $time = time();
my $rating = $in{'rate'};

# Make sure we have a valid rating.
unless (($rating =~ /^\d\d?/) and ($rating >= 1) and ($rating <= 10)) {
&site_html_rate_failure ("Your rating '$rating' is invalid.");
return;
}

# Let's get the link information.
my %rec = &get_record ($id);
($rec{$db_key} eq $id) or (&site_html_rate_failure ("Unable to find link with ID '$id'.") and return);

# Increase the rating.

if (open (HIT, "<$db_rates_path/$id")) {
my $input = <HIT>; chomp $input;
($votes, $old_rating) = split /\s/, $input;
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;

if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$votes = $votes + 1;
$rating = $rating + $old_rating;
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$votes $rating\n$time\n@IP";
close HIT;

open (HIT2, ">second location/$id") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT2, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT2 "$votes $rating\n$time\n@IP";
close HIT2;

&site_html_rate_success;
}
else {
&site_html_rate_failure ("Sorry, you've already rated for this resource once recently.");
}
}
else {
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't increment counter file '$db_rates_path/$id'. Reason: $!");
print HIT "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;

open (HIT2, ">second location/$id") or &cgierr ("Can't increment counter file 'second location/$id'. Reason: $!");
print HIT2 "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT2;

&site_html_rate_success;
}
}


Changing the pieces in red to the path of where the files are in your second directory.

Good Luck!

Glenn


http://mir.spaceports.com/~glennu/