-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmg.php
executable file
·385 lines (317 loc) · 12.6 KB
/
mmg.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php
/*
Plugin Name: mmg
Plugin URI: http://www.museumgam.es/
Description: mmg is a plugin for a set of metadata games based around museum collections (games that help improve digitised museum collections)
Version: 0.3.2
Author: Mia Ridge
Author URI: http://openobjects.org.uk
License: GPL2
*/
/* This version is based on backup from MSc dissertation c Dec 2010 - i.e. most of the code is old and rushed. Try not to judge too harshly! */
/*
Copyright (C) 2014 Mia Ridge
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// ### Add as plugin config setting so it's generalisable. Also db name, not just table names @todo
if ($_SERVER['HTTP_HOST'] == 'localhost' || $_SERVER['HTTP_HOST'] == 'www.museumgames.org.uk' || $_SERVER['HTTP_HOST'] == 'museumgames.org.uk') {
define("table_prefix", "wp_mmg_");
} elseif ($_SERVER['HTTP_HOST'] == 'www.museumgam.es' || $_SERVER['HTTP_HOST'] == 'museumgam.es') {
define("table_prefix", "wplive_mmg_");
}
// include the game-specific files
require_once(dirname(__FILE__) . "/includes/mmg_simpletagging.php");
require_once(dirname(__FILE__) . "/includes/mmg_simplefact.php");
require_once(dirname(__FILE__) . "/includes/mmg_funtagging.php");
require_once(dirname(__FILE__) . "/includes/mmg_factseeker.php");
//require_once(dirname(__FILE__) . "/includes/mmg_taghero.php"); // add it back later or refactor dependencies
require_once(dirname(__FILE__) . "/includes/mmg_reports.php");
//require_once(dirname(__FILE__) . "/includes/mmg_widgets.php"); Not using this anymore @since 0.3.2
// these should really be made into config options ### @todo
define('MMG_IMAGE_URL', WP_CONTENT_URL.'/plugins/'. basename(dirname(__FILE__)) . '/includes/images/');
define('MMG_PLUGIN_URL', WP_PLUGIN_URL.'/includes/'. basename(dirname(__FILE__)));
define("FACTSCORE", "250"); // how many points do players get for a fact added?
define("TAGSCORE", "5"); // how many points do players get per tagged added?
define("PATH_TO_TAGHERO_PAGE", WP_CONTENT_URL. "/taghero/"); // path to page with Tag Hero game shortcode, from WordPress root
define("PATH_TO_DONALD_PAGE", WP_CONTENT_URL. "/donald/"); // path to page with Donald game shortcode, from WordPress root
define("PATH_TO_DORA_PAGE", WP_CONTENT_URL. "/dora/"); // path to page with Donald game shortcode, from WordPress root
define("PATH_TO_UGCREPORTS_PAGE", WP_CONTENT_URL. "/content-added-so-far/"); // path to page with Donald game shortcode, from WordPress root
/////////// set up activation and deactivation stuff
register_activation_hook(__FILE__,'mmg_install');
function mmg_install() {
// do stuff when installed
global $wp_version;
if (version_compare($wp_version, "3", "<")) {
deactivate_plugins(basename(__FILE__)); // deactivate plugin
wp_die("This plugin requires WordPress Version 3 or higher.");
} else {
// this should set up the custom tables and views needed for the plugin @todo
}
}
register_deactivation_hook(__FILE__,'mmg_uninstall');
function mmg_uninstall() {
// ## @todo
// offer option to export data first
}
function mmg_export_data() {
// would double up as a backup function ### @todo
}
/////////// set up option storing stuff
//setting it up now for use later
// create array of options
$mmg_options_arr=array(
"mmg_option_game_length"=>'60', // default value of countdown timer
//"mmg_option_2"=>'Some other value',
);
// store them
update_option('mmg_plugin_options',$mmg_options_arr);
// get them
//$mmg_options_arr = get_option('mmg_plugin_options');
// use them
//$mmg_option_game_length = $mmg_options_arr["mmg_option_game_length"];
// end option array setup
/*
* Adds a page for 'MMG settings' as submenu under general WordPress Setings menu
* @todo - add option for table name with object data?
*
*/
add_action('admin_menu', 'mmg_plugin_menu');
// @todo - change menu option name so it's clearer to casual user?
function mmg_plugin_menu() {
add_options_page('MMG settings page', 'MMG settings', 'administrator', __FILE__, 'mmg_settings_page');
}
// call register settings function before admin pages rendered
add_action('admin_init', 'mmg_register_settings');
function mmg_register_settings() {
// register settings - array, not individual
register_setting('mmg-settings-group', 'mmg_settings_values');
// old way of registering a single field
// register_setting('mmg-settings-group', 'mmg_option_game_length');
}
// write out the plugin options form. Form field name must match option name.
// add other options here as necessary.
function mmg_settings_page() {
?>
<div>
<h2><?php _e('mmg plugin options', 'mmg-plugin') ?></h2>
<form method="post" action="options.php">
<?php settings_fields('mmg-settings-group'); ?>
<?php _e('Game length (seconds)','mmg-plugin') ?>
<?php mmg_setting_game_length(); ?>
<p class="submit"><input type="submit" class="button-primary" value=<?php _e('Save changes', 'mmg-plugin') ?> /></p>
</form>
</div>
<?php
}
// get options from array and display as fields
// @todo update this for other config options
function mmg_setting_game_length() {
// load options array
$mmg_options = get_option('mmg_settings_values');
$game_length = $mmg_options['mmg_option_game_length'];
// display form field
echo '<input type="text" name="mmg_settings_values[mmg_option_game_length]"
value="'.esc_attr($game_length).'" />';
}
/*
*
* Sets up the shortcodes that are added to page content to invoke the game.
* e.g. [mmgame gametype=simpletagging]
* Not sure if I should include mmgSaveNewUserPoints() here but as it's called each time there's
* a shortcode (ie we're on a game page), maybe it's the best place for it
*
*/
function gameShortCode($atts, $content=null) {
if(@is_file(ABSPATH.'/wp-content/plugins/mmg/mmg_functions.php')) {
include_once(ABSPATH.'/wp-content/plugins/mmg/mmg_functions.php');
}
// Checks to see if the user has created an account and/or logged in since they started playing
// Adds their (new) username to their previous turns if so ### check
if ( is_user_logged_in() ) {
mmgSaveNewUserPoints();
}
extract(shortcode_atts(array( // lowercase cos the short tags are, elsewhere camel.
"gametype" => 'simpletagging' // default
), $atts));
if ($gametype == 'simplefacts') {
simpleFacts();
} elseif ($gametype == 'funtagging') {
funtagging();
} elseif ($gametype == 'factseeker') {
mmgFactseekerChoice();
} elseif ($gametype == 'objectugcreport') {
mmgListObjectUGC();
} elseif ($gametype == 'taghero') {
taghero();
} else {
// simple tag game as default
simpleTagging();
}
$GLOBALS['my_game_code'] = $gametype; // so it's accessible in the widget @todo check for deprecation re globals
}
// Add the shortcode
add_shortcode('mmgame', 'gameShortCode');
/* adding a filter for object ID and gamecode so players can return via a link */
function parameter_objID($oVars) {
$oVars[] = "obj_ID";
return $oVars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'parameter_objID');
function parameter_gamecode($gVars) {
$gVars[] = "gamecode"; // not used?
return $gVars;
}
add_filter('query_vars', 'parameter_gamecode');
/* adding a filter for skipped object ID */
function parameter_skippedID($oVars) {
$oVars[] = "skipped_ID";
return $oVars;
}
add_filter('query_vars', 'parameter_skippedID');
/* adding a filter for skipped object ID */
function parameter_reporttype($oVars) {
$oVars[] = "report";
return $oVars;
}
add_filter('query_vars', 'parameter_reporttype');
/*
* game ID for Tag Hero players
* gameID is the unique ID for a particular game setup based on session ID from originating player
* @todo refactor this as tag heros is hackday stuff that shouldn't be here
*/
function parameter_gamesessionID($oVars) {
$oVars[] = "gamesession_ID";
return $oVars;
}
add_filter('query_vars', 'parameter_gamesessionID');
/* for Tag Hero tag quality scores */
/* gametagID is the unique ID of a tag from a player within a game */
function parameter_gametagID($oVars) {
$oVars[] = "gametag_ID";
return $oVars;
}
add_filter('query_vars', 'parameter_gametagID');
/* repeating the tag returned from the tag quality web service for verification (and laziness) */
function parameter_tag($oVars) {
$oVars[] = "tag";
return $oVars;
}
add_filter('query_vars', 'parameter_tag');
/* tag quality score from web service */
function parameter_tag_score($oVars) {
$oVars[] = "tag_score";
return $oVars;
}
add_filter('query_vars', 'parameter_tag_score');
/* end Tag Hero-specific stuff */
/*
* Widget mmgPlayerObjects draws the 'completion box' of played objects and site stats
* Previously called mmgHello
*
* @see drawCompletionBox
*/
class mmgPlayerObjects extends WP_Widget {
function mmgPlayerObjects() {
parent::WP_Widget(false, $name = 'mmg Player Objects');
}
function widget($args, $instance) {
extract( $args );
?>
<?php echo $before_widget; ?>
<?php echo $before_title
. $instance['title'] // will be settable by widget users
. $after_title; ?>
<?php if (!empty ($GLOBALS['my_game_code'])) {
drawCompletionBox($GLOBALS['my_game_code']);
}
?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
return $new_instance;
}
}
add_action('widgets_init', create_function('', 'return register_widget("mmgPlayerObjects");'));
// Final part for registering the mmgPlayerObjects widget
/*
* Adding login widget
* To Do: change header message depending on whether user is logged in
* Picks up some of the things that Theme My Login doesn't do, like showing profile and logout link
* @deprecated 3.0.2 Use Sidebar Login's built in widget instead
*
class mmgLoginWidget extends WP_Widget {
function mmgLoginWidget() {
parent::WP_Widget(false, $name = 'mmg login widget');
}
function widget($args, $instance) {
extract( $args );
?>
<?php if ( is_user_logged_in() ) { // only show if the user is logged in
echo $before_widget; ?>
<?php echo $before_title;
if (!empty($instance['title'])) {
echo $instance['title']; // if settable by widget users
} else {
echo 'Manage your account';
}
echo $after_title; ?>
<?php ?><ul><li>
<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
</li></ul>
<?php echo $after_widget; ?>
<?php }
}
function update($new_instance, $old_instance) {
return $new_instance;
}
}
add_action('widgets_init', create_function('', 'return register_widget("mmgLoginWidget");'));
*/
/*
* Displays user scores by game, even if they're not registeret yet
*
*/
class mmgScoreWidget extends WP_Widget {
function mmgScoreWidget() {
parent::WP_Widget(false, $name = 'mmg score widget');
}
function widget($args, $instance) {
extract( $args );
?>
<?php echo $before_widget; ?>
<?php echo $before_title;
if (!empty($instance['title'])) {
echo $instance['title']; // if settable by widget users
} else {
echo 'Your score for this game:';
}
echo $after_title; ?>
<?php if (!empty ($GLOBALS['my_game_code'])) {
$scoreString = mmgGetUserScoreByGame();
echo $scoreString;
}
if (!is_user_logged_in() ) {
echo 'Login or register to save your points';
}
?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
return $new_instance;
}
}
add_action('widgets_init', create_function('', 'return register_widget("mmgScoreWidget");'));
?>