-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
105 lines (96 loc) · 3.57 KB
/
index.php
File metadata and controls
105 lines (96 loc) · 3.57 KB
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
<?php
/**
* Plugin Name: Collex
* Plugin URI: https://ar-c.org
* Description: A plugin for enabling scholarly engagement with the ARC Catalog
* Author: Bryan Tarpley and Oguzhan Benli
* Author URI: https://codhr.tamu.edu
* Version: 1.0.0
* License: GPL2+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
*
* @package CGB
*/
// Exit if accessed directly.
if (! defined( 'ABSPATH' ) )
{
exit;
}
wp_enqueue_style('dashicons');
add_action('wp_enqueue_scripts','arc_corpora_enqueue_scripts');
function arc_corpora_enqueue_scripts()
{
// Register Javascript
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('collex-popper', plugin_dir_url(__FILE__).'js/popper.min.js');
wp_enqueue_script('collex-tippy', plugin_dir_url(__FILE__).'js/tippy-bundle.umd.min.js', array('collex-popper'));
wp_enqueue_script('collex-autocomplete', plugin_dir_url(__FILE__).'js/autoComplete.min.js');
wp_enqueue_script(
'collex-script',
plugin_dir_url( __FILE__ ).'js/collex.js',
array(
'jquery',
'jquery-ui-core',
'jquery-ui-slider',
'jquery-ui-dialog',
'collex-popper',
'collex-tippy',
'collex-autocomplete'
)
); //your javascript library
// Register CSS
wp_enqueue_style('jquery-ui-css', plugin_dir_url( __FILE__ ).'css/jquery-ui.min.css');
wp_enqueue_style('collex-autocomplete-css', plugin_dir_url( __FILE__ ).'css/autoComplete.min.css');
wp_enqueue_style('collex-css', plugin_dir_url( __FILE__ ).'css/collex.css');
}
function arc_corpora_inject_footer()
{
$corpora_host = getenv('COLLEX_CORPORA_HOST');
$corpus_id = getenv('COLLEX_CORPUS_ID');
$federation_id = getenv('COLLEX_FEDERATION_ID');
$corpora_token = getenv('COLLEX_TOKEN');
$other_federation_ids = getenv('COLLEX_OTHER_FEDERATION_IDS');
$admin_post_url = esc_url( admin_url('admin-post.php') );
$arc_user_auth_token = '';
if (isset($_COOKIE['arc_user_auth_token'])) {
$arc_user_auth_token = $_COOKIE['arc_user_auth_token'];
}
?>
<script>
let arc_user = null;
let collex = null;
jQuery(document).ready(function($)
{
arc_user = new ArcUser('<?=$corpora_host?>', '<?=$corpora_token?>', '<?=$arc_user_auth_token?>', '<?=$admin_post_url?>', '<?=$corpus_id?>', '<?=$federation_id?>');
collex = new ArcFullSearch(arc_user, '<?=$other_federation_ids?>');
});
</script>
<?php
}
add_action('wp_footer', 'arc_corpora_inject_footer');
function arc_corpora_login_user()
{
// LOGIN
if (isset($_POST['arc_user_auth_token'])) {
setcookie(
'arc_user_auth_token',
$_POST['arc_user_auth_token'],
[
'expires' => time()+3600,
'path' => '/',
'samesite' => 'strict',
]
);
wp_send_json(['message' => 'arc user token stored'], 200);
// LOGOUT
} elseif (isset($_POST['arc_user_logout']) && isset($_COOKIE['arc_user_auth_token'])) {
unset($_COOKIE['arc_user_auth_token']);
setcookie('arc_user_auth_token', null, -1, '/');
wp_send_json(['message' => 'arc user logged out'], 200);
}
}
add_action('admin_post_nopriv_arc_user_login', 'arc_corpora_login_user');
add_action('admin_post_arc_user_login', 'arc_corpora_login_user');