/** * insert_article_guid * * insert articel guid * into nc_myfeeds_publish post type * * @param $url * @param $id */ public function insert_article_guid($url, $id) { $myfeeds_guids = NC_Plugin_Article::search_by_url(NC_ACCESS_KEY, $url); if ($myfeeds_guids) { foreach ($myfeeds_guids as $guid) { // Create nc_myfeeds_publish custom post object $my_post = array('post_type' => 'nc_myfeeds_publish', 'post_parent' => $id, 'post_content' => $guid->guid); // Insert the post into the database $myfeed_publish_id = wp_insert_post($my_post); } $publish_time = date("Y-m-d H:i:s", time()); $myfeed_data = get_post_meta($id, "_ncmyfeed_attr", true); $myfeed_data['publish_time'] = $publish_time; $myfeed_data['update_time'] = $publish_time; update_post_meta($id, '_ncmyfeed_attr', $myfeed_data); } }
/** * @return array */ function myfeeds() { $myfeed_id = intval($_POST['myfeed_id']); if (!$myfeed_id) { echo "null"; exit; } $pagesize = 10; $page = absint($_POST['page']); $offset = ($page - 1) * $pagesize; $query = isset($_POST['query']) ? strip_tags($_POST['query']) : ""; $sources = isset($_POST['sources']) ? trim(strip_tags($_POST['sources'])) : null; $source_str = ""; if ($sources) { $source_str = "&sources=" . implode(" ", $sources); } $topics = isset($_POST['topics']) ? trim(strip_tags($_POST['topics'])) : null; $topics_str = ""; if ($topics) { $topics_str = "&topics=" . implode(" ", $topics); } $sort_str = ""; $sort = isset($_POST['sort']) ? trim(strip_tags($_POST['sort'])) : null; if ($sort && ($sort == "date" || $sort == "relevance")) { $sort_str = '&sort=' . $sort; } $result = (object) get_post_meta($myfeed_id, '_ncmyfeed_attr', true); $apicall = $result->apicall; if ($apicall) { if ($query) { $apicall .= "&query=" . $query . $source_str . $topics_str; } $apicall .= $source_str . $topics_str . $sort_str . "&pagesize=" . $pagesize . "&offset=" . $offset; $myfeed_results = array(); try { $myfeed_results = NC_Plugin_Article::search_by_url(NC_ACCESS_KEY, $apicall); if ($myfeed_results) { return $myfeed_results; } } catch (NC_Plugin_Exception $e) { return $myfeed_results; } } return; }