Skip to content

Commit

Permalink
php7 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
volio committed Nov 21, 2019
1 parent ccda64b commit d3041c7
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @package DPlayer
* @author Volio
* @version 1.0.1
* @version 1.0.3
* @link http://github.com/volio/DPlayer-for-typecho
*/
class DPlayer_Plugin implements Typecho_Plugin_Interface
Expand All @@ -17,16 +17,15 @@ class DPlayer_Plugin implements Typecho_Plugin_Interface
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('DPlayer_Plugin', 'playerparse');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('DPlayer_Plugin', 'playerparse');
Typecho_Plugin::factory('Widget_Archive')->header = array('DPlayer_Plugin', 'playerHeader');
Typecho_Plugin::factory('Widget_Archive')->footer = array('DPlayer_Plugin', 'playerFooter');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('DPlayer_Plugin', 'addButton');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('DPlayer_Plugin', 'addButton');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = ['DPlayer_Plugin', 'parsePlayer'];
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = ['DPlayer_Plugin', 'parsePlayer'];
Typecho_Plugin::factory('Widget_Archive')->header = ['DPlayer_Plugin', 'playerHeader'];
Typecho_Plugin::factory('Widget_Archive')->footer = ['DPlayer_Plugin', 'playerFooter'];
Typecho_Plugin::factory('admin/write-post.php')->bottom = ['DPlayer_Plugin', 'addEditorButton'];
Typecho_Plugin::factory('admin/write-page.php')->bottom = ['DPlayer_Plugin', 'addEditorButton'];
}

/**
Expand All @@ -35,7 +34,6 @@ public static function activate()
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Expand All @@ -55,6 +53,7 @@ public static function playerHeader()

/**
* 插入底部代码
* @throws Typecho_Exception
*/
public static function playerFooter()
{
Expand All @@ -75,25 +74,28 @@ public static function playerFooter()
* 内容标签替换
*
* @param string $content
* @param $widget
* @param $lastResult
* @return string
*/
public static function playerparse($content, $widget, $lastResult)
public static function parsePlayer($content, $widget, $lastResult)
{
$content = empty($lastResult) ? $content : $lastResult;
if ($widget instanceof Widget_Archive) {
if (false === strpos($content, '[')) {
return $content;
}
$pattern = self::get_shortcode_regex(array('dplayer'));
$content = preg_replace_callback("/$pattern/", array('DPlayer_Plugin', 'parseCallback'), $content);
$pattern = self::get_shortcode_regex(['dplayer']);
$content = preg_replace_callback("/$pattern/", ['DPlayer_Plugin', 'parseCallback'], $content);
}
return $content;
}

/**
* 回调解析
* @param unknown $matches
* @param $matches
* @return string
* @throws Typecho_Exception
*/
public static function parseCallback($matches)
{
Expand Down Expand Up @@ -134,25 +136,25 @@ public static function parseCallback($matches)
'thumbnails' => isset($atts['thumbnails']) ? $atts['thumbnails'] : '',
);
//弹幕部分配置文件
$subtitle = array(
$subtitle = [
'url' => isset($atts['subtitleurl']) ? $atts['subtitleurl'] : '',
'type' => isset($atts['subtitletype']) ? $atts['subtitletype'] : 'webvtt',
'fontSize' => isset($atts['subtitlefontsize']) ? $atts['subtitlefontsize'] : '25px',
'bottom' => isset($atts['subtitlebottom']) ? $atts['subtitlebottom'] : '10%',
'color' => isset($atts['subtitlecolor']) ? $atts['subtitlecolor'] : '#b7daff',
);
$danmaku = array(
];
$danmaku = [
'id' => $id,
'api' => $api,
'maximum' => isset($atts['maximum']) ? $atts['maximum'] : 1000,
'addition' => isset($atts['addition']) ? array($atts['addition']) : null,
'addition' => isset($atts['addition']) ? [$atts['addition']] : null,
'user' => isset($atts['user']) ? $atts['user'] : 'DIYgod',
'bottom' => isset($atts['bottom']) ? $atts['bottom'] : '15%',
'unlimited' => true,
);
];

//播放器默认属性
$data = array(
$data = [
'id' => $id,
'live' => false,
'autoplay' => false,
Expand All @@ -165,7 +167,7 @@ public static function parseCallback($matches)
'logo' => isset($atts['logo']) ? $atts['logo'] : null,
'volume' => isset($atts['volume']) ? $atts['volume'] : 0.7,
'mutex' => true,
);
];
$data['video'] = $video;
$data['danmaku'] = (isset($atts['danmu']) && $atts['danmu'] == 'true') ? $danmaku : null;
$data['subtitle'] = isset($atts['subtitleurl']) ? $subtitle : null;
Expand All @@ -179,9 +181,9 @@ public static function parseCallback($matches)
return $playerCode;
}

public static function addButton()
public static function addEditorButton()
{
$dir = Helper::options()->pluginUrl.'/DPlayer/dist/editor.js';
$dir = Helper::options()->pluginUrl . '/DPlayer/dist/editor.js';
echo "<script type=\"text/javascript\" src=\"{$dir}\"></script>";
}

Expand Down

0 comments on commit d3041c7

Please sign in to comment.