forked from Moidea/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
executable file
·92 lines (81 loc) · 2.66 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
<?php ! defined('__TYPECHO_ROOT_DIR__') and exit();
/**
* Typecho 应用商店
*
* @package AppStore
* @author chekun
* @version 1.2.0
* @link http://typecho.dilicms.com
*/
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);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
}