public static function pvc_backbone_load_stats() { $post_ids = $_REQUEST['post_ids']; $data = array(); $ids = array(); if (is_array($post_ids) && count($post_ids) > 0) { foreach ($post_ids as $post_id => $post_data) { $ids[] = $post_id; if (isset($post_data['ask_update']) && $post_data['ask_update'] == 'true') { A3_PVC::pvc_stats_update($post_id); } } $results = A3_PVC::pvc_fetch_posts_stats($ids); if ($results) { foreach ($results as $result) { $data[$result->post_id] = array('post_id' => (int) $result->post_id, 'total_view' => (int) $result->total, 'today_view' => (int) $result->today); $ids = array_diff($ids, array($result->post_id)); } } foreach ($ids as $post_id) { $total = A3_PVC::pvc_fetch_post_total($post_id); $data[$post_id] = array('post_id' => (int) $post_id, 'total_view' => (int) $total, 'today_view' => 0); } } header('Content-Type: application/json', true, 200); die(json_encode($data)); }