This repository was archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
127 lines (114 loc) · 3.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
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
<?php
/**
* 显示评论者的UserAgent
*
* @package UserAgent
* @author Jimmy Ho
* @version 1.1.0
* @link https://blog.jimmyho.net/
*/
class UserAgent_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate(){}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
/** user agent icons **/
$icons = new Typecho_Widget_Helper_Form_Element_Radio( 'icons', array(
'16' => '16px',
'24' => '24px'),
'16', _t('选择图标尺寸'), _t('') );
$form->addInput($icons->multiMode());
/** user agent show **/
$show = new Typecho_Widget_Helper_Form_Element_Radio( 'show', array(
'1' => '只显示图标',
'2' => '只显示文字',
'3' => '显示图标和文字'),
'1', _t('选择显示的内容'), _t('') );
$form->addInput($show->multiMode());
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 插件实现方法
*
* @access public
* @return void
*/
public static function render($agent)
{
$options = Typecho_Widget::widget('Widget_Options');
$url_plugin = $options->pluginUrl . '/UserAgent/';
global $url_img, $icons;
$url_img = $url_plugin."img/";
$icons = Typecho_Widget::widget('Widget_Options')->plugin('UserAgent')->icons;
$show = Typecho_Widget::widget('Widget_Options')->plugin('UserAgent')->show;
require_once 'useragent-os.php';
$os = detect_os($agent);
$os_img = self::img($os['code'],"/os/",$os['title']);
$os_title = $os['title'];
require_once 'useragent-webbrowser.php';
$wb = detect_webbrowser($agent);
$wb_img = self::img($wb['code'],"/net/",$wb['title']);
$wb_title = $wb['title'];
switch($show){
case 1:
$ua = $os_img." | ".$wb_img;
break;
case 2:
$ua = $os_title." | ".$wb_title;
break;
case 3:
$ua = $os_img." ".$os_title." | ".$wb_img." ".$wb_title;
break;
default :
$ua = $os_img." | ".$wb_img;
break;
}
echo $ua;
}
/**
* 图标输出
*
* @access public
* @return void
*/
public static function img($code, $type, $title)
{
global $icons, $url_img;
//默认16px
if ($icons == "") {
$icons = 16;
}
$img = "<img src='".$url_img.$icons.$type.$code.".png' title='".$title."' alt='".$title."' height='".$icons."' width='".$icons."' />";
return $img;
}
}