included.inc.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <?php
  2. if(!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. require_once(DISCUZ_ROOT.'source/plugin/milu_seotool/config.inc.php');
  6. sload('F:included,F:copyright');
  7. $header_arr = array('included_set', 'included_forum_list', 'included_portal_list', 'base_data_count', 'trend_data_count');
  8. if(!VIP) unset($header_arr[array_search('included_portal_list', $header_arr)]);
  9. $args = array('default_ac' => 'included_set');
  10. $search_type_arr = array('1' => stlang('baidu'), '2' => stlang('google'));
  11. $spider_type_arr = $search_type_arr;
  12. $ping_type_arr = $search_type_arr;
  13. $view_data_type = array(1 => stlang('bbs'), 2 => stlang('portal'));
  14. $view_search_type = $search_type_arr;
  15. $included_type_arr = $search_type_arr;
  16. $view_types_arr = array(1 => stlang('in_count'), 2 => stlang('in_percent'));
  17. $right_status = '<span class="status_right"></span>';
  18. $notice_status = '<span class="status_notice"></span>';
  19. $included_set = tool_common_get('included');
  20. $included_set['view_user_group'] = dunserialize($included_set['view_user_group']);
  21. $included_set['ping_type'] = dunserialize($included_set['ping_type']);
  22. $included_set['spider_type'] = dunserialize($included_set['spider_type']);
  23. $included_set['included_type'] = dunserialize($included_set['included_type']);
  24. seo_tpl($args);
  25. function included_set(){
  26. global $_G,$pluin_info,$spider_type_arr,$ping_type_arr,$included_set,$included_type_arr;
  27. if($_POST['editsubmit']){
  28. $set = $_POST['set'];
  29. $set['view_user_group'] = serialize($_GET['view_user_group']);
  30. $set['ping_type'] = serialize($_GET['ping_type']);
  31. $set['spider_type'] = serialize($_GET['spider_type']);
  32. $set['included_type'] = serialize($_GET['included_type']);
  33. //计划任务要重新设定
  34. //tool_common_set('milu_seotool_cron', array('included_check' => 0, 'ping_check' => 0));
  35. tool_common_set('included', $set);
  36. cpmsg(stlang('op_success'), PLUGIN_GO."included", 'succeed');
  37. }else{
  38. $info = $included_set;
  39. $cat_arr = $cat_site_arr = get_site_category();
  40. array_unshift($cat_arr, stlang('empty'));
  41. $show .= seoOutput::show_title(stlang('base_set'));
  42. $show .= seoOutput::show_tr(
  43. array(
  44. 'name' => stlang('spider_log_set'),
  45. 'desc' => '',
  46. 'arr' => array(
  47. 'name' => 'spider_type',
  48. 'info' => $info,
  49. 'option_arr' => $spider_type_arr,
  50. ),
  51. )
  52. ,'checkbox');
  53. $show .= seoOutput::show_title(stlang('included_set'));
  54. $show .= seoOutput::show_tr(
  55. array(
  56. 'name' => stlang('included_set'),
  57. 'desc' => stlang('included_set_notice'),
  58. 'arr' => array(
  59. 'name' => 'included_type',
  60. 'info' => $info,
  61. 'option_arr' => $included_type_arr,
  62. ),
  63. )
  64. ,'checkbox');
  65. $show .= seoOutput::show_title(stlang('ping_set'));
  66. $show .= seoOutput::show_tr(
  67. array(
  68. 'name' => stlang('article_ping_set'),
  69. 'arr' => array(
  70. 'name' => 'ping_type',
  71. 'info' => $info,
  72. 'option_arr' => $ping_type_arr,
  73. ),
  74. )
  75. ,'checkbox');
  76. $show .= seoOutput::show_tr(
  77. array(
  78. 'name' => stlang('is_auto_ping'),
  79. 'desc' => '',
  80. 'arr' => array(
  81. 'name' => 'is_auto_ping',
  82. 'info' => $info,
  83. 'int_val' => 2,
  84. 'lang_type' => 2,
  85. ),
  86. )
  87. ,'radio');
  88. $show .= seoOutput::show_tr(
  89. array(
  90. 'name' => stlang('auto_ping_time'),
  91. 'desc' => stlang('auto_ping_time_notice'),
  92. 'arr' => array(
  93. 'name' => 'auto_ping_time',
  94. 'int_val' => 30,
  95. 'info' => $info,
  96. ),
  97. )
  98. ,'input');
  99. $show .= seoOutput::show_tr(
  100. array(
  101. 'name' => stlang('bat_max_num'),
  102. 'desc' => stlang('default_num_article', array('c' => 50)),
  103. 'arr' => array(
  104. 'name' => 'ping_per_num',
  105. 'int_val' => 50,
  106. 'info' => $info,
  107. ),
  108. )
  109. ,'input');
  110. $show .= seoOutput::show_title(stlang('is_auto_check_included'));
  111. $show .= seoOutput::show_tr(
  112. array(
  113. 'name' => stlang('_is_auto_check_included'),
  114. 'desc' => stlang('check_included_notice'),
  115. 'arr' => array(
  116. 'name' => 'is_auto_check',
  117. 'info' => $info,
  118. 'int_val' => 2,
  119. 'lang_type' => 2,
  120. ),
  121. )
  122. ,'radio');
  123. $show .= seoOutput::show_tr(
  124. array(
  125. 'name' => stlang('aoto_check_day'),
  126. 'desc' => stlang('aoto_check_day_notice'),
  127. 'arr' => array(
  128. 'name' => 'aoto_check_day',
  129. 'int_val' => 3,
  130. 'info' => $info,
  131. ),
  132. )
  133. ,'input');
  134. $show .= seoOutput::show_tr(
  135. array(
  136. 'name' => stlang('auto_check_time'),
  137. 'desc' => stlang('auto_check_time_notice', array('c' => 12)),
  138. 'arr' => array(
  139. 'name' => 'auto_check_time',
  140. 'int_val' => 12,
  141. 'info' => $info,
  142. ),
  143. )
  144. ,'input');
  145. $show .= seoOutput::show_tr(
  146. array(
  147. 'name' => stlang('bat_max_num'),
  148. 'desc' => stlang('default_num_article', array('c' => 50)),
  149. 'arr' => array(
  150. 'name' => 'check_per_num',
  151. 'int_val' => 50,
  152. 'info' => $info,
  153. ),
  154. )
  155. ,'input');
  156. if(VIP){
  157. $show .= seoOutput::show_title(stlang('included_is_show_title'));
  158. $show .= seoOutput::show_tr(
  159. array(
  160. 'name' => stlang('included_is_show'),
  161. 'desc' => stlang('included_is_show_notice'),
  162. 'arr' => array(
  163. 'name' => 'is_show',
  164. 'info' => $info,
  165. 'int_val' => 2,
  166. 'lang_type' => 2,
  167. ),
  168. )
  169. ,'radio');
  170. $show .= seoOutput::show_tr(
  171. array(
  172. 'name' => stlang('view_user_type'),
  173. 'desc' => '',
  174. 'arr' => array(
  175. 'name' => 'view_user_type',
  176. 'info' => $info,
  177. 'int_val' => 1,
  178. 'lang_arr' => array(stlang('user_group'), stlang('_user_set')),
  179. 'js' => array(0 => "show_hide('tr_user_group', 'tr_user_set' ,1);", 1 => "show_hide('tr_user_group', 'tr_user_set' ,2);"),
  180. 'lang_type' => 2,
  181. ),
  182. )
  183. ,'radio');
  184. $show .= seoOutput::add_tr(array('desc' => stlang('select_notice_'), 'tr_id' => 'tr_user_group', 'style' => $info['view_user_type'] !=2 ? '' : 'style="display:none"'), seoOutput::user_group_select('view_user_group', $info['view_user_group'], array('group_arr' => array('system', 'special'), 'no_epmty' => 1)));
  185. $show .= seoOutput::add_tr(array('desc' => stlang('included_view_uid'), 'tr_id' => 'tr_user_set', 'style' => $info['view_user_type'] == 2 ? '' : 'style="display:none"'), seoOutput::input(
  186. array(
  187. 'name' => 'view_user',
  188. 'info' => $info,
  189. 'int_val' => '',
  190. ),$info));
  191. }
  192. $info['show'] = $show;
  193. $info['tpl'] = 'common_set';
  194. return $info;
  195. }
  196. }
  197. function included_forum_list(){
  198. return included_list();
  199. }
  200. function included_list($data_type = 0){
  201. global $_G,$included_set;
  202. if($_GET['submit']){//执行批量操作
  203. $set = $_GET['set'];
  204. $set['batch_op_range'] = $set['batch_op_range'] ? $set['batch_op_range'] : $_GET['batch_op_range'];
  205. $set['batch_op_type'] = $set['batch_op_type'] ? $set['batch_op_type'] : $_GET['batch_op_type'];
  206. $set['op_select_type'] = $set['op_select_type'] ? $set['op_select_type'] : $_GET['op_select_type'];
  207. $search_args = urldecode($_GET['search_args']);
  208. $set['title'] = $set['title'] ? $set['title'] : $_GET['title'];
  209. $set['baidu'] = $set['baidu'] ? $set['baidu'] : $_GET['baidu'];
  210. $set['baidu_modify_dateline'] = $set['baidu_modify_dateline'] ? $set['baidu_modify_dateline'] : $_GET['baidu_modify_dateline'];
  211. $set['google_modify_dateline'] = $set['google_modify_dateline'] ? $set['google_modify_dateline'] : $_GET['google_modify_dateline'];
  212. $set['fast_search'] = $set['fast_search'] ? $set['fast_search'] : $_GET['fast_search'];
  213. $set['article_batch_num'] = $article_batch_num = $_GET['article_batch_num'];
  214. $set['page'] = $_GET['page'];
  215. $set['perpage'] = $_GET['perpage'];
  216. $ids_arr = $_GET['ids'];
  217. $batch_args_url = get_args_str($set).$search_args;
  218. if(!$_GET['step']) {
  219. if($set['batch_op_range'] == 1){//所选数据
  220. $count = count($ids_arr);
  221. if(!$ids_arr) cpmsg_error(stlang('please_select_data'));
  222. $ids_str = implode('_', $ids_arr);
  223. }else{//全部数据
  224. $count = 0;
  225. }
  226. cpmsg(stlang('running'), PLUGIN_GO.'included&myac='.$_GET['myac'].'&step=1&submit=1&count='.$count.'&ids_str='.$ids_str.$batch_args_url, 'loading', '', false);
  227. }else if($_GET['step'] == 1){
  228. $ids_str = '';
  229. if($_GET['batch_op_range'] == 1){//所选数据
  230. $ids_arr = $_GET['ids_str'] ? explode('_', $_GET['ids_str']) : array();
  231. $per = $article_batch_num;
  232. $count = $_GET['count'];
  233. $new_ids_arr = array_splice ($ids_arr, $per);
  234. $percent = ( $count - count($new_ids_arr) ) / $count;
  235. $percent = sprintf("%01.0f", $percent*100).'%';
  236. $ids_str = implode('_', $new_ids_arr);
  237. }else{
  238. $search_args['page'] = $page = $_GET['bat_page'] ? $_GET['bat_page'] : 1;
  239. $search_args['title'] = $_GET['title'];
  240. $search_args['baidu'] = $_GET['baidu'];
  241. $search_args['baidu_modify_dateline'] = $_GET['baidu_modify_dateline'];
  242. $search_args['google_modify_dateline'] = $_GET['google_modify_dateline'];
  243. $search_args['fast_search'] = $_GET['fast_search'];
  244. if($set['fast_search']) unset($set['baidu'], $set['baidu_modify_dateline'], $set['google_modify_dateline'], $set['title']);
  245. $search_args['perpage'] = $article_batch_num;
  246. $search_args['data_type'] = $data_type;
  247. $info = included_data_list($search_args);
  248. $count = $info['count'];
  249. foreach($info['list'] as $k => $v){
  250. $ids_arr[] = $v['aid'];
  251. }
  252. $new_count = count($ids_arr);
  253. $new_ids_arr = $ids_arr;
  254. $page +=1;
  255. $batch_args_url .= '&page='.$page;
  256. if($set['op_select_type'] == 2){//有记录就跳过
  257. $ids_arr = filter_article_data($ids_arr, $set['batch_op_type'], $data_type);
  258. }
  259. $percent = ($article_batch_num * ($search_args['page'] - 1) + $new_count) / $count;
  260. $percent = sprintf("%01.0f", $percent*100).'%';
  261. $batch_args_url .= '&bat_page='.$page;
  262. }
  263. batch_run($ids_arr, $set['batch_op_type'], $data_type);
  264. if(!$new_ids_arr) {
  265. if($set['batch_op_range'] == 2) $batch_args_url = str_replace(array('&page=', '&bat_page='), array('&', '&'), $batch_args_url);
  266. cpmsg(stlang('running_finsh'), PLUGIN_GO."included&myac=".$_GET['myac'].$batch_args_url, 'succeed');
  267. }
  268. cpmsg(stlang('running_status', array('p' => $percent)), PLUGIN_GO.'included&myac='.$_GET['myac'].'&step=1&submit=1&count='.$count.'&ids_str='.$ids_str.$batch_args_url, 'loading', '', false);
  269. }
  270. }
  271. $set = $_GET['set'];
  272. $set['title'] = $set['title'] ? $set['title'] : $_GET['title'];
  273. $set['fast_search'] = $_GET['fast_search'];
  274. $set['data_type'] = $data_type;
  275. $set['baidu'] = $_GET['baidu'];
  276. $set['baidu_modify_dateline'] = $_GET['baidu_modify_dateline'];
  277. $set['google_modify_dateline'] = $_GET['google_modify_dateline'];
  278. if($set['fast_search']) unset($set['baidu'], $set['baidu_modify_dateline'], $set['google_modify_dateline'], $set['title']);
  279. $set['page'] = $page = $_GET['page'] ? intval($_GET['page']) : 1;
  280. $set['perpage'] = $_GET['perpage'] ? intval($_GET['perpage']) : 25;
  281. $search_info = $set;
  282. $check_info['show_include']['baidu'] = in_array(1, $included_set['included_type']);
  283. $check_info['show_include']['google'] = in_array(2, $included_set['included_type']);
  284. $check_info['show_spider']['baidu'] = in_array(1, $included_set['spider_type']);
  285. $check_info['show_spider']['google'] = in_array(2, $included_set['spider_type']);
  286. $check_info['show_ping']['baidu'] = in_array(1, $included_set['ping_type']);
  287. $check_info['show_ping']['google'] = in_array(2, $included_set['ping_type']);
  288. $search_show .= stlang('title').' '.seoOutput::input(
  289. array(
  290. 'name' => 'title',
  291. 'info' => $search_info,
  292. 'int_val' => '',
  293. ),$info);
  294. $search_show .= ' '.stlang('baidu').' '.seoOutput::select(
  295. array('option_arr' => array(stlang('all'), stlang('spidered_no_included'), stlang('all_included'), stlang('24hour_included')),
  296. 'name' => 'baidu',
  297. 'info' => $search_info,
  298. 'int_val' => 10,
  299. 'flag' => 2,
  300. ),$info);
  301. if($check_info['show_include']['baidu']){
  302. $search_show .= ' '.stlang('baidu_included_check_time').' '.seoOutput::select(
  303. array('option_arr' => array(stlang('all'), stlang('never_check'), stlang('one_day_before'), stlang('one_week_before')),
  304. 'name' => 'baidu_modify_dateline',
  305. 'info' => $search_info,
  306. 'int_val' => 10,
  307. 'flag' => 2,
  308. ),$info);
  309. }
  310. if($check_info['show_include']['google']){
  311. $search_show .= ' '.stlang('google_included_check_time').' '.seoOutput::select(
  312. array('option_arr' => array(stlang('all'), stlang('never_check'), stlang('one_day_before'), stlang('one_week_before')),
  313. 'name' => 'google_modify_dateline',
  314. 'info' => $search_info,
  315. 'int_val' => 10,
  316. 'flag' => 2,
  317. ),$info);
  318. }
  319. $info = included_data_list($search_info);
  320. $info['op_select_range'] = seoOutput::radio(
  321. array('lang_arr' => array(1 => stlang('selected_data'), 2 => stlang('all_data')),
  322. 'name' => 'batch_op_range',
  323. 'info' => $_GET['batch_op_range'],
  324. 'lang_type' => 3,
  325. 'int_val' => 1,
  326. 'flag' => 2,
  327. ),$info);
  328. $info['op_select'] = seoOutput::radio(
  329. array('lang_arr' => array(1 => stlang('baidu_included_check'), 2 => stlang('google_included_check'), 3 => stlang('baidu_ping'), '4' => stlang('google_ping')),
  330. 'name' => 'batch_op_type',
  331. 'info' => $_GET['batch_op_type'],
  332. 'int_val' => 1,
  333. 'flag' => 2,
  334. ),$info);
  335. $info['op_select_type'] = seoOutput::radio(
  336. array('lang_arr' => array(1 => stlang('no_record_run'), 2 => stlang('have_record_jump') ),
  337. 'name' => 'op_select_type',
  338. 'info' => $_GET['op_select_type'],
  339. 'lang_type' => 3,
  340. 'int_val' => 2,
  341. 'flag' => 2,
  342. ),$info);
  343. $info['show_title'] = stlang('article_inluded');
  344. $fast_search_arr = array(1 => stlang('baidu24hour_included'), 2 => stlang('baidu_spider_no_included'), 3 => stlang('baidu_never_check'));
  345. $fast_search = '';
  346. foreach($fast_search_arr as $k => $v){
  347. $current = isset($search_info['fast_search']) && $k == $search_info['fast_search'] ? 'class="current"' : '';
  348. $link = '?'.PLUGIN_GO.'included&myac='.$_GET['myac'].'&page='.$page.'&data_type'.$search_info['data_type'].'&fast_search='.$k;
  349. $fast_search .= '<li '.$current.'><a href="'.$link.'">'.$v.'</a></li>';
  350. }
  351. $info = array_merge($info, $check_info);
  352. $info['search_args'] = urlencode(get_args_str($search_info));
  353. $info['fast_search'] = $fast_search;
  354. $info['search_show'] = $search_show;
  355. $info['tpl'] = 'included_list';
  356. return $info;
  357. }
  358. function included_data_list($args){
  359. global $_G;
  360. $perpage = $args['perpage'];
  361. $page = $args['page'];
  362. $data_arr['start'] = $start = ($page-1)*$perpage;
  363. $mpurl = get_args_str($args);
  364. $data_arr['mpurl'] = '?'.PLUGIN_GO.'included&myac='.$_GET['myac'].$mpurl;
  365. $data_type = $args['data_type'];
  366. if(!$args['baidu'] && !$args['baidu_modify_dateline'] && !$args['google_modify_dateline'] && !$args['fast_search']){
  367. $func = $args['data_type'] == 1 ? 'included_data_portal' : 'included_data_forum';
  368. $data_list = $func($data_arr, $args);
  369. }else{
  370. $data_id_name = $data_type == 1 ? 'aid' : 'tid';
  371. $where_sql = '';
  372. if($data_type == 1){//门户
  373. $table = 'portal_article_title';
  374. $where_sql = "WHERE a.data_type='1' AND b.status='0'";
  375. $title_name = 'title';
  376. $get_field = 'b.aid,b.title as subject,b.dateline,b.catid';
  377. }else{
  378. $table = 'forum_thread';
  379. $where_sql = "WHERE a.data_type='0' AND b.displayorder='0'";
  380. $title_name = 'subject';
  381. $get_field = 'b.tid as aid,b.subject,b.dateline,b.fid';
  382. }
  383. if($args['title']){
  384. $where_sql .= " AND b.$title_name like '%".$args['title']."%'";
  385. }
  386. //百度收录
  387. if($args['baidu'] == 1 || $args['fast_search'] == 2){//百度爬过但未收录
  388. $where_sql .= " AND a.baidu_spider_count>0 AND a.baidu_included=0 ";
  389. }else if($args['baidu'] == 2){//所有已收录
  390. $where_sql .= " AND a.baidu_included>0 ";
  391. }else if($args['baidu'] == 3 || $args['fast_search'] == 1){//最近24小时收录
  392. $dateline = $_G['timestamp'] - 3600*24;
  393. $where_sql .= " AND a.baidu_included>$dateline ";
  394. }
  395. //百度查询时间
  396. if($args['baidu_modify_dateline'] == 1 || $args['fast_search'] == 3){//从未查询
  397. $where_sql .= " AND a.baidu_modify_dateline=0 ";
  398. }else if($args['baidu_modify_dateline'] == 2){//一天以前
  399. $dateline = $_G['timestamp'] - 3600*24;
  400. $where_sql .= " AND a.baidu_modify_dateline<$dateline ";
  401. }else if($args['baidu_modify_dateline'] == 3){//一周前
  402. $dateline = $_G['timestamp'] - 3600*24*7;
  403. $where_sql .= " AND a.baidu_modify_dateline<$dateline ";
  404. }
  405. //谷歌查询时间
  406. if($args['google_modify_dateline'] == 1 ){//从未查询
  407. $where_sql .= " AND a.google_modify_dateline=0 ";
  408. }else if($args['google_modify_dateline'] == 2){//一天以前
  409. $dateline = $_G['timestamp'] - 3600*24;
  410. $where_sql .= " AND a.google_modify_dateline<$dateline ";
  411. }else if($args['google_modify_dateline'] == 3){//一周前
  412. $dateline = $_G['timestamp'] - 3600*24*7;
  413. $where_sql .= " AND a.google_modify_dateline<$dateline ";
  414. }
  415. $count = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('milu_seotool_included')." as a Inner Join ".DB::table($table)." as b ON b.$data_id_name = a.data_id $where_sql"), 0);
  416. $query = DB::query("SELECT $get_field,a.* FROM ".DB::table('milu_seotool_included')." as a Inner Join ".DB::table($table)." as b ON b.$data_id_name = a.data_id $where_sql ORDER BY b.dateline DESC LIMIT $start,$perpage");
  417. if($count){
  418. if($data_type == 1){//门户
  419. loadcache('portalcategory');
  420. $cat_arr = $_G['cache']['portalcategory'];
  421. }else{
  422. loadcache('forums');
  423. $cat_arr = $_G['cache']['forums'];
  424. }
  425. while($rs = DB::fetch($query)) {
  426. $rs = $data_type == 1 ? portal_rs_data($rs, $cat_arr) : forum_rs_data($rs, $cat_arr);
  427. $rs = format_included_rs($rs);
  428. $list[] = $rs;
  429. $data_list['included_data'][$rs['data_id']] = $rs;
  430. }
  431. }
  432. $data_list['count'] = $count;
  433. $data_list['list'] = $list;
  434. $data_list['multipage'] = multi($count, $perpage, $page, $data_arr['mpurl']);
  435. }
  436. return $data_list;
  437. }
  438. function forum_rs_data($rs, $cat_arr){
  439. global $_G;
  440. $rs['dateline'] = $rs['dateline'] ? dgmdate($rs['dateline']) : '';
  441. $rs['tid'] = $rs['tid'] ? $rs['tid'] : $rs['aid'];
  442. $rs['view_url'] = get_article_url($rs['tid']);
  443. $rs['cat_name'] = $cat_arr[$rs['fid']]['name'];
  444. $rs['cat_url'] = $_G['siteurl'].'forum.php?mod=forumdisplay&fid='.$rs['fid'];
  445. return $rs;
  446. }
  447. function included_data_forum($data_arr, $args){
  448. global $_G;
  449. $perpage = $args['perpage'];
  450. $page = $args['page'];
  451. $list = $aid_arr = array();
  452. $start = $data_arr['start'];
  453. $where_sql = '';
  454. if($args['title']){
  455. $where_sql .= " AND subject like '%".$args['title']."%'";
  456. }
  457. $count = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('forum_thread')." WHERE displayorder='0' $where_sql"), 0);
  458. $query = DB::query("SELECT tid,subject,dateline,fid FROM ".DB::table('forum_thread')." WHERE displayorder='0' $where_sql ORDER BY dateline DESC LIMIT $start,$perpage");
  459. if($count){
  460. loadcache('forums');
  461. $cat_arr = $_G['cache']['forums'];
  462. while($rs = DB::fetch($query)) {
  463. $rs['aid'] = $rs['tid'];
  464. $rs = forum_rs_data($rs, $cat_arr);
  465. $aid_arr[] = $rs['aid'];
  466. $list[] = $rs;
  467. }
  468. }
  469. $data['count'] = $count;
  470. $data['list'] = $list;
  471. $data['included_data'] = data_included_list($aid_arr, 0);
  472. $data['multipage'] = multi($count, $perpage, $page, $data_arr['mpurl']);
  473. return $data;
  474. }
  475. function data_included_list($aid_arr, $type = 0){
  476. if(!$aid_arr) return array();
  477. $query = DB::query("SELECT * FROM ".DB::table('milu_seotool_included')." WHERE data_type='$type' AND data_id IN(".dimplode($aid_arr).")");
  478. while($rs = DB::fetch($query)) {
  479. $rs = format_included_rs($rs);
  480. $data[$rs['data_id']] = $rs;
  481. }
  482. return $data;
  483. }
  484. function format_included_rs($rs){
  485. global $right_status,$notice_status;
  486. $rs['baidu_modify_dateline'] = $rs['baidu_modify_dateline'] ? dgmdate($rs['baidu_modify_dateline'], 'u') : '';
  487. $rs['google_modify_dateline'] = $rs['google_modify_dateline'] ? dgmdate($rs['google_modify_dateline'], 'u') : '';
  488. $rs['google_spider_last'] = $rs['google_spider_last'] ? dgmdate($rs['google_spider_last'], 'u') : '';
  489. $rs['google_included'] = $rs['google_included'] ? $right_status.dgmdate($rs['google_included'], 'Y-m-d') : '';
  490. if($rs['google_ping'] == -1){
  491. $rs['google_ping'] = $notice_status.stlang('fail');
  492. }else{
  493. $rs['google_ping'] = $rs['google_ping'] ? $right_status.dgmdate($rs['google_ping'], 'u') : '';
  494. }
  495. $rs['baidu_spider_last'] = $rs['baidu_spider_last'] ? dgmdate($rs['baidu_spider_last'], 'u') : '';
  496. if($rs['baidu_ping'] == -1){
  497. $rs['baidu_ping'] = $notice_status.stlang('fail');
  498. }else{
  499. $rs['baidu_ping'] = $rs['baidu_ping'] ? $right_status.dgmdate($rs['baidu_ping'], 'u') : '';
  500. }
  501. $rs['baidu_included'] = $rs['baidu_included'] ? $right_status.dgmdate($rs['baidu_included'], 'Y-m-d') : '';
  502. return $rs;
  503. }
  504. function base_data_count(){
  505. global $_G,$view_data_type,$view_types_arr,$view_search_type,$included_set,$notice_status;
  506. $info['tpl'] = 'included_count_base';
  507. $search_type = $_GET['search_type'] ? intval($_GET['search_type']) : 1;
  508. $search_name = $search_type == 1 ? 'baidu' : 'google';
  509. $class_arr = array($search_name.'_included_data');
  510. $temp_arr['all_count'][0] = get_article_count();//论坛文章数量
  511. $temp_arr['all_count'][1] = get_article_count(1);//门户文章收录
  512. $temp_arr['included_count'][0] = get_included_count(0, $search_type);//论坛文章收录数量
  513. $temp_arr['included_count'][1] = get_included_count(1, $search_type);//门户文章收录数量
  514. $temp_arr['no_included'][0] = $temp_arr['all_count'][0] - $temp_arr['included_count'][0];//论坛文章未收录数量
  515. $temp_arr['no_included'][1] = $temp_arr['all_count'][1] - $temp_arr['included_count'][1];//门户文章未收录数量
  516. $temp_arr['count_percent'][0] = $temp_arr['included_count'][0] / $temp_arr['all_count'][0];//论坛文章收录文章占总数
  517. $temp_arr['count_percent'][0] = sprintf("%01.0f", $temp_arr['count_percent'][0]*100).'%';
  518. $temp_arr['count_percent'][1] = $temp_arr['included_count'][1] / $temp_arr['all_count'][1];//门户文章收录文章占总数
  519. $temp_arr['count_percent'][1] = sprintf("%01.0f", $temp_arr['count_percent'][1]*100).'%';
  520. $temp_arr['hour_included_count'][0] = get_included_count(0, $search_type, 1);//论坛文章24小时收录数量
  521. $temp_arr['hour_included_count'][1] = get_included_count(1, $search_type, 1);//门户文章24小时收录数量
  522. $cache_ttl = 3600*2;
  523. if(!($data_arr = st_load_cache($search_name.'_included_data')) || $_GET['clear_cache'] == 1){
  524. $data_arr[$search_name.'_included_data'] = array(
  525. 0 => array(
  526. 'name' => '',
  527. 'value' => array(stlang('forum_article'), stlang('portal_article')),
  528. ),
  529. 1 => array(
  530. 'name' => stlang('article_all_count'),
  531. 'value' => array($temp_arr['all_count'][0], $temp_arr['all_count'][1]),
  532. ),
  533. 2 => array(
  534. 'name' => stlang('all_included_count'),
  535. 'value' => array($temp_arr['included_count'][0], $temp_arr['included_count'][1]),
  536. ),
  537. 3 => array(
  538. 'name' => stlang('no_included_count'),
  539. 'value' => array($temp_arr['no_included'][0], $temp_arr['no_included'][1]),
  540. ),
  541. 4 => array(
  542. 'name' => stlang('included_all_count_percent'),
  543. 'value' => array($temp_arr['count_percent'][0], $temp_arr['count_percent'][1]),
  544. ),
  545. 5 => array(
  546. 'name' => stlang('24hour_included_count'),
  547. 'value' => array($temp_arr['hour_included_count'][0], $temp_arr['hour_included_count'][1]),
  548. ),
  549. );
  550. $data_arr['dateline'] = $_G['timestamp'];
  551. st_cache_data($search_name.'_included_data', $data_arr, $cache_ttl);
  552. }
  553. $info['cache_dateline'] = dgmdate($data_arr['dateline']);
  554. $info['next_dateline'] = dgmdate($data_arr['dateline'] + $cache_ttl);
  555. unset($data_arr['dateline']);
  556. $show_arr[] = array();
  557. foreach($class_arr as $k => $v){
  558. $show_arr[$k] = seoOutput::show_table($data_arr, $v);
  559. }
  560. //状态数据
  561. $cron_info = tool_common_get('milu_seotool_cron');
  562. $included_set['auto_check_time'] = $included_set['auto_check_time'] ? $included_set['auto_check_time'] : 12;
  563. if($included_set['is_auto_check'] == 2){
  564. $info['status']['auto_check'] = $notice_status.stlang('closed_');
  565. }else{
  566. $info['status']['auto_check'] = run_status_output($included_set['auto_check_time'], 3600, $cron_info['included_check']);
  567. }
  568. if($included_set['is_auto_ping'] == 2){
  569. $info['status']['auto_ping'] = $notice_status.stlang('closed_');
  570. }else{
  571. $info['status']['auto_ping'] = run_status_output($included_set['auto_ping_time'], 60, $cron_info['ping_check']);
  572. }
  573. $info['show'] = implode('', $show_arr);
  574. $info['search_type'] = $search_type;
  575. return $info;
  576. }
  577. function run_status_output($check_time, $check_time_flag, $now_run = ''){
  578. $check_time_flag_str = $check_time_flag == '3600' ? stlang('_hour') : stlang('_minute');
  579. $old_now_run = $now_run;
  580. $now_run = $now_run ? $now_run - $check_time * $check_time_flag : '';
  581. $next_run = $old_now_run ? $old_now_run : '';
  582. $next_run = $next_run ? dgmdate($next_run) : stlang('be_run');
  583. $now_run = $now_run ? dgmdate($now_run) : stlang('no_have');
  584. $show_str = stlang('last_run').':<font>'.$now_run.'</font> '.stlang('next_run').':<font>'.$next_run.'</font>'.stlang('per_time').'<font>'.$check_time.'</font>'.$check_time_flag_str.stlang('run_one_times');
  585. return $show_str;
  586. }
  587. //数据趋势
  588. function trend_data_count(){
  589. global $_G,$view_data_type,$view_types_arr,$view_search_type;
  590. $view_info['data_types'] = $_POST['data_types'] ? $_POST['data_types'] : array(1, 2);
  591. $view_info['search_types'] = $_POST['search_types'] ? $_POST['search_types'] : array(1);
  592. $view_info['view_types'] = $_POST['view_types'] ? $_POST['view_types'] : array(1);
  593. $view_info['start_dateline'] = $_POST['start_dateline'] ? strtotime($_POST['start_dateline']) : '';
  594. $view_info['end_dateline'] = $_POST['end_dateline'] ? strtotime($_POST['end_dateline']) : '';
  595. $view_info['start_dateline'] = $view_info['start_dateline'] ? $view_info['start_dateline'] : $_G['timestamp'] - 3600*24*7;
  596. $view_info['end_dateline'] = $view_info['end_dateline'] ? $view_info['end_dateline'] : $_G['timestamp'];
  597. $dateline_arr = st_dayRange($view_info['start_dateline'], $view_info['end_dateline']);
  598. $from = $dateline_arr[1]['from'];
  599. $end = $dateline_arr[count($dateline_arr)]['end'];
  600. //$sql .= 'WHERE '
  601. $search_type_flag = in_array(2, $view_info['search_types']);
  602. $data_types_flag = in_array(2, $view_info['data_types']);
  603. $view_types_flag = in_array(2, $view_info['view_types']);
  604. $temp_end = $end + 1;
  605. $temp_from = $from - 1;
  606. if(count($view_info['search_types']) < 2){//搜索引擎
  607. $search_name = $search_type_flag ? 'google_included' : 'baidu_included';
  608. $sql = " WHERE $search_name<$temp_end AND $search_name>$temp_from ";
  609. }else{
  610. $sql = " WHERE (baidu_included<$temp_end AND baidu_included<$temp_from) OR (google_included<$temp_end OR google_included>$temp_from) ";
  611. }
  612. if(count($view_info['data_types']) < 2){//数据类型
  613. $sql .= in_array(2, $view_info['data_types']) ? " AND data_type='1'" : "AND data_type='0'";
  614. }
  615. if($view_types_flag){
  616. $where_sql = " AND dateline<'$temp_end' AND dateline>'$temp_from'";
  617. //查询文章总数
  618. if(in_array(2, $view_info['data_types'])){//门户
  619. $query = DB::query("SELECT dateline FROM ".DB::table('portal_article_title'). " WHERE status='0' $where_sql");
  620. while($rs = DB::fetch($query)) {
  621. foreach($dateline_arr as $k => $v){
  622. if($rs['dateline'] < $v['end'] && $rs['dateline'] > $v['from']){
  623. $dateline_arr[$k]['article_count']['portal']++;
  624. }
  625. }
  626. }
  627. }
  628. if(in_array(1, $view_info['data_types'])){//论坛
  629. $query = DB::query("SELECT dateline FROM ".DB::table('forum_thread'). " WHERE displayorder='0' $where_sql");
  630. while($rs = DB::fetch($query)) {
  631. foreach($dateline_arr as $k => $v){
  632. if($rs['dateline'] < $v['end'] && $rs['dateline'] > $v['from'] ){
  633. $dateline_arr[$k]['article_count']['bbs']++;
  634. }
  635. }
  636. }
  637. }
  638. }
  639. $query = DB::query("SELECT baidu_included,baidu_spider_count,data_type,google_included,google_spider_count,data_type FROM ".DB::table('milu_seotool_included').$sql);
  640. while($rs = DB::fetch($query)) {
  641. foreach($dateline_arr as $k => $v){
  642. $data_type_name = $rs['data_type'] == 1 ? 'portal' : 'bbs';
  643. $v['end'] +=1;
  644. $v['from'] -=1;
  645. if($rs['baidu_included'] < $v['end'] && $rs['baidu_included'] > $v['from']){//百度收录
  646. $dateline_arr[$k]['included']['baidu'][$data_type_name]++;
  647. }
  648. if($rs['google_included'] < $v['end'] && $rs['google_included'] > $v['from']){//谷歌收录
  649. $dateline_arr[$k]['included']['google'][$data_type_name]++;
  650. }
  651. }
  652. }
  653. $title = date('Y-m-d', $from).' '.stlang('_to').' '.date('Y-m-d', $end). ' '.stlang('trend_flash_title');
  654. $FC = get_flash_obj(array('caption_title' => $caption_title, 'title' => $title, 'width' => '100%', 'height' => 400, 'yAxisName' => '', 'decimals' => 1));
  655. $view_data_arr = array('bbs' => stlang('bbs'), 'portal' => stlang('portal'));
  656. if(!VIP) unset($view_data_arr['portal']);
  657. $search_type_arr = array('baidu' => stlang('baidu'), 'google' => stlang('google'));
  658. $temp_view_types_arr = array('included' => stlang('in_count'), 'included_percent' => stlang('in_percent'));
  659. if(!in_array(1, $view_info['data_types'])) unset($view_data_arr['bbs']);
  660. if(!in_array(2, $view_info['data_types'])) unset($view_data_arr['portal']);
  661. if(!in_array(1, $view_info['search_types'])) unset($search_type_arr['baidu']);
  662. if(!in_array(2, $view_info['search_types'])) unset($search_type_arr['google']);
  663. if(!in_array(1, $view_info['view_types'])) unset($temp_view_types_arr['included']);
  664. if(!in_array(2, $view_info['view_types'])) unset($temp_view_types_arr['included_percent']);
  665. $flag = '';
  666. foreach($view_data_arr as $k1 => $v1){
  667. foreach($search_type_arr as $k2 => $v2){
  668. foreach($temp_view_types_arr as $k3 => $v3){
  669. $FC->addDataset($v1.$v2.$v3);
  670. foreach($dateline_arr as $k => $v){
  671. $key_str = $k1.$k2.$k3;
  672. $flag = $flag ? $flag : $key_str;
  673. if($flag && $key_str == $flag) $FC->addCategory($v['name']);
  674. if($k3 == 'included'){//收录
  675. $FC->addChartData($v[$k3][$k2][$k1]);
  676. }
  677. if($k3 == 'included_percent'){//收录率
  678. $article_count = $v['article_count'][$k1];
  679. $percent = $article_count > 0 ? $v['included'][$k2][$k1]/$v['article_count'][$k1] : 0;
  680. $percent = round($percent, 1);
  681. $percent = $percent > 1 ? 1 : $percent;
  682. //$percent = sprintf("%01.0f", $percent*100).'%';
  683. $FC->addChartData($percent);
  684. }
  685. }
  686. }
  687. }
  688. }
  689. $info['chart_flash'] = $FC->renderChart("", false);
  690. $info['show'] = implode('', $show_arr);
  691. if(!VIP) unset($view_data_type[2]);
  692. $info['view_show']['data_type'] = seoOutput::checkbox( array('name' => 'data_types', 'option_arr' => $view_data_type), $view_info);
  693. $info['view_show']['search_type'] = seoOutput::checkbox( array('name' => 'search_types', 'option_arr' => $view_search_type), $view_info);
  694. $info['view_show']['view_type'] = seoOutput::checkbox( array('name' => 'view_types', 'option_arr' => $view_types_arr), $view_info);
  695. $info['start_dateline'] = date('Y-m-d', $view_info['start_dateline']);
  696. $info['end_dateline'] = date('Y-m-d', $view_info['end_dateline']);
  697. $info['tpl'] = 'included_count_trend';
  698. return $info;
  699. }
  700. //data_type 0论坛 1门户 search_type 1 百度 2谷歌
  701. function get_included_count($data_type = 0, $search_type = 1, $flag = 0){
  702. global $_G;
  703. $search_name = $search_type == 2 ? 'google_included' : 'baidu_included';
  704. $dateline = $_G['timestamp'] - 3600*24;
  705. $sql = $flag == 1 ? " AND $search_name >$dateline" : '';
  706. return DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('milu_seotool_included')." WHERE data_type='$data_type' AND $search_name>0 $sql"), 0);
  707. }
  708. ?>