This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.php
executable file
·292 lines (225 loc) · 8.79 KB
/
plugin.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
<?php
/**
* @wordpress-plugin
* Plugin Name: jPlayer Podcast Widget
* Plugin URI: http://ycfreeman.com
* Description: Widget that use jPlayer to play Podcast RSS playlists
* Version: 1.0.3
* Author: Freeman Man
* Author URI: http://ycfreeman.com
* Text Domain: jplayer-podcast
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: https://github.com/ycfreeman/jplayer-podcast-wordpress-widget
*
* @package JPlayer_Podcast
* @author Freeman Man <freeman@ycfreeman.com>
* @license GPL-2.0+
* @link http://ycfreeman.com
* @copyright 2016 ycfreeman.com
*
*/
$swfPath = plugins_url("jplayer/jplayer/jquery.jplayer.swf", __FILE__);
$podcastParserPath = plugins_url("assets/podparser.php", __FILE__);
// Prevent direct file access
if (!defined('ABSPATH')) {
exit;
}
class JPlayer_Podcast extends WP_Widget
{
/**
*
* Unique identifier for your widget.
*
*
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* widget file.
*
* @since 1.0.0
*
* @var string
*/
protected $widget_slug = 'jplayer-podcast';
/*--------------------------------------------------*/
/* Constructor
/*--------------------------------------------------*/
/**
* Specifies the classname and description, instantiates the widget,
* loads localization files, and includes necessary stylesheets and JavaScript.
*/
public function __construct()
{
// load plugin text domain
add_action('init', array($this, 'widget_textdomain'));
// Hooks fired when the Widget is activated and deactivated
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
parent::__construct(
$this->get_widget_slug(),
__('jPlayer Podcast', $this->get_widget_slug()),
array(
'classname' => $this->get_widget_slug() . '-class',
'description' => __('Widget that use jPlayer to play Podcast RSS', $this->get_widget_slug())
)
);
// Register admin styles and scripts
add_action('admin_print_styles', array($this, 'register_admin_styles'));
add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts'));
// Register site styles and scripts
add_action('wp_enqueue_scripts', array($this, 'register_widget_styles'));
add_action('wp_enqueue_scripts', array($this, 'register_widget_scripts'));
// Refreshing the widget's cached output with each new post
add_action('save_post', array($this, 'flush_widget_cache'));
add_action('deleted_post', array($this, 'flush_widget_cache'));
add_action('switch_theme', array($this, 'flush_widget_cache'));
} // end constructor
/**
* Return the widget slug.
*
* @since 1.0.0
*
* @return Plugin slug variable.
*/
public function get_widget_slug()
{
return $this->widget_slug;
}
/*--------------------------------------------------*/
/* Widget API Functions
/*--------------------------------------------------*/
/**
* Outputs the content of the widget.
*
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget($args, $instance)
{
// Check if there is a cached output
$cache = wp_cache_get($this->get_widget_slug(), 'widget');
if (!is_array($cache))
$cache = array();
if (!isset ($args['widget_id']))
$args['widget_id'] = $this->id;
$widgetId = $args['widget_id'];
if (isset ($cache[$args['widget_id']]))
return print $cache[$args['widget_id']];
// go on with your widget logic, put everything into a string and …
extract($args, EXTR_SKIP);
$widget_string = $before_widget;
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title']);
/* Display the widget title if one was input (before and after defined by themes). */
if (!empty($title)) {
$widget_string .= $before_title . $title . $after_title;
}
ob_start();
include(plugin_dir_path(__FILE__) . 'views/widget.php');
$widget_string .= ob_get_clean();
$widget_string .= $after_widget;
$cache[$args['widget_id']] = $widget_string;
wp_cache_set($this->get_widget_slug(), $cache, 'widget');
print $widget_string;
} // end widget
public function flush_widget_cache()
{
wp_cache_delete($this->get_widget_slug(), 'widget');
}
/**
* Processes the widget's options to be saved.
*
* @param array new_instance The new instance of values to be generated via the update.
* @param array old_instance The previous instance of values before the update.
*/
public function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['url'] = strip_tags($new_instance['url']);
$instance['count'] = strip_tags($new_instance['count']);
$instance['autoplay'] = strip_tags($new_instance['autoplay']);
$instance['corsenabled'] = strip_tags($new_instance['corsenabled']);
return $instance;
} // end widget
/**
* Generates the administration form for the widget.
*
* @param array instance The array of keys and values for the widget.
*/
public function form($instance)
{
$defaults = array(
'title' => '',
'url' => '',
'count' => 20,
'autoplay' => 1,
'corsenabled' => 0
);
$instance = wp_parse_args(
(array)$instance, $defaults
);
// Display the admin form
include(plugin_dir_path(__FILE__) . 'views/admin.php');
} // end form
/*--------------------------------------------------*/
/* Public Functions
/*--------------------------------------------------*/
/**
* Loads the Widget's text domain for localization and translation.
*/
public function widget_textdomain()
{
load_plugin_textdomain($this->get_widget_slug(), false, plugin_dir_path(__FILE__) . 'lang/');
} // end widget_textdomain
/**
* 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)
{
} // 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)
{
} // 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__));
wp_enqueue_style($this->get_widget_slug() . "-widget-styles-theme-font",
plugins_url("jplayer/skin/pixels/css/themicons.css", __FILE__));
wp_enqueue_style($this->get_widget_slug() . "-widget-styles-theme",
plugins_url("jplayer/skin/pixels/css/style.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-jplayer', plugins_url('jplayer/jplayer/jquery.jplayer.min.js', __FILE__), array('jquery'));
wp_enqueue_script($this->get_widget_slug() . '-script-jplayer-playlist', plugins_url('jplayer/add-on/jplayer.playlist.min.js', __FILE__), array('jquery'));
} // end register_widget_scripts
} // end class
add_action('widgets_init', create_function('', 'register_widget("JPlayer_Podcast");'));