-
Notifications
You must be signed in to change notification settings - Fork 0
/
modesCatalogueViewer.php
executable file
·1902 lines (1529 loc) · 58.2 KB
/
modesCatalogueViewer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
# Class to create a MODES catalogue viewer
class modesCatalogueViewer extends frontControllerApplication
{
# Function to assign defaults additional to the general application defaults
public function defaults ()
{
# Specify available arguments as defaults or as NULL (to represent a required argument)
$defaults = array (
'applicationName' => 'Online catalogue',
'h1' => '',
'div' => 'modescatalogue',
'administrators' => true,
# Type, i.e. museum / picturelibrary / archives
'type' => false,
# Tabs - only enabled for admins below
'disableTabs' => true,
'tabUlClass' => 'tabsflat',
'organisationName' => NULL,
'frontPageTextIntroduction' => NULL,
'frontPageTextFooter' => NULL,
# Images
'mainImageSize' => 450,
'listingThumbnailSize' => 100,
'listingThumbnailType' => 'gif',
'articleImageClass' => false,
'imageFilenameLiberalMatching' => true, // Allow case-insensitive matches of image names
'administratorEmail' => NULL,
'multiplesDelimiter' => '|',
'queryTerm' => 'q',
'aatLink' => 'https://www.getty.edu/research/tools/vocabularies/aat/',
'removeEmptyGalleries' => true, // Whether to remove authorised galleries that have no images in them
# Pagination
#!# This should be different for search vs listings - 250 is too many for a search
'paginationRecordsPerPage' => 150,
# Image data source (non-slash terminated)
'imageStoreRoot' => NULL,
# API
'apiUrl' => NULL, // Non-slash terminated
'apiUi' => NULL,
'userAgent' => ucfirst (__CLASS__) . ' API request',
# Templating
'useTemplating' => true,
);
# Return the defaults
return $defaults;
}
# Function to assign supported actions
public function actions ()
{
# Define available tasks
$actions = array (
'home' => array (
'description' => false,
'url' => '',
'tab' => 'Home',
),
'globalsearch' => array (
'description' => false,
'url' => '',
),
'index' => array (
'description' => false,
'url' => 'catalogue/%s/',
),
'about' => array (
'description' => false,
'url' => '',
),
'browse' => array (
'description' => false,
'url' => '',
),
'gallery' => array (
'description' => false,
'url' => '',
),
'categories' => array (
'description' => false,
'url' => '',
),
'category' => array (
'description' => false,
'url' => '',
),
'hierarchy' => array (
'description' => false,
'url' => '',
),
'materials' => array (
'description' => false,
'url' => '',
),
'material' => array (
'description' => false,
'url' => '',
),
'artists' => array (
'description' => false,
'url' => '',
),
'artist' => array (
'description' => false,
'url' => '',
),
'contacts' => array (
'description' => false,
'url' => '',
),
'search' => array (
'description' => false,
'url' => '',
),
'article' => array (
'description' => false,
'url' => '',
),
'apidocumentation' => array (
'description' => 'API (HTTP)',
'url' => 'api/',
'tab' => 'API/import',
'icon' => 'feed',
'administrator' => true,
),
'feedback' => array (
'description' => 'Feedback/contact form',
'url' => 'feedback.html',
'tab' => 'Feedback',
),
'templates' => array (
'description' => 'Templates',
'url' => 'templates/',
'tab' => 'Templates',
'icon' => 'tag',
'administrator' => true,
),
);
# Return the actions
return $actions;
}
# Additional standard processing (pre-actions)
public function mainPreActions ()
{
# Enable tabbing for admins
if ($this->userIsAdministrator) {
$this->settings['disableTabs'] = false;
}
# Register template modifier functions
$this->templateFunctions = array ('articleIdUrl', 'imgTag', 'makeCategoryLink', 'makeArtistLink', 'makeMaterialLink', );
}
# Additional standard processing
public function main ()
{
# Title
$this->titleBrowser = array ();
$this->titleBreadcrumbTrail = array ();
}
# Import page
public function import ()
{
# Show the HTML
echo $html = "\n<p>Data can be updated via the import page of the central <a href=\"{$this->settings['apiUi']}/import/\">unified collections data API</a>.</p>";
}
# API documentation page
public function apidocumentation ($ignored = '')
{
# Show the HTML
echo $html = "\n<p>Data for this site comes from the central <a href=\"{$this->settings['apiUi']}/api/\">unified collections data API</a>, where you can <a href=\"{$this->settings['apiUi']}/import/\"><strong>import catalogue data</strong></a>.</p>";
}
# Function to convert a type key to a name
private function typeToName ($type)
{
# Convert and return the type
$groupings = array (
'museum' => 'Museum',
'picturelibrary' => 'Picture Library',
'archives' => 'Archives',
);
return $groupings[$type];
}
# Function to create the front page
public function home ()
{
# Get the gallery data
$fields = array ('id', 'title', 'abbreviation', 'count', 'baseUrl', 'introductoryTextBrief', 'coverImage');
$collections = $this->getCollections ($fields);
# Heading grouping name
$this->template['grouping'] = $this->typeToName ($this->settings['type']);
# Add the search box
$this->template['searchBox'] = $this->searchBox ($this->baseUrl, true, $global = true);
# Add introduction text
$this->template['frontPageTextIntroduction'] = $this->settings['frontPageTextIntroduction'];
# Add gallery data to the template
$this->template['collections'] = $collections;
# Add the type to the template, e.g. museum/picturelibrary
$this->template['type'] = $this->settings['type'];
# Footer
$this->template['footer'] = $this->settings['frontPageTextFooter'];
# Contact link
$this->template['feedbackHref'] = $this->baseUrl . '/feedback.html';
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Function to create the page header
#!# Needs to be templatised
private function pageHeader ($gallery)
{
# Set the title
if (!$this->titleBrowser) {
$this->titleBrowser = array (
htmlspecialchars ($gallery['title']),
);
}
if (!$this->titleBreadcrumbTrail) {
$this->titleBreadcrumbTrail = array (
($this->action != 'index' ? "<a href=\"{$gallery['baseUrl']}/\">" : '') . htmlspecialchars ($gallery['title']) . ($this->action != 'index' ? '</a>' : ''),
);
}
# Start the HTML
$html = '';
# Add section heading
$html .= "\n<h1><a href=\"{$this->baseUrl}/\">" . $this->typeToName ($this->settings['type']) . " catalogue</a>: <span><a href=\"{$gallery['baseUrl']}/\">" . htmlspecialchars ($gallery['title']) . '</a></span></h1>';
# Add the search box
$html .= $this->searchBox ($gallery['baseUrl'], true);
# Create a tab registry
$tabs = array (
'index' => array (
'subtab' => 'Home',
'url' => '/',
),
'about' => array (
'enableIf' => $gallery['aboutPageHtml'],
'subtab' => $gallery['aboutPageTabText'],
'url' => '/about.html',
),
'browse' => array (
'subtab' => 'Browse all items',
'icon' => 'layout_content',
'url' => '/browse/',
),
'gallery' => array (
'subtab' => 'Gallery',
'icon' => 'map',
'url' => '/gallery/',
),
'artists' => array (
'enableIf' => ($this->settings['type'] == 'museum' && !$gallery['disableArtists']),
'subtab' => 'Artists',
'icon' => 'paintbrush',
'url' => '/artists/',
),
'categories' => array (
'enableIf' => ($this->settings['type'] == 'museum' && !$gallery['disableCategories']),
'subtab' => 'Categories',
'icon' => 'page_copy',
'url' => '/categories/',
),
'materials' => array (
'enableIf' => ($this->settings['type'] == 'museum' && !$gallery['disableMaterials']),
'subtab' => 'Materials',
'icon' => 'images',
'url' => '/materials/',
),
'contacts' => array (
'enableIf' => (isSet ($gallery['contactsPageHtml']) && strlen ($gallery['contactsPageHtml'])),
'subtab' => 'Contacts',
'icon' => 'email',
'url' => '/contacts.html',
),
);
# Compile the tabs
$list = array ();
$list['main'] = "<a href=\"{$this->baseUrl}/\"><span class=\"faded\">« Catalogues list</span></a>";
foreach ($tabs as $key => $tab) {
if (isSet ($tab['enableIf']) && !$tab['enableIf']) {continue;} // Skip if not enabled
$list[$key] = "<a href=\"{$gallery['baseUrl']}{$tab['url']}\">";
if (isSet ($tab['icon'])) {
$list[$key] .= "<img src=\"/images/icons/{$tab['icon']}.png\" alt=\"\" class=\"icon\"> ";
}
$list[$key] .= htmlspecialchars ($tab['subtab']);
$list[$key] .= '</a>';
}
# Determine which tab to highlight
$current = ($this->action == 'article' ? 'browse' : $this->action);
# Compile the HTML
$html .= application::htmlUl ($list, 0, 'tabsflat', true, false, false, $liClass = true, $current);
# Return the HTML
return $html;
}
# Function to create an index page for a collection
public function index ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Page header
$this->template['pageHeader'] = $this->pageHeader ($this->gallery);
# Assign the collection data into the template
$this->template['collection'] = $this->gallery;
#!# Move into model
$this->template['introductoryTextHtml'] = $this->applyPlaceholderReplacement ($this->gallery['introductoryText']);
# Show some random records
$constraints = array (
'collection' => $this->gallery['id'],
'requireimages' => '1',
'random' => 5,
);
$data = $this->getArticles ($constraints);
if ($data['articles']) {
$this->template['randomImagesNumber'] = $constraints['random'];
$this->template['articleListing'] = $this->galleryHtmlFromArticleData ($data['articles'], true);
} else {
# If there are no articles, create blank HTML
$this->template['articleListing'] = '';
}
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Function to apply templating changes
private function applyPlaceholderReplacement ($html)
{
# Define templating replacements
$templatingReplacements = array (
'%baseUrl' => $this->baseUrl,
'%catalogueBaseUrl' => $this->gallery['baseUrl'],
);
# Convert the text to HTML if it is not already (e.g. if coming out of the collection-level records)
if (!substr_count ($html, '<p')) { // This is a bit crude but good enough
$html = application::formatTextBlock ($html);
}
# Return the HTML
return strtr ($html, $templatingReplacements);
}
# Function to create a feedback form
#!# Needs to be templatised
public function feedback ($id_ignored = NULL, $error_ignored = NULL, $echoHtml = true)
{
# Introduction
$html = "\n<h1>Online catalogue feedback</h1>";
$html .= "\n<p>We welcome your feedback on the catalogue and its contents.</p>";
# Load and instantiate the form library
$form = new form (array (
'antispam' => true,
));
# Widgets
$form->textarea (array (
'name' => 'message',
'title' => 'Your feedback',
'required' => true,
'cols' => 40,
));
$form->input (array (
'name' => 'name',
'title' => 'Your name',
'required' => true,
'disallow' => 'https?://',
));
$form->email (array (
'name' => 'contacts',
'title' => 'E-mail',
'required' => true,
));
# Process the form
$form->setOutputEmail ($this->settings['feedbackRecipient'], $this->settings['administratorEmail'], 'Online catalogue feedback', NULL, $replyToField = 'contacts');
$form->setOutputScreen ();
$result = $form->process ($html);
# Show the HTML
echo $html;
}
# Function to browse all records
public function browse ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Obtain the data for this gallery
$parameters = array (
'collection' => $this->gallery['id'],
'page' => (isSet ($_GET['page']) && ctype_digit ($_GET['page']) ? $_GET['page'] : NULL),
'imagesize' => '100',
);
$data = $this->getArticles ($parameters);
# End if error
if (isSet ($data['error'])) {
$this->page404 ();
return false;
}
# Page header
$this->template['pageHeader'] = $this->pageHeader ($this->gallery);
# Assign the gallery data into the template
$this->template['collection'] = $this->gallery;
# Base URL
$this->template['baseUrl'] = $this->baseUrl;
# Assign the data into the template
$this->template['data'] = $data;
if (!$data['articles']) {
#!# Inform admin
application::sendHeader ('404');
return false;
}
# Add pagination links
$this->template['paginationHtml'] = pagination::paginationLinks ($data['pagination']['page'], $data['pagination']['totalPages'], $this->gallery['baseUrl'] . "/{$this->action}/");
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Wrapper function to create a gallery
#!# Needs templatising
public function gallery ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Start the HTML
$html = '';
# Page header
$html .= $this->pageHeader ($this->gallery);
$html .= "\n<h2>Gallery of all items</h2>";
$fullTitle = htmlspecialchars ($this->gallery['title']) . ($this->gallery['abbreviation'] ? ' (' . htmlspecialchars ($this->gallery['abbreviation']) . ')' : '');
$html .= "\n<p>Here you can browse the gallery of all the <a href=\"{$this->gallery['baseUrl']}/\"><strong>{$fullTitle}</strong></a> items.</p>";
$html .= "\n<p>You can also <a href=\"{$this->gallery['baseUrl']}/browse/\"><img src=\"/images/icons/layout_content.png\" alt=\"\" class=\"icon\"> show descriptions for each item</a>.</p>";
# Obtain the data for this gallery
$constraints = array (
'collection' => $this->gallery['id'],
'requireimages' => 1,
'page' => (isSet ($_GET['page']) && ctype_digit ($_GET['page']) ? $_GET['page'] : NULL),
);
$data = $this->getArticles ($constraints);
# End if error
if (isSet ($data['error'])) {
$this->page404 ();
return false;
}
# End if no data
#!# Inform admin
if (!$data['articles']) {
application::sendHeader ('404');
$html = "\n<p>No items were found.</p>";
echo $html;
return false;
}
$paginationHtml = pagination::paginationLinks ($data['pagination']['page'], $data['pagination']['totalPages'], $this->gallery['baseUrl'] . "/{$this->action}/");
# Determine the introduction
#!# Count shows number of items, not total with images
$html .= "\n<p>There " . ($data['pagination']['total'] == 1 ? 'is one item' : 'are ' . number_format ($data['pagination']['total']) . ' items')
. ($this->gallery['count'] == 1 ? ' which has an image' : ' which have images')
. ' in this collection' . ($paginationHtml ? ', of which ' . ($data['pagination']['count'] == 1 ? 'one is shown' : "{$data['pagination']['count']} are shown") . ' below. Use the navigation to view more pages' : '')
. '.</p>';
# Create the HTML, surrounded by pagination controls
$html .= $paginationHtml;
$html .= $this->galleryHtmlFromArticleData ($data['articles'], true);
if ($paginationHtml) {$html .= "\n<div id=\"endpagination\">{$paginationHtml}</div>";}
# Show the listing HTML
echo $html;
}
# Show the 'about' text
public function about ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Load the file if it exists
$file = $_SERVER['DOCUMENT_ROOT'] . $this->gallery['baseUrl'] . '/about.html';
if (file_exists ($file)) {
$this->gallery['aboutPageHtml'] = file_get_contents ($file);
}
# Page header
$this->template['pageHeader'] = $this->pageHeader ($this->gallery);
# Perform string replacement
$this->template['html'] = $this->applyPlaceholderReplacement ($this->gallery['aboutPageHtml']);
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Show the 'contacts' text
public function contacts ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Get the HTML
if (!$this->gallery['contactsPageHtml']) {
echo $html = "<p>No contact details for this collection are available at present.</p>";
return;
}
$html = $this->gallery['contactsPageHtml'];
# Add a contact form
if ($this->gallery['contactsPageEmail']) {
$html .= "\n<h3>Contact form</h3>";
# Add the form
$form = new form (array (
'displayRestrictions' => false,
));
$form->textarea (array (
'name' => 'message',
'title' => 'Message',
'required' => true,
'cols' => 40,
));
$form->input (array (
'name' => 'name',
'title' => 'Your name',
'required' => true,
));
$form->email (array (
'name' => 'contacts',
'title' => 'E-mail',
'required' => true,
));
$form->input (array (
'name' => 'howfoundout',
'title' => 'How did you discover this site?',
'required' => false,
));
# Set the processing options
$form->setOutputEmail ($this->gallery['contactsPageEmail'], $this->settings['administratorEmail'], 'Online catalogue [message via the website]', NULL, $replyToField = 'contacts');
$form->setOutputScreen ();
# Process the form
$result = $form->process ($html);
}
# Show the HTML
echo $html;
}
# Function to do global search
public function globalsearch ()
{
# Run the search page, which will echo directly
$this->search ($global = true);
}
public function dataListing ($data, $table)
{
return $this->galleryHtmlFromArticleData ($data);
}
# Function to create a search facility (also acting as the category screen)
#!# Split this into the public function and doSearch
public function search ($global = false)
{
# In gallery-specific mode, load gallery
if (!$global) {
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
}
# Heading and form
$html = "\n<h2>Search the" . ($global ? ' whole ' . $this->typeToName ($this->settings['type']) : '') . ' catalogue</h2>';
$baseUrl = ($global ? $this->baseUrl : $this->gallery['baseUrl']);
$html .= $this->searchBox ($baseUrl, false, $global);
# Create the results if a query is supplied
$searchPhrase = (isSet ($_GET[$this->settings['queryTerm']]) ? $_GET[$this->settings['queryTerm']] : '');
if ($searchPhrase) {
# Obtain the data for this gallery
$constraints = array (
'collection' => ($global ? NULL : $this->gallery['id']),
'search' => $searchPhrase,
'page' => ((isSet ($_GET['page']) && ctype_digit ($_GET['page'])) ? $_GET['page'] : 1),
);
$data = $this->getArticles ($constraints);
#!# Need to handle error properly - e.g. must be at least three characters long
if (isSet ($data['error']) || (!$data['articles'])) {
$html .= "\n<p>Sorry, no results were found for <strong>" . htmlspecialchars ($searchPhrase) . '</strong>. Try another search using the box above.</p>';
echo $html;
return false;
}
# Add lookups for related terms
if ($data['relatedTerms']) {
$html .= $this->formatRelatedTerms ($data['relatedTerms']);
}
# Determine base link
$baseLink = ($global ? $this->baseUrl : $this->gallery['baseUrl']) . '/search/';
# Determine the query string
$queryString = "{$this->settings['queryTerm']}=" . urlencode ($_GET[$this->settings['queryTerm']]);
$paginationHtml = pagination::paginationLinks ($data['pagination']['page'], $data['pagination']['totalPages'], $baseLink, $queryString);
$html .= "\n<p>There " . ($data['pagination']['total'] == 1 ? 'is one item' : 'are ' . number_format ($data['pagination']['total']) . ' items')
. ' matching <strong>' . htmlspecialchars ($searchPhrase) . '</strong>'
. ($paginationHtml ? ', of which ' . ($data['pagination']['count'] == 1 ? 'one is shown' : "{$data['pagination']['count']} are shown") . ' below. Use the navigation to view more pages.' : ':')
. '</p>';
$html .= $paginationHtml;
$html .= $this->galleryHtmlFromArticleData ($data['articles']);
if ($paginationHtml) {$html .= "\n<div id=\"endpagination\">{$paginationHtml}</div>";}
}
# Show the HTML
echo $html;
}
# Function to create the search box
private function searchBox ($baseUrl, $minisearch = false, $global = false)
{
$defaultText = ($global ? 'Search all' : 'Search');
$query = (isSet ($_GET[$this->settings['queryTerm']]) ? trim ($_GET[$this->settings['queryTerm']]) : '');
$html = "\n\n" . '<form method="get" action="' . $baseUrl . '/search/' . '" class="' . ($minisearch ? 'minisearch' : 'search') . '" name="' . ($minisearch ? 'minisearch' : 'search') . '">
' . ($minisearch ? '<img src="/images/icons/magnifier.png" alt="" class="icon"> ' : 'Search word or phrase: ') . '<input name="' . $this->settings['queryTerm'] . '" type="search" size="' . ($minisearch ? ($global ? '20' : '10') : '30') . '" value="' . htmlspecialchars ($query) . '" placeholder="' . $defaultText . '" class="autocomplete" /> <input value="Search!" accesskey="s" type="submit" class="button" />' /* . ($minisearch ? '' : " <span class=\"small\"> [<a href=\"{$this->baseUrl}/search/\">Advanced search</a></span>]") */ . '
</form>' . "\n";
# Return the HTML
return $html;
}
# Function to create a lookup from gallery MODES indicators (e.g. BPA) to gallery id (polarart)
private function galleryModesIndicatorsToId ($galleries)
{
# Loop through each
$galleryModesIndicators = array ();
foreach ($galleries as $galleryId => $gallery) {
$collectionId = $gallery['collection'];
$galleryModesIndicators[$collectionId] = $galleryId;
}
# Return the lookup array
return $galleryModesIndicators;
}
# Function to create the gallery HTML
#!# Global search throws lots of: "PHP Notice: Undefined property: modesCatalogueViewer::$gallery"
private function galleryHtmlFromArticleData ($data, $galleryMode = false, $computedArtistName = false)
{
# End if no data
if (!$data) {
return $html = "\n<p>There are no items.</p>";
}
# Re-sort - there is no NATSORT() in MySQL sadly
$keys = array_keys ($data);
//natsort ($keys);
# If not in a current gallery, i.e. if in global mode, get the galleries, so that links to them can be created
if (!isSet ($this->gallery)) {
$galleries = $this->getCollections ();
}
//application::dumpData ($galleries);
//application::dumpData ($data);
# Loop through each record
$list = array ();
foreach ($keys as $key) {
# Obtain the article
$article = $data[$key];
# In global mode, ensure the image is part of some Collection, or do not list it
#!# Matching should all be done at the data retrieval API end; counts can currently be wrong
if (isSet ($this->gallery)) {
$gallery = $this->gallery;
} else {
$gallery = false;
foreach ($article['collections'] as $gallerySignifier) {
if (isSet ($galleries['collections'][$gallerySignifier])) {
$gallery = $galleries['collections'][$gallerySignifier];
}
}
if (!$gallery) {
continue; // Do not list it
}
}
# Define the link
$link = '<a href="' . $this->articleIdToUrlSlug ($article['id'], $this->settings['type'], $this->baseUrl, true) . '">';
# Create the items
$thumbnail = $link . (
($article['status'] == 'P')
? "<img src=\"{$this->baseUrl}/images/spacer.gif\" alt=\"Contact curator for image\" class=\"right portrait\" />"
: $this->createImageHtml ($gallery['imagesSubfolder'], $this->getPhotographNumber ($article, $firstOnly = true), $this->settings['listingThumbnailSize'], false, htmlspecialchars ($article['title']), true)
) . '</a>';
# Create either a table or a gallery
if ($galleryMode) {
$list[] = "\n\t<li>{$thumbnail}</li>";
} else {
# Create the gallery link HTML
$galleryLinkHtml = array ();
if (!isSet ($this->gallery)) {
foreach ($article['collections'] as $collectionId) {
if (isSet ($galleries['collections'][$collectionId])) {
$galleryLinkHtml[] = '<a title="' . htmlspecialchars ($galleries['collections'][$collectionId]['title']) . '" href="' . $galleries['collections'][$collectionId]['url'] . '">' . htmlspecialchars ($galleries['collections'][$collectionId]['title']) . '</a>';
}
}
}
# Compile the gallery list(s)
$galleryLinkHtml = ($galleryLinkHtml ? ' <span class="gallerylink">' . ((count ($galleryLinkHtml) == 1) ? 'Gallery' : 'Galleries') . ': ' . implode (', ', $galleryLinkHtml) . '</span>' : '');
# Construct the list
$list[$key]['thumbnail'] = $thumbnail;
$list[$key]['info'] = '<h3>' . $link . htmlspecialchars (ucfirst ($article['title'])) . '</a></h3> <span class="recordnumber">Record: ' . str_replace (' ', ' ', $article['id']) . '</span>' . $galleryLinkHtml;
if ($computedArtistName) {$list[$key]['info'] .= "\n<p class=\"artist\">by " . htmlspecialchars ($computedArtistName) . "</a></p>\n";}
$list[$key]['info'] .= '<p>' . $article['briefDescription'] . '</p>';
}
}
# Compile the HTML
if ($galleryMode) {
$html = "\n<div class=\"gallery\">\n<ul>" . implode ('', $list) . "\n</ul>\n</div>";
} else {
$html = application::htmlTable ($list, false, 'lines listing spaced', false, true, true);
}
# Return the HTML
return $html;
}
# Function to format related terms
private function formatRelatedTerms ($result)
{
# Create the links
$lookup = array ();
foreach ($result as $element => $words) {
$wordLinks = array ();
foreach ($words as $word) {
$word = trim ($word);
$wordLinks[] = "<a href=\"{$this->baseUrl}/search/?{$this->settings['queryTerm']}=" . htmlspecialchars (urlencode ($word)) . '">' . htmlspecialchars ($word) . '</a>';
}
$lookup[$element] = $element . (((count ($wordLinks) > 1) && (substr (strtolower ($element), -4) == 'term')) ? 's' : '') . ': ' . implode (', ', $wordLinks);
}
$html = application::htmlUl ($lookup, 1, 'small compact');
# Return the HTML
return $html;
}
# Function to parse the photograph number
private function getPhotographNumber ($data, $firstOnly = false)
{
# Find the images
$photographs = $data['imageFiles'];
# If only the first is required, return that
if ($firstOnly) {
if ($photographs) {
return $photographs[0];
}
}
# Return the photos list
return array_values ($photographs);
}
# Function to show the categories
public function categories ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# End if not enabled
if ($this->gallery['disableCategories']) {
$this->page404 ();
return false;
}
# Get the categories
if (!$categories = $this->getCategories ($this->gallery['id'])) {
#!# Inform admin
$this->template['notFound'] = true;
} else {
# Page header
$this->template['pageHeader'] = $this->pageHeader ($this->gallery);
# Define link
$this->template['aatLink'] = $this->settings['aatLink'];
# Assign the gallery data into the template
$this->template['collection'] = $this->gallery;
# Register the list to the template
$this->template['categories'] = $categories;
}
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Function to show the category hierarchy
public function hierarchy ()
{
# If no gallery, throw 404 page
if (!$this->gallery = $this->getCollection ()) {
$this->page404 ();
return false;
}
# Get the categories or end
if (!$categories = $this->getCategories ($this->gallery['id'], $includeUnclassified = false)) {
#!# Inform admin
$this->template['notFound'] = true;
} else {
# Page header
$this->template['pageHeader'] = $this->pageHeader ($this->gallery);
# Define link
$this->template['aatLink'] = $this->settings['aatLink'];
# Assign the gallery data into the template
$this->template['collection'] = $this->gallery;
# Get the hierarchy
$categoryHierarchy = $this->getCategoryHierarchy ($categories);
$this->template['categoryHierarchy'] = application::htmlUlHierarchical ($categoryHierarchy, 'pde', false, true, true, 0, $baseUrl = "{$this->gallery['baseUrl']}/categories");
}
# Process the template
$html = $this->templatise ();
# Show the HTML
echo $html;
}
# Function to get the hierarchy of categories
private function getCategoryHierarchy ($categories, $splitBy = ' & ')
{
# Add the final item to the end of the hierarchy if it doesn't already exist as the last component
foreach ($categories as $key => $values) {
if (!preg_match ('@' . ' & ' . trim ($key) . '$' . '@i', trim ($values['classification']))) {
$categories[$key]['classification'] .= $splitBy . '[' . ucfirst ($values['category']) . ']';
}
}
# Loop through each category to get the hierarchy of category components
$categoryComponents = array ();
foreach ($categories as $key => $attributes) {
$categoryComponents[$key] = explode ($splitBy, $attributes['classification']);
}
# Loop through each category to assemble the components hierarchically
$masterHierarchy = array ();
foreach ($categoryComponents as $hierarchyComponents) {
# Convert the indexed array into a hierarchy
$hierarchy = array ();
$elements = count ($hierarchyComponents);
for ($i = $elements - 1; $i >= 0; $i--) {
#!# Use of ucfirst (strtolower ()) and splitting algorithm only necessary due to unclean data
$name = ucfirst (strtolower (trim ($hierarchyComponents[$i])));
if (substr ($name, 0, 1) == '[') {
$name = '[' . ucfirst (substr ($name, 1));
}