Video Embed & Thumbnail Generator - Version 1.0

Version Description

Download this release

Release Info

Developer kylegilman
Plugin Icon 128x128 Video Embed & Thumbnail Generator
Version 1.0
Comparing to
See all releases

Code changes from version 0.2.1 to 1.0

kg_callffmpeg.php CHANGED
@@ -1,18 +1,25 @@
1
  <?php
2
 
3
  $ffmpegPath = $_POST['ffmpeg']."/ffmpeg";
 
 
4
  $movieurl = $_POST['movieurl'];
5
  $numberofthumbs = $_POST['numberofthumbs'];
6
- $randomize = $_POST['randomize'];
7
  $action = $_POST['action'];
8
  $poster = $_POST['poster'];
9
- $uploads = $_POST['uploads'];
 
 
 
 
 
 
10
 
11
  $moviefilepath = str_replace(" ", "%20", $movieurl);
12
  $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
13
  $moviefilebasename = basename($movieurl,'.'.$movie_extension);
14
- $moviefilebasename = str_replace(" ", "_", $moviefilebasename);
15
- $thumbnailfilebase = $uploads[url]."/thumb_tmp/".$moviefilebasename;
16
 
17
  class Process{
18
  private $pid;
@@ -26,6 +33,7 @@ class Process{
26
  }
27
  private function runCom(){
28
  $command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
 
29
  exec($command ,$op);
30
  $this->pid = (int)$op[0];
31
  }
@@ -68,7 +76,7 @@ class Process{
68
  */
69
  function get_video_dimensions($video = false) {
70
  global $ffmpegPath;
71
- $command = $ffmpegPath . ' -i ' . $video . ' -vstats 2>&1';
72
 
73
  exec ( $command, $output );
74
  $output = implode("\n", $output);
@@ -123,40 +131,61 @@ if ($action == generate || $action == encode ) {
123
 
124
  if ($action == generate) {
125
 
126
- //chdir($uploads['path']);
127
- rrmdir($uploads['path'].'/thumb_tmp');
128
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
129
- //foreach (glob($moviefilebasename."*.jpg") as $filename) {
130
- // unlink($filename); // delete the old thumbnails
131
- //}
132
 
133
  $thumbnailheight = strval(round(floatval($movie_height) / floatval($movie_width) * 200));
134
- $jpgpath = $uploads[path]."/thumb_tmp/";
135
 
136
  $i = 1;
137
  $increaser = 0;
138
 
 
 
139
  while ($i <= $numberofthumbs) {
140
 
141
  $iincreaser = $i + $increaser;
142
  $movieoffset = round(($movie_duration_seconds * $iincreaser) / ($numberofthumbs * 2));
143
 
144
- if ($randomize == 1) { //adjust offset random amount
145
  $movieoffset = $movieoffset - rand(0, round($movie_duration_seconds / $numberofthumbs));
146
  }
147
 
148
- $thumbnailfilename[$i] = $jpgpath.$moviefilebasename.$i.".jpg";
149
- $ffmpeg_options = "-ss $movieoffset -i ".$moviefilepath." -vframes 1 ".$thumbnailfilename[$i];
150
- $thumbnailurl = $thumbnailfilebase.$i.'.jpg';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
- //$process = new Process($ffmpegPath." ".$ffmpeg_options);
153
- //sleep(1);
154
  exec($ffmpegPath." ".$ffmpeg_options);
155
- $thumbnaildisplaycode = $thumbnaildisplaycode.'<div style="text-align:center; display:inline-block; margin:2px;"><label for="kgflashmedia-thumb'.$i.'"><img src="'.$thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'"></label><br /><input type="radio" name="kgflashmedia-thumb" id="kgflashmedia-thumb'.$i.'" value="'.str_replace('/thumb_tmp/', '/', $thumbnailurl).'" onchange="getElementById(\'kgflashmediaplayer-poster\').value = this.value;"></div>';
 
 
 
 
 
 
 
 
156
 
157
  $increaser++;
158
  $i++;
159
- }
 
 
160
 
161
  $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "movie_width"=>$movie_width, "movie_height"=>$movie_height );
162
 
@@ -164,35 +193,72 @@ if ($action == generate || $action == encode ) {
164
  }//if generate
165
 
166
  if ($action == encode) {
167
- $encodepath = $uploads[path]."/";
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  $ipodfilepath = $encodepath.$moviefilebasename."-ipod.m4v";
169
  $ogvfilepath = $encodepath.$moviefilebasename.".ogv";
 
170
 
171
- if ( ! file_exists($ipodfilepath) ) {
172
- $ipod_movie_height = strval(round(floatval($movie_height) / floatval($movie_width) * 640));
173
  if ($ipod_movie_height % 2 != 0) { $ipod_movie_height++; }
174
  if ( strpos($movie_info['configuration'], 'enable-libfaac') && strpos($movie_info['configuration'], 'enable-libx264') ) {
175
- $ffmpeg_ipod_options = " -acodec libfaac -ab 128k -s 640x".$ipod_movie_height." -vcodec libx264 -vpre slow -vpre ipod640 -b 800k -bt 800k -threads 0 -f ipod ".$ipodfilepath;
176
- echo "<strong> Encoding iPod... </strong>";
177
  }//if the proper FFMPEG libraries are enabled
178
- else { echo "<strong>FFMPEG missing library 'libfaac' or 'libx264' required for iPod encoding. </strong></strong>"; }
179
  }//if iPod file doesn't already exist
180
- else { echo "<strong>iPod Already Encoded! </strong>"; }
181
 
182
- if ( ! file_exists($ogvfilepath) ) {
 
183
  if ( strpos($movie_info['configuration'], 'enable-libvorbis') && strpos($movie_info['configuration'], 'enable-libtheora') ) {
184
  $ogvbitrate = $movie_height * 3;
185
- $ffmpeg_ogv_options = " -acodec libvorbis -ab 128k -vcodec libtheora -b ".$ogvbitrate."k -threads 0 ".$ogvfilepath;
186
- echo "<strong> Encoding OGG... </strong>";
187
  }//if the proper FFMPEG libraries are enabled
188
- else { echo "<strong>FFMPEG missing library 'libvorbis' or 'libtheora' required for ogv encoding.</strong></strong>"; }
189
  }//if ogv doesn't already exist
190
- else { echo "<strong>OGG Already Encoded!</strong>"; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
- if ( ! file_exists($ogvfilepath) || ! file_exists($ipodfilepath) ) {
193
- $ffmpeg_options = "-i ".$moviefilepath.$ffmpeg_ipod_options.$ffmpeg_ogv_options;
194
- $process = new Process($ffmpegPath." ".$ffmpeg_options);
195
- }//if both HTML5 videos don't exist
 
 
 
 
 
 
 
 
196
 
197
  }//if encode
198
 
@@ -215,17 +281,32 @@ if ($action == generate || $action == encode ) {
215
 
216
  if ($action == delete) {
217
 
 
 
 
 
 
218
  rrmdir($uploads['path'].'/thumb_tmp');
219
- echo ("<strong>Thumbnails Deleted</strong>");
 
 
220
 
221
  }//if delete
222
 
 
223
  if ($action == submit) {
224
 
225
  $posterfile = pathinfo($poster, PATHINFO_BASENAME);
226
- copy($uploads['path'].'/thumb_tmp/'.$posterfile, $uploads['path'].'/'.$posterfile);
227
- //rrmdir($uploads['path'].'/thumb_tmp');
 
 
 
 
 
 
228
 
229
  }//if submit
230
 
 
231
  ?>
1
  <?php
2
 
3
  $ffmpegPath = $_POST['ffmpeg']."/ffmpeg";
4
+ $encodeogg = $_POST['encodeogg'];
5
+ $encodewebm = $_POST['encodewebm'];
6
  $movieurl = $_POST['movieurl'];
7
  $numberofthumbs = $_POST['numberofthumbs'];
8
+ //$randomize = $_POST['randomize'];
9
  $action = $_POST['action'];
10
  $poster = $_POST['poster'];
11
+ $uploads['path'] = $_POST['uploads_path'];
12
+ $uploads['url'] = $_POST['uploads_url'];
13
+ $uploads['basedir'] = $_POST['uploads_basedir'];
14
+ $postID = $_POST['attachmentID'];
15
+ $thumbtimecode = $_POST['thumbtimecode'];
16
+ $dofirstframe = $_POST['dofirstframe'];
17
+ $generate_button = $_POST['generate_button'];
18
 
19
  $moviefilepath = str_replace(" ", "%20", $movieurl);
20
  $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
21
  $moviefilebasename = basename($movieurl,'.'.$movie_extension);
22
+ $thumbnailfilebase = $uploads['url']."/thumb_tmp/".$moviefilebasename;
 
23
 
24
  class Process{
25
  private $pid;
33
  }
34
  private function runCom(){
35
  $command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
36
+ //$command = 'nohup '.$this->command.' 1> /home/kylegilm/output.txt 2>&1';
37
  exec($command ,$op);
38
  $this->pid = (int)$op[0];
39
  }
76
  */
77
  function get_video_dimensions($video = false) {
78
  global $ffmpegPath;
79
+ $command = $ffmpegPath . ' -i "' . $video . '" -vstats 2>&1';
80
 
81
  exec ( $command, $output );
82
  $output = implode("\n", $output);
131
 
132
  if ($action == generate) {
133
 
134
+ //rrmdir($uploads['path'].'/thumb_tmp');
 
135
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
 
 
 
136
 
137
  $thumbnailheight = strval(round(floatval($movie_height) / floatval($movie_width) * 200));
138
+ $jpgpath = $uploads['path']."/thumb_tmp/";
139
 
140
  $i = 1;
141
  $increaser = 0;
142
 
143
+ $thumbnaildisplaycode = '<p><strong>Choose Thumbnail:</strong></p><div style="border-style:solid; border-color:#ccc; border-width:1px; width:425px; text-align:center; margin-bottom:10px; padding:5px;">';
144
+
145
  while ($i <= $numberofthumbs) {
146
 
147
  $iincreaser = $i + $increaser;
148
  $movieoffset = round(($movie_duration_seconds * $iincreaser) / ($numberofthumbs * 2));
149
 
150
+ if ($generate_button == "random") { //adjust offset random amount
151
  $movieoffset = $movieoffset - rand(0, round($movie_duration_seconds / $numberofthumbs));
152
  }
153
 
154
+ if ($thumbtimecode) { //if a specific thumbnail timecode is set
155
+ if ($thumbtimecode == "firstframe") { $thumbtimecode = "0"; }
156
+ $timecode_array = explode(":", $thumbtimecode);
157
+ $timecode_array = array_reverse($timecode_array);
158
+ $thumbtimecode = $timecode_array[0] + ($timecode_array[1] * 60) + ($timecode_array[2] * 3600);
159
+ $movieoffset = $thumbtimecode;
160
+ $i = $numberofthumbs + 1;
161
+ }
162
+
163
+ if ($dofirstframe == "true" && $i == 1) {
164
+ $movieoffset = "0";
165
+ }
166
+
167
+ $thumbnailfilename[$i] = $jpgpath.$moviefilebasename."_thumb".$i.".jpg";
168
+ $thumbnailfilename[$i] = str_replace(" ", "_", $thumbnailfilename[$i]);
169
+ $ffmpeg_options = '-ss '.$movieoffset.' -i "'.$moviefilepath.'" -vframes 1 "'.$thumbnailfilename[$i].'"';
170
+ $thumbnailurl = $thumbnailfilebase."_thumb".$i.'.jpg';
171
+ $thumbnailurl = str_replace(" ", "_", $thumbnailurl);
172
 
 
 
173
  exec($ffmpegPath." ".$ffmpeg_options);
174
+
175
+ if (floatval($movieoffset) > 60) {
176
+ $movieoffset_minutes = sprintf("%02s", intval(intval($movieoffset) / 60) );
177
+ $movieoffset_seconds = sprintf("%02s", round(fmod( floatval($movieoffset), 60), 2) );
178
+ $movieoffset_display = $movieoffset_minutes.":".$movieoffset_seconds;
179
+ }
180
+ else { $movieoffset_display = "00:".sprintf("%02s", $movieoffset); }
181
+
182
+ $thumbnaildisplaycode = $thumbnaildisplaycode.'<div style="text-align:center; display:inline-block; margin:2px;"><label for="kgflashmedia-thumb'.$i.'"><img src="'.$thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'"></label><br /><input type="radio" name="kgflashmedia-thumb" id="kgflashmedia-thumb'.$i.'" value="'.str_replace('/thumb_tmp/', '/', $thumbnailurl).'" onchange="getElementById(\'attachments['. $postID .'][kgflashmediaplayer-poster]\').value = this.value; getElementById(\'attachments['. $postID .'][thumbtime]\').value = \''. $movieoffset_display .'\'; getElementById(\'attachments_'. $postID .'_numberofthumbs\').value =\'1\';"></div>';
183
 
184
  $increaser++;
185
  $i++;
186
+ } //end thumbnail loop
187
+
188
+ //$thumbnaildisplaycode = $thumbnaildisplaycode.'<p><input type="button" id="attachments['. $postID .'][confirmbutton]" class="button-secondary" value="Confirm" name="confirmbutton" onclick="kg_generate_thumb('. $postID .', \'confirm\');"/></p>';
189
 
190
  $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "movie_width"=>$movie_width, "movie_height"=>$movie_height );
191
 
193
  }//if generate
194
 
195
  if ($action == encode) {
196
+
197
+ //preferred encode path is the directory of the original file (likely in the wp_upload dir)
198
+ $encodepath = "";
199
+ $url_parts = parse_url($uploads['url']);
200
+ if ( strpos($moviefilepath, $url_parts['host']) != "" ) { //if we're on the same server
201
+ $home_path = substr(strrev(strstr(strrev($uploads['basedir']), strrev("public_html"))), 0, -strlen("public_html")); //home path of the current server
202
+ $moviefiledirectory = dirname(parse_url($moviefilepath, PHP_URL_PATH)); //gets file's directory
203
+ $encodepath = $home_path."public_html".$moviefiledirectory."/";
204
+ }
205
+ if ( !is_writable($encodepath) ) { //if the original directory is not writable use a directory in base wp_upload
206
+ $encodepath = $uploads['basedir']."/html5encodes/";
207
+ if ( !file_exists($encodepath) ) { mkdir($encodepath); }
208
+ }
209
+
210
  $ipodfilepath = $encodepath.$moviefilebasename."-ipod.m4v";
211
  $ogvfilepath = $encodepath.$moviefilebasename.".ogv";
212
+ $webmfilepath = $encodepath.$moviefilebasename.".webm";
213
 
214
+ if ( ! file_exists($ipodfilepath) || filesize($webmfilepath) < 102400 ) {
215
+ $ipod_movie_height = strval(round(floatval($movie_height) / floatval($movie_width) * 640));
216
  if ($ipod_movie_height % 2 != 0) { $ipod_movie_height++; }
217
  if ( strpos($movie_info['configuration'], 'enable-libfaac') && strpos($movie_info['configuration'], 'enable-libx264') ) {
218
+ $ffmpeg_ipod_options = ' -acodec libfaac -ab 128k -s 640x'.$ipod_movie_height.' -vcodec libx264 -vpre slow -vpre ipod640 -b 800k -bt 800k -threads 0 -f ipod "'.$ipodfilepath.'"';
219
+ $embed_display .= "<strong> Encoding Mobile M4V... </strong>";
220
  }//if the proper FFMPEG libraries are enabled
221
+ else { $embed_display .= "<strong>FFMPEG missing library 'libfaac' or 'libx264' required for iPod encoding. </strong>"; }
222
  }//if iPod file doesn't already exist
223
+ else { $embed_display .= "<strong>Mobile M4V Already Encoded! </strong>"; }
224
 
225
+ if ($encodeogg == "true") {
226
+ if ( ! file_exists($ogvfilepath) || filesize($webmfilepath) < 102400 ) {
227
  if ( strpos($movie_info['configuration'], 'enable-libvorbis') && strpos($movie_info['configuration'], 'enable-libtheora') ) {
228
  $ogvbitrate = $movie_height * 3;
229
+ $ffmpeg_ogv_options = ' -acodec libvorbis -ab 128k -vcodec libtheora -b '.$ogvbitrate.'k -threads 0 "'.$ogvfilepath.'"';
230
+ $embed_display .= "<strong> Encoding OGG... </strong>";
231
  }//if the proper FFMPEG libraries are enabled
232
+ else { $embed_display .= "<strong>FFMPEG missing library 'libvorbis' or 'libtheora' required for ogv encoding. </strong>"; }
233
  }//if ogv doesn't already exist
234
+ else { $embed_display .= "<strong>OGG Already Encoded! </strong>"; }
235
+ }//if encodeogg is checked
236
+
237
+ if ($encodewebm == "true") {
238
+ if ( ! file_exists($webmfilepath) || filesize($webmfilepath) < 102400 ) {
239
+ if ( strpos($movie_info['configuration'], 'enable-libvorbis') && strpos($movie_info['configuration'], 'enable-libvpx') ) {
240
+ $webmbitrate = $movie_height * 3;
241
+ $ffmpeg_webm_options = ' -ab 128k -b '.$webmbitrate.'k -threads 0 "'.$webmfilepath.'"';
242
+ $embed_display .= "<strong> Encoding WEBM... </strong>";
243
+ }//if the proper FFMPEG libraries are enabled
244
+ else { $embed_display .= "<strong>FFMPEG missing library 'libvorbis' or 'libvpx' required for webm encoding. </strong>"; }
245
+ }//if webm doesn't already exist
246
+ else { $embed_display .= "<strong>WEBM Already Encoded! </strong>"; }
247
+ }//if encodewebm is checked
248
+
249
 
250
+ if ( ! file_exists($ogvfilepath) || ! file_exists($ipodfilepath) || ! file_exists($webmfilepath) ) {
251
+ $ffmpeg_options = '-i "'.$moviefilepath.'"'.$ffmpeg_ipod_options.$ffmpeg_ogv_options.$ffmpeg_webm_options;
252
+ exec('ps -aux', $pslist);
253
+ $pslist = print_r($pslist, true);
254
+ if ( strpos($pslist, $ffmpegPath) ) { $embed_display = "<strong>FFMPEG is busy. You'll have to wait until it's finished. Sorry, there's no queue.<strong>"; }
255
+ else { $process = new Process($ffmpegPath." ".$ffmpeg_options); }
256
+
257
+ }//if any HTML5 videos don't already exist
258
+ //$embed_display .= $ffmpeg_options;
259
+ $arr = array ( "embed_display"=>$embed_display );
260
+
261
+ echo json_encode($arr);
262
 
263
  }//if encode
264
 
281
 
282
  if ($action == delete) {
283
 
284
+ if ($poster) {
285
+ $posterfile = pathinfo($poster, PATHINFO_BASENAME);
286
+ $posterpath = $uploads['path'].'/'.$posterfile;
287
+ if ( file_exists($posterpath) ) { unlink($posterpath); }
288
+ }
289
  rrmdir($uploads['path'].'/thumb_tmp');
290
+ $thumbnaildisplaycode = "<strong>Thumbnails Deleted</strong>";
291
+ $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode );
292
+ echo json_encode($arr);
293
 
294
  }//if delete
295
 
296
+
297
  if ($action == submit) {
298
 
299
  $posterfile = pathinfo($poster, PATHINFO_BASENAME);
300
+ $tmp_posterpath = $uploads["path"].'/thumb_tmp/'.$posterfile;
301
+ $final_posterpath = $uploads["path"].'/'.$posterfile;
302
+ if ( is_file($tmp_posterpath) ) { copy($tmp_posterpath, $final_posterpath); }
303
+ rrmdir($uploads['path'].'/thumb_tmp');
304
+
305
+ //$arr = array ( "posterfile"=>$posterfile, "tmp_posterpath"=>$tmp_posterpath, "final_posterpath"=>$final_posterpath );
306
+ echo json_encode($arr);
307
+
308
 
309
  }//if submit
310
 
311
+
312
  ?>
kg_video_plugin.js CHANGED
@@ -1,194 +1,109 @@
1
- // closure to avoid namespace collision
2
-
3
- function tb_remove() {
4
-
5
- jQuery.post(kg_plugin_dir + '/kg_callffmpeg.php', { action: 'delete', uploads: kg_upload_dir } );
6
- jQuery("#TB_imageOff").unbind("click");
7
- jQuery("#TB_closeWindowButton").unbind("click");
8
- jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
9
- jQuery("#TB_load").remove();
10
- if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
11
- $("body","html").css({height: "auto", width: "auto"});
12
- $("html").css("overflow","");
13
- }
14
- document.onkeydown = "";
15
- document.onkeyup = "";
16
- jQuery('#thumbnailplaceholder').empty();
17
- jQuery('#html5placeholder').empty();
18
- jQuery('#kgflashmediaplayer-poster').val("");
19
- return false;
20
-
21
  }
22
 
 
 
 
23
 
24
- (function(){
25
- // creates the plugin
26
- tinymce.create('tinymce.plugins.kgvideoplayer', {
27
- // creates control instances based on the control's id.
28
- // our button's id is "kgvideoplayer_button"
29
- createControl : function(id, controlManager) {
30
- if (id == 'kgvideoplayer_button') {
31
- // creates the button
32
- var button = controlManager.createButton('kgvideoplayer_button', {
33
- title : 'Video Embed & Thumbnail Generator', // title of the button
34
- image : kg_plugin_dir+'/images/cameranoise_logo.png', // path to the button's image
35
- onclick : function() {
36
- // triggers the thickbox
37
- var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
38
- W = W - 80;
39
- H = H - 84;
40
- tb_show( 'Video Embed & Thumbnail Generator', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=kgflashmediaplayer-form' );
41
- }
42
- });
43
- return button;
44
- }
45
- return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
- });
48
-
49
- // registers the plugin. DON'T MISS THIS STEP!!!
50
- tinymce.PluginManager.add('kgvideoplayer', tinymce.plugins.kgvideoplayer);
51
-
52
- // executes this when the DOM is ready
53
- jQuery(function(){
54
- // creates a form to be displayed everytime the button is clicked
55
- // you should achieve this using AJAX instead of direct html code like this
56
-
57
- kg_aspect = (kg_height_option/kg_width_option);
58
-
59
- var form = jQuery('<div id="kgflashmediaplayer-form"><table id="kgflashmediaplayer-table" class="form-table">\
60
- <tr>\
61
- <th><label for="videotitle">Video Title</label></th>\
62
- <td><input type="text" id="videotitle" name="videotitle" value="" size="50" /><br />\
63
- <small>Add an optional header above the video.</small></td>\
64
- </tr>\
65
- <tr>\
66
- <th><label for="kgflashmediaplayer-url">Video URL</label></th>\
67
- <td><input type="text" id="kgflashmediaplayer-url" name="url" value="" size="50" onchange="document.getElementById(\'html5placeholder\').innerHTML = \'\';"/><br />\
68
- <small>Specify the URL of the video file you uploaded.</small></td>\
69
- </tr>\
70
- <tr><td colspan = "2"><div id="thumbnailplaceholder"></div></td></tr>\
71
- <tr>\
72
- <th><label for="numberofthumbs">Number of Thumbnails</label</th>\
73
- <td><input type="text" id="numberofthumbs" name="numberofthumbs" value="3" size="3" maxlength="2" /><input type="button" id="thumbgenerate" class="button-secondary" value="Generate" name="thumbgenerate" /><input type="button" id="thumbrandomize" class="button-secondary" value="Randomize" name="thumbrandomize" /><!--<input type="button" id="thumbdelete" class="button-secondary" value="Delete" name="thumbdelete" />--></td>\
74
- </tr>\
75
- <tr>\
76
- <th><label for="kgflashmediaplayer-poster">Poster URL</label></th>\
77
- <td><input type="text" name="poster" id="kgflashmediaplayer-poster" value="" size="50" /><br />\
78
- <small>Specify the URL of the poster image. Leave blank if you want to use the default.</small>\
79
- </tr>\
80
- <tr>\
81
- <th><label for="kgflashmediaplayer-width">Width</label></th>\
82
- <td><input type="text" name="width" id="kgflashmediaplayer-width" value="'+kg_width_option+'" size="4" maxlength="4" onchange="if (document.getElementById(\'lockaspect\').checked == true) { document.getElementById(\'kgflashmediaplayer-height\').value=Math.round(this.value*kg_aspect); }" /> <input type="checkbox" name="lockaspect" id="lockaspect" checked> <label for="lockaspect"><small>Lock Aspect Ratio</small></label><br />\
83
- <small>Specify the displayed width of the video.</small></td>\
84
- </tr>\
85
- <tr>\
86
- <th><label for="kgflashmediaplayer-height">Height</label></th>\
87
- <td><input type="text" name="height" id="kgflashmediaplayer-height" value="'+kg_height_option+'" onchange="if (document.getElementById(\'lockaspect\').checked == true) { document.getElementById(\'kgflashmediaplayer-width\').value=Math.round(this.value/kg_aspect); }" size="4" maxlength="4" /><br />\
88
- <small>Specify the displayed height of the video.</small></td>\
89
- </tr>\
90
- <tr>\
91
- <th><label for="downloadlink">Include Download Link</label></th>\
92
- <td><input type="checkbox" name="downloadlink" id="downloadlink" value="true" /><br /></td>\
93
- </tr>\
94
- <tr><td colspan = "2"><input type="button" id="html5" class="button-secondary" value="Generate HTML5 Videos" name="html5" /><div id="html5placeholder" style="display:inline-block;"></div></td></tr>\
95
- </table>\
96
- <p class="submit">\
97
- <input type="button" id="kgflashmediaplayer-submit" class="button-primary" value="Insert Flash Media Player" name="submit" />\
98
- </p>\
99
- </div>');
100
-
101
- var table = form.find('table');
102
- form.appendTo('body').hide();
103
-
104
- //handles the click event of the generate button
105
- form.find('#thumbgenerate').click(function(){
106
- jQuery('#thumbnailplaceholder').empty();
107
- jQuery('#thumbnailplaceholder').append('<strong>Loading...</strong>');
108
- jQuery.post(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), numberofthumbs: table.find('#numberofthumbs').val(), action: 'generate', ffmpeg: kg_ffmpeg_path, uploads: kg_upload_dir }, function(data) {
109
- jQuery('#thumbnailplaceholder').empty();
110
- jQuery('#thumbnailplaceholder').append(data.thumbnaildisplaycode);
111
- kg_aspect = data.movie_height/data.movie_width;
112
- if (parseInt(data.movie_width) < parseInt(kg_width_option) ) { jQuery('#kgflashmediaplayer-width').val(data.movie_width); }
113
- else { jQuery('#kgflashmediaplayer-width').val(kg_width_option); }
114
- if (parseInt(data.movie_width) > parseInt(kg_width_option) ) { jQuery('#kgflashmediaplayer-height').val(Math.round(kg_aspect*kg_width_option)); }
115
- else { jQuery('#kgflashmediaplayer-height').val(data.movie_height); }
116
- }, "json");
117
- });
118
-
119
- //handles the click event of the randomize button
120
- form.find('#thumbrandomize').click(function(){
121
- jQuery('#thumbnailplaceholder').empty();
122
- jQuery('#thumbnailplaceholder').append('<strong>Loading...</strong>');
123
- jQuery.post(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), numberofthumbs: table.find('#numberofthumbs').val(), randomize: '1', action: 'generate', ffmpeg: kg_ffmpeg_path, uploads: kg_upload_dir }, function(data) {
124
- jQuery('#thumbnailplaceholder').empty();
125
- jQuery('#thumbnailplaceholder').append(data.thumbnaildisplaycode);
126
  kg_aspect = data.movie_height/data.movie_width;
127
- if (parseInt(data.movie_width) < parseInt(kg_width_option) ) { jQuery('#kgflashmediaplayer-width').val(data.movie_width); }
128
- else { jQuery('#kgflashmediaplayer-width').val(kg_width_option); }
129
- if (parseInt(data.movie_width) > parseInt(kg_width_option) ) { jQuery('#kgflashmediaplayer-height').val(Math.round(kg_aspect*kg_width_option)); }
130
- else { jQuery('#kgflashmediaplayer-height').val(data.movie_height); }
131
- }, "json");
132
- //jQuery('#thumbnailplaceholder').load(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), action: 'generate', poster: table.find('#kgflashmediaplayer-poster').val(), uploads: kg_upload_dir, ffmpeg: kg_ffmpeg_path, numberofthumbs: table.find('#numberofthumbs').val() } );
133
- });
134
-
135
- //handles the click event of the delete button
136
- form.find('#thumbdelete').click(function(){
137
- jQuery('#thumbnailplaceholder').empty();
138
- jQuery('#thumbnailplaceholder').append('<strong>Deleting...</strong>');
139
- jQuery('#thumbnailplaceholder').load(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), action: 'delete', poster: table.find('#kgflashmediaplayer-poster').val(), uploads: kg_upload_dir } );
140
- });
141
-
142
- //handles the click event of the HTML5 button
143
- form.find('#html5').click(function(){
144
- jQuery('#html5placeholder').empty();
145
- jQuery('#html5placeholder').load(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), action: 'encode', ffmpeg: kg_ffmpeg_path, uploads: kg_upload_dir } );
146
- });
147
-
148
- // handles the click event of the submit button
149
- form.find('#kgflashmediaplayer-submit').click(function(){
150
- //delete unused thumbnails
151
- jQuery.post(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: table.find('#kgflashmediaplayer-url').val(), action:'submit', poster:table.find('#kgflashmediaplayer-poster').val(), uploads: kg_upload_dir }, function(data) {
152
- //jQuery('#thumbnailplaceholder').append(data.thumbnaildisplaycode);
153
- jQuery('#thumbnailplaceholder').empty();
154
- }, "json" );
155
-
156
- // defines the options and their default values
157
- // again, this is not the most elegant way to do this
158
- // but well, this gets the job done nonetheless
159
- var options = {
160
- 'url' : '',
161
- 'poster' : '',
162
- 'width' : '',
163
- 'height' : ''
164
- };
165
-
166
- var videotitle = '<p><strong>' + table.find('#videotitle').val() + '</strong></p>';
167
- var shortcode = '[FMP';
168
-
169
- for( var index in options) {
170
- var value = table.find('#kgflashmediaplayer-' + index).val();
171
-
172
- // attaches the attribute to the shortcode only if it's different from the default value
173
- if ( value !== options[index] )
174
- if ( index !== 'url' )
175
- shortcode += ' ' + index + '="' + value + '"';
176
  }
177
-
178
- shortcode += ']' + table.find('#kgflashmediaplayer-url').val();
179
- shortcode += '[/FMP]';
180
- if ( document.getElementById('downloadlink').checked == true )
181
- shortcode += '<p><a href="' + table.find('#kgflashmediaplayer-url').val() + '">Right-click this link to download</a></p>';
182
-
183
- // inserts the shortcode into the active editor
184
- if ( table.find('#videotitle').val() !== "")
185
- tinyMCE.activeEditor.execCommand('mceInsertContent', 0, videotitle);
186
-
187
- tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
188
-
189
- // closes Thickbox
190
- tb_remove();
191
- });
192
-
193
- });
194
- })()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function kg_set_dimension(postID, valuetochange, currentvalue) {
2
+ var kg_aspect = (document.getElementById('attachments['+postID+'][kgflashmediaplayer-aspect]').value);
3
+ var changeaspect = kg_aspect;
4
+ if (valuetochange == "width") { changeaspect = 1/kg_aspect; }
5
+ var changedvalue = Math.round(currentvalue*changeaspect);
6
+ if (document.getElementById('attachments_'+postID+'_kgflashmediaplayer-lockaspect').checked == true && changedvalue != 0) {
7
+ document.getElementById('attachments_'+postID+'_kgflashmediaplayer-'+valuetochange).value = changedvalue;
8
+ }
9
+ if(postID != "singleurl") {
10
+ document.getElementById('attachments['+postID+'][kgflashmediaplayer-widthsave]').value = document.getElementById('attachments_'+postID+'_kgflashmediaplayer-width').value;
11
+ document.getElementById('attachments['+postID+'][kgflashmediaplayer-heightsave]').value = document.getElementById('attachments_'+postID+'_kgflashmediaplayer-height').value;
12
+ }
 
 
 
 
 
 
 
 
13
  }
14
 
15
+ function kg_set_aspect(postID, checked) {
16
+ if (checked) { document.getElementById('attachments['+postID+'][kgflashmediaplayer-aspect]').value = document.getElementById('attachments_'+postID+'_kgflashmediaplayer-height').value / document.getElementById('attachments_'+postID+'_kgflashmediaplayer-width').value; }
17
+ }
18
 
19
+ function kg_generate_thumb(postID, buttonPushed) {
20
+
21
+ var kg_ffmpeg_path = document.getElementById('attachments['+postID+'][kgflashmediaplayer-ffmpeg_path]').value;
22
+ var kg_encodeogg = document.getElementById('attachments['+postID+'][kgflashmediaplayer-encodeogg]').value;
23
+ var kg_encodewebm = document.getElementById('attachments['+postID+'][kgflashmediaplayer-encodewebm]').value;
24
+ var kg_plugin_dir = document.getElementById('attachments['+postID+'][kgflashmediaplayer-plugin_dir]').value;
25
+ var kg_upload_dir_url = document.getElementById('attachments['+postID+'][kgflashmediaplayer-upload_url]').value;
26
+ var kg_upload_dir_path = document.getElementById('attachments['+postID+'][kgflashmediaplayer-upload_path]').value;
27
+ var kg_upload_dir_basedir = document.getElementById('attachments['+postID+'][kgflashmediaplayer-upload_basedir]').value;
28
+ var attachmentURL = document.getElementById('attachments['+postID+'][kgflashmediaplayer-url]').value;
29
+ var howmanythumbs = document.getElementById('attachments_'+postID+'_numberofthumbs').value;
30
+ var firstframethumb = document.getElementById('attachments_'+postID+'_firstframe').checked;
31
+ var posterurl = document.getElementById('attachments['+postID+'][kgflashmediaplayer-poster]').value;
32
+ var specifictimecode = document.getElementById('attachments['+postID+'][thumbtime]').value;
33
+ if (specifictimecode === "0") { specifictimecode = "firstframe"; }
34
+ var thumbnailplaceholderid = "#attachments_"+postID+"_thumbnailplaceholder";
35
+ var encodeplaceholderid = "#attachments_"+postID+"_encodeplaceholder";
36
+ var widthID = 'attachments_'+postID+'_kgflashmediaplayer-width';
37
+ var heightID = 'attachments_'+postID+'_kgflashmediaplayer-height';
38
+ var widthsaveID = 'attachments['+postID+'][kgflashmediaplayer-widthsave]';
39
+ var heightsaveID = 'attachments['+postID+'][kgflashmediaplayer-heightsave]';
40
+ var maxwidthID = 'attachments['+postID+'][kgflashmediaplayer-maxwidth]';
41
+ var maxheightID = 'attachments['+postID+'][kgflashmediaplayer-maxheight]';
42
+
43
+
44
+ if (buttonPushed == "generate" || buttonPushed == "random" ) { actionName = "generate"; }
45
+ else { actionName = buttonPushed; }
46
+
47
+ if (buttonPushed == "delete") {
48
+ document.getElementById('attachments['+postID+'][kgflashmediaplayer-poster]').value = "";
49
+ document.getElementById('attachments['+postID+'][thumbtime]').value = "";
50
+ }
51
+
52
+ if (buttonPushed != "encode") {
53
+ jQuery(thumbnailplaceholderid).empty();
54
+ jQuery(thumbnailplaceholderid).append('<strong>Loading...</strong>');
55
+ }
56
+
57
+ if (buttonPushed == "encode") {
58
+ jQuery(encodeplaceholderid).empty();
59
+ }
60
+
61
+ jQuery.post(kg_plugin_dir + '/kg_callffmpeg.php', { movieurl: attachmentURL, numberofthumbs: howmanythumbs, action: actionName, ffmpeg: kg_ffmpeg_path, encodeogg: kg_encodeogg, encodewebm: kg_encodewebm, uploads_path: kg_upload_dir_path, uploads_url: kg_upload_dir_url, uploads_basedir: kg_upload_dir_basedir, attachmentID: postID, generate_button: buttonPushed, thumbtimecode: specifictimecode, dofirstframe: firstframethumb, poster: posterurl }, function(data) {
62
+
63
+ if (buttonPushed != "encode") {
64
+ jQuery(thumbnailplaceholderid).empty();
65
+ jQuery(thumbnailplaceholderid).append(data.thumbnaildisplaycode);
66
  }
67
+
68
+ if (actionName == "generate") {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  kg_aspect = data.movie_height/data.movie_width;
70
+ document.getElementById('attachments['+postID+'][kgflashmediaplayer-aspect]').value = kg_aspect;
71
+ if (parseInt(data.movie_width) < parseInt(document.getElementById(maxwidthID).value) ) { document.getElementById(widthID).value = data.movie_width; }
72
+ else { document.getElementById(widthID).value = document.getElementById(maxwidthID).value; }
73
+ if (parseInt(data.movie_width) > parseInt(document.getElementById(maxwidthID).value) ) { document.getElementById(heightID).value = Math.round(kg_aspect*parseInt(document.getElementById(maxwidthID).value)); }
74
+ else { document.getElementById(heightID).value = data.movie_height; }
75
+ if(postID != "singleurl") {
76
+ document.getElementById(widthsaveID).value = document.getElementById(widthID).value;
77
+ document.getElementById(heightsaveID).value = document.getElementById(heightID).value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
+ }
80
+
81
+ if (buttonPushed == "encode") {
82
+ jQuery(encodeplaceholderid).append(data.embed_display);
83
+ }
84
+
85
+ }, "json");
86
+
87
+ }
88
+
89
+ function kg_insert_shortcode() {
90
+
91
+ jQuery.post(document.getElementById('attachments[singleurl][kgflashmediaplayer-plugin_dir]').value + '/kg_callffmpeg.php', {
92
+ movieurl: document.getElementById('attachments[singleurl][kgflashmediaplayer-url]').value, action:'submit', poster: document.getElementById('attachments[singleurl][kgflashmediaplayer-poster]').value, uploads_path: document.getElementById('attachments[singleurl][kgflashmediaplayer-upload_path]').value }, function(data) {
93
+ jQuery('attachments_singleurl_thumbnailplaceholder').empty();
94
+ }, "json" );
95
+
96
+ var shortcode = "";
97
+ if (document.getElementById('videotitle').value != "") { shortcode += '<strong>' + document.getElementById('videotitle').value + '</strong><br />'; }
98
+ if (document.getElementById('attachments[singleurl][kgflashmediaplayer-url]').value !="") {
99
+ shortcode += ' [FMP';
100
+ if (document.getElementById('attachments[singleurl][kgflashmediaplayer-poster]').value !="") { shortcode += ' poster="' + document.getElementById("attachments[singleurl][kgflashmediaplayer-poster]").value + '"'; }
101
+ if (document.getElementById('attachments_singleurl_kgflashmediaplayer-width').value !="") { shortcode += ' width="' + document.getElementById("attachments_singleurl_kgflashmediaplayer-width").value + '"'; }
102
+ if (document.getElementById('attachments_singleurl_kgflashmediaplayer-height').value !="") { shortcode += ' height="' + document.getElementById("attachments_singleurl_kgflashmediaplayer-height").value + '"'; }
103
+ shortcode += ']' + document.getElementById('attachments[singleurl][kgflashmediaplayer-url]').value + '[/FMP] '; }
104
+ if (document.getElementById('downloadlink').checked) { shortcode += '<br /><a href="' + document.getElementById("attachments[singleurl][kgflashmediaplayer-url]").value + '">Right-click or ctrl-click this link to download</a>'; }
105
+
106
+ parent.tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
107
+ //Close window
108
+ parent.jQuery("#TB_closeWindowButton").click();
109
+ }
mdetect.php ADDED
@@ -0,0 +1,991 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* *******************************************
4
+ // Copyright 2010-2011, Anthony Hand
5
+ //
6
+ // File version date: August 22, 2011
7
+ // Update:
8
+ // - Updated DetectAndroidTablet() to fix a bug introduced in the last fix! The true/false returns were mixed up.
9
+ //
10
+ // File version date: August 16, 2011
11
+ // Update:
12
+ // - Updated DetectAndroidTablet() to exclude Opera Mini, which was falsely reporting as running on a tablet device when on a phone.
13
+ //
14
+ // File version date: August 7, 2011
15
+ // Update:
16
+ // - The Opera for Android browser doesn't follow Google's recommended useragent string guidelines, so some fixes were needed.
17
+ // - Updated DetectAndroidPhone() and DetectAndroidTablet() to properly detect devices running Opera Mobile.
18
+ // - Created 2 new methods: DetectOperaAndroidPhone() and DetectOperaAndroidTablet().
19
+ // - Updated DetectTierIphone(). Removed the call to DetectMaemoTablet(), an obsolete mobile OS.
20
+ //
21
+ // File version date: July 15, 2011
22
+ // Update:
23
+ // - Refactored the variable called maemoTablet. Its new name is the more generic deviceTablet.
24
+ // - Created the variable deviceWebOShp for HP's line of WebOS devices starting with the TouchPad tablet.
25
+ // - Created the DetectWebOSTablet() method for HP's line of WebOS tablets starting with the TouchPad tablet.
26
+ // - Updated the DetectTierTablet() method to also search for WebOS tablets.
27
+ // - Updated the DetectMaemoTablet() method to disambiguate against WebOS tablets which share some signature traits.
28
+ //
29
+ //
30
+ // LICENSE INFORMATION
31
+ // Licensed under the Apache License, Version 2.0 (the "License");
32
+ // you may not use this file except in compliance with the License.
33
+ // You may obtain a copy of the License at
34
+ // http://www.apache.org/licenses/LICENSE-2.0
35
+ // Unless required by applicable law or agreed to in writing,
36
+ // software distributed under the License is distributed on an
37
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
38
+ // either express or implied. See the License for the specific
39
+ // language governing permissions and limitations under the License.
40
+ //
41
+ //
42
+ // ABOUT THIS PROJECT
43
+ // Project Owner: Anthony Hand
44
+ // Email: anthony.hand@gmail.com
45
+ // Web Site: http://www.mobileesp.com
46
+ // Source Files: http://code.google.com/p/mobileesp/
47
+ //
48
+ // Versions of this code are available for:
49
+ // PHP, JavaScript, Java, ASP.NET (C#), and Ruby
50
+ //
51
+ // *******************************************
52
+ */
53
+
54
+
55
+
56
+ //**************************
57
+ // The uagent_info class encapsulates information about
58
+ // a browser's connection to your web site.
59
+ // You can use it to find out whether the browser asking for
60
+ // your site's content is probably running on a mobile device.
61
+ // The methods were written so you can be as granular as you want.
62
+ // For example, enquiring whether it's as specific as an iPod Touch or
63
+ // as general as a smartphone class device.
64
+ // The object's methods return 1 for true, or 0 for false.
65
+ class uagent_info
66
+ {
67
+ var $useragent = "";
68
+ var $httpaccept = "";
69
+
70
+ //standardized values for true and false.
71
+ var $true = 1;
72
+ var $false = 0;
73
+
74
+ //Let's store values for quickly accessing the same info multiple times.
75
+ var $isIphone = 0; //Stores whether the device is an iPhone or iPod Touch.
76
+ var $isAndroidPhone = 0; //Stores whether the device is a (small-ish) Android phone or media player.
77
+ var $isTierTablet = 0; //Stores whether is the Tablet (HTML5-capable, larger screen) tier of devices.
78
+ var $isTierIphone = 0; //Stores whether is the iPhone tier of devices.
79
+ var $isTierRichCss = 0; //Stores whether the device can probably support Rich CSS, but JavaScript support is not assumed. (e.g., newer BlackBerry, Windows Mobile)
80
+ var $isTierGenericMobile = 0; //Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR)
81
+
82
+ //Initialize some initial smartphone string variables.
83
+ var $engineWebKit = 'webkit';
84
+ var $deviceIphone = 'iphone';
85
+ var $deviceIpod = 'ipod';
86
+ var $deviceIpad = 'ipad';
87
+ var $deviceMacPpc = 'macintosh'; //Used for disambiguation
88
+
89
+ var $deviceAndroid = 'android';
90
+ var $deviceGoogleTV = 'googletv';
91
+ var $deviceXoom = 'xoom'; //Motorola Xoom
92
+ var $deviceHtcFlyer = 'htc_flyer'; //HTC Flyer
93
+
94
+ var $deviceNuvifone = 'nuvifone'; //Garmin Nuvifone
95
+
96
+ var $deviceSymbian = 'symbian';
97
+ var $deviceS60 = 'series60';
98
+ var $deviceS70 = 'series70';
99
+ var $deviceS80 = 'series80';
100
+ var $deviceS90 = 'series90';
101
+
102
+ var $deviceWinPhone7 = 'windows phone os 7';
103
+ var $deviceWinMob = 'windows ce';
104
+ var $deviceWindows = 'windows';
105
+ var $deviceIeMob = 'iemobile';
106
+ var $devicePpc = 'ppc'; //Stands for PocketPC
107
+ var $enginePie = 'wm5 pie'; //An old Windows Mobile
108
+
109
+ var $deviceBB = 'blackberry';
110
+ var $vndRIM = 'vnd.rim'; //Detectable when BB devices emulate IE or Firefox
111
+ var $deviceBBStorm = 'blackberry95'; //Storm 1 and 2
112
+ var $deviceBBBold = 'blackberry97'; //Bold
113
+ var $deviceBBTour = 'blackberry96'; //Tour
114
+ var $deviceBBCurve = 'blackberry89'; //Curve2
115
+ var $deviceBBTorch = 'blackberry 98'; //Torch
116
+ var $deviceBBPlaybook = 'playbook'; //PlayBook tablet
117
+
118
+ var $devicePalm = 'palm';
119
+ var $deviceWebOS = 'webos'; //For Palm's line of WebOS devices
120
+ var $deviceWebOShp = 'hpwos'; //For HP's line of WebOS devices
121
+
122
+ var $engineBlazer = 'blazer'; //Old Palm browser
123
+ var $engineXiino = 'xiino'; //Another old Palm
124
+
125
+ var $deviceKindle = 'kindle'; //Amazon Kindle, eInk one.
126
+
127
+ //Initialize variables for mobile-specific content.
128
+ var $vndwap = 'vnd.wap';
129
+ var $wml = 'wml';
130
+
131
+ //Initialize variables for other random devices and mobile browsers.
132
+ var $deviceTablet = 'tablet'; //Generic term for slate and tablet devices
133
+ var $deviceBrew = 'brew';
134
+ var $deviceDanger = 'danger';
135
+ var $deviceHiptop = 'hiptop';
136
+ var $devicePlaystation = 'playstation';
137
+ var $deviceNintendoDs = 'nitro';
138
+ var $deviceNintendo = 'nintendo';
139
+ var $deviceWii = 'wii';
140
+ var $deviceXbox = 'xbox';
141
+ var $deviceArchos = 'archos';
142
+
143
+ var $engineOpera = 'opera'; //Popular browser
144
+ var $engineNetfront = 'netfront'; //Common embedded OS browser
145
+ var $engineUpBrowser = 'up.browser'; //common on some phones
146
+ var $engineOpenWeb = 'openweb'; //Transcoding by OpenWave server
147
+ var $deviceMidp = 'midp'; //a mobile Java technology
148
+ var $uplink = 'up.link';
149
+ var $engineTelecaQ = 'teleca q'; //a modern feature phone browser
150
+
151
+ var $devicePda = 'pda'; //some devices report themselves as PDAs
152
+ var $mini = 'mini'; //Some mobile browsers put 'mini' in their names.
153
+ var $mobile = 'mobile'; //Some mobile browsers put 'mobile' in their user agent strings.
154
+ var $mobi = 'mobi'; //Some mobile browsers put 'mobi' in their user agent strings.
155
+
156
+ //Use Maemo, Tablet, and Linux to test for Nokia's Internet Tablets.
157
+ var $maemo = 'maemo';
158
+ var $linux = 'linux';
159
+ var $qtembedded = 'qt embedded'; //for Sony Mylo and others
160
+ var $mylocom2 = 'com2'; //for Sony Mylo also
161
+
162
+ //In some UserAgents, the only clue is the manufacturer.
163
+ var $manuSonyEricsson = "sonyericsson";
164
+ var $manuericsson = "ericsson";
165
+ var $manuSamsung1 = "sec-sgh";
166
+ var $manuSony = "sony";
167
+ var $manuHtc = "htc"; //Popular Android and WinMo manufacturer
168
+
169
+ //In some UserAgents, the only clue is the operator.
170
+ var $svcDocomo = "docomo";
171
+ var $svcKddi = "kddi";
172
+ var $svcVodafone = "vodafone";
173
+
174
+ //Disambiguation strings.
175
+ var $disUpdate = "update"; //pda vs. update
176
+
177
+
178
+ //**************************
179
+ //The constructor. Initializes several default variables.
180
+ function uagent_info()
181
+ {
182
+ $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])?strtolower($_SERVER['HTTP_USER_AGENT']):'';
183
+ $this->httpaccept = isset($_SERVER['HTTP_ACCEPT'])?strtolower($_SERVER['HTTP_ACCEPT']):'';
184
+
185
+ //Let's initialize some values to save cycles later.
186
+ $this->InitDeviceScan();
187
+ }
188
+
189
+ //**************************
190
+ // Initialize Key Stored Values.
191
+ function InitDeviceScan()
192
+ {
193
+ global $isIphone, $isAndroidPhone, $isTierTablet, $isTierIphone;
194
+
195
+ //We'll use these 4 variables to speed other processing. They're super common.
196
+ $this->isIphone = $this->DetectIphoneOrIpod();
197
+ $this->isAndroidPhone = $this->DetectAndroidPhone();
198
+ $this->isTierIphone = $this->DetectTierIphone();
199
+ $this->isTierTablet = $this->DetectTierTablet();
200
+
201
+ //Optional: Comment these out if you don't need them.
202
+ global $isTierRichCss, $isTierGenericMobile;
203
+ $this->isTierRichCss = $this->DetectTierRichCss();
204
+ $this->isTierGenericMobile = $this->DetectTierOtherPhones();
205
+ }
206
+
207
+ //**************************
208
+ //Returns the contents of the User Agent value, in lower case.
209
+ function Get_Uagent()
210
+ {
211
+ return $this->useragent;
212
+ }
213
+
214
+ //**************************
215
+ //Returns the contents of the HTTP Accept value, in lower case.
216
+ function Get_HttpAccept()
217
+ {
218
+ return $this->httpaccept;
219
+ }
220
+
221
+
222
+ //**************************
223
+ // Detects if the current device is an iPhone.
224
+ function DetectIphone()
225
+ {
226
+ if (stripos($this->useragent, $this->deviceIphone) > -1)
227
+ {
228
+ //The iPad and iPod Touch say they're an iPhone. So let's disambiguate.
229
+ if ($this->DetectIpad() == $this->true ||
230
+ $this->DetectIpod() == $this->true)
231
+ return $this->false;
232
+ //Yay! It's an iPhone!
233
+ else
234
+ return $this->true;
235
+ }
236
+ else
237
+ return $this->false;
238
+ }
239
+
240
+ //**************************
241
+ // Detects if the current device is an iPod Touch.
242
+ function DetectIpod()
243
+ {
244
+ if (stripos($this->useragent, $this->deviceIpod) > -1)
245
+ return $this->true;
246
+ else
247
+ return $this->false;
248
+ }
249
+
250
+ //**************************
251
+ // Detects if the current device is an iPad tablet.
252
+ function DetectIpad()
253
+ {
254
+ if (stripos($this->useragent, $this->deviceIpad) > -1 &&
255
+ $this->DetectWebkit() == $this->true)
256
+ return $this->true;
257
+ else
258
+ return $this->false;
259
+ }
260
+
261
+ //**************************
262
+ // Detects if the current device is an iPhone or iPod Touch.
263
+ function DetectIphoneOrIpod()
264
+ {
265
+ //We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
266
+ if (stripos($this->useragent, $this->deviceIphone) > -1 ||
267
+ stripos($this->useragent, $this->deviceIpod) > -1)
268
+ return $this->true;
269
+ else
270
+ return $this->false;
271
+ }
272
+
273
+ //**************************
274
+ // Detects *any* iOS device: iPhone, iPod Touch, iPad.
275
+ function DetectIos()
276
+ {
277
+ if (($this->DetectIphoneOrIpod() == $this->true) ||
278
+ ($this->DetectIpad() == $this->true))
279
+ return $this->true;
280
+ else
281
+ return $this->false;
282
+ }
283
+
284
+
285
+ //**************************
286
+ // Detects *any* Android OS-based device: phone, tablet, and multi-media player.
287
+ // Also detects Google TV.
288
+ function DetectAndroid()
289
+ {
290
+ if ((stripos($this->useragent, $this->deviceAndroid) > -1) ||
291
+ ($this->DetectGoogleTV() == $this->true))
292
+ return $this->true;
293
+ //Special check for the HTC Flyer 7" tablet
294
+ if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
295
+ return $this->true;
296
+ else
297
+ return $this->false;
298
+ }
299
+
300
+ //**************************
301
+ // Detects if the current device is a (small-ish) Android OS-based device
302
+ // used for calling and/or multi-media (like a Samsung Galaxy Player).
303
+ // Google says these devices will have 'Android' AND 'mobile' in user agent.
304
+ // Ignores tablets (Honeycomb and later).
305
+ function DetectAndroidPhone()
306
+ {
307
+ if (($this->DetectAndroid() == $this->true) &&
308
+ (stripos($this->useragent, $this->mobile) > -1))
309
+ return $this->true;
310
+ //Special check for Android phones with Opera Mobile. They should report here.
311
+ if (($this->DetectOperaAndroidPhone() == $this->true))
312
+ return $this->true;
313
+ //Special check for the HTC Flyer 7" tablet. It should report here.
314
+ if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
315
+ return $this->true;
316
+ else
317
+ return $this->false;
318
+ }
319
+
320
+ //**************************
321
+ // Detects if the current device is a (self-reported) Android tablet.
322
+ // Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
323
+ function DetectAndroidTablet()
324
+ {
325
+ //First, let's make sure we're on an Android device.
326
+ if ($this->DetectAndroid() == $this->false)
327
+ return $this->false;
328
+
329
+ //Special check for Opera Android Phones. They should NOT report here.
330
+ if ($this->DetectOperaMobile() == $this->true)
331
+ return $this->false;
332
+ //Special check for the HTC Flyer 7" tablet. It should NOT report here.
333
+ if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
334
+ return $this->false;
335
+
336
+ //Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
337
+ if (stripos($this->useragent, $this->mobile) > -1)
338
+ return $this->false;
339
+ else
340
+ return $this->true;
341
+ }
342
+
343
+ //**************************
344
+ // Detects if the current device is an Android OS-based device and
345
+ // the browser is based on WebKit.
346
+ function DetectAndroidWebKit()
347
+ {
348
+ if (($this->DetectAndroid() == $this->true) &&
349
+ ($this->DetectWebkit() == $this->true))
350
+ return $this->true;
351
+ else
352
+ return $this->false;
353
+ }
354
+
355
+ //**************************
356
+ // Detects if the current device is a GoogleTV.
357
+ function DetectGoogleTV()
358
+ {
359
+ if (stripos($this->useragent, $this->deviceGoogleTV) > -1)
360
+ return $this->true;
361
+ else
362
+ return $this->false;
363
+ }
364
+
365
+ //**************************
366
+ // Detects if the current browser is based on WebKit.
367
+ function DetectWebkit()
368
+ {
369
+ if (stripos($this->useragent, $this->engineWebKit) > -1)
370
+ return $this->true;
371
+ else
372
+ return $this->false;
373
+ }
374
+
375
+
376
+ //**************************
377
+ // Detects if the current browser is the Nokia S60 Open Source Browser.
378
+ function DetectS60OssBrowser()
379
+ {
380
+ //First, test for WebKit, then make sure it's either Symbian or S60.
381
+ if ($this->DetectWebkit() == $this->true)
382
+ {
383
+ if (stripos($this->useragent, $this->deviceSymbian) > -1 ||
384
+ stripos($this->useragent, $this->deviceS60) > -1)
385
+ {
386
+ return $this->true;
387
+ }
388
+ else
389
+ return $this->false;
390
+ }
391
+ else
392
+ return $this->false;
393
+ }
394
+
395
+ //**************************
396
+ // Detects if the current device is any Symbian OS-based device,
397
+ // including older S60, Series 70, Series 80, Series 90, and UIQ,
398
+ // or other browsers running on these devices.
399
+ function DetectSymbianOS()
400
+ {
401
+ if (stripos($this->useragent, $this->deviceSymbian) > -1 ||
402
+ stripos($this->useragent, $this->deviceS60) > -1 ||
403
+ stripos($this->useragent, $this->deviceS70) > -1 ||
404
+ stripos($this->useragent, $this->deviceS80) > -1 ||
405
+ stripos($this->useragent, $this->deviceS90) > -1)
406
+ return $this->true;
407
+ else
408
+ return $this->false;
409
+ }
410
+
411
+ //**************************
412
+ // Detects if the current browser is a
413
+ // Windows Phone 7 device.
414
+ function DetectWindowsPhone7()
415
+ {
416
+ if (stripos($this->useragent, $this->deviceWinPhone7) > -1)
417
+ return $this->true;
418
+ else
419
+ return $this->false;
420
+ }
421
+
422
+ //**************************
423
+ // Detects if the current browser is a Windows Mobile device.
424
+ // Excludes Windows Phone 7 devices.
425
+ // Focuses on Windows Mobile 6.xx and earlier.
426
+ function DetectWindowsMobile()
427
+ {
428
+ if ($this->DetectWindowsPhone7() == $this->true)
429
+ return $this->false;
430
+ //Most devices use 'Windows CE', but some report 'iemobile'
431
+ // and some older ones report as 'PIE' for Pocket IE.
432
+ if (stripos($this->useragent, $this->deviceWinMob) > -1 ||
433
+ stripos($this->useragent, $this->deviceIeMob) > -1 ||
434
+ stripos($this->useragent, $this->enginePie) > -1)
435
+ return $this->true;
436
+ //Test for Windows Mobile PPC but not old Macintosh PowerPC.
437
+ if (stripos($this->useragent, $this->devicePpc) > -1
438
+ && !(stripos($this->useragent, $this->deviceMacPpc) > 1))
439
+ return $this->true;
440
+ //Test for certain Windwos Mobile-based HTC devices.
441
+ if (stripos($this->useragent, $this->manuHtc) > -1 &&
442
+ stripos($this->useragent, $this->deviceWindows) > -1)
443
+ return $this->true;
444
+ if ($this->DetectWapWml() == $this->true &&
445
+ stripos($this->useragent, $this->deviceWindows) > -1)
446
+ return $this->true;
447
+ else
448
+ return $this->false;
449
+ }
450
+
451
+ //**************************
452
+ // Detects if the current browser is any BlackBerry device.
453
+ // Includes the PlayBook.
454
+ function DetectBlackBerry()
455
+ {
456
+ if ((stripos($this->useragent, $this->deviceBB) > -1) ||
457
+ (stripos($this->httpaccept, $this->vndRIM) > -1))
458
+ return $this->true;
459
+ else
460
+ return $this->false;
461
+ }
462
+
463
+ //**************************
464
+ // Detects if the current browser is on a BlackBerry tablet device.
465
+ // Examples: PlayBook
466
+ function DetectBlackBerryTablet()
467
+ {
468
+ if ((stripos($this->useragent, $this->deviceBBPlaybook) > -1))
469
+ return $this->true;
470
+ else
471
+ return $this->false;
472
+ }
473
+
474
+ //**************************
475
+ // Detects if the current browser is a BlackBerry phone device AND uses a
476
+ // WebKit-based browser. These are signatures for the new BlackBerry OS 6.
477
+ // Examples: Torch. Includes the Playbook.
478
+ function DetectBlackBerryWebKit()
479
+ {
480
+ if (($this->DetectBlackBerry() == $this->true) &&
481
+ ($this->DetectWebkit() == $this->true))
482
+ return $this->true;
483
+ else
484
+ return $this->false;
485
+ }
486
+
487
+ //**************************
488
+ // Detects if the current browser is a BlackBerry Touch phone
489
+ // device, such as the Storm or Torch. Excludes the Playbook.
490
+ function DetectBlackBerryTouch()
491
+ {
492
+ if ((stripos($this->useragent, $this->deviceBBStorm) > -1) ||
493
+ (stripos($this->useragent, $this->deviceBBTorch) > -1))
494
+ return $this->true;
495
+ else
496
+ return $this->false;
497
+ }
498
+
499
+ //**************************
500
+ // Detects if the current browser is a BlackBerry OS 5 device AND
501
+ // has a more capable recent browser. Excludes the Playbook.
502
+ // Examples, Storm, Bold, Tour, Curve2
503
+ // Excludes the new BlackBerry OS 6 browser!!
504
+ function DetectBlackBerryHigh()
505
+ {
506
+ //Disambiguate for BlackBerry OS 6 (WebKit) browser
507
+ if ($this->DetectBlackBerryWebKit() == $this->true)
508
+ return $this->false;
509
+ if ($this->DetectBlackBerry() == $this->true)
510
+ {
511
+ if (($this->DetectBlackBerryTouch() == $this->true) ||
512
+ stripos($this->useragent, $this->deviceBBBold) > -1 ||
513
+ stripos($this->useragent, $this->deviceBBTour) > -1 ||
514
+ stripos($this->useragent, $this->deviceBBCurve) > -1)
515
+ {
516
+ return $this->true;
517
+ }
518
+ else
519
+ return $this->false;
520
+ }
521
+ else
522
+ return $this->false;
523
+ }
524
+
525
+ //**************************
526
+ // Detects if the current browser is a BlackBerry device AND
527
+ // has an older, less capable browser.
528
+ // Examples: Pearl, 8800, Curve1.
529
+ function DetectBlackBerryLow()
530
+ {
531
+ if ($this->DetectBlackBerry() == $this->true)
532
+ {
533
+ //Assume that if it's not in the High tier, then it's Low.
534
+ if (($this->DetectBlackBerryHigh() == $this->true) ||
535
+ ($this->DetectBlackBerryWebKit() == $this->true))
536
+ return $this->false;
537
+ else
538
+ return $this->true;
539
+ }
540
+ else
541
+ return $this->false;
542
+ }
543
+
544
+ //**************************
545
+ // Detects if the current browser is on a PalmOS device.
546
+ function DetectPalmOS()
547
+ {
548
+ //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
549
+ if (stripos($this->useragent, $this->devicePalm) > -1 ||
550
+ stripos($this->useragent, $this->engineBlazer) > -1 ||
551
+ stripos($this->useragent, $this->engineXiino) > -1)
552
+ {
553
+ //Make sure it's not WebOS first
554
+ if ($this->DetectPalmWebOS() == $this->true)
555
+ return $this->false;
556
+ else
557
+ return $this->true;
558
+ }
559
+ else
560
+ return $this->false;
561
+ }
562
+
563
+
564
+ //**************************
565
+ // Detects if the current browser is on a Palm device
566
+ // running the new WebOS.
567
+ function DetectPalmWebOS()
568
+ {
569
+ if (stripos($this->useragent, $this->deviceWebOS) > -1)
570
+ return $this->true;
571
+ else
572
+ return $this->false;
573
+ }
574
+
575
+ //**************************
576
+ // Detects if the current browser is on an HP tablet running WebOS.
577
+ function DetectWebOSTablet()
578
+ {
579
+ if ((stripos($this->useragent, $this->deviceWebOShp) > -1)
580
+ && (stripos($this->useragent, $this->deviceTablet) > -1))
581
+ return $this->true;
582
+ else
583
+ return $this->false;
584
+ }
585
+
586
+ //**************************
587
+ // Detects if the current browser is a
588
+ // Garmin Nuvifone.
589
+ function DetectGarminNuvifone()
590
+ {
591
+ if (stripos($this->useragent, $this->deviceNuvifone) > -1)
592
+ return $this->true;
593
+ else
594
+ return $this->false;
595
+ }
596
+
597
+
598
+ //**************************
599
+ // Check to see whether the device is any device
600
+ // in the 'smartphone' category.
601
+ function DetectSmartphone()
602
+ {
603
+ global $isIphone, $isAndroidPhone, $isTierIphone;
604
+
605
+ if (($this->isIphone == $this->true)
606
+ || ($this->isAndroidPhone == $this->true)
607
+ || ($this->isTierIphone == $this->true)
608
+ || ($this->DetectS60OssBrowser() == $this->true)
609
+ || ($this->DetectSymbianOS() == $this->true)
610
+ || ($this->DetectWindowsMobile() == $this->true)
611
+ || ($this->DetectWindowsPhone7() == $this->true)
612
+ || ($this->DetectBlackBerry() == $this->true)
613
+ || ($this->DetectPalmWebOS() == $this->true)
614
+ || ($this->DetectPalmOS() == $this->true)
615
+ || ($this->DetectGarminNuvifone() == $this->true))
616
+ return $this->true;
617
+ else
618
+ return $this->false;
619
+ }
620
+
621
+
622
+ //**************************
623
+ // Detects whether the device is a Brew-powered device.
624
+ function DetectBrewDevice()
625
+ {
626
+ if (stripos($this->useragent, $this->deviceBrew) > -1)
627
+ return $this->true;
628
+ else
629
+ return $this->false;
630
+ }
631
+
632
+ //**************************
633
+ // Detects the Danger Hiptop device.
634
+ function DetectDangerHiptop()
635
+ {
636
+ if (stripos($this->useragent, $this->deviceDanger) > -1 ||
637
+ stripos($this->useragent, $this->deviceHiptop) > -1)
638
+ return $this->true;
639
+ else
640
+ return $this->false;
641
+ }
642
+
643
+ //**************************
644
+ // Detects if the current browser is Opera Mobile or Mini.
645
+ function DetectOperaMobile()
646
+ {
647
+ if (stripos($this->useragent, $this->engineOpera) > -1)
648
+ {
649
+ if ((stripos($this->useragent, $this->mini) > -1) ||
650
+ (stripos($this->useragent, $this->mobi) > -1))
651
+ return $this->true;
652
+ else
653
+ return $this->false;
654
+ }
655
+ else
656
+ return $this->false;
657
+ }
658
+
659
+ //**************************
660
+ // Detects if the current browser is Opera Mobile
661
+ // running on an Android phone.
662
+ function DetectOperaAndroidPhone()
663
+ {
664
+ if ((stripos($this->useragent, $this->engineOpera) > -1) &&
665
+ (stripos($this->useragent, $this->deviceAndroid) > -1) &&
666
+ (stripos($this->useragent, $this->mobi) > -1))
667
+ return $this->true;
668
+ else
669
+ return $this->false;
670
+ }
671
+
672
+ //**************************
673
+ // Detects if the current browser is Opera Mobile
674
+ // running on an Android tablet.
675
+ function DetectOperaAndroidTablet()
676
+ {
677
+ if ((stripos($this->useragent, $this->engineOpera) > -1) &&
678
+ (stripos($this->useragent, $this->deviceAndroid) > -1) &&
679
+ (stripos($this->useragent, $this->deviceTablet) > -1))
680
+ return $this->true;
681
+ else
682
+ return $this->false;
683
+ }
684
+
685
+ //**************************
686
+ // Detects whether the device supports WAP or WML.
687
+ function DetectWapWml()
688
+ {
689
+ if (stripos($this->httpaccept, $this->vndwap) > -1 ||
690
+ stripos($this->httpaccept, $this->wml) > -1)
691
+ return $this->true;
692
+ else
693
+ return $this->false;
694
+ }
695
+
696
+ //**************************
697
+ // Detects if the current device is an Amazon Kindle.
698
+ function DetectKindle()
699
+ {
700
+ if (stripos($this->useragent, $this->deviceKindle) > -1)
701
+ return $this->true;
702
+ else
703
+ return $this->false;
704
+ }
705
+
706
+
707
+ //**************************
708
+ // The quick way to detect for a mobile device.
709
+ // Will probably detect most recent/current mid-tier Feature Phones
710
+ // as well as smartphone-class devices. Excludes Apple iPads and other modern tablets.
711
+ function DetectMobileQuick()
712
+ {
713
+ //Let's exclude tablets
714
+ if ($this->isTierTablet == $this->true)
715
+ return $this->false;
716
+
717
+ //Most mobile browsing is done on smartphones
718
+ if ($this->DetectSmartphone() == $this->true)
719
+ return $this->true;
720
+
721
+ if (($this->DetectWapWml() == $this->true)
722
+ || ($this->DetectBrewDevice() == $this->true)
723
+ || ($this->DetectOperaMobile() == $this->true))
724
+ return $this->true;
725
+
726
+ if ((stripos($this->useragent, $this->engineNetfront) > -1)
727
+ || (stripos($this->useragent, $this->engineUpBrowser) > -1)
728
+ || (stripos($this->useragent, $this->engineOpenWeb) > -1))
729
+ return $this->true;
730
+
731
+ if (($this->DetectDangerHiptop() == $this->true)
732
+ || ($this->DetectMidpCapable() == $this->true)
733
+ || ($this->DetectMaemoTablet() == $this->true)
734
+ || ($this->DetectArchos() == $this->true))
735
+ return $this->true;
736
+
737
+ if ((stripos($this->useragent, $this->devicePda) > -1) &&
738
+ !(stripos($this->useragent, $this->disUpdate) > -1))
739
+ return $this->true;
740
+ if (stripos($this->useragent, $this->mobile) > -1)
741
+ return $this->true;
742
+
743
+ else
744
+ return $this->false;
745
+ }
746
+
747
+ //**************************
748
+ // Detects if the current device is a Sony Playstation.
749
+ function DetectSonyPlaystation()
750
+ {
751
+ if (stripos($this->useragent, $this->devicePlaystation) > -1)
752
+ return $this->true;
753
+ else
754
+ return $this->false;
755
+ }
756
+
757
+ //**************************
758
+ // Detects if the current device is a Nintendo game device.
759
+ function DetectNintendo()
760
+ {
761
+ if (stripos($this->useragent, $this->deviceNintendo) > -1 ||
762
+ stripos($this->useragent, $this->deviceWii) > -1 ||
763
+ stripos($this->useragent, $this->deviceNintendoDs) > -1)
764
+ return $this->true;
765
+ else
766
+ return $this->false;
767
+ }
768
+
769
+ //**************************
770
+ // Detects if the current device is a Microsoft Xbox.
771
+ function DetectXbox()
772
+ {
773
+ if (stripos($this->useragent, $this->deviceXbox) > -1)
774
+ return $this->true;
775
+ else
776
+ return $this->false;
777
+ }
778
+
779
+ //**************************
780
+ // Detects if the current device is an Internet-capable game console.
781
+ function DetectGameConsole()
782
+ {
783
+ if ($this->DetectSonyPlaystation() == $this->true)
784
+ return $this->true;
785
+ else if ($this->DetectNintendo() == $this->true)
786
+ return $this->true;
787
+ else if ($this->DetectXbox() == $this->true)
788
+ return $this->true;
789
+ else
790
+ return $this->false;
791
+ }
792
+
793
+ //**************************
794
+ // Detects if the current device supports MIDP, a mobile Java technology.
795
+ function DetectMidpCapable()
796
+ {
797
+ if (stripos($this->useragent, $this->deviceMidp) > -1 ||
798
+ stripos($this->httpaccept, $this->deviceMidp) > -1)
799
+ return $this->true;
800
+ else
801
+ return $this->false;
802
+ }
803
+
804
+ //**************************
805
+ // Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
806
+ function DetectMaemoTablet()
807
+ {
808
+ if (stripos($this->useragent, $this->maemo) > -1)
809
+ return $this->true;
810
+ //For Nokia N810, must be Linux + Tablet, or else it could be something else.
811
+ if ((stripos($this->useragent, $this->linux) > -1)
812
+ && (stripos($this->useragent, $this->deviceTablet) > -1)
813
+ && ($this->DetectWebOSTablet() == $this->false)
814
+ && ($this->DetectAndroid() == $this->false))
815
+ return $this->true;
816
+ else
817
+ return $this->false;
818
+ }
819
+
820
+ //**************************
821
+ // Detects if the current device is an Archos media player/Internet tablet.
822
+ function DetectArchos()
823
+ {
824
+ if (stripos($this->useragent, $this->deviceArchos) > -1)
825
+ return $this->true;
826
+ else
827
+ return $this->false;
828
+ }
829
+
830
+ //**************************
831
+ // Detects if the current browser is a Sony Mylo device.
832
+ function DetectSonyMylo()
833
+ {
834
+ if (stripos($this->useragent, $this->manuSony) > -1)
835
+ {
836
+ if ((stripos($this->useragent, $this->qtembedded) > -1) ||
837
+ (stripos($this->useragent, $this->mylocom2) > -1))
838
+ {
839
+ return $this->true;
840
+ }
841
+ else
842
+ return $this->false;
843
+ }
844
+ else
845
+ return $this->false;
846
+ }
847
+
848
+
849
+ //**************************
850
+ // The longer and more thorough way to detect for a mobile device.
851
+ // Will probably detect most feature phones,
852
+ // smartphone-class devices, Internet Tablets,
853
+ // Internet-enabled game consoles, etc.
854
+ // This ought to catch a lot of the more obscure and older devices, also --
855
+ // but no promises on thoroughness!
856
+ function DetectMobileLong()
857
+ {
858
+ if ($this->DetectMobileQuick() == $this->true)
859
+ return $this->true;
860
+ if ($this->DetectGameConsole() == $this->true)
861
+ return $this->true;
862
+ if ($this->DetectSonyMylo() == $this->true)
863
+ return $this->true;
864
+
865
+ //Detect older phones from certain manufacturers and operators.
866
+ if (stripos($this->useragent, $this->uplink) > -1)
867
+ return $this->true;
868
+ if (stripos($this->useragent, $this->manuSonyEricsson) > -1)
869
+ return $this->true;
870
+ if (stripos($this->useragent, $this->manuericsson) > -1)
871
+ return $this->true;
872
+
873
+ if (stripos($this->useragent, $this->manuSamsung1) > -1)
874
+ return $this->true;
875
+ if (stripos($this->useragent, $this->svcDocomo) > -1)
876
+ return $this->true;
877
+ if (stripos($this->useragent, $this->svcKddi) > -1)
878
+ return $this->true;
879
+ if (stripos($this->useragent, $this->svcVodafone) > -1)
880
+ return $this->true;
881
+
882
+ else
883
+ return $this->false;
884
+ }
885
+
886
+
887
+
888
+ //*****************************
889
+ // For Mobile Web Site Design
890
+ //*****************************
891
+
892
+ //**************************
893
+ // The quick way to detect for a tier of devices.
894
+ // This method detects for the new generation of
895
+ // HTML 5 capable, larger screen tablets.
896
+ // Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
897
+ function DetectTierTablet()
898
+ {
899
+ if (($this->DetectIpad() == $this->true)
900
+ || ($this->DetectAndroidTablet() == $this->true)
901
+ || ($this->DetectBlackBerryTablet() == $this->true)
902
+ || ($this->DetectWebOSTablet() == $this->true))
903
+ return $this->true;
904
+ else
905
+ return $this->false;
906
+ }
907
+
908
+
909
+ //**************************
910
+ // The quick way to detect for a tier of devices.
911
+ // This method detects for devices which can
912
+ // display iPhone-optimized web content.
913
+ // Includes iPhone, iPod Touch, Android, WebOS, etc.
914
+ function DetectTierIphone()
915
+ {
916
+ if (($this->isIphone == $this->true) ||
917
+ ($this->isAndroidPhone == $this->true))
918
+ return $this->true;
919
+
920
+ if (($this->DetectBlackBerryWebKit() == $this->true) &&
921
+ ($this->DetectBlackBerryTouch() == $this->true))
922
+ return $this->true;
923
+ if ($this->DetectPalmWebOS() == $this->true)
924
+ return $this->true;
925
+ if ($this->DetectGarminNuvifone() == $this->true)
926
+ return $this->true;
927
+ else
928
+ return $this->false;
929
+ }
930
+
931
+ //**************************
932
+ // The quick way to detect for a tier of devices.
933
+ // This method detects for devices which are likely to be capable
934
+ // of viewing CSS content optimized for the iPhone,
935
+ // but may not necessarily support JavaScript.
936
+ // Excludes all iPhone Tier devices.
937
+ function DetectTierRichCss()
938
+ {
939
+ if ($this->DetectMobileQuick() == $this->true)
940
+ {
941
+ if (($this->DetectTierIphone() == $this->true))
942
+ return $this->false;
943
+
944
+ //The following devices are explicitly ok.
945
+ if ($this->DetectWebkit() == $this->true) //Any WebKit
946
+ return $this->true;
947
+ if ($this->DetectS60OssBrowser() == $this->true)
948
+ return $this->true;
949
+
950
+ //Note: 'High' BlackBerry devices ONLY
951
+ if ($this->DetectBlackBerryHigh() == $this->true)
952
+ return $this->true;
953
+
954
+ //WP7's IE-7-based browser isn't good enough for iPhone Tier.
955
+ if ($this->DetectWindowsPhone7() == $this->true)
956
+ return $this->true;
957
+ if ($this->DetectWindowsMobile() == $this->true)
958
+ return $this->true;
959
+ if (stripos($this->useragent, $this->engineTelecaQ) > -1)
960
+ return $this->true;
961
+
962
+ //default
963
+ else
964
+ return $this->false;
965
+ }
966
+ else
967
+ return $this->false;
968
+ }
969
+
970
+ //**************************
971
+ // The quick way to detect for a tier of devices.
972
+ // This method detects for all other types of phones,
973
+ // but excludes the iPhone and RichCSS Tier devices.
974
+ function DetectTierOtherPhones()
975
+ {
976
+ //Exclude devices in the other 2 categories
977
+ if (($this->DetectMobileLong() == $this->true)
978
+ && ($this->DetectTierIphone() == $this->false)
979
+ && ($this->DetectTierRichCss() == $this->false))
980
+ return $this->true;
981
+ else
982
+ return $this->false;
983
+ }
984
+
985
+
986
+ }
987
+
988
+
989
+ //Was informed by a MobileESP user that it's a best practice
990
+ // to omit the closing ?&gt; marks here. They can sometimes
991
+ // cause errors with HTML headers.
readme.txt CHANGED
@@ -3,39 +3,48 @@ Contributors: kylegilman
3
  Tags: video, html5, shortcode, thumbnail, ffmpeg
4
  Requires at least: 3.0
5
  Tested up to: 3.2.1
6
- Stable tag: 0.2.1
7
 
8
  Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG for thumbnails and encodes.
9
 
10
  == Description ==
11
 
12
- A plugin for the WordPress visual editor to make embedding videos, generating thumbnails, and encoding HTML5-compliant files a little bit easier.
13
 
14
- The plugin adds a button to the visual editor in WordPress. The icon has a generic man & woman icon with a camera between them. Press the button to open the plugin's dialog box.
15
 
16
- For now you’ll have to upload the video separately, then enter the URL into the Video URL box. The embedded player will default to a Flash video player, so it should be a Flash Video compatible file. You should be able to use FLV, but I haven’t tested it, so I strongly recommend H.264 video and AAC audio in an MP4 container. If you’re using Apple’s Compressor, the “Streaming” setting should be “Fast Start” (NOT Fast Start – Compressed Header).
17
 
18
- The plugin uses FFMPEG to generate thumbnails and encode HTML5 videos. By default the plugin looks for FFMPEG in /usr/local/bin but if FFMPEG is installed in a different place on your server, you can point it to the correct place in the plugin settings.
19
 
20
- If FFMPEG is installed on your server, you can generate thumbnails using either the “Generate” or “Randomize” buttons. The “Generate” button will always generate thumbnails from the same frames of your video. If you don’t like them you can randomize the results with the “Randomize” button. You can generate as many or as few as you need. The unused thumbnails will be deleted once you close the window.
 
 
 
 
21
 
22
  In the plugin settings you can set the default maximum width based on the width of your particular template and those values will be filled in when you open the window. If you generate thumbnails, the video display dimensions will be automatically adjusted to match the size and aspect ratio of the video file. You can make further adjustments if you want.
23
 
24
- The “Generate HTML5 Videos” button is still a bit experimental. If you have FFMPEG on your server, clicking the button will start encoding an iPod/iPad/Android compliant H.264 video (which will also work in Safari and current versions of Chrome) and a Firefox-compatible OGV video. Anyone using a modern browser who doesn’t have a Flash plugin will see these files instead of the original. The files will encode in the background and will take several minutes to complete, depending on your server setup, and the length of your video. In this beta version if something goes wrong after the encode starts, the plugin will not tell you.
 
 
 
 
 
25
 
26
- The plugin is currently favoring Flash instead of HTML5 because Flash works better in my experience. It’s a better user experience in most cases. I’m particularly not a fan of some browsers’ tendencies to auto-download HTML5 video elements. I eventually plan to include the option to favor HTML5.
27
 
28
- Android viewers who don’t use Flash will see a play button superimposed on the thumbnail instead of the default still image.
29
 
30
- If you want to make it easier for people to save the video to their computers, you can choose to include a link to download by checking the “Include Download Link”
31
 
32
- Click Insert Flash Media Player and youll get a shortcode in the visual editor that looks like this:
33
 
34
- `[FMP poster="http://www.kylegilman.net/wp-content/uploads/2011/01/Reel_11-10-10-web1.jpg" width="720" height="404"]http://www.kylegilman.net/videos/Reel 11-10-10-web.mp4[/FMP]`
35
 
36
- Once you save the post, the thumbnail file will be registered in the WordPress media library and added to the posts attachments. Thumbnails and HTML5 videos are saved in the current uploads directory. HTML5 videos are not yet registered with the media library.
37
 
38
- Im not really a software developer. Im just a film editor with some time on his hands who wanted to post video for clients and wasnt happy with the current state of any available software. But I want to really make this thing work, so please help me out by posting your feedback. Im developing the plugin on a VPS and I havent tested it on any other FFMPEG-enabled servers yet, so Im sure there are all kinds of things that only work because of my particular server setup.
39
 
40
  == Installation ==
41
 
@@ -49,14 +58,20 @@ I’m not really a software developer. I’m just a film editor with some time o
49
 
50
  Some of it will work without FFMPEG. You can generate embed codes for your videos on any host because that part of the plugin is JavaScript running in your browser. Without FFMPEG you won't be able to generate thumbnails or generate HTML5 videos. There is no way around this. A program has to read the video files in order to generate the thumbnails, and FFMPEG is the best one I've found to do that.
51
 
 
 
 
 
52
  == Screenshots ==
53
 
54
- 1. The button added to the visual editor.
55
- 2. Pressing the button opens a dialog box.
56
- 3. An example of a fully-filled dialog box.
57
 
58
  == Changelog ==
59
 
 
 
60
  0.2.1 Check made to ensure iPhone/iPod/Android compatible encode video height is an even number when HTML5 video encodes are made.
61
 
62
  0.2 First Release
3
  Tags: video, html5, shortcode, thumbnail, ffmpeg
4
  Requires at least: 3.0
5
  Tested up to: 3.2.1
6
+ Stable tag: 1.0
7
 
8
  Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG for thumbnails and encodes.
9
 
10
  == Description ==
11
 
12
+ This is a big re-write. You no longer have to manually choose the video URL. The visual-editor plugin with my icon is gone. Just click "Insert Video" to get things started.
13
 
14
+ I would appreciate any feedback you have.
15
 
16
+ A plugin for the Wordpress visual editor to make embedding videos, generating thumbnails, and encoding HTML5-compliant files a little bit easier.
17
 
18
+ The plugin adds several fields to any video attachment in the Media Library:
19
 
20
+ The embedded player will default to a Flash video player if you're using a Flash-compatible file (flv, f4v, mp4, mov, or m4v). Otherwise it will use an HTML5 video element. I highly recommend H.264 video and AAC audio in an MP4 container. If you're encoding with Apple's Compressor, the "Streaming" setting should be "Fast Start" (NOT Fast Start - Compressed Header). I've written up my recommended video encode settings in another post.
21
+
22
+ The plugin uses FFMPEG to generate thumbnails and encode HTML5/mobile videos. By default the plugin looks for FFMPEG in /usr/local/bin but if FFMPEG is installed in a different place on your server, you can point it to the correct place in the plugin settings.
23
+
24
+ If FFMPEG is installed on your server, you can generate thumbnails using either the "Generate" or "Randomize" buttons. The "Generate" button will always generate thumbnails from the same frames of your video, evenly spaced. If you don't like them you can randomize the results with the "Randomize" button. If you want to see the first frame of the video, check the "Force 1st Frame Thumbnail" button. If you want really fine control you can enter timecode in the "Thumbnail Timecode" field. Use mm:ss format. If you want even more control you can use decimals to approximate frames. For example, 23.5 will generate a thumbnail halfway between the 23rd and 24th seconds in the video. 02:23.25 would be one quarter of the way between the 143rd and 144th seconds. You can generate as many or as few as you need. The unused thumbnails will be deleted once you click "Insert into Post" or "Save Changes."
25
 
26
  In the plugin settings you can set the default maximum width based on the width of your particular template and those values will be filled in when you open the window. If you generate thumbnails, the video display dimensions will be automatically adjusted to match the size and aspect ratio of the video file. You can make further adjustments if you want.
27
 
28
+ The "Encode" button is still a bit experimental. If you have FFMPEG on your server, clicking the button will start encoding an iPod/iPad/Android compliant H.264 video (which will also work in Safari and IE 9) and a Firefox/Chrome-compatible WEBM video in the same directory as your original file. You can choose to also encode OGV or turn off WEBM encoding in the Video Embed & Thumbnail Generator
29
+ plugin's settings page. Anyone using a modern browser who doesn't have a Flash plugin will see these files instead of the original. The files will encode in the background and will take several minutes to complete, depending on your server setup and the length and size of your video. Currently, if something goes wrong after the encode starts, the plugin will not tell you. It also won't tell you when the files are done. You just have to wait.
30
+
31
+ The plugin is currently favoring Flash instead of HTML5 because Flash is a better user experience in most cases. I'm particularly not a fan of some browsers' tendencies to auto-download HTML5 video elements. I may eventually include the option to favor HTML5.
32
+
33
+ Android viewers who don't use Flash will see a play button superimposed on the thumbnail instead of the default still image.
34
 
35
+ If you want to make it easier for people to save the video to their computers, you can choose to include a link by checking the "Generate Download Link Below Video" button.
36
 
37
+ Sometimes for various reasons you might need to embed video files that are not saved in the Wordpress Media Library. Maybe your file is too large to upload through the media upload form, or maybe it's hosted on another server. Either way, you can use the new tab "Embed from URL" which works much like the old version of the plugin.
38
 
39
+ Just enter the Video URL manually, and all other steps are the same as the Media Library options. If the video is in a directory that isn't writable, any encodes you make will go to an "html5encodes" subdirectory in the Wordpress uploads directory.
40
 
41
+ Once you've filled in all your options, click "Insert Flash Media Player" and you'll get a shortcode in the visual editor like this
42
 
43
+ `[FMP poster="http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web_thumb2.jpg" width="720" height="404"]http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web.mp4[/FMP]`
44
 
45
+ Once you save the post, the thumbnail file will be registered in the Wordpress Media Library and added to the post's attachments. Thumbnails are saved in the current Wordpress uploads directory. HTML5 videos are not yet registered with the media library.
46
 
47
+ I'm not really a software developer. I'm just a film editor with some time on his hands who wanted to post video for clients and wasn't happy with the current state of any available software. But I want to really make this thing work, so please help me out by posting your feedback in the comments. I'm developing the plugin on a VPS and I haven't tested it on any other FFMPEG-enabled servers yet, so I'm sure there are all kinds of things that only work because of my particular server setup.
48
 
49
  == Installation ==
50
 
58
 
59
  Some of it will work without FFMPEG. You can generate embed codes for your videos on any host because that part of the plugin is JavaScript running in your browser. Without FFMPEG you won't be able to generate thumbnails or generate HTML5 videos. There is no way around this. A program has to read the video files in order to generate the thumbnails, and FFMPEG is the best one I've found to do that.
60
 
61
+ = Why do I have to upload the video separately and then copy and paste the URL? =
62
+
63
+ Because I am not a great programmer, and this was too much for me to figure out. In the future I'm hoping to integrate the plugin with the upload dialog box to streamline the process.
64
+
65
  == Screenshots ==
66
 
67
+ 1. Thumbnail & Embed Options in the Media Library/Insert Video page.
68
+ 2. New "Embed by Url" tab.
69
+ 3. Shortcode inserted into the post content by the plugin.
70
 
71
  == Changelog ==
72
 
73
+ 1.0 Huge re-write. Integrated with Wordpress Media Library and added WEBM support. Increased control over thumbnail generation. Added tab to Insert Video dialog box for adding by URL (like the old version).
74
+
75
  0.2.1 Check made to ensure iPhone/iPod/Android compatible encode video height is an even number when HTML5 video encodes are made.
76
 
77
  0.2 First Release
screenshot-1.jpg CHANGED
Binary file
screenshot-2.jpg CHANGED
Binary file
screenshot-3.jpg CHANGED
Binary file
video-embed-thumbnail-generator.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Video Embed & Thumbnail Generator
4
  Plugin URI: http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/
5
  Description: Generate video thumbnails, HTML5-compliant videos, and video embed shortcodes. Some functions require FFMPEG.
6
- Version: 0.2.1
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
 
@@ -28,14 +28,29 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  Website: http://code.google.com/p/swfobject/
29
  License: http://www.opensource.org/licenses/mit-license.php
30
  3) Includes code adapted from Joshua Eldridge's Flash Media Player Plugin
31
- Website: http://www.mac-dev.net/
32
  4) Includes code adapted from Gary Cao's Make Shortcodes User-Friendly tutorial
33
  Website: http://www.wphardcore.com/2010/how-to-make-shortcodes-user-friendly/
 
 
 
 
 
34
  */
35
 
36
  if ( ! defined( 'ABSPATH' ) )
37
  die( "Can't load this file directly" );
38
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  function url_exists($url) {
41
  $hdrs = @get_headers($url);
@@ -43,141 +58,75 @@ function url_exists($url) {
43
  }
44
 
45
 
46
- class KGvideoplayer
47
- {
48
- function __construct() {
49
- add_action( 'admin_init', array( $this, 'kg_action_admin_init' ) );
50
- }
51
-
52
- function kg_action_admin_init() {
53
- // only hook up these filters if we're in the admin panel, and the current user has permission
54
- // to edit posts and pages
55
- if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
56
- add_filter( 'mce_buttons', array( $this, 'filter_mce_button' ) );
57
- add_filter( 'mce_external_plugins', array( $this, 'filter_mce_plugin' ) );
58
- }
59
- }
60
-
61
- function filter_mce_button( $buttons ) {
62
- // add a separation before our button, here our button's id is "kgvideoplayer_button"
63
- array_push( $buttons, '|', 'kgvideoplayer_button' );
64
- return $buttons;
65
- }
66
-
67
- function filter_mce_plugin( $plugins ) {
68
- // this plugin file will work the magic of our button
69
- $plugins['kgvideoplayer'] = plugin_dir_url( __FILE__ ) . 'kg_video_plugin.js';
70
- return $plugins;
71
- }
72
  }
73
 
74
- $kgvideoplayer = new KGvideoplayer();
75
-
76
 
77
- class uagent_info
78
- {
79
- //Stores some info about the browser and device.
80
- var $useragent = "";
81
 
82
- //Stores info about what content formats the browser can display.
83
- var $httpaccept = "";
84
-
85
- // Standardized (and configurable) values for true and false.
86
- var $true = 1;
87
- var $false = 0;
88
-
89
- // A long list of strings which provide clues
90
- // about devices and capabilities.
91
- var $deviceAndroid = 'android';
92
-
93
-
94
- //**************************
95
- //The constructor. Initializes several default variables.
96
- function uagent_info()
97
- {
98
- $this->useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
99
- $this->httpaccept = strtolower($_SERVER['HTTP_ACCEPT']);
100
- }
101
-
102
- //**************************
103
- //Returns the contents of the User Agent value, in lower case.
104
- function Get_Uagent()
105
- {
106
- return $this->useragent;
107
- }
108
-
109
- function DetectAndroid()
110
- {
111
- if (stripos($this->useragent, $this->deviceAndroid) > -1)
112
- return $this->true;
113
- else
114
- return $this->false;
115
- }
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  }
118
 
119
- define("wp_FMP_swfobject_default", "true", true);
120
- define("wp_FMP_flashplayer_default", "<strong>Please upgrade Flash Player</strong> This content is shown when the user does not have a correct Flash Player version installed.", true);
121
- define("wp_FMP_default_width", "480", true);
122
- define("wp_FMP_default_height", "360", true);
123
- define("wp_FMP_default_HTML5", "true", true);
124
- define("wp_FMP_default_controlbar_style", "docked", true);
125
- define("wp_FMP_default_poster", "", true);
126
- define("wp_FMP_default_autohide", "true", true);
127
- define("wp_FMP_default_autoplay", "false", true);
128
- define("wp_FMP_default_loop", "false", true);
129
- define("wp_FMP_default_playbutton", "true", true);
130
- define("wp_FMP_default_http_streaming", "false", true);
131
- define("wp_FMP_default_stream_type", "liveOrRecorded", true);
132
- define("wp_FMP_default_scale_mode", "letterbox", true);
133
- define("wp_FMP_default_bgcolor", "", true);
134
- define("wp_FMP_default_configuration", "", true);
135
- define("wp_FMP_default_skin", "", true);
136
- define("wp_FMP_default_ffmpeg", "/usr/local/bin", true);
137
-
138
- add_option(wp_FMP_swfobject, wp_FMP_swfobject_default, 'Embed SWFObject');
139
- add_option(wp_FMP_flashplayer, wp_FMP_flashplayer_default, 'Flash Player not installed message');
140
- add_option(wp_FMP_width, wp_FMP_default_width, 'Default video width');
141
- add_option(wp_FMP_height, wp_FMP_default_height, 'Default video height');
142
- add_option(wp_FMP_HTML5, wp_FMP_default_HTML5, 'HTML5 video fallback');
143
- add_option(wp_FMP_controlbar_style, wp_FMP_default_controlbar_style, 'Default controlbar style');
144
- add_option(wp_FMP_poster, wp_FMP_default_poster, 'Default poster image');
145
- add_option(wp_FMP_autohide, wp_FMP_default_autohide, 'Default autohide behavior');
146
- add_option(wp_FMP_autoplay, wp_FMP_default_autoplay, 'Default autoplay behavior');
147
- add_option(wp_FMP_loop, wp_FMP_default_loop, 'Default loop behavior');
148
- add_option(wp_FMP_playbutton, wp_FMP_default_playbutton, 'Default play button overlay behavior');
149
- add_option(wp_FMP_http_streaming, wp_FMP_default_http_streaming, 'Default HTTP streaming behavior');
150
- add_option(wp_FMP_stream_type, wp_FMP_default_stream_type, 'Default video type');
151
- add_option(wp_FMP_scale_mode, wp_FMP_default_scale_mode, 'Default video scale mode');
152
- add_option(wp_FMP_bgcolor, wp_FMP_default_bgcolor, 'Default video background color');
153
- add_option(wp_FMP_configuration, wp_FMP_default_configuration, 'Default video configuration file');
154
- add_option(wp_FMP_skin, wp_FMP_default_skin, 'Default video skin file');
155
- add_option(wp_FMP_ffmpeg, wp_FMP_default_ffmpeg, 'Path to FFMPEG');
156
-
157
- function addSWFObject() {
158
- if(get_option(wp_FMP_swfobject) == "true") {
159
- echo "\n<script src=\"http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" type=\"text/javascript\"></script>\n";
160
- }
161
- }
162
 
163
-
164
- if (is_admin()) {
165
- add_action('wp_print_scripts','KG_FMP_JS_VARS');
166
- function KG_FMP_JS_VARS() {
167
- ?>
168
- <script type="text/javascript">
169
- var kg_width_option= <?php echo json_encode(get_option('wp_FMP_width')); ?>;
170
- var kg_height_option= <?php echo json_encode(get_option('wp_FMP_height')); ?>;
171
- var kg_ffmpeg_path= <?php echo json_encode(get_option('wp_FMP_ffmpeg')); ?>;
172
- var kg_plugin_dir= <?php echo json_encode(plugins_url("", __FILE__)); ?>;
173
- var kg_upload_dir= <?php echo json_encode(wp_upload_dir()); ?>;
174
- </script>
175
- <?php
176
  }
177
  }
178
 
179
-
180
- function FMP_shortcode($atts, $content = ''){
181
 
182
  // workaround for relative video URL (contributed by Lee Fernandes)
183
  if(substr($content, 0, 1) == '/') $content = get_bloginfo('url').$content;
@@ -248,15 +197,45 @@ if (is_admin()) {
248
  $params = "{allowfullscreen:'true', allowscriptaccess:'always'}";
249
 
250
  if(get_option(wp_FMP_HTML5) == "true") {
 
251
  $uagent_obj = new uagent_info();
252
  $isAndroid = $uagent_obj->DetectAndroid(); //determine if we're running on an Android device
253
- $encodedpath = dirname($query_atts["poster"]);
254
  $moviefilebasename = pathinfo(trim($content), PATHINFO_FILENAME);
255
- $moviefilebasename = str_replace(" ", "_", $moviefilebasename);
256
- //$ipodurl = plugins_url('/encodes/'.$moviefilebasename.'-ipod.m4v', __FILE__);
257
- //$ogvurl = plugins_url('/encodes/'.$moviefilebasename.'.ogv', __FILE__);
258
- $ipodurl = $encodedpath."/".$moviefilebasename."-ipod.m4v";
259
- $ogvurl = $encodedpath."/".$moviefilebasename.".ogv";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  $code = "<div id=\"flashcontent".$div_suffix."\">";
261
  $code .= "<video ";
262
  if ($isAndroid) { $code .= "onclick='this.play();' "; }
@@ -269,25 +248,33 @@ if (is_admin()) {
269
  }
270
  $code .= " width='".$query_atts["width"]."' height='".$query_atts["height"]."'";
271
  $code .= ">\n";
272
- if (url_exists($ipodurl)) {
273
- $code .= "<source src='".$ipodurl."'";
274
- if (!$isAndroid) {
275
- $code.= " type='video/mp4'";
276
  }
 
 
277
  $code .=">\n";
278
  }
279
- else { $code .= "<source src='".$content."' type='video/mp4'>\n"; }
280
- if (url_exists($ogvurl)) { $code .= "<source src='".$ogvurl."' type='video/ogg'>\n"; }
 
 
 
 
 
281
  $code .= "</video>\n";
282
  $code .= "</div>\n\n";
283
  } else {
284
- $code = "<div id=\"flashcontent".$div_suffix."\">".get_option(wp_FMP_flashplayer)."</div>\n\n";
285
  }
286
 
287
- $code .= "<script type=\"text/javascript\">\n\t";
288
- $code .= "swfobject.embedSWF('".$video_swf."', 'flashcontent".$div_suffix."', '".trim($query_atts['width'])."', '".trim($query_atts['height'])."', '".$minimum_flash."', '".plugins_url("", __FILE__)."/expressinstall.swf', $flashvars, $params)\n";
289
-
290
- $code .= "</script>\n";
 
291
 
292
  return $code;
293
  }
@@ -317,7 +304,8 @@ if (is_admin()) {
317
  update_option(wp_FMP_bgcolor, wp_FMP_default_bgcolor);
318
  update_option(wp_FMP_configuration, wp_FMP_default_configuration);
319
  update_option(wp_FMP_skin, wp_FMP_default_skin);
320
- update_option(wp_FMP_ffmpeg, wp_FMP_default_ffmpeg);
 
321
 
322
  echo "<div class='updated'><p><strong>Flash Media Playback plugin reset to default settings</strong></p></div>";
323
  }
@@ -331,6 +319,8 @@ if (is_admin()) {
331
  $use_loop = $_POST[wp_FMP_loop];
332
  $use_playbutton = $_POST[wp_FMP_playbutton];
333
  $use_http_streaming = $_POST[wp_FMP_http_streaming];
 
 
334
 
335
  if ($use_swfobject == 'use') {
336
  update_option(wp_FMP_swfobject, "true");
@@ -372,7 +362,19 @@ if (is_admin()) {
372
  update_option(wp_FMP_http_streaming, "true");
373
  } else {
374
  update_option(wp_FMP_http_streaming, "false");
375
- }
 
 
 
 
 
 
 
 
 
 
 
 
376
 
377
  update_option(wp_FMP_width, $_POST[wp_FMP_width]);
378
  update_option(wp_FMP_height, $_POST[wp_FMP_height]);
@@ -432,6 +434,39 @@ if (is_admin()) {
432
  Uncheck if you don't want HTML5 video fallback.
433
  </td>
434
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  <tr>
436
  <th scope="row" valign="top" align="left">
437
  <label>Enable HTTP Streaming or Flash Access 2.0:</label>
@@ -465,10 +500,6 @@ if (is_admin()) {
465
  <div style="align:left"><input name="wp_FMP_update" value="Save Changes" type="submit" />&nbsp;&nbsp;&nbsp;<input name="wp_FMP_reset" value="Reset defaults" type="submit" /></div>
466
  </td>
467
  </tr>
468
- <tr>
469
- <th colspan="2"><h3>Default argument values</h3></th><td>
470
- </td>
471
- </tr>
472
  <tr>
473
  <th scope="row" valign="top" align="left">
474
  <label>Path to FFMPEG:</label>
@@ -476,9 +507,13 @@ if (is_admin()) {
476
  <td width="10"></td>
477
  <td>
478
  <input name="wp_FMP_ffmpeg" id="wp_FMP_ffmpeg" type="text" value="<?php echo get_option(wp_FMP_ffmpeg) ?>" /><br />
479
- <em>Don't include trailing slash. Example: /usr/local/bin</em>
480
  </td>
481
  </tr>
 
 
 
 
482
  <tr>
483
  <th scope="row" valign="top" align="left">
484
  <label>Default max video width:</label>
@@ -490,7 +525,7 @@ if (is_admin()) {
490
  </tr>
491
  <tr>
492
  <th scope="row" valign="top" align="left">
493
- <label>Default video height:</label>
494
  </th>
495
  <td width="10"></td>
496
  <td>
@@ -751,9 +786,306 @@ function kg_addPostSave($post_id) {
751
  $flag = 1;
752
  }
753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
  add_action('wp_head', 'addSWFObject');
755
  add_action('admin_menu', 'addFMPOptionsPage');
756
  add_action('save_post', 'kg_addPostSave');
 
757
 
758
  add_shortcode('FMP', 'FMP_shortcode');
759
 
3
  Plugin Name: Video Embed & Thumbnail Generator
4
  Plugin URI: http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/
5
  Description: Generate video thumbnails, HTML5-compliant videos, and video embed shortcodes. Some functions require FFMPEG.
6
+ Version: 1.0
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
 
28
  Website: http://code.google.com/p/swfobject/
29
  License: http://www.opensource.org/licenses/mit-license.php
30
  3) Includes code adapted from Joshua Eldridge's Flash Media Player Plugin
31
+ Website: http://wordpress.org/extend/plugins/flash-video-player/
32
  4) Includes code adapted from Gary Cao's Make Shortcodes User-Friendly tutorial
33
  Website: http://www.wphardcore.com/2010/how-to-make-shortcodes-user-friendly/
34
+ 5) Includes code adapted from Justin Gable's "Modifying Wordpress' Default Method for Inserting Media"
35
+ Website: http://justingable.com/2008/10/03/modifying-wordpress-default-method-for-inserting-media/
36
+ 6) Includes MobileESP class, Apache License 2.0
37
+ Website: http://blog.mobileesp.com/
38
+
39
  */
40
 
41
  if ( ! defined( 'ABSPATH' ) )
42
  die( "Can't load this file directly" );
43
 
44
+ function kg_add_upload_mimes ( $existing_mimes=array() ) {
45
+
46
+ // allows uploading .webm videos
47
+ $existing_mimes['webm'] = 'video/webm';
48
+ return $existing_mimes;
49
+
50
+ }
51
+
52
+ add_filter('upload_mimes', 'kg_add_upload_mimes');
53
+
54
 
55
  function url_exists($url) {
56
  $hdrs = @get_headers($url);
58
  }
59
 
60
 
61
+ function rrmdir($dir) {
62
+ if (is_dir($dir)) {
63
+ $objects = scandir($dir);
64
+ foreach ($objects as $object) {
65
+ if ($object != "." && $object != "..") {
66
+ if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
67
+ }
68
+ }
69
+ reset($objects);
70
+ rmdir($dir);
71
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
 
 
74
 
75
+ function video_embed_thumbnail_generator_activate() {
 
 
 
76
 
77
+ define("wp_FMP_swfobject_default", "true", true);
78
+ define("wp_FMP_flashplayer_default", "<strong>Please upgrade Flash Player</strong> This content is shown when the user does not have a correct Flash Player version installed.", true);
79
+ define("wp_FMP_default_width", "480", true);
80
+ define("wp_FMP_default_height", "360", true);
81
+ define("wp_FMP_default_HTML5", "true", true);
82
+ define("wp_FMP_default_controlbar_style", "docked", true);
83
+ define("wp_FMP_default_poster", "", true);
84
+ define("wp_FMP_default_autohide", "true", true);
85
+ define("wp_FMP_default_autoplay", "false", true);
86
+ define("wp_FMP_default_loop", "false", true);
87
+ define("wp_FMP_default_playbutton", "true", true);
88
+ define("wp_FMP_default_http_streaming", "false", true);
89
+ define("wp_FMP_default_stream_type", "liveOrRecorded", true);
90
+ define("wp_FMP_default_scale_mode", "letterbox", true);
91
+ define("wp_FMP_default_bgcolor", "", true);
92
+ define("wp_FMP_default_configuration", "", true);
93
+ define("wp_FMP_default_skin", "", true);
94
+ define("wp_FMP_default_ffmpeg", "/usr/local/bin", true);
95
+ define("wp_FMP_default_encodeogg", "false", true);
96
+ define("wp_FMP_default_encodewebm", "true", true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
+ add_option('wp_FMP_swfobject', wp_FMP_swfobject_default);
99
+ add_option('wp_FMP_flashplayer', wp_FMP_flashplayer_default);
100
+ add_option('wp_FMP_width', wp_FMP_default_width);
101
+ add_option('wp_FMP_height', wp_FMP_default_height);
102
+ add_option('wp_FMP_HTML5', wp_FMP_default_HTML5);
103
+ add_option('wp_FMP_controlbar_style', wp_FMP_default_controlbar_style);
104
+ add_option('wp_FMP_poster', wp_FMP_default_poster);
105
+ add_option('wp_FMP_autohide', wp_FMP_default_autohide);
106
+ add_option('wp_FMP_autoplay', wp_FMP_default_autoplay);
107
+ add_option('wp_FMP_loop', wp_FMP_default_loop);
108
+ add_option('wp_FMP_playbutton', wp_FMP_default_playbutton);
109
+ add_option('wp_FMP_http_streaming', wp_FMP_default_http_streaming);
110
+ add_option('wp_FMP_stream_type', wp_FMP_default_stream_type);
111
+ add_option('wp_FMP_scale_mode', wp_FMP_default_scale_mode);
112
+ add_option('wp_FMP_bgcolor', wp_FMP_default_bgcolor);
113
+ add_option('wp_FMP_configuration', wp_FMP_default_configuration);
114
+ add_option('wp_FMP_skin', wp_FMP_default_skin);
115
+ add_option('wp_FMP_ffmpeg', wp_FMP_default_ffmpeg);
116
+ add_option('wp_FMP_encodeogg', wp_FMP_default_encodeogg);
117
+ add_option('wp_FMP_encodewebm', wp_FMP_default_encodewebm);
118
  }
119
 
120
+ register_activation_hook( __FILE__, 'video_embed_thumbnail_generator_activate' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
+ function addSWFObject() {
123
+ if(get_option(wp_FMP_swfobject) == "true") {
124
+ echo "\n<script src=\"http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" type=\"text/javascript\"></script>\n";
 
 
 
 
 
 
 
 
 
 
125
  }
126
  }
127
 
128
+
129
+ function FMP_shortcode($atts, $content = ''){
130
 
131
  // workaround for relative video URL (contributed by Lee Fernandes)
132
  if(substr($content, 0, 1) == '/') $content = get_bloginfo('url').$content;
197
  $params = "{allowfullscreen:'true', allowscriptaccess:'always'}";
198
 
199
  if(get_option(wp_FMP_HTML5) == "true") {
200
+ include_once dirname( __FILE__ ) .'/mdetect.php';
201
  $uagent_obj = new uagent_info();
202
  $isAndroid = $uagent_obj->DetectAndroid(); //determine if we're running on an Android device
203
+ $isTierIphone = $uagent_obj->DetectTierIphone(); //determine if we're running on a mobile device that plays iPhone-optimized video
204
  $moviefilebasename = pathinfo(trim($content), PATHINFO_FILENAME);
205
+ //$moviefilebasename = str_replace(" ", "_", $moviefilebasename);
206
+ $moviefiletype = pathinfo(trim($content), PATHINFO_EXTENSION);
207
+ $flashcompatible = array("flv", "f4v", "mp4", "mov", "m4v");
208
+ $h264compatible = array("mp4", "mov", "m4v");
209
+
210
+ //look for encoded files in the same directory as the movie, or in the encodes folder
211
+ $originalurl = dirname(trim($content))."/".$moviefilebasename;
212
+ $uploads = wp_upload_dir();
213
+ $url_parts = parse_url($uploads['baseurl']);
214
+ $moviefiledirectory = dirname(parse_url(trim($content), PHP_URL_PATH));
215
+ $home_path = substr(strrev(strstr(strrev($uploads['basedir']), strrev("public_html"))), 0, -strlen("public_html"));
216
+ if ( strpos( dirname(trim($content)), $url_parts['host']) != "" ) { //if it's on the current server
217
+ $originalpath = $home_path."public_html".$moviefiledirectory."/".$moviefilebasename;
218
+ }
219
+ $encodeurl = $uploads['baseurl']."/html5encodes/".$moviefilebasename;
220
+ $encodepath = $uploads['basedir']."/html5encodes/".$moviefilebasename;
221
+
222
+ $html5type = array("-ipod.m4v", ".ogv", ".webm");
223
+
224
+ foreach ($html5type as $extension) {
225
+ $existing_url = "";
226
+ if ( ".".$moviefiletype == $extension ) { $existing_url = $content; }
227
+ if ($existing_url == "") { //search on the server for matching filename
228
+ if ( file_exists($originalpath.$extension) ) { $existing_url = $originalurl.$extension; }
229
+ }
230
+ if ($existing_url == "") { //search in the wp_upload html5encodes directory
231
+ if ( file_exists($encodepath.$extension) ) { $existing_url = $encodeurl.$extension; }
232
+ }
233
+ if ($existing_url == "" && $originalpath == "") { //if the file's not on the server, search wherever it is
234
+ if ( url_exists($originalurl.$extension) ) { $existing_url = $originalurl.$extension; }
235
+ }
236
+ $html5file[$extension] = $existing_url;
237
+ }
238
+
239
  $code = "<div id=\"flashcontent".$div_suffix."\">";
240
  $code .= "<video ";
241
  if ($isAndroid) { $code .= "onclick='this.play();' "; }
248
  }
249
  $code .= " width='".$query_atts["width"]."' height='".$query_atts["height"]."'";
250
  $code .= ">\n";
251
+
252
+ if ( in_array($moviefiletype, $h264compatible) ) {
253
+ if ( $html5file["-ipod.m4v"] !="" && $isTierIphone ) {
254
+ $code .= "<source src='".$html5file['-ipod.m4v']."'";
255
  }
256
+ else { $code .= "<source src='".$content."'"; }
257
+ if (!$isAndroid) { $code.= " type='video/mp4'"; }
258
  $code .=">\n";
259
  }
260
+ else { if ($html5file["-ipod.m4v"] != "") {
261
+ $code .= "<source src='".$html5file['-ipod.m4v']."'";
262
+ if (!$isAndroid) { $code.= " type='video/mp4'"; }
263
+ $code .=">\n";
264
+ } }
265
+ if ($html5file[".webm"] != "") { $code .= "<source src='".$html5file['.webm']."' type='video/webm'>\n"; }
266
+ if ($html5file[".ogv"] != "") { $code .= "<source src='".$html5file['.ogv']."' type='video/ogg'>\n"; }
267
  $code .= "</video>\n";
268
  $code .= "</div>\n\n";
269
  } else {
270
+ if ( in_array($moviefiletype, $flashcompatible) ) { $code = "<div id=\"flashcontent".$div_suffix."\">".get_option(wp_FMP_flashplayer)."</div>\n\n"; }
271
  }
272
 
273
+ if ( in_array($moviefiletype, $flashcompatible) ) {
274
+ $code .= "<script type=\"text/javascript\">\n\t";
275
+ $code .= "swfobject.embedSWF('".$video_swf."', 'flashcontent".$div_suffix."', '".trim($query_atts['width'])."', '".trim($query_atts['height'])."', '".$minimum_flash."', '".plugins_url("", __FILE__)."/expressinstall.swf', $flashvars, $params)\n";
276
+ $code .= "</script>\n";
277
+ }
278
 
279
  return $code;
280
  }
304
  update_option(wp_FMP_bgcolor, wp_FMP_default_bgcolor);
305
  update_option(wp_FMP_configuration, wp_FMP_default_configuration);
306
  update_option(wp_FMP_skin, wp_FMP_default_skin);
307
+ update_option(wp_FMP_ffmpeg, wp_FMP_default_ffmpeg);
308
+ update_option(wp_FMP_encodeogg, wp_FMP_default_encodeogg);
309
 
310
  echo "<div class='updated'><p><strong>Flash Media Playback plugin reset to default settings</strong></p></div>";
311
  }
319
  $use_loop = $_POST[wp_FMP_loop];
320
  $use_playbutton = $_POST[wp_FMP_playbutton];
321
  $use_http_streaming = $_POST[wp_FMP_http_streaming];
322
+ $use_encodeogg = $_POST[wp_FMP_encodeogg];
323
+ $use_encodewebm = $_POST[wp_FMP_encodewebm];
324
 
325
  if ($use_swfobject == 'use') {
326
  update_option(wp_FMP_swfobject, "true");
362
  update_option(wp_FMP_http_streaming, "true");
363
  } else {
364
  update_option(wp_FMP_http_streaming, "false");
365
+ }
366
+
367
+ if ($use_encodeogg == 'use') {
368
+ update_option(wp_FMP_encodeogg, "true");
369
+ } else {
370
+ update_option(wp_FMP_encodeogg, "false");
371
+ }
372
+
373
+ if ($use_encodewebm == 'use') {
374
+ update_option(wp_FMP_encodewebm, "true");
375
+ } else {
376
+ update_option(wp_FMP_encodewebm, "false");
377
+ }
378
 
379
  update_option(wp_FMP_width, $_POST[wp_FMP_width]);
380
  update_option(wp_FMP_height, $_POST[wp_FMP_height]);
434
  Uncheck if you don't want HTML5 video fallback.
435
  </td>
436
  </tr>
437
+ <tr>
438
+ <th scope="row" valign="top" align="left">
439
+ <label>Generate OGV:</label>
440
+ </th>
441
+ <td width="10"></td>
442
+ <td>
443
+ <?php
444
+ echo "<input type='checkbox' name='wp_FMP_encodeogg' id='wp_FMP_encodeogg' value='use' ";
445
+ if(get_option(wp_FMP_encodeogg) == "true") {
446
+ echo "checked";
447
+ }
448
+ echo " />\n";
449
+ ?>
450
+ Check to generate OGV files when encoding HTML5/Mobile videos.<br />
451
+ <small><em>Turned off by default because OGV is becoming obsolete.</em></small>
452
+ </td>
453
+ </tr>
454
+ <tr>
455
+ <th scope="row" valign="top" align="left">
456
+ <label>Generate WEBM:</label>
457
+ </th>
458
+ <td width="10"></td>
459
+ <td>
460
+ <?php
461
+ echo "<input type='checkbox' name='wp_FMP_encodewebm' id='wp_FMP_encodewebm' value='use' ";
462
+ if(get_option(wp_FMP_encodewebm) == "true") {
463
+ echo "checked";
464
+ }
465
+ echo " />\n";
466
+ ?>
467
+ Check to generate WEBM files when encoding HTML5/Mobile videos.<br />
468
+ </td>
469
+ </tr>
470
  <tr>
471
  <th scope="row" valign="top" align="left">
472
  <label>Enable HTTP Streaming or Flash Access 2.0:</label>
500
  <div style="align:left"><input name="wp_FMP_update" value="Save Changes" type="submit" />&nbsp;&nbsp;&nbsp;<input name="wp_FMP_reset" value="Reset defaults" type="submit" /></div>
501
  </td>
502
  </tr>
 
 
 
 
503
  <tr>
504
  <th scope="row" valign="top" align="left">
505
  <label>Path to FFMPEG:</label>
507
  <td width="10"></td>
508
  <td>
509
  <input name="wp_FMP_ffmpeg" id="wp_FMP_ffmpeg" type="text" value="<?php echo get_option(wp_FMP_ffmpeg) ?>" /><br />
510
+ <em><small>Don't include trailing slash. Example: /usr/local/bin</small></em>
511
  </td>
512
  </tr>
513
+ <tr>
514
+ <th colspan="2"><h3>Default argument values</h3></th><td>
515
+ </td>
516
+ </tr>
517
  <tr>
518
  <th scope="row" valign="top" align="left">
519
  <label>Default max video width:</label>
525
  </tr>
526
  <tr>
527
  <th scope="row" valign="top" align="left">
528
+ <label>Default max video height:</label>
529
  </th>
530
  <td width="10"></td>
531
  <td>
786
  $flag = 1;
787
  }
788
 
789
+
790
+
791
+ /**
792
+ * Adding our custom fields to the $form_fields array
793
+ *
794
+ * @param array $form_fields
795
+ * @param object $post
796
+ * @return array
797
+ */
798
+ function kg_image_attachment_fields_to_edit($form_fields, $post) {
799
+ if( substr($post->post_mime_type, 0, 5) == 'video' ){
800
+
801
+ $form_fields["kgflashmediaplayer-url"]["input"] = "hidden";
802
+ $form_fields["kgflashmediaplayer-url"]["value"] = wp_get_attachment_url($post->ID);
803
+
804
+ $form_fields["kgflashmediaplayer-ffmpeg_path"]["input"] = "hidden";
805
+ $form_fields["kgflashmediaplayer-ffmpeg_path"]["value"] = get_option('wp_FMP_ffmpeg');
806
+
807
+ $form_fields["kgflashmediaplayer-encodeogg"]["input"] = "hidden";
808
+ $form_fields["kgflashmediaplayer-encodeogg"]["value"] = get_option('wp_FMP_encodeogg');
809
+
810
+ $form_fields["kgflashmediaplayer-encodewebm"]["input"] = "hidden";
811
+ $form_fields["kgflashmediaplayer-encodewebm"]["value"] = get_option('wp_FMP_encodewebm');
812
+
813
+ $form_fields["kgflashmediaplayer-plugin_dir"]["input"] = "hidden";
814
+ $form_fields["kgflashmediaplayer-plugin_dir"]["value"] = plugins_url("", __FILE__);
815
+
816
+ $uploads = wp_upload_dir();
817
+ $form_fields["kgflashmediaplayer-upload_url"]["input"] = "hidden";
818
+ $form_fields["kgflashmediaplayer-upload_url"]["value"] = $uploads['url'];
819
+
820
+ $form_fields["kgflashmediaplayer-upload_path"]["input"] = "hidden";
821
+ $form_fields["kgflashmediaplayer-upload_path"]["value"] = $uploads['path'];
822
+
823
+ $form_fields["kgflashmediaplayer-upload_basedir"]["input"] = "hidden";
824
+ $form_fields["kgflashmediaplayer-upload_basedir"]["value"] = $uploads['basedir'];
825
+
826
+ $maxwidth = get_option('wp_FMP_width');
827
+ $widthset = get_post_meta($post->ID, "_kgflashmediaplayer-width", true);
828
+ if ($widthset == "") { $widthset = $maxwidth; }
829
+ $form_fields["kgflashmediaplayer-widthsave"]["input"] = "hidden";
830
+ $form_fields["kgflashmediaplayer-widthsave"]["value"] = $widthset;
831
+
832
+ $form_fields["kgflashmediaplayer-maxwidth"]["input"] = "hidden";
833
+ $form_fields["kgflashmediaplayer-maxwidth"]["value"] = $maxwidth;
834
+
835
+ $maxheight = get_option('wp_FMP_height');
836
+ $heightset = get_post_meta($post->ID, "_kgflashmediaplayer-height", true);
837
+ if ($heightset == "") { $heightset = $maxheight; }
838
+ $form_fields["kgflashmediaplayer-heightsave"]["input"] = "hidden";
839
+ $form_fields["kgflashmediaplayer-heightsave"]["value"] = $heightset;
840
+
841
+ $form_fields["kgflashmediaplayer-maxheight"]["input"] = "hidden";
842
+ $form_fields["kgflashmediaplayer-maxheight"]["value"] = $maxheight;
843
+
844
+ $form_fields["kgflashmediaplayer-aspect"]["input"] = "hidden";
845
+ $form_fields["kgflashmediaplayer-aspect"]["value"] = $heightset/$widthset;
846
+
847
+ $form_fields["kgflashmediaplayer-downloadsave"]["input"] = "hidden";
848
+ $form_fields["kgflashmediaplayer-downloadsave"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-download", true);
849
+
850
+ $form_fields["kgflashmediaplayer-showtitlesave"]["input"] = "hidden";
851
+ $form_fields["kgflashmediaplayer-showtitlesave"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-showtitle", true);
852
+
853
+ $embedset = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
854
+ if ($embedset == "") { $embedset = "checked"; }
855
+ $form_fields["kgflashmediaplayer-embedsave"]["input"] = "hidden";
856
+ $form_fields["kgflashmediaplayer-embedsave"]["value"] = $embedset;
857
+
858
+ $thumbnail_url = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
859
+
860
+ $url_parts = parse_url($uploads['baseurl']);
861
+ $moviefiledirectory = dirname(parse_url(trim($thumbnail_url), PHP_URL_PATH));
862
+ $moviefilebasename = pathinfo(trim($thumbnail_url), PATHINFO_BASENAME);
863
+ $home_path = substr(strrev(strstr(strrev($uploads['basedir']), strrev("public_html"))), 0, -strlen("public_html"));
864
+ if ( strpos( dirname(trim($thumbnail_url)), $url_parts['host']) != "" ) { //if it's on the current server
865
+ $originalpath = $home_path."public_html".$moviefiledirectory."/".$moviefilebasename;
866
+ if ( !file_exists($originalpath) ) { $thumbnail_url = ""; }
867
+ }
868
+ else { if ( !url_exists($thumbnail_url) ) { $thumbnail_url = ""; } }
869
+
870
+ if ($thumbnail_url != "" ) {
871
+ $thumbnail_html = '<div style="border-style:solid; border-color:#ccc; border-width:3px; width:200px; text-align:center; margin:10px;"><img width="200" src="'.$thumbnail_url.'"></div>';
872
+ }
873
+
874
+ $form_fields["generator"]["label"] = __("Thumbnails");
875
+ $form_fields["generator"]["input"] = "html";
876
+ $form_fields["generator"]["html"] = '<div id="attachments_'. $post->ID .'_thumbnailplaceholder">'. $thumbnail_html .'</div><input id="attachments_'. $post->ID .'_numberofthumbs" type="text" value="4" maxlength="2" size="4" style="width:25px;" title="Number of Thumbnails" onchange="document.getElementById(\'attachments['.$post->ID.'][thumbtime]\').value =\'\';"><input type="button" id="attachments['. $post->ID .'][thumbgenerate]" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kg_generate_thumb('. $post->ID .', \'generate\');"/><input type="button" id="thumbrandomize" class="button-secondary" value="Randomize" name="thumbrandomize" onclick="kg_generate_thumb('. $post->ID .', \'random\');" /><input type="button" id="attachments['. $post->ID .'][deletebutton]" class="button-secondary" value="Delete" name="deletebutton" onclick="kg_generate_thumb('. $post->ID .', \'delete\');"/> <input type="checkbox" id="attachments_'. $post->ID .'_firstframe"><label for="attachments_'. $post->ID .'_firstframe">Force 1st Frame Thumbnail</label>';
877
+
878
+ $form_fields["thumbtime"]["label"] = __("Thumbnail Timecode");
879
+ $form_fields["thumbtime"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-thumbtime", true);
880
+ $form_fields["thumbtime"]["helps"] = "<small>Optional: generates a single thumbnail at the specified time (hh:mm:ss, mm:ss, or s).</small>";
881
+
882
+ $form_fields["kgflashmediaplayer-poster"]["label"] = __("Thumbnail URL");
883
+ $form_fields["kgflashmediaplayer-poster"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
884
+ $form_fields["kgflashmediaplayer-poster"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator.php' target='_blank'>default thumbnail</a>.</small>";
885
+
886
+ $form_fields["kgflashmediaplayer-dimensions"]["label"] = __("Video Embed Dimensions");
887
+ $form_fields["kgflashmediaplayer-dimensions"]["input"] = "html";
888
+ $form_fields["kgflashmediaplayer-dimensions"]["html"] = 'Width: <input name="attachments_'. $post->ID .'_kgflashmediaplayer-width" type="text" value="'.$widthset.'" id="attachments_'. $post->ID .'_kgflashmediaplayer-width" type="text" style="width:50px;" onchange="kg_set_dimension('.$post->ID.', \'height\', this.value);" onkeyup="kg_set_dimension('.$post->ID.', \'height\', this.value);"> Height: <input id="attachments_'. $post->ID .'_kgflashmediaplayer-height" type="text" value="'.$heightset.'" style="width:50px;" onchange="kg_set_dimension('.$post->ID.', \'width\', this.value);" onkeyup="kg_set_dimension('.$post->ID.', \'width\', this.value);"> <input type="checkbox" id="attachments_'. $post->ID .'_kgflashmediaplayer-lockaspect" onclick="kg_set_aspect('.$post->ID.', this.checked);" checked> <label for="attachments_'. $post->ID .'_kgflashmediaplayer-lockaspect"><small>Lock to Aspect Ratio</small></label>';
889
+ $form_fields["kgflashmediaplayer-dimensions"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator.php' target='_blank'>default dimensions</a>.</small>";
890
+
891
+ $form_fields["kgflashmediaplayer-encode"]["label"] = __("HTML5 & Mobile");
892
+ $form_fields["kgflashmediaplayer-encode"]["input"] = "html";
893
+ $form_fields["kgflashmediaplayer-encode"]["html"] = '<input type="button" id="attachments['. $post->ID .'][kgflasmediaplayer-encode]" name="attachments['. $post->ID .'][kgflasmediaplayer-encode]" class="button-secondary" value="Encode" name="thumbgenerate" onclick="kg_generate_thumb('. $post->ID .', \'encode\');"/><div style="display:inline-block;" id="attachments_'. $post->ID .'_encodeplaceholder"></div>';
894
+ $form_fields["kgflashmediaplayer-encode"]["helps"] = "<small>(Experimental) Uses FFMPEG to enocde an H.264/M4V file compatible with most mobile browsers and either a WEBM or OGV depending on <a href='options-general.php?page=video-embed-thumbnail-generator.php' target='_blank'>settings</a>.</small>";
895
+
896
+ $showtitlechecked = get_post_meta($post->ID, "_kgflashmediaplayer-showtitle", true);
897
+ $downloadlinkchecked = get_post_meta($post->ID, "_kgflashmediaplayer-download", true);
898
+ $embedchecked = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
899
+ if ($embedchecked == "unchecked") { $embedchecked = ""; }
900
+ else { $embedchecked = "checked"; }
901
+ $form_fields["kgflashmediaplayer-options"]["label"] = __("Video Embed Options");
902
+ $form_fields["kgflashmediaplayer-options"]["input"] = "html";
903
+ $form_fields["kgflashmediaplayer-options"]["html"] = '<input type="checkbox" name="attachments[{$post->ID}][kgflashmediaplayer-showtitle]" id="attachments[{$post->ID}][kgflashmediaplayer-showtitle]" value="checked" onclick="document.getElementById(\'attachments['.$post->ID.'][kgflashmediaplayer-showtitlesave]\').value = this.value;" '.$showtitlechecked.'> <label for="attachments[{$post->ID}][kgflashmediaplayer-showtitle]">Include Title Above Video</label><br /><input type="checkbox" name="attachments[{$post->ID}][kgflashmediaplayer-downloadlink]" id="attachments[{$post->ID}][kgflashmediaplayer-downloadlink]" value="checked" onclick="document.getElementById(\'attachments['.$post->ID.'][kgflashmediaplayer-downloadsave]\').value = this.value;" '.$downloadlinkchecked.'> <label for="attachments[{$post->ID}][kgflashmediaplayer-downloadlink]">Generate Download Link Below Video<em><small>(Makes it easier for users to download video file)</em></small></label><br /><input type="checkbox" name="attachments[{$post->ID}][kgflashmediaplayer-embed]" id="attachments[{$post->ID}][kgflashmediaplayer-embed]" value="checked" onclick="if(this.checked) { document.getElementById(\'attachments['.$post->ID.'][kgflashmediaplayer-embedsave]\').value = \'checked\'; } else { document.getElementById(\'attachments['.$post->ID.'][kgflashmediaplayer-embedsave]\').value = \'unchecked\'; }"'.$embedchecked.'> <label for="attachments[{$post->ID}][kgflashmediaplayer-embed]">Generate Embed Shortcode <em><small>(Turn off checkbox to use default WordPress video embedding)</small></em></label>';
904
+
905
+ //$form_fields["kgflashmediaplayer-attachment"]["label"] = __("All Meta");
906
+ //$form_fields["kgflashmediaplayer-attachment"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-attachment", true);
907
+
908
+ } //only add fields if attachment is video
909
+ return $form_fields;
910
+ }
911
+ // attach our function to the correct hook
912
+ add_filter("attachment_fields_to_edit", "kg_image_attachment_fields_to_edit", null, 2);
913
+
914
+ /**
915
+ * @param array $post
916
+ * @param array $attachment
917
+ * @return array
918
+ */
919
+ function kg_video_attachment_fields_to_save($post, $attachment) {
920
+ // $attachment part of the form $_POST ($_POST[attachments][postID])
921
+ // $post attachments wp post array - will be saved after returned
922
+ // $post['post_type'] == 'attachment'
923
+ if( isset($attachment['kgflashmediaplayer-poster']) ) {
924
+ if ( !url_exists($attachment['kgflashmediaplayer-poster']) ) {
925
+ $uploads = wp_upload_dir();
926
+ $posterfile = pathinfo($attachment['kgflashmediaplayer-poster'], PATHINFO_BASENAME);
927
+ $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile;
928
+ if ( is_file($tmp_posterpath) ) { copy($tmp_posterpath, $uploads['path'].'/'.$posterfile); }
929
+ rrmdir($uploads['path'].'/thumb_tmp');
930
+ }
931
+ update_post_meta($post['ID'], '_kgflashmediaplayer-poster', $attachment['kgflashmediaplayer-poster']);
932
+ }
933
+ if( isset($attachment['thumbtime']) ) {update_post_meta($post['ID'], '_kgflashmediaplayer-thumbtime', $attachment['thumbtime']); }
934
+ if( isset($attachment['kgflashmediaplayer-widthsave']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-width', $attachment['kgflashmediaplayer-widthsave']); }
935
+ if( isset($attachment['kgflashmediaplayer-heightsave']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-height', $attachment['kgflashmediaplayer-heightsave']); }
936
+ if( isset($attachment['kgflashmediaplayer-aspect']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-aspect', $attachment['kgflashmediaplayer-aspect']); }
937
+ if( isset($attachment['kgflashmediaplayer-embedsave']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-embed', $attachment['kgflashmediaplayer-embedsave']); }
938
+ if( isset($attachment['kgflashmediaplayer-downloadsave']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-download', $attachment['kgflashmediaplayer-downloadsave']); }
939
+ if( isset($attachment['kgflashmediaplayer-showtitlesave']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-showtitle', $attachment['kgflashmediaplayer-showtitlesave']); }
940
+
941
+
942
+ //$attachment_printr = print_r($attachment, true);
943
+ //update_post_meta($post['ID'], '_kgflashmediaplayer-attachment', $attachment_printr );
944
+
945
+ return $post;
946
+ }
947
+ add_filter("attachment_fields_to_save", "kg_video_attachment_fields_to_save", null, 2);
948
+
949
+
950
+ class kgInsertMedia {
951
+ //class constructor
952
+ function kgInsertMedia () {
953
+ add_filter('media_send_to_editor', array($this, 'kgmodifyMediaInsert') , 10, 3);
954
+ }
955
+ //function that does the modifying
956
+ function kgmodifyMediaInsert($html, $attachment_id, $attachment) {
957
+
958
+ $output = $html;
959
+
960
+ $attachment['embed'] = get_post_meta($attachment_id, "_kgflashmediaplayer-embed", true);
961
+
962
+ if ($attachment['embed'] == "checked" || $attachment_id == "singleurl" ) {
963
+ $output = "";
964
+ $attachment['url'] = wp_get_attachment_url($attachment_id);
965
+ $attachment['title'] = get_the_title($attachment_id);
966
+ $attachment['poster'] = get_post_meta($attachment_id, "_kgflashmediaplayer-poster", true);
967
+ $attachment['width'] = get_post_meta($attachment_id, "_kgflashmediaplayer-width", true);
968
+ $attachment['height'] = get_post_meta($attachment_id, "_kgflashmediaplayer-height", true);
969
+ $attachment['downloadlink'] = get_post_meta($attachment_id, "_kgflashmediaplayer-download", true);
970
+ $attachment['showtitle'] = get_post_meta($attachment_id, "_kgflashmediaplayer-showtitle", true);
971
+ if ($attachment['showtitle'] =="checked") { $output .= '<strong>'.$attachment["title"].'</strong><br />'; }
972
+ $output .= '[FMP';
973
+ if ($attachment['poster'] !="") { $output .= ' poster="'.$attachment["poster"].'"'; }
974
+ if ($attachment['width'] !="") { $output .= ' width="'.$attachment["width"].'"'; }
975
+ if ($attachment['height'] !="") { $output .= ' height="'.$attachment["height"].'"'; }
976
+ $output .= ']'.$attachment["url"].'[/FMP]<br />';
977
+ if ($attachment['downloadlink'] == "checked") { $output .= '<a href="'.$attachment["url"].'">Right-click or ctrl-click this link to download.</a><br />'; }
978
+ } //if embed code is enabled
979
+ return $output;
980
+ }
981
+ }
982
+ //instantiate the class
983
+ $kgIM = new kgInsertMedia();
984
+
985
+
986
+ //add_filter('video_send_to_editor_url', 'kg_filter_video_url', 20, 3);
987
+
988
+ //function kg_filter_video_url($html, $href, $title) { //when inserting via URL only
989
+ // $html = '[FMP]'.$href.'"[/FMP]';
990
+ // return $html;
991
+ //}
992
+
993
+ function kg_embedurl_menu($tabs) {
994
+ $newtab = array('embedurl' => __('Embed from URL', 'kgoutsidevideo'));
995
+ return array_merge($tabs, $newtab);
996
+ }
997
+ add_filter('media_upload_tabs', 'kg_embedurl_menu');
998
+
999
+ function media_embedurl_process() {
1000
+ media_upload_header();
1001
+ ?>
1002
+ <form class="media-upload-form type-form validate" id="video-form" enctype="multipart/form-data" method="post" action="">
1003
+
1004
+ <div id="media-items">
1005
+ <div class="media-item media-blank">
1006
+ <table id="kgflashmediaplayer-table" class="describe">
1007
+ <tbody>
1008
+ <tr>
1009
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="videotitle">Video Title</label></span></th>
1010
+ <td class="field"><input type="text" id="videotitle" name="videotitle" value="" size="50" />
1011
+ <p class="help"><small>Add an optional header above the video.</small></p></td>
1012
+ </tr>
1013
+ <tr>
1014
+ <th valign="top" scope="row" class="label"><label for="attachments[singleurl][kgflashmediaplayer-url]">Video URL</label></th>
1015
+ <td class="field"><input type="text" id="attachments[singleurl][kgflashmediaplayer-url]" name="attachments[singleurl][kgflashmediaplayer-url]" value="" size="50" onchange="document.getElementById('attachments_singleurl_encodeplaceholder').innerHTML = '';"/>
1016
+ <p class="help"><small>Specify the URL of the video file.</small></p></td>
1017
+ </tr>
1018
+ <tr>
1019
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="numberofthumbs">Thumbnails</label></span></th>
1020
+ <td class="field"><div id="attachments_singleurl_thumbnailplaceholder"></div><input id="attachments_singleurl_numberofthumbs" type="text" value="4" maxlength="2" size="4" style="width:25px;" title="Number of Thumbnails" onchange="document.getElementById('attachments[singleurl][thumbtime]').value='';"><input type="button" id="attachments[singleurl][thumbgenerate]" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kg_generate_thumb('singleurl', 'generate');"/><input type="button" id="thumbrandomize" class="button-secondary" value="Randomize" name="thumbrandomize" onclick="kg_generate_thumb('singleurl', 'random');" /><input type="button" id="attachments['singleurl'][deletebutton]" class="button-secondary" value="Delete" name="deletebutton" onclick="kg_generate_thumb('singleurl', 'delete');"/> <input type="checkbox" id="attachments_singleurl_firstframe"><label for="attachments_1_firstframe">Force 1st Frame Thumbnail</label></td>
1021
+ </tr>
1022
+ <tr>
1023
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="attachments[singleurl][thumbtime]">Thumbnail Timecode</span></label><br class="clear" /></th>
1024
+ <td class="field"><input type="text" name="attachments[singleurl][thumbtime]" id="attachments[singleurl][thumbtime]" value="" size="50" />
1025
+ <p class="help"><small>Optional: generates a single thumbnail at the specified time (hh:mm:ss, mm:ss, or s).</small></p></td>
1026
+ </tr>
1027
+ <tr>
1028
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="attachments[singleurl][kgflashmediaplayer-poster]">Thumbnail URL</label></span></th>
1029
+ <td class="field"><input type="text" name="attachments[singleurl][kgflashmediaplayer-poster]" id="attachments[singleurl][kgflashmediaplayer-poster]" value="" size="50" />
1030
+ <p class="help"><small>Leave blank to use <a href="options-general.php?page=video-embed-thumbnail-generator.php" target="_blank">default thumbnail</a>.</small></p></td>
1031
+ </tr>
1032
+ <tr>
1033
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="attachments[singleurl][kgflashmediaplayer-width]">Dimensions</label></span></th>
1034
+ <td class="field">Width: <input name="attachments_singleurl_kgflashmediaplayer-width" type="text" value="" id="attachments_singleurl_kgflashmediaplayer-width" type="text" style="width:50px;" onchange="kg_set_dimension('singleurl', 'height', this.value);" onkeyup="kg_set_dimension('singleurl', 'height', this.value);"> Height: <input id="attachments_singleurl_kgflashmediaplayer-height" type="text" value="" style="width:50px;" onchange="kg_set_dimension('singleurl', 'width', this.value);" onkeyup="kg_set_dimension('singleurl', 'width', this.value);"> <input type="checkbox" id="attachments_singleurl_kgflashmediaplayer-lockaspect" onclick="kg_set_aspect('singleurl', this.checked);" checked> <label for="attachments_singleurl_kgflashmediaplayer-lockaspect"><small>Lock to Aspect Ratio</small></label>
1035
+ <p class="help"><small>Leave blank to use <a href="options-general.php?page=video-embed-thumbnail-generator.php" target="_blank">default dimensions</a>.</small></p></td>
1036
+ </tr>
1037
+ <tr>
1038
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label>Options</span></label></th>
1039
+ <td><input type="checkbox" name="downloadlink" id="downloadlink" value="true" class="field" /><label for="downloadlink">Generate Download Link Below Video <small>(Makes it easier for users to download video file)</small></label></td>
1040
+ </tr>
1041
+ <tr>
1042
+ <th valign="top" scope="row" class="label"><span class="alignleft"><label for="html5">HTML5 & Mobile</span></label></th>
1043
+ <td><input type="button" id="html5" class="button-secondary" value="Encode" name="html5" onclick="kg_generate_thumb('singleurl', 'encode');" /><div id="attachments_singleurl_encodeplaceholder" name="attachments_singleurl_encodeplaceholder" style="display:inline-block;"></div><br />
1044
+ <small>(Experimental) Uses FFMPEG to enocde an H.264/M4V file compatible with most mobile browsers and either a WEBM or OGV depending on <a href='options-general.php?page=video-embed-thumbnail-generator.php' target='_blank'>settings</a>.</small></td>
1045
+ <tr class="submit">
1046
+ <td></td>
1047
+ <td>
1048
+ <input type="submit" onclick="kg_insert_shortcode();" name="insertonlybutton" id="insertonlybutton" class="button" value="Insert into Post" />
1049
+ </td>
1050
+ </tr>
1051
+ </tbody></table>
1052
+ </div>
1053
+ </div>
1054
+
1055
+ <?php
1056
+ $uploads = wp_upload_dir();
1057
+ $maxheight = get_option('wp_FMP_height');
1058
+ $maxwidth = get_option('wp_FMP_width');
1059
+ ?>
1060
+
1061
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-ffmpeg_path]' id='attachments[singleurl][kgflashmediaplayer-ffmpeg_path]' value='<?php echo get_option('wp_FMP_ffmpeg'); ?>' />
1062
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-encodeogg]' id='attachments[singleurl][kgflashmediaplayer-encodeogg]' value='<?php echo get_option('wp_FMP_encodeogg'); ?>' />
1063
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-encodewebm]' id='attachments[singleurl][kgflashmediaplayer-encodewebm]' value='<?php echo get_option('wp_FMP_encodewebm'); ?>' />
1064
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-plugin_dir]' id='attachments[singleurl][kgflashmediaplayer-plugin_dir]' value='<?php echo plugins_url("", __FILE__); ?>' />
1065
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-upload_url]' id='attachments[singleurl][kgflashmediaplayer-upload_url]' value='<?php echo $uploads['url']; ?>' />
1066
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-upload_path]' id='attachments[singleurl][kgflashmediaplayer-upload_path]' value='<?php echo $uploads['path']; ?>' />
1067
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-upload_basedir]' id='attachments[singleurl][kgflashmediaplayer-upload_basedir]' value='<?php echo $uploads['basedir']; ?>' />
1068
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxheight]' id='attachments[singleurl][kgflashmediaplayer-maxheight]' value='<?php echo($maxheight); ?>' />
1069
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxwidth]' id='attachments[singleurl][kgflashmediaplayer-maxwidth]' value='<?php echo($maxwidth); ?>' />
1070
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-aspect]' id='attachments[singleurl][kgflashmediaplayer-aspect]' value='<?php echo($maxheight/$maxwidth); ?>' />
1071
+ </form>
1072
+
1073
+ <?php
1074
+ }
1075
+ function kg_embedurl_handle() {
1076
+ return wp_iframe( 'media_embedurl_process');
1077
+ }
1078
+ add_action('media_upload_embedurl', 'kg_embedurl_handle');
1079
+
1080
+
1081
+ function enqueue_kg_script() {
1082
+ wp_enqueue_script( 'video_embed_thumbnail_generator_script', plugins_url('/kg_video_plugin.js', __FILE__) );
1083
+ }
1084
+
1085
  add_action('wp_head', 'addSWFObject');
1086
  add_action('admin_menu', 'addFMPOptionsPage');
1087
  add_action('save_post', 'kg_addPostSave');
1088
+ add_action('admin_enqueue_scripts', 'enqueue_kg_script');
1089
 
1090
  add_shortcode('FMP', 'FMP_shortcode');
1091