-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmyarcadeplugin.php
583 lines (496 loc) · 15.9 KB
/
myarcadeplugin.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<?php
/**
* Plugin Name: MyArcadePlugin Lite
* Plugin URI: https://myarcadeplugin.com
* Description: WordPress Arcade Plugin
* Version: 6.1.0
* Author: Daniel Bakovic
* Author URI: https://myarcadeplugin.com
* Requires at least: 5.6
* Requires PHP: 7.0
*
* @package MyArcadePlugin
*/
if ( ! class_exists( 'MyArcadePlugin' ) ) :
/**
* Main MyArcadePlugin Class
*/
final class MyArcadePlugin {
/**
* MyArcadePlugin version number
*
* @var string
*/
public $version = '6.1.0';
/**
* A single instance of MyArcadePlugin.
*
* @var MyArcadePlugin
*/
protected static $instance = null;
/**
* Plugin URL.
*
* @var string
*/
public $plugin_url;
/**
* Plugin Path.
*
* @var string
*/
public $plugin_path;
/**
* Plugin basename folder/filename.php.
*
* @var string
*/
public $plugin_basename;
// Define tables for MyScoresPresenter compatibility.
// This will be removed after MyScoresPresenter Update.
/**
* Stores the games table name.
*
* @var string
*/
public $game_table;
/**
* Stores the scores table name.
*
* @var string
*/
public $score_table;
/**
* Stores the high scores table name.
*
* @var string
*/
public $highscore_table;
/**
* Stores the user's table name.
*
* @var string
*/
public $user_table;
/**
* Stores the medal table name.
*
* @var string
*/
public $medal_table;
/**
* Stores the game plays table name.
*
* @var string
*/
public $plays_table;
/**
* Main MyArcadePlugin Instance.
*
* Ensures only one instance of MyArcadePlugin is loaded or can be loaded.
*
* @see MyArcade()
* @return Main MyArcadePlugin instance
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Cloning is forbidden.
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?' ), '6.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?' ), '6.0.0' );
}
/**
* MyArcadePlugin Constructor.
*/
public function __construct() {
// Define constants.
$this->define_constants();
// Include required files.
$this->includes();
// Init hooks.
$this->init_hooks();
}
/**
* Define constants
*
* @access private
*/
private function define_constants() {
global $wpdb;
$this->plugin_basename = plugin_basename( __FILE__ );
$this->define( 'MYARCADE_VERSION', $this->version );
// Define needed table constants for backward compatibility.
$this->define( 'MYARCADE_GAME_TABLE', $wpdb->prefix . 'myarcadegames' );
$this->define( 'MYARCADE_HIGHSCORES_TABLE', $wpdb->prefix . 'myarcadehighscores' );
$this->define( 'MYARCADE_USER_TABLE', $wpdb->prefix . 'myarcadeuser' );
$this->game_table = MYARCADE_GAME_TABLE;
$this->score_table = $wpdb->prefix . 'myarcadescores';
$this->highscore_table = MYARCADE_HIGHSCORES_TABLE;
$this->user_table = MYARCADE_USER_TABLE;
$this->medal_table = $wpdb->prefix . 'myarcademedals';
$this->plays_table = $wpdb->prefix . 'myarcade_plays';
// Define the plugins abs path.
$dirname = basename( dirname( __FILE__ ) );
$this->define( 'MYARCADE_DIR', dirname( __FILE__ ) );
$this->define( 'MYARCADE_CORE_DIR', MYARCADE_DIR . '/core' );
$this->define( 'MYARCADE_URL', plugins_url() . '/' . $dirname );
$this->define( 'MYARCADE_UPDATE_API', 'http://api.myarcadeplugin.com/' );
$this->define( 'MYARCADE_PLUGIN_FOLDER_NAME', basename( dirname( __FILE__ ) ) );
$this->define( 'MYARCADE_PLUGIN_SLUG', 'myarcadeplugin-lite' );
}
/**
* Define constant if not already set.
*
* @access private
* @param string $name Define name.
* @param string|bool $value Define value.
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Include required core files used in admin and on the frontend.
*/
private function includes() {
include_once $this->plugin_path() . '/includes/class-myarcade-autoloader.php';
require_once $this->plugin_path() . '/includes/class-myarcade-install.php';
require_once $this->plugin_path() . '/core/schedule.php';
require_once $this->plugin_path() . '/core/debug.php';
require_once $this->plugin_path() . '/core/score_handler.php';
require_once $this->plugin_path() . '/core/template.php';
require_once $this->plugin_path() . '/core/game.php';
require_once $this->plugin_path() . '/core/output.php';
require_once $this->plugin_path() . '/core/user.php';
require_once $this->plugin_path() . '/core/feedback.php';
if ( $this->is_request( 'admin' ) ) {
require_once $this->plugin_path() . '/core/myarcade_admin.php';
}
// Do this on the backend and on cron triggers.
if ( $this->is_request( 'admin' ) || defined( 'MYARCADE_DOING_ACTION' ) || defined( 'DOING_CRON' ) ) {
require_once $this->plugin_path() . '/core/translate.php';
require_once $this->plugin_path() . '/core/addgames.php';
require_once $this->plugin_path() . '/core/file.php';
}
if ( $this->is_request( 'frontend' ) ) {
$this->frontend_includes();
}
// Stats / Tracking.
if ( 'yes' === get_option( 'myarcade_allow_tracking', 'no' ) ) {
if ( $this->is_request( 'cron' ) ) {
// Include on on cron jobs.
include_once $this->plugin_path() . '/includes/class-myarcade-tracker.php';
}
if ( ! $this->is_request( 'admin' ) ) {
include_once $this->plugin_path() . '/includes/class-myarcade-stats-aggregator.php';
}
// Include ajax handler only when doing an ajax request.
if ( $this->is_request( 'ajax' ) ) {
include_once $this->plugin_path() . '/includes/class-myarcade-stats-ajax.php';
}
}
}
/**
* Includes required for frontend only
*/
private function frontend_includes() {
require_once $this->plugin_path() . '/includes/class-myarcade-session.php';
}
/**
* Init required actions and filters
*
* @access private
*/
private function init_hooks() {
register_activation_hook( __FILE__, array( 'MyArcade_Install', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'MyArcade_Install', 'plugin_deactivation' ) );
add_action( 'init', array( $this, 'init' ) );
add_action( 'wp_ajax_myarcade_import_handler', array( $this, 'import_handler' ) );
if ( $this->is_network_activated() ) {
if ( is_main_site() ) {
add_action( 'network_admin_notices', 'myarcade_notices' );
}
} else {
add_action( 'admin_notices', 'myarcade_notices' );
}
}
/**
* Init when WordPress initializes.
*/
public function init() {
// Set up localisation.
load_plugin_textdomain( 'myarcadeplugin', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
}
/**
* Locate and include distributor's integration file
*
* @param string $key Distributors key/slug.
*/
public function load_distributor( $key ) {
$distributor_file = apply_filters( 'myarcade_distributor_integration', $this->plugin_path() . '/core/feeds/' . $key . '.php', $key );
if ( file_exists( $distributor_file ) ) {
include_once $distributor_file;
}
}
/**
* Get distributor's settings.
*
* @param string $key Distributors key/slug.
* @return array Settings.
*/
public function get_settings( $key ) {
$settings = get_option( 'myarcade_' . $key );
if ( ! $settings ) {
// No settings found. Check if distirbutor settings have been requested.
$distributors = MyArcade()->distributors();
if ( array_key_exists( $key, $distributors ) ) {
// Default settings function.
$settings_function = 'myarcade_default_settings_' . $key;
if ( function_exists( $settings_function ) ) {
$settings = $settings_function();
} else {
// Function doesn't exist. Try to find the distributor integration file.
$distributor_file = apply_filters( 'myarcade_distributor_integration', MYARCADE_CORE_DIR . '/feeds/' . $key . '.php', $key );
if ( file_exists( $distributor_file ) ) {
include_once $distributor_file;
if ( function_exists( $settings_function ) ) {
$settings = $settings_function();
}
}
}
}
}
if ( ! $settings ) {
$settings = array();
}
return $settings;
}
/**
* Set default game distributors
*
* @return array Array of supported game distributors
*/
public function distributors() {
return apply_filters(
'myarcade_game_distributors',
array(
'famobi' => 'Famobi',
'gamedistribution' => 'GameDistribution',
'gamemonetize' => 'GameMonetize',
'gamepix' => 'GamePix',
'myarcadefeed' => 'MyArcadeFeed',
'softgames' => 'Softgames',
'fourj' => '4J (Pro)',
'fourjrevshare' => '4J (Revenue Share) (Pro)',
'gamearter' => 'GameArter (Pro)',
'htmlgames' => 'HTML Games (Pro)',
'kongregate' => 'Kongregate (Pro)',
'wanted5games' => 'Wanted 5 Games (Pro)',
)
);
}
/**
* Set default custom game types
*
* @return array Array of custom game types.
*/
public function custom_game_types() {
return apply_filters(
'myarcade_import_methods',
array(
'embed' => __( 'Embed Code', 'myarcadeplugin' ),
'custom' => __( 'Flash (SWF)', 'myarcadeplugin' ),
'html5' => __( 'HTML5 Game', 'myarcadeplugin' ),
'ibparcade' => __( 'IBPArcade Game', 'myarcadeplugin' ),
'iframe' => __( 'Iframe URL', 'myarcadeplugin' ),
'phpbb' => __( 'PHPBB Game', 'myarcadeplugin' ),
'dcr' => __( 'Shochwave (DCR)', 'myarcadeplugin' ),
'unity' => __( 'Unity', 'myarcadeplugin' ),
)
);
}
/**
* Get the current game post type.
*
* @return string Post type.
*/
public function get_post_type() {
$general = get_option( 'myarcade_general' );
if ( 'post' !== $general['post_type'] && post_type_exists( $general['post_type'] ) ) {
$post_type = $general['post_type'];
} else {
$post_type = 'post';
}
return $post_type;
}
/**
* Load game import handler
*/
public function import_handler() {
require_once $this->plugin_path() . '/core/admin/import_handler.php';
}
/**
* Get MyArcade upload directories
*
* @return array Upload directories (absolute and url).
*/
public function upload_dir() {
$wp_upload_dir = wp_upload_dir();
$games_base = 'games';
$thumbs_base = 'thumbs';
/**
* Example
* 'basedir' => string 'C:\xampp\htdocs\myarcadeplugin5/wp-content/uploads/'
* 'baseurl' => string 'http://myarcadeplugin5.loc/wp-content/uploads/'
* 'gamesdir' => string 'C:\xampp\htdocs\myarcadeplugin5/wp-content/uploads/games/'
* 'gamesurl' => string 'http://myarcadeplugin5.loc/wp-content/uploads/games/'
* 'gamesbase' => string 'uploads/games/'
* 'thumbsdir' => string 'C:\xampp\htdocs\myarcadeplugin5/wp-content/uploads/thumbs/'
* 'thumbsurl' => string 'http://myarcadeplugin5.loc/wp-content/uploads/thumbs/'
* 'thumbsbase' => string 'uploads/thumbs/'
*/
$upload_dir = apply_filters(
'myarcade_upload_dir',
array(
'basedir' => $wp_upload_dir['basedir'] . '/',
'baseurl' => $wp_upload_dir['baseurl'] . '/',
'gamesdir' => $wp_upload_dir['basedir'] . '/' . $games_base . '/',
'gamesurl' => $wp_upload_dir['baseurl'] . '/' . $games_base . '/',
'gamesbase' => basename( $wp_upload_dir['baseurl'] ) . '/' . $games_base . '/',
'thumbsdir' => $wp_upload_dir['basedir'] . '/' . $thumbs_base . '/',
'thumbsurl' => $wp_upload_dir['baseurl'] . '/' . $thumbs_base . '/',
'thumbsbase' => basename( $wp_upload_dir['baseurl'] ) . '/' . $thumbs_base . '/',
)
);
// Create directories if necessary.
wp_mkdir_p( $upload_dir['gamesdir'] );
wp_mkdir_p( $upload_dir['thumbsdir'] );
return $upload_dir;
}
/**
* Check if MyArcadePlugin is activated for network
*
* @return bool TRUE if activated for network
*/
public function is_network_activated() {
if ( is_multisite() ) {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
if ( is_plugin_active_for_network( $this->plugin_basename ) ) {
return true;
}
}
return false;
}
/**
* What type of request is this?
*
* @param string $type ajax, frontend, admin or myarcade.
*/
public function is_request( $type ) {
switch ( $type ) {
case 'admin':
return is_admin();
case 'ajax':
return defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
case 'cron':
return defined( 'DOING_CRON' ) ? DOING_CRON : false;
case 'frontend':
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
case 'myarcade':
return defined( 'MYARCADE_DOING_ACTION' ) ? MYARCADE_DOING_ACTION : false;
}
}
/**
* Get the plugin url.
*
* @return string Plugin URL.
*/
public function plugin_url() {
if ( ! $this->plugin_url ) {
$this->plugin_url = plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) );
}
return $this->plugin_url;
}
/**
* Get the plugin path.
*
* @return string
*/
public function plugin_path() {
if ( ! $this->plugin_path ) {
$this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
}
return $this->plugin_path;
}
}
endif;
/**
* Keep for backward compatibility.
* Used by MyArcadeFeed
*/
function myarcade_init() {}
/**
* MyArcadePlugin Premium Hint
*
*/
function myarcade_premium_img() {
echo '<img src="'.MYARCADE_URL.'/assets/images/locked.png" alt="Pro Version Only!" title="Pro Version Only!" />';
}
/**
* Upgrade to premium message
*
* @param boolean $alert
*/
function myarcade_premium_message( $alert = true ) {
if ( $alert ) {
echo '<div class="mabp_error">';
}
echo '<p>Get <a href="https://myarcadeplugin.com/buy" target="_blank">MyArcadePlugin Pro</a> to enable this feature. Your <strong>20% off</strong> coupon code: "<strong>upgrademylite</strong>".</p>';
if ( $alert ) {
echo "</div>";
}
}
function myarcade_premium_span( $color = 'yellow' ) {
echo '<span style="color:'.$color.'"">PRO FEATURE</span> - ';
}
/**
* Show a upgrade notice for MyArcadePlugin Lite users.
*/
function myarcade_premium_notice() {
echo '<div class="notice notice-success">';
echo '<h2>Unlock the Full Potential of MyArcadePlugin!</h2>';
echo '<p>Thank you for using MyArcadePlugin Lite. Upgrade to the full version today and enjoy an array of premium features designed to supercharge your gaming experience:</p>';
echo '<ol>';
echo '<li><strong>Exclusive Game Distributors:</strong> Access to thousands of awesome games.</li>';
echo '<li><strong>Advanced Leaderboards:</strong> Enhance player engagement with detailed leaderboards.</li>';
echo '<li><strong>Regular Updates:</strong> Stay ahead with the latest features and improvements.</li>';
echo '<li><strong>Detailed Analytics:</strong> Gain insights with advanced game analytics.</li>';
echo '<li><strong>Game Import Tool:</strong> Easily import games from various sources.</li>';
echo '</ol>';
echo '<p>As a token of our appreciation, use the coupon code <strong>upgrademylite</strong> at checkout to receive <strong>20% off</strong> your upgrade!</p>';
echo '<p><a href="https://myarcadeplugin.com/buy" class="button button-primary" target="_blank">Upgrade Now and Save 20%</a></p>';
echo '</div>';
}
/**
* Returns the main instance of MyArcade to prevent the need to use globals.
*
* @return object MyArcadePlugin
*/
function MyArcade() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return MyArcadePlugin::instance();
}
MyArcade();