Gossamer Forum
Home : Products : Links 2.0 : Discussions :

CGI within CGI?

Quote Reply
CGI within CGI?
Hi Folks,
I would like to call another cgi script within the Link 2.0 cgi-generated pages. Is this possible?

Normally, this banner script would be called by SSI, but I have to use the .shtml extension in order for the SSI to work on my server. So far, I have tried the following:

1) I changed the Links.cfg file to:
The name of an index file.
$build_index = "index.shtml";
# The extension to use for non index files:
$build_extension = ".shtml";

2) I installed the advanced template.pm add on and it appears to work correctly.

Results:
The banner script works great by calling it with the standard tag on my category pages, but not on any of the cgi generated pages such as add.cgi, search.cgi etc...

After installation of the Advanced template.pm, I tried using the same SSI tag (above) with no luck. Someone wrote here on the forum that the same tag should work --only he wrote it without the "<!--" exclamation mark at the beginning of the tag. I tried it that way too-- No luck.

I have spent hours searching all related LINKS 2.0 forums here and can't find out for sure whether a CGI script can be called from the Links - CGI generated pages or not. Or, what tag to use to do it.

Using the <%include filename%> tag suggested with all references to the advanced template.pm does not work because the banner script is not located in the same directory as the templates.

Does anyone have a concrete answer whether this can be done and if so --How do I do it?




Schoolmarm's Lil Red School House & Academic Resource Net.
http://www.schoolmarm.org/
Quote Reply
Re: CGI within CGI? In reply to
Use the codes available throughout the Links 2.0 Customization Forum for the WebAdverts "Mod".

Regards,

Eliot Lee
Quote Reply
Re: CGI within CGI? In reply to
Thank you Eliot for pointing me to a different and unexplored direction. I found the message concerning the WebAdverts code and tried it out. It did not work for me.
The banner tags only showed on the cgi-generated page.

I am not using the WebAdverts script for my banner rotation. Does that make a difference? Is the modifications made to site_html_templates.pl universal for all banner scripts?

Here is what I did:
Since I utilize two differenct scripts for my banners (One for small and the other for large sizes) I made modifications to the code similar to Cookie129's.

sub insertadvert_l {
#---------------------------------------------------------
# Insert Banner Ad L (468x60 Large)
my $ad = `/custs/home/s/sch27660/public_html/cgi-bin/ads/ads.cgi`;
$ad =~s,Content-type:\stext/html,,;
return $ad;
}

sub insertadvert_s {
#---------------------------------------------------------
# Insert Banner Ad S (Small)
my $ad = `/custs/home/s/sch27660/public_html/cgi-bin/banner.cgi`;
$ad =~s,Content-type:\stext/html,,;
return $ad;
}


My %globals are as follows:

bannerl => \&insertadvert_l,
banners => \&insertadvert_s,


Then finnally added the code to the template .html files.

<ºbannerl%> or <ºbanners%> as applicable.

Here is the result of my labors in the Site_html_templates.pl file:

# You can put variables here that you would like to use in any
# of your templates.

%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,

bannerl => \&insertadvert_l,
banners => \&insertadvert_s,

);


sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}

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

return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
%globals
});
}

sub site_html_new {
# --------------------------------------------------------
# This routine will build a what's new page.

return &load_template ('new.html', {
total => $total,
grand_total => $grand_total,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}

sub site_html_cool {
# --------------------------------------------------------
# This routine will build a what's new page.

return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}

sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}

sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.

return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}

sub site_html_ratings {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.

return &load_template ( 'rate_top.html', {
top_rated => $top_rated,
top_votes => $top_votes,
%globals
});
}

########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################

sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;

my $category = shift;
$category ?
($category = qq~$category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));

print &load_template ('add.html', {
Category => $category,
%globals
});
}

sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.

&html_print_headers;

print &load_template ('add_success.html', {
%in,
%globals
});
}

sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.

my ($errormsg) = shift;
$in{'Category'} ?
($in{'Category'} = qq~<input type=hidden name="Category" value="$in{'Category'}">$in{'Category'}~) :
($in{'Category'} = &build_select_field ("Category"));

&html_print_headers;
print &load_template ('add_error.html', {
error => $errormsg,
%in,
%globals
});

}

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.

my $category = &build_select_field ("Category", "$in{'Category'}");

&html_print_headers;
print &load_template ('modify.html', {
Category => $category,
%globals
});
}

sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.

&html_print_headers;
print &load_template ('modify_success.html', {
%in,
%globals
});
}

sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.

my $errormsg = shift;
$in{'Category'} = &build_select_field ("Category", $in{'Category'});

&html_print_headers;
print &load_template ('modify_error.html', {
error => $errormsg,
%in,
%globals
});
}

sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
}

sub site_html_search_failure {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my $error = shift;
my $term = &urlencode ($in{'query'});
&html_print_headers;

print &load_template ('search_error.html', {
term => $term,
error => $error,
%in,
%globals
});
}

sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.

&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
%in,
%globals
});
}

sub site_html_mailing {
# --------------------------------------------------------
# This routine displays your mailing list subscribe/unsubscribe form.
#
my $action = shift;
my $message;
($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~);
($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~);

&html_print_headers;
print &load_template ('email.html', {
message => $message,
%in,
%globals
});
}

sub site_html_mailing_error {
# --------------------------------------------------------
# This routine is displayed if there was a problem subscribing.
#
my $error = shift;

&html_print_headers();
print &load_template ('email_error.html', {
error => $error,
%in,
%globals
});
}

sub site_html_rate_form {
# --------------------------------------------------------
# This routine determines how the rate form page will look like.
#
my %rec = @_;

&html_print_headers;
print &load_template ('rate.html', {
%rec,
%globals
});
}

sub site_html_rate_success {
# --------------------------------------------------------
# This routine determines how the rate success page will look like.

&html_print_headers;
print &load_template ('rate_success.html', {
%in,
%globals
});
}

sub site_html_rate_failure {
# --------------------------------------------------------
# This routine determines how the rate failure page will look like.

my ($errormsg) = shift;

&html_print_headers;
print &load_template ('rate_error.html', {
error => $errormsg,
%in,
%globals
});

}


sub insertadvert_l {
#---------------------------------------------------------
# Insert Banner Ad L (468x60 Large)
my $ad = `/custs/home/s/sch27660/public_html/cgi-bin/ads/ads.cgi`;
$ad =~s,Content-type:\stext/html,,;
return $ad;
}

sub insertadvert_s {
#---------------------------------------------------------
# Insert Banner Ad S (Small)
my $ad = `/custs/home/s/sch27660/public_html/cgi-bin/banner.cgi`;
$ad =~s,Content-type:\stext/html,,;
return $ad;
}


########################################################################################
# THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! #
########################################################################################

sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#

my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;


Now, assuming that the WebAdverts codes does work universally for all banner scripts requiring SSI calls,
Why doesn't this work for me? Did I edit the Site_html_templates.pl file wrong?? I would really appreciate the look over. Thanks


Schoolmarm's Lil Red School House & Academic Resource Net.
http://www.schoolmarm.org/
Quote Reply
Re: CGI within CGI? In reply to
In Reply To:
Does that make a difference?
NOPE...replace the ads.cgi with whatever is the name of your other .cgi script...Also, change the /path/to
codes to the ABSOLUTE PATH where your .cgi banner script is located!

And why the heck did you copy a large {irrlevant} portion of your site_html_templates.pl file?

Regards,

Eliot Lee
Quote Reply
Re: CGI within CGI? In reply to
Thanks for clearing up one of my questions for me concerning whether the webadverts codes could be used universally or not.

In Reply To:
replace the ads.cgi with whatever is the name of your other .cgi script
The one script is named "ads.cgi" and it is under the directory /cgi-bin/ads and the other script is named "banner.cgi" directly under the cgi-bin.

In Reply To:
Also, change the /path/to
codes to the ABSOLUTE PATH where your .cgi banner script is located!
The Absolute path is set correctly for my server. At least, this is the Absolute path used for all my scripts with only the directories after /public_html/cgi-bin/ changed to reflect the location of each individual script. Do you see something wrong about the ABSOLUTE PATH??

I am worried that perhaps I did not include the new subroutines in the proper place within the site_html_templates file. Could this be the problem?

In Reply To:
And why the heck did you copy a large {irrlevant} portion of your site_html_templates.pl file?
Sorry about that. I wanted to make sure that if anyone read my message, they would have as much info as possible to be able to explain to me what in the heck I am doing wrong. Usually, if I am shown an example for altering code I can make the necessary adaptions without a hitch. As you know, I am having a problem with this one-- For the life of me, I can't figure out what I am doing wrong. I have spent so many hours on this and it is frustrating to say the least. I am sure that it must be a simple thing to spot the problem for more experienced eyes than mine.

Again, I would be very thankful for any advice.


Schoolmarm's Lil Red School House & Academic Resource Net.
http://www.schoolmarm.org/
Quote Reply
Re: CGI within CGI? In reply to
Well...the tags can only work in your .cgi generated pages...it will not work in your regular pages, like home.html, category.html, etc.

That is the only thing I can think of.

Good luck!

Regards,

Eliot Lee