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-cron.php

class-ggpush-cron.php in 果果推送 trunk, at includes/class-ggpush-cron.php

229 lines 6.5 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_Cron
7 {
8
9 /**
10 * 更新定时任务
11 * @param bool $enable 是否启用定时任务
12 * @return void
13 */
14 public static function update_cron($enable = true)
15 {
16 if ($enable) {
17 // 插件已激活,启用定时任务
18 self::ggpush_create_baidu_cron();
19 self::ggpush_create_baidu_fast_cron();
20 self::ggpush_create_bing_cron();
21 self::ggpush_create_indexnow_cron();
22 } else {
23 // 插件已禁用,删除定时任务
24 self::ggpush_delete_baidu_cron();
25 self::ggpush_delete_baidu_fast_cron();
26 self::ggpush_delete_bing_cron();
27 self::ggpush_delete_indexnow_cron();
28 }
29 }
30
31 /**
32 * 定时任务过滤器
33 * @param $schedules
34 * @return mixed
35 */
36 public static function cron_schedules($schedules)
37 {
38 // 百度普通收录
39 $baidu_cron_interval = Ggpush_Plugin::get_option('baidu_interval', 0);
40 if ($baidu_cron_interval > 0) {
41 $schedules['ggpush_baidu_cron'] = array(
42 'interval' => $baidu_cron_interval * 60,
43 'display' => '百度普通收录',
44 );
45 } else {
46 unset($schedules['ggpush_baidu_cron']);
47 }
48
49 // 百度快速抓取
50 $baidu_fast_cron_interval = Ggpush_Plugin::get_option('baidu_fast_interval', 0);
51 if ($baidu_fast_cron_interval > 0) {
52 $schedules['ggpush_baidu_fast_cron'] = array(
53 'interval' => $baidu_fast_cron_interval * 60,
54 'display' => '百度快速抓取',
55 );
56 } else {
57 unset($schedules['ggpush_baidu_fast_cron']);
58 }
59
60 // bing收录
61 $bing_cron_interval = Ggpush_Plugin::get_option('bing_interval', 0);
62 if ($bing_cron_interval > 0) {
63 $schedules['ggpush_bing_cron'] = array(
64 'interval' => $bing_cron_interval * 60,
65 'display' => '�
66 应收录',
67 );
68 } else {
69 unset($schedules['ggpush_bing_cron']);
70 }
71
72 // indexnow收录
73 $indexnow_cron_interval = Ggpush_Plugin::get_option('indexnow_interval', 0);
74 if ($indexnow_cron_interval > 0) {
75 $schedules['ggpush_indexnow_cron'] = array(
76 'interval' => $indexnow_cron_interval * 60,
77 'display' => 'IndexNow收录',
78 );
79 } else {
80 unset($schedules['ggpush_indexnow_cron']);
81 }
82
83 return $schedules;
84 }
85
86 /**
87 * 百度普通推送
88 */
89 public static function ggpush_run_baidu_cron()
90 {
91 $urls = Ggpush_Api::get_post_url(Ggpush_Plugin::get_option('baidu_num'), Ggpush_Plugin::get_option('baidu_type'));
92 if (!empty($urls)) {
93 Ggpush_Api::push_baidu($urls);
94 }
95 }
96
97 /**
98 * 百度快速推送
99 */
100 public static function ggpush_run_baidu_fast_cron()
101 {
102 $urls = Ggpush_Api::get_post_url(Ggpush_Plugin::get_option('baidu_fast_num'), Ggpush_Plugin::get_option('baidu_fast_type'));
103 if (!empty($urls)) {
104 Ggpush_Api::push_baidu($urls, true);
105 }
106 }
107
108 /**
109 * bing推送
110 */
111 public static function ggpush_run_bing_cron()
112 {
113 $urls = Ggpush_Api::get_post_url(Ggpush_Plugin::get_option('bing_num'), Ggpush_Plugin::get_option('bing_type'));
114 if (!empty($urls)) {
115 Ggpush_Api::push_bing($urls);
116 }
117 }
118
119 /**
120 * indexnow推送
121 */
122 public static function ggpush_run_indexnow_cron()
123 {
124 $urls = Ggpush_Api::get_post_url(Ggpush_Plugin::get_option('indexnow_num'), Ggpush_Plugin::get_option('indexnow_type'));
125 if (!empty($urls)) {
126 Ggpush_Api::push_indexnow($urls);
127 }
128 }
129
130 /**
131 * 创建百度普通收录定时任务
132 */
133 public static function ggpush_create_baidu_cron()
134 {
135 if (GGPUSH_RUN_BAIDU_CRON) {
136 if (!wp_next_scheduled('ggpush_run_baidu_cron')) {
137 wp_schedule_event(time(), 'ggpush_baidu_cron', 'ggpush_run_baidu_cron');
138 }
139 } else {
140 self::ggpush_delete_baidu_cron();
141 }
142 }
143
144 /**
145 * 删除百度普通收录定时任务
146 */
147 public static function ggpush_delete_baidu_cron()
148 {
149 $timestamp = wp_next_scheduled('ggpush_run_baidu_cron');
150 if ($timestamp) {
151 wp_unschedule_event($timestamp, 'ggpush_run_baidu_cron');
152 }
153 }
154
155 /**
156 * 创建百度快速抓取定时任务
157 */
158 public static function ggpush_create_baidu_fast_cron()
159 {
160 if (GGPUSH_RUN_BAIDU_FAST_CRON) {
161 if (!wp_next_scheduled('ggpush_run_baidu_fast_cron')) {
162 wp_schedule_event(time(), 'ggpush_baidu_fast_cron', 'ggpush_run_baidu_fast_cron');
163 }
164 } else {
165 self::ggpush_delete_baidu_fast_cron();
166 }
167 }
168
169 /**
170 * 删除百度快速抓取定时任务
171 */
172 public static function ggpush_delete_baidu_fast_cron()
173 {
174 $timestamp = wp_next_scheduled('ggpush_run_baidu_fast_cron');
175 if ($timestamp) {
176 wp_unschedule_event($timestamp, 'ggpush_run_baidu_fast_cron');
177 }
178 }
179
180 /**
181 * 创建bing收录定时任务
182 */
183 public static function ggpush_create_bing_cron()
184 {
185 if (GGPUSH_RUN_BING_CRON) {
186 if (!wp_next_scheduled('ggpush_run_bing_cron')) {
187 wp_schedule_event(time(), 'ggpush_bing_cron', 'ggpush_run_bing_cron');
188 }
189 } else {
190 self::ggpush_delete_bing_cron();
191 }
192 }
193
194 /**
195 * 删除bing收录定时任务
196 */
197 public static function ggpush_delete_bing_cron()
198 {
199 $timestamp = wp_next_scheduled('ggpush_run_bing_cron');
200 if ($timestamp) {
201 wp_unschedule_event($timestamp, 'ggpush_run_bing_cron');
202 }
203 }
204
205 /**
206 * 创建indexnow收录定时任务
207 */
208 public static function ggpush_create_indexnow_cron()
209 {
210 if (GGPUSH_RUN_INDEXNOW_CRON) {
211 if (!wp_next_scheduled('ggpush_run_indexnow_cron')) {
212 wp_schedule_event(time(), 'ggpush_indexnow_cron', 'ggpush_run_indexnow_cron');
213 }
214 } else {
215 self::ggpush_delete_indexnow_cron();
216 }
217 }
218
219 /**
220 * 删除indexnow收录定时任务
221 */
222 public static function ggpush_delete_indexnow_cron()
223 {
224 $timestamp = wp_next_scheduled('ggpush_run_indexnow_cron');
225 if ($timestamp) {
226 wp_unschedule_event($timestamp, 'ggpush_run_indexnow_cron');
227 }
228 }
229 }