1 # Copyright 2004-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: breadcrumbs.tag,v 1.5 2007-08-09 13:40:53 pajamian Exp $
10 UserTag breadcrumbs Order number
11 UserTag breadcrumbs addAttr
12 UserTag breadcrumbs Routine <<EOR
14 my ($number, $opt) = @_;
16 use vars qw/$Tag $Scratch $CGI $Session $Variable/;
17 my $only_last = $::Variable->{BREADCRUMB_ONLY_LAST} || 'ord/basket login';
18 my $exclude = $::Variable->{BREADCRUMB_EXCLUDE};
19 my $max = $number || $::Variable->{BREADCRUMB_MAX} || 6;
24 my @exclude = split /[\s,\0]+/, $exclude;
25 my @only_last = split /[\s,\0]+/, $only_last;
26 @exclude{@exclude} = @exclude;
27 @only_last{@only_last} = @only_last;
29 my $curpage = $Global::Variable->{MV_PAGE};
30 my $titles = $Scratch->{bc_titles} ||= {};
35 my @items = split m{/}, $url;
42 elsif(s/^va=banner_text=//) {
46 return ($title, $title);
50 my $curhist = $Session->{History}->[-1] || [];
51 my $curparams = $curhist->[1] || {};
55 my $curfull = $curhist->[0];
56 $curfull =~ s/$Vend::Cfg->{HTMLsuffix}$//;
58 my ($curaction,$curpath) = split m{/}, $curfull, 2;
60 my $ptitle = $opt->{title} || $curparams->{short_title};
61 $ptitle ||= $Scratch->{short_title};
67 if($special{$curaction} and ! $ptitle) {
68 ($ptitle, $keyname) = $special{$curaction}->($curpath);
73 $db = Vend::Data::product_code_exists_ref($Vend::Flypart)
76 my $tab = $db->name();
77 my $record = tag_data($tab, undef, $Vend::Flypart, { hash => 1});
78 $ptitle = $keyname = $record->{$Vend::Cfg->{DescriptionField}};
80 if($record and $record->{prod_group}) {
82 push @parms, "fi=$tab";
83 push @parms, "co=yes";
85 push @parms, "sf=prod_group";
86 push @parms, "se=$record->{prod_group}";
89 key => $record->{prod_group},
90 title => $record->{prod_group},
92 url => $Tag->area({ search => join("\n", @parms) }),
95 if($record and $record->{category}) {
97 push @parms, "fi=$tab";
98 push @parms, "co=yes";
100 if($record->{prod_group}) {
101 push @parms, "sf=prod_group";
102 push @parms, "se=$record->{prod_group}";
103 push @parms, "op=eq";
105 push @parms, "sf=category";
106 push @parms, "se=$record->{category}";
107 push @parms, "op=eq";
109 key => $record->{category},
110 title => $record->{category},
111 description => undef,
112 url => $Tag->area({ search => join "\n", @parms }),
118 $ptitle = $Scratch->{page_title};
119 $ptitle =~ s/(\s*\W+\s*)?$Variable->{COMPANY}(\s*\W+\s*)?//;
125 $keyname ||= $curpage;
127 $titles->{$curpage} = $ptitle if $ptitle;
129 my %exclude_param = qw(
134 if($Scratch->{bread_reset} || $CGI->{bread_reset}) {
135 delete $Session->{breadcrumbs};
138 my $crumbs = $Session->{breadcrumbs} ||= [];
141 if($opt->{reset_on_product} and @extra) {
142 #::logDebug("Resetting based on product");
146 if(! $exclude{$curpage}) {
148 if(! $CGI->{bread_no_params}) {
149 for(grep !$exclude_param{$_}, keys %$curparams) {
151 $form .= join("\n$_=", split /\0/, $curparams->{$_});
156 title => HTML::Entities::encode($ptitle),
157 description => HTML::Entities::encode($Scratch->{page_description}),
158 url => $Tag->area({ href => $curfull, form => $form, secure => $CGI->{secure} }),
162 push @$crumbs, @extra if @extra;
163 push @$crumbs, $crumb if $crumb;
166 my @new = grep !$seen{$_->{key}}++, reverse @$crumbs;
170 ## Kill ones that only are allowed in last position
171 if( $did_one and $only_last{$_->{key}}) {
181 @$crumbs = grep $_, reverse @new;
183 my $tpl = $opt->{template} || <<EOF;
184 <a href="{url}"{description?} title="{description}"{/description?} class=breadlink>{title}</a>
189 next unless ref($_) eq 'HASH' and $_->{url};
190 my $link = tag_attr_list($tpl, $_);
191 #::logDebug("link=$link from:\ntpl=$tpl\ncrumb=" . ::uneval($_));
195 $opt->{joiner} = ' > ' unless defined $opt->{joiner};
196 return join $opt->{joiner}, @out;