forked from MoLeft/ArticlePoster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
192 lines (172 loc) · 5.97 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* 为文章生成海报,原作者 MoLeft:http://www.moleft.cn/,本插件由浅梦修改
*
* @package ArticlePoster
* @author MoLeft
* @author 浅梦
* @version 1.1.0
* @link https://letanml.xyz/
*/
class ArticlePoster_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*/
public static function activate()
{
// 检查GD库是否启用
if (!extension_loaded('gd')) {
throw new Exception('插件激活失败,因为GD库没有启用');
}
Helper::addRoute('ArticlePosterAction_make', '/ArticlePoster/make', 'ArticlePoster_Action', 'make');
Typecho_Plugin::factory('Widget_Archive')->header = array('ArticlePoster_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('ArticlePoster_Plugin', 'footer');
return '插件已激活,请设置相关信息';
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*/
public static function deactivate()
{
Helper::removeRoute('ArticlePosterAction_make');
return '插件已禁用';
}
/**
* 获取插件配置面板
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$options = Helper::options();
$sitename = new Typecho_Widget_Helper_Form_Element_Text(
'sitename',
null,
$options->title,
_t('网站名称'),
_t('请填写网站名称,避免海报排版错误请控制长度')
);
$form->addInput($sitename);
$siteNameSize = new Typecho_Widget_Helper_Form_Element_Text(
'siteNameSize',
null,
30,
_t('网站名称字体大小'),
_t('请填写网站名称字体大小,过大会导致排版错误')
);
$form->addInput($siteNameSize);
$introduction = new Typecho_Widget_Helper_Form_Element_Text(
'introduction',
null,
$options->description,
_t('网站介绍'),
_t('请填写网站介绍,避免海报排版错误请控制长度')
);
$form->addInput($introduction);
$introductionSize = new Typecho_Widget_Helper_Form_Element_Text(
'introductionSize',
null,
15,
_t('网站介绍字体大小'),
_t('请填写网站介绍字体大小,过大会导致排版错误')
);
$form->addInput($introductionSize);
$author = new Typecho_Widget_Helper_Form_Element_Text(
'author',
null,
'',
_t('博主名称'),
_t('请填写博主名称')
);
$form->addInput($author);
$authorSize = new Typecho_Widget_Helper_Form_Element_Text(
'authorSize',
null,
17,
_t('博主名称字体大小'),
_t('请填写博主名称字体大小,过大会导致排版错误')
);
$form->addInput($authorSize);
$qq = new Typecho_Widget_Helper_Form_Element_Text(
'qq',
null,
'',
_t('博主扣扣'),
_t('请填写博主扣扣,以显示头像')
);
$form->addInput($qq);
$content = new Typecho_Widget_Helper_Form_Element_Text(
'content',
null,
'',
_t('自定义摘要字段'),
_t('请填写自定义摘要字段,留空则使用文章摘要)')
);
$form->addInput($content);
$contentSize = new Typecho_Widget_Helper_Form_Element_Text(
'contentSize',
null,
15,
_t('自定义摘要字段字体大小'),
_t('请填写自定义摘要字段字体大小,过大会导致排版错误')
);
$form->addInput($contentSize);
$titleSize = new Typecho_Widget_Helper_Form_Element_Text(
'titleSize',
null,
30,
_t('文章标题字体大小'),
_t('请填写文章标题字体大小,过大会导致排版错误')
);
$form->addInput($titleSize);
$headimage = new Typecho_Widget_Helper_Form_Element_Text(
'headimage',
null,
'https://tu.ltyuanfang.cn/api/fengjing.php',
_t('海报头部图片'),
_t('请填写海报头部图片的URL,推荐填写随机图片API')
);
$form->addInput($headimage);
$button = new Typecho_Widget_Helper_Form_Element_Textarea(
'button',
null,
'<button class="article-poster-button">海报</button>',
_t('自定义按钮样式'),
_t('根据自己模板的按钮样式来自定义分享按钮的样式,在class里面加入<b style="color: #ff0000;">article-poster-button</b>即可使用')
);
$form->addInput($button);
}
/**
* 个人用户的配置面板
*
* @param Form $form
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form)
{
}
/**
* 插件实现方法
*/
public static function render()
{
}
public static function button($cid)
{
$options = Helper::options();
$config = $options->plugin('ArticlePoster');
echo '<!-- ArticlePoster -->';
echo $config->button;
echo '<div data-id="' . $cid . '" class="poster-popover-mask"> <div class="poster-popover-box"> <img class="article-poster-images"> <a class="poster-download">下载海报</a> </div> </div>';
}
public static function header()
{
$options = Helper::options();
echo '<link rel="stylesheet" href="' . $options->pluginUrl . '/ArticlePoster/css/core.css">';
}
public static function footer()
{
echo '<script src="' . Helper::options()->pluginUrl . '/ArticlePoster/js/core.js"></script>';
}
}