Video Embed & Thumbnail Generator - Version 4.0.1

Version Description

  • April 23, 2013 =
  • Added options to display video title and embed code overlays on video player, and captions and view counts below videos.
  • Added option to filter your theme's video attachment page template to display the video instead of WordPress's default behavior of just showing the title of the video. For backwards compatibility retained old method of completely replacing the video attachment template with a video player.
  • Redesigned settings page to save using AJAX, and added a sample video player so changes are seen immediately.
  • Added iframe method to embed your videos on other websites.
  • Additional video formats encoded by the plugin are now added to the WordPress database as video attachments. To avoid a Russian nesting doll scenario these child attachments do not have the fields for creating thumbnails and encoding additional formats.
  • Changed encoded H.264 extensions from .m4v to .mp4 to increase compatibility with WordPress 3.6's new video capabilities. Existing M4V files will still work.
  • Checks only one time for alternate video sources when videos are embedded from other servers. This should speed up page load times considerably.
  • Added ability to rotate and replace the original file for videos recorded vertically on cell phones.
  • Added post meta box to posts with embedded videos that lists alternate formats found for each video.
  • Added option to set a post's featured image to the most recently generated thumbnail, and a button to set all previously generated thumbnails as featured images.
  • Added option to save generated thumbnails as children of either the video or the post the video is attached to, and a button to convert all thumbnails to the chosen hierarchy.
  • Added option to delete associated thumbnails and additional encoded video formats when original video attachment is deleted.
  • Added backwards compatibility for WordPress versions 3.2 and above.
  • If Strobe Media Playback player is selected, the Video.js player is used in situations where Flash doesn't work (webm, ogg playback) instead of the ugly default browser players.
  • Added watermark, view counts, volume attribute, and Google Analytics event tracking when using Strobe Media Playback player.
  • Added alignment option to center or right-justify videos.
  • Revised video player setup to properly resize the player if the containing DIV is smaller than the video, and resize again if the window size changes (or orientation changes on Android).
  • No matter which player is selected, iOS now displays the built-in controls so AirPlay works.
  • Added schema.org videoobject markup for improved SEO.
  • Fixed FLV embedding with Video.js player and improved selection of embedded formats for Strobe Media Playback.
  • Adjusted video gallery CSS and added a play button overlay to gallery thumbnails.
  • Adjusted watermark and Video.js play button CSS so the overlays don't overwhelm small videos.
  • Set Video.js controls to fade out on autoplay and on iOS, without having to mouseover the video.
  • Fixed endless "loading" spinner shown at the end of videos in some browsers in Video.js player.
  • Clicking "Insert into post" immediately after upload without changing any options now inserts shortcode instead of just the title of the video.
  • Inserting shortcode without a thumbnail no longer attempts to save the nonexistent thumbnail. Thumbnail cleanup is handled better.
  • Fixed error message "array_key_exists() expects parameter 2 to be array" when shortcode didn't have attributes.
  • Escaped all shell commands for increased security.
  • Fixed bug that made "Encode" button disappear if all formats were checked.
  • Fixed missing argument for kgvid_clear_completed_queue() when scheduling cleanup.
Download this release

Release Info

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

Code changes from version 3.1.1 to 4.0.1

css/images/ios_novideo.png ADDED
Binary file
css/kgvid_styles.css CHANGED
@@ -1,42 +1,166 @@
1
- div.kgvid_watermark {
 
 
 
 
 
 
 
 
 
 
2
  display: block;
3
  position: absolute;
4
- bottom: 10px;
5
- right: 10px;
6
  z-index: 1001;
7
  margin: 0px;
 
 
8
  }
9
 
10
  .vjs-controls {
11
  z-index:1002;
12
  }
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  .kgvid_video_gallery_thumb {
15
  position: relative;
16
  display:inline-block;
17
- margin:10px;
 
18
  }
19
 
20
  .kgvid_video_gallery_thumb img {
21
  width: 100%;
22
- max-width:none !important; //fixes conflict with some themes
23
  padding:0px;
24
- margins:0px;
25
  }
26
 
27
- .kgvid_video_gallery_thumb span {
28
  position:absolute;
29
- padding-top:10px;
30
- bottom:4px;
31
  left:0px;
32
- height:25px;
33
  width:100%;
34
- text-align:center;
35
- color:white;
36
- background-color: rgba(0,0,0,0.5);
37
- vertical-align:middle;
 
 
 
 
 
 
 
38
  letter-spacing:0.05em;
39
- font-size:10pt;
 
 
 
40
  }
41
 
42
  #kgvid_GalleryVideo {
@@ -54,13 +178,14 @@ div.kgvid_watermark {
54
  *
55
  * http://docs.jquery.com/UI/Dialog#theming
56
  */
57
- .kgvid_gallery .ui-dialog { position: absolute; width: 300px; background-color:black; }
58
  .kgvid_gallery .ui-dialog .ui-dialog-titlebar { position: relative; float:right; }
59
  .kgvid_gallery .ui-dialog .ui-dialog-title { float: left; }
60
- .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; left:10px; top:-10px; }
61
- .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; }
62
- .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close:hover, .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; }
63
- .kgvid_gallery .ui-dialog .ui-dialog-content { position: relative; border: 0; padding: 0px; background: none; overflow: hidden; zoom: 1; }
 
64
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; }
65
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; }
66
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; }
@@ -68,7 +193,7 @@ div.kgvid_watermark {
68
  .kgvid_gallery .ui-draggable .ui-dialog-titlebar { }
69
 
70
  /* Overlays */
71
- .kgvid_gallery .ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
72
 
73
  /* Component containers
74
  ----------------------------------*/
1
+ .kgvid_wrapper {
2
+ margin: 1em 0px;
3
+ display: inline-block;
4
+ position: relative;
5
+ }
6
+
7
+ .kgvid_videodiv {
8
+ position: relative;
9
+ }
10
+
11
+ .kgvid_watermark img {
12
  display: block;
13
  position: absolute;
14
+ bottom: 7%;
15
+ right: 5%;
16
  z-index: 1001;
17
  margin: 0px;
18
+ max-width: 10%;
19
+ box-shadow: none;
20
  }
21
 
22
  .vjs-controls {
23
  z-index:1002;
24
  }
25
 
26
+ div.kgvid_ios_novideo {
27
+ z-index:1003;
28
+ position:absolute;
29
+ width:100%;
30
+ height:100%;
31
+ background: url(images/ios_novideo.png) center center no-repeat;
32
+ background-size: 50px;
33
+ }
34
+
35
+ img.kgvid_ios_novideo {
36
+ width:100%;
37
+ height:100%;
38
+ max-width:100%;
39
+ }
40
+
41
+ .kgvid_video_meta {
42
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
43
+ line-height: normal;
44
+ color: white;
45
+ display: block;
46
+ position: absolute;
47
+ top: 0px;
48
+ z-index: 1003;
49
+ margin: 0px;
50
+ width: 100%;
51
+ height: 32px;
52
+ background: #242424; /* Old browsers */
53
+ background: -moz-linear-gradient(top, #242424 50%, #1f1f1f 50%, #171717 100%); /* FF3.6+ */
54
+ background: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(50%,#242424), color-stop(50%,#1f1f1f), color-stop(100%,#171717)); /* Chrome,Safari4+ */
55
+ background: -webkit-linear-gradient(top, #242424 50%,#1f1f1f 50%,#171717 100%); /* Chrome10+,Safari5.1+ */
56
+ background: -o-linear-gradient(top, #242424 50%,#1f1f1f 50%,#171717 100%); /* Opera11.10+ */
57
+ background: -ms-linear-gradient(top, #242424 50%,#1f1f1f 50%,#171717 100%); /* IE10+ */
58
+ /* Filter was causing a lot of weird issues in IE. Elements would stop showing up, or other styles would break. */
59
+ /*filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#242424', endColorstr='#171717',GradientType=0 );*/ /* IE6-9 */
60
+ background: linear-gradient(top, #242424 50%,#1f1f1f 50%,#171717 100%); /* W3C */
61
+ visibility: hidden;
62
+ opacity: 0;
63
+ -webkit-transition: visibility 1s linear, opacity 1s linear;
64
+ -moz-transition: visibility 1s linear, opacity 1s linear;
65
+ -o-transition: visibility 1s linear, opacity 1s linear;
66
+ }
67
+
68
+ .kgvid_video_meta_hover {
69
+ opacity: 1;
70
+ visibility: visible;
71
+ }
72
+
73
+ .kgvid_video_meta div {
74
+ display:inline-block;
75
+ margin: 6px;
76
+ }
77
+
78
+ .kgvid_title {
79
+ height: 18px;
80
+ font-size: 10pt;
81
+ overflow: hidden;
82
+ padding-top: 1px;
83
+ padding-left: 4px;
84
+ }
85
+
86
+ #content .kgvid_video_meta input {
87
+ font: inherit;
88
+ color: #eee;
89
+ line-height: 1.6em;
90
+ }
91
+
92
+ .kgvid_video_meta input {
93
+ color: #eee;
94
+ width: 100px;
95
+ font: 10px "Helvetica Neue", Helvetica, Arial, sans-serif !important;
96
+ line-height: 1.6em;
97
+ background-color: #999;
98
+ border: none;
99
+ -moz-border-radius: 5px;
100
+ border-radius: 5px;
101
+ padding: 2px;
102
+ }
103
+
104
+ .kgvid_share {
105
+ font-size: 10px;
106
+ float: right;
107
+ }
108
+
109
+ .kgvid_below_video {
110
+ margin: 2px 6px 0px 4px;
111
+ min-height: 20px;
112
+ clear: both;
113
+ }
114
+
115
+ .kgvid_below_video div {
116
+ display: inline-block;
117
+ vertical-align: top;
118
+ }
119
+
120
+ .kgvid-viewcount {
121
+ float: right;
122
+ }
123
+
124
+ .kgvid-caption {
125
+ font-size: 85%;
126
+ font-style: italic;
127
+ }
128
+
129
  .kgvid_video_gallery_thumb {
130
  position: relative;
131
  display:inline-block;
132
+ margin:10px;
133
+ cursor: pointer; !important
134
  }
135
 
136
  .kgvid_video_gallery_thumb img {
137
  width: 100%;
138
+ max-width:none !important;
139
  padding:0px;
140
+ margin:0px;
141
  }
142
 
143
+ .kgvid_video_gallery_thumb .titlebackground {
144
  position:absolute;
145
+ bottom:10px;
 
146
  left:0px;
 
147
  width:100%;
148
+ padding:0px;
149
+ background-color: rgba(0,0,0,0.4);
150
+ overflow:hidden;
151
+ }
152
+
153
+ .kgvid_video_gallery_thumb:hover .titlebackground {
154
+ background-color: rgba(0,0,0,0.8);
155
+ }
156
+
157
+ .kgvid_video_gallery_thumb .videotitle {
158
+ color:white;
159
  letter-spacing:0.05em;
160
+ font-size:14px;
161
+ line-height: 1.5em;
162
+ text-align:center;
163
+ padding:4px;
164
  }
165
 
166
  #kgvid_GalleryVideo {
178
  *
179
  * http://docs.jquery.com/UI/Dialog#theming
180
  */
181
+ .kgvid_gallery .ui-dialog { position: absolute; width: 300px; background-color:black; z-index:10001; }
182
  .kgvid_gallery .ui-dialog .ui-dialog-titlebar { position: relative; float:right; }
183
  .kgvid_gallery .ui-dialog .ui-dialog-title { float: left; }
184
+ .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; left:10px; top:-10px; background: none; border: none; text-indent: -9999999px; }
185
+ .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close span { display: block; }
186
+ .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close span:focus { }
187
+ .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close:hover, .kgvid_gallery .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; outline: none; }
188
+ .kgvid_gallery .ui-dialog .ui-dialog-content { position: relative; border: 0; padding-top: 5px; padding-left: 5px; padding-bottom: 3px; background: none; overflow: hidden; zoom: 1; }
189
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; }
190
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; }
191
  .kgvid_gallery .ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; }
193
  .kgvid_gallery .ui-draggable .ui-dialog-titlebar { }
194
 
195
  /* Overlays */
196
+ .kgvid_gallery .ui-widget-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index:10000; }
197
 
198
  /* Component containers
199
  ----------------------------------*/
css/video-embed-thumbnail-generator_admin.css CHANGED
@@ -1,22 +1,18 @@
1
- .meter, .meter_finished {
2
  height: 14px;
3
- width: 100px;
4
  display: inline-block;
5
  position: relative;
 
6
  background: #e4e4e4;
7
  -moz-border-radius: 4px;
8
  -webkit-border-radius: 4px;
9
  border-radius: 4px;
10
  padding: 2px;
 
11
  }
12
 
13
- .meter > span {
14
- text-align: right;
15
- padding-right: 2px;
16
- font-weight: bold;
17
- vertical-align:top;
18
- color: white;
19
- font-size: 80%;
20
  display: inline-block;
21
  height: 100%;
22
  -webkit-border-top-right-radius: 4px;
@@ -63,6 +59,16 @@
63
  overflow: hidden;
64
  }
65
 
 
 
 
 
 
 
 
 
 
 
66
  .kgvid_cancel_button {
67
  -moz-box-shadow:inset 0px 1px 0px -1px #ffffff;
68
  -webkit-box-shadow:inset 0px 1px 0px -1px #ffffff;
@@ -86,74 +92,21 @@
86
  top:-1px;
87
  text-decoration:none;
88
  height:14px;
89
- }.kgvid_cancel_button:hover {
 
 
90
  background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
91
  background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
92
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
93
  background-color:#dfdfdf;
94
- }.kgvid_cancel_button:active {
 
 
95
  position:relative;
96
  top:1px;
97
  }
98
  /* This imageless css button was generated by CSSButtonGenerator.com */
99
 
100
- .meter_finished > span {
101
- text-align: center;
102
- font-weight: bold;
103
- color: white;
104
- font-size: 80%;
105
- display: inline-block;
106
- height: 100%;
107
- -webkit-border-top-right-radius: 10px;
108
- -webkit-border-bottom-right-radius: 10px;
109
- -moz-border-radius-topright: 10px;
110
- -moz-border-radius-bottomright: 10px;
111
- border-top-right-radius: 10px;
112
- border-bottom-right-radius: 10px;
113
- -webkit-border-top-left-radius: 10px;
114
- -webkit-border-bottom-left-radius: 10px;
115
- -moz-border-radius-topleft: 10px;
116
- -moz-border-radius-bottomleft: 10px;
117
- border-top-left-radius: 10px;
118
- border-bottom-left-radius: 10px;
119
- background-color: rgb(41,140,186);
120
- background-image: -webkit-gradient(
121
- linear,
122
- left bottom,
123
- left top,
124
- color-stop(0, rgb(41,140,186)),
125
- color-stop(1, rgb(41,140,186))
126
- );
127
- background-image: -webkit-linear-gradient(
128
- center bottom,
129
- rgb(41,140,186) 37%,
130
- rgb(41,140,186) 69%
131
- );
132
- background-image: -moz-linear-gradient(
133
- center bottom,
134
- rgb(41,140,186) 37%,
135
- rgb(41,140,186) 69%
136
- );
137
- background-image: -ms-linear-gradient(
138
- center bottom,
139
- rgb(41,140,186) 37%,
140
- rgb(41,140,186) 69%
141
- );
142
- background-image: -o-linear-gradient(
143
- center bottom,
144
- rgb(41,140,186) 37%,
145
- rgb(41,140,186) 69%
146
- );
147
- -webkit-box-shadow:
148
- inset 0 2px 9px rgba(255,255,255,0.3),
149
- inset 0 -2px 6px rgba(0,0,0,0.4);
150
- -moz-box-shadow:
151
- inset 0 2px 9px rgba(255,255,255,0.3),
152
- inset 0 -2px 6px rgba(0,0,0,0.4);
153
- position: relative;
154
- overflow: hidden;
155
- }
156
-
157
  div.kgvid_cancel_button input {
158
  font-size: 1pt;
159
  }
@@ -205,6 +158,11 @@ div.kgvid_cancel_button {
205
  padding-left:5px;
206
  }
207
 
 
 
 
 
 
208
  .kgvid_tooltip {
209
  color: #000000; outline: none;
210
  cursor: help; text-decoration: none;
@@ -272,4 +230,22 @@ a.kgvid_delete-format {
272
 
273
  a.kgvid_delete-format:hover {
274
  color: red !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  }
1
+ .kgvid_meter, .meter_finished {
2
  height: 14px;
3
+ width: 125px;
4
  display: inline-block;
5
  position: relative;
6
+ top: 3px;
7
  background: #e4e4e4;
8
  -moz-border-radius: 4px;
9
  -webkit-border-radius: 4px;
10
  border-radius: 4px;
11
  padding: 2px;
12
+
13
  }
14
 
15
+ .kgvid_meter_bar {
 
 
 
 
 
 
16
  display: inline-block;
17
  height: 100%;
18
  -webkit-border-top-right-radius: 4px;
59
  overflow: hidden;
60
  }
61
 
62
+ .kgvid_meter_text {
63
+ float:right;
64
+ padding-right: 2px;
65
+ font-weight: bold;
66
+ color: white;
67
+ font-size: 80%;
68
+ position:relative;
69
+ top: -2px;
70
+ }
71
+
72
  .kgvid_cancel_button {
73
  -moz-box-shadow:inset 0px 1px 0px -1px #ffffff;
74
  -webkit-box-shadow:inset 0px 1px 0px -1px #ffffff;
92
  top:-1px;
93
  text-decoration:none;
94
  height:14px;
95
+ }
96
+
97
+ .kgvid_cancel_button:hover {
98
  background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
99
  background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
100
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
101
  background-color:#dfdfdf;
102
+ }
103
+
104
+ .kgvid_cancel_button:active {
105
  position:relative;
106
  top:1px;
107
  }
108
  /* This imageless css button was generated by CSSButtonGenerator.com */
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  div.kgvid_cancel_button input {
111
  font-size: 1pt;
112
  }
158
  padding-left:5px;
159
  }
160
 
161
+ .kgvid_setting_nearvid div {
162
+ margin: 5px;
163
+ font-weight: bold;
164
+ }
165
+
166
  .kgvid_tooltip {
167
  color: #000000; outline: none;
168
  cursor: help; text-decoration: none;
230
 
231
  a.kgvid_delete-format:hover {
232
  color: red !important;
233
+ }
234
+
235
+ .kgvid_spinner .spinner {
236
+ float: none;
237
+ vertical-align: top;
238
+ }
239
+
240
+ .kgvid_spinner .saved {
241
+ margin-left:6px;
242
+ }
243
+
244
+ div.kgvid_post_meta_boxes {
245
+ display: inline-block;
246
+ width: 300px;
247
+ border: 1px solid #ddd;
248
+ padding: 10px;
249
+ margin: 5px;
250
+ vertical-align: top;
251
  }
images/nothumbnail.jpg CHANGED
Binary file
images/sample-video-h264.mp4 ADDED
Binary file
js/kgvid_video_embed.js CHANGED
@@ -1,32 +1,114 @@
1
- function kgvid_SetVideo(source, width, height) {
2
- jQuery('#kgvid_GalleryVideo').attr('src', source);
3
- jQuery('#kgvid_GalleryVideo').attr('width', parseInt(width)+20);
4
- jQuery('#kgvid_GalleryVideo').attr('height', parseInt(height)+20);
5
- jQuery('#kgvid_GalleryPlayerDiv').dialog("option", "width", parseInt(width)+30);
6
- jQuery('#kgvid_GalleryPlayerDiv').closest('.ui-dialog').height(parseInt(height))
7
- jQuery('#kgvid_GalleryPlayerDiv').dialog('open');
8
- jQuery('.ui-widget-overlay').click(function () { jQuery('#kgvid_GalleryPlayerDiv').dialog('close'); });
9
  }
10
 
11
- function kgvid_video_counter(id, plays, ends, event) {
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- var changed = false;
14
-
15
- if (plays != "not_countable" ) { //video is in the db
16
- var played = jQuery('#video_'+id+'_div').data("played") || "not played";
17
- if ( played == "not played" ) { plays++; changed = true; console.log("Played") }
18
- if ( event == "ended" ) { ends++; changed = true; }
19
- if ( changed == true ) {
20
- jQuery.post(ajax_object.ajaxurl, {
21
- action: 'kgvid_count_play',
22
- post_id: id,
23
- video_plays: plays,
24
- complete_views: ends
25
- }, function(data) {
26
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
- jQuery('#video_'+id+'_div').data("played", "played");
 
 
 
 
 
 
 
 
 
 
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
1
+ function kgvid_SetVideo(suffix, site_url, id, width, height) {
2
+ jQuery('#kgvid_GalleryPlayerDiv_'+suffix).html('<iframe id="kgvid_GalleryVideo_'+id+'" src="'+site_url+'?attachment_id='+id+'&kgvid_video_embed[enable]=true&kgvid_video_embed[gallery]=true&kgvid_video_embed[width]='+width+'&kgvid_video_embed[height]='+height+'" scrolling="no" width="'+width+'" height="'+height+'" frameborder="0" webkitallowfullscreen="" allowfullscreen=""></iframe>');
3
+ jQuery('#kgvid_GalleryPlayerDiv_'+suffix).dialog("option", "width", parseInt(width)+6);
4
+ jQuery('#kgvid_GalleryPlayerDiv_'+suffix).dialog('open');
5
+ jQuery('#kgvid_GalleryPlayerDiv_'+suffix).dialog("option", "height", parseInt(height)+10);
6
+ jQuery('.ui-widget-overlay').click(function () { jQuery('#kgvid_GalleryPlayerDiv_'+suffix).dialog('close'); });
 
 
7
  }
8
 
9
+ function kgvid_setup_video(id, player_type, set_volume) {
10
+ var player = _V_('video_'+id);
11
+ if ( player_type == "Video.js" ) {
12
+ if ( set_volume != "" ) { player.volume(set_volume); }
13
+ }
14
+ if ( player_type == "Strobe Media Playback" ) {
15
+ if ( set_volume != "" ) { document.getElementById('video_'+id+'html5_api').setVolume(set_volume); }
16
+ jQuery('#video_'+id+'_div').hover(function(){ jQuery('#video_'+id+'_meta').addClass('kgvid_video_meta_hover'); },function(){ jQuery('#video_'+id+'_meta').removeClass('kgvid_video_meta_hover'); });
17
+ }
18
+ jQuery('#video_'+id+'_div').prepend(jQuery('#video_'+id+'_watermark'));
19
+ jQuery('#video_'+id+'_watermark').attr('style', ''); //shows the hidden watermark div
20
+ jQuery('#video_'+id+'_div').prepend(jQuery('#video_'+id+'_meta'));
21
+ jQuery('#video_'+id+'_meta').attr('style', ''); //shows the hidden meta div
22
+ }
23
 
24
+ function kgvid_ios_player(id) {
25
+ //var source = document.getElementById('video_'+id+'_html5_api').src;
26
+ var player = _V_('video_'+id);
27
+ var source = document.getElementById('video_'+id+'_html5_api').src
28
+ var poster = player.options.poster;
29
+ if ( source != "" ) {
30
+ player.tag.src = '';
31
+ player.tech.removeTriggers();
32
+ player.load();
33
+ player.destroy();
34
+ var ios_video = '<video id="video_'+id+'" controls preload="metadata"';
35
+ if ( poster != null ) { ios_video += ' poster="'+poster+'" '; }
36
+ ios_video += '\><source src="'+source+'" type="video/mp4" /></video>';
37
+ }
38
+ else { var ios_video = '<div id="video_'+id+'" style="background-color:black;"><div class="kgvid_ios_novideo"></div>';
39
+ if ( poster != null ) { ios_video += '<img class="kgvid_ios_novideo" src="'+poster+'">'; }
40
+ ios_video += '</div>';
41
+ }
42
+ jQuery(player.el).remove();
43
+ jQuery('#video_'+id+'_div').prepend(ios_video);
44
+ if ( source != "" ) { document.getElementById('video_'+id).load(); }
45
+ }
46
+
47
+ function kgvid_resize_video(id, player_type, set_width, set_height) {
48
+ var aspect_ratio = Math.round(set_height/set_width*1000)/1000
49
+ var parent_width = jQuery('#kgvid_'+id+'_wrapper').parent().width();
50
+ if ( parent_width < set_width ) { set_width = parent_width; }
51
+ set_width = parseInt(set_width);
52
+
53
+ if ( set_width != 0 ) {
54
+
55
+ jQuery('#kgvid_'+id+'_wrapper').width(set_width);
56
+ var set_height = Math.round(set_width * aspect_ratio);
57
+ if ( player_type == "Video.js" ) {
58
+ _V_('video_'+id).width(set_width).height(set_height);
59
+ if ( set_width < 500 ) {
60
+ var scale = Math.round(100*set_width/500)/100;
61
+ jQuery('#kgvid_'+id+'_wrapper .vjs-big-play-button').css('-webkit-transform','scale('+scale+')').css('-o-transform','scale('+scale+')').css('-ms-transform','scale('+scale+')').css('transform','scale('+scale+')');
62
+ }
63
  }
64
+ if ( player_type == "Strobe Media Playback" ) {
65
+ jQuery('#video_'+id+'_div').height(set_height);
66
+ jQuery('#video_'+id+'_html5_api').attr('width',set_width).attr('height',set_height);
67
+ }
68
+ if ( player_type == "iOS" ) {
69
+ jQuery('#video_'+id).attr('width',set_width).attr('height',set_height);
70
+ jQuery('#video_'+id).width(set_width).height(set_height);
71
+ }
72
+
73
  }
74
 
75
+ var width_remove = 10;
76
+ if ( jQuery('#video_'+id+'_embed').length ) { width_remove = 180; }
77
+ jQuery('#video_'+id+'_title').width(set_width-width_remove); //truncates long titles
78
+
79
+ width_remove = 0;
80
+ if ( jQuery('#video_'+id+'_viewcount').length ) { width_remove = jQuery('#video_'+id+'_viewcount').width()+20; }
81
+ jQuery('#video_'+id+'_caption').width(set_width-width_remove); //wraps long captions
82
+ }
83
+
84
+ function kgvid_video_counter(id, plays, ends, event, title) {
85
+ var changed = false;
86
 
87
+ var played = jQuery('#video_'+id+'_div').data("played") || "not played";
88
+ if ( played == "not played" ) {
89
+ if (plays != "not_countable" ) { //video is in the db
90
+ plays++;
91
+ changed = true;
92
+ jQuery('#video_'+id+'_div').data("played", "played");
93
+ }
94
+ if (typeof _gaq != "undefined") { _gaq.push(["_trackEvent", "Videos", "Play Start", title]); }
95
+ }
96
+ if ( event == "end" ) {
97
+ if (ends != "not_countable" ) { //video is in the db
98
+ plays++;
99
+ ends++;
100
+ changed = true;
101
+ }
102
+ if (typeof _gaq != 'undefined') { _gaq.push(['_trackEvent', 'Videos', 'Complete View', title]); }
103
+ }
104
+ if ( changed == true ) {
105
+ jQuery.post(ajax_object.ajaxurl, {
106
+ action: 'kgvid_count_play',
107
+ post_id: id,
108
+ video_plays: plays,
109
+ complete_views: ends
110
+ }, function(data) {
111
+ jQuery('#video_'+id+'_viewcount').html(plays+' views');
112
+ });
113
+ }
114
  }
js/kgvid_video_plugin_admin.js CHANGED
@@ -34,17 +34,18 @@ function kgvid_set_aspect(postID, checked) {
34
 
35
  function kgvid_generate_thumb(postID, buttonPushed) {
36
 
37
- var kgflashmediaplayersecurity = document.getElementsByName('attachments[kgflashmediaplayer-security]')[0].value;
38
  var attachmentURL = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-url]')[0].value;
39
  var howmanythumbs = document.getElementById('attachments-'+postID+'-numberofthumbs').value;
40
  var firstframethumb = document.getElementById('attachments-'+postID+'-firstframe').checked;
41
  var posterurl = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-poster]')[0].value;
 
42
  var specifictimecode = document.getElementsByName('attachments['+postID+'][thumbtime]')[0].value;
43
  if (specifictimecode === "0") { specifictimecode = "firstframe"; }
 
 
 
44
  var thumbnailplaceholderid = "#attachments-"+postID+"-thumbnailplaceholder";
45
- var encodeplaceholderid = "#attachments-"+postID+"-encodeplaceholder";
46
- var encodeprogressplaceholderid = "#attachments-"+postID+"-encodeprogressplaceholder";
47
- var altembedselectid = "#attachments-"+postID+"-altembedselect";
48
  var thumbnailboxID = "#attachments-"+postID+"-kgflashmediaplayer-thumbnailbox";
49
  var thumbnailboxoverlayID = "#attachments-"+postID+"-kgflashmediaplayer-thumbnailboxoverlay";
50
  var cancelthumbdivID = '#attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv';
@@ -55,7 +56,64 @@ function kgvid_generate_thumb(postID, buttonPushed) {
55
  var i=1;
56
  var increaser = 0;
57
  var iincreaser = 0;
 
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  var page = "attachment";
60
  var document_url = document.URL;
61
  var page_check = /[?&]page=([^&]+)/i;
@@ -64,7 +122,7 @@ function kgvid_generate_thumb(postID, buttonPushed) {
64
  page = "queue";
65
  }
66
 
67
- var formats = new Array("1080", "720", "mobile", "ogg", "webm");
68
  var kgvid_encode = new Object();
69
  for ( var key in formats ) {
70
  kgvid_encode[formats[key]] = "";
@@ -73,82 +131,24 @@ function kgvid_generate_thumb(postID, buttonPushed) {
73
  }
74
  }
75
  JSON.stringify(kgvid_encode);
 
 
 
 
 
 
76
 
77
- if (buttonPushed == "generate" || buttonPushed == "random" ) {
78
- actionName = "generate";
79
- if (specifictimecode != 0 ) { howmanythumbs = 1; }
80
- }
81
- else {
82
- actionName = buttonPushed;
83
- howmanythumbs = 1;
84
- }
85
-
86
- if (buttonPushed != "enqueue") {
87
-
88
- jQuery(thumbnailplaceholderid).empty();
89
- jQuery(thumbnailplaceholderid).append('<strong>Choose Thumbnail: </strong><div style="display:inline-block;" id="attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv" name="attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv"> <input type="button" id="attachments-'+postID+'-kgflashmediaplayer-cancelencode" class="button-secondary" value="Cancel Generating" name="attachments-'+postID+'-cancelencode" onclick="kgvid_cancel_thumbs(\''+postID+'\');"></div><div id="attachments-'+postID+'-kgflashmediaplayer-thumbnailboxoverlay" name="attachments-'+postID+'-kgflashmediaplayer-thumbnailboxoverlay" class="kgvid_thumbnail_overlay"><div name="attachments-'+postID+'-kgflashmediaplayer-thumbnailbox" id="attachments-'+postID+'-kgflashmediaplayer-thumbnailbox" class="kgvid_thumbnail_box"></div></div>');
90
- }
91
-
92
- if (buttonPushed == "enqueue") {
93
  jQuery(encodeplaceholderid).empty();
94
  jQuery(encodeprogressplaceholderid).empty();
95
- jQuery(encodeplaceholderid).append('<strong>Loading...</strong>');
96
- }
97
-
98
- function kgvid_do_post() {
99
-
100
- iincreaser = i + increaser;
101
-
102
- jQuery.post(ajaxurl, { action:"kgvid_callffmpeg", security: kgflashmediaplayersecurity, movieurl: attachmentURL, numberofthumbs: howmanythumbs, thumbnumber:i, thumbnumberplusincreaser:iincreaser, ffmpeg_action: actionName, encodeformats: kgvid_encode, attachmentID: postID, generate_button: buttonPushed, thumbtimecode: specifictimecode, dofirstframe: firstframethumb, poster: posterurl }, function(data) {
103
-
104
- if (actionName == "generate") {
105
- kgthumbnailTimeout = jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts") || null;
106
- jQuery(thumbnailboxID).append(data.thumbnaildisplaycode);
107
- var thumbnailselectID = "#attachments-"+postID+"-thumb"+i;
108
- jQuery(thumbnailselectID).css({display:"none"});
109
- jQuery(thumbnailselectID).animate({opacity: 'toggle', height: 'toggle', width: 'toggle'}, 1000);
110
- if (data.lastthumbnumber == "break" || (kgthumbnailTimeout == null && i != 1) ) { i = parseInt(howmanythumbs) + 1; }
111
- else { i = parseInt(data.lastthumbnumber); }
112
- increaser++;
113
- if ( i <= howmanythumbs ) {
114
- if ( kgthumbnailTimeout == null ) { kgthumbnailTimeout = new Array(); }
115
- kgthumbnailTimeout[i] = setTimeout(function(){
116
- //jQuery(thumbnailplaceholderid).data("kgthumbnailTimeout", null);
117
- kgvid_do_post();
118
- }, 750);
119
- jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts", kgthumbnailTimeout);
120
- }
121
- else {
122
- jQuery(thumbnailboxoverlayID).fadeTo(2000, 1);
123
- jQuery(cancelthumbdivID).animate({opacity: 0}, 500);
124
- jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts", null);
125
- }
126
-
127
- kgvid_aspect = data.movie_height/data.movie_width;
128
- document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-aspect]')[0].value = kgvid_aspect;
129
- if (parseInt(data.movie_width) < parseInt(document.getElementsByName(maxwidthID)[0].value) ) { document.getElementById(widthID).value = data.movie_width; }
130
- else { document.getElementById(widthID).value = document.getElementsByName(maxwidthID)[0].value; }
131
- if (parseInt(data.movie_width) > parseInt(document.getElementsByName(maxwidthID)[0].value) ) { document.getElementById(heightID).value = Math.round(kgvid_aspect*parseInt(document.getElementsByName(maxwidthID)[0].value)); }
132
- else { document.getElementById(heightID).value = data.movie_height; }
133
- jQuery.post( ajaxurl , { action:"kgvid_schedule_cleanup_generated_files", security:kgflashmediaplayersecurity, thumbs:"true" } );
134
- kgvid_redraw_encode_checkboxes(attachmentURL, postID, page);
135
- }//if thumbnail button pressed
136
-
137
- if (buttonPushed == "enqueue") {
138
- jQuery(encodeplaceholderid).empty();
139
- jQuery(encodeprogressplaceholderid).empty();
140
- jQuery(encodeplaceholderid).append(data.embed_display);
141
- jQuery.post( ajaxurl , { action:"kgvid_ajax_encode_videos", security:kgflashmediaplayersecurity } , function(data) {
142
- jQuery(encodeprogressplaceholderid).empty();
143
- jQuery(encodeplaceholderid).append(data.embed_display);
144
- kgvid_redraw_encode_checkboxes(attachmentURL, postID, page);
145
- }, "json");
146
- }//if encode button pressed
147
  }, "json");
148
-
149
- }// end kgvid_do_post function
150
-
151
- kgvid_do_post(); //actually call the loop
152
  }
153
 
154
  function kgvid_hide_standard_wordpress_display_settings(postID) {
@@ -157,79 +157,92 @@ function kgvid_hide_standard_wordpress_display_settings(postID) {
157
  }
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  function kgvid_set_singleurl() {
161
 
162
  var oldbasename = jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id") || "singleurl";
 
 
163
  var url = document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-url').value;
164
  var validExtensions = new Array(".flv", ".f4v", ".mp4", ".mov", ".m4v", ".webm", ".ogg", ".ogv");
165
  var extensionExists = false;
166
- for (var i = 0; i < validExtensions.length; i++) {
167
- if (url.indexOf(validExtensions[i]) != -1) {
168
- extensionExists = true;
169
- if ( document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-ffmpegexists').value == "on" ) {
170
- document.getElementById('attachments-'+oldbasename+'-thumbgenerate').disabled = false;
171
- document.getElementById('attachments-'+oldbasename+'-thumbgenerate').title = "";
172
- document.getElementById('attachments-'+oldbasename+'-thumbrandomize').disabled = false;
173
- document.getElementById('attachments-'+oldbasename+'-thumbrandomize').title = "";
174
- document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encode').disabled = false;
175
- document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encode').title = "";
176
- var basename = "singleurl_"+url.replace(/^.*\/|\.[^.]*$/g, '');
177
- //jQuery('#kgflashmediaplayer-table :input').each(function(){
178
- jQuery('#kgvid-form :input').each(function(){
179
- var newid = jQuery(this).attr("id").replace(oldbasename, basename);
180
- jQuery(this).attr("id", newid);
181
- if ( jQuery(this).attr("name") ) {
182
- var newname = jQuery(this).attr("name").replace(oldbasename, basename);
183
- jQuery(this).attr("name", newname);
184
- }
185
- });
186
- jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id", basename);
187
- document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encodeboxes').id = 'attachments-'+basename+'-kgflashmediaplayer-encodeboxes';
188
- document.getElementById('attachments-'+oldbasename+'-thumbnailplaceholder').id = 'attachments-'+basename+'-thumbnailplaceholder';
189
- jQuery('#attachments-'+basename+'-thumbgenerate').replaceWith('<input type="button" id="attachments-'+basename+'-thumbgenerate" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'generate\');" >');
190
- jQuery('#attachments-'+basename+'-thumbrandomize').replaceWith('<input type="button" id="attachments-'+basename+'-thumbrandomize" class="button-secondary" value="Randomize" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'random\');" >');
191
- }
192
- else {
193
- document.getElementById('attachments-'+oldbasename+'-thumbgenerate').title = "FFMPEG not found";
194
- document.getElementById('attachments-'+oldbasename+'-thumbrandomize').title = "FFMPEG not found";
195
  }
196
- document.getElementById('insertonlybutton').disabled = false;
197
- document.getElementById('insertonlybutton').title = "";
198
- break;
199
  }
200
  }
 
201
  if (extensionExists == false) {
202
  if ( url != "" ) { alert("Please enter a URL that points to a valid video file. Video sharing sites are not supported by this plugin.\nTo embed from YouTube, Vimeo, etc, just paste the link directly into the post window and WordPress will handle the rest."); }
203
- document.getElementById('attachments-'+oldbasename+'-thumbgenerate').disabled = true;
204
- document.getElementById('attachments-'+oldbasename+'-thumbgenerate').title = "Please enter a valid video URL";
205
- document.getElementById('attachments-'+oldbasename+'-thumbrandomize').disabled = true;
206
- document.getElementById('attachments-'+oldbasename+'-thumbrandomize').title = "Please enter a valid video URL";
207
- document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encode').disabled = true;
208
- document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encode').title = "Please enter a valid video URL";
 
 
209
  document.getElementById('insertonlybutton').disabled = true;
210
  document.getElementById('insertonlybutton').title = "Please enter a valid video URL";
211
- basename = "singleurl";
212
  }
213
- kgvid_redraw_encode_checkboxes(url, basename, 'attachment');
214
  }
215
 
216
  function kgvid_insert_shortcode() {
217
 
218
- var kgflashmediaplayersecurity = document.getElementsByName('attachments[kgflashmediaplayer-security]')[0].value;
219
  var basename = jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id") || "singleurl";
 
220
  var url = document.getElementById('attachments-'+basename+'-kgflashmediaplayer-url').value;
221
  var posterurl = document.getElementById('attachments-'+basename+'-kgflashmediaplayer-poster').value;
222
-
223
- var iframe_url = document.URL;
224
- var id_check = /[?&]post_id=([^&]+)/i;
225
- var match = id_check.exec(iframe_url);
226
- if (match != null) {
227
- postid = match[1];
228
- } else {
229
- postid = "";
230
- }
231
 
232
- jQuery.post(ajaxurl, { action:'kgvid_callffmpeg', security: kgflashmediaplayersecurity, attachmentID: basename, movieurl: url, ffmpeg_action:'submit', poster: posterurl, post_id: postid }, function(data) {
233
  //jQuery('attachments-singleurl-thumbnailplaceholder').empty();
234
  }, "json" );
235
 
@@ -246,7 +259,7 @@ function kgvid_insert_shortcode() {
246
  endtitlecode = endtitlecode.split(' ');
247
  endtitlecode = endtitlecode[0];
248
  if ( endtitlecode.substr(-1,1) != '>' ) { endtitlecode = endtitlecode+'>'; }
249
- shortcode += titlecode + document.getElementById('videotitle').value + endtitlecode + '<br />';
250
  }
251
  if (url !="") {
252
  shortcode += ' [KGVID';
@@ -259,20 +272,28 @@ function kgvid_insert_shortcode() {
259
  parent.send_to_editor(shortcode);
260
  }
261
 
262
- function kgvid_cancel_encode(kgvid_pid, postID, video_key, format) {
263
 
264
- var kgflashmediaplayersecurity = document.getElementsByName('attachments[kgflashmediaplayer-security]')[0].value;
265
- //var cancelbuttonID = '#attachments-'+postID+'-kgflashmediaplayer-cancelencode';
 
 
 
 
 
 
 
 
 
266
 
267
- //jQuery(cancelbuttonID).empty();
268
- //jQuery(cancelbuttonID).append("<em>Canceling...</em>");
269
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).empty();
270
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).append('<strong>Canceling</strong>');
271
  jQuery.post(ajaxurl, { action:"kgvid_cancel_encode", security: kgflashmediaplayersecurity, kgvid_pid: kgvid_pid, video_key: video_key, format: format } );
272
 
273
  }
274
 
275
- function kgvid_delete_video(movieurl, postID, format) {
276
 
277
  var delete_for_sure = confirm("You are about to permanently delete the encoded video.\n 'Cancel' to stop, 'OK' to delete.");
278
 
@@ -283,12 +304,9 @@ function kgvid_delete_video(movieurl, postID, format) {
283
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encode').css('display', 'inline');
284
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).empty();
285
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).append('<strong>Deleted</strong>');
286
- var kgflashmediaplayersecurity = document.getElementsByName('attachments[kgflashmediaplayer-security]')[0].value;
287
 
288
- jQuery.post(ajaxurl, { action: "kgvid_delete_video", security: kgflashmediaplayersecurity, movieurl: movieurl, postid: postID, format: format }, function(data) {
289
- //document.getElementById('attachments-'+postID+'-kgflashmediaplayer-encode'+format).checked = true;
290
- //document.getElementById('attachments-'+postID+'-kgflashmediaplayer-encode'+format).disabled = false;
291
- //document.getElementById('attachments-'+postID+'-kgflashmediaplayer-encode').disabled = false;
292
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encode'+format).change();
293
  }, "json" );
294
 
@@ -310,9 +328,9 @@ function kgvid_cancel_thumbs(postID) {
310
  }
311
 
312
  function kgvid_redraw_encode_checkboxes(movieurl, postID, page) {
313
- var kgflashmediaplayersecurity = document.getElementsByName('attachments[kgflashmediaplayer-security]')[0].value;
314
 
315
- var formats = new Array("1080", "720", "mobile", "ogg", "webm");
316
  var kgvid_encode = new Object();
317
  for ( var key in formats ) {
318
  kgvid_encode[formats[key]] = "";
@@ -321,16 +339,25 @@ function kgvid_redraw_encode_checkboxes(movieurl, postID, page) {
321
  }
322
  }
323
  JSON.stringify(kgvid_encode);
324
-
325
  jQuery.post(ajaxurl, { action:"kgvid_generate_encode_checkboxes", security: kgflashmediaplayersecurity, movieurl: movieurl, post_id: postID, page: page, encodeformats: kgvid_encode }, function(data) {
326
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').empty();
327
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').append(data.embed_display);
328
- if ( page == "queue" && data.embed_display.indexOf('Elapsed') >= 0) {
329
  jQuery('tr.currently_encoding').removeClass('currently_encoding');
330
  jQuery('[id^=clear]').css("display", "block");
331
- jQuery('#clear_'+postID).css("display", "none");
332
- jQuery('#tr_'+postID).addClass('currently_encoding');
 
 
333
  }
 
 
 
 
 
 
 
334
  }, "json" );
335
  }
336
 
@@ -355,26 +382,132 @@ function kgvid_encode_queue(action, order) {
355
 
356
  }
357
 
358
- function kgvid_hide_plugin_settings(selected_option) {
359
- if (selected_option == "Video.js") {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  jQuery("table:contains(End of video image)").hide();
361
- jQuery("tr:contains(Watermark)").show();
362
  jQuery("h3:contains(The following options will only affect Flash playback)").hide();
363
- jQuery("tr:contains(Skin Class)").show();
364
  }
365
- if (selected_option == "Strobe Media Playback") {
366
  jQuery("table:contains(End of video image)").show();
367
- jQuery("tr:contains(Watermark)").hide();
368
  jQuery("h3:contains(The following options will only affect Flash playback)").show();
369
- jQuery("tr:contains(Skin Class)").hide();
 
 
 
 
 
 
 
 
 
 
 
370
  }
371
  }
372
 
373
- function kgvid_hide_ffmpeg_settings(video_app) {
 
 
 
374
  if (video_app == "ffmpeg") {
375
  jQuery("tr:contains(FFMPEG Options)").show();
376
  }
377
  if (video_app == "avconv") {
378
  jQuery("tr:contains(FFMPEG Options)").hide();
379
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  }
34
 
35
  function kgvid_generate_thumb(postID, buttonPushed) {
36
 
37
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
38
  var attachmentURL = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-url]')[0].value;
39
  var howmanythumbs = document.getElementById('attachments-'+postID+'-numberofthumbs').value;
40
  var firstframethumb = document.getElementById('attachments-'+postID+'-firstframe').checked;
41
  var posterurl = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-poster]')[0].value;
42
+
43
  var specifictimecode = document.getElementsByName('attachments['+postID+'][thumbtime]')[0].value;
44
  if (specifictimecode === "0") { specifictimecode = "firstframe"; }
45
+ if (specifictimecode != 0 ) { howmanythumbs = 1; }
46
+ if (buttonPushed == "random") { specifictimecode = 0; }
47
+
48
  var thumbnailplaceholderid = "#attachments-"+postID+"-thumbnailplaceholder";
 
 
 
49
  var thumbnailboxID = "#attachments-"+postID+"-kgflashmediaplayer-thumbnailbox";
50
  var thumbnailboxoverlayID = "#attachments-"+postID+"-kgflashmediaplayer-thumbnailboxoverlay";
51
  var cancelthumbdivID = '#attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv';
56
  var i=1;
57
  var increaser = 0;
58
  var iincreaser = 0;
59
+ var page = "attachment";
60
 
61
+ jQuery(thumbnailplaceholderid).empty();
62
+ jQuery(thumbnailplaceholderid).append('<strong>Choose Thumbnail: </strong><div style="display:inline-block;" id="attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv" name="attachments-'+postID+'-kgflashmediaplayer-cancelthumbsdiv"> <input type="button" id="attachments-'+postID+'-kgflashmediaplayer-cancelencode" class="button-secondary" value="Cancel Generating" name="attachments-'+postID+'-cancelencode" onclick="kgvid_cancel_thumbs(\''+postID+'\');"></div><div id="attachments-'+postID+'-kgflashmediaplayer-thumbnailboxoverlay" name="attachments-'+postID+'-kgflashmediaplayer-thumbnailboxoverlay" class="kgvid_thumbnail_overlay"><div name="attachments-'+postID+'-kgflashmediaplayer-thumbnailbox" id="attachments-'+postID+'-kgflashmediaplayer-thumbnailbox" class="kgvid_thumbnail_box"></div></div>');
63
+
64
+ function kgvid_do_post() {
65
+
66
+ iincreaser = i + increaser;
67
+
68
+ jQuery.post(ajaxurl, { action:"kgvid_callffmpeg", security: kgflashmediaplayersecurity, movieurl: attachmentURL, numberofthumbs: howmanythumbs, thumbnumber:i, thumbnumberplusincreaser:iincreaser, ffmpeg_action: 'generate', attachmentID: postID, generate_button: buttonPushed, thumbtimecode: specifictimecode, dofirstframe: firstframethumb, poster: posterurl }, function(data) {
69
+
70
+ kgthumbnailTimeout = jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts") || null;
71
+ jQuery(thumbnailboxID).append(data.thumbnaildisplaycode);
72
+ var thumbnailselectID = "#attachments-"+postID+"-thumb"+i;
73
+ jQuery(thumbnailselectID).css({display:"none"});
74
+ jQuery(thumbnailselectID).animate({opacity: 'toggle', height: 'toggle', width: 'toggle'}, 1000);
75
+ if (data.lastthumbnumber == "break" || (kgthumbnailTimeout == null && i != 1) ) { i = parseInt(howmanythumbs) + 1; }
76
+ else { i = parseInt(data.lastthumbnumber); }
77
+ increaser++;
78
+ if ( i <= howmanythumbs ) {
79
+ if ( kgthumbnailTimeout == null ) { kgthumbnailTimeout = new Array(); }
80
+ kgthumbnailTimeout[i] = setTimeout(function(){
81
+ //jQuery(thumbnailplaceholderid).data("kgthumbnailTimeout", null);
82
+ kgvid_do_post();
83
+ }, 750);
84
+ jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts", kgthumbnailTimeout);
85
+ }
86
+ else {
87
+ jQuery(thumbnailboxoverlayID).fadeTo(2000, 1);
88
+ jQuery(cancelthumbdivID).animate({opacity: 0}, 500);
89
+ jQuery(thumbnailplaceholderid).data("kgthumbnailTimeouts", null);
90
+ }
91
+
92
+ kgvid_aspect = data.movie_height/data.movie_width;
93
+ document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-aspect]')[0].value = kgvid_aspect;
94
+ if (parseInt(data.movie_width) < parseInt(document.getElementsByName(maxwidthID)[0].value) ) { document.getElementById(widthID).value = data.movie_width; }
95
+ else { document.getElementById(widthID).value = document.getElementsByName(maxwidthID)[0].value; }
96
+ if (parseInt(data.movie_width) > parseInt(document.getElementsByName(maxwidthID)[0].value) ) { document.getElementById(heightID).value = Math.round(kgvid_aspect*parseInt(document.getElementsByName(maxwidthID)[0].value)); }
97
+ else { document.getElementById(heightID).value = data.movie_height; }
98
+ jQuery.post( ajaxurl , { action:"kgvid_schedule_cleanup_generated_files", security:kgflashmediaplayersecurity, thumbs:"true" } );
99
+ kgvid_redraw_encode_checkboxes(attachmentURL, postID, page);
100
+
101
+ }, "json");
102
+
103
+ }// end kgvid_do_post function
104
+
105
+ kgvid_do_post(); //actually call the loop
106
+ }
107
+
108
+ function kgvid_enqueue_video_encode(postID) {
109
+
110
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
111
+ var attachmentURL = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-url]')[0].value;
112
+ var parent_post_id = jQuery('#post_ID').val();
113
+ if ( parent_post_id == undefined ) { parent_post_id = jQuery('#post_ID', window.parent.document).val(); }
114
+ var encodeplaceholderid = "#attachments-"+postID+"-encodeplaceholder";
115
+ var encodeprogressplaceholderid = "#attachments-"+postID+"-encodeprogressplaceholder";
116
+
117
  var page = "attachment";
118
  var document_url = document.URL;
119
  var page_check = /[?&]page=([^&]+)/i;
122
  page = "queue";
123
  }
124
 
125
+ var formats = new Array("rotated", "1080", "720", "mobile", "ogg", "webm");
126
  var kgvid_encode = new Object();
127
  for ( var key in formats ) {
128
  kgvid_encode[formats[key]] = "";
131
  }
132
  }
133
  JSON.stringify(kgvid_encode);
134
+
135
+ jQuery(encodeplaceholderid).empty();
136
+ jQuery(encodeprogressplaceholderid).empty();
137
+ jQuery(encodeplaceholderid).append('<strong>Loading...</strong>');
138
+
139
+ jQuery.post(ajaxurl, { action:"kgvid_callffmpeg", security: kgflashmediaplayersecurity, movieurl: attachmentURL, ffmpeg_action: 'enqueue', encodeformats: kgvid_encode, attachmentID: postID, parent_id: parent_post_id, }, function(data) {
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  jQuery(encodeplaceholderid).empty();
142
  jQuery(encodeprogressplaceholderid).empty();
143
+ jQuery(encodeplaceholderid).append(data.embed_display);
144
+ jQuery.post( ajaxurl , { action:"kgvid_ajax_encode_videos", security:kgflashmediaplayersecurity } , function(data) {
145
+ jQuery(encodeprogressplaceholderid).empty();
146
+ jQuery(encodeplaceholderid).append(data.embed_display);
147
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').css('opacity', '0.5');
148
+ kgvid_redraw_encode_checkboxes(attachmentURL, postID, page);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }, "json");
150
+
151
+ }, "json");
 
 
152
  }
153
 
154
  function kgvid_hide_standard_wordpress_display_settings(postID) {
157
  }
158
  }
159
 
160
+ function kgvid_change_singleurl(url, basename, oldbasename) {
161
+
162
+ jQuery('#kgvid-form :input').each(function(){
163
+ var newid = jQuery(this).attr("id").replace(oldbasename, basename);
164
+ jQuery(this).attr("id", newid);
165
+ if ( jQuery(this).attr("name") ) {
166
+ var newname = jQuery(this).attr("name").replace(oldbasename, basename);
167
+ jQuery(this).attr("name", newname);
168
+ }
169
+ });
170
+ jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id", basename);
171
+ document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-encodeboxes').id = 'attachments-'+basename+'-kgflashmediaplayer-encodeboxes';
172
+ document.getElementById('attachments-'+oldbasename+'-thumbnailplaceholder').id = 'attachments-'+basename+'-thumbnailplaceholder';
173
+ jQuery('#attachments-'+basename+'-thumbgenerate').replaceWith('<input type="button" id="attachments-'+basename+'-thumbgenerate" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'generate\');" >');
174
+ jQuery('#attachments-'+basename+'-thumbrandomize').replaceWith('<input type="button" id="attachments-'+basename+'-thumbrandomize" class="button-secondary" value="Randomize" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'random\');" >');
175
+
176
+
177
+ if ( document.getElementById('attachments-'+basename+'-kgflashmediaplayer-ffmpegexists').value == "on" ) {
178
+ document.getElementById('attachments-'+basename+'-thumbgenerate').disabled = false;
179
+ document.getElementById('attachments-'+basename+'-thumbgenerate').title = "";
180
+ document.getElementById('attachments-'+basename+'-thumbrandomize').disabled = false;
181
+ document.getElementById('attachments-'+basename+'-thumbrandomize').title = "";
182
+ //document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').disabled = false;
183
+ document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').title = "Loading...";
184
+
185
+ }
186
+ else {
187
+ document.getElementById('attachments-'+basename+'-thumbgenerate').title = "FFMPEG not found";
188
+ document.getElementById('attachments-'+basename+'-thumbrandomize').title = "FFMPEG not found";
189
+ }
190
+ document.getElementById('insertonlybutton').disabled = false;
191
+ document.getElementById('insertonlybutton').title = "";
192
+
193
+ }
194
+
195
  function kgvid_set_singleurl() {
196
 
197
  var oldbasename = jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id") || "singleurl";
198
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+oldbasename+'][kgflashmediaplayer-security]')[0].value;
199
+ var basename;
200
  var url = document.getElementById('attachments-'+oldbasename+'-kgflashmediaplayer-url').value;
201
  var validExtensions = new Array(".flv", ".f4v", ".mp4", ".mov", ".m4v", ".webm", ".ogg", ".ogv");
202
  var extensionExists = false;
203
+
204
+ if ( url.length > 0 ) {
205
+
206
+ for (var i = 0; i < validExtensions.length; i++) {
207
+ if (url.indexOf(validExtensions[i]) != -1) {
208
+ extensionExists = true;
209
+ jQuery.post(ajaxurl, { action:"kgvid_sanitize_url", security: kgflashmediaplayersecurity, movieurl: url }, function(data) {
210
+ basename = data.singleurl_id;
211
+ url = data.movieurl;
212
+ kgvid_change_singleurl(url, basename, oldbasename);
213
+ jQuery('#attachments-'+basename+'-kgflashmediaplayer-encodeboxes').css('opacity', '0.5');
214
+ kgvid_redraw_encode_checkboxes(url, basename, 'attachment');
215
+ }, "json");
216
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  }
 
 
 
218
  }
219
  }
220
+
221
  if (extensionExists == false) {
222
  if ( url != "" ) { alert("Please enter a URL that points to a valid video file. Video sharing sites are not supported by this plugin.\nTo embed from YouTube, Vimeo, etc, just paste the link directly into the post window and WordPress will handle the rest."); }
223
+ basename = "singleurl";
224
+ kgvid_change_singleurl(url, basename, oldbasename);
225
+ document.getElementById('attachments-'+basename+'-thumbgenerate').disabled = true;
226
+ document.getElementById('attachments-'+basename+'-thumbgenerate').title = "Please enter a valid video URL";
227
+ document.getElementById('attachments-'+basename+'-thumbrandomize').disabled = true;
228
+ document.getElementById('attachments-'+basename+'-thumbrandomize').title = "Please enter a valid video URL";
229
+ document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').disabled = true;
230
+ document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').title = "Please enter a valid video URL";
231
  document.getElementById('insertonlybutton').disabled = true;
232
  document.getElementById('insertonlybutton').title = "Please enter a valid video URL";
 
233
  }
234
+
235
  }
236
 
237
  function kgvid_insert_shortcode() {
238
 
 
239
  var basename = jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id") || "singleurl";
240
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+basename+'][kgflashmediaplayer-security]')[0].value;
241
  var url = document.getElementById('attachments-'+basename+'-kgflashmediaplayer-url').value;
242
  var posterurl = document.getElementById('attachments-'+basename+'-kgflashmediaplayer-poster').value;
243
+ var postid = parent.document.getElementById('post_ID').value
 
 
 
 
 
 
 
 
244
 
245
+ jQuery.post(ajaxurl, { action:'kgvid_callffmpeg', security: kgflashmediaplayersecurity, attachmentID: basename, movieurl: url, ffmpeg_action:'submit', poster: posterurl, parent_id: postid }, function(data) {
246
  //jQuery('attachments-singleurl-thumbnailplaceholder').empty();
247
  }, "json" );
248
 
259
  endtitlecode = endtitlecode.split(' ');
260
  endtitlecode = endtitlecode[0];
261
  if ( endtitlecode.substr(-1,1) != '>' ) { endtitlecode = endtitlecode+'>'; }
262
+ shortcode += titlecode + '<span itemprop="name">' + document.getElementById('videotitle').value + '</span>' + endtitlecode + '<br />';
263
  }
264
  if (url !="") {
265
  shortcode += ' [KGVID';
272
  parent.send_to_editor(shortcode);
273
  }
274
 
275
+ function kgvid_rescan_external_server(movieurl, postID) {
276
 
277
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
278
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-rescanplaceholder').empty();
279
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-rescanplaceholder').append('<strong>Scanning...</strong>');
280
+ jQuery.post(ajaxurl, { action:"kgvid_rescan_external_server", security: kgflashmediaplayersecurity, movieurl:movieurl, postID:postID }, function() {
281
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').css('opacity', '0.5');
282
+ kgvid_redraw_encode_checkboxes(movieurl, postID, 'queue');
283
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-rescanplaceholder').empty();
284
+ });
285
+ }
286
+
287
+ function kgvid_cancel_encode(kgvid_pid, postID, video_key, format) {
288
 
289
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
 
290
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).empty();
291
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).append('<strong>Canceling</strong>');
292
  jQuery.post(ajaxurl, { action:"kgvid_cancel_encode", security: kgflashmediaplayersecurity, kgvid_pid: kgvid_pid, video_key: video_key, format: format } );
293
 
294
  }
295
 
296
+ function kgvid_delete_video(movieurl, postID, format, childID) {
297
 
298
  var delete_for_sure = confirm("You are about to permanently delete the encoded video.\n 'Cancel' to stop, 'OK' to delete.");
299
 
304
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encode').css('display', 'inline');
305
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).empty();
306
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-meta'+format).append('<strong>Deleted</strong>');
307
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
308
 
309
+ jQuery.post(ajaxurl, { action: "kgvid_delete_video", security: kgflashmediaplayersecurity, movieurl: movieurl, postid: postID, format: format, childid: childID }, function(data) {
 
 
 
310
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encode'+format).change();
311
  }, "json" );
312
 
328
  }
329
 
330
  function kgvid_redraw_encode_checkboxes(movieurl, postID, page) {
331
+ var kgflashmediaplayersecurity = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-security]')[0].value;
332
 
333
+ var formats = new Array("rotated", "1080", "720", "mobile", "ogg", "webm");
334
  var kgvid_encode = new Object();
335
  for ( var key in formats ) {
336
  kgvid_encode[formats[key]] = "";
339
  }
340
  }
341
  JSON.stringify(kgvid_encode);
342
+
343
  jQuery.post(ajaxurl, { action:"kgvid_generate_encode_checkboxes", security: kgflashmediaplayersecurity, movieurl: movieurl, post_id: postID, page: page, encodeformats: kgvid_encode }, function(data) {
344
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').empty();
345
  jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').append(data.embed_display);
346
+ if ( page == "queue" ) {
347
  jQuery('tr.currently_encoding').removeClass('currently_encoding');
348
  jQuery('[id^=clear]').css("display", "block");
349
+ if ( data.embed_display.indexOf('Elapsed') >= 0) {
350
+ jQuery('#clear_'+postID).css("display", "none");
351
+ jQuery('#tr_'+postID).addClass('currently_encoding');
352
+ }
353
  }
354
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes').removeAttr('style');
355
+ /* if ( page == "attachment" && data.rotate_complete == true ) {
356
+ var width = jQuery('#attachments-'+postID+'-kgflashmediaplayer-width').val();
357
+ var height = jQuery('#attachments-'+postID+'-kgflashmediaplayer-height').val();
358
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-width').val(height);
359
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-height').val(width);
360
+ } */
361
  }, "json" );
362
  }
363
 
382
 
383
  }
384
 
385
+ function kgvid_save_plugin_settings(input_obj) {
386
+ jQuery('#setting-error-options-reset').fadeOut() //if settings were reset, clear the warning
387
+ var kgflashmediaplayersecurity = document.getElementById("kgvid_settings_security").value;
388
+ var setting_value = input_obj.value;
389
+
390
+ if ( input_obj.type == "checkbox" ) {
391
+ if ( input_obj.checked ) { setting_value = "on"; }
392
+ else { setting_value = false; }
393
+ }
394
+ jQuery('.settings-error').fadeOut(); //clear error messages
395
+ jQuery('.settings-save-status').remove();
396
+ var save_span = '<span class="settings-save-status kgvid_spinner"><span class="spinner" style="display:inline-block;"></span><span class="saved" style="display:none;">Saved.</span></span>';
397
+ if ( jQuery(input_obj).parents(".kgvid_video_app_required").length ) { jQuery(input_obj).parents(".kgvid_video_app_required").append(save_span); }
398
+ else { jQuery(input_obj).parents("td:first").append(save_span); }
399
+
400
+ jQuery.post(ajaxurl, { action:"kgvid_save_settings", security: kgflashmediaplayersecurity, setting: input_obj.id, value: setting_value }, function(data) {
401
+ jQuery(input_obj).val(data.validated_value);
402
+ if ( data.error_message != "" ) { jQuery(input_obj).parents("td:first").append('<div class="error settings-error"><p><strong>'+data.error_message+'</strong></p>'); }
403
+ if ( input_obj.id == "width" || input_obj.id == "height" ) {
404
+ var dimension = "";
405
+ if ( input_obj.id == "height" ) { dimension = parseInt(data.validated_value) + 25; }
406
+ else { dimension = data.validated_value }
407
+ jQuery( '#kgvid_samplevideo' ).attr( input_obj.id, dimension);
408
+ jQuery( '.kgvid_setting_nearvid' ).width( jQuery('#width').val() );
409
+ }
410
+ if ( input_obj.id == "app_path" || input_obj.id == "video_app" ) {
411
+ jQuery('#app_path').data('ffmpeg_exists', data.ffmpeg_exists)
412
+ kgvid_hide_plugin_settings();
413
+ }
414
+ jQuery( '#kgvid_samplevideo' ).attr( 'src', function ( i, val ) { return val; }); //reload the video iframe
415
+ jQuery( '.spinner' ).css('display', 'none');
416
+ jQuery( '.saved').css('display', 'inline-block');
417
+ var save_timeout = jQuery( '#wpbody-content' ).data('saving');
418
+ if ( save_timeout != undefined ) { clearTimeout(save_timeout); }
419
+ save_timeout = setTimeout(function(){ jQuery('.settings-save-status').remove(); jQuery( '#wpbody-content' ).removeData('saving'); },1500);
420
+ jQuery( '#wpbody-content' ).data('saving', save_timeout);
421
+ }, "json" );
422
+ }
423
+
424
+ function kgvid_hide_plugin_settings() {
425
+
426
+ var playback_option = jQuery('#embed_method').val();
427
+ var ffmpeg_exists = jQuery('#app_path').data('ffmpeg_exists');
428
+
429
+ if (playback_option == "Video.js") {
430
  jQuery("table:contains(End of video image)").hide();
 
431
  jQuery("h3:contains(The following options will only affect Flash playback)").hide();
 
432
  }
433
+ if (playback_option == "Strobe Media Playback") {
434
  jQuery("table:contains(End of video image)").show();
 
435
  jQuery("h3:contains(The following options will only affect Flash playback)").show();
436
+ }
437
+
438
+ if ( ffmpeg_exists == "notinstalled" ) {
439
+ jQuery(".kgvid_video_app_required").addClass("kgvid_thumbnail_overlay");
440
+ jQuery(".kgvid_video_app_required").attr('title', 'FFMPEG or LIBAV required for these functions');
441
+ jQuery(".kgvid_video_app_required input").attr('disabled', 'disabled');
442
+
443
+ }
444
+ if ( ffmpeg_exists == "on" ) {
445
+ jQuery(".kgvid_video_app_required").removeClass("kgvid_thumbnail_overlay");
446
+ jQuery(".kgvid_video_app_required input").removeAttr('disabled');
447
+ jQuery(".kgvid_video_app_required").removeAttr('title');
448
  }
449
  }
450
 
451
+ function kgvid_hide_ffmpeg_settings() {
452
+
453
+ var video_app = jQuery('#video_app').val();
454
+
455
  if (video_app == "ffmpeg") {
456
  jQuery("tr:contains(FFMPEG Options)").show();
457
  }
458
  if (video_app == "avconv") {
459
  jQuery("tr:contains(FFMPEG Options)").hide();
460
  }
461
+ }
462
+
463
+ function kgvid_set_all_featured() {
464
+
465
+ var set_for_sure = confirm("You are about to set all existing video thumbnails previously generated by this plugin as the featured images for their posts. There is no 'undo' button, so proceed at your own risk. \n 'Cancel' to stop, 'OK' to proceed.");
466
+
467
+ if ( set_for_sure == true ) {
468
+ var kgflashmediaplayersecurity = document.getElementById("kgvid_settings_security").value;
469
+ jQuery('td:contains(Set all as featured)').append('<div id="set_featured_meter" class="kgvid_meter"><div class="kgvid_meter_bar" style="width:0%;"><div class="kgvid_meter_text"></div></div></div><span id="set_featured_status"> Processing...</span>');
470
+ jQuery.post(ajaxurl, { action: "kgvid_get_set_featured", security: kgflashmediaplayersecurity }, function(count) {
471
+ jQuery.post(ajaxurl, { action: "kgvid_set_featured", security: kgflashmediaplayersecurity });
472
+ var interval = setInterval(function(){kgvid_check_cms_progress(count, 'set_featured')}, 1000);
473
+ jQuery( '#wpbody-content' ).data('set_featured_interval', interval);
474
+ }, "text" );
475
+ }
476
+ }
477
+
478
+ function kgvid_switch_parents() {
479
+
480
+ var new_parent = document.getElementById("thumb_parent").value;
481
+ var old_parent = "video";
482
+ if (new_parent == "video") { old_parent = "post"; }
483
+
484
+ var set_for_sure = confirm("You are about to set all existing video thumbnails previously generated by this plugin as attachments of their "+new_parent+"s rather than their associated "+old_parent+"s. Proceed at your own risk. \n 'Cancel' to stop, 'OK' to proceed.");
485
+
486
+ if ( set_for_sure == true ) {
487
+ var kgflashmediaplayersecurity = document.getElementById("kgvid_settings_security").value;
488
+ jQuery('td:contains(Set all parents)').append('<div id="switching_parents_meter" class="kgvid_meter"><div class="kgvid_meter_bar" style="width:0%;"><div class="kgvid_meter_text"></div></div></div><span id="switching_parents_status"> Processing...</span>');
489
+ jQuery.post(ajaxurl, { action: "kgvid_get_switch_parents", security: kgflashmediaplayersecurity, parent: new_parent }, function(count) {
490
+ jQuery.post(ajaxurl, { action: "kgvid_switch_parents", security: kgflashmediaplayersecurity, parent: new_parent });
491
+ var interval = setInterval(function(){kgvid_check_cms_progress(count, 'switching_parents')}, 1000);
492
+ jQuery( '#wpbody-content' ).data('switching_parents_interval', interval);
493
+ }, "text" );
494
+ }
495
+ }
496
+
497
+ function kgvid_check_cms_progress(total, cms_type) {
498
+ var kgflashmediaplayersecurity = document.getElementById("kgvid_settings_security").value;
499
+ var interval = jQuery( '#wpbody-content' ).data(cms_type+'_interval');
500
+ if ( interval != "" ) {
501
+ jQuery.post(ajaxurl, { action: "kgvid_update_cms_progress", security: kgflashmediaplayersecurity, total: total, cms_type: cms_type }, function(remaining) {
502
+ var percent_done = Math.round(parseInt(total-remaining)/parseInt(total)*100)+'%';
503
+ jQuery('#'+cms_type+'_meter .kgvid_meter_bar').css('width', percent_done);
504
+ jQuery('#'+cms_type+'_meter .kgvid_meter_text').html(total-remaining+'/'+total)
505
+ if ( remaining == 0 ) {
506
+ clearInterval(interval);
507
+ jQuery( '#wpbody-content' ).data(cms_type+'_interval', '');
508
+ jQuery( '#'+cms_type+'_status' ).html(' Complete');
509
+ setTimeout(function(){ jQuery('#'+cms_type+'_meter, #'+cms_type+'_status').fadeOut("normal", function(){ jQuery(this).remove(); }); }, 3000);
510
+ }
511
+ }, "text" );
512
+ }
513
  }
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: kylegilman
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation/
4
  Tags: video, video gallery, html5, shortcode, thumbnail, ffmpeg, libav, embed, mobile, webm, ogg, h.264
5
- Requires at least: 3.5
6
- Tested up to: 3.5.1
7
- Stable tag: 3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -16,67 +16,76 @@ Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted
16
 
17
  The plugin adds several fields to any video uploaded to the WordPress Media Library. Just choose a few options and click Insert into Post and you'll get a shortcode in the post editor that will embed a flexible HTML5/Flash video player with a preview image.
18
 
19
- Version 3.0 of the plugin adds the option to use Video.js instead of Adobe's Strobe Media Playback. Video.js is a lightweight, flexible HTML5 player that uses Flash only if the browser can't find any compatible video formats. The HTML5 player is styled the same in all browsers and is easily customizable. The Strobe Media Playback option 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 unstyled HTML5 video element.
20
 
21
- New in version 3.0 is the ability to create a popup video gallery. The short code uses similar options to the WordPress image gallery shortcode. In its simplest form use the code `[KGVID gallery="true"][/KGVID]` to create a gallery of all videos attached to the post. Thumbnail size and video popup size can be set on the plugin settings page.
22
 
23
- The plugin uses FFMPEG or LIBAV to generate thumbnails and encode HTML5/mobile videos. By default the plugin looks for FFMPEG in `/usr/local/bin` but if the application is installed in a different place on your server, you can point it to the correct place in the plugin settings. Users running WordPress on Windows servers should try using Linux-style paths (with forward slashes instead of backslashes and a forward slash instead of C:\)
24
 
25
- 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 (up to 99 at a time). The unused thumbnails will be deleted after you click "Insert into Post" or "Save Changes."
26
 
27
  In the plugin settings you can set the default maximum width and height based on the dimensions 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 adjusted automatically to match the size and aspect ratio of the video file. You can make further adjustments if you want. After you choose a thumbnail it will be registered in the Wordpress Media Library and added to the post's attachments.
28
 
29
  I highly recommend starting with 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 <a href="http://www.kylegilman.net/2011/02/25/making-mp4-h-264-videos-in-apple-compressor/">a post on my website</a>.
30
 
31
- If you have FFMPEG or LIBAV and the proper libraries installed, you can choose to encode your uploaded video into as many as five additional formats depending on your original source. 1080p, 720p, or up to 480p H.264, WEBM, and OGV. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 480p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox is planning to allow H.264 playback in the future and I no longer recommend encoding OGV or WEBM unless you expect a large number of no-Flash sticklers visiting your site.
32
 
33
- 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. New in version 3.0 is a basic encoding queue available from the Tools menu. You will see encoding progress, the option to cancel an encoding job, and you should get an error message if something goes wrong. Users on Windows servers may get inconsistent results with the encoding queue.
34
 
35
- New in version 3.0, encoded H.264 files will be fixed for streaming using qt-faststart or MP4Box if you have one of them installed in the same directory as your encoder and select it in the plugin settings. Without one of these applications, FFMPEG & LIBAV will place moov atoms at the end of H.264 encoded files, which forces the entire file to download before playback can start and prevents the Flash player from playing them at all.
36
 
37
- If you want to make ogv, webm, or H.264 files available and can't use the FFMPEG encode button, you can upload your own files to the same directory as the original and the plugin will automatically find them. For example, if your main file is awesomevid.mp4, the plugin will look for awesomevid-1080.m4v, awesomevid-720.m4v, awesomevid-ipod.m4v (up to 480p H.264), awesomevid.webm and awesomevid.ogv as well.
38
 
39
  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.
40
 
41
- 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 (if it is, I suggest the excellent "Add From Server" plugin), or maybe it's hosted on another server. Either way, you can use the tab "Embed Video From URL" in the Add Media window. 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.
 
 
 
 
 
 
42
 
43
  = Once you've filled in all your options, click "Insert into Post" and you'll get a shortcode in the visual editor like this =
44
 
45
  `[KGVID poster="http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web_thumb2.jpg"
46
  width="720" height="404"]http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web.mp4[/KGVID]`
47
 
48
- = To embed videos on other sites = turn on the Attachment Template Override in the plugin settings. This will replace your video attachment template with a page that only has enough code to display the video. You can then embed the video using code like this
49
-
50
- `<iframe width="960" height="540" frameborder="0" scrolling="no" src="http://www.kylegilman.net/?attachment_id=1906"></iframe>`
51
-
52
- = If you want to further modify the way the video player works, you can add the following options inside the [FMP] tag. These will override anything you�'ve set in the plugin settings. =
53
 
54
  * `poster="http://www.example.com/image.jpg"` sets the thumbnail.
55
  * `width="xxx"`
56
  * `height="xxx"`
57
- * `controlbar="docked/floating/none"` sets the controlbar position. HTML5 videos only respond to the "none" option.
 
 
58
  * `loop="true/false"`
59
  * `autoplay="true/false"`
 
 
 
 
 
 
60
 
61
  = These options will only affect Video.js playback =
62
 
63
- * `watermark="http://www.example.com/image.png"` sets watermark for video. Overrides default watermark in plugin settings.
64
  * `skin="example-css-class"` Completely change the look of the video player. <a href="https://github.com/zencoder/video-js/blob/master/docs/skins.md">Instructions here.</a>
65
- * `volume="0.5"` Pre-set the volume for unusually loud videos. Value between 0 and 1.
66
 
67
  = These options will only affect Flash playback in Strobe Media Playback video elements. They will have no effect on HTML5 or Video.js playback. =
68
 
69
  * `endofvideooverlay="http://www.example.com/end_image.jpg` sets the image shown when the video ends.
70
  * `autohide="true/false"` specify whether to autohide the control bar after a few seconds.
71
  * `playbutton="true/false"` turns the big play button overlay in the middle of the video on or off.
72
- * `streamtype="live/recorded/DVR"` I honestly dont know what this is for.
73
  * `scalemode="letterbox/none/stretch/zoom"` If the video display size isn’t the same as the video file, this determines how the video will be scaled.
74
  * `backgroundcolor="#rrggbb"` set the background color to whatever hex code you want.
75
  * `configuration="http://www.example.com/config.xml"` Lets you specify all these flashvars in an XML file.
76
  * `skin="http://www.example.com/skin.xml"` Completely change the look of the video player. <a href="http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/14/building-skins">Instructions here.</a>
77
 
78
- = These options are available for video galleries =
79
 
 
80
  * `gallery_thumb="xxx"` width in pixels to display gallery thumbnails
81
  * `gallery_exclude="15"` comma separated video attachment IDs. Excludes the videos from the gallery.
82
  * `gallery_include="65"` comma separated video attachment IDs. Includes only these videos in the gallery. Please note that include and exclude cannot be used together.
@@ -104,7 +113,7 @@ Most of the time your video doesn't play because it's not encoded in the right f
104
 
105
  If you recorded the video using a Samsung Galaxy S II phone, even though most programs will tell you it's H.264 video with AAC audio, there's a good chance that it's actually recorded in 3gp4 format, which won't work with the Flash player. Use MediaInfo Library to get really detailed information about your media files.
106
 
107
- The Strobe Media Playback Flash player will not play mp4/m4v/mov files that don't have the MooV atom at the head of the file. FFMPEG puts the moov atom at the end of the file, so this can be a problem. Version 3.0 of the plugin will fix this problem if you have qt-faststart or MP4Box installed on your server.
108
 
109
  = Why doesn't this work with YouTube? =
110
 
@@ -112,7 +121,7 @@ WordPress already has <a href="http://codex.wordpress.org/Embeds">a built-in sys
112
 
113
  = I'm on shared hosting and can't install software. Does this work without FFMPEG? =
114
 
115
- 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. But 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. Dreamhost is one of the few shared hosts I know of that has FFMPEG installed and available for users.
116
 
117
  = How can I encode videos in directories protected by .htaccess passwords? =
118
 
@@ -127,6 +136,41 @@ Use the "Embed from URL" tab. Use the format http://username:password@yourdomain
127
 
128
  == Changelog ==
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  = 3.1.1 - March 5, 2013 =
131
  * Fixed missing ) in uninstall.php
132
 
2
  Contributors: kylegilman
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation/
4
  Tags: video, video gallery, html5, shortcode, thumbnail, ffmpeg, libav, embed, mobile, webm, ogg, h.264
5
+ Requires at least: 3.2
6
+ Tested up to: 3.6
7
+ Stable tag: 4.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
16
 
17
  The plugin adds several fields to any video uploaded to the WordPress Media Library. Just choose a few options and click Insert into Post and you'll get a shortcode in the post editor that will embed a flexible HTML5/Flash video player with a preview image.
18
 
19
+ The plugin gives you the option to use either the lightweight, flexible Video.js HTML5 player or Adobe's Strobe Media Playback Flash player. The HTML5 player is styled the same in all browsers and is easily customizable. The Strobe Media Playback option 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 the Video.js player as a fallback.
20
 
21
+ You can also use the plugin to create a popup video gallery. The shortcode uses options similar to the WordPress image gallery shortcode. In its simplest form use the code `[KGVID gallery="true"][/KGVID]` to create a gallery of all videos attached to the post. Thumbnail size and video popup size can be set on the plugin settings page.
22
 
23
+ If you have them installed on your server, the plugin can use FFMPEG or LIBAV to generate thumbnails and encode HTML5/mobile videos. By default the plugin looks for FFMPEG in `/usr/local/bin` but if the application is installed in a different place on your server, you can point it to the correct place in the plugin settings. Users running WordPress on Windows servers should try using Linux-style paths (with forward slashes instead of backslashes and a forward slash `/` instead of `C:\`)
24
 
25
+ If FFMPEG or LIBAV is set up correctly, 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 (up to 99 at a time). The unused thumbnails will be deleted after you click "Insert into Post" or "Save Changes."
26
 
27
  In the plugin settings you can set the default maximum width and height based on the dimensions 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 adjusted automatically to match the size and aspect ratio of the video file. You can make further adjustments if you want. After you choose a thumbnail it will be registered in the Wordpress Media Library and added to the post's attachments.
28
 
29
  I highly recommend starting with 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 <a href="http://www.kylegilman.net/2011/02/25/making-mp4-h-264-videos-in-apple-compressor/">a post on my website</a>.
30
 
31
+ If you have FFMPEG or LIBAV and the proper libraries installed, you can choose to encode your uploaded video into as many as five additional formats depending on your original source. 1080p, 720p, or up to 480p H.264, WEBM, and OGV. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 480p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox is planning to allow H.264 playback in the future and I no longer recommend encoding OGV or WEBM unless you expect a large number of no-Flash sticklers visiting your site. However, your mileage may vary.
32
 
33
+ 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. The plugin adds a Video Encode Queue menu to the Tools menu. You will see encoding progress, the option to cancel an encoding job, and you should get an error message if something goes wrong. Users on Windows servers may get inconsistent results with the encoding queue.
34
 
35
+ Encoded H.264 files will be fixed for streaming using qt-faststart or MP4Box if you have one of them installed in the same directory as your encoder and select it in the plugin settings. Without one of these applications, FFMPEG & LIBAV will place moov atoms at the end of H.264 encoded files, which forces the entire file to download before playback can start and prevents the Strobe Media player from playing them at all.
36
 
37
+ If you want to make ogv, webm, or H.264 files available and can't use the FFMPEG encode button, you can upload your own files to the same directory as the original and the plugin will automatically find them. For example, if your main file is awesomevid.mp4, the plugin will look for awesomevid-1080.mp4, awesomevid-720.mp4, awesomevid-480.mp4 (up to 480p H.264), awesomevid.webm and awesomevid.ogv as well.
38
 
39
  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.
40
 
41
+ 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 (if it is, I suggest the excellent "Add From Server" plugin), or maybe it's hosted on another server. Either way, you can use the tab "Embed Video From URL" in the Add Media window. Just enter the Video URL manually, and all other steps are the same as the Media Library options. The plugin will look for alternate encoded files in the same directory as the original, but this takes a long time when the video is on another server so it will only check for them once. If you add additional formats you can click the "Re-scan External Server" button in the meta box below the post you've embedded the video in to check again.
42
+
43
+ =To embed videos on other sites= you can use code like this.
44
+
45
+ <iframe src='http://www.kylegilman.net/?attachment_id=1906&kgvid_video_embed[enable]=true' frameborder='0' scrolling='no' width='640' height='360'></iframe>
46
+
47
+ <iframe width="960" height="540" frameborder="0" scrolling="no" src="http://www.kylegilman.net/?attachment_id=1906"></iframe>
48
 
49
  = Once you've filled in all your options, click "Insert into Post" and you'll get a shortcode in the visual editor like this =
50
 
51
  `[KGVID poster="http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web_thumb2.jpg"
52
  width="720" height="404"]http://www.kylegilman.net/wp-content/uploads/2011/10/Reel-11-10-10-web.mp4[/KGVID]`
53
 
54
+ = If you want to further modify the way the video player works, you can add the following options inside the [KGVID] tag. These will override anything you've set in the plugin settings or attachment details. =
 
 
 
 
55
 
56
  * `poster="http://www.example.com/image.jpg"` sets the thumbnail.
57
  * `width="xxx"`
58
  * `height="xxx"`
59
+ * `align="left/right/center"`
60
+ * `volume="0.x"` pre-sets the volume for unusually loud videos. Value between 0 and 1.
61
+ * `controlbar="docked/floating/none"` sets the controlbar position. Video.js only responds to the "none" option.
62
  * `loop="true/false"`
63
  * `autoplay="true/false"`
64
+ * `watermark="http://www.example.com/image.png"`
65
+ * `title="Video Title"`
66
+ * `embedcode="html code"` changes text displayed in the embed code overlay in order to provide a custom method for embedding a video.
67
+ * `view_count="true/false"` turns the view count on or off.
68
+ * `caption="Caption"`
69
+ * `description="Description"` Used for metadata only.
70
 
71
  = These options will only affect Video.js playback =
72
 
 
73
  * `skin="example-css-class"` Completely change the look of the video player. <a href="https://github.com/zencoder/video-js/blob/master/docs/skins.md">Instructions here.</a>
 
74
 
75
  = These options will only affect Flash playback in Strobe Media Playback video elements. They will have no effect on HTML5 or Video.js playback. =
76
 
77
  * `endofvideooverlay="http://www.example.com/end_image.jpg` sets the image shown when the video ends.
78
  * `autohide="true/false"` specify whether to autohide the control bar after a few seconds.
79
  * `playbutton="true/false"` turns the big play button overlay in the middle of the video on or off.
80
+ * `streamtype="live/recorded/DVR"` I honestly don't know what this is for.
81
  * `scalemode="letterbox/none/stretch/zoom"` If the video display size isn’t the same as the video file, this determines how the video will be scaled.
82
  * `backgroundcolor="#rrggbb"` set the background color to whatever hex code you want.
83
  * `configuration="http://www.example.com/config.xml"` Lets you specify all these flashvars in an XML file.
84
  * `skin="http://www.example.com/skin.xml"` Completely change the look of the video player. <a href="http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/14/building-skins">Instructions here.</a>
85
 
86
+ = These options are available for video galleries (options work the same as standard WordPress image galleries) =
87
 
88
+ * `gallery="true"` turns on the gallery
89
  * `gallery_thumb="xxx"` width in pixels to display gallery thumbnails
90
  * `gallery_exclude="15"` comma separated video attachment IDs. Excludes the videos from the gallery.
91
  * `gallery_include="65"` comma separated video attachment IDs. Includes only these videos in the gallery. Please note that include and exclude cannot be used together.
113
 
114
  If you recorded the video using a Samsung Galaxy S II phone, even though most programs will tell you it's H.264 video with AAC audio, there's a good chance that it's actually recorded in 3gp4 format, which won't work with the Flash player. Use MediaInfo Library to get really detailed information about your media files.
115
 
116
+ The Strobe Media Playback Flash player will not play mp4/m4v/mov files that don't have the MooV atom at the head of the file. FFMPEG puts the moov atom at the end of the file, so this can be a problem. The plugin will fix this problem on newly encoded H.264 videos if you have qt-faststart or MP4Box installed on your server.
117
 
118
  = Why doesn't this work with YouTube? =
119
 
121
 
122
  = I'm on shared hosting and can't install software. Does this work without FFMPEG? =
123
 
124
+ Many of the features of the plugin will work without FFMPEG. You can generate embed shortcodes for your videos on any host because that part of the plugin is JavaScript running in your browser. But without FFMPEG you won't be able to generate thumbnails or encode alternate formats. 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. Dreamhost is one of the few shared hosts I know of that has FFMPEG installed and available for users.
125
 
126
  = How can I encode videos in directories protected by .htaccess passwords? =
127
 
136
 
137
  == Changelog ==
138
 
139
+ = 4.0.1 - April 23, 2013 =
140
+ * Added options to display video title and embed code overlays on video player, and captions and view counts below videos.
141
+ * Added option to filter your theme's video attachment page template to display the video instead of WordPress's default behavior of just showing the title of the video. For backwards compatibility retained old method of completely replacing the video attachment template with a video player.
142
+ * Redesigned settings page to save using AJAX, and added a sample video player so changes are seen immediately.
143
+ * Added iframe method to embed your videos on other websites.
144
+ * Additional video formats encoded by the plugin are now added to the WordPress database as video attachments. To avoid a Russian nesting doll scenario these child attachments do not have the fields for creating thumbnails and encoding additional formats.
145
+ * Changed encoded H.264 extensions from .m4v to .mp4 to increase compatibility with WordPress 3.6's new video capabilities. Existing M4V files will still work.
146
+ * Checks only one time for alternate video sources when videos are embedded from other servers. This should speed up page load times considerably.
147
+ * Added ability to rotate and replace the original file for videos recorded vertically on cell phones.
148
+ * Added post meta box to posts with embedded videos that lists alternate formats found for each video.
149
+ * Added option to set a post's featured image to the most recently generated thumbnail, and a button to set all previously generated thumbnails as featured images.
150
+ * Added option to save generated thumbnails as children of either the video or the post the video is attached to, and a button to convert all thumbnails to the chosen hierarchy.
151
+ * Added option to delete associated thumbnails and additional encoded video formats when original video attachment is deleted.
152
+ * Added backwards compatibility for WordPress versions 3.2 and above.
153
+ * If Strobe Media Playback player is selected, the Video.js player is used in situations where Flash doesn't work (webm, ogg playback) instead of the ugly default browser players.
154
+ * Added watermark, view counts, volume attribute, and Google Analytics event tracking when using Strobe Media Playback player.
155
+ * Added alignment option to center or right-justify videos.
156
+ * Revised video player setup to properly resize the player if the containing DIV is smaller than the video, and resize again if the window size changes (or orientation changes on Android).
157
+ * No matter which player is selected, iOS now displays the built-in controls so AirPlay works.
158
+ * Added schema.org videoobject markup for improved SEO.
159
+ * Fixed FLV embedding with Video.js player and improved selection of embedded formats for Strobe Media Playback.
160
+ * Adjusted video gallery CSS and added a play button overlay to gallery thumbnails.
161
+ * Adjusted watermark and Video.js play button CSS so the overlays don't overwhelm small videos.
162
+ * Set Video.js controls to fade out on autoplay and on iOS, without having to mouseover the video.
163
+ * Fixed endless "loading" spinner shown at the end of videos in some browsers in Video.js player.
164
+ * Clicking "Insert into post" immediately after upload without changing any options now inserts shortcode instead of just the title of the video.
165
+ * Inserting shortcode without a thumbnail no longer attempts to save the nonexistent thumbnail. Thumbnail cleanup is handled better.
166
+ * Fixed error message "array_key_exists() expects parameter 2 to be array" when shortcode didn't have attributes.
167
+ * Escaped all shell commands for increased security.
168
+ * Fixed bug that made "Encode" button disappear if all formats were checked.
169
+ * Fixed missing argument for kgvid_clear_completed_queue() when scheduling cleanup.
170
+
171
+ = 4.0 - April 22, 2013 =
172
+ * Accidental release caused by programmer's incompetence.
173
+
174
  = 3.1.1 - March 5, 2013 =
175
  * Fixed missing ) in uninstall.php
176
 
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: Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG for thumbnails and encodes. <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php">Settings</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation/">Donate</a>
6
- Version: 3.1.1
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
 
@@ -41,9 +41,11 @@ if ( ! defined( 'ABSPATH' ) )
41
  die( "Can't load this file directly" );
42
 
43
  function kgvid_default_options_fn() {
44
- $options = array("version"=>3.1,
 
45
  "embed_method"=>"Video.js",
46
  "template"=>false,
 
47
  "encode_1080"=>"on",
48
  "encode_720"=>"on",
49
  "encode_mobile"=>"on",
@@ -56,9 +58,16 @@ function kgvid_default_options_fn() {
56
  "ffmpeg_vpre"=>false,
57
  "moov"=>"none",
58
  "generate_thumbs"=>4,
 
 
 
59
  "titlecode"=>"<strong>",
60
  "poster"=>"",
61
  "watermark"=>"",
 
 
 
 
62
  "width"=>"640",
63
  "height"=>"360",
64
  "gallery_width"=>"960",
@@ -67,7 +76,7 @@ function kgvid_default_options_fn() {
67
  "controlbar_style"=>"docked",
68
  "autoplay"=>false,
69
  "loop"=>false,
70
- "endOfVideoOverlay"=>"",
71
  "endOfVideoOverlaySame"=>"",
72
  "bgcolor"=>"",
73
  "configuration"=>"",
@@ -75,8 +84,8 @@ function kgvid_default_options_fn() {
75
  "js_skin"=>"kg-video-js-skin",
76
  "stream_type"=>"liveOrRecorded",
77
  "scale_mode"=>"letterbox",
78
- "autohide"=>"true",
79
- "playbutton"=>"true");
80
  return $options;
81
  }
82
 
@@ -93,9 +102,10 @@ register_activation_hook(__FILE__, 'kgvid_register_default_options_fn');
93
  function kgvid_video_formats() {
94
 
95
  $video_formats = array(
96
- "1080" => array("name" => "1080p H.264", "width" => 1920, "height" => 1080, "type" => "h264", "suffix" => "-1080.m4v"),
97
- "720" => array("name" => "720p H.264", "width" => 1280, "height" => 720, "type" => "h264", "suffix" => "-720.m4v"),
98
- "mobile" => array("name" => "480p H.264", "width" => 640, "height" => 480, "type" => "h264", "suffix" => "-ipod.m4v"),
 
99
  "webm" => array("name" => "WEBM", "width" => 0, "height" => 0, "type" => "webm", "suffix" => ".webm"),
100
  "ogg" => array("name" => "OGV", "width" => 0, "height" => 0, "type" => "ogv", "suffix" => ".ogv")
101
  );
@@ -134,27 +144,6 @@ function kgvid_is_empty_dir($dir)
134
  else return false; // whatever the reason is : no such dir, not a dir, not readable
135
  }
136
 
137
- function kgvid_explodeX($delimiters,$string)
138
- {
139
- $return_array = Array($string); // The array to return
140
- $d_count = 0;
141
- while (isset($delimiters[$d_count])) // Loop to loop through all delimiters
142
- {
143
- $new_return_array = Array();
144
- foreach($return_array as $el_to_split) // Explode all returned elements by the next delimiter
145
- {
146
- $put_in_new_return_array = explode($delimiters[$d_count],$el_to_split);
147
- foreach($put_in_new_return_array as $substr) // Put all the exploded elements in array to return
148
- {
149
- $new_return_array[] = $substr;
150
- }
151
- }
152
- $return_array = $new_return_array; // Replace the previous return array by the next version
153
- $d_count++;
154
- }
155
- return $return_array; // Return the exploded elements
156
- }
157
-
158
  function kgvid_rrmdir($dir) {
159
  if (is_dir($dir)) {
160
  $objects = scandir($dir);
@@ -168,16 +157,88 @@ function kgvid_rrmdir($dir) {
168
  }
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  function kgvid_check_ffmpeg_exists($options, $save) {
172
  $exec_enabled = false;
173
  $ffmpeg_exists = false;
174
  $output = array();
 
175
  $uploads = wp_upload_dir();
176
 
177
  if(function_exists('exec')) {
178
- $exec_enabled = true;
179
- exec ( $options['app_path'].'/'.$options['video_app'].' -i '.plugin_dir_path(__FILE__).'/flash/skin/images/PlayNormal.png '.$uploads['path'].'/ffmpeg_exists_test.jpg', $output, $returnvalue );
180
- }
 
 
 
 
 
181
 
182
  if ( $exec_enabled == true && file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //if FFMPEG has executed successfully
183
  $ffmpeg_exists = true;
@@ -191,7 +252,7 @@ function kgvid_check_ffmpeg_exists($options, $save) {
191
  }
192
 
193
  $output_output = implode("/n", $output);
194
- $arr = array ("exec_enabled"=>$exec_enabled, "ffmpeg_exists"=>$ffmpeg_exists, "return_value"=>$returnvalue, "output"=>$output_output);
195
  return $arr;
196
  }
197
 
@@ -200,25 +261,32 @@ function kgvid_encodevideo_info($movieurl, $postID) {
200
  $options = get_option('kgvid_video_embed_options');
201
 
202
  $uploads = wp_upload_dir();
203
- $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
204
- $movieurl_noextension = preg_replace("/\\.[^.\\s]{3,4}$/", "", $movieurl);
205
- $encodevideo_info['moviefilebasename'] = basename($movieurl,'.'.$movie_extension);
206
- $moviefilepath = str_replace(" ", "%20", $movieurl);
207
  $video_formats = kgvid_video_formats();
208
-
209
- if ( is_numeric($postID) ) { //if it's an attachment, not from URL
 
 
 
 
210
  $moviefile = get_attached_file($postID);
211
  $path_parts = pathinfo($moviefile);
212
  $encodevideo_info['encodepath'] = $path_parts['dirname']."/";
213
  $encodevideo_info['sameserver'] = true;
 
 
 
 
 
 
214
  }
215
- else {
 
216
  $url_parts = parse_url($uploads['url']);
217
- if ( strpos($moviefilepath, $url_parts['host']) != false ) { //if we're on the same server
218
  $encodevideo_info['sameserver'] = true;
219
- $filename = urldecode($moviefilepath);
220
- $parsed_url= parse_url($filename);
221
- $fileinfo = pathinfo($filename);
222
  $parsed_url['extension'] = $fileinfo['extension'];
223
  $parsed_url['filename'] = $fileinfo['basename'];
224
  $parsed_url['localpath'] = $_SERVER['DOCUMENT_ROOT'].$parsed_url['path'];
@@ -227,45 +295,99 @@ function kgvid_encodevideo_info($movieurl, $postID) {
227
 
228
  $encodevideo_info['encodepath'] = rtrim($parsed_url['localpath'], $parsed_url['filename']);
229
  }
230
- else {
231
- $encodevideo_info['sameserver'] = false;
232
- $encodevideo_info['encodepath'] = $uploads['basedir']."/html5encodes/";
233
- }
234
- }
 
 
 
 
235
 
236
- if ( !is_writable($encodevideo_info['encodepath']) ) { //if the original directory is not writable use a directory in base wp_upload
237
- $encodevideo_info['encodepath'] = $uploads['basedir']."/html5encodes/";
238
- $encodevideo_info['html5encodes'] = true;
239
- foreach ( $video_formats as $format => $format_stats ) {
240
- $encodevideo_info[$format.'url'] = $uploads['baseurl']."/html5encodes/".$encodevideo_info['moviefilebasename'].$format_stats['suffix'];
241
- }
242
  }
 
243
 
244
  foreach ( $video_formats as $format => $format_stats ) { //loop through each format
245
- $encodevideo_info[$format.'url'] = $movieurl_noextension.$format_stats['suffix'];
246
- $encodevideo_info[$format.'filepath'] = $encodevideo_info['encodepath'].$encodevideo_info['moviefilebasename'].$format_stats['suffix'];
247
- $encodevideo_info[$format.'filepath_html5encodes'] = $uploads['basedir']."/html5encodes/".$encodevideo_info['moviefilebasename'].$format_stats['suffix'];
248
-
249
- if ( file_exists($encodevideo_info[$format.'filepath']) ) { $encodevideo_info[$format.'_exists'] = true; }
250
- else {
251
- if ( file_exists($encodevideo_info[$format.'filepath_html5encodes']) ) {
252
- $encodevideo_info[$format.'filepath'] = $encodevideo_info[$format.'filepath_html5encodes'];
253
- $encodevideo_info[$format.'_exists'] = true;
254
- }
255
- else { $encodevideo_info[$format.'_exists'] = false; }
256
- }
257
 
258
- if ( !$encodevideo_info['sameserver'] ) { //last resort if it's not on the same server, check url_exists
259
- if ( !file_exists($encodevideo_info[$format.'filepath']) ) {
260
- if ( kgvid_url_exists($movieurl_noextension.$format_stats['suffix']) ) {
 
 
 
 
 
 
 
 
 
 
 
261
  $encodevideo_info[$format.'_exists'] = true;
262
- $encodevideo_info[$format.'url'] = $movieurl_noextension.$format_stats['suffix']; ;
 
263
  }
264
- else { $encodevideo_info[$format.'_exists'] = false; }
265
  }
266
  }
267
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  return $encodevideo_info;
270
  }
271
 
@@ -282,8 +404,8 @@ function kgvid_get_video_dimensions($video = false) {
282
 
283
  $video = str_replace("https://", "http://", $video);
284
 
285
- $command = $ffmpegPath . ' -i "' . $video . '" 2>&1';
286
-
287
  exec ( $command, $output );
288
  $lastline = end($output);
289
  $lastline = prev($output)."<br />".$lastline;
@@ -297,11 +419,24 @@ function kgvid_get_video_dimensions($video = false) {
297
  $height = $vals [1] ? $vals [1] : null;
298
  preg_match('/Duration: (.*?),/', $output, $matches);
299
  $duration = $matches[1];
 
 
 
 
 
300
  preg_match('/rotate : (.*?)\n/', $output, $matches);
301
  if ( array_key_exists(1, $matches) == true ) { $rotate = $matches[1]; }
302
  else $rotate = "0";
303
 
304
- $command = $ffmpegPath . ' -i "' . $video . '" -codecs 2>&1';
 
 
 
 
 
 
 
 
305
  exec ( $command, $output );
306
  $output = implode("\n", $output);
307
  $configuration = array();
@@ -310,7 +445,8 @@ function kgvid_get_video_dimensions($video = false) {
310
  if ( strpos($output, $lib) !== false ) { $configuration[$lib] = "true"; }
311
  else { $configuration[$lib] = "false"; }
312
  }
313
- return array ('width' => $width, 'height' => $height, 'duration' => $duration, 'configuration' => $configuration, 'rotate' => $rotate, 'worked'=>true );
 
314
  } else {
315
  return array ('output'=>$lastline, 'worked'=>false);
316
  }
@@ -382,24 +518,29 @@ function kgvid_video_embed_enqueue_scripts() {
382
  wp_enqueue_script( 'swfobject' );
383
  }
384
 
385
- if ( $options['embed_method'] == "Video.js" ) {
386
- wp_enqueue_script( 'video-js', plugins_url("", __FILE__).'/video-js/video.js' );
387
- wp_enqueue_style( 'video-js-css', plugins_url("", __FILE__).'/video-js/video-js.css' );
388
- wp_enqueue_style( 'video-js-kg-skin', plugins_url("", __FILE__).'/video-js/kg-video-js-skin.css' );
389
- }
390
-
391
- wp_enqueue_style( 'kgvid_video_gallery', plugins_url("", __FILE__).'/css/kgvid_styles.css' );
392
  wp_enqueue_script( 'jquery-ui-dialog' );
393
- wp_enqueue_script( 'kgvid_video_embed', plugins_url("", __FILE__).'/js/kgvid_video_embed.js' );
394
  wp_localize_script( 'kgvid_video_embed', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
395
  }
396
- add_action('wp_enqueue_scripts', 'kgvid_video_embed_enqueue_scripts');
397
 
398
- function kgvid_video_embed_print_scripts() {
399
 
400
- $options = get_option('kgvid_video_embed_options');
 
 
 
 
401
 
402
- if ( $options['embed_method'] == "Video.js" ) { echo '<script type="text/javascript">_V_.options.flash.swf = "'.plugins_url("", __FILE__).'/video-js/video-js.swf"</script>'."\n"; }
 
 
403
 
404
  }
405
  add_action('wp_head', 'kgvid_video_embed_print_scripts');
@@ -408,14 +549,13 @@ add_action('wp_head', 'kgvid_video_embed_print_scripts');
408
  function KGVID_shortcode($atts, $content = ''){
409
 
410
  $options = get_option('kgvid_video_embed_options');
411
- $post_ID = get_the_ID();
412
-
413
- // workaround for relative video URL (contributed by Lee Fernandes)
414
- if(substr($content, 0, 1) == '/') $content = get_bloginfo('url').$content;
415
 
416
  $query_atts = shortcode_atts(
417
  array('width' => $options['width'],
418
  'height' => $options['height'],
 
419
  'controlbar' => $options['controlbar_style'],
420
  'autohide' => $options['autohide'],
421
  'poster' => $options['poster'],
@@ -437,194 +577,289 @@ function KGVID_shortcode($atts, $content = ''){
437
  'gallery_exclude' => '',
438
  'gallery_include' => '',
439
  'gallery_id' => $post_ID,
440
- 'volume' => ''
 
 
 
 
 
441
  ), $atts);
442
 
443
- if ( $query_atts["loop"] == "on" ) { $query_atts["loop"] = "true"; }
444
- if ( $query_atts["autoplay"] == "on" ) { $query_atts["autoplay"] = "true"; }
 
 
 
 
 
 
 
 
445
 
446
- if ( $query_atts["gallery"] != "true" ) {
447
 
 
 
448
  $content = trim($content);
449
 
450
  global $wpdb;
451
- $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='{$content}'";
452
  $id = $wpdb->get_var($query);
 
453
  $moviefiletype = pathinfo($content, PATHINFO_EXTENSION);
 
 
 
 
 
 
 
 
 
 
454
  $flashcompatible = array("flv", "f4v", "mp4", "mov", "m4v");
455
  $h264compatible = array("mp4", "mov", "m4v");
456
- $div_suffix = substr(uniqid(rand(), true),0,4);
457
 
458
- if ($id != "") {
459
  $div_suffix = $id;
460
  $encodevideo_info = kgvid_encodevideo_info($content, $id);
461
  $attachment_info = get_post( $id );
462
- }
463
- else { $encodevideo_info = kgvid_encodevideo_info($content, 'singleurl'); }
464
-
465
- if ( $options['embed_method'] == "Strobe Media Playback" ) {
466
-
467
- $video_swf = plugins_url('', __FILE__)."/flash/StrobeMediaPlayback.swf";
468
- $minimum_flash = "10.1.0";
469
 
470
- if ( in_array($moviefiletype, $flashcompatible) ) { $flashvars = "{src:'".urlencode($content)."'"; }
471
- else { $flashvars = "{src:'".urlencode(trim($encodevideo_info['mobileurl']))."'"; }
472
-
473
- if($query_atts["poster"] != '') {
474
- $flashvars .= ", poster:'".urlencode(trim($query_atts["poster"]))."'";
475
- }
476
- if($query_atts["endOfVideoOverlaySame"] == "true") { $query_atts["endOfVideoOverlay"] = $query_atts["poster"]; }
477
- if($query_atts["endOfVideoOverlay"] != '') {
478
- $flashvars .= ", endOfVideoOverlay:'".urlencode(trim($query_atts["endOfVideoOverlay"]))."'";
479
- }
480
- if($query_atts["controlbar"] != '') {
481
- $flashvars .= ", controlBarMode:'".$query_atts["controlbar"]."'";
482
- }
483
- if($query_atts["autohide"] != '') {
484
- $flashvars .= ", controlBarAutoHide:'".$query_atts["autohide"]."'";
485
- }
486
- if($query_atts["playbutton"] != '') {
487
- $flashvars .= ", playButtonOverlay:'".$query_atts["playbutton"]."'";
488
- }
489
- if($query_atts["loop"] != '') {
490
- $flashvars .= ", loop:'".$query_atts["loop"]."'";
491
- }
492
- if($query_atts["autoplay"] != '') {
493
- $flashvars .= ", autoPlay:'".$query_atts["autoplay"]."'";
494
  }
495
- if($query_atts["streamtype"] != '') {
496
- $flashvars .= ", streamType:'".$query_atts["streamtype"]."'";
 
 
 
 
497
  }
498
- if($query_atts["scalemode"] != '') {
499
- $flashvars .= ", scaleMode:'".$query_atts["scalemode"]."'";
 
 
 
 
 
 
 
500
  }
501
- if($query_atts["backgroundcolor"] != '') {
502
- $flashvars .= ", backgroundColor:'".$query_atts["backgroundcolor"]."'";
503
- }
504
- if($query_atts["configuration"] != '') {
505
- $flashvars .= ", configuration:'".urlencode($query_atts["configuration"])."'";
506
  }
507
- if($query_atts["skin"] != '') {
508
- $flashvars .= ", skin:'".urlencode($query_atts["skin"])."'";
509
- }
510
- $flashvars .= ", verbose:'true'";
511
- $flashvars .= "}";
512
-
513
- $params = "{wmode:'opaque', allowfullscreen:'true', allowscriptaccess:'always', base:'".plugins_url("", __FILE__)."/flash/'}";
514
- } //if Strobe Media Playback
515
 
516
- if ( in_array($moviefiletype, $h264compatible) ) {
517
  $encodevideo_info["original_exists"] = true;
518
  $encodevideo_info["originalurl"] = $content;
519
  }
520
  else { $encodevideo_info["original_exists"] = false; }
521
 
522
- $video_formats = array(
523
- "original" => "mp4",
524
- "1080" => "mp4",
525
- "720" => "mp4",
526
- "mobile" => "mp4",
527
- "webm" => "webm",
528
- "ogg" => "ogg"
529
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
 
531
- $sources = "";
532
  foreach ($video_formats as $name => $type) {
533
- if ( $encodevideo_info[$name."_exists"] ) { $sources .= "<source id='video_".$div_suffix."_src_".$name."' src='".$encodevideo_info[$name."url"]."' type='video/".$type."'>\n";
534
- if ( $type == "mp4" ) { $mp4_srcs["src_".$name] = $encodevideo_info[$name."url"]; }
535
  }
536
  }
537
 
 
 
 
 
 
 
 
538
  $code = "";
539
 
540
- $code .= "<div id=\"video_".$div_suffix."_div\" class=\"kgvid_videodiv\">";
 
 
 
 
 
 
 
 
 
 
 
 
541
  $code .= "<video id=\"video_".$div_suffix."\" ";
542
- if ($query_atts["loop"] == 'true') { $code .= "loop " ;}
543
- if ($query_atts["autoplay"] == 'true') { $code .= "autoplay " ;}
544
- if ($query_atts["controlbar"] != 'none') { $code .= "controls " ;}
545
  $code .= "preload='metadata' ";
546
- if($query_atts["poster"] != '' ) { $code .= "poster='".$query_atts["poster"]."' "; }
547
  $code .= "width='".$query_atts["width"]."' height='".$query_atts["height"]."'";
548
- if ( $options['embed_method'] == "Video.js" ) {
549
- if ( $options['js_skin'] == "" ) { $options['js_skin'] = "vjs-default-skin"; }
550
- if ( array_key_exists('skin', $atts) ) { $options['js_skin'] = $atts['skin']; } //allows user to set skin for individual videos using the same skin="" attribute
551
- $code .= " class='video-js ".$options['js_skin']."' data-setup='{}'";
552
- }
553
- else { }
554
  $code .= ">\n";
555
 
556
- $code .= $sources; //add the <source> tags created earlier
557
-
558
- if ( !in_array($moviefiletype, $flashcompatible) && $encodevideo_info["mobile_exists"] && $options['embed_method'] == "Strobe Media Playback" ) { // Flash fallback if WEBM/OGV embed
559
- $flashvars_remove = array("{", "}", "'");
560
- $flashvars_reformat = str_replace($flashvars_remove, "", $flashvars);
561
- $flashvars_reformat = str_replace(":", "=", $flashvars_reformat);
562
- $flashvars_reformat = str_replace(", ", "&", $flashvars_reformat);
563
- $code .= '<object width="'.trim($query_atts["width"]).'" height="'.trim($query_atts["height"]).'" type="application/x-shockwave-flash" data="'.$video_swf.'">'."\n";
564
- $code .= '<param name="movie" value="'.$video_swf.'" /></param>'."\n";
565
- $code .= '<param name="flashvars" value="'.$flashvars_reformat.'" /></param>'."\n";
566
- $code .= '<param name="base" value="'.plugins_url('', __FILE__).'/flash/" /></param>'."\n";
567
- $code .= '<param name="allowFullScreen" value="true" /></param>'."\n";
568
- $code .= '<param name="allowscriptaccess" value="always" /></param>'."\n";
569
- $code .= '</object>';
570
- }
571
  $code .= "</video>\n";
572
- $code .= "</div>\n\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
573
 
574
- if ( $options['embed_method'] == "Video.js" ) {
575
- if ($id != "") {
576
- $plays = intval(get_post_meta($id, "_kgflashmediaplayer-starts", true));
577
- $ends = intval(get_post_meta($id, "_kgflashmediaplayer-completeviews", true));
 
578
  }
579
- else {
580
- $plays = "not_countable";
581
- $ends = "not_countable";
 
 
582
  }
583
- $aspect_ratio = round($query_atts["height"] / $query_atts["width"], 3);
 
 
 
 
 
 
 
584
 
585
- $code .= "<script type='text/javascript'>
586
- _V_('video_".$div_suffix."').ready(function(){";
587
- if ( !empty($query_atts["watermark"]) ) { $code .= "\n\t\t\t"."jQuery('#video_".$div_suffix."').prepend(\"<div class='kgvid_watermark'><img src='".$query_atts["watermark"]."'></div>\");"."\n\t\t\t"; }
588
- $code .= "var width = document.getElementById(this.id).parentElement.offsetWidth;
589
- if ( width < ".$query_atts["width"]." ) { this.width(width).height( Math.round(width * ".$aspect_ratio.") ); }";
590
- if ( !empty($query_atts["volume"]) ) { $code .= "\n\t\t\t"."this.volume(".$query_atts['volume'].");"."\n\t\t\t"; }
591
- $code .= "this.addEvent('play', function(){
592
- kgvid_video_counter('".$div_suffix."', '".$plays."', '".$ends."', 'play');
593
- if (typeof _gaq != 'undefined') { _gaq.push(['_trackEvent', 'Videos', 'Play Start', '".get_the_title($id)."']); }
 
 
 
594
  });
595
- this.addEvent('ended', function(){
596
- kgvid_video_counter('".$div_suffix."', '".$plays."', '".$ends."', 'ended');
597
- if (typeof _gaq != 'undefined') { _gaq.push(['_trackEvent', 'Videos', 'Complete View', '".get_the_title($id)."']); }
598
  });
599
- });
600
- </script>\n";
601
  }
602
-
603
- /* if ($id !="") {
604
- $iframeurl = site_url('/')."?attachment_id=".$id;
605
- $iframecode = '<iframe src="'.$iframeurl.'" frameborder="0" scrolling="no" width="'.$query_atts['width'].'" height="'.$query_atts["height"].'"></iframe>';
606
- $code .= "<div class='kgvid_embed_code' type='text' value='".$iframecode."' width='10' onClick='this.select();'></div>\n";
607
- if ( !empty($attachment_info->post_excerpt) ) { $code .= '<p class="wp-caption-text">'.$attachment_info->post_excerpt.'</p></div>'; }
608
- } */
609
-
610
- if ( in_array($moviefiletype, $flashcompatible) && $options['embed_method'] == "Strobe Media Playback" ) {
611
- $code .= "<script type=\"text/javascript\">\n\t";
612
- $code .= "swfobject.embedSWF('".$video_swf."', 'video_".$div_suffix."_div', '".trim($query_atts['width'])."', '".trim($query_atts['height'])."', '".$minimum_flash."', '".plugins_url("", __FILE__)."/flash/expressInstall.swf', $flashvars, $params)\n";
613
- $code .= "</script>\n";
614
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
615
 
616
  } //if not gallery
617
 
618
  else { //if gallery
 
619
  $code = "";
620
- $args = array( 'post_type' => 'attachment', 'orderby' => $query_atts['gallery_orderby'], 'order' => $query_atts['gallery_order'], 'post_mime_type' => 'video', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post_ID, 'exclude' => $query_atts['gallery_exclude'] );
 
 
 
 
 
 
 
 
 
621
  if ( !empty($query_atts['gallery_include']) ) { $args['include'] = $query_atts['gallery_include']; }
622
  $attachments = get_posts($args);
623
  if ($attachments) {
 
 
 
624
  foreach ( $attachments as $attachment ) {
625
  $thumbnail_url = get_post_meta($attachment->ID, "_kgflashmediaplayer-poster", true);
626
- if (!$thumbnail_url) { $thumbnail_url = $options['poster']; }
627
- if (!$thumbnail_url) { $thumbnail_url = plugins_url('/images/nothumbnail.jpg', __FILE__);}
 
 
 
 
 
 
 
 
 
628
 
629
  $video_width = get_post_meta($attachment->ID, "_kgflashmediaplayer-actualwidth", true);
630
  if ( !$video_width ) { $video_width = get_post_meta($attachment->ID, "_kgflashmediaplayer-width", true); }
@@ -634,12 +869,20 @@ function KGVID_shortcode($atts, $content = ''){
634
  if ( !$video_height ) { $video_height = get_post_meta($attachment->ID, "_kgflashmediaplayer-height", true); }
635
  if ( !$video_height || $video_height > intval($options['gallery_height']) ) { $video_height = $options['gallery_height']; }
636
 
637
- $code .= '<div class="kgvid_video_gallery_thumb" style="width:'.$query_atts["gallery_thumb"].'px"><a href="#" onclick="javascript:kgvid_SetVideo(\''.site_url('/').'?attachment_id='.$attachment->ID.'&kgvid_video_embed[gallery]=true&kgvid_video_embed[width]='.$video_width.'&kgvid_video_embed[height]='.$video_height.'\', \''.$video_width.'\', \''.$video_height.'\');return false;"><img src="'.$thumbnail_url.'"></a><span class="videotitle">'.$attachment->post_title.'</span></div>';
 
 
 
 
 
 
638
  }
639
- $code .= '<div id="kgvid_GalleryPlayerDiv"><iframe id="kgvid_GalleryVideo" src="" width="640" height="360" frameborder="0" webkitallowfullscreen="" allowfullscreen=""></iframe></div>';
 
 
640
  $code .= '<script type="text/javascript">jQuery(document).ready(function() {
641
- jQuery(\'#kgvid_GalleryPlayerDiv\').dialog({
642
- zIndex: 10000,
643
  autoOpen: false,
644
  modal: true,
645
  resizable: false,
@@ -651,13 +894,13 @@ function KGVID_shortcode($atts, $content = ''){
651
  jQuery(\'.ui-widget-overlay\').wrap(\'<div class="kgvid_gallery" />\');
652
  },
653
  close: function(event, ui){
 
654
  jQuery(".kgvid_gallery").filter(function(){
655
  if (jQuery(this).text() == "") { return true; }
656
  return false;
657
  }).remove();
658
  }
659
  });
660
- jQuery(\'#kgvid_GalleryPlayerDiv\').bind("dialogclose", function (event, ui) { jQuery(\'#kgvid_GalleryVideo\').attr(\'src\', \'\'); });
661
  }); </script>';
662
 
663
  } //if there are attachments
@@ -705,21 +948,23 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
705
  $post_mime_type = "";
706
  $actualwidth = "1921";
707
  $actualheight = "1081";
 
708
  $encodevideo_info = array();
709
 
710
  if ( !empty($movieurl) ) {
 
711
  $encodevideo_info = kgvid_encodevideo_info($movieurl, $post_id);
712
-
713
- if ( is_numeric($post_id) ) {
 
714
  $post_mime_type = get_post_mime_type($post_id);
715
- if ( $post_mime_type == "video/m4v" || $post_mime_type == "video/quicktime" ) { $post_mime_type = "video/mp4"; }
716
  $actualwidth = get_post_meta($post_id, "_kgflashmediaplayer-actualwidth", true);
717
  $actualheight = get_post_meta($post_id, "_kgflashmediaplayer-actualheight", true);
 
718
  }
719
- else {
720
 
721
- $post_mime_type = pathinfo($movieurl, PATHINFO_EXTENSION);
722
- if ( $post_mime_type == "m4v" || $post_mime_type == "mov" ) { $post_mime_type = "mp4"; }
723
 
724
  if ( !empty($video_embed_queue) ) {
725
  foreach ($video_embed_queue as $video_key => $video_entry) {
@@ -727,6 +972,7 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
727
  if ( array_key_exists('movie_info', $video_entry) ) {
728
  $actualwidth = $video_entry['movie_info']['width'];
729
  $actualheight = $video_entry['movie_info']['height'];
 
730
  }
731
  break;
732
  }
@@ -735,10 +981,11 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
735
  reset($video_embed_queue);
736
 
737
  if ( $page == "queue" ) {
738
- $info = pathinfo($movieurl);
739
- $post_id = 'singleurl_'.basename($movieurl,'.'.$info['extension']);
740
  }
741
  }
 
742
  }
743
  else {
744
  $encode_disabled = ' disabled title="Please enter a valid video URL"';
@@ -750,31 +997,39 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
750
  else { $ffmpeg_disabled_text = ""; }
751
 
752
  $video_key = false;
753
-
754
  if ( !empty($video_embed_queue) && !empty($movieurl) ) {
755
  foreach ($video_embed_queue as $video_key => $video_entry) {
756
  if ( $video_entry['movieurl'] == $movieurl ) {
757
  foreach ( $video_entry['encode_formats'] as $format => $value ) {
758
  $video_formats[$format]['status'] = $value['status'];
 
 
 
759
  }
760
  $video_queued = true;
761
  break;
762
  }
763
  }
764
  }
 
 
 
765
  $checkboxes = '<div id="attachments-'.$post_id.'-kgflashmediaplayer-encodeboxes">';
766
  foreach ( $video_formats as $format => $format_stats ) {
 
767
  $encodeset[$format] = "";
768
  $checked[$format] = "";
769
  $meta[$format] = "";
770
  $disabled[$format] = "";
 
771
 
772
  if ( !array_key_exists('status', $format_stats) ) { $format_stats['status'] = "notchecked"; } //if this video isn't in the queue
773
 
774
- if ( is_numeric($post_id) ) { $encodeset[$format] = get_post_meta($post_id, "_kgflashmediaplayer-encode".$format, true); }
775
- if ( $encodeset[$format] == "" ) { $encodeset[$format] = $options['encode_'.$format]; }
776
-
777
- if ( $format_stats['status'] == "lowres" || $actualheight != "" && ($format == "1080" || $format == "720") && ( (strpos($post_mime_type, "mp4") && $actualheight <= $format_stats['height']) || (!strpos($post_mime_type, "mp4") && $actualheight < $format_stats['height']) ) ) { continue; } //if the format is bigger than the original video, skip the checkbox
778
 
779
  if ( $encodeset[$format] == "on" || $format_stats['status'] == "queued" ) { $checked[$format] = 'checked'; }
780
 
@@ -784,27 +1039,36 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
784
  $meta[$format] .= ': <span style="color:red;">'.$video_embed_queue[$video_key]['encode_formats'][$format]['lastline']."</span>";
785
  }
786
  }
787
-
788
  if ( !empty($encodevideo_info) ) {
789
  if ( $encodevideo_info[$format.'_exists'] ) { //if the video file exists
790
  if ( $format_stats['status'] != "encoding" ) { // not currently encoding
791
  if ( $format_stats['status'] == "notchecked" ) { $meta[$format] = ' <strong>Encoded</strong>'; }
792
- if ( $format_stats['status'] != "canceling" ) { $meta[$format] .= '<a id="delete-'.$post_id.'-'.$format.'" class="kgvid_delete-format" onclick="kgvid_delete_video(\''.$movieurl.'\', \''.$post_id.'\', \''.$format.'\');" href="javascript:void(0)">Delete Permanently</a>'; }
 
 
 
793
  $disabled[$format] = ' disabled title="Format already exists"';
794
  $checked[$format] = '';
795
- }
796
- if ( $format_stats['status'] == "encoding" ) {
797
- $encoding_now = true;
798
- $disabled[$format] = ' disabled title="Currently Encoding"';
799
- $checked[$format] = 'checked';
800
- $progress = kgvid_encode_progress($video_key, $format, $page);
801
- $meta[$format] = $progress['embed_display'];
802
- }
803
-
804
  }
 
805
  }
806
 
807
- if ( $checked[$format] == "" ) { $something_to_encode = true; }
 
 
 
 
 
 
 
 
 
 
 
 
 
808
 
809
  $checkboxes .= "\n\t\t\t".'<input type="checkbox" id="attachments-'.$post_id.'-kgflashmediaplayer-encode'.$format.'" name="attachments['.$post_id.'][kgflashmediaplayer-encode'.$format.']" '.$checked[$format].' '.$ffmpeg_disabled_text.$disabled[$format].'> <label for="attachments-'.$post_id.'-kgflashmediaplayer-encode'.$format.'">'.$format_stats['name'].'</label> <span id="attachments-'.$post_id.'-kgflashmediaplayer-meta'.$format.'">'.$meta[$format].'</span><br />';
810
 
@@ -813,10 +1077,13 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page) {
813
  $encode_disabled = ' disabled title="Nothing to encode" style="display:none;"';
814
  }
815
 
816
- if ( $page == "queue" ) { $button_text = "Update"; }
 
 
 
817
  else { $button_text = "Encode"; }
818
 
819
- $checkboxes .= '<input type="button" id="attachments-'.$post_id.'-kgflashmediaplayer-encode" name="attachments['.$post_id.'][kgflashmediaplayer-encode]" class="button-secondary" value="'.$button_text.'" onclick="kgvid_generate_thumb(\''.$post_id.'\', \'enqueue\');" '.$ffmpeg_disabled_text.$encode_disabled.'/><div style="display:block;" id="attachments-'.$post_id.'-encodeplaceholder"></div>';
820
 
821
  if ( $page != "queue" ) {
822
  $checkboxes .= '<small><em>Generates additional video formats compatible with most mobile & HTML5-compatible browsers.</em></small>';
@@ -861,14 +1128,14 @@ function kgvid_generate_queue_table() {
861
  }
862
  else { $currently_encoding[$order] = false; }
863
  }
864
- $html .= "><input type='hidden' name='attachments[kgflashmediaplayer-security]' value='".$nonce."' />";
865
  $html .= "<td id='td_".$video_entry['attachmentID']."'>".strval(intval($order)+1)."</td>\n";
866
  $thumbnail_url = get_post_meta($video_entry['attachmentID'], "_kgflashmediaplayer-poster", true);
867
  $thumbnail_html = "";
868
  if ($thumbnail_url != "" ) {
869
  $thumbnail_html = '<img width="100" src="'.$thumbnail_url.'">';
870
  }
871
- if ( is_numeric($video_entry['attachmentID']) ) {
872
  $moviefilepath = get_attached_file($video_entry['attachmentID']);
873
  $attachmentlink = "media.php?attachment_id=".$video_entry['attachmentID']."&action=edit";
874
  }
@@ -877,8 +1144,9 @@ function kgvid_generate_queue_table() {
877
  $attachmentlink = $video_entry['movieurl'];
878
  }
879
  $html .= "\t\t\t\t\t<td><a href='".$attachmentlink."'> ".$thumbnail_html."</a></td>\n";
880
- $html .= "\t\t\t\t\t<td><a id='".$moviefilepath."' href='".$attachmentlink."'>".basename($moviefilepath)."</a><input type='hidden' name='attachments[".$video_entry['attachmentID']."][kgflashmediaplayer-url]' value='".$video_entry['movieurl']."'></td>\n";
881
  $html .= "\t\t\t\t\t<td class='queue_encode_formats' id='formats_".$video_entry['attachmentID']."'>";
 
882
  $html .= kgvid_generate_encode_checkboxes($video_entry['movieurl'], $video_entry['attachmentID'], 'queue');
883
  $html .= "</td>\n";
884
  $html .= "\t\t\t\t\t<td>";
@@ -906,44 +1174,6 @@ function kgvid_FFMPEG_Queue_Page() {
906
 
907
  ?>
908
  <div class="wrap">
909
- <script>
910
- jQuery(function() {
911
- jQuery( "#sortable tbody.rows" ).sortable({
912
- items: "tr:not(.currently_encoding)",
913
- containment: "parent",
914
- opacity: 0.6,
915
- helper: function(e, tr) {
916
- var $originals = tr.children();
917
- var $helper = tr.clone();
918
- $helper.children().each(function(index)
919
- {
920
- // Set helper cell sizes to match the original sizes
921
- jQuery(this).width($originals.eq(index).width())
922
- });
923
- return $helper;
924
- }
925
- });
926
- jQuery( "#sortable tbody.rows" ).disableSelection();
927
- jQuery( "#sortable tbody.rows" ).bind("sortupdate", function(event, ui) {
928
- jQuery('table tr').each(function(){
929
- var $new_index = jQuery(this).index();
930
- var $new_ID = "tr_" + $new_index;
931
- jQuery(this).children('td:first-child').html($new_index);
932
- jQuery(this).attr("id", $new_ID);
933
- if ( $new_index == 0 ) { jQuery(this).addClass("currently_encoding"); }
934
- else { jQuery(this).removeClass("currently_encoding"); }
935
- })
936
- });
937
- });
938
-
939
- jQuery("#sortable .submitdelete").live("click", function (e) {
940
- jQuery(this).closest("tr").fadeOut("slow", function(){ jQuery(this).remove(); });
941
- jQuery("#sortable tbody.rows").trigger("sortupdate");
942
- });
943
-
944
-
945
-
946
- </script>
947
  <div id="icon-tools" class="icon32"><br /></div>
948
  <h2>Video Embed & Thumbnail Generator Encoding Queue</h2>
949
  <p></p>
@@ -986,27 +1216,31 @@ function kgvid_addFMPOptionsPage() {
986
  add_action('admin_menu', 'kgvid_addFMPOptionsPage');
987
 
988
  function kgvid_FMPOptionsPage() {
989
- ?>
 
990
  <div class="wrap">
991
  <div class="icon32" id="icon-options-general"><br></div>
992
  <h2>Video Embed & Thumbnail Generator</h2>
993
  <form method="post" action="options.php">
994
  <?php settings_fields('kgvid_video_embed_options'); ?>
 
995
  <?php do_settings_sections(__FILE__); ?>
996
  <p class='submit'>
997
- <?php submit_button('Save Changes', 'primary', 'submit', false); ?>
998
  <?php submit_button('Reset Options', 'secondary', 'video-embed-thumbnail-generator-reset', false); ?>
999
  </p>
1000
  </form>
1001
- <script type="text/javascript">
1002
- var embed_method = jQuery('#embed_method').val();
1003
- var video_app = jQuery('#video_app').val();
1004
  jQuery(document).ready(function() {
1005
- kgvid_hide_plugin_settings(embed_method);
1006
- kgvid_hide_ffmpeg_settings(video_app);
 
 
 
 
1007
  }
1008
  );
1009
- </script>
1010
  </div>
1011
  <?php
1012
  }
@@ -1016,332 +1250,449 @@ function kgvid_video_embed_options_init() {
1016
  register_setting('kgvid_video_embed_options', 'kgvid_video_embed_options', 'kgvid_video_embed_options_validate' );
1017
 
1018
  $options = get_option('kgvid_video_embed_options');
1019
-
1020
- add_settings_section('kgvid_video_embed_plugin_settings', 'Plugin Settings', 'kgvid_plugin_settings_section_callback', __FILE__);
1021
  add_settings_section('kgvid_video_embed_playback_settings', 'Default Video Playback Settings', 'kgvid_plugin_playback_settings_section_callback', __FILE__);
1022
  add_settings_section('kgvid_video_embed_flash_settings', 'The following options will only affect Flash playback', 'kgvid_plugin_flash_settings_section_callback', __FILE__);
1023
-
1024
-
1025
- add_settings_field('embed_method', 'Player:', 'kgvid_embed_method_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'embed_method' ) );
1026
- add_settings_field('template', 'Attachment Template Override:', 'kgvid_template_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'template' ) );
1027
- add_settings_field('encode_formats', 'Default Mobile/HTML5 Video encode formats:', 'kgvid_encode_formats_callback', __FILE__, 'kgvid_video_embed_plugin_settings');
1028
- add_settings_field('app_path', 'Path to applications on server:', 'kgvid_app_path_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'app_path' ) );
1029
- add_settings_field('video_app', 'Application for thumbnails & encoding:', 'kgvid_video_app_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'video_app' ) );
1030
- add_settings_field('video_bitrate_flag', 'FFMPEG Options:', 'kgvid_video_bitrate_flag_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'video_bitrate_flag' ) );
1031
- add_settings_field('ffmpeg_vpre', 'FFMPEG Options:', 'kgvid_ffmpeg_vpre_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'ffmpeg_vpre' ) );
1032
- add_settings_field('moov', 'Application to fix encoded H.264 headers for streaming:', 'kgvid_moov_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'moov' ) );
1033
- add_settings_field('generate_thumbs', 'Default number of thumbnails to generate:', 'kgvid_generate_thumbs_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'generate_thumbs' ) );
1034
- add_settings_field('titlecode', 'Video Title Text HTML Formatting:', 'kgvid_titlecode_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'titlecode' ) );
1035
  add_settings_field('poster', 'Poster image:', 'kgvid_poster_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'poster' ) );
1036
  add_settings_field('watermark', 'Watermark image:', 'kgvid_watermark_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'watermark' ) );
1037
- add_settings_field('width', 'Max video width:', 'kgvid_width_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'width' ) );
1038
- add_settings_field('height', 'Max video height:', 'kgvid_height_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'height' ) );
1039
- add_settings_field('gallery_width', 'Max gallery video width:', 'kgvid_gallery_width_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'gallery_width' ) );
1040
- add_settings_field('gallery_height', 'Max gallery video height:', 'kgvid_gallery_height_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'gallery_height' ) );
1041
  add_settings_field('gallery_thumb', 'Gallery thumbnail width:', 'kgvid_gallery_thumb_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'gallery_thumb' ) );
1042
  add_settings_field('controlbar_style', 'Controlbar style:', 'kgvid_controlbar_style_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'controlbar_style' ) );
1043
- add_settings_field('autoplay', 'Autoplay behavior:', 'kgvid_autoplay_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'autoplay' ) );
1044
- add_settings_field('loop', 'Loop behavior:', 'kgvid_loop_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'loop' ) );
1045
  add_settings_field('js_skin', 'Skin Class:', 'kgvid_js_skin_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'js_skin' ) );
 
1046
  add_settings_field('endOfVideoOverlay', 'End of video image:', 'kgvid_endOfVideoOverlay_callback', __FILE__, 'kgvid_video_embed_flash_settings' );
1047
  add_settings_field('bgcolor', 'Background color:', 'kgvid_bgcolor_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'bgcolor' ) );
1048
  add_settings_field('configuration', 'XML configuration file:', 'kgvid_configuration_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'configuration' ) );
1049
  add_settings_field('skin', 'Video skin file:', 'kgvid_skin_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'skin' ) );
1050
  add_settings_field('stream_type', 'Video stream type:', 'kgvid_stream_type_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'stream_type' ) );
1051
  add_settings_field('scale_mode', 'Video scale mode:', 'kgvid_scale_mode_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'scale_mode' ) );
1052
- add_settings_field('autohide', 'Autohide behavior:', 'kgvid_autohide_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'autohide' ) );
1053
  add_settings_field('playbutton', 'Play button overlay:', 'kgvid_playbutton_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'playbutton' ) );
 
 
 
 
 
 
 
 
 
 
 
 
1054
  }
1055
  add_action('admin_init', 'kgvid_video_embed_options_init' );
1056
 
1057
- function kgvid_update_settings() {
1058
-
1059
- global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1060
 
1061
- $options = get_option('kgvid_video_embed_options');
 
 
 
1062
 
1063
- if ( empty($options) ) { // run if the new settings don't exist yet (before version 3.0)
1064
-
1065
- $default_options = kgvid_default_options_fn();
1066
- $options = array();
1067
 
1068
- $old_setting_equivalents = array (
1069
- "width"=>"wp_FMP_width",
1070
- "height"=>"wp_FMP_height",
1071
- "controlbar_style"=>"wp_FMP_controlbar_style",
1072
- "poster"=>"wp_FMP_poster",
1073
- "endOfVideoOverlay"=>"wp_FMP_endOfVideoOverlay",
1074
- "autohide"=>"wp_FMP_autohide",
1075
- "autoplay"=>"wp_FMP_autoplay",
1076
- "loop"=>"wp_FMP_loop",
1077
- "playbutton"=>"wp_FMP_playbutton",
1078
- "stream_type"=>"wp_FMP_stream_type",
1079
- "scale_mode"=>"wp_FMP_scale_mode",
1080
- "bgcolor"=>"wp_FMP_bgcolor",
1081
- "configuration"=>"wp_FMP_configuration",
1082
- "skin"=>"wp_FMP_skin",
1083
- "app_path"=>"wp_FMP_ffmpeg",
1084
- "ffmpeg_exists"=>"wp_FMP_ffmpeg_exists",
1085
- "encode_mobile"=>"wp_FMP_encodemobile",
1086
- "encode_ogg"=>"wp_FMP_encodeogg",
1087
- "encode_webm"=>"wp_FMP_encodewebm",
1088
- "ffmpeg_vpre"=>"wp_FMP_vpre",
1089
- "template"=>"wp_FMP_template",
1090
- "titlecode"=>"wp_FMP_titlecode");
1091
-
1092
- foreach ($old_setting_equivalents as $new_setting => $old_setting) { //apply any old settings to the new database entry then delete them
1093
- $old_setting_value = get_option($old_setting, "no_setting");
1094
- if ( $old_setting_value != "no_setting" ) {
1095
- if ( $old_setting_value == "true" ) { $old_setting_value = "on"; }
1096
- $options[$new_setting] = $old_setting_value;
1097
- delete_option($old_setting);
1098
- }
1099
  }
1100
- $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wp_FMP%'" );
1101
-
1102
- foreach ( $default_options as $key => $value ) { //apply default values for any settings that didn't exist before
1103
- if ( !array_key_exists($key, $options) ) { $options[$key] = $value; }
1104
- $options['embed_method'] = "Strobe Media Playback";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1105
  }
1106
-
1107
- update_option('kgvid_video_embed_options', $options);
1108
  }
1109
 
1110
- elseif ( $options['version'] < 3.1 ) {
1111
- $options['version'] = 3.1;
1112
- if ( $options['ffmpeg_vpre'] == "on" ) { $options['video_bitrate_flag'] = "on"; } //if user has ffmpeg_vpre turned on, they need the old bitrate flags too
1113
- else { $options['video_bitrate_flag'] = false; }
1114
- $options['watermark'] = "";
1115
- update_option('kgvid_video_embed_options', $options);
1116
  }
1117
- }
1118
- add_action('init', 'kgvid_update_settings' );
1119
-
1120
- function kgvid_video_embed_options_validate($input) { //validate & sanitize input from settings form
1121
-
1122
- $default_options = kgvid_default_options_fn();
1123
 
1124
- if (isset ($_POST["video-embed-thumbnail-generator-reset"])) {
1125
- $input = $default_options;
1126
- add_settings_error( __FILE__, "options-reset", "Video Embed & Thumbnail Generator settings reset to default values.", "updated" );
1127
  }
1128
-
1129
- $ffmpeg_info = kgvid_check_ffmpeg_exists($input, false);
1130
 
1131
- if ( $ffmpeg_info['exec_enabled'] == false ) {
1132
- add_settings_error( __FILE__, "exec-disabled", "EXEC function is disabled in PHP settings. You can embed existing videos, but video thumbnail generation and Mobile/HTML5 video encoding will not work. Contact your System Administrator to find out if you can enable EXEC.", "error");
1133
- $input['ffmpeg_exists'] = "notinstalled";
1134
  }
1135
- elseif ( $ffmpeg_info['ffmpeg_exists'] == false ) {
1136
- add_settings_error( __FILE__, "ffmpeg-not-found", strtoupper($input['video_app'])." not found at ".$input['app_path'].". You can embed existing videos, but video thumbnail generation and Mobile/HTML5 video encoding will not work.", "error");
1137
- $input['ffmpeg_exists'] = "notinstalled";
 
 
1138
  }
1139
- if ( $ffmpeg_info['ffmpeg_exists'] == true ) { $input['ffmpeg_exists'] = "on"; }
1140
 
1141
- $input['titlecode'] = wp_kses_post( $input['titlecode'] );
 
 
 
1142
 
1143
- // load all settings and make sure they get a value of false if they weren't entered into the form
1144
- foreach ( $default_options as $key => $value ) {
1145
- if ( !array_key_exists($key, $input) ) { $input[$key] = false; }
1146
  }
1147
-
1148
- $input['version'] = $default_options['version']; //since this isn't user selectable it has to be re-entered every time
1149
 
1150
- return $input;
1151
- }
1152
-
1153
- //callback functions generating HTML for the settings form
1154
-
1155
- function kgvid_plugin_settings_section_callback() { }
1156
- function kgvid_plugin_playback_settings_section_callback() { }
1157
- function kgvid_plugin_flash_settings_section_callback() { }
1158
 
1159
- function kgvid_embed_method_callback() {
1160
  $options = get_option('kgvid_video_embed_options');
1161
- $items = array("Strobe Media Playback", "Video.js");
1162
- echo "<select onchange='kgvid_hide_plugin_settings(this.value);' id='embed_method' name='kgvid_video_embed_options[embed_method]'>";
1163
  foreach($items as $item) {
1164
- $selected = ($options['embed_method']==$item) ? 'selected="selected"' : '';
1165
  echo "<option value='$item' $selected>$item</option>";
1166
  }
1167
- echo "</select> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>This plugin has used Strobe Media Playback for Flash playback in the past, but you can choose to use the newer and lighter Video-js method which will give priority to HTML5 and only use Flash as a fallback.</span></a>";
1168
  }
1169
-
1170
- function kgvid_template_callback() {
1171
  $options = get_option('kgvid_video_embed_options');
1172
- echo "<input ".checked( $options['template'], "on", false )." id='template' name='kgvid_video_embed_options[template]' type='checkbox' /> <label for='template'>Enable minimalist video attachment template.</label><a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Allows easy iframe embedding on other sites. Will override any existing video attachment template page, which is usually a good thing.</span></a>";
 
 
 
 
 
 
1173
  }
1174
 
1175
- function kgvid_encode_formats_callback() {
1176
  $options = get_option('kgvid_video_embed_options');
1177
- echo "<input ".checked( $options['encode_1080'], "on", false )." id='encode_1080' name='kgvid_video_embed_options[encode_1080]' type='checkbox' /> <label for='encode_1080'>1080p H.264 <small><em>(iPhone 4s+, iPad 2+, few Android, Windows Phone 8, Chrome, Safari, IE 9+)</em></small></label> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>This is complicated. If you have FFMPEG/LIBAV and the proper libraries installed, you can choose to encode your uploaded video into as many as five additional formats depending on your original source. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 480p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox is planning to allow H.264 playback in the future and I no longer recommend encoding OGV or WEBM unless you expect a large number of no-Flash sticklers visiting your site.</span></a><br />";
1178
- echo "<input ".checked( $options['encode_720'], "on", false )." id='encode_720' name='kgvid_video_embed_options[encode_720]' type='checkbox' /> <label for='encode_720'>720p H.264 <small><em>(iPhone 4+, iPad, some Android, Chrome, Safari, IE 9+)</em></small></label><br />";
1179
- echo "<input ".checked( $options['encode_mobile'], "on", false )." id='encode_mobile' name='kgvid_video_embed_options[encode_mobile]' type='checkbox' /> <label for='encode_mobile'>480p H.264 <small><em>(iOS, Android, Windows Phone 7, Chrome, Safari, IE 9+)</em></small></label><br />";
1180
- echo "<input ".checked( $options['encode_webm'], "on", false )." id='encode_webm' name='kgvid_video_embed_options[encode_webm]' type='checkbox' /> <label for='encode_webm'>WEBM <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label><br />";
1181
- echo "<input ".checked( $options['encode_ogg'], "on", false )." id='encode_ogg' name='kgvid_video_embed_options[encode_ogg]' type='checkbox' /> <label for='encode_ogg'>OGV <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label>";
 
1182
  }
1183
 
1184
  function kgvid_app_path_callback() {
1185
  $options = get_option('kgvid_video_embed_options');
1186
- echo "<input id='app_path' name='kgvid_video_embed_options[app_path]' size='40' type='text' value='".stripslashes($options['app_path'])."' /><a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Don't include trailing slash. Example: <code>/usr/local/bin</code>. On Windows servers, use / instead of C:\\";
1187
  }
1188
 
1189
  function kgvid_video_app_callback() {
1190
  $options = get_option('kgvid_video_embed_options');
1191
  $items = array("FFMPEG"=>"ffmpeg", "LIBAV"=>"avconv");
1192
- echo "<select onchange='kgvid_hide_ffmpeg_settings(this.value);' id='video_app' name='kgvid_video_embed_options[video_app]'>";
1193
  foreach($items as $name => $value) {
1194
  $selected = ($options['video_app']==$value) ? 'selected="selected"' : '';
1195
  echo "<option value='$value' $selected>$name</option>";
1196
  }
1197
- echo "</select> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>FFMPEG split into two separate branches in 2011. The new branch is called LIBAV. Both are still actively developed. Debian & Ubuntu users probably have LIBAV installed.</span></a>";
1198
  }
1199
 
1200
- function kgvid_video_bitrate_flag_callback() {
1201
- $options = get_option('kgvid_video_embed_options');
1202
- echo "<input ".checked( $options['video_bitrate_flag'], "on", false )." id='video_bitrate_flag' name='kgvid_video_embed_options[video_bitrate_flag]' type='checkbox' /> <label for='video_bitrate_flag'>Enable legacy FFMPEG '-b' and '-ba' bitrate flags.</label> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Enable if your installed version of FFMPEG is old enough that you can't use the newer -b:v flags (Dreamhost users must turn this on). It will cause newer versions of FFMPEG to fail.</span></a>";
 
 
 
 
 
 
1203
  }
1204
 
1205
- function kgvid_ffmpeg_vpre_callback() {
1206
  $options = get_option('kgvid_video_embed_options');
1207
- echo "<input ".checked( $options['ffmpeg_vpre'], "on", false )." id='ffmpeg_vpre' name='kgvid_video_embed_options[ffmpeg_vpre]' type='checkbox' /> <label for='ffmpeg_vpre'>Enable FFMPEG 'vpre' flags.</label> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Enable if your installed version of FFMPEG is old enough that libx264 requires vpre flags to operate (Dreamhost users must turn this on). This should help if you can encode WEBM or OGV files but H264/Mobile files fail. It will cause newer versions of FFMPEG to fail and probably won't work on Windows servers.</span></a>";
 
 
 
1208
  }
1209
 
1210
  function kgvid_moov_callback() {
1211
  $options = get_option('kgvid_video_embed_options');
 
1212
  $items = array("none", "qt-faststart", "MP4Box");
1213
  echo "<select id='moov' name='kgvid_video_embed_options[moov]'>";
1214
  foreach($items as $item) {
1215
  $selected = ($options['moov']==$item) ? 'selected="selected"' : '';
1216
  echo "<option value='$item' $selected>$item</option>";
1217
  }
1218
- echo "</select> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>FFMPEG & LIBAV place moov atoms at the end of H.264 encoded files, which forces the entire file to download before playback can start and prevents the Flash player from playing them at all. If either of these programs is installed in the application path, you can choose to run it after encoding is finished in order to allow playback while downloading.</span></a>";
 
1219
  }
1220
 
1221
  function kgvid_generate_thumbs_callback() {
1222
  $options = get_option('kgvid_video_embed_options');
1223
- echo "<input id='generate_thumbs' name='kgvid_video_embed_options[generate_thumbs]' size='3' type='text' value='".strval($options['generate_thumbs'])."' />";
 
 
1224
  }
1225
 
1226
- function kgvid_titlecode_callback() {
1227
  $options = get_option('kgvid_video_embed_options');
1228
- echo "<input id='titlecode' name='kgvid_video_embed_options[titlecode]' size='40' type='text' value='".htmlentities(stripslashes($options['titlecode']))."' /> <a class='kgvid_tooltip' href='#'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>HTML tag applied to video titles inserted by the plugin. Ex: &lt;strong&gt;, &lt;em&gt;, &lt;H2&gt;, &lt;span class='videotitle'&gt;. Corresponding closing tags will be applied to the end of the title automatically.</span></a>";
1229
  }
1230
 
1231
- function kgvid_poster_callback() {
1232
  $options = get_option('kgvid_video_embed_options');
1233
- echo "<input id='poster' name='kgvid_video_embed_options[poster]' size='60' type='text' value='".$options['poster']."' />";
 
 
 
 
 
 
1234
  }
1235
 
1236
- function kgvid_watermark_callback() {
1237
  $options = get_option('kgvid_video_embed_options');
1238
- echo "<input id='watermark' name='kgvid_video_embed_options[watermark]' size='60' type='text' value='".$options['watermark']."' />";
 
 
 
 
 
 
1239
  }
1240
 
1241
- function kgvid_width_callback() {
1242
  $options = get_option('kgvid_video_embed_options');
1243
- echo "<input id='width' name='kgvid_video_embed_options[width]' size='5' type='text' value='".$options['width']."' />";
1244
  }
1245
 
1246
- function kgvid_height_callback() {
1247
  $options = get_option('kgvid_video_embed_options');
1248
- echo "<input id='height' name='kgvid_video_embed_options[height]' size='5' type='text' value='".$options['height']."' />";
 
 
 
 
 
 
1249
  }
 
 
 
 
1250
 
1251
- function kgvid_gallery_width_callback() {
1252
- $options = get_option('kgvid_video_embed_options');
1253
- echo "<input id='width' name='kgvid_video_embed_options[gallery_width]' size='5' type='text' value='".$options['gallery_width']."' /> ";
1254
- }
1255
 
1256
- function kgvid_gallery_height_callback() {
1257
- $options = get_option('kgvid_video_embed_options');
1258
- echo "<input id='width' name='kgvid_video_embed_options[gallery_height]' size='5' type='text' value='".$options['gallery_height']."' />";
1259
- }
1260
 
1261
- function kgvid_gallery_thumb_callback() {
1262
- $options = get_option('kgvid_video_embed_options');
1263
- echo "<input id='width' name='kgvid_video_embed_options[gallery_thumb]' size='5' type='text' value='".$options['gallery_thumb']."' />";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1264
  }
1265
 
1266
- function kgvid_controlbar_style_callback() {
1267
- $options = get_option('kgvid_video_embed_options');
1268
- $items = array("docked", "floating", "none");
1269
- echo "<select id='controlbar_style' name='kgvid_video_embed_options[controlbar_style]'>";
1270
- foreach($items as $item) {
1271
- $selected = ($options['controlbar_style']==$item) ? 'selected="selected"' : '';
1272
- echo "<option value='$item' $selected>$item</option>";
1273
  }
1274
- echo "</select> HTML5 video players only respond to the \"none\" option.";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1275
  }
 
 
 
 
 
 
 
1276
 
1277
- function kgvid_autoplay_callback() {
1278
- $options = get_option('kgvid_video_embed_options');
1279
- echo "<input ".checked( $options['autoplay'], "on", false )." id='autoplay' name='kgvid_video_embed_options[autoplay]' type='checkbox' /> <label for='autoplay'>Play automatically when page loads.</label>";
1280
  }
 
 
1281
 
1282
- function kgvid_loop_callback() {
1283
- $options = get_option('kgvid_video_embed_options');
1284
- echo "<input ".checked( $options['loop'], "on", false )." id='loop' name='kgvid_video_embed_options[loop]' type='checkbox' /> <label for='loop'>Loop to beginning when video ends.</label>";
1285
  }
1286
-
1287
- function kgvid_js_skin_callback() {
1288
- $options = get_option('kgvid_video_embed_options');
1289
- echo "<input id='skin' name='kgvid_video_embed_options[js_skin]' size='60' type='text' value='".$options['js_skin']."' /><br /><em><small>Use <code>kg-video-js-skin</code> for a nice, circular play button. Leave blank for the default square play button. <a href='http://videojs.com/docs/skins/'>Or build your own CSS skin.</a></small></em>";
1290
  }
 
1291
 
1292
- function kgvid_endOfVideoOverlay_callback() {
1293
- $options = get_option('kgvid_video_embed_options');
1294
- echo "<input ".checked( $options['endOfVideoOverlaySame'], "true", false )." id='endOfVideoOverlaySame' name='kgvid_video_embed_options[endOfVideoOverlaySame]' type='checkbox' onclick='if (this.checked == true) { document.getElementById(\"endOfVideoOverlay\").disabled=true; } else { document.getElementById(\"endOfVideoOverlay\").disabled=false; }'/> <label for='endOfVideoOverlaySame'>Display poster image again when video ends.</label><br />";
1295
- echo "<input id='endOfVideoOverlay' name='kgvid_video_embed_options[endOfVideoOverlay]' size='60' ".disabled( $options['endOfVideoOverlaySame'], "true", false )." type='text' value='".$options['endOfVideoOverlay']."' /> Display alternate image when video ends.<br /><small><em>Leave blank to display the first frame of the video when video ends.</em></small>";
1296
  }
1297
-
1298
- function kgvid_bgcolor_callback() {
1299
- $options = get_option('kgvid_video_embed_options');
1300
- echo "<input id='bgcolor' name='kgvid_video_embed_options[bgcolor]' size='8' type='text' value='".$options['bgcolor']."' /> #rrggbb";
1301
  }
1302
-
1303
- function kgvid_configuration_callback() {
1304
- $options = get_option('kgvid_video_embed_options');
1305
- echo "<input id='configuration' name='kgvid_video_embed_options[configuration]' size='60' type='text' value='".$options['configuration']."' />";
1306
  }
1307
-
1308
- function kgvid_skin_callback() {
1309
- $options = get_option('kgvid_video_embed_options');
1310
- echo "<input id='skin' name='kgvid_video_embed_options[skin]' size='60' type='text' value='".$options['skin']."' /><br /><em><small>Use <code>".plugins_url("", __FILE__)."/flash/skin/kgvid_skin.xml</code> for a modern, circular play button.<br /> Leave blank for the older style square play button.</small></em>";
1311
  }
1312
 
1313
- function kgvid_stream_type_callback() {
1314
- $options = get_option('kgvid_video_embed_options');
1315
- $items = array("liveOrRecorded", "live", "recorded", "dvr");
1316
- echo "<select id='stream_type' name='kgvid_video_embed_options[stream_type]'>";
1317
- foreach($items as $item) {
1318
- $selected = ($options['stream_type']==$item) ? 'selected="selected"' : '';
1319
- echo "<option value='$item' $selected>$item</option>";
1320
- }
1321
- echo "</select>";
1322
- }
1323
 
1324
- function kgvid_scale_mode_callback() {
1325
- $options = get_option('kgvid_video_embed_options');
1326
- $items = array("letterbox", "none", "stretch", "zoom");
1327
- echo "<select id='scale_mode' name='kgvid_video_embed_options[scale_mode]'>";
1328
- foreach($items as $item) {
1329
- $selected = ($options['scale_mode']==$item) ? 'selected="selected"' : '';
1330
- echo "<option value='$item' $selected>$item</option>";
1331
- }
1332
- echo "</select>";
1333
  }
 
 
1334
 
1335
- function kgvid_autohide_callback() {
1336
- $options = get_option('kgvid_video_embed_options');
1337
- echo "<input ".checked( $options['autohide'], "true", false )." id='autohide' name='kgvid_video_embed_options[autohide]' type='checkbox' /> <label for='autohide'>Autohide controlbar.</label>";
1338
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1339
 
1340
- function kgvid_playbutton_callback() {
1341
- $options = get_option('kgvid_video_embed_options');
1342
- echo "<input ".checked( $options['playbutton'], "true", false )." id='playbutton' name='kgvid_video_embed_options[playbutton]' type='checkbox' /> <label for='playbutton'>Overlay play button on poster frame.</label>";
1343
- }
1344
- //end of settings page callback functions
 
 
 
 
 
 
1345
 
1346
  /**
1347
  * Adding our custom fields to the $form_fields array
@@ -1354,10 +1705,11 @@ function kgvid_image_attachment_fields_to_edit($form_fields, $post) {
1354
 
1355
  $options = get_option('kgvid_video_embed_options');
1356
 
1357
- if( substr($post->post_mime_type, 0, 5) == 'video' ){
1358
 
1359
- //$form_fields["kgflashmediaplayer-security"]["input"] = "hidden";
1360
- //$form_fields["kgflashmediaplayer-security"]["value"] = wp_create_nonce('video-embed-thumbnail-generator-nonce');
 
 
1361
 
1362
  $movieurl = wp_get_attachment_url($post->ID);
1363
  $form_fields["kgflashmediaplayer-url"]["input"] = "hidden";
@@ -1381,7 +1733,10 @@ function kgvid_image_attachment_fields_to_edit($form_fields, $post) {
1381
  $form_fields["kgflashmediaplayer-aspect"]["value"] = $heightset/$widthset;
1382
 
1383
  $embedset = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
1384
- if ($embedset == "") { $embedset = "Single Video"; }
 
 
 
1385
 
1386
  $thumbnail_url = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
1387
 
@@ -1396,229 +1751,245 @@ function kgvid_image_attachment_fields_to_edit($form_fields, $post) {
1396
  }
1397
  else { if ( !kgvid_url_exists($thumbnail_url) ) { $thumbnail_url = ""; } }
1398
 
1399
- $thumbnail_html = "";
1400
  if ($thumbnail_url != "" ) {
1401
- $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.'?'.rand().'"></div>';
1402
- }
1403
-
1404
- $numberofthumbs_value = get_post_meta($post->ID, "_kgflashmediaplayer-numberofthumbs", true);
1405
- if (get_post_meta($post->ID, "_kgflashmediaplayer-thumbtime", true) != "") { $numberofthumbs_value = "1"; }
1406
- if ( empty($numberofthumbs_value) ) { $numberofthumbs_value = $options['generate_thumbs']; }
1407
 
1408
- if ( !isset($options['ffmpeg_exists']) || $options['ffmpeg_exists'] == "notchecked" ) {
1409
- kgvid_check_ffmpeg_exists($options, true);
1410
- }
1411
-
1412
- $forcefirstchecked = get_post_meta($post->ID, "_kgflashmediaplayer-forcefirst", true);
1413
 
1414
- if ( $options['ffmpeg_exists'] == "notinstalled" ) { $ffmpeg_disabled_text = 'disabled="disabled" title="'.strtoupper($options['video_app']).' not found at '.$options['app_path'].'"'; }
1415
- else { $ffmpeg_disabled_text = ""; }
1416
-
1417
- $nonce = wp_create_nonce('video-embed-thumbnail-generator-nonce');
1418
-
1419
- if ( $options['embed_method'] == "Video.js" ) {
1420
-
1421
- $starts = intval(get_post_meta($post->ID, "_kgflashmediaplayer-starts", true));
1422
- $completeviews = intval(get_post_meta($post->ID, "_kgflashmediaplayer-completeviews", true));
1423
-
1424
- $form_fields["views"]["label"] = __("Video Stats");
1425
- $form_fields["views"]["input"] = "html";
1426
- $form_fields["views"]["html"] = $starts." Starts, ".$completeviews." Complete Views";
1427
-
1428
- }
1429
 
1430
- $form_fields["generator"]["label"] = __("Thumbnails");
1431
- $form_fields["generator"]["input"] = "html";
1432
- $form_fields["generator"]["html"] = '<input type="hidden" name="attachments[kgflashmediaplayer-security]" id="attachments-kgflashmediaplayer-security" value="'.$nonce.'" /><div id="attachments-'.$post->ID.'-thumbnailplaceholder">'. $thumbnail_html .'</div>
1433
- <input id="attachments-'. $post->ID .'-numberofthumbs" name="attachments['.$post->ID.'][kgflashmediaplayer-numberofthumbs]" type="text" value="'.$numberofthumbs_value.'" maxlength="2" style="width:35px;text-align:center;" onchange="kgvid_disable_thumb_buttons(\''.$post->ID.'\', \'onchange\');document.getElementById(\'attachments-'.$post->ID.'-thumbtime\').value =\'\';" '.$ffmpeg_disabled_text.'/>
1434
- <input type="button" id="attachments-'. $post->ID .'-thumbgenerate" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kgvid_generate_thumb('. $post->ID .', \'generate\');" '.$ffmpeg_disabled_text.'/>
1435
- <input type="button" id="attachments-'. $post->ID .'-thumbrandomize" class="button-secondary" value="Randomize" name="thumbrandomize" onclick="kgvid_generate_thumb('. $post->ID .', \'random\');" '.$ffmpeg_disabled_text.'/> <br />
1436
- <input type="checkbox" id="attachments-'. $post->ID .'-firstframe" name="attachments['.$post->ID.'][kgflashmediaplayer-forcefirst]" onchange="document.getElementById(\'attachments-'.$post->ID.'-thumbtime\').value =\'\';" value="checked" '.$forcefirstchecked.' '.$ffmpeg_disabled_text.'/>
1437
- <label for="attachments-'. $post->ID .'-firstframe">Force 1st Frame Thumbnail</label>';
1438
 
1439
- $form_fields["thumbtime"]["label"] = __("Thumbnail Time");
1440
- $form_fields["thumbtime"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-thumbtime", true);
1441
- $form_fields["thumbtime"]["helps"] = "<small>Optional: generates a single thumbnail at the specified time (hh:mm:ss, mm:ss, or s).</small>";
 
1442
 
1443
- $form_fields["kgflashmediaplayer-poster"]["label"] = __("Thumbnail URL");
1444
- $form_fields["kgflashmediaplayer-poster"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
1445
- $form_fields["kgflashmediaplayer-poster"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>default thumbnail</a>.</small>";
1446
-
1447
- $lockaspectchecked = get_post_meta($post->ID, "_kgflashmediaplayer-lockaspect", true);
1448
- if ( $lockaspectchecked == "notchecked" ) { $lockaspectchecked = ""; }
1449
- else { $lockaspectchecked = "checked"; }
1450
 
1451
- $form_fields["kgflashmediaplayer-dimensions"]["label"] = __("Video Embed Dimensions");
1452
- $form_fields["kgflashmediaplayer-dimensions"]["input"] = "html";
1453
- $form_fields["kgflashmediaplayer-dimensions"]["html"] = 'Width: <input name="attachments['. $post->ID .'][kgflashmediaplayer-width]" id="attachments-'. $post->ID .'-kgflashmediaplayer-width" type="text" value="'.$widthset.'" style="width:50px;" onchange="kgvid_set_dimension('.$post->ID.', \'height\', this.value);" onkeyup="kgvid_set_dimension('.$post->ID.', \'height\', this.value);"> Height:
1454
- <input name="attachments['. $post->ID .'][kgflashmediaplayer-height]" id="attachments-'. $post->ID .'-kgflashmediaplayer-height" type="text" value="'.$heightset.'" style="width:50px;" onchange="kgvid_set_dimension('.$post->ID.', \'width\', this.value);" onkeyup="kgvid_set_dimension('.$post->ID.', \'width\', this.value);"> <br />
1455
- <input type="checkbox" name="attachments['. $post->ID .'][kgflashmediaplayer-lockaspect]" id="attachments-'. $post->ID .'-kgflashmediaplayer-lockaspect" onclick="kgvid_set_aspect('.$post->ID.', this.checked);" value="checked" '.$lockaspectchecked.'>
1456
- <label for="attachments-'. $post->ID .'-kgflashmediaplayer-lockaspect"><small>Lock to Aspect Ratio</small></label>';
1457
- $form_fields["kgflashmediaplayer-dimensions"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>default dimensions</a>.</small>";
1458
 
1459
- $checkboxes = kgvid_generate_encode_checkboxes($movieurl, $post->ID, "attachment");
 
 
 
 
 
 
 
1460
 
1461
- $form_fields["kgflashmediaplayer-encode"]["label"] = __("Additional Formats");
1462
- $form_fields["kgflashmediaplayer-encode"]["input"] = "html";
1463
- $form_fields["kgflashmediaplayer-encode"]["html"] = $checkboxes;
1464
 
1465
- $showtitlechecked = get_post_meta($post->ID, "_kgflashmediaplayer-showtitle", true);
1466
- if ( $showtitlechecked == "notchecked" ) { $showtitlechecked = ""; }
1467
- $downloadlinkchecked = get_post_meta($post->ID, "_kgflashmediaplayer-downloadlink", true);
1468
- if ( $downloadlinkchecked == "notchecked" ) { $downloadlinkchecked = ""; }
1469
- $embed_option = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1470
 
1471
- $items = array("Single Video", "Video Gallery", "WordPress Default");
1472
- $shortcode_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-embed]" id="attachments['.$post->ID.'][kgflashmediaplayer-embed]">';
1473
- foreach($items as $item) {
1474
- $selected = ($embed_option==$item) ? 'selected="selected"' : '';
1475
- $shortcode_select .= "<option value='$item' $selected>$item</option>";
1476
- }
1477
- $shortcode_select .= "</select>";
1478
 
1479
- $form_fields["kgflashmediaplayer-options"]["label"] = __("Video Embed Options");
1480
- $form_fields["kgflashmediaplayer-options"]["input"] = "html";
1481
- $form_fields["kgflashmediaplayer-options"]["html"] = '<input type="checkbox" name="attachments['.$post->ID.'][kgflashmediaplayer-showtitle]" id="attachments-'.$post->ID.'-kgflashmediaplayer-showtitle" value="checked" '.$showtitlechecked.'>
1482
- <label for="attachments-'.$post->ID.'-kgflashmediaplayer-showtitle">Include Title Above Video</label><br />
1483
 
1484
- <input type="checkbox" name="attachments['.$post->ID.'][kgflashmediaplayer-downloadlink]" id="attachments-'.$post->ID.'-kgflashmediaplayer-downloadlink" value="checked" '.$downloadlinkchecked.'>
1485
- <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 />
1486
- '.$shortcode_select.'
1487
- <label for="attachments-'.$post->ID.'-kgflashmediaplayer-embed">Insert</small></em></label><script type="text/javascript">window.onload=kgvid_hide_standard_wordpress_display_settings('.$post->ID.');</script>';
1488
 
1489
- if ( get_post_meta($post->ID, "_kgflashmediaplayer-embed", true) == "Video Gallery" ) {
 
 
 
1490
 
1491
- $gallery_thumb_width = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_thumb_width", true);
1492
- if ( empty($gallery_thumb_width) ) { $gallery_thumb_width = $options['gallery_thumb']; }
1493
-
1494
- $gallery_exclude = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_exclude", true);
1495
- $gallery_include = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_include", true);
1496
- $gallery_orderby = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_orderby", true);
1497
- $gallery_order = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_order", true);
1498
-
1499
- $gallery_id = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_id", true);
1500
- if ( empty($gallery_id) ) { $gallery_id = $post->post_parent; }
1501
-
1502
- $items = array("menu_order", "title", "post_date", "rand", "ID");
1503
- $gallery_orderby_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_orderby]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_orderby">';
1504
- foreach($items as $item) {
1505
- $selected = ($gallery_orderby==$item) ? 'selected="selected"' : '';
1506
- $gallery_orderby_select .= "<option value='$item' $selected>$item</option>";
1507
- }
1508
- $gallery_orderby_select .= "</select>";
1509
-
1510
- $items = array("ASC", "DESC");
1511
- $gallery_order_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_order]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_order">';
1512
- foreach($items as $item) {
1513
- $selected = ($gallery_order==$item) ? 'selected="selected"' : '';
1514
- $gallery_order_select .= "<option value='$item' $selected>$item</option>";
1515
- }
1516
- $gallery_order_select .= "</select>";
1517
 
1518
- $form_fields["kgflashmediaplayer-gallery"]["label"] = __("Gallery Settings (all optional)");
1519
- $form_fields["kgflashmediaplayer-gallery"]["input"] = "html";
1520
- $form_fields["kgflashmediaplayer-gallery"]["html"] = '<input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_thumb_width]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_thumb_width" type ="text" value="'.$gallery_thumb_width.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_thumb_width">Thumbnail Width</label><br />
1521
- '.$gallery_orderby_select.' Order By<br />
1522
- '.$gallery_order_select.' Sort Order<br />
1523
- <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_exclude]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_exclude" type ="text" value="'.$gallery_exclude.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_exclude">Exclude</label><br />
1524
- <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_include]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_include" type ="text" value="'.$gallery_include.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_include">Include</label><br />
1525
- <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_id]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_id" type ="text" value="'.$gallery_id.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_id">Post ID</label>
1526
- ';
1527
 
1528
- }
1529
-
1530
- //$form_fields["kgflashmediaplayer-attachment"]["label"] = __("All Meta");
1531
- //$form_fields["kgflashmediaplayer-attachment"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-attachment", true);
1532
-
1533
- } //only add fields if attachment is video
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1534
  return $form_fields;
1535
  }
1536
  // attach our function to the correct hook
1537
  add_filter("attachment_fields_to_edit", "kgvid_image_attachment_fields_to_edit", null, 2);
1538
 
1539
  function kgvid_save_thumb($post_id, $post_name, $thumb_url) {
1540
-
 
1541
  $uploads = wp_upload_dir();
1542
 
1543
  $posterfile = pathinfo($thumb_url, PATHINFO_BASENAME);
1544
- $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile;
1545
- if ( !is_file($uploads['path'].'/'.$posterfile) ) {
1546
- if ( is_file($tmp_posterpath) ) {
1547
- copy($tmp_posterpath, $uploads['path'].'/'.$posterfile);
1548
- $thumb_base = substr($tmp_posterpath, 0, -5);
1549
- foreach (glob($thumb_base."?.jpg") as $thumbfilename) {
1550
- unlink($thumbfilename);
1551
- }
1552
  }
1553
- if ( kgvid_is_empty_dir($uploads["path"].'/thumb_tmp') ) { kgvid_rrmdir($uploads["path"].'/thumb_tmp'); }
1554
  }
 
 
1555
 
1556
- //insert the $thumb_url into the media library if it does not already exist
1557
-
1558
- global $wpdb;
1559
- $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='".$thumb_url."'"; //check for existing entry in the db
1560
- $thumb_id = $wpdb->get_var($query);
1561
-
1562
- if ( !$thumb_id ) {
 
 
1563
 
1564
- $desc = $post_name . ' thumbnail';
 
 
 
 
 
 
1565
 
1566
- //is image in uploads directory?
1567
- $upload_dir = wp_upload_dir();
 
1568
 
1569
- if ( FALSE !== strpos( $thumb_url, $upload_dir['baseurl'] ) ) {
1570
- $wp_filetype = wp_check_filetype(basename($thumb_url), null );
1571
- $filename = preg_replace('/\.[^.]+$/', '', basename($thumb_url));
 
 
 
 
1572
 
1573
- $attachment = array(
1574
- 'guid' => $thumb_url,
1575
- 'post_mime_type' => $wp_filetype['type'],
1576
- 'post_title' => $desc,
1577
- 'post_content' => '',
1578
- 'post_status' => 'inherit'
1579
- );
1580
- $thumb_id = wp_insert_attachment( $attachment, $uploads['path'].'/'.$posterfile, $post_id );
1581
- // you must first include the image.php file
1582
- // for the function wp_generate_attachment_metadata() to work
1583
- require_once(ABSPATH . 'wp-admin/includes/image.php');
1584
- $attach_data = wp_generate_attachment_metadata( $thumb_id, $uploads['path'].'/'.$posterfile );
1585
- wp_update_attachment_metadata( $thumb_id, $attach_data );
1586
- } else { //not in uploads so we'll have to sideload it
1587
- $tmp = download_url( $thumb_url );
1588
-
1589
- // Set variables for storage
1590
- // fix file filename for query strings
1591
- preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
1592
- $file_array['name'] = basename($matches[0]);
1593
- $file_array['tmp_name'] = $tmp;
1594
-
1595
- // If error storing temporarily, unlink
1596
- if ( is_wp_error( $tmp ) ) {
1597
- @unlink($file_array['tmp_name']);
1598
- $file_array['tmp_name'] = '';
1599
- }
1600
-
1601
- // do the validation and storage stuff
1602
- $thumb_id = media_handle_sideload( $file_array, $post_id, $desc );
1603
 
1604
- // If error storing permanently, unlink
1605
- if ( is_wp_error($thumb_id) ) {
1606
- @unlink($file_array['tmp_name']);
1607
- return $thumb_id;
1608
- }
1609
 
1610
- if ( $local_src = wp_get_attachment_url( $thumb_id ) ) {
1611
- update_post_meta($post_id, '_kgflashmediaplayer-poster', $local_src);
1612
- }
1613
-
1614
- } //end sideload
1615
 
1616
- } //end get_attachment_id_from_src
 
 
 
 
 
 
 
1617
 
1618
- if(!is_wp_error($thumb_id)) {
1619
- $thumb_id = intval( $thumb_id );
1620
- update_post_meta($post_id, '_kgflashmediaplayer-poster-id', $thumb_id);
1621
- }
1622
 
1623
  }
1624
 
@@ -1631,48 +2002,53 @@ function kgvid_video_attachment_fields_to_save($post, $attachment) {
1631
  // $attachment part of the form $_POST ($_POST[attachments][postID])
1632
  // $post attachments wp post array - will be saved after returned
1633
  // $post['post_type'] == 'attachment'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1634
 
1635
- if( isset($attachment['kgflashmediaplayer-poster']) ) {
 
1636
 
1637
- $thumb_url = $attachment['kgflashmediaplayer-poster'];
1638
- kgvid_save_thumb($post['ID'], $post['post_name'], $thumb_url);
1639
- update_post_meta($post['ID'], '_kgflashmediaplayer-poster', $thumb_url);
 
 
 
 
 
 
 
1640
 
1641
  }
1642
- if( isset($attachment['kgflashmediaplayer-numberofthumbs']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-numberofthumbs', $attachment['kgflashmediaplayer-numberofthumbs']); }
1643
- if( isset($attachment['kgflashmediaplayer-forcefirst']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-forcefirst', $attachment['kgflashmediaplayer-forcefirst']); }
1644
- else { update_post_meta($post['ID'], '_kgflashmediaplayer-forcefirst', ""); }
1645
- if( isset($attachment['thumbtime']) ) {update_post_meta($post['ID'], '_kgflashmediaplayer-thumbtime', $attachment['thumbtime']); }
1646
- if( isset($attachment['kgflashmediaplayer-width']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-width', $attachment['kgflashmediaplayer-width']); }
1647
- if( isset($attachment['kgflashmediaplayer-height']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-height', $attachment['kgflashmediaplayer-height']); }
1648
- if( isset($attachment['kgflashmediaplayer-aspect']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-aspect', $attachment['kgflashmediaplayer-aspect']); }
1649
- if( isset($attachment['kgflashmediaplayer-lockaspect']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-lockaspect', $attachment['kgflashmediaplayer-lockaspect']); }
1650
- else { update_post_meta($post['ID'], '_kgflashmediaplayer-lockaspect', "notchecked"); }
1651
-
1652
- $video_formats = kgvid_video_formats();
1653
- foreach ( $video_formats as $format => $format_stats ) {
1654
- if( isset($attachment['kgflashmediaplayer-encode'.$format]) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-encode'.$format, "on"); }
1655
- else { update_post_meta($post['ID'], '_kgflashmediaplayer-encode'.$format, "notchecked"); }
1656
- }
1657
-
1658
- if( isset($attachment['kgflashmediaplayer-showtitle']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-showtitle', $attachment['kgflashmediaplayer-showtitle']); }
1659
- else { update_post_meta($post['ID'], '_kgflashmediaplayer-showtitle', "notchecked"); }
1660
-
1661
- if( isset($attachment['kgflashmediaplayer-downloadlink']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-downloadlink', $attachment['kgflashmediaplayer-downloadlink']); }
1662
- else { update_post_meta($post['ID'], '_kgflashmediaplayer-downloadlink', "notchecked"); }
1663
-
1664
- if( isset($attachment['kgflashmediaplayer-embed']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-embed', $attachment['kgflashmediaplayer-embed']); }
1665
- if( isset($attachment['kgflashmediaplayer-gallery_thumb_width']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_thumb_width', $attachment['kgflashmediaplayer-gallery_thumb_width']); }
1666
- if( isset($attachment['kgflashmediaplayer-gallery_exclude']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_exclude', $attachment['kgflashmediaplayer-gallery_exclude']); }
1667
- if( isset($attachment['kgflashmediaplayer-gallery_include']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_include', $attachment['kgflashmediaplayer-gallery_include']); }
1668
- if( isset($attachment['kgflashmediaplayer-gallery_orderby']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_orderby', $attachment['kgflashmediaplayer-gallery_orderby']); }
1669
- if( isset($attachment['kgflashmediaplayer-gallery_order']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_order', $attachment['kgflashmediaplayer-gallery_order']); }
1670
- if( isset($attachment['kgflashmediaplayer-gallery_id']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_id', $attachment['kgflashmediaplayer-gallery_id']); }
1671
-
1672
- //$attachment_printr = print_r($attachment, true);
1673
- //update_post_meta($post['ID'], '_kgflashmediaplayer-attachment', $attachment_printr );
1674
-
1675
- return $post;
1676
  }
1677
  add_filter("attachment_fields_to_save", "kgvid_video_attachment_fields_to_save", null, 2);
1678
 
@@ -1686,10 +2062,9 @@ class kgInsertMedia {
1686
 
1687
  $options = get_option('kgvid_video_embed_options');
1688
  $output = $html;
1689
-
1690
  $attachment['embed'] = get_post_meta($attachment_id, "_kgflashmediaplayer-embed", true);
1691
 
1692
- if ( $attachment['embed'] == "Single Video" || $attachment['embed'] == "checked" || !is_numeric($attachment_id) ) {
1693
  $output = "";
1694
  $attachment['url'] = wp_get_attachment_url($attachment_id);
1695
  $attachment['title'] = get_the_title($attachment_id);
@@ -1705,7 +2080,7 @@ class kgInsertMedia {
1705
  $endtitlecode = str_replace("<", "</", $titlecode);
1706
  $endtitlecode_array = explode(' ', $endtitlecode);
1707
  if ( substr($endtitlecode_array[0], -1) != ">" ) { $endtitlecode = $endtitlecode_array[0].">"; }
1708
- $output .= $titlecode.$attachment["title"].$endtitlecode.'<br />';
1709
  }
1710
  $output .= '[KGVID';
1711
  if ($attachment['poster'] !="") { $output .= ' poster="'.$attachment["poster"].'"'; }
@@ -1802,7 +2177,7 @@ function media_embedurl_process() {
1802
  </tr>
1803
  <tr>
1804
  <th valign="top" scope="row" class="label"><span class="alignleft"><label for="attachments-singleurl-kgflashmediaplayer-width">Dimensions</label></span></th>
1805
- <td class="field">Width: <input name="attachments[singleurl][kgflashmediaplayer-width]" type="text" value="" id="attachments-singleurl-kgflashmediaplayer-width" type="text" style="width:50px;" onchange="kgvid_set_dimension('singleurl', 'height', this.value);" onkeyup="kgvid_set_dimension('singleurl', 'height', this.value);"> Height: <input name="attachments[singleurl][kgflashmediaplayer-height]" id="attachments-singleurl-kgflashmediaplayer-height" type="text" value="" style="width:50px;" onchange="kgvid_set_dimension('singleurl', 'width', this.value);" onkeyup="kgvid-set-dimension('singleurl', 'width', this.value);"> <input type="checkbox" name="attachments[singleurl][kgflashmediaplayer-lockaspect]" id="attachments-singleurl-kgflashmediaplayer-lockaspect" onclick="kgvid_set_aspect('singleurl', this.checked);" checked> <label for="attachments-singleurl-kgflashmediaplayer-lockaspect"><small>Lock to Aspect Ratio</small></label>
1806
  <p class="help"><small>Leave blank to use <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php" target="_blank">default dimensions</a>.</small></p></td>
1807
  </tr>
1808
  <tr>
@@ -1823,7 +2198,7 @@ function media_embedurl_process() {
1823
  </div>
1824
  </div>
1825
 
1826
- <input type='hidden' name='attachments[kgflashmediaplayer-security]' id='attachments-kgflashmediaplayer-security' value='<?php echo wp_create_nonce('video-embed-thumbnail-generator-nonce'); ?>' />
1827
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxwidth]' id='attachments-singleurl-kgflashmediaplayer-maxwidth' value='<?php echo($maxwidth); ?>' />
1828
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxheight]' id='attachments-singleurl-kgflashmediaplayer-maxheight' value='<?php echo($maxheight); ?>' />
1829
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-aspect]' id='attachments-singleurl-kgflashmediaplayer-aspect' value='<?php echo(round($maxheight/$maxwidth, 3)); ?>' />
@@ -1846,51 +2221,86 @@ function kgvid_parameter_queryvars( $qvars ) { //add kgvid_video_embed variable
1846
  }
1847
  add_filter('query_vars', 'kgvid_parameter_queryvars' );
1848
 
1849
- function kgvid_video_attachment_template() {
1850
 
1851
  global $post;
1852
  global $wp_query;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1853
 
 
1854
  $options = get_option('kgvid_video_embed_options');
1855
 
1856
- $kgvid_video_embed = "";
1857
- if ( isset($wp_query->query_vars['kgvid_video_embed']) ) { $kgvid_video_embed = $wp_query->query_vars['kgvid_video_embed']; }
 
 
 
 
 
 
 
 
 
 
 
 
1858
 
1859
- if ( ($options['template'] == "on" && is_attachment()) || isset($kgvid_video_embed['gallery']) ) {
 
 
 
 
1860
 
1861
- $embed_enabled = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
1862
 
1863
- if ( $embed_enabled != "WordPress Default" || isset($kgvid_video_embed['gallery']) ) {
1864
 
1865
- remove_action('wp_head', '_admin_bar_bump_cb');
1866
-
1867
- $poster = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
1868
-
1869
- if (isset($kgvid_video_embed['width'])) { $width = $kgvid_video_embed['width']; }
1870
- else { $width = get_post_meta($post->ID, "_kgflashmediaplayer-width", true); }
1871
- if ( !$width ) { $width = get_post_meta($post->ID, "_kgflashmediaplayer-actualwidth", true); }
1872
- if ( !$width ) { $width = $options['width']; }
1873
-
1874
- if (isset($kgvid_video_embed['height'])) { $height = $kgvid_video_embed['height']; }
1875
- else { $height = get_post_meta($post->ID, "_kgflashmediaplayer-height", true); }
1876
- if ( !$height ) { $height = get_post_meta($post->ID, "_kgflashmediaplayer-actualheight", true); }
1877
- if ( !$height ) { $width = $options['width']; }
1878
-
1879
- $url = wp_get_attachment_url($post->ID);
1880
-
1881
- $shortcode = '[KGVID';
1882
- if ($poster !="" ) { $shortcode .= ' poster="'.$poster.'"';}
1883
- if ($width !="" ) { $shortcode .= ' width="'.$width.'"';}
1884
- if ($height !="" ) { $shortcode .= ' height="'.$height.'"';}
1885
- if (isset($kgvid_video_embed["gallery"])) { $shortcode .= ' autoplay="true"'; }
1886
- $shortcode .= ']'.$url.'[/KGVID]';
1887
- echo "<html>\n<head>";
1888
- echo wp_head();
1889
- echo "</head>\n<body>";
1890
- echo do_shortcode( $shortcode );
1891
- echo '</body></html>';
1892
- exit;
1893
- }
1894
  }
1895
  }
1896
  add_action('template_redirect', 'kgvid_video_attachment_template');
@@ -1913,7 +2323,6 @@ add_action('kgvid_cleanup_generated_logfiles','kgvid_cleanup_generated_logfiles_
1913
  function kgvid_cleanup_generated_thumbnails_handler() {
1914
  $uploads = wp_upload_dir();
1915
  kgvid_rrmdir($uploads['path'].'/thumb_tmp'); //remove the whole tmp file directory
1916
- kgvid_clear_completed_queue();
1917
  }
1918
  add_action('kgvid_cleanup_generated_thumbnails','kgvid_cleanup_generated_thumbnails_handler');
1919
 
@@ -1927,16 +2336,244 @@ function kgvid_schedule_cleanup_generated_files() { //schedules deleting all tmp
1927
  wp_schedule_single_event(time()+3600, 'kgvid_cleanup_generated_thumbnails');
1928
  }
1929
 
1930
- if (isset($_POST['logfile'])) {
1931
- $timestamp = wp_next_scheduled( 'kgvid_cleanup_generated_logfiles' );
1932
- wp_unschedule_event($timestamp, 'kgvid_cleanup_generated_logfiles' );
1933
- $args = array('logfile'=>$_POST['logfile']);
1934
- wp_schedule_single_event(time()+600, 'kgvid_cleanup_generated_logfiles', $args);
1935
- }
1936
-
1937
- die(); // this is required to return a proper result
1938
- }
1939
- add_action('wp_ajax_kgvid_schedule_cleanup_generated_files', 'kgvid_schedule_cleanup_generated_files');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1940
 
1941
  function kgvid_callffmpeg() {
1942
 
@@ -1944,226 +2581,35 @@ function kgvid_callffmpeg() {
1944
  global $wpdb;
1945
 
1946
  $options = get_option('kgvid_video_embed_options');
1947
- $ffmpegPath = $options['app_path']."/".$options['video_app'];
1948
- $uploads = wp_upload_dir();
1949
- if (isset($_POST['encodeformats'])) { $encode_checked = $_POST['encodeformats']; }
1950
- if (isset($_POST['movieurl'])) { $movieurl = esc_url_raw($_POST['movieurl']); }
1951
  if (isset($_POST['numberofthumbs'])) { $numberofthumbs = $_POST['numberofthumbs']; }
1952
  if (isset($_POST['thumbnumber'])) { $i = $_POST['thumbnumber']; }
1953
  if (isset($_POST['thumbnumberplusincreaser'])) { $iincreaser = $_POST['thumbnumberplusincreaser']; }
1954
- if (isset($_POST['ffmpeg_action'])) { $action = $_POST['ffmpeg_action']; }
1955
- if (isset($_POST['poster'])) { $poster = $_POST['poster']; }
1956
- if (isset($_POST['attachmentID'])) { $postID = $_POST['attachmentID']; }
1957
  if (isset($_POST['thumbtimecode'])) { $thumbtimecode = $_POST['thumbtimecode']; }
1958
  if (isset($_POST['dofirstframe'])) { $dofirstframe = $_POST['dofirstframe']; }
1959
  if (isset($_POST['generate_button'])) { $generate_button = $_POST['generate_button']; }
1960
 
1961
- if ( is_numeric($postID) ) { $moviefilepath = get_attached_file($postID); }
1962
- else {
1963
- $moviefilepath = str_replace(" ", "%20", $movieurl);
1964
- $moviefilepath = str_replace("https://", "http://", $moviefilepath);
1965
- }
1966
-
1967
- $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
1968
- $moviefilebasename = basename($movieurl,'.'.$movie_extension);
1969
- $thumbnailfilebase = $uploads['url']."/thumb_tmp/".$moviefilebasename;
1970
-
1971
- if ($action == "generate" || $action == "encode" || $action == "enqueue" ) {
1972
-
1973
- if ( $options['ffmpeg_exists'] == true ) { //if FFMPEG is installed
1974
-
1975
- $movie_info = kgvid_get_video_dimensions($moviefilepath);
1976
-
1977
- if ($movie_info['worked'] == true) { //if FFMPEG was able to open the file
1978
-
1979
- $movie_duration_hours = intval(substr($movie_info['duration'], -11, 2));
1980
- $movie_duration_minutes = intval(substr($movie_info['duration'], -8, 2));
1981
- $movie_duration_seconds = intval(substr($movie_info['duration'], -5, 2));
1982
- $movie_duration_seconds = ($movie_duration_hours * 60 * 60) + ($movie_duration_minutes * 60) + $movie_duration_seconds;
1983
- $movie_width = $movie_info['width'];
1984
- $movie_height = $movie_info['height'];
1985
-
1986
- if ( is_numeric($postID) ) {
1987
- update_post_meta($postID, '_kgflashmediaplayer-actualwidth', $movie_width);
1988
- update_post_meta($postID, '_kgflashmediaplayer-actualheight', $movie_height);
1989
- }
1990
-
1991
- switch ($movie_info['rotate']) {
1992
- case "90": $movie_rotate = '-vf "transpose=1"'; break;
1993
- case "180": $movie_rotate = '-vf "hflip,vflip"'; break;
1994
- case "270": $movie_rotate = '-vf "transpose=2"'; break;
1995
- default: $movie_rotate = ""; break;
1996
- }
1997
-
1998
- if ($action == "generate") {
1999
-
2000
- if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
2001
-
2002
- $thumbnailheight = strval(round(floatval($movie_height) / floatval($movie_width) * 200));
2003
-
2004
- switch ($movie_info['rotate']) { //if it's a sideways mobile video
2005
- case "90";
2006
- case "270": $thumbnailheight = strval(round(floatval($movie_width) / floatval($movie_height) * 200));
2007
- }
2008
-
2009
- $jpgpath = $uploads['path']."/thumb_tmp/";
2010
-
2011
- $movieoffset = round(($movie_duration_seconds * $iincreaser) / ($numberofthumbs * 2));
2012
-
2013
- if ($generate_button == "random") { //adjust offset random amount
2014
- $movieoffset = $movieoffset - rand(0, round($movie_duration_seconds / $numberofthumbs));
2015
- if ($movieoffset < 0) { $movieoffset = "0"; }
2016
- }
2017
-
2018
- if ($thumbtimecode) { //if a specific thumbnail timecode is set
2019
- if ($thumbtimecode == "firstframe") { $thumbtimecode = "0"; }
2020
- $timecode_array = explode(":", $thumbtimecode);
2021
- $timecode_array = array_reverse($timecode_array);
2022
- if ( array_key_exists(1, $timecode_array) ) { $timecode_array[1] = $timecode_array[1] * 60; }
2023
- if ( array_key_exists(2, $timecode_array) ) { $timecode_array[2] = $timecode_array[2] * 3600; }
2024
- $thumbtimecode = array_sum($timecode_array);
2025
- $movieoffset = $thumbtimecode;
2026
- $i = $numberofthumbs + 1;
2027
- }
2028
-
2029
- if ($dofirstframe == "true" && $i == 1) {
2030
- $movieoffset = "0";
2031
- }
2032
-
2033
- $thumbnailfilename[$i] = $jpgpath.$moviefilebasename."_thumb".$movieoffset.".jpg";
2034
- $thumbnailfilename[$i] = str_replace(" ", "_", $thumbnailfilename[$i]);
2035
- $ffmpeg_options = '-y -ss '.$movieoffset.' -i "'.$moviefilepath.'" '.$movie_rotate.' -vframes 1 "'.$thumbnailfilename[$i].'"';
2036
- $thumbnailurl = $thumbnailfilebase."_thumb".$movieoffset.'.jpg';
2037
- $thumbnailurl = str_replace(" ", "_", $thumbnailurl);
2038
-
2039
- exec($ffmpegPath." ".$ffmpeg_options);
2040
-
2041
- if (floatval($movieoffset) > 60) {
2042
- $movieoffset_minutes = sprintf("%02s", intval(intval($movieoffset) / 60) );
2043
- $movieoffset_seconds = sprintf("%02s", round(fmod( floatval($movieoffset), 60), 2) );
2044
- $movieoffset_display = $movieoffset_minutes.":".$movieoffset_seconds;
2045
- }
2046
- else { $movieoffset_display = "00:".sprintf("%02s", $movieoffset); }
2047
-
2048
- $thumbnaildisplaycode = '<div class="kgvid_thumbnail_select" name="attachments['.$postID.'][thumb'.$i.']" id="attachments-'.$postID.'-thumb'.$i.'"><label for="kgflashmedia_'.$postID.'_thumb'.$i.'"><img src="'.$thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'" class="kgvid_thumbnail"></label><br /><input type="radio" name="kgflashmedia-thumb" id="kgflashmedia_'.$postID.'_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>';
2049
-
2050
- switch ($movie_info['rotate']) {
2051
- case "90";
2052
- case "270": $movie_width ^= $movie_height ^= $movie_width ^= $movie_height; break; //swap height & width
2053
- }
2054
-
2055
- $i++;
2056
-
2057
- $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "movie_width"=>$movie_width, "movie_height"=>$movie_height, "lastthumbnumber"=>$i, "movieoffset"=>$movieoffset );
2058
-
2059
- echo json_encode($arr);
2060
- }//if generate
2061
-
2062
- if ($action == "enqueue") {
2063
-
2064
- $embed_display = "";
2065
- $start_encoding = false;
2066
- $encode_these = array();
2067
- $encode_list = array();
2068
- $embeddable = array("flv", "f4v", "mp4", "mov", "m4v", "ogv", "ogg", "webm");
2069
- $h264extensions = array("mp4", "m4v");
2070
- $video_formats = kgvid_video_formats();
2071
-
2072
- $encodevideo_info = kgvid_encodevideo_info($movieurl, $postID);
2073
-
2074
- foreach ( $video_formats as $format => $format_stats ) {
2075
- if ( $encode_checked[$format] == "true" ) {
2076
- if ( !$encodevideo_info[$format.'_exists'] ) {
2077
- if ( ($format == "1080" && $movie_height <= 1080) || ($format == "720" && $movie_height <= 720) ) {
2078
- if ( in_array($movie_extension, $h264extensions) || $movie_height < intval($format) ) {
2079
- $encode_formats[$format]['status'] = "lowres";
2080
- } //skip if the resolution of an existing video is lower than the HD format
2081
- }
2082
- else {
2083
- $encode_formats[$format]['status'] = "queued";
2084
- $encode_formats[$format]['name'] = $format_stats['name'];
2085
- $encode_list[$format] = $format_stats['name'];
2086
- update_post_meta($postID, '_kgflashmediaplayer-encode'.$format, 'on');
2087
- }
2088
- } // if video doesn't already exist
2089
- else { $encode_formats[$format]['status'] = "encoded"; }
2090
- } // if user wants to encode format
2091
- else {
2092
- $encode_formats[$format]['status'] = "notchecked";
2093
- update_post_meta($postID, '_kgflashmediaplayer-encode'.$format, 'notchecked');
2094
- }
2095
- }
2096
-
2097
- if ( !empty($encode_list) ) {
2098
- $video_embed_queue = get_option('kgvid_video_embed_queue');
2099
- $queue_entry = array (
2100
- 'attachmentID'=>$postID,
2101
- 'movieurl' => $movieurl,
2102
- 'encode_formats'=> $encode_formats,
2103
- 'movie_info' => $movie_info
2104
- );
2105
- $already_queued = false;
2106
- if ( !empty($video_embed_queue ) ) {
2107
- foreach ($video_embed_queue as $index => $entry) {
2108
- if ( $entry['movieurl'] == $movieurl ) {
2109
- $already_queued = $index;
2110
- foreach ( $entry['encode_formats'] as $format => $value ) {
2111
- if ( $value['status'] == "queued" && array_key_exists($format, $encode_list) ) { unset($encode_list[$format]); }
2112
- if ( $value['status'] == "encoding" ) { $queue_entry['encode_formats'][$format] = $entry['encode_formats'][$format]; } //don't edit queue entry for anything that's currently encoding
2113
- }
2114
- }
2115
- }
2116
- }
2117
-
2118
- if ( $already_queued !== false ) {
2119
- $video_embed_queue[$already_queued] = $queue_entry;
2120
- update_option('kgvid_video_embed_queue', $video_embed_queue);
2121
- if ( !empty($encode_list) ) { $embed_display = "<strong>".implode(", " , $encode_list)." updated in existing queue entry in position ".strval(intval($already_queued)+1).". </strong>"; }
2122
- else { $embed_display = "<strong>Video is already queued in position ".strval(intval($already_queued)+1).". </strong>"; }
2123
- }
2124
- else {
2125
- $video_embed_queue[] = $queue_entry;
2126
- update_option('kgvid_video_embed_queue', $video_embed_queue);
2127
- $queue_position = intval(key( array_slice( $video_embed_queue, -1, 1, TRUE ) ));
2128
- if ( $queue_position == 0 ) { $embed_display = "<strong>Starting ".strtoupper($options['video_app'])."... </strong>"; }
2129
- else { $embed_display = "<strong>".implode(", " , $encode_list)." added to queue in position ".strval(intval($queue_position)+1). ". </strong>";
2130
- }
2131
- }
2132
- } //if any video formats don't already exist, add to queue
2133
- else { $embed_display = "<strong>Nothing to encode.</strong>"; }
2134
-
2135
- $replaceoptions = "";
2136
- $originalselect = "";
2137
-
2138
- $arr = array ( "embed_display"=>$embed_display );
2139
- echo json_encode($arr);
2140
-
2141
- }//if enqueue
2142
-
2143
- }//if ffmpeg can open movie
2144
-
2145
- else { $thumbnaildisplaycode = "<strong>Can't open movie file.</strong><br />".$movie_info['output'];
2146
- $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "embed_display"=>$thumbnaildisplaycode, "lastthumbnumber"=>"break" );
2147
- echo json_encode($arr);
2148
- } //can't open movie
2149
 
2150
- }//if ffmpeg exists
2151
 
2152
- else { $thumbnaildisplaycode = '<strong>Error: '.strtoupper($options["video_app"]).' not found. Verify that '.strtoupper($options["video_app"]).' is installed at '.strtoupper($options["app_path"]).' and check the <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php">application path plugin setting</a>.</strong>' ;
 
 
 
 
 
2153
  $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "embed_display"=>$thumbnaildisplaycode, "lastthumbnumber"=>"break" );
2154
  echo json_encode($arr);
2155
- } //no ffmpeg
2156
-
2157
-
2158
- }// if encoding or generating
2159
-
2160
- if ($action == "submit") { //called by the "Embed Video from URL" tab when submitting
2161
-
2162
- if (isset($_POST['post_id'])) { $post_id = $_POST['post_id']; }
2163
- $post_name = get_the_title($post_id);
2164
- kgvid_save_thumb($post_id, $post_name, $poster);
2165
- }//if submit
2166
-
2167
  die(); // this is required to return a proper result
2168
  }
2169
  add_action('wp_ajax_kgvid_callffmpeg', 'kgvid_callffmpeg');
@@ -2175,6 +2621,7 @@ function kgvid_encode_videos() {
2175
  $video_key = "";
2176
  $queued_format = "";
2177
  $encoding = "";
 
2178
  $movie_info = array("width"=>"", "height"=>"");
2179
  $video_embed_queue = get_option('kgvid_video_embed_queue');
2180
  $video_formats = kgvid_video_formats();
@@ -2211,7 +2658,7 @@ function kgvid_encode_videos() {
2211
  $options = get_option('kgvid_video_embed_options');
2212
 
2213
  $ffmpegPath = $options['app_path']."/".$options['video_app'];
2214
- if ( is_numeric($video['attachmentID']) ) { $moviefilepath = get_attached_file($video['attachmentID']); }
2215
  else {
2216
  $moviefilepath = str_replace(" ", "%20", esc_url_raw($video['movieurl']));
2217
  $moviefilepath = str_replace("https://", "http://", $moviefilepath);
@@ -2225,15 +2672,6 @@ function kgvid_encode_videos() {
2225
  $processPID = "";
2226
  $serverOS = "";
2227
  $ffmpeg_options = "";
2228
-
2229
- switch ($movie_info['rotate']) {
2230
- case "90": $movie_rotate = '-vf "transpose=1"'; break;
2231
- case "180": $movie_rotate = '-vf "hflip,vflip"'; break;
2232
- case "270": $movie_rotate = '-vf "transpose=2"'; break;
2233
- default: $movie_rotate = ""; break;
2234
- }
2235
-
2236
- if ( ! file_exists($encodevideo_info['encodepath']) ) { mkdir($encodevideo_info['encodepath']); }
2237
 
2238
  if ( $options['video_app'] == "avconv" || $options['video_bitrate_flag'] == false ) {
2239
  $video_bitrate_flag = "b:v";
@@ -2262,11 +2700,12 @@ function kgvid_encode_videos() {
2262
  if ( $movie_info['configuration']['libvo_aacenc'] == "true" ) { $aaclib = "libvo_aacenc"; }
2263
  else { $aaclib = "libfaac"; }
2264
 
2265
- $h264bitrate = round($h264_movie_height * 2.75);
 
2266
  $vpre_flags = "";
2267
  if ( $options['ffmpeg_vpre'] == 'on' ) { $vpre_flags = '-vpre slow -vpre ipod640'; }
2268
 
2269
- $ffmpeg_options = ' -acodec '.$aaclib.' -'.$audio_bitrate_flag.' 128k -s '.$h264_movie_width.'x'.$h264_movie_height.' -vcodec libx264 '.$vpre_flags.' -threads 1 '.$movie_rotate.' -'.$video_bitrate_flag.' '.$h264bitrate.'k -bt 800k -f ipod "'.$encodevideo_info[$format.'filepath'].'"';
2270
  $embed_display .= "<strong>Encoding ".$format_stats['name']."</strong>";
2271
  }//if file doesn't already exist
2272
  else { $embed_display .= "<strong>".$format_stats['name']." already encoded. </strong>"; }
@@ -2286,7 +2725,7 @@ function kgvid_encode_videos() {
2286
  if ( ! $encodevideo_info['webm_exists'] || ($encodevideo_info['sameserver'] && filesize($encodevideo_info['webmfilepath']) < 24576) ) {
2287
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration']['libvpx'] == "true" ) {
2288
  $webmbitrate = $movie_info['height'] * 3;
2289
- $ffmpeg_options = ' -'.$audio_bitrate_flag.' 128k -'.$video_bitrate_flag.' '.$webmbitrate.'k '.$movie_rotate.' -threads 1 "'.$encodevideo_info['webmfilepath'].'"';
2290
  $embed_display .= "<strong>Encoding WEBM. </strong>";
2291
  }//if the necessary webm libraries are enabled
2292
  else {
@@ -2304,7 +2743,7 @@ function kgvid_encode_videos() {
2304
 
2305
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration']['libtheora'] == "true" ) {
2306
  $ogvbitrate = $movie_info['height'] * 3;
2307
- $ffmpeg_options = ' -acodec libvorbis -'.$audio_bitrate_flag.' 128k -vcodec libtheora -'.$video_bitrate_flag.' '.$ogvbitrate.'k '.$movie_rotate.' -threads 1 "'.$encodevideo_info['oggfilepath'].'"';
2308
  $embed_display .= "<strong>Encoding OGV. </strong>";
2309
  }//if the necessary OGV libraries are enabled
2310
  else {
@@ -2320,12 +2759,12 @@ function kgvid_encode_videos() {
2320
  if ( !empty($ffmpeg_options) ) {
2321
 
2322
  $ffmpeg_args = '-y -i "'.$moviefilepath.'" '.$ffmpeg_options;
2323
- $logfile = $encodevideo_info['encodepath'].str_replace(" ", "_", $encodevideo_info['moviefilebasename'])."_".$queued_format."_".sprintf("%04s",mt_rand(1, 1000))."_encode.txt";
2324
 
2325
  $cmd = escapeshellcmd($ffmpegPath." ".$ffmpeg_args);
2326
  if ( !empty($cmd) ) { $cmd = $cmd." > ".$logfile." 2>&1 & echo $!"; }
2327
  else {
2328
- $arr = array ( "embed_display"=>"<span style='color:red;'>Error: Command escapeshellcmd is disabled.</span>" );
2329
  return $arr;
2330
  }
2331
  $process = new kgvid_Process($cmd);
@@ -2337,8 +2776,8 @@ function kgvid_encode_videos() {
2337
 
2338
  $args = array('logfile'=>$logfile);
2339
  wp_schedule_single_event(time()+600, 'kgvid_cleanup_generated_logfiles', $args);
2340
- if ( !wp_next_scheduled( 'kgvid_cleanup_queue' ) ) {
2341
- wp_schedule_event( time()+86400, 'daily', 'kgvid_cleanup_queue');
2342
  }
2343
 
2344
  //update_post_meta($video['attachmentID'], '_kgflashmediaplayer-encode'.$format, 'on');
@@ -2347,6 +2786,7 @@ function kgvid_encode_videos() {
2347
  'name' => $video_formats[$queued_format]['name'],
2348
  'status' => 'encoding',
2349
  'filepath' => $encodevideo_info[$queued_format.'filepath'],
 
2350
  'logfile' => $logfile,
2351
  'PID' => $processPID,
2352
  'OS' => $serverOS,
@@ -2355,6 +2795,7 @@ function kgvid_encode_videos() {
2355
 
2356
  $queue_entry = array (
2357
  'attachmentID'=> $video['attachmentID'],
 
2358
  'movieurl' => $video['movieurl'],
2359
  'encode_formats'=> $video['encode_formats'],
2360
  'movie_info' => $video['movie_info']
@@ -2394,142 +2835,220 @@ add_action('wp_ajax_kgvid_ajax_encode_videos', 'kgvid_ajax_encode_videos');
2394
 
2395
  function kgvid_encode_progress($video_key, $format, $page) {
2396
 
2397
- $video_embed_queue = get_option('kgvid_video_embed_queue');
2398
- $video_entry = $video_embed_queue[$video_key];
2399
-
2400
- $pid = $video_entry['encode_formats'][$format]['PID'];
2401
- $logfile = $video_entry['encode_formats'][$format]['logfile'];
2402
- $started = $video_entry['encode_formats'][$format]['started'];
2403
- $movie_duration = $video_entry['movie_info']['duration'];
2404
- $embed_display = "";
2405
- $percent_done = "";
2406
- $time_remaining = "";
2407
- $other_message = "";
2408
- $logfilecontents = "";
2409
- $lastline = "";
2410
-
2411
- if ( is_file($logfile) ) {
2412
-
2413
- $fp = fopen($logfile, 'r');
2414
- $c = '';
2415
- $read = '';
2416
- $offset = -1;
2417
- $lines = 2;
2418
- while ( $lines && fseek($fp, $offset, SEEK_END) >= 0 ) {
2419
- $c = fgetc($fp);
2420
- if( $c == "\n" || $c == "\r" ) {
2421
- $lines--;
2422
- }
2423
- $read .= $c;
2424
- $offset--;
2425
- }
2426
- fclose($fp);
2427
- $lastline = strrev(rtrim($read,"\n\r"));
2428
-
2429
- $last_match = "";
2430
- $time_matches = "";
2431
- $video_matches = "";
2432
- $libx264_matches = "";
2433
- $fps_matches = "";
2434
- $fps_match = "";
2435
- $basename = "";
2436
 
2437
- $script_function = 'kgvid_redraw_encode_checkboxes("'.$video_entry['movieurl'].'", "'.$video_entry['attachmentID'].'", "'.$page.'")';
2438
-
2439
- preg_match('/time=(.*?) /', $lastline, $time_matches);
 
 
 
 
 
 
2440
 
2441
- if ( array_key_exists(1, $time_matches) != true ) { //if something other than the regular FFMPEG encoding output check for these
2442
- preg_match('/video:(.*?) /', $lastline, $video_matches);
2443
- preg_match('/libx264 (.*?) /', $lastline, $libx264_matches);
2444
- //preg_match('/h264 (.*?) /', $lastline, $h264_matches);
2445
- //preg_match('/Press (.*?) /', $lastline, $Press_matches);
2446
- //preg_match('/buffer (.*?) /', $lastline, $buffer_matches);
2447
- }
2448
 
2449
- if ( array_key_exists(1, $time_matches) == true ) { //still encoding
 
 
 
 
 
 
 
2450
 
2451
- if ( strpos($time_matches[1], ':') !== false ) {
2452
- $current_hours = intval(substr($time_matches[1], -11, 2));
2453
- $current_minutes = intval(substr($time_matches[1], -8, 2));
2454
- $current_seconds = intval(substr($time_matches[1], -5, 2));
2455
- $current_seconds = ($current_hours * 60 * 60) + ($current_minutes * 60) + $current_seconds;
2456
- }
2457
- else { $current_seconds = $time_matches[1]; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2458
 
2459
- $duration_hours = intval(substr($movie_duration, -11, 2));
2460
- $duration_minutes = intval(substr($movie_duration, -8, 2));
2461
- $duration_seconds = intval(substr($movie_duration, -5, 2));
2462
- $movie_duration = ($duration_hours * 60 * 60) + ($duration_minutes * 60) + $duration_seconds;
2463
-
2464
- $percent_done = intval($current_seconds)/intval($movie_duration);
2465
- $time_elapsed = time() - $started;
2466
- if ( $percent_done != 0 ) { $time_remaining = date('H:i:s', round($time_elapsed / $percent_done) - $time_elapsed); }
2467
- else $time_remaining = "unknown";
2468
- $percent_done = round($percent_done*100);
2469
- if ( $percent_done < 20 ) { $percent_done_text = ""; }
2470
- else { $percent_done_text = strval($percent_done)."%"; }
2471
-
2472
- preg_match('/fps=\s+(.*?) /', $lastline, $fps_matches);
2473
- if ( array_key_exists(1, $fps_matches) == true ) {
2474
- if ( $fps_matches[1] != 0 ) { $fps_match = $fps_matches[1]; }
2475
- else { $fps_match = "10"; }
2476
- }
2477
- else { $fps_match = "10"; }
2478
- $time_to_wait = strval(max(round(30000/intval($fps_match)), 1000)); //wait at least 1 second
2479
- if ( intval($time_to_wait) > 10000 ) { //wait no more than 10 seconds
2480
- $time_to_wait = 10000;
2481
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2482
 
2483
- $args = array($video_key, $format, $page);
2484
- wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2485
 
2486
- $embed_display = '<strong>Encoding</strong> <div class="meter"><span style="width:'.$percent_done.'%;">'.$percent_done_text.' </span></div><a href="javascript:void(0)" class="kgvid_cancel_button" id="attachments-'.$video_entry["attachmentID"].'-kgflashmediaplayer-cancelencode" onclick="kgvid_cancel_encode('.$pid.', \''.$video_entry["attachmentID"].'\', \''.$video_key.'\', \''.$format.'\');">Cancel</a><div style="display:block;"><small>Elapsed: '.date('H:i:s',$time_elapsed).'. Remaining: '.$time_remaining.'. FPS:'.$fps_match.'</small></div><script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, '.$time_to_wait.');</script>';
2487
- }
2488
- elseif ( time() - $started < 10 ) { //not enough time has passed, so check again later
2489
- $args = array($video_key, $format, $page);
2490
- $embed_display = '<strong>Encoding</strong> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
2491
- wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
2492
- }
2493
- elseif ( array_key_exists(1, $video_matches) == true || array_key_exists(1, $libx264_matches) == true ) { //encoding complete
2494
- $percent_done = 100;
2495
- $ended = filemtime($logfile);
2496
- $time_elapsed = $ended - $started;
2497
- $time_remaining = "0";
2498
- $fps_match = "10";
2499
- if ( array_key_exists(1, $libx264_matches) ) { kgvid_fix_moov_atom($video_key, $format); } //fix the moov atom if the file was encoded by libx264
2500
- $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "Encoding Complete";
2501
- $video_embed_queue[$video_key]['encode_formats'][$format]['ended'] = $ended;
2502
- $video_embed_queue[$video_key]['encode_formats'][$format]['lastline'] = $lastline;
2503
- update_option('kgvid_video_embed_queue', $video_embed_queue);
2504
- $embed_display = '<strong>Encoding Complete</strong> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
2505
- $next_video = kgvid_encode_videos(); //start the next queued video
2506
- if ( !empty($next_video['format']) ) {
2507
- $args = array($next_video['video_key'], $next_video['format'], $page);
2508
- wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
2509
- }
2510
- }
2511
- else { //there was an error";
2512
- if ( strpos($lastline, "signal 15") !== false ) { //if the encoding was intentionally canceled
2513
- $lastline = "Encoding was canceled.";
2514
- }
2515
- $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "error";
2516
- $video_embed_queue[$video_key]['encode_formats'][$format]['lastline'] = $lastline;
2517
- update_option('kgvid_video_embed_queue', $video_embed_queue);
2518
- $other_message = $lastline;
2519
- $embed_display = '<strong>Error: </strong><span style="color:red;">'.$lastline.'.</span> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
2520
- $next_video = kgvid_encode_videos(); //start the next queued video
2521
- if ( !empty($next_video['format']) ) {
2522
- $args = array($next_video['video_key'], $next_video['format'], $page);
2523
- wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
2524
  }
2525
- }
2526
 
2527
- //$embed_display .= $lastline;
2528
- $arr = array ( "embed_display"=>$embed_display );
2529
- }
2530
- else { $arr = array ( "embed_display"=>"<strong>No log file</strong>" ); }
2531
-
2532
- return $arr;
 
2533
 
2534
  }
2535
  add_action('kgvid_cron_queue_check', 'kgvid_encode_progress', 1, 3);
@@ -2672,37 +3191,347 @@ function kgvid_ajax_delete_video() {
2672
  check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
2673
  global $wpdb;
2674
  $deleted = false;
2675
- if (isset($_POST['movieurl'])) {
2676
- $encodevideo_info = kgvid_encodevideo_info($_POST['movieurl'], $_POST['postid']);
2677
- if ( is_file($encodevideo_info[$_POST['format'].'filepath']) ) {
2678
- $deleted = unlink($encodevideo_info[$_POST['format'].'filepath']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2679
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
2680
  $video_embed_queue = get_option('kgvid_video_embed_queue');
2681
- if ( !empty($video_embed_queue) ) {
 
 
 
2682
  foreach ($video_embed_queue as $video_key => $video_entry) {
2683
- if ( $video_entry['movieurl'] == $_POST['movieurl'] ) {
2684
- $video_embed_queue[$video_key]['encode_formats'][$_POST['format']]['status'] = "deleted";
 
 
2685
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2686
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2687
  }
2688
  }
2689
- update_option('kgvid_video_embed_queue', $video_embed_queue);
2690
  }
2691
- echo($deleted);
2692
- die();
 
 
 
 
 
 
2693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2694
  }
2695
- add_action('wp_ajax_kgvid_delete_video', 'kgvid_ajax_delete_video');
2696
 
2697
- function enqueue_kgvid_script() { //loads plugin-related javascripts
2698
- wp_enqueue_script( 'video_embed_thumbnail_generator_script', plugins_url('/js/kgvid_video_plugin_admin.js', __FILE__) );
2699
- wp_enqueue_style( 'kgvid_progressbar_style', plugins_url('/css/video-embed-thumbnail-generator_admin.css', __FILE__) );
2700
- wp_enqueue_script( 'jquery-ui-sortable' );
 
 
 
 
 
 
 
 
 
 
 
2701
  }
2702
- add_action('admin_enqueue_scripts', 'enqueue_kgvid_script');
2703
 
2704
- add_action( 'wp_ajax_kgvid_count_play', 'kgvid_count_play' ); // ajax for logged in users
2705
- add_action( 'wp_ajax_nopriv_kgvid_count_play', 'kgvid_count_play' ); // ajax for not logged in users
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2706
 
2707
  function kgvid_count_play() {
2708
  $post_id = $_POST['post_id'];
@@ -2714,9 +3543,11 @@ function kgvid_count_play() {
2714
  echo 'ajax submitted';
2715
  die(); // stop executing script
2716
  }
 
 
2717
 
2718
  function kgvid_deactivate() {
2719
- wp_clear_scheduled_hook('kgvid_cleanup_queue');
2720
  delete_option('kgvid_video_embed_queue');
2721
  }
2722
  register_deactivation_hook( __FILE__, 'kgvid_deactivate' );
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: Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG for thumbnails and encodes. <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php">Settings</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation/">Donate</a>
6
+ Version: 4.0.1
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
 
41
  die( "Can't load this file directly" );
42
 
43
  function kgvid_default_options_fn() {
44
+ $options = array(
45
+ "version"=>4.01,
46
  "embed_method"=>"Video.js",
47
  "template"=>false,
48
+ "template_gentle"=>"on",
49
  "encode_1080"=>"on",
50
  "encode_720"=>"on",
51
  "encode_mobile"=>"on",
58
  "ffmpeg_vpre"=>false,
59
  "moov"=>"none",
60
  "generate_thumbs"=>4,
61
+ "featured"=>"on",
62
+ "thumb_parent"=>"video",
63
+ "delete_children"=>"encoded videos only",
64
  "titlecode"=>"<strong>",
65
  "poster"=>"",
66
  "watermark"=>"",
67
+ "overlay_title"=>"on",
68
+ "overlay_embedcode"=>false,
69
+ "view_count"=>false,
70
+ "align"=>"left",
71
  "width"=>"640",
72
  "height"=>"360",
73
  "gallery_width"=>"960",
76
  "controlbar_style"=>"docked",
77
  "autoplay"=>false,
78
  "loop"=>false,
79
+ "endOfVideoOverlay"=>false,
80
  "endOfVideoOverlaySame"=>"",
81
  "bgcolor"=>"",
82
  "configuration"=>"",
84
  "js_skin"=>"kg-video-js-skin",
85
  "stream_type"=>"liveOrRecorded",
86
  "scale_mode"=>"letterbox",
87
+ "autohide"=>"on",
88
+ "playbutton"=>"on");
89
  return $options;
90
  }
91
 
102
  function kgvid_video_formats() {
103
 
104
  $video_formats = array(
105
+ "rotated" => array("name" => "Replace original with rotated H.264", "width" => 4096, "height" => 2304, "type" => "h264", "suffix" => "-rotated.mp4"),
106
+ "1080" => array("name" => "1080p H.264", "width" => 1920, "height" => 1080, "type" => "h264", "suffix" => "-1080.mp4", "old_suffix" => "-1080.m4v"),
107
+ "720" => array("name" => "720p H.264", "width" => 1280, "height" => 720, "type" => "h264", "suffix" => "-720.mp4", "old_suffix" => "-720.m4v"),
108
+ "mobile" => array("name" => "480p H.264", "width" => 640, "height" => 480, "type" => "h264", "suffix" => "-480.mp4", "old_suffix" => "-ipod.m4v"),
109
  "webm" => array("name" => "WEBM", "width" => 0, "height" => 0, "type" => "webm", "suffix" => ".webm"),
110
  "ogg" => array("name" => "OGV", "width" => 0, "height" => 0, "type" => "ogv", "suffix" => ".ogv")
111
  );
144
  else return false; // whatever the reason is : no such dir, not a dir, not readable
145
  }
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  function kgvid_rrmdir($dir) {
148
  if (is_dir($dir)) {
149
  $objects = scandir($dir);
157
  }
158
  }
159
 
160
+ function kgvid_check_for_shortcode_in_content() {
161
+ global $post;
162
+ $pattern = get_shortcode_regex();
163
+ preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches );
164
+ if ( array_key_exists( 2, $matches ) && array_key_exists( 5, $matches ) ) {
165
+ foreach ( $matches[2] as $shortcode_index => $shortcode ) {
166
+ if ( $shortcode == "KGVID" || $shortcode == "FMP" ) { continue; }
167
+ else {
168
+ foreach ( $matches as $match_index => $shortcode_matches ) {
169
+ unset($matches[$match_index][$shortcode_index]);
170
+ }
171
+ }
172
+ }
173
+ foreach ( $matches[5] as $index => $url ) {
174
+ if ( empty($url) ) { unset($matches[5][$index]); }
175
+ }
176
+ }
177
+ return $matches;
178
+ }
179
+
180
+ function kgvid_get_attachment_medium_url( $id )
181
+ {
182
+ $medium_array = image_downsize( $id, 'medium' );
183
+ $medium_path = $medium_array[0];
184
+
185
+ return $medium_path;
186
+ }
187
+
188
+ function kgvid_backwards_compatible($post_id) {
189
+
190
+ global $wp_version;
191
+ $field_id = array();
192
+
193
+ if ( $wp_version < 3.5 ) {
194
+ $field_id['poster'] = 'attachments['. $post_id .'][kgflashmediaplayer-poster]';
195
+ $field_id['thumbtime'] = 'attachments['. $post_id .'][thumbtime]';
196
+ }
197
+ else {
198
+ $field_id['poster'] = 'attachments-'. $post_id .'-kgflashmediaplayer-poster';
199
+ $field_id['thumbtime'] = 'attachments-'. $post_id .'-thumbtime';
200
+ }
201
+ return $field_id;
202
+
203
+ }
204
+
205
+ function kgvid_sanitize_url($movieurl) {
206
+ $movieurl = rawurldecode($movieurl);
207
+ $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
208
+ $sanitized_url['noextension'] = preg_replace("/\\.[^.\\s]{3,4}$/", "", $movieurl);
209
+ $sanitized_url['basename'] = sanitize_file_name(basename($movieurl,'.'.$movie_extension));;
210
+ $sanitized_url['singleurl_id'] = "singleurl_".preg_replace('/[^a-zA-Z0-9]/', '_', $sanitized_url['basename']);
211
+ $sanitized_url['movieurl'] = esc_url_raw(str_replace(" ", "%20", $movieurl));
212
+ return $sanitized_url;
213
+ }
214
+
215
+ function kgvid_ajax_sanitize_url() {
216
+
217
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
218
+ $movieurl = $_POST['movieurl'];
219
+ $sanitized_url = kgvid_sanitize_url($movieurl);
220
+ echo json_encode($sanitized_url);
221
+ die();
222
+
223
+ }
224
+ add_action('wp_ajax_kgvid_sanitize_url', 'kgvid_ajax_sanitize_url');
225
+
226
  function kgvid_check_ffmpeg_exists($options, $save) {
227
  $exec_enabled = false;
228
  $ffmpeg_exists = false;
229
  $output = array();
230
+ $function = "";
231
  $uploads = wp_upload_dir();
232
 
233
  if(function_exists('exec')) {
234
+ if (function_exists('escapeshellcmd')) {
235
+ $exec_enabled = true;
236
+ $cmd = escapeshellcmd($options['app_path'].'/'.$options['video_app'].' -i '.plugin_dir_path(__FILE__).'/flash/skin/images/PlayNormal.png '.$uploads['path'].'/ffmpeg_exists_test.jpg');
237
+ exec ( $cmd, $output, $returnvalue );
238
+ }
239
+ else { $function = "ESCAPESHELLCMD"; }
240
+ }
241
+ else { $function = "EXEC"; }
242
 
243
  if ( $exec_enabled == true && file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //if FFMPEG has executed successfully
244
  $ffmpeg_exists = true;
252
  }
253
 
254
  $output_output = implode("/n", $output);
255
+ $arr = array ("exec_enabled"=>$exec_enabled, "ffmpeg_exists"=>$ffmpeg_exists, "output"=>$output_output, "function"=>$function);
256
  return $arr;
257
  }
258
 
261
  $options = get_option('kgvid_video_embed_options');
262
 
263
  $uploads = wp_upload_dir();
 
 
 
 
264
  $video_formats = kgvid_video_formats();
265
+ $sanitized_url = kgvid_sanitize_url($movieurl);
266
+ $movieurl = $sanitized_url['movieurl'];
267
+
268
+ $encodevideo_info['moviefilebasename'] = $sanitized_url['basename'];
269
+ $encodevideo_info['encodepath'] = $uploads['path'];
270
+ if ( get_post_type($postID) == "attachment" ) { //if it's an attachment, not from URL
271
  $moviefile = get_attached_file($postID);
272
  $path_parts = pathinfo($moviefile);
273
  $encodevideo_info['encodepath'] = $path_parts['dirname']."/";
274
  $encodevideo_info['sameserver'] = true;
275
+ $args = array(
276
+ 'numberposts' => '-1',
277
+ 'post_parent' => $postID,
278
+ 'post_type' => 'attachment',
279
+ 'post_mime_type' => 'video'
280
+ );
281
  }
282
+ else {
283
+
284
  $url_parts = parse_url($uploads['url']);
285
+ if ( array_key_exists('host', $url_parts) && strpos($movieurl, $url_parts['host']) !== false ) { //if we're on the same server
286
  $encodevideo_info['sameserver'] = true;
287
+ $decodedurl = urldecode($movieurl);
288
+ $parsed_url= parse_url($decodedurl);
289
+ $fileinfo = pathinfo($decodedurl);
290
  $parsed_url['extension'] = $fileinfo['extension'];
291
  $parsed_url['filename'] = $fileinfo['basename'];
292
  $parsed_url['localpath'] = $_SERVER['DOCUMENT_ROOT'].$parsed_url['path'];
295
 
296
  $encodevideo_info['encodepath'] = rtrim($parsed_url['localpath'], $parsed_url['filename']);
297
  }
298
+ else { $encodevideo_info['sameserver'] = false; }
299
+
300
+ $args = array(
301
+ 'numberposts' => '-1',
302
+ 'post_type' => 'attachment',
303
+ 'meta_key' => '_kgflashmediaplayer-externalurl',
304
+ 'meta_value' => $sanitized_url['movieurl'],
305
+ 'post_mime_type' => 'video'
306
+ );
307
 
 
 
 
 
 
 
308
  }
309
+ $children = get_posts( $args );
310
 
311
  foreach ( $video_formats as $format => $format_stats ) { //loop through each format
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
+ $encodevideo_info[$format.'_exists'] = false;
314
+ $encodevideo_info[$format.'_writable'] = false;
315
+
316
+ //start with the new database info before checking other locations
317
+
318
+ if ($children) {
319
+ foreach ( $children as $child ) {
320
+ $mime_type = get_post_mime_type($child->ID);
321
+ $wp_attached_file = get_post_meta($child->ID, '_wp_attached_file', true);
322
+ $wp_file_info = pathinfo($wp_attached_file);
323
+ if ( substr($wp_attached_file, -strlen($format_stats['suffix'])) == $format_stats['suffix'] ) {
324
+ $encodevideo_info[$format.'url'] = $uploads['baseurl'].'/'.$wp_attached_file;
325
+ $encodevideo_info[$format.'filepath'] = $uploads['basedir'].'/'.$wp_attached_file;
326
+ $encodevideo_info[$format.'id'] = $child->ID;
327
  $encodevideo_info[$format.'_exists'] = true;
328
+ $encodevideo_info[$format.'_writable'] = true;
329
+ continue 2; //skip rest of children loop and format loop
330
  }
 
331
  }
332
  }
333
+
334
+ //if the format's not in the database, check these places
335
+ if ( $format != 'rotated' ) {
336
+
337
+ if ( array_key_exists('old_suffix', $format_stats) ) { $old_suffix = $format_stats['old_suffix']; }
338
+ else { $old_suffix = $format_stats['suffix']; }
339
+ $potential_locations = array(
340
+ "same_directory" => array(
341
+ 'url' => $sanitized_url['noextension'].$format_stats['suffix'],
342
+ 'filepath' => $encodevideo_info['encodepath'].$encodevideo_info['moviefilebasename'].$format_stats['suffix'] ),
343
+ "same_directory_old_suffix" => array(
344
+ 'url' => $sanitized_url['noextension'].$old_suffix,
345
+ 'filepath' => $encodevideo_info['encodepath'].$encodevideo_info['moviefilebasename'].$old_suffix ),
346
+ "html5encodes" => array(
347
+ 'url' => $uploads['baseurl']."/html5encodes/".$encodevideo_info['moviefilebasename'].$old_suffix,
348
+ 'filepath' => $uploads['basedir']."/html5encodes/".$encodevideo_info['moviefilebasename'].$old_suffix ),
349
+ );
350
+ if ( !array_key_exists('old_suffix', $format_stats) ) { unset($potential_locations['same_directory_old_suffix']); }
351
+
352
+ foreach ( $potential_locations as $name => $location ) {
353
 
354
+ if ( file_exists($location['filepath']) ) {
355
+ $encodevideo_info[$format.'_exists'] = true;
356
+ $encodevideo_info[$format.'url'] = $location['url'];
357
+ $encodevideo_info[$format.'filepath'] = $location['filepath'];
358
+ if ( is_writable($location['filepath']) ) { $encodevideo_info[$format.'_writable'] = true; }
359
+ break;
360
+ }
361
+ elseif ( !$encodevideo_info['sameserver'] && $name != "html5encodes" ) { //last resort if it's not on the same server, check url_exists
362
+
363
+ $already_checked_url = get_post_meta($postID, '_kgflashmediaplayer-'.$sanitized_url['singleurl_id'].'-'.$format, true);
364
+ if ( empty($already_checked_url) ) {
365
+ if ( kgvid_url_exists(esc_url_raw(str_replace(" ", "%20", $location['url']))) ) {
366
+ $encodevideo_info[$format.'_exists'] = true;
367
+ $encodevideo_info[$format.'url'] = $location['url'];
368
+ update_post_meta($postID, '_kgflashmediaplayer-'.$sanitized_url['singleurl_id'].'-'.$format, $encodevideo_info[$format.'url']);
369
+ }
370
+ else {
371
+ update_post_meta($postID, '_kgflashmediaplayer-'.$sanitized_url['singleurl_id'].'-'.$format, 'not found');
372
+ }
373
+ }
374
+ else { //url already checked
375
+ if ( substr($already_checked_url, 0, 4) == 'http' ) { //if it smells like a URL...
376
+ $encodevideo_info[$format.'_exists'] = true;
377
+ $encodevideo_info[$format.'url'] = $already_checked_url;
378
+ }
379
+ }
380
+ }//end if not on same server
381
+ }//end potential locations loop
382
+ }
383
+
384
+ if ( !$encodevideo_info[$format.'_exists'] ) {
385
+ $encodevideo_info[$format.'url'] = $uploads['url'].'/'.$encodevideo_info['moviefilebasename'].$format_stats['suffix'];
386
+ $encodevideo_info[$format.'filepath'] = $uploads['path'].'/'.$encodevideo_info['moviefilebasename'].$format_stats['suffix'];
387
+ }
388
+
389
+ }//end format loop
390
+
391
  return $encodevideo_info;
392
  }
393
 
404
 
405
  $video = str_replace("https://", "http://", $video);
406
 
407
+ $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '"');
408
+ $command = $command.' 2>&1';
409
  exec ( $command, $output );
410
  $lastline = end($output);
411
  $lastline = prev($output)."<br />".$lastline;
419
  $height = $vals [1] ? $vals [1] : null;
420
  preg_match('/Duration: (.*?),/', $output, $matches);
421
  $duration = $matches[1];
422
+ $movie_duration_hours = intval(substr($duration, -11, 2));
423
+ $movie_duration_minutes = intval(substr($duration, -8, 2));
424
+ $movie_duration_seconds = intval(substr($duration, -5, 2));
425
+ $movie_duration_seconds = ($movie_duration_hours * 60 * 60) + ($movie_duration_minutes * 60) + $movie_duration_seconds;
426
+
427
  preg_match('/rotate : (.*?)\n/', $output, $matches);
428
  if ( array_key_exists(1, $matches) == true ) { $rotate = $matches[1]; }
429
  else $rotate = "0";
430
 
431
+ switch ($rotate) {
432
+ case "90": $rotate = '-vf "transpose=1"'; break;
433
+ case "180": $rotate = '-vf "hflip,vflip"'; break;
434
+ case "270": $rotate = '-vf "transpose=2"'; break;
435
+ default: $rotate = ""; break;
436
+ }
437
+
438
+ $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '" -codecs');
439
+ $command = $command.' 2>&1';
440
  exec ( $command, $output );
441
  $output = implode("\n", $output);
442
  $configuration = array();
445
  if ( strpos($output, $lib) !== false ) { $configuration[$lib] = "true"; }
446
  else { $configuration[$lib] = "false"; }
447
  }
448
+
449
+ return array ('width' => $width, 'height' => $height, 'duration' => $movie_duration_seconds, 'configuration' => $configuration, 'rotate' => $rotate, 'worked'=>true );
450
  } else {
451
  return array ('output'=>$lastline, 'worked'=>false);
452
  }
518
  wp_enqueue_script( 'swfobject' );
519
  }
520
 
521
+ //Video.js script and skins
522
+ wp_enqueue_script( 'video-js', plugins_url("", __FILE__).'/video-js/video.js', '', '3.2.0' );
523
+ wp_enqueue_style( 'video-js-css', plugins_url("", __FILE__).'/video-js/video-js.css', '', '3.2.0' );
524
+ wp_enqueue_style( 'video-js-kg-skin', plugins_url("", __FILE__).'/video-js/kg-video-js-skin.css', '', $options['version'] );
525
+ //plugin-related frontend scripts and styles
526
+ wp_enqueue_style( 'kgvid_video_styles', plugins_url("/css/kgvid_styles.css", __FILE__), '', $options['version'] );
 
527
  wp_enqueue_script( 'jquery-ui-dialog' );
528
+ wp_enqueue_script( 'kgvid_video_embed', plugins_url("/js/kgvid_video_embed.js", __FILE__), '', $options['version'] );
529
  wp_localize_script( 'kgvid_video_embed', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
530
  }
531
+ add_action('wp_enqueue_scripts', 'kgvid_video_embed_enqueue_scripts', 12);
532
 
533
+ function enqueue_kgvid_script() { //loads plugin-related scripts in the admin area
534
 
535
+ wp_enqueue_script( 'video_embed_thumbnail_generator_script', plugins_url('/js/kgvid_video_plugin_admin.js', __FILE__) );
536
+ wp_enqueue_style( 'video_embed_thumbnail_generator_style', plugins_url('/css/video-embed-thumbnail-generator_admin.css', __FILE__) );
537
+
538
+ }
539
+ add_action('admin_enqueue_scripts', 'enqueue_kgvid_script');
540
 
541
+ function kgvid_video_embed_print_scripts() {
542
+
543
+ echo '<script type="text/javascript">_V_.options.flash.swf = "'.plugins_url("", __FILE__).'/video-js/video-js.swf"</script>'."\n";
544
 
545
  }
546
  add_action('wp_head', 'kgvid_video_embed_print_scripts');
549
  function KGVID_shortcode($atts, $content = ''){
550
 
551
  $options = get_option('kgvid_video_embed_options');
552
+ if ( in_the_loop() ) { $post_ID = get_the_ID(); }
553
+ else { $post_ID = 1; }
 
 
554
 
555
  $query_atts = shortcode_atts(
556
  array('width' => $options['width'],
557
  'height' => $options['height'],
558
+ 'align' => $options['align'],
559
  'controlbar' => $options['controlbar_style'],
560
  'autohide' => $options['autohide'],
561
  'poster' => $options['poster'],
577
  'gallery_exclude' => '',
578
  'gallery_include' => '',
579
  'gallery_id' => $post_ID,
580
+ 'volume' => '',
581
+ 'title' => $options['overlay_title'],
582
+ 'embedcode' => $options['overlay_embedcode'],
583
+ 'view_count' => $options['view_count'],
584
+ 'caption' => '',
585
+ 'description' => ''
586
  ), $atts);
587
 
588
+ $checkbox_convert = array ( "autohide", "endOfVideoOverlaySame", "playbutton", "loop", "autoplay", "title", "embedcode", "view_count");
589
+ foreach ( $checkbox_convert as $query ) {
590
+ if ( $query_atts[$query] == "on" ) { $query_atts[$query] = "true"; }
591
+ if ( $query_atts[$query] == false ) { $query_atts[$query] = "false"; }
592
+ }
593
+
594
+ if ( $options['js_skin'] == "" ) { $options['js_skin'] = "vjs-default-skin"; }
595
+ if ( is_array($atts) ) {
596
+ if ( array_key_exists('skin', $atts) ) { $options['js_skin'] = $atts['skin']; } //allows user to set skin for individual videos using the skin="" attribute
597
+ }
598
 
599
+ if ( $query_atts["gallery"] != "true" ) { //if this is just a single video
600
 
601
+ // workaround for relative video URL (contributed by Lee Fernandes)
602
+ if(substr($content, 0, 1) == '/') $content = get_bloginfo('url').$content;
603
  $content = trim($content);
604
 
605
  global $wpdb;
606
+ $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='{$content}'"; //GUID seems to be the only way to get a video URL
607
  $id = $wpdb->get_var($query);
608
+
609
  $moviefiletype = pathinfo($content, PATHINFO_EXTENSION);
610
+ if ( $moviefiletype == "mov" || $moviefiletype == "m4v" ) { $moviefiletype = "mp4"; }
611
+ $video_formats = array(
612
+ "original" => $moviefiletype,
613
+ "1080" => "mp4",
614
+ "720" => "mp4",
615
+ "mobile" => "mp4",
616
+ "webm" => "webm",
617
+ "ogg" => "ogg"
618
+ );
619
+ $compatible = array("flv", "f4v", "mp4", "mov", "m4v", "ogv", "ogg", "webm");
620
  $flashcompatible = array("flv", "f4v", "mp4", "mov", "m4v");
621
  $h264compatible = array("mp4", "mov", "m4v");
 
622
 
623
+ if ( !empty($id) ) { //if the video is an attachment in the WordPress db
624
  $div_suffix = $id;
625
  $encodevideo_info = kgvid_encodevideo_info($content, $id);
626
  $attachment_info = get_post( $id );
 
 
 
 
 
 
 
627
 
628
+ $poster_id = get_post_meta($id, '_kgflashmediaplayer-poster-id', true);
629
+ if ( !empty($poster_id) ) {
630
+ //$poster_post = get_post($poster_id);
631
+ $poster_image_src = wp_get_attachment_image_src($poster_id);
632
+ if ( empty($query_atts['poster']) ) { $query_atts['poster'] = $poster_image_src[0]; } //if there's no poster URL set, use the database to set it automatically
633
+ if ( $poster_image_src[0] == $query_atts['poster'] && intval($query_atts['width']) <= get_option('medium_size_h') ) {
634
+ $query_atts['poster'] = kgvid_get_attachment_medium_url($poster_id);
635
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  }
637
+
638
+ $plays = intval(get_post_meta($id, "_kgflashmediaplayer-starts", true));
639
+ $ends = intval(get_post_meta($id, "_kgflashmediaplayer-completeviews", true));
640
+ if ( $query_atts['title'] == "true" ) {
641
+ $query_atts['title'] = $attachment_info->post_title;
642
+ $stats_title = $query_atts['title'];
643
  }
644
+ else { $stats_title = $attachment_info->post_title; }
645
+ if ( empty($query_atts['caption']) ) { $query_atts['caption'] = $attachment_info->post_excerpt; }
646
+ if ( empty($query_atts['description']) ) { $query_atts['description'] = $attachment_info->post_content; }
647
+ }
648
+ else { //video is not in the database
649
+ $div_suffix = substr(uniqid(rand(), true),0,4);
650
+ $encodevideo_info = kgvid_encodevideo_info($content, $post_ID); //send the id of the post the video's embedded in
651
+ if ( $query_atts['title'] == "true" ) {
652
+ $query_atts['title'] = "false";
653
  }
654
+ $stats_title = basename($content);
655
+ if ( $query_atts['embedcode'] == "true" ) {
656
+ $query_atts['embedcode'] = "false"; //can't use embed code with videos that are not in the database
 
 
657
  }
658
+ $plays = "not_countable";
659
+ $ends = "not_countable";
660
+ }
 
 
 
 
 
661
 
662
+ if ( in_array($moviefiletype, $compatible) ) {
663
  $encodevideo_info["original_exists"] = true;
664
  $encodevideo_info["originalurl"] = $content;
665
  }
666
  else { $encodevideo_info["original_exists"] = false; }
667
 
668
+ if ( $options['embed_method'] == "Strobe Media Playback" ) {
669
+
670
+ $video_swf = plugins_url('', __FILE__)."/flash/StrobeMediaPlayback.swf";
671
+ $minimum_flash = "10.1.0";
672
+
673
+ if ( in_array($moviefiletype, $flashcompatible) ) { //if the original video is Flash video player compatible
674
+ $flashvars = "{src:'".urlencode($content)."'";
675
+ $flash_source_found = true;
676
+ }
677
+ else {
678
+ $flash_source_found = false;
679
+ foreach ($video_formats as $name => $type) { //check if there's an H.264 format available and pick the highest quality one
680
+ if ( $encodevideo_info[$name."_exists"] && $type == "mp4" ) {
681
+ $flashvars = "{src:'".urlencode(trim($encodevideo_info[$name.'url']))."'";
682
+ $flash_source_found = true;
683
+ break;
684
+ }
685
+ }
686
+ }
687
+ if ( $flash_source_found ) {
688
+ if($query_atts["poster"] != '') { $flashvars .= ", poster:'".urlencode(trim($query_atts["poster"]))."'"; }
689
+ if($query_atts["endOfVideoOverlaySame"] == "true") { $query_atts["endOfVideoOverlay"] = $query_atts["poster"]; }
690
+ if($query_atts["endOfVideoOverlay"] != '') { $flashvars .= ", endOfVideoOverlay:'".urlencode(trim($query_atts["endOfVideoOverlay"]))."'"; }
691
+ if($query_atts["controlbar"] != '') { $flashvars .= ", controlBarMode:'".$query_atts["controlbar"]."'"; }
692
+ if($query_atts["autohide"] != '') { $flashvars .= ", controlBarAutoHide:'".$query_atts["autohide"]."'"; }
693
+ if($query_atts["playbutton"] != '') { $flashvars .= ", playButtonOverlay:'".$query_atts["playbutton"]."'"; }
694
+ if($query_atts["loop"] != '') { $flashvars .= ", loop:'".$query_atts["loop"]."'"; }
695
+ if($query_atts["autoplay"] != '') { $flashvars .= ", autoPlay:'".$query_atts["autoplay"]."'"; }
696
+ if($query_atts["streamtype"] != '') { $flashvars .= ", streamType:'".$query_atts["streamtype"]."'"; }
697
+ if($query_atts["scalemode"] != '') { $flashvars .= ", scaleMode:'".$query_atts["scalemode"]."'"; }
698
+ if($query_atts["backgroundcolor"] != '') { $flashvars .= ", backgroundColor:'".$query_atts["backgroundcolor"]."'"; }
699
+ if($query_atts["configuration"] != '') { $flashvars .= ", configuration:'".urlencode($query_atts["configuration"])."'"; }
700
+ if($query_atts["skin"] != '') { $flashvars .= ", skin:'".urlencode($query_atts["skin"])."'"; }
701
+ $flashvars .= ", verbose:'true', javascriptCallbackFunction:'function(id){ var player=document.getElementById(id); if ( player.getState() == \"buffering\" || player.getState() == \"playing\" ) { kgvid_video_counter(\"".$div_suffix."\", ".$plays.", ".$ends.", \"play\"); } }'"; //apparently this is necessary to turn on the js API
702
+ $flashvars .= "}";
703
+
704
+ $params = "{wmode:'opaque', allowfullscreen:'true', allowScriptAccess:'always', base:'".plugins_url("", __FILE__)."/flash/'}";
705
+ }
706
+ } //if Strobe Media Playback
707
 
708
+ $sources = array();
709
  foreach ($video_formats as $name => $type) {
710
+ if ( $name != "original" && $encodevideo_info[$name."url"] == $content ) { unset($sources['original']); }
711
+ if ( $encodevideo_info[$name."_exists"] ) { $sources[$name] = "<source src='".$encodevideo_info[$name."url"]."' type='video/".$type."'>";
712
  }
713
  }
714
 
715
+ if ( $query_atts['align'] != "left" ) {
716
+ $aligncode = ' style="margin-left:auto; ';
717
+ if ( $query_atts['align'] == "center" ) { $aligncode .= 'margin-right:auto;'; }
718
+ $aligncode .= '" ';
719
+ }
720
+ else { $aligncode = ""; }
721
+
722
  $code = "";
723
 
724
+ $code .= '<div id="kgvid_'.$div_suffix.'_wrapper" class="kgvid_wrapper"'.$aligncode.'>';
725
+ $code .= '<div id="video_'.$div_suffix.'_div" class="kgvid_videodiv" itemscope itemtype="http://schema.org/VideoObject">';
726
+ if ( $query_atts["poster"] != '' ) { $code .= '<meta itemprop="thumbnailURL" content="'.$query_atts["poster"].'" />'; }
727
+ if ( !empty($id) ) { $schema_embedURL = site_url('/')."?attachment_id=".$id."&amp;kgvid_video_embed[enable]=true"; }
728
+ else { $schema_embedURL = $content; }
729
+ $code .= '<meta itemprop="embedURL" content="'.$schema_embedURL.'" />';
730
+
731
+ if ( !empty($query_atts['title']) ) { $code .= '<meta itemprop="name" content="'.$query_atts['title'].'" />'; }
732
+ if ( !empty($query_atts['description']) ) { $description = $query_atts['description']; }
733
+ elseif ( !empty($query_atts['caption']) ) { $description = $query_atts['caption']; }
734
+ else { $description = ""; }
735
+ if ( !empty($description) ) { $code .= '<meta itemprop="description" content="'.esc_attr($description).'" />'; }
736
+
737
  $code .= "<video id=\"video_".$div_suffix."\" ";
738
+ if ( $query_atts["loop"] == 'true') { $code .= "loop " ;}
739
+ if ( $query_atts["autoplay"] == 'true') { $code .= "autoplay " ;}
740
+ if ( $query_atts["controlbar"] != 'none') { $code .= "controls " ;}
741
  $code .= "preload='metadata' ";
742
+ if ( $query_atts["poster"] != '' ) { $code .= "poster='".$query_atts["poster"]."' "; }
743
  $code .= "width='".$query_atts["width"]."' height='".$query_atts["height"]."'";
744
+ $code .= " class='video-js ".$options['js_skin']."' data-setup='{}'";
 
 
 
 
 
745
  $code .= ">\n";
746
 
747
+ $code .= implode("\n", $sources); //add the <source> tags created earlier
748
+
 
 
 
 
 
 
 
 
 
 
 
 
 
749
  $code .= "</video>\n";
750
+ $show_views = false;
751
+ $code .= "</div>";
752
+ if ( !empty($id) || !empty($query_atts['caption']) || $content == plugins_url('/images/sample-video-h264.mp4', __FILE__) ) { //generate content below the video
753
+ $view_count = number_format(intval(get_post_meta($id, "_kgflashmediaplayer-starts", true)));
754
+ if ( empty($view_count) ) { $view_count = "0"; }
755
+ if ( $content == plugins_url('/images/sample-video-h264.mp4', __FILE__) ) { $view_count = "XX"; }
756
+ if ( $query_atts['view_count'] == "true" ) { $show_views = true; }
757
+ if ( !empty($query_atts['caption']) || $show_views ) {
758
+ $code .= '<div class="kgvid_below_video" id="video_'.$div_suffix.'_below">';
759
+ if ( !empty($query_atts['caption']) ) { $code .= '<div class="kgvid-caption" id="video_'.$div_suffix.'_caption">'.$query_atts['caption'].'</div>'; }
760
+ if ( $show_views ) { $code .= '<div class="kgvid-viewcount" id="video_'.$div_suffix.'_viewcount">'.$view_count.' views</div>'; }
761
+ $code .= '</div>';
762
+ }
763
+ }
764
 
765
+ if ( $query_atts['title'] != "false" || $query_atts['embedcode'] != "false" ) { //generate content overlaid on video
766
+ $kgvid_meta = true;
767
+ $code .= "<div style=\"display:none;\" id=\"video_".$div_suffix."_meta\" class=\"kgvid_video_meta kgvid_video_meta_hover\">";
768
+ if ( $query_atts['title'] != "false" ) {
769
+ $code .= "<div id='video_".$div_suffix."_title' class='kgvid_title'>".$query_atts['title']."</div>";
770
  }
771
+ if ( $query_atts['embedcode'] != "false" ) {
772
+ if ( $query_atts['embedcode'] == "true" ) { $iframeurl = site_url('/')."?attachment_id=".$id."&amp;kgvid_video_embed[enable]=true"; }
773
+ else { $iframeurl = $query_atts['embedcode']; }
774
+ $iframecode = "<iframe src='".$iframeurl."' frameborder='0' scrolling='no' width='".$query_atts['width']."' height='".$query_atts["height"]."'></iframe>";
775
+ $code .= "<div id=\"video_".$div_suffix."_embed\" class=\"kgvid_share\"><span>Embed: </span><input type=\"text\" value=\"".$iframecode."\" onClick=\"this.select();\"></div>";
776
  }
777
+ $code .= "</div>";
778
+ }
779
+ else { $kgvid_meta = false; }
780
+ if ( !empty($query_atts["watermark"]) ) { $code .= "<div style=\"display:none;\" id='video_".$div_suffix."_watermark' class='kgvid_watermark'><img src='".$query_atts["watermark"]."' alt='watermark'></div>"; } //generate watermark
781
+ $code .= "</div>"; //end kgvid_XXXX_wrapper div
782
+
783
+ if ( $query_atts['autoplay'] == "true" ) { $timeout = "0"; }
784
+ else { $timeout = "500"; }
785
 
786
+ $code .= "<script type='text/javascript'>
787
+ var player_type = '".$options['embed_method']."';";
788
+ if ( $options['embed_method'] == "Video.js" || ($options['embed_method'] == "Strobe Media Playback" && !$flash_source_found) ) {
789
+ $code .= "\n\t\t\t"."_V_('video_".$div_suffix."').ready(function(){
790
+ kgvid_setup_video('".$div_suffix."', player_type, '".$query_atts["volume"]."');
791
+ this.addEvent('play', function(){";
792
+ if ( $kgvid_meta ) {
793
+ $code .= "\n\t\t\t"."jQuery('#video_".$div_suffix."_div').hover(function(){ jQuery('#video_".$div_suffix."_meta').addClass('kgvid_video_meta_hover'); },function(){ jQuery('#video_".$div_suffix."_meta').removeClass('kgvid_video_meta_hover'); });
794
+ jQuery('#video_".$div_suffix."_meta').removeClass('kgvid_video_meta_hover');";
795
+ } //end if kgvid_meta
796
+ $code .= "\n\t\t\t"."setTimeout(function() { _V_('video_".$div_suffix."').controlBar.fadeOut(); }, ".$timeout.");
797
+ kgvid_video_counter('".$div_suffix."', '".$plays."', '".$ends."', 'play', '".esc_js($stats_title)."');
798
  });
799
+ this.addEvent('ended', function(){
800
+ kgvid_video_counter('".$div_suffix."', '".$plays."', '".$ends."', 'end', '".esc_js($stats_title)."');
801
+ setTimeout(function() { jQuery('#video_".$div_suffix." > .vjs-loading-spinner').hide(); }, 250);
802
  });
803
+ });";
 
804
  }
805
+ if ( $options['embed_method'] == "Strobe Media Playback" && $flash_source_found ) {
806
+ $code .= "swfobject.embedSWF('".$video_swf."', 'video_".$div_suffix."', '".trim($query_atts['width'])."', '".trim($query_atts['height'])."', '".$minimum_flash."', '".plugins_url("", __FILE__)."/flash/expressInstall.swf', $flashvars, $params, '', function() {
807
+ kgvid_setup_video('".$div_suffix."', player_type, '".$query_atts["volume"]."');
808
+ kgvid_resize_video('".$div_suffix."', player_type, '".$query_atts["width"]."', '".$query_atts["height"]."');
809
+ });
810
+ jQuery('#kgvid_".$div_suffix."_wrapper').hover(
811
+ function() { jQuery('#video_".$div_suffix."_watermark').fadeOut(100); },
812
+ function() { setTimeout(function(){jQuery('#video_".$div_suffix."_watermark').fadeIn('slow');},3000); }
813
+ );";
 
 
 
814
  }
815
+ $code .= "\n\t\t\t"."var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false );
816
+ if (iOS) {
817
+ if ( player_type == 'Strobe Media Playback' ) { kgvid_setup_video('".$div_suffix."', 'Video.js', '".$query_atts["volume"]."'); }
818
+ kgvid_ios_player('".$div_suffix."');
819
+ player_type = 'iOS';
820
+ document.getElementById('video_".$div_suffix."').addEventListener('play',function(){
821
+ jQuery('#video_".$div_suffix."_meta').removeClass('kgvid_video_meta_hover');
822
+ kgvid_video_counter('".$div_suffix."', '".$plays."', '".$ends."', 'play', '".esc_js($stats_title)."');
823
+ });
824
+ }
825
+ kgvid_resize_video('".$div_suffix."', player_type, '".$query_atts["width"]."', '".$query_atts["height"]."');
826
+ window.addEventListener('resize', resize_".$div_suffix."=function(){ kgvid_resize_video('".$div_suffix."', '".$options['embed_method']."', '".$query_atts["width"]."', '".$query_atts["height"]."'); }, false);
827
+ </script>";
828
 
829
  } //if not gallery
830
 
831
  else { //if gallery
832
+ $thumbnail_aspect = false;
833
  $code = "";
834
+ $args = array(
835
+ 'post_type' => 'attachment',
836
+ 'orderby' => $query_atts['gallery_orderby'],
837
+ 'order' => $query_atts['gallery_order'],
838
+ 'post_mime_type' => 'video',
839
+ 'numberposts' => -1,
840
+ 'post_status' => null,
841
+ 'post_parent' => $post_ID,
842
+ 'exclude' => $query_atts['gallery_exclude']
843
+ );
844
  if ( !empty($query_atts['gallery_include']) ) { $args['include'] = $query_atts['gallery_include']; }
845
  $attachments = get_posts($args);
846
  if ($attachments) {
847
+
848
+ $div_suffix = substr(uniqid(rand(), true),0,4);
849
+ $code .= '<div class="kgvid_gallerywrapper">';
850
  foreach ( $attachments as $attachment ) {
851
  $thumbnail_url = get_post_meta($attachment->ID, "_kgflashmediaplayer-poster", true);
852
+ $poster_id = get_post_meta($attachment->ID, '_kgflashmediaplayer-poster-id', true);
853
+ if ( !empty($poster_id) && intval($query_atts['gallery_thumb']) <= get_option('medium_size_h') ) {
854
+ $poster_post = get_post($poster_id);
855
+ if ( $poster_post->guid == $thumbnail_url ) {
856
+ $thumbnail_url = kgvid_get_attachment_medium_url($poster_id);
857
+ $thumbnail_info = wp_get_attachment_image_src($poster_id);
858
+ $thumbnail_aspect = round($thumbnail_info[2]/$thumbnail_info[1], 4); //height/width
859
+ } //use the "medium" size image if available
860
+ }
861
+ if (!$thumbnail_url) { $thumbnail_url = $options['poster']; } //use the default poster if no thumbnail set
862
+ if (!$thumbnail_url) { $thumbnail_url = plugins_url('/images/nothumbnail.jpg', __FILE__);} //use the blank image if no other option
863
 
864
  $video_width = get_post_meta($attachment->ID, "_kgflashmediaplayer-actualwidth", true);
865
  if ( !$video_width ) { $video_width = get_post_meta($attachment->ID, "_kgflashmediaplayer-width", true); }
869
  if ( !$video_height ) { $video_height = get_post_meta($attachment->ID, "_kgflashmediaplayer-height", true); }
870
  if ( !$video_height || $video_height > intval($options['gallery_height']) ) { $video_height = $options['gallery_height']; }
871
 
872
+ if ( !$thumbnail_aspect ) { $thumbnail_aspect = round($video_height/$video_width, 4); } //if the thumbnail's not an attachment, set the aspect ratio to the video's
873
+
874
+ $play_offset_left = strval(intval($query_atts["gallery_thumb"])/2-21);
875
+ $play_offset_top = strval((intval($query_atts["gallery_thumb"])*$thumbnail_aspect/2)-30);
876
+ $play_scale = strval( round(intval($query_atts["gallery_thumb"])/600,2) );
877
+
878
+ $code .= '<div onclick="kgvid_SetVideo(\''.$div_suffix.'\', \''.site_url('/').'\', \''.$attachment->ID.'\', \''.$video_width.'\', \''.$video_height.'\');return false;" class="kgvid_video_gallery_thumb" style="width:'.$query_atts["gallery_thumb"].'px"><img src="'.$thumbnail_url.'"><div class="'.$options['js_skin'].'" ><div class="vjs-big-play-button" style="-webkit-transform: scale('.$play_scale.'); -o-transform: scale('.$play_scale.'); -ms-transform: scale('.$play_scale.'); transform: scale('.$play_scale.'); top: '.$play_offset_top.'px; left: '.$play_offset_left.'px;"><span></span></div></div><div class="titlebackground"><div class="videotitle">'.$attachment->post_title.'</div></div></div>'."\n\t\t\t";
879
  }
880
+
881
+ $code .= '</div>'; //end wrapper div
882
+ $code .= '<div id="kgvid_GalleryPlayerDiv_'.$div_suffix.'"></div>';
883
  $code .= '<script type="text/javascript">jQuery(document).ready(function() {
884
+ jQuery(\'#kgvid_GalleryPlayerDiv_'.$div_suffix.'\').dialog({
885
+ zIndex: 1000,
886
  autoOpen: false,
887
  modal: true,
888
  resizable: false,
894
  jQuery(\'.ui-widget-overlay\').wrap(\'<div class="kgvid_gallery" />\');
895
  },
896
  close: function(event, ui){
897
+ jQuery(\'#kgvid_GalleryPlayerDiv_'.$div_suffix.'\').empty();
898
  jQuery(".kgvid_gallery").filter(function(){
899
  if (jQuery(this).text() == "") { return true; }
900
  return false;
901
  }).remove();
902
  }
903
  });
 
904
  }); </script>';
905
 
906
  } //if there are attachments
948
  $post_mime_type = "";
949
  $actualwidth = "1921";
950
  $actualheight = "1081";
951
+ $rotated = false;
952
  $encodevideo_info = array();
953
 
954
  if ( !empty($movieurl) ) {
955
+
956
  $encodevideo_info = kgvid_encodevideo_info($movieurl, $post_id);
957
+ $sanitized_url = kgvid_sanitize_url($movieurl);
958
+ $movieurl = $sanitized_url['movieurl'];
959
+ if ( get_post_type($post_id) == "attachment" ) { //if the video is in the database
960
  $post_mime_type = get_post_mime_type($post_id);
 
961
  $actualwidth = get_post_meta($post_id, "_kgflashmediaplayer-actualwidth", true);
962
  $actualheight = get_post_meta($post_id, "_kgflashmediaplayer-actualheight", true);
963
+ $rotated = get_post_meta($post_id, "_kgflashmediaplayer-rotate", true);
964
  }
965
+ else { //video's not in the database
966
 
967
+ $post_mime_type = "video/".pathinfo($movieurl, PATHINFO_EXTENSION);
 
968
 
969
  if ( !empty($video_embed_queue) ) {
970
  foreach ($video_embed_queue as $video_key => $video_entry) {
972
  if ( array_key_exists('movie_info', $video_entry) ) {
973
  $actualwidth = $video_entry['movie_info']['width'];
974
  $actualheight = $video_entry['movie_info']['height'];
975
+ $rotated = $video_entry['movie_info']['rotate'];
976
  }
977
  break;
978
  }
981
  reset($video_embed_queue);
982
 
983
  if ( $page == "queue" ) {
984
+ //$info = pathinfo($movieurl);
985
+ //$post_id = 'singleurl_'.sanitize_title_with_dashes(urldecode(basename($movieurl,'.'.$info['extension'])));
986
  }
987
  }
988
+ if ( $post_mime_type == "video/m4v" || $post_mime_type == "video/quicktime" ) { $post_mime_type = "video/mp4"; }
989
  }
990
  else {
991
  $encode_disabled = ' disabled title="Please enter a valid video URL"';
997
  else { $ffmpeg_disabled_text = ""; }
998
 
999
  $video_key = false;
1000
+ $rotated_queue = false;
1001
  if ( !empty($video_embed_queue) && !empty($movieurl) ) {
1002
  foreach ($video_embed_queue as $video_key => $video_entry) {
1003
  if ( $video_entry['movieurl'] == $movieurl ) {
1004
  foreach ( $video_entry['encode_formats'] as $format => $value ) {
1005
  $video_formats[$format]['status'] = $value['status'];
1006
+ if ( $format == "rotated" && $value['status'] != 'notchecked') {
1007
+ $rotated_queue = true;
1008
+ }
1009
  }
1010
  $video_queued = true;
1011
  break;
1012
  }
1013
  }
1014
  }
1015
+
1016
+ if ( (!$rotated && !$rotated_queue) || $post_mime_type != "video/mp4" ) { unset($video_formats['rotated']); }
1017
+
1018
  $checkboxes = '<div id="attachments-'.$post_id.'-kgflashmediaplayer-encodeboxes">';
1019
  foreach ( $video_formats as $format => $format_stats ) {
1020
+ if ( strpos($post_mime_type, $format) !== false ) { continue; } //skip webm or ogv checkbox if the video is webm or ogv
1021
  $encodeset[$format] = "";
1022
  $checked[$format] = "";
1023
  $meta[$format] = "";
1024
  $disabled[$format] = "";
1025
+ $child_id[$format] = "";
1026
 
1027
  if ( !array_key_exists('status', $format_stats) ) { $format_stats['status'] = "notchecked"; } //if this video isn't in the queue
1028
 
1029
+ if ( get_post_type($post_id) == "attachment" ) { $encodeset[$format] = get_post_meta($post_id, "_kgflashmediaplayer-encode".$format, true); }
1030
+ if ( $encodeset[$format] == "" && $format != "rotated" ) { $encodeset[$format] = $options['encode_'.$format]; }
1031
+
1032
+ if ( $format_stats['status'] == "lowres" || ( $actualheight != "" && ($format == "1080" || $format == "720") && ( (strpos($post_mime_type, "mp4") !== false && $actualheight <= $format_stats['height']) || (strpos($post_mime_type, "mp4") === false && $actualheight < $format_stats['height']) ) ) ) { continue; } //if the format is bigger than the original video, skip the checkbox
1033
 
1034
  if ( $encodeset[$format] == "on" || $format_stats['status'] == "queued" ) { $checked[$format] = 'checked'; }
1035
 
1039
  $meta[$format] .= ': <span style="color:red;">'.$video_embed_queue[$video_key]['encode_formats'][$format]['lastline']."</span>";
1040
  }
1041
  }
1042
+
1043
  if ( !empty($encodevideo_info) ) {
1044
  if ( $encodevideo_info[$format.'_exists'] ) { //if the video file exists
1045
  if ( $format_stats['status'] != "encoding" ) { // not currently encoding
1046
  if ( $format_stats['status'] == "notchecked" ) { $meta[$format] = ' <strong>Encoded</strong>'; }
1047
+ if ( $format_stats['status'] != "canceling" ) {
1048
+ if ( array_key_exists($format.'id', $encodevideo_info) ) { $child_id[$format] = $encodevideo_info[$format.'id']; }
1049
+ if ( $encodevideo_info[$format.'_writable'] ) { $meta[$format] .= '<a id="delete-'.$post_id.'-'.$format.'" class="kgvid_delete-format" onclick="kgvid_delete_video(\''.$movieurl.'\', \''.$post_id.'\', \''.$format.'\', \''.$child_id[$format].'\');" href="javascript:void(0)">Delete Permanently</a>'; }
1050
+ }
1051
  $disabled[$format] = ' disabled title="Format already exists"';
1052
  $checked[$format] = '';
1053
+ }
 
 
 
 
 
 
 
 
1054
  }
1055
+ else { $something_to_encode = true; } //if the video file doesn't exist, there's something to encode
1056
  }
1057
 
1058
+ if ( $format_stats['status'] == "encoding" ) {
1059
+ $encoding_now = true;
1060
+ $disabled[$format] = ' disabled title="Currently Encoding"';
1061
+ $checked[$format] = 'checked';
1062
+ $progress = kgvid_encode_progress($video_key, $format, $page);
1063
+ $meta[$format] = $progress['embed_display'];
1064
+ }
1065
+
1066
+ if ( $format_stats['status'] == "Encoding Complete" ) {
1067
+ $disabled[$format] = ' disabled title="Format already exists"';
1068
+ $checked[$format] = '';
1069
+ }
1070
+
1071
+ if ( $checked[$format] == '' ) { $something_to_encode = true; }
1072
 
1073
  $checkboxes .= "\n\t\t\t".'<input type="checkbox" id="attachments-'.$post_id.'-kgflashmediaplayer-encode'.$format.'" name="attachments['.$post_id.'][kgflashmediaplayer-encode'.$format.']" '.$checked[$format].' '.$ffmpeg_disabled_text.$disabled[$format].'> <label for="attachments-'.$post_id.'-kgflashmediaplayer-encode'.$format.'">'.$format_stats['name'].'</label> <span id="attachments-'.$post_id.'-kgflashmediaplayer-meta'.$format.'">'.$meta[$format].'</span><br />';
1074
 
1077
  $encode_disabled = ' disabled title="Nothing to encode" style="display:none;"';
1078
  }
1079
 
1080
+ if ( $page == "queue" ) {
1081
+ $button_text = "Update";
1082
+ $checkboxes .= "\n\t\t\t".'<input type="hidden" name="attachments['.$post_id.'][kgflashmediaplayer-url]" value="'.$movieurl.'">';
1083
+ }
1084
  else { $button_text = "Encode"; }
1085
 
1086
+ $checkboxes .= '<input type="button" id="attachments-'.$post_id.'-kgflashmediaplayer-encode" name="attachments['.$post_id.'][kgflashmediaplayer-encode]" class="button-secondary" value="'.$button_text.'" onclick="kgvid_enqueue_video_encode(\''.$post_id.'\');" '.$ffmpeg_disabled_text.$encode_disabled.'/><div style="display:block;" id="attachments-'.$post_id.'-encodeplaceholder"></div>';
1087
 
1088
  if ( $page != "queue" ) {
1089
  $checkboxes .= '<small><em>Generates additional video formats compatible with most mobile & HTML5-compatible browsers.</em></small>';
1128
  }
1129
  else { $currently_encoding[$order] = false; }
1130
  }
1131
+ $html .= ">";
1132
  $html .= "<td id='td_".$video_entry['attachmentID']."'>".strval(intval($order)+1)."</td>\n";
1133
  $thumbnail_url = get_post_meta($video_entry['attachmentID'], "_kgflashmediaplayer-poster", true);
1134
  $thumbnail_html = "";
1135
  if ($thumbnail_url != "" ) {
1136
  $thumbnail_html = '<img width="100" src="'.$thumbnail_url.'">';
1137
  }
1138
+ if ( get_post_type($video_entry['attachmentID']) == "attachment" ) {
1139
  $moviefilepath = get_attached_file($video_entry['attachmentID']);
1140
  $attachmentlink = "media.php?attachment_id=".$video_entry['attachmentID']."&action=edit";
1141
  }
1144
  $attachmentlink = $video_entry['movieurl'];
1145
  }
1146
  $html .= "\t\t\t\t\t<td><a href='".$attachmentlink."'> ".$thumbnail_html."</a></td>\n";
1147
+ $html .= "\t\t\t\t\t<td><a id='".$moviefilepath."' href='".$attachmentlink."'>".urldecode(basename($moviefilepath))."</a><input type='hidden' name='attachments[".$video_entry['attachmentID']."][kgflashmediaplayer-url]' value='".$video_entry['movieurl']."'></td>\n";
1148
  $html .= "\t\t\t\t\t<td class='queue_encode_formats' id='formats_".$video_entry['attachmentID']."'>";
1149
+ $html .= "<input type='hidden' name='attachments[".$video_entry['attachmentID']."][kgflashmediaplayer-security]' value='".$nonce."' />";
1150
  $html .= kgvid_generate_encode_checkboxes($video_entry['movieurl'], $video_entry['attachmentID'], 'queue');
1151
  $html .= "</td>\n";
1152
  $html .= "\t\t\t\t\t<td>";
1174
 
1175
  ?>
1176
  <div class="wrap">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1177
  <div id="icon-tools" class="icon32"><br /></div>
1178
  <h2>Video Embed & Thumbnail Generator Encoding Queue</h2>
1179
  <p></p>
1216
  add_action('admin_menu', 'kgvid_addFMPOptionsPage');
1217
 
1218
  function kgvid_FMPOptionsPage() {
1219
+ $options = get_option('kgvid_video_embed_options');
1220
+ ?>
1221
  <div class="wrap">
1222
  <div class="icon32" id="icon-options-general"><br></div>
1223
  <h2>Video Embed & Thumbnail Generator</h2>
1224
  <form method="post" action="options.php">
1225
  <?php settings_fields('kgvid_video_embed_options'); ?>
1226
+ <input type="hidden" id="kgvid_settings_security" value="<?php echo wp_create_nonce('video-embed-thumbnail-generator-nonce'); ?>">
1227
  <?php do_settings_sections(__FILE__); ?>
1228
  <p class='submit'>
1229
+ <?php submit_button('Save Changes', 'primary', 'kgvid_submit', false); ?>
1230
  <?php submit_button('Reset Options', 'secondary', 'video-embed-thumbnail-generator-reset', false); ?>
1231
  </p>
1232
  </form>
1233
+ <?php echo "<script type='text/javascript'>
 
 
1234
  jQuery(document).ready(function() {
1235
+ jQuery('#app_path').data('ffmpeg_exists', '".$options['ffmpeg_exists']."');
1236
+ kgvid_hide_plugin_settings();
1237
+ kgvid_hide_ffmpeg_settings();
1238
+ jQuery('form :input').change(function() {
1239
+ kgvid_save_plugin_settings(this);
1240
+ });
1241
  }
1242
  );
1243
+ </script>"; ?>
1244
  </div>
1245
  <?php
1246
  }
1250
  register_setting('kgvid_video_embed_options', 'kgvid_video_embed_options', 'kgvid_video_embed_options_validate' );
1251
 
1252
  $options = get_option('kgvid_video_embed_options');
1253
+
 
1254
  add_settings_section('kgvid_video_embed_playback_settings', 'Default Video Playback Settings', 'kgvid_plugin_playback_settings_section_callback', __FILE__);
1255
  add_settings_section('kgvid_video_embed_flash_settings', 'The following options will only affect Flash playback', 'kgvid_plugin_flash_settings_section_callback', __FILE__);
1256
+ add_settings_section('kgvid_video_embed_plugin_settings', 'Plugin Settings', 'kgvid_plugin_settings_section_callback', __FILE__);
1257
+
 
 
 
 
 
 
 
 
 
 
1258
  add_settings_field('poster', 'Poster image:', 'kgvid_poster_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'poster' ) );
1259
  add_settings_field('watermark', 'Watermark image:', 'kgvid_watermark_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'watermark' ) );
1260
+ add_settings_field('align', 'Video alignment:', 'kgvid_align_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'align' ) );
1261
+ add_settings_field('dimensions', 'Max embedded video dimensions:', 'kgvid_dimensions_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'width' ) );
1262
+ add_settings_field('gallery_dimensions', 'Max gallery video dimensions:', 'kgvid_gallery_dimensions_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'gallery_width' ) );
 
1263
  add_settings_field('gallery_thumb', 'Gallery thumbnail width:', 'kgvid_gallery_thumb_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'gallery_thumb' ) );
1264
  add_settings_field('controlbar_style', 'Controlbar style:', 'kgvid_controlbar_style_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'controlbar_style' ) );
1265
+ add_settings_field('autoplay', 'Autoplay:', 'kgvid_autoplay_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'autoplay' ) );
1266
+ add_settings_field('loop', 'Loop:', 'kgvid_loop_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'loop' ) );
1267
  add_settings_field('js_skin', 'Skin Class:', 'kgvid_js_skin_callback', __FILE__, 'kgvid_video_embed_playback_settings', array( 'label_for' => 'js_skin' ) );
1268
+
1269
  add_settings_field('endOfVideoOverlay', 'End of video image:', 'kgvid_endOfVideoOverlay_callback', __FILE__, 'kgvid_video_embed_flash_settings' );
1270
  add_settings_field('bgcolor', 'Background color:', 'kgvid_bgcolor_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'bgcolor' ) );
1271
  add_settings_field('configuration', 'XML configuration file:', 'kgvid_configuration_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'configuration' ) );
1272
  add_settings_field('skin', 'Video skin file:', 'kgvid_skin_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'skin' ) );
1273
  add_settings_field('stream_type', 'Video stream type:', 'kgvid_stream_type_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'stream_type' ) );
1274
  add_settings_field('scale_mode', 'Video scale mode:', 'kgvid_scale_mode_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'scale_mode' ) );
1275
+ add_settings_field('autohide', 'Autohide:', 'kgvid_autohide_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'autohide' ) );
1276
  add_settings_field('playbutton', 'Play button overlay:', 'kgvid_playbutton_callback', __FILE__, 'kgvid_video_embed_flash_settings', array( 'label_for' => 'playbutton' ) );
1277
+
1278
+ add_settings_field('app_path', 'Path to applications on server:', 'kgvid_app_path_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'app_path' ) );
1279
+ add_settings_field('video_app', 'Application for thumbnails & encoding:', 'kgvid_video_app_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'video_app' ) );
1280
+ add_settings_field('encode_formats', 'Default Mobile/HTML5 Video encode formats:', 'kgvid_encode_formats_callback', __FILE__, 'kgvid_video_embed_plugin_settings');
1281
+ add_settings_field('ffmpeg_options', 'FFMPEG Options:', 'kgvid_ffmpeg_options_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'video_bitrate_flag' ) );
1282
+ add_settings_field('moov', 'Application to fix encoded H.264 headers for streaming:', 'kgvid_moov_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'moov' ) );
1283
+ add_settings_field('generate_thumbs', 'Default number of thumbnails to generate:', 'kgvid_generate_thumbs_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'generate_thumbs' ) );
1284
+ add_settings_field('featured', 'Featured Image:', 'kgvid_featured_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'featured' ) );
1285
+ add_settings_field('thumb_parent', 'Attach thumbnails to:', 'kgvid_thumb_parent_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'thumb_parent' ) );
1286
+ add_settings_field('delete_children', 'Delete associated attachments:', 'kgvid_delete_children_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'delete_children' ) );
1287
+ add_settings_field('titlecode', 'Video title text HTML formatting:', 'kgvid_titlecode_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'titlecode' ) );
1288
+ add_settings_field('template', 'Attachment template display:', 'kgvid_template_callback', __FILE__, 'kgvid_video_embed_plugin_settings', array( 'label_for' => 'template' ) );
1289
  }
1290
  add_action('admin_init', 'kgvid_video_embed_options_init' );
1291
 
1292
+ //callback functions generating HTML for the settings form
1293
+
1294
+ function kgvid_plugin_playback_settings_section_callback() {
1295
+ $options = get_option('kgvid_video_embed_options');
1296
+
1297
+ $items = array("Strobe Media Playback", "Video.js");
1298
+ echo "<table class='form-table'><tbody><tr valign='middle'><th scope='row'><label for='embed_method'>Video player:</label></th><td><select onchange='kgvid_hide_plugin_settings();' id='embed_method' name='kgvid_video_embed_options[embed_method]'>";
1299
+ foreach($items as $item) {
1300
+ $selected = ($options['embed_method']==$item) ? 'selected="selected"' : '';
1301
+ echo "<option value='$item' $selected>$item</option>";
1302
+ }
1303
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>This plugin has used Strobe Media Playback for Flash playback in the past, but you can choose to use the newer and lighter Video-js method which will give priority to HTML5 and only use Flash as a fallback.</span></a></td></tr></tbody></table>";
1304
+
1305
+ $sampleheight = intval($options['height']) + 25;
1306
+ echo "<div class='kgvid_setting_nearvid' style='width:".$options['width']."px;'>";
1307
+ echo "<div style='float:left;'><input ".checked( $options['overlay_title'], "on", false )." id='overlay_title' name='kgvid_video_embed_options[overlay_title]' type='checkbox' /> <label for='overlay_title'>Overlay video title</label></div>";
1308
+ echo "<div style='float:right;'><input ".checked( $options['overlay_embedcode'], "on", false )." id='overlay_embedcode' name='kgvid_video_embed_options[overlay_embedcode]' type='checkbox' /> <label for='overlay_embedcode'>Overlay embed code</label></div>";
1309
+ $iframeurl = site_url('/')."?kgvid_video_embed[enable]=true&kgvid_video_embed[sample]=true";
1310
+ echo "<iframe id='kgvid_samplevideo' style='border:2px;' src='".$iframeurl."' scrolling='no' width='".$options['width']."' height='".$sampleheight."'></iframe>";
1311
+ echo "<div style='float:right;'><input ".checked( $options['view_count'], "on", false )." id='view_count' name='kgvid_video_embed_options[view_count]' type='checkbox' /> <label for='view_count'>Show view count</label></div>";
1312
+ echo "</div>";
1313
+ }
1314
+ function kgvid_plugin_flash_settings_section_callback() { }
1315
+ function kgvid_plugin_settings_section_callback() { }
1316
 
1317
+ function kgvid_poster_callback() {
1318
+ $options = get_option('kgvid_video_embed_options');
1319
+ echo "<input class='regular-text' id='poster' name='kgvid_video_embed_options[poster]' type='text' value='".$options['poster']."' />";
1320
+ }
1321
 
1322
+ function kgvid_watermark_callback() {
1323
+ $options = get_option('kgvid_video_embed_options');
1324
+ echo "<input class='regular-text' id='watermark' name='kgvid_video_embed_options[watermark]' type='text' value='".$options['watermark']."' />";
1325
+ }
1326
 
1327
+ function kgvid_align_callback() {
1328
+ $options = get_option('kgvid_video_embed_options');
1329
+ $items = array("left", "center", "right");
1330
+ echo "<select id='align' name='kgvid_video_embed_options[align]'>";
1331
+ foreach($items as $item) {
1332
+ $selected = ($options['align']==$item) ? 'selected="selected"' : '';
1333
+ echo "<option value='$item' $selected>$item</option>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1334
  }
1335
+ }
1336
+
1337
+ function kgvid_dimensions_callback() {
1338
+ $options = get_option('kgvid_video_embed_options');
1339
+ echo "Width: <input class='small-text' id='width' name='kgvid_video_embed_options[width]' type='text' value='".$options['width']."' /> Height: <input class='small-text' id='height' name='kgvid_video_embed_options[height]' type='text' value='".$options['height']."' />";
1340
+ }
1341
+
1342
+ function kgvid_gallery_dimensions_callback() {
1343
+ $options = get_option('kgvid_video_embed_options');
1344
+ echo "Width: <input class='small-text' id='gallery_width' name='kgvid_video_embed_options[gallery_width]' type='text' value='".$options['gallery_width']."' /> Width: <input class='small-text' id='gallery_height' name='kgvid_video_embed_options[gallery_height]' type='text' value='".$options['gallery_height']."' />";
1345
+ }
1346
+
1347
+ function kgvid_gallery_thumb_callback() {
1348
+ $options = get_option('kgvid_video_embed_options');
1349
+ echo "<input class='small-text' id='gallery_thumb' name='kgvid_video_embed_options[gallery_thumb]' type='text' value='".$options['gallery_thumb']."' />";
1350
+ }
1351
+
1352
+ function kgvid_controlbar_style_callback() {
1353
+ $options = get_option('kgvid_video_embed_options');
1354
+ $items = array("docked", "floating", "none");
1355
+ echo "<select id='controlbar_style' name='kgvid_video_embed_options[controlbar_style]'>";
1356
+ foreach($items as $item) {
1357
+ $selected = ($options['controlbar_style']==$item) ? 'selected="selected"' : '';
1358
+ echo "<option value='$item' $selected>$item</option>";
1359
  }
1360
+ echo "</select> HTML5 video players only respond to the \"none\" option.";
 
1361
  }
1362
 
1363
+ function kgvid_autoplay_callback() {
1364
+ $options = get_option('kgvid_video_embed_options');
1365
+ echo "<input ".checked( $options['autoplay'], "on", false )." id='autoplay' name='kgvid_video_embed_options[autoplay]' type='checkbox' /> <label for='autoplay'>Play automatically when page loads.</label>";
 
 
 
1366
  }
 
 
 
 
 
 
1367
 
1368
+ function kgvid_loop_callback() {
1369
+ $options = get_option('kgvid_video_embed_options');
1370
+ echo "<input ".checked( $options['loop'], "on", false )." id='loop' name='kgvid_video_embed_options[loop]' type='checkbox' /> <label for='loop'>Loop to beginning when video ends.</label>";
1371
  }
 
 
1372
 
1373
+ function kgvid_js_skin_callback() {
1374
+ $options = get_option('kgvid_video_embed_options');
1375
+ echo "<input class='regular-text code' id='js_skin' name='kgvid_video_embed_options[js_skin]' type='text' value='".$options['js_skin']."' /><br /><em><small>Use <code>kg-video-js-skin</code> for a nice, circular play button. Leave blank for the default square play button. <a href='http://videojs.com/docs/skins/'>Or build your own CSS skin.</a></small></em>";
1376
  }
1377
+
1378
+ function kgvid_endOfVideoOverlay_callback() {
1379
+ $options = get_option('kgvid_video_embed_options');
1380
+ echo "<input ".checked( $options['endOfVideoOverlaySame'], "true", false )." id='endOfVideoOverlaySame' name='kgvid_video_embed_options[endOfVideoOverlaySame]' type='checkbox' onclick='if (this.checked == true) { document.getElementById(\"endOfVideoOverlay\").disabled=true; } else { document.getElementById(\"endOfVideoOverlay\").disabled=false; }'/> <label for='endOfVideoOverlaySame'>Display poster image again when video ends.</label><br />";
1381
+ echo "<input class='regular-text' id='endOfVideoOverlay' name='kgvid_video_embed_options[endOfVideoOverlay]' ".disabled( $options['endOfVideoOverlaySame'], "true", false )." type='text' value='".$options['endOfVideoOverlay']."' /> Display alternate image when video ends.<br /><small><em>Leave blank to display the first frame of the video when video ends.</em></small>";
1382
  }
 
1383
 
1384
+ function kgvid_bgcolor_callback() {
1385
+ $options = get_option('kgvid_video_embed_options');
1386
+ echo "<input class='small-text' id='bgcolor' name='kgvid_video_embed_options[bgcolor]' maxlength='7' type='text' value='".$options['bgcolor']."' /> #rrggbb";
1387
+ }
1388
 
1389
+ function kgvid_configuration_callback() {
1390
+ $options = get_option('kgvid_video_embed_options');
1391
+ echo "<input class='regular-text' id='configuration' name='kgvid_video_embed_options[configuration]' type='text' value='".$options['configuration']."' />";
1392
  }
 
 
1393
 
1394
+ function kgvid_skin_callback() {
1395
+ $options = get_option('kgvid_video_embed_options');
1396
+ echo "<input class='regular-text' id='skin' name='kgvid_video_embed_options[skin]' type='text' value='".$options['skin']."' /><br /><em><small>Use <code>".plugins_url("", __FILE__)."/flash/skin/kgvid_skin.xml</code> for a modern, circular play button.<br /> Leave blank for the older style square play button.</small></em>";
1397
+ }
 
 
 
 
1398
 
1399
+ function kgvid_stream_type_callback() {
1400
  $options = get_option('kgvid_video_embed_options');
1401
+ $items = array("liveOrRecorded", "live", "recorded", "dvr");
1402
+ echo "<select id='stream_type' name='kgvid_video_embed_options[stream_type]'>";
1403
  foreach($items as $item) {
1404
+ $selected = ($options['stream_type']==$item) ? 'selected="selected"' : '';
1405
  echo "<option value='$item' $selected>$item</option>";
1406
  }
1407
+ echo "</select>";
1408
  }
1409
+
1410
+ function kgvid_scale_mode_callback() {
1411
  $options = get_option('kgvid_video_embed_options');
1412
+ $items = array("letterbox", "none", "stretch", "zoom");
1413
+ echo "<select id='scale_mode' name='kgvid_video_embed_options[scale_mode]'>";
1414
+ foreach($items as $item) {
1415
+ $selected = ($options['scale_mode']==$item) ? 'selected="selected"' : '';
1416
+ echo "<option value='$item' $selected>$item</option>";
1417
+ }
1418
+ echo "</select>";
1419
  }
1420
 
1421
+ function kgvid_autohide_callback() {
1422
  $options = get_option('kgvid_video_embed_options');
1423
+ echo "<input ".checked( $options['autohide'], "on", false )." id='autohide' name='kgvid_video_embed_options[autohide]' type='checkbox' /> <label for='autohide'>Autohide controlbar.</label>";
1424
+ }
1425
+
1426
+ function kgvid_playbutton_callback() {
1427
+ $options = get_option('kgvid_video_embed_options');
1428
+ echo "<input ".checked( $options['playbutton'], "on", false )." id='playbutton' name='kgvid_video_embed_options[playbutton]' type='checkbox' /> <label for='playbutton'>Overlay play button on poster frame.</label>";
1429
  }
1430
 
1431
  function kgvid_app_path_callback() {
1432
  $options = get_option('kgvid_video_embed_options');
1433
+ echo "<input class='regular-text code' id='app_path' name='kgvid_video_embed_options[app_path]' type='text' value='".stripslashes($options['app_path'])."' /><a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Don't include trailing slash. Example: <code>/usr/local/bin</code>. On Windows servers, use / instead of C:\\";
1434
  }
1435
 
1436
  function kgvid_video_app_callback() {
1437
  $options = get_option('kgvid_video_embed_options');
1438
  $items = array("FFMPEG"=>"ffmpeg", "LIBAV"=>"avconv");
1439
+ echo "<select onchange='kgvid_hide_ffmpeg_settings();' id='video_app' name='kgvid_video_embed_options[video_app]'>";
1440
  foreach($items as $name => $value) {
1441
  $selected = ($options['video_app']==$value) ? 'selected="selected"' : '';
1442
  echo "<option value='$value' $selected>$name</option>";
1443
  }
1444
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>FFMPEG split into two separate branches in 2011. The new branch is called LIBAV. Both are still actively developed. Debian & Ubuntu users probably have LIBAV installed.</span></a>";
1445
  }
1446
 
1447
+ function kgvid_encode_formats_callback() {
1448
+ $options = get_option('kgvid_video_embed_options');
1449
+ echo "<div class='kgvid_video_app_required'>";
1450
+ echo "<input ".checked( $options['encode_1080'], "on", false )." id='encode_1080' name='kgvid_video_embed_options[encode_1080]' type='checkbox' /> <label for='encode_1080'>1080p H.264 <small><em>(iPhone 4s+, iPad 2+, few Android, Windows Phone 8, Chrome, Safari, IE 9+)</em></small></label> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>This is complicated. If you have FFMPEG/LIBAV and the proper libraries installed, you can choose to encode your uploaded video into as many as five additional formats depending on your original source. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 480p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox is planning to allow H.264 playback in the future and I no longer recommend encoding OGV or WEBM unless you expect a large number of no-Flash sticklers visiting your site.</span></a><br />";
1451
+ echo "<input ".checked( $options['encode_720'], "on", false )." id='encode_720' name='kgvid_video_embed_options[encode_720]' type='checkbox' /> <label for='encode_720'>720p H.264 <small><em>(iPhone 4+, iPad, some Android, Chrome, Safari, IE 9+)</em></small></label><br />";
1452
+ echo "<input ".checked( $options['encode_mobile'], "on", false )." id='encode_mobile' name='kgvid_video_embed_options[encode_mobile]' type='checkbox' /> <label for='encode_mobile'>480p H.264 <small><em>(iOS, Android, Windows Phone 7, Chrome, Safari, IE 9+)</em></small></label><br />";
1453
+ echo "<input ".checked( $options['encode_webm'], "on", false )." id='encode_webm' name='kgvid_video_embed_options[encode_webm]' type='checkbox' /> <label for='encode_webm'>WEBM <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label><br />";
1454
+ echo "<input ".checked( $options['encode_ogg'], "on", false )." id='encode_ogg' name='kgvid_video_embed_options[encode_ogg]' type='checkbox' /> <label for='encode_ogg'>OGV <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label>";
1455
+ echo '</div>';
1456
  }
1457
 
1458
+ function kgvid_ffmpeg_options_callback() {
1459
  $options = get_option('kgvid_video_embed_options');
1460
+ echo "<div class='kgvid_video_app_required'>";
1461
+ echo "<input onchange='if(jQuery(\"#ffmpeg_vpre\").attr(\"checked\")==\"checked\"){jQuery(\"#video_bitrate_flag\").attr(\"checked\", \"checked\");}' ".checked( $options['video_bitrate_flag'], "on", false )." id='video_bitrate_flag' name='kgvid_video_embed_options[video_bitrate_flag]' type='checkbox' /> <label for='video_bitrate_flag'>Enable legacy FFMPEG '-b' and '-ba' bitrate flags.</label> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Enable if your installed version of FFMPEG is old enough that you can't use the newer -b:v flags (Dreamhost users must turn this on). It will cause newer versions of FFMPEG to fail.</span></a><br />
1462
+ <input onchange='if(jQuery(\"#ffmpeg_vpre\").attr(\"checked\")==\"checked\"){jQuery(\"#video_bitrate_flag\").attr(\"checked\", \"checked\");}' ".checked( $options['ffmpeg_vpre'], "on", false )." id='ffmpeg_vpre' name='kgvid_video_embed_options[ffmpeg_vpre]' type='checkbox' /> <label for='ffmpeg_vpre'>Enable FFMPEG 'vpre' flags.</label> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>Enable if your installed version of FFMPEG is old enough that libx264 requires vpre flags to operate (Dreamhost users must turn this on). This should help if you can encode WEBM or OGV files but H264/Mobile files fail. It will cause newer versions of FFMPEG to fail and probably won't work on Windows servers.</span></a>";
1463
+ echo "</div>";
1464
  }
1465
 
1466
  function kgvid_moov_callback() {
1467
  $options = get_option('kgvid_video_embed_options');
1468
+ echo "<div class='kgvid_video_app_required'>";
1469
  $items = array("none", "qt-faststart", "MP4Box");
1470
  echo "<select id='moov' name='kgvid_video_embed_options[moov]'>";
1471
  foreach($items as $item) {
1472
  $selected = ($options['moov']==$item) ? 'selected="selected"' : '';
1473
  echo "<option value='$item' $selected>$item</option>";
1474
  }
1475
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>FFMPEG & LIBAV place moov atoms at the end of H.264 encoded files, which forces the entire file to download before playback can start and prevents the Flash player from playing them at all. If either of these programs is installed in the application path, you can choose to run it after encoding is finished in order to allow playback while downloading.</span></a>";
1476
+ echo "</div>";
1477
  }
1478
 
1479
  function kgvid_generate_thumbs_callback() {
1480
  $options = get_option('kgvid_video_embed_options');
1481
+ echo "<div class='kgvid_video_app_required'>";
1482
+ echo "<input class='small-text' id='generate_thumbs' name='kgvid_video_embed_options[generate_thumbs]' maxlength='2' type='text' value='".strval($options['generate_thumbs'])."' />";
1483
+ echo "</div>";
1484
  }
1485
 
1486
+ function kgvid_featured_callback() {
1487
  $options = get_option('kgvid_video_embed_options');
1488
+ echo "<input ".checked( $options['featured'], "on", false )." id='featured' name='kgvid_video_embed_options[featured]' type='checkbox' /> <label for='featured'>Set generated video thumbnails as featured images.</label> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>If your theme uses the featured image meta tag, this will automatically set a video's parent post's featured image to the most recently saved thumbnail image.</span></a><br /> <a class='button-secondary' href='javascript:void(0);' onclick='kgvid_set_all_featured();'>Set all as featured</a> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>If you've generated thumbnails with previous versions of the plugin this will set all existing thumbnails as featured images. Be careful!</span></a>";
1489
  }
1490
 
1491
+ function kgvid_thumb_parent_callback() {
1492
  $options = get_option('kgvid_video_embed_options');
1493
+ $items = array("post", "video");
1494
+ echo "<select id='thumb_parent' name='kgvid_video_embed_options[thumb_parent]'>";
1495
+ foreach($items as $item) {
1496
+ $selected = ($options['thumb_parent']==$item) ? 'selected="selected"' : '';
1497
+ echo "<option value='$item' $selected>$item</option>";
1498
+ }
1499
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>This depends on your theme. Thumbnails generated by the plugin can be saved as children of the video attachment or the post. Some themes use an image attached to a post instead of the built-in featured image meta tag. Version 3.x of this plugin saved all thumbnails as children of the video.</span></a><br /> <a class='button-secondary' href='javascript:void(0);' onclick='kgvid_switch_parents();'>Set all parents</a> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>If you've generated thumbnails before changing this option, this will set all existing thumbnails as children of your currently selected option.</span></a>";
1500
  }
1501
 
1502
+ function kgvid_delete_children_callback() {
1503
  $options = get_option('kgvid_video_embed_options');
1504
+ $items = array("none", "all", "encoded videos only");
1505
+ echo "<select id='delete_children' name='kgvid_video_embed_options[delete_children]'>";
1506
+ foreach($items as $item) {
1507
+ $selected = ($options['delete_children']==$item) ? 'selected="selected"' : '';
1508
+ echo "<option value='$item' $selected>$item</option>";
1509
+ }
1510
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>If you delete the original video you can choose to delete all associated attachments (thumbnails & videos) or keep the thumbnail.</span></a>";
1511
  }
1512
 
1513
+ function kgvid_titlecode_callback() {
1514
  $options = get_option('kgvid_video_embed_options');
1515
+ echo "<input class='regular-text code' id='titlecode' name='kgvid_video_embed_options[titlecode]' type='text' value='".htmlentities(stripslashes($options['titlecode']))."' /> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>HTML tag applied to titles inserted above the video. Ex: &lt;strong&gt;, &lt;em&gt;, &lt;H2&gt;, &lt;span class='videotitle'&gt;. Corresponding closing tags will be applied to the end of the title automatically.</span></a>";
1516
  }
1517
 
1518
+ function kgvid_template_callback() {
1519
  $options = get_option('kgvid_video_embed_options');
1520
+ $items = array("Video title (WP default)"=>"none", "Video in existing template"=>"gentle", "Video only (deprecated)"=>"old");
1521
+ echo "<select id='template' name='kgvid_video_embed_options[template]'>";
1522
+ foreach($items as $name => $value) {
1523
+ $selected = ($options['template']==$value) ? 'selected="selected"' : '';
1524
+ echo "<option value='$value' $selected>$name</option>";
1525
+ }
1526
+ echo "</select> <a class='kgvid_tooltip' href='javascript:void(0);'><img src='../wp-includes/images/blank.gif'><span class='kgvid_tooltip_classic'>By default WordPress only displays a video's title on the attachment page. This plugin can filter your attachment page to display the video, or completely replace your attachment template to show only the video. If you were one of the few people using iframe embed codes before version 4.0 of this plugin then you should continue to use 'Video only' but otherwise it's not recommended.</span></a>";
1527
  }
1528
+
1529
+ //end of settings page callback functions
1530
+
1531
+ function kgvid_update_settings() {
1532
 
1533
+ global $wpdb;
 
 
 
1534
 
1535
+ $options = get_option('kgvid_video_embed_options');
1536
+ $default_options = kgvid_default_options_fn();
 
 
1537
 
1538
+ if ( empty($options) ) { // run if the new settings don't exist yet (before version 3.0)
1539
+
1540
+ $options = array();
1541
+
1542
+ $old_setting_equivalents = array (
1543
+ "width"=>"wp_FMP_width",
1544
+ "height"=>"wp_FMP_height",
1545
+ "controlbar_style"=>"wp_FMP_controlbar_style",
1546
+ "poster"=>"wp_FMP_poster",
1547
+ "endOfVideoOverlay"=>"wp_FMP_endOfVideoOverlay",
1548
+ "autohide"=>"wp_FMP_autohide",
1549
+ "autoplay"=>"wp_FMP_autoplay",
1550
+ "loop"=>"wp_FMP_loop",
1551
+ "playbutton"=>"wp_FMP_playbutton",
1552
+ "stream_type"=>"wp_FMP_stream_type",
1553
+ "scale_mode"=>"wp_FMP_scale_mode",
1554
+ "bgcolor"=>"wp_FMP_bgcolor",
1555
+ "configuration"=>"wp_FMP_configuration",
1556
+ "skin"=>"wp_FMP_skin",
1557
+ "app_path"=>"wp_FMP_ffmpeg",
1558
+ "ffmpeg_exists"=>"wp_FMP_ffmpeg_exists",
1559
+ "encode_mobile"=>"wp_FMP_encodemobile",
1560
+ "encode_ogg"=>"wp_FMP_encodeogg",
1561
+ "encode_webm"=>"wp_FMP_encodewebm",
1562
+ "ffmpeg_vpre"=>"wp_FMP_vpre",
1563
+ "template"=>"wp_FMP_template",
1564
+ "titlecode"=>"wp_FMP_titlecode");
1565
+
1566
+ foreach ($old_setting_equivalents as $new_setting => $old_setting) { //apply any old settings to the new database entry then delete them
1567
+ $old_setting_value = get_option($old_setting, "no_setting");
1568
+ if ( $old_setting_value != "no_setting" ) {
1569
+ if ( $old_setting_value == "true" ) { $old_setting_value = "on"; }
1570
+ $options[$new_setting] = $old_setting_value;
1571
+ delete_option($old_setting);
1572
+ }
1573
+ }
1574
+ $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wp_FMP%'" );
1575
+
1576
+ foreach ( $default_options as $key => $value ) { //apply default values for any settings that didn't exist before
1577
+ if ( !array_key_exists($key, $options) ) { $options[$key] = $value; }
1578
+ $options['embed_method'] = "Strobe Media Playback";
1579
+ }
1580
+
1581
+ update_option('kgvid_video_embed_options', $options);
1582
  }
1583
 
1584
+ else { //user is already upgraded to version 3.0, but needs the extra options introduced in later versions
1585
+ if ( $options['version'] < 3.1 ) {
1586
+ $options['version'] = 3.1;
1587
+ if ( $options['ffmpeg_vpre'] == "on" ) { $options['video_bitrate_flag'] = "on"; } //if user has ffmpeg_vpre turned on, they need the old bitrate flags too
1588
+ else { $options['video_bitrate_flag'] = false; }
1589
+ $options['watermark'] = "";
 
1590
  }
1591
+ if ( $options['version'] < 4.0 ) {
1592
+ $options['version'] = 4.01;
1593
+ $options['overlay_title'] = false;
1594
+ $options['overlay_embedcode'] = false;
1595
+ $options['view_count'] = false;
1596
+ $options['align'] = "left";
1597
+ $options['featured'] = "on";
1598
+ $options['thumb_parent'] = "video";
1599
+ $options['delete_children'] = "encoded videos only";
1600
+ if ( $options['template'] == "on" ) { $options['template'] = "old"; }
1601
+ else { $options['template'] = "gentle"; }
1602
+ $checkbox_convert = array ( "autohide", "endOfVideoOverlaySame", "playbutton", "loop", "autoplay" );
1603
+ foreach ( $checkbox_convert as $option ) {
1604
+ if ( $options[$option] == "true" ) { $options[$option] = "on"; } //some checkboxes were incorrectly set to "true" in older versions
1605
+ }
1606
+ if ( wp_next_scheduled('kgvid_cleanup_queue') != false ) { //kgvid_cleanup_queue needs an argument!
1607
+ wp_clear_scheduled_hook('kgvid_cleanup_queue');
1608
+ wp_schedule_event( time()+86400, 'daily', 'kgvid_cleanup_queue', array ( 'scheduled' ) );
1609
+ }
1610
+
1611
+ }
1612
+ update_option('kgvid_video_embed_options', $options);
1613
  }
1614
+ }
1615
+ add_action('init', 'kgvid_update_settings' );
1616
+
1617
+ function kgvid_video_embed_options_validate($input) { //validate & sanitize input from settings form
1618
+
1619
+ $options = get_option('kgvid_video_embed_options');
1620
+ $default_options = kgvid_default_options_fn();
1621
 
1622
+ if (isset ($_POST["video-embed-thumbnail-generator-reset"])) {
1623
+ $input = $default_options;
1624
+ add_settings_error( __FILE__, "options-reset", "Video Embed & Thumbnail Generator settings reset to default values.", "updated" );
1625
  }
1626
+
1627
+ $ffmpeg_info = kgvid_check_ffmpeg_exists($input, false);
1628
 
1629
+ if ( $ffmpeg_info['exec_enabled'] == false ) {
1630
+ add_settings_error( __FILE__, "ffmpeg-disabled", $ffmpeg_info['function']." is disabled in PHP settings. You can embed existing videos, but video thumbnail generation and Mobile/HTML5 video encoding will not work. Contact your System Administrator to find out if you can enable ".$ffmpeg_info['function'].".", "updated");
1631
+ $input['ffmpeg_exists'] = "notinstalled";
1632
  }
1633
+ elseif ( $ffmpeg_info['ffmpeg_exists'] == false ) {
1634
+ add_settings_error( __FILE__, "ffmpeg-disabled", strtoupper($input['video_app'])." not found at ".$input['app_path'].". You can embed existing videos, but video thumbnail generation and Mobile/HTML5 video encoding is not possible without ".strtoupper($options['video_app']).".", "updated");
1635
+ $input['ffmpeg_exists'] = "notinstalled";
 
1636
  }
1637
+ if ( $ffmpeg_info['ffmpeg_exists'] == true ) { $input['ffmpeg_exists'] = "on"; }
1638
 
1639
+ if ( empty($input['width']) ) {
1640
+ add_settings_error( __FILE__, "width-zero", "You must enter a value for the maximum video width.");
1641
+ $input['width'] = $options['width'];
 
1642
  }
1643
+ if ( empty($input['height']) ) {
1644
+ add_settings_error( __FILE__, "height-zero", "You must enter a value for the maximum video height.");
1645
+ $input['height'] = $options['height'];
 
1646
  }
1647
+ if ( empty($input['gallery_width']) ) {
1648
+ add_settings_error( __FILE__, "gallery-width-zero", "You must enter a value for the maximum gallery video width.");
1649
+ $input['gallery_width'] = $options['gallery_width'];
 
1650
  }
1651
+ if ( empty($input['gallery_height']) ) {
1652
+ add_settings_error( __FILE__, "gallery-height-zero", "You must enter a value for the maximum gallery video height.");
1653
+ $input['gallery_height'] = $options['gallery_height'];
 
1654
  }
1655
 
1656
+ $input['titlecode'] = wp_kses_post( $input['titlecode'] );
 
 
 
 
 
 
 
 
 
1657
 
1658
+ // load all settings and make sure they get a value of false if they weren't entered into the form
1659
+ foreach ( $default_options as $key => $value ) {
1660
+ if ( !array_key_exists($key, $input) ) { $input[$key] = false; }
 
 
 
 
 
 
1661
  }
1662
+
1663
+ $input['version'] = $default_options['version']; //since this isn't user selectable it has to be re-entered every time
1664
 
1665
+ return $input;
1666
+ }
1667
+
1668
+ function kgvid_ajax_save_settings() {
1669
+
1670
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
1671
+ $setting = $_POST['setting'];
1672
+ $value = $_POST['value'];
1673
+ $error_message = "";
1674
+ global $wpdb;
1675
+ global $wp_settings_errors;
1676
+ $options = get_option('kgvid_video_embed_options');
1677
+ $options[$setting] = $value;
1678
+ $validated_options = kgvid_video_embed_options_validate($options);
1679
+ update_option('kgvid_video_embed_options', $validated_options);
1680
+ if ( !empty($wp_settings_errors) ) { $error_message = $wp_settings_errors[0]['message']; }
1681
+ $arr = array ( "error_message" => $error_message, "validated_value" => $validated_options[$setting], "ffmpeg_exists" => $validated_options['ffmpeg_exists'] );
1682
+ echo json_encode($arr);
1683
+ die();
1684
 
1685
+ }
1686
+ add_action('wp_ajax_kgvid_save_settings', 'kgvid_ajax_save_settings');
1687
+
1688
+ /* function kgvid_add_attachment_handler($post_id) { // This will start thumbnail generating automatically in a future version
1689
+
1690
+ $options = get_option('kgvid_video_embed_options');
1691
+ $movieurl = wp_get_attachment_url($post_id);
1692
+ kgvid_make_thumbs($post_id, $movieurl, $options['generate_thumbs'], 1, 1, '', '', 'generate');
1693
+
1694
+ }
1695
+ add_action('add_attachment', 'kgvid_add_attachment_handler'); */
1696
 
1697
  /**
1698
  * Adding our custom fields to the $form_fields array
1705
 
1706
  $options = get_option('kgvid_video_embed_options');
1707
 
 
1708
 
1709
+
1710
+ if ( substr($post->post_mime_type, 0, 5) == 'video' && (empty($post->post_parent) || (strpos(get_post_mime_type( $post->post_parent ), 'video') === false && get_post_meta($post->ID, '_kgflashmediaplayer-externalurl', true) == false)) ) { //if the attachment is a video with no parent or if it has a parent the parent is not a video and the video doesn't have the externalurl post meta
1711
+
1712
+ $field_id = kgvid_backwards_compatible($post->ID);
1713
 
1714
  $movieurl = wp_get_attachment_url($post->ID);
1715
  $form_fields["kgflashmediaplayer-url"]["input"] = "hidden";
1733
  $form_fields["kgflashmediaplayer-aspect"]["value"] = $heightset/$widthset;
1734
 
1735
  $embedset = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
1736
+ if ($embedset == "") {
1737
+ $embedset = "Single Video";
1738
+ update_post_meta($post->ID, '_kgflashmediaplayer-embed', $embedset); //make sure at least this value is set before attachment is inserted into post
1739
+ }
1740
 
1741
  $thumbnail_url = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
1742
 
1751
  }
1752
  else { if ( !kgvid_url_exists($thumbnail_url) ) { $thumbnail_url = ""; } }
1753
 
1754
+ $thumbnail_html = "";
1755
  if ($thumbnail_url != "" ) {
1756
+ $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.'?'.rand().'"></div>';
1757
+ }
 
 
 
 
1758
 
1759
+ $numberofthumbs_value = get_post_meta($post->ID, "_kgflashmediaplayer-numberofthumbs", true);
1760
+ if (get_post_meta($post->ID, "_kgflashmediaplayer-thumbtime", true) != "") { $numberofthumbs_value = "1"; }
1761
+ if ( empty($numberofthumbs_value) ) { $numberofthumbs_value = $options['generate_thumbs']; }
 
 
1762
 
1763
+ if ( !isset($options['ffmpeg_exists']) || $options['ffmpeg_exists'] == "notchecked" ) {
1764
+ kgvid_check_ffmpeg_exists($options, true);
1765
+ }
 
 
 
 
 
 
 
 
 
 
 
 
1766
 
1767
+ $forcefirstchecked = get_post_meta($post->ID, "_kgflashmediaplayer-forcefirst", true);
 
 
 
 
 
 
 
1768
 
1769
+ $featuredchecked = get_post_meta($post->ID, "_kgflashmediaplayer-featured", true);
1770
+ if ( empty($featuredchecked) ) { $featuredchecked = $options['featured']; }
1771
+ if ( $featuredchecked == "on" ) { $featuredchecked = "checked"; }
1772
+ else { $featuredchecked = ""; }
1773
 
1774
+ if ( $options['ffmpeg_exists'] == "notinstalled" ) { $ffmpeg_disabled_text = 'disabled="disabled" title="'.strtoupper($options['video_app']).' not found at '.$options['app_path'].'"'; }
1775
+ else { $ffmpeg_disabled_text = ""; }
 
 
 
 
 
1776
 
1777
+ $nonce = wp_create_nonce('video-embed-thumbnail-generator-nonce');
 
 
 
 
 
 
1778
 
1779
+ if ( $options['embed_method'] == "Video.js" ) {
1780
+
1781
+ $starts = intval(get_post_meta($post->ID, "_kgflashmediaplayer-starts", true));
1782
+ $completeviews = intval(get_post_meta($post->ID, "_kgflashmediaplayer-completeviews", true));
1783
+
1784
+ $form_fields["views"]["label"] = __("Video Stats");
1785
+ $form_fields["views"]["input"] = "html";
1786
+ $form_fields["views"]["html"] = $starts." Starts, ".$completeviews." Complete Views";
1787
 
1788
+ }
 
 
1789
 
1790
+ $form_fields["generator"]["label"] = __("Thumbnails");
1791
+ $form_fields["generator"]["input"] = "html";
1792
+ $form_fields["generator"]["html"] = '<input type="hidden" name="attachments['.$post->ID.'][kgflashmediaplayer-security]" id="attachments-'.$post->ID.'-kgflashmediaplayer-security" value="'.$nonce.'" /><div id="attachments-'.$post->ID.'-thumbnailplaceholder">'. $thumbnail_html .'</div>
1793
+ <input id="attachments-'. $post->ID .'-numberofthumbs" name="attachments['.$post->ID.'][kgflashmediaplayer-numberofthumbs]" type="text" value="'.$numberofthumbs_value.'" maxlength="2" style="width:35px;text-align:center;" onchange="kgvid_disable_thumb_buttons(\''.$post->ID.'\', \'onchange\');document.getElementById(\''.$field_id['thumbtime'].'\').value =\'\';" '.$ffmpeg_disabled_text.'/>
1794
+ <input type="button" id="attachments-'. $post->ID .'-thumbgenerate" class="button-secondary" value="Generate" name="thumbgenerate" onclick="kgvid_generate_thumb('. $post->ID .', \'generate\');" '.$ffmpeg_disabled_text.'/>
1795
+ <input type="button" id="attachments-'. $post->ID .'-thumbrandomize" class="button-secondary" value="Randomize" name="thumbrandomize" onclick="kgvid_generate_thumb('. $post->ID .', \'random\');" '.$ffmpeg_disabled_text.'/> <br />
1796
+ <input type="checkbox" id="attachments-'. $post->ID .'-firstframe" name="attachments['.$post->ID.'][kgflashmediaplayer-forcefirst]" onchange="document.getElementById(\''.$field_id['thumbtime'].'\').value =\'\';" value="checked" '.$forcefirstchecked.' '.$ffmpeg_disabled_text.'/> <label for="attachments-'. $post->ID .'-firstframe">Force 1st frame thumbnail</label><br />
1797
+ <input type="checkbox" id="attachments-'. $post->ID .'-featured" name="attachments['.$post->ID.'][kgflashmediaplayer-featured]" '.$featuredchecked.' '.$ffmpeg_disabled_text.'/> <label for="attachments-'. $post->ID .'-featured">Set thumbnail as featured image</label>';
1798
+
1799
+ $form_fields["thumbtime"]["label"] = __("Thumbnail Time");
1800
+ $form_fields["thumbtime"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-thumbtime", true);
1801
+ $form_fields["thumbtime"]["helps"] = "<small>Optional: generates a single thumbnail at the specified time (hh:mm:ss, mm:ss, or s).</small>";
1802
+
1803
+ $form_fields["kgflashmediaplayer-poster"]["label"] = __("Thumbnail URL");
1804
+ $form_fields["kgflashmediaplayer-poster"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
1805
+ $form_fields["kgflashmediaplayer-poster"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>default thumbnail</a>.</small>";
1806
+
1807
+ $lockaspectchecked = get_post_meta($post->ID, "_kgflashmediaplayer-lockaspect", true);
1808
+ if ( $lockaspectchecked == "notchecked" ) { $lockaspectchecked = ""; }
1809
+ else { $lockaspectchecked = "checked"; }
1810
+
1811
+ $form_fields["kgflashmediaplayer-dimensions"]["label"] = __("Video Embed Dimensions");
1812
+ $form_fields["kgflashmediaplayer-dimensions"]["input"] = "html";
1813
+ $form_fields["kgflashmediaplayer-dimensions"]["html"] = 'Width: <input name="attachments['. $post->ID .'][kgflashmediaplayer-width]" id="attachments-'. $post->ID .'-kgflashmediaplayer-width" type="text" value="'.$widthset.'" style="width:50px;" onchange="kgvid_set_dimension('.$post->ID.', \'height\', this.value);" onkeyup="kgvid_set_dimension('.$post->ID.', \'height\', this.value);"> Height:
1814
+ <input name="attachments['. $post->ID .'][kgflashmediaplayer-height]" id="attachments-'. $post->ID .'-kgflashmediaplayer-height" type="text" value="'.$heightset.'" style="width:50px;" onchange="kgvid_set_dimension('.$post->ID.', \'width\', this.value);" onkeyup="kgvid_set_dimension('.$post->ID.', \'width\', this.value);"> <br />
1815
+ <input type="checkbox" name="attachments['. $post->ID .'][kgflashmediaplayer-lockaspect]" id="attachments-'. $post->ID .'-kgflashmediaplayer-lockaspect" onclick="kgvid_set_aspect('.$post->ID.', this.checked);" value="checked" '.$lockaspectchecked.'>
1816
+ <label for="attachments-'. $post->ID .'-kgflashmediaplayer-lockaspect"><small>Lock to aspect ratio</small></label>';
1817
+ $form_fields["kgflashmediaplayer-dimensions"]["helps"] = "<small>Leave blank to use <a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>default dimensions</a>.</small>";
1818
+
1819
+
1820
+ $checkboxes = kgvid_generate_encode_checkboxes($movieurl, $post->ID, "attachment");
1821
+
1822
+ $form_fields["kgflashmediaplayer-encode"]["label"] = __("Additional Formats");
1823
+ $form_fields["kgflashmediaplayer-encode"]["input"] = "html";
1824
+ $form_fields["kgflashmediaplayer-encode"]["html"] = $checkboxes;
1825
+
1826
+ $showtitlechecked = get_post_meta($post->ID, "_kgflashmediaplayer-showtitle", true);
1827
+ if ( $showtitlechecked == "notchecked" ) { $showtitlechecked = ""; }
1828
+ $downloadlinkchecked = get_post_meta($post->ID, "_kgflashmediaplayer-downloadlink", true);
1829
+ if ( $downloadlinkchecked == "notchecked" ) { $downloadlinkchecked = ""; }
1830
+ $embed_option = get_post_meta($post->ID, "_kgflashmediaplayer-embed", true);
1831
+
1832
+ $items = array("Single Video", "Video Gallery", "WordPress Default");
1833
+ $shortcode_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-embed]" id="attachments['.$post->ID.'][kgflashmediaplayer-embed]">';
1834
+ foreach($items as $item) {
1835
+ $selected = ($embed_option==$item) ? 'selected="selected"' : '';
1836
+ $shortcode_select .= "<option value='$item' $selected>$item</option>";
1837
+ }
1838
+ $shortcode_select .= "</select>";
1839
 
1840
+ $form_fields["kgflashmediaplayer-options"]["label"] = __("Video Embed Options");
1841
+ $form_fields["kgflashmediaplayer-options"]["input"] = "html";
1842
+ $form_fields["kgflashmediaplayer-options"]["html"] = '<input type="checkbox" name="attachments['.$post->ID.'][kgflashmediaplayer-showtitle]" id="attachments-'.$post->ID.'-kgflashmediaplayer-showtitle" value="checked" '.$showtitlechecked.'>
1843
+ <label for="attachments-'.$post->ID.'-kgflashmediaplayer-showtitle">Insert title above video</label><br />
 
 
 
1844
 
1845
+ <input type="checkbox" name="attachments['.$post->ID.'][kgflashmediaplayer-downloadlink]" id="attachments-'.$post->ID.'-kgflashmediaplayer-downloadlink" value="checked" '.$downloadlinkchecked.'>
1846
+ <label for="attachments-'.$post->ID.'-kgflashmediaplayer-downloadlink">Insert download link below video<em><small><br />Makes it easier for users to download file.</em></small></label><br />
1847
+ '.$shortcode_select.'
1848
+ <label for="attachments-'.$post->ID.'-kgflashmediaplayer-embed">Insert</small></em></label><script type="text/javascript">window.onload=kgvid_hide_standard_wordpress_display_settings('.$post->ID.');</script>';
1849
 
1850
+ if ( get_post_meta($post->ID, "_kgflashmediaplayer-embed", true) == "Video Gallery" ) {
1851
+
1852
+ $gallery_thumb_width = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_thumb_width", true);
1853
+ if ( empty($gallery_thumb_width) ) { $gallery_thumb_width = $options['gallery_thumb']; }
1854
 
1855
+ $gallery_exclude = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_exclude", true);
1856
+ $gallery_include = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_include", true);
1857
+ $gallery_orderby = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_orderby", true);
1858
+ $gallery_order = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_order", true);
1859
 
1860
+ $gallery_id = get_post_meta($post->ID, "_kgflashmediaplayer-gallery_id", true);
1861
+ if ( empty($gallery_id) ) { $gallery_id = $post->post_parent; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1862
 
1863
+ $items = array("menu_order", "title", "post_date", "rand", "ID");
1864
+ $gallery_orderby_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_orderby]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_orderby">';
1865
+ foreach($items as $item) {
1866
+ $selected = ($gallery_orderby==$item) ? 'selected="selected"' : '';
1867
+ $gallery_orderby_select .= "<option value='$item' $selected>$item</option>";
1868
+ }
1869
+ $gallery_orderby_select .= "</select>";
 
 
1870
 
1871
+ $items = array("ASC", "DESC");
1872
+ $gallery_order_select = '<select name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_order]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_order">';
1873
+ foreach($items as $item) {
1874
+ $selected = ($gallery_order==$item) ? 'selected="selected"' : '';
1875
+ $gallery_order_select .= "<option value='$item' $selected>$item</option>";
1876
+ }
1877
+ $gallery_order_select .= "</select>";
1878
+
1879
+ $form_fields["kgflashmediaplayer-gallery"]["label"] = __("Gallery Settings (all optional)");
1880
+ $form_fields["kgflashmediaplayer-gallery"]["input"] = "html";
1881
+ $form_fields["kgflashmediaplayer-gallery"]["html"] = '<input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_thumb_width]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_thumb_width" type ="text" value="'.$gallery_thumb_width.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_thumb_width">Thumbnail Width</label><br />
1882
+ '.$gallery_orderby_select.' Order By<br />
1883
+ '.$gallery_order_select.' Sort Order<br />
1884
+ <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_exclude]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_exclude" type ="text" value="'.$gallery_exclude.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_exclude">Exclude</label><br />
1885
+ <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_include]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_include" type ="text" value="'.$gallery_include.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_include">Include</label><br />
1886
+ <input name="attachments['.$post->ID.'][kgflashmediaplayer-gallery_id]" id="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_id" type ="text" value="'.$gallery_id.'" style="width:50px;"> <label for="attachments-'.$post->ID.'-kgflashmediaplayer-gallery_id">Post ID</label>
1887
+ ';
1888
+
1889
+ }//if video gallery
1890
+ } //only add fields if attachment is the right kind of video
1891
  return $form_fields;
1892
  }
1893
  // attach our function to the correct hook
1894
  add_filter("attachment_fields_to_edit", "kgvid_image_attachment_fields_to_edit", null, 2);
1895
 
1896
  function kgvid_save_thumb($post_id, $post_name, $thumb_url) {
1897
+
1898
+ $options = get_option('kgvid_video_embed_options');
1899
  $uploads = wp_upload_dir();
1900
 
1901
  $posterfile = pathinfo($thumb_url, PATHINFO_BASENAME);
1902
+ $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile;
1903
+ $final_posterpath = $uploads['path'].'/'.$posterfile;
1904
+ if ( !is_file($final_posterpath) ) { //if the file doesn't already exist
1905
+ if ( is_file($tmp_posterpath) ) {
1906
+ rename($tmp_posterpath, $final_posterpath);
1907
+ $thumb_base = substr($tmp_posterpath, 0, strpos($tmp_posterpath, '_thumb'));
1908
+ foreach (glob($thumb_base."*.jpg") as $thumbfilename) {
1909
+ unlink($thumbfilename);
1910
  }
 
1911
  }
1912
+ if ( kgvid_is_empty_dir($uploads["path"].'/thumb_tmp') ) { kgvid_rrmdir($uploads["path"].'/thumb_tmp'); }
1913
+ }
1914
 
1915
+ //insert the $thumb_url into the media library if it does not already exist
1916
+
1917
+ global $wpdb;
1918
+ $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='".$thumb_url."'"; //check for existing entry in the db
1919
+ $thumb_id = $wpdb->get_var($query);
1920
+
1921
+ if ( !$thumb_id ) {
1922
+
1923
+ $desc = $post_name . ' thumbnail';
1924
 
1925
+ //is image in uploads directory?
1926
+ $upload_dir = wp_upload_dir();
1927
+
1928
+ $video = get_post($post_id);
1929
+ if ( $options['thumb_parent'] == "post" ) {
1930
+ if ( !empty($video->post_parent) ) { $post_id = $video->post_parent; }
1931
+ }
1932
 
1933
+ if ( FALSE !== strpos( $thumb_url, $upload_dir['baseurl'] ) ) {
1934
+ $wp_filetype = wp_check_filetype(basename($thumb_url), null );
1935
+ $filename = preg_replace('/\.[^.]+$/', '', basename($thumb_url));
1936
 
1937
+ $attachment = array(
1938
+ 'guid' => $thumb_url,
1939
+ 'post_mime_type' => $wp_filetype['type'],
1940
+ 'post_title' => $desc,
1941
+ 'post_content' => '',
1942
+ 'post_status' => 'inherit'
1943
+ );
1944
 
1945
+ $thumb_id = wp_insert_attachment( $attachment, $uploads['path'].'/'.$posterfile, $post_id );
1946
+ // you must first include the image.php file
1947
+ // for the function wp_generate_attachment_metadata() to work
1948
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
1949
+ $attach_data = wp_generate_attachment_metadata( $thumb_id, $uploads['path'].'/'.$posterfile );
1950
+ wp_update_attachment_metadata( $thumb_id, $attach_data );
1951
+ }
1952
+ else { //not in uploads so we'll have to sideload it
1953
+ $tmp = download_url( $thumb_url );
1954
+
1955
+ // Set variables for storage
1956
+ // fix file filename for query strings
1957
+ preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
1958
+ $file_array['name'] = basename($matches[0]);
1959
+ $file_array['tmp_name'] = $tmp;
1960
+
1961
+ // If error storing temporarily, unlink
1962
+ if ( is_wp_error( $tmp ) ) {
1963
+ @unlink($file_array['tmp_name']);
1964
+ $file_array['tmp_name'] = '';
1965
+ }
1966
+
1967
+ // do the validation and storage stuff
1968
+ $thumb_id = media_handle_sideload( $file_array, $post_id, $desc );
 
 
 
 
 
 
1969
 
1970
+ // If error storing permanently, unlink
1971
+ if ( is_wp_error($thumb_id) ) {
1972
+ @unlink($file_array['tmp_name']);
1973
+ return $thumb_id;
1974
+ }
1975
 
1976
+ if ( $local_src = wp_get_attachment_url( $thumb_id ) ) {
1977
+ update_post_meta($post_id, '_kgflashmediaplayer-poster', $local_src);
1978
+ }
 
 
1979
 
1980
+ } //end sideload
1981
+
1982
+ $thumb_id = intval( $thumb_id );
1983
+ update_post_meta($post_id, '_kgflashmediaplayer-poster-id', $thumb_id);
1984
+ set_post_thumbnail($post_id, $thumb_id);
1985
+ update_post_meta($thumb_id, '_kgflashmediaplayer-video-id', $video->ID);
1986
+
1987
+ } //end get_attachment_id_from_src
1988
 
1989
+ if(!is_wp_error($thumb_id)) {
1990
+
1991
+ return $thumb_id;
1992
+ }
1993
 
1994
  }
1995
 
2002
  // $attachment part of the form $_POST ($_POST[attachments][postID])
2003
  // $post attachments wp post array - will be saved after returned
2004
  // $post['post_type'] == 'attachment'
2005
+ if( !empty($post['ID']) ) {
2006
+ $thumb_id = "";
2007
+ if( isset($attachment['kgflashmediaplayer-poster']) ) {
2008
+
2009
+ $thumb_url = $attachment['kgflashmediaplayer-poster'];
2010
+ if ( !empty($thumb_url) ) { $thumb_id = kgvid_save_thumb($post['ID'], $post['post_title'], $thumb_url); }
2011
+ update_post_meta($post['ID'], '_kgflashmediaplayer-poster', $thumb_url);
2012
+
2013
+ }
2014
+ if( isset($attachment['kgflashmediaplayer-numberofthumbs']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-numberofthumbs', $attachment['kgflashmediaplayer-numberofthumbs']); }
2015
+ if( isset($attachment['kgflashmediaplayer-forcefirst']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-forcefirst', $attachment['kgflashmediaplayer-forcefirst']); }
2016
+ else { update_post_meta($post['ID'], '_kgflashmediaplayer-forcefirst', ""); }
2017
+ if( isset($attachment['kgflashmediaplayer-featured']) ) {
2018
+ update_post_meta($post['ID'], '_kgflashmediaplayer-featured', $attachment['kgflashmediaplayer-featured']);
2019
+ if ( !empty($thumb_id) && array_key_exists('post_parent', $post) ) { set_post_thumbnail($post['post_parent'], $thumb_id); }
2020
+ }
2021
+ else { update_post_meta($post['ID'], '_kgflashmediaplayer-featured', "notchecked"); }
2022
+ if( isset($attachment['thumbtime']) ) {update_post_meta($post['ID'], '_kgflashmediaplayer-thumbtime', $attachment['thumbtime']); }
2023
+ if( isset($attachment['kgflashmediaplayer-width']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-width', $attachment['kgflashmediaplayer-width']); }
2024
+ if( isset($attachment['kgflashmediaplayer-height']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-height', $attachment['kgflashmediaplayer-height']); }
2025
+ if( isset($attachment['kgflashmediaplayer-aspect']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-aspect', $attachment['kgflashmediaplayer-aspect']); }
2026
+ if( isset($attachment['kgflashmediaplayer-lockaspect']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-lockaspect', $attachment['kgflashmediaplayer-lockaspect']); }
2027
+ else { update_post_meta($post['ID'], '_kgflashmediaplayer-lockaspect', "notchecked"); }
2028
+
2029
+ $video_formats = kgvid_video_formats();
2030
+ foreach ( $video_formats as $format => $format_stats ) {
2031
+ if( isset($attachment['kgflashmediaplayer-encode'.$format]) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-encode'.$format, "on"); }
2032
+ elseif ( $format != "rotated" ) { update_post_meta($post['ID'], '_kgflashmediaplayer-encode'.$format, "notchecked"); } //don't save the fact that rotated isn't checked since it almost never is
2033
+ else { delete_post_meta($post['ID'], '_kgflashmediaplayer-encode'.$format); } //if it used to be checked, delete that meta value
2034
+ }
2035
 
2036
+ if( isset($attachment['kgflashmediaplayer-showtitle']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-showtitle', $attachment['kgflashmediaplayer-showtitle']); }
2037
+ else { update_post_meta($post['ID'], '_kgflashmediaplayer-showtitle', "notchecked"); }
2038
 
2039
+ if( isset($attachment['kgflashmediaplayer-downloadlink']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-downloadlink', $attachment['kgflashmediaplayer-downloadlink']); }
2040
+ else { update_post_meta($post['ID'], '_kgflashmediaplayer-downloadlink', "notchecked"); }
2041
+
2042
+ if( isset($attachment['kgflashmediaplayer-embed']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-embed', $attachment['kgflashmediaplayer-embed']); }
2043
+ if( isset($attachment['kgflashmediaplayer-gallery_thumb_width']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_thumb_width', $attachment['kgflashmediaplayer-gallery_thumb_width']); }
2044
+ if( isset($attachment['kgflashmediaplayer-gallery_exclude']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_exclude', $attachment['kgflashmediaplayer-gallery_exclude']); }
2045
+ if( isset($attachment['kgflashmediaplayer-gallery_include']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_include', $attachment['kgflashmediaplayer-gallery_include']); }
2046
+ if( isset($attachment['kgflashmediaplayer-gallery_orderby']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_orderby', $attachment['kgflashmediaplayer-gallery_orderby']); }
2047
+ if( isset($attachment['kgflashmediaplayer-gallery_order']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_order', $attachment['kgflashmediaplayer-gallery_order']); }
2048
+ if( isset($attachment['kgflashmediaplayer-gallery_id']) ) { update_post_meta($post['ID'], '_kgflashmediaplayer-gallery_id', $attachment['kgflashmediaplayer-gallery_id']); }
2049
 
2050
  }
2051
+ return $post;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2052
  }
2053
  add_filter("attachment_fields_to_save", "kgvid_video_attachment_fields_to_save", null, 2);
2054
 
2062
 
2063
  $options = get_option('kgvid_video_embed_options');
2064
  $output = $html;
 
2065
  $attachment['embed'] = get_post_meta($attachment_id, "_kgflashmediaplayer-embed", true);
2066
 
2067
+ if ( $attachment['embed'] == "Single Video" ) {
2068
  $output = "";
2069
  $attachment['url'] = wp_get_attachment_url($attachment_id);
2070
  $attachment['title'] = get_the_title($attachment_id);
2080
  $endtitlecode = str_replace("<", "</", $titlecode);
2081
  $endtitlecode_array = explode(' ', $endtitlecode);
2082
  if ( substr($endtitlecode_array[0], -1) != ">" ) { $endtitlecode = $endtitlecode_array[0].">"; }
2083
+ $output .= $titlecode.'<span itemprop="name">'.$attachment["title"].'</span>'.$endtitlecode.'<br />';
2084
  }
2085
  $output .= '[KGVID';
2086
  if ($attachment['poster'] !="") { $output .= ' poster="'.$attachment["poster"].'"'; }
2177
  </tr>
2178
  <tr>
2179
  <th valign="top" scope="row" class="label"><span class="alignleft"><label for="attachments-singleurl-kgflashmediaplayer-width">Dimensions</label></span></th>
2180
+ <td class="field">Width: <input name="attachments[singleurl][kgflashmediaplayer-width]" type="text" value="<?php echo $maxwidth; ?>" id="attachments-singleurl-kgflashmediaplayer-width" type="text" style="width:50px;" onchange="kgvid_set_dimension('singleurl', 'height', this.value);" onkeyup="kgvid_set_dimension('singleurl', 'height', this.value);"> Height: <input name="attachments[singleurl][kgflashmediaplayer-height]" id="attachments-singleurl-kgflashmediaplayer-height" type="text" value="<?php echo $maxheight; ?>" style="width:50px;" onchange="kgvid_set_dimension('singleurl', 'width', this.value);" onkeyup="kgvid-set-dimension('singleurl', 'width', this.value);"> <input type="checkbox" name="attachments[singleurl][kgflashmediaplayer-lockaspect]" id="attachments-singleurl-kgflashmediaplayer-lockaspect" onclick="kgvid_set_aspect('singleurl', this.checked);" checked> <label for="attachments-singleurl-kgflashmediaplayer-lockaspect"><small>Lock to Aspect Ratio</small></label>
2181
  <p class="help"><small>Leave blank to use <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php" target="_blank">default dimensions</a>.</small></p></td>
2182
  </tr>
2183
  <tr>
2198
  </div>
2199
  </div>
2200
 
2201
+ <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-security]' id='attachments-kgflashmediaplayer-security' value='<?php echo wp_create_nonce('video-embed-thumbnail-generator-nonce'); ?>' />
2202
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxwidth]' id='attachments-singleurl-kgflashmediaplayer-maxwidth' value='<?php echo($maxwidth); ?>' />
2203
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-maxheight]' id='attachments-singleurl-kgflashmediaplayer-maxheight' value='<?php echo($maxheight); ?>' />
2204
  <input type='hidden' name='attachments[singleurl][kgflashmediaplayer-aspect]' id='attachments-singleurl-kgflashmediaplayer-aspect' value='<?php echo(round($maxheight/$maxwidth, 3)); ?>' />
2221
  }
2222
  add_filter('query_vars', 'kgvid_parameter_queryvars' );
2223
 
2224
+ function kgvid_generate_attachment_shortcode($kgvid_video_embed) {
2225
 
2226
  global $post;
2227
  global $wp_query;
2228
+ $options = get_option('kgvid_video_embed_options');
2229
+
2230
+ if ( array_key_exists('sample', $kgvid_video_embed) ) { $url = plugins_url('/images/sample-video-h264.mp4', __FILE__); }
2231
+ else { $url = wp_get_attachment_url($post->ID); }
2232
+
2233
+ $poster = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
2234
+
2235
+ if ( array_key_exists('width', $kgvid_video_embed) ) { $width = $kgvid_video_embed['width']; }
2236
+ else { $width = get_post_meta($post->ID, "_kgflashmediaplayer-width", true); }
2237
+ if ( !$width ) { $width = get_post_meta($post->ID, "_kgflashmediaplayer-actualwidth", true); }
2238
+ if ( !$width ) { $width = $options['width']; }
2239
+
2240
+ if ( array_key_exists('height', $kgvid_video_embed) ) { $height = $kgvid_video_embed['height']; }
2241
+ else { $height = get_post_meta($post->ID, "_kgflashmediaplayer-height", true); }
2242
+ if ( !$height ) { $height = get_post_meta($post->ID, "_kgflashmediaplayer-actualheight", true); }
2243
+ if ( !$height ) { $width = $options['width']; }
2244
+
2245
+ $shortcode = '[KGVID';
2246
+ if ($poster !="" ) { $shortcode .= ' poster="'.$poster.'"';}
2247
+ if ($width !="" ) { $shortcode .= ' width="'.$width.'"';}
2248
+ if ($height !="" ) { $shortcode .= ' height="'.$height.'"';}
2249
+ if (array_key_exists('gallery', $kgvid_video_embed)) { $shortcode .= ' autoplay="true"'; }
2250
+ if (array_key_exists('sample', $kgvid_video_embed)) {
2251
+ if ( $options['overlay_title'] == "on" ) { $shortcode .= ' title="Sample Video"'; }
2252
+ if ( $options['overlay_embedcode'] == "on" ) { $shortcode .= ' embedcode="Sample Embed Code"'; }
2253
+ $shortcode .= ' caption="Captions are shown automatically if entered."';
2254
+ }
2255
+ //else { $shortcode .= ' view_count="false"'; }
2256
+ $shortcode .= ']'.$url.'[/KGVID]';
2257
+
2258
+ return $shortcode;
2259
+
2260
+ }
2261
+
2262
+ function kgvid_filter_video_attachment_content($content) {
2263
 
2264
+ global $post;
2265
  $options = get_option('kgvid_video_embed_options');
2266
 
2267
+ if ( $options['template'] == "gentle" && strpos($post->post_mime_type, "video") !== false ) {
2268
+ $kgvid_video_embed = array(); //no query set
2269
+ $content = kgvid_generate_attachment_shortcode($kgvid_video_embed);
2270
+ $content .= '<p>'.$post->post_content.'</p>';
2271
+ }
2272
+ return $content;
2273
+ }
2274
+ add_filter( 'the_content', 'kgvid_filter_video_attachment_content' );
2275
+
2276
+ function kgvid_video_attachment_template() {
2277
+
2278
+ global $post;
2279
+ global $wp_query;
2280
+ $options = get_option('kgvid_video_embed_options');
2281
 
2282
+ $kgvid_video_embed = array ( 'enable' => 'false' ); //turned off by default
2283
+ if ( isset($wp_query->query_vars['kgvid_video_embed']) ) { $kgvid_video_embed = $wp_query->query_vars['kgvid_video_embed']; }
2284
+ if ( $options['template'] == "old" ) { $kgvid_video_embed['enable'] = 'true'; } //regardless of any query settings, if we're using the old method it's turned on
2285
+ if ( (!is_array($kgvid_video_embed) && $kgvid_video_embed == "true") ) { $kgvid_video_embed = array ( 'enable' => 'true' ); } //maintain backwards compatibility
2286
+
2287
 
2288
+ if ( $kgvid_video_embed['enable'] == 'true' && (strpos($post->post_mime_type,"video") !== false || array_key_exists('sample', $kgvid_video_embed)) ) {
2289
 
2290
+ remove_action('wp_head', '_admin_bar_bump_cb'); //don't show the WordPress admin bar if you're logged in
2291
 
2292
+ $shortcode = kgvid_generate_attachment_shortcode($kgvid_video_embed);
2293
+
2294
+ echo '<html><head>';
2295
+ echo (wp_head());
2296
+ echo '<style>body { margin:0px; font-family: sans-serif; padding:0px; ';
2297
+ if ( array_key_exists('gallery', $kgvid_video_embed) ) { echo 'background:black; '; }
2298
+ else { echo 'background:white; '; }
2299
+ echo '} .kgvid_wrapper { margin:0; }</style>';
2300
+ echo '</head><body class="content">';
2301
+ echo (do_shortcode( $shortcode ));
2302
+ echo '</body></html>';
2303
+ exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2304
  }
2305
  }
2306
  add_action('template_redirect', 'kgvid_video_attachment_template');
2323
  function kgvid_cleanup_generated_thumbnails_handler() {
2324
  $uploads = wp_upload_dir();
2325
  kgvid_rrmdir($uploads['path'].'/thumb_tmp'); //remove the whole tmp file directory
 
2326
  }
2327
  add_action('kgvid_cleanup_generated_thumbnails','kgvid_cleanup_generated_thumbnails_handler');
2328
 
2336
  wp_schedule_single_event(time()+3600, 'kgvid_cleanup_generated_thumbnails');
2337
  }
2338
 
2339
+ if (isset($_POST['logfile'])) {
2340
+ $timestamp = wp_next_scheduled( 'kgvid_cleanup_generated_logfiles' );
2341
+ wp_unschedule_event($timestamp, 'kgvid_cleanup_generated_logfiles' );
2342
+ $args = array('logfile'=>$_POST['logfile']);
2343
+ wp_schedule_single_event(time()+600, 'kgvid_cleanup_generated_logfiles', $args);
2344
+ }
2345
+
2346
+ die(); // this is required to return a proper result
2347
+ }
2348
+ add_action('wp_ajax_kgvid_schedule_cleanup_generated_files', 'kgvid_schedule_cleanup_generated_files');
2349
+
2350
+ function kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser, $thumbtimecode, $dofirstframe, $generate_button) {
2351
+
2352
+ $options = get_option('kgvid_video_embed_options');
2353
+ $ffmpegPath = $options['app_path']."/".$options['video_app'];
2354
+ $uploads = wp_upload_dir();
2355
+
2356
+ if ( get_post_type($postID) == "attachment" ) {
2357
+ $moviefilepath = get_attached_file($postID);
2358
+ $movie_width = get_post_meta($postID, '_kgflashmediaplayer-actualwidth');
2359
+ if ( empty($movie_width) ) {
2360
+ $movie_info = kgvid_get_video_dimensions($moviefilepath);
2361
+ update_post_meta($postID, '_kgflashmediaplayer-actualwidth', $movie_info['width']);
2362
+ update_post_meta($postID, '_kgflashmediaplayer-actualheight', $movie_info['height']);
2363
+ update_post_meta($postID, '_kgflashmediaplayer-duration', $movie_info['duration']);
2364
+ if ( !empty($movie_info['rotate']) ) { update_post_meta($postID, '_kgflashmediaplayer-rotate', $movie_info['rotate']); }
2365
+ }
2366
+ else {
2367
+ $movie_info = array (
2368
+ 'width' => get_post_meta($postID, '_kgflashmediaplayer-actualwidth', true),
2369
+ 'height' => get_post_meta($postID, '_kgflashmediaplayer-actualheight', true),
2370
+ 'duration' => get_post_meta($postID, '_kgflashmediaplayer-duration', true),
2371
+ 'rotate' => get_post_meta($postID, '_kgflashmediaplayer-rotate', true),
2372
+ 'worked' => true
2373
+ );
2374
+ }
2375
+ }
2376
+ else {
2377
+ $moviefilepath = esc_url_raw(str_replace(" ", "%20", $movieurl));
2378
+ $moviefilepath = str_replace("https://", "http://", $moviefilepath);
2379
+ $movie_info = kgvid_get_video_dimensions($moviefilepath);
2380
+ }
2381
+
2382
+ if ($movie_info['worked'] == true) { //if FFMPEG was able to open the file
2383
+
2384
+ $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
2385
+ $moviefilebasename = sanitize_file_name(basename($movieurl,'.'.$movie_extension));
2386
+ $thumbnailfilebase = $uploads['url']."/thumb_tmp/".$moviefilebasename;
2387
+
2388
+ $movie_width = $movie_info['width'];
2389
+ $movie_height = $movie_info['height'];
2390
+
2391
+ if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
2392
+
2393
+ if ( $movie_info['rotate'] === false) { $movie_info['rotate'] = ""; }
2394
+ switch ($movie_info['rotate']) { //if it's a sideways mobile video
2395
+ case '-vf "transpose=1"': //90 degrees
2396
+ case '-vf "transpose=2"': //270 degrees
2397
+ $movie_width ^= $movie_height ^= $movie_width ^= $movie_height; break; //swap height & width
2398
+ }
2399
+
2400
+ $thumbnailheight = strval(round(floatval($movie_height) / floatval($movie_width) * 200));
2401
+
2402
+ $jpgpath = $uploads['path']."/thumb_tmp/";
2403
+
2404
+ $movieoffset = round((intval($movie_info['duration']) * $iincreaser) / ($numberofthumbs * 2));
2405
+
2406
+ if ($generate_button == "random") { //adjust offset random amount
2407
+ $movieoffset = $movieoffset - rand(0, round(intval($movie_info['duration']) / $numberofthumbs));
2408
+ if ($movieoffset < 0) { $movieoffset = "0"; }
2409
+ }
2410
+
2411
+ if ($thumbtimecode) { //if a specific thumbnail timecode is set
2412
+ if ($thumbtimecode == "firstframe") { $thumbtimecode = "0"; }
2413
+ $timecode_array = explode(":", $thumbtimecode);
2414
+ $timecode_array = array_reverse($timecode_array);
2415
+ if ( array_key_exists(1, $timecode_array) ) { $timecode_array[1] = $timecode_array[1] * 60; }
2416
+ if ( array_key_exists(2, $timecode_array) ) { $timecode_array[2] = $timecode_array[2] * 3600; }
2417
+ $thumbtimecode = array_sum($timecode_array);
2418
+ $movieoffset = $thumbtimecode;
2419
+ $i = $numberofthumbs + 1;
2420
+ }
2421
+
2422
+ if ($dofirstframe == "true" && $i == 1) {
2423
+ $movieoffset = "0";
2424
+ }
2425
+
2426
+ $thumbnailfilename[$i] = $jpgpath.$moviefilebasename."_thumb".$movieoffset.".jpg";
2427
+ $thumbnailfilename[$i] = str_replace(" ", "_", $thumbnailfilename[$i]);
2428
+ $ffmpeg_options = '-y -ss '.$movieoffset.' -i "'.$moviefilepath.'" '.$movie_info['rotate'].' -qscale 1 -vframes 1 "'.$thumbnailfilename[$i].'"';
2429
+ $thumbnailurl = $thumbnailfilebase."_thumb".$movieoffset.'.jpg';
2430
+ $thumbnailurl = str_replace(" ", "_", $thumbnailurl);
2431
+
2432
+ exec(escapeshellcmd($ffmpegPath." ".$ffmpeg_options));
2433
+
2434
+ if (floatval($movieoffset) > 60) {
2435
+ $movieoffset_minutes = sprintf("%02s", intval(intval($movieoffset) / 60) );
2436
+ $movieoffset_seconds = sprintf("%02s", round(fmod( floatval($movieoffset), 60), 2) );
2437
+ $movieoffset_display = $movieoffset_minutes.":".$movieoffset_seconds;
2438
+ }
2439
+ else { $movieoffset_display = "00:".sprintf("%02s", $movieoffset); }
2440
+
2441
+ $field_id = kgvid_backwards_compatible($postID);
2442
+
2443
+ $thumbnaildisplaycode = '<div class="kgvid_thumbnail_select" name="attachments['.$postID.'][thumb'.$i.']" id="attachments-'.$postID.'-thumb'.$i.'"><label for="kgflashmedia-'.$postID.'-thumbradio'.$i.'"><img src="'.$thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'" class="kgvid_thumbnail"></label><br /><input type="radio" name="attachments['.$postID.'][thumbradio'.$i.']" id="kgflashmedia-'.$postID.'-thumbradio'.$i.'" value="'.str_replace('/thumb_tmp/', '/', $thumbnailurl).'" onchange="getElementById(\''.$field_id['poster'].'\').value = this.value; getElementById(\''.$field_id['thumbtime'].'\').value = \''. $movieoffset_display .'\'; getElementById(\'attachments-'. $postID .'-numberofthumbs\').value =\'1\';"></div>';
2444
+
2445
+ $i++;
2446
+
2447
+ $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "movie_width"=>$movie_width, "movie_height"=>$movie_height, "lastthumbnumber"=>$i, "movieoffset"=>$movieoffset );
2448
+
2449
+ echo json_encode($arr);
2450
+
2451
+ }//if ffmpeg can open movie
2452
+
2453
+ else {
2454
+ $thumbnaildisplaycode = "<strong>Can't open movie file.</strong><br />".$movie_info['output'];
2455
+ $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "embed_display"=>$thumbnaildisplaycode, "lastthumbnumber"=>"break" );
2456
+ echo json_encode($arr);
2457
+ } //can't open movie
2458
+
2459
+ }
2460
+
2461
+ function kgvid_enqueue_videos($postID, $movieurl, $encode_checked, $parent_id) {
2462
+
2463
+ $options = get_option('kgvid_video_embed_options');
2464
+ $ffmpegPath = $options['app_path']."/".$options['video_app'];
2465
+ $uploads = wp_upload_dir();
2466
+
2467
+ $embed_display = "";
2468
+ $start_encoding = false;
2469
+ $encode_these = array();
2470
+ $encode_list = array();
2471
+ $embeddable = array("flv", "f4v", "mp4", "mov", "m4v", "ogv", "ogg", "webm");
2472
+ $h264extensions = array("mp4", "m4v", "mov");
2473
+ $video_formats = kgvid_video_formats();
2474
+ $sanitized_url = kgvid_sanitize_url($movieurl);
2475
+ //$movieurl = esc_url_raw(str_replace(" ", "%20", $movieurl));
2476
+ $movieurl = $sanitized_url['movieurl'];
2477
+ $movieurl = str_replace("https://", "http://", $movieurl);
2478
+ $movie_info = kgvid_get_video_dimensions($movieurl);
2479
+
2480
+ if ($movie_info['worked'] == true) { //if FFMPEG was able to open the file
2481
+
2482
+ $movie_width = $movie_info['width'];
2483
+ $movie_height = $movie_info['height'];
2484
+ if ( get_post_type($postID) == "attachment" ) {
2485
+ update_post_meta($postID, '_kgflashmediaplayer-actualheight', $movie_width);
2486
+ update_post_meta($postID, '_kgflashmediaplayer-actualheight', $movie_height);
2487
+ update_post_meta($postID, '_kgflashmediaplayer-duration', $movie_info['duration']);
2488
+ update_post_meta($postID, '_kgflashmediaplayer-rotate', $movie_info['rotate']);
2489
+ }
2490
+
2491
+ $encodevideo_info = kgvid_encodevideo_info($movieurl, $postID);
2492
+
2493
+ foreach ( $video_formats as $format => $format_stats ) {
2494
+ if ( $encode_checked[$format] == "true" ) {
2495
+ if ( !$encodevideo_info[$format.'_exists'] ) {
2496
+ if ( ($format == "1080" && $movie_height <= 1080) || ($format == "720" && $movie_height <= 720) ) {
2497
+ $movie_extension = pathinfo($movieurl, PATHINFO_EXTENSION);
2498
+ if ( in_array($movie_extension, $h264extensions) || $movie_height < intval($format) ) {
2499
+ $encode_formats[$format]['status'] = "lowres";
2500
+ } //skip if the resolution of an existing video is lower than the HD format
2501
+ }
2502
+ else {
2503
+ $encode_formats[$format]['status'] = "queued";
2504
+ $encode_formats[$format]['name'] = $format_stats['name'];
2505
+ $encode_list[$format] = $format_stats['name'];
2506
+ update_post_meta($postID, '_kgflashmediaplayer-encode'.$format, 'on');
2507
+ }
2508
+ } // if video doesn't already exist
2509
+ else { $encode_formats[$format]['status'] = "encoded"; }
2510
+ } // if user wants to encode format
2511
+ else {
2512
+ $encode_formats[$format]['status'] = "notchecked";
2513
+ update_post_meta($postID, '_kgflashmediaplayer-encode'.$format, 'notchecked');
2514
+ }
2515
+ }
2516
+
2517
+ if ( !empty($encode_list) ) {
2518
+ $video_embed_queue = get_option('kgvid_video_embed_queue');
2519
+ if ( empty($parent_id) ) { $parent_id = get_post($postID)->post_parent; }
2520
+ $queue_entry = array (
2521
+ 'attachmentID'=>$postID,
2522
+ 'parent_id'=>$parent_id,
2523
+ 'movieurl' => $movieurl,
2524
+ 'encode_formats'=> $encode_formats,
2525
+ 'movie_info' => $movie_info
2526
+ );
2527
+ $already_queued = false;
2528
+ if ( !empty($video_embed_queue ) ) {
2529
+ foreach ($video_embed_queue as $index => $entry) {
2530
+ if ( $entry['movieurl'] == $movieurl ) {
2531
+ $already_queued = $index;
2532
+ foreach ( $entry['encode_formats'] as $format => $value ) {
2533
+ if ( $value['status'] == "queued" && array_key_exists($format, $encode_list) ) { unset($encode_list[$format]); }
2534
+ if ( $value['status'] == "encoding" || $encode_checked[$format] != "true" ) { $queue_entry['encode_formats'][$format] = $entry['encode_formats'][$format]; } //don't edit queue entry for anything that's currently encoding or not checked
2535
+ if ( $parent_id == "check" ) { $parent_id = $entry['parent_id']; $queue_entry['parent_id'] = $entry['parent_id']; }
2536
+ }
2537
+ }
2538
+ }
2539
+ }
2540
+
2541
+ if ( $already_queued !== false ) {
2542
+ $video_embed_queue[$already_queued] = $queue_entry;
2543
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
2544
+ if ( !empty($encode_list) ) { $embed_display = "<strong>".implode(", " , $encode_list)." updated in existing queue entry in position ".strval(intval($already_queued)+1).". </strong>"; }
2545
+ else { $embed_display = "<strong>Video is already queued in position ".strval(intval($already_queued)+1).". </strong>"; }
2546
+ }
2547
+ else {
2548
+ $video_embed_queue[] = $queue_entry;
2549
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
2550
+ $queue_position = intval(key( array_slice( $video_embed_queue, -1, 1, TRUE ) ));
2551
+ if ( $queue_position == 0 ) { $embed_display = "<strong>Starting ".strtoupper($options['video_app'])."... </strong>"; }
2552
+ else { $embed_display = "<strong>".implode(", " , $encode_list)." added to queue in position ".strval(intval($queue_position)+1). ". </strong>";
2553
+ }
2554
+ }
2555
+ } //if any video formats don't already exist, add to queue
2556
+ else { $embed_display = "<strong>Nothing to encode.</strong>"; }
2557
+
2558
+ $replaceoptions = "";
2559
+ $originalselect = "";
2560
+
2561
+ $arr = array ( "embed_display"=>$embed_display );
2562
+ echo json_encode($arr);
2563
+ }
2564
+ else {
2565
+ $thumbnaildisplaycode = "<strong>Can't open movie file.</strong><br />".$movie_info['output'];
2566
+ $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "embed_display"=>$thumbnaildisplaycode, "lastthumbnumber"=>"break" );
2567
+ echo json_encode($arr);
2568
+ } //can't open movie
2569
+ }//if enqueue
2570
+
2571
+ function kgivd_save_singleurl_poster($parent_id, $poster, $movieurl) { //called by the "Embed Video from URL" tab when submitting
2572
+
2573
+ $sanitized_url = kgvid_sanitize_url($movieurl);
2574
+ if ( !empty($poster) ) { kgvid_save_thumb($parent_id, $sanitized_url['basename'], $poster); }
2575
+
2576
+ }//if submit
2577
 
2578
  function kgvid_callffmpeg() {
2579
 
2581
  global $wpdb;
2582
 
2583
  $options = get_option('kgvid_video_embed_options');
2584
+
2585
+ if (isset($_POST['attachmentID'])) { $postID = $_POST['attachmentID']; }
2586
+ if (isset($_POST['movieurl'])) { $movieurl = $_POST['movieurl']; }
 
2587
  if (isset($_POST['numberofthumbs'])) { $numberofthumbs = $_POST['numberofthumbs']; }
2588
  if (isset($_POST['thumbnumber'])) { $i = $_POST['thumbnumber']; }
2589
  if (isset($_POST['thumbnumberplusincreaser'])) { $iincreaser = $_POST['thumbnumberplusincreaser']; }
 
 
 
2590
  if (isset($_POST['thumbtimecode'])) { $thumbtimecode = $_POST['thumbtimecode']; }
2591
  if (isset($_POST['dofirstframe'])) { $dofirstframe = $_POST['dofirstframe']; }
2592
  if (isset($_POST['generate_button'])) { $generate_button = $_POST['generate_button']; }
2593
 
2594
+ if (isset($_POST['encodeformats'])) { $encode_checked = $_POST['encodeformats']; }
2595
+
2596
+ if (isset($_POST['poster'])) { $poster = $_POST['poster']; }
2597
+ if (isset($_POST['parent_id'])) { $parent_id = $_POST['parent_id']; }
2598
+ if ( !isset($parent_id) ) { $parent_id = "check"; }
2599
+
2600
+ if (isset($_POST['ffmpeg_action'])) { $action = $_POST['ffmpeg_action']; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2601
 
2602
+ if ( $options['ffmpeg_exists'] == true ) {
2603
 
2604
+ if ( $action == "generate" ) { echo kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser, $thumbtimecode, $dofirstframe, $generate_button); }
2605
+ if ( $action == "enqueue" ) { echo kgvid_enqueue_videos($postID, $movieurl, $encode_checked, $parent_id); }
2606
+ if ( $action == "submit" ) { kgivd_save_singleurl_poster($parent_id, $poster, $movieurl); }
2607
+ }
2608
+ else {
2609
+ $thumbnaildisplaycode = '<strong>Error: '.strtoupper($options["video_app"]).' not found. Verify that '.strtoupper($options["video_app"]).' is installed at '.strtoupper($options["app_path"]).' and check the <a href="options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php">application path plugin setting</a>.</strong>' ;
2610
  $arr = array ( "thumbnaildisplaycode"=>$thumbnaildisplaycode, "embed_display"=>$thumbnaildisplaycode, "lastthumbnumber"=>"break" );
2611
  echo json_encode($arr);
2612
+ }//no ffmpeg
 
 
 
 
 
 
 
 
 
 
 
2613
  die(); // this is required to return a proper result
2614
  }
2615
  add_action('wp_ajax_kgvid_callffmpeg', 'kgvid_callffmpeg');
2621
  $video_key = "";
2622
  $queued_format = "";
2623
  $encoding = "";
2624
+ $uploads = wp_upload_dir();
2625
  $movie_info = array("width"=>"", "height"=>"");
2626
  $video_embed_queue = get_option('kgvid_video_embed_queue');
2627
  $video_formats = kgvid_video_formats();
2658
  $options = get_option('kgvid_video_embed_options');
2659
 
2660
  $ffmpegPath = $options['app_path']."/".$options['video_app'];
2661
+ if ( get_post_type($video['attachmentID']) == "attachment" ) { $moviefilepath = get_attached_file($video['attachmentID']); }
2662
  else {
2663
  $moviefilepath = str_replace(" ", "%20", esc_url_raw($video['movieurl']));
2664
  $moviefilepath = str_replace("https://", "http://", $moviefilepath);
2672
  $processPID = "";
2673
  $serverOS = "";
2674
  $ffmpeg_options = "";
 
 
 
 
 
 
 
 
 
2675
 
2676
  if ( $options['video_app'] == "avconv" || $options['video_bitrate_flag'] == false ) {
2677
  $video_bitrate_flag = "b:v";
2700
  if ( $movie_info['configuration']['libvo_aacenc'] == "true" ) { $aaclib = "libvo_aacenc"; }
2701
  else { $aaclib = "libfaac"; }
2702
 
2703
+ if ( $format == "rotated" ) { $h264bitrate = round($h264_movie_width * 3); }
2704
+ else { $h264bitrate = round($h264_movie_height * 3); }
2705
  $vpre_flags = "";
2706
  if ( $options['ffmpeg_vpre'] == 'on' ) { $vpre_flags = '-vpre slow -vpre ipod640'; }
2707
 
2708
+ $ffmpeg_options = ' -acodec '.$aaclib.' -'.$audio_bitrate_flag.' 128k -s '.$h264_movie_width.'x'.$h264_movie_height.' -vcodec libx264 '.$vpre_flags.' -threads 1 '.$movie_info['rotate'].' -'.$video_bitrate_flag.' '.$h264bitrate.'k -bt 800k -f ipod "'.$encodevideo_info[$format.'filepath'].'"';
2709
  $embed_display .= "<strong>Encoding ".$format_stats['name']."</strong>";
2710
  }//if file doesn't already exist
2711
  else { $embed_display .= "<strong>".$format_stats['name']." already encoded. </strong>"; }
2725
  if ( ! $encodevideo_info['webm_exists'] || ($encodevideo_info['sameserver'] && filesize($encodevideo_info['webmfilepath']) < 24576) ) {
2726
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration']['libvpx'] == "true" ) {
2727
  $webmbitrate = $movie_info['height'] * 3;
2728
+ $ffmpeg_options = ' -'.$audio_bitrate_flag.' 128k -'.$video_bitrate_flag.' '.$webmbitrate.'k '.$movie_info['rotate'].' -threads 1 "'.$encodevideo_info['webmfilepath'].'"';
2729
  $embed_display .= "<strong>Encoding WEBM. </strong>";
2730
  }//if the necessary webm libraries are enabled
2731
  else {
2743
 
2744
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration']['libtheora'] == "true" ) {
2745
  $ogvbitrate = $movie_info['height'] * 3;
2746
+ $ffmpeg_options = ' -acodec libvorbis -'.$audio_bitrate_flag.' 128k -vcodec libtheora -'.$video_bitrate_flag.' '.$ogvbitrate.'k '.$movie_info['rotate'].' -threads 1 "'.$encodevideo_info['oggfilepath'].'"';
2747
  $embed_display .= "<strong>Encoding OGV. </strong>";
2748
  }//if the necessary OGV libraries are enabled
2749
  else {
2759
  if ( !empty($ffmpeg_options) ) {
2760
 
2761
  $ffmpeg_args = '-y -i "'.$moviefilepath.'" '.$ffmpeg_options;
2762
+ $logfile = $uploads['path'].'/'.str_replace(" ", "_", $encodevideo_info['moviefilebasename'])."_".$queued_format."_".sprintf("%04s",mt_rand(1, 1000))."_encode.txt";
2763
 
2764
  $cmd = escapeshellcmd($ffmpegPath." ".$ffmpeg_args);
2765
  if ( !empty($cmd) ) { $cmd = $cmd." > ".$logfile." 2>&1 & echo $!"; }
2766
  else {
2767
+ $arr = array ( "embed_display"=>"<span style='color:red;'>Error: Command 'escapeshellcmd' is disabled on your server.</span>" );
2768
  return $arr;
2769
  }
2770
  $process = new kgvid_Process($cmd);
2776
 
2777
  $args = array('logfile'=>$logfile);
2778
  wp_schedule_single_event(time()+600, 'kgvid_cleanup_generated_logfiles', $args);
2779
+ if ( !wp_next_scheduled('kgvid_cleanup_queue', array ( 'scheduled' )) ) {
2780
+ wp_schedule_event( time()+86400, 'daily', 'kgvid_cleanup_queue', array ( 'scheduled' ) );
2781
  }
2782
 
2783
  //update_post_meta($video['attachmentID'], '_kgflashmediaplayer-encode'.$format, 'on');
2786
  'name' => $video_formats[$queued_format]['name'],
2787
  'status' => 'encoding',
2788
  'filepath' => $encodevideo_info[$queued_format.'filepath'],
2789
+ 'url' => $encodevideo_info[$queued_format.'url'],
2790
  'logfile' => $logfile,
2791
  'PID' => $processPID,
2792
  'OS' => $serverOS,
2795
 
2796
  $queue_entry = array (
2797
  'attachmentID'=> $video['attachmentID'],
2798
+ 'parent_id'=>$video['parent_id'],
2799
  'movieurl' => $video['movieurl'],
2800
  'encode_formats'=> $video['encode_formats'],
2801
  'movie_info' => $video['movie_info']
2835
 
2836
  function kgvid_encode_progress($video_key, $format, $page) {
2837
 
2838
+ $video_embed_queue = get_option('kgvid_video_embed_queue');
2839
+
2840
+ if ( is_array($video_embed_queue) && array_key_exists($video_key, $video_embed_queue) ) {
2841
+
2842
+ if ( array_key_exists('logfile', $video_embed_queue[$video_key]['encode_formats'][$format]) ) {
2843
+ $video_entry = $video_embed_queue[$video_key];
2844
+ $pid = $video_entry['encode_formats'][$format]['PID'];
2845
+ $logfile = $video_entry['encode_formats'][$format]['logfile'];
2846
+ $started = $video_entry['encode_formats'][$format]['started'];
2847
+ $movie_duration = $video_entry['movie_info']['duration'];
2848
+ $rotate_complete = false;
2849
+ $embed_display = "";
2850
+ $percent_done = "";
2851
+ $time_remaining = "";
2852
+ $other_message = "";
2853
+ $logfilecontents = "";
2854
+ $lastline = "";
2855
+
2856
+ if ( $video_entry['encode_formats'][$format]['status'] != "Encoding Complete" ) {
2857
+
2858
+ if ( is_file($logfile) ) {
2859
+
2860
+ $fp = fopen($logfile, 'r');
2861
+ $c = '';
2862
+ $read = '';
2863
+ $offset = -1;
2864
+ $lines = 2;
2865
+ while ( $lines && fseek($fp, $offset, SEEK_END) >= 0 ) {
2866
+ $c = fgetc($fp);
2867
+ if( $c == "\n" || $c == "\r" ) {
2868
+ $lines--;
2869
+ }
2870
+ $read .= $c;
2871
+ $offset--;
2872
+ }
2873
+ fclose($fp);
2874
+ $lastline = strrev(rtrim($read,"\n\r"));
 
 
2875
 
2876
+ $last_match = "";
2877
+ $time_matches = "";
2878
+ $video_matches = "";
2879
+ $libx264_matches = "";
2880
+ $fps_matches = "";
2881
+ $fps_match = "";
2882
+ $basename = "";
2883
+
2884
+ $script_function = 'kgvid_redraw_encode_checkboxes("'.$video_entry['movieurl'].'", "'.$video_entry['attachmentID'].'", "'.$page.'")';
2885
 
2886
+ preg_match('/time=(.*?) /', $lastline, $time_matches);
 
 
 
 
 
 
2887
 
2888
+ if ( array_key_exists(1, $time_matches) != true ) { //if something other than the regular FFMPEG encoding output check for these
2889
+ preg_match('/video:(.*?) /', $lastline, $video_matches);
2890
+ preg_match('/libx264 (.*?) /', $lastline, $libx264_matches);
2891
+ //preg_match('/h264 (.*?) /', $lastline, $h264_matches);
2892
+ //preg_match('/Press (.*?) /', $lastline, $Press_matches);
2893
+ //preg_match('/buffer (.*?) /', $lastline, $buffer_matches);
2894
+ }
2895
+ if ( array_key_exists(1, $time_matches) == true ) { //still encoding
2896
 
2897
+ if ( strpos($time_matches[1], ':') !== false ) {
2898
+ $current_hours = intval(substr($time_matches[1], -11, 2));
2899
+ $current_minutes = intval(substr($time_matches[1], -8, 2));
2900
+ $current_seconds = intval(substr($time_matches[1], -5, 2));
2901
+ $current_seconds = ($current_hours * 60 * 60) + ($current_minutes * 60) + $current_seconds;
2902
+ }
2903
+ else { $current_seconds = $time_matches[1]; }
2904
+
2905
+ $percent_done = intval($current_seconds)/intval($movie_duration);
2906
+ $time_elapsed = time() - $started;
2907
+ if ( $percent_done != 0 ) { $time_remaining = date('H:i:s', round($time_elapsed / $percent_done) - $time_elapsed); }
2908
+ else $time_remaining = "unknown";
2909
+ $percent_done = round($percent_done*100);
2910
+ if ( $percent_done < 20 ) { $percent_done_text = ""; }
2911
+ else { $percent_done_text = strval($percent_done)."%"; }
2912
+
2913
+ preg_match('/fps=\s+(.*?) /', $lastline, $fps_matches);
2914
+ if ( array_key_exists(1, $fps_matches) == true ) {
2915
+ if ( $fps_matches[1] != 0 ) { $fps_match = $fps_matches[1]; }
2916
+ else { $fps_match = "10"; }
2917
+ }
2918
+ else { $fps_match = "10"; }
2919
+ $time_to_wait = strval(max(round(30000/intval($fps_match)), 1000)); //wait at least 1 second
2920
+ if ( intval($time_to_wait) > 10000 ) { //wait no more than 10 seconds
2921
+ $time_to_wait = 10000;
2922
+ }
2923
 
2924
+ $args = array($video_key, $format, $page);
2925
+ wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
2926
+
2927
+ $embed_display = '<strong>'.ucwords($video_entry['encode_formats'][$format]['status']).'</strong> <div class="kgvid_meter"><div class="kgvid_meter_bar" style="width:'.$percent_done.'%;"><div class="kgvid_meter_text">'.$percent_done_text.'</div></div></div><a href="javascript:void(0);" class="kgvid_cancel_button" id="attachments-'.$video_entry["attachmentID"].'-kgflashmediaplayer-cancelencode" onclick="kgvid_cancel_encode('.$pid.', \''.$video_entry["attachmentID"].'\', \''.$video_key.'\', \''.$format.'\');">Cancel</a><div style="display:block;"><small>Elapsed: '.date('H:i:s',$time_elapsed).'. Remaining: '.$time_remaining.'. FPS:'.$fps_match.'</small></div><script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, '.$time_to_wait.');</script>';
2928
+ }
2929
+ elseif ( time() - $started < 10 ) { //not enough time has passed, so check again later
2930
+ $args = array($video_key, $format, $page);
2931
+ $embed_display = '<strong>Encoding</strong> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
2932
+ wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
2933
+ }
2934
+ elseif ( array_key_exists(1, $video_matches) == true || array_key_exists(1, $libx264_matches) == true ) { //encoding complete
2935
+ $percent_done = 100;
2936
+ $ended = filemtime($logfile);
2937
+ $time_elapsed = $ended - $started;
2938
+ $time_remaining = "0";
2939
+ $fps_match = "10";
2940
+ if ( array_key_exists(1, $libx264_matches) ) { kgvid_fix_moov_atom($video_key, $format); } //fix the moov atom if the file was encoded by libx264
2941
+ $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "Encoding Complete";
2942
+ $video_embed_queue[$video_key]['encode_formats'][$format]['ended'] = $ended;
2943
+ $video_embed_queue[$video_key]['encode_formats'][$format]['lastline'] = $lastline;
2944
+
2945
+ if ( $format == "rotated" ) {
2946
+
2947
+ $video_embed_queue[$video_key]['movie_info']['rotate'] = ""; //clear rotation because we've just fixed that problem
2948
+ delete_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-rotate');
2949
+
2950
+ //$setwidth = get_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-width', true);
2951
+ //$setheight = get_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-height', true);
2952
+ $setwidth = $video_entry['movie_info']['width'];
2953
+ $setheight = $video_entry['movie_info']['height'];
2954
+ if ( intval($setwidth) > intval($setheight) ) { //swap the width and height meta if it hasn't already been done
2955
+ update_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-actualwidth', $video_entry['movie_info']['height']);
2956
+ update_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-width', $setheight);
2957
+ $video_embed_queue[$video_key]['movie_info']['width'] = $video_entry['movie_info']['height'];
2958
+ update_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-actualheight', $video_entry['movie_info']['width']);
2959
+ update_post_meta($video_entry['attachmentID'], '_kgflashmediaplayer-height', $setwidth);
2960
+ $video_embed_queue[$video_key]['movie_info']['height'] = $video_entry['movie_info']['width'];
2961
+ }
2962
+ $video_embed_queue[$video_key]['encode_formats'][$format]['url'] = $video_embed_queue[$video_key]['movieurl'];
2963
+
2964
+ $original_filename = get_attached_file($video_entry['attachmentID']);
2965
+ if (file_exists($video_embed_queue[$video_key]['encode_formats'][$format]['filepath'])) rename($video_embed_queue[$video_key]['encode_formats'][$format]['filepath'], $original_filename);
2966
+ // you must first include the image.php file
2967
+ // for the function wp_generate_attachment_metadata() to work and media.php for wp_read_video_metadata() in WP 3.6+
2968
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
2969
+ global $wp_version;
2970
+ if ( $wp_version >= 3.6 ) { require_once(ABSPATH . 'wp-admin/includes/media.php'); }
2971
+ $attach_data = wp_generate_attachment_metadata( $video_entry['attachmentID'], $original_filename );
2972
+ wp_update_attachment_metadata( $video_entry['attachmentID'], $attach_data );
2973
+ $rotate_complete = true;
2974
+
2975
+ } //end rotated video replacement
2976
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
2977
 
2978
+ //insert the encoded video as a child attachment of the original video, or post if external original
2979
+ if ( get_post_type($video_entry['attachmentID']) == "attachment" ) { //if the original video is in the database set that as parent
2980
+ $parent_id = $video_entry['attachmentID'];
2981
+ $title = get_the_title($video_entry['attachmentID']);
2982
+ }
2983
+ else { //otherwise set the post as the parent
2984
+ $parent_id = $video_entry['parent_id'];
2985
+ $sanitized_url = kgvid_sanitize_url($video_entry['movieurl']);
2986
+ $title = $sanitized_url['basename'];
2987
+ }
2988
+ global $wpdb;
2989
+ $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='".$video_embed_queue[$video_key]['encode_formats'][$format]['url']."'"; //check for existing entry in the db
2990
+ $video_id = $wpdb->get_var($query);
2991
+ if ( !$video_id ) {
2992
+ $wp_filetype = wp_check_filetype(basename($video_entry['encode_formats'][$format]['filepath']), null );
2993
+ $video_formats = kgvid_video_formats();
2994
+ $title .= " ".$video_formats[$format]['name'];
2995
+ $attachment = array(
2996
+ 'guid' => $video_entry['encode_formats'][$format]['url'],
2997
+ 'post_mime_type' => $wp_filetype['type'],
2998
+ 'post_title' => $title,
2999
+ 'post_content' => '',
3000
+ 'post_status' => 'inherit'
3001
+ );
3002
+ $new_id = wp_insert_attachment( $attachment, $video_entry['encode_formats'][$format]['filepath'], $parent_id );
3003
+ // you must first include the image.php file
3004
+ // for the function wp_generate_attachment_metadata() to work and media.php for wp_read_video_metadata() in WP 3.6+
3005
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
3006
+ global $wp_version;
3007
+ if ( $wp_version >= 3.6 ) { require_once(ABSPATH . 'wp-admin/includes/media.php'); }
3008
+ require_once(ABSPATH . 'wp-admin/includes/media.php');
3009
+ $attach_data = wp_generate_attachment_metadata( $new_id, $video_entry['encode_formats'][$format]['filepath'] );
3010
+ wp_update_attachment_metadata( $new_id, $attach_data );
3011
+ update_post_meta( $new_id, '_kgflashmediaplayer-format', $format );
3012
+ if ( get_post_type($video_entry['attachmentID']) == false ) { update_post_meta( $new_id, '_kgflashmediaplayer-externalurl', $video_entry['movieurl'] ); } //connect new video to external url
3013
+ }
3014
+
3015
+ //finish inserting attachment
3016
 
3017
+ $embed_display = '<strong>Encoding Complete</strong> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
3018
+ $next_video = kgvid_encode_videos(); //start the next queued video
3019
+ if ( !empty($next_video['format']) ) {
3020
+ $args = array($next_video['video_key'], $next_video['format'], $page);
3021
+ wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
3022
+ }
3023
+ }
3024
+ else { //there was an error";
3025
+ if ( strpos($lastline, "signal 15") !== false ) { //if the encoding was intentionally canceled
3026
+ $lastline = "Encoding was canceled.";
3027
+ }
3028
+ $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "error";
3029
+ $video_embed_queue[$video_key]['encode_formats'][$format]['lastline'] = $lastline;
3030
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
3031
+ $other_message = $lastline;
3032
+ $embed_display = '<strong>Error: </strong><span style="color:red;">'.$lastline.'.</span> <script type="text/javascript">percent_timeout = setTimeout(function(){'.$script_function.'}, 1000);</script>';
3033
+ $next_video = kgvid_encode_videos(); //start the next queued video
3034
+ if ( !empty($next_video['format']) ) {
3035
+ $args = array($next_video['video_key'], $next_video['format'], $page);
3036
+ wp_schedule_single_event(time()+60, 'kgvid_cron_queue_check', $args);
3037
+ }
3038
+ }
3039
+
3040
+ //$embed_display .= $lastline;
3041
+ $arr = array ( "embed_display"=>$embed_display, "rotate_complete"=>$rotate_complete );
 
 
 
 
 
 
 
 
 
 
 
 
 
3042
  }
3043
+ else { $arr = array ( "embed_display"=>"<strong>No log file</strong>" ); }
3044
 
3045
+ }//if not completed
3046
+ else { $arr = array ( "embed_display"=>"<strong>".ucwords($video_embed_queue[$video_key]['encode_formats'][$format]['status'])."</strong>" ); }
3047
+ } //if there's a queue and the video is encoding
3048
+ else { $arr = array ( "embed_display"=>"<strong>Waiting...</strong>" ); }
3049
+ return $arr;
3050
+
3051
+ }//end if queue entry exists
3052
 
3053
  }
3054
  add_action('kgvid_cron_queue_check', 'kgvid_encode_progress', 1, 3);
3191
  check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3192
  global $wpdb;
3193
  $deleted = false;
3194
+ $attachment_id = "";
3195
+ if ( isset($_POST['movieurl']) ) { $movieurl = $_POST['movieurl']; }
3196
+ if ( isset($_POST['postid']) ) { $post_id = $_POST['postid']; }
3197
+ if ( isset($_POST['format']) ) { $format = $_POST['format']; }
3198
+ if ( isset($_POST['childid']) ) { $attachment_id = $_POST['childid']; }
3199
+ if ( empty($attachment_id) ) { //if there's no post_meta giving us the attachment to delete
3200
+ $encodevideo_info = kgvid_encodevideo_info($movieurl, $post_id);
3201
+ if ( is_file($encodevideo_info[$format.'filepath']) ) {
3202
+ $deleted = unlink($encodevideo_info[$format.'filepath']);
3203
+ }
3204
+ }
3205
+ else {
3206
+ $deleted = wp_delete_attachment($attachment_id);
3207
+ if ( !empty($deleted) ) { $deleted = true; }
3208
+ }
3209
+ $video_embed_queue = get_option('kgvid_video_embed_queue');
3210
+ /*if ( !empty($video_embed_queue) ) {
3211
+ foreach ($video_embed_queue as $video_key => $video_entry) {
3212
+ if ( $video_entry['movieurl'] == $movieurl ) {
3213
+ $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "deleted";
3214
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
3215
+ break;
3216
+ }
3217
  }
3218
+ }*/
3219
+ echo($deleted);
3220
+ die();
3221
+
3222
+ }
3223
+ add_action('wp_ajax_kgvid_delete_video', 'kgvid_ajax_delete_video');
3224
+
3225
+ function kgvid_delete_video_attachment($video_id) {
3226
+
3227
+ if ( strpos(get_post_mime_type( $video_id ), 'video') !== false ) { //only do this for videos
3228
+ global $wpdb;
3229
+ $parent_post = get_post($video_id);
3230
+ $options = get_option('kgvid_video_embed_options');
3231
  $video_embed_queue = get_option('kgvid_video_embed_queue');
3232
+ $parent_id = get_post($video_id)->post_parent;
3233
+ $wp_attached_file = get_post_meta($video_id, '_wp_attached_file', true);
3234
+
3235
+ if ( !empty($video_embed_queue) ) { //remove any encode queue entry related to this attachment
3236
  foreach ($video_embed_queue as $video_key => $video_entry) {
3237
+ if ( $video_entry['attachmentID'] == $video_id ) {
3238
+ unset($video_embed_queue[$video_key]);
3239
+ sort($video_embed_queue);
3240
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
3241
  break;
3242
+ }//if the video is an original format
3243
+ if ( $video_entry['attachmentID'] == $parent_id || get_post_meta($video_id, '_kgflashmediaplayer-externalurl', true) == $video_entry['movieurl'] ) {
3244
+ foreach ( $video_entry['encode_formats'] as $format => $value ) {
3245
+ if ( array_key_exists('filepath', $value) ) {
3246
+ if ( strpos($value['filepath'], $wp_attached_file) !== false ) {
3247
+ $video_embed_queue[$video_key]['encode_formats'][$format]['status'] = "deleted";
3248
+ update_option('kgvid_video_embed_queue', $video_embed_queue);
3249
+ break;
3250
+ }//if the format has filepath information
3251
+ }//if the encoded child format is in the database
3252
+ }//loop through formats
3253
+ }//if the video is a child format
3254
+ }
3255
+ }
3256
+
3257
+ $args = array(
3258
+ 'post_parent' => $video_id,
3259
+ 'post_type' => 'attachment',
3260
+ 'numberposts' => '-1'
3261
+ );
3262
+ $posts = get_posts( $args ); //find all children of the video in the database
3263
+ if ($posts) {
3264
+ foreach ($posts as $post) {
3265
+ wp_update_post( array( 'ID' => $post->ID, 'post_parent' => $parent_id ) ); //set post_parent field to the original video's post_parent
3266
+ if ( $options['delete_children'] != 'none' ) {
3267
+ if ( $options['delete_children'] == 'all' ) { wp_delete_attachment($post->ID, true); }
3268
+ else if ( strpos($post->post_mime_type, 'video') !== false ) { wp_delete_attachment($post->ID, true); } //only delete videos
3269
  }
3270
+ }//end loop
3271
+ }//end if there are any children
3272
+ }//end if video
3273
+
3274
+ elseif ( strpos(get_post_mime_type( $video_id ), 'image') !== false ) {
3275
+ $args = array(
3276
+ 'numberposts' => '-1',
3277
+ 'post_type' => 'attachment',
3278
+ 'meta_key' => '_kgflashmediaplayer-poster-id',
3279
+ 'meta_value' => $video_id
3280
+ );
3281
+ $posts = get_posts( $args ); //find all posts that have this thumbnail ID in their meta
3282
+ if ( $posts ) {
3283
+ foreach ($posts as $post) {
3284
+ delete_post_meta($post->ID, '_kgflashmediaplayer-poster-id');
3285
+ delete_post_meta($post->ID, '_thumbnail-id');
3286
+ delete_post_meta($post->ID, '_kgflashmediaplayer-poster');
3287
  }
3288
  }
 
3289
  }
3290
+ }
3291
+ add_action('delete_attachment', 'kgvid_delete_video_attachment');
3292
+
3293
+ function kgvid_get_set_featured() {
3294
+
3295
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3296
+
3297
+ global $wpdb;
3298
 
3299
+ /* $querystr = "
3300
+ SELECT $wpdb->posts.*
3301
+ FROM $wpdb->posts, $wpdb->postmeta
3302
+ WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
3303
+ AND $wpdb->postmeta.meta_key = '_kgflashmediaplayer-poster-id'
3304
+ ORDER BY $wpdb->posts.post_date ASC
3305
+ ";
3306
+ $videoposts = $wpdb->get_results($querystr, OBJECT); */
3307
+
3308
+ $args = array(
3309
+ 'post_type' => null,
3310
+ 'numberposts' => -1,
3311
+ 'meta_key' => '_kgflashmediaplayer-poster-id'
3312
+ );
3313
+ $videoposts = get_posts( $args );
3314
+
3315
+ if ($videoposts) {
3316
+ foreach ($videoposts as $post) {
3317
+ if ( $post->post_type == "attachment" ) { $post_id = $post->post_parent; }
3318
+ else { $post_id = $post->ID; }
3319
+ $poster_id = get_post_meta($post->ID, "_kgflashmediaplayer-poster-id", true);
3320
+ if ( !empty($post_id) && !empty($poster_id) ) { $posts[$post_id] = $poster_id; }
3321
+ }//end loop
3322
+ }//end if posts
3323
+
3324
+ $cms_switch_queue = get_option('kgvid_video_embed_cms_switch');
3325
+ $cms_switch_queue['set_featured'] = $posts;
3326
+ update_option('kgvid_video_embed_cms_switch', $cms_switch_queue);
3327
+ echo count($posts);
3328
+ die;
3329
  }
3330
+ add_action('wp_ajax_kgvid_get_set_featured', 'kgvid_get_set_featured');
3331
 
3332
+ function kgvid_set_featured() {
3333
+
3334
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3335
+ $queue = get_option('kgvid_video_embed_cms_switch');
3336
+ if ( $queue['set_featured'] ) {
3337
+ foreach ( $queue['set_featured'] as $post_id => $poster_id ) {
3338
+ set_post_thumbnail($post_id, $poster_id);
3339
+ unset($queue['switching_parents'][$post_id]);
3340
+ update_option('kgvid_video_embed_cms_switch', $queue);
3341
+ }
3342
+ unset($queue['set_featured']);
3343
+ if ( empty($queue) ) { delete_option('kgvid_video_embed_cms_switch'); }
3344
+ else { update_option('kgvid_video_embed_cms_switch', $queue); }
3345
+ }
3346
+ die;
3347
  }
3348
+ add_action('wp_ajax_kgvid_set_featured', 'kgvid_set_featured');
3349
 
3350
+ function kgvid_get_switch_parents() {
3351
+
3352
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3353
+ $new_parent = 'post';
3354
+ if (isset($_POST['parent'])) { $new_parent = $_POST['parent']; }
3355
+ $children = array();
3356
+
3357
+ if ( $new_parent == 'post' ) {
3358
+
3359
+ $args = array(
3360
+ 'orderby' => 'post_date',
3361
+ 'order' => 'ASC',
3362
+ 'post_type' => 'attachment',
3363
+ 'numberposts' => -1,
3364
+ 'post_mime_type' => 'video'
3365
+ );
3366
+ $attachments = get_posts( $args );
3367
+
3368
+ if ($attachments) {
3369
+ foreach ($attachments as $post) {
3370
+ if ( !empty($post->post_parent) ) { //if the video is attached to a post
3371
+ $args = array(
3372
+ 'orderby' => 'post_date',
3373
+ 'order' => 'ASC',
3374
+ 'post_parent' => $post->ID,
3375
+ 'post_type' => 'attachment',
3376
+ 'post_mime_type' => 'image',
3377
+ 'numberposts' => -1
3378
+ );
3379
+ $thumbnails = get_posts( $args );
3380
+ if ($thumbnails) {
3381
+ foreach ( $thumbnails as $thumbnail ) {
3382
+ $children[$thumbnail->ID] = array( 'post_parent' => $post->post_parent, 'video_id' => $post->ID );
3383
+ }
3384
+ }//end if there are children
3385
+ }//end if it has a parent
3386
+ }//end loop
3387
+ }//end if posts
3388
+ }//end if new parent is post
3389
+
3390
+ if ( $new_parent == 'video' ) {
3391
+
3392
+ $args = array(
3393
+ 'orderby' => 'post_date',
3394
+ 'order' => 'ASC',
3395
+ 'post_type' => 'attachment',
3396
+ 'post_mime_type' => 'image',
3397
+ 'meta_key' => '_kgflashmediaplayer-video-id',
3398
+ 'numberposts' => -1
3399
+ );
3400
+ $thumbnails = get_posts( $args );
3401
+
3402
+ if ( $thumbnails ) {
3403
+ foreach ($thumbnails as $thumbnail) {
3404
+ $video_id = get_post_meta($thumbnail->ID, '_kgflashmediaplayer-video-id', true);
3405
+ $children[$thumbnail->ID] = array( 'post_parent' => false, 'video_id' => $video_id );
3406
+ }
3407
+ }
3408
+ }
3409
+ $cms_switch_queue = get_option('kgvid_video_embed_cms_switch');
3410
+ $cms_switch_queue['switching_parents'] = $children;
3411
+ update_option('kgvid_video_embed_cms_switch', $cms_switch_queue);
3412
+ echo count($children);
3413
+ die;
3414
+ }
3415
+ add_action('wp_ajax_kgvid_get_switch_parents', 'kgvid_get_switch_parents');
3416
+
3417
+ function kgvid_switch_parents() {
3418
+
3419
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3420
+ $queue = get_option('kgvid_video_embed_cms_switch');
3421
+ if ( $queue['switching_parents'] ) {
3422
+ $new_parent = 'post';
3423
+ if (isset($_POST['parent'])) { $new_parent = $_POST['parent']; }
3424
+
3425
+ foreach ( $queue['switching_parents'] as $thumbnail_id => $thumbnail ) {
3426
+ if ( $new_parent == 'post' ) {
3427
+ wp_update_post( array( 'ID' => $thumbnail_id, 'post_parent' => $thumbnail['post_parent'] ) );
3428
+ update_post_meta($thumbnail_id, '_kgflashmediaplayer-video-id', $thumbnail['video_id']);
3429
+ }
3430
+
3431
+ if ( $new_parent == 'video' ) {
3432
+ wp_update_post( array( 'ID' => $thumbnail_id, 'post_parent' => $thumbnail['video_id'] ) );
3433
+ }
3434
+ unset($queue['switching_parents'][$thumbnail_id]);
3435
+ update_option('kgvid_video_embed_cms_switch', $queue);
3436
+ }
3437
+ unset($queue['switching_parents']);
3438
+ if ( empty($queue) ) { delete_option('kgvid_video_embed_cms_switch'); }
3439
+ else { update_option('kgvid_video_embed_cms_switch', $queue); }
3440
+ }
3441
+ die;
3442
+ }
3443
+ add_action('wp_ajax_kgvid_switch_parents', 'kgvid_switch_parents');
3444
+
3445
+ function kgvid_update_cms_progress() {
3446
+
3447
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3448
+ $remaining = 0;
3449
+ if (isset($_POST['cms_type'])) { $type = $_POST['cms_type']; }
3450
+ if (isset($_POST['total'])) { $total = $_POST['total']; }
3451
+ $queue = get_option('kgvid_video_embed_cms_switch');
3452
+ if ( is_array($queue) ) {
3453
+ if ( array_key_exists($type, $queue) ) { $remaining = count($queue[$type]); }
3454
+ }
3455
+ echo $remaining;
3456
+ die;
3457
+
3458
+ }
3459
+ add_action('wp_ajax_kgvid_update_cms_progress', 'kgvid_update_cms_progress');
3460
+
3461
+ function kgvid_singleurl_meta_box($postType) {
3462
+
3463
+ $matches = kgvid_check_for_shortcode_in_content();
3464
+
3465
+ if ( $matches[5] ) {
3466
+ add_meta_box(
3467
+ 'kgvid_singleurl_meta',
3468
+ 'Video Embed & Thumbnail Generator',
3469
+ 'kgvid_singleurl_inner_custom_box',
3470
+ $postType
3471
+ );
3472
+ }
3473
+ }
3474
+ add_action( 'add_meta_boxes', 'kgvid_singleurl_meta_box' );
3475
+
3476
+ function kgvid_singleurl_inner_custom_box($post) {
3477
+
3478
+ global $wpdb;
3479
+
3480
+ $video_formats = kgvid_video_formats();
3481
+ $matches = kgvid_check_for_shortcode_in_content();
3482
+ $urls = array_unique($matches[5]);
3483
+ if ( $urls ) {
3484
+ $nonce = wp_create_nonce('video-embed-thumbnail-generator-nonce');
3485
+ echo '<h4>Alternate formats of embedded videos</h4>';
3486
+ foreach ( $urls as $movieurl ) {
3487
+ $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='{$movieurl}'"; //GUID seems to be the only way to get a video URL
3488
+ $video_id = $wpdb->get_var($query);
3489
+
3490
+ echo '<div class="kgvid_post_meta_boxes">';
3491
+ if ( empty($video_id) ) {
3492
+ $sanitized_url = kgvid_sanitize_url($movieurl);
3493
+ echo '<input type="hidden" name="attachments['.$sanitized_url['singleurl_id'].'][kgflashmediaplayer-security]" value="'.$nonce.'">';
3494
+ echo '<strong>'.$sanitized_url['basename'].'</strong>';
3495
+ echo kgvid_generate_encode_checkboxes($movieurl, $sanitized_url['singleurl_id'], 'queue');
3496
+ echo '<input type="button" id="attachments-'.$sanitized_url['singleurl_id'].'-kgflashmediaplayer-update" name="attachments['.$sanitized_url['singleurl_id'].'][kgflashmediaplayer-update]" class="button-secondary" value="Re-scan External Server" onclick="kgvid_rescan_external_server(\''.$movieurl.'\', \''.$sanitized_url['singleurl_id'].'\');" /><span id="attachments-'.$sanitized_url['singleurl_id'].'-kgflashmediaplayer-rescanplaceholder"></span>';
3497
+ }
3498
+ else {
3499
+ echo '<input type="hidden" name="attachments['.$video_id.'][kgflashmediaplayer-security]" value="'.$nonce.'">';
3500
+ echo '<strong>'.get_the_title($video_id).'</strong>';
3501
+ echo kgvid_generate_encode_checkboxes($movieurl, $video_id, 'queue');
3502
+ }
3503
+ echo '</div>';
3504
+ }//loop through KGVID URLs
3505
+ }//if there are any KGVID URLs
3506
+ }
3507
+
3508
+ function kgvid_ajax_rescan_external_server() {
3509
+
3510
+ check_ajax_referer( 'video-embed-thumbnail-generator-nonce', 'security' );
3511
+ if (isset($_POST['movieurl'])) { $movieurl = $_POST['movieurl']; }
3512
+ if (isset($_POST['postID'])) { $post_id = $_POST['postID']; }
3513
+ $video_formats = kgvid_video_formats();
3514
+ $matching_posts = array();
3515
+ foreach ( $video_formats as $format => $format_stats ) {
3516
+ $args = array(
3517
+ 'numberposts' => '-1',
3518
+ 'post_type' => null,
3519
+ 'meta_key' => '_kgflashmediaplayer-'.$post_id.'-'.$format
3520
+ );
3521
+ $posts = get_posts($args);
3522
+ if ( $posts ) {
3523
+ foreach ( $posts as $post ) {
3524
+ $matching_posts[$post->ID] = $post;
3525
+ delete_post_meta($post->ID, '_kgflashmediaplayer-'.$post_id.'-'.$format);
3526
+ }
3527
+ }
3528
+ }
3529
+ if ( $matching_posts ) {
3530
+ foreach ( $matching_posts as $post ) { kgvid_encodevideo_info($movieurl, $post->ID); }
3531
+ }
3532
+ die;
3533
+ }
3534
+ add_action('wp_ajax_kgvid_rescan_external_server', 'kgvid_ajax_rescan_external_server');
3535
 
3536
  function kgvid_count_play() {
3537
  $post_id = $_POST['post_id'];
3543
  echo 'ajax submitted';
3544
  die(); // stop executing script
3545
  }
3546
+ add_action( 'wp_ajax_kgvid_count_play', 'kgvid_count_play' ); // ajax for logged in users
3547
+ add_action( 'wp_ajax_nopriv_kgvid_count_play', 'kgvid_count_play' ); // ajax for not logged in users
3548
 
3549
  function kgvid_deactivate() {
3550
+ wp_clear_scheduled_hook('kgvid_cleanup_queue', array( 'scheduled' ) );
3551
  delete_option('kgvid_video_embed_queue');
3552
  }
3553
  register_deactivation_hook( __FILE__, 'kgvid_deactivate' );
video-js/kg-video-js-skin.css CHANGED
@@ -241,9 +241,9 @@
241
  ---------------------------------------------------------*/
242
  .kg-video-js-skin .vjs-big-play-button {
243
  display: block; /* Start hidden */ z-index: 2;
244
- position: absolute; top: 50%; left: 50%; width: 8.0em; height: 8.0em; margin: -42px 0 0 -42px; text-align: center; vertical-align: center; cursor: pointer !important;
245
  border: 0.8em solid #fff; opacity: 0.7;
246
- -webkit-border-radius: 50px; -moz-border-radius: 50px; border-radius: 50px;
247
 
248
  background: #454545;
249
  background: -moz-linear-gradient(top, #454545 0%, #232323 50%, #161616 50%, #3f3f3f 100%);
241
  ---------------------------------------------------------*/
242
  .kg-video-js-skin .vjs-big-play-button {
243
  display: block; /* Start hidden */ z-index: 2;
244
+ position: absolute; top: 49%; left: 49%; width: 8.0em; height: 8.0em; margin: -42px 0 0 -42px; text-align: center; vertical-align: center; cursor: pointer !important;
245
  border: 0.8em solid #fff; opacity: 0.7;
246
+ -webkit-border-radius: 100px; -moz-border-radius: 100px; border-radius: 100px;
247
 
248
  background: #454545;
249
  background: -moz-linear-gradient(top, #454545 0%, #232323 50%, #161616 50%, #3f3f3f 100%);