source: trunk/cic-hcap/perllib/plugins/CICPlug.pm@ 11972

Last change on this file since 11972 was 11972, checked in by mdewsnip, 18 years ago

State metadata now includes the area (West/Mountain/Southwest/Midwest/Southeast/Northeast), for the advanced search page.

  • Property svn:keywords set to Author Date Id Revision
File size: 51.1 KB
Line 
1###########################################################################
2#
3# CICPlug.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) 2005 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
26package CICPlug;
27
28
29use BasPlug;
30use DBI;
31use strict;
32no strict 'refs';
33
34
35sub BEGIN {
36 @CICPlug::ISA = ('BasPlug');
37}
38
39
40my $arguments =
41 [
42 { 'name' => "images_directory",
43 'type' => "string",
44 'deft' => "",
45 'reqd' => "yes" },
46 { 'name' => "cache_directory",
47 'type' => "string",
48 'deft' => &util::filename_cat($ENV{'GSDLHOME'}, "tmp"),
49 'reqd' => "no" },
50 { 'name' => "large_image_options",
51 'type' => "string",
52 'deft' => "",
53 'reqd' => "no" },
54 { 'name' => "large_image_type",
55 'type' => "string",
56 'deft' => "jpg",
57 'reqd' => "no" },
58 { 'name' => "large_image_width",
59 'type' => "string",
60 'deft' => "1250",
61 'reqd' => "no" },
62 { 'name' => "medium_image_options",
63 'type' => "string",
64 'deft' => "",
65 'reqd' => "no" },
66 { 'name' => "medium_image_type",
67 'type' => "string",
68 'deft' => "jpg",
69 'reqd' => "no" },
70 { 'name' => "medium_image_width",
71 'type' => "string",
72 'deft' => "375",
73 'reqd' => "no" },
74 { 'name' => "small_image_options",
75 'type' => "string",
76 'deft' => "",
77 'reqd' => "no" },
78 { 'name' => "small_image_type",
79 'type' => "string",
80 'deft' => "jpg",
81 'reqd' => "no" },
82 { 'name' => "small_image_width",
83 'type' => "string",
84 'deft' => "125",
85 'reqd' => "no" }
86 ];
87
88my $options = { 'name' => "CICPlug",
89 'desc' => "{CICPlug.desc}",
90 'abstract' => "no",
91 'inherits' => "yes" };
92
93
94sub get_default_process_exp
95{
96 return q^(?i)\.mdb$^;
97}
98
99
100sub new
101{
102 my ($class) = shift (@_);
103 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
104 push(@$pluginlist, $class);
105
106 if (defined $arguments) { push(@{$hashArgOptLists->{"ArgList"}}, @{$arguments}); }
107 if (defined $options) { push(@{$hashArgOptLists->{"OptList"}}, $options); }
108
109 my $self = (defined $hashArgOptLists) ? new BasPlug($pluginlist,$inputargs,$hashArgOptLists) : new BasPlug($pluginlist,$inputargs);
110
111 return bless $self, $class;
112}
113
114
115my $state_abbr_to_name_mapping = {
116 "AL" => "Alabama",
117 "AK" => "Alaska",
118 "AZ" => "Arizona",
119 "AR" => "Arkansas",
120 "CA" => "California",
121 "CO" => "Colorado",
122 "CT" => "Connecticut",
123 "DE" => "Delaware",
124 "FL" => "Florida",
125 "GA" => "Georgia",
126 "HI" => "Hawaii",
127 "ID" => "Idaho",
128 "IL" => "Illinois",
129 "IN" => "Indiana",
130 "IA" => "Iowa",
131 "KS" => "Kansas",
132 "KY" => "Kentucky",
133 "LA" => "Louisiana",
134 "ME" => "Maine",
135 "MD" => "Maryland",
136 "MA" => "Massachusetts",
137 "MI" => "Michigan",
138 "MN" => "Minnesota",
139 "MS" => "Mississippi",
140 "MO" => "Missouri",
141 "MT" => "Montana",
142 "NE" => "Nebraska",
143 "NV" => "Nevada",
144 "NH" => "New Hampshire",
145 "NJ" => "New Jersey",
146 "NM" => "New Mexico",
147 "NY" => "New York",
148 "NC" => "North Carolina",
149 "ND" => "North Dakota",
150 "OH" => "Ohio",
151 "OK" => "Oklahoma",
152 "OR" => "Oregon",
153 "PA" => "Pennsylvania",
154 "RI" => "Rhode Island",
155 "SC" => "South Carolina",
156 "SD" => "South Dakota",
157 "TN" => "Tennessee",
158 "TX" => "Texas",
159 "UT" => "Utah",
160 "VT" => "Vermont",
161 "VA" => "Virginia",
162 "WA" => "Washington",
163 "WV" => "West Virginia",
164 "WI" => "Wisconsin",
165 "WY" => "Wyoming"
166 };
167
168my $state_abbr_to_area_mapping = {
169 "AL" => "Southeast",
170 "AK" => "West",
171 "AZ" => "Southwest",
172 "AR" => "Southeast",
173 "CA" => "West",
174 "CO" => "Mountain",
175 "CT" => "Northeast",
176 "DE" => "Northeast",
177 "FL" => "Southeast",
178 "GA" => "Southeast",
179 "HI" => "West",
180 "ID" => "Mountain",
181 "IL" => "Midwest",
182 "IN" => "Midwest",
183 "IA" => "Midwest",
184 "KS" => "Midwest",
185 "KY" => "Southeast",
186 "LA" => "Southeast",
187 "ME" => "Northeast",
188 "MD" => "Northeast",
189 "MA" => "Northeast",
190 "MI" => "Midwest",
191 "MN" => "Midwest",
192 "MS" => "Southeast",
193 "MO" => "Midwest",
194 "MT" => "Mountain",
195 "NE" => "Midwest",
196 "NV" => "West",
197 "NH" => "Northeast",
198 "NJ" => "Northeast",
199 "NM" => "Southwest",
200 "NY" => "Northeast",
201 "NC" => "Southeast",
202 "ND" => "Midwest",
203 "OH" => "Midwest",
204 "OK" => "Southwest",
205 "OR" => "West",
206 "PA" => "Northeast",
207 "RI" => "Northeast",
208 "SC" => "Southeast",
209 "SD" => "Midwest",
210 "TN" => "Southeast",
211 "TX" => "Southwest",
212 "UT" => "Mountain",
213 "VT" => "Northeast",
214 "VA" => "Southeast",
215 "WA" => "West",
216 "WV" => "Southeast",
217 "WI" => "Midwest",
218 "WY" => "Mountain"
219 };
220
221
222my $place_type_id_to_name_mapping = {
223 "1" => "Individual building",
224 "2" => "Landscape site",
225 "3" => "Campus arrangement",
226 "4" => "Building group",
227};
228
229
230sub read
231{
232 my $self = shift (@_);
233 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
234
235 $self->{'filename'} = &util::filename_cat($base_dir, $file);
236 if ($self->{'filename'} !~ /$self->{'process_exp'}/ || !-f $self->{'filename'}) {
237 return undef;
238 }
239 $self->{'processor'} = $processor;
240 $self->{'gli'} = $gli;
241
242 # Open connection to Access database
243 my $dbh = DBI->connect('dbi:ODBC:CIC-HCAP');
244
245 $self->process_institutions($dbh);
246 $self->process_places($dbh);
247 $self->process_designers($dbh);
248
249 return 1;
250}
251
252
253sub process_institutions
254{
255 my $self = shift(@_);
256 my $dbh = shift(@_);
257 my $fail_log_handle = $self->{'failhandle'};
258
259 # Prepare SQL statement for getting everything from the Institution table
260 my $institution_sql_statement = "SELECT * FROM tblInstitution"; # WHERE Institution_ID<200";
261 my $institution_sql_handle = $dbh->prepare($institution_sql_statement);
262 $institution_sql_handle->{LongReadLen} = 65536;
263 $institution_sql_handle->execute() or die "Could not execute SQL statement.";
264
265 # Prepare SQL statement for getting the Institution places
266 my $institution_places_sql_statement = "SELECT Entry_ID,Current_name FROM tblPlace WHERE PlaceType>0 AND Institution_ID=?";
267 my $institution_places_sql_handle = $dbh->prepare($institution_places_sql_statement);
268 $institution_places_sql_handle->{LongReadLen} = 65536;
269
270 # Prepare SQL statement for getting the Institution best place image location
271 my $institution_best_place_image_location_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND FileName=?";
272 my $institution_best_place_image_location_sql_handle = $dbh->prepare($institution_best_place_image_location_sql_statement);
273 $institution_best_place_image_location_sql_handle->{LongReadLen} = 65536;
274
275 # Prepare SQL statement for getting the Institution places images
276 my $institution_places_images_sql_statement = "SELECT FileName FROM tblImages,tblPlace WHERE tblImages.FileType=1 AND tblImages.Entry_ID=tblPlace.Entry_ID AND tblPlace.Institution_ID=?";
277 my $institution_places_images_sql_handle = $dbh->prepare($institution_places_images_sql_statement);
278 $institution_places_images_sql_handle->{LongReadLen} = 65536;
279
280 # Prepare SQL statement for getting the Institution campus plans
281 my $institution_campus_plans_sql_statement = "SELECT * FROM tblCampusMaps WHERE Electronic=1 AND Institution_ID=?";
282 my $institution_campus_plans_sql_handle = $dbh->prepare($institution_campus_plans_sql_statement);
283 $institution_campus_plans_sql_handle->{LongReadLen} = 65536;
284
285 # Create a document object for each institution
286 my %institution_id_to_name_mapping;
287 my %institution_state_to_ids_mapping;
288 while (my $row_hashref = $institution_sql_handle->fetchrow_hashref) {
289 # Skip any institutions that didn't respond
290 next if !defined($row_hashref->{"City"});
291
292 my $institution_id = $row_hashref->{"Institution_ID"};
293 # print STDERR " Institution $institution_id\n";
294 my $institution_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
295 $institution_doc_obj->set_OID("i$institution_id");
296 &new_metadata_entry($institution_doc_obj, "DocumentType", "Institution");
297
298 # For some reason the hyphen seems to be lost from the Zip field, so add it back in
299 my $institution_zip = $row_hashref->{"Zip"};
300 if ($institution_zip =~ /^(\d\d\d\d\d)(\d\d\d\d)$/) {
301 $row_hashref->{"Zip"} = $1 . "-" . $2;
302 }
303
304 # Map state to full name
305 $row_hashref->{"State"} = $state_abbr_to_name_mapping->{$row_hashref->{"State"}};
306
307 # Get the places in this institution
308 my $institution_random_place_id;
309 my $institution_places_list_html = "";
310 $institution_places_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
311 while (my $institution_places_match_hashref = $institution_places_sql_handle->fetchrow_hashref) {
312 my $institution_place_id = $institution_places_match_hashref->{"Entry_ID"};
313 my $institution_place_name = $institution_places_match_hashref->{"Current_name"};
314 $institution_places_list_html .= "<span class=\"cictext\"><a href=\"_gwcgi_?a=d&d=p$institution_place_id\">$institution_place_name</a></span><br />\n";
315 }
316 &new_metadata_entry($institution_doc_obj, "InstitutionPlacesListHTML", $institution_places_list_html);
317
318 # Get the best place image for this institution
319 my $institution_best_place_image_name = $row_hashref->{"Best_image"};
320 if (!defined($institution_best_place_image_name) || $institution_best_place_image_name eq "") {
321 # Some institutions have no electronic images, and thus have no best image
322 $institution_places_images_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
323 if (defined($institution_places_images_sql_handle->fetchrow_hashref())) {
324 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='No best image'>\n" if ($self->{'gli'});
325 print STDERR "Error: Institution $institution_id -- No best image.\n";
326 print $fail_log_handle "Error: Institution $institution_id -- No best image.\n";
327 $self->{'num_not_processed'}++;
328 next;
329 }
330 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "");
331 }
332 else {
333 # Get the file location of the best place image for this institution
334 $institution_best_place_image_location_sql_handle->execute($institution_best_place_image_name) or die "Could not execute SQL statement.";
335 my $institution_best_place_image_location = $institution_best_place_image_location_sql_handle->fetchrow();
336 if (!defined($institution_best_place_image_location) || $institution_best_place_image_location eq "") {
337 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='Could not match best image $institution_best_place_image_name to a file'>\n" if ($self->{'gli'});
338 print STDERR "Error: Institution $institution_id -- Could not match best image $institution_best_place_image_name to a file.\n";
339 print $fail_log_handle "Error: Institution $institution_id -- Could not match best image $institution_best_place_image_name to a file.\n";
340 $self->{'num_not_processed'}++;
341 next;
342 }
343
344 # PDFs are not allowed for institution best place images
345 if ($institution_best_place_image_location =~ /.pdf$/i) {
346 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='PDF not allowed for best image'>\n" if ($self->{'gli'});
347 print STDERR "Error: Institution $institution_id -- PDF not allowed for best image.\n";
348 print $fail_log_handle "Error: Institution $institution_id -- PDF not allowed for best image.\n";
349 $self->{'num_not_processed'}++;
350 next;
351 }
352
353 my $institution_best_place_image_medium_file_href = $self->generate_place_image_variant($institution_doc_obj, $institution_best_place_image_location, "medium");
354 my $institution_best_place_image_large_file_href = $self->generate_place_image_variant($institution_doc_obj, $institution_best_place_image_location, "large");
355 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "<a href=\"$institution_best_place_image_large_file_href\"><img src=\"$institution_best_place_image_medium_file_href\"/><br /><span class=\"cictext\">$institution_best_place_image_name</span></a>");
356 }
357
358 # Get institution campus plans
359 my $institution_campus_plans_list_html = "";
360 $institution_campus_plans_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
361 while (my $institution_campus_plans_match_hashref = $institution_campus_plans_sql_handle->fetchrow_hashref) {
362 my $institution_campus_plan_name = $institution_campus_plans_match_hashref->{"NameAndFormat"};
363 my $institution_campus_plan_image_location = $institution_campus_plans_match_hashref->{"Location_electronic"};
364
365 # Deal with PDF files separately: don't convert, just associate
366 if ($institution_campus_plan_image_location =~ /\.pdf$/i) {
367 # Convert the server location of the file into the local location of the file
368 my $institution_campus_plan_pdf_file_path = $institution_campus_plan_image_location;
369 $institution_campus_plan_pdf_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
370
371 if (-f $institution_campus_plan_pdf_file_path) {
372 my $institution_campus_plan_pdf_file_name = $institution_campus_plan_name . ".pdf";
373 $institution_campus_plan_pdf_file_name =~ s/ /%20/g;
374 my $institution_campus_plan_pdf_file_href = "_httpcollection_/index/assoc/[assocfilepath]/$institution_campus_plan_pdf_file_name";
375 $institution_campus_plans_list_html .= "<a href=\"$institution_campus_plan_pdf_file_href\"><span class=\"cictext\">$institution_campus_plan_name (PDF)</span></a><br />";
376
377 $institution_doc_obj->associate_file($institution_campus_plan_pdf_file_path, $institution_campus_plan_name . ".pdf", undef, $institution_doc_obj->get_top_section());
378 }
379 else {
380 print STDERR "<ProcessingError n='$institution_campus_plan_pdf_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
381 print STDERR "Error: File $institution_campus_plan_pdf_file_path does not exist.\n";
382 print $fail_log_handle "Error: File $institution_campus_plan_pdf_file_path does not exist.\n";
383 }
384 }
385 else {
386 my $institution_campus_plan_image_large_file_href = $self->generate_place_image_variant($institution_doc_obj, $institution_campus_plan_image_location, "large");
387
388 # Create a new section for each institution campus plan image
389 my $institution_campus_plan_image_section = $institution_doc_obj->insert_section($institution_doc_obj->get_end_child($institution_doc_obj->get_top_section()));
390 $institution_doc_obj->add_utf8_text($institution_campus_plan_image_section, "_"); # This is necessary
391 $institution_doc_obj->add_utf8_metadata($institution_campus_plan_image_section, "DocumentType", "Image");
392 $institution_doc_obj->add_utf8_metadata($institution_campus_plan_image_section, "Title", $institution_campus_plan_name);
393 $institution_doc_obj->add_utf8_metadata($institution_campus_plan_image_section, "ImagePath", $institution_campus_plan_image_large_file_href);
394
395 $institution_campus_plans_list_html .= "<a href=\"_gwcgi_?a=d&d=i$institution_id.$institution_campus_plan_image_section\"><span class=\"cictext\">$institution_campus_plan_name</span></a><br />";
396 }
397 }
398 &new_metadata_entry($institution_doc_obj, "InstitutionCampusPlansListHTML", $institution_campus_plans_list_html);
399
400 # Add each field from the table as metadata
401 foreach my $key (keys(%$row_hashref)) {
402 my $value = $row_hashref->{$key};
403 if (defined($value)) {
404 &new_metadata_entry($institution_doc_obj, $key, $value);
405 }
406 }
407
408 $institution_doc_obj->add_utf8_text($institution_doc_obj->get_top_section(), "Some dummy text.");
409 $self->{'processor'}->process($institution_doc_obj);
410 $self->{'num_processed'}++;
411
412 # Build mappings for creating the static macrofiles
413 my $institution_name = $row_hashref->{"Institution_Name"};
414 $institution_id_to_name_mapping{$institution_doc_obj->get_OID()} = $institution_name;
415 my $institution_state = $row_hashref->{"State"};
416 push(@{$institution_state_to_ids_mapping{$institution_state}}, $institution_doc_obj->get_OID());
417 }
418
419 # Write the institutions.dm macrofile
420 &write_static_browser_macrofile("institutions", \%institution_id_to_name_mapping);
421
422 # Write the states.dm macrofile
423 &write_state_browser_macrofile("states", \%institution_state_to_ids_mapping, \%institution_id_to_name_mapping);
424}
425
426
427sub process_places
428{
429 my $self = shift(@_);
430 my $dbh = shift(@_);
431 my $fail_log_handle = $self->{'failhandle'};
432
433 # Prepare SQL statement for getting everything from the Place table
434 my $place_sql_statement = "SELECT * FROM tblPlace";
435 my $place_sql_handle = $dbh->prepare($place_sql_statement);
436 $place_sql_handle->{LongReadLen} = 65536;
437 $place_sql_handle->execute() or die "Could not execute SQL statement.";
438
439 # Prepare SQL statement for getting the Place institution
440 my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
441 my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
442
443 # Prepare SQL statement for getting the Place "date of construction"
444 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
445 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
446
447 # Prepare SQL statement for getting the Place images
448 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
449 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
450 $place_images_sql_handle->{LongReadLen} = 65536;
451
452 # Prepare SQL statement for getting the Place materials
453 my $place_materials_sql_statement = "SELECT * FROM tblDescription_building WHERE Entry_ID=?";
454 my $place_materials_sql_handle = $dbh->prepare($place_materials_sql_statement);
455 $place_materials_sql_handle->{LongReadLen} = 65536;
456
457 # Prepare SQL statement for getting the Place building styles
458 my $place_styles_sql_statement = "SELECT Architectural_Classification FROM tblArchTypes,jnxtblArchPlace WHERE tblArchTypes.ArchType_ID=jnxtblArchPlace.ArchType_ID AND Entry_ID=?";
459 my $place_styles_sql_handle = $dbh->prepare($place_styles_sql_statement);
460 $place_styles_sql_handle->{LongReadLen} = 65536;
461
462 # Prepare SQL statement for getting the Place functions
463 my $place_functions_sql_statement = "SELECT Function,Year,Prefix FROM tblFunction_and_dates WHERE Entry_ID=?";
464 my $place_functions_sql_handle = $dbh->prepare($place_functions_sql_statement);
465 $place_functions_sql_handle->{LongReadLen} = 65536;
466
467 # Prepare SQL statement for getting the Place significance
468 my $place_significance_sql_statement = "SELECT SigType FROM tblSigTypes,SigPlace WHERE tblSigTypes.SigTypes_ID=SigPlace.SigType_ID+1 AND SigPlace.Entry_ID=?";
469 my $place_significance_sql_handle = $dbh->prepare($place_significance_sql_statement);
470 $place_significance_sql_handle->{LongReadLen} = 65536;
471
472 # Prepare SQL statement for getting the Place references
473 my $place_references_sql_statement = "SELECT Bibliography FROM tblReferences WHERE Entry_ID=?";
474 my $place_references_sql_handle = $dbh->prepare($place_references_sql_statement);
475 $place_references_sql_handle->{LongReadLen} = 65536;
476
477 # Prepare SQL statement for getting the Place narrative
478 my $place_narrative_sql_statement = "SELECT Narrative FROM tblSignificance_Narrative WHERE Entry_ID=?";
479 my $place_narrative_sql_handle = $dbh->prepare($place_narrative_sql_statement);
480 $place_narrative_sql_handle->{LongReadLen} = 65536;
481
482 # Prepare SQL statement for getting the Place state
483 my $place_state_sql_statement = "SELECT State FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID AND Entry_ID=?";
484 my $place_state_sql_handle = $dbh->prepare($place_state_sql_statement);
485 $place_state_sql_handle->{LongReadLen} = 65536;
486
487 # Create a document object for each place
488 my %place_type_to_ids_mapping;
489 my %place_style_to_ids_mapping;
490 my %place_date_to_ids_mapping;
491 my %place_function_to_ids_mapping;
492 my %place_id_to_name_mapping;
493 my %place_id_to_institution_name_mapping;
494 while (my $row_hashref = $place_sql_handle->fetchrow_hashref) {
495 my $place_id = $row_hashref->{"Entry_ID"};
496 # print STDERR " Place $place_id\n";
497 my $place_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
498 $place_doc_obj->set_OID("p$place_id");
499 &new_metadata_entry($place_doc_obj, "DocumentType", "Place");
500
501 # Convert the place type ID into a name
502 $row_hashref->{"PlaceType"} = $place_type_id_to_name_mapping->{$row_hashref->{"PlaceType"}};
503
504 # Add each field from the table as metadata
505 foreach my $key (keys(%$row_hashref)) {
506 my $value = $row_hashref->{$key};
507 if (defined($value)) {
508 &new_metadata_entry($place_doc_obj, $key, $value);
509 }
510 }
511
512 # Get place name
513 my $place_name = $row_hashref->{"Current_name"};
514 if (!defined($place_name)) {
515 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place name'>\n" if ($self->{'gli'});
516 print STDERR "Error: Place $place_id -- Missing place name.\n";
517 print $fail_log_handle "Error: Place $place_id -- Missing place name.\n";
518 $self->{'num_not_processed'}++;
519 next;
520 }
521
522 # Get place type
523 my $place_type = $row_hashref->{"PlaceType"};
524 if (!defined($place_type)) {
525 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place type'>\n" if ($self->{'gli'});
526 print STDERR "Error: Place $place_id -- Missing place type.\n";
527 print $fail_log_handle "Error: Place $place_id -- Missing place type.\n";
528 $self->{'num_not_processed'}++;
529 next;
530 }
531
532 # Get place date of construction, except for landscape sites which have no date
533 $place_construction_date_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
534 my $place_construction_date_value = $place_construction_date_sql_handle->fetchrow();
535 if (!defined($place_construction_date_value) && $place_type eq "Landscape site") {
536 # Landscape sites may not have a construction date
537 $place_construction_date_value = "";
538 }
539 if (!defined($place_construction_date_value)) {
540 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing construction date'>\n" if ($self->{'gli'});
541 print STDERR "Error: Place $place_id -- Missing construction date.\n";
542 print $fail_log_handle "Error: Place $place_id -- Missing construction date.\n";
543 $self->{'num_not_processed'}++;
544 next;
545 }
546 &new_metadata_entry($place_doc_obj, "Construction_date", $place_construction_date_value);
547
548 # Create place styles mapping
549 $place_styles_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
550 while (my $place_styles_match_hashref = $place_styles_sql_handle->fetchrow_hashref()) {
551 my $place_style = $place_styles_match_hashref->{"Architectural_Classification"};
552 push(@{$place_style_to_ids_mapping{$place_style}}, $place_doc_obj->get_OID());
553 &new_metadata_entry($place_doc_obj, "Style", $place_style);
554 }
555
556 # Get place institution
557 $place_institution_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
558 my $place_institution = $place_institution_sql_handle->fetchrow();
559 &new_metadata_entry($place_doc_obj, "Institution_name", $place_institution);
560 $place_id_to_institution_name_mapping{$place_doc_obj->get_OID()} = ", " . $place_institution;
561
562 # Get place state and area (for searching)
563 $place_state_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
564 my $place_state_abbr = $place_state_sql_handle->fetchrow();
565 &new_metadata_entry($place_doc_obj, "State", $place_state_abbr . " " . $state_abbr_to_name_mapping->{$place_state_abbr} . " " . $state_abbr_to_area_mapping->{$place_state_abbr});
566
567 # Create place dates mapping
568 my $place_time_period = $place_construction_date_value;
569 if ($place_construction_date_value =~ /^(\d\d\d\d).*$/) {
570 $place_construction_date_value =~ s/^(\d\d\d\d).*$/$1/;
571 if ($place_construction_date_value < 1800) { $place_time_period = "pre-1800"; }
572 elsif ($place_construction_date_value < 1850) { $place_time_period = "1800-1850"; }
573 elsif ($place_construction_date_value < 1900) { $place_time_period = "1850-1900"; }
574 elsif ($place_construction_date_value < 1945) { $place_time_period = "1900-1945"; }
575 elsif ($place_construction_date_value < 1995) { $place_time_period = "1945-1995"; }
576 else { $place_time_period = "post-1995"; }
577 push(@{$place_date_to_ids_mapping{$place_time_period}}, $place_doc_obj->get_OID());
578 }
579 &new_metadata_entry($place_doc_obj, "Time_period", $place_time_period);
580
581 # Get place materials (individual buildings only)
582 if ($row_hashref->{"PlaceType"} eq "Individual building") {
583 $place_materials_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
584 my $place_materials_match_hashref = $place_materials_sql_handle->fetchrow_hashref();
585 &new_metadata_entry($place_doc_obj, "MaterialFoundation", $place_materials_match_hashref->{"foundation"} || "");
586 &new_metadata_entry($place_doc_obj, "MaterialRoof", $place_materials_match_hashref->{"roof"} || "");
587 &new_metadata_entry($place_doc_obj, "MaterialWalls", $place_materials_match_hashref->{"walls"} || "");
588 }
589
590 # Get place functions
591 my $place_functions = "";
592 my $place_functions_table_html = "";
593 $place_functions_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
594 while (my $place_functions_match_hashref = $place_functions_sql_handle->fetchrow_hashref()) {
595 my $place_function = $place_functions_match_hashref->{"Function"};
596 if (!defined($place_function)) {
597 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function'>\n" if ($self->{'gli'});
598 print STDERR "Error: Place $place_id -- Missing function.\n";
599 print $fail_log_handle "Error: Place $place_id -- Missing function.\n";
600 next;
601 }
602 # Check for multiline values (these are errors)
603 if ($place_function =~ /\n/) {
604 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Multiline function'>\n" if ($self->{'gli'});
605 print STDERR "Error: Place $place_id -- Multiline function.\n";
606 print $fail_log_handle "Error: Place $place_id -- Multiline function.\n";
607 next;
608 }
609 my $place_year = $place_functions_match_hashref->{"Year"};
610 if (!defined($place_year)) {
611 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function year'>\n" if ($self->{'gli'});
612 print STDERR "Error: Place $place_id -- Missing function year.\n";
613 print $fail_log_handle "Error: Place $place_id -- Missing function year.\n";
614 next;
615 }
616 my $place_year_prefix = $place_functions_match_hashref->{"Prefix"} || "";
617 $place_functions .= "$place_function ";
618 $place_functions_table_html .= "<tr><td valign=\"top\"><nobr>$place_year_prefix $place_year</nobr>&nbsp;</td><td valign=\"top\">$place_function</td></tr>";
619
620 # Create place functions mapping
621 $place_function = lc($place_function);
622 $place_function =~ s/\.$//;
623 $place_function =~ s/\(.*\)//g;
624 $place_function =~ s/^\s*//;
625 $place_function =~ s/\s*$//;
626 $place_function =~ s/classroom$/classrooms/;
627 $place_function =~ s/department buildings$/department building/;
628 $place_function =~ s/faculty office$/faculty offices/;
629 $place_function =~ s/garden$/gardens/;
630 $place_function =~ s/residence halls$/residence hall/;
631 next if ($place_function eq "");
632 push(@{$place_function_to_ids_mapping{$place_function}}, $place_doc_obj->get_OID());
633 }
634 &new_metadata_entry($place_doc_obj, "Functions", $place_functions);
635 &new_metadata_entry($place_doc_obj, "PlaceFunctionsTableHTML", "<table cellpadding=\"0\" cellspacing=\"0\">" . $place_functions_table_html . "</table>");
636
637 # Get place significance
638 $place_significance_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
639 while (my $place_significance_match_hashref = $place_significance_sql_handle->fetchrow_hashref()) {
640 my $place_significance = $place_significance_match_hashref->{"SigType"};
641 &new_metadata_entry($place_doc_obj, "Significance", lc($place_significance));
642 }
643
644 # Get place references
645 $place_references_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
646 my $place_references = $place_references_sql_handle->fetchrow();
647 if (defined($place_references)) {
648 &new_metadata_entry($place_doc_obj, "References", &rtf_to_html($place_references));
649 }
650
651 # Get place narrative
652 $place_narrative_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
653 my $place_narrative = $place_narrative_sql_handle->fetchrow();
654 if (defined($place_narrative)) {
655 $place_narrative = &rtf_to_html($place_narrative);
656 $place_narrative =~ s/<br \/>(\s|\n)*$//; # Remove any trailing <br /> tags
657 &new_metadata_entry($place_doc_obj, "Narrative", $place_narrative);
658 }
659
660 # Get place images
661 my $place_images_html = "";
662 $place_images_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
663 while (my $place_images_match_hashref = $place_images_sql_handle->fetchrow_hashref) {
664 my $place_image_location = $place_images_match_hashref->{"Location"};
665 my $place_image_name = $place_images_match_hashref->{"FileName"};
666
667 # Deal with PDF files separately: don't convert, just associate
668 if ($place_image_location =~ /\.pdf$/i) {
669 # Convert the server location of the PDF file into the local location of the file
670 my $place_pdf_file_path = $place_image_location;
671 $place_pdf_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
672
673 if (-f $place_pdf_file_path) {
674 my ($place_pdf_file_name) = ($place_pdf_file_path =~ /^.+\\(.+)$/);
675 $place_doc_obj->associate_file($place_pdf_file_path, $place_pdf_file_name, undef, $place_doc_obj->get_top_section());
676
677 $place_pdf_file_name =~ s/ /%20/g;
678 my $place_pdf_file_href = "_httpcollection_/index/assoc/[assocfilepath]/$place_pdf_file_name";
679 $place_images_html .= "<tr><td align=\"right\" valign=\"top\"><a href=\"$place_pdf_file_href\">_iconpdf_</a></td><td valign=\"top\"><a href=\"$place_pdf_file_href\"><span class=\"cictext\">$place_image_name (PDF)</span></a></td></tr>\n";
680 }
681 else {
682 print STDERR "<ProcessingError n='$place_pdf_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
683 print STDERR "Error: File $place_pdf_file_path does not exist.\n";
684 print $fail_log_handle "Error: File $place_pdf_file_path does not exist.\n";
685 }
686 }
687 else {
688 my $place_image_small_file_href = $self->generate_place_image_variant($place_doc_obj, $place_image_location, "small");
689 my $place_image_large_file_href = $self->generate_place_image_variant($place_doc_obj, $place_image_location, "large");
690
691 if (defined($place_image_name)) {
692 # Create a new section for each place image
693 my $place_image_section = $place_doc_obj->insert_section($place_doc_obj->get_end_child($place_doc_obj->get_top_section()));
694 $place_doc_obj->add_utf8_text($place_image_section, "_"); # This is necessary
695 $place_doc_obj->add_utf8_metadata($place_image_section, "DocumentType", "Image");
696 $place_doc_obj->add_utf8_metadata($place_image_section, "Title", $place_image_name);
697 $place_doc_obj->add_utf8_metadata($place_image_section, "ImagePath", $place_image_large_file_href);
698
699 $place_images_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$place_id.$place_image_section\"><img src=\"$place_image_small_file_href\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$place_id.$place_image_section\"><span class=\"cictext\">$place_image_name</span></a></td></tr>\n";
700 }
701 else {
702 $place_images_html .= "<tr><td valign=\"top\"><img src=\"_httpcollection_/images/no_image-small.jpg\"/></td><td valign=\"top\"><span class=\"cictext\">&nbsp;</span></td></tr>\n";
703 }
704 }
705 }
706
707 &new_metadata_entry($place_doc_obj, "PlaceImagesHTML", "<table>" . $place_images_html . "</table>");
708
709 $place_doc_obj->add_utf8_text($place_doc_obj->get_top_section(), "Some dummy text.");
710 $self->{'processor'}->process($place_doc_obj);
711 $self->{'num_processed'}++;
712
713 # Build mappings for creating the static macrofiles
714 $place_id_to_name_mapping{$place_doc_obj->get_OID()} = $place_name;
715 push(@{$place_type_to_ids_mapping{$place_type}}, $place_doc_obj->get_OID());
716 }
717
718 &write_bilevel_static_browser_macrofile("types", \%place_type_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
719 &write_bilevel_static_browser_macrofile("styles", \%place_style_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
720 &write_bilevel_static_browser_macrofile("dates", \%place_date_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
721 &write_bilevel_static_browser_macrofile("functions", \%place_function_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
722}
723
724
725sub process_designers
726{
727 my $self = shift(@_);
728 my $dbh = shift(@_);
729 my $fail_log_handle = $self->{'failhandle'};
730
731 # Prepare SQL statement for getting all the Architects from the Place table
732 my $designer_sql_statement = "SELECT Architect_Name,Entry_ID FROM tblConstruction_and_dates";
733 my $designer_sql_handle = $dbh->prepare($designer_sql_statement);
734 $designer_sql_handle->{LongReadLen} = 65536;
735 $designer_sql_handle->execute() or die "Could not execute SQL statement.";
736
737 # Prepare SQL statement for getting the Place name
738 my $place_name_sql_statement = "SELECT Current_name FROM tblPlace WHERE Entry_ID=?";
739 my $place_name_sql_handle = $dbh->prepare($place_name_sql_statement);
740
741 # Prepare SQL statement for getting the Place institution
742 my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
743 my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
744
745 # Prepare SQL statement for getting the Place "date of construction"
746 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
747 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
748
749 # Prepare SQL statement for getting the Place non-PDF images
750 my $place_images_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND Location NOT LIKE '%.pdf' AND Entry_ID=?";
751 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
752 $place_images_sql_handle->{LongReadLen} = 65536;
753
754 # Get a list of all the designers, and the places they worked on
755 my %designer_name_to_place_ids_mapping;
756 my %designer_name_to_id_mapping;
757 my %designer_id_to_name_mapping;
758 my $designer_count = 0;
759 while (my $designer_hashref = $designer_sql_handle->fetchrow_hashref) {
760 my $designer_names_string = $designer_hashref->{"Architect_Name"};
761 next if !defined($designer_names_string);
762 foreach my $designer_name (split(/;/, $designer_names_string)) {
763 $designer_name =~ s/\(.*?\)//g;
764 $designer_name =~ s/^\s*//;
765 $designer_name =~ s/\s*$//;
766
767 if (!defined($designer_name_to_id_mapping{$designer_name})) {
768 $designer_count++;
769 $designer_name_to_id_mapping{$designer_name} = "d" . $designer_count;
770 }
771
772 $designer_id_to_name_mapping{$designer_name_to_id_mapping{$designer_name}} = $designer_name;
773 push(@{$designer_name_to_place_ids_mapping{$designer_name}}, $designer_hashref->{"Entry_ID"});
774 }
775 }
776
777 # Create a document object for each designer
778 foreach my $designer_name (keys %designer_name_to_place_ids_mapping) {
779 my $designer_id = $designer_name_to_id_mapping{$designer_name};
780 # print STDERR " Designer $designer_id\n";
781 my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
782 $designer_doc_obj->set_OID($designer_id);
783 &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
784
785 &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
786
787 my $designer_places_list_html = "";
788 foreach my $designer_place_id (@{$designer_name_to_place_ids_mapping{$designer_name}}) {
789 # Get place name
790 $place_name_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
791 my $designer_place_name = $place_name_sql_handle->fetchrow();
792
793 # Get place institution name
794 $place_institution_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
795 my $designer_place_institution_name = $place_institution_sql_handle->fetchrow();
796
797 # Get place date of construction
798 $place_construction_date_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
799 my $designer_place_construction_date_value = $place_construction_date_sql_handle->fetchrow() || "";
800
801 # Get the first non-PDF image for this place
802 my $designer_place_image_small_file_href;
803 $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
804 my $designer_place_image_location = $place_images_sql_handle->fetchrow();
805 if (defined($designer_place_image_location)) {
806 $designer_place_image_small_file_href = $self->generate_place_image_variant($designer_doc_obj, $designer_place_image_location, "small");
807 }
808 else {
809 # There is no non-PDF image for this place
810 $designer_place_image_small_file_href = "_httpcollection_/images/no_image-small.jpg";
811 }
812
813 $designer_places_list_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><img src=\"$designer_place_image_small_file_href\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\">$designer_place_name</a>, $designer_place_institution_name<br /><b>Date of construction:</b> $designer_place_construction_date_value</td></tr>\n";
814 }
815
816 &new_metadata_entry($designer_doc_obj, "DesignerPlacesListHTML", "<table>" . $designer_places_list_html . "</table>");
817
818 $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
819 $self->{'processor'}->process($designer_doc_obj);
820 $self->{'num_processed'}++;
821 }
822
823 # Write the designers.dm macrofile
824 &write_static_browser_macrofile("designers", \%designer_id_to_name_mapping);
825}
826
827
828sub new_metadata_entry
829{
830 my ($doc_obj, $metadata_name, $metadata_value) = (@_);
831
832 # Don't bother with empty metadata
833 return if ($metadata_value eq "");
834
835 # Spaces aren't allowed in metadata names
836 $metadata_name =~ s/ /_/g;
837
838 # Anything from the database is ISO 8859-1 encoded, so convert to UTF-8
839 $metadata_value = &unicode::ascii2utf8(\$metadata_value);
840
841 # Remove '#' characters around links
842 if ($metadata_value =~ /\#(.*?)\#/) {
843 $metadata_value = $1;
844 }
845
846 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
847}
848
849
850sub rtf_to_html
851{
852 my $rtf_string = shift(@_);
853 $rtf_string =~ s/\{(.*?)\}//g;
854 $rtf_string =~ s/\\rquote /'/g; # ' # (for Emacs)
855 $rtf_string =~ s/\\pard//g;
856 $rtf_string =~ s/\\par/<br \/>/g;
857 $rtf_string =~ s/\\i0 /<\/i>/g;
858 $rtf_string =~ s/\\i /<i>/g;
859 $rtf_string =~ s/\\~/ /g;
860 $rtf_string =~ s/\\([A-Za-z0-9]+)//g;
861 $rtf_string =~ s/\}//g;
862
863 # Assume non-ASCII is ISO 8859-1, and convert into HTML entities
864 while ($rtf_string =~ /\\'([a-z0-9][a-z0-9])/) {
865 my $dec = hex($1);
866 $rtf_string =~ s/\\'$1/&#$dec\;/;
867 }
868
869 return $rtf_string;
870}
871
872
873sub get_place_image_dimensions
874{
875 my $self = shift(@_);
876 my $place_image_file_path = shift(@_);
877 my $fail_log_handle = $self->{'failhandle'};
878
879 # Make sure the place image file actually exists
880 if (!-f $place_image_file_path) {
881 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
882 print STDERR "Error: Image $place_image_file_path does not exist.\n";
883 print $fail_log_handle "Error: Image $place_image_file_path does not exist.\n";
884 return;
885 }
886 my $place_image_file_date = (stat($place_image_file_path))[9];
887
888 # Check if this place image has already been identified by looking for a ".info" file in the same directory
889 my $place_image_info_file_path = $place_image_file_path . ".info";
890 if (-f $place_image_info_file_path) {
891 # A ".info" file exists, so read the cached place image information from it
892 open(PLACE_IMAGE_INFO_FILE, "<$place_image_info_file_path");
893 my @place_image_info = <PLACE_IMAGE_INFO_FILE>;
894 close(PLACE_IMAGE_INFO_FILE);
895
896 # Read the cached place image file date and check that it matches
897 my $cached_place_image_file_date = $place_image_info[0];
898 $cached_place_image_file_date =~ s/\n$//;
899 if ($cached_place_image_file_date == $place_image_file_date) {
900 # It does match, so use the cached information from the ".info" file instead of re-identifying the file
901 my $place_image_width = $place_image_info[1];
902 $place_image_width =~ s/\n$//;
903 my $place_image_height = $place_image_info[2];
904 $place_image_height =~ s/\n$//;
905 return ($place_image_width, $place_image_height);
906 }
907 }
908
909 # We haven't already identified the place image, so do it now
910 print STDERR "Identifying place image $place_image_file_path...\n";
911 my $identify_command = "identify -format \"%w %h\" \"$place_image_file_path\"";
912 my $identify_result = `$identify_command`;
913 print "Identify result: $identify_result\n" if ($self->{'verbosity'} > 2);
914
915 # Check that the output is what we're expecting
916 if ($identify_result !~ /(\d+) (\d+)/) {
917 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Could not identify'>\n" if ($self->{'gli'});
918 print STDERR "Error: Place image $place_image_file_path could not be identified.\n";
919 print $fail_log_handle "Error: Place image $place_image_file_path could not be identified.\n";
920 return;
921 }
922
923 # Parse the place image width and height from the output
924 my $place_image_width = $1;
925 my $place_image_height = $2;
926
927 # Write the place image info file so we don't have to identify this exact image again in the future
928 open(PLACE_IMAGE_INFO_FILE, ">$place_image_info_file_path");
929 print PLACE_IMAGE_INFO_FILE "$place_image_file_date\n";
930 print PLACE_IMAGE_INFO_FILE "$place_image_width\n";
931 print PLACE_IMAGE_INFO_FILE "$place_image_height\n";
932 close(PLACE_IMAGE_INFO_FILE);
933 return ($place_image_width, $place_image_height);
934}
935
936
937sub generate_place_image_variant
938{
939 my $self = shift(@_);
940 my ($doc_obj, $place_image_location, $place_image_variant_size) = (@_);
941 my $fail_log_handle = $self->{'failhandle'};
942
943 # Convert the server location of the file into the local location of the file
944 my $place_image_file_path = $place_image_location;
945 $place_image_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
946
947 # Get the width and height of the place image
948 my ($place_image_width, $place_image_height) = $self->get_place_image_dimensions($place_image_file_path);
949 if (!defined($place_image_width) || !defined($place_image_height)) {
950 # An error has occurred (error message generated by get_place_image_dimensions())
951 return;
952 }
953 my $place_image_file_date = (stat($place_image_file_path))[9];
954
955 # Generate the path of the place image variant (in the cache directory)
956 my $place_image_variant_file_suffix = "-$place_image_variant_size." . $self->{$place_image_variant_size . '_image_type'};
957 my $place_image_variant_file_path = $place_image_location;
958 $place_image_variant_file_path =~ s/^[A-Z]:/$self->{'cache_directory'}/;
959 $place_image_variant_file_path =~ s/^(.+)(\..*)/$1$place_image_variant_file_suffix/;
960 my ($place_image_variant_file_name) = ($place_image_variant_file_path =~ /^.+\\(.+)$/);
961
962 # Only scale down the place image if it is bigger than the desired width
963 my $place_image_variant_desired_width = $self->{$place_image_variant_size . '_image_width'};
964 if ($place_image_width > $place_image_variant_desired_width) {
965 # Only generate the place image variant if it doesn't already exist, or if the place image is newer
966 if (!-f $place_image_variant_file_path || $place_image_file_date > (stat($place_image_variant_file_path))[9]) {
967 print STDERR "Generating place image variant $place_image_variant_file_path...\n";
968 my ($place_image_variant_directory) = ($place_image_variant_file_path =~ /^(.+)\\.+$/);
969 &util::mk_all_dir($place_image_variant_directory);
970 my $place_image_variant_options = "-scale $place_image_variant_desired_width " . $self->{$place_image_variant_size . '_image_options'};
971 my $convert_command = "convert $place_image_variant_options \"$place_image_file_path\" \"$place_image_variant_file_path\"";
972 my $convert_result = `$convert_command`;
973 }
974 }
975 else {
976 # The desired width is bigger than the place image, so we just use the original
977 $place_image_variant_file_path = $place_image_file_path;
978 }
979
980 my ($place_image_variant_width, $place_image_variant_height) = $self->get_place_image_dimensions($place_image_variant_file_path);
981 if (!defined($place_image_variant_width) || !defined($place_image_variant_height)) {
982 # An error has occurred (error message generated by get_place_image_dimensions())
983 return;
984 }
985
986 # Associate the place image variant file
987 $doc_obj->associate_file($place_image_variant_file_path, $place_image_variant_file_name, undef, $doc_obj->get_top_section());
988
989 # Add various bits of metadata for the place image variant
990 my $place_image_variant_href = "_httpcollection_/index/assoc/{Or}{[parent(Top):assocfilepath],[assocfilepath]}/" . $place_image_variant_file_name;
991 $place_image_variant_href =~ s/ /%20/g;
992 return $place_image_variant_href;
993}
994
995
996sub write_static_browser_macrofile
997{
998 my $static_browser_package_name = shift(@_);
999 my $id_to_name_mapping = shift(@_);
1000
1001 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
1002 print STDERR "Writing $static_browser_macrofile_path...\n";
1003 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1004 &write_static_browser_macros($static_browser_package_name, $id_to_name_mapping);
1005 close(BROWSER_MACROFILE);
1006}
1007
1008
1009sub write_static_browser_macros
1010{
1011 my $static_browser_package_name = shift(@_);
1012 my $id_to_name_mapping = shift(@_);
1013 my $id_to_extra_mapping = shift(@_);
1014
1015 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
1016 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
1017
1018 my %letter_to_ids_mapping;
1019 foreach my $id (keys %$id_to_name_mapping) {
1020 my $name = $id_to_name_mapping->{$id};
1021 my ($letter) = ($name =~ /([A-Za-z0-9])/);
1022 push(@{$letter_to_ids_mapping{$letter}}, $id);
1023 }
1024
1025 print BROWSER_MACROFILE "<center><b>";
1026 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
1027 if (defined($letter_to_ids_mapping{$letter})) {
1028 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
1029 }
1030 else {
1031 print BROWSER_MACROFILE "$letter&nbsp;";
1032 }
1033 }
1034 print BROWSER_MACROFILE "</b></center>\n";
1035
1036 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1037 foreach my $letter (sort(keys %letter_to_ids_mapping)) {
1038 my @letter_ids = @{$letter_to_ids_mapping{$letter}};
1039 &write_static_browser_macros_chunk($letter, \@letter_ids, $id_to_name_mapping, $id_to_extra_mapping);
1040 }
1041 print BROWSER_MACROFILE "</table>\n";
1042
1043 print BROWSER_MACROFILE "}\n";
1044}
1045
1046
1047sub write_static_browser_macros_chunk
1048{
1049 my $chunk_title = shift(@_);
1050 my $chunk_ids_ref = shift(@_);
1051 my $id_to_name_mapping = shift(@_);
1052 my $id_to_extra_mapping = shift(@_);
1053
1054 print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$chunk_title\"/><span style=\"color: black;\"><b>$chunk_title</b></span></td><td width=\"50%\"></td></tr>\n";
1055
1056 my %full_name_to_id_mapping;
1057 foreach my $id (@{$chunk_ids_ref}) {
1058 my $full_name = $id_to_name_mapping->{$id};
1059 if (defined($id_to_extra_mapping)) {
1060 $full_name .= " " . $id_to_extra_mapping->{$id};
1061 }
1062 $full_name_to_id_mapping{$full_name} = $id;
1063 }
1064
1065 my @full_names = sort(keys(%full_name_to_id_mapping));
1066 my $half_point = ((scalar(@full_names) % 2 == 0) ? scalar(@full_names) / 2 : (scalar(@full_names) + 1) / 2);
1067 for (my $i = 0; $i < $half_point; $i++) {
1068 print BROWSER_MACROFILE "<tr>";
1069
1070 my $id = $full_name_to_id_mapping{$full_names[$i]};
1071 my $name = $id_to_name_mapping->{$id};
1072 my $extra = $id_to_extra_mapping->{$id} || "";
1073 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra</td>";
1074
1075 print BROWSER_MACROFILE "<td valign=\"top\">";
1076 if (defined($full_names[$i+$half_point])) {
1077 $id = $full_name_to_id_mapping{$full_names[$i+$half_point]};
1078 $name = $id_to_name_mapping->{$id};
1079 $extra = $id_to_extra_mapping->{$id} || "";
1080 print BROWSER_MACROFILE "<a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra";
1081 }
1082 print BROWSER_MACROFILE "</td>";
1083
1084 print BROWSER_MACROFILE "</tr>\n";
1085 }
1086}
1087
1088
1089sub write_bilevel_static_browser_macrofile
1090{
1091 my $static_browser_package_root = shift(@_);
1092 my $category_to_ids_mapping = shift(@_);
1093 my $id_to_name_mapping = shift(@_);
1094 my $id_to_extra_mapping = shift(@_);
1095
1096 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_root.dm";
1097 print STDERR "Writing $static_browser_macrofile_path...\n";
1098 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1099
1100 foreach my $category (keys(%{$category_to_ids_mapping})) {
1101 my $static_browser_package_name = $static_browser_package_root . $category;
1102 $static_browser_package_name =~ s/\W//g;
1103
1104 my %id_to_name_mapping_for_category = ();
1105 foreach my $id (@{$category_to_ids_mapping->{$category}}) {
1106 $id_to_name_mapping_for_category{$id} = $id_to_name_mapping->{$id};
1107 }
1108 &write_static_browser_macros($static_browser_package_name, \%id_to_name_mapping_for_category, $id_to_extra_mapping);
1109 }
1110
1111 close(BROWSER_MACROFILE);
1112}
1113
1114
1115sub write_state_browser_macrofile
1116{
1117 my $static_browser_package_name = shift(@_);
1118 my $state_to_ids_mapping = shift(@_);
1119 my $id_to_name_mapping = shift(@_);
1120
1121 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
1122 print STDERR "Writing $static_browser_macrofile_path...\n";
1123 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1124 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
1125 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
1126
1127 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1128 foreach my $state (sort(keys(%{$state_to_ids_mapping}))) {
1129 my @state_ids = @{$state_to_ids_mapping->{$state}};
1130 &write_static_browser_macros_chunk($state, \@state_ids, $id_to_name_mapping, undef);
1131 }
1132 print BROWSER_MACROFILE "</table>\n";
1133
1134 print BROWSER_MACROFILE "}\n";
1135 close(BROWSER_MACROFILE);
1136}
1137
1138
11391;
Note: See TracBrowser for help on using the repository browser.