cron.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id:$
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once(DISCUZ_ROOT.'source/plugin/milu_seotool/config.inc.php');
  12. class milu_seotool_cron{
  13. //定时查询收录
  14. public static function included_check(){
  15. global $_G;
  16. $timestamp = TIMESTAMP;
  17. $processname ='INCLUDED_CRON_CHECK';
  18. if(discuz_process::islocked($processname, 5*60)) {
  19. return false;
  20. }
  21. sload('F:included');
  22. $included_set = tool_common_get('included');
  23. if($included_set['is_auto_check'] != 1) return;
  24. @set_time_limit(1000);
  25. @ignore_user_abort(TRUE);
  26. $check_time = $included_set['auto_check_time'] ? intval($included_set['auto_check_time']) : 12;
  27. $aoto_check_day = $included_set['aoto_check_day'] ? intval($included_set['aoto_check_day']) : 3;
  28. $check_per_num = $included_set['check_per_num'] ? intval($included_set['check_per_num']) : 50;
  29. $included_set['included_type'] = dunserialize($included_set['included_type']);
  30. //执行
  31. $dateline = TIMESTAMP - $aoto_check_day*3600*24;
  32. $included_baidu_flag = in_array(1, $included_set['included_type']);
  33. $included_google_flag = in_array(2, $included_set['included_type']);
  34. //门户
  35. if(VIP){
  36. $ids_arr = self::new_article($check_per_num, $dateline, 1);
  37. if($included_baidu_flag) $baidu_ids_arr = filter_article_data($ids_arr, 1, 1);//需要百度查询的数据
  38. batch_run($baidu_ids_arr, 1, 1);
  39. if($included_google_flag) $google_ids_arr = filter_article_data($ids_arr, 2, 1);//需要谷歌查询的数据
  40. batch_run($google_ids_arr, 2, 1);
  41. }
  42. //论坛
  43. $ids_arr = self::new_article($check_per_num, $dateline, 0);
  44. if($included_baidu_flag) $baidu_ids_arr = filter_article_data($ids_arr, 1, 0);//需要百度查询的数据
  45. batch_run($baidu_ids_arr, 1, 0);
  46. if($included_google_flag) $google_ids_arr = filter_article_data($ids_arr, 2, 0);//需要谷歌查询的数据
  47. batch_run($google_ids_arr, 2, 0);
  48. tool_common_set('milu_seotool_cron', array('included_check' => TIMESTAMP + $check_time*3600 ));//成功运行,时间按正常设置
  49. discuz_process::unlock($processname);
  50. return true;
  51. }
  52. //定时ping
  53. public static function ping_check(){
  54. global $_G;
  55. $timestamp = TIMESTAMP;
  56. $processname ='PING_CRON_CHECK';
  57. if(discuz_process::islocked($processname, 5*60)) {
  58. return false;
  59. }
  60. sload('F:included');
  61. $included_set = tool_common_get('included');
  62. if($included_set['is_auto_ping'] != 1) return;
  63. @set_time_limit(1000);
  64. @ignore_user_abort(TRUE);
  65. $check_time = $included_set['auto_ping_time'] ? intval($included_set['auto_ping_time']) : 30;
  66. $check_per_num = $included_set['ping_per_num'] ? intval($included_set['ping_per_num']) : 50;
  67. $included_set['ping_type'] = dunserialize($included_set['ping_type']);
  68. //执行
  69. $dateline = TIMESTAMP - 24 * 3600;//只检查一天之内发布未ping的文章。
  70. $ping_baidu_flag = in_array(1, $included_set['ping_type']);
  71. $ping_google_flag = in_array(2, $included_set['ping_type']);
  72. //门户
  73. if(VIP){
  74. $ids_arr = self::new_article($check_per_num, $dateline, 1);
  75. if($ping_baidu_flag) $baidu_ids_arr = filter_article_data($ids_arr, 3, 1);//百度ping
  76. batch_run($baidu_ids_arr, 3, 1);
  77. if($ping_google_flag) $google_ids_arr = filter_article_data($ids_arr, 4, 1);//谷歌ping
  78. batch_run($google_ids_arr, 4, 1);
  79. }
  80. //论坛
  81. $ids_arr = self::new_article($check_per_num, $dateline, 0);
  82. if($ping_baidu_flag) $baidu_ids_arr = filter_article_data($ids_arr, 3, 0);//百度ping
  83. batch_run($baidu_ids_arr, 3, 0);
  84. if($ping_google_flag) $google_ids_arr = filter_article_data($ids_arr, 4, 0);//谷歌ping
  85. batch_run($google_ids_arr, 4, 0);
  86. tool_common_set('milu_seotool_cron', array('ping_check' => TIMESTAMP + $check_time*60) );
  87. discuz_process::unlock($processname);
  88. return true;
  89. }
  90. //定时监控排名
  91. public static function keyword_rank_check(){
  92. global $_G;
  93. sload('F:keyword');
  94. $timestamp = TIMESTAMP;
  95. $processname ='KEYWORD_RANK_CRON_CHECK';
  96. if(discuz_process::islocked($processname, 5*60)) {
  97. return false;
  98. }
  99. $keyword_set = tool_common_get('keyword');
  100. if($keyword_set['is_auto_rank'] != 1) return;
  101. @set_time_limit(1000);
  102. @ignore_user_abort(TRUE);
  103. $check_time = 15 * 3600;//每隔15个小时运行一次
  104. //执行
  105. $cache_keyword_data = $keyword_set['keyword_data'];
  106. if($cache_keyword_data){
  107. foreach($cache_keyword_data as $k => $v){
  108. get_rank_data($k);
  109. }
  110. }else{
  111. $query = DB::query("SELECT name FROM ".DB::table('milu_seotool_keyword'));
  112. while($rs = DB::fetch($query)) {
  113. get_rank_data($rs['name']);
  114. }
  115. }
  116. tool_common_set('milu_seotool_cron', array('keyword_rank_check' => TIMESTAMP + $check_time));
  117. discuz_process::unlock($processname);
  118. return true;
  119. }
  120. //网站地图更新
  121. public static function sitemap_maker(){
  122. global $_G;
  123. sload('F:sitemap');
  124. $timestamp = TIMESTAMP;
  125. $processname ='SITEMAP_CRON_CHECK';
  126. if(discuz_process::islocked($processname, 5*60)) {
  127. return false;
  128. }
  129. $sitemap_set = tool_common_get('sitemap');
  130. if($sitemap_set['is_auto'] != 1) return;
  131. @set_time_limit(1000);
  132. @ignore_user_abort(TRUE);
  133. $sitemap_set['auto_time'] = $sitemap_set['auto_time'] ? $sitemap_set['auto_time'] : 1;
  134. $check_time = $sitemap_set['auto_time'] * 3600*24;
  135. $update_info = update_sitemap($sitemap_set);
  136. save_syscache('milu_seotool_sitemap', $update_info);
  137. tool_common_set('milu_seotool_cron', array('sitemap_maker' => TIMESTAMP + $check_time));
  138. discuz_process::unlock($processname);
  139. return true;
  140. }
  141. public static function new_article($max_num, $dateline, $data_type = 0){
  142. $where_sql = " AND dateline>'$dateline'";
  143. $count = get_article_count($data_type, $where_sql);
  144. if(!$count) return FALSE;
  145. if($data_type == 1){//门户
  146. $query = DB::query("SELECT aid,dateline FROM ".DB::table('portal_article_title')." WHERE status='0' $where_sql ORDER BY dateline DESC LIMIT $max_num");
  147. }else{
  148. $query = DB::query("SELECT tid as aid,dateline FROM ".DB::table('forum_thread')." WHERE displayorder='0' $where_sql ORDER BY dateline DESC LIMIT $max_num");
  149. }
  150. while($rs = DB::fetch($query)) {
  151. $ids_arr[] = $rs['aid'];
  152. }
  153. return $ids_arr;
  154. }
  155. }
  156. ?>