Version Description
(2014-07-25) = * Add: admin notices after upgrade to prevent errors and avare users to do ReCache and prevent mixed json_decode / base64_encode strings for cached feeds * Change: moved ReCache part to Tools tab on settings page
Download this release
Release Info
Developer | urkekg |
Plugin | YouTube Channel |
Version | 2.2.2 |
Comparing to | |
See all releases |
Code changes from version 2.2.1 to 2.2.2
- assets/settings.php +20 -0
- assets/settings_help.php +0 -20
- assets/settings_tools.php +19 -0
- readme.txt +9 -32
- youtube-channel.php +83 -66
assets/settings.php
CHANGED
@@ -8,6 +8,7 @@ if(class_exists('WPAU_YOUTUBE_CHANNEL') && !class_exists('WPAU_YOUTUBE_CHANNEL_S
|
|
8 |
private $video_settings_key = 'ytc_video';
|
9 |
private $content_settings_key = 'ytc_content';
|
10 |
private $link_settings_key = 'ytc_link';
|
|
|
11 |
private $help_settings_key = 'ytc_help';
|
12 |
private $plugin_options_key = 'youtube_channel_defaults';
|
13 |
private $plugin_settings_page = YTCTDOM;
|
@@ -25,6 +26,7 @@ if(class_exists('WPAU_YOUTUBE_CHANNEL') && !class_exists('WPAU_YOUTUBE_CHANNEL_S
|
|
25 |
add_action('admin_init', array( &$this, 'register_video_settings' ) );
|
26 |
add_action('admin_init', array( &$this, 'register_content_settings' ) );
|
27 |
add_action('admin_init', array( &$this, 'register_link_settings' ) );
|
|
|
28 |
add_action('admin_init', array( &$this, 'register_help_settings' ) );
|
29 |
|
30 |
add_action('admin_menu', array( &$this, 'add_menu' ) );
|
@@ -515,6 +517,20 @@ if(class_exists('WPAU_YOUTUBE_CHANNEL') && !class_exists('WPAU_YOUTUBE_CHANNEL_S
|
|
515 |
);
|
516 |
} // END register_link_settings()
|
517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
function register_help_settings()
|
519 |
{
|
520 |
$this->plugin_settings_tabs[$this->help_settings_key] = 'Help';
|
@@ -559,6 +575,10 @@ if(class_exists('WPAU_YOUTUBE_CHANNEL') && !class_exists('WPAU_YOUTUBE_CHANNEL_S
|
|
559 |
// Think of this as help text for the section.
|
560 |
_e('<p>Default settings for channel link at the bottom of video block. This will be used as default values for shortcode.</p>',YTCTDOM);
|
561 |
}
|
|
|
|
|
|
|
|
|
562 |
public function help_settings_section()
|
563 |
{
|
564 |
include('settings_help.php');
|
8 |
private $video_settings_key = 'ytc_video';
|
9 |
private $content_settings_key = 'ytc_content';
|
10 |
private $link_settings_key = 'ytc_link';
|
11 |
+
private $tools_settings_key = 'ytc_tools';
|
12 |
private $help_settings_key = 'ytc_help';
|
13 |
private $plugin_options_key = 'youtube_channel_defaults';
|
14 |
private $plugin_settings_page = YTCTDOM;
|
26 |
add_action('admin_init', array( &$this, 'register_video_settings' ) );
|
27 |
add_action('admin_init', array( &$this, 'register_content_settings' ) );
|
28 |
add_action('admin_init', array( &$this, 'register_link_settings' ) );
|
29 |
+
add_action('admin_init', array( &$this, 'register_tools_settings' ) );
|
30 |
add_action('admin_init', array( &$this, 'register_help_settings' ) );
|
31 |
|
32 |
add_action('admin_menu', array( &$this, 'add_menu' ) );
|
517 |
);
|
518 |
} // END register_link_settings()
|
519 |
|
520 |
+
function register_tools_settings()
|
521 |
+
{
|
522 |
+
$this->plugin_settings_tabs[$this->tools_settings_key] = 'Tools';
|
523 |
+
register_setting($this->help_settings_key, $this->help_settings_key);
|
524 |
+
|
525 |
+
add_settings_section(
|
526 |
+
'tools_settings',
|
527 |
+
__('Tools',YTCTDOM),
|
528 |
+
array(&$this, 'tools_settings_section'),
|
529 |
+
$this->tools_settings_key
|
530 |
+
);
|
531 |
+
|
532 |
+
} // END register_help_settings()
|
533 |
+
|
534 |
function register_help_settings()
|
535 |
{
|
536 |
$this->plugin_settings_tabs[$this->help_settings_key] = 'Help';
|
575 |
// Think of this as help text for the section.
|
576 |
_e('<p>Default settings for channel link at the bottom of video block. This will be used as default values for shortcode.</p>',YTCTDOM);
|
577 |
}
|
578 |
+
public function tools_settings_section()
|
579 |
+
{
|
580 |
+
include('settings_tools.php');
|
581 |
+
}
|
582 |
public function help_settings_section()
|
583 |
{
|
584 |
include('settings_help.php');
|
assets/settings_help.php
CHANGED
@@ -60,23 +60,3 @@
|
|
60 |
|
61 |
<p>Please note, you can exclude all options listed above, and then we'll use default options from Settings page.</p>
|
62 |
<p>YTC blocks inserted through widget have own settings.</p>
|
63 |
-
<h3>Caching</h3>
|
64 |
-
<p>To avoid page load slowdown, we provide internal YouTube Channel caching. You can enable caching per widget or shortcode, and set how long cache for particular widget or shortcode will live.</p>
|
65 |
-
<p>If you wish to clear cache before it expire (for example, you have set cache timeout to 2 days, but wish to force loading of fresh channel or playlist feed) for particular widget or shortcode, you can use form below instead to manually remove transients from database.</p>
|
66 |
-
|
67 |
-
<form name="ytc_recache">
|
68 |
-
<label for="slug">Enter relative URL to page where you display target YTC block (include starting and ending slash): <input name="recache_slug" id="recache_slug" value="" /></label>
|
69 |
-
<input type="submit" name="do_recache" id="do_recache" value="ReCache" class="button button-secondary" /> <span id="recache_message"></span>
|
70 |
-
</form>
|
71 |
-
<script type="text/javascript">
|
72 |
-
jQuery(document).ready(function($){
|
73 |
-
$('#do_recache').on('click', function(ev){
|
74 |
-
ev.preventDefault();
|
75 |
-
if ( $('#recache_slug').val() == '' ) {
|
76 |
-
$('#recache_message').html("Please type relative path and try again!").show().delay(3000).fadeOut(700);
|
77 |
-
} else {
|
78 |
-
window.open( $('#recache_slug').val()+'?ytc_force_recache=1' );
|
79 |
-
}
|
80 |
-
});
|
81 |
-
});
|
82 |
-
</script>
|
60 |
|
61 |
<p>Please note, you can exclude all options listed above, and then we'll use default options from Settings page.</p>
|
62 |
<p>YTC blocks inserted through widget have own settings.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/settings_tools.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>To avoid page load slowdown, we provide internal YouTube Channel caching functionality. You can enable caching per widget or shortcode, and set how long cached feed for particular widget or shortcode will live.</p>
|
2 |
+
<p>If you wish to force clear cache before it expires (for example, you have set cache timeout to 2 days, but wish to force loading of fresh channel or playlist feed), you can use form below instead to manually remove transients from database.</p>
|
3 |
+
|
4 |
+
<form name="ytc_recache">
|
5 |
+
<label for="slug">Enter relative URL to page where you display target YTC block (include starting and ending slash): <input name="recache_slug" id="recache_slug" value="" /></label>
|
6 |
+
<input type="submit" name="do_recache" id="do_recache" value="ReCache" class="button button-secondary" /> <span id="recache_message"></span>
|
7 |
+
</form>
|
8 |
+
<script type="text/javascript">
|
9 |
+
jQuery(document).ready(function($){
|
10 |
+
$('#do_recache').on('click', function(ev){
|
11 |
+
ev.preventDefault();
|
12 |
+
if ( $('#recache_slug').val() == '' ) {
|
13 |
+
$('#recache_message').html("Please type relative path and try again!").show().delay(3000).fadeOut(700);
|
14 |
+
} else {
|
15 |
+
window.open( $('#recache_slug').val()+'?ytc_force_recache=1' );
|
16 |
+
}
|
17 |
+
});
|
18 |
+
});
|
19 |
+
</script>
|
readme.txt
CHANGED
@@ -4,11 +4,11 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: youtube, channel, playlist, single, widget, widgets, youtube player, flash player, rss, feed, video, thumbnail, embed, sidebar, chromeless, iframe, html5
|
5 |
Requires at least: 3.8.0
|
6 |
Tested up to: 4.0
|
7 |
-
Stable tag: 2.2.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
-
|
12 |
|
13 |
== Description ==
|
14 |
|
@@ -81,7 +81,7 @@ You can use the built in installer and upgrader, or you can install the plugin m
|
|
81 |
|
82 |
1. You can either use the automatic plugin installer or your FTP program to upload unziped `youtube-channel` directory to your `wp-content/plugins` directory.
|
83 |
2. Activate the plugin through the `Plugins` menu in WordPress
|
84 |
-
3. Add YouTube Channel widget to
|
85 |
4. Set channel name and save changes
|
86 |
|
87 |
If you have to upgrade manually simply repeat the installation steps and re-enable the plugin.
|
@@ -120,7 +120,11 @@ Video feed for YTC has been retreived with standard youtube feed [uploads by spe
|
|
120 |
If you does not see your latest video in your uplaods feed (which you can access at https://gdata.youtube.com/feeds/api/users/YOUR_YT_USERID/uploads by replacing YOUR_YT_USERID with your real youtube user ID), then YTC will not see it too.
|
121 |
|
122 |
== Changelog ==
|
123 |
-
= 2.2.
|
|
|
|
|
|
|
|
|
124 |
* Fix: to prevent broken JSON feed, transient caching changed from plain serialized string to base64_encode
|
125 |
* Add: URL parameter `ytc_force_recache` to force recache, also included on Help tab in plugin settings
|
126 |
|
@@ -243,35 +247,8 @@ If you does not see your latest video in your uplaods feed (which you can access
|
|
243 |
* Initial release
|
244 |
|
245 |
== Upgrade Notice ==
|
246 |
-
= 2.2.1 =
|
247 |
-
Because we changed caching method, from Help tab on plugin Settings page do ReCache (read help page).
|
248 |
-
|
249 |
-
= 0.1.3 =
|
250 |
-
After upgrade check widget options.
|
251 |
-
|
252 |
-
= 0.1.2 =
|
253 |
-
After upgrade set option for random video from channel.
|
254 |
-
|
255 |
-
= 0.1.1 =
|
256 |
-
After upgrade please reconfigure widget. Some variables are changed and implemented new features.
|
257 |
-
|
258 |
-
= 0.1.0 =
|
259 |
-
Just try it and rate it. Only initial release is available right now.
|
260 |
-
|
261 |
-
== Upgrade Notice ==
|
262 |
-
|
263 |
-
= 2.1.0.2 =
|
264 |
-
|
265 |
-
Fixed broken IFRAME type implementation.
|
266 |
-
|
267 |
-
= 2.1.0 =
|
268 |
-
|
269 |
-
Before you upgrade to this version, BACKUP DATABASE because experimental transition code converts YouTube Channel widgets made in versions prior to 2.0.0 to new format. You can lose all predefined YTC widgets.
|
270 |
-
|
271 |
-
= 2.0.0 =
|
272 |
|
273 |
-
|
274 |
-
We highly recommend to you made database backup before you upgrade to latest version 2.0.0.
|
275 |
|
276 |
== Screenshots ==
|
277 |
|
4 |
Tags: youtube, channel, playlist, single, widget, widgets, youtube player, flash player, rss, feed, video, thumbnail, embed, sidebar, chromeless, iframe, html5
|
5 |
Requires at least: 3.8.0
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 2.2.2
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
+
Show video thumbnails or playable blocks of recent videos from YouTube Channel or Playlist.
|
12 |
|
13 |
== Description ==
|
14 |
|
81 |
|
82 |
1. You can either use the automatic plugin installer or your FTP program to upload unziped `youtube-channel` directory to your `wp-content/plugins` directory.
|
83 |
2. Activate the plugin through the `Plugins` menu in WordPress
|
84 |
+
3. Add YouTube Channel widget to sidebar
|
85 |
4. Set channel name and save changes
|
86 |
|
87 |
If you have to upgrade manually simply repeat the installation steps and re-enable the plugin.
|
120 |
If you does not see your latest video in your uplaods feed (which you can access at https://gdata.youtube.com/feeds/api/users/YOUR_YT_USERID/uploads by replacing YOUR_YT_USERID with your real youtube user ID), then YTC will not see it too.
|
121 |
|
122 |
== Changelog ==
|
123 |
+
= 2.2.2 (2014-07-25) =
|
124 |
+
* Add: admin notices after upgrade to prevent errors and avare users to do ReCache and prevent mixed json_decode / base64_encode strings for cached feeds
|
125 |
+
* Change: moved ReCache part to Tools tab on settings page
|
126 |
+
|
127 |
+
= 2.2.1 (2014-07-13) =
|
128 |
* Fix: to prevent broken JSON feed, transient caching changed from plain serialized string to base64_encode
|
129 |
* Add: URL parameter `ytc_force_recache` to force recache, also included on Help tab in plugin settings
|
130 |
|
247 |
* Initial release
|
248 |
|
249 |
== Upgrade Notice ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
+
Better handling of cached UNICODE content, ReCache tool to force reloading cached feeds.
|
|
|
252 |
|
253 |
== Screenshots ==
|
254 |
|
youtube-channel.php
CHANGED
@@ -4,10 +4,10 @@ Plugin Name: YouTube Channel
|
|
4 |
Plugin URI: http://urosevic.net/wordpress/plugins/youtube-channel/
|
5 |
Description: <a href="widgets.php">Widget</a> that display latest video thumbnail, iframe (HTML5 video), object (Flash video) or chromeless video from YouTube Channel or Playlist.
|
6 |
Author: Aleksandar Urošević
|
7 |
-
Version: 2.2.
|
8 |
Author URI: http://urosevic.net/
|
9 |
*/
|
10 |
-
define( 'YTCVER', '2.2.
|
11 |
define( 'YOUTUBE_CHANNEL_URL', plugin_dir_url(__FILE__) );
|
12 |
define( 'YTCPLID', 'PLEC850BE962234400' );
|
13 |
define( 'YTCUID', 'urkekg' );
|
@@ -17,27 +17,44 @@ define( 'YTCNAME', 'YouTube Channel' );
|
|
17 |
/* youtube widget */
|
18 |
class WPAU_YOUTUBE_CHANNEL extends WP_Widget {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
// if ( is_admin() ){ // admin actions
|
23 |
-
// add_action( 'admin_menu', array($this,'add_admin_menu') );
|
24 |
-
// }
|
25 |
-
|
26 |
-
// Initialize Settings
|
27 |
-
require_once(sprintf("%s/assets/settings.php", dirname(__FILE__)));
|
28 |
|
29 |
add_shortcode( 'youtube_channel', array($this, 'youtube_channel_shortcode') );
|
30 |
-
|
31 |
parent::__construct(
|
32 |
-
|
33 |
__( 'Youtube Channel' , YTCTDOM ),
|
34 |
array( 'description' => __( 'Serve YouTube videos from channel or playlist right to widget area', YTCTDOM ) )
|
35 |
);
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
}
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
public static function defaults()
|
42 |
{
|
43 |
$defaults = array(
|
@@ -72,32 +89,32 @@ class WPAU_YOUTUBE_CHANNEL extends WP_Widget {
|
|
72 |
'popup_goto' => 3, // 3 same window, 2 new window JS, 1 new window target
|
73 |
'userchan' => false
|
74 |
);
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
}
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
// get pre-2.0.0 YTC widgets, and if exist, convert to 2.0.0+ version
|
88 |
if ( $old = get_option('widget_youtube_channel_widget') ) {
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
$widget_areas = get_option('sidebars_widgets');
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
foreach ($old as $k=>$v) {
|
99 |
-
|
100 |
-
if ( $k !== "_multiwidget" ){
|
101 |
// option for resource
|
102 |
$v['use_res'] = 0;
|
103 |
if ( $v['usepl'] == "on" ) {
|
@@ -140,30 +157,30 @@ class WPAU_YOUTUBE_CHANNEL extends WP_Widget {
|
|
140 |
if ( $ytc_widget_added == 0 )
|
141 |
array_push($widget_areas['wp_inactive_widgets'], $ytc_widget_id);
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
} // foreach widget option
|
147 |
-
|
148 |
-
// update widget areas set
|
149 |
-
update_option('sidebars_widgets',$widget_areas);
|
150 |
-
|
151 |
-
// update new YTC widgets
|
152 |
-
update_option('widget_youtube-channel',$new);
|
153 |
-
|
154 |
-
// remove old YTC widgets entry
|
155 |
-
delete_option('widget_youtube_channel_widget');
|
156 |
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
} // if we have old YTC widgets
|
161 |
|
162 |
-
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
$times = array(
|
168 |
'minute' => array(
|
169 |
1 => "1 minute",
|
@@ -222,7 +239,7 @@ class WPAU_YOUTUBE_CHANNEL extends WP_Widget {
|
|
222 |
}
|
223 |
}
|
224 |
return $out;
|
225 |
-
|
226 |
|
227 |
// TODO: Form code
|
228 |
public function form($instance) {
|
@@ -557,14 +574,15 @@ if ( $debugon == 'on' ) {
|
|
557 |
|
558 |
if (!empty($_GET['ytc_force_recache']))
|
559 |
delete_transient($cache_key);
|
|
|
560 |
// get/set transient cache
|
561 |
if ( false === ($json = get_transient($cache_key)) ) {
|
562 |
// no cached JSON, get new
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
|
569 |
// $json = file_get_contents($feed_url,0,null,null);
|
570 |
// set decoded JSON to transient cache_key
|
@@ -576,11 +594,11 @@ if ( $debugon == 'on' ) {
|
|
576 |
} else {
|
577 |
// just get fresh feed if cache disabled
|
578 |
// $json = file_get_contents($feed_url,0,null,null);
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
}
|
585 |
|
586 |
// decode JSON data
|
@@ -660,9 +678,8 @@ if ( $debugon == 'on' ) {
|
|
660 |
|
661 |
if( class_exists('WPAU_YOUTUBE_CHANNEL'))
|
662 |
{
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
|
667 |
/* Load plugin's textdomain */
|
668 |
add_action( 'init', 'youtube_channel_init' ); /*TODO: move inside class*/
|
4 |
Plugin URI: http://urosevic.net/wordpress/plugins/youtube-channel/
|
5 |
Description: <a href="widgets.php">Widget</a> that display latest video thumbnail, iframe (HTML5 video), object (Flash video) or chromeless video from YouTube Channel or Playlist.
|
6 |
Author: Aleksandar Urošević
|
7 |
+
Version: 2.2.2
|
8 |
Author URI: http://urosevic.net/
|
9 |
*/
|
10 |
+
define( 'YTCVER', '2.2.2' );
|
11 |
define( 'YOUTUBE_CHANNEL_URL', plugin_dir_url(__FILE__) );
|
12 |
define( 'YTCPLID', 'PLEC850BE962234400' );
|
13 |
define( 'YTCUID', 'urkekg' );
|
17 |
/* youtube widget */
|
18 |
class WPAU_YOUTUBE_CHANNEL extends WP_Widget {
|
19 |
|
20 |
+
function __construct() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
add_shortcode( 'youtube_channel', array($this, 'youtube_channel_shortcode') );
|
23 |
+
// Initialize Widget
|
24 |
parent::__construct(
|
25 |
+
YTCTDOM,
|
26 |
__( 'Youtube Channel' , YTCTDOM ),
|
27 |
array( 'description' => __( 'Serve YouTube videos from channel or playlist right to widget area', YTCTDOM ) )
|
28 |
);
|
29 |
|
30 |
+
// update YTC version in database on request
|
31 |
+
if ( !empty($_GET['ytc_dismiss_update_notice']) )
|
32 |
+
update_option( 'ytc_version', YTCVER );
|
33 |
+
|
34 |
+
// add dashboard notice if version changed
|
35 |
+
$version = get_option('ytc_version','0');
|
36 |
+
if ( version_compare($version, YTCVER, "<") )
|
37 |
+
add_action( 'admin_notices', array($this, 'admin_notices') );
|
38 |
+
|
39 |
+
// Initialize Settings
|
40 |
+
require_once(sprintf("%s/assets/settings.php", dirname(__FILE__)));
|
41 |
+
|
42 |
+
$WPAU_YOUTUBE_CHANNEL_SETTINGS = new WPAU_YOUTUBE_CHANNEL_SETTINGS();
|
43 |
|
44 |
}
|
45 |
|
46 |
+
function admin_notices()
|
47 |
+
{
|
48 |
+
?>
|
49 |
+
<div class="update-nag">
|
50 |
+
<p>
|
51 |
+
<strong><?php echo YTCNAME; ?></strong> is updated to version <strong><?php echo YTCVER; ?></strong>.
|
52 |
+
If you enabled caching for any YTC widget or shortcode, please <strong>ReCache</strong> feeds at <a href="options-general.php?page=youtube-channel&tab=ytc_tools">Tools</a> tab of settings page.
|
53 |
+
<a href="?ytc_dismiss_update_notice=1" class="button button-secondary">I did this already, dismiss notice!</a>
|
54 |
+
</p>
|
55 |
+
</div>
|
56 |
+
<?php
|
57 |
+
}
|
58 |
public static function defaults()
|
59 |
{
|
60 |
$defaults = array(
|
89 |
'popup_goto' => 3, // 3 same window, 2 new window JS, 1 new window target
|
90 |
'userchan' => false
|
91 |
);
|
92 |
+
|
93 |
+
$options = wp_parse_args(get_option('youtube_channel_defaults'), $defaults);
|
94 |
+
|
95 |
+
return $options;
|
96 |
}
|
97 |
|
98 |
+
/**
|
99 |
+
* Activate the plugin
|
100 |
+
*/
|
101 |
+
public static function activate()
|
102 |
+
{
|
103 |
+
// Transit old settings to new format
|
104 |
// get pre-2.0.0 YTC widgets, and if exist, convert to 2.0.0+ version
|
105 |
if ( $old = get_option('widget_youtube_channel_widget') ) {
|
106 |
+
// if we have pre-2.0.0 YTC widgets, merge them to new version
|
107 |
+
|
108 |
+
// get new YTC widgets
|
109 |
+
$new = get_option('widget_youtube-channel');
|
110 |
+
|
111 |
+
// get all widget areas
|
112 |
$widget_areas = get_option('sidebars_widgets');
|
113 |
+
|
114 |
+
// update options to 2.0.0+ version
|
115 |
+
foreach ($old as $k=>$v) {
|
116 |
|
117 |
+
if ( $k !== "_multiwidget" ){
|
|
|
|
|
|
|
118 |
// option for resource
|
119 |
$v['use_res'] = 0;
|
120 |
if ( $v['usepl'] == "on" ) {
|
157 |
if ( $ytc_widget_added == 0 )
|
158 |
array_push($widget_areas['wp_inactive_widgets'], $ytc_widget_id);
|
159 |
|
160 |
+
}
|
161 |
+
// add to inactive widgets if don't belong to any widget area
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
+
} // foreach widget option
|
164 |
+
|
165 |
+
// update widget areas set
|
166 |
+
update_option('sidebars_widgets',$widget_areas);
|
167 |
+
|
168 |
+
// update new YTC widgets
|
169 |
+
update_option('widget_youtube-channel',$new);
|
170 |
+
|
171 |
+
// remove old YTC widgets entry
|
172 |
+
delete_option('widget_youtube_channel_widget');
|
173 |
+
|
174 |
+
// clear temporary vars
|
175 |
+
unset ($old,$new);
|
176 |
|
177 |
} // if we have old YTC widgets
|
178 |
|
179 |
+
} // END public static function activate
|
180 |
|
181 |
+
// Helper function cache_time()
|
182 |
+
function cache_time($cache_time)
|
183 |
+
{
|
184 |
$times = array(
|
185 |
'minute' => array(
|
186 |
1 => "1 minute",
|
239 |
}
|
240 |
}
|
241 |
return $out;
|
242 |
+
}
|
243 |
|
244 |
// TODO: Form code
|
245 |
public function form($instance) {
|
574 |
|
575 |
if (!empty($_GET['ytc_force_recache']))
|
576 |
delete_transient($cache_key);
|
577 |
+
|
578 |
// get/set transient cache
|
579 |
if ( false === ($json = get_transient($cache_key)) ) {
|
580 |
// no cached JSON, get new
|
581 |
+
$wprga = array(
|
582 |
+
'timeout' => 2 // two seconds only
|
583 |
+
);
|
584 |
+
$response = wp_remote_get($feed_url, $wprga);
|
585 |
+
$json = wp_remote_retrieve_body( $response );
|
586 |
|
587 |
// $json = file_get_contents($feed_url,0,null,null);
|
588 |
// set decoded JSON to transient cache_key
|
594 |
} else {
|
595 |
// just get fresh feed if cache disabled
|
596 |
// $json = file_get_contents($feed_url,0,null,null);
|
597 |
+
$wprga = array(
|
598 |
+
'timeout' => 2 // two seconds only
|
599 |
+
);
|
600 |
+
$response = wp_remote_get($feed_url, $wprga);
|
601 |
+
$json = wp_remote_retrieve_body( $response );
|
602 |
}
|
603 |
|
604 |
// decode JSON data
|
678 |
|
679 |
if( class_exists('WPAU_YOUTUBE_CHANNEL'))
|
680 |
{
|
681 |
+
// Installation and uninstallation hooks
|
682 |
+
register_activation_hook(__FILE__, array('WPAU_YOUTUBE_CHANNEL', 'activate'));
|
|
|
683 |
|
684 |
/* Load plugin's textdomain */
|
685 |
add_action( 'init', 'youtube_channel_init' ); /*TODO: move inside class*/
|