ob-integrations.php
8.19 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
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
<?php
/**
* Open Badge Integrations.
*
* @package BadgeOS
* @subpackage Open Badge
* @author Learning Times
* @license http://www.gnu.org/licenses/agpl.txt GNU AGPL v3.0
*/
/**
* Abort if this file is accessed directly.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function badgeos_ob_integration_page() {
$badgeos_assertion_url = badgeos_utilities::get_option( 'badgeos_assertion_url' );
$badgeos_json_url = badgeos_utilities::get_option( 'badgeos_json_url' );
$badgeos_issuer_url = badgeos_utilities::get_option( 'badgeos_issuer_url' );
$badgeos_evidence_url = badgeos_utilities::get_option( 'badgeos_evidence_url' );
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"></div>
<h2><?php esc_html_e( 'Open Badge Settings', 'badgeos' ); ?></h2>
<form method="post">
<table class="form-table">
<tr valign="top">
<td align="left" width="20%" valign="top">
<?php esc_html_e( 'Assertion Page', 'badgeos' ); ?>
</td>
<td width="80%" align="left">
<label for="badgeos_assertion_url">
<?php
wp_dropdown_pages(
array(
'show_option_none' => esc_html__( 'Select Assertion Page', 'badgeos' ),
'selected' => esc_html( $badgeos_assertion_url ),
'name' => esc_html__( 'badgeos_assertion_url', 'badgeos' ),
'id' => esc_html__( 'badgeos_assertion_url', 'badgeos' ),
)
);
?>
</label>
<p class="badgeos_hint"><?php esc_html_e( 'Please, select a page where assertion json data will show up. Open badge needs assertion data in json format for validation purpose.', 'badgeos' ); ?></p>
</td>
</tr>
<tr valign="top">
<td align="left" valign="top">
<?php esc_html_e( 'Issuer Page', 'badgeos' ); ?>
</td>
<td align="left">
<label for="badgeos_issuer_url">
<?php
wp_dropdown_pages(
array(
'show_option_none' => esc_html__( 'Select Issuer Page', 'badgeos' ),
'selected' => esc_html( $badgeos_issuer_url ),
'name' => esc_html__( 'badgeos_issuer_url', 'badgeos' ),
'id' => esc_html__( 'badgeos_issuer_url', 'badgeos' ),
)
);
?>
</label>
<p class="badgeos_hint"><?php esc_html_e( 'Please, select a page where issuer json data will show up. Open badge needs issuer data in json format for validation purpose.', 'badgeos' ); ?></p>
</td>
</tr>
<tr valign="top">
<td align="left" valign="top">
<?php esc_html_e( 'Badge Page', 'badgeos' ); ?>
</td>
<td align="left">
<label for="badgeos_json_url">
<?php
wp_dropdown_pages(
array(
'show_option_none' => esc_html__( 'Select Badge Page', 'badgeos' ),
'selected' => esc_html( $badgeos_json_url ),
'name' => esc_html__( 'badgeos_json_url', 'badgeos' ),
'id' => esc_html__( 'badgeos_json_url', 'badgeos' ),
)
);
?>
</label>
<p class="badgeos_hint"><?php esc_html_e( 'Please, select a page where badge json data will show up. Open badge needs badge data in json format for validation purpose.', 'badgeos' ); ?></p>
</td>
</tr>
<tr valign="top">
<td align="left" valign="top">
<?php esc_html_e( 'Evidence Page', 'badgeos' ); ?>
</td>
<td align="left">
<label for="badgeos_evidence_url">
<?php
wp_dropdown_pages(
array(
'show_option_none' => esc_html__( 'Select Evidence Page', 'badgeos' ),
'selected' => esc_html( $badgeos_evidence_url ),
'name' => esc_html__( 'badgeos_evidence_url', 'badgeos' ),
'id' => esc_html__( 'badgeos_evidence_url', 'badgeos' ),
)
);
?>
</label>
<p class="badgeos_hint"><?php esc_html_e( 'Please, select a page for badge evidence and add [badgeos_evidence] shortcode in page description.', 'badgeos' ); ?></p>
</td>
</tr>
</table>
<?php wp_nonce_field( 'bos_ob_settings', 'ob_settings_field' ); ?>
<?php
$assertion_page = badgeos_utilities::get_option( 'badgeos_assertion_url', false );
$json_page = badgeos_utilities::get_option( 'badgeos_json_url', false );
$issuer_page = badgeos_utilities::get_option( 'badgeos_issuer_url', false );
$evidence_page = badgeos_utilities::get_option( 'badgeos_evidence_url', false );
if ( current_user_can( 'manage_options' ) && ( ! badgeos_ob_is_page_exists( $assertion_page ) || ! badgeos_ob_is_page_exists( $json_page ) || ! badgeos_ob_is_page_exists( $issuer_page ) || ! badgeos_ob_is_page_exists( $evidence_page ) ) ) {
$config_link = 'admin-post.php?action=badgeos_config_pages';
$message = esc_html__( 'Please, click <a href="admin-post.php?action=badgeos_config_pages">here</a> to configure/create missing open badge pages.', 'badgeos' );
printf( '<p><strong>%s</strong></p>', esc_html( $message ) );
} else {
$message = esc_html__( 'All of the open badge pages are configured.', 'badgeos' );
printf( '<p><strong>%s</strong></p>', esc_html( $message ) );
}
?>
<?php
// We need to get our api key
submit_button( esc_html__( 'Save Settings', 'badgeos' ) );
?>
</form>
<?php
$non_ob_conversion_progress = 0;
get_transient( 'non_ob_conversion_progress' ); // check if background conversion process is running
$non_os_badgeos_achievements = badgeos_ob_get_all_non_achievements();
$message = 'Please click on "Convert Achievements" button below to convert existing non-open standard user\'s achievements into open standards.';
?>
<div class="open_badge_convert_wrapper">
<h3><?php esc_html_e( 'Convert non-open standard achievements', 'badgeos' ); ?></h3>
<?php if ( ! $non_ob_conversion_progress && ! empty( $non_os_badgeos_achievements ) ) : ?>
<div id="non_ob_button_message">
<p><?php esc_html_e( $message, 'badgeos' ); ?></p>
<input type="button" id="convert_non_open_achievements" class="button-primary" value="<?php esc_html_e( 'Convert Achievements', 'badgeos' ); ?>" />
</div>
<?php elseif ( ! $non_ob_conversion_progress ) : ?>
<div id="no-non-ob"><p><?php esc_html_e( 'All user\'s achievements are in open-standards, no non-open standard achievements found.' ); ?></p></div>
<?php endif; ?>
<div id="open_badge_conversion_in_progress" style="<?php echo ! $non_ob_conversion_progress ? 'display: none;' : ''; ?> padding: 10px; margin-top: 10px;">
<div style="float: left; margin-right:10px;"><img src="<?php echo esc_url( admin_url( 'images/spinner.gif' ) ); ?>"></div>
<div style="float: left;"><?php esc_html_e( 'Non open standards achievements conversion is processing in background, you will receive an email after conversion is completed.', 'badgeos' ); ?></div>
<div style="clear: both;"></div>
</div>
</div>
</div>
<?php
}
function badgeos_ob_save_settings() {
if ( isset( $_POST['ob_settings_field'] ) && check_admin_referer( 'bos_ob_settings', 'ob_settings_field' ) ) {
if ( isset( $_POST['badgeos_assertion_url'] ) && ! empty( $_POST['badgeos_assertion_url'] ) ) {
badgeos_utilities::update_option( 'badgeos_assertion_url', sanitize_text_field( $_POST['badgeos_assertion_url'] ) );
}
if ( isset( $_POST['badgeos_issuer_url'] ) && ! empty( $_POST['badgeos_issuer_url'] ) ) {
badgeos_utilities::update_option( 'badgeos_issuer_url', sanitize_text_field( $_POST['badgeos_issuer_url'] ) );
}
if ( isset( $_POST['badgeos_json_url'] ) && ! empty( $_POST['badgeos_json_url'] ) ) {
badgeos_utilities::update_option( 'badgeos_json_url', sanitize_text_field( $_POST['badgeos_json_url'] ) );
}
if ( isset( $_POST['badgeos_evidence_url'] ) && ! empty( $_POST['badgeos_evidence_url'] ) ) {
badgeos_utilities::update_option( 'badgeos_evidence_url', sanitize_text_field( $_POST['badgeos_evidence_url'] ) );
}
add_action( 'admin_notices', 'badgeos_ob_save_settings_notification' );
}
}
add_action( 'admin_init', 'badgeos_ob_save_settings' );
/**
* Setting notification
*/
function badgeos_ob_save_settings_notification() {
$class = 'notice notice-success is-dismissible';
$message = esc_html__( 'Settings Saved.', 'badgeos' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}