PluginProbe
果果推送 / 0.0.4
果果推送 v0.0.4
trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7
ggpush / includes / class-ggpush-settings.php

class-ggpush-settings.php in 果果推送 0.0.4, at includes/class-ggpush-settings.php

348 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * 推送设置
5 */
6 class Ggpush_Settings
7 {
8 /**
9 * 初始化页面
10 * @return void
11 */
12 public static function init_page()
13 {
14 self::add_settings_page();
15 self::add_baidu_page();
16 self::add_bing_page();
17 self::add_indexnow_page();
18 }
19
20 /**
21 * 显示设置页面
22 * @return void
23 */
24 public static function show_page()
25 {
26 // 检查用户权限
27 if (!current_user_can('manage_options')) {
28 return;
29 }
30 $tab = Ggpush_Plugin::get('tab', 'ggpush-settings');
31 if (!empty($_GET['settings-updated'])) {
32 // 添加更新信息
33 add_settings_error('ggpush_messages', 'ggpush_message', '设置已保存。', 'updated');
34 // 更新定时任务
35 Ggpush_Cron::update_cron();
36 }
37 // 显示错误/更新信息
38 settings_errors('ggpush_messages');
39 ?>
40 <div class="wrap">
41 <h1 class="wp-heading-inline"><?php echo esc_html(get_admin_page_title()); ?></h1>
42 <nav class="nav-tab-wrapper wp-clearfix">
43 <a href="admin.php?page=ggpush-settings"
44 class="nav-tab<?php if (empty($tab) || 'ggpush-settings' === $tab) {
45 echo ' nav-tab-active';
46 } ?>">基本设置</a>
47 <a href="admin.php?page=ggpush-settings&tab=ggpush-baidu-page"
48 class="nav-tab<?php if ('ggpush-baidu-page' === $tab) {
49 echo ' nav-tab-active';
50 } ?>">百度推送</a>
51 <a href="admin.php?page=ggpush-settings&tab=ggpush-bing-page"
52 class="nav-tab<?php if ('ggpush-bing-page' === $tab) {
53 echo ' nav-tab-active';
54 } ?>">�
55 应推送</a>
56 <a href="admin.php?page=ggpush-settings&tab=ggpush-indexnow-page"
57 class="nav-tab<?php if ('ggpush-indexnow-page' === $tab) {
58 echo ' nav-tab-active';
59 } ?>">IndexNow推送</a>
60 </nav>
61 <form action="options.php" method="post">
62 <input type="hidden" name="page" value="ggpush-settings">
63 <?php
64 // 输出表单
65 settings_fields($tab);
66 do_settings_sections($tab);
67 // 输出保存设置按钮
68 submit_button('保存更改');
69 ?>
70 </form>
71 </div>
72 <?php
73 }
74
75 // 基本设置页面
76 public static function add_settings_page()
77 {
78 // 注册一个新页面
79 register_setting('ggpush-settings', 'ggpush_options', array('Ggpush_Plugin', 'sanitize'));
80
81 add_settings_section(
82 'ggpush_section_base',
83 null,
84 null,
85 'ggpush-settings'
86 );
87
88
89 add_settings_field(
90 'menu_position',
91 '显示位置',
92 array('Ggpush_Plugin', 'field_callback'),
93 'ggpush-settings',
94 'ggpush_section_base',
95 array(
96 'label_for' => 'menu_position',
97 'form_type' => 'select',
98 'form_data' => array(
99 array(
100 'title' => '文章',
101 'value' => '5'
102 ),
103 array(
104 'title' => '媒体',
105 'value' => '10'
106 ),
107 array(
108 'title' => '页面',
109 'value' => '20'
110 ),
111 array(
112 'title' => '评论',
113 'value' => '25'
114 ),
115 array(
116 'title' => '插件',
117 'value' => '65'
118 ),
119 array(
120 'title' => '用户',
121 'value' => '70'
122 ),
123 array(
124 'title' => '工�
125 �',
126 'value' => '75'
127 ),
128 array(
129 'title' => '设置',
130 'value' => '80'
131 ),
132 array(
133 'title' => '默认',
134 'value' => '100'
135 )
136 )
137 )
138 );
139
140 add_settings_field(
141 'push_timeout',
142 '请求�
143 时时间',
144 array('Ggpush_Plugin', 'field_callback'),
145 'ggpush-settings',
146 'ggpush_section_base',
147 array(
148 'label_for' => 'push_timeout',
149 'form_type' => 'input',
150 'type' => 'number',
151 'form_desc' => '请求�
152 过多少秒后,自动停止推送,默认为30秒'
153 )
154 );
155
156 add_settings_field(
157 'push_record',
158 '推送记录',
159 array('Ggpush_Plugin', 'field_callback'),
160 'ggpush-settings',
161 'ggpush_section_base',
162 array(
163 'label_for' => 'push_record',
164 'form_type' => 'select',
165 'form_data' => array(
166 array(
167 'title' => '开启',
168 'value' => '0'
169 ),
170 array(
171 'title' => '�
172 �闭',
173 'value' => '1'
174 )
175 ),
176 'form_desc' => '保存推送请求与响应数据,可以在推送记录页面查看推送记录'
177 )
178 );
179 }
180
181 // 百度
182 public static function add_baidu_page()
183 {
184 // 注册一个新页面
185 register_setting('ggpush-baidu-page', 'ggpush_options', array('Ggpush_Plugin', 'sanitize'));
186
187 add_settings_section(
188 'ggpush_section',
189 '说明',
190 array('Ggpush_Settings', 'baidu_callback'),
191 'ggpush-baidu-page'
192 );
193
194 add_settings_field(
195 'baidu_token',
196 '准�
197 �密钥',
198 array('Ggpush_Plugin', 'field_callback'),
199 'ggpush-baidu-page',
200 'ggpush_section',
201 array(
202 'label_for' => 'baidu_token',
203 'form_type' => 'input',
204 'type' => 'text',
205 'form_desc' => '请填写接口调用地址中的token参数值'
206 )
207 );
208 }
209
210 /**
211 * 百度说明
212 * @return void
213 */
214 public static function baidu_callback()
215 {
216 ?>
217 <p>
218 准�
219 �密钥可以在<a href="https://ziyuan.baidu.com/linksubmit/index" target="_blank" style="margin: 0 5px;">https://ziyuan.baidu.com/linksubmit/index</a>页面获取(接口调用地址中的<b>token</b>参数值)。
220 </p>
221 <?php
222 }
223
224 // �
225
226 public static function add_bing_page()
227 {
228 // 注册一个新页面
229 register_setting('ggpush-bing-page', 'ggpush_options', array('Ggpush_Plugin', 'sanitize'));
230
231 // �
232 应搜索引擎
233 add_settings_section(
234 'ggpush_section_bing',
235 '说明',
236 array('Ggpush_Settings', 'bing_callback'),
237 'ggpush-bing-page'
238 );
239
240 add_settings_field(
241 'bing_token',
242 'API密钥',
243 array('Ggpush_Plugin', 'field_callback'),
244 'ggpush-bing-page',
245 'ggpush_section_bing',
246 array(
247 'label_for' => 'bing_token',
248 'form_type' => 'input',
249 'type' => 'text'
250 )
251 );
252 }
253
254 /**
255 * �
256 应说明
257 * @return void
258 */
259 public static function bing_callback()
260 {
261 ?>
262 <p>
263 API密钥可以在<a href="https://www.bing.com/webmasters/home" target="_blank"
264 style="margin: 0 5px;">https://www.bing.com/webmasters/home</a>页面获取(依次点击:页面右上方的设置按钮、API 访问、API
265 密钥)。
266 </p>
267 <?php
268 }
269
270 // indexnow
271 public static function add_indexnow_page()
272 {
273 // 注册一个新页面
274 register_setting('ggpush-indexnow-page', 'ggpush_options', array('Ggpush_Plugin', 'sanitize'));
275
276 // IndexNow
277 add_settings_section(
278 'ggpush_section_indexnow',
279 '说明',
280 array('Ggpush_Settings', 'indexnow_callback'),
281 'ggpush-indexnow-page'
282 );
283
284 add_settings_field(
285 'indexnow_token',
286 '密钥',
287 array('Ggpush_Plugin', 'field_callback'),
288 'ggpush-indexnow-page',
289 'ggpush_section_indexnow',
290 array(
291 'label_for' => 'indexnow_token',
292 'form_type' => 'input',
293 'type' => 'text',
294 'form_desc' => '填写密钥保存后,将会在您的网站根目录下生成密钥文本文件'
295 )
296 );
297
298 add_settings_field(
299 'indexnow_search_engine',
300 // 输�
301 �框说明文字
302 '推送平台',
303 array('Ggpush_Plugin', 'field_callback'),
304 'ggpush-indexnow-page',
305 'ggpush_section_indexnow',
306 array(
307 'label_for' => 'indexnow_search_engine',
308 'form_type' => 'checkbox',
309 'form_data' => array(
310 array(
311 'title' => 'IndexNow',
312 'value' => '1'
313 ),
314 array(
315 'title' => '�
316 ',
317 'value' => '2'
318 ),
319 array(
320 'title' => 'Yandex',
321 'value' => '3'
322 ),
323 array(
324 'title' => 'Seznam.cz',
325 'value' => '4'
326 )
327 )
328 )
329 );
330 }
331
332 /**
333 * indexnow说明
334 * @return void
335 */
336 public static function indexnow_callback()
337 {
338 ?>
339 <p>
340 <a href="https://www.indexnow.org/zh_cn/documentation" target="_blank">IndexNow</a>密钥最少有8个,最多128个字符组成。密钥只能�
341 含以下字符:小写字母(a-z),大写字母(A-Z),数字(0-9),以及短破折号(-)。
342 </p>
343 <p>
344 您可以点击右侧链接生成一个随机密钥:<a href="https://www.bing.com/indexnow#generateApiKey" target="_blank">https://www.bing.com/indexnow#generateApiKey</a>。
345 </p>
346 <?php
347 }
348 }