forked from futtta/wp-youtube-lyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.php
514 lines (481 loc) · 26 KB
/
options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
require( 'lytePartners.php');
$plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
add_action('admin_menu', 'lyte_create_menu');
if ( get_option( 'lyte_emptycache','0') === '1') {
$emptycache = lyte_rm_cache();
update_option( 'lyte_emptycache','0' );
if ( $emptycache === 'OK' ) {
add_action( 'admin_notices', 'lyte_cacheclear_ok_notice' );
} elseif ( $emptycache === 'PART') {
add_action( 'admin_notices', 'lyte_cacheclear_part_notice' );
update_option( 'lyte_emptycache', '1' ); // to ensure cache-purging continues
} else {
add_action( 'admin_notices', 'lyte_cacheclear_fail_notice' );
}
}
function lyte_cacheclear_ok_notice() {
echo '<div class="updated"><p>';
_e( 'Your WP YouTube Lyte cache has been succesfully cleared.', 'wp-youtube-lyte' );
echo '</p></div>';
}
function lyte_cacheclear_part_notice() {
echo '<div class="error"><p>';
_e( 'WP YouTube Lyte cache was partially cleared, refresh this page to continue purging.', 'wp-youtube-lyte' );
echo '</p></div>';
}
function lyte_cacheclear_fail_notice() {
echo '<div class="error"><p>';
_e( 'There was a problem, the WP YouTube Lyte cache could not be cleared.', 'wp-youtube-lyte' );
echo '</p></div>';
}
function lyte_create_menu() {
$hook=add_options_page( 'WP YouTube Lyte settings', 'WP YouTube Lyte', 'manage_options', 'lyte_settings_page', 'lyte_settings_page');
add_action( 'admin_init', 'register_lyte_settings' );
add_action( 'admin_print_scripts-' . $hook, 'lyte_admin_scripts' );
add_action( 'admin_print_styles-' . $hook, 'lyte_admin_styles' );
}
function register_lyte_settings() {
register_setting( 'lyte-settings-group', 'lyte_show_links' );
register_setting( 'lyte-settings-group', 'lyte_size' );
register_setting( 'lyte-settings-group', 'lyte_hidef' );
register_setting( 'lyte-settings-group', 'lyte_position' );
register_setting( 'lyte-settings-group', 'lyte_microdata' );
register_setting( 'lyte-settings-group', 'lyte_emptycache' );
register_setting( 'lyte-settings-group', 'lyte_greedy' );
register_setting( 'lyte-settings-group', 'lyte_yt_api_key' );
register_setting( 'lyte-settings-group', 'lyte_local_thumb' );
register_setting( 'lyte-settings-group', 'lyte_disclaimer' );
}
function lyte_admin_scripts() {
wp_enqueue_script('jqcookie', plugins_url( '/external/jquery.cookie.min.js', __FILE__) , array( 'jquery' ), null, true );
wp_enqueue_script('unslider', plugins_url( '/external/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
}
function lyte_admin_styles() {
wp_enqueue_style( 'unslider', plugins_url( '/external/unslider.css', __FILE__ ) );
wp_enqueue_style( 'unslider-dots', plugins_url( '/external/unslider-dots.css', __FILE__ ) );
}
function lyte_admin_nag_apikey() {
echo '<div class="update-nag">';
_e( 'For WP YouTube Lyte to function optimally, you should enter an YouTube API key ', 'wp-youtube-lyte' );
echo ' <a href="options-general.php?page=lyte_settings_page">';
_e( 'in the settings screen.', 'wp-youtube-lyte' );
echo '</a>.</div>';
}
$lyte_yt_api_key = get_option( 'lyte_yt_api_key', '' );
$lyte_yt_api_key = apply_filters( 'lyte_filter_yt_api_key', $lyte_yt_api_key );
if ( empty( $lyte_yt_api_key ) ) {
add_action( 'admin_notices', 'lyte_admin_nag_apikey' );
}
function lyte_admin_api_error(){
$yt_error = json_decode( get_option( 'lyte_api_error' ), 1 );
echo '<div class="error"><p>';
_e( 'WP YouTube Lyte got the following error back from the YouTube API: ', 'wp-youtube-lyte' );
echo '<strong>' . $yt_error['reason'] . '</strong>';
echo ' (' . date('r', $yt_error['timestamp'] ) . ').';
echo '</a>.</p></div>';
update_option( 'lyte_api_error', '' );
}
if ( get_option( 'lyte_api_error', '' ) !== '' ) {
add_action( 'admin_notices', 'lyte_admin_api_error' );
}
function lyte_settings_page() {
global $pSize, $pSizeOrder;
?>
<style>
/* rss block */
#futtta_feed ul{list-style:outside;}
#futtta_feed {font-size:medium; margin:0px 20px;}
/* banner + unslider */
.lyte_banner {
margin: 0 38px;
padding-bottom: 5px;
}
.lyte_banner ul li {
font-size:medium;
text-align:center;
}
.unslider {
position:relative;
}
.unslider-arrow {
display: block;
left: unset;
margin-top: -35px;
margin-left: 7px;
margin-right: 7px;
border-radius: 32px;
background: rgba(0, 0, 0, 0.10) no-repeat 50% 50%;
color: rgba(255, 255, 255, 0.8);
font: normal 20px/1 dashicons;
speak: none;
padding: 3px 2px 3px 4px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.unslider-arrow:hover {
background-color: rgba(0, 0, 0, 0.20);
color: #FFF;
}
.unslider-arrow.prev {
padding: 3px 4px 3px 2px;
}
.unslider-arrow.next {
right: 0px;
}
.unslider-arrow.prev::before {
content: "\f341";
}
.unslider-arrow.next::before {
content: "\f345";
}
/* responsive stuff: hide admin-feed on smaller screens */
@media (min-width: 961px) {
#lyte_main {float:left;width:69%;}
#lyte_admin_feed{float:right;width:30%;display:block !important;}
}
@media (max-width: 960px) {
#lyte_main {width:100%;}
#lyte_admin_feed {width:0%;display:none !important;}
}
@media (max-width: 782px) {
#lyte_hide_adv span, #lyte_show_adv span {display: none;}
#lyte_hide_adv,#lyte_show_adv {height: 34px;padding: 4px 12px 8px 8px;}
#lyte_hide_adv:before,#lyte_show_adv:before {font-size: 25px;}
#lyte_main input[type="checkbox"] {margin-left: 10px;}
#lyte_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
}
</style>
<div class="wrap">
<h2><?php _e( 'WP YouTube Lyte Settings', 'wp-youtube-lyte' ); ?></h2>
<div style="float:left;width:70%;">
<?php echo lyte_admin_tabs(); ?>
<form method="post" action="options.php">
<?php settings_fields( 'lyte-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e( 'Your YouTube API key.', 'wp-youtube-lyte' ); ?></th>
<td>
<?php // only show api key input field if there's no result from filter
$filter_key = apply_filters( 'lyte_filter_yt_api_key', '' );
if ( empty( $filter_key ) ) { ?>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Please enter your YouTube API key.', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'API key', 'wp-youtube-lyte' ); ?>"><input type="text" size="28" name="lyte_yt_api_key" id="lyte_yt_api_key" value="<?php echo esc_attr( wp_strip_all_tags( get_option( 'lyte_yt_api_key', '' ) ) ); ?>"><span id="check_api_key" class="submit button-secondary" style="margin:0px 5px;"><?php _e( 'Test Key' ); ?></span></label><br />
<div id="lyte_key_check_output" style="display:none;margin-bottom:5px;background-color:white;border-left:solid;border-width:4px;border-color:#2ea2cc;padding:5px 5px 5px 15px;"></div>
<?php _e( "WP YouTube Lyte uses YouTube's API to fetch information on each video. For your site to use that API, you will have to <a href=\"https://console.developers.google.com/project/\" target=\"_blank\">register your site as a new application</a>, enable the YouTube API for it and get a server key and fill it out here.", 'wp-youtube-lyte' ); ?>
</fieldset>
<?php } else { ?>
<?php _e( 'Great, your YouTube API key has been taken care of!', 'wp-youtube-lyte' ); ?>
<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Player size', 'wp-youtube-lyte' ); ?>:</th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Player size', 'wp-youtube-lyte' ); ?></span></legend>
<?php
$sel = ! is_bool( get_option( 'lyte_size' ) ) ? (int) get_option( 'lyte_size' ) : 0;
foreach ( array ( '169', '43' ) as $f ) {
foreach ( $pSizeOrder[$f] as $i ) {
$pS = $pSize[$i];
if ( $pS['a'] === true ) {
?>
<label title="<?php echo $pS['w'] . 'X' . $pS['h']; ?>"><input type="radio" name="lyte_size" class="l_size" value="<?php echo $i . '"'; if ( $i===$sel ) echo ' checked'; echo ' /> ' . $pS['w'] . 'X' . $pS['h'] . ' (' . $pS['t'] ;?>)</label><br />
<?php
}
}
?><br /><?php
}
?>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Add links below the embedded videos?', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Show links?', 'wp-youtube-lyte' ) ?></span></legend>
<label title="<?php _e( 'Show YouTube-link', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_show_links" value="1" <?php if ( get_option( 'lyte_show_links') === '1' || get_option( 'lyte_show_links') === '2' ) echo 'checked' ?> /><?php _e( ' Add YouTube-link.', 'wp-youtube-lyte') ?></label><br />
<label title="<?php _e( 'Don\'t include links.', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_show_links" value="0" <?php if ( ( get_option( 'lyte_show_links' ) !== '1' ) && ( get_option( 'lyte_show_links')!=="2")) echo 'checked' ?> /><?php _e( ' Don\'t add any links.', 'wp-youtube-lyte' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Player position:', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Left, center or right?', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'Left', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_position" value="0" <?php if ( get_option( 'lyte_position', '0' ) === '0') echo 'checked' ?> /><?php _e( 'Left', 'wp-youtube-lyte' ); ?></label><br />
<label title="<?php _e( 'Center', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_position" value="1" <?php if ( get_option( 'lyte_position', '0' ) === '1') echo 'checked' ?> /><?php _e( 'Center', 'wp-youtube-lyte' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Try to force HD?', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'HD or not?', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'Enable HD?', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_hidef" value="1" <?php if ( get_option( 'lyte_hidef','0') === '1') echo 'checked' ?> /><?php _e( 'Enable HD', 'wp-youtube-lyte' ); ?></label><br />
<label title="<?php _e( 'Don\'t enable HD playback', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_hidef" value="0" <?php if ( get_option( 'lyte_hidef','0') !== '1' ) echo 'checked' ?> /><?php _e( 'No HD (default)', 'wp-youtube-lyte' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Add microdata?', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Add video microdata to the HTML?', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'Sure, add microdata!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_microdata" value="1" <?php if ( get_option( 'lyte_microdata', '1' ) === '1') echo 'checked' ?> /><?php _e( 'Yes (default)', 'wp-youtube-lyte' ); ?></label><br />
<label title="<?php _e( 'No microdata in my HTML please.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_microdata" value="0" <?php if ( get_option( 'lyte_microdata', '1' ) !== '1' ) echo 'checked' ?> /><?php _e( 'No microdata, thanks.', 'wp-youtube-lyte' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Also act on normal YouTube links and iframes?', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Also act on normal YouTube links?', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'That would be great!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_greedy" value="1" <?php if ( get_option( 'lyte_greedy', '1' ) === '1') echo 'checked' ?> /><?php _e( 'Yes (default)', 'wp-youtube-lyte' ); ?></label><br />
<label title="<?php _e( 'No, I\'ll stick to httpv or shortcodes.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_greedy" value="0" <?php if ( get_option( 'lyte_greedy', '1' ) !== '1' ) echo 'checked' ?> /><?php _e( 'No thanks.', 'wp-youtube-lyte' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Cache thumbnails locally?', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Cache thumbnails locally?', 'wp-youtube-lyte' ); ?></span></legend>
<label title="<?php _e( 'That would be great!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_local_thumb" value="1" <?php if ( get_option( 'lyte_local_thumb','0') === '1') echo 'checked' ?> /><?php _e( 'Yes.', 'wp-youtube-lyte' ); ?></label><br />
<label title="<?php _e( 'No, keep on using YouTube hosted thumbnails.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_local_thumb" value="0" <?php if ( get_option( 'lyte_local_thumb','0') !== '1' ) echo 'checked' ?> /><?php _e( 'No (default).', 'wp-youtube-lyte' ); ?></label>
<br />
<?php _e( 'Having the thumbnails cached locally can improve performance and will enhance visitor privacy as by default no requests will be sent to YouTube unless the video is played.', 'wp-youtube-lyte' ); ?>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Text to be added under every LYTE video.', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Text (e.g. for disclaimer) to be added under every LYTE video.', 'wp-youtube-lyte' ); ?></span></legend>
<input type="text" style="width:100%;" name="lyte_disclaimer" placeholder="" value="<?php echo esc_textarea( get_option( 'lyte_disclaimer', '' ) ); ?>" /><br />
<br />
<?php _e( 'If you want to add e.g. a privacy disclaimer under every LYTE embedded video, you can do so here. Some HTML is allowed. Simply leave empty not to show anything.', 'wp-youtube-lyte' ); ?>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Empty WP YouTube Lyte\'s cache', 'wp-youtube-lyte' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Remove WP YouTube Lyte's cache</span></legend>
<input type="checkbox" name="lyte_emptycache" value="1" />
</fieldset>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
</p>
</form>
</div>
<div id="lyte_admin_feed" class="">
<div class="lyte_banner ">
<ul>
<?php
if ( apply_filters('wp-youtube-lyte_settingsscreen_remotehttp', true ) ) {
$lyte_banner = get_transient( 'wp-youtube-lyte_banner' );
if ( empty( $lyte_banner ) ) {
$banner_resp = wp_remote_get('https://misc.optimizingmatters.com/wp-youtube-lyte_news.html');
if ( ! is_wp_error( $banner_resp ) ) {
if ( wp_remote_retrieve_response_code( $banner_resp ) == '200' ) {
$lyte_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
set_transient( 'wp-youtube-lyte_banner', $lyte_banner, DAY_IN_SECONDS );
}
}
}
echo $lyte_banner;
}
?>
<li><?php _e( 'Need help? <a href="https://wordpress.org/plugins/wp-youtube-lyte/faq/">Check out the FAQ here</a>.', 'wp-youtube-lyte' ); ?></li>
<li><?php _e( 'Happy with wp-youtube-lyte?', 'wp-youtube-lyte' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'wp-youtube-lyte' ); ?></a></li>
</ul>
</div>
<div style="margin-left:10px;margin-top:-5px;">
<h2>
<?php _e( 'futtta about', 'wp-youtube-lyte' ); ?>
<select id="feed_dropdown" >
<option value="1"><?php _e( 'WP YouTube Lyte', 'wp-youtube-lyte' ); ?></option>
<option value="2"><?php _e( 'WordPress', 'wp-youtube-lyte' ); ?></option>
<option value="3"><?php _e( 'Web Technology', 'wp-youtube-lyte' ); ?></option>
</select>
</h2>
<div id="futtta_feed">
<div id="wp-youtube-lytefeed">
<?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_wp-youtube-lyte' ); ?>
</div>
<div id="wordpressfeed">
<?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_wordpress' ); ?>
</div>
<div id="webtechfeed">
<?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_webtech'); ?>
</div>
</div>
</div>
<div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'wp-youtube-lyte' ); ?>"></a></div>
</div>
<script type="text/javascript">
var feed = new Array;
feed[1]="wp-youtube-lytefeed";
feed[2]="wordpressfeed";
feed[3]="webtechfeed";
cookiename="wp-youtube-lyte_feed";
jQuery(document).ready(function() {
jQuery( "#check_api_key" ).click(function() {
jQuery("#lyte_key_check_output").show();
jQuery("#lyte_key_check_output").append("<p><?php _e( 'Checking your key ...'); ?></p>");
lyte_yt_api_key=jQuery("input#lyte_yt_api_key").val();
if ((lyte_yt_api_key.length>9) &&(lyte_yt_api_key.length<99)) {
var data = {
'action': 'lyte_check_yt_api_key',
'lyte_nonce': '<?php echo wp_create_nonce( "lyte_check_api_key" );?>',
'lyte_yt_api_key': jQuery("input#lyte_yt_api_key").val()
};
jQuery.post(ajaxurl, data, function(response) {
jQuery("#lyte_key_check_output").append('<p>'+response+'</p>');
});
} else {
jQuery("#lyte_key_check_output").append('<p><?php _e( "That does not seem to be a correct API key!"); ?></p>');
}
})
jQuery('#lyte_admin_feed').fadeTo("slow",1).show();
jQuery('.lyte_banner').unslider({autoplay:true, delay:3500, infinite: false, arrows:{prev:'<a class="unslider-arrow prev"></a>', next:'<a class="unslider-arrow next"></a>'}}).fadeTo("slow",1).show();
jQuery( "#feed_dropdown" ).change(function() {
jQuery("#futtta_feed").fadeTo(0,0);
jQuery("#futtta_feed").fadeTo("slow",1);
});
jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
feedid=jQuery.cookie(cookiename);
if(typeof(feedid) !== "string") feedid=1;
show_feed(feedid);
})
function show_feed(id) {
jQuery('#futtta_feed').children().hide();
jQuery('#'+feed[id]).show();
jQuery("#feed_dropdown").val(id);
jQuery.cookie(cookiename,id,{ expires: 365 });
}
</script>
</div>
<?php }
// ajax receiver for YT API key check
add_action( 'wp_ajax_lyte_check_yt_api_key', 'lyte_check_yt_api_key_callback' );
function lyte_check_yt_api_key_callback() {
check_ajax_referer( 'lyte_check_api_key', 'lyte_nonce' );
$api_key = ( esc_html( $_POST['lyte_yt_api_key'] ) === $_POST['lyte_yt_api_key'] ) ? $_POST['lyte_yt_api_key'] : '' ;
// use random video to make sure a cache is not spoiling things
$vidToCheck = array('ZmnZHudtzXg', '2_7oQcAkyl8', 'nOvv80wkSgI', 'pBCt5nfsZ30', 'KHw7gdJ14uQ', 'qJ_PMvjmC6M', 'DVwHCGAr_OE', 'LtOGa5M8AuU', 'VHO9uZX9FNU' );
$randVidIndex = array_rand( $vidToCheck );
if ( ! empty( $api_key ) ) {
$api_response = lyte_get_YT_resp( $vidToCheck[$randVidIndex], false, '', $api_key );
} else {
$api_response = 'API key format error.';
}
if ( is_array( $api_response ) ) {
if ( ! empty( $api_response['title'] ) ) {
_e( 'API seems OK, you can Save Changes below now.', 'wp-youtube-lyte' );
} else if ( ! empty($api_response['reason'] ) ) {
$all_but_one = __( 'API key not OK, your key seems to ', 'wp-youtube-lyte' );
switch ( $api_response['reason'] ) {
case 'keyInvalid':
echo $all_but_one;
_e( 'be invalid.', 'wp-youtube-lyte' );
break;
case 'ipRefererBlocked':
echo $all_but_one;
_e( 'be valid, but restricted to an IP-address which is not your server\'s.', 'wp-youtube-lyte' );
_e( 'Try changing the allowed IP for your API key to include this one: ', 'wp-youtube-lyte' );
echo $_SERVER["SERVER_ADDR"];
break;
case 'keyExpired':
echo $all_but_one;
_e( 'have expired, please check in the Google Developer Console.', 'wp-youtube-lyte' );
break;
case 'limitExceeded':
case 'quotaExceeded':
case 'rateLimitExceeded':
case 'userRateLimitExceeded':
echo $all_but_one;
_e( 'be correct, but seems to have exceeded the number of requests that can be made with it.', 'wp-youtube-lyte' );
break;
case 'videoNotFound':
echo $all_but_one;
_e( 'probably work, but as the video with id ', 'wp-youtube-lyte' );
echo $vidToCheck[$randVidIndex];
_e( ' was not found we cannot be sure, please try again.', 'wp-youtube-lyte' );
break;
default:
_e( 'Your API key might be OK, but the API call did not succeed or the response was not entirely expected. Technical error: ', 'wp-youtube-lyte' );
echo $api_response['reason'];
}
}
} else {
_e( 'Something went wrong, WP YouTube Lyte might not have been able to retrieve information from the YouTube API, got error: ', 'wp-youtube-lyte' );
print_r( $api_response );
}
wp_die();
}
function getFutttaFeeds($url) {
if ( apply_filters( 'lyte_settingsscreen_remotehttp', true ) ) {
$rss = fetch_feed( $url );
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) {
$maxitems = $rss->get_item_quantity( 7 );
$rss_items = $rss->get_items( 0, $maxitems );
}
?>
<ul>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'wp-youtube-lyte' ); ?></li>
<?php else : ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'wp-youtube-lyte' ), $item->get_date('j F Y | g:i a') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<?php
}
}
// based on http://wordpress.stackexchange.com/a/58826
function lyte_admin_tabs(){
$tabs = apply_filters( 'wp-youtube-lyte_filter_settingsscreen_tabs', array( 'lyte_settings_page' => __('Main', 'wp-youtube-lyte' ) ) );
$tabContent = '';
if ( count( $tabs ) >= 1 ) {
if( isset( $_GET['page'] ) ) {
$currentId = sanitize_text_field( $_GET['page'] );
} else {
$currentId = 'wp-youtube-lyte';
}
$tabContent .= '<h2 class="nav-tab-wrapper">';
foreach( $tabs as $tabId => $tabName ){
if( $currentId == $tabId ) {
$class = ' nav-tab-active';
} else{
$class = '';
}
$tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">' . $tabName . '</a>';
}
$tabContent .= '</h2>';
} else {
$tabContent = '<hr/>';
}
return $tabContent;
}
?>