Version Description
- Enhancement: What have I been doing during the pandemic? Picking through this code and resolving coding standards. Sigh. There's a LOT. Not all are done but will be in future updates but, for now, the majority are. Based on the amount of code I've had to change, I'm worried I've broken something. But, you know, every day's a school day and this has taught me a LOT
- Enhancement: Look, I know I keep moving it but the plugin settings really shouldn't be anywhere other than under the Settings menu. So I've moved it back there
- Enhancement: Added native lazy loading to the videos. I'll maybe look to add it to the thumbnails at a later time - does anybody want that?
- Enhancement: I've improved the cache key generation. But, what this does mean, is that updating will cause all your YouTube Embed caches to clear. All your cache are belong to us
- Enhancement: Clarified the API sign-up process in the README
Download this release
Release Info
Developer | dartiss |
Plugin | YouTube Embed |
Version | 5.2 |
Comparing to | |
See all releases |
Code changes from version 5.1.1 to 5.2
- css/admin.css +17 -17
- css/main.css +16 -16
- includes/add-scripts.php +240 -256
- includes/admin-config.php +345 -332
- includes/api-access.php +122 -89
- includes/caching.php +94 -104
- includes/generate-embed-code.php +443 -263
- includes/generate-other-code.php +171 -148
- includes/generate-widgets.php +239 -208
- includes/options-general.php +520 -323
- includes/options-lists.php +258 -236
- includes/options-profiles.php +841 -422
- includes/shared-functions.php +549 -567
- includes/shortcodes.php +429 -352
- readme.txt +27 -9
- uninstall.php +59 -58
- youtube-embed.php +36 -36
css/admin.css
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
-
|
2 |
-
.ye-container {
|
3 |
-
position: relative;
|
4 |
-
padding-bottom: 56.25%;
|
5 |
-
padding-top: 0;
|
6 |
-
height: 0;
|
7 |
-
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
}
|
9 |
-
|
10 |
-
.ye-container iframe,
|
11 |
-
.ye-container object,
|
12 |
-
.ye-container embed {
|
13 |
-
position: absolute;
|
14 |
-
top: 0;
|
15 |
-
left: 0;
|
16 |
-
width: 100%;
|
17 |
-
height: 100%;
|
18 |
-
}
|
1 |
+
|
2 |
+
.ye-container {
|
3 |
+
position: relative;
|
4 |
+
padding-bottom: 56.25%;
|
5 |
+
padding-top: 0;
|
6 |
+
height: 0;
|
7 |
+
overflow: hidden;
|
8 |
+
}
|
9 |
+
|
10 |
+
.ye-container iframe,
|
11 |
+
.ye-container object,
|
12 |
+
.ye-container embed {
|
13 |
+
position: absolute;
|
14 |
+
top: 0;
|
15 |
+
left: 0;
|
16 |
+
width: 100%;
|
17 |
+
height: 100%;
|
18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css/main.css
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
-
.ye-container {
|
2 |
-
position: relative;
|
3 |
-
padding-bottom: 56.25%;
|
4 |
-
padding-top: 0;
|
5 |
-
height: 0;
|
6 |
-
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
-
|
9 |
-
.ye-container iframe,
|
10 |
-
.ye-container object,
|
11 |
-
.ye-container embed {
|
12 |
-
position: absolute;
|
13 |
-
top: 0;
|
14 |
-
left: 0;
|
15 |
-
width: 100%;
|
16 |
-
height: 100%;
|
17 |
-
}
|
1 |
+
.ye-container {
|
2 |
+
position: relative;
|
3 |
+
padding-bottom: 56.25%;
|
4 |
+
padding-top: 0;
|
5 |
+
height: 0;
|
6 |
+
overflow: hidden;
|
7 |
+
}
|
8 |
+
|
9 |
+
.ye-container iframe,
|
10 |
+
.ye-container object,
|
11 |
+
.ye-container embed {
|
12 |
+
position: absolute;
|
13 |
+
top: 0;
|
14 |
+
left: 0;
|
15 |
+
width: 100%;
|
16 |
+
height: 100%;
|
17 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/add-scripts.php
CHANGED
@@ -1,256 +1,240 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Add Scripts
|
4 |
-
*
|
5 |
-
* Add JS and CSS to the main theme and to admin
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
/**
|
43 |
-
*
|
44 |
-
*
|
45 |
-
*
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
* Add
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
*
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
// If the shortcode is empty, it's fine in admin but elsewhere
|
242 |
-
// is another fail.
|
243 |
-
|
244 |
-
if ( $shortcode_usage == '' ) {
|
245 |
-
|
246 |
-
if ( $source == 'admin' ) {
|
247 |
-
$shortcode = 0;
|
248 |
-
} else {
|
249 |
-
$shortcode = 3;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
}
|
253 |
-
}
|
254 |
-
|
255 |
-
update_option( 'youtube_embed_shortcode_' . $source, $shortcode );
|
256 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Add Scripts
|
4 |
+
*
|
5 |
+
* Add JS and CSS to the main theme and to admin
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
$version = get_option( 'youtube_embed_version' );
|
11 |
+
|
12 |
+
if ( YOUTUBE_EMBED_VERSION != $version ) {
|
13 |
+
|
14 |
+
// Set up default option values (if not already set).
|
15 |
+
|
16 |
+
$options = ye_set_general_defaults();
|
17 |
+
ye_set_shortcode();
|
18 |
+
ye_set_list( $options['list_no'] );
|
19 |
+
ye_set_profile( $options['profile_no'] );
|
20 |
+
|
21 |
+
// Update saved version number.
|
22 |
+
|
23 |
+
update_option( 'youtube_embed_version', YOUTUBE_EMBED_VERSION );
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Admin initialisation
|
28 |
+
*
|
29 |
+
* Switch on shortcodes in widgets, if required
|
30 |
+
*/
|
31 |
+
function ye_admin_init() {
|
32 |
+
|
33 |
+
$options = get_option( 'youtube_embed_general' );
|
34 |
+
|
35 |
+
if ( 1 == $options['widgets'] ) {
|
36 |
+
add_filter( 'widget_text', 'do_shortcode' );
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
add_action( 'admin_init', 'ye_admin_init' );
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Add scripts to theme
|
44 |
+
*
|
45 |
+
* Add styles and scripts to the main theme
|
46 |
+
*/
|
47 |
+
function ye_main_scripts() {
|
48 |
+
|
49 |
+
wp_register_style( 'ye_dynamic', plugins_url( 'css/main.min.css', dirname( __FILE__ ) ), '', YOUTUBE_EMBED_VERSION );
|
50 |
+
|
51 |
+
wp_enqueue_style( 'ye_dynamic' );
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
add_action( 'wp_enqueue_scripts', 'ye_main_scripts' );
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Add CSS to admin
|
59 |
+
*
|
60 |
+
* Add stylesheets to the admin screens
|
61 |
+
*/
|
62 |
+
function ye_admin_css() {
|
63 |
+
|
64 |
+
wp_enqueue_style( 'dynamic_video', plugins_url( 'css/admin.min.css', dirname( __FILE__ ) ), '', YOUTUBE_EMBED_VERSION );
|
65 |
+
|
66 |
+
}
|
67 |
+
|
68 |
+
add_action( 'admin_print_styles', 'ye_admin_css' );
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Add option to Admin Bar
|
72 |
+
*
|
73 |
+
* Add link to YouTube Embed profile options to Admin Bar.
|
74 |
+
* With help from http://technerdia.com/1140_wordpress-admin-bar.html
|
75 |
+
*
|
76 |
+
* @param string $meta Meta.
|
77 |
+
* @uses ye_set_general_default Set default options
|
78 |
+
*/
|
79 |
+
function ye_admin_bar_render( $meta = true ) {
|
80 |
+
|
81 |
+
if ( ! is_admin() ) {
|
82 |
+
|
83 |
+
$options = ye_get_general_defaults();
|
84 |
+
|
85 |
+
if ( '' != $options['admin_bar'] ) {
|
86 |
+
|
87 |
+
global $wp_admin_bar;
|
88 |
+
|
89 |
+
if ( ! is_user_logged_in() ) {
|
90 |
+
return;
|
91 |
+
}
|
92 |
+
if ( ! is_admin_bar_showing() ) {
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
if ( ! current_user_can( $options['menu_access'] ) ) {
|
96 |
+
return;
|
97 |
+
}
|
98 |
+
|
99 |
+
$wp_admin_bar->add_menu(
|
100 |
+
array(
|
101 |
+
'id' => 'aye-menu',
|
102 |
+
'title' => __( 'YouTube Embed', 'youtube-embed' ),
|
103 |
+
)
|
104 |
+
);
|
105 |
+
|
106 |
+
$wp_admin_bar->add_menu(
|
107 |
+
array(
|
108 |
+
'parent' => 'aye-menu',
|
109 |
+
'id' => 'aye-options',
|
110 |
+
'title' => __( 'Options', 'youtube-embed' ),
|
111 |
+
'href' => admin_url( 'admin.php?page=ye-general-options' ),
|
112 |
+
'meta' => array( 'target' => '_blank' ),
|
113 |
+
)
|
114 |
+
);
|
115 |
+
|
116 |
+
$wp_admin_bar->add_menu(
|
117 |
+
array(
|
118 |
+
'parent' => 'aye-menu',
|
119 |
+
'id' => 'aye-profile',
|
120 |
+
'title' => __( 'Profiles', 'youtube-embed' ),
|
121 |
+
'href' => admin_url( 'admin.php?page=ye-profile-options' ),
|
122 |
+
'meta' => array( 'target' => '_blank' ),
|
123 |
+
)
|
124 |
+
);
|
125 |
+
|
126 |
+
$wp_admin_bar->add_menu(
|
127 |
+
array(
|
128 |
+
'parent' => 'aye-menu',
|
129 |
+
'id' => 'aye-lists',
|
130 |
+
'title' => __( 'Lists', 'youtube-embed' ),
|
131 |
+
'href' => admin_url( 'admin.php?page=ye-list-options' ),
|
132 |
+
'meta' => array( 'target' => '_blank' ),
|
133 |
+
)
|
134 |
+
);
|
135 |
+
}
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
add_action( 'admin_bar_menu', 'ye_admin_bar_render', 99 );
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Add to site header
|
143 |
+
*
|
144 |
+
* Perform main site head processing
|
145 |
+
*
|
146 |
+
* @uses youtube_embed_head_checks Perform the actual checks
|
147 |
+
*/
|
148 |
+
function youtube_embed_add_to_head() {
|
149 |
+
|
150 |
+
youtube_embed_shortcode_checks( 'site' );
|
151 |
+
|
152 |
+
$options = ye_get_general_defaults();
|
153 |
+
|
154 |
+
if ( 'f' == $options['script'] ) {
|
155 |
+
|
156 |
+
$tab = "\t";
|
157 |
+
$newline = "\n";
|
158 |
+
|
159 |
+
echo '<script type="text/javascript" src="' . esc_url( plugins_url( 'js/jquery.fitvids.js', dirname( __FILE__ ) ) ) . '"></script>' . wp_kses( $newline );
|
160 |
+
|
161 |
+
echo '<script>' . wp_kses( $newline );
|
162 |
+
echo wp_kses( $tab ) . '$(".youtube-embed").fitVids();' . wp_kses( $newline );
|
163 |
+
echo '</script>' . wp_kses( $newline );
|
164 |
+
|
165 |
+
}
|
166 |
+
|
167 |
+
if ( 'i' == $options['script'] ) {
|
168 |
+
wp_enqueue_script( 'youtube-embed-iframe-resizer', plugins_url( 'js/iframeResizer.min.js', dirname( __FILE__ ) ), '', YOUTUBE_EMBED_VERSION, false );
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
add_action( 'wp_head', 'youtube_embed_add_to_head' );
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Admin Head Checks
|
176 |
+
*
|
177 |
+
* Perform admin head processing
|
178 |
+
*
|
179 |
+
* @uses youtube_embed_head_checks Perform the actual checks.
|
180 |
+
*/
|
181 |
+
function youtube_embed_admin_head_checks() {
|
182 |
+
|
183 |
+
youtube_embed_shortcode_checks( 'admin' );
|
184 |
+
|
185 |
+
}
|
186 |
+
|
187 |
+
|
188 |
+
add_action( 'admin_head', 'youtube_embed_admin_head_checks' );
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Shortcode Checking
|
192 |
+
*
|
193 |
+
* Check if the shortcode is in use by another plugin. If so, note it
|
194 |
+
* in the options.
|
195 |
+
*
|
196 |
+
* @param string $source Where the checks are coming from.
|
197 |
+
*/
|
198 |
+
function youtube_embed_shortcode_checks( $source ) {
|
199 |
+
|
200 |
+
global $shortcode_tags;
|
201 |
+
if ( isset( $shortcode_tags['youtube'] ) ) {
|
202 |
+
$shortcode_usage = $shortcode_tags['youtube'];
|
203 |
+
} else {
|
204 |
+
$shortcode_usage = '';
|
205 |
+
}
|
206 |
+
|
207 |
+
$shortcode = 1;
|
208 |
+
|
209 |
+
// All is fine.
|
210 |
+
|
211 |
+
if ( substr( $shortcode_usage, 0, 19 ) == 'ye_video_shortcode_' ) {
|
212 |
+
|
213 |
+
$shortcode = 0;
|
214 |
+
|
215 |
+
} else {
|
216 |
+
|
217 |
+
// Jetpack is overriding.
|
218 |
+
|
219 |
+
if ( 'youtube_shortcode' == $shortcode_usage ) {
|
220 |
+
|
221 |
+
$shortcode = 2;
|
222 |
+
|
223 |
+
} else {
|
224 |
+
|
225 |
+
// If the shortcode is empty, it's fine in admin but elsewhere
|
226 |
+
// is another fail.
|
227 |
+
|
228 |
+
if ( '' == $shortcode_usage ) {
|
229 |
+
|
230 |
+
if ( 'admin' == $source ) {
|
231 |
+
$shortcode = 0;
|
232 |
+
} else {
|
233 |
+
$shortcode = 3;
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
update_option( 'youtube_embed_shortcode_' . $source, $shortcode );
|
240 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/admin-config.php
CHANGED
@@ -1,332 +1,345 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Admin Config Functions
|
4 |
-
*
|
5 |
-
* Various functions relating to the various administration screens
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Add Settings link to plugin list
|
12 |
-
*
|
13 |
-
* Add a Settings link to the options listed against this plugin
|
14 |
-
*
|
15 |
-
* @
|
16 |
-
*
|
17 |
-
* @
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
*
|
40 |
-
*
|
41 |
-
*
|
42 |
-
*
|
43 |
-
* @param string $
|
44 |
-
* @
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
*
|
67 |
-
*
|
68 |
-
*
|
69 |
-
*
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
*
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
*
|
162 |
-
*
|
163 |
-
*
|
164 |
-
*
|
165 |
-
|
166 |
-
|
167 |
-
function
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
* Add
|
197 |
-
*
|
198 |
-
*
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
$screen
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
$text
|
271 |
-
|
272 |
-
if (
|
273 |
-
|
274 |
-
$text .= '<p
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Admin Config Functions
|
4 |
+
*
|
5 |
+
* Various functions relating to the various administration screens
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Add Settings link to plugin list
|
12 |
+
*
|
13 |
+
* Add a Settings link to the options listed against this plugin
|
14 |
+
*
|
15 |
+
* @param string $links Current links.
|
16 |
+
* @param string $file File in use.
|
17 |
+
* @return string Links, now with settings added.
|
18 |
+
*/
|
19 |
+
function ye_add_settings_link( $links, $file ) {
|
20 |
+
|
21 |
+
static $this_plugin;
|
22 |
+
|
23 |
+
if ( ! $this_plugin ) {
|
24 |
+
$this_plugin = plugin_basename( __FILE__ );
|
25 |
+
}
|
26 |
+
|
27 |
+
if ( strpos( $file, 'youtube-embed.php' ) !== false ) {
|
28 |
+
$settings_link = '<a href="admin.php?page=ye-general-options">' . __( 'Settings', 'youtube-embed' ) . '</a>';
|
29 |
+
array_unshift( $links, $settings_link );
|
30 |
+
}
|
31 |
+
|
32 |
+
return $links;
|
33 |
+
}
|
34 |
+
|
35 |
+
add_filter( 'plugin_action_links', 'ye_add_settings_link', 10, 2 );
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Add meta to plugin details
|
39 |
+
*
|
40 |
+
* Add options to plugin meta line
|
41 |
+
*
|
42 |
+
* @param string $links Current links.
|
43 |
+
* @param string $file File in use.
|
44 |
+
* @return string Links, now with settings added.
|
45 |
+
*/
|
46 |
+
function ye_set_plugin_meta( $links, $file ) {
|
47 |
+
|
48 |
+
if ( strpos( $file, 'youtube-embed.php' ) !== false ) {
|
49 |
+
|
50 |
+
$links = array_merge( $links, array( '<a href="https://github.com/dartiss/youtube-embed">' . __( 'Github', 'youtube-embed' ) . '</a>' ) );
|
51 |
+
|
52 |
+
$links = array_merge( $links, array( '<a href="https://wordpress.org/support/plugin/youtube-embed">' . __( 'Support', 'youtube-embed' ) . '</a>' ) );
|
53 |
+
|
54 |
+
$links = array_merge( $links, array( '<a href="https://artiss.blog/donate">' . __( 'Donate', 'youtube-embed' ) . '</a>' ) );
|
55 |
+
|
56 |
+
$links = array_merge( $links, array( '<a href="https://wordpress.org/support/plugin/youtube-embed/reviews/#new-post">' . __( 'Write a Review', 'youtube-embed' ) . ' ⭐️⭐️⭐️⭐️⭐️</a>' ) );
|
57 |
+
}
|
58 |
+
|
59 |
+
return $links;
|
60 |
+
}
|
61 |
+
|
62 |
+
add_filter( 'plugin_row_meta', 'ye_set_plugin_meta', 10, 2 );
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Admin Screen Initialisation
|
66 |
+
*
|
67 |
+
* Set up admin menu and submenu options
|
68 |
+
*
|
69 |
+
* @uses ye_contextual_help_type Work out help type.
|
70 |
+
*/
|
71 |
+
function ye_menu_initialise() {
|
72 |
+
|
73 |
+
// Get level access for menus.
|
74 |
+
|
75 |
+
$options = ye_get_general_defaults();
|
76 |
+
|
77 |
+
$menu_access = $options['menu_access'];
|
78 |
+
|
79 |
+
// Add main admin option.
|
80 |
+
|
81 |
+
$menu_icon = 'dashicons-video-alt3';
|
82 |
+
|
83 |
+
add_menu_page( __( 'About YouTube Embed', 'youtube-embed' ), __( 'YouTube Embed', 'youtube-embed' ), $menu_access, 'ye-profile-options', 'ye_profile_options', $menu_icon, 12 );
|
84 |
+
|
85 |
+
// Add profiles sub-menu.
|
86 |
+
|
87 |
+
global $ye_profiles_hook;
|
88 |
+
|
89 |
+
$ye_profiles_hook = add_submenu_page( 'ye-profile-options', __( 'YouTube Embed Profiles', 'youtube-embed' ), __( 'Profiles', 'youtube-embed' ), $menu_access, 'ye-profile-options', 'ye_profile_options' );
|
90 |
+
|
91 |
+
add_action( 'load-' . $ye_profiles_hook, 'ye_add_profiles_help' );
|
92 |
+
|
93 |
+
// Add lists sub-menu.
|
94 |
+
|
95 |
+
global $ye_lists_hook;
|
96 |
+
|
97 |
+
$ye_lists_hook = add_submenu_page( 'ye-profile-options', __( 'YouTube Embed Lists', 'youtube-embed' ), __( 'Lists', 'youtube-embed' ), $menu_access, 'ye-list-options', 'ye_list_options' );
|
98 |
+
|
99 |
+
add_action( 'load-' . $ye_lists_hook, 'ye_add_lists_help' );
|
100 |
+
|
101 |
+
// If installed, add link to Video Overlay Ads plugin.
|
102 |
+
|
103 |
+
if ( function_exists( 'video_overlay_create_menu' ) ) {
|
104 |
+
|
105 |
+
add_submenu_page( 'ye-profile-options', __( 'Video Overlay Ads', 'youtube-embed' ), __( 'Video Overlay Ads', 'youtube-embed' ), 'administrator', 'ye-video-overlay', 'video_overlay_settings_page' );
|
106 |
+
}
|
107 |
+
|
108 |
+
// If installed, add link to Video SEO.
|
109 |
+
|
110 |
+
if ( class_exists( 'wpseo_Video_Sitemap' ) ) {
|
111 |
+
|
112 |
+
add_submenu_page( 'ye-profile-options', __( 'Video SEO', 'youtube-embed' ), __( 'Video SEO', 'youtube-embed' ), 'manage_options', 'ye-wpseo-video', 'wpseo_Video_Sitemap::admin_panel' );
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
// Add settings sub-menu.
|
117 |
+
|
118 |
+
global $ye_options_hook;
|
119 |
+
|
120 |
+
$ye_options_hook = add_submenu_page( 'options-general.php', __( 'YouTube Embed Settings', 'youtube-embed' ), __( 'YouTube Embed', 'youtube-embed' ), $menu_access, 'ye-general-options', 'ye_general_options' );
|
121 |
+
|
122 |
+
add_action( 'load-' . $ye_options_hook, 'ye_add_options_help' );
|
123 |
+
}
|
124 |
+
|
125 |
+
add_action( 'admin_menu', 'ye_menu_initialise' );
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Include general options screen
|
129 |
+
*
|
130 |
+
* XHTML options screen to prompt and update some general plugin options
|
131 |
+
*/
|
132 |
+
function ye_general_options() {
|
133 |
+
|
134 |
+
include_once plugin_dir_path( __FILE__ ) . 'options-general.php';
|
135 |
+
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Include profile options screen
|
140 |
+
*
|
141 |
+
* XHTML options screen to prompt and update profile options
|
142 |
+
*/
|
143 |
+
function ye_profile_options() {
|
144 |
+
|
145 |
+
include_once plugin_dir_path( __FILE__ ) . 'options-profiles.php';
|
146 |
+
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Include list options screen
|
151 |
+
*
|
152 |
+
* XHTML options screen to prompt and update list options
|
153 |
+
*/
|
154 |
+
function ye_list_options() {
|
155 |
+
|
156 |
+
include_once plugin_dir_path( __FILE__ ) . 'options-lists.php';
|
157 |
+
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Add Options Help
|
162 |
+
*
|
163 |
+
* Add help tab to options screen
|
164 |
+
*
|
165 |
+
* @uses ye_options_help Return help text.
|
166 |
+
*/
|
167 |
+
function ye_add_options_help() {
|
168 |
+
|
169 |
+
global $ye_options_hook;
|
170 |
+
$screen = get_current_screen();
|
171 |
+
|
172 |
+
if ( $screen->id != $ye_options_hook ) {
|
173 |
+
return;
|
174 |
+
}
|
175 |
+
|
176 |
+
$screen->add_help_tab(
|
177 |
+
array(
|
178 |
+
'id' => 'options-help-tab',
|
179 |
+
'title' => __( 'Help', 'youtube-embed' ),
|
180 |
+
'content' => youtube_embed_help( 'options' ),
|
181 |
+
)
|
182 |
+
);
|
183 |
+
|
184 |
+
$screen->add_help_tab(
|
185 |
+
array(
|
186 |
+
'id' => 'options-links-tab',
|
187 |
+
'title' => __( 'Links', 'youtube-embed' ),
|
188 |
+
'content' => youtube_embed_help( 'options', 'links' ),
|
189 |
+
)
|
190 |
+
);
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Add Profiles Help
|
195 |
+
*
|
196 |
+
* Add help tab to profiles screen
|
197 |
+
*
|
198 |
+
* @uses ye_profiles_help Return help text.
|
199 |
+
*/
|
200 |
+
function ye_add_profiles_help() {
|
201 |
+
|
202 |
+
global $ye_profiles_hook;
|
203 |
+
$screen = get_current_screen();
|
204 |
+
|
205 |
+
if ( $screen->id != $ye_profiles_hook ) {
|
206 |
+
return;
|
207 |
+
}
|
208 |
+
|
209 |
+
$screen->add_help_tab(
|
210 |
+
array(
|
211 |
+
'id' => 'profiles-help-tab',
|
212 |
+
'title' => __( 'Help', 'youtube-embed' ),
|
213 |
+
'content' => youtube_embed_help( 'profiles' ),
|
214 |
+
)
|
215 |
+
);
|
216 |
+
|
217 |
+
$screen->add_help_tab(
|
218 |
+
array(
|
219 |
+
'id' => 'profiles-links-tab',
|
220 |
+
'title' => __( 'Links', 'youtube-embed' ),
|
221 |
+
'content' => youtube_embed_help( 'profiles', 'links' ),
|
222 |
+
)
|
223 |
+
);
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Add Lists Help
|
228 |
+
*
|
229 |
+
* Add help tab to lists screen
|
230 |
+
*
|
231 |
+
* @uses ye_lists_help Return help text.
|
232 |
+
*/
|
233 |
+
function ye_add_lists_help() {
|
234 |
+
|
235 |
+
global $ye_lists_hook;
|
236 |
+
$screen = get_current_screen();
|
237 |
+
|
238 |
+
if ( $screen->id != $ye_lists_hook ) {
|
239 |
+
return;
|
240 |
+
}
|
241 |
+
|
242 |
+
$screen->add_help_tab(
|
243 |
+
array(
|
244 |
+
'id' => 'lists-help-tab',
|
245 |
+
'title' => __( 'Help', 'youtube-embed' ),
|
246 |
+
'content' => youtube_embed_help( 'lists' ),
|
247 |
+
)
|
248 |
+
);
|
249 |
+
|
250 |
+
$screen->add_help_tab(
|
251 |
+
array(
|
252 |
+
'id' => 'lists-links-tab',
|
253 |
+
'title' => __( 'Links', 'youtube-embed' ),
|
254 |
+
'content' => youtube_embed_help( 'lists', 'links' ),
|
255 |
+
)
|
256 |
+
);
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Help Screens
|
261 |
+
*
|
262 |
+
* Generate help screen text
|
263 |
+
*
|
264 |
+
* @param string $screen Which help screen to return text for.
|
265 |
+
* @param string $tab Which tab of the help this is for.
|
266 |
+
* @return string Help Text.
|
267 |
+
*/
|
268 |
+
function youtube_embed_help( $screen, $tab = 'help' ) {
|
269 |
+
|
270 |
+
$text = '';
|
271 |
+
|
272 |
+
if ( 'options' == $screen && 'help' == $tab ) {
|
273 |
+
|
274 |
+
$text .= '<p>' . __( 'This screen allows you to select non-specific options for the YouTube Embed plugin. For the default embedding settings, please select the <a href="admin.php?page=ye-profile-options">Profiles</a> administration option.', 'youtube-embed' ) . '</p>';
|
275 |
+
}
|
276 |
+
|
277 |
+
if ( 'profiles' == $screen && 'help' == $tab ) {
|
278 |
+
|
279 |
+
$text .= '<p>' . __( 'This screen allows you to set the options for the default and additional profiles. If you don\'t specify a specific parameter when displaying your YouTube video then the default profile option will be used instead. Additional profiles, which you may name, can be used as well and used as required.', 'youtube-embed' ) . '</p>';
|
280 |
+
}
|
281 |
+
|
282 |
+
if ( 'lists' == $screen && 'help' == $tab ) {
|
283 |
+
|
284 |
+
$text .= '<p>' . __( 'This screen allows you to create lists of YouTube videos, which may be named. These lists can then be used in preference to a single video ID.', 'youtube-embed' ) . '</p>';
|
285 |
+
}
|
286 |
+
|
287 |
+
$text .= '<p>' . __( 'Remember to click the Save Changes button at the bottom of the screen for any changes to take effect.', 'youtube-embed' ) . '</p>';
|
288 |
+
|
289 |
+
if ( 'links' == $tab ) {
|
290 |
+
|
291 |
+
$text .= '<p><strong>' . __( 'For more information:', 'youtube-embed' ) . '</strong></p>';
|
292 |
+
$text .= '<p><a href="https://wordpress.org/plugins/youtube-embed/">' . __( 'YouTube Embed Plugin Documentation', 'youtube-embed' ) . '</a></p>';
|
293 |
+
|
294 |
+
if ( 'lists' != $screen ) {
|
295 |
+
$text .= '<p><a href="https://code.google.com/apis/youtube/player_parameters.html">' . __( 'YouTube Player Documentation', 'youtube-embed' ) . '</a></p>';
|
296 |
+
}
|
297 |
+
|
298 |
+
if ( 'options' == $screen ) {
|
299 |
+
|
300 |
+
$text .= '<p><a href="https://github.com/davatron5000/FitVids.js">FitVids.js</a></p>';
|
301 |
+
$text .= '<p><a href="https://github.com/davidjbradshaw/iframe-resizer">iFrame Resizer</a></p>';
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
return $text;
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Show Admin Messages
|
310 |
+
*
|
311 |
+
* Display messages on the administration screen
|
312 |
+
*/
|
313 |
+
function youtube_embed_admin_messages() {
|
314 |
+
|
315 |
+
$shortcode_site = get_option( 'youtube_embed_shortcode_site' );
|
316 |
+
|
317 |
+
$shortcode_admin = get_option( 'youtube_embed_shortcode_admin' );
|
318 |
+
|
319 |
+
if ( ( 0 != $shortcode_admin ) || ( 0 != $shortcode_site ) ) {
|
320 |
+
|
321 |
+
$options = ye_get_general_defaults();
|
322 |
+
|
323 |
+
if ( 1 == $options['prompt'] ) {
|
324 |
+
|
325 |
+
if ( 3 == $shortcode_site ) {
|
326 |
+
$message = __( 'For some reason the shortcode <strong>[youtube]</strong> is not working on the main site' );
|
327 |
+
}
|
328 |
+
|
329 |
+
$alternative = __( 'An alternative plugin is using the <strong>[youtube]</strong> shortcode' );
|
330 |
+
|
331 |
+
if ( ( 1 == $shortcode_admin ) || ( 1 == $shortcode_site ) ) {
|
332 |
+
$message = $alternative;
|
333 |
+
}
|
334 |
+
|
335 |
+
if ( ( 2 == $shortcode_admin ) || ( 2 == $shortcode_site ) ) {
|
336 |
+
$message = __( $alternative . ', possibly the <a href="admin.php?page=jetpack_modules&activated=true">Shortcode Embeds module</a> in Jetpack' );
|
337 |
+
}
|
338 |
+
|
339 |
+
echo '<div class="error notice"><p>YouTube Embed: ' . $message . '.</p></div>';
|
340 |
+
}
|
341 |
+
}
|
342 |
+
|
343 |
+
}
|
344 |
+
|
345 |
+
add_action( 'admin_notices', 'youtube_embed_admin_messages' );
|
includes/api-access.php
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* API
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
* @since 5.0
|
10 |
-
*
|
11 |
-
* @param string $video_id The ID of the video
|
12 |
-
* @param string $api_key Allows an alternative API key to be specified
|
13 |
-
* @param string $no_cache Suppresses caching
|
14 |
-
* @param string $cache_time If the calling function already has the cache time, send it along, otherwise it is fetched
|
15 |
-
* @param string $playlist If a playlist, this is the name
|
16 |
-
* @return array Array of video information
|
17 |
-
*/
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
function ye_get_api_data( $video_id, $api_key = '', $no_cache = false, $cache_time = '', $playlist = '' ) {
|
20 |
|
21 |
-
// Check for cached data. If exists, return that
|
22 |
|
23 |
-
if (
|
24 |
$key = 'api_' . $video_id;
|
25 |
} else {
|
26 |
$key = 'api_' . $playlist;
|
@@ -28,23 +31,25 @@ function ye_get_api_data( $video_id, $api_key = '', $no_cache = false, $cache_ti
|
|
28 |
|
29 |
$cache = ye_get_transient( $key );
|
30 |
|
31 |
-
if (
|
|
|
|
|
32 |
|
33 |
-
// Calculate the default video type
|
34 |
|
35 |
$valid = false;
|
36 |
-
$type
|
37 |
if ( strlen( $video_id ) == 11 ) {
|
38 |
$type = 'v';
|
39 |
-
if ( preg_match('/^[a-zA-Z0-9_-]{11}$/', $video_id)
|
40 |
$valid = false;
|
41 |
} else {
|
42 |
$valid = true;
|
43 |
}
|
44 |
} else {
|
45 |
-
if ( ( strtolower( substr( $video_id, 0, 2 ) )
|
46 |
$type = 'p';
|
47 |
-
if (
|
48 |
$valid = false;
|
49 |
} else {
|
50 |
$valid = true;
|
@@ -52,116 +57,144 @@ function ye_get_api_data( $video_id, $api_key = '', $no_cache = false, $cache_ti
|
|
52 |
}
|
53 |
}
|
54 |
|
55 |
-
// Set the default values
|
56 |
|
57 |
$return_data = array(
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
// Set the default thumbnail URLs
|
73 |
-
|
74 |
-
if ( (
|
75 |
-
|
76 |
-
$return_data[
|
77 |
-
$return_data[
|
78 |
-
$return_data[
|
79 |
-
$return_data[
|
80 |
-
$return_data[
|
81 |
|
82 |
}
|
83 |
|
84 |
-
// If a user defined playlist, go no further
|
85 |
|
86 |
-
if (
|
|
|
|
|
87 |
|
88 |
-
// Get the API key
|
89 |
|
90 |
-
if (
|
91 |
$options = ye_get_general_defaults();
|
92 |
-
$api_key = $options[
|
93 |
-
if (
|
|
|
|
|
94 |
}
|
95 |
|
96 |
-
// Get the API results and convert from JSON to a PHP array
|
97 |
|
98 |
-
$url
|
99 |
$api_data = json_decode( @file_get_contents( $url ), true );
|
100 |
-
if (
|
|
|
|
|
101 |
|
102 |
-
if ( !isset( $api_data[
|
103 |
|
104 |
-
$url
|
105 |
$api_data = json_decode( file_get_contents( $url ), true );
|
106 |
-
if (
|
|
|
|
|
107 |
|
108 |
-
if ( isset( $api_data[
|
109 |
-
$id_found
|
110 |
-
$return_data[
|
111 |
} else {
|
112 |
$id_found = false;
|
113 |
}
|
114 |
} else {
|
115 |
-
$id_found
|
116 |
-
$return_data[
|
117 |
}
|
118 |
|
119 |
-
$return_data[
|
120 |
|
121 |
-
// Extract out the API data
|
122 |
|
123 |
if ( $id_found ) {
|
124 |
|
125 |
-
$return_data[
|
126 |
|
127 |
-
// Strip off the first two dimensions of the array
|
128 |
|
129 |
-
if ( isset( $api_data[
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
if ( isset( $api_data[ 'snippet' ][ 'publishedAt' ] ) ) { $return_data[ 'published' ] = $api_data[ 'snippet' ][ 'publishedAt' ]; }
|
134 |
|
135 |
-
|
136 |
|
137 |
-
if ( isset( $api_data[
|
|
|
|
|
138 |
|
139 |
-
if ( isset( $api_data[
|
|
|
|
|
140 |
|
141 |
-
if ( isset( $api_data[
|
142 |
-
|
143 |
-
|
144 |
-
if ( isset( $api_data[ 'snippet' ][ 'thumbnails' ][ 'standard' ][ 'url' ] ) ) { $return_data[ 'thumb_standard' ] = $api_data[ 'snippet' ][ 'thumbnails' ][ 'standard' ][ 'url' ]; }
|
145 |
-
if ( isset( $api_data[ 'snippet' ][ 'thumbnails' ][ 'maxres' ][ 'url' ] ) ) { $return_data[ 'thumb_maxres' ] = $api_data[ 'snippet' ][ 'thumbnails' ][ 'maxres' ][ 'url' ]; }
|
146 |
|
|
|
|
|
|
|
|
|
|
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
} else {
|
149 |
-
|
150 |
-
$return_data[ 'valid' ] = false;
|
151 |
-
|
152 |
}
|
153 |
|
154 |
-
// If the description is missing or blank, set it to the title
|
155 |
|
156 |
-
if ( !isset( $return_data[
|
|
|
|
|
157 |
|
158 |
-
// Save the non-cached data (if required), but only if the API retrival was successful
|
159 |
|
160 |
$options = ye_get_general_defaults();
|
161 |
|
162 |
-
if ( $options[
|
163 |
|
164 |
-
$cache = $options[
|
165 |
|
166 |
ye_set_transient( $key, $return_data, $cache );
|
167 |
|
1 |
<?php
|
2 |
/**
|
3 |
+
* API Scripts
|
4 |
+
*
|
5 |
+
* Scripts for API access
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
/**
|
11 |
+
* API Access
|
12 |
+
*
|
13 |
+
* Function to access YouTube API for video data
|
14 |
+
*
|
15 |
+
* @param string $video_id The ID of the video.
|
16 |
+
* @param string $api_key Allows an alternative API key to be specified.
|
17 |
+
* @param string $no_cache Suppresses caching.
|
18 |
+
* @param string $cache_time If the calling function already has the cache time, send it along, otherwise it is fetched.
|
19 |
+
* @param string $playlist If a playlist, this is the name.
|
20 |
+
* @return array Array of video information.
|
21 |
+
*/
|
22 |
function ye_get_api_data( $video_id, $api_key = '', $no_cache = false, $cache_time = '', $playlist = '' ) {
|
23 |
|
24 |
+
// Check for cached data. If exists, return that.
|
25 |
|
26 |
+
if ( '' == $playlist ) {
|
27 |
$key = 'api_' . $video_id;
|
28 |
} else {
|
29 |
$key = 'api_' . $playlist;
|
31 |
|
32 |
$cache = ye_get_transient( $key );
|
33 |
|
34 |
+
if ( false !== $cache ) {
|
35 |
+
return $cache;
|
36 |
+
}
|
37 |
|
38 |
+
// Calculate the default video type.
|
39 |
|
40 |
$valid = false;
|
41 |
+
$type = '';
|
42 |
if ( strlen( $video_id ) == 11 ) {
|
43 |
$type = 'v';
|
44 |
+
if ( 0 == preg_match( '/^[a-zA-Z0-9_-]{11}$/', $video_id ) ) {
|
45 |
$valid = false;
|
46 |
} else {
|
47 |
$valid = true;
|
48 |
}
|
49 |
} else {
|
50 |
+
if ( ( 'pl' == strtolower( substr( $video_id, 0, 2 ) ) && 34 == strlen( $video_id ) ) || ( 16 == strlen( $video_id ) ) || ( '' != $playlist ) ) {
|
51 |
$type = 'p';
|
52 |
+
if ( '' == $playlist && 1 == preg_match( '/[^A-Za-z0-9_-]/', $video_id ) ) {
|
53 |
$valid = false;
|
54 |
} else {
|
55 |
$valid = true;
|
57 |
}
|
58 |
}
|
59 |
|
60 |
+
// Set the default values.
|
61 |
|
62 |
$return_data = array(
|
63 |
+
'restricted' => '',
|
64 |
+
'title' => get_the_title(),
|
65 |
+
'description' => get_the_title(),
|
66 |
+
'published' => get_the_date( 'c' ),
|
67 |
+
'valid' => $valid,
|
68 |
+
'type' => $type,
|
69 |
+
'api' => false,
|
70 |
+
'thumb_default' => '',
|
71 |
+
'thumb_medium' => '',
|
72 |
+
'thumb_high' => '',
|
73 |
+
'thumb_standard' => '',
|
74 |
+
'thumb_maxres' => '',
|
75 |
+
);
|
76 |
+
|
77 |
+
// Set the default thumbnail URLs.
|
78 |
+
|
79 |
+
if ( ( 'v' == $type ) || ( '' != $playlist ) ) {
|
80 |
+
|
81 |
+
$return_data['thumb_default'] = 'https://i.ytimg.com/vi/' . $video_id . '/default.jpg';
|
82 |
+
$return_data['thumb_medium'] = 'https://i.ytimg.com/vi/' . $video_id . '/mqdefault.jpg';
|
83 |
+
$return_data['thumb_high'] = 'https://i.ytimg.com/vi/' . $video_id . '/hqdefault.jpg';
|
84 |
+
$return_data['thumb_standard'] = 'https://i.ytimg.com/vi/' . $video_id . '/sddefault.jpg';
|
85 |
+
$return_data['thumb_maxres'] = 'https://i.ytimg.com/vi/' . $video_id . '/maxresdefault.jpg';
|
86 |
|
87 |
}
|
88 |
|
89 |
+
// If a user defined playlist, go no further.
|
90 |
|
91 |
+
if ( '' != $playlist ) {
|
92 |
+
return $return_data;
|
93 |
+
}
|
94 |
|
95 |
+
// Get the API key.
|
96 |
|
97 |
+
if ( '' == $api_key ) {
|
98 |
$options = ye_get_general_defaults();
|
99 |
+
$api_key = $options['api'];
|
100 |
+
if ( '' == $api_key ) {
|
101 |
+
return $return_data;
|
102 |
+
}
|
103 |
}
|
104 |
|
105 |
+
// Get the API results and convert from JSON to a PHP array.
|
106 |
|
107 |
+
$url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=' . $video_id . '&key=' . $api_key;
|
108 |
$api_data = json_decode( @file_get_contents( $url ), true );
|
109 |
+
if ( '' == $api_data ) {
|
110 |
+
return $return_data;
|
111 |
+
}
|
112 |
|
113 |
+
if ( ! isset( $api_data['items']['0'] ) ) {
|
114 |
|
115 |
+
$url = 'https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&id=' . $video_id . '&key=' . $api_key;
|
116 |
$api_data = json_decode( file_get_contents( $url ), true );
|
117 |
+
if ( '' == $api_data ) {
|
118 |
+
return $return_data;
|
119 |
+
}
|
120 |
|
121 |
+
if ( isset( $api_data['items']['0'] ) ) {
|
122 |
+
$id_found = true;
|
123 |
+
$return_data['type'] = 'p';
|
124 |
} else {
|
125 |
$id_found = false;
|
126 |
}
|
127 |
} else {
|
128 |
+
$id_found = true;
|
129 |
+
$return_data['type'] = 'v';
|
130 |
}
|
131 |
|
132 |
+
$return_data['api'] = true; // Show that API data was used.
|
133 |
|
134 |
+
// Extract out the API data.
|
135 |
|
136 |
if ( $id_found ) {
|
137 |
|
138 |
+
$return_data['valid'] = true;
|
139 |
|
140 |
+
// Strip off the first two dimensions of the array.
|
141 |
|
142 |
+
if ( isset( $api_data['items']['0'] ) ) {
|
143 |
+
$api_data = $api_data['items']['0'];
|
144 |
+
}
|
|
|
|
|
145 |
|
146 |
+
// If set, assign the appropriate API data to the return array.
|
147 |
|
148 |
+
if ( isset( $api_data['snippet']['publishedAt'] ) ) {
|
149 |
+
$return_data['published'] = $api_data['snippet']['publishedAt'];
|
150 |
+
}
|
151 |
|
152 |
+
if ( isset( $api_data['snippet']['title'] ) ) {
|
153 |
+
$return_data['title'] = htmlspecialchars( $api_data['snippet']['title'] );
|
154 |
+
}
|
155 |
|
156 |
+
if ( isset( $api_data['snippet']['description'] ) ) {
|
157 |
+
$return_data['description'] = htmlspecialchars( $api_data['snippet']['description'] );
|
158 |
+
}
|
|
|
|
|
159 |
|
160 |
+
if ( isset( $api_data['contentDetails']['contentRating']['ytRating'] ) ) {
|
161 |
+
$return_data['restricted'] = true;
|
162 |
+
} else {
|
163 |
+
$return_data['restricted'] = false;
|
164 |
+
}
|
165 |
|
166 |
+
if ( isset( $api_data['snippet']['thumbnails']['default']['url'] ) ) {
|
167 |
+
$return_data['thumb_default'] = $api_data['snippet']['thumbnails']['default']['url'];
|
168 |
+
}
|
169 |
+
if ( isset( $api_data['snippet']['thumbnails']['medium']['url'] ) ) {
|
170 |
+
$return_data['thumb_medium'] = $api_data['snippet']['thumbnails']['medium']['url'];
|
171 |
+
}
|
172 |
+
if ( isset( $api_data['snippet']['thumbnails']['high']['url'] ) ) {
|
173 |
+
$return_data['thumb_high'] = $api_data['snippet']['thumbnails']['high']['url'];
|
174 |
+
}
|
175 |
+
if ( isset( $api_data['snippet']['thumbnails']['standard']['url'] ) ) {
|
176 |
+
$return_data['thumb_standard'] = $api_data['snippet']['thumbnails']['standard']['url'];
|
177 |
+
}
|
178 |
+
if ( isset( $api_data['snippet']['thumbnails']['maxres']['url'] ) ) {
|
179 |
+
$return_data['thumb_maxres'] = $api_data['snippet']['thumbnails']['maxres']['url'];
|
180 |
+
}
|
181 |
} else {
|
182 |
+
$return_data['valid'] = false;
|
|
|
|
|
183 |
}
|
184 |
|
185 |
+
// If the description is missing or blank, set it to the title.
|
186 |
|
187 |
+
if ( ! isset( $return_data['description'] ) || '' == trim( $return_data['description'] ) ) {
|
188 |
+
$return_data['description'] = $return_data['title'];
|
189 |
+
}
|
190 |
|
191 |
+
// Save the non-cached data (if required), but only if the API retrival was successful.
|
192 |
|
193 |
$options = ye_get_general_defaults();
|
194 |
|
195 |
+
if ( 0 != $options['api_cache'] && $id_found ) {
|
196 |
|
197 |
+
$cache = $options['api_cache'] * DAY_IN_SECONDS;
|
198 |
|
199 |
ye_set_transient( $key, $return_data, $cache );
|
200 |
|
includes/caching.php
CHANGED
@@ -1,104 +1,94 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Transient Functions
|
4 |
-
*
|
5 |
-
* Functions to save cache data and housekeep it
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Save a transient
|
12 |
-
*
|
13 |
-
* Generate a transient name and save it
|
14 |
-
*
|
15 |
-
* @
|
16 |
-
*
|
17 |
-
* @param
|
18 |
-
* @param
|
19 |
-
* @
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
*
|
35 |
-
*
|
36 |
-
*
|
37 |
-
*
|
38 |
-
* @
|
39 |
-
*
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
$result
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
* Set up the scheduler
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
)
|
96 |
-
AND b.option_value < UNIX_TIMESTAMP()
|
97 |
-
";
|
98 |
-
|
99 |
-
$wpdb -> query( $sql );
|
100 |
-
|
101 |
-
return;
|
102 |
-
}
|
103 |
-
|
104 |
-
add_action( 'ye_housekeep_transients', 'ye_clean_transients' );
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Transient Functions
|
4 |
+
*
|
5 |
+
* Functions to save cache data and housekeep it
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Save a transient
|
12 |
+
*
|
13 |
+
* Generate a transient name and save it
|
14 |
+
*
|
15 |
+
* @param string $name The name of the transient.
|
16 |
+
* @param string $data The data to store.
|
17 |
+
* @param string $cache How long to cache the data for.
|
18 |
+
* @param string $hash Whether to hash the name (true or false).
|
19 |
+
* @return string True or false, indicating success.
|
20 |
+
*/
|
21 |
+
function ye_set_transient( $name, $data, $cache, $hash = false ) {
|
22 |
+
|
23 |
+
if ( $hash ) {
|
24 |
+
$name = hash( 'ripemd128', $name );
|
25 |
+
}
|
26 |
+
|
27 |
+
$result = set_transient( 'youtubeembed_' . $name, $data, $cache );
|
28 |
+
|
29 |
+
return $result;
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Get a transient
|
34 |
+
*
|
35 |
+
* Generate a transient name and fetch it
|
36 |
+
*
|
37 |
+
* @param string $name The name of the transient.
|
38 |
+
* @param string $hash Whether to hash the name (true or false).
|
39 |
+
* @return string The transient result or false, if failed.
|
40 |
+
*/
|
41 |
+
function ye_get_transient( $name, $hash = false ) {
|
42 |
+
|
43 |
+
if ( $hash ) {
|
44 |
+
$name = hash( 'ripemd128', $name );
|
45 |
+
}
|
46 |
+
|
47 |
+
$result = get_transient( 'youtubeembed_' . $name );
|
48 |
+
|
49 |
+
return $result;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Set up the scheduler
|
54 |
+
*
|
55 |
+
* Set up the scheduler for midnight to run the housekeeping
|
56 |
+
*/
|
57 |
+
function ye_set_up_scheduler() {
|
58 |
+
|
59 |
+
if ( ! wp_next_scheduled( 'housekeep_ye_transients' ) ) {
|
60 |
+
wp_schedule_event( strtotime( '00:00' ), 'daily', 'housekeep_ye_transients' );
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
add_action( 'init', 'ye_set_up_scheduler' );
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Housekeep the transients
|
68 |
+
*
|
69 |
+
* Remove any expired transients, relevant to this plugin
|
70 |
+
*/
|
71 |
+
function ye_housekeep_transients() {
|
72 |
+
|
73 |
+
$sql = "
|
74 |
+
DELETE
|
75 |
+
a, b
|
76 |
+
FROM
|
77 |
+
{$wpdb->options} a, {$wpdb->options} b
|
78 |
+
WHERE
|
79 |
+
a.option_name LIKE '%_transient_youtubeembed_%' AND
|
80 |
+
a.option_name NOT LIKE '%_transient_timeout_youtubeembed_%' AND
|
81 |
+
b.option_name = CONCAT(
|
82 |
+
'_transient_timeout_',
|
83 |
+
SUBSTRING(
|
84 |
+
a.option_name,
|
85 |
+
CHAR_LENGTH('_transient_') + 1
|
86 |
+
)
|
87 |
+
)
|
88 |
+
AND b.option_value < UNIX_TIMESTAMP()
|
89 |
+
";
|
90 |
+
|
91 |
+
$wpdb->query( $sql );
|
92 |
+
}
|
93 |
+
|
94 |
+
add_action( 'ye_housekeep_transients', 'ye_clean_transients' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/generate-embed-code.php
CHANGED
@@ -28,90 +28,122 @@ function ye_generate_youtube_code( $array ) {
|
|
28 |
|
29 |
// Set defaults then merge with passed array. Finally, split array into individual variables.
|
30 |
|
31 |
-
$default = array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
$array = array_merge( $default, $array );
|
34 |
|
35 |
extract( $array );
|
36 |
|
37 |
-
// Initialisation
|
38 |
|
39 |
-
$start_time
|
40 |
-
|
41 |
-
|
42 |
$cache_suppress = false;
|
43 |
|
44 |
-
// Ensure an ID is passed
|
45 |
|
46 |
-
if (
|
|
|
|
|
47 |
|
48 |
-
// Get general options
|
49 |
|
50 |
$general = ye_get_general_defaults();
|
51 |
|
52 |
-
// Find the profile, if one is specified. Otherwise use default
|
53 |
|
54 |
-
if (
|
55 |
-
$profile = ye_validate_profile( $profile, $general[
|
56 |
} else {
|
57 |
$profile = 0;
|
58 |
}
|
59 |
$options = ye_get_profile( $profile );
|
60 |
|
61 |
// If a user look-up or search has been requested, miss out looking up list details and
|
62 |
-
// simple assign it as an IFRAME video
|
63 |
|
64 |
$playlist_ids = '';
|
65 |
-
$embed_type
|
66 |
|
67 |
-
if ( (
|
68 |
|
69 |
-
// Check if it's a list
|
70 |
|
71 |
$list_found = false;
|
72 |
-
if ( ( $general[
|
73 |
-
$list = ye_validate_list( $id, $general[
|
74 |
-
if ( is_array( $list ) ) {
|
|
|
|
|
75 |
}
|
76 |
|
77 |
-
// If this isn't a list, extract the ID and work out the type
|
78 |
|
79 |
-
if (
|
80 |
|
81 |
-
// Check if certain parameters are included in the URL
|
82 |
|
83 |
-
$width
|
84 |
$height = ye_get_url_para( $id, 'h', $height );
|
85 |
|
86 |
-
// Extract the ID if a full URL has been specified
|
87 |
|
88 |
$id = ye_extract_id( $id );
|
89 |
|
90 |
-
// Fetch in video data
|
91 |
|
92 |
-
$api_data
|
93 |
-
$embed_type = $api_data[
|
94 |
|
95 |
-
// If the video is invalid, output an error
|
96 |
|
97 |
-
if (
|
98 |
-
$result = $newline . '<!-- YouTube Embed v' .
|
|
|
99 |
$result .= sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) . $newline . '<!-- ' . __( 'End of YouTube Embed code' ) . ' -->' . $newline;
|
100 |
return $result;
|
101 |
}
|
102 |
-
|
103 |
}
|
104 |
|
105 |
-
// This is a list, so build the list appropriately
|
106 |
|
107 |
if ( $list_found ) {
|
108 |
|
109 |
$embed_type = 'v';
|
110 |
-
$list_name
|
111 |
|
112 |
-
// Randomize the video
|
113 |
|
114 |
-
if (
|
115 |
|
116 |
shuffle( $list );
|
117 |
|
@@ -119,9 +151,9 @@ function ye_generate_youtube_code( $array ) {
|
|
119 |
|
120 |
}
|
121 |
|
122 |
-
// Extract one video randomly
|
123 |
|
124 |
-
if (
|
125 |
|
126 |
$id = $list[ array_rand( $list, 1 ) ];
|
127 |
|
@@ -129,129 +161,191 @@ function ye_generate_youtube_code( $array ) {
|
|
129 |
|
130 |
} else {
|
131 |
|
132 |
-
$id = $list [
|
133 |
|
134 |
-
// Build the playlist
|
135 |
|
136 |
if ( count( $list ) > 1 ) {
|
137 |
-
$loop
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
141 |
$playlist_ids .= $list_id;
|
142 |
$loop ++;
|
143 |
}
|
144 |
}
|
145 |
}
|
146 |
|
147 |
-
// Fetch in video data
|
148 |
|
149 |
$api_data = ye_get_api_data( $id, '', '', '', $list_name );
|
150 |
}
|
151 |
}
|
152 |
|
153 |
-
|
154 |
|
155 |
-
|
|
|
|
|
156 |
|
157 |
-
// Get from cache, if required
|
158 |
|
159 |
-
if ( $general[
|
160 |
|
161 |
-
// Generate the cache key - it's a combination of ALL the passed parameters, some of the general options, all of the relevant profile options and the playlist, if specified
|
162 |
|
163 |
-
$general_extract = array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
$key =
|
166 |
|
167 |
-
if ( $list_found ) {
|
|
|
|
|
168 |
|
169 |
-
// Now fetch the cache
|
170 |
|
171 |
$cache = ye_get_transient( $key, true );
|
172 |
-
if (
|
|
|
|
|
173 |
}
|
174 |
|
175 |
-
// If this is a feed then display a thumbnail and/or text link to the original video
|
176 |
|
177 |
-
if ( is_feed
|
178 |
$result = '';
|
179 |
-
if ( (
|
180 |
-
$result .= '<p>'.__( 'A video list cannot be viewed within this feed - please view the original content', 'youtube-embed' ) . '.</p>' . $newline;
|
181 |
} else {
|
182 |
$youtube_url = 'https://www.youtube.com/watch?' . $embed_type . '=' . $id;
|
183 |
-
|
184 |
-
if ( (
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
return $result;
|
187 |
}
|
188 |
|
189 |
-
// If responsive output has been requested, check whether the width should be fixed
|
190 |
|
191 |
$fixed = '';
|
192 |
-
if (
|
193 |
-
$responsive = $options[
|
194 |
-
$fixed
|
195 |
} else {
|
196 |
-
if (
|
|
|
|
|
197 |
}
|
198 |
|
199 |
-
// Only set width and height from defaults if both are missing
|
200 |
|
201 |
-
if ( (
|
202 |
-
$width
|
203 |
-
$height = $options[
|
204 |
}
|
205 |
|
206 |
-
// If height or width is missing, calculate missing parameter using ratio
|
207 |
|
208 |
-
if ( ( (
|
209 |
-
$new_sizes = ye_calculate_video_size( $width, $height, $options[
|
210 |
-
$width
|
211 |
-
$height
|
212 |
}
|
213 |
|
214 |
-
// If values have not been passed, use the default values
|
215 |
|
216 |
-
if (
|
217 |
-
|
218 |
-
|
219 |
-
if (
|
220 |
-
|
221 |
-
|
222 |
-
if (
|
223 |
-
|
224 |
-
|
225 |
-
if (
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
-
// And for those not passed, simply assign the defaults to variables
|
232 |
|
233 |
-
$metadata = $general[
|
234 |
-
$debug
|
235 |
-
$privacy
|
236 |
|
237 |
-
if (
|
238 |
-
|
|
|
|
|
|
|
|
|
239 |
|
240 |
$class = 'youtube-player';
|
241 |
|
242 |
-
// Build the required template
|
243 |
-
// If no video tag is found, set to the default
|
244 |
|
245 |
-
if (
|
246 |
-
$template = $options[
|
247 |
} else {
|
248 |
$template = htmlspecialchars_decode( $template, ENT_QUOTES );
|
249 |
}
|
250 |
-
if ( strpos( $template, '%video%' )
|
|
|
|
|
251 |
|
252 |
// Set frameborder options.
|
253 |
|
254 |
-
if ( isset( $general[
|
255 |
$frameborder = 'frameborder="0" ';
|
256 |
} else {
|
257 |
$frameborder = '';
|
@@ -261,21 +355,51 @@ function ye_generate_youtube_code( $array ) {
|
|
261 |
|
262 |
$paras = '';
|
263 |
|
264 |
-
if (
|
265 |
-
|
266 |
-
|
267 |
-
if (
|
268 |
-
|
269 |
-
|
270 |
-
if (
|
271 |
-
|
272 |
-
|
273 |
-
if (
|
274 |
-
|
275 |
-
|
276 |
-
if (
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
280 |
// If the loop parameter is being used, make this a single video playlist.
|
281 |
|
@@ -289,120 +413,169 @@ function ye_generate_youtube_code( $array ) {
|
|
289 |
$paras .= '&playlist=' . $playlist_ids;
|
290 |
}
|
291 |
|
292 |
-
// Generate DIVs to wrap around video
|
293 |
|
294 |
-
$ttab
|
295 |
$result = '<div class="youtube-embed';
|
296 |
-
|
|
|
|
|
|
|
297 |
$result .= '"';
|
298 |
-
if (
|
|
|
|
|
299 |
$result .= '>' . $newline;
|
300 |
-
if ( (
|
301 |
$result = '<div style="width: ' . $width . 'px; max-width: 100%">' . $newline . $tab . $result;
|
302 |
-
$ttab
|
303 |
}
|
304 |
|
305 |
-
|
306 |
|
307 |
-
|
308 |
|
309 |
-
if ( $api_data[
|
310 |
$friendly = 'false';
|
311 |
} else {
|
312 |
-
if ( $api_data[
|
313 |
$friendly = 'true';
|
314 |
} else {
|
315 |
$friendly = '';
|
316 |
}
|
317 |
}
|
318 |
|
319 |
-
|
320 |
-
if ( $api_data[ 'title' ] != '' ) { $result .= $ttab . '<meta itemprop="name" content="' . $api_data[ 'title' ] . '" />' . $newline; }
|
321 |
-
if ( $api_data[ 'description' ] != '' ) { $result .= $ttab . '<meta itemprop="description" content="' . $api_data[ 'description' ] . '" />' . $newline; }
|
322 |
-
if ( $api_data[ 'published' ] != '' ) { $result .= $ttab . '<meta itemprop="uploadDate" content="' . $api_data[ 'published' ] . '" />' . $newline; }
|
323 |
-
if ( $api_data[ 'thumb_default' ] != '' ) { $result .= $ttab . '<meta itemprop="thumbnailUrl" content="' . $api_data[ 'thumb_default' ] . '" />' . $newline; }
|
324 |
-
$result .= $ttab . '<meta itemprop="embedUrl" content="https://www.youtube.com/embed/' . $id . '" />' . $newline;
|
325 |
-
$result .= $ttab . '<meta itemprop="height" content="' . $height . '" />' . $newline;
|
326 |
-
$result .= $ttab . '<meta itemprop="width" content="' . $width . '" />' . $newline;
|
327 |
-
if ( $friendly != '' ) { $result .= $ttab . '<meta itemprop="isFamilyFriendly" content="' . $friendly . '" />' . $newline; }
|
328 |
-
}
|
329 |
|
330 |
-
|
|
|
|
|
331 |
|
332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
$do_not_track = ye_do_not_track();
|
334 |
-
if ( $do_not_track ) {
|
|
|
|
|
|
|
|
|
335 |
}
|
336 |
|
337 |
-
if (
|
|
|
|
|
|
|
|
|
338 |
|
339 |
-
// Generate the first part of the embed URL along with the ID section
|
340 |
|
341 |
$embed_url = 'https://www.' . $url_privacy . '/embed';
|
342 |
-
|
343 |
|
344 |
-
// If a playlist, user or download build the ID appropriately
|
345 |
|
346 |
-
if ( (
|
347 |
|
348 |
$list_type = '';
|
349 |
-
if (
|
350 |
-
|
351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
$id_paras = '?listType=' . $list_type . '&list=';
|
354 |
-
if ( (
|
|
|
|
|
355 |
$id_paras .= $id;
|
356 |
}
|
357 |
|
358 |
-
// Combine URL parts together
|
359 |
|
360 |
$embed_url .= $id_paras;
|
361 |
-
if ( ( !strpos( $embed_url, '?' ) ) && (
|
|
|
|
|
362 |
$embed_url .= $paras;
|
363 |
|
364 |
-
// Check length of URL to ensure it doesn't exceed 2000 characters
|
365 |
|
366 |
-
if ( strlen( $embed_url ) > 2000 ) {
|
|
|
|
|
367 |
|
368 |
-
// Add IFRAME embed code
|
369 |
|
370 |
-
if (
|
|
|
|
|
|
|
|
|
371 |
$result .= $ttab . '<iframe ' . $frameborder . 'style="border: 0;' . $style . '" class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . $embed_url . '"';
|
372 |
-
if (
|
373 |
-
|
|
|
|
|
|
|
|
|
|
|
374 |
|
375 |
-
// Now apply the template to the result
|
376 |
|
377 |
$end_tag = '';
|
378 |
-
if ( (
|
379 |
$end_tag .= $tab . '</div>' . $newline . '</div>' . $newline;
|
380 |
} else {
|
381 |
$end_tag .= '</div>' . $newline;
|
382 |
}
|
383 |
$result = str_replace( '%video%', $result . $end_tag, $template );
|
384 |
|
385 |
-
// Add the download link, if required
|
386 |
|
387 |
-
if ( ( $options[
|
388 |
-
$result .= '<div style="' . $options[
|
389 |
}
|
390 |
|
391 |
-
// Now add a commented header and trailer
|
392 |
|
393 |
-
if (
|
394 |
-
$result
|
395 |
$runtime = round( microtime( true ) - $start_time, 5 );
|
396 |
$result .= '<!-- End of YouTube Embed code. Generated in ' . $runtime . ' seconds -->' . $newline;
|
397 |
}
|
398 |
|
399 |
$result = $newline . $result;
|
400 |
|
401 |
-
// Save the cache
|
402 |
|
403 |
-
if ( $general[
|
404 |
|
405 |
-
$cache = $general[
|
406 |
|
407 |
ye_set_transient( $key, $result, $cache, true );
|
408 |
|
@@ -412,34 +585,33 @@ function ye_generate_youtube_code( $array ) {
|
|
412 |
}
|
413 |
|
414 |
/**
|
415 |
-
* Validate a supplied profile name
|
416 |
-
*
|
417 |
-
* Returns a profile number for a supplied name
|
418 |
-
*
|
419 |
-
* @
|
420 |
-
*
|
421 |
-
* @
|
422 |
-
|
423 |
-
* @return string The profile number (defaults to 0)
|
424 |
-
*/
|
425 |
-
|
426 |
function ye_validate_profile( $name, $number ) {
|
427 |
|
428 |
$profile = 0;
|
429 |
-
$name
|
430 |
|
431 |
-
if ( (
|
432 |
|
433 |
-
// Loop around, fetching in profile names
|
434 |
|
435 |
$loop = 1;
|
436 |
-
while ( ( $loop <= $number ) && (
|
437 |
-
if ( ( $name == $loop )
|
438 |
$profile = $loop;
|
439 |
} else {
|
440 |
$profiles = ye_get_profile( $loop );
|
441 |
-
$profname = strtolower( $profiles[
|
442 |
-
if ( $profname == $name ) {
|
|
|
|
|
443 |
}
|
444 |
$loop ++;
|
445 |
}
|
@@ -448,81 +620,83 @@ function ye_validate_profile( $name, $number ) {
|
|
448 |
}
|
449 |
|
450 |
/**
|
451 |
-
* Validate a supplied list name
|
452 |
-
*
|
453 |
-
* Returns a list for a supplied list number or name name - blank if not a valid list
|
454 |
-
*
|
455 |
-
* @
|
456 |
-
*
|
457 |
-
* @
|
458 |
-
|
459 |
-
* @return string The list (defaults to blank)
|
460 |
-
*/
|
461 |
-
|
462 |
function ye_validate_list( $name, $number ) {
|
463 |
|
464 |
$list = '';
|
465 |
|
466 |
-
// If the parameter contains commas, assume to be a comma seperated list and move into an array
|
467 |
|
468 |
if ( strpos( $name, ',' ) !== false ) {
|
469 |
$list = explode( ',', $name );
|
470 |
} else {
|
471 |
|
472 |
-
// No comma, so check if this is a named list
|
473 |
|
474 |
$name = strtolower( $name );
|
475 |
|
476 |
-
if (
|
477 |
|
478 |
-
// Loop around, fetching in profile names
|
479 |
|
480 |
$loop = 1;
|
481 |
-
while ( ( $loop <= $number ) && (
|
482 |
$listfiles = ye_get_list( $loop );
|
483 |
-
if ( is_array( $listfiles) ) {
|
484 |
-
if ( (
|
485 |
-
$list = $listfiles[
|
486 |
} else {
|
487 |
-
$listname = strtolower( $listfiles[
|
488 |
-
if ( $listname == $name ) {
|
|
|
|
|
489 |
}
|
490 |
}
|
491 |
$loop ++;
|
492 |
}
|
493 |
}
|
494 |
-
if (
|
|
|
|
|
495 |
}
|
496 |
return $list;
|
497 |
}
|
498 |
|
499 |
/**
|
500 |
-
* Get URL parameters
|
501 |
-
*
|
502 |
-
* Extract a requested parameter from a URL
|
503 |
-
*
|
504 |
-
* @
|
505 |
-
*
|
506 |
-
* @param
|
507 |
-
* @
|
508 |
-
|
509 |
-
* @return string The parameter value
|
510 |
-
*/
|
511 |
-
|
512 |
function ye_get_url_para( $id, $para, $current ) {
|
513 |
|
514 |
-
// Look for an ampersand
|
515 |
|
516 |
$start_pos = false;
|
517 |
-
if (
|
|
|
|
|
518 |
|
519 |
-
// If a parameter was found, look for the end of it
|
520 |
|
521 |
-
if (
|
522 |
$end_pos = strpos( $id, '&', $start_pos + 1 );
|
523 |
-
if (
|
|
|
|
|
524 |
|
525 |
-
// Extract the parameter and return it
|
526 |
|
527 |
$current = substr( $id, $start_pos, $end_pos - $start_pos );
|
528 |
}
|
@@ -531,24 +705,25 @@ function ye_get_url_para( $id, $para, $current ) {
|
|
531 |
}
|
532 |
|
533 |
/**
|
534 |
-
* Is Do Not Track active?
|
535 |
-
*
|
536 |
-
* Function to return whether Do Not Track is active in the current
|
537 |
-
* browser
|
538 |
-
*
|
539 |
-
* @
|
540 |
-
|
541 |
-
* @return string True or false
|
542 |
-
*/
|
543 |
-
|
544 |
function ye_do_not_track() {
|
545 |
|
546 |
-
if ( isset( $_SERVER[
|
547 |
-
if ( $_SERVER[
|
|
|
|
|
548 |
} else {
|
549 |
if ( function_exists( 'getallheaders' ) ) {
|
550 |
foreach ( getallheaders() as $key => $value ) {
|
551 |
-
if ( ( strtolower( $key )
|
|
|
|
|
552 |
}
|
553 |
}
|
554 |
}
|
@@ -556,47 +731,52 @@ function ye_do_not_track() {
|
|
556 |
}
|
557 |
|
558 |
/**
|
559 |
-
* Calculate video size
|
560 |
-
*
|
561 |
-
* Calculate the video size using a ratio
|
562 |
-
*
|
563 |
-
* @
|
564 |
-
*
|
565 |
-
* @param
|
566 |
-
* @param
|
567 |
-
* @param
|
568 |
-
* @
|
569 |
-
|
570 |
-
* @return array Array of new width and height
|
571 |
-
*/
|
572 |
-
|
573 |
function ye_calculate_video_size( $width, $height, $default_width, $default_height, $ratio ) {
|
574 |
|
575 |
$ratio_to_use = '';
|
576 |
-
$new_sizes
|
577 |
|
578 |
-
// If a ratio has been specified by the user, extract it
|
579 |
|
580 |
-
if (
|
581 |
$pos = strpos( $ratio, ':', 0 );
|
582 |
-
if (
|
583 |
$ratio_l = substr( $ratio, 0, $pos );
|
584 |
$ratio_r = substr( $ratio, $pos + 1 );
|
585 |
-
if ( ( is_numeric( $ratio_l ) ) && ( is_numeric( $ratio_r ) ) ) {
|
|
|
|
|
586 |
}
|
587 |
}
|
588 |
|
589 |
-
// If no, or invalid, ratio supplied, calculate from the default video dimensions
|
590 |
|
591 |
-
if (
|
|
|
|
|
592 |
|
593 |
-
// Complete the missing width or height using the ratio
|
594 |
|
595 |
-
if (
|
596 |
-
|
|
|
|
|
|
|
|
|
597 |
|
598 |
-
$new_sizes[
|
599 |
-
$new_sizes[
|
600 |
|
601 |
return $new_sizes;
|
602 |
}
|
28 |
|
29 |
// Set defaults then merge with passed array. Finally, split array into individual variables.
|
30 |
|
31 |
+
$default = array(
|
32 |
+
'id' => '',
|
33 |
+
'width' => '',
|
34 |
+
'height' => '',
|
35 |
+
'fullscreen' => '',
|
36 |
+
'related' => '',
|
37 |
+
'autoplay' => '',
|
38 |
+
'loop' => '',
|
39 |
+
'start' => '',
|
40 |
+
'annotation' => '',
|
41 |
+
'cc' => '',
|
42 |
+
'style' => '',
|
43 |
+
'stop' => '',
|
44 |
+
'disablekb' => '',
|
45 |
+
'ratio' => '',
|
46 |
+
'controls' => '',
|
47 |
+
'profile' => '',
|
48 |
+
'list_style' => '',
|
49 |
+
'template' => '',
|
50 |
+
'color' => '',
|
51 |
+
'responsive' => '',
|
52 |
+
'search' => '',
|
53 |
+
'user' => '',
|
54 |
+
'modest' => '',
|
55 |
+
'playsinline' => '',
|
56 |
+
'cc_lang' => '',
|
57 |
+
'language' => '',
|
58 |
+
'lazyload' => '',
|
59 |
+
);
|
60 |
|
61 |
$array = array_merge( $default, $array );
|
62 |
|
63 |
extract( $array );
|
64 |
|
65 |
+
// Initialisation.
|
66 |
|
67 |
+
$start_time = microtime( true );
|
68 |
+
$newline = "\n";
|
69 |
+
$tab = "\t";
|
70 |
$cache_suppress = false;
|
71 |
|
72 |
+
// Ensure an ID is passed.
|
73 |
|
74 |
+
if ( '' == $id ) {
|
75 |
+
return ye_error( __( 'No video/playlist ID has been supplied', 'youtube-embed' ) );
|
76 |
+
}
|
77 |
|
78 |
+
// Get general options.
|
79 |
|
80 |
$general = ye_get_general_defaults();
|
81 |
|
82 |
+
// Find the profile, if one is specified. Otherwise use default.
|
83 |
|
84 |
+
if ( '' != $profile ) {
|
85 |
+
$profile = ye_validate_profile( $profile, $general['profile_no'] );
|
86 |
} else {
|
87 |
$profile = 0;
|
88 |
}
|
89 |
$options = ye_get_profile( $profile );
|
90 |
|
91 |
// If a user look-up or search has been requested, miss out looking up list details and
|
92 |
+
// simple assign it as an IFRAME video.
|
93 |
|
94 |
$playlist_ids = '';
|
95 |
+
$embed_type = '';
|
96 |
|
97 |
+
if ( ( 0 == $user ) && ( 0 == $search ) ) {
|
98 |
|
99 |
+
// Check if it's a list.
|
100 |
|
101 |
$list_found = false;
|
102 |
+
if ( ( 1 == $general['force_list_type'] && '' != $list_style ) || ( 1 != $general['force_list_type'] ) ) {
|
103 |
+
$list = ye_validate_list( $id, $general['list_no'] );
|
104 |
+
if ( is_array( $list ) ) {
|
105 |
+
$list_found = true;
|
106 |
+
}
|
107 |
}
|
108 |
|
109 |
+
// If this isn't a list, extract the ID and work out the type.
|
110 |
|
111 |
+
if ( ! $list_found ) {
|
112 |
|
113 |
+
// Check if certain parameters are included in the URL.
|
114 |
|
115 |
+
$width = ye_get_url_para( $id, 'w', $width );
|
116 |
$height = ye_get_url_para( $id, 'h', $height );
|
117 |
|
118 |
+
// Extract the ID if a full URL has been specified.
|
119 |
|
120 |
$id = ye_extract_id( $id );
|
121 |
|
122 |
+
// Fetch in video data.
|
123 |
|
124 |
+
$api_data = ye_get_api_data( $id );
|
125 |
+
$embed_type = $api_data['type'];
|
126 |
|
127 |
+
// If the video is invalid, output an error.
|
128 |
|
129 |
+
if ( ! $api_data['valid'] ) {
|
130 |
+
$result = $newline . '<!-- YouTube Embed v' . YOUTUBE_EMBED_VERSION . ' -->' . $newline;
|
131 |
+
/* translators: %s is replaced with the ID of the YouTube video */
|
132 |
$result .= sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) . $newline . '<!-- ' . __( 'End of YouTube Embed code' ) . ' -->' . $newline;
|
133 |
return $result;
|
134 |
}
|
|
|
135 |
}
|
136 |
|
137 |
+
// This is a list, so build the list appropriately.
|
138 |
|
139 |
if ( $list_found ) {
|
140 |
|
141 |
$embed_type = 'v';
|
142 |
+
$list_name = $id;
|
143 |
|
144 |
+
// Randomize the video.
|
145 |
|
146 |
+
if ( 'random' == $list_style ) {
|
147 |
|
148 |
shuffle( $list );
|
149 |
|
151 |
|
152 |
}
|
153 |
|
154 |
+
// Extract one video randomly.
|
155 |
|
156 |
+
if ( 'single' == $list_style ) {
|
157 |
|
158 |
$id = $list[ array_rand( $list, 1 ) ];
|
159 |
|
161 |
|
162 |
} else {
|
163 |
|
164 |
+
$id = $list [0];
|
165 |
|
166 |
+
// Build the playlist.
|
167 |
|
168 |
if ( count( $list ) > 1 ) {
|
169 |
+
$loop = 1;
|
170 |
+
$playlist_count = count( $list );
|
171 |
+
while ( $loop < $playlist_count ) {
|
172 |
+
if ( '' != $playlist_ids ) {
|
173 |
+
$playlist_ids .= ',';
|
174 |
+
}
|
175 |
+
$list_id = ye_extract_id( $list[ $loop ] );
|
176 |
$playlist_ids .= $list_id;
|
177 |
$loop ++;
|
178 |
}
|
179 |
}
|
180 |
}
|
181 |
|
182 |
+
// Fetch in video data.
|
183 |
|
184 |
$api_data = ye_get_api_data( $id, '', '', '', $list_name );
|
185 |
}
|
186 |
}
|
187 |
|
188 |
+
// Correct the ID if a playlist.
|
189 |
|
190 |
+
if ( 'pl' == strtolower( substr( $id, 0, 2 ) ) && 34 == strlen( $id ) ) {
|
191 |
+
$id = substr( $id, 2 );
|
192 |
+
}
|
193 |
|
194 |
+
// Get from cache, if required.
|
195 |
|
196 |
+
if ( 0 != $general['video_cache'] && get_the_date() !== false && ! $cache_suppress ) {
|
197 |
|
198 |
+
// Generate the cache key - it's a combination of ALL the passed parameters, some of the general options, all of the relevant profile options and the playlist, if specified.
|
199 |
|
200 |
+
$general_extract = array(
|
201 |
+
'metadata' => $general['metadata'],
|
202 |
+
'feed' => $general['feed'],
|
203 |
+
'thumbnail' => $general['thumbnail'],
|
204 |
+
'privacy' => $general['privacy'],
|
205 |
+
'frameborder' => $general['frameborder'],
|
206 |
+
'debug' => $general['debug'],
|
207 |
+
'script' => $general['script'],
|
208 |
+
'force_list_type' => $general['force_list_type'],
|
209 |
+
);
|
210 |
|
211 |
+
$key = wp_json_encode( $options ) . wp_json_encode( $array ) . wp_json_encode( $general_extract );
|
212 |
|
213 |
+
if ( $list_found ) {
|
214 |
+
$key .= wp_json_encode( $list );
|
215 |
+
}
|
216 |
|
217 |
+
// Now fetch the cache.
|
218 |
|
219 |
$cache = ye_get_transient( $key, true );
|
220 |
+
if ( false !== $cache ) {
|
221 |
+
return $cache;
|
222 |
+
}
|
223 |
}
|
224 |
|
225 |
+
// If this is a feed then display a thumbnail and/or text link to the original video.
|
226 |
|
227 |
+
if ( is_feed() ) {
|
228 |
$result = '';
|
229 |
+
if ( ( '' != $playlist_ids ) || ( 0 != $user ) || ( 0 != $search ) ) {
|
230 |
+
$result .= '<p>' . __( 'A video list cannot be viewed within this feed - please view the original content', 'youtube-embed' ) . '.</p>' . $newline;
|
231 |
} else {
|
232 |
$youtube_url = 'https://www.youtube.com/watch?' . $embed_type . '=' . $id;
|
233 |
+
|
234 |
+
if ( ( 'v' == $embed_type ) && ( 't' != $general['feed'] ) ) {
|
235 |
+
$result .= '<p><a href="' . $youtube_url . '"><img src="https://img.youtube.com/vi/' . $id . '/' . $general['thumbnail'] . '.jpg" alt="' . $api_data['title'] . '"></a></p>' . $newline;
|
236 |
+
}
|
237 |
+
if ( ( 'v' != $general['feed'] ) || ( 'v' != $embed_type ) ) {
|
238 |
+
$result .= '<p><a href="' . $youtube_url . '">' . __( 'Click here to view the video on YouTube', 'youtube-embed' ) . '</a>.</p>' . $newline;
|
239 |
+
}
|
240 |
}
|
241 |
return $result;
|
242 |
}
|
243 |
|
244 |
+
// If responsive output has been requested, check whether the width should be fixed.
|
245 |
|
246 |
$fixed = '';
|
247 |
+
if ( '' == $responsive ) {
|
248 |
+
$responsive = $options['dynamic'];
|
249 |
+
$fixed = $options['fixed'];
|
250 |
} else {
|
251 |
+
if ( '' != $width ) {
|
252 |
+
$fixed = 1;
|
253 |
+
}
|
254 |
}
|
255 |
|
256 |
+
// Only set width and height from defaults if both are missing.
|
257 |
|
258 |
+
if ( ( '' == $width ) && ( '' == $height ) ) {
|
259 |
+
$width = $options['width'];
|
260 |
+
$height = $options['height'];
|
261 |
}
|
262 |
|
263 |
+
// If height or width is missing, calculate missing parameter using ratio.
|
264 |
|
265 |
+
if ( ( ( '' == $width ) || ( '' == $height ) ) && ( ( '' != $width ) || ( '' != $height ) ) ) {
|
266 |
+
$new_sizes = ye_calculate_video_size( $width, $height, $options['width'], $options['height'], $ratio );
|
267 |
+
$width = $new_sizes['width'];
|
268 |
+
$height = $new_sizes['height'];
|
269 |
}
|
270 |
|
271 |
+
// If values have not been passed, use the default values.
|
272 |
|
273 |
+
if ( '' == $fullscreen ) {
|
274 |
+
$fullscreen = $options['fullscreen'];
|
275 |
+
}
|
276 |
+
if ( '' == $related ) {
|
277 |
+
$related = $options['related'];
|
278 |
+
}
|
279 |
+
if ( '' == $autoplay ) {
|
280 |
+
$autoplay = $options['autoplay'];
|
281 |
+
}
|
282 |
+
if ( '' == $loop ) {
|
283 |
+
$loop = $options['loop'];
|
284 |
+
}
|
285 |
+
if ( '' == $annotation ) {
|
286 |
+
$annotation = $options['annotation'];
|
287 |
+
}
|
288 |
+
if ( '' == $cc ) {
|
289 |
+
$cc = $options['cc'];
|
290 |
+
}
|
291 |
+
if ( '' == $cc_lang ) {
|
292 |
+
$cc_lang = $options['cc_lang'];
|
293 |
+
}
|
294 |
+
if ( '' == $language ) {
|
295 |
+
$language = $options['language'];
|
296 |
+
}
|
297 |
+
if ( '' == $disablekb ) {
|
298 |
+
$disablekb = $options['disablekb'];
|
299 |
+
}
|
300 |
+
if ( '' == $controls ) {
|
301 |
+
$controls = $options['controls'];
|
302 |
+
}
|
303 |
+
if ( '' == $style ) {
|
304 |
+
$style = $options['style'];
|
305 |
+
}
|
306 |
+
if ( '' == $color ) {
|
307 |
+
$color = $options['color'];
|
308 |
+
}
|
309 |
+
if ( '' == $modest ) {
|
310 |
+
$modest = $options['modest'];
|
311 |
+
}
|
312 |
+
if ( '' == $playsinline ) {
|
313 |
+
$playsinline = $options['playsinline'];
|
314 |
+
}
|
315 |
+
if ( '' == $lazyload ) {
|
316 |
+
$lazyload = $general['lazyload'];
|
317 |
+
}
|
318 |
|
319 |
+
// And for those not passed, simply assign the defaults to variables.
|
320 |
|
321 |
+
$metadata = $general['metadata'];
|
322 |
+
$debug = $general['debug'];
|
323 |
+
$privacy = $general['privacy'];
|
324 |
|
325 |
+
if ( '' == $start ) {
|
326 |
+
$start = '0';
|
327 |
+
}
|
328 |
+
if ( '' == $stop ) {
|
329 |
+
$stop = '0';
|
330 |
+
}
|
331 |
|
332 |
$class = 'youtube-player';
|
333 |
|
334 |
+
// Build the required template.
|
335 |
+
// If no video tag is found, set to the default.
|
336 |
|
337 |
+
if ( '' == $template ) {
|
338 |
+
$template = $options['template'];
|
339 |
} else {
|
340 |
$template = htmlspecialchars_decode( $template, ENT_QUOTES );
|
341 |
}
|
342 |
+
if ( false === strpos( $template, '%video%' ) ) {
|
343 |
+
$template = '%video%';
|
344 |
+
}
|
345 |
|
346 |
// Set frameborder options.
|
347 |
|
348 |
+
if ( isset( $general['frameborder'] ) && 1 != $general['frameborder'] ) {
|
349 |
$frameborder = 'frameborder="0" ';
|
350 |
} else {
|
351 |
$frameborder = '';
|
355 |
|
356 |
$paras = '';
|
357 |
|
358 |
+
if ( 1 == $modest ) {
|
359 |
+
$paras .= '&modestbranding=1';
|
360 |
+
}
|
361 |
+
if ( 1 != $fullscreen ) {
|
362 |
+
$paras .= '&fs=0';
|
363 |
+
}
|
364 |
+
if ( 1 != $related ) {
|
365 |
+
$paras .= '&rel=0';
|
366 |
+
}
|
367 |
+
if ( 1 == $autoplay ) {
|
368 |
+
$paras .= '&autoplay=1';
|
369 |
+
}
|
370 |
+
if ( 1 == $loop ) {
|
371 |
+
$paras .= '&loop=1';
|
372 |
+
}
|
373 |
+
if ( 1 != $annotation ) {
|
374 |
+
$paras .= '&iv_load_policy=3';
|
375 |
+
}
|
376 |
+
if ( '' != $cc ) {
|
377 |
+
$paras .= '&cc_load_policy=' . $cc;
|
378 |
+
}
|
379 |
+
if ( '' != $cc_lang ) {
|
380 |
+
$paras .= '&cc_lang_pref=' . $cc_lang;
|
381 |
+
}
|
382 |
+
if ( 1 == $disablekb ) {
|
383 |
+
$paras .= '&disablekb=1';
|
384 |
+
}
|
385 |
+
if ( 1 != $controls ) {
|
386 |
+
$paras .= '&controls=' . $controls;
|
387 |
+
}
|
388 |
+
if ( 'red' != strtolower( $color ) ) {
|
389 |
+
$paras .= '&color=' . strtolower( $color );
|
390 |
+
}
|
391 |
+
if ( 1 == $playsinline ) {
|
392 |
+
$paras .= '&playsinline=1';
|
393 |
+
}
|
394 |
+
if ( '' != $language ) {
|
395 |
+
$paras .= '&hl=' . $language;
|
396 |
+
}
|
397 |
+
if ( 0 != $start ) {
|
398 |
+
$paras .= '&start=' . $start;
|
399 |
+
}
|
400 |
+
if ( 0 != $stop ) {
|
401 |
+
$paras .= '&end=' . $stop;
|
402 |
+
}
|
403 |
|
404 |
// If the loop parameter is being used, make this a single video playlist.
|
405 |
|
413 |
$paras .= '&playlist=' . $playlist_ids;
|
414 |
}
|
415 |
|
416 |
+
// Generate DIVs to wrap around video.
|
417 |
|
418 |
+
$ttab = $tab;
|
419 |
$result = '<div class="youtube-embed';
|
420 |
+
|
421 |
+
if ( 1 == $responsive ) {
|
422 |
+
$result .= ' ye-container';
|
423 |
+
}
|
424 |
$result .= '"';
|
425 |
+
if ( 0 != $metadata ) {
|
426 |
+
$result .= ' itemprop="video" itemscope itemtype="https://schema.org/VideoObject"';
|
427 |
+
}
|
428 |
$result .= '>' . $newline;
|
429 |
+
if ( ( 1 == $responsive ) && ( 1 == $fixed ) ) {
|
430 |
$result = '<div style="width: ' . $width . 'px; max-width: 100%">' . $newline . $tab . $result;
|
431 |
+
$ttab .= $tab;
|
432 |
}
|
433 |
|
434 |
+
// Add Metadata.
|
435 |
|
436 |
+
if ( 0 != $metadata ) {
|
437 |
|
438 |
+
if ( true === $api_data['restricted'] ) {
|
439 |
$friendly = 'false';
|
440 |
} else {
|
441 |
+
if ( false === $api_data['restricted'] ) {
|
442 |
$friendly = 'true';
|
443 |
} else {
|
444 |
$friendly = '';
|
445 |
}
|
446 |
}
|
447 |
|
448 |
+
$result .= $ttab . '<meta itemprop="url" content="https://www.youtube.com/' . $embed_type . '/' . $id . '" />' . $newline;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
|
450 |
+
if ( '' != $api_data['title'] ) {
|
451 |
+
$result .= $ttab . '<meta itemprop="name" content="' . $api_data['title'] . '" />' . $newline;
|
452 |
+
}
|
453 |
|
454 |
+
if ( '' != $api_data['description'] ) {
|
455 |
+
$result .= $ttab . '<meta itemprop="description" content="' . $api_data['description'] . '" />' . $newline;
|
456 |
+
}
|
457 |
+
if ( '' != $api_data['published'] ) {
|
458 |
+
$result .= $ttab . '<meta itemprop="uploadDate" content="' . $api_data['published'] . '" />' . $newline;
|
459 |
+
}
|
460 |
+
if ( '' != $api_data['thumb_default'] ) {
|
461 |
+
$result .= $ttab . '<meta itemprop="thumbnailUrl" content="' . $api_data['thumb_default'] . '" />' . $newline;
|
462 |
+
}
|
463 |
+
|
464 |
+
$result .= $ttab . '<meta itemprop="embedUrl" content="https://www.youtube.com/embed/' . $id . '" />' . $newline;
|
465 |
+
$result .= $ttab . '<meta itemprop="height" content="' . $height . '" />' . $newline;
|
466 |
+
$result .= $ttab . '<meta itemprop="width" content="' . $width . '" />' . $newline;
|
467 |
+
|
468 |
+
if ( '' != $friendly ) {
|
469 |
+
$result .= $ttab . '<meta itemprop="isFamilyFriendly" content="' . $friendly . '" />' . $newline;
|
470 |
+
}
|
471 |
+
}
|
472 |
+
|
473 |
+
// Work out, depending on privacy settings, the main address to use.
|
474 |
+
|
475 |
+
if ( 2 == $privacy ) {
|
476 |
$do_not_track = ye_do_not_track();
|
477 |
+
if ( $do_not_track ) {
|
478 |
+
$privacy = 1;
|
479 |
+
} else {
|
480 |
+
$privacy = 0;
|
481 |
+
}
|
482 |
}
|
483 |
|
484 |
+
if ( 1 == $privacy ) {
|
485 |
+
$url_privacy = 'youtube-nocookie.com';
|
486 |
+
} else {
|
487 |
+
$url_privacy = 'youtube.com';
|
488 |
+
}
|
489 |
|
490 |
+
// Generate the first part of the embed URL along with the ID section.
|
491 |
|
492 |
$embed_url = 'https://www.' . $url_privacy . '/embed';
|
493 |
+
$id_paras = '/' . $id;
|
494 |
|
495 |
+
// If a playlist, user or download build the ID appropriately.
|
496 |
|
497 |
+
if ( ( 'p' == $embed_type ) || ( 0 != $user ) || ( 0 != $search ) ) {
|
498 |
|
499 |
$list_type = '';
|
500 |
+
if ( 'p' == $embed_type ) {
|
501 |
+
$list_type = 'playlist';
|
502 |
+
}
|
503 |
+
if ( 0 != $user ) {
|
504 |
+
$list_type = 'user_uploads';
|
505 |
+
}
|
506 |
+
if ( 0 != $search ) {
|
507 |
+
$list_type = 'search';
|
508 |
+
$id = urlencode( $id );
|
509 |
+
}
|
510 |
|
511 |
$id_paras = '?listType=' . $list_type . '&list=';
|
512 |
+
if ( ( 'p' == $embed_type ) && ( 'pl' != strtolower( substr( $id, 0, 2 ) ) ) ) {
|
513 |
+
$id_paras .= 'PL';
|
514 |
+
}
|
515 |
$id_paras .= $id;
|
516 |
}
|
517 |
|
518 |
+
// Combine URL parts together.
|
519 |
|
520 |
$embed_url .= $id_paras;
|
521 |
+
if ( ( ! strpos( $embed_url, '?' ) ) && ( '' != $paras ) ) {
|
522 |
+
$paras = '?' . substr( $paras, 1 );
|
523 |
+
}
|
524 |
$embed_url .= $paras;
|
525 |
|
526 |
+
// Check length of URL to ensure it doesn't exceed 2000 characters.
|
527 |
|
528 |
+
if ( strlen( $embed_url ) > 2000 ) {
|
529 |
+
return ye_error( __( 'The maximum URL length has been exceeded. Please reduce your parameter and/or playlist.', 'youtube-embed' ) );
|
530 |
+
}
|
531 |
|
532 |
+
// Add IFRAME embed code.
|
533 |
|
534 |
+
if ( 'p' == $embed_type ) {
|
535 |
+
$playlist_para = 'p/';
|
536 |
+
} else {
|
537 |
+
$playlist_para = '';
|
538 |
+
}
|
539 |
$result .= $ttab . '<iframe ' . $frameborder . 'style="border: 0;' . $style . '" class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . $embed_url . '"';
|
540 |
+
if ( 1 == $lazyload ) {
|
541 |
+
$result .= ' loading="lazy"';
|
542 |
+
}
|
543 |
+
if ( 1 == $fullscreen ) {
|
544 |
+
$result .= ' allowfullscreen';
|
545 |
+
}
|
546 |
+
$result .= '></iframe>' . $newline;
|
547 |
|
548 |
+
// Now apply the template to the result.
|
549 |
|
550 |
$end_tag = '';
|
551 |
+
if ( ( 1 == $responsive ) && ( 1 == $fixed ) ) {
|
552 |
$end_tag .= $tab . '</div>' . $newline . '</div>' . $newline;
|
553 |
} else {
|
554 |
$end_tag .= '</div>' . $newline;
|
555 |
}
|
556 |
$result = str_replace( '%video%', $result . $end_tag, $template );
|
557 |
|
558 |
+
// Add the download link, if required.
|
559 |
|
560 |
+
if ( ( 1 == $options['download'] ) && ( 'v' == $embed_type ) ) {
|
561 |
+
$result .= '<div style="' . $options['download_style'] . '" class="aye_download">' . $newline . $tab . '<a href="' . ye_generate_download_code( $id ) . '">' . $options['download_text'] . '</a>' . $newline . '</div>' . $newline;
|
562 |
}
|
563 |
|
564 |
+
// Now add a commented header and trailer.
|
565 |
|
566 |
+
if ( 1 == $debug ) {
|
567 |
+
$result = '<!-- YouTube Embed v' . YOUTUBE_EMBED_VERSION . ' -->' . $newline . $result;
|
568 |
$runtime = round( microtime( true ) - $start_time, 5 );
|
569 |
$result .= '<!-- End of YouTube Embed code. Generated in ' . $runtime . ' seconds -->' . $newline;
|
570 |
}
|
571 |
|
572 |
$result = $newline . $result;
|
573 |
|
574 |
+
// Save the cache.
|
575 |
|
576 |
+
if ( 0 != $general['video_cache'] && false !== get_the_date() && ! $cache_suppress ) {
|
577 |
|
578 |
+
$cache = $general['video_cache'] * HOUR_IN_SECONDS;
|
579 |
|
580 |
ye_set_transient( $key, $result, $cache, true );
|
581 |
|
585 |
}
|
586 |
|
587 |
/**
|
588 |
+
* Validate a supplied profile name
|
589 |
+
*
|
590 |
+
* Returns a profile number for a supplied name
|
591 |
+
*
|
592 |
+
* @param string $name The name of the profile to find.
|
593 |
+
* @param string $number The number of profiles available.
|
594 |
+
* @return string The profile number (defaults to 0).
|
595 |
+
*/
|
|
|
|
|
|
|
596 |
function ye_validate_profile( $name, $number ) {
|
597 |
|
598 |
$profile = 0;
|
599 |
+
$name = strtolower( $name );
|
600 |
|
601 |
+
if ( ( '' != $name ) && ( 'default' != $name ) ) {
|
602 |
|
603 |
+
// Loop around, fetching in profile names.
|
604 |
|
605 |
$loop = 1;
|
606 |
+
while ( ( $loop <= $number ) && ( 0 == $profile ) ) {
|
607 |
+
if ( ( $name == $loop ) || ( 'Profile ' . $loop == $name ) ) {
|
608 |
$profile = $loop;
|
609 |
} else {
|
610 |
$profiles = ye_get_profile( $loop );
|
611 |
+
$profname = strtolower( $profiles['profile_name'] );
|
612 |
+
if ( $profname == $name ) {
|
613 |
+
$profile = $loop;
|
614 |
+
}
|
615 |
}
|
616 |
$loop ++;
|
617 |
}
|
620 |
}
|
621 |
|
622 |
/**
|
623 |
+
* Validate a supplied list name
|
624 |
+
*
|
625 |
+
* Returns a list for a supplied list number or name name - blank if not a valid list
|
626 |
+
*
|
627 |
+
* @param string $name The name of the list to find.
|
628 |
+
* @param string $number The number of lists available.
|
629 |
+
* @return string The list (defaults to blank).
|
630 |
+
*/
|
|
|
|
|
|
|
631 |
function ye_validate_list( $name, $number ) {
|
632 |
|
633 |
$list = '';
|
634 |
|
635 |
+
// If the parameter contains commas, assume to be a comma seperated list and move into an array.
|
636 |
|
637 |
if ( strpos( $name, ',' ) !== false ) {
|
638 |
$list = explode( ',', $name );
|
639 |
} else {
|
640 |
|
641 |
+
// No comma, so check if this is a named list.
|
642 |
|
643 |
$name = strtolower( $name );
|
644 |
|
645 |
+
if ( '' != $name ) {
|
646 |
|
647 |
+
// Loop around, fetching in profile names.
|
648 |
|
649 |
$loop = 1;
|
650 |
+
while ( ( $loop <= $number ) && ( '' == $list ) ) {
|
651 |
$listfiles = ye_get_list( $loop );
|
652 |
+
if ( is_array( $listfiles ) ) {
|
653 |
+
if ( ( strval( $loop ) == $name ) || ( 'List ' . $loop == $name ) ) {
|
654 |
+
$list = $listfiles['list'];
|
655 |
} else {
|
656 |
+
$listname = strtolower( $listfiles['list_name'] );
|
657 |
+
if ( $listname == $name ) {
|
658 |
+
$list = $listfiles['list'];
|
659 |
+
}
|
660 |
}
|
661 |
}
|
662 |
$loop ++;
|
663 |
}
|
664 |
}
|
665 |
+
if ( '' != $list ) {
|
666 |
+
$list = explode( "\n", $list );
|
667 |
+
}
|
668 |
}
|
669 |
return $list;
|
670 |
}
|
671 |
|
672 |
/**
|
673 |
+
* Get URL parameters
|
674 |
+
*
|
675 |
+
* Extract a requested parameter from a URL
|
676 |
+
*
|
677 |
+
* @param string $id The ID of the video.
|
678 |
+
* @param string $para The parameter to extract.
|
679 |
+
* @param string $current The current parameter value.
|
680 |
+
* @return string The parameter value.
|
681 |
+
*/
|
|
|
|
|
|
|
682 |
function ye_get_url_para( $id, $para, $current ) {
|
683 |
|
684 |
+
// Look for an ampersand.
|
685 |
|
686 |
$start_pos = false;
|
687 |
+
if ( false !== strpos( $id, '&' . $para . '=' ) ) {
|
688 |
+
$start_pos = strpos( $id, '&' . $para . '=' ) + 6 + strlen( $para );
|
689 |
+
}
|
690 |
|
691 |
+
// If a parameter was found, look for the end of it.
|
692 |
|
693 |
+
if ( false !== $start_pos ) {
|
694 |
$end_pos = strpos( $id, '&', $start_pos + 1 );
|
695 |
+
if ( ! $end_pos ) {
|
696 |
+
$end_pos = strlen( $id );
|
697 |
+
}
|
698 |
|
699 |
+
// Extract the parameter and return it.
|
700 |
|
701 |
$current = substr( $id, $start_pos, $end_pos - $start_pos );
|
702 |
}
|
705 |
}
|
706 |
|
707 |
/**
|
708 |
+
* Is Do Not Track active?
|
709 |
+
*
|
710 |
+
* Function to return whether Do Not Track is active in the current
|
711 |
+
* browser
|
712 |
+
*
|
713 |
+
* @return string True or false.
|
714 |
+
*/
|
|
|
|
|
|
|
715 |
function ye_do_not_track() {
|
716 |
|
717 |
+
if ( isset( $_SERVER['HTTP_DNT'] ) ) {
|
718 |
+
if ( 1 == $_SERVER['HTTP_DNT'] ) {
|
719 |
+
return true;
|
720 |
+
}
|
721 |
} else {
|
722 |
if ( function_exists( 'getallheaders' ) ) {
|
723 |
foreach ( getallheaders() as $key => $value ) {
|
724 |
+
if ( ( 'dnt' == strtolower( $key ) ) && ( 1 == $value ) ) {
|
725 |
+
return true;
|
726 |
+
}
|
727 |
}
|
728 |
}
|
729 |
}
|
731 |
}
|
732 |
|
733 |
/**
|
734 |
+
* Calculate video size
|
735 |
+
*
|
736 |
+
* Calculate the video size using a ratio
|
737 |
+
*
|
738 |
+
* @param string $width Current width.
|
739 |
+
* @param string $height Current height.
|
740 |
+
* @param string $default_width The default width.
|
741 |
+
* @param string $default_height The default height.
|
742 |
+
* @param string $ratio User supplied ratio.
|
743 |
+
* @return array Array of new width and height.
|
744 |
+
*/
|
|
|
|
|
|
|
745 |
function ye_calculate_video_size( $width, $height, $default_width, $default_height, $ratio ) {
|
746 |
|
747 |
$ratio_to_use = '';
|
748 |
+
$new_sizes = array();
|
749 |
|
750 |
+
// If a ratio has been specified by the user, extract it.
|
751 |
|
752 |
+
if ( '' != $ratio ) {
|
753 |
$pos = strpos( $ratio, ':', 0 );
|
754 |
+
if ( false !== $pos ) {
|
755 |
$ratio_l = substr( $ratio, 0, $pos );
|
756 |
$ratio_r = substr( $ratio, $pos + 1 );
|
757 |
+
if ( ( is_numeric( $ratio_l ) ) && ( is_numeric( $ratio_r ) ) ) {
|
758 |
+
$ratio_to_use = $ratio_l / $ratio_r;
|
759 |
+
}
|
760 |
}
|
761 |
}
|
762 |
|
763 |
+
// If no, or invalid, ratio supplied, calculate from the default video dimensions.
|
764 |
|
765 |
+
if ( '' == $ratio_to_use ) {
|
766 |
+
$ratio_to_use = $default_width / $default_height;
|
767 |
+
}
|
768 |
|
769 |
+
// Complete the missing width or height using the ratio.
|
770 |
|
771 |
+
if ( '' == $width ) {
|
772 |
+
$width = round( $height * $ratio_to_use, 0 );
|
773 |
+
}
|
774 |
+
if ( '' == $height ) {
|
775 |
+
$height = round( $width / $ratio_to_use, 0 );
|
776 |
+
}
|
777 |
|
778 |
+
$new_sizes['width'] = $width;
|
779 |
+
$new_sizes['height'] = $height;
|
780 |
|
781 |
return $new_sizes;
|
782 |
}
|
includes/generate-other-code.php
CHANGED
@@ -1,148 +1,171 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Generate
|
4 |
-
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
*
|
26 |
-
*
|
27 |
-
*
|
28 |
-
*
|
29 |
-
* @uses
|
30 |
-
* @uses
|
31 |
-
*
|
32 |
-
*
|
33 |
-
* @
|
34 |
-
|
35 |
-
|
36 |
-
function ye_generate_shorturl_code( $id ) {
|
37 |
-
|
38 |
-
return ye_generate_vinfo_code( $id, '%shorturl%' );
|
39 |
-
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Generate Thumbnail Code
|
44 |
-
*
|
45 |
-
* Generate XHTML compatible YouTube video thumbnail
|
46 |
-
*
|
47 |
-
* @
|
48 |
-
* @
|
49 |
-
*
|
50 |
-
*
|
51 |
-
* @
|
52 |
-
* @
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
$
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
$
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Generate other code
|
4 |
+
*
|
5 |
+
* Various functions for generating output code
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Generate Download Code
|
12 |
+
*
|
13 |
+
* Create code to allow a YouTube video to be downloaded
|
14 |
+
*
|
15 |
+
* @param string $id YouTube video ID.
|
16 |
+
* @return string Download HTML.
|
17 |
+
*/
|
18 |
+
function ye_generate_download_code( $id ) {
|
19 |
+
|
20 |
+
return ye_generate_vinfo_code( $id, '%download%' );
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Generate video short URL
|
26 |
+
*
|
27 |
+
* Create a short URL to a YouTube video
|
28 |
+
*
|
29 |
+
* @uses ye_extract_id Extract an ID from a string.
|
30 |
+
* @uses ye_get_api_data Get API data.
|
31 |
+
* @uses ye_error Display an error.
|
32 |
+
*
|
33 |
+
* @param string $id YouTube video ID.
|
34 |
+
* @return string $youtube_code Code.
|
35 |
+
*/
|
36 |
+
function ye_generate_shorturl_code( $id ) {
|
37 |
+
|
38 |
+
return ye_generate_vinfo_code( $id, '%shorturl%' );
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Generate Thumbnail Code
|
44 |
+
*
|
45 |
+
* Generate XHTML compatible YouTube video thumbnail
|
46 |
+
*
|
47 |
+
* @uses ye_extract_id Extract an ID from a string.
|
48 |
+
* @uses ye_get_api_data Get API data.
|
49 |
+
* @uses ye_error Display an error.
|
50 |
+
*
|
51 |
+
* @param string $array Array of parameters.
|
52 |
+
* @return string $youtube_cod Code.
|
53 |
+
*/
|
54 |
+
function ye_generate_thumbnail_code( $array ) {
|
55 |
+
|
56 |
+
// Set defaults then merge with passed array. Finally, split array into individual variables.
|
57 |
+
|
58 |
+
$default = array(
|
59 |
+
'id' => '',
|
60 |
+
'style' => '',
|
61 |
+
'class' => '',
|
62 |
+
'rel' => '',
|
63 |
+
'target' => '',
|
64 |
+
'width' => '',
|
65 |
+
'height' => '',
|
66 |
+
'alt' => '',
|
67 |
+
'version' => '',
|
68 |
+
'nolink' => false,
|
69 |
+
);
|
70 |
+
|
71 |
+
$array = array_merge( $default, $array );
|
72 |
+
|
73 |
+
extract( $array );
|
74 |
+
|
75 |
+
// Create the relevant version name to find it in the API array.
|
76 |
+
|
77 |
+
$version = strtolower( $version );
|
78 |
+
if ( ( 'default' != $version ) && ( 'medium' != $version ) && ( 'high' != $version ) && ( 'standard' != $version ) && ( 'maxres' != $version ) ) {
|
79 |
+
$version = 'default';
|
80 |
+
}
|
81 |
+
|
82 |
+
// Now create the required code.
|
83 |
+
|
84 |
+
if ( '' == $alt ) {
|
85 |
+
$alt = '%title%';
|
86 |
+
}
|
87 |
+
if ( ! $nolink ) {
|
88 |
+
$youtube_code = '<a href="https://www.youtube.com/watch?v=' . $id . '"';
|
89 |
+
if ( '' != $style ) {
|
90 |
+
$youtube_code .= ' style="' . $style . '"';
|
91 |
+
}
|
92 |
+
if ( '' != $class ) {
|
93 |
+
$youtube_code .= ' class="' . $class . '"';
|
94 |
+
}
|
95 |
+
if ( '' != $rel ) {
|
96 |
+
$youtube_code .= ' rel="' . $rel . '"';
|
97 |
+
}
|
98 |
+
if ( '' != $target ) {
|
99 |
+
$youtube_code .= ' target="' . $target . '"';
|
100 |
+
}
|
101 |
+
$youtube_code .= '>';
|
102 |
+
}
|
103 |
+
$youtube_code .= '<img src="%thumb_' . $version . '%"';
|
104 |
+
if ( '' != $width ) {
|
105 |
+
$youtube_code .= ' width="' . $width . '"';
|
106 |
+
}
|
107 |
+
if ( '' != $height ) {
|
108 |
+
$youtube_code .= ' height="' . $height . '"';
|
109 |
+
}
|
110 |
+
$youtube_code .= ' alt="' . $alt . '"/>';
|
111 |
+
if ( ! $nolink ) {
|
112 |
+
$youtube_code .= '</a>';
|
113 |
+
}
|
114 |
+
|
115 |
+
$youtube_code = ye_generate_vinfo_code( $id, $youtube_code );
|
116 |
+
|
117 |
+
return $youtube_code;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Generate Video Information
|
122 |
+
*
|
123 |
+
* Output video information
|
124 |
+
*
|
125 |
+
* @uses ye_extract_id Extract an ID from a string.
|
126 |
+
* @uses ye_get_api_data Get API data.
|
127 |
+
* @uses ye_error Display an error.
|
128 |
+
*
|
129 |
+
* @param string $id Video ID.
|
130 |
+
* @param string $text The text containing the information requirements.
|
131 |
+
* @return string $output The resulting output.
|
132 |
+
*/
|
133 |
+
function ye_generate_vinfo_code( $id, $text ) {
|
134 |
+
|
135 |
+
if ( '' == $id ) {
|
136 |
+
return ye_error( __( 'No YouTube ID was specified.', 'youtube-embed' ) );
|
137 |
+
}
|
138 |
+
|
139 |
+
// Extract the ID if a full URL has been specified.
|
140 |
+
|
141 |
+
$id = ye_extract_id( $id );
|
142 |
+
|
143 |
+
// Get the data from the API.
|
144 |
+
|
145 |
+
$data = ye_get_api_data( $id );
|
146 |
+
|
147 |
+
// Exit out with an error if the ID was not valid.
|
148 |
+
|
149 |
+
if ( ! $data['valid'] ) {
|
150 |
+
/* translators: %s is replaced with the ID of the YouTube video */
|
151 |
+
return ye_error( sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) );
|
152 |
+
}
|
153 |
+
|
154 |
+
// Now replace any tags in the text with the relevant information.
|
155 |
+
|
156 |
+
$output = $text;
|
157 |
+
|
158 |
+
$output = str_replace( '%title%', $data['title'], $output );
|
159 |
+
$output = str_replace( '%description%', $data['description'], $output );
|
160 |
+
$output = str_replace( '%url%', 'https://www.youtube.com/watch?v=' . $id, $output );
|
161 |
+
$output = str_replace( '%shorturl%', 'https://youtu.be/' . $id, $output );
|
162 |
+
$output = str_replace( '%download%', 'http://keepvid.com/?url=https://www.youtube.com/watch?v=' . $id, $output );
|
163 |
+
|
164 |
+
$output = str_replace( '%thumb_default%', $data['thumb_default'], $output );
|
165 |
+
$output = str_replace( '%thumb_medium%', $data['thumb_medium'], $output );
|
166 |
+
$output = str_replace( '%thumb_high%', $data['thumb_high'], $output );
|
167 |
+
$output = str_replace( '%thumb_standard%', $data['thumb_standard'], $output );
|
168 |
+
$output = str_replace( '%thumb_maxres%', $data['thumb_maxres'], $output );
|
169 |
+
|
170 |
+
return $output;
|
171 |
+
}
|
includes/generate-widgets.php
CHANGED
@@ -1,208 +1,239 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Widgets
|
4 |
-
*
|
5 |
-
* Create and display widgets
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
//
|
59 |
-
|
60 |
-
if (
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
//
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
$
|
144 |
-
$
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
$
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Widgets
|
4 |
+
*
|
5 |
+
* Create and display widgets
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Widget Class
|
12 |
+
*
|
13 |
+
* Create and display widgets
|
14 |
+
*/
|
15 |
+
class YouTubeEmbedWidget extends WP_Widget {
|
16 |
+
/**
|
17 |
+
* Widget Constructor
|
18 |
+
*
|
19 |
+
* Call WP_Widget class to define widget
|
20 |
+
*
|
21 |
+
* @uses WP_Widget Standard WP_Widget class.
|
22 |
+
*/
|
23 |
+
function __construct() {
|
24 |
+
|
25 |
+
parent::__construct(
|
26 |
+
'youtube_embed_widget',
|
27 |
+
__( 'YouTube Embed', 'youtube-embed' ),
|
28 |
+
array(
|
29 |
+
'description' => __( 'Embed YouTube Widget.', 'youtube-embed' ),
|
30 |
+
'class' => 'ye-widget',
|
31 |
+
'customize_selective_refresh' => true,
|
32 |
+
)
|
33 |
+
);
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Display widget
|
38 |
+
*
|
39 |
+
* Display the YouTube widget
|
40 |
+
*
|
41 |
+
* @uses generate_youtube_code Generate the required YouTube code.
|
42 |
+
*
|
43 |
+
* @param string $args Arguments.
|
44 |
+
* @param string $instance Instance.
|
45 |
+
*/
|
46 |
+
function widget( $args, $instance ) {
|
47 |
+
|
48 |
+
extract( $args, EXTR_SKIP );
|
49 |
+
|
50 |
+
// Output the header.
|
51 |
+
|
52 |
+
echo $before_widget;
|
53 |
+
|
54 |
+
// Extract title for heading.
|
55 |
+
|
56 |
+
$title = $instance['titles'];
|
57 |
+
|
58 |
+
// Output title, if one exists.
|
59 |
+
|
60 |
+
if ( ! empty( $title ) ) {
|
61 |
+
echo $before_title . $title . $after_title;
|
62 |
+
}
|
63 |
+
|
64 |
+
// Set the correct.
|
65 |
+
|
66 |
+
if ( 's' == $instance['id_type'] ) {
|
67 |
+
$search = 1;
|
68 |
+
} else {
|
69 |
+
$search = '';
|
70 |
+
}
|
71 |
+
if ( 'u' == $instance['id_type'] ) {
|
72 |
+
$user = 1;
|
73 |
+
} else {
|
74 |
+
$user = '';
|
75 |
+
}
|
76 |
+
|
77 |
+
// Built the parameter array.
|
78 |
+
|
79 |
+
$array = array(
|
80 |
+
'id' => $instance['id'],
|
81 |
+
'start' => $instance['start'],
|
82 |
+
'stop' => $instance['start'],
|
83 |
+
'profile' => $instance['profile'],
|
84 |
+
'list_style' => $instance['list'],
|
85 |
+
'search' => $search,
|
86 |
+
'user' => $user,
|
87 |
+
);
|
88 |
+
|
89 |
+
// Generate the video and output it.
|
90 |
+
|
91 |
+
echo apply_filters( 'a3_lazy_load_html', ye_generate_youtube_code( $array ) );
|
92 |
+
|
93 |
+
// Output the trailer.
|
94 |
+
|
95 |
+
echo $after_widget;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Widget update/save function
|
100 |
+
*
|
101 |
+
* Update and save widget
|
102 |
+
*
|
103 |
+
* @param string $new_instance New instance.
|
104 |
+
* @param string $old_instance Old instance.
|
105 |
+
* @return string Instance.
|
106 |
+
*/
|
107 |
+
function update( $new_instance, $old_instance ) {
|
108 |
+
|
109 |
+
$instance = $old_instance;
|
110 |
+
$instance['titles'] = wp_strip_all_tags( $new_instance['titles'] );
|
111 |
+
$instance['id'] = $new_instance['id'];
|
112 |
+
$instance['profile'] = $new_instance['profile'];
|
113 |
+
$instance['start'] = $new_instance['start'];
|
114 |
+
$instance['list'] = $new_instance['list'];
|
115 |
+
$instance['stop'] = $new_instance['stop'];
|
116 |
+
$instance['id_type'] = $new_instance['id_type'];
|
117 |
+
|
118 |
+
return $instance;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Widget Admin control form
|
123 |
+
*
|
124 |
+
* Define admin file
|
125 |
+
*
|
126 |
+
* @uses ye_get_general_defaults Fetch general options.
|
127 |
+
*
|
128 |
+
* @param string $instance Instance.
|
129 |
+
*/
|
130 |
+
function form( $instance ) {
|
131 |
+
|
132 |
+
// Set default options.
|
133 |
+
|
134 |
+
$default = array(
|
135 |
+
'titles' => 'YouTube',
|
136 |
+
'id' => '',
|
137 |
+
'profile' => '',
|
138 |
+
'start' => '',
|
139 |
+
'list' => '',
|
140 |
+
'stop' => '',
|
141 |
+
'id_type' => 'v',
|
142 |
+
);
|
143 |
+
$instance = wp_parse_args( (array) $instance, $default );
|
144 |
+
$general = ye_get_general_defaults();
|
145 |
+
|
146 |
+
// Widget Title field.
|
147 |
+
|
148 |
+
$field_id = $this->get_field_id( 'titles' );
|
149 |
+
$field_name = $this->get_field_name( 'titles' );
|
150 |
+
echo "\r\n" . '<p><label for="' . $field_id . '">' . __( 'Widget Title', 'youtube-embed' ) . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr( $instance['titles'] ) . '" /></p>';
|
151 |
+
|
152 |
+
// Video ID field.
|
153 |
+
|
154 |
+
$field_id = $this->get_field_id( 'id' );
|
155 |
+
$field_name = $this->get_field_name( 'id' );
|
156 |
+
echo "\r\n" . '<p><label for="' . $field_id . '">' . __( 'Video ID', 'youtube-embed' ) . ': </label><input type="text" class="widefat" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr( $instance['id'] ) . '" /></p>';
|
157 |
+
|
158 |
+
// ID Type.
|
159 |
+
|
160 |
+
echo "<table>\n";
|
161 |
+
|
162 |
+
$field_id = $this->get_field_id( 'id_type' );
|
163 |
+
$field_name = $this->get_field_name( 'id_type' );
|
164 |
+
echo "\r\n" . '<tr><td width="100%">' . __( 'ID Type', 'youtube-embed' ) . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value="v"';
|
165 |
+
if ( 'v' == esc_attr( $instance['id_type'] ) ) {
|
166 |
+
echo " selected='selected'";
|
167 |
+
}
|
168 |
+
echo '>' . __( 'Video or Playlist', 'youtube-embed' ) . '</option><option value="s"';
|
169 |
+
if ( 's' == esc_attr( $instance['id_type'] ) ) {
|
170 |
+
echo " selected='selected'";
|
171 |
+
}
|
172 |
+
echo '>' . __( 'Search', 'youtube-embed' ) . '</option><option value="u"';
|
173 |
+
if ( 'u' == esc_attr( $instance['id_type'] ) ) {
|
174 |
+
echo " selected='selected'";
|
175 |
+
}
|
176 |
+
echo '>' . __( 'User', 'youtube-embed' ) . '</option></select></td></tr>';
|
177 |
+
|
178 |
+
echo "</table>\n";
|
179 |
+
|
180 |
+
// Profile field.
|
181 |
+
|
182 |
+
$field_id = $this->get_field_id( 'profile' );
|
183 |
+
$field_name = $this->get_field_name( 'profile' );
|
184 |
+
echo "\r\n" . '<p><label for="' . $field_id . '">' . __( 'Profile', 'youtube-embed' ) . ': </label><select name="' . $field_name . '" class="widefat" id="' . $field_id . '">';
|
185 |
+
ye_generate_profile_list( esc_attr( $instance['profile'] ), $general['profile_no'] );
|
186 |
+
echo '</select></p>';
|
187 |
+
|
188 |
+
echo "<table>\n";
|
189 |
+
|
190 |
+
// Start field.
|
191 |
+
|
192 |
+
$field_id = $this->get_field_id( 'start' );
|
193 |
+
$field_name = $this->get_field_name( 'start' );
|
194 |
+
echo "\r\n" . '<tr><td width="100%">' . __( 'Start (seconds)', 'youtube-embed' ) . '</td><td><input type="text" size="3" maxlength="3" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr( $instance['start'] ) . '" /></td></tr>';
|
195 |
+
|
196 |
+
// Stop field.
|
197 |
+
|
198 |
+
$field_id = $this->get_field_id( 'stop' );
|
199 |
+
$field_name = $this->get_field_name( 'stop' );
|
200 |
+
echo "\r\n" . '<tr><td width="100%">' . __( 'Stop (seconds)', 'youtube-embed' ) . '</td><td><input type="text" size="3" maxlength="3" id="' . $field_id . '" name="' . $field_name . '" value="' . esc_attr( $instance['stop'] ) . '" /></td></tr>';
|
201 |
+
|
202 |
+
echo "</table><table>\n";
|
203 |
+
|
204 |
+
// List field.
|
205 |
+
|
206 |
+
$field_id = $this->get_field_id( 'list' );
|
207 |
+
$field_name = $this->get_field_name( 'list' );
|
208 |
+
echo "\r\n" . '<tr><td width="100%">' . __( 'List Playback', 'youtube-embed' ) . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value=""';
|
209 |
+
if ( '' == esc_attr( $instance['list'] ) ) {
|
210 |
+
echo " selected='selected'";
|
211 |
+
}
|
212 |
+
echo '>' . __( 'Profile default', 'youtube-embed' ) . '</option><option value="order"';
|
213 |
+
if ( 'order' == esc_attr( $instance['list'] ) ) {
|
214 |
+
echo " selected='selected'";
|
215 |
+
}
|
216 |
+
echo '>' . __( 'Play each video in order', 'youtube-embed' ) . '</option><option value="random"';
|
217 |
+
if ( 'random' == esc_attr( $instance['list'] ) ) {
|
218 |
+
echo " selected='selected'";
|
219 |
+
}
|
220 |
+
echo '>' . __( 'Play videos randomly', 'youtube-embed' ) . '</option><option value="single"';
|
221 |
+
if ( 'single' == esc_attr( $instance['list'] ) ) {
|
222 |
+
echo " selected='selected'";
|
223 |
+
}
|
224 |
+
echo '>' . __( 'Play one random video', 'youtube-embed' ) . '</option></select></td></tr>';
|
225 |
+
|
226 |
+
echo "</table>\n";
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Register Widget
|
232 |
+
*
|
233 |
+
* Register widget when loading the WP core
|
234 |
+
*/
|
235 |
+
function youtube_embed_register_widgets() {
|
236 |
+
register_widget( 'YouTubeEmbedWidget' );
|
237 |
+
}
|
238 |
+
|
239 |
+
add_action( 'widgets_init', 'youtube_embed_register_widgets' );
|
includes/options-general.php
CHANGED
@@ -1,323 +1,520 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* General
|
4 |
-
*
|
5 |
-
* Screen for generic options
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
?>
|
11 |
-
<div class="wrap">
|
12 |
-
<h1><?php _e( 'YouTube Embed Settings', 'youtube-embed' ); ?></h1>
|
13 |
-
|
14 |
-
<?php
|
15 |
-
|
16 |
-
// If options have been updated on screen, update the database
|
17 |
-
|
18 |
-
if ( ( !empty( $_POST ) ) && ( check_admin_referer( 'youtube-embed-general', 'youtube_embed_general_nonce' ) ) ) {
|
19 |
-
|
20 |
-
// If the number of profiles or lists have changed check that they all have
|
21 |
-
// correct values assigned (if at all)
|
22 |
-
|
23 |
-
$options = ye_get_general_defaults();
|
24 |
-
if ( isset( $options[
|
25 |
-
ye_set_list( sanitize_text_field( $_POST[
|
26 |
-
}
|
27 |
-
if ( isset( $options[
|
28 |
-
ye_set_profile( sanitize_text_field( $_POST[
|
29 |
-
}
|
30 |
-
|
31 |
-
// Update options
|
32 |
-
|
33 |
-
if ( isset( $_POST[
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
$options[
|
40 |
-
$options[
|
41 |
-
$options[
|
42 |
-
$options[
|
43 |
-
$options[
|
44 |
-
$options[
|
45 |
-
|
46 |
-
$options[
|
47 |
-
|
48 |
-
$options[
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
if (
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
if (
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
if ( $
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
$
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
$
|
74 |
-
|
75 |
-
|
76 |
-
$options[
|
77 |
-
|
78 |
-
$
|
79 |
-
}
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
$
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
<tr>
|
152 |
-
<th scope="row"><?php _e( '
|
153 |
-
<td><label for="
|
154 |
-
<
|
155 |
-
|
156 |
-
|
157 |
-
</
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
<
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
</
|
217 |
-
<
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
<
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
</
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
<
|
260 |
-
<
|
261 |
-
<
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
<option value="
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
<
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
<
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
<
|
299 |
-
<
|
300 |
-
|
301 |
-
<p class="description"><?php _e( '
|
302 |
-
</tr>
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
<
|
309 |
-
<
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
<?php
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* General options page
|
4 |
+
*
|
5 |
+
* Screen for generic options
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
?>
|
11 |
+
<div class="wrap">
|
12 |
+
<h1><?php _e( 'YouTube Embed Settings', 'youtube-embed' ); ?></h1>
|
13 |
+
|
14 |
+
<?php
|
15 |
+
|
16 |
+
// If options have been updated on screen, update the database.
|
17 |
+
|
18 |
+
if ( ( ! empty( $_POST ) ) && ( check_admin_referer( 'youtube-embed-general', 'youtube_embed_general_nonce' ) ) ) {
|
19 |
+
|
20 |
+
// If the number of profiles or lists have changed check that they all have
|
21 |
+
// correct values assigned (if at all).
|
22 |
+
|
23 |
+
$options = ye_get_general_defaults();
|
24 |
+
if ( isset( $options['list_no'] ) && isset( $_POST['youtube_embed_list_no'] ) && $options['list_no'] != $_POST['youtube_embed_list_no'] ) {
|
25 |
+
ye_set_list( sanitize_text_field( $_POST['youtube_embed_list_no'] ) );
|
26 |
+
}
|
27 |
+
if ( isset( $options['profile_no'] ) && isset( $_POST['youtube_embed_list_no'] ) && $options['profile_no'] != $_POST['youtube_embed_list_no'] ) {
|
28 |
+
ye_set_profile( sanitize_text_field( $_POST['youtube_embed_profile_no'] ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
// Update options.
|
32 |
+
|
33 |
+
if ( isset( $_POST['youtube_embed_admin_bar'] ) ) {
|
34 |
+
$options['admin_bar'] = sanitize_text_field( $_POST['youtube_embed_admin_bar'] );
|
35 |
+
} else {
|
36 |
+
$options['admin_bar'] = '';
|
37 |
+
}
|
38 |
+
|
39 |
+
$options['profile_no'] = sanitize_text_field( $_POST['youtube_embed_profile_no'] );
|
40 |
+
$options['list_no'] = sanitize_text_field( $_POST['youtube_embed_list_no'] );
|
41 |
+
$options['alt_profile'] = sanitize_text_field( $_POST['youtube_embed_alt_profile'] );
|
42 |
+
$options['feed'] = sanitize_text_field( $_POST['youtube_embed_feed'] );
|
43 |
+
$options['thumbnail'] = sanitize_text_field( $_POST['youtube_embed_thumbnail'] );
|
44 |
+
$options['privacy'] = sanitize_text_field( $_POST['youtube_embed_privacy'] );
|
45 |
+
$options['menu_access'] = sanitize_text_field( $_POST['youtube_embed_menu_access'] );
|
46 |
+
$options['script'] = sanitize_text_field( $_POST['youtube_embed_script'] );
|
47 |
+
$options['standard_video'] = sanitize_text_field( $_POST['youtube_embed_video'] );
|
48 |
+
$options['playlist_video'] = sanitize_text_field( $_POST['youtube_embed_playlist'] );
|
49 |
+
$options['lazyload'] = sanitize_text_field( $_POST['youtube_embed_lazyload'] );
|
50 |
+
|
51 |
+
$options['api_cache'] = sanitize_text_field( $_POST['youtube_embed_api_cache'] );
|
52 |
+
if ( ! is_numeric( $options['api_cache'] ) ) {
|
53 |
+
$options['api_cache'] = 0;
|
54 |
+
}
|
55 |
+
$options['video_cache'] = sanitize_text_field( $_POST['youtube_embed_video_cache'] );
|
56 |
+
if ( ! is_numeric( $options['video_cache'] ) ) {
|
57 |
+
$options['video_cache'] = 0;
|
58 |
+
}
|
59 |
+
|
60 |
+
if ( isset( $_POST['youtube_embed_metadata'] ) ) {
|
61 |
+
$options['metadata'] = sanitize_text_field( $_POST['youtube_embed_metadata'] );
|
62 |
+
} else {
|
63 |
+
$options['metadata'] = '';
|
64 |
+
}
|
65 |
+
if ( isset( $_POST['youtube_embed_frameborder'] ) ) {
|
66 |
+
$options['frameborder'] = sanitize_text_field( $_POST['youtube_embed_frameborder'] );
|
67 |
+
} else {
|
68 |
+
$options['frameborder'] = '';
|
69 |
+
}
|
70 |
+
if ( isset( $_POST['youtube_embed_widgets'] ) ) {
|
71 |
+
$options['widgets'] = sanitize_text_field( $_POST['youtube_embed_widgets'] );
|
72 |
+
} else {
|
73 |
+
$options['widgets'] = '';
|
74 |
+
}
|
75 |
+
if ( isset( $_POST['youtube_embed_debug'] ) ) {
|
76 |
+
$options['debug'] = sanitize_text_field( $_POST['youtube_embed_debug'] );
|
77 |
+
} else {
|
78 |
+
$options['debug'] = '';
|
79 |
+
}
|
80 |
+
if ( isset( $_POST['youtube_embed_prompt'] ) ) {
|
81 |
+
$options['prompt'] = sanitize_text_field( $_POST['youtube_embed_prompt'] );
|
82 |
+
} else {
|
83 |
+
$options['prompt'] = '';
|
84 |
+
}
|
85 |
+
if ( isset( $_POST['youtube_embed_list'] ) ) {
|
86 |
+
$options['force_list_type'] = sanitize_text_field( $_POST['youtube_embed_list'] );
|
87 |
+
} else {
|
88 |
+
$options['force_list_type'] = '';
|
89 |
+
}
|
90 |
+
if ( isset( $_POST['youtube_embed_lazyload'] ) ) {
|
91 |
+
$options['lazyload'] = sanitize_text_field( $_POST['youtube_embed_lazyload'] );
|
92 |
+
} else {
|
93 |
+
$options['lazyload'] = '';
|
94 |
+
}
|
95 |
+
|
96 |
+
// If the number of profiles or lists is less than zero, put it to 0.
|
97 |
+
|
98 |
+
if ( $options['profile_no'] < 0 ) {
|
99 |
+
$options['profile_no'] = 0;
|
100 |
+
}
|
101 |
+
if ( $options['list_no'] < 0 ) {
|
102 |
+
$options['list_no'] = 0;
|
103 |
+
}
|
104 |
+
|
105 |
+
// Test the API key.
|
106 |
+
|
107 |
+
$api_key = sanitize_text_field( $_POST['youtube_embed_api'] );
|
108 |
+
$api_valid = true;
|
109 |
+
if ( '' != $api_key ) {
|
110 |
+
$api_test = ye_get_api_data( 'jNQXAC9IVRw', $api_key, true );
|
111 |
+
if ( ! $api_test['api'] ) {
|
112 |
+
$api_valid = false;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( ! $api_valid ) {
|
117 |
+
$update_message = __( 'API key is invalid or API is unavailable.', 'youtube-embed' );
|
118 |
+
$update_class = 'error';
|
119 |
+
} else {
|
120 |
+
$options['api'] = $api_key;
|
121 |
+
$update_message = __( 'Settings Saved.', 'youtube-embed' );
|
122 |
+
$update_class = 'updated';
|
123 |
+
}
|
124 |
+
|
125 |
+
// Update the options.
|
126 |
+
|
127 |
+
update_option( 'youtube_embed_general', $options );
|
128 |
+
|
129 |
+
// Update the alternative shortcodes.
|
130 |
+
|
131 |
+
$shortcode = sanitize_text_field( $_POST['youtube_embed_shortcode'] );
|
132 |
+
$shortcode = trim( $shortcode, '[]' );
|
133 |
+
|
134 |
+
update_option( 'youtube_embed_shortcode', $shortcode );
|
135 |
+
|
136 |
+
echo '<div class="' . $update_class . ' fade"><p><strong>' . $update_message . "</strong></p></div>\n";
|
137 |
+
}
|
138 |
+
|
139 |
+
// Get options.
|
140 |
+
|
141 |
+
$options = ye_get_general_defaults();
|
142 |
+
$shortcode = ye_get_shortcode();
|
143 |
+
?>
|
144 |
+
|
145 |
+
<p><?php _e( 'These are the general settings for YouTube Embed. Please select <a href="admin.php?page=ye-profile-options">Profiles</a> for default embedding settings.', 'youtube-embed' ); ?></p>
|
146 |
+
|
147 |
+
<form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ye-general-options'; ?>">
|
148 |
+
|
149 |
+
<table class="form-table">
|
150 |
+
|
151 |
+
<tr>
|
152 |
+
<th scope="row"><?php _e( 'API Key', 'youtube-embed' ); ?></th>
|
153 |
+
<td><label for="youtube_embed_api"><input type="text" size="50" name="youtube_embed_api" value="<?php echo esc_attr( $options['api'] ); ?>"/></label>
|
154 |
+
<p class="description"><?php _e( 'Please see the instructions for details on creating your own API key.', 'youtube-embed' ); ?></p></td>
|
155 |
+
</tr>
|
156 |
+
|
157 |
+
</table><hr><h3 class="title"><?php _e( 'Embedding', 'youtube-embed' ); ?></h3><table class="form-table">
|
158 |
+
|
159 |
+
<!-- Add Metadata -->
|
160 |
+
|
161 |
+
<tr>
|
162 |
+
<th scope="row"><label for="youtube_embed_metadata"><?php _e( 'Add Metadata', 'youtube-embed' ); ?></label></th>
|
163 |
+
<td><input type="checkbox" name="youtube_embed_metadata" value="1" <?php checked( $options['metadata'], '1' ); ?>/>
|
164 |
+
<?php _e( 'Allow rich metadata to be added to code', 'youtube-embed' ); ?></td>
|
165 |
+
</tr>
|
166 |
+
|
167 |
+
<!-- Feed -->
|
168 |
+
|
169 |
+
<tr>
|
170 |
+
<th scope="row"><?php _e( 'Feed', 'youtube-embed' ); ?></th>
|
171 |
+
<td><label for="youtube_embed_feed"><select name="youtube_embed_feed">
|
172 |
+
<option value="t"
|
173 |
+
<?php
|
174 |
+
if ( 't' == $options['feed'] ) {
|
175 |
+
echo " selected='selected'";
|
176 |
+
}
|
177 |
+
?>
|
178 |
+
>
|
179 |
+
<?php _e( 'Text link', 'youtube-embed' ); ?>
|
180 |
+
</option>
|
181 |
+
<option value="v"
|
182 |
+
<?php
|
183 |
+
if ( 'v' == $options['feed'] ) {
|
184 |
+
echo " selected='selected'";
|
185 |
+
}
|
186 |
+
?>
|
187 |
+
>
|
188 |
+
<?php _e( 'Thumbnail', 'youtube-embed' ); ?>
|
189 |
+
</option>
|
190 |
+
<option value="b"
|
191 |
+
<?php
|
192 |
+
if ( 'b' == $options['feed'] ) {
|
193 |
+
echo " selected='selected'";
|
194 |
+
}
|
195 |
+
?>
|
196 |
+
>
|
197 |
+
<?php _e( 'Thumbnail & Text Link', 'youtube-embed' ); ?>
|
198 |
+
</option>
|
199 |
+
</select></label>
|
200 |
+
<p class="description"><?php _e( 'Videos cannot be embedded in feeds. Select how you wish them to be shown instead.', 'youtube-embed' ); ?></p></td>
|
201 |
+
</tr>
|
202 |
+
|
203 |
+
<!-- Feed Thumbnail -->
|
204 |
+
|
205 |
+
<tr>
|
206 |
+
<th scope="row"> <?php _e( 'Thumbnail to use', 'youtube-embed' ); ?></th>
|
207 |
+
<td><label for="youtube_embed_thumbnail"><select name="youtube_embed_thumbnail">
|
208 |
+
<option value="default"
|
209 |
+
<?php
|
210 |
+
if ( 'default' == $options['thumbnail'] ) {
|
211 |
+
echo " selected='selected'";
|
212 |
+
}
|
213 |
+
?>
|
214 |
+
>
|
215 |
+
<?php _e( 'Default', 'youtube-embed' ); ?>
|
216 |
+
</option>
|
217 |
+
<option value="hqdefault"
|
218 |
+
<?php
|
219 |
+
if ( 'hqdefault' == $options['thumbnail'] ) {
|
220 |
+
echo " selected='selected'";
|
221 |
+
}
|
222 |
+
?>
|
223 |
+
>
|
224 |
+
<?php _e( 'Default (HQ)', 'youtube-embed' ); ?>
|
225 |
+
</option>
|
226 |
+
<option value="1"
|
227 |
+
<?php
|
228 |
+
if ( '1' == $options['thumbnail'] ) {
|
229 |
+
echo " selected='selected'";
|
230 |
+
}
|
231 |
+
?>
|
232 |
+
>
|
233 |
+
<?php _e( 'Start', 'youtube-embed' ); ?>
|
234 |
+
</option>
|
235 |
+
<option value="2"
|
236 |
+
<?php
|
237 |
+
if ( '2' == $options['thumbnail'] ) {
|
238 |
+
echo " selected='selected'";
|
239 |
+
}
|
240 |
+
?>
|
241 |
+
>
|
242 |
+
<?php _e( 'Middle', 'youtube-embed' ); ?>
|
243 |
+
</option>
|
244 |
+
<option value="3"
|
245 |
+
<?php
|
246 |
+
if ( '3' == $options['thumbnail'] ) {
|
247 |
+
echo " selected='selected'";
|
248 |
+
}
|
249 |
+
?>
|
250 |
+
>
|
251 |
+
<?php _e( 'End', 'youtube-embed' ); ?>
|
252 |
+
</option>
|
253 |
+
</select></label>
|
254 |
+
<p class="description"><?php _e( 'Choose which thumbnail to use.', 'youtube-embed' ); ?></p></td>
|
255 |
+
</tr>
|
256 |
+
|
257 |
+
<!-- Content Resizing Scripts -->
|
258 |
+
|
259 |
+
<tr>
|
260 |
+
<th scope="row"><?php _e( 'Content Resizing Script', 'youtube-embed' ); ?></th>
|
261 |
+
<td><label for="youtube_embed_script"><select name="youtube_embed_script">
|
262 |
+
<option value=""
|
263 |
+
<?php
|
264 |
+
if ( '' == $options['script'] ) {
|
265 |
+
echo " selected='selected'";
|
266 |
+
}
|
267 |
+
?>
|
268 |
+
>
|
269 |
+
<?php _e( 'None', 'youtube-embed' ); ?>
|
270 |
+
</option>
|
271 |
+
<option value="f"
|
272 |
+
<?php
|
273 |
+
if ( 'f' == $options['script'] ) {
|
274 |
+
echo " selected='selected'";
|
275 |
+
}
|
276 |
+
?>
|
277 |
+
>
|
278 |
+
<?php _e( 'FitVids.js', 'youtube-embed' ); ?>
|
279 |
+
</option>
|
280 |
+
<option value="i"
|
281 |
+
<?php
|
282 |
+
if ( 'i' == $options['script'] ) {
|
283 |
+
echo " selected='selected'";
|
284 |
+
}
|
285 |
+
?>
|
286 |
+
>
|
287 |
+
<?php _e( 'iFrame Resizer', 'youtube-embed' ); ?>
|
288 |
+
</option>
|
289 |
+
</select></label>
|
290 |
+
<p class="description"><?php _e( 'Use a third party content resizing script?', 'youtube-embed' ); ?></p></td>
|
291 |
+
</tr>
|
292 |
+
|
293 |
+
</table><hr><h3 class="title"><?php _e( 'Shortcodes', 'youtube-embed' ); ?></h3><table class="form-table">
|
294 |
+
|
295 |
+
<!-- Shortcodes in Widgets -->
|
296 |
+
|
297 |
+
<tr>
|
298 |
+
<th scope="row"><?php _e( 'Allow shortcodes in widgets', 'youtube-embed' ); ?></th>
|
299 |
+
<td><label for="youtube_embed_widgets"><input type="checkbox" name="youtube_embed_widgets" value="1" <?php checked( $options['widgets'], '1' ); ?>/>
|
300 |
+
<?php _e( 'Allow shortcodes to be used in widgets', 'youtube-embed' ); ?></label>
|
301 |
+
<p class="description"><?php _e( 'This will apply to <strong>all</strong> widgets.', 'youtube-embed' ); ?></p></td>
|
302 |
+
</tr>
|
303 |
+
|
304 |
+
<!-- Alternative Shortcode -->
|
305 |
+
|
306 |
+
<tr>
|
307 |
+
<th scope="row"><?php _e( 'Alternative Shortcode', 'youtube-embed' ); ?></th>
|
308 |
+
<td><label for="youtube_embed_shortcode"><input type="text" size="30" name="youtube_embed_shortcode" value="<?php echo esc_attr( $shortcode ); ?>"/></label>
|
309 |
+
<p class="description"><?php _e( 'An alternative shortcode to use.', 'youtube-embed' ); ?></p></td>
|
310 |
+
</tr>
|
311 |
+
|
312 |
+
<!-- Alternative Shortcode Profile -->
|
313 |
+
|
314 |
+
<tr>
|
315 |
+
<th scope="row"> <?php _e( 'Profile to use', 'youtube-embed' ); ?></th>
|
316 |
+
<td><label for="youtube_embed_alt_profile"><select name="youtube_embed_alt_profile">
|
317 |
+
<?php ye_generate_profile_list( $options['alt_profile'], $options['profile_no'] ); ?>
|
318 |
+
</select></label></td>
|
319 |
+
</tr>
|
320 |
+
|
321 |
+
<!-- Shortcode Re-Use Prompt -->
|
322 |
+
|
323 |
+
<tr>
|
324 |
+
<th scope="row"><?php _e( 'Show Shortcode Re-use Prompt', 'youtube-embed' ); ?></th>
|
325 |
+
<td><label for="youtube_embed_prompt"><input type="checkbox" name="youtube_embed_prompt" value="1" <?php checked( $options['prompt'], '1' ); ?>/>
|
326 |
+
<?php _e( 'Show a prompt if the main shortcode is being re-used by another plugin', 'youtube-embed' ); ?></label></td>
|
327 |
+
</tr>
|
328 |
+
|
329 |
+
</table><hr><h3 class="title"><?php _e( 'Administration Options', 'youtube-embed' ); ?></h3><table class="form-table">
|
330 |
+
|
331 |
+
<!-- Admin Bar -->
|
332 |
+
|
333 |
+
<tr>
|
334 |
+
<th scope="row"><?php _e( 'Show in Admin Bar', 'youtube-embed' ); ?></th>
|
335 |
+
<td><label for="youtube_embed_admin_bar"><input type="checkbox" name="youtube_embed_admin_bar" value="1" <?php checked( $options['admin_bar'], '1' ); ?>/>
|
336 |
+
<?php _e( 'Add link to options screen to Admin Bar', 'youtube-embed' ); ?></label></td>
|
337 |
+
</tr>
|
338 |
+
|
339 |
+
<!-- Menu Screen Access -->
|
340 |
+
|
341 |
+
<tr>
|
342 |
+
<th scope="row"><?php _e( 'Menu Screen Access', 'youtube-embed' ); ?></th>
|
343 |
+
<td><label for="youtube_embed_menu_access"><select name="youtube_embed_menu_access">
|
344 |
+
<option value="list_users"
|
345 |
+
<?php
|
346 |
+
if ( 'list_users' == $options['menu_access'] ) {
|
347 |
+
echo " selected='selected'";
|
348 |
+
}
|
349 |
+
?>
|
350 |
+
>
|
351 |
+
<?php _e( 'Administrator', 'youtube-embed' ); ?>
|
352 |
+
</option>
|
353 |
+
<option value="edit_pages"
|
354 |
+
<?php
|
355 |
+
if ( 'edit_pages' == $options['menu_access'] ) {
|
356 |
+
echo " selected='selected'";
|
357 |
+
}
|
358 |
+
?>
|
359 |
+
>
|
360 |
+
<?php _e( 'Editor', 'youtube-embed' ); ?>
|
361 |
+
</option>
|
362 |
+
<option value="publish_posts"
|
363 |
+
<?php
|
364 |
+
if ( 'edit_pages' == $options['menu_access'] ) {
|
365 |
+
echo " selected='selected'";
|
366 |
+
}
|
367 |
+
?>
|
368 |
+
>
|
369 |
+
<?php _e( 'Author', 'youtube-embed' ); ?>
|
370 |
+
</option>
|
371 |
+
<option value="edit_posts"
|
372 |
+
<?php
|
373 |
+
if ( 'edit_posts' == $options['menu_access'] ) {
|
374 |
+
echo " selected='selected'";
|
375 |
+
}
|
376 |
+
?>
|
377 |
+
>
|
378 |
+
<?php _e( 'Contributor', 'youtube-embed' ); ?>
|
379 |
+
</option>
|
380 |
+
</select></label>
|
381 |
+
<p class="description"><?php _e( 'Specify the user access required for the menu screens.', 'youtube-embed' ); ?></p></td>
|
382 |
+
</tr>
|
383 |
+
|
384 |
+
</table><hr><h3 class="title"><?php _e( 'Profile & List Sizes', 'youtube-embed' ); ?></h3><table class="form-table">
|
385 |
+
|
386 |
+
<!-- Number of Profiles -->
|
387 |
+
|
388 |
+
<tr>
|
389 |
+
<th scope="row"><?php _e( 'Number of Profiles', 'youtube-embed' ); ?></th>
|
390 |
+
<td><label for="youtube_embed_profile_no"><input type="text" size="2" maxlength="2" name="youtube_embed_profile_no" value="<?php echo esc_attr( $options['profile_no'] ); ?>"/> <?php _e( 'Maximum number of profiles.', 'youtube-embed' ); ?></label></td>
|
391 |
+
</tr>
|
392 |
+
|
393 |
+
<!-- Number of Lists -->
|
394 |
+
|
395 |
+
<tr>
|
396 |
+
<th scope="row"><?php _e( 'Number of Lists', 'youtube-embed' ); ?></th>
|
397 |
+
<td><label for="youtube_embed_list_no"><input type="text" size="2" maxlength="2" name="youtube_embed_list_no" value="<?php echo esc_attr( $options['list_no'] ); ?>"/> <?php _e( 'Maximum number of lists.', 'youtube-embed' ); ?></label></td>
|
398 |
+
</tr>
|
399 |
+
|
400 |
+
</table><hr><h3 class="title"><?php _e( 'Performance', 'youtube-embed' ); ?></h3><table class="form-table">
|
401 |
+
|
402 |
+
|
403 |
+
<!-- Force list specification -->
|
404 |
+
|
405 |
+
<tr>
|
406 |
+
<th scope="row"><?php _e( 'Force list specification', 'youtube-embed' ); ?></th>
|
407 |
+
<td><label for="youtube_embed_list"><input type="checkbox" name="youtube_embed_list" value="1" <?php checked( $options['force_list_type'], '1' ); ?>/>
|
408 |
+
<?php _e( 'Force users to specify a list type', 'youtube-embed' ); ?></label>
|
409 |
+
<p class="description"><?php _e( 'By switching this on, a list type must be specified for a list to be valid. This improves performance as use of a list doesn\'t then need to be verified.', 'youtube-embed' ); ?></p></td>
|
410 |
+
</tr>
|
411 |
+
|
412 |
+
<!-- Video cache -->
|
413 |
+
|
414 |
+
<tr>
|
415 |
+
<th scope="row"><?php _e( 'Video Cache', 'youtube-embed' ); ?></th>
|
416 |
+
<td><label for="youtube_embed_video_cache"><input type="text" size="2" maxlength="2" name="youtube_embed_video_cache" value="<?php echo esc_attr( $options['video_cache'] ); ?>"/> <?php _e( 'days', 'youtube-embed' ); ?></label>
|
417 |
+
<p class="description"><?php _e( 'How long to cache the video output. Set to 0 to switch off.', 'youtube-embed' ); ?></p></td>
|
418 |
+
</tr>
|
419 |
+
|
420 |
+
<!-- API cache -->
|
421 |
+
|
422 |
+
<tr>
|
423 |
+
<th scope="row"><?php _e( 'API Cache', 'youtube-embed' ); ?></th>
|
424 |
+
<td><label for="youtube_embed_api_cache"><input type="text" size="2" maxlength="2" name="youtube_embed_api_cache" value="<?php echo esc_attr( $options['api_cache'] ); ?>"/> <?php _e( 'hours', 'youtube-embed' ); ?></label>
|
425 |
+
<p class="description"><?php _e( 'How long to cache the API data. Set to 0 to switch off.', 'youtube-embed' ); ?></p></td>
|
426 |
+
</tr>
|
427 |
+
|
428 |
+
<!-- Lazy-loading -->
|
429 |
+
|
430 |
+
<tr>
|
431 |
+
<th scope="row"><?php _e( 'Lazy-load Video', 'youtube-embed' ); ?></th>
|
432 |
+
<td><label for="youtube_embed_lazyload"><input type="checkbox" name="youtube_embed_lazyload" value="1" <?php checked( $options['lazyload'], '1' ); ?>/>
|
433 |
+
<?php _e( 'Use native lazy-loading for video', 'youtube-embed' ); ?></label>
|
434 |
+
<p class="description"><?php _e( 'Native lazy-loading is only supported by some browsers.', 'youtube-embed' ); ?></p></td>
|
435 |
+
</tr>
|
436 |
+
|
437 |
+
</table><hr><h3 class="title"><?php _e( 'Security', 'youtube-embed' ); ?></h3><table class="form-table">
|
438 |
+
|
439 |
+
<!-- Privacy-Enhanced Mode -->
|
440 |
+
|
441 |
+
<tr>
|
442 |
+
<th scope="row"><?php _e( 'Privacy-Enhanced Mode', 'youtube-embed' ); ?></th>
|
443 |
+
<td><label for="youtube_embed_menu_access"><select name="youtube_embed_privacy">
|
444 |
+
<option value="0"
|
445 |
+
<?php
|
446 |
+
if ( '0' == $options['privacy'] ) {
|
447 |
+
echo " selected='selected'";
|
448 |
+
}
|
449 |
+
?>
|
450 |
+
>
|
451 |
+
<?php _e( 'Cookies should always be stored', 'youtube-embed' ); ?>
|
452 |
+
</option>
|
453 |
+
<option value="1"
|
454 |
+
<?php
|
455 |
+
if ( '1' == $options['privacy'] ) {
|
456 |
+
echo " selected='selected'";
|
457 |
+
}
|
458 |
+
?>
|
459 |
+
>
|
460 |
+
<?php _e( 'Cookies should never be stored', 'youtube-embed' ); ?>
|
461 |
+
</option>
|
462 |
+
<option value="2"
|
463 |
+
<?php
|
464 |
+
if ( '2' == $options['privacy'] ) {
|
465 |
+
echo " selected='selected'";
|
466 |
+
}
|
467 |
+
?>
|
468 |
+
>
|
469 |
+
<?php _e( "Cookies should be stored based on user's Do Not Track setting", 'youtube-embed' ); ?>
|
470 |
+
</option>
|
471 |
+
</select></label>
|
472 |
+
<p class="description"><?php _e( 'Read more about <a href="http://donottrack.us/">Do Not Track</a>.', 'youtube-embed' ); ?></p></td>
|
473 |
+
</tr>
|
474 |
+
|
475 |
+
<!-- Show debug output -->
|
476 |
+
|
477 |
+
<tr>
|
478 |
+
<th scope="row"><?php _e( 'Show debug output', 'youtube-embed' ); ?></th>
|
479 |
+
<td><label for="youtube_embed_debug"><input type="checkbox" name="youtube_embed_debug" value="1" <?php checked( $options['debug'], '1' ); ?>/>
|
480 |
+
<?php _e( 'Show debug output as HTML comments', 'youtube-embed' ); ?></label></td>
|
481 |
+
</tr>
|
482 |
+
|
483 |
+
</table><hr><h3 class="title"><?php _e( 'Profile Demo Videos', 'youtube-embed' ); ?></h3><table class="form-table">
|
484 |
+
|
485 |
+
<!-- Standard Video -->
|
486 |
+
|
487 |
+
<tr>
|
488 |
+
<th scope="row"><?php _e( 'Standard Video', 'youtube-embed' ); ?></th>
|
489 |
+
<td><label for="youtube_embed_video"><input type="text" size="30" name="youtube_embed_video" value="<?php echo esc_attr( $options['standard_video'] ); ?>"/></label>
|
490 |
+
<p class="description"><?php _e( 'ID of a YouTube video.', 'youtube-embed' ); ?></p></td>
|
491 |
+
</tr>
|
492 |
+
|
493 |
+
<!-- Playlist Video -->
|
494 |
+
|
495 |
+
<tr>
|
496 |
+
<th scope="row"><?php _e( 'Playlist', 'youtube-embed' ); ?></th>
|
497 |
+
<td><label for="youtube_embed_playlist"><input type="text" size="30" name="youtube_embed_playlist" value="<?php echo esc_attr( $options['playlist_video'] ); ?>"/></label>
|
498 |
+
<p class="description"><?php _e( 'ID of a YouTube playlist.', 'youtube-embed' ); ?></p></td>
|
499 |
+
</tr>
|
500 |
+
|
501 |
+
</table><hr><h3 class="title"><?php _e( 'Miscellaneous', 'youtube-embed' ); ?></h3><table class="form-table">
|
502 |
+
|
503 |
+
<!-- Validation -->
|
504 |
+
|
505 |
+
<tr>
|
506 |
+
<th scope="row"><?php _e( 'Improve Validation', 'youtube-embed' ); ?></th>
|
507 |
+
<td><label for="youtube_embed_frameborder"><input type="checkbox" name="youtube_embed_frameborder" value="1" <?php checked( $options['frameborder'], '1' ); ?>/>
|
508 |
+
<?php _e( 'Improve the validity of the generated markup', 'youtube-embed' ); ?></label>
|
509 |
+
<p class="description"><?php _e( 'Will extend the length of the URL, limiting the number of videos in a manual playlist. Switch off metadata for even better validation results.', 'youtube-embed' ); ?></p></td>
|
510 |
+
</tr>
|
511 |
+
|
512 |
+
</table>
|
513 |
+
|
514 |
+
<?php wp_nonce_field( 'youtube-embed-general', 'youtube_embed_general_nonce', true, true ); ?>
|
515 |
+
|
516 |
+
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
|
517 |
+
|
518 |
+
</form>
|
519 |
+
|
520 |
+
</div>
|
includes/options-lists.php
CHANGED
@@ -1,236 +1,258 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Lists Options Page
|
4 |
-
*
|
5 |
-
* Screen for specifying different lists and the video IDs within them
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
$
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
$
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
$
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
//
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
} else {
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Lists Options Page
|
4 |
+
*
|
5 |
+
* Screen for specifying different lists and the video IDs within them
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
// Set current list number.
|
11 |
+
|
12 |
+
if ( isset( $_POST['youtube_embed_list_no'] ) ) {
|
13 |
+
$list_no = esc_textarea( $_POST['youtube_embed_list_no'] );
|
14 |
+
} else {
|
15 |
+
$list_no = 0;
|
16 |
+
}
|
17 |
+
if ( '' == $list_no ) {
|
18 |
+
$list_no = 1;
|
19 |
+
}
|
20 |
+
|
21 |
+
// If options have been updated on screen, update the database.
|
22 |
+
|
23 |
+
$message = '';
|
24 |
+
|
25 |
+
if ( ( ! empty( $_POST['Submit'] ) ) && ( check_admin_referer( 'youtube-embed-general', 'youtube_embed_general_nonce' ) ) ) {
|
26 |
+
|
27 |
+
$class = 'updated fade';
|
28 |
+
$message = __( 'Settings Saved.', 'youtube-embed' );
|
29 |
+
$new_id_list = '';
|
30 |
+
|
31 |
+
if ( ( '' == $_POST['youtube_embed_video_list'] ) || ( '' == $_POST['youtube_embed_name'] ) ) {
|
32 |
+
$class = 'error';
|
33 |
+
$message = __( 'All fields must be completed.', 'youtube-embed' );
|
34 |
+
} else {
|
35 |
+
$id_array = explode( "\n", esc_textarea( $_POST['youtube_embed_video_list'] ) );
|
36 |
+
$loop = 0;
|
37 |
+
$valid = true;
|
38 |
+
|
39 |
+
// Loop through the video IDs.
|
40 |
+
|
41 |
+
$video_count = count( $id_array );
|
42 |
+
while ( $loop < $video_count ) {
|
43 |
+
|
44 |
+
// Extract the ID from the provided data.
|
45 |
+
|
46 |
+
$id = trim( ye_extract_id( $id_array[ $loop ] ) );
|
47 |
+
|
48 |
+
// Now check its validity using the API data.
|
49 |
+
|
50 |
+
if ( '' != $id ) {
|
51 |
+
$data = ye_get_api_data( $id );
|
52 |
+
$valid = $data['valid'];
|
53 |
+
if ( 'v' != $data['type'] ) {
|
54 |
+
$valid = false;
|
55 |
+
}
|
56 |
+
$new_id_list .= $id . "\n";
|
57 |
+
}
|
58 |
+
$loop ++;
|
59 |
+
}
|
60 |
+
|
61 |
+
// If one or more IDs weren't valid, output an error.
|
62 |
+
|
63 |
+
if ( ! $valid ) {
|
64 |
+
$class = 'error';
|
65 |
+
$message = __( 'Errors were found with your video list. See the list below for details.', 'youtube-embed' );
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
// Update the options.
|
70 |
+
|
71 |
+
$options['list_name'] = $_POST['youtube_embed_name'];
|
72 |
+
|
73 |
+
if ( '' == $new_id_list ) {
|
74 |
+
$options['list'] = sanitize_text_field( $_POST['youtube_embed_video_list'] );
|
75 |
+
} else {
|
76 |
+
$options['list'] = substr( $new_id_list, 0, strlen( $new_id_list ) - 1 );
|
77 |
+
}
|
78 |
+
|
79 |
+
if ( 'updated' == substr( $class, 0, 7 ) ) {
|
80 |
+
update_option( 'youtube_embed_list' . $list_no, $options );
|
81 |
+
}
|
82 |
+
} else {
|
83 |
+
$class = '';
|
84 |
+
}
|
85 |
+
|
86 |
+
// Fetch options into an array.
|
87 |
+
|
88 |
+
if ( 'error' != $class ) {
|
89 |
+
$options = ye_get_list( $list_no );
|
90 |
+
}
|
91 |
+
$general = ye_get_general_defaults();
|
92 |
+
|
93 |
+
// Get number of lists in use.
|
94 |
+
|
95 |
+
$loop = 0;
|
96 |
+
$max_lists = 0;
|
97 |
+
while ( $loop <= $general['list_no'] ) {
|
98 |
+
|
99 |
+
$list = ye_get_list( $loop );
|
100 |
+
if ( ! $list['default'] ) {
|
101 |
+
$max_lists ++;
|
102 |
+
}
|
103 |
+
|
104 |
+
$loop ++;
|
105 |
+
}
|
106 |
+
|
107 |
+
// Display any screen headings.
|
108 |
+
|
109 |
+
?>
|
110 |
+
<div class="wrap">
|
111 |
+
<h1><?php _e( 'YouTube Embed Lists', 'youtube-embed' ); ?><span class="title-count"><?php echo $max_lists; ?></span></h1>
|
112 |
+
|
113 |
+
<?php
|
114 |
+
|
115 |
+
// Output any messages.
|
116 |
+
|
117 |
+
if ( '' != $message ) {
|
118 |
+
echo '<div class="' . $class . '"><p><strong>' . $message . "</strong></p></div>\n";
|
119 |
+
}
|
120 |
+
?>
|
121 |
+
|
122 |
+
<form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ye-list-options'; ?>">
|
123 |
+
|
124 |
+
<span class="alignright">
|
125 |
+
<select name="youtube_embed_list_no">
|
126 |
+
<?php
|
127 |
+
$loop = 1;
|
128 |
+
while ( $loop <= $general['list_no'] ) {
|
129 |
+
|
130 |
+
$listfiles = ye_get_list( $loop );
|
131 |
+
if ( '' != $listfiles['list'] ) {
|
132 |
+
$listname = $listfiles['list_name'];
|
133 |
+
$list_found = true;
|
134 |
+
} else {
|
135 |
+
$listname = __( 'List', 'youtube-embed' ) . ' ' . $loop;
|
136 |
+
$list_found = false;
|
137 |
+
}
|
138 |
+
echo '<option value="' . $loop . '"';
|
139 |
+
if ( $list_no == $loop ) {
|
140 |
+
echo " selected='selected'";
|
141 |
+
}
|
142 |
+
echo '>' . $listname;
|
143 |
+
if ( ! $list_found ) {
|
144 |
+
echo ' [undefined]';
|
145 |
+
}
|
146 |
+
echo "</option>\n";
|
147 |
+
|
148 |
+
$loop ++;
|
149 |
+
}
|
150 |
+
?>
|
151 |
+
</select>
|
152 |
+
<input type="submit" name="List" class="button-secondary" value="<?php _e( 'Change list' ); ?>"/>
|
153 |
+
</span><br/>
|
154 |
+
|
155 |
+
<?php echo sprintf( __( 'These are the options for list %s.', 'youtube-embed' ), $list_no ) . '<br/>' . __( 'Update the name, if required, and specify a list of YouTube video IDs. Use the drop-down on the right hand side to swap between lists.', 'youtube-embed' ); ?>
|
156 |
+
|
157 |
+
<table class="form-table">
|
158 |
+
|
159 |
+
<!-- List Name -->
|
160 |
+
|
161 |
+
<tr>
|
162 |
+
<th scope="row"><?php _e( 'List Name', 'youtube-embed' ); ?></th>
|
163 |
+
<td><label for="youtube_embed_name"><input type="text" size="20" name="youtube_embed_name" value="<?php echo esc_attr( $options['list_name'] ); ?>"/>
|
164 |
+
<?php _e( 'The name you wish to give this list', 'youtube-embed' ); ?></label></td>
|
165 |
+
</tr>
|
166 |
+
|
167 |
+
<!-- Video IDs -->
|
168 |
+
|
169 |
+
<tr>
|
170 |
+
<th scope="row"><?php _e( 'Video IDs (one per line)', 'youtube-embed' ); ?></th>
|
171 |
+
<td><label for="youtube_embed_list"><textarea name="youtube_embed_video_list" rows="10" cols="20" class="regular-text code"><?php echo esc_textarea( $options['list'] ); ?></textarea></label></td>
|
172 |
+
</tr>
|
173 |
+
|
174 |
+
</table>
|
175 |
+
|
176 |
+
<?php wp_nonce_field( 'youtube-embed-general', 'youtube_embed_general_nonce', true, true ); ?>
|
177 |
+
|
178 |
+
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
|
179 |
+
|
180 |
+
</form>
|
181 |
+
|
182 |
+
<?php
|
183 |
+
|
184 |
+
// If video IDs exist display them on screen along with their status.
|
185 |
+
|
186 |
+
if ( '' != $options['list'] ) {
|
187 |
+
|
188 |
+
$id_array = explode( "\n", $options['list'] );
|
189 |
+
|
190 |
+
echo "<table class=\"widefat\" style=\"max-width: 800px\">\n<thead>\n\t<tr>\n\t\t<th>" . __( 'Video ID', 'youtube-embed' ) . "</th>\n\t\t<th>" . __( 'Video Title', 'youtube-embed' ) . "</th>\n\t\t<th>" . __( 'Status', 'youtube-embed' ) . "</th>\n\t</tr>\n</thead>\n<tbody>\n";
|
191 |
+
$loop = 0;
|
192 |
+
|
193 |
+
$array_count = count( $id_array );
|
194 |
+
while ( $loop < $array_count ) {
|
195 |
+
|
196 |
+
// Extract the ID from the provided data.
|
197 |
+
|
198 |
+
$id = trim( ye_extract_id( $id_array[ $loop ] ) );
|
199 |
+
if ( '' != $id ) {
|
200 |
+
|
201 |
+
// Validate the video type.
|
202 |
+
|
203 |
+
$api_data = ye_get_api_data( $id );
|
204 |
+
|
205 |
+
if ( 'p' == $api_data['type'] ) {
|
206 |
+
$text = __( 'This is a playlist', 'youtube-embed' );
|
207 |
+
$status = '-1';
|
208 |
+
} else {
|
209 |
+
if ( ! $api_data['valid'] ) {
|
210 |
+
$text = __( 'Invalid video ID', 'youtube-embed' );
|
211 |
+
$status = '-2';
|
212 |
+
} else {
|
213 |
+
if ( $api_data['valid'] ) {
|
214 |
+
$text = __( 'Valid video', 'youtube-embed' );
|
215 |
+
$status = '0';
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
// Output the video information.
|
221 |
+
|
222 |
+
echo "\t<tr>\n\t\t<td>" . $id . "</td>\n";
|
223 |
+
echo "\t\t<td>";
|
224 |
+
if ( $api_data['api'] ) {
|
225 |
+
if ( '' == $api_data['title'] ) {
|
226 |
+
echo '[No title available]';
|
227 |
+
} else {
|
228 |
+
echo $api_data['title'];
|
229 |
+
}
|
230 |
+
} else {
|
231 |
+
echo '[No title - API not available]';
|
232 |
+
}
|
233 |
+
echo "</td>\n";
|
234 |
+
echo "\t\t<td style=\"";
|
235 |
+
|
236 |
+
if ( 0 != $status ) {
|
237 |
+
echo 'font-weight: bold; color: #f00;';
|
238 |
+
}
|
239 |
+
|
240 |
+
echo '"><img src="' . plugins_url( 'images/', dirname( __FILE__ ) );
|
241 |
+
|
242 |
+
if ( 0 == $status ) {
|
243 |
+
$alt_text = __( 'The video ID is valid', 'youtube-embed' );
|
244 |
+
echo 'tick.png" alt="' . $alt_text . '" ';
|
245 |
+
} else {
|
246 |
+
$alt_text = __( 'The video ID is invalid', 'youtube-embed' );
|
247 |
+
echo 'cross.png" alt="' . $alt_text . '" ';
|
248 |
+
}
|
249 |
+
|
250 |
+
echo 'height="16px" width="16px"/> ' . $text . "</td>\n\t</tr>\n";
|
251 |
+
}
|
252 |
+
$loop ++;
|
253 |
+
}
|
254 |
+
echo "</tbody>\n</table>\n";
|
255 |
+
}
|
256 |
+
?>
|
257 |
+
|
258 |
+
</div>
|
includes/options-profiles.php
CHANGED
@@ -1,422 +1,841 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Profiles Options Page
|
4 |
-
*
|
5 |
-
* Screen for specifying different profiles and settings the options for each
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
<
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
<?php
|
408 |
-
|
409 |
-
<
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Profiles Options Page
|
4 |
+
*
|
5 |
+
* Screen for specifying different profiles and settings the options for each
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
$langs = array(
|
11 |
+
'aa',
|
12 |
+
'ab',
|
13 |
+
'ae',
|
14 |
+
'af',
|
15 |
+
'ak',
|
16 |
+
'am',
|
17 |
+
'an',
|
18 |
+
'ar',
|
19 |
+
'as',
|
20 |
+
'av',
|
21 |
+
'ay',
|
22 |
+
'az',
|
23 |
+
'ba',
|
24 |
+
'be',
|
25 |
+
'bg',
|
26 |
+
'bh',
|
27 |
+
'bi',
|
28 |
+
'bm',
|
29 |
+
'bn',
|
30 |
+
'bo',
|
31 |
+
'br',
|
32 |
+
'bs',
|
33 |
+
'ca',
|
34 |
+
'ce',
|
35 |
+
'ch',
|
36 |
+
'co',
|
37 |
+
'cr',
|
38 |
+
'cs',
|
39 |
+
'cu',
|
40 |
+
'cv',
|
41 |
+
'cy',
|
42 |
+
'da',
|
43 |
+
'de',
|
44 |
+
'dv',
|
45 |
+
'dz',
|
46 |
+
'ee',
|
47 |
+
'el',
|
48 |
+
'en',
|
49 |
+
'eo',
|
50 |
+
'es',
|
51 |
+
'et',
|
52 |
+
'eu',
|
53 |
+
'fa',
|
54 |
+
'ff',
|
55 |
+
'fi',
|
56 |
+
'fj',
|
57 |
+
'fo',
|
58 |
+
'fr',
|
59 |
+
'fy',
|
60 |
+
'ga',
|
61 |
+
'gd',
|
62 |
+
'gl',
|
63 |
+
'gn',
|
64 |
+
'gu',
|
65 |
+
'gv',
|
66 |
+
'ha',
|
67 |
+
'he',
|
68 |
+
'hi',
|
69 |
+
'ho',
|
70 |
+
'hr',
|
71 |
+
'ht',
|
72 |
+
'hu',
|
73 |
+
'hy',
|
74 |
+
'hz',
|
75 |
+
'ia',
|
76 |
+
'id',
|
77 |
+
'ie',
|
78 |
+
'ig',
|
79 |
+
'ii',
|
80 |
+
'ik',
|
81 |
+
'io',
|
82 |
+
'is',
|
83 |
+
'it',
|
84 |
+
'iu',
|
85 |
+
'ja',
|
86 |
+
'jv',
|
87 |
+
'ka',
|
88 |
+
'kg',
|
89 |
+
'ki',
|
90 |
+
'kj',
|
91 |
+
'kk',
|
92 |
+
'kl',
|
93 |
+
'km',
|
94 |
+
'kn',
|
95 |
+
'ko',
|
96 |
+
'kr',
|
97 |
+
'ks',
|
98 |
+
'ku',
|
99 |
+
'kv',
|
100 |
+
'kw',
|
101 |
+
'ky',
|
102 |
+
'la',
|
103 |
+
'lb',
|
104 |
+
'lg',
|
105 |
+
'li',
|
106 |
+
'ln',
|
107 |
+
'lo',
|
108 |
+
'lt',
|
109 |
+
'lu',
|
110 |
+
'lv',
|
111 |
+
'mg',
|
112 |
+
'mh',
|
113 |
+
'mi',
|
114 |
+
'mk',
|
115 |
+
'ml',
|
116 |
+
'mn',
|
117 |
+
'mr',
|
118 |
+
'ms',
|
119 |
+
'mt',
|
120 |
+
'my',
|
121 |
+
'na',
|
122 |
+
'nb',
|
123 |
+
'nd',
|
124 |
+
'ne',
|
125 |
+
'ng',
|
126 |
+
'nl',
|
127 |
+
'nn',
|
128 |
+
'no',
|
129 |
+
'nr',
|
130 |
+
'nv',
|
131 |
+
'ny',
|
132 |
+
'oc',
|
133 |
+
'oj',
|
134 |
+
'om',
|
135 |
+
'or',
|
136 |
+
'os',
|
137 |
+
'pa',
|
138 |
+
'pi',
|
139 |
+
'pl',
|
140 |
+
'ps',
|
141 |
+
'pt',
|
142 |
+
'qu',
|
143 |
+
'rm',
|
144 |
+
'rn',
|
145 |
+
'ro',
|
146 |
+
'ru',
|
147 |
+
'rw',
|
148 |
+
'sa',
|
149 |
+
'sc',
|
150 |
+
'sd',
|
151 |
+
'se',
|
152 |
+
'sg',
|
153 |
+
'si',
|
154 |
+
'sk',
|
155 |
+
'sl',
|
156 |
+
'sm',
|
157 |
+
'sn',
|
158 |
+
'so',
|
159 |
+
'sq',
|
160 |
+
'sr',
|
161 |
+
'ss',
|
162 |
+
'st',
|
163 |
+
'su',
|
164 |
+
'sv',
|
165 |
+
'sw',
|
166 |
+
'ta',
|
167 |
+
'te',
|
168 |
+
'tg',
|
169 |
+
'th',
|
170 |
+
'ti',
|
171 |
+
'tk',
|
172 |
+
'tl',
|
173 |
+
'tn',
|
174 |
+
'to',
|
175 |
+
'tr',
|
176 |
+
'ts',
|
177 |
+
'tt',
|
178 |
+
'tw',
|
179 |
+
'ty',
|
180 |
+
'ug',
|
181 |
+
'uk',
|
182 |
+
'ur',
|
183 |
+
'uz',
|
184 |
+
've',
|
185 |
+
'vi',
|
186 |
+
'vo',
|
187 |
+
'wa',
|
188 |
+
'wo',
|
189 |
+
'xh',
|
190 |
+
'yi',
|
191 |
+
'yo',
|
192 |
+
'za',
|
193 |
+
'zh',
|
194 |
+
);
|
195 |
+
|
196 |
+
// Set current profile number.
|
197 |
+
|
198 |
+
if ( isset( $_POST['youtube_embed_profile_no'] ) ) {
|
199 |
+
$profile_no = sanitize_text_field( $_POST['youtube_embed_profile_no'] );
|
200 |
+
} else {
|
201 |
+
$profile_no = 0;
|
202 |
+
}
|
203 |
+
if ( '' == $profile_no ) {
|
204 |
+
$profile_no = 0;
|
205 |
+
}
|
206 |
+
|
207 |
+
// If options have been updated on screen, update the database.
|
208 |
+
|
209 |
+
if ( ( ! empty( $_POST['Submit'] ) ) && ( check_admin_referer( 'youtube-embed-profile', 'youtube_embed_profile_nonce' ) ) ) {
|
210 |
+
|
211 |
+
$options['profile_name'] = sanitize_text_field( $_POST['youtube_embed_name'] );
|
212 |
+
$options['width'] = sanitize_text_field( $_POST['youtube_embed_width'] );
|
213 |
+
$options['height'] = sanitize_text_field( $_POST['youtube_embed_height'] );
|
214 |
+
|
215 |
+
$allowed_html = array(
|
216 |
+
'a' => array(
|
217 |
+
'href' => array(),
|
218 |
+
'title' => array(),
|
219 |
+
'target' => array(),
|
220 |
+
'class' => array(),
|
221 |
+
'id' => array(),
|
222 |
+
'style' => array(),
|
223 |
+
),
|
224 |
+
'img' => array(
|
225 |
+
'src' => array(),
|
226 |
+
'alt' => array(),
|
227 |
+
'height' => array(),
|
228 |
+
'width' => array(),
|
229 |
+
'align' => array(),
|
230 |
+
'class' => array(),
|
231 |
+
'id' => array(),
|
232 |
+
'style' => array(),
|
233 |
+
),
|
234 |
+
'div' => array(
|
235 |
+
'class' => array(),
|
236 |
+
'id' => array(),
|
237 |
+
'align' => array(),
|
238 |
+
'style' => array(),
|
239 |
+
),
|
240 |
+
'span' => array(
|
241 |
+
'class' => array(),
|
242 |
+
'id' => array(),
|
243 |
+
'style' => array(),
|
244 |
+
),
|
245 |
+
'br' => array(),
|
246 |
+
'p' => array(),
|
247 |
+
'strong' => array(),
|
248 |
+
);
|
249 |
+
|
250 |
+
$options['template'] = wp_kses( htmlspecialchars_decode( $_POST['youtube_embed_template'] ), $allowed_html );
|
251 |
+
if ( false === strpos( $options['template'], '%video%' ) ) {
|
252 |
+
$options['template'] = '%video%';
|
253 |
+
}
|
254 |
+
|
255 |
+
$options['style'] = sanitize_text_field( $_POST['youtube_embed_style'] );
|
256 |
+
$options['controls'] = sanitize_text_field( $_POST['youtube_embed_controls'] );
|
257 |
+
$options['color'] = sanitize_text_field( $_POST['youtube_embed_color'] );
|
258 |
+
$options['download_style'] = sanitize_text_field( $_POST['youtube_embed_download_style'] );
|
259 |
+
$options['cc_lang'] = sanitize_text_field( $_POST['youtube_embed_cc_lang'] );
|
260 |
+
$options['language'] = sanitize_text_field( $_POST['youtube_embed_language'] );
|
261 |
+
$options['download_text'] = str_replace( '\"', '"', str_replace( "\'", "'", $_POST['youtube_embed_download_text'] ) );
|
262 |
+
|
263 |
+
if ( isset( $_POST['youtube_embed_playsinline'] ) ) {
|
264 |
+
$options['playsinline'] = sanitize_text_field( $_POST['youtube_embed_playsinline'] );
|
265 |
+
} else {
|
266 |
+
$options['playsinline'] = '';
|
267 |
+
}
|
268 |
+
if ( isset( $_POST['youtube_embed_fullscreen'] ) ) {
|
269 |
+
$options['fullscreen'] = sanitize_text_field( $_POST['youtube_embed_fullscreen'] );
|
270 |
+
} else {
|
271 |
+
$options['fullscreen'] = '';
|
272 |
+
}
|
273 |
+
if ( isset( $_POST['youtube_embed_autoplay'] ) ) {
|
274 |
+
$options['autoplay'] = sanitize_text_field( $_POST['youtube_embed_autoplay'] );
|
275 |
+
} else {
|
276 |
+
$options['autoplay'] = '';
|
277 |
+
}
|
278 |
+
if ( isset( $_POST['youtube_embed_loop'] ) ) {
|
279 |
+
$options['loop'] = sanitize_text_field( $_POST['youtube_embed_loop'] );
|
280 |
+
} else {
|
281 |
+
$options['loop'] = '';
|
282 |
+
}
|
283 |
+
if ( isset( $_POST['youtube_embed_cc'] ) ) {
|
284 |
+
$options['cc'] = sanitize_text_field( $_POST['youtube_embed_cc'] );
|
285 |
+
} else {
|
286 |
+
$options['cc'] = '';
|
287 |
+
}
|
288 |
+
|
289 |
+
if ( isset( $_POST['youtube_embed_annotation'] ) ) {
|
290 |
+
$options['annotation'] = sanitize_text_field( $_POST['youtube_embed_annotation'] );
|
291 |
+
} else {
|
292 |
+
$options['annotation'] = '';
|
293 |
+
}
|
294 |
+
if ( isset( $_POST['youtube_embed_related'] ) ) {
|
295 |
+
$options['related'] = sanitize_text_field( $_POST['youtube_embed_related'] );
|
296 |
+
} else {
|
297 |
+
$options['related'] = '';
|
298 |
+
}
|
299 |
+
if ( isset( $_POST['youtube_embed_disablekb'] ) ) {
|
300 |
+
$options['disablekb'] = sanitize_text_field( $_POST['youtube_embed_disablekb'] );
|
301 |
+
} else {
|
302 |
+
$options['disablekb'] = '';
|
303 |
+
}
|
304 |
+
if ( isset( $_POST['youtube_embed_modest'] ) ) {
|
305 |
+
$options['modest'] = sanitize_text_field( $_POST['youtube_embed_modest'] );
|
306 |
+
} else {
|
307 |
+
$options['modest'] = '';
|
308 |
+
}
|
309 |
+
if ( isset( $_POST['youtube_embed_dynamic'] ) ) {
|
310 |
+
$options['dynamic'] = sanitize_text_field( $_POST['youtube_embed_dynamic'] );
|
311 |
+
} else {
|
312 |
+
$options['dynamic'] = '';
|
313 |
+
}
|
314 |
+
if ( isset( $_POST['youtube_embed_fixed'] ) ) {
|
315 |
+
$options['fixed'] = sanitize_text_field( $_POST['youtube_embed_fixed'] );
|
316 |
+
} else {
|
317 |
+
$options['fixed'] = '';
|
318 |
+
}
|
319 |
+
if ( isset( $_POST['youtube_embed_download'] ) ) {
|
320 |
+
$options['download'] = sanitize_text_field( $_POST['youtube_embed_download'] );
|
321 |
+
} else {
|
322 |
+
$options['download'] = '';
|
323 |
+
}
|
324 |
+
|
325 |
+
$default_size = $_POST['youtube_embed_size'];
|
326 |
+
|
327 |
+
if ( '' != $default_size ) {
|
328 |
+
$options['width'] = ltrim( substr( $default_size, 0, 4 ), '0' );
|
329 |
+
$options['height'] = ltrim( substr( $default_size, -4, 4 ), '0' );
|
330 |
+
}
|
331 |
+
|
332 |
+
// Set width or height, if missing.
|
333 |
+
|
334 |
+
if ( '' == $options['width'] && '' == $options['height'] ) {
|
335 |
+
if ( isset( $GLOBALS['content_width'] ) ) {
|
336 |
+
$options['width'] = $GLOBALS['content_width'];
|
337 |
+
} else {
|
338 |
+
$options['width'] = 560;
|
339 |
+
}
|
340 |
+
$options['height'] = 27 + round( ( $options['width'] / 16 ) * 9, 0 );
|
341 |
+
}
|
342 |
+
if ( ( '' == $options['width'] ) && ( '' != $options['height'] ) ) {
|
343 |
+
$options['width'] = round( ( $options['height'] / 9 ) * 16, 0 );
|
344 |
+
}
|
345 |
+
if ( ( '' != $options['width'] ) && ( '' == $options['height'] ) ) {
|
346 |
+
$options['height'] = 27 + round( ( $options['width'] / 16 ) * 9, 0 );
|
347 |
+
}
|
348 |
+
|
349 |
+
update_option( 'youtube_embed_profile' . $profile_no, $options );
|
350 |
+
$updated = true;
|
351 |
+
|
352 |
+
} else {
|
353 |
+
|
354 |
+
$default_size = '';
|
355 |
+
$updated = false;
|
356 |
+
}
|
357 |
+
|
358 |
+
// Fetch options into an array.
|
359 |
+
|
360 |
+
$options = ye_get_profile( $profile_no );
|
361 |
+
$general = ye_get_general_defaults();
|
362 |
+
|
363 |
+
// Get number of profiles in use.
|
364 |
+
|
365 |
+
$loop = 0;
|
366 |
+
$max_profiles = 0;
|
367 |
+
while ( $loop <= $general['profile_no'] ) {
|
368 |
+
|
369 |
+
$profile = ye_get_profile( $loop );
|
370 |
+
if ( ! $profile['default'] ) {
|
371 |
+
$max_profiles ++;
|
372 |
+
}
|
373 |
+
|
374 |
+
$loop ++;
|
375 |
+
}
|
376 |
+
|
377 |
+
|
378 |
+
// Output headings.
|
379 |
+
?>
|
380 |
+
|
381 |
+
<div class="wrap">
|
382 |
+
|
383 |
+
<h1><?php _e( 'YouTube Embed Profiles', 'youtube-embed' ); ?><span class="title-count"><?php echo $max_profiles; ?></span></h1>
|
384 |
+
|
385 |
+
<?php
|
386 |
+
|
387 |
+
// Output message text.
|
388 |
+
|
389 |
+
if ( $updated ) {
|
390 |
+
echo '<div class="updated fade"><p><strong>' . __( $options['profile_name'] . ' Profile Saved.' ) . "</strong></p></div>\n";
|
391 |
+
}
|
392 |
+
|
393 |
+
// Video option button has been pressed.
|
394 |
+
|
395 |
+
if ( ! empty( $_POST['Video'] ) ) {
|
396 |
+
$video_type = $_POST['youtube_embed_video_type'];
|
397 |
+
} else {
|
398 |
+
$video_type = 'd';
|
399 |
+
}
|
400 |
+
|
401 |
+
// Generate Profile list.
|
402 |
+
?>
|
403 |
+
<form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ye-profile-options'; ?>">
|
404 |
+
|
405 |
+
<span class="alignright">
|
406 |
+
<select name="youtube_embed_profile_no">
|
407 |
+
<?php ye_generate_profile_list( $profile_no, $general['profile_no'], true ); ?>
|
408 |
+
</select>
|
409 |
+
<input type="submit" name="Profile" class="button-secondary" value="<?php _e( 'Change profile', 'youtube-embed' ); ?>"/>
|
410 |
+
</span><br/>
|
411 |
+
|
412 |
+
<?php
|
413 |
+
|
414 |
+
// Show explanatory message at top of screen.
|
415 |
+
|
416 |
+
if ( '0' == $profile_no ) {
|
417 |
+
_e( 'These are the options for the default profile.', 'youtube-embed' );
|
418 |
+
} else {
|
419 |
+
sprintf( _e( 'These are the options for profile %s.', 'youtube-embed' ), $profile_no );
|
420 |
+
}
|
421 |
+
echo ' ' . __( 'Use the drop-down on the right hand side to swap between profiles.', 'youtube-embed' );
|
422 |
+
?>
|
423 |
+
|
424 |
+
<table class="form-table">
|
425 |
+
|
426 |
+
<!-- Profile Name -->
|
427 |
+
|
428 |
+
<tr>
|
429 |
+
<th scope="row"><?php _e( 'Profile Name', 'youtube-embed' ); ?></th>
|
430 |
+
<td><label for="youtube_embed_name"><input type="text" size="20" name="youtube_embed_name" value="<?php echo esc_attr( $options['profile_name'] ); ?>"
|
431 |
+
<?php
|
432 |
+
if ( 0 == $profile_no ) {
|
433 |
+
echo ' readonly="readonly"';
|
434 |
+
}
|
435 |
+
?>
|
436 |
+
/>
|
437 |
+
<?php
|
438 |
+
if ( 0 != $profile_no ) {
|
439 |
+
_e( 'The name you wish to give this profile', 'youtube-embed' );
|
440 |
+
}
|
441 |
+
?>
|
442 |
+
</label></td>
|
443 |
+
</tr>
|
444 |
+
|
445 |
+
<!-- Template -->
|
446 |
+
|
447 |
+
<tr>
|
448 |
+
<th scope="row"><?php _e( 'Template', 'youtube-embed' ); ?></th>
|
449 |
+
<td><label for="youtube_embed_template"><textarea name="youtube_embed_template" rows="4" cols="50" class="large-text code"><?php echo esc_html( $options['template'] ); ?></textarea>
|
450 |
+
<p class="description"><?php _e( 'Wrapper for video output. Must include <code>%video%</code> tag to show video position. Valid HTML tags are <code>a</code>, <code>br</code>, <code>div</code>, <code>img</code>, <code>p</code>, <code>span</code> and <code>strong</code>.', 'youtube-embed' ); ?></p></label></td>
|
451 |
+
</tr>
|
452 |
+
|
453 |
+
<!-- Style -->
|
454 |
+
|
455 |
+
<tr>
|
456 |
+
<th scope="row"><?php _e( 'Style', 'youtube-embed' ); ?></th>
|
457 |
+
<td><label for="youtube_embed_style"><input type="text" name="youtube_embed_style" class="large-text code" value="<?php echo esc_html( $options['style'] ); ?>"/>
|
458 |
+
<p class="description"><?php _e( 'CSS elements to apply to video.', 'youtube-embed' ); ?></p></label></td>
|
459 |
+
</tr>
|
460 |
+
|
461 |
+
</table><hr><h3 class="title"><?php _e( 'Video Size', 'youtube-embed' ); ?></h3><table class="form-table">
|
462 |
+
|
463 |
+
<!-- Video Size -->
|
464 |
+
|
465 |
+
<tr>
|
466 |
+
<th scope="row"><?php _e( 'Video Size', 'youtube-embed' ); ?></th>
|
467 |
+
<td><label for="youtube_embed_height"><input type="text" size="3" maxlength="3" name="youtube_embed_width" value="<?php echo esc_attr( $options['width'] ); ?>"/> x <input type="text" size="3" maxlength="3" name="youtube_embed_height" value="<?php echo esc_attr( $options['height'] ); ?>"/>
|
468 |
+
<?php _e( 'The width x height of the video, in pixels', 'youtube-embed' ); ?></label></td>
|
469 |
+
</tr>
|
470 |
+
|
471 |
+
<!-- Default Sizes -->
|
472 |
+
|
473 |
+
<tr>
|
474 |
+
<th scope="row"><?php _e( 'Default Sizes', 'youtube-embed' ); ?></th>
|
475 |
+
<td><label for="youtube_embed_size"><select name="youtube_embed_size">
|
476 |
+
<option value=""
|
477 |
+
<?php
|
478 |
+
if ( '' == $default_size ) {
|
479 |
+
echo " selected='selected'";
|
480 |
+
}
|
481 |
+
?>
|
482 |
+
>
|
483 |
+
<?php _e( 'Use above sizes', 'youtube-embed' ); ?>
|
484 |
+
</option>
|
485 |
+
<option value="04260420"
|
486 |
+
<?php
|
487 |
+
if ( '04260420' == $default_size ) {
|
488 |
+
echo " selected='selected'";
|
489 |
+
}
|
490 |
+
?>
|
491 |
+
>240p</option>
|
492 |
+
<option value="06400360"
|
493 |
+
<?php
|
494 |
+
if ( '06400360' == $default_size ) {
|
495 |
+
echo " selected='selected'";
|
496 |
+
}
|
497 |
+
?>
|
498 |
+
>360p</option>
|
499 |
+
<option value="08540480"
|
500 |
+
<?php
|
501 |
+
if ( '08540480' == $default_size ) {
|
502 |
+
echo " selected='selected'";
|
503 |
+
}
|
504 |
+
?>
|
505 |
+
>480p</option>
|
506 |
+
<option value="12800720"
|
507 |
+
<?php
|
508 |
+
if ( '12800720' == $default_size ) {
|
509 |
+
echo " selected='selected'";
|
510 |
+
}
|
511 |
+
?>
|
512 |
+
>720p</option>
|
513 |
+
<option value="19201080"
|
514 |
+
<?php
|
515 |
+
if ( '19201080' == $default_size ) {
|
516 |
+
echo " selected='selected'";
|
517 |
+
}
|
518 |
+
?>
|
519 |
+
>1080p</option>
|
520 |
+
<option value="38402160"
|
521 |
+
<?php
|
522 |
+
if ( '38402160' == $default_size ) {
|
523 |
+
echo " selected='selected'";
|
524 |
+
}
|
525 |
+
?>
|
526 |
+
>1440p</option>
|
527 |
+
<option value="38402160"
|
528 |
+
<?php
|
529 |
+
if ( '38402160' == $default_size ) {
|
530 |
+
echo " selected='selected'";
|
531 |
+
}
|
532 |
+
?>
|
533 |
+
>2160p</option>
|
534 |
+
</select></label><p class="description"><?php _e( 'Select one of these default sizes to override the above video sizes.', 'youtube-embed' ); ?></p></td>
|
535 |
+
</tr>
|
536 |
+
|
537 |
+
<!-- Responsive Output -->
|
538 |
+
|
539 |
+
<tr>
|
540 |
+
<th scope="row"><?php _e( 'Responsive Output', 'youtube-embed' ); ?></th>
|
541 |
+
<td><label for="youtube_embed_dynamic"><input type="checkbox" name="youtube_embed_dynamic" value="1" <?php checked( $options['dynamic'], '1' ); ?>/>
|
542 |
+
<?php _e( 'Show full width and resize with the browser', 'youtube-embed' ); ?></label></td>
|
543 |
+
</tr>
|
544 |
+
|
545 |
+
<!-- Maximum Size -->
|
546 |
+
|
547 |
+
<tr>
|
548 |
+
<th scope="row"> <?php _e( 'Set Maximum Size', 'youtube-embed' ); ?></th>
|
549 |
+
<td><label for="youtube_embed_fixed"><input type="checkbox" name="youtube_embed_fixed" value="1" <?php checked( $options['fixed'], '1' ); ?>/>
|
550 |
+
<?php _e( 'Use above width to define maximum size', 'youtube-embed' ); ?></label></td>
|
551 |
+
</tr>
|
552 |
+
|
553 |
+
<!-- Playsinline -->
|
554 |
+
|
555 |
+
<tr>
|
556 |
+
<th scope="row"><?php _e( 'Plays Inline', 'youtube-embed' ); ?></th>
|
557 |
+
|
558 |
+
<td><label for="youtube_embed_playsinline"><input type="checkbox" name="youtube_embed_playsinline" value="1" <?php checked( $options['playsinline'], '1' ); ?>/>
|
559 |
+
<?php _e( 'Whether videos play inline or fullscreen in an HTML5 player on iOS. ', 'youtube-embed' ); ?></label></td>
|
560 |
+
</tr>
|
561 |
+
|
562 |
+
</table><hr><h3 class="title"><?php _e( 'Playback', 'youtube-embed' ); ?></h3><table class="form-table">
|
563 |
+
|
564 |
+
<!-- Autoplay -->
|
565 |
+
|
566 |
+
<tr>
|
567 |
+
<th scope="row"><?php _e( 'Autoplay', 'youtube-embed' ); ?></th>
|
568 |
+
<td><label for="youtube_embed_autoplay"><input type="checkbox" name="youtube_embed_autoplay" value="1" <?php checked( $options['autoplay'], '1' ); ?>/>
|
569 |
+
<?php _e( 'Choose whether the initial video will automatically start to play when the player loads', 'youtube-embed' ); ?></label></td>
|
570 |
+
</tr>
|
571 |
+
|
572 |
+
<!-- Loop Video -->
|
573 |
+
|
574 |
+
<tr>
|
575 |
+
<th scope="row"><?php _e( 'Loop Video', 'youtube-embed' ); ?></th>
|
576 |
+
<td><label for="youtube_embed_loop"><input type="checkbox" name="youtube_embed_loop" value="1" <?php checked( $options['loop'], '1' ); ?>/>
|
577 |
+
<?php _e( 'Play the initial video again and again', 'youtube-embed' ); ?></label>
|
578 |
+
<p class="description"><?php _e( 'In the case of a playlist, this will play the entire playlist and then start again at the first video.', 'youtube-embed' ); ?></p></td>
|
579 |
+
</tr>
|
580 |
+
|
581 |
+
<!-- Annotations -->
|
582 |
+
|
583 |
+
<tr>
|
584 |
+
<th scope="row"><?php _e( 'Annotations', 'youtube-embed' ); ?></th>
|
585 |
+
<td><label for="youtube_embed_annotation"><input type="checkbox" name="youtube_embed_annotation" value="1" <?php checked( $options['annotation'], '1' ); ?>/>
|
586 |
+
<?php _e( 'Video annotations are shown by default', 'youtube-embed' ); ?></label></td>
|
587 |
+
</tr>
|
588 |
+
|
589 |
+
<!-- Closed Captions -->
|
590 |
+
|
591 |
+
<tr>
|
592 |
+
<th scope="row"><?php _e( 'Closed Captions', 'youtube-embed' ); ?></th>
|
593 |
+
<td><label for="youtube_embed_cc"><select name="youtube_embed_cc">
|
594 |
+
<option value="0"
|
595 |
+
<?php
|
596 |
+
if ( '0' == $options['cc'] ) {
|
597 |
+
echo " selected='selected'";
|
598 |
+
}
|
599 |
+
?>
|
600 |
+
>
|
601 |
+
<?php _e( 'Don\'t show closed captions', 'youtube-embed' ); ?>
|
602 |
+
</option>
|
603 |
+
<option value="1"
|
604 |
+
<?php
|
605 |
+
if ( '1' == $options['cc'] ) {
|
606 |
+
echo " selected='selected'";
|
607 |
+
}
|
608 |
+
?>
|
609 |
+
>
|
610 |
+
<?php _e( 'Show closed captions', 'youtube-embed' ); ?>
|
611 |
+
</option>
|
612 |
+
<option value=""
|
613 |
+
<?php
|
614 |
+
if ( '' == $options['cc'] ) {
|
615 |
+
echo " selected='selected'";
|
616 |
+
}
|
617 |
+
?>
|
618 |
+
>
|
619 |
+
<?php _e( 'User default', 'youtube-embed' ); ?>
|
620 |
+
</option>
|
621 |
+
</select></label>
|
622 |
+
<p class="description"><?php _e( 'Show closed captions.', 'youtube-embed' ); ?></p></td>
|
623 |
+
</tr>
|
624 |
+
|
625 |
+
<!-- Closed Caption Language -->
|
626 |
+
|
627 |
+
<tr>
|
628 |
+
<th scope="row"><?php _e( 'Closed Captions Language', 'youtube-embed' ); ?></th>
|
629 |
+
<td><label for="youtube_embed_cc_lang"><select name="youtube_embed_cc_lang">
|
630 |
+
<option value=""
|
631 |
+
<?php
|
632 |
+
if ( '' == $options['cc_lang'] ) {
|
633 |
+
echo " selected='selected'";
|
634 |
+
}
|
635 |
+
?>
|
636 |
+
>N/A</option>
|
637 |
+
<?php
|
638 |
+
$loop = 0;
|
639 |
+
$array_count = count( $langs );
|
640 |
+
while ( $loop < $array_count ) {
|
641 |
+
|
642 |
+
echo '<option value=" ' . $langs[ $loop ] . '"';
|
643 |
+
if ( $langs[ $loop ] == $options['cc_lang'] ) {
|
644 |
+
echo " selected='selected'";
|
645 |
+
}
|
646 |
+
echo '>' . $langs[ $loop ] . '</option>';
|
647 |
+
|
648 |
+
$loop ++;
|
649 |
+
}
|
650 |
+
|
651 |
+
?>
|
652 |
+
</select></label>
|
653 |
+
<p class="description"><?php echo __( 'Closed captions language. Select a <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO 639-1 two-letter language code</a> or N/A for none.', 'youtube-embed' ); ?></p></td>
|
654 |
+
|
655 |
+
</tr>
|
656 |
+
|
657 |
+
<!-- Related -->
|
658 |
+
|
659 |
+
<tr>
|
660 |
+
<th scope="row"><?php _e( 'Related Videos', 'youtube-embed' ); ?></th>
|
661 |
+
<td><label for="youtube_embed_related"><select name="youtube_embed_related">
|
662 |
+
<option value="0"
|
663 |
+
<?php
|
664 |
+
if ( '0' == $options['related'] ) {
|
665 |
+
echo " selected='selected'";
|
666 |
+
}
|
667 |
+
?>
|
668 |
+
>
|
669 |
+
<?php _e( 'Show from the same channel', 'youtube-embed' ); ?>
|
670 |
+
</option>
|
671 |
+
<option value="1"
|
672 |
+
<?php
|
673 |
+
if ( '1' == $options['related'] ) {
|
674 |
+
echo " selected='selected'";
|
675 |
+
}
|
676 |
+
?>
|
677 |
+
>
|
678 |
+
<?php _e( 'Show related videos from any channel', 'youtube-embed' ); ?>
|
679 |
+
</option></label>
|
680 |
+
<p class="description"><?php _e( 'Defines where related videos are fetched from.', 'youtube-embed' ); ?></p></td>
|
681 |
+
</tr>
|
682 |
+
|
683 |
+
<!-- Modest Branding -->
|
684 |
+
|
685 |
+
<tr>
|
686 |
+
<th scope="row"><?php _e( 'Modest Branding', 'youtube-embed' ); ?></th>
|
687 |
+
<td><label for="youtube_embed_modest"><input type="checkbox" name="youtube_embed_modest" value="1" <?php checked( $options['modest'], '1' ); ?>/>
|
688 |
+
<?php _e( 'Reduce branding on video', 'youtube-embed' ); ?></label></td>
|
689 |
+
</tr>
|
690 |
+
|
691 |
+
</table><hr><h3 class="title"><?php _e( 'Controls', 'youtube-embed' ); ?></h3><table class="form-table">
|
692 |
+
|
693 |
+
<!-- Interface language -->
|
694 |
+
|
695 |
+
<tr>
|
696 |
+
<th scope="row"><?php _e( 'Interface Language', 'youtube-embed' ); ?></th>
|
697 |
+
<td><label for="youtube_embed_language"><input type="text" size="5" maxlength="5" name="youtube_embed_language" value="<?php echo esc_attr( $options['language'] ); ?>"/><?php _e( 'The player\'s interface language', 'youtube-embed' ); ?></label>
|
698 |
+
<p class="description"><?php echo __( 'The parameter value is an <a href="https://www.loc.gov/standards/iso639-2/php/code_list.php">ISO 639-1 two-letter language code</a> or a fully specified locale. Leave blank for the default.', 'youtube-embed' ); ?></p></td>
|
699 |
+
</tr>
|
700 |
+
|
701 |
+
<!-- Controls -->
|
702 |
+
|
703 |
+
<tr>
|
704 |
+
<th scope="row"><?php _e( 'Controls', 'youtube-embed' ); ?></th>
|
705 |
+
<td><label for="youtube_embed_controls"><select name="youtube_embed_controls">
|
706 |
+
<option value="0"
|
707 |
+
<?php
|
708 |
+
if ( '0' == $options['controls'] ) {
|
709 |
+
echo " selected='selected'";
|
710 |
+
}
|
711 |
+
?>
|
712 |
+
>
|
713 |
+
<?php _e( 'Controls do not display & Flash player loads immediately', 'youtube-embed' ); ?>
|
714 |
+
</option>
|
715 |
+
<option value="1"
|
716 |
+
<?php
|
717 |
+
if ( '1' == $options['controls'] ) {
|
718 |
+
echo " selected='selected'";
|
719 |
+
}
|
720 |
+
?>
|
721 |
+
>
|
722 |
+
<?php _e( 'Controls display & Flash player loads immediately', 'youtube-embed' ); ?>
|
723 |
+
</option>
|
724 |
+
<option value="2"
|
725 |
+
<?php
|
726 |
+
if ( '2' == $options['controls'] ) {
|
727 |
+
echo " selected='selected'";
|
728 |
+
}
|
729 |
+
?>
|
730 |
+
>
|
731 |
+
<?php _e( 'Controls display & Flash player loads once video starts', 'youtube-embed' ); ?>
|
732 |
+
</option>
|
733 |
+
</select></label>
|
734 |
+
<p class="description"><?php _e( 'Whether the video player controls are displayed. For Flash it also defines when the controls display in the player as well as when the player will load.', 'youtube-embed' ); ?></p></td>
|
735 |
+
</tr>
|
736 |
+
|
737 |
+
<!-- Disable Keyboard -->
|
738 |
+
|
739 |
+
<tr>
|
740 |
+
<th scope="row"><?php _e( 'Disable Keyboard', 'youtube-embed' ); ?></th>
|
741 |
+
<td><label for="youtube_embed_disablekb"><input type="checkbox" name="youtube_embed_disablekb" value="1" <?php checked( $options['disablekb'], '1' ); ?>/>
|
742 |
+
<?php _e( 'Disable the player keyboard controls', 'youtube-embed' ); ?></label></td>
|
743 |
+
</tr>
|
744 |
+
|
745 |
+
<!-- Fullscreen -->
|
746 |
+
|
747 |
+
<tr>
|
748 |
+
<th scope="row"><?php _e( 'Fullscreen', 'youtube-embed' ); ?></th>
|
749 |
+
<td><label for="youtube_embed_fullscreen"><input type="checkbox" name="youtube_embed_fullscreen" value="1" <?php checked( $options['fullscreen'], '1' ); ?>/>
|
750 |
+
<?php _e( 'A button will allow the viewer to watch the video fullscreen', 'youtube-embed' ); ?></label></td>
|
751 |
+
</tr>
|
752 |
+
|
753 |
+
<!-- Color -->
|
754 |
+
|
755 |
+
<tr>
|
756 |
+
<th scope="row"><?php _e( 'Progress Bar Color', 'youtube-embed' ); ?></th>
|
757 |
+
<td><label for="youtube_embed_color"><select name="youtube_embed_color">
|
758 |
+
<option value="red"
|
759 |
+
<?php
|
760 |
+
if ( 'red' == $options['color'] ) {
|
761 |
+
echo " selected='selected'";
|
762 |
+
}
|
763 |
+
?>
|
764 |
+
>
|
765 |
+
<?php _e( 'Red', 'youtube-embed' ); ?>
|
766 |
+
</option>
|
767 |
+
<option value="white"
|
768 |
+
<?php
|
769 |
+
if ( 'white' == $options['color'] ) {
|
770 |
+
echo " selected='selected'";
|
771 |
+
}
|
772 |
+
?>
|
773 |
+
>
|
774 |
+
<?php _e( 'White (desaturated)', 'youtube-embed' ); ?>
|
775 |
+
</option>
|
776 |
+
</select></label>
|
777 |
+
<p class="description"><?php _e( 'The color that will be used in the player\'s video progress bar to highlight the amount of the video that\'s already been seen.', 'youtube-embed' ); ?></p></td>
|
778 |
+
</tr>
|
779 |
+
|
780 |
+
</table><hr><h3 class="title"><?php _e( 'Download Link', 'youtube-embed' ); ?></h3><table class="form-table">
|
781 |
+
|
782 |
+
<!-- Download Link -->
|
783 |
+
|
784 |
+
<tr>
|
785 |
+
<th scope="row"><?php _e( 'Show Download Link', 'youtube-embed' ); ?></th>
|
786 |
+
<td><label for="youtube_embed_download"><input type="checkbox" name="youtube_embed_download" value="1" <?php checked( $options['download'], '1' ); ?>/>
|
787 |
+
<?php echo sprintf( __( 'Show a link to %s under the video', 'youtube-embed' ), '<a href="http://keepvid.com/" rel="nofollow">KeepVid</a>' ); ?></label></td>
|
788 |
+
</tr>
|
789 |
+
|
790 |
+
<!-- Download Text -->
|
791 |
+
|
792 |
+
<tr>
|
793 |
+
<th scope="row"><?php _e( 'Download Text', 'youtube-embed' ); ?></th>
|
794 |
+
<td><label for="youtube_embed_download_txt"><input type="text" name="youtube_embed_download_text" class="large-text" value="<?php echo esc_attr( $options['download_text'] ); ?>"/>
|
795 |
+
<p class="description"><?php _e( 'Text or HTML to display to prompt download.', 'youtube-embed' ); ?></p></label></td>
|
796 |
+
</tr>
|
797 |
+
|
798 |
+
<!-- Download Style -->
|
799 |
+
|
800 |
+
<tr>
|
801 |
+
<th scope="row"><?php _e( 'Download Style', 'youtube-embed' ); ?></th>
|
802 |
+
<td><label for="youtube_embed_download_style"><input type="text" name="youtube_embed_download_style" class="large-text code" value="<?php echo esc_attr( $options['download_style'] ); ?>"/>
|
803 |
+
<p class="description"><?php _e( 'CSS elements to apply to video download link.', 'youtube-embed' ); ?></p></label></td>
|
804 |
+
</tr>
|
805 |
+
|
806 |
+
</table>
|
807 |
+
|
808 |
+
<?php wp_nonce_field( 'youtube-embed-profile', 'youtube_embed_profile_nonce', true, true ); ?>
|
809 |
+
|
810 |
+
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
|
811 |
+
|
812 |
+
</form>
|
813 |
+
|
814 |
+
<a href="#" name="video"></a>
|
815 |
+
<div style="max-width: <?php echo esc_attr( $options['width'] ); ?>px">
|
816 |
+
<h3><?php _e( 'YouTube Video Sample', 'youtube-embed' ); ?></h3>
|
817 |
+
<p><?php _e( 'The videos below uses the above, saved profile settings in use', 'youtube-embed' ); ?></p>
|
818 |
+
<h4><?php _e( 'Standard video', 'youtube-embed' ); ?></h3>
|
819 |
+
<p>
|
820 |
+
<?php
|
821 |
+
echo ye_generate_youtube_code(
|
822 |
+
array(
|
823 |
+
'id' => $general['standard_video'],
|
824 |
+
'profile' => $profile_no,
|
825 |
+
)
|
826 |
+
);
|
827 |
+
?>
|
828 |
+
</p>
|
829 |
+
<h4><?php _e( 'Playlist', 'youtube-embed' ); ?></h3>
|
830 |
+
<p>
|
831 |
+
<?php
|
832 |
+
echo ye_generate_youtube_code(
|
833 |
+
array(
|
834 |
+
'id' => $general['playlist_video'],
|
835 |
+
'profile' => $profile_no,
|
836 |
+
)
|
837 |
+
);
|
838 |
+
?>
|
839 |
+
</p>
|
840 |
+
|
841 |
+
</div>
|
includes/shared-functions.php
CHANGED
@@ -1,567 +1,549 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Shared Functions
|
4 |
-
*
|
5 |
-
* Small utilities shared by a number of other functions
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Extract a video ID
|
12 |
-
*
|
13 |
-
* Function to extract an ID if a full URL has been supplied
|
14 |
-
*
|
15 |
-
* @
|
16 |
-
*
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
$
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
$
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
if (
|
59 |
-
$video_pos = $video_pos + 14;
|
60 |
-
$qmark_pos = strpos( $id, '?', $video_pos );
|
61 |
-
if (
|
62 |
-
$id = substr( $id, $video_pos );
|
63 |
-
} else {
|
64 |
-
$id = substr( $id, $video_pos, $qmark_pos - $video_pos );
|
65 |
-
}
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
$
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
*
|
90 |
-
*
|
91 |
-
*
|
92 |
-
*
|
93 |
-
* @
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
* Convert input to a
|
107 |
-
*
|
108 |
-
*
|
109 |
-
*
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
*
|
130 |
-
*
|
131 |
-
*
|
132 |
-
*
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
*
|
174 |
-
*
|
175 |
-
*
|
176 |
-
*
|
177 |
-
*
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
*
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
// If
|
204 |
-
|
205 |
-
if (
|
206 |
-
$shortcode =
|
207 |
-
update_option( 'youtube_embed_shortcode', $shortcode );
|
208 |
-
}
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
*
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
//
|
281 |
-
|
282 |
-
if (
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
*
|
301 |
-
*
|
302 |
-
*
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
*
|
333 |
-
*
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
// Because
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
//
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
$
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
*
|
450 |
-
*
|
451 |
-
*
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
*
|
534 |
-
*
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
* Used by the author for testing purposes
|
551 |
-
*
|
552 |
-
* @since 4.1
|
553 |
-
*
|
554 |
-
* @param string $checkpoint The last time
|
555 |
-
* @param string $name The name of the checkpoint
|
556 |
-
* @return string New checkpoint
|
557 |
-
*/
|
558 |
-
|
559 |
-
function ye_timer( $checkpoint, $name ) {
|
560 |
-
|
561 |
-
$timing = ( microtime( true ) - $checkpoint );
|
562 |
-
|
563 |
-
echo '<p>' . $name . ': ' . ( $timing * 1000000 ) . ' microseconds.</p>';
|
564 |
-
|
565 |
-
return microtime( true );
|
566 |
-
|
567 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Shared Functions
|
4 |
+
*
|
5 |
+
* Small utilities shared by a number of other functions
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Extract a video ID
|
12 |
+
*
|
13 |
+
* Function to extract an ID if a full URL has been supplied
|
14 |
+
*
|
15 |
+
* @param string $id Video ID.
|
16 |
+
* @return string Extracted ID.
|
17 |
+
*/
|
18 |
+
function ye_extract_id( $id ) {
|
19 |
+
|
20 |
+
// Convert and trim video ID characters.
|
21 |
+
|
22 |
+
$replacement_from = array( '–', '—', '×' );
|
23 |
+
$replacement_to = array( '--', '---', 'x' );
|
24 |
+
|
25 |
+
$id = trim( wp_strip_all_tags( str_replace( $replacement_from, $replacement_to, $id ) ) );
|
26 |
+
|
27 |
+
// Check if it's the full URL, as found in address bar.
|
28 |
+
|
29 |
+
$video_pos = strpos( $id, 'youtube.com/watch?', 0 );
|
30 |
+
|
31 |
+
if ( false !== $video_pos ) {
|
32 |
+
|
33 |
+
$video_pos = strpos( $id, 'v=', $video_pos + 18 );
|
34 |
+
if ( false === $video_pos ) {
|
35 |
+
$video_pos = strpos( $id, 'p=', $video_pos + 18 );
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( false !== $video_pos ) {
|
39 |
+
|
40 |
+
$video_pos = $video_pos + 2;
|
41 |
+
$ampersand_pos = strpos( $id, '&', $video_pos );
|
42 |
+
if ( ! $ampersand_pos ) {
|
43 |
+
$id = substr( $id, $video_pos );
|
44 |
+
} else {
|
45 |
+
$id = substr( $id, $video_pos, $ampersand_pos - $video_pos );
|
46 |
+
}
|
47 |
+
}
|
48 |
+
} else {
|
49 |
+
|
50 |
+
// Now check to see if it's a full URL, as used in the embed code
|
51 |
+
// Need to check both video and playlist formats.
|
52 |
+
|
53 |
+
$video_pos = strpos( $id, 'youtube.com/v/' );
|
54 |
+
if ( false === $video_pos ) {
|
55 |
+
$video_pos = strpos( $id, 'youtube.com/p/' );
|
56 |
+
}
|
57 |
+
|
58 |
+
if ( false !== $video_pos ) {
|
59 |
+
$video_pos = $video_pos + 14;
|
60 |
+
$qmark_pos = strpos( $id, '?', $video_pos );
|
61 |
+
if ( ! $qmark_pos ) {
|
62 |
+
$id = substr( $id, $video_pos );
|
63 |
+
} else {
|
64 |
+
$id = substr( $id, $video_pos, $qmark_pos - $video_pos );
|
65 |
+
}
|
66 |
+
} else {
|
67 |
+
|
68 |
+
// Check if it's a shortened URL.
|
69 |
+
|
70 |
+
$video_pos = strpos( $id, 'youtu.be/', 0 );
|
71 |
+
|
72 |
+
if ( false !== $video_pos ) {
|
73 |
+
$video_pos = $video_pos + 9;
|
74 |
+
$ampersand_pos = strpos( $id, '&', $video_pos );
|
75 |
+
if ( ! $ampersand_pos ) {
|
76 |
+
$id = substr( $id, $video_pos );
|
77 |
+
} else {
|
78 |
+
$id = substr( $id, $video_pos, $ampersand_pos - $video_pos );
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
return $id;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Function to report an error
|
89 |
+
*
|
90 |
+
* Display an error message in a standard format
|
91 |
+
*
|
92 |
+
* @param string $errorin Error message.
|
93 |
+
* @return string Error output.
|
94 |
+
*/
|
95 |
+
function ye_error( $errorin ) {
|
96 |
+
|
97 |
+
return '<p style="color: #f00; font-weight: bold;">YouTube Embed: ' . $errorin . "</p>\n";
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Convert input to a 1 or 0 equivalent
|
103 |
+
*
|
104 |
+
* Function to convert a Yes or No input to an equivalent 1 or 0 output
|
105 |
+
*
|
106 |
+
* @uses ye_yes_or_no Convert input to a true or false equivalent.
|
107 |
+
*
|
108 |
+
* @param string $input Input, usually Yes or No.
|
109 |
+
* @return string 1, 0 or blank, depending on input.
|
110 |
+
*/
|
111 |
+
function ye_convert( $input ) {
|
112 |
+
|
113 |
+
$input = ye_yes_or_no( $input );
|
114 |
+
$output = '';
|
115 |
+
if ( true === $input ) {
|
116 |
+
$output = '1';
|
117 |
+
}
|
118 |
+
if ( false === $input ) {
|
119 |
+
$output = '0';
|
120 |
+
}
|
121 |
+
|
122 |
+
return $output;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Generate a profile list
|
127 |
+
*
|
128 |
+
* Generate FORM options for the current profiles
|
129 |
+
*
|
130 |
+
* @param string $current The current profile number.
|
131 |
+
* @param string $total The total number of profiles.
|
132 |
+
* @param string $full_list Show the full list or just those defined.
|
133 |
+
*/
|
134 |
+
function ye_generate_profile_list( $current, $total, $full_list = false ) {
|
135 |
+
|
136 |
+
$loop = 0;
|
137 |
+
while ( $loop <= $total ) {
|
138 |
+
|
139 |
+
// Attempt to get profile.
|
140 |
+
|
141 |
+
$profiles = ye_get_profile( $loop );
|
142 |
+
|
143 |
+
// If list is undefined, give it a default name.
|
144 |
+
|
145 |
+
if ( $profiles['default'] ) {
|
146 |
+
$list_found = false;
|
147 |
+
} else {
|
148 |
+
$list_found = true;
|
149 |
+
}
|
150 |
+
|
151 |
+
// Output profile information.
|
152 |
+
|
153 |
+
if ( ( $list_found ) || ( $full_list ) ) {
|
154 |
+
|
155 |
+
echo '<option value="' . $loop . '"';
|
156 |
+
if ( $current == $loop ) {
|
157 |
+
echo " selected='selected'";
|
158 |
+
}
|
159 |
+
echo '>' . __( $profiles['profile_name'] );
|
160 |
+
if ( ! $list_found ) {
|
161 |
+
echo ' [undefined]';
|
162 |
+
}
|
163 |
+
echo "</option>\n";
|
164 |
+
|
165 |
+
}
|
166 |
+
|
167 |
+
$loop ++;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Function to get shortcode options
|
173 |
+
*
|
174 |
+
* Return shortcode options. It's in a seperate function in case any further shared
|
175 |
+
* functionality needs to be added.
|
176 |
+
*
|
177 |
+
* @return strings Alternative shortcode name.
|
178 |
+
*/
|
179 |
+
function ye_get_shortcode() {
|
180 |
+
|
181 |
+
return get_option( 'youtube_embed_shortcode' );
|
182 |
+
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Function to set Shortcode option
|
187 |
+
*
|
188 |
+
* Looks up shortcode option - if it's not set, assign a default
|
189 |
+
*
|
190 |
+
* @return string Alternative Shortcode.
|
191 |
+
*/
|
192 |
+
function ye_set_shortcode() {
|
193 |
+
|
194 |
+
$shortcode = get_option( 'youtube_embed_shortcode' );
|
195 |
+
|
196 |
+
// If an array, transform to new format.
|
197 |
+
|
198 |
+
if ( is_array( $shortcode ) ) {
|
199 |
+
$shortcode = $shortcode[1];
|
200 |
+
update_option( 'youtube_embed_shortcode', $shortcode );
|
201 |
+
}
|
202 |
+
|
203 |
+
// If setting doesn't exist, set defaults.
|
204 |
+
|
205 |
+
if ( '' == $shortcode ) {
|
206 |
+
$shortcode = 'youtube_video';
|
207 |
+
update_option( 'youtube_embed_shortcode', $shortcode );
|
208 |
+
}
|
209 |
+
|
210 |
+
return $shortcode;
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Function to get general YouTube options
|
215 |
+
*
|
216 |
+
* Return options. It's in a seperate function in case any further shared
|
217 |
+
* functionality needs to be added.
|
218 |
+
*
|
219 |
+
* @return strings Options array.
|
220 |
+
*/
|
221 |
+
function ye_get_general_defaults() {
|
222 |
+
|
223 |
+
return get_option( 'youtube_embed_general' );
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Function to set general YouTube options
|
229 |
+
*
|
230 |
+
* Looks up options. If none exist, or some are missing, set default values
|
231 |
+
*
|
232 |
+
* @return string Options array.
|
233 |
+
*/
|
234 |
+
function ye_set_general_defaults() {
|
235 |
+
|
236 |
+
$options = get_option( 'youtube_embed_general' );
|
237 |
+
|
238 |
+
// If options don't exist, create an empty array.
|
239 |
+
|
240 |
+
if ( ! is_array( $options ) ) {
|
241 |
+
$options = array();
|
242 |
+
}
|
243 |
+
|
244 |
+
// Because of upgrading, check each option - if not set, apply default.
|
245 |
+
|
246 |
+
$default_array = array(
|
247 |
+
'admin_bar' => 1,
|
248 |
+
'profile_no' => 5,
|
249 |
+
'list_no' => 5,
|
250 |
+
'alt_profile' => 0,
|
251 |
+
'metadata' => 1,
|
252 |
+
'feed' => 'b',
|
253 |
+
'thumbnail' => 2,
|
254 |
+
'privacy' => 0,
|
255 |
+
'frameborder' => 1,
|
256 |
+
'widgets' => 0,
|
257 |
+
'menu_access' => 'list_users',
|
258 |
+
'debug' => 1,
|
259 |
+
'script' => '',
|
260 |
+
'prompt' => 1,
|
261 |
+
'force_list_type' => 0,
|
262 |
+
'api' => '',
|
263 |
+
'api_cache' => 7,
|
264 |
+
'video_cache' => 24,
|
265 |
+
'standard_video' => 'YA8lE3sswX0',
|
266 |
+
'playlist_video' => 'PLQFhxUeNFfdLLVYP5qI7CVZeQmsT7aV0t',
|
267 |
+
'lazyload' => 0,
|
268 |
+
);
|
269 |
+
|
270 |
+
// If a new user switch the list option on. Otherwise, an existing user will default to off.
|
271 |
+
|
272 |
+
if ( ! is_array( $options ) ) {
|
273 |
+
$default_array['list'] = 1;
|
274 |
+
}
|
275 |
+
|
276 |
+
// Merge existing and default options - any missing from existing will take the default settings.
|
277 |
+
|
278 |
+
$new_options = array_merge( $default_array, $options );
|
279 |
+
|
280 |
+
// Check if API is invalid (some people are finding a value left over from past install). If so, clear it down.
|
281 |
+
|
282 |
+
if ( 1 == strlen( $new_options['api'] ) ) {
|
283 |
+
$new_options['api'] = '';
|
284 |
+
}
|
285 |
+
|
286 |
+
// Update the options, if changed, and return the result.
|
287 |
+
|
288 |
+
if ( $options != $new_options ) {
|
289 |
+
update_option( 'youtube_embed_general', $new_options );
|
290 |
+
}
|
291 |
+
|
292 |
+
return $new_options;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Function to get profile options
|
297 |
+
*
|
298 |
+
* Return profiles. It's in a seperate function in case any further shared
|
299 |
+
* functionality needs to be added.
|
300 |
+
*
|
301 |
+
* @param string $profile Profile number.
|
302 |
+
* @return array Profile array.
|
303 |
+
*/
|
304 |
+
function ye_get_profile( $profile ) {
|
305 |
+
|
306 |
+
$options = get_option( 'youtube_embed_profile' . $profile );
|
307 |
+
|
308 |
+
// If there is no profile set up, set to default values and save.
|
309 |
+
|
310 |
+
if ( ! is_array( $options ) ) {
|
311 |
+
$options = ye_set_profile_defaults( $profile );
|
312 |
+
$options['default'] = true;
|
313 |
+
} else {
|
314 |
+
$options['default'] = false;
|
315 |
+
}
|
316 |
+
|
317 |
+
// Remove added slashes from template XHTML.
|
318 |
+
|
319 |
+
if ( isset( $options['template'] ) ) {
|
320 |
+
$options['template'] = stripslashes( $options['template'] );
|
321 |
+
}
|
322 |
+
|
323 |
+
return $options;
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Function to set YouTube profile options
|
328 |
+
*
|
329 |
+
* Looks up profile options, based on passed number of profiles.
|
330 |
+
* If none exist, or some are missing, set default values
|
331 |
+
*
|
332 |
+
* @param string $profiles Number of profiles.
|
333 |
+
* @return array Options array.
|
334 |
+
*/
|
335 |
+
function ye_set_profile( $profiles ) {
|
336 |
+
|
337 |
+
$profile = 0;
|
338 |
+
while ( $profile <= $profiles ) {
|
339 |
+
|
340 |
+
$options = get_option( 'youtube_embed_profile' . $profile );
|
341 |
+
|
342 |
+
// If the profile doesn't exist, don't assign anything to it.
|
343 |
+
|
344 |
+
if ( is_array( $options ) ) {
|
345 |
+
|
346 |
+
// Because of upgrading, check each option - if not set, apply default.
|
347 |
+
|
348 |
+
$default_array = ye_set_profile_defaults( $profile );
|
349 |
+
|
350 |
+
// Merge the two arrays.
|
351 |
+
|
352 |
+
$new_options = array_merge( $default_array, $options );
|
353 |
+
|
354 |
+
// Because I've changed the variable name from name to profile_name, convert any with the old name.
|
355 |
+
|
356 |
+
if ( isset( $new_options['name'] ) ) {
|
357 |
+
$new_options['profile_name'] = $new_options['name'];
|
358 |
+
unset( $new_options['name'] );
|
359 |
+
}
|
360 |
+
|
361 |
+
// Update the options, if changed, and return the result.
|
362 |
+
|
363 |
+
if ( $options != $new_options ) {
|
364 |
+
update_option( 'youtube_embed_profile' . $profile, $new_options );
|
365 |
+
}
|
366 |
+
|
367 |
+
// Remove added slashes from template XHTML.
|
368 |
+
|
369 |
+
$options['template'] = stripslashes( $options['template'] );
|
370 |
+
|
371 |
+
}
|
372 |
+
|
373 |
+
$profile++;
|
374 |
+
|
375 |
+
}
|
376 |
+
|
377 |
+
return $options;
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Function to set initial profile default options
|
382 |
+
*
|
383 |
+
* Sets default values for a profile
|
384 |
+
*
|
385 |
+
* @param string $profile Profile name.
|
386 |
+
* @return array Profile array.
|
387 |
+
*/
|
388 |
+
function ye_set_profile_defaults( $profile ) {
|
389 |
+
|
390 |
+
// Set profile name.
|
391 |
+
|
392 |
+
if ( 0 == $profile ) {
|
393 |
+
$profname = 'Default';
|
394 |
+
} else {
|
395 |
+
$profname = 'Profile ' . $profile;
|
396 |
+
}
|
397 |
+
|
398 |
+
// Work out default dimensions.
|
399 |
+
|
400 |
+
$width = 0;
|
401 |
+
if ( isset( $content_width ) ) {
|
402 |
+
$width = $content_width;
|
403 |
+
}
|
404 |
+
if ( ( 0 == $width ) || ( '' == $width ) ) {
|
405 |
+
$width = 560;
|
406 |
+
}
|
407 |
+
$height = 25 + round( ( $width / 16 ) * 9, 0 );
|
408 |
+
|
409 |
+
// Set default array.
|
410 |
+
|
411 |
+
$default = array(
|
412 |
+
'profile_name' => $profname,
|
413 |
+
'width' => $width,
|
414 |
+
'height' => $height,
|
415 |
+
'fullscreen' => 1,
|
416 |
+
'template' => '%video%',
|
417 |
+
'autoplay' => '',
|
418 |
+
'start' => 0,
|
419 |
+
'loop' => '',
|
420 |
+
'cc' => '',
|
421 |
+
'cc_lang' => '',
|
422 |
+
'annotation' => 1,
|
423 |
+
'related' => 1,
|
424 |
+
'info' => 1,
|
425 |
+
'stop' => 0,
|
426 |
+
'disablekb' => '',
|
427 |
+
'controls' => 1,
|
428 |
+
'style' => '',
|
429 |
+
'color' => 'red',
|
430 |
+
'modest' => '',
|
431 |
+
'dynamic' => '',
|
432 |
+
'fixed' => '',
|
433 |
+
'download' => '',
|
434 |
+
'download_style' => '',
|
435 |
+
'download_text' => 'Click here to download the video',
|
436 |
+
'playsinline' => '',
|
437 |
+
'language' => '',
|
438 |
+
);
|
439 |
+
|
440 |
+
return $default;
|
441 |
+
|
442 |
+
}
|
443 |
+
|
444 |
+
/**
|
445 |
+
* Function to get list options
|
446 |
+
*
|
447 |
+
* Return lists. It's in a seperate function in case any further shared
|
448 |
+
* functionality needs to be added.
|
449 |
+
*
|
450 |
+
* @param string $list List number.
|
451 |
+
* @return array Options array.
|
452 |
+
*/
|
453 |
+
function ye_get_list( $list ) {
|
454 |
+
|
455 |
+
$options = get_option( 'youtube_embed_list' . $list );
|
456 |
+
|
457 |
+
// If there is no list set up, set to default values and save.
|
458 |
+
|
459 |
+
if ( ! is_array( $options ) ) {
|
460 |
+
$options = ye_set_list_defaults( $list );
|
461 |
+
$options['default'] = true;
|
462 |
+
} else {
|
463 |
+
$options['default'] = false;
|
464 |
+
}
|
465 |
+
|
466 |
+
return $options;
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Function to set default list options
|
471 |
+
*
|
472 |
+
* Looks up list options, based on passed number of lists.
|
473 |
+
* If any options are missing, set default values
|
474 |
+
*
|
475 |
+
* @param string $lists Number of lists.
|
476 |
+
*/
|
477 |
+
function ye_set_list( $lists ) {
|
478 |
+
|
479 |
+
$list = 1;
|
480 |
+
while ( $list <= $lists ) {
|
481 |
+
|
482 |
+
$options = get_option( 'youtube_embed_list' . $list );
|
483 |
+
|
484 |
+
// Only process if array exists.
|
485 |
+
|
486 |
+
if ( is_array( $options ) ) {
|
487 |
+
|
488 |
+
// Because of upgrading, check each option - if not set, apply default.
|
489 |
+
|
490 |
+
$default_array = ye_set_list_defaults( $list );
|
491 |
+
|
492 |
+
// Merge the two arrays.
|
493 |
+
|
494 |
+
$new_options = array_merge( $default_array, $options );
|
495 |
+
|
496 |
+
// Because I've changed the variable name from name to list_name, convert any with the old name.
|
497 |
+
|
498 |
+
if ( isset( $new_options['name'] ) ) {
|
499 |
+
$new_options['list_name'] = $new_options['name'];
|
500 |
+
unset( $new_options['name'] );
|
501 |
+
}
|
502 |
+
|
503 |
+
// Update the options, if changed, and return the result.
|
504 |
+
|
505 |
+
if ( $options != $new_options ) {
|
506 |
+
update_option( 'youtube_embed_list' . $list, $new_options );
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
$list++;
|
511 |
+
}
|
512 |
+
}
|
513 |
+
|
514 |
+
/**
|
515 |
+
* Function to set initial list default options
|
516 |
+
*
|
517 |
+
* Sets default values for a list
|
518 |
+
*
|
519 |
+
* @param string $list List number.
|
520 |
+
* @return array List array.
|
521 |
+
*/
|
522 |
+
function ye_set_list_defaults( $list ) {
|
523 |
+
|
524 |
+
$default = array(
|
525 |
+
'list_name' => 'List ' . $list,
|
526 |
+
'list' => '',
|
527 |
+
);
|
528 |
+
|
529 |
+
return $default;
|
530 |
+
}
|
531 |
+
|
532 |
+
/**
|
533 |
+
* Output timing
|
534 |
+
*
|
535 |
+
* Used by the author for testing purposes
|
536 |
+
*
|
537 |
+
* @param string $checkpoint The last time.
|
538 |
+
* @param string $name The name of the checkpoint.
|
539 |
+
* @return string New checkpoint.
|
540 |
+
*/
|
541 |
+
function ye_timer( $checkpoint, $name ) {
|
542 |
+
|
543 |
+
$timing = ( microtime( true ) - $checkpoint );
|
544 |
+
|
545 |
+
echo '<p>' . $name . ': ' . ( $timing * 1000000 ) . ' microseconds.</p>';
|
546 |
+
|
547 |
+
return microtime( true );
|
548 |
+
|
549 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/shortcodes.php
CHANGED
@@ -1,352 +1,429 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Shortcodes
|
4 |
-
*
|
5 |
-
* Define the various shortcodes
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
-
* @
|
19 |
-
*
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
*
|
35 |
-
*
|
36 |
-
*
|
37 |
-
*
|
38 |
-
* @
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
*
|
59 |
-
*
|
60 |
-
*
|
61 |
-
*
|
62 |
-
* @
|
63 |
-
*
|
64 |
-
* @
|
65 |
-
* @
|
66 |
-
* @
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
$
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
*
|
227 |
-
*
|
228 |
-
*
|
229 |
-
*
|
230 |
-
* @
|
231 |
-
*
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
*
|
297 |
-
*
|
298 |
-
*
|
299 |
-
*
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
*
|
318 |
-
*
|
319 |
-
*
|
320 |
-
*
|
321 |
-
* @
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Shortcodes
|
4 |
+
*
|
5 |
+
* Define the various shortcodes
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Default Video shortcode
|
12 |
+
*
|
13 |
+
* Main [youtube] shortcode to display video
|
14 |
+
*
|
15 |
+
* @uses ye_video_shortcode Action the shortcode parameters
|
16 |
+
*
|
17 |
+
* @param string $paras Shortcode parameters.
|
18 |
+
* @param string $content Shortcode content.
|
19 |
+
* @return string YouTube embed code.
|
20 |
+
*/
|
21 |
+
function ye_video_shortcode_default( $paras = '', $content = '' ) {
|
22 |
+
|
23 |
+
return do_shortcode( ye_video_shortcode( $paras, $content ) );
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
add_shortcode( 'youtube', 'ye_video_shortcode_default' );
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Alternative Video shortcode 1
|
31 |
+
*
|
32 |
+
* 1st alternative shortcode to display video
|
33 |
+
*
|
34 |
+
* @uses ye_video_shortcode Action the shortcode parameters
|
35 |
+
*
|
36 |
+
* @param string $paras Shortcode parameters.
|
37 |
+
* @param string $content Shortcode content.
|
38 |
+
* @return string YouTube embed code.
|
39 |
+
*/
|
40 |
+
function ye_video_shortcode_alt( $paras = '', $content = '' ) {
|
41 |
+
|
42 |
+
return do_shortcode( ye_video_shortcode( $paras, $content, '', true ) );
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
$shortcode = ye_get_shortcode();
|
47 |
+
|
48 |
+
if ( isset( $shortcode ) && '' != $shortcode ) {
|
49 |
+
add_shortcode( $shortcode, 'ye_video_shortcode_alt' );
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Video shortcode
|
54 |
+
*
|
55 |
+
* Use shortcode parameters to embed a YouTube video or playlist
|
56 |
+
*
|
57 |
+
* @uses ye_get_embed_type Get the embed type.
|
58 |
+
* @uses ye_set_autohide Get the autohide parameter.
|
59 |
+
* @uses ye_get_general_defaults Set default options.
|
60 |
+
* @uses ye_generate_youtube_code Generate the embed code.
|
61 |
+
*
|
62 |
+
* @param string $paras Shortcode parameters.
|
63 |
+
* @param string $content Shortcode content.
|
64 |
+
* @param string $callback REDUNDANT.
|
65 |
+
* @param string $alt_shortcode The number of the alternative shortcode used.
|
66 |
+
* @return string YouTube embed code.
|
67 |
+
*/
|
68 |
+
function ye_video_shortcode( $paras = '', $content = '', $callback = '', $alt_shortcode = false ) {
|
69 |
+
|
70 |
+
extract(
|
71 |
+
shortcode_atts(
|
72 |
+
array(
|
73 |
+
'width' => '',
|
74 |
+
'height' => '',
|
75 |
+
'fullscreen' => '',
|
76 |
+
'related' => '',
|
77 |
+
'autoplay' => '',
|
78 |
+
'loop' => '',
|
79 |
+
'start' => '',
|
80 |
+
'info' => '',
|
81 |
+
'annotation' => '',
|
82 |
+
'cc' => '',
|
83 |
+
'cc_lang' => '',
|
84 |
+
'language' => '',
|
85 |
+
'style' => '',
|
86 |
+
'stop' => '',
|
87 |
+
'disablekb' => '',
|
88 |
+
'ratio' => '',
|
89 |
+
'controls' => '',
|
90 |
+
'profile' => '',
|
91 |
+
'id' => '',
|
92 |
+
'url' => '',
|
93 |
+
'rel' => '',
|
94 |
+
'fs' => '',
|
95 |
+
'cc_load_policy' => '',
|
96 |
+
'iv_load_policy' => '',
|
97 |
+
'showinfo' => '',
|
98 |
+
'youtubeurl' => '',
|
99 |
+
'template' => '',
|
100 |
+
'list' => '',
|
101 |
+
'color' => '',
|
102 |
+
'dynamic' => '',
|
103 |
+
'responsive' => '',
|
104 |
+
'h' => '',
|
105 |
+
'w' => '',
|
106 |
+
'search' => '',
|
107 |
+
'user' => '',
|
108 |
+
'modest' => '',
|
109 |
+
'playsinline' => '',
|
110 |
+
'lazyload' => '',
|
111 |
+
),
|
112 |
+
$paras
|
113 |
+
)
|
114 |
+
);
|
115 |
+
|
116 |
+
// If no profile specified and an alternative shortcode used, get that shortcodes default profile.
|
117 |
+
|
118 |
+
if ( ( '' == $profile ) && ( $alt_shortcode ) ) {
|
119 |
+
|
120 |
+
// Get general options.
|
121 |
+
|
122 |
+
$options = ye_get_general_defaults();
|
123 |
+
$profile = $options['alt_profile'];
|
124 |
+
}
|
125 |
+
|
126 |
+
// If an alternative field is set, use it.
|
127 |
+
|
128 |
+
if ( ( '' != $id ) && ( '' == $content ) ) {
|
129 |
+
$content = $id;
|
130 |
+
}
|
131 |
+
if ( ( '' != $url ) && ( '' == $content ) ) {
|
132 |
+
$content = $url;
|
133 |
+
}
|
134 |
+
if ( ( '' != $youtubeurl ) && ( '' == $content ) ) {
|
135 |
+
$content = $youtubeurl;
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( ( '' != $h ) && ( '' == $height ) ) {
|
139 |
+
$height = $h;
|
140 |
+
}
|
141 |
+
if ( ( '' != $w ) && ( '' == $width ) ) {
|
142 |
+
$width = $w;
|
143 |
+
}
|
144 |
+
|
145 |
+
if ( ( '' != $rel ) && ( '' == $related ) ) {
|
146 |
+
$related = $rel;
|
147 |
+
}
|
148 |
+
if ( ( '' != $fs ) && ( '' == $fullscreen ) ) {
|
149 |
+
$fullscreen = $fs;
|
150 |
+
}
|
151 |
+
if ( ( '' != $cc_load_policy ) && ( '' == $cc ) ) {
|
152 |
+
$cc = $cc_load_policy;
|
153 |
+
}
|
154 |
+
if ( ( '' != $iv_load_policy ) && ( '' == $annotation ) ) {
|
155 |
+
$annotation = $iv_load_policy;
|
156 |
+
}
|
157 |
+
if ( ( '' != $showinfo ) && ( '' == $info ) ) {
|
158 |
+
$info = $showinfo;
|
159 |
+
}
|
160 |
+
|
161 |
+
// If ID was not passed in the content and the first parameter is set, assume that to be the ID.
|
162 |
+
|
163 |
+
if ( ( '' == $content ) && ( '' != $paras[0] ) ) {
|
164 |
+
$content = $paras[0];
|
165 |
+
if ( ( ':' == substr( $content, 0, 1 ) ) || ( '=' == substr( $content, 0, 1 ) ) ) {
|
166 |
+
$content = substr( $content, 1 );
|
167 |
+
}
|
168 |
+
|
169 |
+
if ( array_key_exists( 1, $paras ) ) {
|
170 |
+
if ( '' != $paras[1] ) {
|
171 |
+
$width = $paras[1];
|
172 |
+
}
|
173 |
+
}
|
174 |
+
if ( array_key_exists( 2, $paras ) ) {
|
175 |
+
if ( '' != $paras[2] ) {
|
176 |
+
$height = $paras[2];
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
// If no responsive parameter specified use the deprecated dynamic parameter instead.
|
182 |
+
|
183 |
+
if ( '' == $responsive ) {
|
184 |
+
$responsive = $dynamic;
|
185 |
+
}
|
186 |
+
|
187 |
+
// Create YouTube code.
|
188 |
+
|
189 |
+
$array = array(
|
190 |
+
'id' => $content,
|
191 |
+
'width' => $width,
|
192 |
+
'height' => $height,
|
193 |
+
'fullscreen' => ye_convert( $fullscreen ),
|
194 |
+
'related' => ye_convert( $related ),
|
195 |
+
'autoplay' => ye_convert( $autoplay ),
|
196 |
+
'loop' => ye_convert( $loop ),
|
197 |
+
'start' => $start,
|
198 |
+
'info' => ye_convert( $info ),
|
199 |
+
'annotation' => ye_convert_3( $annotation ),
|
200 |
+
'cc' => ye_convert( $cc ),
|
201 |
+
'style' => $style,
|
202 |
+
'stop' => $stop,
|
203 |
+
'disablekb' => ye_convert( $disablekb ),
|
204 |
+
'ratio' => $ratio,
|
205 |
+
'controls' => $controls,
|
206 |
+
'profile' => $profile,
|
207 |
+
'list_style' => $list,
|
208 |
+
'template' => $template,
|
209 |
+
'color' => $color,
|
210 |
+
'responsive' => ye_convert( $responsive ),
|
211 |
+
'search' => ye_convert( $search ),
|
212 |
+
'user' => ye_convert( $user ),
|
213 |
+
'modest' => ye_convert( $modest ),
|
214 |
+
'playsinline' => ye_convert( $playsinline ),
|
215 |
+
'cc_lang' => $cc_lang,
|
216 |
+
'language' => $language,
|
217 |
+
'lazyload' => ye_convert( $lazyload ),
|
218 |
+
);
|
219 |
+
|
220 |
+
$youtube_code = ye_generate_youtube_code( $array );
|
221 |
+
|
222 |
+
return apply_filters( 'a3_lazy_load_html', do_shortcode( $youtube_code ) );
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Return a thumbnail URL
|
227 |
+
*
|
228 |
+
* Shortcode to return the URL for a thumbnail
|
229 |
+
*
|
230 |
+
* @uses ye_generate_thumbnail_code Generate the thumbnail code.
|
231 |
+
*
|
232 |
+
* @param string $paras Shortcode parameters.
|
233 |
+
* @param string $content Shortcode content.
|
234 |
+
* @return string YouTube thumbnail code.
|
235 |
+
*/
|
236 |
+
function ye_thumbnail_sc( $paras = '', $content = '' ) {
|
237 |
+
|
238 |
+
extract(
|
239 |
+
shortcode_atts(
|
240 |
+
array(
|
241 |
+
'style' => '',
|
242 |
+
'class' => '',
|
243 |
+
'rel' => '',
|
244 |
+
'target' => '',
|
245 |
+
'width' => '',
|
246 |
+
'height' => '',
|
247 |
+
'alt' => '',
|
248 |
+
'version' => '',
|
249 |
+
'nolink' => '',
|
250 |
+
),
|
251 |
+
$paras
|
252 |
+
)
|
253 |
+
);
|
254 |
+
|
255 |
+
$array = array(
|
256 |
+
'id' => $content,
|
257 |
+
'style' => $style,
|
258 |
+
'class' => $class,
|
259 |
+
'rel' => $rel,
|
260 |
+
'target' => $target,
|
261 |
+
'width' => $width,
|
262 |
+
'height' => $height,
|
263 |
+
'alt' => $alt,
|
264 |
+
'version' => $version,
|
265 |
+
'nolink' => $nolink,
|
266 |
+
);
|
267 |
+
|
268 |
+
return do_shortcode( ye_generate_thumbnail_code( $array ) );
|
269 |
+
|
270 |
+
}
|
271 |
+
|
272 |
+
add_shortcode( 'youtube_thumb', 'ye_thumbnail_sc' );
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Video Information Shortcode
|
276 |
+
*
|
277 |
+
* Shortcode to return video information
|
278 |
+
*
|
279 |
+
* @uses ye_generate_vinfo_code Generate the video information code
|
280 |
+
*
|
281 |
+
* @param string $paras Shortcode parameters.
|
282 |
+
* @param string $content Shortcode content.
|
283 |
+
* @return string Video information code.
|
284 |
+
*/
|
285 |
+
function ye_vinfo_sc( $paras = '', $content = '' ) {
|
286 |
+
|
287 |
+
extract( shortcode_atts( array( 'id' => '' ), $paras ) );
|
288 |
+
|
289 |
+
return do_shortcode( ye_generate_vinfo_code( $id, $content ) );
|
290 |
+
|
291 |
+
}
|
292 |
+
|
293 |
+
add_shortcode( 'vinfo', 'ye_vinfo_sc' );
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Short URL shortcode
|
297 |
+
*
|
298 |
+
* Generate a short URL for a YouTube video
|
299 |
+
*
|
300 |
+
* @uses ye_generate_shorturl_code Generate the code.
|
301 |
+
*
|
302 |
+
* @param string $paras Shortcode parameters.
|
303 |
+
* @param string $content Shortcode content.
|
304 |
+
* @return string YouTube short URL code.
|
305 |
+
*/
|
306 |
+
function ye_shorturl_sc( $paras = '', $content = '' ) {
|
307 |
+
|
308 |
+
extract( shortcode_atts( array( 'id' => '' ), $paras ) );
|
309 |
+
|
310 |
+
return do_shortcode( ye_generate_shorturl_code( $id ) );
|
311 |
+
|
312 |
+
}
|
313 |
+
|
314 |
+
add_shortcode( 'youtube_url', 'ye_shorturl_sc' );
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Download shortcode
|
318 |
+
*
|
319 |
+
* Generate a short URL for a YouTube video
|
320 |
+
*
|
321 |
+
* @uses ye_generate_download_code Generate the download code.
|
322 |
+
*
|
323 |
+
* @param string $paras Shortcode parameters.
|
324 |
+
* @param string $content Shortcode content.
|
325 |
+
* @return string YouTube download link.
|
326 |
+
*/
|
327 |
+
function ye_video_download( $paras = '', $content = '' ) {
|
328 |
+
|
329 |
+
extract( shortcode_atts( array( 'id' => '' ), $paras ) );
|
330 |
+
|
331 |
+
if ( '' == $id ) {
|
332 |
+
return do_shortcode( ye_error( __( 'No YouTube ID was found.', 'youtube-embed' ) ) );
|
333 |
+
}
|
334 |
+
|
335 |
+
// Extract the ID if a full URL has been specified.
|
336 |
+
|
337 |
+
$id = ye_extract_id( $id );
|
338 |
+
|
339 |
+
// Extract the API data.
|
340 |
+
|
341 |
+
$data = ye_get_api_data( $id );
|
342 |
+
|
343 |
+
if ( 'v' != $data['type'] || ! $data['valid'] ) {
|
344 |
+
|
345 |
+
// translators: %s: the YouTube video ID.
|
346 |
+
return do_shortcode( ye_error( sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) ) );
|
347 |
+
|
348 |
+
}
|
349 |
+
|
350 |
+
// Get the download code.
|
351 |
+
|
352 |
+
$link = ye_generate_download_code( $id );
|
353 |
+
|
354 |
+
// Now return the HTML.
|
355 |
+
|
356 |
+
return do_shortcode( $link );
|
357 |
+
}
|
358 |
+
|
359 |
+
add_shortcode( 'download_video', 'ye_video_download' );
|
360 |
+
|
361 |
+
/**
|
362 |
+
* Convert input to a 1 or 3 equivalent
|
363 |
+
*
|
364 |
+
* Function to convert a Yes or No input to an equivalent 1 or 3 output
|
365 |
+
*
|
366 |
+
* @uses ye_yes_or_no Convert input to a true or false equivalent.
|
367 |
+
*
|
368 |
+
* @param string $input Input, usually Yes or No.
|
369 |
+
* @return string 1, 3 or blank, depending on input.
|
370 |
+
*/
|
371 |
+
function ye_convert_3( $input ) {
|
372 |
+
|
373 |
+
$input = ye_yes_or_no( $input );
|
374 |
+
$output = '';
|
375 |
+
if ( true === $input ) {
|
376 |
+
$output = '1';
|
377 |
+
}
|
378 |
+
if ( false === $input ) {
|
379 |
+
$output = '3';
|
380 |
+
}
|
381 |
+
|
382 |
+
return $output;
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Convert input to True or False (1.0)
|
387 |
+
*
|
388 |
+
* Return true or false, depending on the input. Possible inputs are Yes, No, 0, 1, True,
|
389 |
+
* False, On, Off
|
390 |
+
*
|
391 |
+
* @param string $input Value passed for checking.
|
392 |
+
* @return string Blank string or boolean true, false.
|
393 |
+
*/
|
394 |
+
function ye_yes_or_no( $input = '' ) {
|
395 |
+
|
396 |
+
$input = strtolower( $input );
|
397 |
+
if ( ( true === $input ) || ( 'true' == $input ) || ( '1' == $input ) || ( 'yes' == $input ) || ( 'on' == $input ) ) {
|
398 |
+
return true;
|
399 |
+
}
|
400 |
+
if ( ( false === $input ) || ( 'false' == $input ) || ( '0' == $input ) || ( 'no' == $input ) || ( 'off' == $input ) ) {
|
401 |
+
return false;
|
402 |
+
}
|
403 |
+
|
404 |
+
return '';
|
405 |
+
}
|
406 |
+
|
407 |
+
/**
|
408 |
+
* Convert autohide parameter
|
409 |
+
*
|
410 |
+
* Convert autohide text value to a numeric equivalent
|
411 |
+
*
|
412 |
+
* @param string $autohide Autohide parameter value.
|
413 |
+
* @return string Autohide numeric equivalent.
|
414 |
+
*/
|
415 |
+
function ye_set_autohide( $autohide ) {
|
416 |
+
|
417 |
+
$autohide = strtolower( $autohide );
|
418 |
+
if ( 'no' == $autohide ) {
|
419 |
+
$autohide = '0';
|
420 |
+
}
|
421 |
+
if ( 'yes' == $autohide ) {
|
422 |
+
$autohide = '1';
|
423 |
+
}
|
424 |
+
if ( 'fade' == $autohide ) {
|
425 |
+
$autohide = '2';
|
426 |
+
}
|
427 |
+
|
428 |
+
return $autohide;
|
429 |
+
}
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: embed, insert, video, youtube
|
|
5 |
Requires at least: 4.6
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 5.3
|
8 |
-
Stable tag: 5.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -42,15 +42,26 @@ To add a video to a post or page simply use the shortcode `[[youtube]video[/yout
|
|
42 |
|
43 |
If you're not sure what the video ID is, please head to the FAQ section where it's explained in greater detail!
|
44 |
|
45 |
-
Within the administration area, click on the
|
46 |
|
47 |
Although this document contains a lot of information more is provided on the various administration pages. Whilst on the administration pages, click on the "Help" button in the top right for some useful tips and links. If anything isn't covered and you're unsure of what it does please ask [on the forum](https://wordpress.org/support/plugin/youtube-embed "WordPress Plugins Forum").
|
48 |
|
49 |
== 🔑 Creating an API Key ==
|
50 |
|
51 |
-
At the top of the `
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
== Further embedding options ==
|
56 |
|
@@ -88,7 +99,7 @@ Which options are available depends upon the users's set-up (for example, whethe
|
|
88 |
|
89 |
== Alternative Shortcodes ==
|
90 |
|
91 |
-
Within Administration, selecting
|
92 |
|
93 |
There are 2 reasons why you might want to do this...
|
94 |
|
@@ -223,7 +234,7 @@ This would display a 120x90 pixel thumbnail with a clickable link to the origina
|
|
223 |
|
224 |
== Other Settings ==
|
225 |
|
226 |
-
Under the
|
227 |
|
228 |
1. Add Metadata - by default, RDFa metadata is added to video output. This can be switched on or off as required (see the FAQs for more information about metadata usage).
|
229 |
2. Feed - videos will not appear in feeds so use this option to decide whether you want them to be converted to links and/or thumbnails.
|
@@ -315,6 +326,13 @@ Before reporting it please bear in mind that this plugin uses the standard YouTu
|
|
315 |
|
316 |
🔢 [Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning")
|
317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
= 5.1.1 =
|
319 |
* Enhancement: Added extra plugin meta
|
320 |
* Bug: The URL separator was not always correct - it still seemed to work but it was sloppy
|
@@ -543,5 +561,5 @@ Before reporting it please bear in mind that this plugin uses the standard YouTu
|
|
543 |
|
544 |
== Upgrade Notice ==
|
545 |
|
546 |
-
= 5.
|
547 |
-
*
|
5 |
Requires at least: 4.6
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 5.3
|
8 |
+
Stable tag: 5.2
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
42 |
|
43 |
If you're not sure what the video ID is, please head to the FAQ section where it's explained in greater detail!
|
44 |
|
45 |
+
Within the administration area, click on the Settings menu option and then YouTube Embed to view and edit the generic settings for the plugin. Also under the YouTube Embed menu (see screenshot 1) you can click on the Profiles sub-menu to set the default options which define the output of your videos. Any videos you display (unless overridden by parameters - more on that later) will use the settings from the Profiles screen.
|
46 |
|
47 |
Although this document contains a lot of information more is provided on the various administration pages. Whilst on the administration pages, click on the "Help" button in the top right for some useful tips and links. If anything isn't covered and you're unsure of what it does please ask [on the forum](https://wordpress.org/support/plugin/youtube-embed "WordPress Plugins Forum").
|
48 |
|
49 |
== 🔑 Creating an API Key ==
|
50 |
|
51 |
+
At the top of the `YouTube Embed Settings` administration screen is an option to specify an API key. This is optional but many of the features of this plugin - including accurate video information being added to the metadata - will not be available without it. Thankfully an API key is easy to get and is free.
|
52 |
+
|
53 |
+
1. Head to the [YouTube Developers Console](https://console.developers.google.com/cloud-resource-manager "Developers Console")
|
54 |
+
2. Click on CREATE PROJECT
|
55 |
+
3. Once created, head into it
|
56 |
+
4. In the APIs box, click on "Go to APIs overview"
|
57 |
+
5. Click on "ENABLE APIS AND SERVICES" at the top of the screen
|
58 |
+
6. You can now choose your API - click on YouTube Data API v3
|
59 |
+
7. Click the "ENABLE" button
|
60 |
+
8. Click on "CREATE CREDENTIALS"
|
61 |
+
9. On the drop-downs, choose the API we selected before, "Web browser and "Public data"
|
62 |
+
10. You will now be presented with your API key
|
63 |
+
|
64 |
+
The API key can now be pasted into the settings in WP Admin.
|
65 |
|
66 |
== Further embedding options ==
|
67 |
|
99 |
|
100 |
== Alternative Shortcodes ==
|
101 |
|
102 |
+
Within Administration, selecting Settings -> YouTube Embed will provide a list of generic options. One option is named `Alternative Shortcode` and allows you to specify another shortcode that will work exactly the same as the standard shortcode of `[[youtube]]`.
|
103 |
|
104 |
There are 2 reasons why you might want to do this...
|
105 |
|
234 |
|
235 |
== Other Settings ==
|
236 |
|
237 |
+
Under the Settings menu s a sub-menu named YouTube Embed. Select this and find the section named Embedding. There are 2 options here that have not been covered already...
|
238 |
|
239 |
1. Add Metadata - by default, RDFa metadata is added to video output. This can be switched on or off as required (see the FAQs for more information about metadata usage).
|
240 |
2. Feed - videos will not appear in feeds so use this option to decide whether you want them to be converted to links and/or thumbnails.
|
326 |
|
327 |
🔢 [Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning")
|
328 |
|
329 |
+
= 5.2 =
|
330 |
+
* Enhancement: What have I been doing during the pandemic? Picking through this code and resolving coding standards. Sigh. There's a LOT. Not all are done but will be in future updates but, for now, the majority are. Based on the amount of code I've had to change, I'm worried I've broken something. But, you know, every day's a school day and this has taught me a LOT
|
331 |
+
* Enhancement: Look, I know I keep moving it but the plugin settings really shouldn't be anywhere other than under the Settings menu. So I've moved it back there
|
332 |
+
* Enhancement: Added native lazy loading to the videos. I'll maybe look to add it to the thumbnails at a later time - does anybody want that?
|
333 |
+
* Enhancement: I've improved the cache key generation. But, what this does mean, is that updating will cause all your YouTube Embed caches to clear. All your cache are belong to us
|
334 |
+
* Enhancement: Clarified the API sign-up process in the README
|
335 |
+
|
336 |
= 5.1.1 =
|
337 |
* Enhancement: Added extra plugin meta
|
338 |
* Bug: The URL separator was not always correct - it still seemed to work but it was sloppy
|
561 |
|
562 |
== Upgrade Notice ==
|
563 |
|
564 |
+
= 5.2 =
|
565 |
+
* Native lazy loading is a go! And lots of code quality tweaks that you won't notice unless you crack open the source code...
|
uninstall.php
CHANGED
@@ -1,58 +1,59 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Uninstaller
|
4 |
-
*
|
5 |
-
* Uninstall the plugin by removing any options from the database
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
$loop
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
$loop
|
42 |
-
|
43 |
-
|
44 |
-
}
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
delete_option( '
|
50 |
-
delete_option( '
|
51 |
-
delete_option( '
|
52 |
-
delete_option( '
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
$
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Uninstaller
|
4 |
+
*
|
5 |
+
* Uninstall the plugin by removing any options from the database
|
6 |
+
*
|
7 |
+
* @package youtube-embed
|
8 |
+
*/
|
9 |
+
|
10 |
+
// If the uninstall was not called by WordPress, exit.
|
11 |
+
|
12 |
+
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
13 |
+
exit();
|
14 |
+
}
|
15 |
+
|
16 |
+
// Read the general options (will tell us how many profile and list options there should be.
|
17 |
+
|
18 |
+
$options = get_option( 'youtube_embed_general' );
|
19 |
+
|
20 |
+
// If the general options existed, delete it!
|
21 |
+
|
22 |
+
if ( is_array( $options ) ) {
|
23 |
+
|
24 |
+
delete_option( 'youtube_embed_general' );
|
25 |
+
|
26 |
+
// If the number of profiles field exists, delete each one in turn.
|
27 |
+
|
28 |
+
if ( isset( $options['profile_no'] ) ) {
|
29 |
+
$loop = 0;
|
30 |
+
while ( $loop <= $options['profile_no'] ) {
|
31 |
+
delete_option( 'youtube_embed_profile' . $loop );
|
32 |
+
$loop ++;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
// If the number of lists field exists, delete each one in turn.
|
37 |
+
|
38 |
+
if ( isset( $options['list_no'] ) ) {
|
39 |
+
$loop = 1;
|
40 |
+
while ( $loop <= $options['list_no'] ) {
|
41 |
+
delete_option( 'youtube_embed_list' . $loop );
|
42 |
+
$loop ++;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
// Delete all other options.
|
48 |
+
|
49 |
+
delete_option( 'youtube_embed_general' );
|
50 |
+
delete_option( 'youtube_embed_shortcode' );
|
51 |
+
delete_option( 'youtube_embed_shortcode_admin' );
|
52 |
+
delete_option( 'youtube_embed_shortcode_site' );
|
53 |
+
delete_option( 'youtube_embed_version' );
|
54 |
+
|
55 |
+
// Remove any transient data.
|
56 |
+
|
57 |
+
global $wpdb;
|
58 |
+
$sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_youtubeembed_%' OR option_name LIKE '_transient_timeout_youtubeembed_%'";
|
59 |
+
$wipe = $wpdb->query( $sql );
|
youtube-embed.php
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
Plugin Name: YouTube Embed
|
4 |
-
Plugin URI: https://github.com/dartiss/youtube-embed
|
5 |
-
Description: An incredibly fast, simple, yet powerful, method of embedding YouTube videos into your WordPress site.
|
6 |
-
Version: 5.
|
7 |
-
Author: dartiss
|
8 |
-
Author URI: https://artiss.blog
|
9 |
-
Text Domain: youtube-embed
|
10 |
-
|
11 |
-
@package youtube-embed
|
12 |
-
*/
|
13 |
-
|
14 |
-
define( '
|
15 |
-
|
16 |
-
$functions_dir = plugin_dir_path( __FILE__ ) . 'includes/';
|
17 |
-
|
18 |
-
// Include all the various functions.
|
19 |
-
|
20 |
-
require_once $functions_dir . 'shared-functions.php'; // Shared routines.
|
21 |
-
|
22 |
-
require_once $functions_dir . 'add-scripts.php'; // Add various scripts.
|
23 |
-
|
24 |
-
require_once $functions_dir . 'generate-embed-code.php'; // Generate YouTube embed code.
|
25 |
-
|
26 |
-
require_once $functions_dir . 'generate-other-code.php'; // Generate download & short URLs & thumbnails.
|
27 |
-
|
28 |
-
require_once $functions_dir . 'generate-widgets.php'; // Generate widgets.
|
29 |
-
|
30 |
-
require_once $functions_dir . 'api-access.php'; // Fetch video data from YouTube API.
|
31 |
-
|
32 |
-
require_once $functions_dir . 'caching.php'; // Data caching functions.
|
33 |
-
|
34 |
-
require_once $functions_dir . 'shortcodes.php'; // Shortcodes.
|
35 |
-
|
36 |
-
require_once $functions_dir . 'admin-config.php'; // Administration configuration.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
Plugin Name: YouTube Embed
|
4 |
+
Plugin URI: https://github.com/dartiss/youtube-embed
|
5 |
+
Description: An incredibly fast, simple, yet powerful, method of embedding YouTube videos into your WordPress site.
|
6 |
+
Version: 5.2
|
7 |
+
Author: dartiss
|
8 |
+
Author URI: https://artiss.blog
|
9 |
+
Text Domain: youtube-embed
|
10 |
+
|
11 |
+
@package youtube-embed
|
12 |
+
*/
|
13 |
+
|
14 |
+
define( 'YOUTUBE_EMBED_VERSION', '5.2' );
|
15 |
+
|
16 |
+
$functions_dir = plugin_dir_path( __FILE__ ) . 'includes/';
|
17 |
+
|
18 |
+
// Include all the various functions.
|
19 |
+
|
20 |
+
require_once $functions_dir . 'shared-functions.php'; // Shared routines.
|
21 |
+
|
22 |
+
require_once $functions_dir . 'add-scripts.php'; // Add various scripts.
|
23 |
+
|
24 |
+
require_once $functions_dir . 'generate-embed-code.php'; // Generate YouTube embed code.
|
25 |
+
|
26 |
+
require_once $functions_dir . 'generate-other-code.php'; // Generate download & short URLs & thumbnails.
|
27 |
+
|
28 |
+
require_once $functions_dir . 'generate-widgets.php'; // Generate widgets.
|
29 |
+
|
30 |
+
require_once $functions_dir . 'api-access.php'; // Fetch video data from YouTube API.
|
31 |
+
|
32 |
+
require_once $functions_dir . 'caching.php'; // Data caching functions.
|
33 |
+
|
34 |
+
require_once $functions_dir . 'shortcodes.php'; // Shortcodes.
|
35 |
+
|
36 |
+
require_once $functions_dir . 'admin-config.php'; // Administration configuration.
|