-
Notifications
You must be signed in to change notification settings - Fork 592
/
Plugin.php
83 lines (78 loc) · 2.43 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
<?php
/**
* 把外部链接转换为 your_blog_path/go/key/<br>
* 通过菜单“撰写->链接转换”设置
*
* @package 链接转换 GoLinks
* @author DEFE
* @version 0.3.0
* @link http://defe.me
*/
class GoLinks_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
$db = Typecho_Db::get();
$golinks = $db->getPrefix() . 'golinks';
$adapter = $db->getAdapterName();
if("Pdo_SQLite" === $adapter || "SQLite" === $adapter){
$db->query(" CREATE TABLE IF NOT EXISTS ". $golinks ." (
id INTEGER PRIMARY KEY,
key TEXT,
target TEXT,
count NUMERIC)");
}
if("Pdo_Mysql" === $adapter || "Mysql" === $adapter){
$db->query("CREATE TABLE IF NOT EXISTS ". $golinks ." (
`id` int(8) NOT NULL AUTO_INCREMENT,
`key` varchar(32) NOT NULL,
`target` varchar(10000) NOT NULL,
`count` int(8) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");
}
Helper::addAction('golinks', 'GoLinks_Action');
Helper::addRoute('go', '/go/[key]/', 'GoLinks_Action', 'golink');
Helper::addPanel(2, 'GoLinks/panel.php', '链接转换', '链接转换管理', 'administrator');
return('数据表 '.$golinks.' 创建成功, 插件已经成功激活!');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removeRoute('go');
Helper::removeAction('golinks');
Helper::removePanel(2, 'GoLinks/panel.php');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
}