Skip to content

Commit

Permalink
V1.3
Browse files Browse the repository at this point in the history
* 修复 低版本PHP(5.3) 兼容问题
* 修复 某些主题后台 背景显示问题
  • Loading branch information
fghrsh committed Apr 21, 2017
1 parent 1e0ea65 commit 2d44210
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
39 changes: 20 additions & 19 deletions api/aplayer_music_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@

class aplayer_music_api {
function url($id) {
return ($api = json_decode((new NeteaseMusicAPI())
->url((int)$id), 1))['code'] == 200 ? $api['data'][0]['url'] : 0; }
$api = new NeteaseMusicAPI(); $api = json_decode($api->url((int)$id), 1);
return $api['code'] == 200 ? $api['data'][0]['url'] : 0; }
function pic($id) {
return ($api = json_decode(($api = new NeteaseMusicAPI())
->album((int)json_decode($api->detail((int)$id))->songs[0]->al->id), 1))['code'] == 200 ? $api['album']['picUrl'] : 0; }
$api = new NeteaseMusicAPI(); $t = json_decode($api->detail((int)$id))->songs[0]->al->id; $api = json_decode($api->album((int)$t), 1);
return $api['code'] == 200 ? $api['album']['picUrl'] : 0; }
function lrc($id, $lang = 0) {
return ($api = json_decode((new NeteaseMusicAPI())
->lyric((int)$id), 1))['code'] == 200 ? ($out = $lang ? self::mix_lyric($api) : $api['lrc']['lyric']) ? $out : "[00:00.00]暂无歌词\n[99:00.00] " : 0; }
$api = new NeteaseMusicAPI(); $api = json_decode($api->lyric((int)$id), 1);
return $api['code'] == 200 ? ($out = $lang ? self::mix_lyric($api) : $api['lrc']['lyric']) ? $out : "[00:00.00]暂无歌词\n[99:00.00] " : 0; }
function song($ids, $url, $mix) {
foreach (explode(',', $ids) as $id) if (($api = json_decode((new NeteaseMusicAPI())
->detail((int)$id), 1))['code'] == 200) $o[] = $api['songs'][0]; return self::playlist($o, $url, $mix); }
$api = new NeteaseMusicAPI();
foreach (explode(',', $ids) as $id) if ($t = json_decode($api->detail((int)$id), 1) && $t['code'] == 200) $o[] = $api['songs'][0];
return self::playlist($o, $url, $mix); }
function collect($id, $url, $mix) {
return ($api = json_decode((new NeteaseMusicAPI())
->playlist((int)$id), 1))['code'] == 200 ? self::playlist($api['playlist']['tracks'], $url, $mix) : 0; }
$api = new NeteaseMusicAPI(); $api = json_decode($api->playlist((int)$id), 1);
return $api['code'] == 200 ? self::playlist($api['playlist']['tracks'], $url, $mix) : 0; }
function artist($id, $url, $mix) {
return ($api = json_decode((new NeteaseMusicAPI())
->artist((int)$id), 1))['code'] == 200 ? self::playlist($api['hotSongs'], $url, $mix) : 0; }
$api = new NeteaseMusicAPI(); $api = json_decode($api->artist((int)$id), 1);
return $api['code'] == 200 ? self::playlist($api['hotSongs'], $url, $mix) : 0; }
function album($id, $url, $mix) {
return ($api = json_decode((new NeteaseMusicAPI())
->album((int)$id), 1))['code'] == 200 ? self::playlist($api['songs'], $url, $mix) : 0; }
$api = new NeteaseMusicAPI(); $api = json_decode($api->album((int)$id), 1);
return $api['code'] == 200 ? self::playlist($api['songs'], $url, $mix) : 0; }
function playlist($arr, $api, $mix) {
foreach ($arr as $v) $o[] = array(
'title' => $v['name'],
'author' => self::ar2str($v['ar']),
'url' => $api.'?'.$v['id'].'.mp3',
'pic' => $api.'?'.$v['id'].'.jpg',
'lrc' => $api.'?'.$v['id'].'.'.($mix ? 'lrc2' : 'lrc') ); return $o; }
'url' => $api.'?id='.$v['id'].'.mp3',
'pic' => $api.'?id='.$v['id'].'.jpg',
'lrc' => $api.'?id='.$v['id'].'.'.($mix ? 'lrc2' : 'lrc') ); return $o; }
function mix_lyric($json) {
if ($json['tlyric']['lyric']) {
$lrc = explode("\n", str_replace('undefined', '', $json['lrc']['lyric'])); $cnlrc = explode("\n", $json['tlyric']['lyric']);
Expand All @@ -39,6 +40,6 @@ function mix_lyric($json) {
foreach ($cnlrc_line as $k => $v) $lrc_line[$k] = !empty($v) && !(($s=$lrc_line[$k]) == $v) ? $s.' ['.self::cnlrc_format($v).']' : '';
foreach ($lrc_line as $k => $v) $lrc_out .= $k.']'.$v."\n"; } else return str_replace('undefined', '', $json['lrc']['lyric']); return $lrc_out; }
function ar2str($r) { foreach ($r as $v) $o .= $v['name'].' / '; return substr($o, 0, -3); }
function time_format($t) { return str_replace($s = explode('.', $t)[1], substr($s, 0, 2), $t); }
function cnlrc_format($c) { return str_replace(['/', '[', ']', '', '', '', ''], '', $c); }
function time_format($t) { $e = explode('.', $t); return str_replace($s = $e[1], substr($s, 0, 2), $t); }
function cnlrc_format($c) { return str_replace(array('/', '[', ']', '', '', '', ''), '', $c); }
}
15 changes: 7 additions & 8 deletions api/index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<?php require dirname(__FILE__).'/aplayer_music_api.php';

$api = new aplayer_music_api(); $id = ($switch = explode('_',array_keys($_GET)[0]))[0]; $mix = $switch[2];
$api = new aplayer_music_api(); $switch = explode('.', $_GET['id']); $id = $switch[0]; $mix = $switch[2];
$url = str_replace('?'.$_SERVER["QUERY_STRING"], '', check_https('http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]));

switch ($switch[1]) {
case 'mp3': short_header('audio/mp3');exit(header('Location: '.check_https($api->url($id))));
case 'mp3': short_header('audio/mp3'); exit(header('Location: '.check_https($api->url($id))));
case 'jpg': short_header('image/jpg'); exit(header('Location: '.check_https($api->pic($id))));
case 'lrc': short_header('text/plain'); exit(str_replace('undefined', '', $api->lrc($id, 0)));
case 'lrc2': short_header('text/plain'); exit(str_replace('undefined', '', $api->lrc($id, 1)));
case 'song': short_header('application/json'); exit(pretty_json_encode($api->song($id, $url, $mix)));
case 'album': short_header('application/json'); exit(pretty_json_encode($api->album($id, $url, $mix)));
case 'artist': short_header('application/json'); exit(pretty_json_encode($api->artist($id, $url, $mix)));
case 'collect': short_header('application/json'); exit(pretty_json_encode($api->collect($id, $url, $mix)));
case 'song': short_header('application/json'); exit(json_encode($api->song($id, $url, $mix)));
case 'album': short_header('application/json'); exit(json_encode($api->album($id, $url, $mix)));
case 'artist': short_header('application/json'); exit(json_encode($api->artist($id, $url, $mix)));
case 'collect': short_header('application/json'); exit(json_encode($api->collect($id, $url, $mix)));
default: header('http/1.1 404 Not Found'); exit('error');
}

function short_header($head) { header("Content-Type: $head;charset=UTF-8"); }
function check_https($url) { return ((isset($_SERVER['HTTPS']) and $_SERVER['HTTPS']=='on') or
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ?
str_replace('http://','https://',$url) : str_replace('https://','http://',$url); }
function pretty_json_encode($src) { return json_encode($src, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); }
str_replace('http://','https://',$url) : str_replace('https://','http://',$url); }
16 changes: 8 additions & 8 deletions function.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class aplayer_class
{
function parseCallback($post, $config) {
$api = self::check_https($config->api);
$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>";
Expand Down Expand Up @@ -39,17 +39,17 @@ function parseCallback($post, $config) {
$tmp['author'] = isset($atts['author']) ? $atts['author'] : (isset($atts['artist']) ? $atts['artist'] : 'Unknown');
$data['music'][] = $tmp;
} elseif (isset($atts['id']))
$data['showlrc'] = ($data['music'][] = json_decode(self::curl($api.'?'.(int)$atts['id'].'.song'), 1)[0]) ? 3 : 3;
$data['showlrc'] = ($data['music'][] = ($t = json_decode(self::curl($api.'?id='.(int)$atts['id'].'.song'), 1)) ? $t[0] : $t[0]) ? 3 : 3;
} $data['music'] = count($data['music']) == 1 ? $data['music'][0] : $data['music'];
}
} else {
if (isset($atts['id'])) {
$data['showlrc'] = 3; $mix = $config->mix ? '.2' : '';
switch ($atts['type']) {
case 'collect': $data['music'] = json_decode(self::curl($api.'?'.$atts['id'].'.collect'.$mix), 1); break;
case 'artist': $data['music'] = json_decode(self::curl($api.'?'.$atts['id'].'.artist'.$mix), 1); break;
case 'album': $data['music'] = json_decode(self::curl($api.'?'.$atts['id'].'.album'.$mix), 1); break;
default: $data['music'] = json_decode(self::curl($api.'?'.$atts['id'].'.song'.$mix), 1); break;
case 'collect': $data['music'] = json_decode(self::curl($api.'?id='.$atts['id'].'.collect'.$mix), 1); break;
case 'artist': $data['music'] = json_decode(self::curl($api.'?id='.$atts['id'].'.artist'.$mix), 1); break;
case 'album': $data['music'] = json_decode(self::curl($api.'?id='.$atts['id'].'.album'.$mix), 1); break;
default: $data['music'] = json_decode(self::curl($api.'?id='.$atts['id'].'.song'.$mix), 1); break;
}
} else {
isset($atts['url']) ? $data['music']['url'] = $atts['url'] : 0;
Expand All @@ -61,8 +61,8 @@ function parseCallback($post, $config) {
isset($atts['lrc']) ? $data['music']['lrc'] = $atts['lrc'] : $data['showlrc'] = 0;
}
}
$data['showlrc'] = $atts['lrc']=='false' ? 0 : $data['showlrc'];
if ($data['music']) $js .= "\nAPlayerOptions.push(".json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT).");\n";
$data['showlrc'] = isset($atts['lrc']) && $atts['lrc']=='false' ? 0 : $data['showlrc'];
if ($data['music']) $js .= 'APlayerOptions.push('.json_encode($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);
Expand Down
10 changes: 5 additions & 5 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require '../../../zb_system/admin/admin_top.php';

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

if(empty($api)){
$zbp->ShowHint('bad', 'API 地址不允许为空!');
Expand Down Expand Up @@ -63,12 +63,12 @@
}
?>
<link rel="stylesheet" href="jcolor/jcolor.min.css" type="text/css" />
<style>table,td,th,tr,.api,tr.color1,tr.color2,tr.color3,tr.color4 { background: rgba(0,0,0,0)!important; border: 1px solid rgba(100,100,100,0.2)!important; }</style>
<style>table,td,th,tr,.api,tr.color1,tr.color2,tr.color3,tr.color4 { background: rgba(0,0,0,0)!important; border: 2px solid rgba(100,100,100,0.2)!important; }</style>
<script type="text/javascript" src="jcolor/jcolor.min.js"></script>
<!-- 背景图取自 pixiv,作品ID:62477678。 (https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62477678) -->
<div id="divMain" style="background: url(<?php echo $zbp->host; ?>zb_users/plugin/APlayer/bg.png) no-repeat right bottom;">
<div id="divMain" style="border-radius: 3px; padding: 10px; background: white url(<?php echo $zbp->host; ?>zb_users/plugin/APlayer/bg.png) no-repeat right bottom;">
<div class="divHeader"><a href="https://app.zblogcn.com/?id=1321" target="_blank">APlayer for Z-BlogPHP</a> - 插件配置</div>
<div id="divMain2" style="background: rgba(0,0,0,0);">
<div id="divMain2">
<form id="form1" name="form1" method="post">
<table width="90%" style='padding:0px;margin:0px;' cellspacing='0' cellpadding='0' class="tableBorder">
<tr>
Expand Down Expand Up @@ -158,7 +158,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.2</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.3</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.2</version>
<version>1.3</version>
<pubdate>2016-06-02</pubdate>
<modified>2017-04-20</modified>
<modified>2017-04-21</modified>
<price>0</price>
<phpver>5.2</phpver>
<advanced>
Expand Down

0 comments on commit 2d44210

Please sign in to comment.