Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Lastlink SSI

(Page 1 of 2)
> >
Quote Reply
Lastlink SSI
Hello all,

The mod below is the way how to create the Lastlink and call the file using the SSI, but its for Links 2.0, how can i make it with Links SQL 2.1.0 ? Please help.

1. =====lastlink.cgi=====
#!/usr/bin/perl
$txtfile1 = '/path/to/1.txt';
$txtfile2 = '/path/to/2.txt';
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "/path/to/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.

sub main {
# --------------------------------------------------------
my $LASTX1 = 9;
my $LASTX2 = 9;
open (DB, "<$db_file_name") or &cgierr("unable to open database:$db_file_name.\nReason: $!");
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
my @lines = <DB>;
close DB;
for ($i=$#lines; $i>=$#lines - $LASTX1; $i--) {
chomp $lines[$i];
@tmp = &split_decode ($lines[$i]);
%tmp = &array_to_hash (0, @tmp);
$tmp{Title} =~ s/^(.{20}).*$/$1.../;
$lastlink .= &site_html_last_link1 (%tmp);
}
open (LASTLINK1, ">$txtfile1") or &cgierr ("Can't Open FILE: $txtfile1. Reason: $!");
print LASTLINK1 &site_html_last_link2;
close LASTLINK1;

for ($i=$#lines; $i>=$#lines - $LASTX2; $i--) {
chomp $lines[$i];
@tmp2 = &split_decode ($lines[$i]);
%tmp2 = &array_to_hash (0, @tmp2);
$tmp2{Title} =~ s/^(.{20}).*$/$1.../;
$lastlink2 .= &site_html_last_link1 (%tmp2);
}
open (LASTLINK2, ">$txtfile2") or &cgierr ("Can't Open FILE: $txtfile2. Reason: $!");
print LASTLINK2 &site_html_last_link2;
close LASTLINK2;
}

2. Add the following sub-routines in your site_html_templates.pl file:

sub site_html_last_link1 {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.

my %rec = @_;
return &load_template ('lastlink1.html', {
%rec,
%globals
});
}

sub site_html_last_link2 {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
return &load_template ('lastlink2.html', {
lastlink => $lastlink,
%globals
});
}

3. Create the following template files:

a) lastlink1.html
b) lastlink2.html

The first template file should include the tags that you want to print, like the following:
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> (Added: <%Date%> )

The second template file should ONLY include the following tag:
<%lastlink%>

4. Upload a blank file called 1.txt and 2.txt to your $txtfile1 and $txtfile2 directory. Change the permission of this file to 777 (rwxrwxrwx).

5. Then add the following codes to your non-links pages (Make sure that these files allow SSI calls)

<!--#include virtual="/lastlink/1.txt"-->
and
<!--#include virtual="/lastlink/2.txt"-->
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Somebody help me please ? Is it possible or not with Links SQL 2.1.0 and how ? Please help
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Hi,

Why do you not use global variable or plugin to show the last link?

I have a pluggin can do this. Please feel free to contact me.

Cheers,

Beck
Quote Reply
Re: [Beck] Lastlink SSI In reply to
Hi Beck,

Thank you so much, i'm using this way because i need to show the lastlink out of Links SQL directories, is it your plugins can create a text file out of Links SQL directories ? Any idea please ?

Thanks for help.
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Hi,

Please send me more details via my email so I canhelp you out with this.

Cheers,

Beck
Quote Reply
Re: [reenee] Lastlink SSI In reply to
If all you want is the last link try something like:

Code:
#!/usr/bin/perl

#================================

use strict;
use lib '/path/to/admin';
use Links::init('/path/to/admin');
use Links qw/$IN $DB/;
use Links::SiteHTML;

local $SIG{__DIE__} = \&Links::fatal;
main();

#================================

sub main {
#---------------------------------------------------
# Display the newest link.

my $tab = $DB->table('Links');
$tab->select_options('ORDER BY ID DESC', 'LIMIT 1');

my $rec = $tab->select;

print $IN->header();
print Links::HTML::display('link', $rec);

}

Last edited by:

RedRum: Mar 12, 2002, 2:43 AM
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
And, to make it LastLink for the last 5 links, you would change LIMIT to 5, I believe

Thanks, RedRum

------------------------------------------
Quote Reply
Re: [DogTags] Lastlink SSI In reply to
Thanks Beck, Paul & DogTags,

But i found an error when i run the file:

Can't locate Links/init.pm

Please help.

P/S: I did change the path to admin directory.
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Ah if you have an older version (ie not 2.1.0) remove the Links::init bit.
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Thanks Paul,

For you information, i'm using Links SQL 2.1.0, but i try to remove it, it was an error:

Can't call method "table" on an undefined value at lastlink.cgi line 20.

Please help.
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Whoops, try re-adding:

use Links::init('/path/to/admin');

...but put it below:

use Links qw/$DB $IN/;
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Sorry Paul,

Still have an error:

Can't locate Links/init.pm

I try to find 'init.pm' file manually from Links directory, there was no file name init.pm

Please help.
Quote Reply
Re: [reenee] Lastlink SSI In reply to
I'm not sure why it is saying that. init() is a subroutine not a module. Can you show me exactly what code you have now?
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Below is the code i'm using :

#!/usr/bin/perl

#================================

use strict;
use lib '/home/worldbar/public_html/directories/cgi-bin/admin';
use Links qw/$DB $IN/;
use Links::init('/home/worldbar/public_html/directories/cgi-bin/admin');
use Links::SiteHTML;

local $SIG{__DIE__} = \&Links::fatal;
main();

#================================

sub main {
#---------------------------------------------------
# Display the newest link.

my $tab = $DB->table('Links');
$tab->select_options('ORDER BY ID DESC', 'LIMIT 1');

my $rec = $tab->select;

print $IN->header();
print Links::HTML::display('link', $rec);

}
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Ugh I'm so stupid. Try:

Code:
#!/usr/bin/perl
#================================

use strict;
use lib '/home/worldbar/public_html/directories/cgi-bin/admin';
use Links qw/$DB $IN/;
Links::init('/home/worldbar/public_html/directories/cgi-bin/admin');
use Links::SiteHTML;

local $SIG{__DIE__} = \&Links::fatal;
main();

#================================

sub main {
#---------------------------------------------------
# Display the newest link.

my $tab = $DB->table('Links');
$tab->select_options('ORDER BY ID DESC', 'LIMIT 1');

my $rec = $tab->select()->fetchrow_hashref;

print $IN->header();
print Links::SiteHTML::display('link', $rec);

}
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Yessss!! Its work, no more error, Thanks Paul.

But, can you tell me how to make the mod is print into txt file like i posted before.

Thanks again. Blush
Quote Reply
Re: [reenee] Lastlink SSI In reply to
The joy of mysql is that you don't need to use text files :)

I read your post just now but was a bit unsure about what goes in the text file and how it gets in there? Blush
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Errkk,

Forget about txt file, let say the output is print into html file, from my experience, loading a cgi file by using exec cgi is take more memory and cpu resources and the page is slow on loading instead of using a include virtual.

Please correct me if i'm wrong.

Thanks for help Paul.
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Emm....

I think it was a bug, the list of lastlink is a link not Validated yet, how to show only a validated link ?

Please help....
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Hmm I'll get it right first time one of these days Cool

Change:

my $rec = $tab->select()->fetchrow_hashref;

to

my $rec = $tab->select( { isValidated => 'Yes' } )->fetchrow_hashref;
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Laugh

Its work Paul,

But, i think one more error happen, i try to change LIMIT 1 to LIMIT 5 but still show only 1 links.

P/S: I was add and validate 30 links hours ago :)
Quote Reply
Re: [reenee] Lastlink SSI In reply to
Try:

LIMIT 0,5

(although it should work the other way...hmm)

Last edited by:

RedRum: Mar 12, 2002, 8:01 AM
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Hmm....still same, only 1 link.

Well, the global tag below i get from Gossamer Threads Resources, may be this can help.

lastlink =>
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
return $output;
}


Please help Paul...
Quote Reply
Re: [reenee] Lastlink SSI In reply to
It should work either way. You can try if you want.

$tab->select_options ('ORDER BY ID DESC Limit 5');
Quote Reply
Re: [RedRum] Lastlink SSI In reply to
Hmm...i try many way to make it work, but still same, its only show one link, i try to change from $tab->select_options('ORDER BY ID DESC', 'LIMIT 0,5'); to $tab->select_options('ORDER BY ID DESC LIMIT 5'); but still no luck, i also try to add more links and validate it, well ..its also same, maybe something i never try, well .. my knowledge so limited

Frown

Last edited by:

reenee: Mar 12, 2002, 8:24 AM
> >