YouTube Embed - Version 1.0

Version Description

  • Initial release

=

Download this release

Release Info

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

Version 1.0

readme.txt ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === YouTube Embed ===
2
+ Contributors: dartiss
3
+ Donate link: http://tinyurl.com/bdc4uu
4
+ Tags: YouTube, XHTML, Video, Embed, Playlist, Thumbnail
5
+ Requires at least: 2.0.0
6
+ Tested up to: 2.9.1
7
+ Stable tag: 1.0
8
+
9
+ YouTube Embed is a powerful, but simple to use, method of embedding YouTube videos in your WordPress theme.
10
+
11
+ == Description ==
12
+
13
+ YouTube Embed is a powerful, but simple to use, method of embedding YouTube videos in your WordPress theme.
14
+
15
+ It works with all the current YouTube API parameters, including HD video, and produces XHTML valid output. It also, unlike many others similar plugins, works with videos with certain characters within their ID (e.g. double dashes).
16
+
17
+ Over the coming instructions I'll take you through the various ways to embed video, playlists and other YouTube related abilities.
18
+
19
+ == Usage ==
20
+
21
+ There are 3 ways to embed a video - a function call (requires PHP coding, but can be placed anywhere), a short code (which can be easily placed in a post or page) or with a sidebar widget.
22
+
23
+ A video will use the default settings - these can be changed via the YouTube Embed options screen within your administration panel. However, with the exception of the widget, you can also change any of these settings on a per-video basis.
24
+
25
+ Let's go through each of the 3 methods in turn...
26
+
27
+ *1. Function Call*
28
+
29
+ For those with access (and the requirement) to their theme PHP, a function calls adds total flexibility as it can be added anywhere within your theme.
30
+
31
+ `<?php if (function_exists('youtube_video_embed')) {youtube_video_embed('id','paras','style');} ?>`
32
+
33
+ Where id is the video ID, paras is a list of parameters (more on this in a minute) and style (optional) is a list of stylesheet elements that you wish to apply to the resulting video.
34
+
35
+ The parameters are supplied with an ampersand seperating each. See the "Parameters" section of these instructions for details on what parameters are available, but here's an example where I override the height and width of a video...
36
+
37
+ `<?php if (function_exists('youtube_video_embed')) {youtube_video_embed('id','width=100&height=200');} ?>`
38
+
39
+ *2. Short Code*
40
+
41
+ This is an easy one. Within any post or page, simply type the following...
42
+
43
+ `[youtube]id[/youtube]`
44
+
45
+ Where id is the ID of the video.
46
+
47
+ If you wish to override any of the settings, then these must be specified within the opening short code. So, to adjust the width and height, you'd put...
48
+
49
+ `[youtube width=100 height=200]id[/youtube]`
50
+
51
+ In this case, the width is 100px and the height is 200px.
52
+
53
+ For a complete list of the parameters, please see the appropriate tab above. You may also specify a stylesheet override by using the `style` parameter. For example...
54
+
55
+ `[youtube style="text-align:center"]id[/youtube]`
56
+
57
+ This will centre the resulting video.
58
+
59
+ *3. Widget*
60
+
61
+ The Widget is available from the Appearance->Widgets menu within Administation. Drag it to the appropriate sidebar and click on the down arrow to modify the default options.
62
+
63
+ These NEED to be done as you also have to specify the video ID and type (video or playlist).
64
+
65
+ **Playlists**
66
+
67
+ You can also embed playlists using any of the video embedding methods mentioned before.
68
+
69
+ For function calls, simply use the function `youtube_playlist_embed`, with the same parameters as the video equivalent.
70
+
71
+ For short codes, use the short code `[youtube_playlist]`, again with the same parameters as before.
72
+
73
+ For the widget, simply change the "Type" option in the Widget options to "Playlist".
74
+
75
+ In all cases you must specify a valid playlist ID, instead of the standard video ID.
76
+
77
+ **Thumbnails**
78
+
79
+ YouTube embed also has the ability to return a thumbnail of a video (sorry, this doesn't work with playlists).
80
+
81
+ There are two methods you can use for this - a shortcode or a function call.
82
+
83
+ Use the following function call to add a thumbnail to any part of your theme.
84
+
85
+ `<?php if (function_exists('youtube_thumb_embed')) {youtube_thumb_embed('id','paras','style','alt');} ?>`
86
+
87
+ Like the video embed equivalent, the ID is the video ID, the style is a list of stylesheet elements (but is optional) and alt is the alternative text for the thumbnail image (also optional). The parameters are different, however, but, again, are seperated by ampersand.
88
+
89
+ The parameters are as follows...
90
+
91
+ * *rel* - specify a REL override, e.g. rel="nofollow"
92
+ * *target* - specify a TARGET override, e.g. target="_blank"
93
+ * *width* - this specifies the width of the thumbnail image
94
+ * *height* - this specifies the height of the thumbnail image
95
+
96
+ Here's an example, with parameters to specify the REL, TARGET and ALT elements.
97
+
98
+ `<?php if (function_exists('youtube_thumb_embed')) {youtube_thumb_embed('id','rel=nofollow&target=_blank','','Demo Video');} ?>`
99
+
100
+ To use the short code method, insert [youtube_thumb]id[/youtube_thumb] into a post or page to create a thumbnail of the relevant video ID which, once clicked, will open up the appropriate YouTube page.
101
+
102
+ Like the function call above, you can specify a number of parameters. They are the same as detailed above but with the addition of two further parameters...
103
+
104
+ * *style* - allows you to specify any stylesheet elements that you'd like applied
105
+ * *alt* - specify some "ALT" text for the thumbnail image
106
+
107
+ e.g. `[youtube_thumb target="_blank" alt="Demo video"]id[/youtube_thumb]`
108
+
109
+ This overrides the TARGET and ALT elements of the thumbnail.
110
+
111
+ **Short URL**
112
+
113
+ You may return a short URL for any YouTube video by way of either a function call or a shortcode.
114
+
115
+ For a function call, add the following to your code to return a URL - note that this is not written out, but returned as a value. id is the video ID.
116
+
117
+ `<?php if (function_exists('youtube_short_url')) {youtube_short_url('id');} ?>`
118
+
119
+ So, an example may be...
120
+
121
+ `<a href="<?php echo youtube_short_url('id'); ?>"Click here for video</a>`
122
+
123
+ This will create a link to a video using the short URL standard.
124
+
125
+ To use the shortcode method simply insert `[youtube_url]id[/youtube_url]` anywhere within a post or page to return a shortened URL. As with other examples, id is the ID of the video.
126
+
127
+ == Installation ==
128
+
129
+ 1. Upload the entire youtube-embed folder to your wp-content/plugins/ directory.
130
+ 2. Activate the plugin through the �Plugins� menu in WordPress.
131
+ 3. Visit the YouTube Embed options screen in your Administration menu and set the default parameters
132
+ 4. If using the widget, browse to Appearance->Widgets, add the widget, and configure the options
133
+
134
+ == Frequently Asked Questions ==
135
+
136
+ = How do I find the ID of a YouTube video? =
137
+
138
+ If you play a YouTube video, look at the URL - it will probably look something like this...
139
+
140
+ `http://www.youtube.com/watch?v=L5Y4qzc_JTg`
141
+
142
+ The video ID is the list of letters and numbers after `v=`, in this case L5Y4qzc_JTg.
143
+
144
+ = How can I get help or request possible changes =
145
+
146
+ Feel free to report any problems, or suggestions for enhancements, to me either via [my contact form](http://www.artiss.co.uk/contact "Contact Me") or by [the plugins homepage](http://www.artiss.co.uk/youtube-embed "YouTube Embed").
147
+
148
+ == Changelog ==
149
+
150
+ = 1.0 =
151
+ * Initial release
152
+
153
+ == Upgrade Notice ==
154
+
155
+ = 1.0 =
156
+ * Initial release
157
+
158
+ == Parameters ==
159
+
160
+ 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.
161
+
162
+ * *width* - the width of the video in pixels
163
+ * *height* - the height of the video in pixels
164
+ * *fullscreen* - yes or no, this adds a button to the video player, allowing the video to be shown fullscreen
165
+ * *hd* - yes or no, this determines whether a video defaults to HD quality, if available
166
+ * *color1* - this is 1 of 2 colors that can be used on the video player. It is in a hex RGB format, and should be 6 letters long.
167
+ * *color2* - this is the second video player colour. Again, this is a hex RGB format.
168
+ * *autoplay* - yes or no, this specifies whether the video automatically starts to play
169
+ * *start* - this can be specified if you wish for the video not to start at the beginning. Specify a number of seconds.
170
+ * *loop* - yes or no, this specifies whether the video loops back to the beginning once it completes
171
+ * *cc* - yes or no, this turns on or off closed captions (subtitles)
172
+ * *annotation* - yes or no, this specifies whether you wish video annotations to be shown
173
+ * *egm* - yes or no, this enables or disables the Enhanced Genie Menu
174
+ * *related* - yes or no, this specifies whether you wish to display related videos
175
+ * *info* - yes or no, this determines whether video information is shown
176
+ * *search* - yes or no, this specifies whether the search box is shown
177
+
178
+ For further details on these parameters, please read the [YouTube documentation](http://code.google.com/apis/youtube/player_parameters.html "YouTube Embedded Player Parameters").
youtube-embed-options.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <?php screen_icon(); ?>
3
+ <h2>YouTube Embed Options</h2>
4
+ <?php
5
+ // If options have been updated on screen, update the database
6
+ if(!empty($_POST['Submit'])) {
7
+ $options['width']=$_POST['youtube_embed_width'];
8
+ $options['height']=$_POST['youtube_embed_height'];
9
+ $options['border']=$_POST['youtube_embed_border'];
10
+ $options['fullscreen']=$_POST['youtube_embed_fullscreen'];
11
+ $options['hd']=$_POST['youtube_embed_hd'];
12
+ $options['color1']=$_POST['youtube_embed_color1'];
13
+ $options['color2']=$_POST['youtube_embed_color2'];
14
+ $options['style']=$_POST['youtube_embed_style'];
15
+ $options['autoplay']=$_POST['youtube_embed_autoplay'];
16
+ $options['start']=$_POST['youtube_embed_start'];
17
+ $options['loop']=$_POST['youtube_embed_loop'];
18
+ $options['cc']=$_POST['youtube_embed_cc'];
19
+ $options['annotation']=$_POST['youtube_embed_annotation'];
20
+ $options['egm']=$_POST['youtube_embed_egm'];
21
+ $options['related']=$_POST['youtube_embed_related'];
22
+ $options['info']=$_POST['youtube_embed_info'];
23
+ $options['search']=$_POST['youtube_embed_search'];
24
+ update_option("youtube_embed",$options);
25
+ }
26
+ // Fetch options into an array
27
+ $options=get_option("youtube_embed");
28
+ // Set defaults if no array is defined
29
+ if (!is_array($options)) {
30
+ echo "<div class=\"updated\"><p><strong>Please review the default options below and click \"Save Settings\" to update them.</strong></p></div>\n";
31
+ $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');}
32
+ ?>
33
+
34
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float: right;" target="_blank">
35
+ <input type="hidden" name="cmd" value="_s-xclick"/>
36
+ <input type="hidden" name="hosted_button_id" value="2827258"/>
37
+ <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" name="submit" alt="Donate!"/>
38
+ <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"/>
39
+ </form>
40
+
41
+ <p><?php _e('These are the default settings for YouTube videos embedded with YouTube Embed.'); ?></p>
42
+ <p><?php _e('Further details about these parameters can be found in <a href="http://code.google.com/apis/youtube/player_parameters.html">the official YouTube documentation</a> for embedded videos.'); ?></p>
43
+ <p><?php _e('If you like this plugin, please consider donating.'); ?></p>
44
+
45
+ <form method="post" action="<?php echo get_bloginfo('wpurl').'/wp-admin/options-general.php?page=youtube-embed-settings&amp;updated=true' ?>">
46
+ <table class="form-table">
47
+
48
+ <tr valign="top">
49
+ <th style="font-weight: bold" scope="row"><?php _e('Video Display Properties'); ?></th>
50
+ </tr><tr>
51
+
52
+ <th scope="row"><?php _e('Width'); ?></th>
53
+ <td><input type="text" size="3" maxlength="3" name="youtube_embed_width" value="<?php echo $options['width']; ?>"/>px</td>
54
+
55
+ <th scope="row"><?php _e('Height'); ?></th>
56
+ <td><input type="text" size="3" maxlength="3" name="youtube_embed_height" value="<?php echo $options['height']; ?>"/>px</td>
57
+ </tr><tr>
58
+
59
+ <th scope="row"><?php _e('Show Border'); ?></th>
60
+ <td><select name="youtube_embed_border">
61
+ <option value="0"<?php if ($options['border']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
62
+ <option value="1"<?php if ($options['border']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
63
+ </select></td>
64
+
65
+ <th scope="row"><?php _e('Fullscreen Button'); ?></th>
66
+ <td><select name="youtube_embed_fullscreen">
67
+ <option value="0"<?php if ($options['fullscreen']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
68
+ <option value="1"<?php if ($options['fullscreen']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
69
+ </select></td>
70
+ </tr><tr>
71
+
72
+ <th scope="row"><?php _e('Default to HD Quality'); ?></th>
73
+ <td colspan="2"><select name="youtube_embed_hd">
74
+ <option value="0"<?php if ($options['hd']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
75
+ <option value="1"<?php if ($options['hd']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
76
+ </select> (if available)</td>
77
+ </tr><tr>
78
+
79
+ <th scope="row"><?php _e('Color 1'); ?></th>
80
+ <td>#<input type="text" size="6" maxlength="6" name="youtube_embed_color1" value="<?php echo $options['color1']; ?>"/>&nbsp;<span style="padding-right: 16px; background-color: #<?php echo $options['color1']; ?>">&nbsp;</span></td>
81
+
82
+ <th scope="row"><?php _e('Color 2'); ?></th>
83
+ <td>#<input type="text" size="6" maxlength="6" name="youtube_embed_color2" value="<?php echo $options['color2']; ?>"/>&nbsp;<span style="padding-right: 16px; background-color: #<?php echo $options['color2'] ?>">&nbsp;</span></td>
84
+ </tr><tr>
85
+
86
+ <th scope="row"><?php _e('Style Information'); ?></th>
87
+ <td colspan="2"><input type="text" size="40" name="youtube_embed_style" value="<?php echo $options['style']; ?>"/> e.g. text-align:center</td>
88
+ </tr><tr>
89
+
90
+ <th style="font-weight: bold" scope="row"><?php _e('Playback'); ?></th>
91
+ </tr><tr>
92
+
93
+ <th scope="row"><?php _e('Autoplay'); ?></th>
94
+ <td><select name="youtube_embed_autoplay">
95
+ <option value="0"<?php if ($options['autoplay']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
96
+ <option value="1"<?php if ($options['autoplay']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
97
+ </select></td>
98
+
99
+ <th scope="row"><?php _e('Start'); ?></th>
100
+ <td><input type="text" size="3" maxlength="3" name="youtube_embed_start" value="<?php echo $options['start']; ?>"/> seconds</td>
101
+ </tr><tr>
102
+
103
+ <th scope="row"><?php _e('Loop Video'); ?></th>
104
+ <td><select name="youtube_embed_loop">
105
+ <option value="0"<?php if ($options['loop']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
106
+ <option value="1"<?php if ($options['loop']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
107
+ </select></td>
108
+
109
+ <th scope="row"><?php _e('Show Closed Captions'); ?></th>
110
+ <td><select name="youtube_embed_cc">
111
+ <option value="0"<?php if ($options['cc']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
112
+ <option value="1"<?php if ($options['cc']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
113
+ </select></td>
114
+ </tr><tr>
115
+
116
+ <th scope="row"><?php _e('Show Annotations'); ?></th>
117
+ <td><select name="youtube_embed_annotation">
118
+ <option value="3"<?php if ($options['annotation']=="3") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
119
+ <option value="1"<?php if ($options['annotation']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
120
+ </select></td>
121
+ </tr><tr>
122
+
123
+ <th style="font-weight: bold" scope="row"><?php _e('Video Information'); ?></th>
124
+ </tr><tr>
125
+
126
+ <th scope="row"><?php _e('Enable Enhanced Genie Menu'); ?></th>
127
+ <td><select name="youtube_embed_egm">
128
+ <option value="0"<?php if ($options['egm']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
129
+ <option value="1"<?php if ($options['egm']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
130
+ </select></td>
131
+
132
+ <th scope="row"><?php _e('Show Related Videos'); ?></th>
133
+ <td><select name="youtube_embed_related">
134
+ <option value="0"<?php if ($options['related']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
135
+ <option value="1"<?php if ($options['related']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
136
+ </select></td>
137
+ </tr><tr>
138
+
139
+ <th scope="row"><?php _e('Show Video Information'); ?></th>
140
+ <td><select name="youtube_embed_info">
141
+ <option value="0"<?php if ($options['info']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
142
+ <option value="1"<?php if ($options['info']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
143
+ </select></td>
144
+
145
+ <th scope="row"><?php _e('Show Search Box'); ?></th>
146
+ <td><select name="youtube_embed_search">
147
+ <option value="0"<?php if ($options['search']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
148
+ <option value="1"<?php if ($options['search']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
149
+ </select></td>
150
+
151
+ </tr>
152
+ </table>
153
+ <p class="submit">
154
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Settings'); ?>"/>
155
+ </p>
156
+ </form>
157
+
158
+ <h3>YouTube Video Sample</h3>
159
+ <p>This uses the above settings, once they have been saved.</p>
160
+ <p><?php youtube_video_embed("I0mftrFD7X4"); ?></p>
161
+
162
+ <h3>Further Help</h3>
163
+ <p>Comprehensive instructions can be found on <a href="http://www.artiss.co.uk/youtube-embed">the official site page</a>, along with <a href="http://www.artiss.co.uk/category/software/wordpress">blog updates</a> and a comprehensive <a href="http://www.artiss.co.uk/category/software/wordpress/feed">news feed</a>.</p>
164
+ <p>Alternatively, please see <a href="http://wordpress.org/extend/plugins/youtube-embed/">the WordPress plugin page</a>.</p>
165
+
166
+ <p><a href="http://validator.w3.org"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31px" width="88px" style="float: right"/></a></p>
167
+ </div>
youtube-embed.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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.0
7
+ Author: David Artiss
8
+ Author URI: http://www.artiss.co.uk
9
+ */
10
+ // Set up WordPress shortcodes and actions
11
+ add_shortcode('youtube','youtube_video_sc');
12
+ add_shortcode('youtube_playlist','youtube_playlist_sc');
13
+ add_shortcode('youtube_thumb','youtube_thumbnail_sc');
14
+ add_shortcode('youtube_url','youtube_url_sc');
15
+ add_action('admin_menu','youtube_embed_menu');
16
+ add_action('plugins_loaded','youtube_widget_init');
17
+
18
+ // Shortcode function to embed a YouTube video
19
+ function youtube_video_sc($paras="",$content="") {
20
+ extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>''),$paras));
21
+ $youtube_code=generate_youtube_code($content,"v",$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);
22
+ return $youtube_code;
23
+ }
24
+
25
+ // Shortcode function to embed a YouTube playlist
26
+ function youtube_playlist_sc($paras="",$content="") {
27
+ extract(shortcode_atts(array('width'=>'','height'=>'','fullscreen'=>'','related'=>'','autoplay'=>'','loop'=>'','egm'=>'','border'=>'','color1'=>'','color2'=>'','start'=>'','hd'=>'','search'=>'','info'=>'','annotation'=>'','cc'=>'','style'=>''),$paras));
28
+ 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);
29
+ }
30
+
31
+ // TShortcode function to embed a YouTube playlist
32
+ function youtube_thumbnail_sc($paras="",$content="") {
33
+ extract(shortcode_atts(array('style'=>'','class'=>'','rel'=>'','target'=>'','width'=>'','height'=>'','alt'=>''),$paras));
34
+ return generate_thumbnail_code($content,$style,$class,$rel,$target,$width,$height,$alt);
35
+ }
36
+
37
+ // Shortcode function to return a short YouTube URL
38
+ function youtube_url_sc($paras="",$content="") {
39
+ if ($content=="") {return youtube_embed_error("No video ID has been supplied");} else {return "http://youtu.be/".$content;}
40
+ }
41
+
42
+ // Embed a video via your own function call
43
+ function youtube_video_embed($content,$paras="",$style="",$type="v") {
44
+ $width=youtube_get_parameters($paras,"width");
45
+ $height=youtube_get_parameters($paras,"height");
46
+ $fullscreen=youtube_get_parameters($paras,"fullscreen");
47
+ $related=youtube_get_parameters($paras,"related");
48
+ $autoplay=youtube_get_parameters($paras,"autoplay");
49
+ $loop=youtube_get_parameters($paras,"loop");
50
+ $egm=youtube_get_parameters($paras,"egm");
51
+ $border=youtube_get_parameters($paras,"border");
52
+ $color1=youtube_get_parameters($paras,"color1");
53
+ $color2=youtube_get_parameters($paras,"color2");
54
+ $start=youtube_get_parameters($paras,"start");
55
+ $hd=youtube_get_parameters($paras,"hd");
56
+ $search=youtube_get_parameters($paras,"search");
57
+ $info=youtube_get_parameters($paras,"info");
58
+ $annotation=youtube_get_parameters($paras,"annotation");
59
+ $cc=youtube_get_parameters($paras,"cc");
60
+ 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);
61
+ return;
62
+ }
63
+
64
+ // Embed a playlist via your own function call
65
+ function youtube_playlist_embed($content,$paras="",$style="") {
66
+ youtube_video_embed($content,$paras="",$style="","p");
67
+ return;
68
+ }
69
+
70
+ // Display a video thumbnail via your own function call
71
+ function youtube_thumb_embed($content,$paras="",$style="",$alt="") {
72
+ $class=youtube_get_parameters($paras,"class");
73
+ $rel=youtube_get_parameters($paras,"rel");
74
+ $target=youtube_get_parameters($paras,"target");
75
+ $width=youtube_get_parameters($paras,"width");
76
+ $height=youtube_get_parameters($paras,"height");
77
+ echo generate_thumbnail_code($content,$style,$class,$rel,$target,$width,$height,$alt);
78
+ return;
79
+ }
80
+
81
+ // Display a short YouTube URL via your own function call
82
+ function youtube_short_url($id) {return "http://youtu.be/".$id;}
83
+
84
+ // Generate XHTML compatible YouTube embed code
85
+ function generate_youtube_code($id,$type,$width,$height,$fullscreen,$related,$autoplay,$loop,$egm,$border,$color1,$color2,$start,$hd,$search,$info,$annotation,$cc,$style,$widget="") {
86
+ // Ensure an ID is passed
87
+ if (($id=="")&&(strtolower($widget)!="yes")) {
88
+ return youtube_embed_error("No video/playlist ID has been supplied");
89
+ } else {
90
+ // Get default values if no override values are supplied
91
+ if (strtolower($widget)=="yes") {
92
+ $options=get_option("youtube_widget");
93
+ if (!is_array($options)) {
94
+ $options=array('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');
95
+ }
96
+ $id=$options['id'];
97
+ $type=$options['type'];
98
+ } else {
99
+ $options=get_option("youtube_embed");
100
+ if (!is_array($options)) {
101
+ $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');
102
+ }
103
+ }
104
+ if ($width=="") {$width=$options['width'];}
105
+ if ($height=="") {$height=$options['height'];}
106
+ if ($fullscreen=="") {$fullscreen=$options['fullscreen'];}
107
+ if ($related=="") {$related=$options['related'];}
108
+ if ($autoplay=="") {$autoplay=$options['autoplay'];}
109
+ if ($loop=="") {$loop=$options['loop'];}
110
+ if ($egm=="") {$egm=$options['egm'];}
111
+ if ($border=="") {$border=$options['border'];}
112
+ if ($color1=="") {$color1=$options['color1'];}
113
+ if ($color2=="") {$color2=$options['color2'];}
114
+ if ($start=="") {$start=$options['start'];}
115
+ if ($hd=="") {$hd=$options['hd'];}
116
+ if ($search=="") {$search=$options['search'];}
117
+ if ($info=="") {$info=$options['info'];}
118
+ if ($annotation=="") {$annotation=$options['annotation'];}
119
+ if ($cc=="") {$cc=$options['cc'];}
120
+ if ($style=="") {$style=$options['style'];}
121
+ // Convert video ID characters
122
+ $id=str_replace("&#8211;","--",$id);
123
+ $id=str_replace("&#215;","x",$id);
124
+ // Generate parameters to add to URL
125
+ $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;
126
+ if ($start!=0) {$paras=$paras."&amp;start=".$start;}
127
+ // Write out JavaScript
128
+ if ($style!="") {$result="<div style=\"".$style."\">";}
129
+ $result=$result."<object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/".$type."/".$id.$paras."\" width=\"".$width."px\" height=\"".$height."px\">\n";
130
+ $result=$result."<param name=\"movie\" value=\"http://www.youtube.com/".$type."/".$id.$paras."\"></param>\n";
131
+ if ($fullscreen==1) {$result=$result."<param name=\"allowFullScreen\" value=\"true\"></param>\n";}
132
+ $result=$result."</object>\n";
133
+ if ($style!="") {$result=$result."</div>\n";}
134
+ return $result;
135
+ }
136
+ }
137
+
138
+ // Function to generate XHTML compatible YouTube video thumbnail
139
+ function generate_thumbnail_code($id,$style,$class,$rel,$target,$width,$height,$alt) {
140
+ if ($alt=="") {$alt="YouTube Video ".$id;}
141
+ $youtube_code="<a href=\"http://www.youtube.com/watch?v=".$id."\"";
142
+ if ($style!="") {$youtube_code=$youtube_code." style=\"".$style."\"";}
143
+ if ($class!="") {$youtube_code=$youtube_code." class=\"".$class."\"";}
144
+ if ($rel!="") {$youtube_code=$youtube_code." rel=\"".$rel."\"";}
145
+ if ($target!="") {$youtube_code=$youtube_code." target=\"".$target."\"";}
146
+ $youtube_code=$youtube_code."><img src=\"http://img.youtube.com/vi/".$id."/2.jpg\"";
147
+ if ($width!="") {$youtube_code=$youtube_code." width=\"".$width."px\"";}
148
+ if ($height!="") {$youtube_code=$youtube_code." height=\"".$height."px\"";}
149
+ $youtube_code=$youtube_code." alt=\"".$alt."\"";
150
+ return $youtube_code."/></a>";
151
+ }
152
+
153
+ // Function to generate YouTube widget
154
+ function youtube_widget($args) {
155
+ extract($args);
156
+ echo $before_widget;
157
+ echo $before_title."YouTube".$after_title;
158
+ echo generate_youtube_code("","","","","","","","","","","","","","","","","","","","yes");
159
+ echo $after_widget;
160
+ }
161
+
162
+ // Function to extract parameters from an input string (1.0)
163
+ function youtube_get_parameters($input,$para) {
164
+ $start=strpos(strtolower($input),$para."=");
165
+ $content="";
166
+ if ($start!==false) {
167
+ $start=$start+strlen($para)+1;
168
+ $end=strpos(strtolower($input),"&",$start);
169
+ if ($end!==false) {$end=$end-1;} else {$end=strlen($input);}
170
+ $content=substr($input,$start,$end-$start+1);
171
+ }
172
+ return $content;
173
+ }
174
+
175
+ // Function to report an error
176
+ function youtube_embed_error($errorin) {return "<p style=\"color: #f00; font-weight: bold;\">YouTube Embed: ".$errorin."</p>\n";}
177
+
178
+ // Function to convert a Yes or No input to an equivalent 1 or 0 output
179
+ function ye_convert($input) {
180
+ $input=strtolower($input);
181
+ $output="";
182
+ if (($input=="yes")or($input=="1")) {$output="1";}
183
+ if (($input=="no")or($input=="0")) {$output="0";}
184
+ return $output;
185
+ }
186
+
187
+ // Function to convert a Yes or No input to an equivalent 1 or 3 output
188
+ function ye_convert_3($input) {
189
+ $input=strtolower($input);
190
+ $output="";
191
+ if (($input=="yes")or($input=="1")) {$output="1";}
192
+ if (($input=="no")or($input=="3")) {$output="3";}
193
+ return $output;
194
+ }
195
+
196
+ function youtube_embed_menu() {add_options_page('YouTube Embed Settings','YouTube Embed',10, 'youtube-embed-settings', 'youtube_embed_options');}
197
+ function youtube_embed_options() {include_once(WP_PLUGIN_DIR."/youtube-embed/youtube-embed-options.php");}
198
+ function youtube_widget_init() {
199
+ register_sidebar_widget(__('YouTube Embed'),'youtube_widget');
200
+ register_widget_control('YouTube Embed','youtube_widget_options');
201
+ }
202
+ function youtube_widget_options() {include_once(WP_PLUGIN_DIR."/youtube-embed/youtube-widget-options.php");}
203
+ ?>
youtube-widget-options.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $options=get_option("youtube_widget");
3
+ if (!is_array($options)) {
4
+ $options=array('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');
5
+ }
6
+ if ($_POST['youtube-widget-submit']) {
7
+ $options['id']=$_POST['youtube_widget_id'];
8
+ $options['type']=$_POST['youtube_widget_type'];
9
+ $options['width']=$_POST['youtube_widget_width'];
10
+ $options['height']=$_POST['youtube_widget_height'];
11
+ $options['border']=$_POST['youtube_widget_border'];
12
+ $options['fullscreen']=$_POST['youtube_widget_fullscreen'];
13
+ $options['hd']=$_POST['youtube_widget_hd'];
14
+ $options['color1']=$_POST['youtube_widget_color1'];
15
+ $options['color2']=$_POST['youtube_widget_color2'];
16
+ $options['style']=$_POST['youtube_widget_style'];
17
+ $options['autoplay']=$_POST['youtube_widget_autoplay'];
18
+ $options['start']=$_POST['youtube_widget_start'];
19
+ $options['loop']=$_POST['youtube_widget_loop'];
20
+ $options['cc']=$_POST['youtube_widget_cc'];
21
+ $options['annotation']=$_POST['youtube_widget_annotation'];
22
+ $options['egm']=$_POST['youtube_widget_egm'];
23
+ $options['related']=$_POST['youtube_widget_related'];
24
+ $options['info']=$_POST['youtube_widget_info'];
25
+ $options['search']=$_POST['youtube_widget_search'];
26
+ update_option("youtube_widget",$options);
27
+ }
28
+ ?>
29
+ <p>
30
+ <label for="youtube_widget_id"><?php _e('Video ID'); ?>: </label>
31
+ <input type="text" name="youtube_widget_id" value="<?php echo $options['id'];?>" /><br/>
32
+
33
+ <label for="youtube_widget_type"><?php _e('Embed Type'); ?>: </label>
34
+ <select name="youtube_widget_type">
35
+ <option value="v"<?php if ($options['type']=="v") {echo " selected='selected'";} ?>><?php _e('Video'); ?></option>
36
+ <option value="p"<?php if ($options['type']=="p") {echo " selected='selected'";} ?>><?php _e('Playlist'); ?></option>
37
+ </select><br/>
38
+
39
+ <h3><?php _e('Video Display Properties'); ?></h3>
40
+
41
+ <label for="youtube_widget_width"><?php _e('Width'); ?>: </label>
42
+ <input type="text" size="3" maxlength="3" name="youtube_widget_width" value="<?php echo $options['width']; ?>"/>px<br/>
43
+
44
+ <label for="youtube_widget_height"><?php _e('Height'); ?>: </label>
45
+ <input type="text" size="3" maxlength="3" name="youtube_widget_height" value="<?php echo $options['height']; ?>"/>px<br/>
46
+
47
+ <label for="youtube_widget_border"><?php _e('Show Border'); ?>: </label>
48
+ <select name="youtube_widget_border">
49
+ <option value="0"<?php if ($options['border']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
50
+ <option value="1"<?php if ($options['border']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
51
+ </select><br/>
52
+
53
+ <label for="youtube_widget_fullscreen"><?php _e('Fullscreen Button'); ?>: </label>
54
+ <select name="youtube_widget_fullscreen">
55
+ <option value="0"<?php if ($options['fullscreen']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
56
+ <option value="1"<?php if ($options['fullscreen']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
57
+ </select><br/>
58
+
59
+ <label for="youtube_widget_hd"><?php _e('Default to HD Quality'); ?>: </label>
60
+ <select name="youtube_widget_hd">
61
+ <option value="0"<?php if ($options['hd']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
62
+ <option value="1"<?php if ($options['hd']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
63
+ </select><br/>
64
+
65
+ <label for="youtube_widget_color1"><?php _e('Color 1'); ?>: </label>
66
+ #<input type="text" size="6" maxlength="6" name="youtube_widget_color1" value="<?php echo $options['color1']; ?>"/>&nbsp;<span style="padding-right: 16px; background-color: #<?php echo $options['color1']; ?>">&nbsp;</span><br/>
67
+
68
+ <label for="youtube_widget_color2"><?php _e('Color 2'); ?>: </label>
69
+ #<input type="text" size="6" maxlength="6" name="youtube_widget_color2" value="<?php echo $options['color2']; ?>"/>&nbsp;<span style="padding-right: 16px; background-color: #<?php echo $options['color2'] ?>">&nbsp;</span><br/>
70
+
71
+ <label for="youtube_widget_style"><?php _e('Style'); ?>: </label>
72
+ <input type="text" size="20" name="youtube_widget_style" value="<?php echo $options['style']; ?>"/><br/>
73
+
74
+ <h3><?php _e('Playback'); ?></h3>
75
+
76
+ <label for="youtube_widget_autoplay"><?php _e('Autoplay'); ?>: </label>
77
+ <select name="youtube_widget_autoplay">
78
+ <option value="0"<?php if ($options['autoplay']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
79
+ <option value="1"<?php if ($options['autoplay']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
80
+ </select><br/>
81
+
82
+ <label for="youtube_widget_start"><?php _e('Start'); ?>: </label>
83
+ <input type="text" size="3" maxlength="3" name="youtube_widget_start" value="<?php echo $options['start']; ?>"/> seconds<br/>
84
+
85
+ <label for="youtube_widget_loop"><?php _e('Loop Video'); ?>: </label>
86
+ <select name="youtube_widget_loop">
87
+ <option value="0"<?php if ($options['loop']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
88
+ <option value="1"<?php if ($options['loop']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
89
+ </select><br/>
90
+
91
+ <label for="youtube_widget_cc"><?php _e('Show Closed Captions'); ?>: </label>
92
+ <select name="youtube_widget_cc">
93
+ <option value="0"<?php if ($options['cc']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
94
+ <option value="1"<?php if ($options['cc']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
95
+ </select><br/>
96
+
97
+ <label for="youtube_widget_annotation"><?php _e('Show Annotations'); ?>: </label>
98
+ <select name="youtube_widget_annotation">
99
+ <option value="3"<?php if ($options['annotation']=="3") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
100
+ <option value="1"<?php if ($options['annotation']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
101
+ </select><br/>
102
+
103
+ <h3><?php _e('Video Information'); ?></h3>
104
+
105
+ <label for="youtube_widget_egm"><?php _e('Enable Enhanced Genie Menu'); ?>: </label>
106
+ <select name="youtube_widget_egm">
107
+ <option value="0"<?php if ($options['egm']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
108
+ <option value="1"<?php if ($options['egm']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
109
+ </select><br/>
110
+
111
+ <label for="youtube_widget_related"><?php _e('Show Related Videos'); ?>: </label>
112
+ <select name="youtube_widget_related">
113
+ <option value="0"<?php if ($options['related']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
114
+ <option value="1"<?php if ($options['related']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
115
+ </select><br/>
116
+
117
+ <label for="youtube_widget_info"><?php _e('Show Video Information'); ?>: </label>
118
+ <select name="youtube_widget_info">
119
+ <option value="0"<?php if ($options['info']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
120
+ <option value="1"<?php if ($options['info']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
121
+ </select><br/>
122
+
123
+ <label for="youtube_widget_search"><?php _e('Show Search Box'); ?>: </label>
124
+ <select name="youtube_widget_search">
125
+ <option value="0"<?php if ($options['search']=="0") {echo " selected='selected'";} ?>><?php _e('No'); ?></option>
126
+ <option value="1"<?php if ($options['search']=="1") {echo " selected='selected'";} ?>><?php _e('Yes'); ?></option>
127
+ </select>
128
+
129
+ <input type="hidden" id="youtube-widget-submit" name="youtube-widget-submit" value="1" />
130
+ </p>