This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwp-youtube-lyte.php
504 lines (422 loc) · 21.7 KB
/
wp-youtube-lyte.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
<?php
/*
Plugin Name: WP YouTube Lyte
Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
Description: Lite and accessible YouTube audio and video embedding.
Author: Frank Goossens (futtta)
Version: 1.3.3
Author URI: http://blog.futtta.be/
Text Domain: wp-youtube-lyte
Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) exit;
$debug=false;
$lyte_version="1.3.3";
$lyte_db_version=get_option('lyte_version','none');
/** have we updated? */
if ($lyte_db_version !== $lyte_version) {
switch($lyte_db_version) {
case "none":
lyte_options_update();
}
update_option('lyte_version',$lyte_version);
$lyte_db_version=$lyte_version;
}
/** are we in debug-mode */
if (!$debug) {
$wyl_version=$lyte_version;
$wyl_file="lyte-min.js";
} else {
$wyl_version=rand()/1000;
$wyl_file="lyte.js";
lyte_rm_cache();
}
/** get paths, language and includes */
$plugin_dir = basename(dirname(__FILE__)).'/languages';
load_plugin_textdomain( 'wp-youtube-lyte', null, $plugin_dir );
$wp_lyte_plugin_url = trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/';
require_once(dirname(__FILE__).'/player_sizes.inc.php');
require_once(dirname(__FILE__).'/widget.php');
/** get default embed size and build array to change size later if requested */
$oSize = (int) get_option('lyte_size');
if ((is_bool($oSize)) || ($pSize[$oSize]['a']===false)) { $sel = (int) $pDefault; } else { $sel=$oSize; }
$pSizeFormat=$pSize[$sel]['f'];
$j=0;
foreach ($pSizeOrder[$pSizeFormat] as $sizeId) {
$sArray[$j]['w']=(int) $pSize[$sizeId]['w'];
$sArray[$j]['h']=(int) $pSize[$sizeId]['h'];
if ($sizeId===$sel) $selSize=$j;
$j++;
}
/** get other options and push in array*/
$lyteSettings['sizeArray']=$sArray;
$lyteSettings['selSize']=$selSize;
$lyteSettings['path']=$wp_lyte_plugin_url.'lyte/';
$lyteSettings['links']=get_option('lyte_show_links');
$lyteSettings['file']=$wyl_file."?wyl_version=".$wyl_version;
$lyteSettings['ratioClass']= ( $pSizeFormat==="43" ) ? " fourthree" : "";
$lyteSettings['pos']= ( get_option('lyte_position','0')==="1" ) ? "margin:5px auto;" : "margin:5px;";
$lyteSettings['microdata']=get_option('lyte_microdata','1');
$lyteSettings['hidef']=get_option('lyte_hidef',0);
$lyteSettings['scheme'] = ( is_ssl() ) ? "https" : "http";
/** API: filter hook to alter $lyteSettings */
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
/** main function to parse the content, searching and replacing httpv-links */
function lyte_parse($the_content,$doExcerpt=false) {
global $lyteSettings;
$urlArr=parse_url($lyteSettings['path']);
$origin=$urlArr['scheme']."://".$urlArr['host']."/";
/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
$the_content = apply_filters( 'lyte_content_preparse',$the_content );
if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
$char_codes = array('×','–');
$replacements = array("x", "--");
$the_content=str_replace($char_codes, $replacements, $the_content);
$lyte_feed=is_feed();
$hidefClass = ($lyteSettings['hidef']==="1") ? " hidef" : "";
$postID = get_the_ID();
$toCache_index=array();
$lytes_regexp="/(?:<p>)?http(v|a):\/\/([a-zA-Z0-9\-\_]+\.|)(youtube|youtu)(\.com|\.be)\/(((watch(\?v\=|\/v\/)|.+?v\=|)([a-zA-Z0-9\-\_]{11}))|(playlist\?list\=(PL[a-zA-Z0-9\-\_]*)))([^\s<]*)(<?:\/p>)?/";
preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
foreach($matches as $match) {
/* echo "<pre>";
print_r($match);
echo "</pre>"; */
/** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
$match[12] = apply_filters( 'lyte_match_preparse_fragment',$match[12] );
preg_match("/stepSize\=([\+\-0-9]{2})/",$match[12],$sMatch);
preg_match("/showinfo\=([0-1]{1})/",$match[12],$showinfo);
preg_match("/start\=([0-9]*)/",$match[12],$start);
preg_match("/enablejsapi\=([0-1]{1})/",$match[12],$jsapi);
preg_match("/hqThumb\=([0-1]{1})/",$match[12],$hqThumb);
preg_match("/noMicroData\=([0-1]{1})/",$match[12],$microData);
$thumb="0.jpg";
if (!empty($hqThumb)) {
if ($hqThumb[0]==="hqThumb=1") {
$thumb="maxresdefault.jpg";
}
}
$noMicroData="0";
if (!empty($microData)) {
if ($microData[0]==="noMicroData=1") {
$noMicroData="1";
}
}
$qsa="";
if (!empty($showinfo[0])) {
$qsa="&".$showinfo[0];
$titleClass=" hidden";
} else {
$titleClass="";
}
if (!empty($start[0])) $qsa.="&".$start[0];
if (!empty($jsapi[0])) $qsa.="&".$jsapi[0]."&origin=".$origin;
if (!empty($qsa)) {
$esc_arr=array("&" => "\&", "?" => "\?", "=" => "\=");
$qsaClass=" qsa_".strtr($qsa,$esc_arr);
} else {
$qsaClass="";
}
if (!empty($sMatch)) {
$newSize=(int) $sMatch[1];
$newPos=(int) $lyteSettings['selSize']+$newSize;
if ($newPos<0) {
$newPos=0;
} else if ($newPos > count($lyteSettings['sizeArray'])-1) {
$newPos=count($lyteSettings['sizeArray'])-1;
}
$lyteSettings[2]=$lyteSettings['sizeArray'][$newPos]['w'];
$lyteSettings[3]=$lyteSettings['sizeArray'][$newPos]['h'];
} else {
$lyteSettings[2]=$lyteSettings['sizeArray'][$lyteSettings['selSize']]['w'];
$lyteSettings[3]=$lyteSettings['sizeArray'][$lyteSettings['selSize']]['h'];
}
if ($match[1]!=="a") {
$divHeight=$lyteSettings[3];
$audioClass="";
$audio=false;
} else {
$audio=true;
$audioClass=" lyte-audio";
$divHeight=38;
}
$NSimgHeight=$divHeight-20;
$NSbanner="Embedded with WP YouTube Lyte.";
if ($match[11]!="") {
$plClass=" playlist";
$vid=$match[11];
switch ($lyteSettings['links']) {
case "0":
$noscript_post="<br />".__("Watch this playlist on YouTube","wp-youtube-lyte");
$noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtube.com/playlist?list=PL".$vid."\">".$noscript_post."</a> ".$NSbanner."</noscript>";
$lytelinks_txt="";
break;
default:
$noscript="<noscript>".$NSbanner."</noscript>";
$lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".__("Watch this playlist","wp-youtube-lyte")." <a href=\"".$lyteSettings['scheme']."://www.youtube.com/playlist?list=PL".$vid."\">".__("on YouTube","wp-youtube-lyte")."</a></div>";
}
} else if ($match[9]!="") {
$plClass="";
$vid=$match[9];
switch ($lyteSettings['links']) {
case "0":
$noscript_post="<br />".__("Watch this video on YouTube","wp-youtube-lyte");
$lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\"></div>";
break;
case "2":
$noscript_post="";
$lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".__("Watch this video","wp-youtube-lyte")." <a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\">".__("on YouTube","wp-youtube-lyte")."</a> ".__("or on","wp-youtube-lyte")." <a href=\"http://icant.co.uk/easy-youtube/?http://www.youtube.com/watch?v=".$vid."\">Easy Youtube</a>.</div>";
break;
default:
$noscript_post="";
$lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".__("Watch this video","wp-youtube-lyte")." <a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\">".__("on YouTube","wp-youtube-lyte")."</a>.</div>";
}
$noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"\" width=\"".$lyteSettings[2]."\" height=\"".$NSimgHeight."\" />".$noscript_post."</a> ".$NSbanner."</noscript>";
}
/** logic to get video info from cache or get it from YouTube and set it */
if ( $postID ) {
// Check for a cached result (stored in the post meta)
$cachekey = '_lyte_' . $vid;
$yt_resp = get_post_meta( $postID, $cachekey, true );
if (!empty($yt_resp)) {
$yt_resp = gzuncompress(base64_decode($yt_resp));
}
} else {
$yt_resp = "";
}
if ( empty( $yt_resp ) ) {
// get info from youtube
$yt_api_base = "http://gdata.youtube.com/feeds/api/";
if ($plClass===" playlist") {
$yt_api_target = "playlists/".$vid."?v=2&alt=json&fields=id,title,author,updated,media:group(media:thumbnail)";
} else {
$yt_api_target = "videos/".$vid."?v=2&alt=json&fields=id,title,published,content,media:group(media:description,yt:duration,yt:aspectRatio),author(name)";
}
$yt_api_url = $yt_api_base.$yt_api_target;
$yt_resp = wp_remote_get($yt_api_url);
// check if we got through
if (is_wp_error($yt_resp)) {
$yt_resp="";
} else {
$yt_resp = wp_remote_retrieve_body($yt_resp);
if ( $postID ) {
// we can cache the result
// first add timestamp
$yt_resp_array=json_decode($yt_resp,true);
if(is_array($yt_resp_array)) {
//entry is new
$yt_resp_array['lyte_date_added']=time();
$yt_resp_precache=json_encode($yt_resp_array);
// then gzip + base64 (to limit amount of data + solve problems with wordpress removing slashes)
$yt_resp_precache=base64_encode(gzcompress($yt_resp_precache));
// and do the actual caching
$toCache = ( $yt_resp_precache ) ? $yt_resp_precache : '{{unknown}}';
update_post_meta( $postID, $cachekey, $toCache );
// and finally add new cache-entry to toCache_index which will be added to lyte_cache_index pref
$toCache_index[]=$cachekey;
}
}
}
}
// If there was a result from youtube or from cache, use it
if ( $yt_resp ) {
$yt_resp_array=json_decode($yt_resp,true);
if (is_array($yt_resp_array)) {
if ($plClass===" playlist") {
$yt_title="Playlist: ".esc_attr(sanitize_text_field(@$yt_resp_array['feed']['title']['$t']));
$thumbUrl=esc_url(@$yt_resp_array['feed']['media$group']['media$thumbnail'][2]['url']);
$dateField=sanitize_text_field(@$yt_resp_array['feed']['updated']['$t']);
$duration="";
$description=$yt_title;
} else {
// add in here if time constraint if false
$yt_title=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['title']['$t']));
$thumbUrl=esc_url($lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/".$thumb);
$dateField=sanitize_text_field(@$yt_resp_array['entry']['published']['$t']);
$duration="T".sanitize_text_field(@$yt_resp_array['entry']['media$group']['yt$duration']['seconds'])."S";
$description=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['media$group']['media$description']['$t']));
//if there was something in cache, write to metadata
if(($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" )) {
if($yt_resp_array["captions_data"]) {
$captionsMeta="<meta itemprop=\"accessibilityFeature\" content=\"captions\" />";
} else {
$captionsMeta="";
$cache_timestamp = $yt_resp_array["captions_timestamp"];
$interval = (strtotime("now") - $cache_timestamp)/60/60/24;
//for first time OR not first time, and false, and last check was more than 24 hours before, schedule captions lookup and set timestamp
if(!is_int($cache_timestamp) || ($interval > 1 && !is_null($yt_resp_array["captions_data"]))) {
$yt_resp_array['captions_timestamp'] = strtotime("now");
wp_schedule_single_event(strtotime("now") + 60*60, 'schedule_captions_lookup', array($postID, $cachekey, $vid));
$yt_resp_precache=json_encode($yt_resp_array);
$toCache=base64_encode(gzcompress($yt_resp_precache));
update_post_meta($postID, $cachekey, $toCache);
}
}
}
}
}
}
if ($audio===true) {
$wrapper="<div class=\"lyte-wrapper-audio\" style=\"width:".$lyteSettings[2]."px;max-width:100%;overflow:hidden;height:38px;".$lyteSettings['pos']."\">";
} else {
$wrapper="<div class=\"lyte-wrapper".$lyteSettings['ratioClass']."\" style=\"width:".$lyteSettings[2]."px;max-width: 100%;".$lyteSettings['pos']."\">";
}
if ($doExcerpt) {
$lytetemplate="";
$templateType="excerpt";
} elseif ($lyte_feed) {
$postURL = get_permalink( $postID );
$textLink = ($lyteSettings['links']===0)? "" : "<br />".strip_tags($lytelinks_txt, '<a>')."<br />";
$lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>".$textLink;
$templateType="feed";
} elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
$lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\" itemprop=\"video\" itemscope itemtype=\"http://schema.org/VideoObject\"><meta itemprop=\"thumbnailUrl\" content=\"".$thumbUrl."\" /><meta itemprop=\"embedURL\" content=\"http://www.youtube.com/embed/".$vid."\" /><meta itemprop=\"uploadDate\" content=\"".$dateField."\" />".$captionsMeta."<div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\" itemprop=\"name\">".$yt_title."</div></div><div class=\"play\"></div><div class=\"ctrl\"><div class=\"Lctrl\"></div><div class=\"Rctrl\"></div></div></div>".$noscript."<meta itemprop=\"description\" content=\"".$description."\"></div></div>".$lytelinks_txt;
$templateType="postMicrodata";
} else {
$lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\">".$yt_title."</div></div><div class=\"play\"></div><div class=\"ctrl\"><div class=\"Lctrl\"></div><div class=\"Rctrl\"></div></div></div>".$noscript."</div></div>".$lytelinks_txt;
$templateType="post";
}
/** API: filter hook to parse template before being applied */
$lytetemplate = apply_filters( 'lyte_match_postparse_template',$lytetemplate,$templateType );
$the_content = preg_replace($lytes_regexp, $lytetemplate, $the_content, 1);
}
// update lyte_cache_index
if ((is_array($toCache_index))&&(!empty($toCache_index))) {
$lyte_cache=json_decode(get_option('lyte_cache_index'),true);
$lyte_cache[$postID]=$toCache_index;
update_option('lyte_cache_index',json_encode($lyte_cache));
}
if (!$lyte_feed) {
lyte_initer();
}
}
/** API: filter hook to postparse the_content before returning */
$the_content = apply_filters( 'lyte_content_postparse',$the_content );
return $the_content;
}
add_action('schedule_captions_lookup', 'captions_lookup', 1, 3);
// captions lookup API call for YouTube
function captions_lookup($postID, $cachekey, $vid) {
// call YouTube captions API
$response = wp_remote_request("http://api.a11ymetadata.org/captions/youtubeid=".$vid."/youtube");
if(!is_wp_error($response)) {
$rawJson = wp_remote_retrieve_body($response);
$decodeJson = json_decode($rawJson, true);
$yt_resp = get_post_meta($postID, $cachekey, true);
if (!empty($yt_resp)) {
$yt_resp = gzuncompress(base64_decode($yt_resp));
if($yt_resp) {
$yt_resp_array=json_decode($yt_resp,true);
// if captions = true, update cache
if ($decodeJson['status'] == 'success' && $decodeJson['data']['captions'] == '1') {
$yt_resp_array['captions_data'] = true;
} else {
$yt_resp_array['captions_data'] = false;
}
// update timestamps for both
$yt_resp_array['captions_timestamp'] = strtotime("now");
$yt_resp_precache=json_encode($yt_resp_array);
$toCache=base64_encode(gzcompress($yt_resp_precache));
update_post_meta($postID, $cachekey, $toCache);
}
}
}
}
/* only add js/css once and only if needed */
function lyte_initer() {
global $lynited;
if (!$lynited) {
$lynited=true;
add_action('wp_footer', 'lyte_init');
}
}
/* actual initialization */
function lyte_init() {
global $lyteSettings;
$lyte_css = ".lyte-wrapper-audio div, .lyte-wrapper div {margin:0px !important; overflow:hidden;} .lyte,.lyMe{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;background-color:#777;} .fourthree .lyMe, .fourthree .lyte {padding-bottom:75%;} .lidget{margin-bottom:5px;} .lidget .lyte, .widget .lyMe {padding-bottom:0!important;height:100%!important;} .lyte-wrapper-audio .lyte{height:38px!important;overflow:hidden;padding:0!important} .lyte iframe,.lyte .pL{position:absolute;top:0;left:0;width:100%;height:100%;background:no-repeat scroll center #000;background-size:cover;cursor:pointer} .tC{background-color:rgba(0,0,0,0.5);left:0;position:absolute;top:0;width:100%} .tT{color:#FFF;font-family:sans-serif;font-size:12px;height:auto;text-align:left;padding:5px 10px} .tT:hover{text-decoration:underline} .play{background:no-repeat scroll 0 0 transparent;width:90px;height:62px;position:absolute;left:43%;left:calc(50% - 45px);left:-webkit-calc(50% - 45px);top:38%;top:calc(50% - 31px);top:-webkit-calc(50% - 31px);opacity:0.9;} .widget .play {top:30%;top:calc(45% - 31px);top:-webkit-calc(45% - 31px);transform:scale(0.6);-webkit-transform:scale(0.6);-ms-transform:scale(0.6);} .lyte:hover .play{background-position:0 -65px; opacity:1;} .lyte-audio .pL{max-height:38px!important} .lyte-audio iframe{height:438px!important} .ctrl{background:repeat scroll 0 -215px transparent;width:100%;height:40px;bottom:0;left:0;position:absolute} .Lctrl{background:no-repeat scroll 0 -132px transparent;width:158px;height:40px;bottom:0;left:0;position:absolute} .Rctrl{background:no-repeat scroll -42px -174px transparent;width:117px;height:40px;bottom:0;right:0;position:absolute} .lyte-audio .play,.lyte-audio .tC{display:none} .hidden{display:none}";
/** API: filter hook to change css */
$lyte_css = apply_filters( 'lyte_css', $lyte_css);
if (!empty($lyte_css)) {
echo "<script type=\"text/javascript\">var bU='".$lyteSettings['path']."';style = document.createElement('style');style.type = 'text/css';rules = document.createTextNode(\"".$lyte_css."\" );if(style.styleSheet) { style.styleSheet.cssText = rules.nodeValue;} else {style.appendChild(rules);}document.getElementsByTagName('head')[0].appendChild(style);</script>";
}
echo "<script type=\"text/javascript\" async src=\"".$lyteSettings['path'].$lyteSettings['file']."\"></script>";
}
/** override default wp_trim_excerpt to have lyte_parse remove the httpv-links */
function lyte_trim_excerpt($text) {
global $post;
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = lyte_parse($text, true);
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
if (function_exists('wp_trim_words')) {
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
} else {
$length = $excerpt_length*6;
$text = substr( strip_tags(trim(preg_replace('/\s+/', ' ', $text))), 0, $length );
$text .= $excerpt_more;
}
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
/** Lyte shortcode */
function shortcode_lyte($atts) {
extract(shortcode_atts(array(
"id" => '',
"audio" => '',
"playlist" => '',
), $atts));
if ($audio) {$proto="httpa";} else {$proto="httpv";}
if ($playlist) {$action="playlist?list=";} else {$action="watch?v=";}
return lyte_parse($proto.'://www.youtube.com/'.$action.$id);
}
/** update functions */
/** upgrade function for 1.1.x to 1.2.x */
function lyte_options_update() {
if (get_option('size')!==false) {
foreach (array('size','show_links','position','hidef','notification') as $oldOptionName) {
$oldOptionValue=get_option($oldOptionName);
$newOptionName="lyte_".$oldOptionName;
update_option($newOptionName,$oldOptionValue);
delete_option($oldOptionName);
}
}
}
/** function to flush YT responses from cache */
function lyte_rm_cache() {
try {
$lyte_posts=json_decode(get_option('lyte_cache_index'),true);
if (is_array($lyte_posts)){
foreach ($lyte_posts as $postID => $lyte_post) {
foreach ($lyte_post as $cachekey) {
delete_post_meta($postID, $cachekey);
}
}
delete_option('lyte_cache_index');
}
return "OK";
} catch(Exception $e) {
return $e->getMessage();
}
}
/** function to call from within themes */
/* use with e.g. : <?php if(function_exists('lyte_preparse')) { echo lyte_preparse($videoId); } ?> */
function lyte_preparse($videoId) {
return lyte_parse('httpv://www.youtube.com/watch?v='.$videoId);
}
/** hooking it all up to wordpress */
if ( is_admin() ) {
require_once(dirname(__FILE__).'/options.php');
} else {
add_filter('the_content', 'lyte_parse', 4);
add_shortcode("lyte", "shortcode_lyte");
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'lyte_trim_excerpt');
/** API: action hook to allow extra actions or filters to be added */
do_action("lyte_actionsfilters");
}
?>