Skip to content

Commit

Permalink
2.0.4
Browse files Browse the repository at this point in the history
新增 支持乐视体育
新增 AcFun支持H5播放
新增 支持部分网站https
新增 支持YouTube
新增 Tips配置

优化 AcFun引用
优化 Tips加载方式
优化 Tips加载逻辑
优化 对bilibili https的支持

修复 Tips不能加载的BUG
修复 Tips可能与其他插件产生冲突的BUG
  • Loading branch information
nothingisover committed Jan 11, 2016
1 parent 02777a7 commit 0591778
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 29 deletions.
122 changes: 93 additions & 29 deletions smartideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,7 @@



define('SMARTIDEO_VERSION', '2.0.0');
define('SMARTIDEO_VERSION', '2.0.4');

define('SMARTIDEO_URL', plugins_url('', __FILE__));

Expand All @@ -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'));
Expand All @@ -45,6 +46,7 @@ public function __construct(){
}else{
$option = array();
}
$this->option = $option;
extract($option);
if(!empty($strategy)){
$this->strategy = $strategy;
Expand All @@ -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',
Expand Down Expand Up @@ -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/(?<video_id>\d+)#i',
'#https?://(?:[a-z0-9/]+\.)?letv\.com/(?:[a-z0-9/]+)/(?<video_id>\d+)#i',
array($this, 'smartideo_embed_handler_letv') );

wp_embed_register_handler( 'smartideo_hunantv',
Expand All @@ -106,6 +109,10 @@ public function __construct(){
'#https?://www\.bilibili\.com/video/av(?<video_id>\d+)#i',
array($this, 'smartideo_embed_handler_bilibili') );

wp_embed_register_handler( 'smartideo_youtube',
'#https?://www\.youtube\.com/watch\?v=(?<video_id>\w+)#i',
array($this, 'smartideo_embed_handler_youtube') );

// music
wp_embed_register_handler( 'smartideo_music163',
'#https?://music\.163\.com/\#/song\?id=(?<video_id>\d+)#i',
Expand All @@ -119,86 +126,96 @@ 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);
return apply_filters( 'embed_yinyuetai', $embed, $matches, $attr, $url, $rawattr );
}

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 =
'<div id="smartideo" style="background: transparent;">
<script src="http://www.xiami.com/widget/player-single?uid=0&sid='.$matches['video_id'].'&autoplay=0&mode=js" type="text/javascript"></script>
<script src="//www.xiami.com/widget/player-single?uid=0&sid='.$matches['video_id'].'&autoplay=0&mode=js" type="text/javascript"></script>
</div>';
return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr );
}

private function get_embed($url = '', $source = '', $width = '', $height = ''){
$style = $html = '';
if($this->strategy == 1){
$html .= sprintf('<link rel="stylesheet" id="smartideo-cssdd" href="%1$s" type="text/css" media="screen">', SMARTIDEO_URL . '/static/smartideo.css?ver=' . SMARTIDEO_VERSION);
$html .= sprintf('<link rel="stylesheet" href="%1$s" type="text/css" media="screen">', SMARTIDEO_URL . '/static/smartideo.css?ver=' . SMARTIDEO_VERSION);
$html .= sprintf('<script type="text/javascript" src="%1$s"></script>', SMARTIDEO_URL . '/static/smartideo.js?ver=' . SMARTIDEO_VERSION);
}
if($this->edit){
$width = $this->width;
Expand All @@ -218,10 +235,16 @@ private function get_embed($url = '', $source = '', $width = '', $height = ''){
<div class="player"' . $style . '>
<embed src="' . $url . '" allowFullScreen="true" quality="high" width="100%" height="100%" allowScriptAccess="always" type="application/x-shockwave-flash" wmode="transparent"></embed>
</div>';
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 .=
'<div class="tips">
<a href="' . $source . '" target="_blank" title="如果视频无法播放,点击这里试试" rel="nofollow">如果视频无法播放,点击这里试试</a>
<a href="' . $source . '" target="_blank" smartideo-title="' . $this->option['tips_content'] . '" title="' . $this->option['tips_content'] . '" id="smartideo_tips" rel="nofollow">' . $this->option['tips_content'] . '</a>
</div>';
}
$html .= '</div>';
Expand Down Expand Up @@ -251,18 +274,25 @@ private function get_iframe($url = '', $source = '', $width = '', $height = ''){
<div class="player"' . $style . '>
<iframe src="' . $url . '" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>
</div>';
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 .=
'<div class="tips">
<a href="' . $source . '" target="_blank" title="如果视频无法播放,点击这里试试" rel="nofollow">如果视频无法播放,点击这里试试</a>
<a href="' . $source . '" target="_blank" smartideo-title="' . $this->option['tips_content'] . '" title="' . $this->option['tips_content'] . '" id="smartideo_tips" rel="nofollow">' . $this->option['tips_content'] . '</a>
</div>';
}
}
$html .= '</div>';
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(){
Expand All @@ -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)){
Expand All @@ -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 '<h2>Smartideo 设置</h2>';
echo '<form action="" method="post">
Expand All @@ -304,8 +337,39 @@ public function admin_settings(){
<p class="description">默认全局加载</p>
</td>
</tr>
<tr valign="top">
<th scope="row">贴士</th>
<td>
<label title="开启">
<input type="radio" name="tips_status" value="1" ' . ($option['tips_status'] == 1 ? 'checked="checked"' : '') . '/>
<span>开启</span>
</label>
<label title="关闭">
<input type="radio" name="tips_status" value="0" ' . ($option['tips_status'] != 1 ? 'checked="checked"' : '') . '/>
<span>关闭</span>
</label>
<br />
<p class="description">默认关闭</p>
</td>
</tr>
<tr valign="top">
<th scope="row">贴士内容</th>
<td>
<label><input type="text" class="regular-text code" name="tips_content" value="'.$option['tips_content'].'"></label>
<br />
<p class="description"></p>
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="smartideo_submit" id="submit" class="button-primary" value="保存"></p>
</form>';
}

private function is_https(){
if($_SERVER['HTTPS'] == 'on'){
return true;
}else{
return false;
}
}
}
6 changes: 6 additions & 0 deletions static/smartideo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
window.onload = function(){
if(document.getElementById('smartideo_tips')){
var tips = document.getElementById("smartideo_tips");
tips.innerHTML = tips.getAttribute("smartideo-title");
}
}

0 comments on commit 0591778

Please sign in to comment.