|
|
<?php
|
|
|
/*
|
|
|
Plugin Name: NiCa音乐插件
|
|
|
Plugin URI:
|
|
|
Description: 小白写的音乐插件,通过Meting开发
|
|
|
Version: 2.1
|
|
|
Author: NiCa
|
|
|
Author URI: http://blog.liutao.love
|
|
|
*/
|
|
|
|
|
|
define('max_music', plugin_dir_url(__FILE__) . 'assets/');//资源目录
|
|
|
|
|
|
//添加样式(初始化)
|
|
|
function max_music_style()
|
|
|
{
|
|
|
wp_enqueue_style('APlayer.css', max_music . "css/APlayer.min.css");//css
|
|
|
}
|
|
|
|
|
|
function max_music_script()
|
|
|
{
|
|
|
wp_enqueue_script('APlayer.js', max_music . 'js/APlayer.min.js');
|
|
|
wp_enqueue_script('Meting.js', max_music . 'js/Meting.js');
|
|
|
}
|
|
|
|
|
|
//在头部引入脚本
|
|
|
add_action('wp_head', 'max_music_style');
|
|
|
add_action('wp_footer', 'max_music_script');
|
|
|
// 创建自定义插件设置菜单
|
|
|
add_action('admin_menu', 'max_music_create_menu');
|
|
|
|
|
|
function max_music_create_menu()
|
|
|
{
|
|
|
// 创建新的顶级菜单
|
|
|
add_menu_page('Max音乐插件', 'Max音乐插件', 'administrator', 'Max_music', 'guide_view', '');
|
|
|
// 调用注册设置函数
|
|
|
add_action('admin_init', 'register_settings');
|
|
|
}
|
|
|
|
|
|
function register_settings()
|
|
|
{
|
|
|
// 注册我们的设置
|
|
|
register_setting('max_music-settings-group', 'max_music_api_url');
|
|
|
register_setting('max_music-settings-group', 'max_music_server');
|
|
|
register_setting('max_music-settings-group', 'max_music_type');
|
|
|
register_setting('max_music-settings-group', 'max_music_lrctype');
|
|
|
register_setting('max_music-settings-group', 'max_music_id');
|
|
|
register_setting('max_music-settings-group', 'max_music_mini');
|
|
|
register_setting('max_music-settings-group', 'max_music_fixed');
|
|
|
register_setting('max_music-settings-group', 'max_music_volume');
|
|
|
register_setting('max_music-settings-group', 'max_music_autoplay');
|
|
|
register_setting('max_music-settings-group', 'max_music_loop');
|
|
|
register_setting('max_music-settings-group', 'max_music_order');
|
|
|
register_setting('max_music-settings-group', 'max_music_player_position');
|
|
|
}
|
|
|
|
|
|
function guide_view()
|
|
|
{
|
|
|
?>
|
|
|
<div class="wrap">
|
|
|
<h2>歌曲/歌单设置</h2>
|
|
|
|
|
|
<form method="post" action="options.php">
|
|
|
<?php
|
|
|
settings_fields('max_music-settings-group'); // 设置字段 这个函数取代了 nonce magic, action field, and page_options
|
|
|
do_settings_sections('max_music-settings-group'); // 这个函数取代了表单字段标记形式本身
|
|
|
$API = esc_attr(get_option('max_music_api_url')) ?:"https://www.liutao.love/api/meting/";
|
|
|
$server = esc_attr(get_option('max_music_server'));
|
|
|
$type = esc_attr(get_option('max_music_type'));
|
|
|
$ID = esc_attr(get_option('max_music_id'));
|
|
|
$lrc = esc_attr(get_option('max_music_lrctype'));
|
|
|
$mini = esc_attr(get_option('max_music_mini'));
|
|
|
$volume = esc_attr(get_option('max_music_volume'));
|
|
|
$fixed = esc_attr(get_option('max_music_fixed'));
|
|
|
$loop = esc_attr(get_option('max_music_loop'));
|
|
|
$autoplay = esc_attr(get_option('max_music_autoplay'));
|
|
|
$order = esc_attr(get_option('max_music_order'));
|
|
|
$PlayerOosition = esc_attr(get_option('max_music_player_position'));
|
|
|
?>
|
|
|
<table class="form-table">
|
|
|
<tr valign="top">
|
|
|
<th scope="row">音乐API</th>
|
|
|
<td><input type="text" name="max_music_api_url" value="<?php echo $API ?>"/></td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">歌单渠道</th>
|
|
|
<td>
|
|
|
<select name="max_music_server" value="<?php echo $server ?>">
|
|
|
<option value="netease" <?php if ($server == "netease") echo 'selected'; ?>>网易云</option>
|
|
|
<option value="tencent" <?php if ($server == "tencent") echo 'selected'; ?>>QQ音乐</option>
|
|
|
<option value="kugou" <?php if ($server == "kugou") echo 'selected'; ?>>酷狗音乐</option>
|
|
|
<option value="xiami" <?php if ($server == "xiami") echo 'selected'; ?>>小米音乐</option>
|
|
|
<option value="baidu" <?php if ($server == "baidu") echo 'selected'; ?>>百度音乐</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">播放模式</th>
|
|
|
<td>
|
|
|
<select name="max_music_type" value="<?php echo $type ?>">
|
|
|
<option value="playlist" <?php if ($type == "playlist") echo 'selected'; ?>>歌单</option>
|
|
|
<option value="song" <?php if ($type == "song") echo 'selected'; ?>>单曲</option>
|
|
|
<option value="album" <?php if ($type == "album") echo 'selected'; ?>>专辑</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">ID</th>
|
|
|
<td><input type="text" name="max_music_id" value="<?php echo $ID ?>"/></td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">歌词</th>
|
|
|
<td>
|
|
|
<select name="max_music_lrctype" value="<?php echo $lrc ?>">
|
|
|
<option value="0" <?php if ($lrc == "0") echo 'selected'; ?>>开启</option>
|
|
|
<option value="2" <?php if ($lrc == "2") echo 'selected'; ?>>关闭</option>
|
|
|
<option value="3" <?php if ($lrc == "3") echo 'selected'; ?>>在播放器上显示</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">迷你模式</th>
|
|
|
<td>
|
|
|
<select name="max_music_mini" value="<?php echo $mini ?>">
|
|
|
<option value="true" <?php if ($mini) echo 'selected' ?>>开启</option>
|
|
|
<option value="false"<?php if (!$mini) echo 'selected' ?>>关闭</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">音量<span id="volume"></span></th>
|
|
|
<td><input type="range" max="1" min="0" name="max_music_volume" step="0.01"
|
|
|
value="<?php echo $volume ?>"
|
|
|
onchange="document.getElementById('volume').textContent = ':' + this.value*100 + '%';"/>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">固定底部</th>
|
|
|
<td>
|
|
|
<select name="max_music_fixed" value="<?php echo $fixed ?>">
|
|
|
<option value="true" <?php if ($fixed == "true") echo 'selected' ?>>开启</option>
|
|
|
<option value="false"
|
|
|
"<?php if ($fixed == "false") echo 'selected' ?>>关闭</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">循环模式</th>
|
|
|
<td>
|
|
|
<select name="max_music_loop" value="<?php echo $loop ?>">
|
|
|
<option value="all" <?php if ($loop == "all") echo 'selected' ?>>播放所有</option>
|
|
|
<option value="one" <?php if ($loop == "one") echo 'selected' ?>>单曲循环</option>
|
|
|
<option value="none" <?php if ($loop == "none") echo 'selected' ?>>不循环</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">自动播放</th>
|
|
|
<td>
|
|
|
<select name="max_music_autoplay" value="<?php echo $autoplay ?>">
|
|
|
<option value="true" <?php if ($autoplay == "true") echo 'selected' ?>>开启</option>
|
|
|
<option value="false" <?php if ($autoplay == "false") echo 'selected' ?>>关闭</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">播放顺序</th>
|
|
|
<td>
|
|
|
<select name="max_music_order" value="<?php echo $order ?>">
|
|
|
<option value="list" <?php if ($order == "list") echo 'selected' ?>>列表播放</option>
|
|
|
<option value="random" <?php if ($order == "random") echo 'selected' ?>>随机播放</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr valign="top">
|
|
|
<th scope="row">播放器位置</th>
|
|
|
<td>
|
|
|
<select name="max_music_player_position" value="<?php echo $PlayerOosition ?>">
|
|
|
<option value="wp_head" <?php if ($PlayerOosition == "wp_head") echo 'selected' ?>>
|
|
|
页头(wp_head)
|
|
|
</option>
|
|
|
<option value="wp_sidebar" <?php if ($PlayerOosition == "wp_sidebar") echo 'selected' ?>>
|
|
|
侧边栏(wp_sidebar)
|
|
|
</option>
|
|
|
<option value="wp_footer" <?php if ($PlayerOosition == "wp_footer") echo 'selected' ?>>
|
|
|
页脚(wp_footer)
|
|
|
</option>
|
|
|
</select>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</table>
|
|
|
<?php submit_button(); ?>
|
|
|
</form>
|
|
|
</div>
|
|
|
<?php
|
|
|
}
|
|
|
function meting_api()
|
|
|
{
|
|
|
?>
|
|
|
<script>
|
|
|
var meting_api='<?php echo esc_attr(get_option('max_music_api_url'));?>?server=:server&type=:type&id=:id&auth=:auth&r=:r';
|
|
|
</script>
|
|
|
<?php
|
|
|
}
|
|
|
add_action('wp_head', 'meting_api');
|
|
|
function meting()
|
|
|
{
|
|
|
?>
|
|
|
<meting-js
|
|
|
server="<?php echo esc_attr(get_option('max_music_server')); ?>"
|
|
|
type="<?php echo esc_attr(get_option('max_music_type')); ?>"
|
|
|
id="<?php echo esc_attr(get_option('max_music_id')); ?>"
|
|
|
mini="<?php echo esc_attr(get_option('max_music_mini')); ?>"
|
|
|
fixed="<?php echo esc_attr(get_option('max_music_fixed')); ?>"
|
|
|
volume="<?php echo esc_attr(get_option('max_music_volume')); ?>"
|
|
|
autoplay="<?php echo esc_attr(get_option('max_music_autoplay')); ?>"
|
|
|
loop="<?php echo esc_attr(get_option('max_music_loop')); ?>"
|
|
|
order="<?php echo esc_attr(get_option('max_music_order')); ?>"
|
|
|
lrcType="<?php echo esc_attr(get_option('max_music_lrctype')); ?>"></meting-js>
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
add_action(get_option('max_music_player_position'), 'meting');
|
|
|
|
|
|
function meting_shortcode($atts)
|
|
|
{
|
|
|
$server = $atts['server'];
|
|
|
$type = $atts['type'];
|
|
|
$ID = $atts['id'];
|
|
|
$lrc = $atts['lrc'];
|
|
|
$mini = $atts['mini'];
|
|
|
$volume = $atts['volume'];
|
|
|
$fixed = $atts['fixed'];
|
|
|
$loop = $atts['loop'];
|
|
|
$autoplay = $atts['autoplay'];
|
|
|
$order = $atts['order'];
|
|
|
|
|
|
return "<meting-js
|
|
|
server=".$server."
|
|
|
type=".$type."
|
|
|
id=".$ID."
|
|
|
mini=".$mini."
|
|
|
fixed=".$fixed."
|
|
|
volume=".$volume / 100 ."
|
|
|
autoplay=".$autoplay."
|
|
|
loop=".$loop."
|
|
|
order=".$order."
|
|
|
lrcType=".$lrc."></meting-js>";
|
|
|
}
|
|
|
add_shortcode('MetingShortCode', 'meting_shortcode');
|
|
|
|
|
|
?>
|