forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
145 lines (131 loc) · 6.88 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* SlimBox2 精致小巧的灯箱效果,需jQuery的支持。
*
* @package SlimBox2
* @author Ryan, 冰剑
* @version 1.0.7
* @link http://www.binjoo.net/
*/
class SlimBox2_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate() {
Typecho_Plugin::factory('Widget_Archive')->header = array('SlimBox2_Plugin', 'headlink');
Typecho_Plugin::factory('Widget_Archive')->footer = array('SlimBox2_Plugin', 'footlink');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @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){
$selectImg = new Typecho_Widget_Helper_Form_Element_Text('selectImg',NULL,'.post-content img','范围选择器', '根据你所使用的主题而修改,一般只需修改.entry_content部分即可。');
$form->addInput($selectImg);
$overlayOpacity = new Typecho_Widget_Helper_Form_Element_Text('overlayOpacity',NULL,'0.75','遮罩层透明度', '默认为0.75,1 为不透明,0 为完全透明。');
$overlayOpacity->input->setAttribute('class', 'mini');
$form->addInput($overlayOpacity->addRule('isInteger','请输入0-1之间的数字,推荐默认0.75。')->addRule('required', '请设置遮罩层透明度,推荐默认0.75。'));
$overlayFadeDuration = new Typecho_Widget_Helper_Form_Element_Text('overlayFadeDuration',NULL,'400','遮罩层隐现速度', '单位为毫秒,默认为400,禁用动画效果为1。');
$overlayFadeDuration->input->setAttribute('class', 'mini');
$form->addInput($overlayFadeDuration->addRule('isInteger','请输入数字,推荐默认400毫秒。')->addRule('required', '请设置遮罩层隐现速度,推荐默认400毫秒。'));
$resizeDuration = new Typecho_Widget_Helper_Form_Element_Text('resizeDuration',NULL,'250','灯箱大小变化速度', '单位为毫秒,默认为250,禁用动画效果为1。');
$resizeDuration->input->setAttribute('class', 'mini');
$form->addInput($resizeDuration->addRule('isInteger','请输入数字,推荐默认250毫秒。')->addRule('required', '请设置灯箱大小变化速度,推荐默认250毫秒。'));
$imageFadeDuration = new Typecho_Widget_Helper_Form_Element_Text('imageFadeDuration',NULL,'300','图片滑出速度', '单位为毫秒,默认为300,禁用动画效果为1。');
$imageFadeDuration->input->setAttribute('class', 'mini');
$form->addInput($imageFadeDuration->addRule('isInteger','请输入数字,推荐默认300毫秒。')->addRule('required', '请设置图片滑出速度,推荐默认300毫秒。'));
$title = new Typecho_Widget_Helper_Form_Element_Radio('title',
array('true' => '显示',
'false' => '隐藏'),
'true', '标题栏','隐藏后将不会显示标题、计数器、CLOSE关闭按钮。');
$form->addInput($title);
$captionAnimationDuration = new Typecho_Widget_Helper_Form_Element_Text('captionAnimationDuration',NULL,'200','标题栏滑出速度', '单位为毫秒,默认为200,禁用动画效果为1,标题栏隐藏后此设置失去效果。');
$captionAnimationDuration->input->setAttribute('class', 'mini');
$form->addInput($captionAnimationDuration->addRule('isInteger','请输入数字,推荐默认200毫秒。')->addRule('required', '请输入数字,推荐默认200毫秒。'));
$loop = new Typecho_Widget_Helper_Form_Element_Radio('loop',
array('true' => '是',
'false' => '否'),
'false', '图片循环','浏览至页面中第一张或最后一张图片时,是否可以循环。');
$form->addInput($loop);
$counterText = new Typecho_Widget_Helper_Form_Element_Text('counterText',NULL,'Image {x} of {y}','计数器提示', '<b>{x}</b>为当前图片索引,<b>{y}</b>为当前页面总图片数。<br />填写 <b>false</b> 是关闭此功能,不显示任何计数。');
$form->addInput($counterText->addRule('required', '如果你不知道写什么,建议填写默认的:Image {x} of {y}。'));
$jquerySelect= new Typecho_Widget_Helper_Form_Element_Radio('jquerySelect',
array('true' => '是',
'false' => '否'),
'false', '加载jQuery库','如果主题本身已经引用了jQuery库,那么请无视此选项。');
$form->addInput($jquerySelect);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 头部样式
*
* @access public
* @param unknown $headlink
* @return unknown
*/
public static function headlink($cssUrl) {
$Options = Helper::options();
$Settings = $Options->plugin('SlimBox2');
//$Archive = Typecho_Widget::widget('Widget_Archive');
$SlimBox2_url = $Options->pluginUrl .'/SlimBox2/';
$links = '<link rel="stylesheet" type="text/css" href="'.$SlimBox2_url.'css/slimbox2.css" />
';
if($Settings->jquerySelect != "false"){
$links .= '<script type="text/javascript" src="http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
';
}
echo $links;
}
/**
* 底部脚本
*
* @access public
* @param unknown $footlink
* @return unknown
*/
public static function footlink($links) {
$Settings = Helper::options()->plugin('SlimBox2');
$SlimBox2_url = Helper::options()->pluginUrl .'/SlimBox2/';
$links= '<script type="text/javascript" src="'.$SlimBox2_url.'js/slimbox2.js"></script>';
$links.= '<script type="text/javascript" id="slimbox">';
$links.= 'jQuery(function($) {
$("'.$Settings->selectImg.'").slimbox({
overlayOpacity: '.$Settings->overlayOpacity.',
overlayFadeDuration: '.$Settings->overlayFadeDuration.',
resizeDuration: '.$Settings->resizeDuration.',
imageFadeDuration: '.$Settings->imageFadeDuration.',
captionAnimationDuration: '.$Settings->captionAnimationDuration.',
loop:'.$Settings->loop.',
counterText:"'.$Settings->counterText.'",
showTitle: "'.$Settings->title.'"
});
});';
$links.= '</script>';
echo $links;
}
}