This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Plugin.php
executable file
·107 lines (96 loc) · 3.23 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
<?php ! defined('__TYPECHO_ROOT_DIR__') and exit();
/**
* Typecho 应用商店
*
* @package AppStore
* @author chekun
* @version 2.0.0
* @link https://typecho.chekun.me
*/
class AppStore_Plugin implements Typecho_Plugin_Interface
{
/**
* 插件下载临时目录
*
* @var string
*/
public static $tempPath = '/.app_store/';
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
//检查是否有curl扩展
if (! extension_loaded('curl')) {
throw new Typecho_Plugin_Exception('缺少curl扩展支持.');
}
//创建下载临时目录
$tempDir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.self::$tempPath;
! file_exists($tempDir) and ! @mkdir($tempDir);
//创建菜单和路由
Helper::addPanel(1, 'AppStore/market.php', '应用商店', '应用商店', 'administrator');
Helper::addRoute('app.store.market', __TYPECHO_ADMIN_DIR__.'app-store/market', 'AppStore_Action', 'market');
Helper::addRoute('app.store.install', __TYPECHO_ADMIN_DIR__.'app-store/install', 'AppStore_Action', 'install');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
include 'helpers/helpers.php';
//删除下载临时目录
$tempDir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.self::$tempPath;
if (file_exists($tempDir) and (! delete_files($tempDir) or !@rmdir($tempDir))) {
throw new Typecho_Plugin_Exception('无法删除插件下载临时目录.');
}
//移除菜单和路由
Helper::removePanel(1, 'AppStore/market.php');
Helper::removeRoute('app.store.market');
Helper::removeRoute('app.store.install');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
/** 应用服务器地址 */
$name = new Typecho_Widget_Helper_Form_Element_Text(
'server',
NULL,
'https://typecho.chekun.me/',
_t('应用服务器地址'),
'参与服务端开发的小伙伴可以通过设置此处调试,普通的小伙伴默认就好,😄'
);
$form->addInput($name);
/** 下载插件方法 */
$http = new Typecho_Widget_Helper_Form_Element_Select(
'http',
['curl' => 'curl', 'file_get_contents' => 'file_get_contents'],
'curl',
_t('下载插件方法'),
'不能正常显示插件列表/下载插件的小伙伴可以设置为file_get_contents方式'
);
$form->addInput($http);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
}