[ic] PreFork Yes causing strange results
Bill Carr
interchange-users@icdevgroup.org
Wed Jun 25 17:19:01 2003
--=-OgdjH6zYsLmpeaSMHIxR
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Wed, 2003-06-25 at 13:05, Kevin Walsh wrote:
> Bill Carr [bill@worldwideimpact.com] wrote:
> >
> > I have a user tag called image. It predates the IC tag of the same name.
> > Anyway, it's job is to look into a database table and figure out an
> > appropriate HTML image tag to return for a given thingy. Usually the
> > thingy is an item but it could be a brand or something else. If I run
> > with PreFork Yes I do not get any images or error messages. If I run
> > with PreFork No the tag works as expected. How do I begin to debug this?
> >
> If you post the UserTag here then someone may be able to spot something
> that you've missed.
--
Bill Carr
Worldwide Impact
bill@worldwideimpact.com
413-253-6700
--=-OgdjH6zYsLmpeaSMHIxR
Content-Disposition: attachment; filename=image.tag
Content-Type: text/plain; name=image.tag; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
UserTag image Order classid identity view alt align width height border detailpage detailpagewidth tolerance number ls default
UserTag image Routine <<EOR
sub {
my $params;
for ('classid','identity','view','alt','align','width','height','border','detailpage','detailpagewidth','tolerance','number','ls','default') {
$params->{$_} = shift;
}
################################################################################
# Defaults
$params->{classid} = q{item} unless $params->{classid};
my $default_image;
$default_image = qq{<img src=$params->{default} border=$params->{border}>} if $params->{default};
unless ($params->{identity}) {
&Log("No `identity' in image tag");
return $default_image;
}
my $BN_DB = $Variable->{BN_DB};
my $db = &Vend::Data::database_exists_ref("$BN_DB.images");
unless ($db) {
&Log("Unable to get DB handle $BN_DB.images: $!\n");
return $default_image;
}
$params->{view} = &get_views($db) unless $params->{view};
my ($default_width,$r) = split /,/,$Variable->{BN_IMAGE_WIDTHS},2;
my @bn_image_widths = sort { $b <=> $a} split /\D+/,$Variable->{BN_IMAGE_WIDTHS};
$params->{width} = $default_width unless $params->{width} || $params->{height};
$params->{border} = q{0} unless $params->{border};
$params->{detailpage} = q{image} unless $params->{detailpage};
$params->{detailpagewidth} = 'max' unless $params->{detailpagewidth};
undef $params->{detailpage} if $params->{detailpage} =~ /(none|0|null)/i;
$params->{number} = 1 unless $params->{number};
$params->{ls} = '<br><br>' unless $params->{ls};
$params->{base_image_url} = $Global::Variable->{BN_IMAGE_URL} || q{/images/bn};
my @out;
my %images = &get_images($db,$params);
my @views;
@views = split ',', $params->{view};
for (my $i = 0;$views[$i] && $#out + 1 < $params->{number};$i++) {
my ($classid,$typeid) = split '\.', $views[$i];
push @out, &html_img($params,\%images,$classid,$typeid,@bn_image_widths) if $images{$classid}{$typeid};
}
$Scratch->{image_count} = $#out + 1;
return (join $params->{ls}, @out) || $default_image;
################################################################################
sub get_views {
my $db = shift;
my $sql = q{SELECT CONCAT(classid,'.',typeid) FROM types};
my $rows = $db->query({
query => $sql,
st => 'db'
});
my @views;
for my $row (@$rows) {
push @views, $row->[0];
}
return join ',', @views;
}
################################################################################
sub widest_width {
my ($image_file,@bn_image_widths) = @_;
for (@bn_image_widths) {
return $_ if (-f "$Variable->{BN_IMAGE_DIR}/$_/$image_file")
}
return 0;
}
################################################################################
sub html_img {
my ($params,$images,$classid,$typeid,@bn_image_widths) = @_;
my $out = '';
my @out;
for my $image (@{$images->{$classid}->{$typeid}}) {
my $image_file = "$image->{imageid}.$image->{format}";
my $widest_width = &widest_width($image_file,@bn_image_widths);
my $detailpage_link;
if (
$params->{detailpage}
&&
(
($params->{detailpagewidth} eq 'max' && $widest_width > $params->{width})
|| $params->{detailpagewidth} <= $widest_width
)
) {
$detailpage_link = $Tag->area({
href => $params->{detailpage},
form => qq{
classid=$params->{classid}
identity=$params->{identity}
view=$classid.$typeid
align=$params->{align}
detailpage=$params->{detailpage}
tolerance=$params->{tolerance}
width=$widest_width
ls=$params->{ls}
}
});
} else {
undef $detailpage_link;
}
my $out = q{};
my ($width, $height);
SWITCH: {
if ($params->{width} eq 'max') {
$width = $widest_width;
$height = int($image->{height} * $widest_width / $image->{width}) + 1;
last SWITCH;
}
if ($params->{width} =~ /\%/) {
$height = $width = $params->{width};
last SWITCH;
}
if ($params->{height} =~ /\%/) {
$width = $height = $params->{height};
last SWITCH;
}
if ($params->{width}) {
$width = $params->{width};
$height = int($image->{height} * $params->{width} / $image->{width}) + 1;
}
if ($params->{height} && (!$params->{width} || $height > $params->{height})) {
$height = $params->{height};
$width = int($image->{width} * $params->{height} / $image->{height}) + 1;
}
}
my $image_width_dir;
if ($params->{width} eq 'max') {
$image_width_dir = $widest_width;
} else {
for (@bn_image_widths) {
$image_width_dir = $_;
last if $_ <= $width;
}
}
$out .= qq{<a href="$detailpage_link">} if ($params->{detailpage} && $detailpage_link);
$out .= qq{<img src="$params->{base_image_url}/$image_width_dir/$image_file"};
$out .= qq{ WIDTH="$width"};
$out .= qq{ HEIGHT="$height"};
$out .= qq{ ALT="}.($params->{alt} ? $params->{alt} : $image->{caption}).q{"};
$out .= qq{ ALIGN="$params->{align}"} if $params->{align};
$out .= qq{ BORDER="$params->{border}"};
$out .= q{>};
$out .= q{</a>} if $params->{detailpage};
if ($Tag->acl('admin@bottlenose')) {
my $mv_nextpage = $Tag->var('MV_PAGE',1);
$Scratch->{'deleteImage'.$image->{imageid}} = "[delete_image $image_file]";
my $delete_link = $Tag->area( {
href => 'process',
form => qq{
mv_todo=go
mv_click=deleteImage$image->{imageid}
mv_nextpage=$mv_nextpage
itemid=$CGI->{itemid}
brandid=$CGI->{brandid}
}
} );
$out .= qq{ <a onclick="return confirm('Are you sure you want to delete $image_file? This should only be used for broken or duplicate image.')"
href=$delete_link><img src=/images/wi/delsm.gif border=0></a><br>};
}
push @out, $out;
}
return @out;
}
################################################################################
sub get_images {
my ($db,$params) = @_;
my %images;
my $sql;
if ($params->{classid} eq 'item') {
$sql = qq{SELECT
imageid,
classid,
typeid,
COALESCE(
caption,
CONCAT(
brands.brand,
' ',
items.title,
' ',
items.vintage
)
) AS caption,
format,
width,
height
FROM
$Variable->{BN_DB}.items
LEFT JOIN
$Variable->{BN_DB}.brands USING(brandid)
LEFT JOIN
$Variable->{BN_DB}.regions ON items.regionid=regions.regionid
LEFT JOIN
$Variable->{BN_DB}.images ON (
(classid='item' AND identity=items.itemid)
OR
(classid='brand' AND identity=brands.brandid)
OR
(classid='region' AND identity=regions.regionid)
)
WHERE
items.itemid='$params->{identity}'
};
} else {
my $class = $params->{classid} || 'brandid';
$class =~ s/id$//;
my $table = $class;
$table =~ s/country/countries/;
$table =~ s/([^s])$/$1s/;
$sql = qq{SELECT
imageid,
classid,
typeid,
COALESCE(caption,$class),
format,
width,
height
FROM
$Variable->{BN_DB}.images
LEFT JOIN
$Variable->{BN_DB}.$table ON }.$class.q{id='}.$params->{identity}.qq{'
WHERE
classid='$params->{classid}' AND identity='$params->{identity}'
};
}
$sql .= qq{ AND width >= $params->{width}} if $params->{width} =~ /^\d+$/;
#$sql =~ s/\s+/ /g;
#::logDebug($sql);
my $rows = $db->query({
query => $sql,
st => 'db'
});
for my $row (@$rows) {
my %image;
$image{imageid} = $row->[0];
$image{caption} = $row->[3];
$image{format} = $row->[4];
$image{width} = $row->[5];
$image{height} = $row->[6];
push @{$images{$row->[1]}{$row->[2]}}, { %image };
}
return %images;
}
}
EOR
UserTag image Documentation <<EOD
=head1 NAME
image
=head1 SYNOPSIS
[image classid=E<lt>classidE<gt> identity=E<lt>itemidE<gt> view=E<lt>classid.typeid,...E<gt> width=E<lt>widthE<gt>]
=head1 DESCRPIPTION
Use this tag to place images from the Bottlenose(TM) Database on IC enabled web pages. The tag returns a series of HTML IMG tags. The tag will create a link to a page for displaying the image in greater detail. The scratch variable C<image_count> will be set indicating the number of images returned.
=head1 PARAMETERS
=over 4
=item classid
Required. The class of the identity. See the Bottlenose Database classes table.
=item identity
Required. The id of the class. If the classid is C<item> then the identity is the itemid.
=item view
This is a comma seperated list of the desired views. A view consists of a classid and typeid seperated by a C<.>
=item alt
HTML output for the img alt parameter
=item align
HTML output for the img align parameter
=item width
=item height
=item border
HTML output for the img border parameter
=item detailpage
Default: image
Set to the IC page to display detailed image views. A link will be generated for the image to the specified detail page. Start from the IC pages directory and specify in IC style similar to setting MV_NEXTPAGE. Set to C<none> for no link.
=item detailpagewidth
Default: 320
Set to the desired image width for the detail page. Will check to make sure the image exists for the given width before returning a link.
=item tolerance
The amount of allowable scaling for the image in percentage. If the tolerance is set at 100% and the width is set to 100 then an image would be returned if it's base width is at least 50 pixels. This parameter is used to specify the maximum amount an image is to be scaled up. Any amount of scaling down is permitted.
=item number
Default: 1
The number of images to return.
=item ls
ls - line seperator. This is the seperator used when image returns multiuple images. Default: E{<}brE{>}E{<}brE{>}
=item default
A default image to return if no other images are available
=back
=head1 CONFIGURATION
catalog.cfg should be configured with the images table from the Bottlenose(TM) Database
=head2 Example
Database images images.txt __BN_DSN__
=head2 Global Variables
These should be set in the C<interchange.cfg> file.
=over 8
=item BN_IMAGE_DIR
The full path to base image directory. I</www/bnose.com/htdocs/images>
=item BN_IMAGE_URL
The URL to the base images. I<http://bnose.com/images>
=item BN_WIDTHS
A comma seperated list of the standard image widths I<50,100,160,320>
=item BN_DB
The name of the Bottlenose database
=back
=head1 AUTHOR
Bill Carr
=head1 COPYRIGHT
Copyright (c) 2001 Worldwide Impact, Inc. Amherst, MA 413.253.6700
All rights reserved
=cut
EOD
--=-OgdjH6zYsLmpeaSMHIxR--