1 # Copyright 2002-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: component.tag,v 1.10 2009-05-01 13:50:00 pajamian Exp $
10 UserTag component Order component
11 UserTag component addAttr
12 UserTag component NoReparse 1
13 UserTag component Version $Revision: 1.10 $
14 UserTag component Routine <<EOR
16 my ($name, $opt) = @_;
28 my @override = grep ! $ignore{$_}, keys %$opt;
30 my $control = $::Control->[$::Scratch->{control_index}];
31 for(grep $_ !~ /^comp(?:onent)?_?/, keys %$opt) {
32 $control->{$_} = $opt->{$_};
35 $name ||= $control->{component};
36 $name ||= $opt->{default};
38 if (! $name or $name eq 'none') {
39 # Increment control_index so empty component has no side effect
40 $::Scratch->{control_index}++;
44 my $t = $opt->{comp_table} || $::Variable->{MV_COMPONENT_TABLE} || 'component';
45 my $ctab = $::Variable->{MV_COMPONENT_CACHE} || 'component_cache';
48 my $db = database_exists_ref($t);
52 if(my $when = $Vend::Session->{teleport}) {
56 WHERE base_code = '$name'
57 AND expiration_date < $when
58 AND show_date >= $when
59 ORDER BY show_date DESC
61 my $ary = $db->query($q);
62 if($ary and $ary->[0]) {
66 $record = $db->row_hash($name);
71 my $body = $record->{comptext};
74 my $dir = $opt->{comp_dir}
75 || $::Variable->{MV_COMPONENT_DIR}
76 || 'templates/components';
77 $body = readfile("$dir/$name",undef,1);
80 # Increment control_index so empty component has no side effect
82 $::Scratch->{control_index}++;
92 and $record->{cache_interval}
93 and $cdb = database_exists_ref($ctab)
98 # Cache based not only on name, but control values specified
99 if($record->{cache_options}) {
100 my @opts = split /[\s,\0]+/, $record->{cache_options};
102 $cache_it .= generate_key( join "\0", @{$control}{@opts});
105 $crecord = $cdb->row_hash($cache_it) || {};
108 my $exp = adjust_time($record->{cache_interval}, $crecord->{cache_time});
111 # Increment control_index as not done below
112 $::Scratch->{control_index}++;
113 return $crecord->{compcache};
117 my $result = interpolate_html($body);
118 $::Scratch->{control_index}++;
121 compcache => $result,
124 $cdb->set_slice($cache_it, $thing);
127 if($record->{output}) {
128 Vend::Interpolate::substitute_image(\$result)
129 unless $opt->{no_image_substitute};
130 $Tag->output_to($record->{output}, undef, $result);