YouTube Embed - Version 5.2

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 Icon 128x128 YouTube Embed
Version 5.2
Comparing to
See all releases

Code changes from version 5.1.1 to 5.2

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 youtube-embed
8
- */
9
-
10
- /**
11
- * Plugin initialisation
12
- *
13
- * Perform various actions upon initialisation of the plugin
14
- *
15
- * @since 2.5.5
16
- */
17
-
18
- /**
19
- * Upgrade checks
20
- *
21
- * Check if plugin has upgraded and, if so, perform further actions
22
- *
23
- * @since 5.0.1
24
- */
25
-
26
- $version = get_option( 'youtube_embed_version' );
27
-
28
- if ( $version != youtube_embed_version ) {
29
-
30
- // Set up default option values (if not already set)
31
-
32
- $options = ye_set_general_defaults();
33
- ye_set_shortcode();
34
- ye_set_list( $options[ 'list_no' ] );
35
- ye_set_profile( $options[ 'profile_no' ] );
36
-
37
- // Update saved version number
38
-
39
- update_option( 'youtube_embed_version', youtube_embed_version );
40
- }
41
-
42
- /**
43
- * Admin initialisation
44
- *
45
- * Switch on shortcodes in widgets, if required
46
- *
47
- * @since 5.0.1
48
- */
49
-
50
- function ye_admin_init() {
51
-
52
- $options = get_option( 'youtube_embed_general' );
53
-
54
- if ( $options[ 'widgets' ] == 1 ) { add_filter( 'widget_text', 'do_shortcode' ); }
55
- }
56
-
57
- add_action( 'admin_init', 'ye_admin_init' );
58
-
59
- /**
60
- * Add scripts to theme
61
- *
62
- * Add styles and scripts to the main theme
63
- *
64
- * @since 2.4
65
- */
66
-
67
- function ye_main_scripts() {
68
-
69
- wp_register_style( 'ye_dynamic', plugins_url( 'css/main.min.css', dirname(__FILE__) ) );
70
-
71
- wp_enqueue_style( 'ye_dynamic' );
72
-
73
- }
74
-
75
- add_action( 'wp_enqueue_scripts', 'ye_main_scripts' );
76
-
77
- /**
78
- * Add CSS to admin
79
- *
80
- * Add stylesheets to the admin screens
81
- *
82
- * @since 2.0
83
- */
84
-
85
- function ye_admin_css() {
86
-
87
- wp_enqueue_style( 'dynamic_video', plugins_url( 'css/admin.min.css', dirname(__FILE__) ));
88
-
89
- }
90
-
91
- add_action( 'admin_print_styles', 'ye_admin_css' );
92
-
93
- /**
94
- * Add option to Admin Bar
95
- *
96
- * Add link to YouTube Embed profile options to Admin Bar.
97
- * With help from http://technerdia.com/1140_wordpress-admin-bar.html
98
- *
99
- * @uses ye_set_general_default Set default options
100
- *
101
- * @since 2.5
102
- */
103
-
104
- function ye_admin_bar_render( $meta = TRUE ) {
105
-
106
- if ( !is_admin() ) {
107
-
108
- $options = ye_get_general_defaults();
109
-
110
- if ( $options[ 'admin_bar' ] != '' ) {
111
-
112
- global $wp_admin_bar;
113
-
114
- if ( !is_user_logged_in() ) { return; }
115
- if ( !is_admin_bar_showing() ) { return; }
116
- if ( !current_user_can( $options[ 'menu_access' ] ) ) { return; }
117
-
118
- $wp_admin_bar -> add_menu( array(
119
- 'id' => 'aye-menu',
120
- 'title' => __( 'YouTube Embed', 'youtube-embed' ) ) );
121
-
122
- $wp_admin_bar -> add_menu( array(
123
- 'parent' => 'aye-menu',
124
- 'id' => 'aye-options',
125
- 'title' => __( 'Options', 'youtube-embed' ),
126
- 'href' => admin_url( 'admin.php?page=ye-general-options' ),
127
- 'meta' => array( 'target' => '_blank' ) ) );
128
-
129
- $wp_admin_bar -> add_menu( array(
130
- 'parent' => 'aye-menu',
131
- 'id' => 'aye-profile',
132
- 'title' => __( 'Profiles', 'youtube-embed' ),
133
- 'href' => admin_url( 'admin.php?page=ye-profile-options' ),
134
- 'meta' => array( 'target' => '_blank' ) ) );
135
-
136
- $wp_admin_bar -> add_menu( array(
137
- 'parent' => 'aye-menu',
138
- 'id' => 'aye-lists',
139
- 'title' => __( 'Lists', 'youtube-embed' ),
140
- 'href' => admin_url( 'admin.php?page=ye-list-options' ),
141
- 'meta' => array( 'target' => '_blank' ) ) );
142
- }
143
- }
144
- }
145
-
146
- add_action( 'admin_bar_menu', 'ye_admin_bar_render', 99 );
147
-
148
- /**
149
- * Add to site header
150
- *
151
- * Perform main site head processing
152
- *
153
- * @uses youtube_embed_head_checks Perform the actual checks
154
- *
155
- * @since 4.1
156
- */
157
-
158
- function youtube_embed_add_to_head() {
159
-
160
- youtube_embed_shortcode_checks( 'site' );
161
-
162
- $options = ye_get_general_defaults();
163
-
164
- if ( $options[ 'script' ] == 'f' ) {
165
-
166
- $tab = "\t";
167
- $newline = "\n";
168
-
169
- echo '<script type="text/javascript" src="' . plugins_url( 'js/jquery.fitvids.js', dirname(__FILE__) ) . '"></script>' . $newline;
170
-
171
- echo '<script>' . $newline;
172
- echo $tab . '$(".youtube-embed").fitVids();' . $newline;
173
- echo '</script>' . $newline;
174
-
175
- }
176
-
177
- if ( $options[ 'script' ] == 'i' ) {
178
- wp_enqueue_script( 'youtube-embed-iframe-resizer', plugins_url( 'js/iframeResizer.min.js', dirname(__FILE__) ) );
179
- }
180
- }
181
-
182
- add_action( 'wp_head', 'youtube_embed_add_to_head' );
183
-
184
- /**
185
- * Admin Head Checks
186
- *
187
- * Perform admin head processing
188
- *
189
- * @uses youtube_embed_head_checks Perform the actual checks
190
- *
191
- * @since 4.1
192
- */
193
-
194
- function youtube_embed_admin_head_checks() {
195
-
196
- youtube_embed_shortcode_checks( 'admin' );
197
-
198
- }
199
-
200
-
201
- add_action( 'admin_head', 'youtube_embed_admin_head_checks' );
202
-
203
- /**
204
- * Shortcode Checking
205
- *
206
- * Check if the shortcode is in use by another plugin. If so, note it
207
- * in the options.
208
- *
209
- * @param string $source Where the checks are coming from
210
- *
211
- * @since 4.1
212
- */
213
-
214
- function youtube_embed_shortcode_checks( $source ) {
215
-
216
- global $shortcode_tags;
217
- if ( isset( $shortcode_tags[ 'youtube' ] ) ) {
218
- $shortcode_usage = $shortcode_tags[ 'youtube' ];
219
- } else {
220
- $shortcode_usage = '';
221
- }
222
-
223
- $shortcode = 1;
224
-
225
- // All is fine
226
-
227
- if ( substr( $shortcode_usage, 0, 19 ) == 'ye_video_shortcode_' ) {
228
-
229
- $shortcode = 0;
230
-
231
- } else {
232
-
233
- // Jetpack is overriding
234
-
235
- if ( $shortcode_usage == 'youtube_shortcode' ) {
236
-
237
- $shortcode = 2;
238
-
239
- } else {
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 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
- * @since 2.0
16
- *
17
- * @param string $links Current links
18
- * @param string $file File in use
19
- * @return string Links, now with settings added
20
- */
21
-
22
- function ye_add_settings_link( $links, $file ) {
23
-
24
- static $this_plugin;
25
-
26
- if ( !$this_plugin ) { $this_plugin = plugin_basename( __FILE__ ); }
27
-
28
- if ( strpos( $file, 'youtube-embed.php' ) !== false ) {
29
- $settings_link = '<a href="admin.php?page=ye-general-options">' . __( 'Settings', 'youtube-embed' ) . '</a>';
30
- array_unshift( $links, $settings_link );
31
- }
32
-
33
- return $links;
34
- }
35
-
36
- add_filter( 'plugin_action_links', 'ye_add_settings_link', 10, 2 );
37
-
38
- /**
39
- * Add meta to plugin details
40
- *
41
- * Add options to plugin meta line
42
- *
43
- * @param string $links Current links.
44
- * @param string $file File in use.
45
- * @return string Links, now with settings added.
46
- */
47
- function ye_set_plugin_meta( $links, $file ) {
48
-
49
- if ( strpos( $file, 'youtube-embed.php' ) !== false ) {
50
-
51
- $links = array_merge( $links, array( '<a href="https://github.com/dartiss/youtube-embed">' . __( 'Github', 'youtube-embed' ) . '</a>' ) );
52
-
53
- $links = array_merge( $links, array( '<a href="https://wordpress.org/support/plugin/youtube-embed">' . __( 'Support', 'youtube-embed' ) . '</a>' ) );
54
-
55
- $links = array_merge( $links, array( '<a href="https://artiss.blog/donate">' . __( 'Donate', 'youtube-embed' ) . '</a>' ) );
56
-
57
- $links = array_merge( $links, array( '<a href="https://wordpress.org/support/plugin/youtube-embed/reviews/#new-post">' . __( 'Write a Review', 'youtube-embed' ) . '&nbsp;⭐️⭐️⭐️⭐️⭐️</a>' ) );
58
- }
59
-
60
- return $links;
61
- }
62
-
63
- add_filter( 'plugin_row_meta', 'ye_set_plugin_meta', 10, 2 );
64
-
65
- /**
66
- * Admin Screen Initialisation
67
- *
68
- * Set up admin menu and submenu options
69
- *
70
- * @since 2.0
71
- *
72
- * @uses ye_contextual_help_type Work out help type
73
- */
74
-
75
- function ye_menu_initialise() {
76
-
77
- // Get level access for menus
78
-
79
- $options = ye_get_general_defaults();
80
-
81
- $menu_access = $options[ 'menu_access' ];
82
-
83
- // Add main admin option
84
-
85
- $menu_icon = 'dashicons-video-alt3';
86
-
87
- add_menu_page( __( 'About YouTube Embed', 'youtube-embed' ), __( 'YouTube Embed', 'youtube-embed' ), $menu_access, 'ye-profile-options', 'ye_profile_options', $menu_icon, 12 );
88
-
89
- // Add profiles sub-menu
90
-
91
- global $ye_profiles_hook;
92
-
93
- $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' );
94
-
95
- add_action( 'load-' . $ye_profiles_hook, 'ye_add_profiles_help' );
96
-
97
- // Add lists sub-menu
98
-
99
- global $ye_lists_hook;
100
-
101
- $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' );
102
-
103
- add_action( 'load-' . $ye_lists_hook, 'ye_add_lists_help' );
104
-
105
- // If installed, add link to Video Overlay Ads plugin
106
-
107
- if ( function_exists( 'video_overlay_create_menu' ) ) {
108
-
109
- add_submenu_page( 'ye-profile-options', __( 'Video Overlay Ads', 'youtube-embed' ), __( 'Video Overlay Ads', 'youtube-embed' ), 'administrator', 'ye-video-overlay', 'video_overlay_settings_page' );
110
- }
111
-
112
- // If installed, add link to Video SEO
113
-
114
- if ( class_exists( 'wpseo_Video_Sitemap' ) ) {
115
-
116
- add_submenu_page( 'ye-profile-options', __( 'Video SEO', 'youtube-embed' ), __( 'Video SEO', 'youtube-embed' ), 'manage_options', 'ye-wpseo-video', 'wpseo_Video_Sitemap::admin_panel' );
117
-
118
- }
119
-
120
- // Add settings sub-menu
121
-
122
- global $ye_options_hook;
123
-
124
- $ye_options_hook = add_submenu_page( 'ye-profile-options', __( 'General Settings', 'youtube-embed' ), __( 'General Settings', 'youtube-embed' ), $menu_access, 'ye-general-options', 'ye_general_options' );
125
-
126
- add_action( 'load-' . $ye_options_hook, 'ye_add_options_help' );
127
- }
128
-
129
- add_action( 'admin_menu', 'ye_menu_initialise' );
130
-
131
- /**
132
- * Include general options screen
133
- *
134
- * XHTML options screen to prompt and update some general plugin options
135
- *
136
- * @since 2.0
137
- */
138
-
139
- function ye_general_options() {
140
-
141
- include_once( plugin_dir_path( __FILE__ ) . 'options-general.php' );
142
-
143
- }
144
-
145
- /**
146
- * Include profile options screen
147
- *
148
- * XHTML options screen to prompt and update profile options
149
- *
150
- * @since 2.0
151
- */
152
-
153
- function ye_profile_options() {
154
-
155
- include_once( plugin_dir_path( __FILE__ ) . 'options-profiles.php' );
156
-
157
- }
158
-
159
- /**
160
- * Include list options screen
161
- *
162
- * XHTML options screen to prompt and update list options
163
- *
164
- * @since 2.0
165
- */
166
-
167
- function ye_list_options() {
168
-
169
- include_once( plugin_dir_path( __FILE__ ) . 'options-lists.php' );
170
-
171
- }
172
-
173
- /**
174
- * Add Options Help
175
- *
176
- * Add help tab to options screen
177
- *
178
- * @since 2.5
179
- *
180
- * @uses ye_options_help Return help text
181
- */
182
-
183
- function ye_add_options_help() {
184
-
185
- global $ye_options_hook;
186
- $screen = get_current_screen();
187
-
188
- if ( $screen->id != $ye_options_hook ) { return; }
189
-
190
- $screen -> add_help_tab( array( 'id' => 'options-help-tab', 'title' => __( 'Help', 'youtube-embed' ), 'content' => youtube_embed_help( 'options' ) ) );
191
-
192
- $screen -> add_help_tab( array( 'id' => 'options-links-tab', 'title' => __( 'Links', 'youtube-embed' ), 'content' => youtube_embed_help( 'options', 'links' ) ) );
193
- }
194
-
195
- /**
196
- * Add Profiles Help
197
- *
198
- * Add help tab to profiles screen
199
- *
200
- * @since 2.5
201
- *
202
- * @uses ye_profiles_help Return help text
203
- */
204
-
205
- function ye_add_profiles_help() {
206
-
207
- global $ye_profiles_hook;
208
- $screen = get_current_screen();
209
-
210
- if ( $screen->id != $ye_profiles_hook ) { return; }
211
-
212
- $screen -> add_help_tab( array( 'id' => 'profiles-help-tab', 'title' => __( 'Help', 'youtube-embed' ), 'content' => youtube_embed_help( 'profiles' ) ) );
213
-
214
- $screen -> add_help_tab( array( 'id' => 'profiles-links-tab', 'title' => __( 'Links', 'youtube-embed' ), 'content' => youtube_embed_help( 'profiles', 'links' ) ) );
215
- }
216
-
217
- /**
218
- * Add Lists Help
219
- *
220
- * Add help tab to lists screen
221
- *
222
- * @since 2.5
223
- *
224
- * @uses ye_lists_help Return help text
225
- */
226
-
227
- function ye_add_lists_help() {
228
-
229
- global $ye_lists_hook;
230
- $screen = get_current_screen();
231
-
232
- if ( $screen->id != $ye_lists_hook ) { return; }
233
-
234
- $screen -> add_help_tab( array( 'id' => 'lists-help-tab', 'title' => __( 'Help', 'youtube-embed' ), 'content' => youtube_embed_help( 'lists' ) ) );
235
-
236
- $screen -> add_help_tab( array( 'id' => 'lists-links-tab', 'title' => __( 'Links', 'youtube-embed' ), 'content' => youtube_embed_help( 'lists', 'links' ) ) );
237
- }
238
-
239
- /**
240
- * Help Screens
241
- *
242
- * Generate help screen text
243
- *
244
- * @since 4.1
245
- *
246
- * @param string $screen Which help screen to return text for
247
- * @param string $tab Which tab of the help this is for
248
- * @return string Help Text
249
- */
250
-
251
- function youtube_embed_help( $screen, $tab = 'help' ) {
252
-
253
- $text = '';
254
-
255
- if ( $screen == 'options' && $tab == 'help' ) {
256
-
257
- $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>';
258
- }
259
-
260
- if ( $screen == 'profiles' && $tab == 'help' ) {
261
-
262
- $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>';
263
- }
264
-
265
- if ( $screen == 'lists' && $tab == 'help' ) {
266
-
267
- $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>';
268
- }
269
-
270
- $text .= '<p>' . __( 'Remember to click the Save Changes button at the bottom of the screen for any changes to take effect.', 'youtube-embed' ) . '</p>';
271
-
272
- if ( $tab == 'links' ) {
273
-
274
- $text .= '<p><strong>' . __( 'For more information:', 'youtube-embed' ) . '</strong></p>';
275
- $text .= '<p><a href="https://wordpress.org/plugins/youtube-embed/">' . __( 'YouTube Embed Plugin Documentation', 'youtube-embed' ) . '</a></p>';
276
-
277
- if ( $screen != 'lists' ) {
278
- $text .= '<p><a href="https://code.google.com/apis/youtube/player_parameters.html">' . __( 'YouTube Player Documentation', 'youtube-embed' ) . '</a></p>';
279
- }
280
-
281
- if ( $screen == 'options' ) {
282
-
283
- $text .= '<p><a href="https://github.com/davatron5000/FitVids.js">FitVids.js</a></p>';
284
- $text .= '<p><a href="https://github.com/davidjbradshaw/iframe-resizer">iFrame Resizer</a></p>';
285
- }
286
- }
287
-
288
- return $text;
289
- }
290
-
291
- /**
292
- * Show Admin Messages
293
- *
294
- * Display messages on the administration screen
295
- *
296
- * @since 4.1
297
- *
298
- */
299
-
300
- function youtube_embed_admin_messages() {
301
-
302
- $shortcode_site = get_option( 'youtube_embed_shortcode_site' );
303
-
304
- $shortcode_admin = get_option( 'youtube_embed_shortcode_admin' );
305
-
306
- if ( ( $shortcode_admin != 0 ) or ( $shortcode_site != 0 ) ) {
307
-
308
- $options = ye_get_general_defaults();
309
-
310
- if ( $options[ 'prompt' ] == 1 ) {
311
-
312
- if ( $shortcode_site == 3 ) {
313
- $message = __( 'For some reason the shortcode <strong>[youtube]</strong> is not working on the main site' );
314
- }
315
-
316
- $alternative = __( 'An alternative plugin is using the <strong>[youtube]</strong> shortcode' );
317
-
318
- if ( ( $shortcode_admin == 1 ) or ( $shortcode_site == 1 ) ) {
319
- $message = $alternative;
320
- }
321
-
322
- if ( ( $shortcode_admin == 2 ) or ( $shortcode_site == 2 ) ) {
323
- $message = __( $alternative . ', possibly the <a href="admin.php?page=jetpack_modules&activated=true">Shortcode Embeds module</a> in Jetpack' );
324
- }
325
-
326
- echo '<div class="error notice"><p>YouTube Embed: ' . $message . '.</p></div>';
327
- }
328
- }
329
-
330
- }
331
-
332
- add_action( 'admin_notices', 'youtube_embed_admin_messages' );
 
 
 
 
 
 
 
 
 
 
 
 
 
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' ) . '&nbsp;⭐️⭐️⭐️⭐️⭐️</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 Access
4
- *
5
- * Function to access YouTube API for video data
6
- *
7
- * @package youtube-embed
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 ( $playlist == '' ) {
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 ( $cache !== false ) { return $cache; }
 
 
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) == 0 ) {
40
  $valid = false;
41
  } else {
42
  $valid = true;
43
  }
44
  } else {
45
- if ( ( strtolower( substr( $video_id, 0, 2 ) ) == 'pl' && strlen( $video_id ) == 34 ) or ( strlen( $video_id ) == 16 ) or ( $playlist != '' ) ) {
46
  $type = 'p';
47
- if ( $playlist == '' && preg_match( '/[^A-Za-z0-9_-]/', $video_id ) == 1 ) {
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
- 'restricted' => '',
59
- 'title' => get_the_title(),
60
- 'description' => get_the_title(),
61
- 'published' => get_the_date( 'c' ),
62
- 'valid' => $valid,
63
- 'type' => $type,
64
- 'api' => false,
65
- 'thumb_default' => '',
66
- 'thumb_medium' => '',
67
- 'thumb_high' => '',
68
- 'thumb_standard' => '',
69
- 'thumb_maxres' => ''
70
- );
71
-
72
- // Set the default thumbnail URLs
73
-
74
- if ( ( $type == 'v' ) or ( $playlist != '' ) ) {
75
-
76
- $return_data[ 'thumb_default' ] = 'https://i.ytimg.com/vi/' . $video_id . '/default.jpg';
77
- $return_data[ 'thumb_medium' ] = 'https://i.ytimg.com/vi/' . $video_id . '/mqdefault.jpg';
78
- $return_data[ 'thumb_high' ] = 'https://i.ytimg.com/vi/' . $video_id . '/hqdefault.jpg';
79
- $return_data[ 'thumb_standard' ] = 'https://i.ytimg.com/vi/' . $video_id . '/sddefault.jpg';
80
- $return_data[ 'thumb_maxres' ] = 'https://i.ytimg.com/vi/' . $video_id . '/maxresdefault.jpg';
81
 
82
  }
83
 
84
- // If a user defined playlist, go no further
85
 
86
- if ( $playlist != '' ) { return $return_data; }
 
 
87
 
88
- // Get the API key
89
 
90
- if ( $api_key == '' ) {
91
  $options = ye_get_general_defaults();
92
- $api_key = $options[ 'api' ];
93
- if ( $api_key == '' ) { return $return_data; }
 
 
94
  }
95
 
96
- // Get the API results and convert from JSON to a PHP array
97
 
98
- $url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=' . $video_id . '&key=' . $api_key;
99
  $api_data = json_decode( @file_get_contents( $url ), true );
100
- if ( $api_data == '' ) { return $return_data; }
 
 
101
 
102
- if ( !isset( $api_data[ 'items' ][ '0' ] ) ) {
103
 
104
- $url = 'https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&id=' . $video_id . '&key=' . $api_key;
105
  $api_data = json_decode( file_get_contents( $url ), true );
106
- if ( $api_data == '' ) { return $return_data; }
 
 
107
 
108
- if ( isset( $api_data[ 'items' ][ '0' ] ) ) {
109
- $id_found = true;
110
- $return_data[ 'type' ] = 'p';
111
  } else {
112
  $id_found = false;
113
  }
114
  } else {
115
- $id_found = true;
116
- $return_data[ 'type' ] = 'v';
117
  }
118
 
119
- $return_data[ 'api' ] = true; // Show that API data was used
120
 
121
- // Extract out the API data
122
 
123
  if ( $id_found ) {
124
 
125
- $return_data[ 'valid' ] = true;
126
 
127
- // Strip off the first two dimensions of the array
128
 
129
- if ( isset( $api_data[ 'items' ][ '0' ] ) ) { $api_data = $api_data[ 'items' ][ '0' ]; }
130
-
131
- // If set, assign the appropriate API data to the return array
132
-
133
- if ( isset( $api_data[ 'snippet' ][ 'publishedAt' ] ) ) { $return_data[ 'published' ] = $api_data[ 'snippet' ][ 'publishedAt' ]; }
134
 
135
- if ( isset( $api_data[ 'snippet' ][ 'title' ] ) ) { $return_data[ 'title' ] = htmlspecialchars( $api_data[ 'snippet' ][ 'title' ] ); }
136
 
137
- if ( isset( $api_data[ 'snippet' ][ 'description' ] ) ) { $return_data[ 'description' ] = htmlspecialchars( $api_data[ 'snippet' ][ 'description' ] ); }
 
 
138
 
139
- if ( isset( $api_data[ 'contentDetails' ][ 'contentRating' ][ 'ytRating' ] ) ) { $return_data[ 'restricted' ] = true; } else { $return_data[ 'restricted' ] = false; }
 
 
140
 
141
- if ( isset( $api_data[ 'snippet' ][ 'thumbnails' ][ 'default' ][ 'url' ] ) ) { $return_data[ 'thumb_default' ] = $api_data[ 'snippet' ][ 'thumbnails' ][ 'default' ][ 'url' ]; }
142
- if ( isset( $api_data[ 'snippet' ][ 'thumbnails' ][ 'medium' ][ 'url' ] ) ) { $return_data[ 'thumb_medium' ] = $api_data[ 'snippet' ][ 'thumbnails' ][ 'medium' ][ 'url' ]; }
143
- if ( isset( $api_data[ 'snippet' ][ 'thumbnails' ][ 'high' ][ 'url' ] ) ) { $return_data[ 'thumb_high' ] = $api_data[ 'snippet' ][ 'thumbnails' ][ 'high' ][ 'url' ]; }
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[ 'description' ] ) or trim( $return_data[ 'description' ] ) == '' ) { $return_data[ 'description' ] = $return_data[ 'title' ]; }
 
 
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[ 'api_cache' ] != 0 && $id_found ) {
163
 
164
- $cache = $options[ 'api_cache' ] * DAY_IN_SECONDS;
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 youtube-embed
8
- */
9
-
10
- /**
11
- * Save a transient
12
- *
13
- * Generate a transient name and save it
14
- *
15
- * @since 5.0
16
- *
17
- * @param string $name The name of the transient
18
- * @param string $data The data to store
19
- * @param string $cache How long to cache the data for
20
- * @param string $hash Whether to hash the name (true or false)
21
- * @return string True or false, indicating success
22
- */
23
-
24
- function ye_set_transient( $name, $data, $cache, $hash = false ) {
25
-
26
- if ( $hash ) { $name = hash( 'ripemd128', $name ); }
27
-
28
- $result = set_transient( 'youtubeembed_' . $name, $data, $cache);
29
-
30
- return $result;
31
- }
32
-
33
- /**
34
- * Get a transient
35
- *
36
- * Generate a transient name and fetch it
37
- *
38
- * @since 5.0
39
- *
40
- * @param string $name The name of the transient
41
- * @param string $hash Whether to hash the name (true or false)
42
- * @return string The transient result or false, if failed
43
- */
44
-
45
- function ye_get_transient( $name, $hash = false ) {
46
-
47
- if ( $hash ) { $name = hash( 'ripemd128', $name ); }
48
-
49
- $result = get_transient( 'youtubeembed_' . $name );
50
-
51
- return $result;
52
- }
53
-
54
- /**
55
- * Set up the scheduler
56
- *
57
- * Set up the scheduler for midnight to run the housekeeping
58
- *
59
- * @since 5.0
60
- */
61
-
62
- function ye_set_up_scheduler() {
63
-
64
- if ( !wp_next_scheduled( 'housekeep_ye_transients' ) ) {
65
- wp_schedule_event( strtotime( '00:00' ) , 'daily', 'housekeep_ye_transients' );
66
- }
67
- }
68
-
69
- add_action( 'init', 'ye_set_up_scheduler' );
70
-
71
- /**
72
- * Housekeep the transients
73
- *
74
- * Remove any expired transients, relevant to this plugin
75
- *
76
- * @since 5.0
77
- */
78
-
79
- function ye_housekeep_transients() {
80
-
81
- $sql = "
82
- DELETE
83
- a, b
84
- FROM
85
- {$wpdb->options} a, {$wpdb->options} b
86
- WHERE
87
- a.option_name LIKE '%_transient_youtubeembed_%' AND
88
- a.option_name NOT LIKE '%_transient_timeout_youtubeembed_%' AND
89
- b.option_name = CONCAT(
90
- '_transient_timeout_',
91
- SUBSTRING(
92
- a.option_name,
93
- CHAR_LENGTH('_transient_') + 1
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( 'id' => '', 'width' => '', 'height' => '', 'fullscreen' => '', 'related' => '', 'autoplay' => '', 'loop' => '', 'start' => '', 'annotation' => '', 'cc' => '', 'style' => '', 'stop' => '', 'disablekb' => '', 'ratio' => '', 'controls' => '', 'profile' => '', 'list_style' => '', 'template' => '', 'color' => '', 'responsive' => '', 'search' => '', 'user' => '', 'modest' => '', 'playsinline' => '', 'cc_lang' => '', 'language' => '' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  $array = array_merge( $default, $array );
34
 
35
  extract( $array );
36
 
37
- // Initialisation
38
 
39
- $start_time = microtime( true );
40
- $newline = "\n";
41
- $tab = "\t";
42
  $cache_suppress = false;
43
 
44
- // Ensure an ID is passed
45
 
46
- if ( $id == '' ) { return ye_error( __( 'No video/playlist ID has been supplied', 'youtube-embed' ) ); }
 
 
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 ( $profile != '' ) {
55
- $profile = ye_validate_profile( $profile, $general[ 'profile_no' ] );
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 ( ( $user == 0 ) && ( $search == 0 ) ) {
68
 
69
- // Check if it's a list
70
 
71
  $list_found = false;
72
- if ( ( $general[ 'force_list_type' ] == 1 && $list_style != '' ) or ( $general[ 'force_list_type' ] != 1 ) ) {
73
- $list = ye_validate_list( $id, $general[ 'list_no' ] );
74
- if ( is_array( $list ) ) { $list_found = true; }
 
 
75
  }
76
 
77
- // If this isn't a list, extract the ID and work out the type
78
 
79
- if ( !$list_found ) {
80
 
81
- // Check if certain parameters are included in the URL
82
 
83
- $width = ye_get_url_para( $id, 'w', $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 = ye_get_api_data( $id );
93
- $embed_type = $api_data[ 'type' ];
94
 
95
- // If the video is invalid, output an error
96
 
97
- if ( !$api_data[ 'valid' ] ) {
98
- $result = $newline . '<!-- YouTube Embed v' . youtube_embed_version . ' -->' . $newline;
 
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 = $id;
111
 
112
- // Randomize the video
113
 
114
- if ( $list_style == 'random' ) {
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 ( $list_style == 'single' ) {
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 [ 0 ];
133
 
134
- // Build the playlist
135
 
136
  if ( count( $list ) > 1 ) {
137
- $loop = 1;
138
- while ( $loop < count( $list ) ) {
139
- if ( $playlist_ids != '' ) { $playlist_ids .= ','; }
140
- $list_id = ye_extract_id( $list[ $loop ] );
 
 
 
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
- // Correct the ID if a playlist
154
 
155
- if ( strtolower( substr( $id, 0, 2 ) ) == 'pl' && strlen( $id ) == 34 ) { $id = substr( $id, 2 ); }
 
 
156
 
157
- // Get from cache, if required
158
 
159
- if ( $general[ 'video_cache' ] != 0 && get_the_date() !== false && !$cache_suppress ) {
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( 'metadata' => $general[ 'metadata' ], 'feed' => $general[ 'feed' ], 'thumbnail' => $general[ 'thumbnail' ], 'privacy' => $general[ 'privacy' ], 'frameborder' => $general[ 'frameborder' ], 'debug' => $general[ 'debug' ], 'script' => $general[ 'script' ], 'force_list_type' => $general[ 'force_list_type' ] );
 
 
 
 
 
 
 
 
 
164
 
165
- $key = serialize( $options ) . serialize( $array ) . serialize ( $general_extract );
166
 
167
- if ( $list_found ) { $key .= serialize( $list ); }
 
 
168
 
169
- // Now fetch the cache
170
 
171
  $cache = ye_get_transient( $key, true );
172
- if ( $cache !== false ) { return $cache; }
 
 
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 ( ( $playlist_ids != '' ) or ( $user != 0 ) or ( $search != 0 ) ) {
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
- if ( ( $embed_type == 'v' ) && ( $general[ 'feed' ] != 't' ) ) { $result .= '<p><a href="' . $youtube_url . '"><img src="https://img.youtube.com/vi/' . $id . '/' . $general[ 'thumbnail' ] . '.jpg" alt="' . $api_data[ 'title' ] . '"></a></p>' . $newline; }
184
- if ( ( $general ['feed'] != 'v' ) or ( $embed_type != 'v' ) ) { $result .= '<p><a href="' . $youtube_url . '">' . __( 'Click here to view the video on YouTube', 'youtube-embed' ) . '</a>.</p>' . $newline; }
 
 
 
 
 
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 ( $responsive == '' ) {
193
- $responsive = $options[ 'dynamic' ];
194
- $fixed = $options[ 'fixed' ];
195
  } else {
196
- if ( $width != '' ) { $fixed = 1; }
 
 
197
  }
198
 
199
- // Only set width and height from defaults if both are missing
200
 
201
- if ( ( $width == '' ) && ( $height == '' ) ) {
202
- $width = $options[ 'width' ];
203
- $height = $options[ 'height' ];
204
  }
205
 
206
- // If height or width is missing, calculate missing parameter using ratio
207
 
208
- if ( ( ( $width == '' ) or ( $height == '' ) ) && ( ( $width != '' ) or ( $height != '' ) ) ) {
209
- $new_sizes = ye_calculate_video_size( $width, $height, $options[ 'width' ], $options[ 'height' ], $ratio);
210
- $width = $new_sizes[ 'width' ];
211
- $height = $new_sizes[ 'height' ];
212
  }
213
 
214
- // If values have not been passed, use the default values
215
 
216
- if ( $fullscreen == '' ) { $fullscreen = $options[ 'fullscreen' ]; }
217
- if ( $related == '' ) { $related = $options[ 'related' ]; }
218
- if ( $autoplay == '' ) { $autoplay = $options[ 'autoplay' ]; }
219
- if ( $loop == '' ) { $loop = $options[ 'loop' ]; }
220
- if ( $annotation == '' ) { $annotation = $options[ 'annotation' ]; }
221
- if ( $cc == '' ) { $cc = $options[ 'cc' ]; }
222
- if ( $cc_lang == '' ) { $cc_lang = $options[ 'cc_lang']; }
223
- if ( $language == '' ) { $language = $options[ 'language']; }
224
- if ( $disablekb == '' ) { $disablekb = $options[ 'disablekb' ]; }
225
- if ( $controls == '' ) { $controls = $options[ 'controls' ]; }
226
- if ( $style == '' ) { $style = $options[ 'style' ]; }
227
- if ( $color == '' ) { $color = $options[ 'color' ]; }
228
- if ( $modest == '' ) { $modest = $options[ 'modest' ]; }
229
- if ( $playsinline == '' ) { $playsinline = $options[ 'playsinline' ]; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
- // And for those not passed, simply assign the defaults to variables
232
 
233
- $metadata = $general[ 'metadata' ];
234
- $debug = $general[ 'debug' ];
235
- $privacy = $general[ 'privacy' ];
236
 
237
- if ( $start == '' ) { $start = '0'; }
238
- if ( $stop == '' ) { $stop = '0'; }
 
 
 
 
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 ( $template == '' ) {
246
- $template = $options[ 'template' ];
247
  } else {
248
  $template = htmlspecialchars_decode( $template, ENT_QUOTES );
249
  }
250
- if ( strpos( $template, '%video%' ) === false ) { $template = '%video%'; }
 
 
251
 
252
  // Set frameborder options.
253
 
254
- if ( isset( $general[ 'frameborder' ] ) && $general[ 'frameborder' ] != 1 ) {
255
  $frameborder = 'frameborder="0" ';
256
  } else {
257
  $frameborder = '';
@@ -261,21 +355,51 @@ function ye_generate_youtube_code( $array ) {
261
 
262
  $paras = '';
263
 
264
- if ( $modest == 1 ) { $paras .= '&modestbranding=1'; }
265
- if ( $fullscreen != 1 ) { $paras .= '&fs=0'; }
266
- if ( $related != 1 ) { $paras .= '&rel=0'; }
267
- if ( $autoplay == 1 ) { $paras .= '&autoplay=1'; }
268
- if ( $loop == 1 ) { $paras .= '&loop=1'; }
269
- if ( $annotation != 1 ) { $paras .= '&iv_load_policy=3'; }
270
- if ( $cc != '' ) { $paras .= '&cc_load_policy=' . $cc; }
271
- if ( $cc_lang != '' ) { $paras .= '&cc_lang_pref=' . $cc_lang; }
272
- if ( $disablekb == 1 ) { $paras .= '&disablekb=1'; }
273
- if ( $controls != 1 ) { $paras .= '&controls=' . $controls; }
274
- if ( strtolower( $color ) != 'red' ) { $paras .= '&color=' . strtolower( $color ); }
275
- if ( $playsinline == 1 ) { $paras .= '&playsinline=1'; }
276
- if ( $language != '' ) { $paras .= '&hl=' . $language; }
277
- if ( $start != 0 ) { $paras .= '&start=' . $start; }
278
- if ( $stop != 0 ) { $paras .= '&end=' . $stop; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = $tab;
295
  $result = '<div class="youtube-embed';
296
- if ( $responsive == 1 ) { $result .= ' ye-container'; }
 
 
 
297
  $result .= '"';
298
- if ( $metadata != 0 ) { $result .= ' itemprop="video" itemscope itemtype="https://schema.org/VideoObject"'; }
 
 
299
  $result .= '>' . $newline;
300
- if ( ( $responsive == 1 ) && ( $fixed == 1) ) {
301
  $result = '<div style="width: ' . $width . 'px; max-width: 100%">' . $newline . $tab . $result;
302
- $ttab .= $tab;
303
  }
304
 
305
- // Add Metadata
306
 
307
- if ( $metadata != 0 ) {
308
 
309
- if ( $api_data[ 'restricted' ] === true ) {
310
  $friendly = 'false';
311
  } else {
312
- if ( $api_data[ 'restricted' ] === false ) {
313
  $friendly = 'true';
314
  } else {
315
  $friendly = '';
316
  }
317
  }
318
 
319
- $result .= $ttab . '<meta itemprop="url" content="https://www.youtube.com/' . $embed_type . '/' . $id . '" />' . $newline;
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
- // Work out, depending on privacy settings, the main address to use
 
 
331
 
332
- if ( $privacy == 2 ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  $do_not_track = ye_do_not_track();
334
- if ( $do_not_track ) { $privacy = 1; } else { $privacy = 0; }
 
 
 
 
335
  }
336
 
337
- if ( $privacy == 1 ) { $url_privacy = 'youtube-nocookie.com'; } else { $url_privacy = 'youtube.com'; }
 
 
 
 
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
- $id_paras = '/' . $id;
343
 
344
- // If a playlist, user or download build the ID appropriately
345
 
346
- if ( ( $embed_type == 'p' ) or ( $user != 0 ) or ( $search != 0 ) ) {
347
 
348
  $list_type = '';
349
- if ( $embed_type == 'p' ) { $list_type = 'playlist'; }
350
- if ( $user != 0 ) { $list_type = 'user_uploads'; }
351
- if ( $search != 0 ) { $list_type = 'search'; $id = urlencode( $id ); }
 
 
 
 
 
 
 
352
 
353
  $id_paras = '?listType=' . $list_type . '&list=';
354
- if ( ( $embed_type == 'p' ) && ( strtolower( substr ( $id, 0, 2 ) ) != 'pl' ) ) { $id_paras .= 'PL'; }
 
 
355
  $id_paras .= $id;
356
  }
357
 
358
- // Combine URL parts together
359
 
360
  $embed_url .= $id_paras;
361
- if ( ( !strpos( $embed_url, '?' ) ) && ( $paras != '' ) ) { $paras = '?' . substr( $paras, 1 ); }
 
 
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 ) { return ye_error( __( 'The maximum URL length has been exceeded. Please reduce your parameter and/or playlist.', 'youtube-embed' ) ); }
 
 
367
 
368
- // Add IFRAME embed code
369
 
370
- if ( $embed_type == "p" ) { $playlist_para = "p/"; } else { $playlist_para = ''; }
 
 
 
 
371
  $result .= $ttab . '<iframe ' . $frameborder . 'style="border: 0;' . $style . '" class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . $embed_url . '"';
372
- if ( $fullscreen == 1 ) { $result .= ' allowfullscreen'; }
373
- $result .= ' ></iframe>' . $newline;
 
 
 
 
 
374
 
375
- // Now apply the template to the result
376
 
377
  $end_tag = '';
378
- if ( ( $responsive == 1 ) && ( $fixed == 1 ) ) {
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[ 'download' ] == 1 ) && ( $embed_type == 'v' ) ) {
388
- $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;
389
  }
390
 
391
- // Now add a commented header and trailer
392
 
393
- if ( $debug == 1 ) {
394
- $result = '<!-- YouTube Embed v' . youtube_embed_version . ' -->' . $newline . $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[ 'video_cache' ] != 0 && get_the_date() !== false && !$cache_suppress ) {
404
 
405
- $cache = $general[ 'video_cache' ] * HOUR_IN_SECONDS;
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
- * @since 2.0
420
- *
421
- * @param string $name The name of the profile to find
422
- * @param string $number The number of profiles available
423
- * @return string The profile number (defaults to 0)
424
- */
425
-
426
  function ye_validate_profile( $name, $number ) {
427
 
428
  $profile = 0;
429
- $name = strtolower( $name );
430
 
431
- if ( ( $name != '' ) && ( $name != 'default' ) ) {
432
 
433
- // Loop around, fetching in profile names
434
 
435
  $loop = 1;
436
- while ( ( $loop <= $number ) && ( $profile == 0 ) ) {
437
- if ( ( $name == $loop ) or ( $name == 'Profile ' . $loop ) ) {
438
  $profile = $loop;
439
  } else {
440
  $profiles = ye_get_profile( $loop );
441
- $profname = strtolower( $profiles[ 'profile_name' ] );
442
- if ( $profname == $name ) { $profile = $loop; }
 
 
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
- * @since 2.0
456
- *
457
- * @param string $name The name of the list to find
458
- * @param string $number The number of lists available
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 ( $name != '' ) {
477
 
478
- // Loop around, fetching in profile names
479
 
480
  $loop = 1;
481
- while ( ( $loop <= $number ) && ( $list == '' ) ) {
482
  $listfiles = ye_get_list( $loop );
483
- if ( is_array( $listfiles) ) {
484
- if ( ( $name == strval( $loop ) ) or ( $name == 'List ' . $loop ) ) {
485
- $list = $listfiles[ 'list' ];
486
  } else {
487
- $listname = strtolower( $listfiles[ 'list_name' ] );
488
- if ( $listname == $name ) { $list = $listfiles[ 'list' ]; }
 
 
489
  }
490
  }
491
  $loop ++;
492
  }
493
  }
494
- if ( $list != '' ) { $list = explode( "\n", $list ); }
 
 
495
  }
496
  return $list;
497
  }
498
 
499
  /**
500
- * Get URL parameters
501
- *
502
- * Extract a requested parameter from a URL
503
- *
504
- * @since 2.0
505
- *
506
- * @param string $id The ID of the video
507
- * @param string $para The parameter to extract
508
- * @param string $current The current parameter value
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 ( strpos( $id, '&' . $para . '=' ) !== false ) { $start_pos = strpos( $id, '&' . $para . '=' ) + 6 + strlen( $para ); }
 
 
518
 
519
- // If a parameter was found, look for the end of it
520
 
521
- if ( $start_pos !== false ) {
522
  $end_pos = strpos( $id, '&', $start_pos + 1 );
523
- if ( !$end_pos ) { $end_pos = strlen( $id ); }
 
 
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
- * @since 2.6
540
- *
541
- * @return string True or false
542
- */
543
-
544
  function ye_do_not_track() {
545
 
546
- if ( isset( $_SERVER[ 'HTTP_DNT' ] ) ) {
547
- if ( $_SERVER[ 'HTTP_DNT' ] == 1 ) { return true; }
 
 
548
  } else {
549
  if ( function_exists( 'getallheaders' ) ) {
550
  foreach ( getallheaders() as $key => $value ) {
551
- if ( ( strtolower( $key ) === 'dnt' ) && ( $value == 1 ) ) { return true; }
 
 
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
- * @since 4.2
564
- *
565
- * @param string $width Current width
566
- * @param string $height Current height
567
- * @param string $default_width The default width
568
- * @param string $default_height The default height
569
- * @param string $ratio User supplied ratio
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 = array();
577
 
578
- // If a ratio has been specified by the user, extract it
579
 
580
- if ( $ratio != '' ) {
581
  $pos = strpos( $ratio, ':', 0 );
582
- if ( $pos !== false ) {
583
  $ratio_l = substr( $ratio, 0, $pos );
584
  $ratio_r = substr( $ratio, $pos + 1 );
585
- if ( ( is_numeric( $ratio_l ) ) && ( is_numeric( $ratio_r ) ) ) { $ratio_to_use = $ratio_l / $ratio_r; }
 
 
586
  }
587
  }
588
 
589
- // If no, or invalid, ratio supplied, calculate from the default video dimensions
590
 
591
- if ( $ratio_to_use == '' ) { $ratio_to_use = $default_width / $default_height; }
 
 
592
 
593
- // Complete the missing width or height using the ratio
594
 
595
- if ( $width == '' ) { $width = round( $height * $ratio_to_use, 0); }
596
- if ( $height == '' ) { $height = round( $width / $ratio_to_use, 0); }
 
 
 
 
597
 
598
- $new_sizes[ 'width' ] = $width;
599
- $new_sizes[ 'height' ] = $height;
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 Download Code
4
- *
5
- * Create code to allow a YouTube video to be downloaded
6
- *
7
- * @package youtube-embed
8
- * @since 2.0
9
- *
10
- * @param string $id YouTube video ID
11
- * @return string Download HTML
12
- */
13
-
14
- function ye_generate_download_code( $id ) {
15
-
16
- return ye_generate_vinfo_code( $id, '%download%' );
17
-
18
- }
19
-
20
- /**
21
- * Generate video short URL
22
- *
23
- * Create a short URL to a YouTube video
24
- *
25
- * @package YouTube-Embed
26
- * @since 2.0
27
- *
28
- * @uses ye_extract_id Extract an ID from a string
29
- * @uses ye_get_api_data Get API data
30
- * @uses ye_error Display an error
31
- *
32
- * @param string $id YouTube video ID
33
- * @return string $youtube_code Code
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
- * @package YouTube-Embed
48
- * @since 2.0
49
- *
50
- * @uses ye_extract_id Extract an ID from a string
51
- * @uses ye_get_api_data Get API data
52
- * @uses ye_error Display an error
53
- *
54
- * @param string $array Array of parameters
55
- * @return string $youtube_code Code
56
- */
57
-
58
- function ye_generate_thumbnail_code( $array ) {
59
-
60
- // Set defaults then merge with passed array. Finally, split array into individual variables
61
-
62
- $default = array( 'id' => '', 'style' => '', 'class' => '', 'rel' => '', 'target' => '', 'width' => '', 'height' => '', 'alt' => '', 'version' => '', 'nolink' => false );
63
-
64
- $array = array_merge( $default, $array );
65
-
66
- extract( $array );
67
-
68
- // Create the relevant version name to find it in the API array
69
-
70
- $version = strtolower( $version );
71
- if ( ( $version != 'default' ) && ( $version != 'medium' ) && ( $version != 'high' ) && ( $version != 'standard' ) && ( $version != 'maxres' ) ) { $version = 'default'; }
72
-
73
- // Now create the required code
74
-
75
- if ( $alt == '' ) { $alt = '%title%'; }
76
- if ( !$nolink ) {
77
- $youtube_code = '<a href="https://www.youtube.com/watch?v=' . $id . '"';
78
- if ( $style != '' ) { $youtube_code .= ' style="' . $style . '"'; }
79
- if ( $class != '' ) { $youtube_code .= ' class="' . $class . '"'; }
80
- if ( $rel != '' ) { $youtube_code .= ' rel="' . $rel . '"'; }
81
- if ( $target != '' ) { $youtube_code .= ' target="' . $target . '"'; }
82
- $youtube_code .= '>';
83
- }
84
- $youtube_code .= '<img src="%thumb_' . $version . '%"';
85
- if ( $width != '' ) { $youtube_code .= ' width="' . $width . '"'; }
86
- if ( $height != '' ) { $youtube_code .= ' height="' . $height . '"'; }
87
- $youtube_code .= ' alt="' . $alt . '"/>';
88
- if ( !$nolink ) { $youtube_code .= '</a>'; }
89
-
90
- $youtube_code = ye_generate_vinfo_code( $id, $youtube_code) ;
91
-
92
- return $youtube_code;
93
- }
94
-
95
- /**
96
- * Generate Video Information
97
- *
98
- * Output video information
99
- *
100
- * @since 5.0
101
- *
102
- * @uses ye_extract_id Extract an ID from a string
103
- * @uses ye_get_api_data Get API data
104
- * @uses ye_error Display an error
105
- *
106
- * @param string $id Video ID
107
- * @param string $text The text containing the information requirements
108
- * @return string $output The resulting output
109
- */
110
-
111
- function ye_generate_vinfo_code( $id, $text ) {
112
-
113
- if ( $id == '' ) {
114
- return ye_error( __( 'No YouTube ID was specified.', 'youtube-embed' ) );
115
- }
116
-
117
- // Extract the ID if a full URL has been specified
118
-
119
- $id = ye_extract_id( $id );
120
-
121
- // Get the data from the API
122
-
123
- $data = ye_get_api_data( $id );
124
-
125
- // Exit out with an error if the ID was not valid
126
-
127
- if ( !$data[ 'valid' ] ) {
128
- return ye_error( sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) );
129
- }
130
-
131
- // Now replace any tags in the text with the relevant information
132
-
133
- $output = $text;
134
-
135
- $output = str_replace( '%title%', $data[ 'title' ], $output );
136
- $output = str_replace( '%description%', $data[ 'description' ], $output );
137
- $output = str_replace( '%url%', 'https://www.youtube.com/watch?v=' . $id, $output );
138
- $output = str_replace( '%shorturl%', 'https://youtu.be/' . $id, $output );
139
- $output = str_replace( '%download%', 'http://keepvid.com/?url=https://www.youtube.com/watch?v=' . $id, $output );
140
-
141
- $output = str_replace( '%thumb_default%', $data[ 'thumb_default' ], $output );
142
- $output = str_replace( '%thumb_medium%', $data[ 'thumb_medium' ], $output );
143
- $output = str_replace( '%thumb_high%', $data[ 'thumb_high' ], $output );
144
- $output = str_replace( '%thumb_standard%', $data[ 'thumb_standard' ], $output );
145
- $output = str_replace( '%thumb_maxres%', $data[ 'thumb_maxres' ], $output );
146
-
147
- return $output;
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 youtube-embed
8
- */
9
-
10
- class YouTubeEmbedWidget extends WP_Widget {
11
-
12
- /**
13
- * Widget Constructor
14
- *
15
- * Call WP_Widget class to define widget
16
- *
17
- * @since 2.0
18
- *
19
- * @uses WP_Widget Standard WP_Widget class
20
- */
21
-
22
- function __construct() {
23
-
24
- parent::__construct( 'youtube_embed_widget',
25
- __( 'YouTube Embed', 'youtube-embed' ),
26
- array( 'description' => __( 'Embed YouTube Widget.', 'youtube-embed' ),
27
- 'class' => 'ye-widget',
28
- 'customize_selective_refresh' => true )
29
- );
30
- }
31
-
32
- /**
33
- * Display widget
34
- *
35
- * Display the YouTube widget
36
- *
37
- * @since 2.0
38
- *
39
- * @uses generate_youtube_code Generate the required YouTube code
40
- *
41
- * @param string $args Arguments
42
- * @param string $instance Instance
43
- */
44
-
45
- function widget( $args, $instance ) {
46
-
47
- extract( $args, EXTR_SKIP );
48
-
49
- // Output the header
50
- echo $before_widget;
51
-
52
- // Extract title for heading
53
- $title = $instance[ 'titles' ];
54
-
55
- // Output title, if one exists
56
- if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }
57
-
58
- // Set the correct
59
- if ( $instance[ 'id_type' ] == 's' ) { $search = 1; } else { $search = ''; }
60
- if ( $instance[ 'id_type' ] == 'u' ) { $user = 1; } else { $user = ''; }
61
-
62
- // Built the parameter array
63
-
64
- $array = array(
65
- 'id' => $instance[ 'id' ],
66
- 'start' => $instance[ 'start' ],
67
- 'stop' => $instance[ 'start' ],
68
- 'profile' => $instance[ 'profile' ],
69
- 'list_style' => $instance[ 'list' ],
70
- 'search' => $search,
71
- 'user' => $user );
72
-
73
- // Generate the video and output it
74
-
75
- echo apply_filters( 'a3_lazy_load_html', ye_generate_youtube_code ( $array ) );
76
-
77
- // Output the trailer
78
- echo $after_widget;
79
- }
80
-
81
- /**
82
- * Widget update/save function
83
- *
84
- * Update and save widget
85
- *
86
- * @since 2.0
87
- *
88
- * @param string $new_instance New instance
89
- * @param string $old_instance Old instance
90
- * @return string Instance
91
- */
92
-
93
- function update( $new_instance, $old_instance ) {
94
-
95
- $instance = $old_instance;
96
- $instance[ 'titles' ] = strip_tags( $new_instance[ 'titles' ] );
97
- $instance[ 'id' ] = $new_instance[ 'id' ];
98
- $instance[ 'profile' ] = $new_instance[ 'profile' ];
99
- $instance[ 'start' ] = $new_instance[ 'start' ];
100
- $instance[ 'list' ] = $new_instance[ 'list' ];
101
- $instance[ 'stop' ] = $new_instance[ 'stop' ];
102
- $instance[ 'id_type' ] = $new_instance[ 'id_type' ];
103
-
104
- return $instance;
105
- }
106
-
107
- /**
108
- * Widget Admin control form
109
- *
110
- * Define admin file
111
- *
112
- * @since 2.0
113
- *
114
- * @uses ye_get_general_defaults Fetch general options
115
- *
116
- * @param string $instance Instance
117
- */
118
-
119
- function form( $instance ) {
120
-
121
- // Set default options
122
-
123
- $default = array( 'titles' => 'YouTube', 'id' => '', 'profile' => '', 'start' => '', 'list' => '', 'stop' => '', 'id_type' => 'v' );
124
- $instance = wp_parse_args( ( array ) $instance, $default );
125
- $general = ye_get_general_defaults();
126
-
127
- // Widget Title field
128
-
129
- $field_id = $this -> get_field_id( 'titles' );
130
- $field_name = $this -> get_field_name( 'titles' );
131
- 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>';
132
-
133
- // Video ID field
134
-
135
- $field_id = $this -> get_field_id( 'id' );
136
- $field_name = $this -> get_field_name( 'id' );
137
- 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>';
138
-
139
- // ID Type
140
-
141
- echo "<table>\n";
142
-
143
- $field_id = $this -> get_field_id( 'id_type' );
144
- $field_name = $this -> get_field_name( 'id_type' );
145
- echo "\r\n" . '<tr><td width="100%">' . __( 'ID Type', 'youtube-embed' ) . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value="v"';
146
- if ( esc_attr( $instance[ 'id_type' ] ) == 'v' ) { echo " selected='selected'"; }
147
- echo '>' . __( 'Video or Playlist', 'youtube-embed' ) . '</option><option value="s"';
148
- if ( esc_attr( $instance[ 'id_type' ] ) == 's' ) { echo " selected='selected'"; }
149
- echo '>' . __( 'Search', 'youtube-embed' ) . '</option><option value="u"';
150
- if ( esc_attr( $instance[ 'id_type' ] ) == 'u' ) { echo " selected='selected'"; }
151
- echo '>' . __( 'User', 'youtube-embed' ) . '</option></select></td></tr>';
152
-
153
- echo "</table>\n";
154
-
155
- // Profile field
156
-
157
- $field_id = $this -> get_field_id( 'profile' );
158
- $field_name = $this -> get_field_name( 'profile' );
159
- echo "\r\n" . '<p><label for="' . $field_id . '">' . __( 'Profile', 'youtube-embed' ) . ': </label><select name="' . $field_name . '" class="widefat" id="' . $field_id . '">';
160
- ye_generate_profile_list( esc_attr( $instance[ 'profile' ] ), $general[ 'profile_no' ] );
161
- echo '</select></p>';
162
-
163
- echo "<table>\n";
164
-
165
- // Start field
166
-
167
- $field_id = $this -> get_field_id( 'start' );
168
- $field_name = $this -> get_field_name( 'start' );
169
- 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>';
170
-
171
- // Stop field
172
-
173
- $field_id = $this -> get_field_id( 'stop' );
174
- $field_name = $this -> get_field_name( 'stop' );
175
- 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>';
176
-
177
- echo "</table><table>\n";
178
-
179
- // List field
180
-
181
- $field_id = $this -> get_field_id( 'list' );
182
- $field_name = $this -> get_field_name( 'list' );
183
- echo "\r\n" . '<tr><td width="100%">' . __( 'List Playback', 'youtube-embed' ) . '</td><td><select name="' . $field_name . '" id="' . $field_id . '"><option value=""';
184
- if ( esc_attr( $instance[ 'list' ] ) == '' ) { echo " selected='selected'"; }
185
- echo '>' . __( 'Profile default', 'youtube-embed' ) . '</option><option value="order"';
186
- if ( esc_attr( $instance[ 'list' ] ) == 'order' ) { echo " selected='selected'"; }
187
- echo '>' . __( 'Play each video in order', 'youtube-embed' ) . '</option><option value="random"';
188
- if ( esc_attr( $instance[ 'list' ] ) == 'random' ) { echo " selected='selected'"; }
189
- echo '>' . __( 'Play videos randomly', 'youtube-embed' ) . '</option><option value="single"';
190
- if ( esc_attr( $instance[ 'list' ] ) == 'single' ) { echo " selected='selected'"; }
191
- echo '>' . __( 'Play one random video', 'youtube-embed' ) . '</option></select></td></tr>';
192
-
193
- echo "</table>\n";
194
- }
195
- }
196
-
197
- /**
198
- * Register Widget
199
- *
200
- * Register widget when loading the WP core
201
- *
202
- * @since 2.0
203
- */
204
-
205
- function youtube_embed_register_widgets() {
206
- register_widget( 'YouTubeEmbedWidget' );
207
- }
208
- add_action( 'widgets_init', 'youtube_embed_register_widgets' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Options Page
4
- *
5
- * Screen for generic options
6
- *
7
- * @package youtube-embed
8
- * @since 2.0
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' ] ) ) { $options[ 'admin_bar' ] = sanitize_text_field( $_POST[ 'youtube_embed_admin_bar' ] ); } else { $options[ 'admin_bar' ] = ''; }
34
-
35
- $options[ 'profile_no' ] = sanitize_text_field( $_POST[ 'youtube_embed_profile_no' ] );
36
- $options[ 'list_no' ] = sanitize_text_field( $_POST[ 'youtube_embed_list_no' ] );
37
- $options[ 'alt_profile' ] = sanitize_text_field( $_POST[ 'youtube_embed_alt_profile' ] );
38
- $options[ 'feed' ] = sanitize_text_field( $_POST[ 'youtube_embed_feed' ] );
39
- $options[ 'thumbnail' ] = sanitize_text_field( $_POST[ 'youtube_embed_thumbnail' ] );
40
- $options[ 'privacy' ] = sanitize_text_field( $_POST[ 'youtube_embed_privacy' ] );
41
- $options[ 'menu_access' ] = sanitize_text_field( $_POST[ 'youtube_embed_menu_access' ] );
42
- $options[ 'script' ] = sanitize_text_field( $_POST[ 'youtube_embed_script' ] );
43
- $options[ 'standard_video' ] = sanitize_text_field( $_POST[ 'youtube_embed_video' ] );
44
- $options[ 'playlist_video' ] = sanitize_text_field( $_POST[ 'youtube_embed_playlist' ] );
45
-
46
- $options[ 'api_cache' ] = sanitize_text_field( $_POST[ 'youtube_embed_api_cache' ] );
47
- if ( !is_numeric( $options[ 'api_cache' ] ) ) { $options[ 'api_cache' ] = 0; }
48
- $options[ 'video_cache' ] = sanitize_text_field( $_POST[ 'youtube_embed_video_cache' ] );
49
- if ( !is_numeric( $options[ 'video_cache' ] ) ) { $options[ 'video_cache' ] = 0; }
50
-
51
- if ( isset( $_POST[ 'youtube_embed_metadata' ] ) ) { $options[ 'metadata' ] = sanitize_text_field( $_POST[ 'youtube_embed_metadata' ] ); } else { $options[ 'metadata' ] = ''; }
52
- if ( isset( $_POST[ 'youtube_embed_frameborder' ] ) ) { $options[ 'frameborder' ] = sanitize_text_field( $_POST[ 'youtube_embed_frameborder' ] ); } else { $options[ 'frameborder' ] = ''; }
53
- if ( isset( $_POST[ 'youtube_embed_widgets' ] ) ) { $options[ 'widgets' ] = sanitize_text_field( $_POST[ 'youtube_embed_widgets' ] ); } else { $options[ 'widgets' ] = ''; }
54
- if ( isset( $_POST[ 'youtube_embed_debug' ] ) ) { $options[ 'debug' ] = sanitize_text_field( $_POST[ 'youtube_embed_debug' ] ); } else { $options[ 'debug' ] = ''; }
55
- if ( isset( $_POST[ 'youtube_embed_prompt' ] ) ) { $options[ 'prompt' ] = sanitize_text_field( $_POST[ 'youtube_embed_prompt' ] ); } else { $options[ 'prompt' ] = ''; }
56
- if ( isset( $_POST[ 'youtube_embed_list' ] ) ) { $options[ 'force_list_type' ] = sanitize_text_field( $_POST[ 'youtube_embed_list' ] ); } else { $options[ 'force_list_type' ] = ''; }
57
-
58
- // If the number of profiles or lists is less than zero, put it to 0
59
-
60
- if ( $options[ 'profile_no' ] < 0 ) { $options[ 'profile_no' ] = 0; }
61
- if ( $options[ 'list_no' ] < 0 ) { $options[ 'list_no' ] = 0; }
62
-
63
- // Test the API key
64
-
65
- $api_key = sanitize_text_field( $_POST[ 'youtube_embed_api' ] );
66
- $api_valid = true;
67
- if ( $api_key != '' ) {
68
- $api_test = ye_get_api_data( 'jNQXAC9IVRw', $api_key, true );
69
- if ( !$api_test[ 'api' ] ) { $api_valid = false; }
70
- }
71
-
72
- if ( !$api_valid ) {
73
- $update_message = __( 'API key is invalid or API is unavailable.', 'youtube-embed' );
74
- $update_class = 'error';
75
- } else {
76
- $options[ 'api' ] = $api_key;
77
- $update_message = __( 'Settings Saved.', 'youtube-embed' );
78
- $update_class = 'updated';
79
- }
80
-
81
- // Update the options
82
-
83
- update_option( 'youtube_embed_general', $options );
84
-
85
- // Update the alternative shortcodes
86
-
87
- $shortcode = sanitize_text_field( $_POST[ 'youtube_embed_shortcode' ] );
88
- $shortcode = trim( $shortcode, '[]' );
89
-
90
- update_option( 'youtube_embed_shortcode', $shortcode );
91
-
92
- echo '<div class="' . $update_class . ' fade"><p><strong>' . $update_message . "</strong></p></div>\n";
93
- }
94
-
95
- // Get options
96
-
97
- $options = ye_get_general_defaults();
98
- $shortcode = ye_get_shortcode();
99
- ?>
100
-
101
- <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>
102
-
103
- <form method="post" action="<?php echo get_bloginfo( 'wpurl' ).'/wp-admin/admin.php?page=ye-general-options' ?>">
104
-
105
- <table class="form-table">
106
-
107
- <tr>
108
- <th scope="row"><?php _e( 'API Key', 'youtube-embed' ); ?></th>
109
- <td><label for="youtube_embed_api"><input type="text" size="50" name="youtube_embed_api" value="<?php echo esc_attr( $options[ 'api' ] ); ?>"/></label>
110
- <p class="description"><?php _e( 'Please see the instructions for details on creating your own API key.', 'youtube-embed' ); ?></p></td>
111
- </tr>
112
-
113
- </table><hr><h3 class="title"><?php _e( 'Embedding', 'youtube-embed' ); ?></h3><table class="form-table">
114
-
115
- <!-- Add Metadata -->
116
-
117
- <tr>
118
- <th scope="row"><label for="youtube_embed_metadata"><?php _e( 'Add Metadata', 'youtube-embed' ); ?></label></th>
119
- <td><input type="checkbox" name="youtube_embed_metadata" value="1" <?php checked( $options[ 'metadata' ], "1" ); ?>/>
120
- <?php _e( 'Allow rich metadata to be added to code', 'youtube-embed' ); ?></td>
121
- </tr>
122
-
123
- <!-- Feed -->
124
-
125
- <tr>
126
- <th scope="row"><?php _e( 'Feed', 'youtube-embed' ); ?></th>
127
- <td><label for="youtube_embed_feed"><select name="youtube_embed_feed">
128
- <option value="t"<?php if ( $options[ 'feed' ] == "t" ) { echo " selected='selected'"; } ?>><?php _e ( 'Text link', 'youtube-embed' ); ?></option>
129
- <option value="v"<?php if ( $options[ 'feed' ] == "v" ) { echo " selected='selected'"; } ?>><?php _e ( 'Thumbnail', 'youtube-embed' ); ?></option>
130
- <option value="b"<?php if ( $options[ 'feed' ] == "b" ) { echo " selected='selected'"; } ?>><?php _e ( 'Thumbnail &amp; Text Link', 'youtube-embed' ); ?></option>
131
- </select></label>
132
- <p class="description"><?php _e( 'Videos cannot be embedded in feeds. Select how you wish them to be shown instead.', 'youtube-embed' ); ?></p></td>
133
- </tr>
134
-
135
- <!-- Feed Thumbnail -->
136
-
137
- <tr>
138
- <th scope="row">&nbsp;&nbsp;&nbsp;&nbsp;<?php _e( 'Thumbnail to use', 'youtube-embed' ); ?></th>
139
- <td><label for="youtube_embed_thumbnail"><select name="youtube_embed_thumbnail">
140
- <option value="default"<?php if ( $options[ 'thumbnail' ] == "default" ) { echo " selected='selected'"; } ?>><?php _e ( 'Default', 'youtube-embed' ); ?></option>
141
- <option value="hqdefault"<?php if ( $options[ 'thumbnail' ] == "hqdefault" ) { echo " selected='selected'"; } ?>><?php _e ( 'Default (HQ)', 'youtube-embed' ); ?></option>
142
- <option value="1"<?php if ( $options[ 'thumbnail' ] == "1" ) { echo " selected='selected'"; } ?>><?php _e ( 'Start', 'youtube-embed' ); ?></option>
143
- <option value="2"<?php if ( $options[ 'thumbnail' ] == "2" ) { echo " selected='selected'"; } ?>><?php _e ( 'Middle', 'youtube-embed' ); ?></option>
144
- <option value="3"<?php if ( $options[ 'thumbnail' ] == "3" ) { echo " selected='selected'"; } ?>><?php _e ( 'End', 'youtube-embed' ); ?></option>
145
- </select></label>
146
- <p class="description"><?php _e( 'Choose which thumbnail to use.', 'youtube-embed' ); ?></p></td>
147
- </tr>
148
-
149
- <!-- Content Resizing Scripts -->
150
-
151
- <tr>
152
- <th scope="row"><?php _e( 'Content Resizing Script', 'youtube-embed' ); ?></th>
153
- <td><label for="youtube_embed_script"><select name="youtube_embed_script">
154
- <option value=""<?php if ( $options[ 'script' ] == "" ) { echo " selected='selected'"; } ?>><?php _e ( 'None', 'youtube-embed' ); ?></option>
155
- <option value="f"<?php if ( $options[ 'script' ] == "f" ) { echo " selected='selected'"; } ?>><?php _e ( 'FitVids.js', 'youtube-embed' ); ?></option>
156
- <option value="i"<?php if ( $options[ 'script' ] == "i" ) { echo " selected='selected'"; } ?>><?php _e ( 'iFrame Resizer', 'youtube-embed' ); ?></option>
157
- </select></label>
158
- <p class="description"><?php _e( 'Use a third party content resizing script?', 'youtube-embed' ); ?></p></td>
159
- </tr>
160
-
161
- </table><hr><h3 class="title"><?php _e( 'Shortcodes', 'youtube-embed' ); ?></h3><table class="form-table">
162
-
163
- <!-- Shortcodes in Widgets -->
164
-
165
- <tr>
166
- <th scope="row"><?php _e( 'Allow shortcodes in widgets', 'youtube-embed' ); ?></th>
167
- <td><label for="youtube_embed_widgets"><input type="checkbox" name="youtube_embed_widgets" value="1" <?php checked( $options[ 'widgets' ], "1" ); ?>/>
168
- <?php _e( 'Allow shortcodes to be used in widgets', 'youtube-embed' ); ?></label>
169
- <p class="description"><?php _e( 'This will apply to <strong>all</strong> widgets.', 'youtube-embed' ); ?></p></td>
170
- </tr>
171
-
172
- <!-- Alternative Shortcode -->
173
-
174
- <tr>
175
- <th scope="row"><?php _e( 'Alternative Shortcode', 'youtube-embed' ); ?></th>
176
- <td><label for="youtube_embed_shortcode"><input type="text" size="30" name="youtube_embed_shortcode" value="<?php echo esc_attr( $shortcode ); ?>"/></label>
177
- <p class="description"><?php _e( 'An alternative shortcode to use.', 'youtube-embed' ); ?></p></td>
178
- </tr>
179
-
180
- <!-- Alternative Shortcode Profile -->
181
-
182
- <tr>
183
- <th scope="row">&nbsp;&nbsp;&nbsp;&nbsp;<?php _e( 'Profile to use', 'youtube-embed' ); ?></th>
184
- <td><label for="youtube_embed_alt_profile"><select name="youtube_embed_alt_profile">
185
- <?php ye_generate_profile_list( $options[ 'alt_profile' ], $options[ 'profile_no' ] ) ?>
186
- </select></label></td>
187
- </tr>
188
-
189
- <!-- Shortcode Re-Use Prompt -->
190
-
191
- <tr>
192
- <th scope="row"><?php _e( 'Show Shortcode Re-use Prompt', 'youtube-embed' ); ?></th>
193
- <td><label for="youtube_embed_prompt"><input type="checkbox" name="youtube_embed_prompt" value="1" <?php checked( $options[ 'prompt' ], "1" ); ?>/>
194
- <?php _e( 'Show a prompt if the main shortcode is being re-used by another plugin', 'youtube-embed' ); ?></label></td>
195
- </tr>
196
-
197
- </table><hr><h3 class="title"><?php _e( 'Administration Options', 'youtube-embed' ); ?></h3><table class="form-table">
198
-
199
- <!-- Admin Bar -->
200
-
201
- <tr>
202
- <th scope="row"><?php _e( 'Show in Admin Bar', 'youtube-embed' ); ?></th>
203
- <td><label for="youtube_embed_admin_bar"><input type="checkbox" name="youtube_embed_admin_bar" value="1" <?php checked( $options[ 'admin_bar' ], "1" ); ?>/>
204
- <?php _e( 'Add link to options screen to Admin Bar', 'youtube-embed' ); ?></label></td>
205
- </tr>
206
-
207
- <!-- Menu Screen Access -->
208
-
209
- <tr>
210
- <th scope="row"><?php _e( 'Menu Screen Access', 'youtube-embed' ); ?></th>
211
- <td><label for="youtube_embed_menu_access"><select name="youtube_embed_menu_access">
212
- <option value="list_users"<?php if ( $options[ 'menu_access' ] == "list_users" ) { echo " selected='selected'"; } ?>><?php _e ( 'Administrator', 'youtube-embed' ); ?></option>
213
- <option value="edit_pages"<?php if ( $options[ 'menu_access' ] == "edit_pages" ) { echo " selected='selected'"; } ?>><?php _e ( 'Editor', 'youtube-embed' ); ?></option>
214
- <option value="publish_posts"<?php if ( $options[ 'menu_access' ] == "publish_posts" ) { echo " selected='selected'"; } ?>><?php _e ( 'Author', 'youtube-embed' ); ?></option>
215
- <option value="edit_posts"<?php if ( $options[ 'menu_access' ] == "edit_posts" ) { echo " selected='selected'"; } ?>><?php _e ( 'Contributor', 'youtube-embed' ); ?></option>
216
- </select></label>
217
- <p class="description"><?php _e( 'Specify the user access required for the menu screens.', 'youtube-embed' ); ?></p></td>
218
- </tr>
219
-
220
- </table><hr><h3 class="title"><?php _e( 'Profile &amp; List Sizes', 'youtube-embed' ); ?></h3><table class="form-table">
221
-
222
- <!-- Number of Profiles -->
223
-
224
- <tr>
225
- <th scope="row"><?php _e( 'Number of Profiles', 'youtube-embed' ); ?></th>
226
- <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>
227
- </tr>
228
-
229
- <!-- Number of Lists -->
230
-
231
- <tr>
232
- <th scope="row"><?php _e( 'Number of Lists', 'youtube-embed' ); ?></th>
233
- <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>
234
- </tr>
235
-
236
- </table><hr><h3 class="title"><?php _e( 'Performance', 'youtube-embed' ); ?></h3><table class="form-table">
237
-
238
-
239
- <!-- Specify a list -->
240
-
241
- <tr>
242
- <th scope="row"><?php _e( 'Force list specification', 'youtube-embed' ); ?></th>
243
- <td><label for="youtube_embed_list"><input type="checkbox" name="youtube_embed_list" value="1" <?php checked( $options[ 'force_list_type' ], "1" ); ?>/>
244
- <?php _e( 'Force users to specify a list type', 'youtube-embed' ); ?></label>
245
- <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>
246
- </tr>
247
-
248
- <!-- Video cache -->
249
-
250
- <tr>
251
- <th scope="row"><?php _e( 'Video Cache', 'youtube-embed' ); ?></th>
252
- <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>
253
- <p class="description"><?php _e( 'How long to cache the video output. Set to 0 to switch off.', 'youtube-embed' ); ?></p></td>
254
- </tr>
255
-
256
- <!-- API cache -->
257
-
258
- <tr>
259
- <th scope="row"><?php _e( 'API Cache', 'youtube-embed' ); ?></th>
260
- <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>
261
- <p class="description"><?php _e( 'How long to cache the API data. Set to 0 to switch off.', 'youtube-embed' ); ?></p></td>
262
- </tr>
263
-
264
- </table><hr><h3 class="title"><?php _e( 'Security', 'youtube-embed' ); ?></h3><table class="form-table">
265
-
266
- <!-- Privacy-Enhanced Mode -->
267
-
268
- <tr>
269
- <th scope="row"><?php _e( 'Privacy-Enhanced Mode', 'youtube-embed' ); ?></th>
270
- <td><label for="youtube_embed_menu_access"><select name="youtube_embed_privacy">
271
- <option value="0"<?php if ( $options[ 'privacy' ] == "0" ) { echo " selected='selected'"; } ?>><?php _e ( 'Cookies should always be stored', 'youtube-embed' ); ?></option>
272
- <option value="1"<?php if ( $options[ 'privacy' ] == "1" ) { echo " selected='selected'"; } ?>><?php _e ( 'Cookies should never be stored', 'youtube-embed' ); ?></option>
273
- <option value="2"<?php if ( $options[ 'privacy' ] == "2" ) { echo " selected='selected'"; } ?>><?php _e ( "Cookies should be stored based on user's Do Not Track setting", 'youtube-embed' ); ?></option>
274
- </select></label>
275
- <p class="description"><?php _e( 'Read more about <a href="http://donottrack.us/">Do Not Track</a>.', 'youtube-embed' ); ?></p></td>
276
- </tr>
277
-
278
- <!-- Show debug output -->
279
-
280
- <tr>
281
- <th scope="row"><?php _e( 'Show debug output', 'youtube-embed' ); ?></th>
282
- <td><label for="youtube_embed_debug"><input type="checkbox" name="youtube_embed_debug" value="1" <?php checked( $options[ 'debug' ], "1" ); ?>/>
283
- <?php _e( 'Show debug output as HTML comments', 'youtube-embed' ); ?></label></td>
284
- </tr>
285
-
286
- </table><hr><h3 class="title"><?php _e( 'Profile Demo Videos', 'youtube-embed' ); ?></h3><table class="form-table">
287
-
288
- <!-- Standard Video -->
289
-
290
- <tr>
291
- <th scope="row"><?php _e( 'Standard Video', 'youtube-embed' ); ?></th>
292
- <td><label for="youtube_embed_video"><input type="text" size="30" name="youtube_embed_video" value="<?php echo esc_attr( $options[ 'standard_video' ] ); ?>"/></label>
293
- <p class="description"><?php _e( 'ID of a YouTube video.', 'youtube-embed' ); ?></p></td>
294
- </tr>
295
-
296
- <!-- Playlist Video -->
297
-
298
- <tr>
299
- <th scope="row"><?php _e( 'Playlist', 'youtube-embed' ); ?></th>
300
- <td><label for="youtube_embed_playlist"><input type="text" size="30" name="youtube_embed_playlist" value="<?php echo esc_attr( $options[ 'playlist_video' ] ); ?>"/></label>
301
- <p class="description"><?php _e( 'ID of a YouTube playlist.', 'youtube-embed' ); ?></p></td>
302
- </tr>
303
-
304
- </table><hr><h3 class="title"><?php _e( 'Miscellaneous', 'youtube-embed' ); ?></h3><table class="form-table">
305
-
306
- <!-- Validation -->
307
-
308
- <tr>
309
- <th scope="row"><?php _e( 'Improve Validation', 'youtube-embed' ); ?></th>
310
- <td><label for="youtube_embed_frameborder"><input type="checkbox" name="youtube_embed_frameborder" value="1" <?php checked( $options[ 'frameborder' ], "1" ); ?>/>
311
- <?php _e( 'Improve the validity of the generated markup', 'youtube-embed' ); ?></label>
312
- <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>
313
- </tr>
314
-
315
- </table>
316
-
317
- <?php wp_nonce_field( 'youtube-embed-general','youtube_embed_general_nonce', true, true ); ?>
318
-
319
- <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
320
-
321
- </form>
322
-
323
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 &amp; 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">&nbsp;&nbsp;&nbsp;&nbsp;<?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">&nbsp;&nbsp;&nbsp;&nbsp;<?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 &amp; 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 youtube-embed
8
- * @since 2.0
9
- */
10
-
11
- // Set current list number
12
-
13
- if ( isset( $_POST[ 'youtube_embed_list_no' ] ) ) { $list_no = esc_textarea( $_POST[ 'youtube_embed_list_no' ] ); } else { $list_no = 0; }
14
- if ( $list_no == '' ) { $list_no = 1; }
15
-
16
- // If options have been updated on screen, update the database
17
-
18
- $message = '';
19
- if ( ( !empty( $_POST[ 'Submit' ] ) ) && ( check_admin_referer( 'youtube-embed-general', 'youtube_embed_general_nonce' ) ) ) {
20
-
21
- $class = 'updated fade';
22
- $message = __( 'Settings Saved.', 'youtube-embed' );
23
- $new_id_list = '';
24
-
25
- if ( ( $_POST[ 'youtube_embed_video_list' ] == '' ) or ( $_POST[ 'youtube_embed_name' ] == '' ) ) {
26
- $class = 'error';
27
- $message = __( 'All fields must be completed.', 'youtube-embed' );
28
- } else {
29
- $id_array = explode( "\n", esc_textarea( $_POST[ 'youtube_embed_video_list' ] ) );
30
- $loop = 0;
31
- $valid = true;
32
-
33
- // Loop through the video IDs
34
-
35
- while ( $loop < count( $id_array ) ) {
36
-
37
- // Extract the ID from the provided data
38
-
39
- $id = trim( ye_extract_id( $id_array[ $loop ] ) );
40
-
41
- // Now check its validity using the API data
42
-
43
- if ( $id != '' ) {
44
- $data = ye_get_api_data( $id );
45
- $valid = $data[ 'valid' ];
46
- if ( $data[ 'type' ] != 'v' ) { $valid = false; }
47
- $new_id_list .= $id . "\n";
48
- }
49
- $loop ++;
50
- }
51
-
52
- // If one or more IDs weren't valid, output an error
53
-
54
- if ( !$valid ) {
55
- $class = 'error';
56
- $message = __( 'Errors were found with your video list. See the list below for details.', 'youtube-embed' );
57
- }
58
- }
59
-
60
- // Update the options
61
-
62
- $options[ 'list_name' ] = $_POST[ 'youtube_embed_name' ];
63
-
64
- if ( $new_id_list == '' ) {
65
- $options[ 'list' ] = sanitize_text_field( $_POST[ 'youtube_embed_video_list' ] );
66
- } else {
67
- $options[ 'list' ] = substr( $new_id_list, 0, strlen( $new_id_list ) - 1 );
68
- }
69
-
70
- if ( substr( $class, 0, 7 ) == 'updated' ) { update_option( 'youtube_embed_list' . $list_no, $options ); }
71
-
72
- } else {
73
- $class = '';
74
- }
75
-
76
- // Fetch options into an array
77
-
78
- if ( $class != "error" ) { $options = ye_get_list( $list_no ); }
79
- $general = ye_get_general_defaults();
80
-
81
- // Get number of lists in use
82
-
83
- $loop = 0;
84
- $max_lists = 0;
85
- while ( $loop <= $general[ 'list_no' ] ) {
86
-
87
- $list = ye_get_list( $loop );
88
- if ( !$list[ 'default' ] ) { $max_lists ++; }
89
-
90
- $loop ++;
91
- }
92
-
93
- // Display any screen headings
94
-
95
- ?>
96
- <div class="wrap">
97
- <h1><?php _e( 'YouTube Embed Lists', 'youtube-embed' ); ?><span class="title-count"><?php echo $max_lists; ?></span></h1>
98
-
99
- <?php
100
-
101
- // Output any messages
102
-
103
- if ( $message != '' ) { echo '<div class="' . $class . '"><p><strong>' . $message . "</strong></p></div>\n"; }
104
- ?>
105
-
106
- <form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ye-list-options'; ?>">
107
-
108
- <span class="alignright">
109
- <select name="youtube_embed_list_no">
110
- <?php
111
- $loop = 1;
112
- while ( $loop <= $general[ 'list_no' ] ) {
113
-
114
- $listfiles = ye_get_list( $loop );
115
- if ( $listfiles[ 'list' ] != '' ) {
116
- $listname = $listfiles[ 'list_name' ];
117
- $list_found = true;
118
- } else {
119
- $listname = __( 'List', 'youtube-embed' ) . ' ' . $loop;
120
- $list_found = false;
121
- }
122
- echo '<option value="' . $loop . '"';
123
- if ( $list_no == $loop ) { echo " selected='selected'"; }
124
- echo '>' . $listname;
125
- if ( !$list_found ) { echo ' [undefined]'; }
126
- echo "</option>\n";
127
-
128
- $loop ++;
129
- }
130
- ?>
131
- </select>
132
- <input type="submit" name="List" class="button-secondary" value="<?php _e( 'Change list' ); ?>"/>
133
- </span><br/>
134
-
135
- <?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' ); ?>
136
-
137
- <table class="form-table">
138
-
139
- <!-- List Name -->
140
-
141
- <tr>
142
- <th scope="row"><?php _e( 'List Name', 'youtube-embed' ); ?></th>
143
- <td><label for="youtube_embed_name"><input type="text" size="20" name="youtube_embed_name" value="<?php echo esc_attr( $options[ 'list_name' ] ); ?>"/>
144
- <?php _e( 'The name you wish to give this list', 'youtube-embed' ); ?></label></td>
145
- </tr>
146
-
147
- <!-- Video IDs -->
148
-
149
- <tr>
150
- <th scope="row"><?php _e( 'Video IDs (one per line)', 'youtube-embed' ); ?></th>
151
- <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>
152
- </tr>
153
-
154
- </table>
155
-
156
- <?php wp_nonce_field( 'youtube-embed-general','youtube_embed_general_nonce', true, true ); ?>
157
-
158
- <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
159
-
160
- </form>
161
-
162
- <?php
163
-
164
- // If video IDs exist display them on screen along with their status'
165
- if ( $options[ 'list' ] != '' ) {
166
-
167
- $id_array = explode( "\n", $options[ 'list' ] );
168
-
169
- 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";
170
- $loop = 0;
171
-
172
- while ( $loop < count( $id_array ) ) {
173
-
174
- // Extract the ID from the provided data
175
-
176
- $id = trim( ye_extract_id( $id_array[ $loop ] ) );
177
- if ( $id != '' ) {
178
-
179
- // Validate the video type
180
-
181
- $api_data = ye_get_api_data( $id );
182
-
183
- if ( $api_data[ 'type' ] == 'p' ) {
184
- $text = __( 'This is a playlist', 'youtube-embed' );
185
- $status = '-1';
186
- } else {
187
- if ( !$api_data[ 'valid' ] ) {
188
- $text = __( 'Invalid video ID', 'youtube-embed' );
189
- $status = '-2';
190
- } else {
191
- if ( $api_data[ 'valid' ] ) {
192
- $text = __( 'Valid video', 'youtube-embed' );
193
- $status = '0';
194
- }
195
- }
196
- }
197
-
198
- // Output the video information
199
-
200
- echo "\t<tr>\n\t\t<td>" . $id . "</td>\n";
201
- echo "\t\t<td>";
202
- if ( $api_data[ 'api' ] ) {
203
- if ( $api_data[ 'title' ] == '' ) {
204
- echo '[No title available]';
205
- } else {
206
- echo $api_data[ 'title' ];
207
- }
208
- } else {
209
- echo '[No title - API not available]';
210
- }
211
- echo "</td>\n";
212
- echo "\t\t<td style=\"";
213
-
214
- if ( $status != 0 ) {
215
- echo 'font-weight: bold; color: #f00;';
216
- }
217
-
218
- echo '"><img src="' . plugins_url( 'images/', dirname(__FILE__) );
219
-
220
- if ( $status == 0 ) {
221
- $alt_text = __( 'The video ID is valid', 'youtube-embed' );
222
- echo 'tick.png" alt="' . $alt_text . '" ';
223
- } else {
224
- $alt_text = __( 'The video ID is invalid', 'youtube-embed' );
225
- echo 'cross.png" alt="' . $alt_text . '" ';
226
- }
227
-
228
- echo "height=\"16px\" width=\"16px\"/>&nbsp;" . $text . "</td>\n\t</tr>\n";
229
- }
230
- $loop ++;
231
- }
232
- echo "</tbody>\n</table>\n";
233
- }
234
- ?>
235
-
236
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"/>&nbsp;' . $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 youtube-embed
8
- * @since 2.0
9
- */
10
-
11
- $langs = array( "aa", "ab", "ae", "af", "ak", "am", "an", "ar", "as", "av", "ay", "az", "ba", "be", "bg", "bh", "bi", "bm", "bn", "bo", "br", "bs", "ca", "ce", "ch", "co", "cr", "cs", "cu", "cv", "cy", "da", "de", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fj", "fo", "fr", "fy", "ga", "gd", "gl", "gn", "gu", "gv", "ha", "he", "hi", "ho", "hr", "ht", "hu", "hy", "hz", "ia", "id", "ie", "ig", "ii", "ik", "io", "is", "it", "iu", "ja", "jv", "ka", "kg", "ki", "kj", "kk", "kl", "km", "kn", "ko", "kr", "ks", "ku", "kv", "kw", "ky", "la", "lb", "lg", "li", "ln", "lo", "lt", "lu", "lv", "mg", "mh", "mi", "mk", "ml", "mn", "mr", "ms", "mt", "my", "na", "nb", "nd", "ne", "ng", "nl", "nn", "no", "nr", "nv", "ny", "oc", "oj", "om", "or", "os", "pa", "pi", "pl", "ps", "pt", "qu", "rm", "rn", "ro", "ru", "rw", "sa", "sc", "sd", "se", "sg", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr", "ss", "st", "su", "sv", "sw", "ta", "te", "tg", "th", "ti", "tk", "tl", "tn", "to", "tr", "ts", "tt", "tw", "ty", "ug", "uk", "ur", "uz", "ve", "vi", "vo", "wa", "wo", "xh", "yi", "yo", "za", "zh" );
12
-
13
- // Set current profile number
14
-
15
- if ( isset( $_POST[ 'youtube_embed_profile_no' ] ) ) { $profile_no = sanitize_text_field( $_POST[ 'youtube_embed_profile_no' ] ); } else { $profile_no = 0; }
16
- if ( $profile_no == '' ) { $profile_no = 0; }
17
-
18
- // If options have been updated on screen, update the database
19
-
20
- if ( ( !empty( $_POST[ 'Submit' ] ) ) && ( check_admin_referer( 'youtube-embed-profile' , 'youtube_embed_profile_nonce' ) ) ) {
21
-
22
- $options[ 'profile_name' ] = sanitize_text_field( $_POST[ 'youtube_embed_name' ] );
23
- $options[ 'width' ] = sanitize_text_field( $_POST[ 'youtube_embed_width' ] );
24
- $options[ 'height' ] = sanitize_text_field( $_POST[ 'youtube_embed_height' ] );
25
-
26
- $allowed_html = array( 'a' => array( 'href' => array(),
27
- 'title' => array(),
28
- 'target' => array(),
29
- 'class' => array(),
30
- 'id' => array(),
31
- 'style' => array()
32
- ),
33
- 'img' => array( 'src' => array(),
34
- 'alt' => array(),
35
- 'height' => array(),
36
- 'width' => array(),
37
- 'align' => array(),
38
- 'class' => array(),
39
- 'id' => array(),
40
- 'style' => array()
41
- ),
42
- 'div' => array( 'class' => array(),
43
- 'id' => array(),
44
- 'align' => array(),
45
- 'style' => array()
46
- ),
47
- 'span' => array('class' => array(),
48
- 'id' => array(),
49
- 'style' => array()
50
- ),
51
- 'br' => array(),
52
- 'p' => array(),
53
- 'strong' => array(),
54
- );
55
-
56
- $options[ 'template' ] = wp_kses( htmlspecialchars_decode( $_POST[ 'youtube_embed_template' ] ), $allowed_html );
57
- if ( strpos( $options[ 'template' ], '%video%' ) === false ) { $options[ 'template' ] = '%video%'; }
58
-
59
- $options[ 'style' ] = sanitize_text_field( $_POST[ 'youtube_embed_style' ] );
60
- $options[ 'controls'] = sanitize_text_field( $_POST[ 'youtube_embed_controls' ] );
61
- $options[ 'color' ] = sanitize_text_field( $_POST[ 'youtube_embed_color' ] );
62
- $options[ 'download_style' ] = sanitize_text_field( $_POST[ 'youtube_embed_download_style' ] );
63
- $options[ 'cc_lang' ] = sanitize_text_field( $_POST[ 'youtube_embed_cc_lang' ] );
64
- $options[ 'language' ] = sanitize_text_field( $_POST[ 'youtube_embed_language' ] );
65
-
66
- $options[ 'download_text' ] = str_replace( '\"', '"', str_replace( "\'", "'", $_POST[ 'youtube_embed_download_text' ] ) );
67
-
68
- if ( isset( $_POST[ 'youtube_embed_playsinline' ] ) ) { $options[ 'playsinline' ] = sanitize_text_field( $_POST[ 'youtube_embed_playsinline' ] ); } else { $options[ 'playsinline' ] = ''; }
69
- if ( isset( $_POST[ 'youtube_embed_fullscreen' ] ) ) { $options[ 'fullscreen' ] = sanitize_text_field( $_POST[ 'youtube_embed_fullscreen' ] ); } else { $options[ 'fullscreen' ] = ''; }
70
- if ( isset( $_POST[ 'youtube_embed_autoplay' ] ) ) { $options[ 'autoplay'] = sanitize_text_field( $_POST[ 'youtube_embed_autoplay' ] ); } else { $options[ 'autoplay' ] = ''; }
71
- if ( isset( $_POST[ 'youtube_embed_loop' ] ) ) { $options[ 'loop'] = sanitize_text_field( $_POST[ 'youtube_embed_loop' ] ); } else { $options[ 'loop' ] = ''; }
72
- if ( isset( $_POST[ 'youtube_embed_cc' ] ) ) { $options[ 'cc'] = sanitize_text_field( $_POST[ 'youtube_embed_cc' ] ); } else { $options[ 'cc' ] = ''; }
73
-
74
- if ( isset( $_POST[ 'youtube_embed_annotation' ] ) ) { $options[ 'annotation'] = sanitize_text_field( $_POST[ 'youtube_embed_annotation' ] ); } else { $options[ 'annotation' ] = ''; }
75
- if ( isset( $_POST[ 'youtube_embed_related' ] ) ) { $options[ 'related'] = sanitize_text_field( $_POST[ 'youtube_embed_related' ] ); } else { $options[ 'related' ] = ''; }
76
- if ( isset( $_POST[ 'youtube_embed_disablekb' ] ) ) { $options[ 'disablekb'] = sanitize_text_field( $_POST[ 'youtube_embed_disablekb' ] ); } else { $options[ 'disablekb' ] = ''; }
77
- if ( isset( $_POST[ 'youtube_embed_modest' ] ) ) { $options[ 'modest' ] = sanitize_text_field( $_POST[ 'youtube_embed_modest' ] ); } else { $options[ 'modest' ] = ''; }
78
- if ( isset( $_POST[ 'youtube_embed_dynamic' ] ) ) { $options[ 'dynamic' ] = sanitize_text_field( $_POST[ 'youtube_embed_dynamic' ] ); } else { $options[ 'dynamic' ] = ''; }
79
- if ( isset( $_POST[ 'youtube_embed_fixed' ] ) ) { $options[ 'fixed' ] = sanitize_text_field( $_POST[ 'youtube_embed_fixed' ] ); } else { $options[ 'fixed' ] = ''; }
80
- if ( isset( $_POST[ 'youtube_embed_download' ] ) ) { $options[ 'download' ] = sanitize_text_field( $_POST[ 'youtube_embed_download' ] ); } else { $options[ 'download' ] = ''; }
81
-
82
- $default_size = $_POST[ 'youtube_embed_size' ];
83
-
84
- if ( $default_size !== '' ) {
85
- $options[ 'width' ] = ltrim( substr( $default_size, 0, 4 ), '0' );
86
- $options[ 'height'] = ltrim( substr( $default_size, -4, 4 ), '0' );
87
- }
88
-
89
- // Set width or height, if missing
90
-
91
- if ( ( $options[ 'width' ] == '' ) && ( $options[ 'height' ] == '' ) ) {
92
- if ( isset( $GLOBALS[ 'content_width' ] ) ) {
93
- $options[ 'width' ] = $GLOBALS[ 'content_width' ];
94
- } else {
95
- $options[ 'width' ] = 560;
96
- }
97
- $options[ 'height' ] = 27 + round( ( $options[ 'width' ] / 16 ) * 9, 0 );
98
- }
99
- if ( ( $options[ 'width' ] == '' ) && ( $options[ 'height' ] != '' ) ) {
100
- $options[ 'width' ] = round( ( $options[ 'height' ] / 9 ) * 16, 0 );
101
- }
102
- if ( ( $options[ 'width' ] != '' ) && ( $options[ 'height' ] == '' ) ) {
103
- $options[ 'height' ] = 27 + round( ( $options[ 'width' ] / 16 ) * 9, 0 );
104
- }
105
-
106
- update_option( 'youtube_embed_profile' . $profile_no, $options );
107
- $updated = true;
108
-
109
- } else {
110
-
111
- $default_size = '';
112
- $updated = false;
113
- }
114
-
115
- // Fetch options into an array
116
-
117
- $options = ye_get_profile( $profile_no );
118
- $general = ye_get_general_defaults();
119
-
120
- // Get number of profiles in use
121
-
122
- $loop = 0;
123
- $max_profiles = 0;
124
- while ( $loop <= $general[ 'profile_no' ] ) {
125
-
126
- $profile = ye_get_profile( $loop );
127
- if ( !$profile[ 'default' ] ) { $max_profiles ++; }
128
-
129
- $loop ++;
130
- }
131
-
132
-
133
- // Output headings
134
- ?>
135
-
136
- <div class="wrap">
137
-
138
- <h1><?php _e( 'YouTube Embed Profiles', 'youtube-embed' ); ?><span class="title-count"><?php echo $max_profiles; ?></span></h1>
139
-
140
- <?php
141
-
142
- // Output message text
143
-
144
- if ( $updated ) { echo '<div class="updated fade"><p><strong>' . __( $options[ 'profile_name' ].' Profile Saved.' ) . "</strong></p></div>\n"; }
145
-
146
- // Video option button has been pressed
147
-
148
- if ( !empty( $_POST[ 'Video' ] ) ) { $video_type = $_POST[ 'youtube_embed_video_type' ]; } else { $video_type = 'd'; }
149
-
150
- // Generate Profile list
151
- ?>
152
- <form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ye-profile-options' ?>">
153
-
154
- <span class="alignright">
155
- <select name="youtube_embed_profile_no">
156
- <?php ye_generate_profile_list( $profile_no, $general[ 'profile_no' ], true ) ?>
157
- </select>
158
- <input type="submit" name="Profile" class="button-secondary" value="<?php _e( 'Change profile', 'youtube-embed' ); ?>"/>
159
- </span><br/>
160
-
161
- <?php
162
-
163
- // Show explanatory message at top of screen
164
-
165
- if ( $profile_no == '0' ) {
166
- _e( 'These are the options for the default profile.', 'youtube-embed' );
167
- } else {
168
- sprintf( _e( 'These are the options for profile %s.', 'youtube-embed' ), $profile_no );
169
- }
170
- echo ' ' . __( 'Use the drop-down on the right hand side to swap between profiles.', 'youtube-embed' );
171
- ?>
172
-
173
- <table class="form-table">
174
-
175
- <!-- Profile Name -->
176
-
177
- <tr>
178
- <th scope="row"><?php _e( 'Profile Name', 'youtube-embed' ); ?></th>
179
- <td><label for="youtube_embed_name"><input type="text" size="20" name="youtube_embed_name" value="<?php echo esc_attr( $options[ 'profile_name' ] ); ?>"<?php if ( $profile_no == 0 ) { echo ' readonly="readonly"'; } ?>/>
180
- <?php if ( $profile_no != 0 ) { _e( 'The name you wish to give this profile', 'youtube-embed' ); } ?></label></td>
181
- </tr>
182
-
183
- <!-- Template -->
184
-
185
- <tr>
186
- <th scope="row"><?php _e( 'Template', 'youtube-embed' ); ?></th>
187
- <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>
188
- <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>
189
- </tr>
190
-
191
- <!-- Style -->
192
-
193
- <tr>
194
- <th scope="row"><?php _e( 'Style', 'youtube-embed' ); ?></th>
195
- <td><label for="youtube_embed_style"><input type="text" name="youtube_embed_style" class="large-text code" value="<?php echo esc_html( $options[ 'style' ] ); ?>"/>
196
- <p class="description"><?php _e( 'CSS elements to apply to video.', 'youtube-embed' ); ?></p></label></td>
197
- </tr>
198
-
199
- </table><hr><h3 class="title"><?php _e( 'Video Size', 'youtube-embed' ); ?></h3><table class="form-table">
200
-
201
- <!-- Video Size -->
202
-
203
- <tr>
204
- <th scope="row"><?php _e( 'Video Size', 'youtube-embed' ); ?></th>
205
- <td><label for="youtube_embed_height"><input type="text" size="3" maxlength="3" name="youtube_embed_width" value="<?php echo esc_attr( $options[ 'width' ] ); ?>"/>&nbsp;x&nbsp;<input type="text" size="3" maxlength="3" name="youtube_embed_height" value="<?php echo esc_attr( $options[ 'height' ] ); ?>"/>
206
- <?php _e( 'The width x height of the video, in pixels', 'youtube-embed' ); ?></label></td>
207
- </tr>
208
-
209
- <!-- Default Sizes -->
210
-
211
- <tr>
212
- <th scope="row"><?php _e( 'Default Sizes', 'youtube-embed' ); ?></th>
213
- <td><label for="youtube_embed_size"><select name="youtube_embed_size">
214
- <option value=""<?php if ( $default_size == '' ) { echo " selected='selected'"; } ?>><?php _e( 'Use above sizes', 'youtube-embed' ); ?></option>
215
- <option value="04260420"<?php if ( $default_size == "04260420" ) { echo " selected='selected'"; } ?>><?php echo '240p'; ?></option>
216
- <option value="06400360"<?php if ( $default_size == "06400360" ) { echo " selected='selected'"; } ?>><?php echo '360p'; ?></option>
217
- <option value="08540480"<?php if ( $default_size == "08540480" ) { echo " selected='selected'"; } ?>><?php echo '480p'; ?></option>
218
- <option value="12800720"<?php if ( $default_size == "12800720" ) { echo " selected='selected'"; } ?>><?php echo '720p'; ?></option>
219
- <option value="19201080"<?php if ( $default_size == "19201080" ) { echo " selected='selected'"; } ?>><?php echo '1080p'; ?></option>
220
- <option value="38402160"<?php if ( $default_size == "38402160" ) { echo " selected='selected'"; } ?>><?php echo '1440p'; ?></option>
221
- <option value="38402160"<?php if ( $default_size == "38402160" ) { echo " selected='selected'"; } ?>><?php echo '2160p'; ?></option>
222
- </select></label><p class="description"><?php _e( 'Select one of these default sizes to override the above video sizes.', 'youtube-embed' ); ?></p></td>
223
- </tr>
224
-
225
- <!-- Responsive Output -->
226
-
227
- <tr>
228
- <th scope="row"><?php _e( 'Responsive Output', 'youtube-embed' ); ?></th>
229
- <td><label for="youtube_embed_dynamic"><input type="checkbox" name="youtube_embed_dynamic" value="1" <?php checked( $options[ 'dynamic' ], "1" ); ?>/>
230
- <?php _e( 'Show full width and resize with the browser', 'youtube-embed' ); ?></label></td>
231
- </tr>
232
-
233
- <!-- Maximum Size -->
234
-
235
- <tr>
236
- <th scope="row">&nbsp;&nbsp;&nbsp;&nbsp;<?php _e( 'Set Maximum Size', 'youtube-embed' ); ?></th>
237
- <td><label for="youtube_embed_fixed"><input type="checkbox" name="youtube_embed_fixed" value="1" <?php checked( $options[ 'fixed' ], "1" ); ?>/>
238
- <?php _e( 'Use above width to define maximum size', 'youtube-embed' ); ?></label></td>
239
- </tr>
240
-
241
- <!-- Playsinline -->
242
-
243
- <tr>
244
- <th scope="row"><?php _e( 'Plays Inline', 'youtube-embed' ); ?></th>
245
-
246
- <td><label for="youtube_embed_playsinline"><input type="checkbox" name="youtube_embed_playsinline" value="1" <?php checked( $options[ 'playsinline' ], "1" ); ?>/>
247
- <?php _e( 'Whether videos play inline or fullscreen in an HTML5 player on iOS. ', 'youtube-embed' ); ?></label></td>
248
- </tr>
249
-
250
- </table><hr><h3 class="title"><?php _e( 'Playback', 'youtube-embed' ); ?></h3><table class="form-table">
251
-
252
- <!-- Autoplay -->
253
-
254
- <tr>
255
- <th scope="row"><?php _e( 'Autoplay', 'youtube-embed' ); ?></th>
256
- <td><label for="youtube_embed_autoplay"><input type="checkbox" name="youtube_embed_autoplay" value="1" <?php checked( $options[ 'autoplay' ], "1" ); ?>/>
257
- <?php _e( 'Choose whether the initial video will automatically start to play when the player loads', 'youtube-embed' ); ?></label></td>
258
- </tr>
259
-
260
- <!-- Loop Video -->
261
-
262
- <tr>
263
- <th scope="row"><?php _e( 'Loop Video', 'youtube-embed' ); ?></th>
264
- <td><label for="youtube_embed_loop"><input type="checkbox" name="youtube_embed_loop" value="1" <?php checked( $options[ 'loop' ], "1" ); ?>/>
265
- <?php _e( 'Play the initial video again and again', 'youtube-embed' ); ?></label>
266
- <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>
267
- </tr>
268
-
269
- <!-- Annotations -->
270
-
271
- <tr>
272
- <th scope="row"><?php _e( 'Annotations', 'youtube-embed' ); ?></th>
273
- <td><label for="youtube_embed_annotation"><input type="checkbox" name="youtube_embed_annotation" value="1" <?php checked( $options[ 'annotation' ], "1" ); ?>/>
274
- <?php _e( 'Video annotations are shown by default', 'youtube-embed' ); ?></label></td>
275
- </tr>
276
-
277
- <!-- Closed Captions -->
278
-
279
- <tr>
280
- <th scope="row"><?php _e( 'Closed Captions', 'youtube-embed' ); ?></th>
281
- <td><label for="youtube_embed_cc"><select name="youtube_embed_cc">
282
- <option value="0"<?php if ( $options[ 'cc' ] == "0" ) { echo " selected='selected'"; } ?>><?php _e( 'Don\'t show closed captions', 'youtube-embed' ); ?></option>
283
- <option value="1"<?php if ( $options[ 'cc' ] == "1" ) { echo " selected='selected'"; } ?>><?php _e( 'Show closed captions', 'youtube-embed' ); ?></option>
284
- <option value=""<?php if ( $options[ 'cc' ] == "" ) { echo " selected='selected'"; } ?>><?php _e( 'User default', 'youtube-embed' ); ?></option>
285
- </select></label>
286
- <p class="description"><?php _e( 'Show closed captions.', 'youtube-embed' ); ?></p></td>
287
- </tr>
288
-
289
- <!-- Closed Caption Language -->
290
-
291
- <tr>
292
- <th scope="row"><?php _e( 'Closed Captions Language', 'youtube-embed' ); ?></th>
293
- <td><label for="youtube_embed_cc_lang"><select name="youtube_embed_cc_lang">
294
- <option value=""<?php if ( $options[ 'cc_lang' ] == "" ) { echo " selected='selected'"; } ?>>N/A</option>
295
- <?php
296
- $loop = 0;
297
- while ( $loop < count( $langs ) ) {
298
-
299
- echo '<option value=" '. $langs[ $loop ] . '"';
300
- if ( $langs[ $loop ] == $options[ 'cc_lang' ] ) { echo " selected='selected'"; }
301
- echo '>' . $langs[ $loop ] . '</option>';
302
-
303
- $loop ++;
304
- }
305
-
306
- ?>
307
- </select></label>
308
- <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>
309
-
310
- </tr>
311
-
312
- <!-- Related -->
313
-
314
- <tr>
315
- <th scope="row"><?php _e( 'Related Videos', 'youtube-embed' ); ?></th>
316
- <td><label for="youtube_embed_related"><select name="youtube_embed_related">
317
- <option value="0"<?php if ( $options[ 'related' ] == "0" ) { echo " selected='selected'"; } ?>><?php _e( 'Show from the same channel', 'youtube-embed' ); ?></option>
318
- <option value="1"<?php if ( $options[ 'related' ] == "1" ) { echo " selected='selected'"; } ?>><?php _e( 'Show related videos from any channel', 'youtube-embed' ); ?></option></label>
319
- <p class="description"><?php _e( 'Defines where related videos are fetched from.', 'youtube-embed' ); ?></p></td>
320
- </tr>
321
-
322
- <!-- Modest Branding -->
323
-
324
- <tr>
325
- <th scope="row"><?php _e( 'Modest Branding', 'youtube-embed' ); ?></th>
326
- <td><label for="youtube_embed_modest"><input type="checkbox" name="youtube_embed_modest" value="1" <?php checked( $options[ 'modest' ], "1" ); ?>/>
327
- <?php _e( 'Reduce branding on video', 'youtube-embed' ); ?></label></td>
328
- </tr>
329
-
330
- </table><hr><h3 class="title"><?php _e( 'Controls', 'youtube-embed' ); ?></h3><table class="form-table">
331
-
332
- <!-- Interface language -->
333
-
334
- <tr>
335
- <th scope="row"><?php _e( 'Interface Language', 'youtube-embed' ); ?></th>
336
- <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>
337
- <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>
338
- </tr>
339
-
340
- <!-- Controls -->
341
-
342
- <tr>
343
- <th scope="row"><?php _e( 'Controls', 'youtube-embed' ); ?></th>
344
- <td><label for="youtube_embed_controls"><select name="youtube_embed_controls">
345
- <option value="0"<?php if ( $options[ 'controls' ] == "0" ) { echo " selected='selected'"; } ?>><?php _e( 'Controls do not display &amp; Flash player loads immediately', 'youtube-embed' ); ?></option>
346
- <option value="1"<?php if ( $options[ 'controls' ] == "1" ) { echo " selected='selected'"; } ?>><?php _e( 'Controls display &amp; Flash player loads immediately', 'youtube-embed' ); ?></option>
347
- <option value="2"<?php if ( $options[ 'controls' ] == "2" ) { echo " selected='selected'"; } ?>><?php _e( 'Controls display &amp; Flash player loads once video starts', 'youtube-embed' ); ?></option>
348
- </select></label>
349
- <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>
350
- </tr>
351
-
352
- <!-- Disable Keyboard -->
353
-
354
- <tr>
355
- <th scope="row"><?php _e( 'Disable Keyboard', 'youtube-embed' ); ?></th>
356
- <td><label for="youtube_embed_disablekb"><input type="checkbox" name="youtube_embed_disablekb" value="1" <?php checked( $options[ 'disablekb' ], "1" ); ?>/>
357
- <?php _e( 'Disable the player keyboard controls', 'youtube-embed' ); ?></label></td>
358
- </tr>
359
-
360
- <!-- Fullscreen -->
361
-
362
- <tr>
363
- <th scope="row"><?php _e( 'Fullscreen', 'youtube-embed' ); ?></th>
364
- <td><label for="youtube_embed_fullscreen"><input type="checkbox" name="youtube_embed_fullscreen" value="1" <?php checked( $options[ 'fullscreen' ], "1" ); ?>/>
365
- <?php _e( 'A button will allow the viewer to watch the video fullscreen', 'youtube-embed' ); ?></label></td>
366
- </tr>
367
-
368
- <!-- Color -->
369
-
370
- <tr>
371
- <th scope="row"><?php _e( 'Progress Bar Color', 'youtube-embed' ); ?></th>
372
- <td><label for="youtube_embed_color"><select name="youtube_embed_color">
373
- <option value="red"<?php if ( $options[ 'color' ] == "red" ) { echo " selected='selected'"; } ?>><?php _e( 'Red', 'youtube-embed' ); ?></option>
374
- <option value="white"<?php if ( $options[ 'color' ] == "white" ) { echo " selected='selected'"; } ?>><?php _e( 'White (desaturated)', 'youtube-embed' ); ?></option>
375
- </select></label>
376
- <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>
377
- </tr>
378
-
379
- </table><hr><h3 class="title"><?php _e( 'Download Link', 'youtube-embed' ); ?></h3><table class="form-table">
380
-
381
- <!-- Download Link -->
382
-
383
- <tr>
384
- <th scope="row"><?php _e( 'Show Download Link', 'youtube-embed' ); ?></th>
385
- <td><label for="youtube_embed_download"><input type="checkbox" name="youtube_embed_download" value="1" <?php checked( $options[ 'download' ], "1" ); ?>/>
386
- <?php echo sprintf( __( 'Show a link to %s under the video', 'youtube-embed' ), '<a href="http://keepvid.com/" rel="nofollow">KeepVid</a>' ); ?></label></td>
387
- </tr>
388
-
389
- <!-- Download Text -->
390
-
391
- <tr>
392
- <th scope="row"><?php _e( 'Download Text', 'youtube-embed' ); ?></th>
393
- <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' ] ); ?>"/>
394
- <p class="description"><?php _e( 'Text or HTML to display to prompt download.', 'youtube-embed' ); ?></p></label></td>
395
- </tr>
396
-
397
- <!-- Download Style -->
398
-
399
- <tr>
400
- <th scope="row"><?php _e( 'Download Style', 'youtube-embed' ); ?></th>
401
- <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' ] ); ?>"/>
402
- <p class="description"><?php _e( 'CSS elements to apply to video download link.', 'youtube-embed' ); ?></p></label></td>
403
- </tr>
404
-
405
- </table>
406
-
407
- <?php wp_nonce_field( 'youtube-embed-profile', 'youtube_embed_profile_nonce', true, true ); ?>
408
-
409
- <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'youtube-embed' ); ?>"/></p>
410
-
411
- </form>
412
-
413
- <a href="#" name="video"></a>
414
- <div style="max-width: <?php echo esc_attr( $options[ 'width' ] ); ?>px">
415
- <h3><?php _e( 'YouTube Video Sample', 'youtube-embed' ); ?></h3>
416
- <p><?php _e( 'The videos below uses the above, saved profile settings in use', 'youtube-embed' ); ?></p>
417
- <h4><?php _e( 'Standard video', 'youtube-embed' ); ?></h3>
418
- <p><?php echo ye_generate_youtube_code( array( 'id' => $general[ 'standard_video' ], 'profile' => $profile_no ) ); ?></p>
419
- <h4><?php _e( 'Playlist', 'youtube-embed' ); ?></h3>
420
- <p><?php echo ye_generate_youtube_code( array( 'id' => $general[ 'playlist_video' ], 'profile' => $profile_no ) ); ?></p>
421
-
422
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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'] ); ?>"/>&nbsp;x&nbsp;<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">&nbsp;&nbsp;&nbsp;&nbsp;<?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 &amp; 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 &amp; 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 &amp; 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 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
- * @since 2.0
16
- *
17
- * @param string $id Video ID
18
- * @return string Extracted ID
19
- */
20
-
21
- function ye_extract_id( $id ) {
22
-
23
- // Convert and trim video ID characters
24
-
25
- $replacement_from = array( '&#8211;', '&#8212;', '&#215;' );
26
- $replacement_to = array( '--', '---', 'x' );
27
-
28
- $id = trim( wp_strip_all_tags( str_replace( $replacement_from, $replacement_to, $id ) ) );
29
-
30
- // Check if it's the full URL, as found in address bar
31
-
32
- $video_pos = strpos( $id, 'youtube.com/watch?', 0 );
33
-
34
- if ( $video_pos !== false ) {
35
-
36
- $video_pos = strpos( $id, 'v=', $video_pos + 18 );
37
- if ( $video_pos === false ) { $video_pos = strpos( $id, 'p=', $video_pos + 18 ); }
38
-
39
- if ( $video_pos !== false ) {
40
-
41
- $video_pos = $video_pos + 2;
42
- $ampersand_pos = strpos( $id, '&', $video_pos );
43
- if ( !$ampersand_pos ) {
44
- $id = substr( $id, $video_pos );
45
- } else {
46
- $id = substr( $id, $video_pos, $ampersand_pos - $video_pos );
47
- }
48
- }
49
-
50
- } else {
51
-
52
- // Now check to see if it's a full URL, as used in the embed code
53
- // Need to check both video and playlist formats
54
-
55
- $video_pos = strpos( $id, 'youtube.com/v/' );
56
- if ($video_pos === false) { $video_pos = strpos( $id, 'youtube.com/p/' ); }
57
-
58
- if ( $video_pos !== false ) {
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
-
67
- } else {
68
-
69
- // Check if it's a shortened URL
70
-
71
- $video_pos = strpos( $id, 'youtu.be/', 0 );
72
-
73
- if ( $video_pos !== false ) {
74
- $video_pos = $video_pos + 9;
75
- $ampersand_pos = strpos( $id, '&', $video_pos );
76
- if ( !$ampersand_pos ) {
77
- $id = substr( $id, $video_pos );
78
- } else {
79
- $id = substr( $id, $video_pos, $ampersand_pos - $video_pos );
80
- }
81
- }
82
- }
83
- }
84
-
85
- return $id;
86
- }
87
-
88
- /**
89
- * Function to report an error
90
- *
91
- * Display an error message in a standard format
92
- *
93
- * @since 2.0
94
- *
95
- * @param string $errorin Error message
96
- * @return string Error output
97
- */
98
-
99
- function ye_error( $errorin ) {
100
-
101
- return '<p style="color: #f00; font-weight: bold;">YouTube Embed: ' . $errorin . "</p>\n";
102
-
103
- }
104
-
105
- /**
106
- * Convert input to a 1 or 0 equivalent
107
- *
108
- * Function to convert a Yes or No input to an equivalent 1 or 0 output
109
- *
110
- * @since 2.0
111
- *
112
- * @uses ye_yes_or_no Convert input to a true or false equivalent
113
- *
114
- * @param string $input Input, usually Yes or No
115
- * @return string 1, 0 or blank, depending on input
116
- */
117
-
118
- function ye_convert( $input ) {
119
-
120
- $input = ye_yes_or_no( $input );
121
- $output = '';
122
- if ( $input === true ) { $output = '1'; }
123
- if ( $input === false ) { $output = '0'; }
124
-
125
- return $output;
126
- }
127
-
128
- /**
129
- * Generate a profile list
130
- *
131
- * Generate FORM options for the current profiles
132
- *
133
- * @since 2.0
134
- *
135
- * @param string $current The current profile number
136
- * @param string $total The total number of profiles
137
- * @param string $full_list Show the full list or just those defined?
138
- */
139
-
140
- function ye_generate_profile_list( $current, $total, $full_list = false ) {
141
-
142
- $loop = 0;
143
- echo 'Total: ' . $total;
144
- while ( $loop <= $total ) {
145
-
146
- // Attempt to get profile
147
-
148
- $profiles = ye_get_profile( $loop );
149
-
150
- // If list is undefined, give it a default name
151
-
152
- if ( $profiles[ 'default' ] ) { $list_found = false; } else { $list_found = true; }
153
-
154
- // Output profile information
155
-
156
- if ( ( $list_found ) or ( $full_list ) ) {
157
-
158
- echo '<option value="' . $loop . '"';
159
- if ( $current == $loop ) { echo " selected='selected'"; }
160
- echo '>' . __( $profiles[ 'profile_name' ] );
161
- if ( !$list_found ) { echo ' [undefined]'; }
162
- echo "</option>\n";
163
-
164
- }
165
-
166
- $loop ++;
167
- }
168
-
169
- return;
170
- }
171
-
172
- /**
173
- * Function to get shortcode options
174
- *
175
- * Return shortcode options. It's in a seperate function in case any further shared
176
- * functionality needs to be added.
177
- *
178
- * @since 4.2
179
- *
180
- * @return strings Alternative shortcode name
181
- */
182
-
183
- function ye_get_shortcode() {
184
-
185
- return get_option( 'youtube_embed_shortcode' );
186
-
187
- }
188
-
189
- /**
190
- * Function to set Shortcode option
191
- *
192
- * Looks up shortcode option - if it's not set, assign a default
193
- *
194
- * @since 2.0
195
- *
196
- * @return string Alternative Shortcode
197
- */
198
-
199
- function ye_set_shortcode() {
200
-
201
- $shortcode = get_option( 'youtube_embed_shortcode' );
202
-
203
- // If an array, transform to new format
204
-
205
- if ( is_array( $shortcode ) ) {
206
- $shortcode = $shortcode[ 1 ];
207
- update_option( 'youtube_embed_shortcode', $shortcode );
208
- }
209
-
210
- // If setting doesn't exist, set defaults
211
-
212
- if ( $shortcode == '' ) {
213
- $shortcode = 'youtube_video';
214
- update_option( 'youtube_embed_shortcode', $shortcode );
215
- }
216
-
217
- return $shortcode;
218
- }
219
-
220
- /**
221
- * Function to get general YouTube options
222
- *
223
- * Return options. It's in a seperate function in case any further shared
224
- * functionality needs to be added.
225
- *
226
- * @since 4.2
227
- *
228
- * @return strings Options array
229
- */
230
-
231
- function ye_get_general_defaults() {
232
-
233
- return get_option( 'youtube_embed_general' );
234
-
235
- }
236
-
237
- /**
238
- * Function to set general YouTube options
239
- *
240
- * Looks up options. If none exist, or some are missing, set default values
241
- *
242
- * @since 2.0
243
- *
244
- * @return string Options array
245
- */
246
-
247
- function ye_set_general_defaults() {
248
-
249
- $options = get_option( 'youtube_embed_general' );
250
-
251
- // If options don't exist, create an empty array
252
-
253
- if ( !is_array( $options ) ) { $options = array(); }
254
-
255
- // Because of upgrading, check each option - if not set, apply default
256
-
257
- $default_array = array(
258
- 'admin_bar' => 1,
259
- 'profile_no' => 5,
260
- 'list_no' => 5,
261
- 'alt_profile' => 0,
262
- 'metadata' => 1,
263
- 'feed' => 'b',
264
- 'thumbnail' => 2,
265
- 'privacy' => 0,
266
- 'frameborder' => 1,
267
- 'widgets' => 0,
268
- 'menu_access' => 'list_users',
269
- 'debug' => 1,
270
- 'script' => '',
271
- 'prompt' => 1,
272
- 'force_list_type' => 0,
273
- 'api' => '',
274
- 'api_cache' => 7,
275
- 'video_cache' => 24,
276
- 'standard_video' => 'RxAtuMu_ph4',
277
- 'playlist_video' => '1DD10E84B9B08A35'
278
- );
279
-
280
- // If a new user switch the list option on. Otherwise, an existing user will default to off
281
-
282
- if ( !is_array( $options )) { $default_array[ 'list' ] = 1; }
283
-
284
- // Merge existing and default options - any missing from existing will take the default settings
285
-
286
- $new_options = array_merge( $default_array, $options );
287
-
288
- // Check if API is invalid (some people are finding a value left over from past install). If so, clear it down
289
-
290
- if ( strlen( $new_options[ 'api'] ) == 1 ) { $new_options[ 'api' ] = ''; }
291
-
292
- // Update the options, if changed, and return the result
293
-
294
- if ( $options != $new_options ) { update_option( 'youtube_embed_general', $new_options ); }
295
-
296
- return $new_options;
297
- }
298
-
299
- /**
300
- * Function to get profile options
301
- *
302
- * Return profiles. It's in a seperate function in case any further shared
303
- * functionality needs to be added.
304
- *
305
- * @since 4.2
306
- *
307
- * @param string $profile Profile number
308
- * @return strings Profile array
309
- */
310
-
311
- function ye_get_profile( $profile ) {
312
-
313
- $options = get_option( 'youtube_embed_profile' . $profile );
314
-
315
- // If there is no profile set up, set to default values and save
316
-
317
- if ( !is_array( $options ) ) {
318
- $options = ye_set_profile_defaults( $profile );
319
- $options[ 'default' ] = true;
320
- } else {
321
- $options[ 'default' ] = false;
322
- }
323
-
324
- // Remove added slashes from template XHTML
325
-
326
- if ( isset( $options[ 'template' ] ) ) { $options[ 'template' ] = stripslashes( $options[ 'template' ] ); }
327
-
328
- return $options;
329
- }
330
-
331
- /**
332
- * Function to set YouTube profile options
333
- *
334
- * Looks up profile options, based on passed number of profiles.
335
- * If none exist, or some are missing, set default values
336
- *
337
- * @since 2.0
338
- *
339
- * @param string $profiles Number of profiles
340
- * @return string Options array
341
- */
342
-
343
- function ye_set_profile( $profiles ) {
344
-
345
- $profile = 0;
346
- while ( $profile <= $profiles ) {
347
-
348
- $options = get_option( 'youtube_embed_profile' . $profile );
349
-
350
- // If the profile doesn't exist, don't assign anything to it
351
-
352
- if ( is_array( $options ) ) {
353
-
354
- // Because of upgrading, check each option - if not set, apply default
355
-
356
- $default_array = ye_set_profile_defaults( $profile );
357
-
358
- // Merge the two arrays
359
-
360
- $new_options = array_merge( $default_array, $options );
361
-
362
- // Because I've changed the variable name from name to profile_name, convert any with the old name
363
-
364
- if ( isset( $new_options[ 'name' ] ) ) {
365
- $new_options[ 'profile_name' ] = $new_options[ 'name' ];
366
- unset( $new_options[ 'name' ] );
367
- }
368
-
369
- // Update the options, if changed, and return the result
370
-
371
- if ( $options != $new_options ) { update_option( 'youtube_embed_profile' . $profile, $new_options ); }
372
-
373
- // Remove added slashes from template XHTML
374
-
375
- $options[ 'template' ] = stripslashes( $options[ 'template' ] );
376
-
377
- }
378
-
379
- $profile++;
380
-
381
- }
382
-
383
- return $options;
384
- }
385
-
386
- /**
387
- * Function to set initial profile default options
388
- *
389
- * Sets default values for a profile
390
- *
391
- * @since 4.2
392
- *
393
- * @return array Profile array
394
- */
395
-
396
- function ye_set_profile_defaults( $profile ) {
397
-
398
- // Set profile name
399
-
400
- if ( $profile == 0 ) {
401
- $profname = 'Default';
402
- } else {
403
- $profname = 'Profile ' . $profile;
404
- }
405
-
406
- // Work out default dimensions
407
-
408
- $width = 0;
409
- if ( isset( $content_width ) ) { $width = $content_width; }
410
- if ( ( $width == 0 ) or ( $width == '' ) ) { $width = 560; }
411
- $height = 25 + round( ( $width / 16 ) * 9, 0 );
412
-
413
- // Set default array
414
-
415
- $default = array(
416
- 'profile_name' => $profname,
417
- 'width' => $width,
418
- 'height' => $height,
419
- 'fullscreen' => 1,
420
- 'template' => '%video%',
421
- 'autoplay' => '',
422
- 'start' => 0,
423
- 'loop' => '',
424
- 'cc' => '',
425
- 'cc_lang' => '',
426
- 'annotation' => 1,
427
- 'related' => 1,
428
- 'info' => 1,
429
- 'stop' => 0,
430
- 'disablekb' => '',
431
- 'controls' => 1,
432
- 'style' => '',
433
- 'color' => 'red',
434
- 'modest' => '',
435
- 'dynamic' => '',
436
- 'fixed' => '',
437
- 'download' => '',
438
- 'download_style' => '',
439
- 'download_text' => 'Click here to download the video',
440
- 'playsinline' => '',
441
- 'language' => ''
442
- );
443
-
444
- return $default;
445
-
446
- }
447
-
448
- /**
449
- * Function to get list options
450
- *
451
- * Return lists. It's in a seperate function in case any further shared
452
- * functionality needs to be added.
453
- *
454
- * @since 4.2
455
- *
456
- * @param string $list List number
457
- * @return strings Options array
458
- */
459
-
460
- function ye_get_list( $list ) {
461
-
462
- $options = get_option( 'youtube_embed_list' . $list );
463
-
464
- // If there is no list set up, set to default values and save
465
-
466
- if ( !is_array( $options ) ) {
467
- $options = ye_set_list_defaults( $list );
468
- $options[ 'default' ] = true;
469
- } else {
470
- $options[ 'default' ] = false;
471
- }
472
-
473
- return $options;
474
- }
475
-
476
- /**
477
- * Function to set default list options
478
- *
479
- * Looks up list options, based on passed number of lists.
480
- * If any options are missing, set default values
481
- *
482
- * @since 2.0
483
- *
484
- * @param string $list Number of lists
485
- */
486
-
487
- function ye_set_list( $lists ) {
488
-
489
- $list = 1;
490
- while ( $list <= $lists ) {
491
-
492
- $options = get_option( 'youtube_embed_list' . $list );
493
-
494
- // Only process if array exists
495
-
496
- if ( is_array( $options ) ) {
497
-
498
- // Because of upgrading, check each option - if not set, apply default
499
-
500
- $default_array = ye_set_list_defaults( $list );
501
-
502
- // Merge the two arrays
503
-
504
- $new_options = array_merge( $default_array, $options );
505
-
506
- // Because I've changed the variable name from name to list_name, convert any with the old name
507
-
508
- if ( isset( $new_options[ 'name' ] ) ) {
509
- $new_options[ 'list_name' ] = $new_options[ 'name' ];
510
- unset( $new_options[ 'name' ] );
511
- }
512
-
513
- // Update the options, if changed, and return the result
514
-
515
- if ( $options != $new_options ) { update_option( 'youtube_embed_list' . $list, $new_options ); }
516
-
517
- }
518
-
519
- $list++;
520
- }
521
-
522
- return;
523
- }
524
-
525
-
526
- /**
527
- * Function to set initial list default options
528
- *
529
- * Sets default values for a list
530
- *
531
- * @since 4.2
532
- *
533
- * @param string $list List number
534
- * @return array List array
535
- */
536
-
537
- function ye_set_list_defaults( $list ) {
538
-
539
- $default = array(
540
- 'list_name' => 'List ' . $list,
541
- 'list' => ''
542
- );
543
-
544
- return $default;
545
- }
546
-
547
- /**
548
- * Output timing
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( '&#8211;', '&#8212;', '&#215;' );
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 youtube-embed
8
- * @since 2.0
9
- */
10
-
11
- /**
12
- * Default Video shortcode
13
- *
14
- * Main [youtube] shortcode to display video
15
- *
16
- * @since 2.0
17
- *
18
- * @uses ye_video_shortcode Action the shortcode parameters
19
- *
20
- * @param string $paras Shortcode parameters
21
- * @param string $content Shortcode content
22
- * @return string YouTube embed code
23
- */
24
-
25
- function ye_video_shortcode_default( $paras = '', $content = '' ) {
26
-
27
- return do_shortcode( ye_video_shortcode( $paras, $content ) );
28
-
29
- }
30
-
31
- add_shortcode( 'youtube', 'ye_video_shortcode_default' );
32
-
33
- /**
34
- * Alternative Video shortcode 1
35
- *
36
- * 1st alternative shortcode to display video
37
- *
38
- * @since 2.0
39
- *
40
- * @uses ye_video_shortcode Action the shortcode parameters
41
- *
42
- * @param string $paras Shortcode parameters
43
- * @param string $content Shortcode content
44
- * @return string YouTube embed code
45
- */
46
-
47
- function ye_video_shortcode_alt( $paras = '', $content = '' ) {
48
-
49
- return do_shortcode( ye_video_shortcode( $paras, $content, '', true ) );
50
-
51
- }
52
-
53
- $shortcode = ye_get_shortcode();
54
-
55
- if ( isset( $shortcode ) && $shortcode != '' ) { add_shortcode( $shortcode, 'ye_video_shortcode_alt' ); }
56
-
57
- /**
58
- * Video shortcode
59
- *
60
- * Use shortcode parameters to embed a YouTube video or playlist
61
- *
62
- * @since 2.0
63
- *
64
- * @uses ye_get_embed_type Get the embed type
65
- * @uses ye_set_autohide Get the autohide parameter
66
- * @uses ye_get_general_defaults Set default options
67
- * @uses ye_generate_youtube_code Generate the embed code
68
- *
69
- * @param string $paras Shortcode parameters
70
- * @param string $content Shortcode content
71
- * @param string $alt_shortcode The number of the alternative shortcode used
72
- * @return string YouTube embed code
73
- */
74
-
75
- function ye_video_shortcode( $paras = '', $content = '', $callback = '', $alt_shortcode = false ) {
76
-
77
- extract( shortcode_atts( array( 'width' => '', 'height' => '', 'fullscreen' => '', 'related' => '', 'autoplay' => '', 'loop' => '', 'start' => '', 'info' => '', 'annotation' => '', 'cc' => '', 'cc_lang' => '', 'language' => '', 'style' => '', 'stop' => '', 'disablekb' => '', 'ratio' => '', 'controls' => '', 'profile' => '', 'id' => '', 'url' => '', 'rel' => '', 'fs' => '', 'cc_load_policy' => '', 'iv_load_policy' => '', 'showinfo' => '', 'youtubeurl' => '', 'template' => '', 'list' => '', 'color' => '', 'dynamic' => '', 'responsive' => '', 'h' => '', 'w' => '', 'search' => '', 'user' => '', 'modest' => '', 'playsinline' => '' ), $paras ) );
78
-
79
- // If no profile specified and an alternative shortcode used, get that shortcodes default profile
80
-
81
- if ( ( $profile == '' ) && ( $alt_shortcode ) ) {
82
-
83
- // Get general options
84
-
85
- $options = ye_get_general_defaults();
86
- $profile = $options[ 'alt_profile' ];
87
- }
88
-
89
- // If an alternative field is set, use it
90
-
91
- if ( ( $id != '' ) && ( $content == '' ) ) { $content = $id; }
92
- if ( ( $url != '' ) && ( $content == '' ) ) { $content = $url; }
93
- if ( ( $youtubeurl != '' ) && ( $content == '' ) ) { $content = $youtubeurl; }
94
-
95
- if ( ( $h != '' ) && ( $height == '' ) ) { $height = $h; }
96
- if ( ( $w != '' ) && ( $width == '' ) ) { $width = $w; }
97
-
98
- if ( ( $rel != '' ) && ( $related == '' ) ) { $related = $rel;}
99
- if ( ( $fs != '' ) && ( $fullscreen == '' ) ) { $fullscreen = $fs;}
100
- if ( ( $cc_load_policy != '' ) && ( $cc == '' ) ) { $cc = $cc_load_policy;}
101
- if ( ( $iv_load_policy != '' ) && ( $annotation == '' ) ) { $annotation = $iv_load_policy;}
102
- if ( ( $showinfo != '' ) && ( $info == '' ) ) { $info = $showinfo;}
103
-
104
- // If ID was not passed in the content and the first parameter is set, assume that to be the ID
105
-
106
- if ( ( $content == '' ) && ( $paras[ 0 ] != '' ) ) {
107
- $content = $paras[ 0 ];
108
- if ( (substr( $content, 0, 1 ) == ":" ) or ( substr( $content, 0, 1 ) == "=" ) ) { $content = substr( $content, 1 ); }
109
-
110
- if ( array_key_exists( 1, $paras ) ) {
111
- if ( $paras[ 1 ] != '' ) { $width = $paras[ 1 ]; }
112
- }
113
- if ( array_key_exists( 2, $paras ) ) {
114
- if ( $paras[ 2 ] != '' ) { $height = $paras[ 2 ]; }
115
- }
116
- }
117
-
118
- // If no responsive parameter specified use the deprecated dynamic parameter instead
119
-
120
- if ( $responsive == '' ) { $responsive = $dynamic; }
121
-
122
- // Create YouTube code
123
-
124
- $array = array(
125
- 'id' => $content,
126
- 'width' => $width,
127
- 'height' => $height,
128
- 'fullscreen' => ye_convert( $fullscreen ),
129
- 'related' => ye_convert( $related ),
130
- 'autoplay' => ye_convert( $autoplay ),
131
- 'loop' => ye_convert( $loop ),
132
- 'start' => $start,
133
- 'info' => ye_convert( $info ),
134
- 'annotation' => ye_convert_3( $annotation ),
135
- 'cc' => ye_convert( $cc ),
136
- 'style' => $style,
137
- 'stop' => $stop,
138
- 'disablekb' => ye_convert( $disablekb ),
139
- 'ratio' => $ratio,
140
- 'controls' => $controls,
141
- 'profile' => $profile,
142
- 'list_style' => $list,
143
- 'template' => $template,
144
- 'color' => $color,
145
- 'responsive' => ye_convert( $responsive ),
146
- 'search' => ye_convert( $search ),
147
- 'user' => ye_convert( $user ),
148
- 'modest' => ye_convert( $modest ),
149
- 'playsinline' => ye_convert( $playsinline ),
150
- 'cc_lang' => $cc_lang,
151
- 'language' => $language
152
- );
153
-
154
- $youtube_code = ye_generate_youtube_code( $array );
155
-
156
- return apply_filters( 'a3_lazy_load_html', do_shortcode( $youtube_code ) );
157
- }
158
-
159
- /**
160
- * Return a thumbnail URL
161
- *
162
- * Shortcode to return the URL for a thumbnail
163
- *
164
- * @since 2.0
165
- *
166
- * @uses ye_generate_thumbnail_code Generate the thumbnail code
167
- *
168
- * @param string $paras Shortcode parameters
169
- * @param string $content Shortcode content
170
- * @return string YouTube thumbnail code
171
- */
172
-
173
- function ye_thumbnail_sc( $paras = '', $content = '' ) {
174
-
175
- extract( shortcode_atts( array( 'style' => '', 'class' => '', 'rel' => '', 'target' => '', 'width' => '', 'height' => '', 'alt' => '', 'version' => '', 'nolink' => '' ), $paras ) );
176
-
177
- $array = array(
178
- 'id' => $content,
179
- 'style' => $style,
180
- 'class' => $class,
181
- 'rel' => $rel,
182
- 'target' => $target,
183
- 'width' => $width,
184
- 'height' => $height,
185
- 'alt' => $alt,
186
- 'version' => $version,
187
- 'nolink' => $nolink
188
- );
189
-
190
- return do_shortcode( ye_generate_thumbnail_code( $array ) );
191
-
192
- }
193
-
194
- add_shortcode( 'youtube_thumb', 'ye_thumbnail_sc' );
195
-
196
- /**
197
- * Video Information Shortcode
198
- *
199
- * Shortcode to return video information
200
- *
201
- * @since 5.0
202
- *
203
- * @uses ye_generate_vinfo_code Generate the video information code
204
- *
205
- * @param string $paras Shortcode parameters
206
- * @param string $content Shortcode content
207
- * @return string Video information code
208
- */
209
-
210
- function ye_vinfo_sc( $paras = '', $content = '' ) {
211
-
212
- extract( shortcode_atts( array( 'id' => '' ), $paras ) );
213
-
214
- return do_shortcode( ye_generate_vinfo_code( $id, $content ) );
215
-
216
- }
217
-
218
- add_shortcode( 'vinfo', 'ye_vinfo_sc' );
219
-
220
- /**
221
- * Short URL shortcode
222
- *
223
- * Generate a short URL for a YouTube video
224
- *
225
- * @since 2.0
226
- *
227
- * @uses ye_generate_shorturl_code Generate the code
228
- *
229
- * @param string $paras Shortcode parameters
230
- * @param string $content Shortcode content
231
- * @return string YouTube short URL code
232
- */
233
-
234
- function ye_shorturl_sc( $paras = '', $content = '' ) {
235
-
236
- extract( shortcode_atts( array( 'id' => '' ), $paras ) );
237
-
238
- return do_shortcode( ye_generate_shorturl_code( $id ) );
239
-
240
- }
241
-
242
- add_shortcode( 'youtube_url', 'ye_shorturl_sc' );
243
-
244
- /**
245
- * Download shortcode
246
- *
247
- * Generate a short URL for a YouTube video
248
- *
249
- * @since 2.0
250
- *
251
- * @uses ye_generate_download_code Generate the download code
252
- *
253
- * @param string $paras Shortcode parameters
254
- * @param string $content Shortcode content
255
- * @return string YouTube download link
256
- */
257
-
258
- function ye_video_download( $paras = '', $content = '' ) {
259
-
260
- extract( shortcode_atts( array( 'id' => '' ), $paras ) );
261
-
262
- if ( $id == '' ) { return do_shortcode( ye_error( __ ( 'No YouTube ID was found.', 'youtube-embed' ) ) ); }
263
-
264
- // Extract the ID if a full URL has been specified
265
-
266
- $id = ye_extract_id( $id );
267
-
268
- // Extract the API data
269
-
270
- $data = ye_get_api_data( $id );
271
-
272
- if ( $data[ 'type' ] != 'v' or !$data[ 'valid' ] ) {
273
-
274
- return do_shortcode( ye_error( sprintf( __( 'The YouTube ID of %s is invalid.', 'youtube-embed' ), $id ) ) );
275
-
276
- }
277
-
278
- // Get the download code
279
-
280
- $link = ye_generate_download_code( $id );
281
-
282
- // Now return the HTML
283
-
284
- return do_shortcode( $link );
285
- }
286
-
287
- add_shortcode( 'download_video', 'ye_video_download' );
288
-
289
- /**
290
- * Convert input to a 1 or 3 equivalent
291
- *
292
- * Function to convert a Yes or No input to an equivalent 1 or 3 output
293
- *
294
- * @since 2.0
295
- *
296
- * @uses ye_yes_or_no Convert input to a true or false equivalent
297
- *
298
- * @param string $input Input, usually Yes or No
299
- * @return string 1, 3 or blank, depending on input
300
- */
301
-
302
- function ye_convert_3( $input ) {
303
-
304
- $input = ye_yes_or_no( $input );
305
- $output = '';
306
- if ( $input === true ) { $output = '1'; }
307
- if ( $input === false ) { $output = '3'; }
308
-
309
- return $output;
310
- }
311
-
312
- /**
313
- * Convert input to True or False (1.0)
314
- *
315
- * Return true or false, depending on the input. Possible inputs are Yes, No, 0, 1, True,
316
- * False, On, Off
317
- *
318
- * @since 2.0
319
- *
320
- * @param string $input Value passed for checking
321
- * @return string Blank string or boolean true, false
322
- */
323
-
324
- function ye_yes_or_no( $input = '' ) {
325
-
326
- $input = strtolower( $input );
327
- if ( ( $input === true ) or ( $input == 'true' ) or ( $input == '1' ) or ( $input == 'yes' ) or ( $input == 'on' ) ) { return true; }
328
- if ( ( $input === false ) or ( $input == 'false' ) or ( $input == '0' ) or ( $input == 'no' ) or ( $input == 'off' ) ) { return false; }
329
-
330
- return;
331
- }
332
-
333
- /**
334
- * Convert autohide parameter
335
- *
336
- * Convert autohide text value to a numeric equivalent
337
- *
338
- * @since 2.0
339
- *
340
- * @param string $autohide Autohide parameter value
341
- * @return string Autohide numeric equivalent
342
- */
343
-
344
- function ye_set_autohide( $autohide ) {
345
-
346
- $autohide = strtolower( $autohide );
347
- if ( $autohide == 'no' ) { $autohide = '0'; }
348
- if ( $autohide == 'yes' ) { $autohide = '1'; }
349
- if ( $autohide == 'fade' ) { $autohide = '2'; }
350
-
351
- return $autohide;
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.1.1
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 YouTube Embed menu option and then General Settings 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 `General 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
- First, head to the [YouTube Developers Console](https://console.developers.google.com/project "Developers Console") and create a project. Click on this project and head to "Credentials" in the side menu. Click on "Create credentials" and from the drop-down select API Key. You will be prompted for the type of key so select "Server key". Name it and then press Create. The API key will be shown.
 
 
 
 
 
 
 
 
 
 
 
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 General Settings from the YouTube Embed menu 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]]`.
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 YouTube Embed administration menu is a sub-menu named General Settings. Select this and find the section named Embedding. There are 2 options here that have not been covered already...
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.1.1 =
547
- * Whilst we'd holed up at home, it's bug fix time!
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 youtube-embed
8
- * @since 2.0
9
- */
10
-
11
- // If the uninstall was not called by WordPress, exit
12
-
13
- if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit(); }
14
-
15
- // Read the general options (will tell us how many profile and list options there should be
16
-
17
- $options = get_option( 'youtube_embed_general' );
18
-
19
- // If the general options existed, delete it!
20
-
21
- if ( is_array( $options ) ) {
22
-
23
- delete_option( 'youtube_embed_general' );
24
-
25
- // If the number of profiles field exists, delete each one in turn
26
-
27
- if ( isset( $options[ 'profile_no' ] ) ) {
28
- $loop = 0;
29
- while ( $loop <= $options[ 'profile_no' ] ) {
30
- delete_option( 'youtube_embed_profile' . $loop );
31
- $loop ++;
32
- }
33
- }
34
-
35
- // If the number of lists field exists, delete each one in turn
36
-
37
- if ( isset( $options[ 'list_no' ] ) ) {
38
- $loop = 1;
39
- while ( $loop <= $options[ 'list_no' ] ) {
40
- delete_option( 'youtube_embed_list' . $loop );
41
- $loop ++;
42
- }
43
- }
44
- }
45
-
46
- // Delete all other options
47
-
48
- delete_option( 'youtube_embed_general' );
49
- delete_option( 'youtube_embed_shortcode' );
50
- delete_option( 'youtube_embed_shortcode_admin' );
51
- delete_option( 'youtube_embed_shortcode_site' );
52
- delete_option( 'youtube_embed_version' );
53
-
54
- // Remove any transient data
55
-
56
- global $wpdb;
57
- $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_youtubeembed_%' OR option_name LIKE '_transient_timeout_youtubeembed_%'";
58
- $wipe = $wpdb -> query( $sql );
 
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.1.1
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.1.1' );
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.