-
Notifications
You must be signed in to change notification settings - Fork 593
/
Plugin.php
93 lines (82 loc) · 2.61 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
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
*
*
* @package 畅言单点登录插件
* @author 泽泽社长
* @version 1.0.0
* @link https://zezeshe.com/archives/typecho-changyan-plugin.html
*/
class changyandandian_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Helper::addRoute("route_changyan","/changyan","changyandandian_Action",'action');
Helper::addRoute("route_changyanlogout","/changyan/logout","changyandandian_Action",'logout');
Typecho_Plugin::factory('Widget_Archive')->footer = array('changyandandian_Plugin', 'footer');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removeRoute("route_changyan");
Helper::removeRoute("route_changyanlogout");
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$set1 = new Typecho_Widget_Helper_Form_Element_Textarea('loginjsurl', NULL,$f, _t('网站登录地址'), _t('请在此处填写网站登录地址,不填则调用默认的typecho登录地址,如果您的主题用的是弹窗式的登录界面,您也可以在此写js代码调用出登录弹窗!'));
$form->addInput($set1);
}
public static function footer($obj)
{
$loginurl=Typecho_Widget::widget('Widget_Options')->adminUrl.'login.php';
$url=Helper::options()->Plugin('changyandandian')->loginjsurl;
if(empty($url)){
$url='window.location.href="'.$loginurl.'";';
}
elseif(strpos($url,'https://') !== false||strpos($url,'http://') !== false){
$url='window.location.href="'.$url.'";';
}
?>
<script>
function changyanlogin() {
<?php echo $url;?>
}
<?php
if (!Typecho_Widget::widget('Widget_User')->hasLogin()&&$_COOKIE["cyCookie"]){setcookie("cyCookie",''); echo 'if(localStorage.getItem("cy_lt")){localStorage.removeItem("cy_lt");window.location.reload();}';
}
?>
</script>
<?php
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){
}
}