Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
新增 播放器响应式支持(播放器根据不同设备的屏幕大小设置不同的屏幕高度和宽度)
新增 播放器下方友好提示(不支持H5播放的视频可通过这里引导回源站播放)
优化 播放器引用方式(先 iframe 后 embed)
优化 核心代码(更简洁更高效)
  • Loading branch information
nothingisover committed Jul 30, 2015
1 parent 0338d7c commit 02777a7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 164 deletions.
250 changes: 87 additions & 163 deletions smartideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
Description: Smartideo 是为 WordPress 添加对在线视频支持的一款插件(支持手机、平板等设备HTML5播放)。 目前支持优酷、搜狐视频、土豆、56、腾讯视频、新浪视频、酷6、华数、乐视 等网站。
Version: 1.3.7
Version: 2.0.0
Author: Fens Liu
Author URI: http://www.fengziliu.com/smartideo-for-wordpress.html
Author URI: http://www.fengziliu.com/smartideo-2.html
*/



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

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

Expand All @@ -31,9 +31,7 @@
class smartideo{
private $edit = false;
private $width = '100%';
private $height = '500';
private $mobile_width = '100%';
private $mobile_height = '250';
private $height = '500px';
private $strategy = 0;
public function __construct(){
if(is_admin()){
Expand All @@ -48,18 +46,6 @@ public function __construct(){
$option = array();
}
extract($option);
if(!empty($width)){
$this->width = $width;
}
if(!empty($height)){
$this->height = $height;
}
if(!empty($mobile_width)){
$this->mobile_width = $mobile_width;
}
if(!empty($mobile_height)){
$this->mobile_height = $mobile_height;
}
if(!empty($strategy)){
$this->strategy = $strategy;
}
Expand Down Expand Up @@ -131,165 +117,147 @@ public function __construct(){

}

# video
public function smartideo_embed_handler_tudou( $matches, $attr, $url, $rawattr ) {
if(wp_is_mobile()){
$embed = $this->get_iframe("http://www.tudou.com/programs/view/html5embed.action?type=0&code={$matches['video_id']}");
}else{
$embed = $this->get_embed("http://www.tudou.com/v/{$matches['video_id']}/&resourceId=0_05_05_99&bid=05/v.swf");
}
return apply_filters( 'embed_tudou', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_iframe("http://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'];
if(wp_is_mobile()){
$embed = $this->get_iframe("http://www.56.com/iframe/{$matches['video_id']}");
}else{
$embed = $this->get_embed("http://player.56.com/v_{$matches['video_id']}.swf");
}
return apply_filters( 'embed_56', $embed, $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);
return apply_filters( 'embed_56', $embed, $matches, $attr, $url, $rawattr );
}

public function smartideo_embed_handler_youku( $matches, $attr, $url, $rawattr ) {
if(wp_is_mobile()){
$embed = $this->get_iframe("http://player.youku.com/embed/{$matches['video_id']}");
}else{
$embed = $this->get_embed("http://player.youku.com/player.php/sid/{$matches['video_id']}/v.swf");
}
return apply_filters( 'embed_youku', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_iframe("http://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'];
if(wp_is_mobile()){
$embed = $this->get_iframe("http://v.qq.com/iframe/player.html?vid={$matches['video_id']}");
}else{
$embed = $this->get_embed("http://static.video.qq.com/TPout.swf?vid={$matches['video_id']}");
}
return apply_filters( 'embed_qq', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_iframe("http://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 ) {
if(wp_is_mobile()){
$embed = $this->get_iframe("http://tv.sohu.com/upload/static/share/share_play.html#{$matches['video_id']}_0_0_9001_0");
}else{
$embed = $this->get_embed("http://share.vrs.sohu.com/my/v.swf&topBar=1&id={$matches['video_id']}&autoplay=false&xuid=&from=page");
}
return apply_filters( 'embed_sohu', $embed, $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);
return apply_filters( 'embed_sohu', $embed, $matches, $attr, $url, $rawattr );
}

public function smartideo_embed_handler_wasu( $matches, $attr, $url, $rawattr ) {
if(wp_is_mobile()){
$embed = $this->get_iframe("http://www.wasu.cn/Play/iframe/id/{$matches['video_id']}");
}else{
$embed = $this->get_embed("http://s.wasu.cn/portal/player/20141216/WsPlayer.swf?mode=3&vid={$matches['video_id']}&auto=0&ad=4228");
}
return apply_filters( 'embed_wasu', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_iframe("http://www.wasu.cn/Play/iframe/id/{$matches['video_id']}", $url);
return apply_filters( 'embed_wasu', $embed, $matches, $attr, $url, $rawattr );
}

# video widthout h5
public function smartideo_embed_handler_yinyuetai( $matches, $attr, $url, $rawattr ){
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$embed = $this->get_embed("http://player.yinyuetai.com/video/player/{$matches['video_id']}/v_0.swf");
}
return apply_filters( 'embed_yinyuetai', $embed, $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 ){
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$embed = $this->get_embed("http://player.ku6.com/refer/{$matches['video_id']}/v.swf");
}
return apply_filters( 'embed_ku6', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_embed("http://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){
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$embed = $this->get_embed("http://i7.imgs.letv.com/player/swfPlayer.swf?id={$matches['video_id']}&autoplay=0");
}
return apply_filters( 'embed_letv', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_embed("http://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 ) {
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$embed = $this->get_embed("http://i1.hunantv.com/ui/swf/share/player.swf?video_id={$matches['video_id']}");
}
return apply_filters( 'embed_hunantv', $embed, $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);
return apply_filters( 'embed_hunantv', $embed, $matches, $attr, $url, $rawattr );
}

public function smartideo_embed_handler_acfun( $matches, $attr, $url, $rawattr ) {
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$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']}");
}
return apply_filters( 'embed_acfun', $embed, $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 ) {
if(wp_is_mobile() && !$this->edit){
$embed = $this->get_link($url);
}else{
$embed = $this->get_embed("http://static.hdslb.com/miniloader.swf?aid={$matches['video_id']}&page=1");
}
return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
$embed = $this->get_embed("http://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%', '110');
return apply_filters( 'embed_music163', $embed, $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');
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>
</div>';
return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr );
return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr );
}

private function get_embed($url){
$html = '';
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(
if($this->edit){
$width = $this->width;
$height = $this->height;
}
if(!empty($width)){
$style .= "width: {$width};";
}
if(!empty($height)){
$style .= "height: {$height};";
}
if(!empty($style)){
$style = ' style="' . $style . '"';
}
$html .=
'<div id="smartideo">
<embed src="%1$s" allowFullScreen="true" quality="high" width="%2$s" height="%3$s" allowScriptAccess="always" type="application/x-shockwave-flash" wmode="transparent"></embed>
</div>',
$url, $this->width, $this->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){
$html .=
'<div class="tips">
<a href="' . $source . '" target="_blank" title="如果视频无法播放,点击这里试试" rel="nofollow">如果视频无法播放,点击这里试试</a>
</div>';
}
$html .= '</div>';
return $html;
}

private function get_iframe($url = '', $width = '', $height = ''){
$html = '';
private function get_iframe($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);
}
$width = empty($width) ? $this->mobile_width : $width;
$height = empty($height) ? $this->mobile_height : $height;
$html .= sprintf(
if($this->edit){
$width = $this->width;
$height = $this->height;
}
if(!empty($width)){
$style .= "width: {$width};";
}
if(!empty($height)){
$style .= "height: {$height};";
}
if(!empty($style)){
$style = ' style="' . $style . '"';
}
$html .=
'<div id="smartideo">
<iframe src="%1$s" width="%2$s" height="%3$s" frameborder="0" allowfullscreen="true"></iframe>
</div>',
$url, $width, $height);
return $html;
<div class="player"' . $style . '>
<iframe src="' . $url . '" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>
</div>';
if(!empty($source) && !$this->edit){
$html .=
'<div class="tips">
<a href="' . $source . '" target="_blank" title="如果视频无法播放,点击这里试试" rel="nofollow">如果视频无法播放,点击这里试试</a>
</div>';
}

private function get_link($url){
$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('<div id="smartideo" style="width: %2$spx; height: %3$spx; line-height: %3$spx;">
<a href="%1$s" target="_blank" title="该视频不支持您的浏览器,请点击这里播放~" class="link">播放</a>
</div>', $url, $this->mobile_width, $this->mobile_height);
$html .= '</div>';
return $html;
}

Expand Down Expand Up @@ -317,54 +285,10 @@ public function admin_settings(){
if(!empty($option)){
$option = json_decode($option, true);
}
if(empty($option['width'])){
$option['width'] = '100%';
}
if(empty($option['height'])){
$option['height'] = '500';
}
if(empty($option['mobile_width'])){
$option['mobile_width'] = '100%';
}
if(empty($option['mobile_height'])){
$option['mobile_height'] = '250';
}

echo '<h2>Smartideo 设置</h2>';
echo '<form action="" method="post">
<table class="form-table">
<tr valign="top">
<th scope="row">播放器宽度</th>
<td>
<label><input type="text" class="regular-text code" name="width" value="'.$option['width'].'"></label>
<br />
<p class="description">默认宽度为100%</p>
</td>
</tr>
<tr valign="top">
<th scope="row">播放器高度</th>
<td>
<label><input type="text" class="regular-text code" name="height" value="'.$option['height'].'"></label>
<br />
<p class="description">默认高度为500px</p>
</td>
</tr>
<tr valign="top">
<th scope="row">移动设备播放器宽度</th>
<td>
<label><input type="text" class="regular-text code" name="mobile_width" value="'.$option['mobile_width'].'"></label>
<br />
<p class="description">手机、平板等设备访问时,默认宽度为100%</p>
</td>
</tr>
<tr valign="top">
<th scope="row">移动设备播放器高度</th>
<td>
<label><input type="text" class="regular-text code" name="mobile_height" value="'.$option['mobile_height'].'"></label>
<br />
<p class="description">手机、平板等设备访问时,默认高度为250px</p>
</td>
</tr>
<tr valign="top">
<th scope="row">资源加载策略</th>
<td>
Expand All @@ -379,7 +303,7 @@ public function admin_settings(){
<br />
<p class="description">默认全局加载</p>
</td>
</tr>
</tr>
</table>
<p class="submit"><input type="submit" name="smartideo_submit" id="submit" class="button-primary" value="保存"></p>
</form>';
Expand Down
Binary file removed static/play.png
Binary file not shown.
17 changes: 16 additions & 1 deletion static/smartideo.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#smartideo { z-index: 0; text-align: center; background: #CCC; line-height: 0; text-indent: 0; }
#smartideo embed, #smartideo iframe { padding: 0; margin: 0; }
#smartideo .link { background: url(play.png) no-repeat center center; background-size: 15%; display: block; text-indent: -100000px; }
#smartideo .player { width: 100%; height: 500px; }
#smartideo .tips { background: #f2f2f2; text-align: center; height: 32px; line-height: 32px; font-size: 12px; }
#smartideo .tips a { text-decoration: none; }

@media screen and (max-width:959px){
#smartideo .player { height: 450px; }
}
@media screen and (max-width:767px){
#smartideo .player { height: 400px; }
}
@media screen and (max-width:639px){
#smartideo .player { height: 350px; }
}
@media screen and (max-width:479px){
#smartideo .player { height: 250px; }
}

0 comments on commit 02777a7

Please sign in to comment.