forked from Jrohy/QPlayer-Typecho-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
177 lines (165 loc) · 6.45 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* 简洁美观非常Qの悬浮音乐播放器,MoLeft修复网易云解析接口
*
* @package QPlayer
* @author Jrohy,MoLeft
* @version 1.3.5.2
* @link http://www.moleft.cn
*/
class QPlayer_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Archive')->header = array('QPlayer_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('QPlayer_Plugin', 'footer');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){
$autoPlay = new Typecho_Widget_Helper_Form_Element_Radio(
'autoPlay', array('0'=> '关闭', '1'=> '开启'), 0, '自动播放',
'');
$form->addInput($autoPlay);
$rotate = new Typecho_Widget_Helper_Form_Element_Radio(
'rotate', array('0'=> '关闭', '1'=> '开启'), 0, '封面旋转',
'');
$form->addInput($rotate);
$color = new Typecho_Widget_Helper_Form_Element_Text('color', NULL, '', _t('自定义主色调'), _t('默认为<span style="color: #1abc9c;">#1abc9c</span>, 你可以自定义任何你喜欢的颜色作为播放器主色调。自定义主色调支持css的设置格式,如: `#233333`,"rgb(255,255,255)","rgba(255,255,255,1)","hsl(0, 0%, 100%)","hsla(0, 0%, 100%,1)"。填写其他错误的格式可能不会生效。'));
$form->addInput($color);
$css = new Typecho_Widget_Helper_Form_Element_Textarea('css', NULL, '', _t('自定义CSS'),'');
$form->addInput($css);
$js = new Typecho_Widget_Helper_Form_Element_Textarea('js', NULL,
'//改变列表的背景颜色(错开颜色)
function bgChange() {
var lis= $(".lib");
for(var i=0; i<lis.length; i+=2)
lis[i].style.background = "rgba(246, 246, 246, 0.5)";
}
window.onload = bgChange;
', _t('自定义JS'),'');
$form->addInput($js);
$musicList = new Typecho_Widget_Helper_Form_Element_Textarea('musicList', NULL,
'{
title:"感谢你曾来过",
artist:"周思涵",
mp3:"http://music.163.com/song/media/outer/url?id=460578140.mp3",
cover:"http://p2.music.126.net/iL36G-e6rm2zwCUmlL4pOw==/109951162859100521.jpg?param=106x106",
},
{
title:"绿色",
artist:"陈雪凝",
mp3:"http://music.163.com/song/media/outer/url?id=1345848098.mp3",
cover:"http://p1.music.126.net/R4ZP3AJ9xV0vvw8LX7AbMA==/109951163860425334.jpg?param=106x106",
},
',_t('歌曲列表'), _t('格式: {title:"xxx", artist:"xxx", cover:"http:xxxx", mp3:"http:xxxx"} ,每个歌曲之间用英文,隔开。请保证歌曲列表里至少有一首歌!<br><h4 style="margin-bottom:5px;margin-top:12px;">添加网易云音乐(需主机支持curl扩展)</h4><div style="background-color:#467b96;padding:5px 10px;max-width:109px;border-radius: 2px;"><a href="'.Helper::options()->pluginUrl.'/QPlayer/IDExplain.php" target="_blank" style="font-size:14px;color:#fff;outline:none;text-decoration:none;">网易云音乐id解析</a>
</div><p style="font-size: .92857em;color: #999; margin-top: 4px; margin-bottom:15px;">请自行去网易云音乐网页版获取音乐id(具体在每个音乐项目的网址最后会有个id)。<b style="color: #888;">将解析出的音乐链接复制到上面歌曲列表里(注意检查与现有歌曲是否用英文,隔开)。有版权的音乐无法解析!</b></p>'));
$form->addInput($musicList);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 输出头部css
*
* @access public
* @return void
*/
public static function header(){
$cssUrl = Helper::options()->pluginUrl . '/QPlayer/css/player.css';
echo '<link rel="stylesheet" href="' . $cssUrl . '">';
}
/**
* 输出底部
*
* @access public
* @return void
*/
public static function footer(){
$options = Typecho_Widget::widget('Widget_Options')->plugin('QPlayer');
echo '
<div id="QPlayer" style="z-index:2016">
<div id="pContent">
<div id="player">
<span class="cover"></span>
<div class="ctrl">
<div class="musicTag marquee">
<strong>Title</strong>
<span> - </span>
<span class="artist">Artist</span>
</div>
<div class="progress">
<div class="timer left">0:00</div>
<div class="contr">
<div class="rewind icon"></div>
<div class="playback icon"></div>
<div class="fastforward icon"></div>
</div>
<div class="right">
<div class="liebiao icon"></div>
</div>
</div>
</div>
</div>
<div class="ssBtn">
<div class="adf"></div>
</div>
</div>
<ol id="playlist"></ol>
</div>
';
if($options->color != '') {
echo '<style>
#pContent .ssBtn {
background-color:'.$options->color.';
}
#playlist li.playing, #playlist li:hover{
border-left-color:'.$options->color.';
}
</style>';
}
if($options->css != '') {
echo '<style>'.$options->css.'</style>' . "\n";
}
echo '<script src="'. Helper::options()->pluginUrl . '/QPlayer/js/jquery.min.js"></script>';
echo '
<script>
var autoplay = '.$options->autoPlay.';
var playlist = [
'.$options->musicList.'
];
var isRotate = '.$options->rotate.';
</script> ' . "\n";
echo '<script src="'.Helper::options()->pluginUrl . '/QPlayer/js/jquery.marquee.min.js"></script>' . "\n";
echo '<script src="'.Helper::options()->pluginUrl . '/QPlayer/js/player.js"></script>' . "\n";
if ($options->js != '') {
echo '<script>'.$options->js.'</script>' . "\n";
}
}
}