-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdrs-tk.php
executable file
·1542 lines (1336 loc) · 62.9 KB
/
drs-tk.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
/**
* Plugin Name: CERES: Exhibit Toolkit Plugin
* Plugin URI:
* Version: 1.2
* Author: Digital Scholarship Group, Northeastern University. Eli Zoller, Patrick Murray-John, et al.
* Description: This plugin provides the core functionality of the CERES: Exhibit Toolkit and brings the content of a project from the DRS into Wordpress using the DRS API.
*/
require_once( plugin_dir_path( __FILE__ ) . 'inc/item.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/browse.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/breadcrumb.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/shortcodes.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/video_shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/item_shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/tiles_shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/slider_shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/map_shortcode.php');
require_once( plugin_dir_path( __FILE__ ) . 'inc/timeline_shortcode.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/metabox.php' );
require_once( plugin_dir_path( __FILE__ ) . 'config.php' );
/* Moving toward a Ceres namespace for podcasting */
// require_once( plugin_dir_path( __FILE__ ) . 'classes/fetchers/Ceres_Abstract_Fetcher.php' );
// require_once( plugin_dir_path( __FILE__ ) . 'classes/renderers/Ceres_Abstract_Renderer.php' );
// require_once( plugin_dir_path( __FILE__ ) . 'classes/fetchers/Ceres_Drs_Fetcher.php' );
// require_once( plugin_dir_path( __FILE__ ) . 'classes/renderers/Ceres_Podcast_Renderer.php' );
// require_once( plugin_dir_path( __FILE__ ) . 'classes/renderers/Ceres_Podcast_Rss_Renderer.php' );
// require_once( plugin_dir_path( __FILE__ ) . 'classes/renderers/Ceres_Jwplayer_Renderer.php' );
define( 'ALLOW_UNFILTERED_UPLOADS', true ); //this will allow files without extensions - aka from fedora
define('DRS_PLUGIN_PATH', plugin_dir_path( __FILE__ ));
define('DRS_PLUGIN_URL', plugin_dir_url(__FILE__));
define('DPLA_FALLBACK_IMAGE_URL', DRS_PLUGIN_URL . 'assets/images/DPLA-square-logo-color.jpeg');
define('DRSTK_PODCAST_REGISTER_HTML',
"
<small>When you register your podcast with this service, it will tell you the URL to use here.</small>
<br /><small>Use this feed URL to tell the service where to look for your podcasts: <br />" . get_site_url() . "?feed=podcasts</small><br/>
");
// Set template names here so we don't have to go into the code.
$TEMPLATE = array(
'browse_template' => dirname(__FILE__) . '/templates/browse.php',
'item_template' => dirname(__FILE__) . '/templates/item.php',
'download_template' => dirname(__FILE__) . '/templates/download.php',
'mirador_template' => dirname(__FILE__) . '/templates/mirador.php',
);
$TEMPLATE_THEME = array(
'browse_template' => 'overrides/drstk-browse.php',
'item_template' => 'overrides/drstk-item.php',
'download_template' => 'overrides/drstk-download.php',
'mirador_template' => 'overrides/drstk-mirador.php',
);
register_activation_hook( __FILE__, 'drstk_install' );
register_deactivation_hook( __FILE__, 'drstk_deactivation' );
$all_meta_options = array("Title","Alternative Title","Creator","Contributor","Publisher","Type of Resource","Genre","Language","Physical Description","Abstract/Description","Table of contents","Notes","Subjects and keywords","Related item","Identifier","Access condition","Location","uri","Format","Permanent URL","Date created","Date issued","Copyright date","Biographical/Historical","Biográfica/histórica", "Issuance","Frequency","Digital origin","Map data","Use and reproduction","Restriction on access");
$all_assoc_meta_options = array("full_title_ssi","creator_tesim","abstract_tesim");
/**
* Rewrite rules for the plugin.
*/
add_action('init', 'drstk_rewrite_rule');
function drstk_rewrite_rule() {
global $post;
$home_url = get_option('drstk_home_url');
add_rewrite_rule('^'.$home_url.'browse/?$', 'index.php?post_type=drs&drstk_template_type=browse', 'top');
add_rewrite_rule('^'.$home_url.'search/?$', 'index.php?post_type=drs&drstk_template_type=search', 'top');
add_rewrite_rule('^'.$home_url.'item/([^/]*)/?([^/]*)*', 'index.php?post_type=drs&drstk_template_type=item&pid=$matches[1]&js=$matches[2]', 'top');
add_rewrite_rule('^'.$home_url.'download/([^/]*)/?', 'index.php?post_type=drs&drstk_template_type=download&pid=$matches[1]', 'top');
add_rewrite_rule('^'.$home_url.'collections/?$', 'index.php?post_type=drs&drstk_template_type=collections', 'top');
add_rewrite_rule('^'.$home_url.'collection/([^/]*)/?', 'index.php?post_type=drs&drstk_template_type=collection&pid=$matches[1]', 'top');
$mirador_url = get_option('drstk_mirador_url') == '' ? 'mirador' : get_option('drstk_mirador_url');
add_rewrite_rule('^'.$home_url.$mirador_url.'/?$', 'index.php?post_type=drs&drstk_template_type=mirador', 'top');
if (get_option('drstk_item_extensions') == "on"){
$args = array(
'post_type' => 'drstk_item_extension',
'posts_per_page' => 1,
'post_status' => 'publish',
);
$meta_query = new WP_Query( $args );
if ($meta_query->have_posts()){
while ($meta_query->have_posts()){
$meta_query->the_post();
$post_id = $post->ID;
$item_url = get_post_meta($post_id, 'item-url', true);
$item_id = get_post_meta($post_id, 'item-id', true);
if (isset($item_url) && isset($item_id)){
add_rewrite_rule("^$home_url$item_url/?$", 'index.php?post_type=drs&drstk_template_type=item&pid='.$item_id, 'top');
}
}
}
}
}
/*add something like this later to override manual paths to the original wp search */
// function fb_change_search_url_rewrite() {
// if ( is_search() && ! empty( $_GET['s'] ) ) {
// wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
// exit();
// }
// }
// add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
function drstk_install() {
// Clear the permalinks after the post type has been registered
drstk_rewrite_rule();
flush_rewrite_rules();
}
function drstk_deactivation() {
// Clear the permalinks to remove our post type's rules
flush_rewrite_rules();
}
//This function creates the settings page for entering the pid
add_action('admin_menu', 'drs_admin_add_page');
function drs_admin_add_page() {
$hook = add_options_page('Settings for CERES: Exhibit Toolkit Plugin', 'CERES: Exhibit Toolkit', 'manage_options', 'drstk_admin_menu', 'drstk_display_settings');
add_action('load-'.$hook,'drstk_plugin_settings_save');
}
//This registers the settings
function register_drs_settings() {
//Project Settings
add_settings_section('drstk_project', "Project", null, 'drstk_options');
add_settings_field('drstk_collection', 'Project Collection or Set URL', 'drstk_collection_callback', 'drstk_options', 'drstk_project');
register_setting( 'drstk_options', 'drstk_collection' );
add_settings_field('drstk_home_url', 'Permalink/URL Base', 'drstk_home_url_callback', 'drstk_options', 'drstk_project');
register_setting( 'drstk_options', 'drstk_home_url', 'drstk_home_url_validation' );
//Search Settings
add_settings_section('drstk_search_settings', 'Search', null, 'drstk_options');
add_settings_field('drstk_search_page_title', 'Search Page Title', 'drstk_search_page_title_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_search_page_title' );
add_settings_field('drstk_search_placeholder', 'Search Box Placeholder Text', 'drstk_search_placeholder_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_search_placeholder' );
add_settings_field('drstk_search_metadata', 'Metadata to Display', 'drstk_search_metadata_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_search_metadata' );
add_settings_field('drstk_search_related_content_title', 'Related Content Title', 'drstk_search_related_content_title_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_search_related_content_title' );
add_settings_field('drstk_default_search_per_page', 'Default Per Page', 'drstk_default_search_per_page_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_default_search_per_page' );
add_settings_field('drstk_search_show_facets', 'Show Facets', 'drstk_search_show_facets_callback', 'drstk_options', 'drstk_search_settings');
register_setting( 'drstk_options', 'drstk_search_show_facets' );
// Browse Settings
add_settings_section('drstk_browse_settings', 'Browse', null, 'drstk_options');
add_settings_field('drstk_browse_page_title', 'Browse Page Title', 'drstk_browse_page_title_callback', 'drstk_options', 'drstk_browse_settings');
register_setting( 'drstk_options', 'drstk_browse_page_title' );
add_settings_field('drstk_browse_metadata', 'Metadata to Display', 'drstk_browse_metadata_callback', 'drstk_options', 'drstk_browse_settings');
register_setting( 'drstk_options', 'drstk_browse_metadata' );
add_settings_field('drstk_default_sort', 'Default Sort', 'drstk_default_sort_callback', 'drstk_options', 'drstk_browse_settings');
register_setting( 'drstk_options', 'drstk_default_sort' );
add_settings_field('drstk_default_browse_per_page', 'Default Per Page', 'drstk_default_browse_per_page_callback', 'drstk_options', 'drstk_browse_settings');
register_setting( 'drstk_options', 'drstk_default_browse_per_page' );
add_settings_field('drstk_browse_show_facets', 'Show Facets', 'drstk_browse_show_facets_callback', 'drstk_options', 'drstk_browse_settings');
register_setting( 'drstk_options', 'drstk_browse_show_facets' );
add_settings_section('drstk_facet_settings', 'Facets', null, 'drstk_options');
add_settings_field('drstk_facets', 'Facets to Display<br/><small>Select which facets you would like to display on the search and browse pages. Once selected, you may enter custom names for these facets. Drag and drop the order of the facets to change the order of display.</small>', 'drstk_facets_callback', 'drstk_options', 'drstk_facet_settings');
register_setting( 'drstk_options', 'drstk_facets' );
$facet_options = drstk_facets_get_option('drstk', true);
foreach($facet_options as $option){
add_settings_field('drstk_'.$option.'_title', null, 'drstk_facet_title_callback', 'drstk_options', 'drstk_facet_settings', array('class'=>'hidden'));
register_setting( 'drstk_options', 'drstk_'.$option.'_title');
}
add_settings_field('drstk_facet_sort_order', 'Default Facet Sort', 'drstk_facet_sort_callback', 'drstk_options', 'drstk_facet_settings');
register_setting('drstk_options', 'drstk_facet_sort_order');
add_settings_section('drstk_collections_settings', 'Collections Browse Page', null, 'drstk_options');
add_settings_field('drstk_collections_page_title', 'Collections Browse Title', 'drstk_collections_page_title_callback', 'drstk_options', 'drstk_collections_settings');
register_setting( 'drstk_options', 'drstk_collections_page_title' );
add_settings_section('drstk_collection_settings', 'Collection Page', null, 'drstk_options');
add_settings_field('drstk_collection_page_title', 'Collection Page Title', 'drstk_collection_page_title_callback', 'drstk_options', 'drstk_collection_settings');
register_setting( 'drstk_options', 'drstk_collection_page_title' );
//Single Item Page
add_settings_section('drstk_single_settings', 'Single Item Page', null, 'drstk_options');
add_settings_field('drstk_item_page_metadata', 'Metadata to Display<br/><small>If none are selected, all metadata will display in the default order. To reorder or limit the fields which display, select the desired fields and drag and drop to reorder. To add custom fields, click the add button and type in the label.</small>', 'drstk_item_page_metadata_callback', 'drstk_options', 'drstk_single_settings');
register_setting( 'drstk_options', 'drstk_item_page_metadata' );
add_settings_field('drstk_appears', 'Display Item Appears In', 'drstk_appears_callback', 'drstk_options', 'drstk_single_settings');
register_setting('drstk_options', 'drstk_appears');
add_settings_field('drstk_appears_title', 'Item Appears In Block Title', 'drstk_appears_title_callback', 'drstk_options', 'drstk_single_settings', array('class'=>'appears'));
register_setting('drstk_options', 'drstk_appears_title');
add_settings_field('drstk_assoc', 'Display Associated Files', 'drstk_assoc_callback', 'drstk_options', 'drstk_single_settings');
register_setting( 'drstk_options', 'drstk_assoc' );
add_settings_field('drstk_assoc_title', 'Associated Files Block Title', 'drstk_assoc_title_callback', 'drstk_options', 'drstk_single_settings', array('class'=>'assoc'));
register_setting( 'drstk_options', 'drstk_assoc_title' );
add_settings_field('drstk_assoc_file_metadata', 'Metadata to Display', 'drstk_assoc_file_metadata_callback', 'drstk_options', 'drstk_single_settings', array('class'=>'assoc'));
register_setting( 'drstk_options', 'drstk_assoc_file_metadata' );
add_settings_field('drstk_annotations', 'Display Annotations', 'drstk_annotations_callback', 'drstk_options', 'drstk_single_settings');
register_setting( 'drstk_options', 'drstk_annotations' );
add_settings_field('drstk_item_extensions', 'Enable Item Page Custom Text', 'drstk_item_extensions_callback', 'drstk_options', 'drstk_single_settings');
register_setting( 'drstk_options', 'drstk_item_extensions' );
//Advanced Options
add_settings_section('drstk_advanced', "Advanced", null, 'drstk_options');
add_settings_field('drstk_is_podcast',
'Is this a podcast site?',
'drstk_is_podcast_callback',
'drstk_options',
'drstk_advanced');
register_setting('drstk_options', 'drstk_is_podcast');
add_settings_field('drstk_podcast_poster',
'Show an image for each podcast episode?',
'drstk_podcast_poster_callback',
'drstk_options',
'drstk_advanced');
register_setting('drstk_options', 'drstk_podcast_poster');
add_settings_field('drstk_podcast_page',
'Select page to contain your podcast list',
'drstk_podcast_page_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_podcast_page');
add_settings_field('drstk_podcast_author',
'Name to use as the podcast author (usually the instructor of record)',
'drstk_podcast_author_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_podcast_author');
add_settings_field('drstk_podcast_image_url',
'Image for podcast feed',
'drstk_podcast_image_url_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_podcast_image_url');
add_settings_field('drstk_itunes_link',
'Link to iTunes',
'drstk_itunes_link_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options')
);
register_setting('drstk_options', 'drstk_itunes_link');
add_settings_field('drstk_googleplay_link',
'Link to Google Play',
'drstk_googleplay_link_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_googleplay_link');
add_settings_field('drstk_spotify_link',
'Link to Spotify',
'drstk_spotify_link_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_spotify_link');
add_settings_field('drstk_stitcher_link',
'Link to Stitcher',
'drstk_stitcher_link_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_stitcher_link');
add_settings_field('drstk_overcast_link',
'Link to Overcast',
'drstk_overcast_link_callback',
'drstk_options',
'drstk_advanced',
array('class' => 'drstk_podcast_options'));
register_setting('drstk_options', 'drstk_overcast_link');
add_settings_field('drstk_niec',
'Does your project include NIEC metadata?',
'drstk_niec_callback',
'drstk_options',
'drstk_advanced');
register_setting('drstk_options', 'drstk_niec');
add_settings_field('drstk_niec_metadata',
'NIEC Facets and Metadata to Display',
'drstk_niec_metadata_callback',
'drstk_options',
'drstk_advanced',
array('class'=>'niec'));
register_setting( 'drstk_options', 'drstk_niec_metadata' );
$niec_facet_options = drstk_facets_get_option('niec', true);
foreach($niec_facet_options as $option){
add_settings_field('drstk_niec_'.$option.'_title',
null,
'drstk_niec_metadata_title_callback',
'drstk_options',
'drstk_advanced',
array('class'=>'hidden'));
register_setting( 'drstk_options', 'drstk_niec_'.$option.'_title');
}
//Leaflet
add_settings_field('leaflet_api_key',
'Leaflet API Key',
'leaflet_api_key_callback',
'drstk_options',
'drstk_advanced');
register_setting( 'drstk_options', 'leaflet_api_key' );
add_settings_field('leaflet_project_key',
'Leaflet Project Key',
'leaflet_project_key_callback',
'drstk_options',
'drstk_advanced');
register_setting( 'drstk_options', 'leaflet_project_key' );
add_settings_field('drstk_assoc',
'Allow Mirador Page Viewer<br/><small>This requires a manifest file and modifications to a javascript file. Please contact the Toolkit team if you would like to enable this feature.</small>',
'drstk_mirador_callback', 'drstk_options',
'drstk_advanced');
register_setting( 'drstk_options', 'drstk_mirador' );
add_settings_field('drstk_mirador_page_title',
'Mirador Page Title',
'drstk_mirador_page_title_callback',
'drstk_options',
'drstk_advanced',
array('class'=>'mirador'));
register_setting( 'drstk_options', 'drstk_mirador_page_title' );
add_settings_field('drstk_mirador_url',
'Mirador URL',
'drstk_mirador_url_callback',
'drstk_options',
'drstk_advanced',
array('class'=>'mirador'));
register_setting('drstk_options', 'drstk_mirador_url');
//Google Maps key
//DPLA key
}
add_action( 'admin_init', 'register_drs_settings' );
add_action( 'admin_init', 'add_tinymce_plugin');
/*API URL Builder helper method*/
function drstk_api_url($source, $pid, $action, $sub_action = NULL, $url_arguments = NULL){
$url = "";
$dak = constant("DPLA_API_KEY");
$dau = constant("DRS_API_USER");
$dap = constant("DRS_API_PASSWORD");
if($source == "drs"){
$url .= "https://repository.library.northeastern.edu/api/v1";
} else if ($source == "dpla"){
$url .= "https://api.dp.la/v2";
}
//when searching dpla on admin side, there's no pid, and the API barfs with a 404 if there's /? instead of just ?
if ($source == 'dpla') {
if (empty($pid)) {
$url .= '/' . $action;
} else {
// grabbing a dpla item by ?q=pid no longer works, so build the url direct to the item's data
$url .= '/' . $action . '/';
}
} else {
//assuming the only else is DRS
$url .= "/" . $action . "/";
}
//DRS subaction of content_objects has special needs for building the URL
//PMJ assuming this only gets invoked when the action is 'files'
switch ($sub_action) {
case 'content_objects':
$url .= "$pid/$sub_action";
break;
case null:
//do nothing since there's no subaction
$url .= $pid . "?";
break;
default:
//most common url construction
$url .= $sub_action . "/";
$url .= $pid . "?";
break;
}
// @TODO it might be nice to guarantee somehow that before we get here we know the DPLA key is in place
// since if it isn't this won't return anything anyway
if($source == "dpla" && !empty($dak)){
$url .= "api_key=" . DPLA_API_KEY . "&";
}
if($source == "drs" && !(empty($dau) || empty($dap))){
$token = drstk_drs_auth();
if ($token != false && is_string($token))
$url .= "token=" . $token . "&";
}
//direct DPLA item pid barfs on extraneous params
switch ($source) {
case 'dpla':
if (empty($pid) && $url_arguments != null) {
$url .= $url_arguments;
}
break;
case 'drs':
if($url_arguments != NULL){
$url .= $url_arguments;
}
break;
}
return $url;
}
/*DRS API Auth Enabled helper method */
function drstk_api_auth_enabled(){
$dau = constant("DRS_API_USER");
$dap = constant("DRS_API_PASSWORD");
// search config.php for username and password
// if they're both not blank, use them and ask DRS API for a JWT token
if (empty($dau) || empty($dap))
{
return false;
}
else
{
return true;
}
}
/*DRS API Authenticate helper method*/
function drstk_drs_auth(){
if(drstk_api_auth_enabled() == true){
// Token is only good for one hour
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://repository.library.northeastern.edu/api/v1/auth_user");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "email=" . DRS_API_USER . "&password=" . DRS_API_PASSWORD);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
// result should be json
$data = json_decode($result, true);
$token = $data["auth_token"];
if (!empty($token)) {
return $token;
} else {
return false;
}
}
else {
// No user and/or password set
return false;
}
}
function add_tinymce_plugin(){
add_filter("mce_external_plugins", 'mce_plugin');
}
function mce_plugin($plugin_array){
$plugin_array['drstkshortcodes'] = DRS_PLUGIN_URL.'/assets/js/mce-button.js';
return $plugin_array;
}
/*helper functions for getting default values and cleaning up stored options*/
function drstk_get_pid(){
$collection_pid = get_option('drstk_collection');
$collection_pid = explode("/", $collection_pid);
$collection_pid = end($collection_pid);
return $collection_pid;
}
function drstk_get_assoc_meta_options(){
$meta_options = get_option('drstk_assoc_file_metadata');
if ($meta_options == NULL){
$meta_options = array("full_title_ssi","creator_tesim","abstract_tesim");
}
return $meta_options;
}
function drstk_get_facets_to_display(){
$facet_options = get_option('drstk_facets');
if ($facet_options == NULL){
if (get_option('drstk_niec_metadata') == NULL) {
// this is a little weird, but it helps make the list of default facets more consistent -- PMJ
// @TODO what happens here could probably be folded in to drstk_facets_get_option() eventually
$facet_options = drstk_facets_get_option('drstk', true);
} else {
$facet_options = array();
}
}
return $facet_options;
}
function drstk_get_facet_name($facet, $niec=false){
if ($niec){
$name = get_option('drstk_niec_'.$facet.'_title');
} else {
$name = get_option('drstk_'.$facet.'_title');
}
if ($name == NULL){
$name = titleize($facet);
}
return $name;
}
function drstk_get_errors(){
$errors = array(
"admin" => array(
"api_fail" => "Sorry, DRS files and metadata are currently unavailable. Please refresh the page or try again later. If problem persists please contact [email protected].",
),
"search" => array(
"no_results" => "Your query produced no results. Please refine your search and try again.",
"fail_null" => "Sorry, these project materials are currently unavailable. Please try again later.",
"no_sub_collections" => "This project has no sub-collections.",
"missing_collection" => "No collections are available at this time. Please contact the site administrator.",
),
"item" => array(
"no_results" => "This file is currently unavailable. Please check the URL and try again.",
"fail" => "Sorry, project materials are currently unavailable. Please refresh the page or try again later. If problem persists please contact the site administrator.",
"jwplayer_fail" => "There was an issue playing this file. Please contact the site administrator.",
),
"shortcodes" => array(
"fail" => "Sorry, project materials are currently unavailable. Please refresh the page or try again later. If problem persists please contact the site administrator.",
),
);
return $errors;
}
function drstk_get_map_api_key(){
$api_key = get_option('leaflet_api_key');
return $api_key;
}
function drstk_get_map_project_key(){
$project_key = get_option('leaflet_project_key');
return $project_key;
}
/*callback functions for display fields on settings page*/
function drstk_collection_callback() {
$collection_pid = (get_option('drstk_collection') != '') ? get_option('drstk_collection') : 'https://repository.library.northeastern.edu/collections/neu:1';
echo '<input name="drstk_collection" type="text" value="'.$collection_pid.'" style="width:100%;"></input><br/>
<small>Ie. <a href="https://repository.library.northeastern.edu/collections/neu:6012">https://repository.library.northeastern.edu/collections/neu:6012</a></small>';
if (WP_DEBUG) {
$commonPidsHtml = "
<p>Reference PIDs for dev and testing:</p>
<ul>
<li>ETD: https://repository.library.northeastern.edu/sets/neu:cj82r3884</li>
<li>What's New: https://repository.library.northeastern.edu/collections/neu:cj82q862v</li>
<li>Class podcasts: https://repository.library.northeastern.edu/collections/neu:f1881z41n</li>
<li>LGBTAQ+ : https://repository.library.northeastern.edu/sets/neu:f1882114b</li>
</ul>
";
echo $commonPidsHtml;
}
}
function drstk_home_url_callback() {
$url_base = get_option('drstk_home_url');
echo '<input name="drstk_home_url" type="text" value="'.$url_base.'"></input><br/>
<small>This sets the URL permalink base for /browse/, /search/, /item/, and /collection/<br/>
Currently, yours will look like: <strong>'.drstk_home_url().'browse/</strong></small>';
}
/**
* Basic validation and standardization of the $url_base entry;
* should return a safe string that ends with a forward slash
* (and does not begin with one).
*/
function drstk_home_url_validation($input){
$url_base = '';
$parts = explode("/", $input);
foreach ($parts as $part) {
if ($part != '') {
$safe_part = sanitize_title($part);
if ($safe_part) {
$url_base .= sanitize_title($part);
$url_base .= '/';
}
}
}
return $url_base;
}
function drstk_is_podcast_callback() {
$is_podcast = get_option('drstk_is_podcast');
if (get_option('drstk_is_podcast')) {
$checked_attribute = "checked='checked'";
} else {
$checked_attribute = '';
}
echo "<input name='drstk_is_podcast' type='checkbox' $checked_attribute></input>";
}
function drstk_podcast_poster_callback() {
$is_podcast = get_option('drstk_podcast_poster');
if (get_option('drstk_podcast_poster')) {
$checked_attribute = "checked='checked'";
} else {
$checked_attribute = '';
}
echo "<input name='drstk_podcast_poster' type='checkbox' $checked_attribute></input>";
}
function drstk_podcast_page_callback() {
$selected = get_option('drstk_podcast_page');
wp_dropdown_pages( array(
'selected' => $selected,
'name' => 'drstk_podcast_page',
'id' => 'drstk_podcast_page',
'class' => 'drstk_podcast_options'
)
);
echo "<p><a href='" . get_page_link($selected, false) . "'>" . get_the_title($selected) . "</a></p>";
}
function leaflet_api_key_callback(){
$leaflet_api_key = (get_option('leaflet_api_key') != '') ? get_option('leaflet_api_key') : '';
echo '<input name="leaflet_api_key" type="text" value="'.$leaflet_api_key.'" style="width:100%;"></input><br/>
<small>Ie. pk.eyJ1IjoiZGhhcmFtbWFuaWFyIiwiYSI6ImNpbTN0cjJmMTAwYmtpY2tyNjlvZDUzdXMifQ.8sUclClJc2zSBNW0ckJLOg</small>';
}
function leaflet_project_key_callback(){
$leaflet_project_key = (get_option('leaflet_project_key') != '') ? get_option('leaflet_project_key') : '';
echo '<input name="leaflet_project_key" type="text" value="'.$leaflet_project_key.'" style="width:100%;"></input><br/>
<small>Ie. dharammaniar.pfnog3b9</small>';
}
function drstk_search_page_title_callback(){
echo '<input type="text" name="drstk_search_page_title" value="';
if (get_option('drstk_search_page_title') == ''){ echo 'Search';} else { echo get_option('drstk_search_page_title'); }
echo '" />';
}
function drstk_search_placeholder_callback(){
echo '<input type="text" name="drstk_search_placeholder" value="';
if (get_option('drstk_search_placeholder') == ''){ echo 'Search ...';} else { echo get_option('drstk_search_placeholder'); }
echo '" />';
}
function drstk_search_metadata_callback(){
$search_meta_options = array('Title','Creator','Abstract/Description','Date Created');
$options = get_option('drstk_search_metadata');
foreach($search_meta_options as $option){
echo '<label><input type="checkbox" name="drstk_search_metadata[]" value="'.$option.'"';
if (is_array($options) && in_array($option, $options)){ echo 'checked="checked"';}
echo '/> '.$option.'</label><br/>';
}
}
function drstk_search_related_content_title_callback(){
echo '<input type="text" name="drstk_search_related_content_title" value="';
if (get_option('drstk_search_related_content_title') == ''){ echo 'Related Content';} else { echo get_option('drstk_search_related_content_title'); }
echo '" />';
}
function drstk_browse_page_title_callback(){
echo '<input type="text" name="drstk_browse_page_title" value="';
if (get_option('drstk_browse_page_title') == ''){ echo 'Browse';} else { echo get_option('drstk_browse_page_title'); }
echo '" />';
}
function drstk_browse_metadata_callback(){
$browse_meta_options = array('Title','Creator','Abstract/Description','Date Created');
$options = get_option('drstk_browse_metadata');
foreach($browse_meta_options as $option){
echo '<label><input type="checkbox" name="drstk_browse_metadata[]" value="'.$option.'"';
if (is_array($options) && in_array($option, $options)){ echo 'checked="checked"';}
echo '/> '.$option.'</label><br/>';
}
}
function drstk_default_sort_callback(){
$sort_options = array("title_ssi%20asc"=>"Title A-Z","title_ssi%20desc"=>"Title Z-A", "score+desc%2C+system_create_dtsi+desc"=>"Relevance", "creator_ssi%20asc"=>"Creator A-Z","creator_ssi%20desc"=>"Creator Z-A","system_modified_dtsi%20asc"=>"Date (earliest to latest)","system_modified_dtsi%20desc"=>"Date (latest to earliest)");
$default_sort = get_option('drstk_default_sort');
echo '<select name="drstk_default_sort">';
foreach($sort_options as $val=>$option){
echo '<option value="'.$val.'"';
if ($default_sort == $val){ echo 'selected="true"';}
echo '/> '.$option.'</option>';
}
echo '</select><br/>';
}
function drstk_default_browse_per_page_callback(){
$per_page_options = array("10"=>"10","20"=>"20", "50"=>"50");
$default_per_page = get_option('drstk_default_browse_per_page');
echo '<select name="drstk_default_browse_per_page">';
foreach($per_page_options as $val=>$option){
echo '<option value="'.$val.'"';
if ($default_per_page == $val){ echo 'selected="true"';}
echo '/> '.$option.'</option>';
}
echo '</select><br/>';
}
function drstk_browse_show_facets_callback(){
echo '<input type="checkbox" name="drstk_browse_show_facets" ';
if (get_option('drstk_browse_show_facets') == 'on'){ echo 'checked="checked"';}
echo '/>Yes</label>';
}
function drstk_default_search_per_page_callback(){
$per_page_options = array("10"=>"10","20"=>"20", "50"=>"50");
$default_per_page = get_option('drstk_default_search_per_page');
echo '<select name="drstk_default_search_per_page">';
foreach($per_page_options as $val=>$option){
echo '<option value="'.$val.'"';
if ($default_per_page == $val){ echo 'selected="true"';}
echo '/> '.$option.'</option>';
}
echo '</select><br/>';
}
function drstk_search_show_facets_callback(){
echo '<input type="checkbox" name="drstk_search_show_facets" ';
if (get_option('drstk_search_show_facets') == 'on'){ echo 'checked="checked"';}
echo '/>Yes</label>';
}
function drstk_facets_callback(){
$facet_options = drstk_facets_get_option('drstk', true);
$facets_to_display = drstk_get_facets_to_display();
echo "<table class='drstk_facets'><tbody id='facets_sortable'>";
foreach($facets_to_display as $option){
echo '<tr><td style="padding:0;"><input type="checkbox" name="drstk_facets[]" value="'.$option.'" checked="checked"/> <label> <span class="dashicons dashicons-sort"></span> '.titleize($option).'</label></td>';
echo '<td style="padding:0;" class="title"><input type="text" name="drstk_'.$option.'_title" value="'.get_option('drstk_'.$option.'_title').'"></td></tr>';
}
foreach($facet_options as $option){
if (!in_array($option, $facets_to_display)){
echo '<tr><td style="padding:0;"><input type="checkbox" name="drstk_facets[]" value="'.$option.'"/> <label> <span class="dashicons dashicons-sort"></span> '.titleize($option).'</label></td>';
echo '<td style="padding:0;display:none" class="title"><input type="text" name="drstk_'.$option.'_title" value="'.get_option('drstk_'.$option.'_title').'"></td></tr>';
}
}
echo "</tbody></table>";
}
function drstk_facet_title_callback(){
echo '';
}
function drstk_facet_sort_callback(){
$sort_options = array("fc_desc"=>"Facet Count (Highest to Lowest)","fc_asc"=>"Facet Count (Lowest to Highest)","abc_asc"=>"Facet Title (A-Z)","abc_desc"=>"Facet Title (Z-A)");
$default_sort = get_option('drstk_facet_sort_order');
echo '<select name="drstk_facet_sort_order">';
foreach($sort_options as $val=>$option){
echo '<option value="'.$val.'"';
if ($default_sort == $val){ echo 'selected="true"';}
echo '/> '.$option.'</option>';
}
echo '</select><br/>';
}
function drstk_niec_callback(){
echo '<input type="checkbox" name="drstk_niec" ';
if (get_option('drstk_niec') == 'on'){ echo 'checked="checked"';}
echo '/>Yes</label>';
}
function drstk_niec_metadata_callback(){
$niec_facet_options = drstk_facets_get_option('niec', true);;
$niec_facets_to_display = get_option('drstk_niec_metadata');
echo "<table class='drstk_facets drstk_niec_facets'><tbody id='niec_facets_sortable'>";
if (is_array($niec_facets_to_display)){
foreach($niec_facets_to_display as $option){
echo '<tr><td style="padding:0;"><input type="checkbox" name="drstk_niec_metadata[]" value="'.$option.'" checked="checked"/> <label> <span class="dashicons dashicons-sort"></span> '.titleize($option).'</label></td>';
echo '<td style="padding:0;" class="title"><input type="text" name="drstk_niec_'.$option.'_title" value="'.get_option('drstk_niec_'.$option.'_title').'"></td></tr>';
}
}
foreach($niec_facet_options as $option){
if (!is_array($niec_facets_to_display) || (is_array($niec_facets_to_display) && !in_array($option, $niec_facets_to_display))){
echo '<tr><td style="padding:0;"><input type="checkbox" name="drstk_niec_metadata[]" value="'.$option.'"/> <label> <span class="dashicons dashicons-sort"></span> '.titleize($option).'</label></td>';
echo '<td style="padding:0;display:none" class="title"><input type="text" name="drstk_niec_'.$option.'_title" value="'.get_option('drstk_niec_'.$option.'_title').'"></td></tr>';
}
}
echo "</tbody></table>";
}
function drstk_niec_metadata_title_callback(){
echo '';
}
function drstk_collections_page_title_callback(){
echo '<input type="text" name="drstk_collections_page_title" value="';
if (get_option('drstk_collections_page_title') == ''){ echo 'Browse Collections';} else { echo get_option('drstk_collections_page_title'); }
echo '" />';
}
function drstk_collection_page_title_callback(){
echo '<input type="text" name="drstk_collection_page_title" value="';
if (get_option('drstk_collection_page_title') == ''){ echo 'Collection';} else { echo get_option('drstk_collection_page_title'); }
echo '" />';
}
function drstk_mirador_callback(){
echo '<input type="checkbox" name="drstk_mirador" ';
if (get_option('drstk_mirador') == 'on'){ echo 'checked="checked"';}
echo '/>Display</label>';
}
function drstk_mirador_page_title_callback(){
echo '<input type="text" name="drstk_mirador_page_title" value="';
if (get_option('drstk_mirador_page_title') == ''){ echo 'Book View';} else { echo get_option('drstk_mirador_page_title'); }
echo '" />';
}
function drstk_mirador_url_callback() {
$mirador_url = get_option('drstk_mirador_url') == '' ? 'mirador' : get_option('drstk_mirador_url');
echo '<input name="drstk_mirador_url" type="text" value="'.$mirador_url.'"></input><br/>
<small>This sets the URL path for the mirador viewer<br/>
Currently, yours will look like: <strong>'.drstk_home_url().'mirador/</strong></small>';
}
function drstk_item_page_metadata_callback(){
global $all_meta_options;
$item_options = get_option('drstk_item_page_metadata') != "" ? get_option('drstk_item_page_metadata') : array();
echo '<table class="drstk_item_metadata"><tbody id="item_metadata_sortable">';
foreach($item_options as $option){
echo'<tr><td style="padding:0"><label><input type="checkbox" name="drstk_item_page_metadata[]" value="'.$option.'" ';
if (is_array($item_options) && in_array($option, $item_options)){echo'checked="checked"';}
echo'/> <span class="dashicons dashicons-sort"></span> '.$option.' </label></td></tr>';
}
foreach($all_meta_options as $option){
if (!in_array($option, $item_options)){
echo'<tr><td style="padding:0"><label><input type="checkbox" name="drstk_item_page_metadata[]" value="'.$option.'" ';
if (is_array($item_options) && in_array($option, $item_options)){echo'checked="checked"';}
echo'/> <span class="dashicons dashicons-sort"></span> '.$option.' </label></td></tr>';
}
}
echo '</tbody></table>';
echo '<a href="" class="add-item-meta button"><span class="dashicons dashicons-plus"></span>Add Metadata Field</a>';
}
function drstk_appears_callback(){
echo '<input type="checkbox" name="drstk_appears" ';
if (get_option('drstk_appears') == 'on'){ echo 'checked="checked"';}
echo '/>Display</label>';
}
function drstk_appears_title_callback(){
echo '<input type="text" name="drstk_appears_title" value="';
if (get_option('drstk_appears_title') == ''){ echo 'Item Appears In';} else { echo get_option('drstk_appears_title'); }
echo '" />';
}
function drstk_assoc_callback(){
echo '<input type="checkbox" name="drstk_assoc" ';
if (get_option('drstk_assoc') == 'on'){ echo 'checked="checked"';}
echo '/>Display</label>';
}
function drstk_assoc_title_callback(){
echo '<input type="text" name="drstk_assoc_title" value="';
if (get_option('drstk_assoc_title') == ''){ echo 'Associated Files';} else { echo get_option('drstk_assoc_title'); }
echo '" />';
}
function drstk_assoc_file_metadata_callback(){
global $all_assoc_meta_options;
$assoc_options = drstk_get_assoc_meta_options();
foreach($all_assoc_meta_options as $option){
echo'<label><input type="checkbox" name="drstk_assoc_file_metadata[]" value="'.$option.'" ';
if (is_array($assoc_options) && in_array($option, $assoc_options)){echo'checked="checked"';}
echo'/> '.titleize($option).'</label><br/>';
}
}
function drstk_annotations_callback(){
echo '<input type="checkbox" name="drstk_annotations" ';
if (get_option('drstk_annotations') == 'on'){ echo 'checked="checked"';}
echo '/>Display</label>';
}
function drstk_item_extensions_callback(){
echo '<input type="checkbox" name="drstk_item_extensions" ';
if (get_option('drstk_item_extensions') == 'on'){ echo 'checked="checked"';}
echo '/>Enable</label>';
}
function drstk_podcast_author_callback() {
$author = get_option('drstk_podcast_author');
echo "<input name='drstk_podcast_author' type='text'
class = 'drstk_podcast_options'
value='$author' class='drstk_podcast_author_setting'>
</input><br/>";
}
function drstk_itunes_link_callback() {
$link = get_option('drstk_itunes_link');
echo "<input name='drstk_itunes_link' type='text'
class = 'drstk_podcast_options'
value='$link' class='drstk_podcast_link_setting'>
</input><br/>";
echo DRSTK_PODCAST_REGISTER_HTML;
}
function drstk_spotify_link_callback() {
$link = get_option('drstk_spotify_link');
echo "<input name='drstk_spotify_link' type='text'
class = 'drstk_podcast_options'
value='$link' class='drstk_podcast_link_setting'>
</input><br/>";
echo DRSTK_PODCAST_REGISTER_HTML;
}
function drstk_googleplay_link_callback() {
$link = get_option('drstk_googleplay_link');
echo "<input name='drstk_googleplay_link' type='text'
class = 'drstk_podcast_options'
value='$link' class='drstk_podcast_link_setting'>
</input><br/>";
echo DRSTK_PODCAST_REGISTER_HTML;
}
function drstk_overcast_link_callback() {
$link = get_option('drstk_overcast_link');
echo "<input name='drstk_overcast_link' type='text'
class = 'drstk_podcast_options'
value='$link' class='drstk_podcast_link_setting'>
</input><br/>";
echo DRSTK_PODCAST_REGISTER_HTML;
}
function drstk_stitcher_link_callback() {
$link = get_option('drstk_stitcher_link');
echo "<input name='drstk_stitcher_link' type='text'
class = 'drstk_podcast_options'
value='$link' class='drstk_podcast_link_setting'>
</input><br/>";
echo DRSTK_PODCAST_REGISTER_HTML;
}
function drstk_podcast_image_url_callback() {
$url = get_option('drstk_podcast_image_url') ? get_option('drstk_podcast_image_url') : 'https://brand.northeastern.edu/wp-content/uploads/logotype-250x85.png';
echo "<input name='drstk_podcast_image_url' type='text'
class = 'drstk_podcast_options drstk_podcast_link_setting'
value='$url'>
</input><br/>
<small>URL to an image to use in your podcast feed (usually something you upload to Media).</small>
<br/>
<img src='$url' />
";
}
//this creates the form for the drstk settings page
function drstk_display_settings(){
?>
<div class="wrap">
<h1>CERES Settings</h1>
<form method="post" action="options.php" name="options">
<?php
settings_fields("drstk_options");
do_settings_sections("drstk_options");