PluginProbe
果果推送 / trunk
果果推送 vtrunk
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 果果推送 trunk, at includes/class-ggpush-settings.php

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