-
Notifications
You must be signed in to change notification settings - Fork 19
/
wp-h5p-xapi.php
112 lines (89 loc) · 2.79 KB
/
wp-h5p-xapi.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
<?php
require_once __DIR__ . "/src/utils/Template.php";
require_once __DIR__ . "/plugin.php";
use h5pxapi\Template;
/*
Plugin Name: H5P xAPI
Plugin URI: http://github.com/tunapanda/wp-h5p-xapi
GitHub Plugin URI: https://github.com/tunapanda/wp-h5p-xapi
Description: Send H5P achievements to an xAPI repo.
Version: 0.1.6
*/
/**
* Enqueue scripts and stylesheets.
*/
function h5pxapi_enqueue_scripts()
{
wp_register_script("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.js", array("jquery"));
wp_enqueue_script("wp-h5p-xapi");
wp_register_style("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.css");
wp_enqueue_style("wp-h5p-xapi");
$xapi_js_settings = array();
$settings = h5pxapi_get_auth_settings();
$xapi_js_settings['ajax_url'] = admin_url('admin-ajax.php');
// Permalink is not available in the admin interface.
if (get_permalink()) {
$xapi_js_settings['context_activity'] = array(
'id' => get_permalink(),
'definition' => array(
'type' => 'http://activitystrea.ms/schema/1.0/page',
'name' => array(
'en' => wp_title("|", false),
),
'moreInfo' => get_permalink(),
),
);
}
wp_localize_script('wp-h5p-xapi', 'xapi_settings', $xapi_js_settings);
}
/**
* Create the admin menu.
*/
function h5pxapi_admin_menu()
{
$settings = apply_filters("h5p-xapi-auth-settings", null);
if (!$settings) {
add_options_page(
'H5P xAPI',
'H5P xAPI',
'manage_options',
'h5pxapi_settings',
'h5pxapi_create_settings_page'
);
}
}
/**
* Admin init.
*/
function h5pxapi_admin_init() {
register_setting("h5pxapi","h5pxapi_endpoint_url");
register_setting("h5pxapi","h5pxapi_username");
register_setting("h5pxapi","h5pxapi_password");
register_setting("h5pxapi", "h5pxapi_alerts");
}
/**
* Create settings page.
*/
function h5pxapi_create_settings_page()
{
wp_register_style("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.css");
wp_enqueue_style("wp-h5p-xapi");
$template = new Template(__DIR__ . "/src/template/settings.tpl.php");
$template->show();
}
function h5pxapi_event_handler()
{
require_once __DIR__.'/process-xapi-statement.php';
wp_die();
}
add_action('wp_enqueue_scripts', 'h5pxapi_enqueue_scripts');
add_action('admin_enqueue_scripts', 'h5pxapi_enqueue_scripts');
add_action('admin_menu', 'h5pxapi_admin_menu');
add_action('admin_init', 'h5pxapi_admin_init');
add_action('wp_ajax_xapi_event', 'h5pxapi_event_handler');
add_action('wp_ajax_nopriv_xapi_event', 'h5pxapi_event_handler');
function h5pxapi_response_message($message)
{
global $h5pxapi_response_message;
$h5pxapi_response_message = $message;
}