Skip to content

Commit

Permalink
V1.6
Browse files Browse the repository at this point in the history
新增 弹幕id参数
新增 全局默认设置
优化 插件配置 界面
更新 DPlayer 至 1.0.8 版本
  • Loading branch information
fghrsh committed Sep 2, 2016
1 parent cc80818 commit aea9b8a
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 186 deletions.
6 changes: 3 additions & 3 deletions DPlayer.min.js

Large diffs are not rendered by default.

75 changes: 41 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
# [DPlayer_for_Z-BlogPHP](https://www.fghrsh.net/post/57.html)
[DPlayer](https://github.com/DIYgod/DPlayer) for Z-BlogPHP

## 声明
#[DPlayer_for_Z-BlogPHP](https://www.fghrsh.net/post/57.html)
<p>
Demo:
<a href="https://www.fghrsh.net/post/57.html" target="_blank">
https://www.fghrsh.net/post/57.html
</a>
</p>
<p>
效果截图
</p>
<p>
<img width="80%" src="https://fp1.fghrsh.net/2016/06/01/5dc96d3a7e157c883ea62e22339cee39.jpg" border="0" vspace="0"/>
</p>
<p>
<br/>
</p>
<p>
<a rel='nofollow' title="DPlayer" style="color: rgb(0, 112, 192); text-decoration: none;" href="https://github.com/DIYgod/DPlayer" target="_blank">
<span style="color: #0070C0;">DIYgod开发的超级好看的HTML5弹幕视频播放器,现已移植到了 Z-BlogPHP 233</span>
</a>
</p>
<p>
<br/>
</p>


##声明
代码和用法参考了 [https://github.com/volio/DPlayer-for-typecho](https://github.com/volio/DPlayer-for-typecho)

##使用方式
下载后将文件夹名改为DPlayer上传启用即可

默认不自动播放,弹幕开启
```
[dplayer url="http://xxx.com/xxx.mp4" pic="http://xxx.com/xxx.jpg" autoplay="true" danmu="false"/]
```
直接在文章插入上述标签即可,默认不自动播放,弹幕开启

### V1.4 更新
更新 DPlayer 至最新版本
新增 去除右键菜单
新增 去除全局按键检测 设置
新版 DPlayer 更新了 [SATA](https://github.com/DIYgod/DPlayer/blob/master/LICENSE "The Star And Thank Author License") 授权协议,用前请先 [+1star](https://github.com/DIYgod/DPlayer "DPlayer") =-= (支持作者)

### V1.2 更新
已实现Ajax/Pjax模板支持,仅需在 加载完成时执行 里加入
###参数说明
```
dpajaxload();
url - 视频地址(必须)   // 填url地址
pic - 视频封面(可选)   // 填url地址
autoplay - 自动播放(可选)  // true(开启) 或 false(关闭)
theme - 自定义颜色(可选)   // 十六进制 (hex) 例:#FADFA3
loop - 循环播放(可选)   // true(开启) 或 false(关闭)
lang - 界面语言(可选)   // 'zh'(中文) 或 'en'(英文)
danmu - 弹幕开关(可选)   // true(开启) 或 false(关闭)
id - 指定弹幕ID(可选)   // 跳过弹幕ID生成,直接绑定弹幕池ID
screenshot - 截图功能(可选) // true 或 false,开启截图功能需源站支持 Cross-Origin
hotkey - 热键(可选)   // true 或 false,空格 播放/暂停,↕调节音量,↔调节进度
preload - 预加载(可选)   //'auto'(自动) 或 'metadata'(开启) 或 'none'(关闭)
```
即可无刷新加载 DPlayer 播放器(效果见我博客,全站pjax)

###参数说明
url - 视频地址(必须)
pic - 视频封面(可选)
danmu - 弹幕(可选,默认开)
loop - 循环播放(可选,默认关)
autoplay - 自动播放(可选,默认关)
theme - 自定义颜色(可选,默认为全局设置)

###后台配置说明
本站地址 - 用于生成唯一视频ID
去除右键菜单 - 隐藏播放器右键菜单
弹幕后端服务器 - 用于指定弹幕服务器地址
去除全局按键检测 - 解决评论 输入空格 导致 播放器暂停/播放 问题
播放器色调 - 指定全局播放器颜色主题(颜色生效在哪?你看看进度条..)
Tips:想多个站显示同一弹幕,设置“本站地址”为同一地址即可(视频地址需相同)

## LICENSE
MIT © [FGHRSH](https://www.fghrsh.net)
MIT ©2016 [FGHRSH](https://www.fghrsh.net)
85 changes: 49 additions & 36 deletions function.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
<?php
class dplayer_class
{
function parseCallback($post,$siteurl,$dmserver,$theme) {
function parseCallback($post,$config) {
$pattern = self::get_shortcode_regex(array('dplayer'));
preg_match_all("/$pattern/",$post,$matches);
if (empty($matches[0])) {
return $post."<i id=\"dpajax\" hidden=\"hidden\"></i>";
}
for ($i=0;$i<count($matches[3]);$i++) {
if ($matches[1][$i] == '[' && $matches[6][$i] == ']') {
for ($i=0;$i<count($matches[0]);$i++) {
if ($matches[1][$i] == '[' and $matches[6][$i] == ']') {
$dp["#dp#$i#"] = substr($matches[0][$i], 1, -1);
if (empty($out)) {
$out = str_replace($matches[0][$i], substr($matches[0][$i], 1, -1), $post);
$out = self::str_replace_once($matches[0][$i], "#dp#$i#", $post);
} else {
$out = str_replace($matches[0][$i], substr($matches[0][$i], 1, -1), $out);
$out = self::str_replace_once($matches[0][$i], "#dp#$i#", $out);
}
} else {
$attr = htmlspecialchars_decode($matches[3][$i]);
$atts = self::shortcode_parse_atts($attr);
$id = md5($siteurl.$atts['url']);
$result = array(
'url' => $atts['url'] ? $atts['url'] : '',
'pic' => $atts['pic'] ? $atts['pic'] : '');
if (empty($result)) return '';
if (empty($theme)) $theme = '#FADFA3';
$data = array(
'id' => $id,
'autoplay' => false,
'theme' => $theme);
$data['autoplay'] = ($atts['autoplay'] == 'true') ? true : false;
$data['theme'] = $atts['theme'] ? $atts['theme'] : $theme;
$data['loop'] = ($atts['loop'] == 'true') ? true : false;
$data['lang'] = 'zh';
$data['video'] = $result;
$danmaku = array(
'id' => md5($id),
'token' => md5(md5($id) . date('YmdH', time())),
'api' => $dmserver,);
$data['danmaku'] = ($atts['danmu'] != 'false') ? $danmaku : null;
if (empty($dmserver)) $data['danmaku'] = null;
$js = json_encode($data);
$src = "<div id=\"player".$id."\" class=\"dplayer\"></div>";
if (empty($out)) {
$out = str_replace($matches[0][$i], $src, $post);
$jssrc = "dPlayerOptions.push(".$js.");";
} else {
$out = str_replace($matches[0][$i], $src, $out);
$jssrc .= "dPlayerOptions.push(".$js.");";
if (isset($atts['url'])) {
$data = array('id' => md5($siteurl.$atts['url']));
if (isset($atts['hotkey'])) $data['hotkey']=self::str2bool($atts['hotkey']); else $data['hotkey']=(bool)$config['hotkey'];
if (isset($atts['screenshot'])) $data['screenshot']=self::str2bool($atts['screenshot']); else $data['screenshot']=(bool)$config['screenshot'];
if (isset($atts['loop'])) $data['loop']=self::str2bool($atts['loop']); else $data['loop']=(bool)$config['loop'];
if (isset($atts['autoplay'])) $data['autoplay']=self::str2bool($atts['autoplay']); else $data['autoplay']=(bool)$config['autoplay'];
if (isset($atts['theme'])) $data['theme']=$atts['theme']; else $data['theme']=$config['theme'];
if ($config['lang']==1) $data['lang'] = 'zh'; elseif ($config['lang']==2) $data['lang'] = 'en';
if ($config['preload']==1) $data['preload'] = 'metadata'; elseif ($config['preload']==2) $data['preload'] = 'none'; else $data['preload'] = 'auto';
if (isset($atts['lang'])) $data['lang'] = $atts['lang'];if (isset($atts['preload'])) $data['preload'] = $atts['preload'];
$data['video'] = array(
'url' => $atts['url'] ? $atts['url'] : '',
'pic' => $atts['pic'] ? $atts['pic'] : ''
);
if (isset($atts['id'])) $dmid = $atts['id']; else $dmid = md5($data['id']);
$data['danmaku'] = array(
'id' => $dmid,
'token' => md5($dmid.date('YmdH',time())),
'api' => $config['dmserver']
);
if (empty($config['dmserver']) or !$config['danmaku']) $data['danmaku'] = null;
if (isset($atts['danmu'])) if (!self::str2bool($atts['danmu'])) $data['danmaku'] = null;
if (empty($out)) {
$js = "DPlayerOptions.push(".json_encode($data).");";
$out = self::str_replace_once($matches[0][$i], "<div id=\"player".$data['id']."\" class=\"dplayer\"></div>", $post);
} else {
$js .= "DPlayerOptions.push(".json_encode($data).");";
$out = self::str_replace_once($matches[0][$i], "<div id=\"player".$data['id']."\" class=\"dplayer\"></div>", $out);
}
}
}
}
$out .= "<i id=\"dpajax\" hidden=\"hidden\">".$jssrc."</i>";
return $out;
$out .= "<i id=\"dpajax\" hidden=\"hidden\">".$js."</i>";
if (isset($dp)) foreach ($dp as $k => $v) return str_replace($k,$v,$out); else return $out;
}

function shortcode_parse_atts($text) {
Expand Down Expand Up @@ -87,5 +88,17 @@ function get_shortcode_regex($tagnames = null) {
$tagregexp = join('|', array_map('preg_quote', $tagnames));
return '\\['.'(\\[?)'. "($tagregexp)".'(?![\\w-])'.'('.'[^\\]\\/]*'.'(?:'.'\\/(?!\\])'.'[^\\]\\/]*'.')*?'.')'. '(?:'.'(\\/)'.'\\]'.'|'.'\\]'.'(?:'.'('.'[^\\[]*+'.'(?:'.'\\[(?!\\/\\2\\])'.'[^\\[]*+'.')*+'.')'.'\\[\\/\\2\\]'.')?'.')'.'(\\]?)';
}

function str_replace_once($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}

function str2bool($str) {
if ($str=='true') return true;elseif ($str=='false') return false;else return $str;
}
}
?>
54 changes: 39 additions & 15 deletions include.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,65 @@ function DPlayer_Filter_Plugin_ViewPost_Template(&$template) {
global $dplayer;
global $zbp;
$article = $template->GetTags('article');
$article->Content = $dplayer->parseCallback($article->Content,$zbp->Config('DPlayer')->seturl,$zbp->Config('DPlayer')->dmserver,$zbp->Config('DPlayer')->theme);
$config = array(
"seturl" => $zbp->Config('DPlayer')->seturl,
"dmserver" => $zbp->Config('DPlayer')->dmserver,
"hotkey" => $zbp->Config('DPlayer')->hotkey,
"danmaku" => $zbp->Config('DPlayer')->danmaku,
"screenshot" => $zbp->Config('DPlayer')->screenshot,
"loop" => $zbp->Config('DPlayer')->loop,
"autoplay" => $zbp->Config('DPlayer')->autoplay,
"preload" => $zbp->Config('DPlayer')->preload,
"lang" => $zbp->Config('DPlayer')->lang,
"maximum" => $zbp->Config('DPlayer')->maximum,
"theme" => $zbp->Config('DPlayer')->theme
);
$article->Content = $dplayer->parseCallback($article->Content,$config);
}

function DPlayer_Filter_Plugin_ViewList_Template(&$template) {
global $dplayer;
global $zbp;
$articles = $template->GetTags('articles');
$config = array(
"seturl" => $zbp->Config('DPlayer')->seturl,
"dmserver" => $zbp->Config('DPlayer')->dmserver,
"hotkey" => $zbp->Config('DPlayer')->hotkey,
"danmaku" => $zbp->Config('DPlayer')->danmaku,
"screenshot" => $zbp->Config('DPlayer')->screenshot,
"loop" => $zbp->Config('DPlayer')->loop,
"autoplay" => $zbp->Config('DPlayer')->autoplay,
"preload" => $zbp->Config('DPlayer')->preload,
"lang" => $zbp->Config('DPlayer')->lang,
"maximum" => $zbp->Config('DPlayer')->maximum,
"theme" => $zbp->Config('DPlayer')->theme
);
foreach($articles as $article) {
$article->Intro = $dplayer->parseCallback($article->Intro,$zbp->Config('DPlayer')->seturl,$zbp->Config('DPlayer')->dmserver,$zbp->Config('DPlayer')->theme);
$article->Intro = $dplayer->parseCallback($article->Intro,$config);
}
}

function DPlayer_Filter_Plugin_Zbp_MakeTemplatetags() {
global $zbp;
//$zbp->header .= '<link rel="stylesheet" href="'.$zbp->host.'zb_users/plugin/DPlayer/dplayer/DPlayer.min.css">'."\r\n";
$zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/DPlayer.min.js?v=1.0.2"></script>'."\r\n"."<script>function dpajaxload(){var dPlayers=[],dPlayerOptions=[];if($(\"#dpajax\").length>0){eval($(\"#dpajax\").text());var len=dPlayerOptions.length;for(var i=0;i<len;i++){dPlayers[i]=new DPlayer({element:document.getElementById('player'+dPlayerOptions[i]['id']),autoplay:dPlayerOptions[i]['autoplay'],loop:dPlayerOptions[i]['loop'],lang:dPlayerOptions[i]['lang'],video:dPlayerOptions[i]['video'],theme:dPlayerOptions[i]['theme'],danmaku:dPlayerOptions[i]['danmaku'],});dPlayers[i].init()}}}dpajaxload();</script>";
$zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/DPlayer.min.js?v=1.0.5"></script>'."\r\n"."<script>function dpajaxload(){if(0<$('#dpajax').length){var DPlayerOptions=[];eval($('#dpajax').text());for(i=0;i<DPlayerOptions.length;i++)new DPlayer({element:document.getElementById('player'+DPlayerOptions[i].id),autoplay:DPlayerOptions[i].autoplay,theme:DPlayerOptions[i].theme,loop:DPlayerOptions[i].loop,lang:DPlayerOptions[i].lang,screenshot:DPlayerOptions[i].screenshot,hotkey:DPlayerOptions[i].hotkey,preload:DPlayerOptions[i].preload,video:DPlayerOptions[i].video,danmaku:DPlayerOptions[i].danmaku})}}dpajaxload();</script>";
}

function InstallPlugin_DPlayer() {
global $zbp,$obj,$bucket;
if (!$zbp->Config('DPlayer')->HasKey('theme')) {
$zbp->Config('DPlayer')->seturl = $zbp->host;
$zbp->Config('DPlayer')->dmserver = '//dplayer.daoapp.io/';
$zbp->Config('DPlayer')->useue = 1;
$zbp->Config('DPlayer')->hidermmenu = 0;
$zbp->Config('DPlayer')->hotkey = 1;
$zbp->Config('DPlayer')->danmaku = 1;
$zbp->Config('DPlayer')->screenshot = 0;
$zbp->Config('DPlayer')->loop = 0;
$zbp->Config('DPlayer')->autoplay = 0;
$zbp->Config('DPlayer')->preload = 0;
$zbp->Config('DPlayer')->lang = 1;
$zbp->Config('DPlayer')->maximum = 1000;
$zbp->Config('DPlayer')->theme = '#FADFA3';
$zbp->Config('DPlayer')->hidermmenu = '0';
$zbp->Config('DPlayer')->fixcodekey = '0';
$zbp->SaveConfig('DPlayer');
}
}
Expand All @@ -51,14 +84,5 @@ function UninstallPlugin_DPlayer() {
$dpjs = str_replace('About DPlayer")+"</a></span></div>\n </div>-->\n','About DPlayer")+"</a></span></div>\n </div>\n',$dpjs);
file_put_contents(dirname(__FILE__)."/DPlayer.min.js",$dpjs);
}
if ($zbp->Config('DPlayer')->hidermmenu !== '0') {
$dpjs = file_get_contents(dirname(__FILE__)."/DPlayer.min.js");
$dpjs = str_replace('/*fixcodekey32*/','a.preventDefault(),e.toggle();',$dpjs);
$dpjs = str_replace('/*fixcodekey37*/','a.preventDefault(),e.audio.currentTime=e.audio.currentTime-5;',$dpjs);
$dpjs = str_replace('/*fixcodekey39*/','a.preventDefault(),e.audio.currentTime=e.audio.currentTime+5;',$dpjs);
$dpjs = str_replace('/*fixcodekey38*/','a.preventDefault(),r=e.audio.volume+.1,r=r>0?r:0,r=r<1?r:1,e.updateBar("volume",r,"width"),e.audio.volume=r,e.audio.muted&&(e.audio.muted=!1),b();',$dpjs);
$dpjs = str_replace('/*fixcodekey40*/','a.preventDefault(),r=e.audio.volume-.1,r=r>0?r:0,r=r<1?r:1,e.updateBar("volume",r,"width"),e.audio.volume=r,e.audio.muted&&(e.audio.muted=!1),b()',$dpjs);
file_put_contents(dirname(__FILE__)."/DPlayer.min.js",$dpjs);
}
$zbp->DelConfig('DPlayer');
}
Loading

0 comments on commit aea9b8a

Please sign in to comment.