function run_timing($a) { global $_G; $timestamp = TIMESTAMP; $processname = 'TIMING_CRON_CHECK'; $check = DB::result(DB::query("SELECT COUNT(*) FROM " . DB::table('strayer_timing') . " WHERE public_dateline<='{$timestamp}' "), 0); if ($check) { discuz_process::unlock($processname); } if (discuz_process::islocked($processname, 600)) { return false; } if (!$check) { return FALSE; } @set_time_limit(1000); @ignore_user_abort(TRUE); //防止发生异常,先预订一个1小时的总时间,假如发布文章需要2小时才完成。还未到2小时,又被触发了,这样会造成文章的重复发布 save_syscache('pick_timing', TIMESTAMP + 60 * 60 * 1); $optype_arr = array(1 => 'move_portal', 2 => 'move_forums', 3 => 'move_blog'); $query = DB::query("SELECT * FROM " . DB::table('strayer_timing') . " WHERE public_dateline<='{$timestamp}' ORDER by public_dateline"); $timing_aid_arr = $tid_arr = $args = array(); while ($rs = DB::fetch($query)) { $timing_aid_arr[] = dstripslashes($rs); $tid_arr[] = $rs['id']; } if (!$timing_aid_arr) { return; } pload('F:article,F:pick'); article_timing_delete($tid_arr); //不管有没有发布成功,先清理掉定时发布表里面的数据,防止文章又被重复检测到 foreach ($timing_aid_arr as $k => $rs) { $args = unserialize($rs['public_info']); $args['aid'] = array($rs['data_id']); $args['pid'] = $rs['pid']; $args['timing'] = 1; $args['cron_run'] = 1; $args['public_time'][$rs['data_id']] = $rs['public_dateline']; article_import($optype_arr[$rs['public_type']], $args); } save_syscache('pick_timing', TIMESTAMP + 600); //成功运行,时间按正常设置 discuz_process::unlock($processname); return true; }
function article_batch() { global $_G; $aid_arr = $_GET['aid']; $is_public_del = $_GET['is_public_del']; if (!VIP) { $today_arr = dunserialize(pick_common_get('', 'pick_today')); if ($today_arr['day'] != date('md', $_G['timestamp'])) { $c_set['pick_today'] = array(); pick_common_set($c_set); } else { $article_public_num = $today_arr['article_public_num']; if ($article_public_num > 10000) { cpmsg_error(milu_lang('article_public_limit', array('n' => 10000))); } } } extract($_GET); extract($set); $public_start_time = strtotime($public_start_time); $public_end_time = strtotime($public_end_time); $args_arr = array('optype', 'pid', 'is_public_del', 'article_public_sort', 'is_public_del', 'public_start_time', 'public_end_time', 'status', 's', 'ordersc', 'orderby', 'time_public', 'portal', 'forums', 'threadtypeid', 'blog', 'perpage', 'oparea', 'article_batch_num', 'move_pid', 'p'); $args_url = ''; foreach ($args_arr as $k => $v) { $args_url .= '&' . $v . '=' . ${$v}; } //$args_url .= '&myac=' //echo $args_url;exit(); $from_url = PICK_GO . "picker_manage&myac=article_manage&finished=1" . $args_url; if ($_GET['finished']) { cpmsg(milu_lang('run_finsh'), $from_url, 'succeed'); } if (!$_GET['confirmed']) { $article_batch_num = $setrr['article_batch_num'] = $article_batch_num ? $article_batch_num : 15; pick_common_set($setrr); if (!$optype) { cpmsg_error(milu_lang('must_select_optype')); } if ($oparea == 'selected') { if (!$aid_arr) { cpmsg_error(milu_lang('must_select_data')); } $aid_str = base64_encode(serialize($aid_arr)); $total = count($aid_arr); } else { if ($oparea == 'all') { $total = article_count($pid, $status, array('s' => $s)); } } pcpmsg_loading(milu_lang('bat_import_article', array('a' => $article_batch_num, 't' => $total)), $from_url, 'loadingform', '', '<div id="percent">0%</div>', FALSE); $ajax_url = "admin.php?" . PICK_GO . "picker_manage&myac=ajax_func&inajax=1&af=" . $myac . "&tpl=no&confirmed=1&oparea={$oparea}&aid={$aid_str}" . $args_url; $finsh_url = "admin.php?" . PICK_GO . "picker_manage&myac=article_manage&finished=1" . $args_url; //echo $ajax_url;exit(); echo pick_loading($ajax_url, $finsh_url, $total, array('bat_num' => $article_batch_num)); } else { ob_end_clean(); $total = intval($_GET['total']); $pp = intval($_GET['pp']); $pid = intval($_GET['pid']); $currow = intval($_GET['currow']); $oparea = $_GET['oparea']; $public_sort = $_GET['public_sort']; $public_sort = $public_sort == 1 ? 'asc' : 'desc'; if ($oparea == 'selected') { $aid_arr = unserialize(base64_decode($aid)); $where = $optype == 'timing_delete' ? " AND t.id IN (" . dimplode($aid_arr) . ") " : " AND aid IN (" . dimplode($aid_arr) . ") "; } else { if ($oparea == 'all') { $where = $optype == 'timing_delete' ? " AND a.title like '%" . $_GET['s'] . "%' " : " AND title like '%" . $_GET['s'] . "%' "; } } $aid_arr = array(); if ($is_public_del == 1 && ($optype == 'move_portal' || $optype == 'move_forums' || $optype == 'move_blog') || $optype == 'delete') { $currow = 0; } if ($optype == 'timing_delete') { $query = DB::query("SELECT a.aid,t.id, t.data_id FROM " . DB::table('strayer_timing') . " t Inner Join " . DB::table('strayer_article_title') . " a ON a.aid = t.data_id WHERE t.pid='{$pid}' {$where} ORDER by t.data_id LIMIT {$currow},{$pp}"); while ($rs = DB::fetch($query)) { if ($rs['aid']) { DB::update('strayer_article_title', array('status' => 1), array('aid' => $rs['aid'])); } $aid_arr[] = $rs['id']; } } else { $query = DB::query("SELECT aid FROM " . DB::table('strayer_article_title') . " WHERE pid='{$pid}' {$where} ORDER by dateline " . $public_sort . " LIMIT {$currow},{$pp}"); while ($rs = DB::fetch($query)) { $aid_arr[] = $rs['aid']; } } if ($optype == 'move_portal' || $optype == 'move_forums' || $optype == 'move_blog') { article_import($_GET['optype'], array('aid' => $aid_arr)); } else { $action = 'article_' . $optype; $action($aid_arr, $pid); } if ($currow + $pp > $total) { echo 'TRUE'; exit; } echo 'GO'; exit; } }