-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldcup-widget.php
More file actions
executable file
·171 lines (137 loc) · 4.74 KB
/
worldcup-widget.php
File metadata and controls
executable file
·171 lines (137 loc) · 4.74 KB
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
<?php
/**
* WorldCup Widget Plugin
*
* Built with help from The WordPress Widget Boilerplate by Tom McFarlin
* :: https://github.com/tommcfarlin/WordPress-Widget-Boilerplate
*
* @package WorldCup Widget
* @author Eric Katz <eric@30lines.com>
* @license GPL-2.0+
* @link http://30lines.com
* @copyright 2014 30 Lines
*
* @worldcup-widget
* Plugin Name: WorldCup Widget
* Plugin URI: http://30lines.com
* Description:
* Version: 1.0.4
* Author: Eric Katz
* Author URI: http://ericnkatz.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: https://github.com/30lines/worldcup-widget
*
*/
class WorldCup_Widget extends WP_Widget {
/**
* @since 1.0.0
*
* @var string
*/
protected $widget_slug = 'worldcup-widget';
protected $api_key = '1c8265af34f7d6e618888652d32b20b6';
/**
* Return the team by searching specific identifier.
*
* @since 1.0.0
*
* @return Team from API/Cache.
*/
public function getTeamByIdentifier($identifier, $teamslist) {
foreach($teamslist as $key => $value) {
$current_key = $key;
if($identifier === $value OR (is_array($value) && $this->getTeamByIdentifier($identifier,$value) !== false)) {
return $current_key;
}
}
return false;
}
/**
* Return json decoded array from API.
*
* @since 1.0.0
*
* @return Array any API call. Default is teams list sorted alphabetically.
*/
public function worldcup_api_call($request = 'teams', $parameters = '&sort=name') {
$url = 'http://worldcup.kimonolabs.com/api/' . $request . '?apikey=' . $this->api_key . $parameters;
$response = get_transient($url);
if($response) {
$r = json_decode($response, TRUE);
return $r;
}
$response = file_get_contents($url);
$saveForLater = set_transient($url, $response, 3 * 60);
$r = json_decode($response, TRUE);
return $r;
}
/**
* Return the widget slug.
*
* @since 1.0.0
*
* @return Plugin slug variable.
*/
public function get_widget_slug() {
return $this->widget_slug;
}
public function get_widget_path() {
return plugin_dir_path( __FILE__ );
}
public function flush_widget_cache()
{
wp_cache_delete( $this->get_widget_slug(), 'widget' );
}
/*--------------------------------------------------*/
/* Public Functions
/*--------------------------------------------------*/
/**
* Fired when the plugin is activated.
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
*/
public function activate( $network_wide ) {
// TODO define activation functionality here
} // end activate
/**
* Fired when the plugin is deactivated.
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
*/
public function deactivate( $network_wide ) {
// TODO define deactivation functionality here
} // end deactivate
/**
* Registers and enqueues admin-specific styles.
*/
public function register_admin_styles() {
wp_enqueue_style( $this->get_widget_slug().'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ) );
} // end register_admin_styles
/**
* Registers and enqueues admin-specific JavaScript.
*/
public function register_admin_scripts() {
wp_enqueue_script( $this->get_widget_slug().'-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array('jquery') );
} // end register_admin_scripts
/**
* Registers and enqueues widget-specific styles.
*/
public function register_widget_styles() {
wp_enqueue_style( $this->get_widget_slug().'-widget-styles', plugins_url( 'css/widget.css', __FILE__ ) );
} // end register_widget_styles
/**
* Registers and enqueues widget-specific scripts.
*/
public function register_widget_scripts() {
wp_enqueue_script( $this->get_widget_slug().'-script', plugins_url( 'js/widget.js', __FILE__ ), array('jquery') );
} // end register_widget_scripts
} // end class
// Include actual widget files
include( plugin_dir_path(__FILE__) . 'widgets/widget-main.php' );
include( plugin_dir_path(__FILE__) . 'widgets/widget-scorers.php' );
include( plugin_dir_path(__FILE__) . 'widgets/widget-groups.php' );
// Create the widgets
add_action( 'widgets_init', create_function( '', 'register_widget("WorldCup_Widget_Main");' ) );
add_action( 'widgets_init', create_function( '', 'register_widget("WorldCup_Widget_Scorers");' ) );
add_action( 'widgets_init', create_function( '', 'register_widget("WorldCup_Widget_Groups");' ) );