-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-deliverable.php
151 lines (126 loc) · 3.77 KB
/
wp-deliverable.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
<?php
require_once __DIR__."/src/controller/DeliverableController.php";
require_once __DIR__."/src/controller/ReviewPageController.php";
require_once __DIR__."/src/controller/DeliverableShortcodeController.php";
require_once __DIR__."/src/model/Deliverable.php";
require_once __DIR__."/src/model/DeliverableSubmission.php";
require_once __DIR__."/src/utils/Xapi.php";
require_once __DIR__."/src/utils/Template.php";
require_once __DIR__."/src/plugin/DeliverableSyncer.php";
use wpdeliverable\Deliverable;
use wpdeliverable\DeliverableSubmission;
use wpdeliverable\DeliverableController;
use wpdeliverable\DeliverableShortcodeController;
use wpdeliverable\ReviewPageController;
use wpdeliverable\Xapi;
use wpdeliverable\Template;
use wpdeliverable\DeliverableSyncer;
/*
Plugin Name: Deliverable
Plugin URI: http://github.com/tunapanda/wp-deliverable
GitHub Plugin URI: http://github.com/tunapanda/wp-deliverable
Description: Lets learners submit deliverables and have coaches review them.
Version: 0.0.4
*/
/**
* Create review page.
*/
function deliverable_create_review_page() {
$reviewPageController=new ReviewPageController();
$reviewPageController->process();
}
/**
* Create xapi settings page.
*/
function deliverable_create_xapi_settings_page() {
$t=new Template(__DIR__."/src/template/xapisettings.php");
$t->show();
}
/**
* Listener for the admin_menu action.
*/
function deliverable_admin_menu() {
add_menu_page(
"Deliverables",
"Deliverables",
"manage_options",
"deliverables"
);
DeliverableController::admin_menu();
add_submenu_page(
'deliverables',
'Review Submissions',
'Review Submissions',
'manage_options',
'manage_deliverables',
'deliverable_create_review_page'
);
$settings=apply_filters("deliverable-xapi-auth-settings",NULL);
if (!$settings) {
add_submenu_page(
'deliverables',
'xAPI Settings',
'xAPI Settings',
'manage_options',
'deliverable_xapi_settings',
'deliverable_create_xapi_settings_page'
);
}
}
add_action('admin_menu','deliverable_admin_menu');
/**
* Admin init.
*/
function deliverable_admin_init() {
register_setting("deliverable","deliverable_xapi_endpoint_url");
register_setting("deliverable","deliverable_xapi_username");
register_setting("deliverable","deliverable_xapi_password");
}
add_action('admin_init','deliverable_admin_init');
/**
* Handle deliverable shortcode.
*/
function deliverable_deliverable($params) {
$shortcodeController=new DeliverableShortcodeController();
return $shortcodeController->deliverable($params);
return DeliverableShortcode::process($params);
}
add_shortcode("deliverable","deliverable_deliverable");
/**
* Enqueue scripts and styles.
*/
function deliverable_enqueue_scripts() {
wp_enqueue_style('wp-deliverable', plugin_dir_url(__FILE__)."/wp-deliverable.css");
}
add_action("wp_enqueue_scripts","deliverable_enqueue_scripts");
add_action("admin_enqueue_scripts","deliverable_enqueue_scripts");
/**
* Activation hook.
*/
function deliverable_activate() {
Deliverable::install();
DeliverableSubmission::install();
$deliverableDir=wp_upload_dir()["basedir"]."/deliverables";
if (!is_dir($deliverableDir)) {
if (!mkdir($deliverableDir,0777,TRUE))
wp_die("Unable to create directory for storing uploaded deliverables: ".$deliverableDir);
}
if (!touch($deliverableDir."/install.tmp"))
wp_die("Delivery directory is not writeable: ".$deliverableDir);
unlink($deliverableDir."/install.tmp");
}
register_activation_hook(__FILE__,'deliverable_activate');
/**
* Uninstall hook.
*/
function deliverable_uninstall() {
Deliverable::uninstall();
}
register_uninstall_hook(__FILE__,'deliverable_uninstall');
/**
* Syncer.
*/
add_filter("remote-syncers",function($syncers) {
$syncers[]=new DeliverableSyncer();
return $syncers;
});