From 05917781512308f178591f87c53b1e0ed25f334e Mon Sep 17 00:00:00 2001 From: "fensliu@gmail.com" Date: Mon, 11 Jan 2016 14:52:34 +0800 Subject: [PATCH] 2.0.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 支持乐视体育 新增 AcFun支持H5播放 新增 支持部分网站https 新增 支持YouTube 新增 Tips配置 优化 AcFun引用 优化 Tips加载方式 优化 Tips加载逻辑 优化 对bilibili https的支持 修复 Tips不能加载的BUG 修复 Tips可能与其他插件产生冲突的BUG --- smartideo.php | 122 +++++++++++++++++++++++++++++++++----------- static/smartideo.js | 6 +++ 2 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 static/smartideo.js diff --git a/smartideo.php b/smartideo.php index 4cf1ba1..7bbbc39 100644 --- a/smartideo.php +++ b/smartideo.php @@ -6,9 +6,9 @@ Plugin URI: http://www.fengziliu.com/ -Description: Smartideo 是为 WordPress 添加对在线视频支持的一款插件(支持手机、平板等设备HTML5播放)。 目前支持优酷、搜狐视频、土豆、56、腾讯视频、新浪视频、酷6、华数、乐视 等网站。 +Description: Smartideo 是为 WordPress 添加对在线视频支持的一款插件(支持手机、平板等设备HTML5播放)。 目前支持优酷、搜狐视频、土豆、56、腾讯视频、新浪视频、酷6、华数、乐视、YouTube 等网站。 -Version: 2.0.0 +Version: 2.0.4 Author: Fens Liu @@ -18,7 +18,7 @@ -define('SMARTIDEO_VERSION', '2.0.0'); +define('SMARTIDEO_VERSION', '2.0.4'); define('SMARTIDEO_URL', plugins_url('', __FILE__)); @@ -33,6 +33,7 @@ class smartideo{ private $width = '100%'; private $height = '500px'; private $strategy = 0; + private $option = array(); public function __construct(){ if(is_admin()){ add_action('admin_menu', array($this, 'admin_menu')); @@ -45,6 +46,7 @@ public function __construct(){ }else{ $option = array(); } + $this->option = $option; extract($option); if(!empty($strategy)){ $this->strategy = $strategy; @@ -56,6 +58,7 @@ public function __construct(){ wp_embed_unregister_handler('youku'); wp_embed_unregister_handler('tudou'); wp_embed_unregister_handler('56com'); + wp_embed_unregister_handler('youtube'); // video wp_embed_register_handler( 'smartideo_tudou', @@ -91,7 +94,7 @@ public function __construct(){ array($this, 'smartideo_embed_handler_ku6') ); wp_embed_register_handler( 'smartideo_letv', - '#https?://www\.letv\.com/ptv/vplay/(?\d+)#i', + '#https?://(?:[a-z0-9/]+\.)?letv\.com/(?:[a-z0-9/]+)/(?\d+)#i', array($this, 'smartideo_embed_handler_letv') ); wp_embed_register_handler( 'smartideo_hunantv', @@ -106,6 +109,10 @@ public function __construct(){ '#https?://www\.bilibili\.com/video/av(?\d+)#i', array($this, 'smartideo_embed_handler_bilibili') ); + wp_embed_register_handler( 'smartideo_youtube', + '#https?://www\.youtube\.com/watch\?v=(?\w+)#i', + array($this, 'smartideo_embed_handler_youtube') ); + // music wp_embed_register_handler( 'smartideo_music163', '#https?://music\.163\.com/\#/song\?id=(?\d+)#i', @@ -119,37 +126,47 @@ public function __construct(){ # video public function smartideo_embed_handler_tudou( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_iframe("http://www.tudou.com/programs/view/html5embed.action?type=0&code={$matches['video_id']}", $url); + $embed = $this->get_iframe("//www.tudou.com/programs/view/html5embed.action?type=0&code={$matches['video_id']}", $url); return apply_filters( 'embed_tudou', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_56( $matches, $attr, $url, $rawattr ) { $matches['video_id'] = $matches['video_id1'] == '' ? $matches['video_id2'] : $matches['video_id1']; - $embed = $this->get_iframe("http://www.56.com/iframe/{$matches['video_id']}", $url); + $embed = $this->get_iframe("//www.56.com/iframe/{$matches['video_id']}", $url); return apply_filters( 'embed_56', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_youku( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_iframe("http://player.youku.com/embed/{$matches['video_id']}", $url); + $embed = $this->get_iframe("//player.youku.com/embed/{$matches['video_id']}", $url); return apply_filters( 'embed_youku', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_qq( $matches, $attr, $url, $rawattr ) { $matches['video_id'] = $matches['video_id1'] == '' ? $matches['video_id2'] : $matches['video_id1']; - $embed = $this->get_iframe("http://v.qq.com/iframe/player.html?vid={$matches['video_id']}&tiny=0&auto=0", $url); + $embed = $this->get_iframe("//v.qq.com/iframe/player.html?vid={$matches['video_id']}&tiny=0&auto=0", $url); return apply_filters( 'embed_qq', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_sohu( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_iframe("http://tv.sohu.com/upload/static/share/share_play.html#{$matches['video_id']}_0_0_9001_0", $url); + $embed = $this->get_iframe("//tv.sohu.com/upload/static/share/share_play.html#{$matches['video_id']}_0_0_9001_0", $url); return apply_filters( 'embed_sohu', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_wasu( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_iframe("http://www.wasu.cn/Play/iframe/id/{$matches['video_id']}", $url); + $embed = $this->get_iframe("//www.wasu.cn/Play/iframe/id/{$matches['video_id']}", $url); return apply_filters( 'embed_wasu', $embed, $matches, $attr, $url, $rawattr ); } + public function smartideo_embed_handler_acfun( $matches, $attr, $url, $rawattr ) { + $embed = $this->get_iframe("//ssl.acfun.tv/block-player-homura.html#vid={$matches['video_id']};from=http://www.acfun.tv", $url); + return apply_filters( 'embed_acfun', $embed, $matches, $attr, $url, $rawattr ); + } + + public function smartideo_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { + $embed = $this->get_iframe("//www.youtube.com/embed/{$matches['video_id']}", $url); + return apply_filters( 'embed_youtube', $embed, $matches, $attr, $url, $rawattr ); + } + # video widthout h5 public function smartideo_embed_handler_yinyuetai( $matches, $attr, $url, $rawattr ){ $embed = $this->get_embed("http://player.yinyuetai.com/video/player/{$matches['video_id']}/v_0.swf", $url); @@ -157,40 +174,39 @@ public function smartideo_embed_handler_yinyuetai( $matches, $attr, $url, $rawat } public function smartideo_embed_handler_ku6( $matches, $attr, $url, $rawattr ){ - $embed = $this->get_embed("http://player.ku6.com/refer/{$matches['video_id']}/v.swf", $url); + $embed = $this->get_embed("//player.ku6.com/refer/{$matches['video_id']}/v.swf", $url); return apply_filters( 'embed_ku6', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_letv($matches, $attr, $url, $rawattr){ - $embed = $this->get_embed("http://i7.imgs.letv.com/player/swfPlayer.swf?id={$matches['video_id']}&autoplay=0", $url); + $embed = $this->get_embed("//i7.imgs.letv.com/player/swfPlayer.swf?id={$matches['video_id']}&autoplay=0", $url); return apply_filters( 'embed_letv', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_hunantv( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_embed("http://i1.hunantv.com/ui/swf/share/player.swf?video_id={$matches['video_id']}&autoplay=0", $url); + $embed = $this->get_embed("//i1.hunantv.com/ui/swf/share/player.swf?video_id={$matches['video_id']}&autoplay=0", $url); return apply_filters( 'embed_hunantv', $embed, $matches, $attr, $url, $rawattr ); } - public function smartideo_embed_handler_acfun( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_embed("http://static.acfun.mm111.net/player/ACFlashPlayer.out.swf?type=page&url=http://www.acfun.tv/v/ac{$matches['video_id']}", $url); - return apply_filters( 'embed_acfun', $embed, $matches, $attr, $url, $rawattr ); - } - public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_embed("http://static.hdslb.com/miniloader.swf?aid={$matches['video_id']}&page=1", $url); + if($this->is_https()){ + $embed = $this->get_embed("//static-s.bilibili.com/miniloader.swf?aid={$matches['video_id']}&page=1", $url); + }else{ + $embed = $this->get_embed("//static.hdslb.com/miniloader.swf?aid={$matches['video_id']}&page=1", $url); + } return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr ); } # music public function smartideo_embed_handler_music163( $matches, $attr, $url, $rawattr ) { - $embed = $this->get_iframe("http://music.163.com/outchain/player?type=2&id={$matches['video_id']}&auto=0&height=90", '', '100%', '110px'); + $embed = $this->get_iframe("//music.163.com/outchain/player?type=2&id={$matches['video_id']}&auto=0&height=90", '', '100%', '110px'); return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr ); } public function smartideo_embed_handler_xiami( $matches, $attr, $url, $rawattr ) { $embed = '
- +
'; return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr ); } @@ -198,7 +214,8 @@ public function smartideo_embed_handler_xiami( $matches, $attr, $url, $rawattr ) private function get_embed($url = '', $source = '', $width = '', $height = ''){ $style = $html = ''; if($this->strategy == 1){ - $html .= sprintf('', SMARTIDEO_URL . '/static/smartideo.css?ver=' . SMARTIDEO_VERSION); + $html .= sprintf('', SMARTIDEO_URL . '/static/smartideo.css?ver=' . SMARTIDEO_VERSION); + $html .= sprintf('', SMARTIDEO_URL . '/static/smartideo.js?ver=' . SMARTIDEO_VERSION); } if($this->edit){ $width = $this->width; @@ -218,10 +235,16 @@ private function get_embed($url = '', $source = '', $width = '', $height = ''){
'; - if(!empty($source) && !$this->edit){ + if($this->option['tips_status'] == 1 && !$this->edit){ + if(!empty($source)){ + $source = 'javascript:void(0);'; + } + if(empty($this->option['tips_content'])){ + $this->option['tips_content'] = '建议在WIFI环境下播放,土豪请随意~'; + } $html .= ''; } $html .= ''; @@ -251,18 +274,25 @@ private function get_iframe($url = '', $source = '', $width = '', $height = ''){
'; - if(!empty($source) && !$this->edit){ + if($this->option['tips_status'] == 1 && !$this->edit){ + if(!empty($source)){ + $source = 'javascript:void(0);'; + } + if(empty($this->option['tips_content'])){ + $this->option['tips_content'] = '建议在WIFI环境下播放,土豪请随意~'; + } $html .= ''; - } + } $html .= ''; return $html; } public function smartideo_scripts(){ - wp_enqueue_style('smartideo', SMARTIDEO_URL . '/static/smartideo.css', array(), SMARTIDEO_VERSION, 'screen'); + wp_enqueue_style('smartideo_css', SMARTIDEO_URL . '/static/smartideo.css', array(), SMARTIDEO_VERSION, 'screen'); + wp_enqueue_script('smartideo_js', SMARTIDEO_URL . '/static/smartideo.js', array(), SMARTIDEO_VERSION, true); } public function admin_menu(){ @@ -271,7 +301,7 @@ public function admin_menu(){ public function admin_settings(){ if($_POST['smartideo_submit'] == '保存'){ - $param = array('width', 'height', 'mobile_width', 'mobile_height', 'strategy'); + $param = array('width', 'height', 'strategy', 'tips_status', 'tips_content'); $json = array(); foreach($_POST as $key => $val){ if(in_array($key, $param)){ @@ -285,6 +315,9 @@ public function admin_settings(){ if(!empty($option)){ $option = json_decode($option, true); } + if(empty($option['tips_content'])){ + $option['tips_content'] = '建议在WIFI环境下播放,土豪请随意~'; + } echo '

Smartideo 设置

'; echo '
@@ -304,8 +337,39 @@ public function admin_settings(){

默认全局加载

+ + 贴士 + + + +
+

默认关闭

+ + + + 贴士内容 + + +
+

+ +

'; } + + private function is_https(){ + if($_SERVER['HTTPS'] == 'on'){ + return true; + }else{ + return false; + } + } } diff --git a/static/smartideo.js b/static/smartideo.js new file mode 100644 index 0000000..4c83fd1 --- /dev/null +++ b/static/smartideo.js @@ -0,0 +1,6 @@ +window.onload = function(){ + if(document.getElementById('smartideo_tips')){ + var tips = document.getElementById("smartideo_tips"); + tips.innerHTML = tips.getAttribute("smartideo-title"); + } +} \ No newline at end of file