YouTube Embed - Version 1.5

Version Description

  • Added clone of 'youtube' shortcode, called 'youtube_video'
  • Editor now has YouTube button, which inserts the YouTube shortcode (this can be switched off in the options screen)
  • Added new option to disable keyboard controls
  • Added option to supply a ratio, in case height or width are not supplied - the missing parameter will then be calculated
  • Option to create a download link (for video and playlist) using function call or shortcode
  • You can now change on the options screen which set of parameters the demonstration video uses (i.e. "normal" or EmbedPlus). This allows you to try your options on a different video type without switching to it.

=

Download this release

Release Info

Developer dartiss
Plugin Icon 128x128 YouTube Embed
Version 1.5
Comparing to
See all releases

Code changes from version 1.4.2 to 1.5

mcebutton.js ADDED
@@ -0,0 +1 @@
 
1
+ (function(){tinymce.create('tinymce.plugins.youtube',{init:function(ed,url){ed.addButton('YouTube',{title:'YouTube Embed',image:url+'/youtube.png',onclick:function(){ed.selection.setContent('[youtube]'+ed.selection.getContent()+'[/youtube]')}})},createControl:function(n,cm){return null},});tinymce.PluginManager.add('YouTube',tinymce.plugins.youtube)})();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://artiss.co.uk/donate
4
  Tags: YouTube, embed, XHTML, video, playlist, thumbnail, EmbedPlus, widget, shortcode
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
- Stable tag: 1.4.2
8
 
9
  YouTube Embed is a powerful, but simple to use, method of embedding YouTube videos in your WordPress theme.
10
 
@@ -159,6 +159,26 @@ In all of these cases, the original XML format has been changed to a readable ou
159
 
160
  `get_youtube_transcript_xml(ID)`
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  == Parameters ==
163
 
164
  The following parameters can be specified for any embedded YouTube video. Some of these will also work with playlists but, due to a lack of YouTube documentation on the subject, I'm unable to say which they are.
@@ -169,6 +189,7 @@ The following work with a standard video/playlist and an EmbedPlus video...
169
  * *hd* - yes or no, this determines whether a video defaults to HD quality, if available
170
  * *width* - the width of the video in pixels
171
  * *height* - the height of the video in pixels
 
172
  * *fullscreen* - yes or no, this adds a button to the video player, allowing the video to be shown fullscreen
173
  * *start* - this can be specified if you wish for the video not to start at the beginning. Specify a number of seconds
174
 
@@ -186,6 +207,7 @@ The following only work with the standard video/playlist embedding...
186
  * *info* - yes or no, this determines whether video information is shown
187
  * *search* - yes or no, determine whether search box should be shown
188
  * *link* - yes or no, this determines whether the video links back to YouTube
 
189
 
190
  The following are only valid with an EmbedPlus video...
191
 
@@ -232,6 +254,12 @@ If you play a YouTube video, look at the URL - it will probably look something l
232
 
233
  The video ID is the list of letters and numbers after `v=`, in this case `L5Y4qzc_JTg`.
234
 
 
 
 
 
 
 
235
  = Which version of PHP does this plugin work with? =
236
 
237
  It has been tested and been found valid from PHP 4 upwards.
@@ -271,6 +299,15 @@ It has been tested and been found valid from PHP 4 upwards.
271
 
272
  = 1.4.2 =
273
  * Fixed bug which meant that people upgrading from previous versions may not be able to display video until they've been to the options screen and re-saved their default options
 
 
 
 
 
 
 
 
 
274
 
275
  == Upgrade Notice ==
276
 
@@ -296,4 +333,7 @@ It has been tested and been found valid from PHP 4 upwards.
296
  * Upgrade to make a small correction to the parameter lists
297
 
298
  = 1.4.2 =
299
- * Upgrade is you upgraded to version 1.4 or 1.4.1 from a previous version, to fix an important bug
 
 
 
4
  Tags: YouTube, embed, XHTML, video, playlist, thumbnail, EmbedPlus, widget, shortcode
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
+ Stable tag: 1.5
8
 
9
  YouTube Embed is a powerful, but simple to use, method of embedding YouTube videos in your WordPress theme.
10
 
159
 
160
  `get_youtube_transcript_xml(ID)`
161
 
162
+ **Video Download**
163
+
164
+ If you wish your users to be able to download a YouTube video or playlist then you can do this via either a shortcode of PHP function call.
165
+
166
+ The function call is named `get_video_download` or `get_playlist_download` and has one parameter - the video or playlist ID. It will return the download link URL.
167
+
168
+ For example...
169
+
170
+ `<a href="<?php get_video_download('id'); ?>">Download the video</a>`
171
+
172
+ Alternatively, you can use the shortcode `download_video` or `download_playlist`. The content to link is specified between the open and close shortcode tags and there are 3 parameters...
173
+
174
+ *id* - The ID of the video or playlist. This is required.
175
+ *target* - The target of the link (e.g. `_blank`). This is optional.
176
+ *nofollow* - This should be `Yes` or `No` to specify whether a `nofollow` tag should be added to the link. This is optional and by default it will be included.
177
+
178
+ For example...
179
+
180
+ `[download_video id="id" target="_blank"]Download the video[/download_video]`
181
+
182
  == Parameters ==
183
 
184
  The following parameters can be specified for any embedded YouTube video. Some of these will also work with playlists but, due to a lack of YouTube documentation on the subject, I'm unable to say which they are.
189
  * *hd* - yes or no, this determines whether a video defaults to HD quality, if available
190
  * *width* - the width of the video in pixels
191
  * *height* - the height of the video in pixels
192
+ * *ratio* - if the height or width is omitted then it will be calculated with this ratio, in the format w:h (width:height) If this ratio is not supplied or is invalid it will be calculated using your default height and width settings. The ratio can only be specified via the shortcode or function call.
193
  * *fullscreen* - yes or no, this adds a button to the video player, allowing the video to be shown fullscreen
194
  * *start* - this can be specified if you wish for the video not to start at the beginning. Specify a number of seconds
195
 
207
  * *info* - yes or no, this determines whether video information is shown
208
  * *search* - yes or no, determine whether search box should be shown
209
  * *link* - yes or no, this determines whether the video links back to YouTube
210
+ * *disablekb* - yes or not, this is whether you wish the keyboard controls to be disabled or not
211
 
212
  The following are only valid with an EmbedPlus video...
213
 
254
 
255
  The video ID is the list of letters and numbers after `v=`, in this case `L5Y4qzc_JTg`.
256
 
257
+ = I've installed another plugin which also uses the 'youtube' shortcode. How can I use yours too? =
258
+
259
+ Jetpack is a good example of a plugin that can do this - install this and leave the "shortcodes" component active and this plugin may no longer appear to work for you.
260
+
261
+ If the `youtube` shortcode has already been used, an additional code is now available - `youtube_video`. This does the same thing and has the same parameters.
262
+
263
  = Which version of PHP does this plugin work with? =
264
 
265
  It has been tested and been found valid from PHP 4 upwards.
299
 
300
  = 1.4.2 =
301
  * Fixed bug which meant that people upgrading from previous versions may not be able to display video until they've been to the options screen and re-saved their default options
302
+ * Added keyboard disable option
303
+
304
+ = 1.5 =
305
+ * Added clone of 'youtube' shortcode, called 'youtube_video'
306
+ * Editor now has YouTube button, which inserts the YouTube shortcode (this can be switched off in the options screen)
307
+ * Added new option to disable keyboard controls
308
+ * Added option to supply a ratio, in case height or width are not supplied - the missing parameter will then be calculated
309
+ * Option to create a download link (for video and playlist) using function call or shortcode
310
+ * You can now change on the options screen which set of parameters the demonstration video uses (i.e. "normal" or EmbedPlus). This allows you to try your options on a different video type without switching to it.
311
 
312
  == Upgrade Notice ==
313
 
333
  * Upgrade to make a small correction to the parameter lists
334
 
335
  = 1.4.2 =
336
+ * Upgrade is you upgraded to version 1.4 or 1.4.1 from a previous version, to fix an important bug
337
+
338
+ = 1.5 =
339
+ * Upgrade to add a number of new options including video size ratios, disabling keyboard controls, an editor button and different demonstration video options on the admin screen
screenshot-1.png CHANGED
Binary file
youtube-embed-options.php CHANGED
@@ -26,17 +26,25 @@ if(!empty($_POST['Submit'])) {
26
  $options['stop']=$_POST['youtube_embed_stop'];
27
  $options['sweetspot']=$_POST['youtube_embed_sweetspot'];
28
  $options['type']=$_POST['youtube_embed_type'];
 
29
  update_option("youtube_embed",$options);
 
 
30
  }
31
 
 
 
 
32
  // Fetch options into an array
33
  $options=get_option("youtube_embed");
 
34
 
35
  // Set defaults if no array is defined
36
  if (!is_array($options)) {
37
  echo "<div class=\"updated\"><p><strong>Please review the default options below and click \"Save Settings\" to update them.</strong></p></div>\n";
38
- $options = array('width'=>'425','height'=>'355','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1','type'=>'v');
39
  }
 
40
 
41
  // Set default values for new options, if missing
42
  if ($options['link']=="") {$options['link']='1';}
@@ -44,6 +52,7 @@ if ($options['react']=="") {$options['react']='1';}
44
  if ($options['stop']=="") {$options['stop']='0';}
45
  if ($options['sweetspot']=="") {$options['sweetspot']='1';}
46
  if ($options['type']=="") {$options['type']='v';}
 
47
  ?>
48
 
49
  <a href="http://embedplus.com/"><img src="<?php echo WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); ?>embedplus.png" alt="EmbedPlus" title="EmbedPlus" align="right" /></a>
@@ -166,6 +175,13 @@ if ($options['type']=="") {$options['type']='v';}
166
  </select></td>
167
  </tr><tr>
168
 
 
 
 
 
 
 
 
169
  <th style="font-weight: bold" scope="row"><?php _e('EmbedPlus Video Only'); ?></th>
170
  </tr><tr>
171
 
@@ -184,17 +200,39 @@ if ($options['type']=="") {$options['type']='v';}
184
  <option value="1"<?php if ($options['sweetspot']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
185
  <option value="0"<?php if ($options['sweetspot']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
186
  </select></td>
 
 
 
 
187
 
 
 
 
 
 
188
  </tr>
 
189
  </table>
190
  <p class="submit">
191
  <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Settings'); ?>"/>
192
  </p>
193
- </form>
194
 
195
  <h3><?php _e('YouTube Video Sample'); ?></h3>
196
  <p><?php _e('This uses the above settings, once they have been saved. <b>Would you like this to be your video? If so, <a href="http://www.artiss.co.uk/contact">contact me</a>!</b>'); ?></p>
197
- <p><?php youtube_video_embed("ru6219KIKS0"); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  <h3><?php _e('Further Help'); ?></h3>
200
  <?php _e('<p>All of my plugins are supported via <a title="Artiss.co.uk" href="http://www.artiss.co.uk" target="_blank">my website</a>.</p><p>Please feel free to visit the site for plugin updates and development news - either visit the site regularly, follow <a title="RSS News Feed" href="http://www.artiss.co.uk/feed" target="_blank">my news feed</a> or <a title="Artiss.co.uk on Twitter" href="http://www.twitter.com/artiss_tech" target="_blank">follow me on Twitter</a> (@artiss_tech).</p><p>For problems, suggestions or enhancements for this plugin, there is <a title="YouTube Embed" href="http://www.artiss.co.uk/youtube-embed" target="_blank">a dedicated page</a> and <a title="WordPress Plugins Forum" href="http://www.artiss.co.uk/forum" target="_blank">a forum</a>. The dedicated page will also list any known issues and planned enhancements.</p><p>Alternatively, please <a title="Contact Me" href="http://www.artiss.co.uk/contact" target="_blank">contact me directly</a>.</p><p style="font-weight: bold">This plugin, and all support, is supplied for free, but <a title="Donate" href="http://artiss.co.uk/donate" target="_blank">donations</a> are always welcome.</p>'); ?>
26
  $options['stop']=$_POST['youtube_embed_stop'];
27
  $options['sweetspot']=$_POST['youtube_embed_sweetspot'];
28
  $options['type']=$_POST['youtube_embed_type'];
29
+ $options['disablekb']=$_POST['youtube_embed_disablekb'];
30
  update_option("youtube_embed",$options);
31
+ $editor['youtube']=$_POST['youtube_embed_youtube_key'];
32
+ update_option("youtube_embed_editor",$editor);
33
  }
34
 
35
+ // Video option button has been pressed
36
+ if(!empty($_POST['Video'])) {$video_type=$_POST['youtube_embed_video_type'];} else {$video_type="d";}
37
+
38
  // Fetch options into an array
39
  $options=get_option("youtube_embed");
40
+ $editor=get_option("youtube_embed_editor");
41
 
42
  // Set defaults if no array is defined
43
  if (!is_array($options)) {
44
  echo "<div class=\"updated\"><p><strong>Please review the default options below and click \"Save Settings\" to update them.</strong></p></div>\n";
45
+ $options=array('width'=>'425','height'=>'355','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1','type'=>'v','disablekb'=>'0');
46
  }
47
+ if (!is_array($editor)) {$editor=array('youtube'=>'1');}
48
 
49
  // Set default values for new options, if missing
50
  if ($options['link']=="") {$options['link']='1';}
52
  if ($options['stop']=="") {$options['stop']='0';}
53
  if ($options['sweetspot']=="") {$options['sweetspot']='1';}
54
  if ($options['type']=="") {$options['type']='v';}
55
+ if ($options['disablekb']=="") {$options['disablekb']='0';}
56
  ?>
57
 
58
  <a href="http://embedplus.com/"><img src="<?php echo WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); ?>embedplus.png" alt="EmbedPlus" title="EmbedPlus" align="right" /></a>
175
  </select></td>
176
  </tr><tr>
177
 
178
+ <th scope="row"><?php _e('Disable Keyboard Controls'); ?></th>
179
+ <td><select name="youtube_embed_disablekb">
180
+ <option value="0"<?php if (($options['disablekb']=="0")&&($options['disablekb']!="")) {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
181
+ <option value="1"<?php if (($options['disablekb']=="1")or($options['disablekb']=="")) {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
182
+ </select></td>
183
+ </tr><tr>
184
+
185
  <th style="font-weight: bold" scope="row"><?php _e('EmbedPlus Video Only'); ?></th>
186
  </tr><tr>
187
 
200
  <option value="1"<?php if ($options['sweetspot']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
201
  <option value="0"<?php if ($options['sweetspot']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
202
  </select></td>
203
+ </tr><tr>
204
+
205
+ <th style="font-weight: bold" scope="row"><?php _e('Editor Options'); ?></th>
206
+ </tr><tr>
207
 
208
+ <th scope="row"><?php _e('Show YouTube Button'); ?></th>
209
+ <td><select name="youtube_embed_youtube_key">
210
+ <option value="1"<?php if ($editor['youtube']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
211
+ <option value="0"<?php if ($editor['youtube']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
212
+ </select></td>
213
  </tr>
214
+
215
  </table>
216
  <p class="submit">
217
  <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Settings'); ?>"/>
218
  </p>
 
219
 
220
  <h3><?php _e('YouTube Video Sample'); ?></h3>
221
  <p><?php _e('This uses the above settings, once they have been saved. <b>Would you like this to be your video? If so, <a href="http://www.artiss.co.uk/contact">contact me</a>!</b>'); ?></p>
222
+ <p><?php _e('Use the drop-down below to change which parameters the video uses - press the Change Video button to update it.</b>'); ?></p>
223
+ <p><select name="youtube_embed_video_type">
224
+ <option value="d"<?php if ($video_type=="d") {echo " selected='selected'";} ?>><?php _e('Default'); ?></option>
225
+ <option value="p"<?php if ($video_type=="p") {echo " selected='selected'";} ?>><?php _e('EmbedPlus'); ?></option>
226
+ </select>
227
+ <input type="submit" name="Video" class="button-secondary" value="<?php _e('Change video'); ?>"/></p>
228
+
229
+ <p><?php
230
+ if ($video_type=="d") {$id='ru6219KIKS0'; $paras='';}
231
+ if ($video_type=="p") {$id='YVvn8dpSAt0'; $paras='embedplus=yes';}
232
+ youtube_video_embed($id,$paras);
233
+ ?></p>
234
+
235
+ </form>
236
 
237
  <h3><?php _e('Further Help'); ?></h3>
238
  <?php _e('<p>All of my plugins are supported via <a title="Artiss.co.uk" href="http://www.artiss.co.uk" target="_blank">my website</a>.</p><p>Please feel free to visit the site for plugin updates and development news - either visit the site regularly, follow <a title="RSS News Feed" href="http://www.artiss.co.uk/feed" target="_blank">my news feed</a> or <a title="Artiss.co.uk on Twitter" href="http://www.twitter.com/artiss_tech" target="_blank">follow me on Twitter</a> (@artiss_tech).</p><p>For problems, suggestions or enhancements for this plugin, there is <a title="YouTube Embed" href="http://www.artiss.co.uk/youtube-embed" target="_blank">a dedicated page</a> and <a title="WordPress Plugins Forum" href="http://www.artiss.co.uk/forum" target="_blank">a forum</a>. The dedicated page will also list any known issues and planned enhancements.</p><p>Alternatively, please <a title="Contact Me" href="http://www.artiss.co.uk/contact" target="_blank">contact me directly</a>.</p><p style="font-weight: bold">This plugin, and all support, is supplied for free, but <a title="Donate" href="http://artiss.co.uk/donate" target="_blank">donations</a> are always welcome.</p>'); ?>
youtube-embed.php CHANGED
@@ -3,19 +3,23 @@
3
  Plugin Name: YouTube Embed
4
  Plugin URI: http://www.artiss.co.uk/youtube-embed
5
  Description: Embed YouTube Videos in WordPress
6
- Version: 1.4.2
7
  Author: David Artiss
8
  Author URI: http://www.artiss.co.uk
9
  */
10
- define('youtube_embed_version','1.4.2');
11
 
12
  // Set up WordPress shortcodes and actions
13
  add_shortcode('youtube','youtube_video_sc');
 
14
  add_shortcode('youtube_playlist','youtube_playlist_sc');
15
  add_shortcode('youtube_thumb','youtube_thumbnail_sc');
16
  add_shortcode('youtube_url','youtube_url_sc');
17
  add_shortcode('transcript','youtube_transcript');
 
 
18
  add_action('admin_menu','youtube_embed_menu');
 
19
 
20
  /*
21
  Shortcodes
@@ -23,18 +27,18 @@ Shortcodes
23
 
24
  // Embed a YouTube video
25
  function youtube_video_sc($paras="",$content="") {
26
- extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>'','link'=>'','react'=>'','stop'=>'','sweetspot'=>'','embedplus'=>''),$paras));
27
  $embedplus=ye_convert($embedplus);
28
  if ($embedplus=="1") {$type="m";}
29
  if ($embedplus=="0") {$type="v";}
30
- $youtube_code=generate_youtube_code($content,$type,$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot));
31
  return $youtube_code;
32
  }
33
 
34
  // Embed a YouTube playlist
35
  function youtube_playlist_sc($paras="",$content="") {
36
- extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>'','link'=>'','react'=>'','stop'=>'','sweetspot'=>''),$paras));
37
- return generate_youtube_code($content,"p",$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot));
38
  }
39
 
40
  // Return a thumbnail URL
@@ -53,6 +57,24 @@ function youtube_transcript($paras="",$content="") {
53
  return get_youtube_transcript($content);
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  /*
57
  Function calls
58
  */
@@ -80,9 +102,11 @@ function youtube_video_embed($content,$paras="",$style="") {
80
  $stop=youtube_get_parameters($paras,"stop");
81
  $sweetspot=youtube_get_parameters($paras,"sweetspot");
82
  $embedplus=ye_convert(youtube_get_parameters($paras,"embedplus"));
 
 
83
  if ($embedplus=="1") {$type="m";}
84
  if ($embedplus=="0") {$type="v";}
85
- echo generate_youtube_code($content,$type,$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot));
86
  return;
87
  }
88
 
@@ -114,6 +138,12 @@ function get_youtube_transcript_xml($id="") {
114
  if ($return['rc']<0) {return false;} else {return $return['file'];}
115
  }
116
 
 
 
 
 
 
 
117
  /*
118
  Admin Menu
119
  */
@@ -147,7 +177,7 @@ if((float)$wp_version>=2.8){
147
  $title=$instance['titles'];
148
  $id=$instance['id'];
149
  if (!empty($title)) {echo $before_title.$title.$after_title;}
150
- echo generate_youtube_code($instance['id'],$instance['type'],$instance['width'],$instance['height'],$instance['fullscreen'],$instance['related'],$instance['autoplay'],$instance['loop'],$instance['egm'],$instance['border'],$instance['color1'],$instance['color2'],$instance['start'],$instance['hd'],$instance['search'],$instance['info'],$instance['annotation'],$instance['cc'],$instance['style'],$instance['link'],$instance['react'],$instance['stop'],$instance['sweetspot']);
151
  echo $after_widget;
152
  }
153
 
@@ -178,6 +208,7 @@ if((float)$wp_version>=2.8){
178
  $instance['react']=$new_instance['react'];
179
  $instance['stop']=$new_instance['stop'];
180
  $instance['sweetspot']=$new_instance['sweetspot'];
 
181
  return $instance;
182
  }
183
 
@@ -197,7 +228,7 @@ Generate Embed code
197
  */
198
 
199
  // Generate XHTML compatible YouTube embed code
200
- function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$autoplay,$loop,$egm,$border,$color1,$color2,$start,$hd,$search,$info,$annotation,$cc,$style,$link,$react,$stop,$sweetspot) {
201
 
202
  // Ensure an ID is passed
203
  if (($id=="")&&(strtolower($widget)!="yes")) {
@@ -207,10 +238,12 @@ function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$au
207
  // Get default values if no values are supplied
208
  $options=get_option("youtube_embed");
209
  if (!is_array($options)) {
210
- $options = array('width'=>'425','height'=>'355','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1','type'=>'v');
 
 
 
 
211
  }
212
- if ($width=="") {$width=$options['width'];}
213
- if ($height=="") {$height=$options['height'];}
214
  if ($fullscreen=="") {$fullscreen=$options['fullscreen'];}
215
  if ($related=="") {$related=$options['related'];}
216
  if ($autoplay=="") {$autoplay=$options['autoplay'];}
@@ -231,13 +264,36 @@ function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$au
231
  if ($stop=="") {$stop=$options['stop'];}
232
  if ($sweetspot=="") {$sweetspot=$options['sweetspot'];}
233
  if ($type=="") {$type=$options['type'];}
234
-
 
235
  // Set default values for new options, if missing
236
  if ($link=="") {$link='1';}
237
  if ($react=="") {$react='1';}
238
  if ($stop=="") {$stop='0';}
239
  if ($sweetspot=="") {$sweetspot='1';}
240
- if ($type=="") {$type='v';}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
  // Set up EmbedPlus
243
  if ($type=="m") {
@@ -257,7 +313,7 @@ function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$au
257
  $id=str_replace("&#215;","x",$id);
258
 
259
  // Generate parameters to add to URL
260
- $paras="&amp;fs=".$fullscreen."&amp;rel=".$related."&amp;autoplay=".$autoplay."&amp;loop=".$loop."&amp;egm=".$egm."&amp;border=".$border."&amp;color1=0x".$color1."&amp;color2=0x".$color2."&amp;hd=".$hd."&amp;showsearch=".$search."&amp;showinfo=".$info."&amp;iv_load_policy=".$annotation."&amp;cc_load_policy=".$cc;
261
  $paras_ep="&amp;width=".$width."&amp;height=".$height."&amp;hd=".$hd."&amp;react=".$react."&amp;sweetspot=".$sweetspot;
262
  if ($start!=0) {$paras.="&amp;start=".$start; $paras_ep.="&amp;start=".$start;}
263
  if ($stop!=0) {$paras_ep.="&amp;stop=".$stop;}
@@ -350,6 +406,31 @@ function get_youtube_transcript($id) {
350
  return $output;
351
  }
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  /*
354
  Shared Functions
355
  */
3
  Plugin Name: YouTube Embed
4
  Plugin URI: http://www.artiss.co.uk/youtube-embed
5
  Description: Embed YouTube Videos in WordPress
6
+ Version: 1.5
7
  Author: David Artiss
8
  Author URI: http://www.artiss.co.uk
9
  */
10
+ define('youtube_embed_version','1.5');
11
 
12
  // Set up WordPress shortcodes and actions
13
  add_shortcode('youtube','youtube_video_sc');
14
+ add_shortcode('youtube_video','youtube_video_sc');
15
  add_shortcode('youtube_playlist','youtube_playlist_sc');
16
  add_shortcode('youtube_thumb','youtube_thumbnail_sc');
17
  add_shortcode('youtube_url','youtube_url_sc');
18
  add_shortcode('transcript','youtube_transcript');
19
+ add_shortcode('download_video','youtube_video_download');
20
+ add_shortcode('download_playlist','youtube_playlist_download');
21
  add_action('admin_menu','youtube_embed_menu');
22
+ add_action('init','youtube_button');
23
 
24
  /*
25
  Shortcodes
27
 
28
  // Embed a YouTube video
29
  function youtube_video_sc($paras="",$content="") {
30
+ extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>'','link'=>'','react'=>'','stop'=>'','sweetspot'=>'','embedplus'=>'','disablekb'=>'','ratio'=>''),$paras));
31
  $embedplus=ye_convert($embedplus);
32
  if ($embedplus=="1") {$type="m";}
33
  if ($embedplus=="0") {$type="v";}
34
+ $youtube_code=generate_youtube_code($content,$type,$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot),ye_convert($disablekb),$ratio);
35
  return $youtube_code;
36
  }
37
 
38
  // Embed a YouTube playlist
39
  function youtube_playlist_sc($paras="",$content="") {
40
+ extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>'','link'=>'','react'=>'','stop'=>'','sweetspot'=>'','disablekb'=>'','ratio'=>''),$paras));
41
+ return generate_youtube_code($content,"p",$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot),ye_convert($disablekb),$ratio);
42
  }
43
 
44
  // Return a thumbnail URL
57
  return get_youtube_transcript($content);
58
  }
59
 
60
+ // Shortcode to show a link to download the video
61
+ function youtube_video_download($paras="",$content="") {
62
+ extract(shortcode_atts(array('id'=>'','target'=>'','nofollow'=>''),$paras));
63
+ $link='<a href="'.get_video_download($id).'"';
64
+ if ($target!="") {$link.=' target="'.$target.'"';}
65
+ if (strtolower($nofollow)!="no") {$link.=' rel="nofollow"';}
66
+ return $link.'>'.$content.'</a>';
67
+ }
68
+
69
+ // Shortcode to show a link to download the playlist
70
+ function youtube_playlist_download($paras="",$content="") {
71
+ extract(shortcode_atts(array('id'=>'','target'=>'','nofollow'=>''),$paras));
72
+ $link='<a href="'.get_playlist_download($id);
73
+ if ($target!="") {$link.=' target="'.$target.'"';}
74
+ if (strtolower($nofollow)!="no") {$link.=' rel="nofollow"';}
75
+ return $link.'">'.$content.'</a>';
76
+ }
77
+
78
  /*
79
  Function calls
80
  */
102
  $stop=youtube_get_parameters($paras,"stop");
103
  $sweetspot=youtube_get_parameters($paras,"sweetspot");
104
  $embedplus=ye_convert(youtube_get_parameters($paras,"embedplus"));
105
+ $disablekb=ye_convert(youtube_get_parameters($paras,"disablekb"));
106
+ $ratio=youtube_get_parameters($paras,"ratio");
107
  if ($embedplus=="1") {$type="m";}
108
  if ($embedplus=="0") {$type="v";}
109
+ echo generate_youtube_code($content,$type,$width,$height,ye_convert($fullscreen),ye_convert($related),ye_convert($autoplay),ye_convert($loop),ye_convert($egm),ye_convert($border),$color1,$color2,$start,ye_convert($hd),ye_convert($search),ye_convert($info),ye_convert_3($annotation),ye_convert($cc),$style,ye_convert($link),ye_convert($react),$stop,ye_convert($sweetspot),ye_convert($disablekb),$ratio);
110
  return;
111
  }
112
 
138
  if ($return['rc']<0) {return false;} else {return $return['file'];}
139
  }
140
 
141
+ // Return YouTube video download URL
142
+ function get_video_download($id="") {return "http://www.savevid.com/?url=http://www.youtube.com/watch?v=".$id;}
143
+
144
+ // Return YouTube playlist download URL
145
+ function get_playlist_download($id="") {return "http://www.savevid.com/?url=http://www.youtube.com/watch?p=".$id;}
146
+
147
  /*
148
  Admin Menu
149
  */
177
  $title=$instance['titles'];
178
  $id=$instance['id'];
179
  if (!empty($title)) {echo $before_title.$title.$after_title;}
180
+ echo generate_youtube_code($instance['id'],$instance['type'],$instance['width'],$instance['height'],$instance['fullscreen'],$instance['related'],$instance['autoplay'],$instance['loop'],$instance['egm'],$instance['border'],$instance['color1'],$instance['color2'],$instance['start'],$instance['hd'],$instance['search'],$instance['info'],$instance['annotation'],$instance['cc'],$instance['style'],$instance['link'],$instance['react'],$instance['stop'],$instance['sweetspot'],$instance['disablekb'],'');
181
  echo $after_widget;
182
  }
183
 
208
  $instance['react']=$new_instance['react'];
209
  $instance['stop']=$new_instance['stop'];
210
  $instance['sweetspot']=$new_instance['sweetspot'];
211
+ $instance['disablekb']=$new_instance['disablekb'];
212
  return $instance;
213
  }
214
 
228
  */
229
 
230
  // Generate XHTML compatible YouTube embed code
231
+ function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$autoplay,$loop,$egm,$border,$color1,$color2,$start,$hd,$search,$info,$annotation,$cc,$style,$link,$react,$stop,$sweetspot,$disablekb,$ratio) {
232
 
233
  // Ensure an ID is passed
234
  if (($id=="")&&(strtolower($widget)!="yes")) {
238
  // Get default values if no values are supplied
239
  $options=get_option("youtube_embed");
240
  if (!is_array($options)) {
241
+ $options=array('width'=>'425','height'=>'355','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1','type'=>'v','disablekb'=>'0');
242
+ }
243
+ if (($width=="")&&($height=="")) {
244
+ $width=$options['width'];
245
+ $height=$options['height'];
246
  }
 
 
247
  if ($fullscreen=="") {$fullscreen=$options['fullscreen'];}
248
  if ($related=="") {$related=$options['related'];}
249
  if ($autoplay=="") {$autoplay=$options['autoplay'];}
264
  if ($stop=="") {$stop=$options['stop'];}
265
  if ($sweetspot=="") {$sweetspot=$options['sweetspot'];}
266
  if ($type=="") {$type=$options['type'];}
267
+ if ($disablekb=="") {$disablekb=$options['disablekb'];}
268
+
269
  // Set default values for new options, if missing
270
  if ($link=="") {$link='1';}
271
  if ($react=="") {$react='1';}
272
  if ($stop=="") {$stop='0';}
273
  if ($sweetspot=="") {$sweetspot='1';}
274
+ if ($type=="") {$type='v';}
275
+ if ($disablekb=="") {$disablekb='0';}
276
+
277
+ // If height or width is missing, calculate missing parameter using ratio
278
+ if ((($width=="")or($height==""))&&(($width!="")or($height!=""))) {
279
+ if ($ratio!="") {
280
+ // Extract the ratio from the provided string
281
+ $ratio_to_use="";
282
+ $pos=strpos($ratio,":",0);
283
+ if ($pos!==false) {
284
+ $ratio_l=substr($ratio,0,$pos);
285
+ $ratio_r=substr($ratio,$pos+1);
286
+ if ((is_numeric($ratio_l))&&(is_numeric($ratio_r))) {$ratio_to_use=$ratio_l/$ratio_r;}
287
+ }
288
+ }
289
+
290
+ // If no, or invalid, ratio supplied, calculate from the default video dimensions
291
+ if ($ratio_to_use=="") {$ratio_to_use=$options['width']/$options['height'];}
292
+
293
+ // Complete the missing width or height using the ratio
294
+ if ($width=="") {$width=round($height*$ratio_to_use,0);}
295
+ if ($height=="") {$height=round($width/$ratio_to_use,0);}
296
+ }
297
 
298
  // Set up EmbedPlus
299
  if ($type=="m") {
313
  $id=str_replace("&#215;","x",$id);
314
 
315
  // Generate parameters to add to URL
316
+ $paras="&amp;fs=".$fullscreen."&amp;rel=".$related."&amp;autoplay=".$autoplay."&amp;loop=".$loop."&amp;egm=".$egm."&amp;border=".$border."&amp;color1=0x".$color1."&amp;color2=0x".$color2."&amp;hd=".$hd."&amp;showsearch=".$search."&amp;showinfo=".$info."&amp;iv_load_policy=".$annotation."&amp;cc_load_policy=".$cc."&amp;disablekb=".$disablekb;
317
  $paras_ep="&amp;width=".$width."&amp;height=".$height."&amp;hd=".$hd."&amp;react=".$react."&amp;sweetspot=".$sweetspot;
318
  if ($start!=0) {$paras.="&amp;start=".$start; $paras_ep.="&amp;start=".$start;}
319
  if ($stop!=0) {$paras_ep.="&amp;stop=".$stop;}
406
  return $output;
407
  }
408
 
409
+ /*
410
+ Editor Button
411
+ */
412
+
413
+ function youtube_button() {
414
+ if ((!current_user_can('edit_posts'))&&(!current_user_can('edit_pages'))) {return;}
415
+ $editor=get_option("youtube_embed_editor");
416
+ if ((get_user_option('rich_editing')=='true')&&($editor['youtube']!="0")) {
417
+ add_filter('mce_external_plugins','add_youtube_mce_plugin');
418
+ add_filter('mce_buttons','register_youtube_button');
419
+ }
420
+ }
421
+
422
+ // Register button
423
+ function register_youtube_button($buttons) {
424
+ array_push($buttons,"|","YouTube");
425
+ return $buttons;
426
+ }
427
+
428
+ // Register TinyMCE Plugin
429
+ function add_youtube_mce_plugin( $plugin_array ) {
430
+ $plugin_array['YouTube']=WP_PLUGIN_URL.'/youtube-embed/mcebutton.js';
431
+ return $plugin_array;
432
+ }
433
+
434
  /*
435
  Shared Functions
436
  */
youtube-widget-options.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php
2
- $default=array('titles'=>'YouTube','id'=>'','type'=>'v','width'=>'170','height'=>'142','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1');
3
  $instance=wp_parse_args( (array) $instance, $default);
4
 
5
  $field_id=$this->get_field_id('titles');
1
  <?php
2
+ $default=array('titles'=>'YouTube','id'=>'','type'=>'v','width'=>'170','height'=>'142','border'=>'0','fullscreen'=>'0','hd'=>'1','color1'=>'2b405b','color2'=>'6b8ab6','style'=>'','autoplay'=>'0','start'=>'0','loop'=>'0','cc'=>'0','annotation'=>'1','egm'=>'0','related'=>'0','info'=>'1','search'=>'1','link'=>'1','react'=>'1','stop'=>'0','sweetspot'=>'1','disablekb'=>'0');
3
  $instance=wp_parse_args( (array) $instance, $default);
4
 
5
  $field_id=$this->get_field_id('titles');
youtube.png ADDED
Binary file