/**
  * search the articles list for metabax
  * get_metabox_articles
  * @static
  * @return array
  */
 public static function get_metabox_articles()
 {
     $pagesize = 10;
     $page = absint($_POST['page']);
     $offset = ($page - 1) * $pagesize;
     $query = isset($_POST['query']) ? strip_tags($_POST['query']) : "";
     $fields = array('article.guid', 'article.description', 'article.title', 'article.published_at', 'article.source.name', 'article.tracking_pixel', 'article.topic.name', 'article.categories.dashed_name', 'article.categories.name', 'article.author.name', 'article.image.guid', 'article.image.caption', 'article.image.description', 'article.image.height', 'article.image.width', 'article.image.published_at', 'article.image.source.name', 'article.image.urls.large');
     $options = array('fields' => $fields, 'pagesize' => $pagesize, 'offset' => $offset);
     $sort = isset($_POST['sort']) ? trim(strip_tags($_POST['sort'])) : null;
     if ($sort && ($sort == "date" || $sort == "relevance")) {
         $options['sort'] = sanitize_text_field($sort);
     }
     $sources = isset($_POST['sources']) ? $_POST['sources'] : null;
     if ($sources) {
         $options['sources'] = $sources;
     }
     $topics = isset($_POST['topics']) ? $_POST['topics'] : null;
     if ($topics) {
         $options['topics'] = $topics;
     }
     if (get_option('nc_article_has_images')) {
         $options['has_images'] = "true";
     }
     if (get_option('nc_article_fulltext')) {
         $options['fulltext'] = "true";
     }
     $articles = array();
     try {
         $articles = NC_Plugin_Article::search(NC_ACCESS_KEY, $query, $options);
     } catch (NC_Plugin_Exception $e) {
         return $articles;
     }
     return $articles;
 }
 /**
  * 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);
     }
 }
 /**
  * createApiCall
  * create a NewsCred API for myfeeds
  */
 function create_api_call()
 {
     global $nc_controller;
     // check nonce and capability
     if (!$nc_controller->check_nonce_capability("nc_create_apicall_nonce")) {
         exit;
     }
     $pagesize = 10;
     $offset = 0;
     $fields = array('article.guid', 'article.description', 'article.title', 'article.published_at', 'article.source.name', 'article.tracking_pixel', 'article.topic.name', 'article.categories.dashed_name', 'article.categories.name', 'article.author.name', 'article.image.guid', 'article.image.caption', 'article.image.description', 'article.image.height', 'article.image.width', 'article.image.published_at', 'article.image.source.name', 'article.image.urls.large');
     $options = array('fields' => $fields, 'get_topics' => true);
     if (!empty($_POST['categories'])) {
         $options['categories'] = $_POST['categories'];
     }
     if (!empty($_POST['source_guids'])) {
         $options['sources'] = sanitize_text_field($_POST['source_guids']);
     }
     if (!empty($_POST['source_filter_name'])) {
         $options['source_filter_name'] = sanitize_text_field($_POST['source_filter_name']);
         $options['source_filter_mode'] = "whitelist";
     }
     if (!empty($_POST['topic_guids'])) {
         $options['topics'] = sanitize_text_field($_POST['topic_guids']);
     }
     if (!empty($_POST['topic_filter_name'])) {
         $options['topic_filter_name'] = sanitize_text_field($_POST['topic_filter_name']);
         $options['topic_filter_mode'] = "whitelist";
     }
     if (isset($_POST['has_images'])) {
         $options['has_images'] = "true";
     }
     if (isset($_POST['fulltext'])) {
         $options['fulltext'] = "true";
     }
     echo NC_Plugin_Article::api_call(NC_ACCESS_KEY, $options);
     exit;
 }
 /**
  * @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;
 }