-
Notifications
You must be signed in to change notification settings - Fork 19
/
phpleague.php
859 lines (775 loc) · 35.2 KB
/
phpleague.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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
<?php
/*
Copyright 2011 M. Dizerens (email : [email protected])
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
Plugin Name: PHPLeague for WordPress
Plugin URI: http://www.phpleague.com/
Description: PHPLeague for WordPress is the best companion to manage your championships.
Version: 1.4.5
Author: M. Dizerens
Author URI: http://www.phpleague.com/
*/
if ( ! class_exists('PHPLeague')) {
/**
* PHPLeague library.
*
* @package PHPLeague
* @author Maxime Dizerens
* @copyright (c) 2011 Mikaweb Design, Ltd
*/
class PHPLeague {
// Variables
public $longname = 'PHPLeague for WordPress';
public $shortname = 'PHPLeague for WP';
public $homepage = 'http://www.phpleague.com/';
public $edition = 'Ultimate Edition';
public static $access = 'administrator';
public static $pages = array(
'phpleague_about',
'phpleague_club',
'phpleague_overview',
'phpleague_player',
'phpleague_setting'
);
/**
* Constructor
*
* @param none
* @return void
*/
public function __construct()
{
// Load the constants
$this->define_constants();
// PHPLeague Translation
load_plugin_textdomain('phpleague', FALSE, 'phpleague/i18n');
// Core files
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-tools.php';
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-database.php';
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-widgets.php';
// Sports files
// Soccer is used for testing...
require_once WP_PHPLEAGUE_PATH.'inc/sports/sports.php';
require_once WP_PHPLEAGUE_PATH.'inc/sports/football.php';
// Load our tables
$this->define_tables();
// PHPLeague back-end
if (is_admin())
{
// Specific WP actions...
register_activation_hook(__FILE__, array('PHPLeague', 'activate'));
register_uninstall_hook(__FILE__, array('PHPLeague', 'uninstall'));
// Load the backend controller system
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-admin.php';
add_action('init', array('PHPLeague_Admin', 'add_editor_button'));
add_action('admin_init', array(&$this, 'plugin_admin_init'));
add_action('admin_init', array(&$this, 'plugin_check_upgrade'));
add_action('admin_menu', array('PHPLeague_Admin', 'admin_menu'));
add_action('admin_print_styles', array('PHPLeague_Admin', 'print_admin_styles'));
add_action('admin_print_scripts', array('PHPLeague_Admin', 'print_admin_scripts'));
add_action('wp_dashboard_setup', array('PHPLeague_Admin', 'register_admin_widgets'));
add_action('admin_bar_menu', array('PHPLeague_Admin', 'render_adminbar_links'));
// AJAX library
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-ajax.php';
// Ajax request to delete a team in player history
add_action('wp_ajax_delete_player_history_team', array('PHPLeague_AJAX', 'delete_player_history_team'));
}
else // PHPLeague frontend
{
// Don't need to be admin to use PHPLeague in the frontend
PHPLeague::$access = '';
// Load the frontend controller system
require_once WP_PHPLEAGUE_PATH.'libs/phpleague-front.php';
add_action('wp_print_styles', array('PHPLeague_Front', 'print_front_styles'));
add_shortcode('phpleague', array(&$this, 'shortcodes_controller'));
}
}
/**
* Define constants
*
* @param none
* @return void
*/
public function define_constants()
{
define('WP_PHPLEAGUE_VERSION', '1.4.5');
define('WP_PHPLEAGUE_DB_VERSION', '1.3.1');
define('WP_PHPLEAGUE_EDITION', $this->edition);
define('WP_PHPLEAGUE_PATH', plugin_dir_path(__FILE__));
define('WP_PHPLEAGUE_UPLOADS_PATH', ABSPATH.'wp-content/uploads/phpleague/');
}
/**
* Admin initializer
*
* @param none
* @return void
*/
public function plugin_admin_init()
{
// Just after the plugin activation, we redirect user to PHPLeague...
if (get_option('phpleague_do_activation_redirect', FALSE))
{
delete_option('phpleague_do_activation_redirect');
wp_redirect(get_option('siteurl').'/wp-admin/admin.php?page=phpleague_overview&activation=1');
die;
}
// Set capabilities
$role = get_role(PHPLeague::$access);
$role->add_cap('manage_phpleague');
$role->add_cap('phpleague');
// Give everyone access to the editor button
$role = get_role('editor');
$role->add_cap('phpleague');
// On every PHPLeague page, we check the permission!
if (isset($_GET['page']) && in_array(trim($_GET['page']), PHPLeague::$pages))
{
if ( ! current_user_can('manage_phpleague'))
wp_die(__('Permission insufficient to run PHPLeague!', 'phpleague'));
}
}
/**
* Plugin upgrade handler
*
* @param none
* @return void
*/
public function plugin_check_upgrade()
{
global $wpdb;
// Get the current versions from the database
$version = get_option('phpleague_version');
$current_version = isset($version) ? $version : 0;
$db_version = get_option('phpleague_db_version');
$current_db_version = isset($db_version) ? $db_version : 0;
// You're already using the latest version
// so we're leaving!
if ($current_version == WP_PHPLEAGUE_VERSION AND $current_db_version == WP_PHPLEAGUE_DB_VERSION)
return;
// Few people encounter issues because they can't handle
// with a 'NOT DEFAULT' without any value
if (version_compare($current_db_version, '1.2.0', '<'))
{
// ALTER tables
$wpdb->query("ALTER TABLE $wpdb->country MODIFY name VARCHAR(100) DEFAULT NULL;");
$wpdb->query("ALTER TABLE $wpdb->club MODIFY venue VARCHAR(100) DEFAULT NULL;");
$wpdb->query("ALTER TABLE $wpdb->club MODIFY coach VARCHAR(100) DEFAULT NULL;");
$wpdb->query("ALTER TABLE $wpdb->club MODIFY logo_big VARCHAR(255) DEFAULT NULL;");
$wpdb->query("ALTER TABLE $wpdb->club MODIFY logo_mini VARCHAR(255) DEFAULT NULL;");
}
// We add the 4 UK members...
if (version_compare($current_db_version, '1.2.1', '<'))
{
$countries = array(
238 => 'England',
239 => 'Wales',
240 => 'Northern Ireland',
241 => 'Scotland'
);
// Update the country table with all of the above
foreach ($countries as $key => $country)
{
$wpdb->query("INSERT INTO $wpdb->country VALUES($key, '".$country."');");
}
// Penalty is not unsigned anymore
$wpdb->query("ALTER TABLE $wpdb->team MODIFY penalty TINYINT(1) NOT NULL DEFAULT '0';");
}
// Drop constraints because too much pain in the ass with WP
if (version_compare($current_db_version, '1.2.2', '<'))
{
// ALTER tables
$wpdb->query("ALTER TABLE $wpdb->fixture DROP FOREIGN KEY phpleague_fixture_ibfk_1;");
$wpdb->query("ALTER TABLE $wpdb->match DROP FOREIGN KEY phpleague_match_ibfk_1;");
$wpdb->query("ALTER TABLE $wpdb->table_cache DROP FOREIGN KEY phpleague_table_cache_ibfk_1;");
$wpdb->query("ALTER TABLE $wpdb->team DROP FOREIGN KEY phpleague_team_ibfk_1;");
}
// Few modifications
if (version_compare($current_db_version, '1.3.2', '<'))
{
// ALTER tables
$wpdb->query("ALTER TABLE $wpdb->league MODIFY id_favorite smallint(4) unsigned NOT NULL DEFAULT '0';");
$wpdb->query("ALTER TABLE $wpdb->club ADD creation YEAR(4) NOT NULL DEFAULT '0000' AFTER coach;");
$wpdb->query("ALTER TABLE $wpdb->club ADD website VARCHAR(255) DEFAULT NULL AFTER creation;");
$wpdb->query("ALTER TABLE $wpdb->league ADD team_link ENUM('no','yes') NOT NULL DEFAULT 'no' AFTER nb_leg;");
$wpdb->query("ALTER TABLE $wpdb->league ADD default_time time NOT NULL DEFAULT '17:00:00' AFTER team_link;");
// ALTER league table
$wpdb->query("ALTER TABLE $wpdb->league ADD player_mod ENUM('no','yes') NOT NULL DEFAULT 'no' AFTER nb_teams;");
$wpdb->query("ALTER TABLE $wpdb->league ADD sport_type VARCHAR(50) NOT NULL DEFAULT 'football' AFTER player_mod;");
$wpdb->query("ALTER TABLE $wpdb->league ADD nb_starter TINYINT(1) unsigned NOT NULL DEFAULT '0' AFTER sport_type;");
$wpdb->query("ALTER TABLE $wpdb->league ADD nb_bench TINYINT(1) unsigned NOT NULL DEFAULT '0' AFTER nb_starter;");
$wpdb->query("ALTER TABLE $wpdb->league ADD prediction_mod ENUM('no','yes') NOT NULL DEFAULT 'no' AFTER nb_bench;");
$wpdb->query("ALTER TABLE $wpdb->league ADD point_right TINYINT(1) unsigned NOT NULL DEFAULT '5' AFTER prediction_mod;");
$wpdb->query("ALTER TABLE $wpdb->league ADD point_wrong TINYINT(1) unsigned NOT NULL DEFAULT '0' AFTER point_right;");
$wpdb->query("ALTER TABLE $wpdb->league ADD point_part TINYINT(1) unsigned NOT NULL DEFAULT '1' AFTER point_wrong;");
$wpdb->query("ALTER TABLE $wpdb->league ADD deadline TINYINT(1) unsigned NOT NULL DEFAULT '1' AFTER point_part;");
// ALTER club table
$wpdb->query("ALTER TABLE $wpdb->club MODIFY creation VARCHAR(4) NOT NULL DEFAULT '0000';");
}
// Basic actions to do everytime we upgrade PHPLeague...
if ($current_version < WP_PHPLEAGUE_VERSION)
{
update_option('phpleague_version', WP_PHPLEAGUE_VERSION);
update_option('phpleague_db_version', WP_PHPLEAGUE_DB_VERSION);
}
}
/**
* Define every table
*
* @param none
* @return void
*/
public function define_tables()
{
global $wpdb;
// PHPLeague tables
$wpdb->club = $wpdb->prefix.'phpleague_club';
$wpdb->country = $wpdb->prefix.'phpleague_country';
$wpdb->fixture = $wpdb->prefix.'phpleague_fixture';
$wpdb->league = $wpdb->prefix.'phpleague_league';
$wpdb->match = $wpdb->prefix.'phpleague_match';
$wpdb->table_cache = $wpdb->prefix.'phpleague_table_cache';
$wpdb->team = $wpdb->prefix.'phpleague_team';
$wpdb->player = $wpdb->prefix.'phpleague_player';
$wpdb->player_team = $wpdb->prefix.'phpleague_player_team';
$wpdb->player_data = $wpdb->prefix.'phpleague_player_data';
$wpdb->table_chart = $wpdb->prefix.'phpleague_table_chart';
$wpdb->table_predi = $wpdb->prefix.'phpleague_table_prediction';
}
/**
* Create or update the tables
*
* @param string table name
* @param string sql
* @param integer db version
* @return object
*/
public static function run_install_or_upgrade($table_name, $sql, $db_version)
{
global $wpdb;
// Table does not exist, we create it!
// We use InnoDB and UTF-8 by default
if ($wpdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name)
{
$create = "CREATE TABLE ".$table_name." ( ".$sql." ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;";
// We use the dbDelta method given by WP!
require_once ABSPATH.'wp-admin/includes/upgrade.php';
dbDelta($create);
}
}
/**
* Plugin activation method
*
* @param none
* @return void
*/
public static function activate()
{
global $wpdb;
$db_version = WP_PHPLEAGUE_DB_VERSION;
// Club table
$sql = "id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL DEFAULT '',
id_country smallint(4) unsigned NOT NULL,
venue VARCHAR(100) DEFAULT NULL,
coach VARCHAR(100) DEFAULT NULL,
logo_big VARCHAR(255) DEFAULT NULL,
logo_mini VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name)";
PHPLeague::run_install_or_upgrade($wpdb->club, $sql, $db_version);
// Country table
$sql = "id tinyint(1) unsigned NOT NULL AUTO_INCREMENT,
name VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name)";
PHPLeague::run_install_or_upgrade($wpdb->country, $sql, $db_version);
// Fixture table
$sql = "number tinyint(3) unsigned NOT NULL DEFAULT '0',
scheduled date NOT NULL DEFAULT '0000-00-00',
id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
id_league smallint(5) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY id_league (id_league)";
PHPLeague::run_install_or_upgrade($wpdb->fixture, $sql, $db_version);
// League table
$sql = "id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL DEFAULT '',
year year(4) NOT NULL,
pt_victory tinyint(3) unsigned NOT NULL DEFAULT '3',
pt_draw tinyint(3) unsigned NOT NULL DEFAULT '1',
pt_defeat tinyint(3) unsigned NOT NULL DEFAULT '0',
promotion tinyint(3) unsigned NOT NULL DEFAULT '4',
qualifying tinyint(3) unsigned NOT NULL DEFAULT '2',
relegation tinyint(3) unsigned NOT NULL DEFAULT '3',
id_favorite smallint(4) unsigned NOT NULL DEFAULT '0',
nb_leg tinyint(1) NOT NULL DEFAULT '2',
nb_teams tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id)";
PHPLeague::run_install_or_upgrade($wpdb->league, $sql, $db_version);
// Match table
$sql = "id mediumint(6) unsigned NOT NULL AUTO_INCREMENT,
id_team_home smallint(5) unsigned DEFAULT NULL,
id_team_away smallint(5) unsigned DEFAULT NULL,
played datetime DEFAULT NULL,
id_fixture smallint(5) unsigned DEFAULT NULL,
goal_home tinyint(1) unsigned DEFAULT NULL,
goal_away tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (id),
KEY id_fixture (id_fixture),
KEY id_team_away (id_team_away),
KEY id_team_home (id_team_home)";
PHPLeague::run_install_or_upgrade($wpdb->match, $sql, $db_version);
// Table Cache table
$sql = "club_name VARCHAR(255) DEFAULT NULL,
points smallint(4) unsigned DEFAULT NULL,
played tinyint(3) unsigned DEFAULT NULL,
victory tinyint(3) unsigned DEFAULT NULL,
draw tinyint(3) unsigned DEFAULT NULL,
defeat tinyint(3) unsigned DEFAULT NULL,
goal_for smallint(4) unsigned DEFAULT NULL,
goal_against smallint(4) unsigned DEFAULT NULL,
diff smallint(4) DEFAULT NULL,
pen tinyint(2) DEFAULT NULL,
home_points smallint(4) unsigned DEFAULT NULL,
home_played tinyint(3) unsigned DEFAULT NULL,
home_v tinyint(3) unsigned DEFAULT NULL,
home_d tinyint(3) unsigned DEFAULT NULL,
home_l tinyint(3) unsigned DEFAULT NULL,
home_g_for smallint(4) unsigned DEFAULT NULL,
home_g_against smallint(4) unsigned DEFAULT NULL,
home_diff smallint(4) DEFAULT NULL,
away_points smallint(4) unsigned DEFAULT NULL,
away_played tinyint(3) unsigned DEFAULT NULL,
away_v tinyint(3) unsigned DEFAULT NULL,
away_d tinyint(3) unsigned DEFAULT NULL,
away_l tinyint(3) unsigned DEFAULT NULL,
away_g_for smallint(4) unsigned DEFAULT NULL,
away_g_against smallint(4) unsigned DEFAULT NULL,
away_diff tinyint(4) DEFAULT NULL,
id_team smallint(5) unsigned NOT NULL DEFAULT '0',
id_league smallint(5) unsigned NOT NULL DEFAULT '0',
KEY id_league (id_league)";
PHPLeague::run_install_or_upgrade($wpdb->table_cache, $sql, $db_version);
// Team table
$sql = "id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
id_league smallint(5) unsigned NOT NULL DEFAULT '0',
id_club smallint(5) unsigned NOT NULL DEFAULT '0',
penalty tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY id_club (id_club),
KEY id_league (id_league)";
PHPLeague::run_install_or_upgrade($wpdb->team, $sql, $db_version);
// Player table
$sql = "id smallint(6) unsigned NOT NULL AUTO_INCREMENT,
firstname varchar(100) NOT NULL DEFAULT '',
lastname varchar(100) NOT NULL DEFAULT '',
description text,
birthdate date NOT NULL DEFAULT '0000-00-00',
weight tinyint(1) unsigned NOT NULL DEFAULT '0',
height tinyint(1) unsigned NOT NULL DEFAULT '0',
picture varchar(255) NOT NULL DEFAULT '',
id_country tinyint(1) unsigned NOT NULL DEFAULT '0',
id_term smallint(6) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (id)";
PHPLeague::run_install_or_upgrade($wpdb->player, $sql, $db_version);
// Player data table
$sql = "id_event tinyint(1) unsigned NOT NULL DEFAULT '0',
id_player_team smallint(4) unsigned NOT NULL DEFAULT '0',
id_match smallint(4) unsigned NOT NULL DEFAULT '0',
value tinyint(1) unsigned NOT NULL DEFAULT '0',
KEY id_match (id_match),
KEY id_event (id_event),
KEY id_player_team (id_player_team)";
PHPLeague::run_install_or_upgrade($wpdb->player_data, $sql, $db_version);
// Player team table
$sql = "id smallint(4) unsigned NOT NULL AUTO_INCREMENT,
id_player smallint(4) unsigned NOT NULL DEFAULT '0',
id_team smallint(4) unsigned NOT NULL DEFAULT '0',
number tinyint(1) unsigned NOT NULL DEFAULT '0',
position tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY id_player (id_player),
KEY id_team (id_team)";
PHPLeague::run_install_or_upgrade($wpdb->player_team, $sql, $db_version);
// Charts table
$sql = "id_team mediumint(5) unsigned NOT NULL DEFAULT '0',
fixture tinyint(1) unsigned NOT NULL DEFAULT '0',
ranking tinyint(1) unsigned NOT NULL DEFAULT '0',
KEY id_team (id_team)";
PHPLeague::run_install_or_upgrade($wpdb->table_chart, $sql, $db_version);
// Prediction table
$sql = "id_league smallint(3) unsigned NOT NULL DEFAULT '0',
id_member smallint(3) unsigned NOT NULL DEFAULT '0',
points smallint(3) unsigned NOT NULL DEFAULT '0',
participation smallint(3) unsigned NOT NULL DEFAULT '0',
KEY id_league (id_league),
KEY id_member (id_member)";
// TODO - Add 'type of ranking (monthly, weekly, yearly, ...)' field later
// TODO - Give possibility to predict the score too...
PHPLeague::run_install_or_upgrade($wpdb->table_predi, $sql, $db_version);
// Countries listing
$countries = array(
1 => 'Afghanistan',
2 => 'Zaire',
3 => 'Albania',
4 => 'Algeria',
5 => 'American Samoa',
6 => 'Andorra',
7 => 'Angola',
8 => 'Anguilla',
9 => 'Antarctica',
10 => 'Antigua and Barbuda',
11 => 'Argentina',
12 => 'Armenia',
13 => 'Aruba',
14 => 'Australia',
15 => 'Austria',
16 => 'Azerbaijan',
17 => 'Bahamas',
18 => 'Bahrain',
19 => 'Bangladesh',
20 => 'Barbados',
21 => 'Belarus',
22 => 'Belgium',
23 => 'Belize',
24 => 'Benin',
25 => 'Bermuda',
26 => 'Bhutan',
27 => 'Bolivia',
28 => 'Bosnia and Herzegovina',
29 => 'Botswana',
30 => 'Bouvet Island',
31 => 'Brazil',
32 => 'British Indian Ocean territory',
33 => 'Brunei Darussalam',
34 => 'Bulgaria',
35 => 'Burkina Faso',
36 => 'Burundi',
37 => 'Cambodia',
38 => 'Cameroon',
39 => 'Canada',
40 => 'Cape Verde',
41 => 'Cayman Islands',
42 => 'Central African Republic',
43 => 'Chad',
44 => 'Chile',
45 => 'China',
46 => 'Christmas Island',
47 => 'Cocos Keeling) Islands',
48 => 'Colombia',
49 => 'Comoros',
50 => 'Congo',
51 => 'Zambia',
52 => 'Zimbabwe',
53 => 'Cook Islands',
54 => 'Costa Rica',
55 => 'Ivory Coast',
56 => 'Croatia',
57 => 'Cuba',
58 => 'Cyprus',
59 => 'Czech Republic',
60 => 'Denmark',
61 => 'Djibouti',
62 => 'Dominica',
63 => 'Dominican Republic',
64 => 'East Timor',
65 => 'Ecuador',
66 => 'Egypt',
67 => 'El Salvador',
68 => 'Equatorial Guinea',
69 => 'Eritrea',
70 => 'Estonia',
71 => 'Ethiopia',
72 => 'Falkland Islands',
73 => 'Faroe Islands',
74 => 'Fiji',
75 => 'Finland',
76 => 'France',
77 => 'French Guiana',
78 => 'French Polynesia',
79 => 'French Southern Territories',
80 => 'Gabon',
81 => 'Gambia',
82 => 'Georgia',
83 => 'Germany',
84 => 'Ghana',
85 => 'Gibraltar',
86 => 'Greece',
87 => 'Greenland',
88 => 'Grenada',
89 => 'Guadeloupe',
90 => 'Guam',
91 => 'Guatemala',
92 => 'Guinea',
93 => 'Guinea-Bissau',
94 => 'Guyana',
95 => 'Haiti',
96 => 'Heard and McDonald Islands',
97 => 'Honduras',
98 => 'Hong Kong',
99 => 'Hungary',
100 => 'Iceland',
101 => 'India',
102 => 'Indonesia',
103 => 'Iran',
104 => 'Iraq',
105 => 'Ireland',
106 => 'Israel',
107 => 'Italy',
108 => 'Jamaica',
109 => 'Japan',
110 => 'Jordan',
111 => 'Kazakhstan',
112 => 'Kenya',
113 => 'Kiribati',
114 => 'North Korea',
115 => 'South Korea',
116 => 'Kuwait',
117 => 'Kyrgyzstan',
118 => 'Laos',
119 => 'Latvia',
120 => 'Lebanon',
121 => 'Lesotho',
122 => 'Liberia',
123 => 'Libyan Arab Jamahiriya',
124 => 'Liechtenstein',
125 => 'Lithuania',
126 => 'Luxembourg',
127 => 'Macao',
128 => 'Macedonia',
129 => 'Madagascar',
130 => 'Malawi',
131 => 'Malaysia',
132 => 'Maldives',
133 => 'Mali',
134 => 'Malta',
135 => 'Marshall Islands',
136 => 'Martinique',
137 => 'Mauritania',
138 => 'Mauritius',
139 => 'Mayotte',
140 => 'Mexico',
141 => 'Micronesia',
142 => 'Moldova',
143 => 'Monaco',
144 => 'Mongolia',
145 => 'Montserrat',
146 => 'Morocco',
147 => 'Mozambique',
148 => 'Myanmar',
149 => 'Namibia',
150 => 'Nauru',
151 => 'Nepal',
152 => 'Netherlands',
153 => 'Netherlands Antilles',
154 => 'New Caledonia',
155 => 'New Zealand',
156 => 'Nicaragua',
157 => 'Niger',
158 => 'Nigeria',
159 => 'Niue',
160 => 'Norfolk Island',
161 => 'Northern Mariana Islands',
162 => 'Norway',
163 => 'Oman',
164 => 'Pakistan',
165 => 'Palau',
166 => 'Palestinian Territories',
167 => 'Panama',
168 => 'Papua New Guinea',
169 => 'Paraguay',
170 => 'Peru',
171 => 'Philippines',
172 => 'Pitcairn',
173 => 'Poland',
174 => 'Portugal',
175 => 'Puerto Rico',
176 => 'Qatar',
177 => 'Réunion',
178 => 'Romania',
179 => 'Russia',
180 => 'Rwanda',
181 => 'Saint Helena',
182 => 'Saint Kitts and Nevis',
183 => 'Saint Lucia',
184 => 'Saint Pierre and Miquelon',
185 => 'Saint Vincent and the Grenadines',
186 => 'Samoa',
187 => 'San Marino',
188 => 'Sao Tome and Principe',
189 => 'Saudi Arabia',
190 => 'Senegal',
191 => 'Serbia and Montenegro',
192 => 'Seychelles',
193 => 'Sierra Leone',
194 => 'Singapore',
195 => 'Slovakia',
196 => 'Slovenia',
197 => 'Solomon Islands',
198 => 'Somalia',
199 => 'South Africa',
200 => 'Yemen',
201 => 'Spain',
202 => 'Sri Lanka',
203 => 'Sudan',
204 => 'Suriname',
205 => 'Svalbard and Jan Mayen Islands',
206 => 'Swaziland',
207 => 'Sweden',
208 => 'Switzerland',
209 => 'Syria',
210 => 'Taiwan',
211 => 'Tajikistan',
212 => 'Tanzania',
213 => 'Thailand',
214 => 'Togo',
215 => 'Tokelau',
216 => 'Tonga',
217 => 'Trinidad and Tobago',
218 => 'Tunisia',
219 => 'Turkey',
220 => 'Turkmenistan',
221 => 'Turks and Caicos Islands',
222 => 'Tuvalu',
223 => 'Uganda',
224 => 'Ukraine',
225 => 'United Arab Emirates',
226 => 'United Kingdom',
227 => 'United States of America',
228 => 'Uruguay',
229 => 'Uzbekistan',
230 => 'Vanuatu',
231 => 'Vatican City',
232 => 'Venezuela',
233 => 'Vietnam',
234 => 'Virgin Islands British',
235 => 'Virgin Islands US',
236 => 'Wallis and Futuna Islands',
237 => 'Western Sahara',
238 => 'England',
239 => 'Wales',
240 => 'Northern Ireland',
241 => 'Scotland'
);
// Add every country in the database
foreach ($countries as $key => $country)
{
$wpdb->query("INSERT INTO $wpdb->country VALUES($key, '".$country."');");
}
// Create the PHPLeague directory and sub-directories
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH, 'create');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'logo_big/', 'create');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'logo_mini/', 'create');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'players/', 'create');
// Save versions
add_option('phpleague_version', WP_PHPLEAGUE_VERSION);
add_option('phpleague_db_version', $db_version);
add_option('phpleague_do_activation_redirect', TRUE);
}
/**
* Uninstall plugin method
*
* @param none
* @return void
*/
public static function uninstall()
{
global $wpdb;
// PHPLeague tables
$tables = array(
$wpdb->fixture,
$wpdb->league,
$wpdb->club,
$wpdb->country,
$wpdb->match,
$wpdb->table_cache,
$wpdb->team,
$wpdb->player,
$wpdb->player_team,
$wpdb->player_data,
$wpdb->table_chart,
$wpdb->table_predi
);
// Delete each table one by one
foreach ($tables as $table)
{
$wpdb->query('DROP TABLE IF EXISTS '.$table.';');
}
// Delete the versions in the options table
delete_option('phpleague_version');
delete_option('phpleague_db_version');
// Delete the PHPLeague directory and sub-directories
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH, 'delete');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'logo_big/', 'delete');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'logo_mini/', 'delete');
PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH.'players/', 'delete');
}
/**
* The shortcodes controller
*
* @param mixed $attributes
* @return void
*/
public function shortcodes_controller($attributes)
{
// Extract data
extract(shortcode_atts(
array(
'id' => 1,
'type' => 'table',
'style' => 'general',
'id_team' => '',
'latest' => 'false'
),
$attributes
));
// TODO - In the future, make a specific Front_Controller for every sport.
// Make sure the ID is an integer
$id = (int) $id;
// Get front-end methods
$front = new PHPLeague_Front;
// Display ranking table
if ($type == 'table')
{
if ($style == 'home')
return $front->get_league_table($id, 'home', $latest);
elseif ($style == 'away')
return $front->get_league_table($id, 'away', $latest);
else
return $front->get_league_table($id, 'general', $latest);
}
elseif ($type == 'fixture') // Display fixture table
{
return $front->get_league_fixture($id);
}
elseif ($type == 'fixtures') // Display fixtures table
{
if ( ! empty($id_team))
return $front->get_league_fixtures($id, $id_team);
else
return $front->get_league_fixtures($id);
}
elseif ($type == 'club') // Display club information
{
return $front->get_club_information($id);
}
else // Display ranking table by default
{
return $front->get_league_table($id);
}
}
}
// Let's get it started!
$phpleague = new PHPLeague;
}