OK...I used Jerry's code for MyLinks for Links SQL 1.13 and have tried to modify it to work with NG.
Can Jerry/Pugdog/Anthro or other perl "gurus" please take a look at this code and try to erradicate afew of the errors. I have done "perl mylinks.cgi" when I was logged into my SSH account and it produced no syntax errors or any other errors, but when I execute the script is gives me an internal server error so the code must be incorrect still to work with NG.
The code is likely to be totally wrong but I am trying my best :)
Here is the code I have so far:
#!/usr/bin/perl
# Load required modules.
# ---------------------------------------------------
use strict;
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib '/MY/FULL/PATH/TO/ADMIN/admin';
use Links;
use Links::SQL;
use Links::Tools;
use Links::SiteHTML;
use Links::Link;
use vars qw!$DB $USER $IN!;
&main ();
sub main {
# --------------------------------------------------------------
# Determine what to do.
#
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
$DB = new Links::SQL "$Links::CFG->{admin_root_path}/defs/Links.def";
my $s = $in->param('s') || $in->cookie('s');
$USER->{Referer} = $ENV{HTTP_REFERER};
print $in->header ();
if ($in->param('add')) {
&add ($in, $dynamic);
}
elsif ($in->param('delete')) {
&delete ($in, $dynamic);
}
else {
&display ($in, $dynamic);
}
}
sub add {
# --------------------------------------------------------
# Adds an ID into the users links.
#
my ($in, $dynamic) = @_;
my $id = $in->param('add');
my @c = split /\|/, $USER->{MyLinks};
my $args = $IN->get_hash;
# Make sure we have a valid link.
my $rec = $DB->get_record ($id, $args);
$rec or &site_html_my_add_error ({ error => "Unkown Link ID: '$id'." }, $dynamic) and return;
# Check to see if the ID is in the database.
my %c = map { $_ => 1 } @c;
$c{$id} and &site_html_my_add_error ({ error => "Link Already Added '$id'." }, $dynamic) and return;
# Update the database.
push (@c, $id);
@c = sort { $a <=> $b } @c;
$" = $Links::CFG->{MYLINKS_DELIM};
$DB->do ("UPDATE Users SET MyLinks = '@c' WHERE Username = '$$USER{Username}'");
# Display the add page.
&site_html_my_add ($rec, $dynamic);
}
sub delete {
# --------------------------------------------------------
# Deletes an ID from the users cookie.
#
my ($in, $dynamic) = @_;
my $id = $in->param('delete');
my @c = split /\|/, $USER->{MyLinks};
my $args = $IN->get_hash;
if ($id =~ /all/i) {
$DB->do ("UPDATE Users SET MyLinks = '' WHERE Username = '$$USER{Username}'");
&site_html_my_delete_all ($USER, $dynamic);
return;
}
# Make sure we have a valid ID.
my $rec = $DB->get_record ($id, $args);
$rec or &site_html_my_delete_error ({ error => "Unkown Link ID: '$id'." }, $dynamic) and return;
# Check to see if the ID is in the database.
my %c = map { $_ => 1 } @c;
$c{$id} or &site_html_my_delete_error ({ error => "Link Not in Database '$id'." }, $dynamic) and return;
# Update the database.
@c = grep {!/^$id$/} @c;
$" = $Links::CFG->{MYLINKS_DELIM};
$DB->do ("UPDATE Users SET MyLinks = '@c' WHERE Username = '$$USER{Username}'");
# Display the delete page.
&site_html_my_delete ($rec, $dynamic);
}
sub display {
my ($in, $dynamic) = @_;
my @c = split /\|/, $USER->{MyLinks};
# Get total of links.
$USER->{Total} = @c || 0;
if (@c) {
$USER->{Pages} = int $$USER{Total}/$Links::CFG->{MYLINKS_PERPAGE} (($$USER{Total} % $Links::CFG->{MYLINKS_PERPAGE}) ? 1 : 0);
$USER->{Page} = $in->param('p') || 1;
$USER->{Page} = (($$USER{Page} > $$USER{Pages}) ? 1 : $$USER{Page});
$USER->{Start} = ($$USER{Page}-1) * $Links::CFG->{MYLINKS_PERPAGE};
$USER->{Finish} = $USER->{Start};
# Build span pages.
if ($USER->{Pages} > 1) {
my $prev = $USER->{Page} - 1;
my $next = $USER->{Page} 1;
if ($$USER{Page} > 1) {
$USER->{Span} = qq~<a href="$ENV{SCRIPT_NAME}~;
$USER->{Span} .= qq~?p=$prev~ if ($prev > 1);
$USER->{Span} .= qq~"><b>< Previous</b></a> <a href="$ENV{SCRIPT_NAME}">1</a> ~;
if ($prev > 1) {
for (2 .. $prev) { $USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$_">$_</a> ~; }
}
}
else { $USER->{Span} = qq~< Previous ~; }
$USER->{Span} .= qq~<b>$$USER{Page}</b> ~;
if ($$USER{Page} < $$USER{Pages}) {
for ($next .. $$USER{Pages}) { $USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$_">$_</a> ~; }
$USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$next"><b>Next ></b></a>~;
}
else { $USER->{Span} .= qq~Next >~; }
}
# Get the links to display.
$" = ",";
my $sth = $DB->prepare ("SELECT * FROM Links WHERE ID IN (@c) ORDER BY $Links::CFG->{MYLINKS_ORDER} LIMIT $$USER{Start}, $Links::CFG->{MYLINKS_PERPAGE}");
$sth->execute() or die $DBI::errstr;
while (my $rec = $sth->fetchrow_hashref) {
$USER->{Links} .= &site_html_my_link ($rec, $dynamic);
$USER->{Finish} ;
}
$USER->{Start} ;
}
# Display the home page.
&site_html_my_home ($USER, $dynamic);
}
I have got all the templates in my default templates directory and have added the following code for each template into SiteHTML.pm...
sub site_html_my_home {
# --------------------------------------------------------
# Return parsed category page.
#
my $tags = shift;
my $output = Links::load_template ('my_home.html', $tags, 1);
return $output;
}
(Not sure if im meant to to that or not)[/red]
I would be really grateful if someone could tell me what ive done wrong (If youve got a few hours spare to fix my code)...lol
This bit is bothering me $" = $Links::CFG->{MYLINKS_DELIM}; and this bit $Links::CFG->{MYLINKS_ORDER};...oh and also....$Links::CFG->{MYLINKS_PERPAGE};.
Do I have to add some code to /Links/Config.pm or /Links/ConfigData.pm ???
THANKS
Paul Wilson.
(Dont blame me if I'm wrong!)
Can Jerry/Pugdog/Anthro or other perl "gurus" please take a look at this code and try to erradicate afew of the errors. I have done "perl mylinks.cgi" when I was logged into my SSH account and it produced no syntax errors or any other errors, but when I execute the script is gives me an internal server error so the code must be incorrect still to work with NG.
The code is likely to be totally wrong but I am trying my best :)
Here is the code I have so far:
#!/usr/bin/perl
# Load required modules.
# ---------------------------------------------------
use strict;
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib '/MY/FULL/PATH/TO/ADMIN/admin';
use Links;
use Links::SQL;
use Links::Tools;
use Links::SiteHTML;
use Links::Link;
use vars qw!$DB $USER $IN!;
&main ();
sub main {
# --------------------------------------------------------------
# Determine what to do.
#
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
$DB = new Links::SQL "$Links::CFG->{admin_root_path}/defs/Links.def";
my $s = $in->param('s') || $in->cookie('s');
$USER->{Referer} = $ENV{HTTP_REFERER};
print $in->header ();
if ($in->param('add')) {
&add ($in, $dynamic);
}
elsif ($in->param('delete')) {
&delete ($in, $dynamic);
}
else {
&display ($in, $dynamic);
}
}
sub add {
# --------------------------------------------------------
# Adds an ID into the users links.
#
my ($in, $dynamic) = @_;
my $id = $in->param('add');
my @c = split /\|/, $USER->{MyLinks};
my $args = $IN->get_hash;
# Make sure we have a valid link.
my $rec = $DB->get_record ($id, $args);
$rec or &site_html_my_add_error ({ error => "Unkown Link ID: '$id'." }, $dynamic) and return;
# Check to see if the ID is in the database.
my %c = map { $_ => 1 } @c;
$c{$id} and &site_html_my_add_error ({ error => "Link Already Added '$id'." }, $dynamic) and return;
# Update the database.
push (@c, $id);
@c = sort { $a <=> $b } @c;
$" = $Links::CFG->{MYLINKS_DELIM};
$DB->do ("UPDATE Users SET MyLinks = '@c' WHERE Username = '$$USER{Username}'");
# Display the add page.
&site_html_my_add ($rec, $dynamic);
}
sub delete {
# --------------------------------------------------------
# Deletes an ID from the users cookie.
#
my ($in, $dynamic) = @_;
my $id = $in->param('delete');
my @c = split /\|/, $USER->{MyLinks};
my $args = $IN->get_hash;
if ($id =~ /all/i) {
$DB->do ("UPDATE Users SET MyLinks = '' WHERE Username = '$$USER{Username}'");
&site_html_my_delete_all ($USER, $dynamic);
return;
}
# Make sure we have a valid ID.
my $rec = $DB->get_record ($id, $args);
$rec or &site_html_my_delete_error ({ error => "Unkown Link ID: '$id'." }, $dynamic) and return;
# Check to see if the ID is in the database.
my %c = map { $_ => 1 } @c;
$c{$id} or &site_html_my_delete_error ({ error => "Link Not in Database '$id'." }, $dynamic) and return;
# Update the database.
@c = grep {!/^$id$/} @c;
$" = $Links::CFG->{MYLINKS_DELIM};
$DB->do ("UPDATE Users SET MyLinks = '@c' WHERE Username = '$$USER{Username}'");
# Display the delete page.
&site_html_my_delete ($rec, $dynamic);
}
sub display {
my ($in, $dynamic) = @_;
my @c = split /\|/, $USER->{MyLinks};
# Get total of links.
$USER->{Total} = @c || 0;
if (@c) {
$USER->{Pages} = int $$USER{Total}/$Links::CFG->{MYLINKS_PERPAGE} (($$USER{Total} % $Links::CFG->{MYLINKS_PERPAGE}) ? 1 : 0);
$USER->{Page} = $in->param('p') || 1;
$USER->{Page} = (($$USER{Page} > $$USER{Pages}) ? 1 : $$USER{Page});
$USER->{Start} = ($$USER{Page}-1) * $Links::CFG->{MYLINKS_PERPAGE};
$USER->{Finish} = $USER->{Start};
# Build span pages.
if ($USER->{Pages} > 1) {
my $prev = $USER->{Page} - 1;
my $next = $USER->{Page} 1;
if ($$USER{Page} > 1) {
$USER->{Span} = qq~<a href="$ENV{SCRIPT_NAME}~;
$USER->{Span} .= qq~?p=$prev~ if ($prev > 1);
$USER->{Span} .= qq~"><b>< Previous</b></a> <a href="$ENV{SCRIPT_NAME}">1</a> ~;
if ($prev > 1) {
for (2 .. $prev) { $USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$_">$_</a> ~; }
}
}
else { $USER->{Span} = qq~< Previous ~; }
$USER->{Span} .= qq~<b>$$USER{Page}</b> ~;
if ($$USER{Page} < $$USER{Pages}) {
for ($next .. $$USER{Pages}) { $USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$_">$_</a> ~; }
$USER->{Span} .= qq~<a href="$ENV{SCRIPT_NAME}?p=$next"><b>Next ></b></a>~;
}
else { $USER->{Span} .= qq~Next >~; }
}
# Get the links to display.
$" = ",";
my $sth = $DB->prepare ("SELECT * FROM Links WHERE ID IN (@c) ORDER BY $Links::CFG->{MYLINKS_ORDER} LIMIT $$USER{Start}, $Links::CFG->{MYLINKS_PERPAGE}");
$sth->execute() or die $DBI::errstr;
while (my $rec = $sth->fetchrow_hashref) {
$USER->{Links} .= &site_html_my_link ($rec, $dynamic);
$USER->{Finish} ;
}
$USER->{Start} ;
}
# Display the home page.
&site_html_my_home ($USER, $dynamic);
}
I have got all the templates in my default templates directory and have added the following code for each template into SiteHTML.pm...
sub site_html_my_home {
# --------------------------------------------------------
# Return parsed category page.
#
my $tags = shift;
my $output = Links::load_template ('my_home.html', $tags, 1);
return $output;
}
(Not sure if im meant to to that or not)[/red]
I would be really grateful if someone could tell me what ive done wrong (If youve got a few hours spare to fix my code)...lol
This bit is bothering me $" = $Links::CFG->{MYLINKS_DELIM}; and this bit $Links::CFG->{MYLINKS_ORDER};...oh and also....$Links::CFG->{MYLINKS_PERPAGE};.
Do I have to add some code to /Links/Config.pm or /Links/ConfigData.pm ???
THANKS
Paul Wilson.

(Dont blame me if I'm wrong!)