[ic] modified [loop-exec bar_link]

Jonathan Clark jonc@webmaint.net
Sat, 26 Aug 2000 21:19:06 +0100


Here is a modified bar_link routine which changes the following:

1) fix the </A> left on a 'No Link' link type
2) allow you to set the class of the link as apposed to the hard coded
barlink

usage: [prefix-exec bar_link]<table>,<archorclass>[/prefix-exec]


Add the routine below to your catalog.cfg to override the default routine in
catalog_before.cfg

Jonathan.
Webmaint.com
---

Sub <<EOR
sub bar_link {
 my $base = shift || 'cat,barlink';
 my ($base,$class) = split /\,/, $base;
 my $ref = shift;
 my $code = $ref->[0];
 my $record =  tag_data($base, 'n/a', $code, { hash => 1 });
 return $ref->[0] unless $record;

 my $url;
 my $anchor;
 my $first;

 LINK: {
  if($record->{link_type} eq 'external') {
   $first = $record->{url};
   $first =~ s/\s+$//;
   $first =~ s/^\s+//;
   $url = $first;
  }
  elsif ($record->{link_type} eq 'internal') {
   my ($page, $form) = split /\s+/, $record->{url}, 2;
   $url = $Tag->area( { href => $page, form => $form });
  }
  elsif ($record->{link_type} eq 'simple') {
   my (@items) = split /\s*[\n,]\s*/, $record->{selector};
   my @out;
   my $fi = $record->{tab};
   my $sp = $record->{page};
   my %options = (
    href => 'scan',
   );
   push @out, "fi=$fi" if $fi;
   push @out, "sp=$sp" if $sp;
   push @out, "st=db";
   if(! @items) {
    push @out, "ra=yes";
    $options{arg} = join "\n", @out;
    $url = $Tag->area(\%options);
    last LINK;
   }
   push @out, "co=yes";
   for(@items) {
    my ($col, $string) = split /\s*=\s*/;
    push @out, "sf=$col";
    push @out, "se=$string";
   }
   push @out, qq{va=link_image=$record->{banner_img}};
   push @out, qq{va=link_banner=$record->{banner_text}};
   push @out, qq{va=link_sub=$record->{subs}};
   $options{arg} = join "\n", @out;
   $url = $Tag->area(\%options);
  }
  elsif ($record->{link_type} eq 'complex') {
   $record->{search} =~ s/[\r\n+]/\n/g;
   $url = $Tag->area('scan', $record->{search});
  }
  else {
   $url = "";
  }
 }

 ANCHOR: {
  if($record->{display_type} eq 'url') {
   $anchor = "";
  }
  elsif ($record->{display_type} eq 'name') {
   $anchor = "$record->{name}";
   if ($record->{link_type} ne 'none'){
    $anchor .= "</A>";
   }
  }
  elsif ($record->{display_type} eq 'icon') {
   $anchor = qq{<img src="$record->{image}" alt="$record->{name}"};
   $anchor .= " $record->{image_prop}"
    if $record->{image_prop};
   $anchor .= '>';
   $anchor .= $record->{name};
   $anchor .= '</A>';
  }
  elsif ($record->{display_type} eq 'image') {
   $anchor = qq{<img src="$record->{image}" alt="$record->{name}"};
   $anchor .= " $record->{image_prop}"
    if $record->{image_prop};
   $anchor .= '>';
   $anchor .= '</A>';
  }
  else {
   $anchor = "$record->{name}</A>";
  }
 }

 return $url if ! $anchor;
 return $anchor if ! $url;
 return qq{<A HREF="$url" CLASS="$class">$anchor};
}
EOR