Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: Bad Links Mod for LSQL2

Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
NB: To use the spidering for checking the status of the link which is reported as bad you need the LWP Perl module installed.

OK - here we go:

First make a copy of rate.cgi and call it badlink.cgi
In that add the line
Code:
use LWP::UserAgent;
after
Code:
use GT::Mail;
Then, in sub main:
delete or comment out the following lines (right at the beginning of the sub)
Code:
# Make sure we are allowed to rate it.
if ($CFG->{user_rate_required} and ! $USER) {
print $IN->redirect( Links::redirect_login_url ('rate') );
return;
}
In the lines directly after that, change all references to template names from rate.cgi to the badlink equivalents (changes marked red here):

Code:
# Now figure out what to do.
if ($IN->param('reason')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'bad_link', \&report_it, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('badlink_error', $results);
}
else {
print $IN->header();
print Links::SiteHTML::display ('badlink_success', $results);
}
}
elsif (defined $id and ($id =~ /^\d+$/)) {
print $IN->header();
my $db = $DB->table('Links');
my $rec = $db->get ($id);
$rec ?
print Links::SiteHTML::display ('badlink', $rec) :
print Links::SiteHTML::display ('badlink_error', { error => Links::language('BADLINK_INVALIDID', $id) });
}
else {
$IN->param('d') ?
print $IN->redirect ("$CFG->{db_cgi_url}/page.cgi") :
print $IN->redirect ($CFG->{build_root_url});
}
}
Then change the name of the sub "rate_it" of the original script to "report_it". Here is the modified sub. It contains code from the original rate.cgi, some of add.cgi (for mailing the admin) and essentially from the badlink-mod for LSQL1 from Chris Ihlenfeld (http://www.digital-concepts.net/links-sql/bad_link.html).

Code:
sub report_it {
# --------------------------------------------------------
# report a link as bad
#
# get the link id
my $id = $IN->param('ID');
# user submitted form fields from template badlink.html
my $reason = $IN->param('reason');
my $comment = $IN->param('comment');
my $usermail = $IN->param('usermail');
# auto generated url of refering page where the user clicked on the link 'report link as bad'
my $goback = $IN->param('goback');

# Let's get the link information.
my $db = $DB->table('Links');
my $rec = $db->get ($id);
$rec or return { error => Links::language('BADLINK_INVALIDID', $id) };

# Lets try to spider the url and see what happens
my ($ua,$req,$res,$page,$message);
$ua = LWP::UserAgent->new();
$ua->agent('Your personal spiders name');
$ua->timeout(30); # set this to what you want in seconds.
$req = new HTTP::Request('GET',(${$rec}{'URL'}));
$res = $ua->request($req);
$message = $res->status_line;


###################################
# send mail to admin
my ($to, $from, $subject, $msg, $host, $refer, $error);
$to = $CFG->{db_admin_email};
$from = $usermail;
$subject = "Bad Link: ID $id -> $reason\n";
$host = defined $ENV{REMOTE_HOST} ? "$ENV{REMOTE_HOST} ($ENV{REMOTE_ADDR})" : 'none';
$refer = defined $ENV{HTTP_REFERER} ? $ENV{HTTP_REFERER} : 'none';
$msg = qq|
The following link was reported as bad:
ID: $id
Title: $rec->{'Title'}
URL: $rec->{'URL'}
Description: $rec->{'Description'}
----------------------------------------------
Problem: $reason
Spider Diagnosis: $message
--[comment]---------------------------------
$comment
----------------------------------------------
User-Mail: $usermail
To change this link go to:
$CFG->{admin_root_url}/admin.cgi

Sincerely,

Links Manager.
|;

# Send to the admin.
require GT::Mail;
$GT::Mail::error ||= ''; # Silence -w
GT::Mail->send (
smtp => $CFG->{db_smtp_server},
sendmail => $CFG->{db_mail_path},
from => $from,
subject => $subject,
to => $to,
msg => $msg,
debug => $Links::DEBUG
) or Links::fatal ("Unable to send mail: $GT::Mail::error");
####################################################

return $rec;
}
That's it for the badlink.cgi script.

Next: the templates "badlink.html", "badlink_succes.html" and "badlink_error.html" which are to be placed in the default template folder.

In badlink.html you need a form like this one (the important variables marked red):

Code:
<form action="<%db_cgi_url%>/badlink.cgi" method="POST">
<input type=hidden name="ID" value="<%ID%>">
<input type="hidden" name="goback" value="<%ref_page%>">

<h3>Report Bad Link</h3>

<p>On this page you can report the following link as bad:</p>

<ul><li><a href="<%URL%>"><%Title%></a>
<%if Description%>

<%Description%>
<%endif%>
</ul>

<p>We will check this link and correct or delete it accordingly.</p>
<p>Please select the problem you are encountering when visiting the page
<a href="<%URL%>"><%Title%></a>.</p>

<p>Problem description:
<select name="reason">
<option>page not found (error 404)</option>
<option>page has new URL</option>
<option>server not found (DNS error)</option>
<option>server not responding</option>
<option>authorization required (error 401)</option>
<option>internal server error (error 500)</option>
<option>link description is not correct</option>
<option>other problem</option>
</select>
</p>
<p>Your comment (eg. a new URL, or what you'd like to see as the link's description etc.):

<textarea name="comment" rows="4" cols="38"></textarea></p>
<p>Your email: <input type="text" name="usermail" size="30"></p>
<p><input type=submit value="Report it!"></p>
</FORM>
In badlink_error.html just place
Code:
<%error%>
where you want the error message to appear. Additionally you can give the user the possibility to return to the page where he clicked on "report link as bad":
Code:
<A HREF="<%goback%>">go back</a>
In badlink_success.html you should give the user feedback that he successfully reported the link:
Code:
<h3>Thank you!</h3>
<BLOCKQUOTE>
<P>You successfully reported the following link as bad:</p>
<ul><li><a href="<%URL%>"><%Title%></a>
<%if Description%>

<%Description%>
<%endif%>
</ul>
<p>We will check this link and correct or delete it accordingly.</P>
<P>[<A HREF="<%goback%>">go back</a>]</P>
</BLOCKQUOTE>
To make the "goback" link work you have to add the global ref_page (in the links admin -> build -> template globals)
Code:
sub {
# Displays the refering URL
my $refoutput = $ENV{HTTP_REFERER};
return $refoutput;
}
Finally, in the "user language" section of the admin you have to add BADLINK_INVALIDID for the error message - something like "Unable to find link with ID: '%s'."

I hope these explanations will help to make the whole thing a plugin. I think the possibilites of the plugin technology are very exciting and hopefully it helps me to better understand it if someone takes my chunks of code and forges a plugin of it.

Good Luck!

Andreas Brunn

--------------------------------------------
http://www.archaeologie-online.de
Subject Author Views Date
Thread Bad Links Mod for LSQL2 ? Digger 7254 Feb 7, 2001, 7:05 AM
Thread Bad Links Mod for LSQL2
Digger 7050 Feb 8, 2001, 5:43 AM
Thread Re: Bad Links Mod for LSQL2
Chef 6993 Feb 10, 2001, 2:36 AM
Thread Re: Bad Links Mod for LSQL2
Robert_B 7022 Feb 10, 2001, 5:50 AM
Thread Re: Bad Links Mod for LSQL2
Digger 7006 Feb 10, 2001, 9:34 AM
Thread Re: Bad Links Mod for LSQL2
Stealth 6970 Feb 10, 2001, 10:58 AM
Thread Re: Bad Links Mod for LSQL2
Paul 7044 Feb 10, 2001, 11:21 AM
Thread Re: Bad Links Mod for LSQL2
Stealth 7015 Feb 10, 2001, 11:29 AM
Thread Re: Bad Links Mod for LSQL2
Paul 7019 Feb 10, 2001, 11:34 AM
Thread Re: Bad Links Mod for LSQL2
padders 6999 Feb 10, 2001, 1:31 PM
Thread Re: Bad Links Mod for LSQL2
Paul 7040 Feb 10, 2001, 1:33 PM
Thread Re: Bad Links Mod for LSQL2
padders 7271 Feb 10, 2001, 1:40 PM
Post Re: Bad Links Mod for LSQL2
padders 7005 Feb 10, 2001, 1:41 PM
Post Re: Bad Links Mod for LSQL2
Paul 6954 Feb 10, 2001, 1:43 PM
Thread Re: Bad Links Mod for LSQL2
Stealth 6983 Feb 10, 2001, 1:59 PM
Post Re: Bad Links Mod for LSQL2
Paul 7007 Feb 10, 2001, 2:01 PM
Post Re: Bad Links Mod for LSQL2
Alex 6970 Feb 10, 2001, 3:59 PM
Post Re: Bad Links Mod for LSQL2
Chef 6922 Feb 13, 2001, 11:19 AM