Skip to content

Commit

Permalink
V1.4
Browse files Browse the repository at this point in the history
优化 部分主题兼容问题
美化 微调管理界面背景图片
美化 格式化输出初始化 JSON
修复 部分小细节导致的小 BUG
  • Loading branch information
fghrsh committed May 28, 2017
1 parent 7cbc35d commit e600831
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
Binary file modified bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 27 additions & 5 deletions function.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function parseCallback($post, $config) {
$api = self::check_https($config->api); $js = '';
$pattern = self::get_shortcode_regex(array('aplayer'));
preg_match_all("/$pattern/",$post,$matches);
if (empty($matches[0])) return $post."<i id=\"apajax\" hidden=\"hidden\"></i>";
if (empty($matches[0])) return $post.'<div id="apajax" style="display:none;"></div>';
for ($i=0;$i<count($matches[0]);$i++) {
if ($matches[1][$i] == '[' and $matches[6][$i] == ']') {
$ap["#ap#$i#"] = substr($matches[0][$i], 1, -1);
Expand Down Expand Up @@ -61,15 +61,37 @@ function parseCallback($post, $config) {
}
}
$data['showlrc'] = isset($atts['lrc']) && $atts['lrc']=='false' ? 0 : $data['showlrc'];
if ($data['music']) $js .= 'APlayerOptions.push('.json_encode($data).');';
if ($data['music']) $js .= "\n".'APlayerOptions.push('.self::json_encode_pretty($data).');';
$out = empty($out) ?
self::str_replace_once($matches[0][$i], "<div id=\"ap".$data['id']."\" class=\"aplayer\"></div>", $post):
self::str_replace_once($matches[0][$i], "<div id=\"ap".$data['id']."\" class=\"aplayer\"></div>", $out);
self::str_replace_once($matches[0][$i], '<div id="ap'.$data['id'].'" class="aplayer"></div>', $post):
self::str_replace_once($matches[0][$i], '<div id="ap'.$data['id'].'" class="aplayer"></div>', $out);
}
}
$out .= "<i id=\"apajax\" hidden=\"hidden\">".$js."</i>";
$out .= "<div id=\"apajax\" style=\"display:none;\">$js\n</div>";
if (isset($ap)) foreach ($ap as $k => $v) $out = str_replace($k, $v, $out); return $out;
}

function json_encode_pretty($src) {
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
return json_encode($src, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
} else {
array_walk_recursive($src, 'self::json_encode_unescaped');
$src = urldecode(json_encode($src));
$ret = ''; $pos = 0; $newline = "\n"; $prevchar = '';
$length = strlen($src); $indent = ' '; $outofquotes = true;
for ($i=0; $i<=$length; $i++) {
$char = substr($src, $i, 1);
if ($char=='"' && $prevchar!='\\') $outofquotes = !$outofquotes;
elseif (($char=='}' || $char==']') && $outofquotes) {
$ret .= $newline; $pos --; for ($j=0; $j<$pos; $j++) $ret .= $indent; }
$ret .= $char;
if (($char==',' || $char=='{' || $char=='[') && $outofquotes) {
$ret .= $newline; if ($char=='{' || $char=='[') $pos ++; for ($j=0; $j<$pos; $j++) $ret .= $indent; }
$prevchar = $char;
}
return str_replace(array('":', '"0"', '"1"', '"2"', '"3"'), array('": ', '0', '1', '2', '3'), $ret);
} }
function json_encode_unescaped(&$val) { if ($val!==true && $val!==false && $val!==null) $val = urlencode($val); }

function shortcode_parse_atts($text) {
$atts = array();
Expand Down
12 changes: 6 additions & 6 deletions include.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
require dirname(__FILE__).'/function.php';
$APlayer = new APlayer_class();
RegisterPlugin("APlayer","ActivePlugin_APlayer");
RegisterPlugin("APlayer", "ActivePlugin_APlayer");

function ActivePlugin_APlayer() {
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','APlayer_Filter_Plugin_ViewPost_Template');
Add_Filter_Plugin('Filter_Plugin_ViewList_Template','APlayer_Filter_Plugin_ViewList_Template');
Add_Filter_Plugin('Filter_Plugin_Zbp_MakeTemplatetags','APlayer_Filter_Plugin_Zbp_MakeTemplatetags');
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template', 'APlayer_Filter_Plugin_ViewPost_Template');
Add_Filter_Plugin('Filter_Plugin_ViewList_Template', 'APlayer_Filter_Plugin_ViewList_Template');
Add_Filter_Plugin('Filter_Plugin_Zbp_MakeTemplatetags', 'APlayer_Filter_Plugin_Zbp_MakeTemplatetags');
}

function APlayer_Filter_Plugin_ViewPost_Template(&$template) {
global $zbp;
global $APlayer;
global $zbp;
$article = $template->GetTags('article');
$article->Content = $APlayer->parseCallback($article->Content, $zbp->Config('APlayer'));
}

function APlayer_Filter_Plugin_ViewList_Template(&$template) {
global $zbp;
global $APlayer;
global $zbp;
$config = $zbp->Config('APlayer');
if ($config->parselist) {
$articles = $template->GetTags('articles');
Expand Down
5 changes: 3 additions & 2 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
require '../../../zb_system/admin/admin_top.php';

if(isset($_POST['api'])){
$tips = '';
foreach($_POST as $k => $v) $$k = $v; $tips = '';

if(empty($api)){
$zbp->ShowHint('bad', 'API 地址不允许为空!');
} else {
if ($api != ($zbp->Config('APlayer')->api)) {
$zbp->Config('APlayer')->api = $api;
$tips = 'API 地址设置成功;';
$tips .= 'API 地址设置成功;';
}
}
$mutex = in_array('mutex', $options) ? 1 : 0;
Expand Down Expand Up @@ -161,7 +162,7 @@ function color_picker(hex) {
</table>
<div style="width:90%;float:inherit">
<div style="float:left;padding:10px 0">
&copy;2017 <a href="https://www.fghrsh.net" target="_blank" style="color:#333333">FGHRSH</a> - <a href="https://www.fghrsh.net/post/77.html" target="_blank" style="color:#333333">APlayer for Z-BlogPHP V1.3</a> (APlayer 1.6.0)
&copy;2017 <a href="https://www.fghrsh.net" target="_blank" style="color:#333333">FGHRSH</a> - <a href="https://www.fghrsh.net/post/77.html" target="_blank" style="color:#333333">APlayer for Z-BlogPHP V1.4</a> (APlayer 1.6.0)
</div>
<div style="float:right;padding:5px 0;">
<input type="Submit" class="button" value="保存设置" />
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<url></url>
</source>
<adapted>140614</adapted>
<version>1.3</version>
<version>1.4</version>
<pubdate>2016-06-02</pubdate>
<modified>2017-04-24</modified>
<modified>2017-05-28</modified>
<price>0</price>
<phpver>5.2</phpver>
<advanced>
Expand Down

0 comments on commit e600831

Please sign in to comment.