[7331] | 1 | ##########################################################################
|
---|
[6808] | 2 | #
|
---|
| 3 | # Collage.pm --
|
---|
| 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
[6968] | 26 | package Collage;
|
---|
[6808] | 27 |
|
---|
[17209] | 28 | use BaseClassifier;
|
---|
[6808] | 29 | use sorttools;
|
---|
| 30 |
|
---|
[10253] | 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 33 |
|
---|
[6808] | 34 | sub BEGIN {
|
---|
[17209] | 35 | @Collage::ISA = ('BaseClassifier');
|
---|
[6808] | 36 | }
|
---|
| 37 |
|
---|
| 38 | my $arguments =
|
---|
| 39 | [ { 'name' => "buttonname",
|
---|
[10485] | 40 | 'desc' => "{Collage.buttonname}",
|
---|
[6808] | 41 | 'type' => "string",
|
---|
[6968] | 42 | 'deft' => "Collage",
|
---|
[7331] | 43 | 'reqd' => "no" },
|
---|
| 44 | { 'name' => "geometry",
|
---|
[7405] | 45 | 'desc' => "{Collage.geometry}",
|
---|
[7331] | 46 | 'type' => "string",
|
---|
| 47 | 'deft' => "600x300",
|
---|
| 48 | 'reqd' => "no" },
|
---|
| 49 | { 'name' => "verbosity",
|
---|
| 50 | 'desc' => "{BasClas.verbosity}",
|
---|
| 51 | 'type' => "string",
|
---|
| 52 | 'deft' => "5",
|
---|
| 53 | 'reqd' => "no" },
|
---|
| 54 | { 'name' => "maxDepth",
|
---|
[7405] | 55 | 'desc' => "{Collage.maxDepth}",
|
---|
[7331] | 56 | 'type' => "string",
|
---|
[7345] | 57 | 'deft' => "500"},
|
---|
[7331] | 58 | # { 'name' => "maxDownloads",
|
---|
[17209] | 59 | # 'desc' => "{Collage.maxDownloads}",
|
---|
[7331] | 60 | # 'type' => "string",
|
---|
| 61 | # 'deft' => "",
|
---|
| 62 | # 'reqd' => "no" },
|
---|
| 63 | { 'name' => "maxDisplay",
|
---|
[7405] | 64 | 'desc' => "{Collage.maxDisplay}",
|
---|
[7331] | 65 | 'type' => "string",
|
---|
| 66 | 'deft' => "25",
|
---|
| 67 | 'reqd' => "no" },
|
---|
| 68 | { 'name' => "imageType",
|
---|
[7405] | 69 | 'desc' => "{Collage.imageType}",
|
---|
[7331] | 70 | 'type' => "string",
|
---|
[7409] | 71 | 'deft' => ".jpg%%.png",
|
---|
[7331] | 72 | 'reqd' => "no" },
|
---|
| 73 | { 'name' => "bgcolor",
|
---|
[7405] | 74 | 'desc' => "{Collage.bgcolor}",
|
---|
[7331] | 75 | 'type' => "string",
|
---|
| 76 | 'deft' => "#96c29a",
|
---|
| 77 | 'reqd' => "no" },
|
---|
| 78 | { 'name' => "refreshDelay",
|
---|
[7405] | 79 | 'desc' => "{Collage.refreshDelay}",
|
---|
[7331] | 80 | 'type' => "string",
|
---|
| 81 | 'deft' => "1500",
|
---|
| 82 | 'reqd' => "no" },
|
---|
| 83 | { 'name' => "isJava2",
|
---|
[7405] | 84 | 'desc' => "{Collage.isJava2}",
|
---|
[7331] | 85 | 'type' => "string",
|
---|
| 86 | 'deft' => "auto",
|
---|
| 87 | 'reqd' => "no" },
|
---|
| 88 | { 'name' => "imageMustNotHave",
|
---|
[7405] | 89 | 'desc' => "{Collage.imageMustNotHave}",
|
---|
[7331] | 90 | 'type' => "string",
|
---|
[7405] | 91 | 'deft' => "hl=%%x=%%gt=%%gc=%%.pr",
|
---|
[7331] | 92 | 'reqd' => "no" },
|
---|
| 93 | { 'name' => "caption",
|
---|
[7405] | 94 | 'desc' => "{Collage.caption}",
|
---|
[7331] | 95 | 'type' => "string",
|
---|
[11474] | 96 | 'deft' => " ",
|
---|
[7331] | 97 | 'reqd' => "no" }
|
---|
| 98 | ];
|
---|
[6808] | 99 |
|
---|
[7331] | 100 |
|
---|
| 101 |
|
---|
| 102 |
|
---|
[6808] | 103 | my $options = { 'name' => "Collage",
|
---|
| 104 | 'desc' => "{Collage.desc}",
|
---|
[7409] | 105 | 'abstract' => "no",
|
---|
[6808] | 106 | 'inherits' => "Yes",
|
---|
| 107 | 'args' => $arguments };
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | sub new {
|
---|
[10218] | 111 | my ($class) = shift (@_);
|
---|
| 112 | my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 113 | push(@$classifierslist, $class);
|
---|
[6808] | 114 |
|
---|
[17209] | 115 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 116 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[6808] | 117 |
|
---|
[17209] | 118 | my $self = new BaseClassifier($classifierslist, $inputargs, $hashArgOptLists);
|
---|
[10253] | 119 |
|
---|
| 120 | if ($self->{'info_only'}) {
|
---|
| 121 | # don't worry about any options etc
|
---|
| 122 | return bless $self, $class;
|
---|
| 123 | }
|
---|
[6968] | 124 |
|
---|
[10218] | 125 | # Manually set $self parameters.
|
---|
| 126 | $self->{'list'} = {};
|
---|
| 127 | $self->{'buttonname'} = 'Collage' unless ($self->{'buttonname'});
|
---|
[6808] | 128 |
|
---|
| 129 | return bless $self, $class;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | sub init {
|
---|
| 133 | my $self = shift (@_);
|
---|
| 134 |
|
---|
| 135 | $self->{'list'} = [];
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | sub classify {
|
---|
| 139 |
|
---|
| 140 | my $self = shift (@_);
|
---|
[23116] | 141 | my ($doc_obj) = @_;
|
---|
[6808] | 142 |
|
---|
[9142] | 143 | my $has_image_type = 0;
|
---|
| 144 |
|
---|
| 145 | my @image_type_split = split(/%/,$self->{'imageType'});
|
---|
| 146 | my @image_type_ext = map { "($_)" } @image_type_split;
|
---|
| 147 | my $image_type_re = join("|",@image_type_ext);
|
---|
| 148 | $image_type_re =~ s/\./\\\./g;
|
---|
| 149 |
|
---|
| 150 | my $assoc_files = $doc_obj->{'associated_files'};
|
---|
| 151 |
|
---|
| 152 | foreach my $af ( @$assoc_files ) {
|
---|
| 153 | my ($real_filename, $assoc_filename, $mime_type, $section) = @$af;
|
---|
| 154 | if ($assoc_filename =~ m/$image_type_re/) {
|
---|
| 155 | $has_image_type = 1;
|
---|
| 156 | last;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if ($has_image_type) {
|
---|
[18455] | 161 |
|
---|
[9142] | 162 | my $doc_OID = $doc_obj->get_OID();
|
---|
[18455] | 163 |
|
---|
[23116] | 164 | push (@{$self->{'list'}}, $doc_OID);
|
---|
| 165 |
|
---|
[9142] | 166 | }
|
---|
| 167 |
|
---|
[6808] | 168 | }
|
---|
| 169 |
|
---|
| 170 | sub get_classify_info {
|
---|
| 171 | my $self = shift (@_);
|
---|
| 172 |
|
---|
[7345] | 173 | my $items_per_page = 2;
|
---|
| 174 | my $max_items_per_page = 20;
|
---|
[6808] | 175 |
|
---|
[7345] | 176 | my @list = @{$self->{'list'}};
|
---|
[6808] | 177 |
|
---|
[7345] | 178 | my $outhandle = $self->{'outhandle'};
|
---|
| 179 | my $verbosity = $self->{'verbosity'};
|
---|
[6808] | 180 |
|
---|
[7345] | 181 | if ($verbosity>1) {
|
---|
[10218] | 182 | print $outhandle ("$self->{'buttonname'}\n");
|
---|
[7345] | 183 | }
|
---|
[6808] | 184 |
|
---|
[10218] | 185 | my $collage_head = $self->get_entry ($self->{'buttonname'}, "Collage", "Invisible");
|
---|
[7345] | 186 | my $collage_curr = $self->get_entry("Collage","VList");
|
---|
| 187 | push (@{$collage_head->{'contains'}},$collage_curr);
|
---|
| 188 |
|
---|
| 189 | my $global_c=1;
|
---|
| 190 | my $within_page_c=1;
|
---|
| 191 |
|
---|
[10253] | 192 | foreach my $oid (@list) {
|
---|
[7345] | 193 | if ($within_page_c>$items_per_page) {
|
---|
| 194 | my $title = "Items $global_c+";
|
---|
| 195 | my $nested_node = $self->get_entry($title,"VList");
|
---|
| 196 | push (@{$collage_curr->{'contains'}}, $nested_node);
|
---|
| 197 | $collage_curr = $nested_node;
|
---|
| 198 |
|
---|
| 199 | $within_page_c=1;
|
---|
| 200 |
|
---|
| 201 | $items_per_page++ if ($items_per_page < $max_items_per_page);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | push (@{$collage_curr->{'contains'}}, {'OID'=>$oid});
|
---|
| 205 | $global_c++;
|
---|
| 206 | $within_page_c++;
|
---|
[6808] | 207 | }
|
---|
| 208 |
|
---|
[7345] | 209 | return $collage_head;
|
---|
[6808] | 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | sub get_entry {
|
---|
| 214 | my $self = shift (@_);
|
---|
| 215 | my ($title, $childtype, $thistype) = @_;
|
---|
[7331] | 216 |
|
---|
[7345] | 217 | # organise into classification structure
|
---|
| 218 | my %classifyinfo = ('childtype'=>$childtype,
|
---|
| 219 | 'Title'=>$title,
|
---|
| 220 | 'contains'=>[]);
|
---|
[7331] | 221 |
|
---|
[7345] | 222 | $classifyinfo{'thistype'} = $thistype if (defined $thistype);
|
---|
[7331] | 223 |
|
---|
[7345] | 224 | if ($childtype eq "Collage") {
|
---|
| 225 | my $geometry = $self->{'geometry'};
|
---|
| 226 | my ($x_dim,$y_dim) = ($geometry =~ m/^(.*)x(.*)$/);
|
---|
| 227 | my $verbosity = $self->{'verbosity'};
|
---|
| 228 | my $maxDepth = $self->{'maxDepth'};
|
---|
| 229 | # my $maxDownloads = $self->{'maxDownloads'};
|
---|
| 230 | my $maxDisplay = $self->{'maxDisplay'};
|
---|
| 231 | my $imageType = $self->{'imageType'};
|
---|
| 232 | my $bgcolor = $self->{'bgcolor'};
|
---|
| 233 | my $refreshDelay = $self->{'refreshDelay'};
|
---|
| 234 | my $isJava2 = $self->{'isJava2'};
|
---|
| 235 | my $imageMustNotHave = $self->{'imageMustNotHave'};
|
---|
| 236 | my $caption = $self->{'caption'};
|
---|
| 237 |
|
---|
[10253] | 238 | #if (!defined($maxDownloads)) {
|
---|
| 239 | # $maxDownloads="";
|
---|
| 240 | #}
|
---|
[7331] | 241 |
|
---|
[7345] | 242 | my $parameters;
|
---|
[7331] | 243 |
|
---|
[7345] | 244 | $parameters = "xdim=".$x_dim;
|
---|
| 245 | $parameters .= ";ydim=".$y_dim;
|
---|
| 246 | $parameters .= ";geometry=".$self->{'geometry'};
|
---|
| 247 | $parameters .= ";verbosity=".$self->{'verbosity'};
|
---|
| 248 | $parameters .= ";maxDepth=".$self->{'maxDepth'};
|
---|
| 249 | # $parameters .= ";maxDownloads=".$maxDownloads;
|
---|
| 250 | $parameters .= ";maxDisplay=".$self->{'maxDisplay'};
|
---|
| 251 | $parameters .= ";imageType=".$self->{'imageType'};
|
---|
| 252 | $parameters .= ";bgcolor=".$self->{'bgcolor'};
|
---|
| 253 | $parameters .= ";refreshDelay=".$self->{'refreshDelay'};
|
---|
| 254 | $parameters .= ";isJava2=".$self->{'isJava2'};
|
---|
| 255 | $parameters .= ";caption=".$self->{'caption'};
|
---|
[7331] | 256 |
|
---|
[7345] | 257 | # $parameters .= ";imageMustNotHave=".$self->{'imageMustNotHave'};
|
---|
| 258 |
|
---|
[6808] | 259 |
|
---|
[7345] | 260 | $classifyinfo{'parameters'} = $parameters;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[6808] | 263 | return \%classifyinfo;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | 1;
|
---|