[ic] Barlink

Nora Heuer - Baytides Management Inc. interchange-users@icdevgroup.org
Thu Oct 10 14:34:00 2002


On 10 Oct 2002 at 14:15, Chris Bartholomew wrote:

> The only subroutine I could find was this, in the category_vertical:
> 
> [set found_cat][/set]
> [loop
>     prefix=box
>     search="
>         fi=area
>         st=db
>         tf=sort
>         ac=0
>         ac=0
>         co=yes
> 
>         sf=sel
>         op=eq
>         se=[control set_selector left]
> 
>         sf=which_page
>         op=rm
>         se=[control page_class all|@@MV_PAGE@@]
> "]
> 
>   <tr> 
>     <td valign="top" class="categorybar">
>       <b>[box-exec bar_link]area[/box-exec]</b>
>     </td>
>   </tr>
>   <tr> 
>     <td valign="top" class="categorybar">
> 
> [set found_cat]1[/set]
> [loop prefix=cat
>     search="
>         fi=cat
>         st=db
>         tf=sort
>         tf=name
>         rf=code,name
>         sf=sel
>         se=[box-code]
>     "
>     ]
>       &nbsp;&nbsp;[cat-exec bar_link]cat[/cat-exec]<BR>
> [/loop]
> 
>     </td>
>   </tr>
> [/loop]
> 
> Does this look OK?
> 

No,
copy the code below to your catalog.cfg file

Sub <<EOR
sub bar_link {
	my $base = shift || 'cat';
	my $extra;
	$base =~ s/(\W.*)//s
		and $extra = $1;
	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 $highlight;
	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;
			my $current = $Tag->var('MV_PAGE', 1);
            $highlight = 1 if   $page eq $current
                                    or
                                $page eq $CGI->{ui_explode};
			$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, $record->{search}
				if $record->{search} =~ /^\s*\w\w=/;

			push @out, qq{va=banner_image=$record->{banner_image}};
			push @out, qq{va=banner_text=$record->{banner_text}};
			$options{arg} = join "\n", @out;
			$url = $Tag->area(\%options);
		}
		elsif	($record->{link_type} eq 'complex') {
			$record->{search} =~ s/[\r\n+]/\n/g;
			$record->{search} .= qq{\nva=banner_text=$record->{banner_text}};
			$record->{search} .= qq{\nva=banner_image=$record-
>{banner_image}};
			$url = $Tag->area('scan', $record->{search});
		}
		else {
			$url = "";
		}
	}

	ANCHOR: {
		my $display_text = $record->{name} || $record->{banner_text};
		$display_text =~ s/"/&quot;/g;
		if($record->{display_type} eq 'url') {
			$anchor = "";
		}
		elsif ($record->{display_type} eq 'name') {
			$anchor = $display_text;
		}
		elsif ($record->{display_type} eq 'icon') {
			$anchor = qq{<img src="$record->{image}" alt="$display_text"};
			$anchor .= " $record->{image_prop}"
				if $record->{image_prop};
			$anchor .= '>';
			$anchor .= $display_text;
		}
		elsif ($record->{display_type} eq 'image') {
			$anchor = qq{<img src="$record->{image}" alt="$display_text"};
			$anchor .= " $record->{image_prop}"
				if $record->{image_prop};
			$anchor .= '>';
		}
		else {
			$anchor = $display_text;
		}
	}
	return $url if ! $anchor;
	return $anchor if ! $url;
	my $tmpl = $record->{link_template}
			 || $extra
			 || $Variable->{BAR_LINK_TEMPLATE}
			 || q{<A HREF="$URL$" class=barlink>$ANCHOR$</A>};
	$record->{ANCHOR} = $anchor;
	$record->{URL} = $url;
	$tmpl =~ s!{HIGHLIGHT}(.*?){/HIGHLIGHT}! $highlight ? $1 : '' !gise;
	$tmpl =~ s/\$(\w+)\$/$record->{$1}/g;
	return $tmpl;
}
EOR


Tha's what I meant.

Nora