Skip to content

Commit

Permalink
V1.7
Browse files Browse the repository at this point in the history
更新 DPlayer 至 1.3.3 版
新增 FLV 和 HLS(m3u8)支持
新增 额外弹幕源 支持(新版 DPlayer 功能)
修复 若干BUG 和 若干优化,新增了几项可选自定义参数
  • Loading branch information
fghrsh committed Mar 30, 2017
1 parent 2a6f51f commit 3dc02c5
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 175 deletions.
5 changes: 2 additions & 3 deletions DPlayer.min.js

Large diffs are not rendered by default.

36 changes: 11 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[DPlayer_for_Z-BlogPHP](https://app.zblogcn.com/?id=1033)
# [DPlayer_for_Z-BlogPHP](https://app.zblogcn.com/?id=1033)
Demo:https://www.fghrsh.net/post/57.html
效果截图
<img width="80%" src="https://fp1.fghrsh.net/2016/06/01/5dc96d3a7e157c883ea62e22339cee39.jpg" border="0" vspace="0"/>
Expand All @@ -7,29 +7,15 @@ Demo:https://www.fghrsh.net/post/57.html
<span style="color: #0070C0;">DIYgod开发的超级好看的HTML5弹幕视频播放器,现已移植到了 Z-BlogPHP 233</span>
</a>

##声明
部分代码参考 [https://github.com/volio/DPlayer-for-typecho](https://github.com/volio/DPlayer-for-typecho)

##使用方式
## 声明
部分代码参考 [https://github.com/volio/DPlayer-for-typecho](https://github.com/volio/DPlayer-for-typecho)
## 使用方式
```
[dplayer url="http://xxx.com/xxx.mp4" pic="http://xxx.com/xxx.jpg" autoplay="true" danmu="false"/]
```
直接在文章插入上述标签即可,默认不自动播放,弹幕开启

###参数说明
```
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'(关闭)
```

## LICENSE
MIT &copy; [FGHRSH](https://www.fghrsh.net)
```
直接在文章插入上述标签即可,默认不自动播放,弹幕开启
更多说明见 Z-Blog 应用中心 https://app.zblogcn.com/?id=1033

## LICENSE
MIT &copy; [FGHRSH](https://www.fghrsh.net)
94 changes: 36 additions & 58 deletions function.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,45 @@
class dplayer_class
{
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>";
}
preg_match_all('/'.self::get_shortcode_regex(array('dplayer')).'/', $post, $matches);
if (empty($matches[0])) return $post . '<i id="dpajax" hidden="hidden"></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 = self::str_replace_once($matches[0][$i], "#dp#$i#", $post);
} else {
$out = self::str_replace_once($matches[0][$i], "#dp#$i#", $out);
}
$out = empty($out) ? self::str_replace_once($matches[0][$i], "#dp#$i#", $post) : $out = self::str_replace_once($matches[0][$i], "#dp#$i#", $out);
} else {
$attr = htmlspecialchars_decode($matches[3][$i]);
$atts = self::shortcode_parse_atts($attr);
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']
);
$data['hotkey'] = isset($atts['hotkey']) ? self::str2bool($atts['hotkey']) : (bool)$config['hotkey'];
$data['screenshot'] = isset($atts['screenshot']) ? self::str2bool($atts['screenshot']) : (bool)$config['screenshot'];
$data['loop'] = isset($atts['loop']) ? self::str2bool($atts['loop']) : (bool)$config['loop'];
$data['autoplay'] = isset($atts['autoplay']) ? self::str2bool($atts['autoplay']) : (bool)$config['autoplay'];
$data['theme'] = isset($atts['theme']) ? $atts['theme'] : $config['theme'];
$data['lang'] = isset($atts['lang']) ? $atts['lang'] : $config['lang']=='1' ? 'zh' : 'en';
$data['preload'] = isset($atts['preload']) ? $atts['preload'] : $config['preload']=='1' ? 'metadata' : $config['preload']=='2' ? 'none' : 'auto';
$data['video'] = array_filter(array(
'url' => $atts['url'] ? $atts['url'] : null,
'pic' => $atts['pic'] ? $atts['pic'] : null,
'type' => $atts['type'] ? $atts['type'] : 'auto' ));
$data['danmaku'] = array_filter(array(
'id' => $atts['id'] ? $atts['id'] : md5($data['id']),
'api' => $atts['api'] ? $atts['api'] : $config['dmserver'],
'token' => $atts['token'] ? $atts['token'] : md5($data['id'].time()),
'maximum' => $atts['maximum'] ? $atts['maximum'] : $config['maximum'],
'addition' => $atts['addition'] ? explode('|',$atts['addition']) : null ));
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);
}
$js .= "DPlayerOptions.push(".json_encode(array_filter($data, 'self::is_not_null')).");";
$out = empty($out) ?
self::str_replace_once($matches[0][$i], '<div id="dplayer-'.$data['id'].'" class="dplayer"></div>', $post):
self::str_replace_once($matches[0][$i], '<div id="dplayer-'.$data['id'].'" class="dplayer"></div>', $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;
$out .= '<i id="dpajax" hidden="hidden">'.$js.'</i>';
if (isset($dp)) foreach ($dp as $k => $v) $out = str_replace($k,$v,$out); return $out;
}

function shortcode_parse_atts($text) {
Expand All @@ -60,24 +49,13 @@ function shortcode_parse_atts($text) {
$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) {
foreach ($match as $m) {
if (!empty($m[1]))
$atts[strtolower($m[1])] = stripcslashes($m[2]);
elseif (!empty($m[3]))
$atts[strtolower($m[3])] = stripcslashes($m[4]);
elseif (!empty($m[5]))
$atts[strtolower($m[5])] = stripcslashes($m[6]);
elseif (isset($m[7]) && strlen($m[7]))
$atts[] = stripcslashes($m[7]);
elseif (isset($m[8]))
$atts[] = stripcslashes($m[8]);
}
foreach ($atts as &$value) {
if (false !== strpos($value, '<')) {
if (1 !== preg_match('/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value)) {
$value = '';
}
}
if (!empty($m[1])) $atts[strtolower($m[1])] = stripcslashes($m[2]);
elseif (!empty($m[3])) $atts[strtolower($m[3])] = stripcslashes($m[4]);
elseif (!empty($m[5])) $atts[strtolower($m[5])] = stripcslashes($m[6]);
elseif (isset($m[7]) && strlen($m[7])) $atts[] = stripcslashes($m[7]);
elseif (isset($m[8])) $atts[] = stripcslashes($m[8]);
}
foreach ($atts as &$value) if (false !== strpos($value, '<')) if (1 !== preg_match('/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value)) $value = '';
} else {
$atts = ltrim($text);
}
Expand All @@ -91,14 +69,14 @@ function get_shortcode_regex($tagnames = null) {

function str_replace_once($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
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;
if ($str=='true') return true; elseif ($str=='false') return false; else return $str;
}

function is_not_null($val) { return !is_null($val); }
}
?>
78 changes: 41 additions & 37 deletions include.php
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
<?php
require dirname(__FILE__).'/function.php';
$dplayer = new dplayer_class();
RegisterPlugin("DPlayer","ActivePlugin_DPlayer");
RegisterPlugin("DPlayer", "ActivePlugin_DPlayer");

function ActivePlugin_DPlayer() {
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','DPlayer_Filter_Plugin_ViewPost_Template');
Add_Filter_Plugin('Filter_Plugin_ViewList_Template','DPlayer_Filter_Plugin_ViewList_Template');
Add_Filter_Plugin('Filter_Plugin_Zbp_MakeTemplatetags','DPlayer_Filter_Plugin_Zbp_MakeTemplatetags');
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template', 'DPlayer_Filter_Plugin_ViewPost_Template');
Add_Filter_Plugin('Filter_Plugin_ViewList_Template', 'DPlayer_Filter_Plugin_ViewList_Template');
Add_Filter_Plugin('Filter_Plugin_Zbp_MakeTemplatetags', 'DPlayer_Filter_Plugin_Zbp_MakeTemplatetags');
}

function DPlayer_Filter_Plugin_ViewPost_Template(&$template) {
global $zbp;
global $dplayer;
global $zbp;
$article = $template->GetTags('article');
$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);
'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 $zbp;
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
);
'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,$config);
$article->Intro = $dplayer->parseCallback($article->Intro, $config);
}
}

function DPlayer_Filter_Plugin_Zbp_MakeTemplatetags() {
global $zbp;
$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>";
if ($zbp->Config('DPlayer')->flv) $zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/plugin/flv.min.js"></script>'."\n";
if ($zbp->Config('DPlayer')->hls) $zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/plugin/hls.min.js"></script>'."\n";
$zbp->footer .=
'<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/DPlayer.min.js?v=1.1.3"></script>'."\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(\'dplayer-\'+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')->dmserver = '//api.prprpr.me/dplayer/';
$zbp->Config('DPlayer')->useue = 1;
$zbp->Config('DPlayer')->hidermmenu = 0;
$zbp->Config('DPlayer')->hotkey = 1;
Expand All @@ -71,6 +73,8 @@ function InstallPlugin_DPlayer() {
$zbp->Config('DPlayer')->preload = 0;
$zbp->Config('DPlayer')->lang = 1;
$zbp->Config('DPlayer')->maximum = 1000;
$zbp->Config('DPlayer')->flv = 1;
$zbp->Config('DPlayer')->hls = 0;
$zbp->Config('DPlayer')->theme = '#FADFA3';
$zbp->SaveConfig('DPlayer');
}
Expand All @@ -80,9 +84,9 @@ function UninstallPlugin_DPlayer() {
global $zbp;
if ($zbp->Config('DPlayer')->hidermmenu == '1') {
$dpjs = file_get_contents(dirname(__FILE__)."/DPlayer.min.js");
$dpjs = str_replace('<!--<div class="dplayer-menu">','<div class="dplayer-menu">',$dpjs);
$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);
$dpjs = str_replace('<!--<div class="dplayer-menu">', '<div class="dplayer-menu">', $dpjs);
$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);
}
$zbp->DelConfig('DPlayer');
}
Loading

0 comments on commit 3dc02c5

Please sign in to comment.