-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhumcore-deposits.php
674 lines (580 loc) · 23.5 KB
/
humcore-deposits.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
<?php
/**
* The HumCORE Deposits Plugin
*
* HumCORE Deposits is a WordPress / Buddypress plugin to connect the Commons-In-A-Box (CBOX) social network platform to a Fedora-based institutional repository system.
*
* @package HumCORE
* @subpackage Deposits
*/
/**
* Plugin Name: HumCORE Deposits
* Description: HumCORE Deposits is a WordPress / Buddypress plugin to connect the Commons-In-A-Box (CBOX) social network platform to a Fedora-based institutional repository system.
* Version: 1.0
* Author: MLA
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Wrapper around wp taxonomy functions for multi-sites, from 'humanities-commons'
require_once dirname( __FILE__ ) . '/wpmn-taxonomy-functions.php';
/**
* Register the humcore_deposit custom post type.
*/
function humcore_register_post_type() {
// Define the labels to be used by the post type humcore_deposits.
$labels = array(
// 'name' => _x( 'HumCORE Deposits', 'post type general name', 'humcore_domain' ),
'singular_name' => _x( 'Deposit', 'post type singular name', 'humcore_domain' ),
'menu_name' => _x( 'HumCORE Deposits', 'admin menu', 'humcore_domain' ),
'name_admin_bar' => _x( 'Deposit', 'add new on admin bar', 'humcore_domain' ),
'add_new' => _x( 'Add New', 'add new', 'humcore_domain' ),
'add_new_item' => __( 'Add New Deposits', 'humcore_domain' ),
'new_item' => __( 'New Deposit', 'humcore_domain' ),
'edit_item' => __( 'Edit Deposit', 'humcore_domain' ),
'view_item' => __( 'View Deposit', 'humcore_domain' ),
'all_items' => __( 'All Deposits', 'humcore_domain' ),
'search_items' => __( 'Search Deposits', 'humcore_domain' ),
'not_found' => __( 'No Deposits found', 'humcore_domain' ),
'not_found_in_trash' => __( 'No Deposits found in Trash', 'humcore_domain' ),
'parent_item_colon' => '',
);
$post_type_args = array(
'label' => __( 'HumCORE Deposits', 'humcore_domain' ),
'labels' => $labels,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => false,
'query_var' => false,
'rewrite' => array(
'slug' => 'humcore_deposit',
'with_front' => true,
),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'author', 'excerpt' ),
// 'supports' => array( 'title', 'author', 'excerpt', 'custom-fields', revisions', 'page-attributes' ),
'register_meta_box_cb' => 'humcore_add_post_type_metabox',
);
register_post_type( 'humcore_deposit', $post_type_args );
}
// Hook into the init action and call humcore_register_post_type when init fires.
add_action( 'init', 'humcore_register_post_type' );
/**
* Create two taxonomies, humcore_deposit_subjects and humcore_deposit_tags for the post type "humcore_deposit".
*/
function humcore_register_taxonomies() {
$current_network = get_current_site();
if ( 1 === (int) $current_network->id ) {
$taxonomy_ui_setting = true;
} else {
$taxonomy_ui_setting = false;
}
// Add new taxonomy, make it hierarchical (like categories).
$labels = array(
'name' => _x( 'Subjects', 'taxonomy general name', 'humcore_domain' ),
'singular_name' => _x( 'Subject', 'taxonomy singular name', 'humcore_domain' ),
'search_items' => __( 'Search Subjects', 'humcore_domain' ),
'all_items' => __( 'All Subjects', 'humcore_domain' ),
'parent_item' => __( 'Parent Subject', 'humcore_domain' ),
'parent_item_colon' => __( 'Parent Subject:', 'humcore_domain' ),
'edit_item' => __( 'Edit Subject', 'humcore_domain' ),
'update_item' => __( 'Update Subject', 'humcore_domain' ),
'add_new_item' => __( 'Add New Subject', 'humcore_domain' ),
'new_item_name' => __( 'New Subject Name', 'humcore_domain' ),
'menu_name' => __( 'Subjects', 'humcore_domain' ),
);
$args = array(
'public' => false,
'hierarchical' => true,
'labels' => $labels,
'show_ui' => $taxonomy_ui_setting,
'show_admin_column' => false,
'query_var' => false,
'rewrite' => false,
);
register_taxonomy( 'humcore_deposit_subject', array( 'humcore_deposit' ), $args );
register_taxonomy_for_object_type( 'humcore_deposit_subject', 'humcore_deposit' );
// Add new taxonomy, NOT hierarchical (like tags).
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name', 'humcore_domain' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name', 'humcore_domain' ),
'search_items' => __( 'Search Tags', 'humcore_domain' ),
'popular_items' => __( 'Popular Tags', 'humcore_domain' ),
'all_items' => __( 'All Tags', 'humcore_domain' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag', 'humcore_domain' ),
'update_item' => __( 'Update Tag', 'humcore_domain' ),
'add_new_item' => __( 'Add New Tag', 'humcore_domain' ),
'new_item_name' => __( 'New Tag Name', 'humcore_domain' ),
'separate_items_with_commas' => __( 'Separate tags with commas', 'humcore_domain' ),
'add_or_remove_items' => __( 'Add or remove tags', 'humcore_domain' ),
'choose_from_most_used' => __( 'Choose from the most used tags', 'humcore_domain' ),
'not_found' => __( 'No tags found.', 'humcore_domain' ),
'menu_name' => __( 'Tags', 'humcore_domain' ),
);
$args = array(
'public' => false,
'hierarchical' => false,
'labels' => $labels,
'show_ui' => $taxonomy_ui_setting,
'show_admin_column' => false,
'update_count_callback' => '_update_post_term_count',
'query_var' => false,
'rewrite' => false,
);
register_taxonomy( 'humcore_deposit_tag', array( 'humcore_deposit' ), $args );
register_taxonomy_for_object_type( 'humcore_deposit_tag', 'humcore_deposit' );
// Add new taxonomy, NOT hierarchical (like tags).
$labels = array(
'name' => _x( 'Languages', 'taxonomy general name', 'humcore_domain' ),
'singular_name' => _x( 'Language', 'taxonomy singular name', 'humcore_domain' ),
'search_items' => __( 'Search Languages', 'humcore_domain' ),
'popular_items' => __( 'Popular Languages', 'humcore_domain' ),
'all_items' => __( 'All Languages', 'humcore_domain' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Language', 'humcore_domain' ),
'update_item' => __( 'Update Language', 'humcore_domain' ),
'add_new_item' => __( 'Add New Language', 'humcore_domain' ),
'new_item_name' => __( 'New Language Name', 'humcore_domain' ),
'separate_items_with_commas' => __( 'Separate languages with commas', 'humcore_domain' ),
'add_or_remove_items' => __( 'Add or remove languages', 'humcore_domain' ),
'choose_from_most_used' => __( 'Choose from the most used languages', 'humcore_domain' ),
'not_found' => __( 'No languages found.', 'humcore_domain' ),
'menu_name' => __( 'Languages', 'humcore_domain' ),
);
$args = array(
'public' => false,
'hierarchical' => false,
'labels' => $labels,
'show_ui' => $taxonomy_ui_setting,
'show_admin_column' => false,
'update_count_callback' => '_update_post_term_count',
'query_var' => false,
'rewrite' => false,
);
register_taxonomy( 'humcore_deposit_language', array( 'humcore_deposit' ), $args );
register_taxonomy_for_object_type( 'humcore_deposit_language', 'humcore_deposit' );
}
// Hook into the init action and call humcore_create_taxonomies when init fires.
add_action( 'init', 'humcore_register_taxonomies' );
add_action( 'wpmn_register_taxonomies', 'humcore_register_taxonomies' );
/**
* Remove the custom taxonomy meta boxes.
*/
function humcore_remove_meta_boxes() {
remove_meta_box( 'humcore_deposit_subjectdiv', 'humcore_deposit', 'side' );
remove_meta_box( 'tagsdiv-humcore_deposit_tag', 'humcore_deposit', 'side' );
}
// Hook into the admin_menu action and call humcore_remove_meta_boxes when admin_menu fires.
add_action( 'admin_menu', 'humcore_remove_meta_boxes' );
/**
* Register sidebars for the welcome, deposits index and search results pages.
*/
function humcore_register_sidebars() {
register_sidebar(
array(
'name' => 'CORE Welcome Right',
'id' => 'core-welcome-right',
'description' => __( 'The Welcome page widget area', 'humcore_domain' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
register_sidebar(
array(
'name' => 'Deposits Directory Sidebar',
'id' => 'deposits-directory-sidebar',
'description' => __( 'The Deposits directory widget area', 'humcore_domain' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
register_sidebar(
array(
'name' => 'Deposits Search Sidebar',
'id' => 'deposits-search-sidebar',
'description' => __( 'The Deposits faceted search widget area', 'humcore_domain' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
)
);
}
// Hook into the init action and call humcore_register_sidebars when init fires.
add_action( 'init', 'humcore_register_sidebars' );
/**
* Check for cURL upon activation.
*/
function humcore_check_dependencies() {
if ( ! in_array( 'curl', get_loaded_extensions() ) ) {
trigger_error( __( 'cURL is not installed on your server. In order to make this plugin work, you need to install cURL on your server.', 'humcore_domain' ), E_USER_ERROR );
}
}
/**
* This function is hooked in via the cron
*/
function humcore_release_provisional_fire() {
// TODO move the activity creation to an action - https://codex.wordpress.org/Post_Status_Transitions#transition_post_status_Hook
$query_args = array(
'post_parent' => 0,
'post_type' => 'humcore_deposit',
'post_status' => 'draft',
'posts_per_page' => -1,
'order' => 'ASC',
'order_by' => 'ID',
);
// echo "\n";
$deposit_posts = get_posts( $query_args );
foreach ( $deposit_posts as $deposit_post ) {
$now = time();
$metadata = json_decode( get_post_meta( $deposit_post->ID, '_deposit_metadata', true ), true );
$local_link = sprintf( HC_SITE_URL . '/deposits/item/%s/', $metadata['pid'] );
//$local_link = $metadata['handle']; // Let's try doi.
$post_name = str_replace( ':', '', $metadata['pid'] );
$diff = (int) abs( $now - strtotime( $metadata['record_change_date'] ) );
$hours_since = round( $diff / HOUR_IN_SECONDS );
//echo $deposit_post->ID, ", ", $deposit_post->post_name, ", ", $deposit_post->post_status, ", ", $metadata['record_change_date'], ", ", $hours_since, "\n";
if ( $hours_since > 2 ) {
if ( 'no' === $metadata['embargoed'] ) {
$post_args = array(
'ID' => $deposit_post->ID,
'post_status' => 'publish',
'post_name' => $post_name,
);
$update_status = wp_update_post( $post_args, true );
//echo $deposit_post->ID, ", ", var_export( $update_status, true ), ", ", $deposit_post->post_name, ", ", "Published!", "\n";
if ( is_wp_error( $update_status ) ) {
humcore_write_error_log(
'error', '*****HumCORE Error - CRON provisional release error*****' .
$deposit_post->ID . ', ' . $deposit_post->post_name . ' ' . var_export( $update_status, true )
);
} else {
humcore_write_error_log(
'info', '*****HumCORE CRON *****' . $deposit_post->ID . ', ' .
$deposit_post->post_name . ' Published!'
);
$bp = buddypress();
$notification_id = bp_notifications_add_notification(
array(
'user_id' => $deposit_post->post_author,
'item_id' => $deposit_post->ID,
'component_name' => $bp->humcore_deposits->id,
'component_action' => 'deposit_published',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
)
);
//echo "Notification ID ", $notification_id,"\n";
$group_activity_ids = array();
if ( ! empty( $metadata['group_ids'] ) ) {
foreach ( $metadata['group_ids'] as $group_id ) {
//echo "Group ID ", $group_id,"\n";
$group_activity_id = humcore_new_group_deposit_activity(
$metadata['record_identifier'],
$group_id, $metadata['abstract'], $local_link, $metadata['submitter']
);
//echo "Group Activity ID ", $Group_activity_id,"\n";
$group_society_id = bp_groups_get_group_type( $group_id );
if ( humcore_get_current_society_id() !== $group_society_id ) {
bp_activity_update_meta(
$group_activity_id, 'society_id', $group_society_id,
humcore_get_current_society_id()
);
}
$group_activity_ids[] = $group_activity_id;
}
if ( ! empty( $group_activity_ids ) ) {
humcore_write_error_log(
'info', '*****HumCORE CRON GROUP ACTIVITIES*****' . $deposit_post->ID . ', ' .
$deposit_post->post_name . implode( ',', $group_activity_ids )
);
}
//echo "After ", implode( ',', $group_activity_ids ),"\n";
}
}
}
}
}
}
add_action( 'humcore_release_provisional', 'humcore_release_provisional_fire' );
/**
* Register HumCORE cron job(s) upon activation.
*/
function humcore_activate_cron_jobs() {
$the_time = date( 'Y-m-d' ) . ' ' . '04' . ':' . '00';
$the_timestamp = strtotime( $the_time );
/* If the time has already passed today, the next run will be tomorrow */
$the_timestamp = ( $the_timestamp > time() ) ? $the_timestamp : (int) $the_timestamp + 86400;
/* Clear any existing recurring event and set up a new one */
wp_clear_scheduled_hook( 'humcore_release_provisional' );
wp_schedule_event( $the_timestamp, 'daily', 'humcore_release_provisional' );
}
register_activation_hook( __FILE__, 'humcore_activate_cron_jobs' );
/**
* Register post type and flush rewrite rules upon activation.
*/
function humcore_activate() {
humcore_check_dependencies();
humcore_register_post_type();
humcore_add_rewrite_rule();
global $wp_rewrite;
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'humcore_activate' );
/**
* Cleanup cron job(s) upon deactivation.
*/
function humcore_deactivate_cron_jobs() {
/* Clear any existing recurring event */
wp_clear_scheduled_hook( 'humcore_release_provisional' );
}
register_deactivation_hook( __FILE__, 'humcore_deactivate_cron_jobs' );
/**
* Cleanup upon deactivation.
*/
function humcore_deactivate() {
global $wp_rewrite;
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'humcore_deactivate' );
/**
* Add custom rewrite rules.
*/
function humcore_add_rewrite_rule() {
add_rewrite_rule(
'[^/]*/?(deposits/item)/([^/]+)(/(review))?/?$',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_command=$matches[4]',
'top'
);
add_rewrite_rule(
'[^/]*/?(deposits/item)/([^/]+)(/(edit))?/?$',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_command=$matches[4]',
'top'
);
add_rewrite_rule(
'[^/]*/?(deposits/item)/([^/]+)(/(embed))?/?$',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_command=$matches[4]',
'top'
);
/*
add_rewrite_rule(
'(deposits/item)/([^/]+)/?(\?(embed[^\&]+))?\&?',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_command=$matches[4]',
'top'
);
*/
add_rewrite_rule(
'[^/]*/?(deposits/download)/([^/]+)/([^/]+)/([^/]+)/?$',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_datastream=$matches[3]&deposits_filename=$matches[4]',
'top'
);
// Rewrite for deposits/objects handled as ngix proxy pass.
add_rewrite_rule(
'[^/]*/?(deposits/view)/([^/]+)/([^/]+)/([^/]+)/?$',
'index.php?pagename=$matches[1]&deposits_item=$matches[2]&deposits_datastream=$matches[3]&deposits_filename=$matches[4]',
'top'
);
add_rewrite_rule(
'[^/]*/?(deposits/list)/?$',
'index.php?pagename=$matches[1]',
'top'
);
}
// Hook into the init action and call humcore_add_rewrite_rule when init fires.
add_action( 'init', 'humcore_add_rewrite_rule' );
/**
* Add custom rewrite tags.
*/
function humcore_add_rewrite_tag() {
add_rewrite_tag( '%deposits_item%', '([^/]*)' );
add_rewrite_tag( '%deposits_datastream%', '([^/]*)' );
add_rewrite_tag( '%deposits_filename%', '([^/]*)' );
add_rewrite_tag( '%deposits_command%', '([^/]*)' );
add_rewrite_tag( '%facets%', '([^&]*)' );
}
// Hook into the init action and call humcore_add_rewrite_tag when init fires.
add_action( 'init', 'humcore_add_rewrite_tag' );
/**
* Add support for additional mime types.
*/
function humcore_deposit_upload_mimes( $existing_mimes ) {
$existing_mimes['dng'] = 'image/x-adobe-dng';
$existing_mimes['cr2'] = 'image/x-dcraw';
$existing_mimes['crw'] = 'image/x-dcraw';
$existing_mimes['nef'] = 'image/x-dcraw';
return $existing_mimes;
}
// Hook into the mime_types filter and call humcore_deposit_upload_mimes when mime_types fires.
/**
* Disabled for now.
* add_filter( 'mime_types', 'humcore_deposit_upload_mimes' );
* TODO We could support storage of raw images without any additional config. We would need imagick to support conversion.
*/
/**
* Initialize the API classes.
*/
function humcore_deposit_api_classes_init() {
//global $ezid_api, $fedora_api, $solr_client;
global $datacite_api, $fedora_api, $solr_client;
//// Create an ezid client instance.
//require_once dirname( __FILE__ ) . '/class-humcore-deposit-ezid-api.php';
//$ezid_api = new Humcore_Deposit_Ezid_Api;
// Create a datacite client instance.
require_once dirname( __FILE__ ) . '/class-humcore-deposit-datacite-api.php';
$datacite_api = new Humcore_Deposit_DataCite_Api;
// Create a fedora client instance.
require_once dirname( __FILE__ ) . '/class-humcore-deposit-fedora-api.php';
$fedora_api = new Humcore_Deposit_Fedora_Api;
// Create a solr client instance.
require_once dirname( __FILE__ ) . '/class-humcore-deposit-solr-api.php';
$solr_client = new Humcore_Deposit_Solr_Api;
}
// Hook into the plugins_loaded action and call humcore_deposit_api_classes_init when plugins_loaded fires.
add_action( 'plugins_loaded', 'humcore_deposit_api_classes_init' );
/**
* Add custom user meta field.
*/
function humcore_deposit_show_user_fields( $user ) {
?>
<h3><em>CORE</em> Details</h3>
<table class="form-table">
<tbody>
<tr>
<th><label>Accepted Terms</label></th>
<td>
<?php
if ( get_the_author_meta( 'accepted_core_terms', $user->ID ) == 'Yes' ) {
echo 'Yes';
} else {
echo 'No'; }
?>
</td>
</tr>
</tbody>
</table>
<?php
}
// Hook into the show_user_profile, edit_user_profile actions and call humcore_deposit_show_user_fields when they fire.
add_action( 'show_user_profile', 'humcore_deposit_show_user_fields' );
add_action( 'edit_user_profile', 'humcore_deposit_show_user_fields' );
/**
* Load only when BuddyPress is present.
*/
function humcore_deposit_component_include() {
require_once dirname( __FILE__ ) . '/class-humcore-deposit-component.php';
require_once dirname( __FILE__ ) . '/class-pagetemplater.php';
require_once dirname( __FILE__ ) . '/class-humcore-theme-compatibility.php';
}
// Hook into the bp_include action and call humcore_deposit_component_include when bp_include fires.
add_action( 'bp_include', 'humcore_deposit_component_include' );
/**
* Write a formatted HumCORE error or informational message.
*/
function humcore_write_error_log( $error_type, $error_message, $info = null ) {
$info_text = $info ? ': ' . serialize( $info ) : '';
$message = '[' . strtoupper($error_type) . '] ' . $error_message . $info_text . "\n";
error_log( $message );
}
/**
* Writes wp http data to a custom log file if debugging is active.
*/
function humcore_http_api_debug( $response = null, $state = null, $class = null, $args = null, $url = null ) {
if ( stripos( $url, 'WordPress.' ) !== false || stripos( $url, 'akismet.' ) !== false ||
stripos( $url, 'commons.' ) !== false ) {
return;
}
$info = array(
'state' => $state,
'transport_class' => $class,
'args' => $args,
'url' => $url,
'response' => $response,
);
humcore_write_error_log( 'info', 'http api debug', $info );
}
/**
* Conditionally activate the http debug action.
*/
function humcore_http_api_debug_action() {
if ( defined( 'CORE_HTTP_DEBUG' ) && 'true' === CORE_HTTP_DEBUG && defined( 'CORE_ERROR_LOG' ) && '' != CORE_ERROR_LOG ) {
// Hook into the http_api_debug action and call humcore_http_api_debug when http_api_debug fires.
add_action( 'http_api_debug', 'humcore_http_api_debug', 1000, 5 );
}
}
// Hook into the init action and call humcore_http_api_debug_action when init fires.
add_action( 'init', 'humcore_http_api_debug_action' );
/**
* Include the faceted search results widgets.
*/
require( dirname( __FILE__ ) . '/widgets.php' );
// Include the settings page and custom post admin screen.
if ( is_admin() ) {
require( dirname( __FILE__ ) . '/settings.php' );
require( dirname( __FILE__ ) . '/admin-screens.php' );
}
/**
* Include conditional support for Better WordPress Google XML Sitemaps plugin
*/
function humcore_bwp_gxs_add_modules() {
global $bwp_gxs;
$bwp_gxs->add_module( 'sitemap_humcore' );
}
function humcore_bwp_gxs_add_rewrite_rules() {
$humcore_rules = array(
'sitemap_humcore\.xml' => 'index.php?gxs_module=sitemap_humcore',
);
return $humcore_rules;
}
if ( class_exists( 'BWP_Sitemaps' ) ) {
add_filter( 'bwp_gxs_rewrite_rules', 'humcore_bwp_gxs_add_rewrite_rules' );
add_action( 'bwp_gxs_modules_built', 'humcore_bwp_gxs_add_modules' );
}
/**
* Register our asynchronous tika extraction.
*
* @see Humcore_Async_Tika_Action
**/
function humcore_register_async_tika_action() {
if ( false === class_exists( 'WP_Async_Task' ) ) {
require( plugin_dir_path( __FILE__ ) . 'lib/wp-async-task.php' ); }
if ( false === class_exists( 'Humcore_Async_Tika_Action' ) ) {
require( plugin_dir_path( __FILE__ ) . 'class-humcore-async-tika-action.php' );
}
// We need to call the Humcore_Async_Tika_Action constructor to hook in our asynchronous request logic.
$humcore_async_tika_action = new Humcore_Async_Tika_Action();
}
add_action( 'init', 'humcore_register_async_tika_action' );
add_filter( 'https_local_ssl_verify', '__return_false' );
// Keyword REST controllers.
require_once dirname( __FILE__ ) . '/class-humcore-deposits-keyword-rest-controller.php';
require_once dirname( __FILE__ ) . '/class-humcore-deposits-subject-rest-controller.php';
add_action(
'rest_api_init', function () {
$keyword_controller = new Humcore_Deposits_Keyword_REST_Controller;
$keyword_controller->register_routes();
$subject_controller = new Humcore_Deposits_Subject_REST_Controller;
$subject_controller->register_routes();
}
);
/**
* HumCORE: CLI Commands
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once dirname( __FILE__ ) . '/class-datacite-command.php';
// require_once dirname( __FILE__ ) . '/class-ezid-command.php';
require_once dirname( __FILE__ ) . '/class-fedora-command.php';
/* require_once dirname( __FILE__ ) . '/humcore-cli.php'; */
require_once dirname( __FILE__ ) . '/class-solr-command.php';
}