Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Bad Links Mod for LSQL2 ?

Quote Reply
Bad Links Mod for LSQL2 ?
Hi,

two months ago somebody asked how to port the bad links mod from LSQL1 to LSQL2. I found the following thread in the forum:
http://www.gossamer-threads.com/...w=collapsed&sb=5

but unfortunately I still have no idea where exactly I have to enter the mentioned code to make it work.

Did anybody do a port for that mod to a plugin already?
If not: could someone please point me to the right direction?
Of course a step by step instruction would be much appreciated. Wink

Andreas

--------------------------------------------
http://www.archaeologie-online.de
Quote Reply
Bad Links Mod for LSQL2 In reply to
Finally I figured out how to solve the problem.

I am now using a modified version of rate.cgi (now badlink.cgi) plus the templates badlink.html, badlink_succes.html and badlink_error.html and it works fine for my site now.

I am not quite familiar with plugin authoring, so I didn't make it a plugin. Maybe I will do this later.

Andreas

--------------------------------------------
http://www.archaeologie-online.de
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Hi,

could you please post the changes you've done for this?

Thanks

Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Yes, please do, maybe I'll make this into a plugin.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
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
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
How about saving the codes into text files and then added a link to where your text files are located? It is virtually impossible to copy codes from the forum to make them work properly in files.

Just a suggestion.

Regards,

Eliot Lee
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
I would have thought you'd be able to write that code yourself. Smile

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Uh...I already am using similar and less codes in my script, Paul! Tongue

And I made the suggestion to help out novice users who are not familar with Perl coding. "think globally"

Regards,

Eliot Lee
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Im sure you are using similar codes.....now.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
is there no
Code:
tag in wwwthreads?

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Pardon?

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
most forums ubb and vbulletin have a code tag. You do

Code:
amd fksadfkl
sdf k
sadfkj ksdf
and it just prevents any mucking up of the code.



http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
arr it does have it,

i thought that elliot was worried about this, that the forum mucks up the html and code, i guess it shouldn't so don't see what the problem is.

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
ohhhhh

no i dont think wwwthreads does, or not on this forum at least.

It is annoying when you copy some code and it squidges in to a big block (tech term)



Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Uh...I already wrote another type of modification a long time ago, PAUL! Wink

Regards,

Eliot Lee
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Good for you. Laugh

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
If you are feeling daring, you can replace LWP, with GT::URI::HTTP and then it will work for everyone's copy. =)

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Bad Links Mod for LSQL2 In reply to
Digger,

(edit) found my bug - sorry ...