Gossamer Forum
Home : Products : DBMan : Customization :

SSI within html.pl

Quote Reply
SSI within html.pl
hi all,

I've been using the following for a while now to embed ssi's into html.pl.....

sub include {
# --------------------------------------------------------
# This is text to include. Use like an SSI.

my $file = shift;
open (FILE, "$file") or die "Can't open $file ($!)";
print <FILE>;
close FILE;
}

The code to embed where u want is......

|; &include ("../../header.html"); print qq| for example.

This has been working fine, but i need (or i think i do..?) to embed a different type of ssi. I have installed the What's New MOD. I want a small list of the last 15 what's new items to show in a little side menu. I can do it from an html page, no problem (as per url below). How would i go about calling in the following from the html.pl, it's not quite working.......?

|; &include ("/cgi-local/dbman/db.cgi?db=ssi&uid=default&listnew=1&view_records=1"); print qq|

I hope this is clear as mud!!!! I've included the url for u to see.

http://www.englishcivilwar.net/adv_search.shtml

thanks in advance.........Wink

Last edited by:

philm: Oct 3, 2001, 2:05 AM
Quote Reply
Re: [philm] SSI within html.pl In reply to
Well, since the string passed to sub include is a filename,
the sub will simply attempt to open the string as such.
I don't think you could, or should, do this by using sub include.

You could code a special subroutine that retrieves all records,
or just some of their field names, for the last n entries added.


kellner
Quote Reply
Re: [kellner] SSI within html.pl In reply to
Thanks for the prompt reply and suggestion. I'm not actually that familiar with perl and such. I managed to find the below code in the unofficial FAQ. I've entered my db url in the last section and i can pretty much follow whats going on but i haven't a clue how to make it work... Unsure

Could you help me hack it around please?

------------------------------------------------------

sub headlines {
open (DB, "<$db_file_name") or &cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my @lines = <DB>;
close DB;
my $LASTX = 10;
for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {
chomp $lines[$i];
@data = split(/\|/,$lines[$i]);
next unless ($data[#18] eq 'Yes');
$latest .= qq|
<A HREF="http://www.englishcivilwar.net/cgi-local/dbman/db.cgi?
db=ssi&uid=default&listnew=1&view_records=1">$data[1]</A> - $data[2] |;
}
print $latest;
}

i call it somewhere in my html.pl using.......

|; &headlines; print qq|

------------------------------------------------------

Just to clarify, i have a second .cfg and html.pl file for the ssi call with different formatting, no headers/footers etc. It's only the 'title' field that i will be displaying.

Thanks

Last edited by:

philm: Oct 3, 2001, 3:42 AM
Quote Reply
Re: [philm] SSI within html.pl In reply to
It print the last X records from your database - you just add it into html.pl and put &headlines; where you want the records to appear.

There are a few mistakes in the code though like:

next unless ($data[#18] eq 'Yes');

....should be:

next unless ($data[18] eq 'Yes');

(providing you even have that 18th (well 17th really) field in your database)

Last edited by:

RedRum: Oct 3, 2001, 4:56 AM
Quote Reply
Re: [RedRum] SSI within html.pl In reply to
cool, thanks my friend, that little # fixed it, hehehe, i do have 18 fields, it's my most to date.....LOL

FYO i was only getting the latest 6 items??!?? I had to change it to......
my $LASTX = 19;

I don't why......but it works...

Laugh
Quote Reply
Re: [philm] SSI within html.pl In reply to
I don't understand what the "next unless ($data[18] eq 'Yes')" means anyway.
If you want to pull only titles, I suggest you get the number of the title field first,
and then get the element accordingly.
For this code, I'll assume the field is called "title".
I take it you would then want a link to the complete record?
For this you need to use the database key - unless you can assure you will have unique titles!
I'l assume the database key field is called "ID" - change all instances of "ID" in the code if necessary,
don't forget the one inside the link.

sub headlines {
my $title_pos = $db_def{'title'}[0];#number of title field,
my $id_pos = $db_def{'ID'}[0];# number of database key field
open (DB, "<$db_file_name") or &cgierr("error. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my @lines = <DB>;
close DB;
my $LASTX = 10;
for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {
chomp;
@data = split /\|/;
$latest .= "<a href="$db_script_url?db=$db_setup&uid=$db_uid&view_records=1&ID=$data[$id_pos]">$data[$title_pos]<\a><br>";
}
print $latest;
}

I'm sure it could still be simplified, but if it works ...
This code pulls the last 10 titles. If you want 15, you have to change the value of $LASTX.
kellner

Last edited by:

kellner: Oct 3, 2001, 5:05 AM
Quote Reply
Re: [philm] SSI within html.pl In reply to
You may wish to use this much faster method......

Code:
sub lastx {

my $lines = 10;
my @stack = ();

open(LF, $db_file_name) or die "Error opening $db_file_name : $!\n";
while (<LF>) {
shift @stack if ($stack[$lines - 1]);
push @stack, $_;
}
close(LF);
print @stack;
}

Then just put &lastx; in html.pl

Last edited by:

RedRum: Oct 3, 2001, 5:10 AM
Quote Reply
Re: [RedRum] SSI within html.pl In reply to
Code:
next unless ($data[18] eq 'Yes');

The above code was to check that the records are validated, sorry i forgot to mention i was using that mod ....Blush

Kellner i can't get ur new code to work, i change

Code:
my $title_pos = $db_def{'title'}[13];#number of title field,

to my title field (13),still no go Unsure

RedRum, ur code works but pulls in the whole last 10 records. It was just the last 10 titles i needed, each linking to the full record.

thanks again guys, sorry for taking up too much time......Sly

Last edited by:

philm: Oct 3, 2001, 5:28 AM
Quote Reply
Re: [philm] SSI within html.pl In reply to
no, don't change the number in the square brackets: This *HAS* to be zero.
Just change the name of the field if necessary.
The comment "#number of title field" refers to what's stored in $title_pos,
not to the number in square brackets - easy to misunderstand, I admit.
kellner
Quote Reply
Re: [philm] SSI within html.pl In reply to
Hi,

>>$db_def{'title'}[13];

Thats because the code above is not infact finding the title field.

It is accessing the %db_def hash at the title key but is then looking for element 13.

The key looks something like...

Title => [1, 'alpha', 40, 255, 1, '', ''],

So $db_def{Title}[13] would be going across 13 elements like:

Code:
Title => [1, 'alpha', 40, 255, 1, '', ''],
0 1 2 3 4 5 6 (oops no 13)

So you just need $db_def{Title};

Ok with my code try:

Code:
sub lastx {
my $lines = 10;
my @stack = ();

open(LF, $db_file_name) or die "Error opening $db_file_name : $!\n";
while (<LF>) {
shift @stack if ($stack[$lines - 1]);
split /\|/;
push @stack, $_[2]; #Number of title field in $db_def
}
close(LF);
print qq|<a href="Bla....">$_</a>| foreach @stack;
}

Last edited by:

RedRum: Oct 3, 2001, 5:48 AM
Post deleted by RedRum In reply to
Quote Reply
Re: [RedRum] SSI within html.pl In reply to
Ok guys.. Kellner i'm sorry but ur code still isn't working even if i change the 13 back to 0, sorry Frown

RedRum, ur's is working fine but i still need a couple of tweaks. I can't figure out what to put in the url / <a href="......"> bit.

On my static html part of the site i use this...
Code:
<!--#include virtual="cgi-local/dbman/db.cgi?db=ssi&uid=default&listnew=1&view_records=1sb=2&so=descend"-->
which pulls in the 10 titles as a list.

Now, in ur code i'm not pulling in the list just the relevant record No. The way it is done elsewhere in html.pl (short/long MOD) uses this code....
Code:
$record_number = ((($nh - 1) * $db_max_hits) + $rec_count);

blah = "blahblahblahblahblahblahblah&nh=$record_number&mh=1";

How can i incorporate the above into ur code....hmmmmm.... am i over complicating things, i'm sure there's any easier way.

Thanks guys, if you really getting bored of me just say and i'll leave now.....
Tongue

Last edited by:

philm: Oct 3, 2001, 7:42 AM
Quote Reply
Re: [philm] SSI within html.pl In reply to
Ok what you could do is move the code into db.cgi, then add this at the top of db.cgi.......

elsif ($in{'lastx'}) { if ($per_view) { &lastx; } else { &html_unauth; } }

(along with the other elsif's)

Then you can link to ...db.cgi?db=ssi&uid=default&lastx=1&number=10

In the code I gave, changed my $lines = 10 to my $lines = $in{number};

Then you can vary the number to show like:

db.cgi?db=ssi&uid=default&lastx=1&number=10 <-
db.cgi?db=ssi&uid=default&lastx=1&number=20 <-
db.cgi?db=ssi&uid=default&lastx=1&number=30 <-

Last edited by:

RedRum: Oct 3, 2001, 7:47 AM
Quote Reply
Re: [RedRum] SSI within html.pl In reply to
Smile

Hi, i'm not sure if i mislead you in my last post, i don't actually want to be able to ssi to it, i just dont know what to put in this line in your latest piece of code....

Code:
print qq|<a href="WHAT DO I PUT HERE FOR IT TO LINK TO THE RELEVANT RECORD?">$_</a>| foreach @stack;

I need the title links to look something like this....

Code:
print qq|<a href="/cgi-local/dbman/db.cgi?db=ssi&uid=$db_uid&view_records=1&ID=*&
nh=1&mh=1">$_</a>| foreach @stack;

For each link the 'nh' counter goes up +1 to give me a link to the relevant record...... i think Crazy

If this is what ur code does then i apologize in advance, but i was under the impression i had to use the ......

Code:
|; &lastx; print qq|

format to pull it in from within html.pl and not a

Code:
blahblah=db.cgi?db=ssi&uid=default&lastx=1&number=10

as this was my original problem, not being able to execute a cgi call from within html.pl Crazy

Here is the url if it's any clearer
http://www.englishcivilwar.net/...;sb=2&so=descend

The little brown links on the left under 'Recent Research'

Last edited by:

philm: Oct 3, 2001, 8:40 AM