Gossamer Forum
Home : Products : Links 2.0 : Customization :

islink mod help

Quote Reply
islink mod help
I just followed the instructions to install this mod from
http://www.isee-multimedia.co.uk/scripts/links2.htm

now the only problem I'm having is for the link.html
The if statement works and the
ifnot statement does not work

and I just updated my template.pm
for the if statements to work

Did I miss somethihng ???

heres a copy of my template.pm
incase I updated it wrong

# -------------
# Links
# -------------
# Links Manager
#
# File: Template.pm
# Description: Template parser package lossely based off of CGI::FastTemplate
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================

package Template;
# ===============================================================
use strict;
use vars qw($VERSION $error @ISA @EXPORT); # Globals.
@ISA = (); # Not inhereited.
@EXPORT = qw();
$Template::VERSION = '1.0';

sub error {
# ---------------------------------------------------------------
# Handles error messages.
#
my ($errtype, $e1, $e2) = @_;
my %errors = (
'CANTINIT' => "Template: Can't init, no root defined, or not a hash ref: '$e1'",
'NOTEMPLATE' => "Template: Can't find template: $e1",
'CANTOPEN' => "Template: Can't open template: $e1. Reason: $e2",
'NONAMESPACE' => "Tempalte: You haven't loaded a namespace yet!",
'NONAME' => "Template: No name was defined for this template!",
'NOSTRING' => "Template: No text was defined for template: $e1"
);
$Template::error = $errors{$errtype};
die $Template::error;
}

sub new {
# ---------------------------------------------------------------
# Initilizes a new instance of the template parser.
#
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless $self, $class;

my $opt = shift;
unless ((ref $opt eq 'HASH') and (exists ${$opt}{'ROOT'})) {
&error ('CANTINIT', $opt);
return undef;
}
$self->{'ROOT'} = ${$opt}{'ROOT'};
$self->{'CHECK'} = ${$opt}{'CHECK'};

return $self;
}

sub load_template {
# ---------------------------------------------------------------
# Loads a template either from a file or from a string.
#
my $self = shift;
my ($name, $text) = @_;

if (!$self->{'CHECK'} and exists $self->{'templates'}{$name}) { return 1; }
if (!defined $text) {
my $file = $self->{'ROOT'} . "/$name";
-e $file or (&error('NOTEMPLATE', $file) and return undef);
open (TPL, "<$file") or (&error('CANTOPEN', $file, $!) and return undef);
$text = join ("", <TPL>);
close TPL;
}
$self->{'templates'}{$name} = $text;
return 1;
}

sub load_vars {
# ---------------------------------------------------------------
# Sets the variables (all the search and replaces).
#
my $self = shift;
my $vars = shift;

my ($name, $value);
while (($name, $value) = each %{$vars}) {
$self->{'vars'}{$name} = $value;
}
return 1;
}

sub clear_vars {
# ---------------------------------------------------------------
# Clears the namespace.
#
my $self = shift;
$self->{'vars'} = {};
return 1;
}

sub parse {
# ---------------------------------------------------------------
# Parses a template.
#
my ($self, $template) = @_;
my $begin = $self->{'begin'} || quotemeta('<%');
my $end = $self->{'end'} || quotemeta('%>');

exists $self->{'templates'}{$template} or ($self->load_template($template) or return undef);
exists $self->{'vars'} or (&error ('NONAMESPACE') and return undef);
$self->{'parsed'}{$template} = '';

my $temp = $self->{'templates'}{$template};

# Parse includes, do this first so that the includes can include
# template tags.
$temp =~ s#$begin\s*include\s*(.+?)\s*$end#
if (exists $self->{'inc'}{$1}) { $self->{'inc'}{$1}; }
else {
if (open (INC, "${$self}{'ROOT'}/$1")) {
$self->{'inc'}{$1} = join ("", <INC> );
close INC;
$self->{'inc'}{$1};
}
else {
"Can't find file: ${$self}{'ROOT'}/$1";
}
}
#goe;

# Now go line by line and strip out the unwanted stuff looking for
# if and ifnot tags.
my @lines = split /\n/, $temp;
$temp = ''; my @go = (1,1); my $depth = 1; my $line = '';

LINE: foreach $line (@lines) {
# Init the previous, variable and more strings.
my ($prev, $var, $neg, $more, $orig, $full_comp, $comp, $val) = ('', '', '', '', '', '', '', '');
my $result = 0;

# Check for if tags.
$line =~ s/((.*?)$begin\s*if(not)?\s+(.+?)(\s+(<|>|lt|gt|eq|=)\s*(.+?))?$end(.*))/
($orig, $prev, $neg, $var, $full_comp, $comp, $val, $more) = ($1, $2, $3, $4, $5, $6, $7, $8);

# We've found an if tag, let's set the depth to see whether we are in print mode or not.
if ($prev !~ m,$begin\s*endif\s*$end,og) {
$go[$depth] and ($temp .= $prev);
if (!$full_comp) {
if ($neg) { ($self->{'vars'}{$var}) ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { ($self->{'vars'}{$var}) ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
else {
$val =~ s,^['"],,; $val =~ s,['"]$,,;
($comp eq 'eq') and ($result = ($self->{'vars'}{$var} eq $val));
($comp eq '==') and ($result = ($self->{'vars'}{$var} == $val));
($comp eq 'lt') and ($result = ($self->{'vars'}{$var} lt $val));
($comp eq 'gt') and ($result = ($self->{'vars'}{$var} gt $val));
($comp eq '>') and ($result = ($self->{'vars'}{$var} > $val));
($comp eq '<') and ($result = ($self->{'vars'}{$var} < $val));
if ($neg) { $result ? ($go[++$depth] = 0) : ($go[++$depth] = $go[$depth]) and ""; }
else { $result ? ($go[++$depth] = $go[$depth]) : ($go[++$depth] = 0) and ""; }
}
}
else {
# Oops, there was an endif tag we missed, set the original line back and keep going.
$more = ''; $orig;
}
/oe;
if ($more) { $line = $more; redo LINE; }

# Check for endif tags.
$line =~ s/(.*?)$begin\s*endif\s*$end(.*)/
($prev, $more) = ($1, $2);
$go[$depth] and ($temp .= $prev);
$go[$depth--] = 1;
"";
/oe;
if ($more) { $line = $more; redo LINE; }

# Add the content..
$go[$depth] and ($temp .= "$line\n");
}

# Replace the special variables, we allow code ref mapping.
$temp =~ s/$begin\s*(.+?)\s*$end/
if (exists $self->{'vars'}{$1}) {
ref ($self->{'vars'}{$1}) eq 'CODE' ?
&{$self->{'vars'}{$1}}($self->{'vars'}) : $self->{'vars'}{$1};
}
else { "Unkown Tag: $1"; }
/goe;

$self->{'parsed'}{$template} = $temp;

return $self->{'parsed'}{$template};
}

sub DESTROY {
# ---------------------------------------------------------------

}

1;

Quote Reply
Re: islink mod help In reply to
You most likely forgot to add the following codes in the sub site_html_link routine (which is plainly stated in the instructions)....

Code:

($rec{'isLinked'} eq 'Yes') ?
($rec{'isLinked'} = 1):
(delete $rec{'isLinked'});


Regards,

Eliot Lee
Quote Reply
Re: islink mod help In reply to
I have that in there maybe I put it in wrong heres how it looks:

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


Quote Reply
Re: islink mod help In reply to
Uh, no you don't! YOU need to add the codes I just posted AFTER:

Code:

($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});


READ THE INSTRUCTIONS AGAIN!!!!

Code:

Open site_html_temlpates.pl and change

# 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'});

To

# 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'});
($rec{'isLinked'} eq 'Yes') ? ($rec{'isLinked'} = 1) : (delete $rec{'isLinked'});


So, actual, you did NOT follow all the INSTRUCTIONS! Please read MOD INSTRUCTIONS more carefully before posting questions.

Regards,

Eliot Lee
Quote Reply
Re: islink mod help In reply to
Well clearly you don't have it in there because the code that Eliot showed you isn't in the snippet you pasted..........

($rec{'isLinked'} eq 'Yes') ? ($rec{'isLinked'} = 1): (delete $rec{'isLinked'});

EDIT:
Ooops too late :)


Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: islink mod help In reply to
it worked

I didnt think it made a difference if it was in the first line or the third line.

I guess it does.

Thanks for your help

Quote Reply
Re: islink mod help In reply to
Uh...Lines? Doesn't matter...but it DOES MATTER that you include ALL codes in MODS to make them work, which as you posted earlier, you DID NOT add the appropriate codes into the sub site_html_link routine!

Regards,

Eliot Lee