Skip to content

Commit d9e842d

Browse files
committed
DPlayer for WordPress
0 parents  commit d9e842d

File tree

9 files changed

+180
-0
lines changed

9 files changed

+180
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## DPlayer-WordPress: DPlayer for WordPress
2+
3+
[DPlayer](https://github.com/DIYgod/DPlayer) is such a lovely HTML5 danmaku video player by [DIYGod](https://github.com/DIYgod), and it's used on many platforms (as listed below).
4+
- [DPlayer-for-typecho](https://github.com/volio/DPlayer-for-typecho)
5+
6+
- [Hexo-tag-dplayer](https://github.com/NextMoe/hexo-tag-dplayer)
7+
8+
- [DPlayer_for_Z-BlogPHP](https://github.com/fghrsh/DPlayer_for_Z-BlogPHP)
9+
10+
- [纸飞机视频区插件(DPlayer for Discuz!)](https://coding.net/u/Click_04/p/video/git)
11+
12+
- [dplayer_py_backend](https://github.com/dixyes/dplayer_py_backend)
13+
14+
- [dplayer_lua_backend](https://github.com/dixyes/dplayer_lua_backend)
15+
16+
Today, DPlayer is coming to WordPress.
17+
18+
Usage is rather simple, and here is the template of shortcode we supported.
19+
[dplayer url="http://xxx.xxx.com/xxx.mp4" pic="http://xxx.xxx.com/xxx.png" autoplay="true" danmu="true"/]
20+
21+
Parameter 'url' is the source URL to the video file, you can upload the video to your WordPress library, then use it here.
22+
Parameter 'pic' is the poster of the video. And it's optional.
23+
Parameter 'autoplay', as the name suggests, if it is true, then once the video is prepared, it starts to play . Default false and it's optional also.
24+
Parameter 'danmu', should DPlayer load danmaku. Default false and it's optional.

dist/dplayer.zip

138 KB
Binary file not shown.

dplayer.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/*
3+
* Plugin Name: DPlayer for WordPress
4+
* Description: Wow, such a lovely HTML5 danmaku video player comes to WordPress
5+
* Version: 1.0
6+
* Author: BlueCocoa(WordPress Plugins)
7+
* Author URI: https://blog.0xbbc.com/
8+
*
9+
* Acknowledgement
10+
* Part of this work is done under Copy and paste programming :)
11+
* Thanks to https://github.com/volio/DPlayer-for-typecho
12+
*/
13+
14+
/*
15+
The Star And Thank Author License (SATA)
16+
17+
Copyright (c) 2016 DIYgod(i@html.love)
18+
19+
Project Url: https://github.com/DIYgod/DPlayer
20+
21+
Permission is hereby granted, free of charge, to any person obtaining a copy
22+
of this software and associated documentation files (the "Software"), to deal
23+
in the Software without restriction, including without limitation the rights
24+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
copies of the Software, and to permit persons to whom the Software is
26+
furnished to do so, subject to the following conditions:
27+
28+
The above copyright notice and this permission notice shall be included in
29+
all copies or substantial portions of the Software.
30+
31+
And wait, the most important, you shall star/+1/like the project(s) in project url
32+
section above first, and then thank the author(s) in Copyright section.
33+
34+
Here are some suggested ways:
35+
36+
- Email the authors a thank-you letter, and make friends with him/her/them.
37+
- Report bugs or issues.
38+
- Tell friends what a wonderful project this is.
39+
- And, sure, you can just express thanks in your mind without telling the world.
40+
41+
Contributors of this project by forking have the option to add his/her name and
42+
forked project url at copyright and project url sections, but shall not delete
43+
or modify anything else in these two sections.
44+
45+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51+
THE SOFTWARE.
52+
*/
53+
54+
class DPlayer {
55+
static $add_script;
56+
57+
public static function init() {
58+
add_action( 'wp_head', array( __CLASS__, 'ready') );
59+
add_action( 'wp_footer', array( __CLASS__, 'add_script' ) );
60+
add_shortcode( 'dplayer', array( __CLASS__, 'dplayer_load') );
61+
}
62+
63+
public static function ready() {
64+
?>
65+
<script>var dPlayers = [];var dPlayerOptions = [];</script>;
66+
<?php
67+
}
68+
69+
public static function dplayer_load($atts = [], $content = null, $tag = '') {
70+
// normalize attribute keys, lowercase
71+
$atts = array_change_key_case((array)$atts, CASE_LOWER);
72+
73+
$id = md5($_SERVER['HTTP_HOST'] . $atts['url']);
74+
$result = array(
75+
'url' => $atts['url'] ? $atts['url'] : '',
76+
'pic' => $atts['pic'] ? $atts['pic'] : ''
77+
);
78+
if (empty($result)) return;
79+
80+
$theme = $atts['theme'];
81+
if (!$theme) $theme = '#FADFA3';
82+
83+
$data = array(
84+
'id' => $id,
85+
'autoplay' => false,
86+
'theme' => $theme
87+
);
88+
89+
$data['autoplay'] = ($atts['autoplay'] == 'true') ? true : false;
90+
91+
$playerCode = '<div id="player'.$id.'" class="dplayer">';
92+
$playerCode .= "</div>\n";
93+
$data['video'] = $result;
94+
95+
$danmaku = array(
96+
'id' => md5($id),
97+
'token' => md5(md5($id) . date('YmdH', time())),
98+
'api' => '//danmaku.daoapp.io/dplayer/danmaku',
99+
);
100+
$data['danmaku'] = ($atts['danmu'] != 'false') ? $danmaku : null;
101+
102+
$js = json_encode($data);
103+
$playerCode .= <<<EOF
104+
<script>dPlayerOptions.push({$js});</script>
105+
EOF;
106+
echo $playerCode;
107+
}
108+
109+
public static function add_script() {
110+
if (!self::$add_script) {
111+
wp_enqueue_script( 'dplayer', site_url('/wp-content/plugins/dplayer/js/DPlayer.min.js'), false, '1.0.9', false );
112+
wp_enqueue_script( 'dplayer-hls', site_url('/wp-content/plugins/dplayer/js/plugins/hls.min.js'), false, '1.0.9', false );
113+
wp_enqueue_script( 'init-dplayer', site_url('/wp-content/plugins/dplayer/js/init-dplayer.js'), false, '1.0.0', false );
114+
self::$add_script = true;
115+
}
116+
}
117+
};
118+
119+
DPlayer::init();

js/DPlayer.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/DPlayer.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/hls.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/init-dplayer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var len = dPlayerOptions.length;
2+
for(var i=0;i<len;i++){
3+
dPlayers[i] = new DPlayer({
4+
element: document.getElementById('player' + dPlayerOptions[i]['id']),
5+
autoplay: dPlayerOptions[i]['autoplay'],
6+
video: dPlayerOptions[i]['video'],
7+
theme: dPlayerOptions[i]['theme'],
8+
danmaku: dPlayerOptions[i]['danmaku'],
9+
});
10+
}
11+

js/plugins/hls.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DPlayer is such a lovely HTML5 danmaku video player by DIYGod, and it's used on many platforms.
2+
Today, DPlayer is coming to WordPress.
3+
4+
Usage is rather simple, and here is the template of shortcode we supported.
5+
[dplayer url="http://xxx.xxx.com/xxx.mp4" pic="http://xxx.xxx.com/xxx.png" autoplay="true" danmu="true"/]
6+
7+
Parameter 'url' is the source URL to the video file, you can upload the video to your WordPress library, then use it here.
8+
Parameter 'pic' is the poster of the video. And it's optional.
9+
Parameter 'autoplay', as the name suggests, if it is true, then once the video is prepared, it starts to play . Default false and it's optional also.
10+
Parameter 'danmu', should DPlayer load danmaku. Default false and it's optional.
11+

0 commit comments

Comments
 (0)