-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.php
247 lines (212 loc) · 11.1 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* AdminMD是一款基于Material Design设计的typecho后台美化插件
* <hr><a style="width:fit-content" id="AdminMD">版本检测中... </div>
* <script>var simversion="1.8.1";function update_detec(){var container=document.getElementById("AdminMD");if(!container){return}var ajax=new XMLHttpRequest();container.style.display="block";ajax.open("get","https://api.github.com/repos/ouyangyanhuo/AdminMD/releases/latest");ajax.send();ajax.onreadystatechange=function(){if(ajax.readyState===4&&ajax.status===200){var obj=JSON.parse(ajax.responseText);var newest=obj.tag_name;if(newest>simversion){container.innerHTML="发现新主题版本:"+obj.name+'。下载地址:<a href="'+obj.zipball_url+'">点击下载</a>'+"<br>您目前的版本:"+String(simversion)+"。"+'<a target="_blank" href="'+obj.html_url+'">👉查看新版亮点</a>'}else{container.innerHTML="您目前的版本:"+String(simversion)+"。"+"您目前使用的是最新版。"}}}};update_detec();</script>
*
* @package AdminMD
* @author Magneto
* @version 1.8.2_Alpha
* @link https://www.fmcf.cc
*/
class AdminMD_Plugin implements Typecho_Plugin_Interface
{
public static $file_map = [];
/**
* @return array
*/
public static function getFileMap()
{
return self::$file_map;
}
/**
* @param array $file_map
*/
public static function setFileMap($file_map)
{
self::$file_map = $file_map;
}
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
$plugin_path = dirname(__FILE__);
Typecho_Plugin::factory('admin/header.php')->header_2000 = array('AdminMD_Plugin', 'renderHeader');
Typecho_Plugin::factory('admin/footer.php')->end_2000 = array('AdminMD_Plugin', 'renderFooter');
if(file_exists("var/Widget/Menu.php")){
//挂载menu.php
rename("var/Widget/Menu.php", "var/Widget/Menu.php.bak");
copy("usr/plugins/AdminMD/var/Widget/Menu.php", "var/Widget/Menu.php");
}
$admin_files = self::readdir($plugin_path.'/admin/');
self::setFileMap($admin_files);
foreach ($admin_files as $tmp_file){
$tmp_file_path = "usr/plugins/AdminMD/admin/".$tmp_file;
$target_file_path = "admin/".$tmp_file;
$target_file_bak = "admin/".$tmp_file.".bak";
if(file_exists($target_file_path)){
//挂载
rename($target_file_path, $target_file_bak);
copy($tmp_file_path, $target_file_path);
}
}
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
//还原Menu.php
if(file_exists("var/Widget/Menu.php.bak")){
unlink("var/Widget/Menu.php");
rename("var/Widget/Menu.php.bak", "var/Widget/Menu.php");
}
$plugin_path = dirname(__FILE__);
$admin_files = self::readdir($plugin_path.'/admin/');
foreach ($admin_files as $tmp_file){
$target_file_path = "admin/".$tmp_file;
$target_file_bak = "admin/".$tmp_file.".bak";
if(file_exists($target_file_bak)){
unlink($target_file_path);
rename($target_file_bak, $target_file_path);
}
}
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
?>
<link rel="stylesheet" href="<?php Helper::options()->pluginUrl(); ?>/AdminMD/assets/login.css">
<?php
$TheNotice = new Typecho_Widget_Helper_Form_Element_Text('TheNotice', NULL, NULL, _t('<h2>基础外观</h2>'));
$TheNotice->input->setAttribute('style', 'display:none');
$form->addInput($TheNotice);
$url = Helper::options()->pluginUrl . '/AdminMD/';
$zz1 = '<div class="zz">绿色[你的名字]</div>';
$zz2 = '<div class="zz">蓝天和远山[网络]</div>';
$zz3 = '<div class="zz">后花园[Pixiv 95741043]</div>';
$zz4 = '<div class="zz">枫[Pixiv 66986409]</div>';
$zz5 = '<div class="zz">Default</div>';
$bgfengge = new Typecho_Widget_Helper_Form_Element_Radio(
'bgfengge', array(
'Green' => _t('<div class="kuai"><img src="http://p5.qhimg.com/bdm/960_593_0/t01573b4f467fdf51e2.jpg" loading="lazy">' . $zz1 . '</div>'),
'BlueSkyAndMountains' => _t('<div class="kuai"><img src="https://cdn.jsdelivr.net/gh/fyhgay/CDNS@latest/2021/07/15/0531f7895a5627b8737e0690d7dcb4e5.png" loading="lazy">' . $zz2 . '</div>'),
'Back_garden' => _t('<div class="kuai"><img src="https://tva4.sinaimg.cn/large/008aATBzly8gze1cpfkuuj31i00u0k56.jpg" loading="lazy">' . $zz3 . '</div>'),
'Maple' => _t('<div class="kuai"><img src="https://tva4.sinaimg.cn/large/008aATBzly1h07hmpmbj5j30yq0g6dvm.jpg" loading="lazy">' . $zz4 . '</div>'),
'Default' => _t('<div class="kuai"><img src="https://fastly.jsdelivr.net/gh/fyhgay/CDNS@latest/2021/07/15/05b54e433729eb89a067ff992176c442.png" loading="lazy">' . $zz5 . '</div>'),
), 'Green', _t('登陆/注册页面样式'), _t(''));
$bgfengge->setAttribute('id', 'yangshi');
$form->addInput($bgfengge);
$bgUrl = new Typecho_Widget_Helper_Form_Element_Text('bgUrl', NULL, NULL, _t('自定义背景图'), _t('选中上方的基础样式后,可以在这里填写图片地址自定义背景图'));
$form->addInput($bgUrl);
$diycss = new Typecho_Widget_Helper_Form_Element_Textarea('diycss', NULL, NULL, '自定义样式', _t('上边的样式选择【Default】,然后在这里自己写css美化注册/登录页面;<b>注意</b>:该功能与【自定义背景图】功能冲突,使用该功能时如果想设置背景图请写css里面。'));
$form->addInput($diycss);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form)
{
}
/**
*
* 函数名:readdir($dir)
* 作用:读取目录所有的文件名
* 参数:$dir 目录地址
* 返回值:文件名数组
*
* */
public static function readdir($dir) {
$handle=opendir($dir);
$i=0;
while(!!$file = readdir($handle)) {
if (($file!=".")and($file!="..")) {
$list[$i]=$file;
$i=$i+1;
}
}
closedir($handle);
return $list;
}
/**
* 插件实现方法
*
* @access public
* @return string
*/
public static function renderHeader($hed)
{
$options = Helper::options();
$url = $options->pluginUrl . '/AdminMD/';
list($prefixVersion, $suffixVersion) = explode('/', $options->version);
if (!Typecho_Widget::widget('Widget_User')->hasLogin()) {
$skin = Typecho_Widget::widget('Widget_Options')->plugin('AdminMD')->bgfengge;
$diycss = Typecho_Widget::widget('Widget_Options')->plugin('AdminMD')->diycss;
if ($skin == 'kongbai') {
$hed = $hed . '<style>' . $diycss . '</style>';
} else {
if ($skin == 'heike') {
$hed = $hed . '<link rel="stylesheet" href="' . $url . 'assets/skin/' . $skin . '.css?' . $suffixVersion.'">';
} else {
$bgUrl = Typecho_Widget::widget('Widget_Options')->plugin('AdminMD')->bgUrl;
$zidingyi = "";
if ($bgUrl) {
$zidingyi = "<style>body{background-image: url(" . $bgUrl . ");}</style>";
}
$hed = $hed . '<link rel="stylesheet" href="' . $url . 'assets/skin/' . $skin . '.css?' . $suffixVersion.'">' . $zidingyi;
}
}
echo $hed;
}else{
/* 添加 Material Design style */
$hed = $hed . '<link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/css/style.min.css">';
$hed = $hed.'<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/MaterialDesign-Webfont/6.6.96/css/materialdesignicons.min.css">';
$hed = $hed.'<link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/vendors/css/vendor.bundle.base.css?">';
$hed = $hed.'<script src="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/vendors/js/vendor.bundle.base.js"></script>';
$hed = $hed.'<script src="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/js/off-canvas.js"></script>';
$hed = $hed.'<script src="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/js/hoverable-collapse.js"></script>';
}
return $hed;
}
public static function renderFooter()
{
$options = Helper::options();
$url = $options->pluginUrl . '/AdminMD/';
list($prefixVersion, $suffixVersion) = explode('/', $options->version);
if (!Typecho_Widget::widget('Widget_User')->hasLogin()) {
$url = Helper::options()->pluginUrl . '/AdminMD/';
$skin = Typecho_Widget::widget('Widget_Options')->plugin('AdminMD')->bgfengge;
$ft = '';
if ($skin == 'heike') {
$ft = '<canvas id="canvas"></canvas><script type="text/javascript">window.onload=function(){var canvas=document.getElementById("canvas");var context=canvas.getContext("2d");var W=window.innerWidth;var H=window.innerHeight;canvas.width=W;canvas.height=H;var fontSize=16;var colunms=Math.floor(W/fontSize);var drops=[];for(var i=0;i<colunms;i++){drops.push(0)}var str="111001101000100010010001111001111000100010110001111001001011110110100000";function draw(){context.fillStyle="rgba(0,0,0,0.05)";context.fillRect(0,0,W,H);context.font="700 "+fontSize+"px 微软雅黑";context.fillStyle="#00cc33";for(var i=0;i<colunms;i++){var index=Math.floor(Math.random()*str.length);var x=i*fontSize;var y=drops[i]*fontSize;context.fillText(str[index],x,y);if(y>=canvas.height&&Math.random()>0.99){drops[i]=0}drops[i]++}}function randColor(){var r=Math.floor(Math.random()*256);var g=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);return"rgb("+r+","+g+","+b+")"}draw();setInterval(draw,30)};</script>';
}
if ($skin == 'lv') {
$ft = '<ul class="bg-bubbles"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>';
}
echo $ft;
}else{
echo '<script src="https://fastly.jsdelivr.net/gh/ouyangyanhuo/[email protected]/assets/js/misc.js"></script>';
}
}
}