Gossamer Forum
Home : Products : Links 2.0 : Customization :

comments4 mod combined with rate.cgi?!?

Quote Reply
comments4 mod combined with rate.cgi?!?
im pretty sure this would be handy but i am not enough of a perl guru to do it but it would be really nice to combine the comments 4 mod ( http://cgi-resource.co.uk/pages/comment4l.html ) with the standard rate.cgi that comes with links 2.0. That way when someone posts a review with a rating - it will not only post thier rating with their review but also count toward the links rating on the rate.cgi and therefore on the top ten page... anybody have any ideas on how to do this?




Vote Stinky
Quote Reply
Re: [security_man] comments4 mod combined with rate.cgi?!? In reply to
Well, here's an idea...

1) Add this to the comments4l, sub display routine:

Code:
require "$db_lib_path/links.def";
if ($in{$db_key} =~ /^\d+$/) {
my (%rek) = &get_record ($in{$db_key});
($rek{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rek) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}

my %rec = &get_record ($in{'LID'});
$pheader= "There are $links comments for <b>$rec{'Title'}</b>
<br><br>(<b>$rate1</b> people liked the site)
(<b>$rate2</b> thought it was okay)
(<b>$rate3</b> didn't like it)

";





2) And the sub main routine:

Code:
sub main {
#-------------------------------------------------------------------
local (%in) = &parse_form;
if ($in{'function'} eq 'post_comment'){
&post_comment;
}
if ($in{'rate'}) {
&rate_it;
}

elsif ($in{'function'} eq 'display'){
&display;
}
else {
&site_error;
}
}





3) Copy the sub rate_it routine from rate.cgi into comments4.cgi.


Change the HTML of the comments page. The original rate page HTML is below, with the form tags removed. Put this between the form tags in the comment page:

<input type=hidden name="ID" value="<%ID%>">
<p>Please rate the link <strong><a href="<%URL%>"><%Title%></a></strong> between one and ten, with ten being tops.</p>
<div class="margin">
<p><select name=rate>
<option>---
<option>1
<option>2
<option>3
<option>4
<option>5
<option>6
<option>7
<option>8
<option>9
<option>10
</select>
<input type=submit value="Rate this Link">
</p>
</div>

The comment display page should probably be changed to reflect the Links rating system, too. And probably remove the Comments rating system.

Could be wrong... Unsure

That should be enough to keep ya busy fer awhile!


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Jan 30, 2006, 11:31 AM
Quote Reply
Re: [PerlFlunkie] comments4 mod combined with rate.cgi?!? In reply to
you were darn close leonard, my man... here is the way i got it to work
i will start from the beginning in case someone else wants to do this (all credit to leonard for the starting point)...


in comments4l.cgi

1) add this subroutine before sub display
Code:
sub rate_it {
# --------------------------------------------------------
require "$db_lib_path/links.def";
my $id = $in{'LID'};
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;

}
else {
;
}
}
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;

}
}


2) add what is in red to sub display routine:

Code:
require "$db_lib_path/links.def";
if ($in{$db_key} =~ /^\d+$/) {
my (%rek) = &get_record ($in{$db_key});
($rek{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rek) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}

my %rec = &get_record ($in{'LID'});
$pheader= "There are $links comments for <b>$rec{'Title'}</b>
<br><br>(<b>$rate1</b> people liked the site)
(<b>$rate2</b> thought it was okay)
(<b>$rate3</b> didn't like it)

";
[/code]


3) still in sub display, replace
Code:
require "$db_lib_path/links.def";
my %rec = &get_record ($in{'LID'});

$pheader= "There are $links comments for <b>$rec{'Title'}</b>
<br><br>(<b>$rate1</b> people liked the site)
(<b>$rate2</b> thought it was okay)
(<b>$rate3</b> didn't like it)

";

with
Code:
require "$db_lib_path/links.def";
if ($in{$db_key} =~ /^\d+$/) {
my (%rek) = &get_record ($in{$db_key});
($rek{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rek) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}
my %rec = &get_record ($in{'LID'});

$pheader= "There are $links comments for <b>$rec{'Title'}</b>
<br><br>Overall it is rated $rec{'Rating'} on a scale of 1 to 10 (ten being best)

";

4) yet still in sub display replace
Code:
<INPUT type="radio" name=Rating value = 2><IMG SRC="$db_images/up.jpg" ALT="Great site">
<INPUT type="radio" name=Rating value = 1><IMG SRC="$db_images/okay.jpg" ALT="Okay site">
<INPUT type="radio" name=Rating value = 0><IMG SRC="$db_images/down.jpg" ALT="Terrible site">

with
Code:
<p><select name=rate>
<option>---
<option>1
<option>2
<option>3
<option>4
<option>5
<option>6
<option>7
<option>8
<option>9
<option>10
</select>

5) in sub post_comment add what is in red
Code:
close DB;
&rate_it;
my ($key, $status, $line, $output);
$name = $in{'Contact Name'};



6) in site_html_templates.pl replace the entire sub site_html_commenter2 routine with
Code:

sub site_html_commenter2 {
# --------------------------------------------------------
# This routine is used to display what a comment/review should look
# like.
my %rec = @_;

return &load_template ('comment4.html', {
ratepict => $rec{'Rating'},
%rec,
%globals
});
}



I think that is everything... hope it helps :)




Vote Stinky
Quote Reply
Re: [security_man] comments4 mod combined with rate.cgi?!? In reply to
crap... i screwed up one thing...

it should be
5) in sub post_comment add what is in red
Code:
&site_html_comments4l;&send_add_email;
&rate_it;
}
else {

&site_error($status) and return;
}




Vote Stinky