/
DetailController.php
1560 lines (1381 loc) · 69.3 KB
/
DetailController.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
/* ----------------------------------------------------------------------
* app/controllers/DetailController.php : controller for object search request handling - processes searches from top search bar
* ----------------------------------------------------------------------
* CollectiveAccess
* Open-source collections management software
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2013-2019 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
* This program is free software; you may redistribute it and/or modify it under
* the terms of the provided license as published by Whirl-i-Gig
*
* CollectiveAccess is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This source code is free and modifiable under the terms of
* GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
* the "license.txt" file for details, or visit the CollectiveAccess web site at
* http://www.CollectiveAccess.org
*
* ----------------------------------------------------------------------
*/
require_once(__CA_LIB_DIR__."/BaseSearchController.php");
require_once(__CA_LIB_DIR__."/MediaContentLocationIndexer.php");
require_once(__CA_LIB_DIR__.'/Media/MediaViewerManager.php');
require_once(__CA_LIB_DIR__.'/ApplicationPluginManager.php');
require_once(__CA_APP_DIR__."/controllers/FindController.php");
require_once(__CA_APP_DIR__."/helpers/printHelpers.php");
require_once(__CA_APP_DIR__."/helpers/exportHelpers.php");
require_once(__CA_MODELS_DIR__."/ca_objects.php");
require_once(__CA_LIB_DIR__.'/Logging/Downloadlog.php');
class DetailController extends FindController {
# -------------------------------------------------------
/**
*
*/
protected $opa_detail_types = null;
/**
*
*/
protected $config = null;
/**
*
*/
protected $ops_view_prefix = 'Details';
/**
* Path to temporary download scratch file
*/
protected $ops_tmp_download_file_path = null;
# -------------------------------------------------------
public function __construct(&$po_request, &$po_response, $pa_view_paths=null) {
parent::__construct($po_request, $po_response, $pa_view_paths);
if ($this->request->config->get('pawtucket_requires_login')&&!($this->request->isLoggedIn())) {
$this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "LoginForm"));
}
if (($this->request->config->get('deploy_bristol'))&&($this->request->isLoggedIn())) {
if (!($ps_id = urldecode($this->request->getActionExtra()))) { $ps_id = $this->request->getParameter('id', pInteger); }
$t_set_list = new ca_sets();
$t_set = new ca_sets();
$va_sets = $t_set_list->getSetsForUser(array("table" => "ca_objects", "user_id" => $this->request->getUserID(), "checkAccess" => $this->opa_access_values));
$va_user_has_access = false;
if (sizeof($va_sets) > 0) {
foreach ($va_sets as $va_key => $va_set) {
if($t_set->isInSet('ca_objects', $ps_id, $va_set['set_id'])) {
$va_user_has_access = true;
}
}
}
if ($va_user_has_access == false) {
print "You do not have access to view this page.";
die;
}
}
$this->config = caGetDetailConfig();
$this->opa_detail_types = $this->config->getAssoc('detailTypes');
// expand to aliases
foreach($this->opa_detail_types as $vs_code => $va_info) {
if(is_array($va_aliases = caGetOption('aliases', $va_info, null))) {
foreach($va_aliases as $vs_alias) {
$this->opa_detail_types[$vs_alias] =& $this->opa_detail_types[$vs_code];
}
}
}
caSetPageCSSClasses(array("detail"));
}
# -------------------------------------------------------
/**
*
*/
public function __call($ps_function, $pa_args) {
AssetLoadManager::register("panel");
AssetLoadManager::register("mediaViewer");
AssetLoadManager::register("carousel");
AssetLoadManager::register("readmore");
AssetLoadManager::register("maps");
//
// Media viewer
//
if ($this->request->getActionExtra() == 'GetMediaInline') {
return $this->GetMediaInline();
}
if ($this->request->getActionExtra() == 'GetMediaOverlay') {
return $this->GetMediaOverlay();
}
if ($this->request->getActionExtra() == 'GetMediaData') {
return $this->GetMediaData();
}
//
// Return facet content
//
if(($ps_facet = $this->request->getParameter('facet', pString)) || ($ps_remove_facet = $this->request->getParameter('removeCriterion', pString))) {
$vs_browse_type = $this->request->getParameter('browseType', pString);
if (
($vs_browse_table = ((isset($this->opa_detail_types[$vs_browse_type]) && isset($this->opa_detail_types[$vs_browse_type]['table']))) ? $this->opa_detail_types[$vs_browse_type]['table'] : null)
&&
($o_browse = caGetBrowseInstance($vs_browse_table))
) {
if (!($this->request->getParameter('getFacet', pInteger))) {
if ($ps_cache_key = $this->request->getParameter('key', pString)) {
$o_browse->reload($ps_cache_key);
}
if ($ps_facet) {
$o_browse->addCriteria($ps_facet, array($this->request->getParameter('id', pString)));
} else {
$o_browse->removeCriteria($ps_remove_facet, array($this->request->getParameter('removeID', pString)));
}
$o_browse->execute();
$ps_cache_key = $o_browse->getBrowseID();
$this->request->setParameter('key', $ps_cache_key);
} else {
$vs_class = 'ca_objects';
$o_browse = caGetBrowseInstance($vs_class);
if ($ps_cache_key = $this->request->getParameter('key', pString)) {
$o_browse->reload($ps_cache_key);
} else {
$o_browse->addCriteria("collection_facet", $t_subject->getPrimaryKey() );
$o_browse->execute();
}
return $this->getFacet($o_browse);
}
}
}
$ps_function = strtolower($ps_function);
$ps_id = urldecode($this->request->getActionExtra());
if (!isset($this->opa_detail_types[$ps_function]) || !isset($this->opa_detail_types[$ps_function]['table']) || (!($vs_table = $this->opa_detail_types[$ps_function]['table']))) {
// invalid detail type – throw error
throw new ApplicationException("Invalid detail type");
}
$t_subject = Datamodel::getInstance($vs_table, true);
$vs_use_alt_identifier_in_urls = caUseAltIdentifierInUrls($vs_table);
if ((($vb_use_identifiers_in_urls = caUseIdentifiersInUrls()) || ($vs_use_alt_identifier_in_urls)) && (substr($ps_id, 0, 3) == "id:")) {
$va_tmp = explode(":", $ps_id);
$ps_id = (int)$va_tmp[1];
$vb_use_identifiers_in_urls = $vs_use_alt_identifier_in_urls = false;
}
if($vs_use_alt_identifier_in_urls && $t_subject->hasElement($vs_use_alt_identifier_in_urls)) {
$va_load_params = [$vs_use_alt_identifier_in_urls => $ps_id];
} elseif ($vb_use_identifiers_in_urls && $t_subject->getProperty('ID_NUMBERING_ID_FIELD')) {
$va_load_params = [$t_subject->getProperty('ID_NUMBERING_ID_FIELD') => $ps_id];
} else {
$va_load_params = [$t_subject->primaryKey() => (int)$ps_id];
}
if (!($t_subject = call_user_func_array($t_subject->tableName().'::find', array($va_load_params, ['returnAs' => 'firstModelInstance'])))) {
// invalid id - throw error
throw new ApplicationException("Invalid id");
}
// Record view
$t_subject->registerItemView();
$va_options = (isset($this->opa_detail_types[$ps_function]['options']) && is_array($this->opa_detail_types[$ps_function]['options'])) ? $this->opa_detail_types[$ps_function]['options'] : array();
$this->view->setVar("config_options", $va_options);
if (!caGetOption('disableExport', $va_options, false)) {
// Exportables/printables
// merge displays with drop-in print templates
//
$va_available_export_options = caGetAvailablePrintTemplates('summary', array('table' => $t_subject->tableName()));
$this->view->setVar('export_formats', $va_available_export_options);
$va_export_options = array();
foreach($va_available_export_options as $vn_i => $va_format_info) {
$va_export_options[$va_format_info['name']] = $va_format_info['code'];
}
// Get current display list
$t_display = new ca_bundle_displays();
foreach(caExtractValuesByUserLocale($t_display->getBundleDisplays(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'checkAccess' => caGetUserAccessValues($this->request)))) as $va_display) {
$va_export_options[$va_display['name']] = "_display_".$va_display['display_id'];
}
ksort($va_export_options);
$this->view->setVar('export_format_select', caHTMLSelect('export_format', $va_export_options, array('class' => 'searchToolsSelect'), array('value' => $this->view->getVar('current_export_format'), 'width' => '150px')));
}
#
# Enforce access control
#
if(sizeof($this->opa_access_values) && ($t_subject->hasField('access')) && (!in_array($t_subject->get("access"), $this->opa_access_values))){
$this->notification->addNotification(_t("This item is not available for view"), "message");
$this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
return;
}
MetaTagManager::setWindowTitle($this->request->config->get("app_display_name").$this->request->config->get("page_title_delimiter").$t_subject->getTypeName().$this->request->config->get("page_title_delimiter").$t_subject->get('preferred_labels').(($vs_idno = $t_subject->get($t_subject->getProperty('ID_NUMBERING_ID_FIELD'))) ? " [{$vs_idno}]" : ""));
$vs_type = $t_subject->getTypeCode();
$this->view->setVar('detailType', $vs_table);
$this->view->setVar('item', $t_subject);
$this->view->setVar('itemType', $vs_type);
caAddPageCSSClasses(array($vs_table, $ps_function, $vs_type));
// Do we need to pull in the multisearch result set?
if ((ResultContext::getLastFind($this->request, $vs_table, array('noSubtype' => true))) === 'multisearch') {
$o_context = new ResultContext($this->request, $vs_table, 'multisearch', $ps_function);
$o_context->setAsLastFind(false);
$o_context->saveContext();
} else {
$o_context = ResultContext::getResultContextForLastFind($this->request, $vs_table);
}
$this->view->setVar('previousID', $vn_previous_id = $o_context->getPreviousID($t_subject->getPrimaryKey()));
$this->view->setVar('nextID', $vn_next_id = $o_context->getNextID($t_subject->getPrimaryKey()));
$this->view->setVar('previousURL', caDetailUrl($this->request, $vs_table, $vn_previous_id));
$this->view->setVar('nextURL', caDetailUrl($this->request, $vs_table, $vn_next_id));
$this->view->setVar('previousLink', ($vn_previous_id > 0) ? caDetailLink($this->request, caGetOption('previousLink', $va_options, _t('Previous')), '', $vs_table, $vn_previous_id) : '');
$this->view->setVar('nextLink', ($vn_next_id > 0) ? caDetailLink($this->request, caGetOption('nextLink', $va_options, _t('Next')), '', $vs_table, $vn_next_id) : '');
$va_params = array();
$va_params["row_id"] = $t_subject->getPrimaryKey(); # --- used to jump to the last viewed item in the search/browse results
$this->view->setVar('resultsLink', ResultContext::getResultsLinkForLastFind($this->request, $vs_table, caGetOption('resultsLink', $va_options, _t('Back')), null, $va_params));
$this->view->setVar('resultsURL', ResultContext::getResultsUrlForLastFind($this->request, $vs_table, $va_params));
//
// Representation viewer
//
if (method_exists($t_subject, 'getPrimaryRepresentationInstance')) {
if($pn_representation_id = $this->request->getParameter('representation_id', pInteger)){
$t_representation = Datamodel::getInstance("ca_object_representations", true);
$t_representation->load($pn_representation_id);
}else{
$t_representation = $t_subject->getPrimaryRepresentationInstance(array("checkAccess" => $this->opa_access_values));
}
if ($t_representation) {
$this->view->setVar("t_representation", $t_representation);
$this->view->setVar("representation_id", $t_representation->get("representation_id"));
}else{
$t_representation = Datamodel::getInstance("ca_object_representations", true);
$this->view->setVar("representation_id", null);
}
if(!is_array($va_media_display_info = caGetMediaDisplayInfo('detail', $t_representation->getMediaInfo('media', 'original', 'MIMETYPE')))) { $va_media_display_info = []; }
$this->view->setVar('representationViewerPrimaryOnly', caGetOption('representationViewerPrimaryOnly', $va_options, false));
$this->view->setVar('representationViewer',
caRepresentationViewer(
$this->request,
$t_subject,
$t_subject,
array_merge($va_options, $va_media_display_info,
array(
'display' => 'detail',
'showAnnotations' => true,
'primaryOnly' => caGetOption('representationViewerPrimaryOnly', $va_options, false),
'dontShowPlaceholder' => caGetOption('representationViewerDontShowPlaceholder', $va_options, false),
'captionTemplate' => caGetOption('representationViewerCaptionTemplate', $va_options, false)
)
)
)
);
}
//
// map
//
if (!is_array($va_map_attributes = caGetOption(['mapAttributes', 'map_attributes'], $va_options, array())) || !sizeof($va_map_attributes)) {
if ($vs_map_attribute = caGetOption(['mapAttribute', 'map_attribute'], $va_options, false)) { $va_map_attributes = array($vs_map_attribute); }
}
$this->view->setVar("map", "");
if(is_array($va_map_attributes) && sizeof($va_map_attributes)) {
$o_map = new GeographicMap((($vn_width = caGetOption(['mapWidth', 'map_width'], $va_options, false)) ? $vn_width : 285), (($vn_height = caGetOption(['mapHeight', 'map_height'], $va_options, false)) ? $vn_height : 200), 'map');
$vn_mapped_count = 0;
foreach($va_map_attributes as $vs_map_attribute) {
if ($t_subject->get($vs_map_attribute)){
$va_ret = $o_map->mapFrom($t_subject, $vs_map_attribute, array('contentTemplate' => caGetOption('mapContentTemplate', $va_options, false)));
$vn_mapped_count += $va_ret['items'];
}
}
if ($vn_mapped_count > 0) {
$this->view->setVar("map", $o_map->render('HTML', array('zoomLevel' => caGetOption(['mapZoomLevel', 'zoom_level'], $va_options, 12))));
}
}
// Filtering of related items
if (($t_subject->tableName() != 'ca_objects') && (!$this->opa_detail_types[$ps_function]['disableRelatedItemsBrowse'])) {
$vs_class = 'ca_objects';
$o_browse = caGetBrowseInstance($vs_class);
if ($ps_cache_key = $this->request->getParameter('key', pString)) {
$o_browse->reload($ps_cache_key);
} else {
$o_browse->addCriteria("collection_facet", $t_subject->getPrimaryKey() );
$ps_cache_key = $o_browse->getBrowseID();
}
$o_browse->execute();
$this->view->setVar('key', $o_browse->getBrowseID());
$this->view->setVar('browse', $o_browse);
//
// Facets
//
if ($vs_facet_group = caGetOption('facetGroup', $va_browse_info, null)) {
$o_browse->setFacetGroup($vs_facet_group);
}
$o_browse->execute();
$va_available_facet_list = caGetOption('availableFacets', $va_browse_info, null);
$va_facets = $o_browse->getInfoForAvailableFacets();
foreach($va_facets as $vs_facet_name => $va_facet_info) {
if(isset($va_base_criteria[$vs_facet_name])) { continue; } // skip base criteria
$va_facets[$vs_facet_name]['content'] = $o_browse->getFacet($vs_facet_name, array("checkAccess" => $this->opa_access_values, 'checkAvailabilityOnly' => caGetOption('deferred_load', $va_facet_info, false, array('castTo' => 'bool'))));
}
$this->view->setVar('facets', $va_facets);
$this->view->setVar('key', $vs_key = $o_browse->getBrowseID());
Session::setVar($ps_function.'_last_browse_id', $vs_key);
// remove base criteria from display list
if (is_array($va_base_criteria)) {
foreach($va_base_criteria as $vs_base_facet => $vs_criteria_value) {
unset($va_criteria[$vs_base_facet]);
}
}
$va_criteria = $o_browse->getCriteriaWithLabels();
$va_criteria_for_display = array();
foreach($va_criteria as $vs_facet_name => $va_criterion) {
$va_facet_info = $o_browse->getInfoForFacet($vs_facet_name);
foreach($va_criterion as $vn_criterion_id => $vs_criterion) {
$va_criteria_for_display[] = array('facet' => $va_facet_info['label_singular'], 'facet_name' => $vs_facet_name, 'value' => $vs_criterion, 'id' => $vn_criterion_id);
}
}
$this->view->setVar('criteria', $va_criteria_for_display);
$o_rel_context = new ResultContext($this->request, 'ca_objects', 'detailrelated', $ps_function);
$o_rel_context->setParameter('key', $vs_key);
$o_rel_context->setAsLastFind(true);
$qr_rel_res = $o_browse->getResults();
$o_rel_context->setResultList($qr_rel_res->getAllFieldValues('ca_objects.object_id'));
$o_rel_context->saveContext();
}
//
// comments, tags, rank
//
$this->view->setVar('commentsEnabled', (bool)$va_options['enableComments']);
if ((bool)$va_options['enableComments']) {
$this->view->setVar('averageRank', $t_subject->getAverageRating(true));
$this->view->setVar('numRank', $t_subject->getNumRatings(true));
#
# User-generated comments, tags and ratings
#
$va_user_comments = $t_subject->getComments(null, true);
$va_comments = array();
if (is_array($va_user_comments)) {
foreach($va_user_comments as $va_user_comment){
if($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]){
# TODO: format date based on locale
$va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
# -- get name of commenter
if($va_user_comment["user_id"]){
$t_user = new ca_users($va_user_comment["user_id"]);
$va_user_comment["author"] = $t_user->getName();
}elseif($va_user_comment["name"]){
$va_user_comment["author"] = $va_user_comment["name"];
}
$va_comments[] = $va_user_comment;
}
}
}
$this->view->setVar('comments', $va_comments);
$va_user_tags = $t_subject->getTags(null, true);
$va_tags = array();
if (is_array($va_user_tags)) {
foreach($va_user_tags as $va_user_tag){
if(!in_array($va_user_tag["tag"], $va_tags)){
$va_tags[] = $va_user_tag["tag"];
}
}
}
$this->view->setVar('tags_array', $va_tags);
$this->view->setVar('tags', implode(", ", $va_tags));
$this->view->setVar("itemComments", caDetailItemComments($this->request, $t_subject->getPrimaryKey(), $t_subject, $va_comments, $va_tags));
} else {
$this->view->setVar("itemComments", '');
}
//
// Set row_id for use within the view
//
$this->view->setVar('id', $ps_id);
$this->view->setVar($t_subject->primaryKey(), $ps_id);
//
// share link
//
$this->view->setVar('shareEnabled', (bool)$va_options['enableShare']);
$va_options['shareLabel'] ? $ps_label = $va_options['shareLabel'] : $ps_label = 'Share';
$this->view->setVar("shareLink", "<a href='#' onclick='caMediaPanel.showPanel(\"".caNavUrl($this->request, '', 'Detail', 'ShareForm', array("tablename" => $t_subject->tableName(), "item_id" => $t_subject->getPrimaryKey()))."\"); return false;'>".$ps_label."</a>");
// find view
// first look for type-specific view
$vs_path = "Details/{$vs_table}_default_html.php"; // If no type specific view use the default
if (is_array($va_type_codes = caMakeTypeList($vs_table, [$t_subject->getTypeCode()]))) {
$va_type_codes = array_merge($va_type_codes, caMakeTypeList($vs_table, $t_subject->getTypeInstance()->getHierarchyAncestors($t_subject->getTypeID(), ['idsOnly' => true]), ['dontIncludeSubtypesInTypeRestriction' => true]));
foreach(array_reverse($va_type_codes) as $vs_type_code) { // reverse list to try more specific types first
if ($this->viewExists("Details/{$vs_table}_{$vs_type_code}_html.php")) {
$vs_path = "Details/{$vs_table}_{$vs_type_code}_html.php";
break;
}
}
}
//
// pdf link
//
$this->view->setVar('pdfEnabled', (bool)$va_options['enablePDF']);
switch($ps_view = $this->request->getParameter('view', pString)) {
case 'pdf':
if (!($vn_limit = ini_get('max_execution_time'))) { $vn_limit = 30; }
set_time_limit($vn_limit * 6);
caExportItemAsPDF($this->request, $t_subject, $this->request->getParameter("export_format", pString), caGenerateDownloadFileName(caGetOption('pdfExportTitle', $va_options, null), ['t_subject' => $t_subject]), ['checkAccess' => $this->opa_access_values]);
break;
default:
caDoTemplateTagSubstitution($this->view, $t_subject, $vs_path, ['checkAccess' => $this->opa_access_values]);
$this->render($vs_path);
break;
}
}
# -------------------------------------------------------
/**
* Returns list of *timebased* (audio/video) annotations to display
*
* Expects the following request parameters:
* object_id = the id of the ca_objects record to display
* representation_id = the id of the ca_object_representations record to display; the representation must belong to the specified object
*
* Optional request parameters:
* version = The version of the representation to display. If omitted the display version configured in media_display.conf is used
*
*/
public function GetTimebasedRepresentationAnnotationList() {
$pn_id = $this->request->getParameter('id', pInteger);
$pn_representation_id = $this->request->getParameter('representation_id', pInteger);
$ps_detail_type = $this->request->getParameter('context', pString);
$va_detail_options = (isset($this->opa_detail_types[$ps_detail_type]['options']) && is_array($this->opa_detail_types[$ps_detail_type]['options'])) ? $this->opa_detail_types[$ps_detail_type]['options'] : array();
if(!$pn_id) { $pn_id = 0; }
$t_rep = new ca_object_representations($pn_representation_id);
if (!$t_rep->getPrimaryKey()) {
$this->postError(1100, _t('Invalid object/representation'), 'DetailController->GetTimebasedRepresentationAnnotationList');
return;
}
if (!($vs_template = $va_detail_options['displayAnnotationTemplate'])) { $vs_template = '^ca_representation_annotations.preferred_labels.name'; }
$va_props = $t_rep->getMediaInfo('media', 'original', 'PROPERTIES');
$va_annotation_list = $va_annotation_times = array();
if (
is_array($va_annotations = $t_rep->getAnnotations(array('idsOnly' => true))) //$t_rep->get('ca_representation_annotations.annotation_id', array('returnAsArray' => true)))
&&
sizeof($va_annotations)
&&
($qr_annotations = caMakeSearchResult('ca_representation_annotations', $va_annotations))
) {
while($qr_annotations->nextHit()) {
if (!preg_match('!^TimeBased!', $qr_annotations->getAnnotationType())) { continue; }
$va_annotation_list[] = $qr_annotations->getWithTemplate($vs_template);
$va_annotation_times[] = array((float)$qr_annotations->getPropertyValue('startTimecode', true) - (float)$va_props['timecode_offset'], (float)$qr_annotations->getPropertyValue('endTimecode', true) - (float)$va_props['timecode_offset']);
}
$qr_annotations->seek(0);
}
$this->view->setVar('representation_id', $pn_representation_id);
$this->view->setVar('annotation_list', $va_annotation_list);
$this->view->setVar('annotation_times', $va_annotation_times);
$this->view->setVar('annotations_search_results', $qr_annotations);
$this->view->setVar('player_name', "caMediaOverlayTimebased_{$pn_representation_id}_detail");
$this->render('Details/annotations_html.php');
}
# -------------------------------------------------------
/**
*
*/
public function SearchWithinMedia() {
$pn_representation_id = $this->request->getParameter('representation_id', pInteger);
$ps_q = $this->request->getParameter('q', pString);
$va_results = MediaContentLocationIndexer::SearchWithinMedia($ps_q, 'ca_object_representations', $pn_representation_id, 'media');
$this->view->setVar('results', $va_results);
$this->render('Details/object_representation_within_media_search_results_json.php');
}
# -------------------------------------------------------
/**
* Download all media attached to specified object (not necessarily open for editing)
* Includes all representation media attached to the specified object + any media attached to other
* objects in the same object hierarchy as the specified object. Used by the book viewer interfacce to
* initiate a download.
*
* TODO: make configurable
*/
public function DownloadMedia() {
if (!caObjectsDisplayDownloadLink($this->request)) {
$this->postError(1100, _t('Cannot download media'), 'DetailController->DownloadMedia');
return;
}
$o_app_plugin_manager = new ApplicationPluginManager();
$pn_object_id = $this->request->getParameter('object_id', pInteger);
$pb_exclude_ancestors = $this->request->getParameter('exclude_ancestors', pInteger);
$pn_value_id = $this->request->getParameter('value_id', pInteger);
if ($pn_value_id) {
return $this->DownloadAttributeMedia();
}
$t_object = new ca_objects($pn_object_id);
if (!($vn_object_id = $t_object->getPrimaryKey())) { return; }
if(sizeof($this->opa_access_values) && (!in_array($t_object->get("access"), $this->opa_access_values))){
return;
}
$ps_version = $this->request->getParameter('version', pString);
if (!$ps_version) { $ps_version = 'original'; }
$this->view->setVar('version', $ps_version);
if($pb_exclude_ancestors){
$va_ancestor_ids = array($pn_object_id);
}else{
$va_ancestor_ids = $t_object->getHierarchyAncestors(null, array('idsOnly' => true, 'includeSelf' => true));
if ($vn_parent_id = array_pop($va_ancestor_ids)) {
$t_object->load($vn_parent_id);
if(!sizeof($this->opa_access_values) || (in_array($t_object->get("access"), $this->opa_access_values))){
array_unshift($va_ancestor_ids, $vn_parent_id);
}
}
}
$va_child_ids = $t_object->get("ca_objects.children.object_id", array("returnWithStructure" => true, "checkAccess" => $this->opa_access_values));
foreach($va_ancestor_ids as $vn_id) {
array_unshift($va_child_ids, $vn_id);
}
$vn_c = 1;
$va_file_names = array();
$va_file_paths = array();
// Allow plugins to modify object_id list
$va_child_ids = $o_app_plugin_manager->hookDetailDownloadMediaObjectIDs($va_child_ids);
$va_child_ids = array_unique($va_child_ids);
$t_download_log = new Downloadlog();
foreach($va_child_ids as $vn_object_id) {
$t_child_object = new ca_objects($vn_object_id);
if (!$t_child_object->getPrimaryKey()) { continue; }
$t_download_log->log(array(
"user_id" => $this->request->getUserID() ? $this->request->getUserID() : null,
"ip_addr" => $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : null,
"table_num" => $t_object->TableNum(),
"row_id" => $vn_object_id,
"representation_id" => null,
"download_source" => "pawtucket"
));
$va_reps = $t_child_object->getRepresentations(array($ps_version), null, array("checkAccess" => $this->opa_access_values));
$vs_idno = $t_child_object->get('idno');
foreach($va_reps as $vn_representation_id => $va_rep) {
$va_rep_info = $va_rep['info'][$ps_version];
$vs_idno_proc = preg_replace('![^A-Za-z0-9_\-]+!', '_', $vs_idno);
switch($this->request->user->getPreference('downloaded_file_naming')) {
case 'idno':
$vs_file_name = $vs_idno_proc.'_'.$vn_c.'.'.$va_rep_info['EXTENSION'];
break;
case 'idno_and_version':
$vs_file_name = $vs_idno_proc.'_'.$ps_version.'_'.$vn_c.'.'.$va_rep_info['EXTENSION'];
break;
case 'idno_and_rep_id_and_version':
$vs_file_name = $vs_idno_proc.'_representation_'.$vn_representation_id.'_'.$ps_version.'.'.$va_rep_info['EXTENSION'];
break;
case 'original_name':
default:
if ($va_rep['info']['original_filename']) {
$va_tmp = explode('.', $va_rep['info']['original_filename']);
if (sizeof($va_tmp) > 1) {
if (strlen($vs_ext = array_pop($va_tmp)) < 3) {
$va_tmp[] = $vs_ext;
}
}
$vs_file_name = join('_', $va_tmp);
} else {
$vs_file_name = $vs_idno_proc.'_representation_'.$vn_representation_id.'_'.$ps_version;
}
if (isset($va_file_names[$vs_file_name.'.'.$va_rep_info['EXTENSION']])) {
$vs_file_name.= "_{$vn_c}";
}
$vs_file_name .= '.'.$va_rep_info['EXTENSION'];
break;
}
$va_file_names[$vs_file_name] = true;
$this->view->setVar('version_download_name', $vs_file_name);
//
// Perform metadata embedding
$t_rep = new ca_object_representations($va_rep['representation_id']);
if (!($vs_path = $this->ops_tmp_download_file_path = caEmbedMediaMetadataIntoFile($t_rep->getMediaPath('media', $ps_version), 'ca_objects', $t_child_object->getPrimaryKey(), $t_child_object->getTypeCode(), $t_rep->getPrimaryKey(), $t_rep->getTypeCode()))) {
$vs_path = $t_rep->getMediaPath('media', $ps_version);
}
$va_file_paths[$vs_path] = $vs_file_name;
$vn_c++;
}
}
// Allow plugins to modify file path list
$va_file_paths = $o_app_plugin_manager->hookDetailDownloadMediaFilePaths($va_file_paths);
if (sizeof($va_file_paths) > 1) {
if (!($vn_limit = ini_get('max_execution_time'))) { $vn_limit = 30; }
set_time_limit($vn_limit * 2);
$o_zip = new ZipFile();
foreach($va_file_paths as $vs_path => $vs_name) {
$o_zip->addFile($vs_path, $vs_name, null, array('compression' => 0)); // don't try to compress
}
$this->view->setVar('archive_path', $vs_path = $o_zip->output(ZIPFILE_FILEPATH));
$this->view->setVar('archive_name', preg_replace('![^A-Za-z0-9\.\-]+!', '_', $t_object->get('idno')).'.zip');
$vn_rc = $this->render('Details/object_download_media_binary.php');
if ($vs_path) { unlink($vs_path); }
} else {
foreach($va_file_paths as $vs_path => $vs_name) {
$this->view->setVar('archive_path', $vs_path);
$this->view->setVar('archive_name', $vs_name);
}
$vn_rc = $this->render('Details/object_download_media_binary.php');
}
return $vn_rc;
}
# -------------------------------------------------------
/**
* Download single representation from currently open object
*
* TODO: remove and route all references to DownloadMedia()
*/
public function DownloadRepresentation() {
if (!caObjectsDisplayDownloadLink($this->request)) {
$this->postError(1100, _t('Cannot download media'), 'DetailController->DownloadMedia');
return;
}
$ps_context = $this->request->getParameter('context', pString);
if ($ps_context == 'gallery') {
$va_context = [
'table' => 'ca_objects'
];
} elseif (!is_array($va_context = $this->opa_detail_types[$ps_context])) {
throw new ApplicationException(_t('Invalid context'));
}
if (!($t_instance = Datamodel::getInstance($va_context['table'], true))) {
throw new ApplicationException(_t('Invalid context'));
}
if (!($vn_object_id = $this->request->getParameter('object_id', pInteger))) {
$vn_object_id = $this->request->getParameter('id', pInteger);
}
$t_instance->load($vn_object_id);
if (!$t_instance->isLoaded()) {
throw new ApplicationException(_t('Cannot download media'));
}
if(sizeof($this->opa_access_values) && (!in_array($t_instance->get("access"), $this->opa_access_values))){
return;
}
$pn_representation_id = $this->request->getParameter('representation_id', pInteger);
$ps_version = $this->request->getParameter('version', pString);
$this->view->setVar('representation_id', $pn_representation_id);
$t_rep = new ca_object_representations($pn_representation_id);
if(sizeof($this->opa_access_values) && (!in_array($t_rep->get("access"), $this->opa_access_values))){
return;
}
$this->view->setVar('t_object_representation', $t_rep);
$t_download_log = new Downloadlog();
$t_download_log->log(array(
"user_id" => $this->request->getUserID() ? $this->request->getUserID() : null,
"ip_addr" => $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : null,
"table_num" => $t_instance->TableNum(),
"row_id" => $vn_object_id,
"representation_id" => $pn_representation_id,
"download_source" => "pawtucket"
));
$va_versions = $t_rep->getMediaVersions('media');
if (!in_array($ps_version, $va_versions)) { $ps_version = $va_versions[0]; }
$this->view->setVar('version', $ps_version);
$va_rep_info = $t_rep->getMediaInfo('media', $ps_version);
$this->view->setVar('version_info', $va_rep_info);
$va_info = $t_rep->getMediaInfo('media');
$vs_idno_proc = preg_replace('![^A-Za-z0-9_\-]+!', '_', $t_instance->get('idno'));
$vs_mode = $this->request->config->get('downloaded_file_naming');
$vals = ['idno' => $vs_idno_proc];
foreach(array_merge($va_rep_info, $va_info) as $k => $v) {
if (is_array($v)) { continue; }
if (strtolower($k) == 'original_filename') { $v = pathinfo($v, PATHINFO_FILENAME); }
$vals[strtolower($k)] = preg_replace('![^A-Za-z0-9_\-]+!', '_', $v);
}
switch($vs_mode) {
case 'idno':
$this->view->setVar('version_download_name', $vs_idno_proc.'.'.$va_rep_info['EXTENSION']);
break;
case 'idno_and_version':
$this->view->setVar('version_download_name', $vs_idno_proc.'_'.$ps_version.'.'.$va_rep_info['EXTENSION']);
break;
case 'idno_and_rep_id_and_version':
$this->view->setVar('version_download_name', $vs_idno_proc.'_representation_'.$pn_representation_id.'_'.$ps_version.'.'.$va_rep_info['EXTENSION']);
break;
case 'original_name':
default:
if (strpos($vs_mode, "^") !== false) { // template
$this->view->setVar('version_download_name', caProcessTemplate($vs_mode, $vals).'.'.$va_rep_info['EXTENSION']);
} elseif ($va_info['ORIGINAL_FILENAME']) {
$va_tmp = explode('.', $va_info['ORIGINAL_FILENAME']);
if (sizeof($va_tmp) > 1) {
if (strlen($vs_ext = array_pop($va_tmp)) < 3) {
$va_tmp[] = $vs_ext;
}
}
$this->view->setVar('version_download_name', str_replace(" ", "_", join('_', $va_tmp).'.'.$va_rep_info['EXTENSION']));
} else {
$this->view->setVar('version_download_name', $vs_idno_proc.'_representation_'.$pn_representation_id.'_'.$ps_version.'.'.$va_rep_info['EXTENSION']);
}
break;
}
//
// Perform metadata embedding
if ($this->ops_tmp_download_file_path = caEmbedMediaMetadataIntoFile($t_rep->getMediaPath('media', $ps_version), 'ca_objects', $t_instance->getPrimaryKey(), $t_instance->getTypeCode(), $t_rep->getPrimaryKey(), $t_rep->getTypeCode())) {
$this->view->setVar('version_path', $this->ops_tmp_download_file_path);
} else {
$this->view->setVar('version_path', $t_rep->getMediaPath('media', $ps_version));
}
$this->render('Details/object_representation_download_binary.php', true);
}
# -------------------------------------------------------
# Tagging and commenting
# -------------------------------------------------------
/**
*
*/
public function CommentForm(){
if (!$this->request->isLoggedIn()) { $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm')); return; }
$this->view->setVar("item_id", $this->request->getParameter('item_id', pInteger));
$this->view->setVar("tablename", $this->request->getParameter('tablename', pString));
$this->render('Details/form_comments_html.php');
}
# -------------------------------------------------------
/**
*
*/
public function SaveCommentTagging() {
if (!caValidateCSRFToken($this->request)) {
throw new ApplicationException(_t("Invalid CSRF token"));
}
# --- inline is passed to indicate form appears embedded in detail page, not in overlay
$vn_inline_form = $this->request->getParameter("inline", pInteger);
if(!$t_item = Datamodel::getInstance($this->request->getParameter("tablename", pString), true)) {
throw new ApplicationException("Invalid table name ".$this->request->getParameter("tablename", pString)." for saving comment");
}
$ps_table = $this->request->getParameter("tablename", pString);
if(!($vn_item_id = $this->request->getParameter("item_id", pInteger))){
if($vn_inline_form){
$this->notification->addNotification(_t("Invalid ID"), __NOTIFICATION_TYPE_ERROR__);
$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
}else{
$this->view->setVar("message", _t("Invalid ID"));
$this->render("Form/reload_html.php");
}
return;
}
if(!$t_item->load($vn_item_id)){
if($vn_inline_form){
$this->notification->addNotification(_t("ID does not exist"), __NOTIFICATION_TYPE_ERROR__);
$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
}else{
$this->view->setVar("message", _t("ID does not exist"));
$this->render("Form/reload_html.php");
}
return;
}
# --- get params from form
$ps_comment = $this->request->getParameter('comment', pString);
$pn_rank = $this->request->getParameter('rank', pInteger);
$ps_tags = $this->request->getParameter('tags', pString);
$ps_email = $this->request->getParameter('email', pString);
$ps_name = $this->request->getParameter('name', pString);
$ps_location = $this->request->getParameter('location', pString);
$ps_media1 = $_FILES['media1']['tmp_name'];
$ps_media1_original_name = $_FILES['media1']['name'];
$va_errors = array();
if(!$this->request->getUserID() && !$ps_name && !$ps_email){
$va_errors["general"] = _t("Please enter your name and email");
}
if(!$ps_comment && !$pn_rank && !$ps_tags && !$ps_media1){
$va_errors["general"] = _t("Please enter your contribution");
}
if(sizeof($va_errors)){
$this->view->setVar("form_comment", $ps_comment);
$this->view->setVar("form_rank", $pn_rank);
$this->view->setVar("form_tags", $ps_tags);
$this->view->setVar("form_email", $ps_email);
$this->view->setVar("form_name", $ps_name);
$this->view->setVar("form_location", $ps_location);
$this->view->setVar("item_id", $vn_item_id);
$this->view->setVar("tablename", $ps_table);
if($vn_inline_form){
$this->notification->addNotification($va_errors["general"], __NOTIFICATION_TYPE_ERROR__);
$this->request->setActionExtra($vn_item_id);
$this->__call(caGetDetailForType($ps_table), null);
#$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
}else{
$this->view->setVar("errors", $va_errors);
$this->render('Details/form_comments_html.php');
}
}else{
# --- if there is already a rank set from this user/IP don't let another
$t_item_comment = new ca_item_comments();
$vs_dup_rank_message = "";
$vb_dup_rank = false;
if($this->request->getUserID() && $t_item_comment->load(array("row_id" => $vn_item_id, "user_id" => $this->request->getUserID()))){
if($t_item_comment->get("comment_id")){
$pn_rank = null;
$vb_dup_rank = true;
}
}
if($t_item_comment->load(array("row_id" => $vn_item_id, "ip_addr" => $_SERVER['REMOTE_ADDR']))){
$pn_rank = null;
$vb_dup_rank = true;
}
if($vb_dup_rank){
$vs_dup_rank_message = " "._t("You can only rate an item once.");
}
if(!(($pn_rank > 0) && ($pn_rank <= 5))){
$pn_rank = null;
}
if($ps_comment || $pn_rank || $ps_media1){
$t_item->addComment($ps_comment, $pn_rank, $this->request->getUserID(), null, $ps_name, $ps_email, ($this->request->config->get("dont_moderate_comments")) ? 1:0, null, array('media1_original_filename' => $ps_media1_original_name), $ps_media1, null, null, null, $ps_location);
}
if($ps_tags){
$va_tags = array();
$va_tags = explode(",", $ps_tags);
foreach($va_tags as $vs_tag){
$t_item->addTag(trim($vs_tag), $this->request->getUserID(), null, ($this->request->config->get("dont_moderate_comments")) ? 1:0, null);
}
}
if($ps_comment || $ps_tags || $ps_media1){
# --- check if email notification should be sent to admin
if(!$this->request->config->get("dont_email_notification_for_new_comments")){
# --- send email confirmation
$o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
$o_view->setVar("comment", $ps_comment);
$o_view->setVar("tags", $ps_tags);
$o_view->setVar("name", $ps_name);
$o_view->setVar("email", $ps_email);
$o_view->setVar("item", $t_item);
# -- generate email subject line from template
$vs_subject_line = $o_view->render("mailTemplates/admin_comment_notification_subject.tpl");
# -- generate mail text from template - get both the text and the html versions
$vs_mail_message_text = $o_view->render("mailTemplates/admin_comment_notification.tpl");
$vs_mail_message_html = $o_view->render("mailTemplates/admin_comment_notification_html.tpl");
caSendmail($this->request->config->get("ca_admin_email"), $this->request->config->get("ca_admin_email"), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
}
if($this->request->config->get("dont_moderate_comments")){
if($vn_inline_form){
$this->notification->addNotification(_t("Thank you for contributing.").$vs_dup_rank_message, __NOTIFICATION_TYPE_INFO__);
$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
return;
}else{
$this->view->setVar("message", _t("Thank you for contributing.").$vs_dup_rank_message);
$this->render("Form/reload_html.php");
}
}else{
if($vn_inline_form){
$this->notification->addNotification(_t("Thank you for contributing. Your comments will be posted on this page after review by site staff.").$vs_dup_rank_message, __NOTIFICATION_TYPE_INFO__);
$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
return;
}else{
$this->view->setVar("message", _t("Thank you for contributing. Your comments will be posted on this page after review by site staff.").$vs_dup_rank_message);
$this->render("Form/reload_html.php");
}
}
}else{
if($vn_inline_form){
$this->notification->addNotification(_t("Thank you for your contribution.").$vs_dup_rank_message, __NOTIFICATION_TYPE_INFO__);
$this->response->setRedirect(caDetailUrl($this->request, $ps_table, $vn_item_id));
return;
}else{
$this->view->setVar("message", _t("Thank you for your contribution.").$vs_dup_rank_message);
$this->render("Form/reload_html.php");
}
}
}
}
# -------------------------------------------------------
# share - email item
# -------------------------------------------------------
/**
*
*/
function ShareForm() {
$ps_tablename = $this->request->getParameter('tablename', pString);
$pn_item_id = $this->request->getParameter('item_id', pInteger);
if(!$t_item = Datamodel::getInstance($ps_tablename, true)) {
throw new ApplicationException("Invalid table name ".$ps_tablename." for detail"); // shouldn't happen
}
if(!$t_item->load($pn_item_id)){
throw new ApplicationException("ID does not exist"); // shouldn't happen
}
$this->view->setVar('t_item', $t_item);
$this->view->setVar('item_id', $pn_item_id);
$this->view->setVar('tablename', $ps_tablename);
$this->render("Details/form_share_html.php");
}
# ------------------------------------------------------
/**
*
*/
public function SendShare() {