forked from TheMacLab/game-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame-on.php
executable file
·277 lines (261 loc) · 11.1 KB
/
game-on.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
<?php
/*
Plugin Name: Game-On
Plugin URI: http://maclab.guhsd.net/game-on
Description: Gamification tools for teachers.
Author: Valhalla Mac Lab
Author URI: https://github.com/TheMacLab/game-on/blob/master/README.md
Version: 2.5.4
*/
include( 'go_datatable.php' );
include( 'types/types.php' );
include( 'go_pnc.php' );
include( 'go_returns.php' );
include( 'go_ranks.php' );
include( 'scripts/go_enque.php' );
include( 'go_globals.php' );
include( 'go_admin_bar.php' );
include( 'go_message.php' );
include( 'styles/go_enque_styles.php' );
include( 'go_options.php' );
include( 'go_stats.php' );
include( 'go_clipboard.php' );
include( 'go_open_badge.php' );
include( 'go_shortcodes.php' );
include( 'go_comments.php' );
include( 'go_definitions.php' );
include( 'go_mail.php' );
include( 'go_messages.php' );
include( 'go_task_search.php' );
include( 'go_pods.php' );
register_activation_hook( __FILE__, 'go_table_totals' );
register_activation_hook( __FILE__, 'go_table_individual' );
register_activation_hook( __FILE__, 'go_ranks_registration' );
register_activation_hook( __FILE__, 'go_presets_registration' );
register_activation_hook( __FILE__, 'go_install_data' );
register_activation_hook( __FILE__, 'go_define_options' );
register_activation_hook( __FILE__, 'go_open_comments' );
register_activation_hook( __FILE__, 'go_tsk_actv_activate' );
add_action( 'user_register', 'go_user_registration' );
add_action( 'delete_user', 'go_user_delete' );
add_action( 'wp_ajax_go_deactivate_plugin', 'go_deactivate_plugin' );
add_action( 'go_add_post','go_add_post' );
add_action( 'go_add_currency','go_add_currency' );
add_action( 'go_add_bonus_currency','go_add_bonus_currency' );
add_action( 'go_add_penalty','go_add_penalty' );
add_action( 'go_add_minutes','go_add_minutes' );
add_action( 'go_return_currency','go_return_currency' );
add_action( 'go_return_points','go_return_points' );
add_action( 'go_return_bonus_currency','go_return_bonus_currency' );
add_action( 'go_return_penalty','go_return_penalty' );
add_action( 'go_return_minutes','go_return_minutes' );
add_action( 'go_display_user_focuses', 'go_display_user_focuses' );
add_action( 'go_display_rewards', 'go_display_rewards' );
add_action( 'admin_menu', 'go_clipboard' );
add_action( 'go_jquery_clipboard','go_jquery_clipboard' );
add_action( 'go_style_clipboard','go_style_clipboard' );
add_action( 'wp_ajax_go_clone_post', 'go_clone_post' );
add_action( 'wp_ajax_go_clipboard_intable','go_clipboard_intable' );
add_action( 'wp_ajax_go_clipboard_intable_messages','go_clipboard_intable_messages' );
add_action( 'wp_ajax_go_user_option_add','go_user_option_add' );
add_action( 'go_update_totals','go_update_totals' );
add_action( 'init', 'go_jquery' );
add_action( 'init', 'go_admin_menu_js' );
add_action( 'init', 'go_register_tax_and_cpt' );
add_action( 'wp', 'go_task_timer_headers' );
add_action( 'admin_bar_init','go_global_defaults' );
add_action( 'admin_bar_init','go_global_info' );
add_action( 'admin_bar_init', 'go_admin_bar' );
add_action( 'admin_bar_init', 'go_style_everypage' );
add_action( 'admin_bar_init','go_style_stats' );
add_action( 'show_admin_bar', 'go_display_admin_bar' );
add_action( 'go_get_all_ranks','go_get_all_ranks' );
add_action( 'wp_ajax_test_point_update', 'test_point_update' );
add_action( 'go_get_all_focuses', 'go_get_all_focuses' );
add_action( 'wp_ajax_unlock_stage', 'unlock_stage' );
add_action( 'wp_ajax_task_change_stage','task_change_stage' );
add_action( 'wp_ajax_go_task_abandon','go_task_abandon' );
add_action( 'go_update_admin_bar','go_update_admin_bar' );
add_action( 'go_update_progress_bar','go_update_progress_bar' );
add_action( 'go_style_periods','go_style_periods' );
add_action( 'go_jquery_periods','go_jquery_periods' );
add_action( 'wp_ajax_go_admin_bar_add','go_admin_bar_add' );
add_action( 'wp_ajax_go_admin_bar_stats','go_admin_bar_stats' );
add_action( 'wp_ajax_go_class_a_save','go_class_a_save' );
add_action( 'wp_ajax_go_class_b_save','go_class_b_save' );
add_action( 'wp_ajax_go_update_user_sc_data', 'go_update_user_sc_data' );
add_action( 'wp_ajax_go_focus_save','go_focus_save' );
add_action( 'wp_ajax_go_reset_levels', 'go_reset_levels' );
add_action( 'wp_ajax_go_save_levels', 'go_save_levels' );
add_action( 'wp_ajax_go_reset_data', 'go_reset_data' );
add_action( 'wp_ajax_go_stats_task_list','go_stats_task_list' );
add_action( 'wp_ajax_go_stats_move_stage', 'go_stats_move_stage' );
add_action( 'wp_ajax_go_stats_item_list', 'go_stats_item_list' );
add_action( 'wp_ajax_go_stats_rewards_list', 'go_stats_rewards_list' );
add_action( 'wp_ajax_go_stats_minutes_list', 'go_stats_minutes_list' );
add_action( 'wp_ajax_go_stats_penalties_list', 'go_stats_penalties_list' );
add_action( 'wp_ajax_go_stats_badges_list', 'go_stats_badges_list' );
add_action( 'wp_ajax_go_stats_leaderboard_choices','go_stats_leaderboard_choices' );
add_action( 'wp_ajax_go_stats_leaderboard','go_stats_leaderboard' );
add_action( 'wp_ajax_go_presets_reset','go_presets_reset' );
add_action( 'wp_ajax_go_presets_save','go_presets_save' );
add_action( 'wp_ajax_go_fix_levels', 'go_fix_levels' );
add_action( 'wp_ajax_listurl', 'listurl' );
add_action( 'wp_ajax_nopriv_listurl', 'listurl' );
add_action( 'wp_ajax_go_update_user_focuses', 'go_update_user_focuses' );
add_action( 'wp_ajax_go_get_all_terms', 'go_get_all_terms' );
add_action( 'wp_ajax_nopriv_go_get_all_terms', 'go_get_all_terms' );
add_action( 'wp_ajax_go_get_all_posts', 'go_get_all_posts' );
add_action( 'wp_ajax_nopriv_go_get_all_posts', 'go_get_all_posts' );
add_action( 'wp_ajax_go_update_task_order', 'go_update_task_order' );
add_action( 'wp_ajax_go_search_for_user', 'go_search_for_user' );
add_action( 'wp_ajax_go_admin_remove_notification', 'go_admin_remove_notification' );
add_action( 'wp_ajax_go_get_purchase_count', 'go_get_purchase_count' );
add_shortcode( 'go_stats_page', 'go_stats_page' );
add_action( 'admin_init', 'go_tsk_actv_redirect' );
add_action( 'admin_init', 'go_add_delete_post_hook' );
add_action( 'inRange', 'inRange' );
add_action( 'isEven','isEven' );
add_action( 'wp_head', 'go_stats_overlay' );
add_action( 'admin_head', 'go_stats_overlay' );
add_action( 'admin_notices', 'go_admin_head_notification' );
add_action( 'go_display_points','go_display_points' );
add_action( 'go_display_currency','go_display_currency' );
add_action( 'go_display_penalty','go_display_penalty' );
add_action( 'go_display_minutes','go_display_minutes' );
add_action( 'go_return_options','go_return_options' );
add_action( 'go_update_globals','go_update_globals' );
add_action( 'barColor','barColor' );
add_action( 'go_return_multiplier','go_return_multiplier' );
add_filter( 'get_comment_author', 'go_display_comment_author' );
add_action( 'check_custom', 'check_custom' );
add_action( 'check_values', 'check_values' );
add_action( 'go_message_user', 'go_message_user' );
add_filter( 'jetpack_enable_open_graph', '__return_false' );
add_action( 'login_redirect', 'go_user_redirect', 10, 3 );
add_filter( 'cron_schedules', 'go_weekly_schedule' );
function go_deactivate_plugin() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$plugin = plugin_basename( __FILE__ );
deactivate_plugins( $plugin );
die();
}
function go_tsk_actv_activate() {
add_option( 'go_tsk_actv_do_activation_redirect', true );
update_option( 'go_display_admin_explanation', true );
}
function go_tsk_actv_redirect() {
if ( get_option( 'go_tsk_actv_do_activation_redirect', false ) ) {
delete_option( 'go_tsk_actv_do_activation_redirect' );
if ( ! isset( $_GET['activate-multi'] ) ) {
wp_redirect( 'admin.php?page=game-on-options.php&settings-updated=true' );
}
}
}
function go_add_delete_post_hook() {
if ( current_user_can( 'delete_posts' ) ) {
add_action( 'delete_post', 'go_delete_cpt_data' );
}
}
function go_delete_cpt_data( $cpt_id ) {
global $wpdb;
if ( "tasks" == get_post_type( $cpt_id ) || "go_store" == get_post_type( $cpt_id ) ) {
$cpt_to_delete = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}go WHERE post_id = %d", $cpt_id ) );
if ( $cpt_to_delete ) {
return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}go WHERE post_id = %d", $cpt_id ) );
}
}
return true;
}
/*
* Registers Game On custom post types and taxonomies, then
* updates the site's rewrite rules to mitigate cpt and
* permalink conflicts. flush_rewrite_rules() must always
* be called AFTER custom post types and taxonomies are
* registered.
*/
function go_register_tax_and_cpt() {
go_register_task_tax_and_cpt();
go_register_store_tax_and_cpt();
flush_rewrite_rules();
}
function inRange( $int, $min, $max ) {
return ( $int > $min && $int <= $max );
}
function isEven( $value ) {
if ( $value % 2 == 0 ) {
return 'even';
} else {
return 'odd';
}
}
function check_values( $req = null, $cur = null ) {
if ( $cur >= $req || $req <= 0 ) {
return true;
} else {
return false;
}
}
function go_user_redirect( $redirect_to, $request, $user ) {
if ( get_option( 'go_admin_bar_user_redirect', true ) ) {
$roles = $user->roles;
if ( is_array( $roles) ) {
if ( in_array( 'administrator', $roles ) ) {
return admin_url();
} else {
return site_url();
}
} else {
if ( $roles == 'administrator' ) {
return admin_url();
} else {
return site_url();
}
}
} else {
return $redirect_to;
}
}
function go_admin_head_notification() {
if ( get_option( 'go_display_admin_explanation' ) && current_user_can( 'manage_options' ) ) {
$plugin_data = get_plugin_data( __FILE__, false, false );
$plugin_version = $plugin_data['Version'];
echo "<div id='message' class='update-nag' style='font-size: 16px;'>This is a fresh installation of Game On (version <a href='https://github.com/TheMacLab/game-on/releases/tag/v{$plugin_version}' target='_blank'>{$plugin_version}</a>).<br/>Watch <a href='javascript:;' onclick='go_display_help_video("http://maclab.guhsd.net/go/video/gameOn.mp4");' style='display:inline-block;'>this short video</a> for important information.<br/>Or visit the <a href='http://maclab.guhsd.net/game-on' target='_blank'>documentation page</a>.<br/><a href='javascript:;' onclick='go_remove_admin_notification()'>Dismiss messsage</a></div>";
echo "<script>
function go_remove_admin_notification() {
jQuery.ajax( {
type: 'post',
url: MyAjax.ajaxurl,
data: {
action: 'go_admin_remove_notification'
},
success: function( html ) {
location.reload();
}
} );
}
</script>";
}
}
function go_admin_remove_notification() {
update_option( 'go_display_admin_explanation', false );
die();
}
function go_weekly_schedule( $schedules ) {
$schedules['go_weekly'] = array(
'interval' => 604800,
'display' => __( 'Once Weekly' )
);
return $schedules;
}
function go_task_timer_headers() {
$custom_fields = get_post_custom();
$future_switches = ( ! empty( $custom_fields['go_mta_time_filters'][0] ) ? unserialize( $custom_fields['go_mta_time_filters'][0] ) : '' );
if ( 'tasks' == get_post_type() && ! empty( $future_switches['future'] ) && 'on' == $future_switches['future'] ) {
header( 'Expires: Thu, 1 Jan 1970 00:00:00 GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', FALSE );
header( 'Pragma: no-cache' );
}
}
?>