forked from jewlofthelotus/SlickQuiz-WordPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slickquiz.php
264 lines (216 loc) · 9.94 KB
/
slickquiz.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
<?php
/*
Plugin Name: SlickQuiz
Plugin URI: http://github.com/jewlofthelotus/SlickQuiz-WordPress
Description: Plugin for displaying and managing pretty, dynamic quizzes.
Version: 1.2.32
Author: Julie Cameron
Author URI: http://juliecameron.com
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl.html
*/
/*
Copyright (c) 2013 Quicken Loans
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Stop direct call
if ( preg_match( '#' . basename( __FILE__ ) . '#', $_SERVER['PHP_SELF'] ) ) {
die( 'You are not allowed to call this page directly.' );
}
if ( !class_exists( 'SlickQuiz' ) ) {
class SlickQuiz
{
// Constructor
function __construct()
{
$this->plugin_name = basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ );
// Activate for New Installs
register_activation_hook( $this->plugin_name, array( &$this, 'activate' ) );
// Activate for Updates
add_action( 'plugins_loaded', array( &$this, 'activate' ) );
// Include Quiz Helper (Shared Methods)
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-helper.php' );
// Include Quiz Model
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-model.php' );
// Include Quiz Widgets
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-widgets.php' );
// Setup Quiz Shortcodes
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-front.php' );
$slickQuizFront = new SlickQuizFront();
// Register AJAX actions
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-functions.php' );
$slickQuizFunctions = new SlickQuizFunctions();
// Register non-menu pages
add_action( 'admin_menu', array( &$this, 'register_aux_pages' ) );
// Add the admin menu
add_action( 'admin_menu', array( &$this, 'add_menu' ) );
// Add the script and style files
add_action( 'admin_enqueue_scripts', array( &$this, 'load_resources' ) );
// Display Update Notice
add_action( 'admin_notices', array( &$this, 'update_notice' ) );
add_action( 'admin_init', array( &$this, 'ignore_notice' ) );
}
// On Activation - Create SlickQuiz Database Table And Setup Options
function activate()
{
$this->create_quiz_table();
$this->create_score_table();
$quizHelper = new SlickQuizHelper;
$quizHelper->get_admin_options();
}
// Display update notice
function update_notice()
{
global $current_user;
$options = get_option( "slick_quiz_options" );
$disabled = $options['disable_responses'];
if ( $disabled && !get_user_meta( $current_user->ID, 'slickquiz_ignore_notice_disabled' ) ) {
echo '<div class="error">';
printf( __( '<p><strong>NOTICE: SlickQuiz options have changed.</strong></p>' .
'<p>The single option to disable response messages has been removed, ' .
'instead you should disable both per question and completion response message options.</p>' .
'<p><a href="' . admin_url( 'admin.php?page=slickquiz-options#responses' ) . '">Edit Options</a> ' .
'<a href="%1$s">Hide This Notice</a></p>' ), add_query_arg( 'slickquiz_ignore_notice', '0' ) );
echo "</div>";
}
}
// Allow user to ignore update notice
function ignore_notice()
{
global $current_user;
if ( isset( $_GET['slickquiz_ignore_notice'] ) && '0' == $_GET['slickquiz_ignore_notice'] ) {
add_user_meta( $current_user->ID, 'slickquiz_ignore_notice_disabled', 'true', true );
}
}
// Add SlickQuiz Menu to Navigation
function add_menu()
{
// Accessible to Authors, Editors, and Admins
add_menu_page( 'SlickQuizzes', 'SlickQuizzes', 'publish_posts', 'slickquiz', array( &$this, 'direct_route' ) );
// Accessible to Editors and Admins
add_submenu_page( 'slickquiz', 'Add Quiz', 'Add Quiz', 'publish_pages', 'slickquiz-new', array( &$this, 'direct_route') );
// Accessible to Admins
add_submenu_page( 'slickquiz', 'Options', 'Options', 'manage_options', 'slickquiz-options', array( &$this, 'direct_route') );
}
// Register Non-Menu Pages
function register_aux_pages()
{
global $_registered_pages;
$hooknameEdit = get_plugin_page_hookname( 'slickquiz-edit', 'admin.php' );
if ( !empty( $hooknameEdit ) ) {
add_action( $hooknameEdit, array( &$this, 'direct_route' ) );
}
$_registered_pages[$hooknameEdit] = true;
$hooknamePreview = get_plugin_page_hookname( 'slickquiz-preview', 'admin.php' );
if ( !empty( $hooknamePreview ) ) {
add_action( $hooknamePreview, array( &$this, 'direct_route' ) );
}
$_registered_pages[$hooknamePreview] = true;
$hooknameScores = get_plugin_page_hookname( 'slickquiz-scores', 'admin.php' );
if ( !empty( $hooknameScores ) ) {
add_action( $hooknameScores, array( &$this, 'direct_route' ) );
}
$_registered_pages[$hooknameScores] = true;
}
// Basic Router
function direct_route()
{
switch ( $_GET['page'] ) {
case 'slickquiz-new' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-new.php' );
break;
case 'slickquiz-edit' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-edit.php' );
break;
case 'slickquiz-preview' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-preview.php' );
break;
case 'slickquiz-functions' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-functions.php' );
break;
case 'slickquiz-options' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-options.php' );
break;
case 'slickquiz-scores' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-scores.php' );
break;
case 'slickquiz' :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-admin.php' );
break;
default :
include_once ( dirname ( __FILE__ ) . '/php/slickquiz-admin.php' );
break;
}
}
// Add Admin JS and styles
function load_resources()
{
// Only load resources when in SlickQuiz Admin section
preg_match( '/slickquiz/is', $_SERVER['REQUEST_URI'], $matches );
if ( count( $matches) == 0 ) return;
// Scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'slickquiz_admin_js', plugins_url( '/js/admin.js', __FILE__ ) );
// Styles
wp_enqueue_style( 'slickquiz_admin_css', plugins_url( '/css/admin.css', __FILE__ ) );
}
// Create Quiz Database Table
function create_quiz_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'plugin_slickquiz';
$sql = "CREATE TABLE $table_name (
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
publishedJson longtext NULL,
workingJson longtext NULL,
publishedQCount int(11) NULL,
workingQCount int(11) NULL,
hasBeenPublished tinyint(1) NOT NULL DEFAULT '0',
publishedBy bigint(20) unsigned NOT NULL DEFAULT '0',
publishedDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
createdBy bigint(20) unsigned NOT NULL DEFAULT '0',
createdDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
lastUpdatedBy bigint(20) unsigned NOT NULL DEFAULT '0',
lastUpdatedDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (id),
KEY createdBy_index (createdBy)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
// Create User Score Database Table
function create_score_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'plugin_slickquiz_scores';
$sql = "CREATE TABLE $table_name (
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
score varchar(50) NOT NULL,
quiz_id bigint(20) unsigned NOT NULL DEFAULT '0',
createdBy bigint(20) unsigned NOT NULL DEFAULT '0',
createdDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (id),
KEY quiz_id_index (quiz_id),
KEY score_index (score)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
} // End Class SlickQuiz
}
if ( class_exists( 'SlickQuiz' ) ) {
global $slickQuiz;
$slickQuiz = new SlickQuiz();
}
?>