Example #1
0
 function testMakeExcerptReturns55WordsIfNegativeNumberOfWordsSpecified()
 {
     // Arrange
     $this->post->post_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tellus est, euismod ut massa luctus, ornare mollis erat. Quisque eu felis auctor neque consectetur venenatis. Pellentesque vestibulum velit nec vehicula consectetur. Praesent dictum vulputate nisl, nec ornare sem lobortis ac. Ut rhoncus purus tellus, sit amet auctor nisi consectetur non. Donec posuere nunc at odio fringilla, et sagittis elit porta.';
     $expectedExcerpt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tellus est, euismod ut massa luctus, ornare mollis erat. Quisque eu felis auctor neque consectetur venenatis. Pellentesque vestibulum velit nec vehicula consectetur. Praesent dictum vulputate nisl, nec ornare sem lobortis ac. Ut rhoncus purus tellus, sit amet auctor nisi consectetur non. Donec posuere nunc at odio...';
     // Act
     $actualExcerpt = tls_make_post_excerpt($this->post->post_content, -10);
     // Assert
     $this->assertEquals($expectedExcerpt, $actualExcerpt);
 }
/**
 * Blogs Archive Page Template JSON API Response Modifications
 *
 * @param $response     The JSON API Response Object
 *
 * @return $response    Update JSON API Response Object
 */
function tls_blogs_archive_json_api_encode($response)
{
    if (isset($response['page']) && $response['page_template_slug'] == 'template-blogs-archive.php') {
        // Globals to be used with many of the specific searches
        global $json_api, $wp_query;
        // Page ID
        $page_id = $response['page']->id;
        /**
         * ===========================================
         *              Featured Blog Post
         * ===========================================
         */
        // Get Featured Post Details
        $featured_post = get_field('featured_blog_post', $page_id);
        // Get Featured Post Category
        $featured_post_category = wp_get_post_terms($featured_post[0]->ID, 'category');
        $attachment_id = get_post_thumbnail_id($featured_post[0]->ID);
        $featured_post_hero_image = wp_get_attachment_image_src($attachment_id, 'full');
        $response['featured_post'] = array('type' => $featured_post_category[0]->slug == 'a-dons-life' || $featured_post_category[0]->slug == 'dons-life' ? 'dons_life_blog' : str_replace('-', '_', $featured_post_category[0]->slug) . '_blog', 'id' => $featured_post[0]->ID, 'title' => get_the_title($featured_post[0]->ID), 'excerpt' => tls_make_post_excerpt($featured_post[0]->post_content, 30), 'link' => get_permalink($featured_post[0]->ID), 'hero_image' => esc_url($featured_post_hero_image[0]));
        /**
         * ===========================================
         *              Spotlight Podcast
         * ===========================================
         */
        $spotlight_podcast = get_field('spotlight_podcast', $page_id);
        $spotlight_podcast_custom_fields = get_post_custom($spotlight_podcast[0]->ID);
        $response['posts'][] = array('type' => 'listen_blog', 'id' => $spotlight_podcast[0]->ID, 'title' => get_the_title($spotlight_podcast[0]->ID), 'link' => get_permalink($spotlight_podcast[0]->ID), 'soundcloud' => $spotlight_podcast_custom_fields['soundcloud_embed_code'][0]);
        /**
         * ===========================================
         *              Blog Posts Archive
         * ===========================================
         */
        // Get Blog Archive excluding Featured Blog from list
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $blogs_archive_args = array('post_type' => array('post'), 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'post__not_in' => array($featured_post[0]->ID, $spotlight_podcast[0]->ID));
        $wp_query->query = $blogs_archive_args;
        $blogs_archive = $json_api->introspector->get_posts($wp_query->query);
        foreach ($blogs_archive as $blog_post) {
            $categories = wp_get_post_terms($blog_post->id, 'category');
            $blog_post_custom_fields = get_post_custom($blog_post->id);
            $blog_post->soundcloud = $blog_post_custom_fields['soundcloud_embed_code'][0];
            $blog_post->category_url = get_term_link($categories[0]->term_id, $categories[0]->taxonomy);
            if ($categories[0]->slug == 'a-dons-life' || $categories[0]->slug == 'dons-life') {
                $blog_post->type = 'dons_life_blog';
            } else {
                $blog_post->type = str_replace('-', '_', $categories[0]->slug) . '_blog';
            }
            $response['posts'][] = $blog_post;
        }
        $response['count'] = count($blogs_archive);
        $response['count_total'] = (int) $wp_query->found_posts;
        $response['pages'] = $wp_query->max_num_pages;
    }
    // If it is archive of blogs (post type 'post') create new excerpt
    if ($response['posts']) {
        foreach ($response['posts'] as $response_post) {
            if ('post' == get_post_type($response_post->id)) {
                $response_post->excerpt = tls_make_post_excerpt($response_post->content, 30);
                $blog_post_thumb = wp_get_attachment_image_src(get_post_thumbnail_id($response_post->id));
                if ($blog_post_thumb !== false || $blog_post_thumb !== null) {
                    $response_post->thumbnail = $blog_post_thumb[0];
                }
            }
        }
    }
    return $response;
}
/**
 * Home Page Template JSON API Response Modifications
 *
 * @param $response     JSON API Response Object
 *
 * @return Object       Updated JSON API Response Object
 */
function tls_home_page_json_api_encode($response)
{
    if (isset($response['page']) && $response['page_template_slug'] == 'template-home.php') {
        // Get Home Page ID for this page using Template Home Page Template
        $home_page_id = $response['page']->id;
        // Get Featured Post Details
        $featured_article = get_field('featured_article', $home_page_id);
        $hero_image_url = '';
        if (get_field('hero_image_url', $featured_article[0]->ID)) {
            $hero_image = get_field('hero_image_url', $featured_article[0]->ID);
            $hero_image_url = $hero_image['url'];
        } else {
            if (get_field('full_image_url', $featured_article[0]->ID)) {
                $hero_image = get_field('full_image_url', $featured_article[0]->ID);
                $hero_image_url = $hero_image['url'];
            }
        }
        if (get_field('teaser_summary', $featured_article[0]->ID)) {
            $text = get_field('teaser_summary', $featured_article[0]->ID);
        } else {
            $text = tls_make_post_excerpt($featured_article[0]->post_content, 30);
        }
        $response['featured_article'] = array('id' => $featured_article[0]->ID, 'title' => get_the_title($featured_article[0]->ID), 'author' => get_the_author_meta('display_name', $featured_article[0]->post_author), 'text' => $text, 'link' => get_permalink($featured_article[0]->ID), 'hero_image' => esc_url($hero_image_url));
        /**
         * Home Page Blog Cards (For the 2 first Blog Cards)
         */
        $blog_cards = get_field('blogs_cards', $home_page_id);
        foreach ((array) $blog_cards as $blog_card) {
            // Get the categories for the Blog Post
            $categories = wp_get_post_terms($blog_card->ID, 'category');
            // Get the blog post featured image as thumbnail and then get the URL for it
            $thumbnail_id = get_post_thumbnail_id($blog_card->ID);
            $thumbnail_array = wp_get_attachment_image_src($thumbnail_id, 'thumbnail');
            // Add Blog Post Cards to JSON Response in the first card slot
            $response['home_page_cards']['card_0'][] = array('type' => 'blog', 'id' => $blog_card->ID, 'title' => get_the_title($blog_card->ID), 'author' => array('name' => get_the_author_meta('display_name', $blog_card->post_author), 'slug' => get_the_author_meta('user_nicename', $blog_card->post_author)), 'text' => tls_make_post_excerpt($blog_card, 15), 'link' => get_permalink($blog_card->ID), 'section' => array('name' => $categories[0]->name, 'link' => get_term_link($categories[0]->term_id, $categories[0]->taxonomy)), 'thumbnail' => $thumbnail_array[0]);
        }
        /**
         * Home Page Cards (For the rest of the home page cards)
         */
        $home_page_cards = get_field('home_page_cards', $home_page_id);
        // Start the Cards at 1 since the Home Page Blog Cards already took the place 0
        $home_page_card_count = 1;
        foreach ((array) $home_page_cards as $home_page_card) {
            // Variable that grabs Card Type from Custom fields
            $card_type = $home_page_card['card_type'];
            // Variable that gets the post for the Card Type and adds _post to match the Post Object Custom field in the backend
            $card_post = $home_page_card[$card_type . '_post'][0];
            // If Card Type is Article the create variable $section with the article-section taxonomy otherwise use the taxonomy category
            if ($card_type == 'article') {
                $section = wp_get_post_terms($card_post->ID, 'article_section');
                $visibility = wp_get_post_terms($card_post->ID, 'article_visibility');
            } else {
                $section = wp_get_post_terms($card_post->ID, 'category');
            }
            // Get Custom Field Value using WP get_post_custom to return correct HTML output
            // because ACF get_field in the JSON API was returning all the tags with HTML stripped and encoded
            $card_post_custom_fields = get_post_custom($card_post->ID);
            $card_post_soundcloud_custom_field = $card_post_custom_fields['soundcloud_embed_code'];
            $teaserSummary = $card_post_custom_fields['teaser_summary'];
            // IF there is a teaser use it otherwise make one
            if (!empty($teaserSummary)) {
                $articleText = $teaserSummary;
            } else {
                $articleText = tls_make_post_excerpt($card_post->post_content, 30);
            }
            $card_post_full_image = get_field('field_54e4d4a5b009b', $card_post->ID);
            $card_post_thumbnail_image = get_field('field_54e4d481b009a', $card_post->ID);
            $thumbnail_image = '';
            if ($card_post_thumbnail_image) {
                $thumbnail_image = $card_post_thumbnail_image['url'];
            } else {
                if ($card_post_full_image) {
                    $thumbnail_image = $card_post_full_image['url'];
                }
            }
            // Add Cards to the JSON Response in the specific count slot
            $response['home_page_cards']['card_' . $home_page_card_count] = array('type' => $card_type, 'id' => $card_post->ID, 'title' => get_the_title($card_post->ID), 'author' => get_the_author_meta('display_name', $card_post->post_author), 'excerpt' => $articleText, 'link' => get_permalink($card_post->ID), 'section' => array('name' => $section[0]->name, 'link' => get_term_link($section[0]->term_id, $section[0]->taxonomy)), 'soundcloud' => $card_post_soundcloud_custom_field[0], 'custom_fields' => array('thumbnail_image_url' => $thumbnail_image), 'image_url' => $thumbnail_image, 'books' => get_field('field_54edde1e60d80', $card_post->ID), 'taxonomy_article_visibility' => $visibility);
            // If the current Home Page card is a Blog Post
            if (get_post_type($card_post->ID) == "post") {
                // Get a blog post's featured image as a thumbnail and then get its URL
                $card_thumbnail_id = get_post_thumbnail_id($card_post->ID);
                $card_thumbnail_array = wp_get_attachment_image_src($card_thumbnail_id, 'thumbnail');
                // Add a thumbnail to the JSON Response only for the Blog posts
                $response['home_page_cards']['card_' . $home_page_card_count]['thumbnail'] = $card_thumbnail_array[0];
            }
            // END If
            // Iterate to next count slot
            $home_page_card_count++;
        }
    }
    return $response;
}
Example #4
0
 /**
  * Method to parse each article entry from the XML feed and save all its data, taxonomy terms and custom fields
  *
  * @param $article
  *
  * @return int $articleCount    The count of how many articles were parsed to be returned back to parseFeed
  */
 protected function parseArticles($article)
 {
     // Start the articleCount variable
     $articleCount = 0;
     // Get all cpi: nodes from the XML
     $cpiNamespace = $article->children('cpi', true);
     // Get Article Entry ID from the URL in the id node
     // ID after the last slash /
     $article_id_url = explode('/', $article->id);
     $article_entry_id = trim(array_pop($article_id_url));
     // Add try catch in order to show possible date format erros on CMS Log
     try {
         $article_entry_published = new Carbon($article->published);
         $article_entry_updated = new Carbon($article->updated);
     } catch (Exception $e) {
         HubLogger::error('ArticleID: ' . $article->id . ' Date Published: ' . $article->published . ' Date Updated: ' . $article->updated . "\t" . 'Date Error: ' . $e->getMessage());
     }
     $article_content_copy = html_entity_decode(htmlspecialchars_decode($cpiNamespace->copy), ENT_QUOTES, 'UTF-8');
     $article_content_copy = trim(preg_replace('/\\s+/', ' ', $article_content_copy));
     /*
      * Prepare and make WP_Query to check if the article being parsed already exists in WP
      * based on the ID in the XML Feed entry
      */
     $articleMatches_args = array('posts_per_page' => 1, 'post_type' => 'tls_articles', 'meta_key' => 'article_feed_id', 'meta_value' => (string) $article_entry_id);
     $articleMatches = new WP_Query($articleMatches_args);
     if ($articleMatches->found_posts > 0) {
         $last_updated_date = new Carbon(get_field('field_54eb50af14d87', $articleMatches->posts[0]->ID));
         if ($article_entry_updated->toDayDateTimeString() <= $last_updated_date->toDayDateTimeString()) {
             die('This article will not be imported because this article seems older than another one we have');
         }
     }
     // Get all of the Inline Images
     preg_match_all("|<link(.+?)\\/>|mis", (string) $article_content_copy, $content_inline_images_matches);
     if ($content_inline_images_matches > 0) {
         $inline_images = array();
         $inline_image_counter = 0;
         foreach ($content_inline_images_matches[0] as $content_inline_images_match) {
             $inline_image_obj = simplexml_load_string($content_inline_images_match);
             $inline_img = $this->handleImageUpload($inline_image_obj->attributes()->href, true, $inline_image_counter);
             $inline_images += $inline_img;
             $inline_image_counter++;
         }
     }
     // Download related images
     $related_images = array();
     foreach ($article->link as $link) {
         if ($link->attributes()->rel == 'related') {
             $image = $this->handleImageUpload($link->attributes()->href);
             if ($image != false || $image != null) {
                 $related_images += $image;
             }
         }
     }
     // Add all the Article Data into an array
     $article_data = array('post_content' => $article_content_copy, 'post_title' => wp_strip_all_tags($cpiNamespace->headline), 'post_status' => 'publish', 'post_type' => 'tls_articles', 'post_author' => 1, 'ping_status' => 'closed', 'comment_status' => 'closed');
     /*
      * Check to see if there wasn't any matches. If no match is found
      * then send $article_data to saveArticleData method to insert new article
      * Otherwise if a match was found the send $article_data to saveArticleData method
      * with update parameter true to update article instead
      */
     if (!$articleMatches->found_posts > 0) {
         $article_data['post_date'] = $article_entry_published->toDateTimeString();
         // Published Date
         $article_data['post_date_gmt'] = $article_entry_published->toDateTimeString();
         // Published Date GMT
         $article_data['post_modified'] = $article_entry_updated->toDateTimeString();
         // Updated Date
         $article_data['post_modified_gmt'] = $article_entry_updated->toDateTimeString();
         // Updated Date GMT
         $article_id = $this->saveArticleData($article_data, $article_entry_id);
         $teaser_summary_custom_field = array('field_54e4d3c3b0095' => tls_make_post_excerpt($cpiNamespace->copy, 30));
         $this->saveArticleCustomFields($teaser_summary_custom_field, $article_id);
         $import_type = 'import';
     } else {
         if ($article_entry_updated->toDayDateTimeString() > $last_updated_date->toDayDateTimeString()) {
             $article_data['ID'] = (int) $articleMatches->posts[0]->ID;
             $article_id = $this->saveArticleData($article_data, $article_entry_id, true);
             $import_type = 'update';
         }
     }
     // Save Article Section Taxonomy Term
     $article_section = $this->saveArticleTaxonomyTerms($article_id, $cpiNamespace->section, 'article_section');
     // Save Article Visibility Taxonomy Term
     $article_visibility = $this->saveArticleTaxonomyTerms($article_id, $cpiNamespace->visibility, 'article_visibility');
     // Save Article Tags Taxonomy Terms
     $article_tags = $this->saveArticleTaxonomyTerms($article_id, $cpiNamespace->tag, 'article_tags');
     // Article Review Books
     $books = array();
     foreach ($cpiNamespace->books->book as $book) {
         $books[] = array('book_title' => (string) $book->title, 'book_author' => (string) $book->authorname, 'book_info' => (string) $book->info, 'book_isbn' => (string) $book->isbn);
     }
     $this->saveArticleCustomFields($books, $article_id, 'field_54edde1e60d80');
     // Books
     // Add all the Custom Fields' data into an array
     $article_custom_fields = array('field_54e4d372b0093' => (string) $article_entry_id, 'field_54eb50af14d87' => (string) $article_entry_updated->toDateTimeString(), 'field_54e4d3b1b0094' => (string) $cpiNamespace->byline);
     // Send Custom Fields Data to saveArticleCustomFields method to be saved
     // using the $article_id that came out of the saving or updating method
     $this->saveArticleCustomFields($article_custom_fields, $article_id);
     /*
      * Save All Related Images Custom Fields
      */
     // Get Main Full Image based upon either the size or being main_image
     if (isset($related_images['full_image_attachment_id'])) {
         $full_image_attachment_id = (int) $related_images['full_image_attachment_id'];
     } else {
         if (isset($related_images['main_image_attachment_id'])) {
             $full_image_attachment_id = (int) $related_images['main_image_attachment_id'];
         } else {
             $full_image_attachment_id = '';
         }
     }
     $thumb_image = isset($related_images['thumbnail_image_attachment_id']) ? (int) $related_images['thumbnail_image_attachment_id'] : '';
     $hero_image = isset($related_images['hero_image_attachment_id']) ? (int) $related_images['hero_image_attachment_id'] : '';
     $related_images_custom_fields = array('field_54e4d481b009a' => $thumb_image, 'field_54e4d4a5b009b' => $full_image_attachment_id, 'field_54e4d4b3b009c' => $hero_image);
     $this->saveArticleCustomFields($related_images_custom_fields, $article_id);
     /*
      * Search and replace all Inline Images with downloaded images.
      */
     if ($content_inline_images_matches[0] > 0) {
         $content_with_inline_images = $this->searchReplaceInlineImages($article_content_copy, $content_inline_images_matches[0], $inline_images);
         $inline_images_updated_article_data = array('ID' => $article_id, 'post_content' => $content_with_inline_images);
         $this->saveArticleData($inline_images_updated_article_data, $article_entry_id, true);
     }
     // Attach all images to post
     if (!empty($inline_images) || !empty($related_images)) {
         $attach_images = array_merge($inline_images, $related_images);
         $attach_images_ids = array_values($attach_images);
         $this->attachImagesToPost($attach_images_ids, $article_id);
     }
     // Add 1 to the articleCount after parsing the article
     $articleCount++;
     // Returns the number of articles parsed back into the parseFeed method
     // to add a log of how many articles were imported
     return array('import_type' => $import_type, 'articleCount' => $articleCount, 'original_article_id' => (string) $article_entry_id, 'original_article_title' => wp_strip_all_tags($cpiNamespace->headline));
 }
/**
 * Discover Articles Archive Page Template JSON API Response Modifications
 *
 * @param $response     The JSON API Response Object
 *
 * @return $response    Update JSON API Response Object
 */
function tls_discover_json_api_encode($response)
{
    if (isset($response['page']) && $response['page_template_slug'] == 'template-articles-archive.php') {
        // Globals to be used with many of the specific searches
        global $json_api, $wp_query;
        /**
         * Top Article from each Article Section
         */
        // Variable to store Top Articles IDs to later on remove from the second list of articles
        $top_section_articles = array();
        // Get all the terms from Article Section Taxonomy
        $article_sections_args = array('hide_empty' => true, 'orderby' => 'name', 'order' => 'ASC');
        $article_sections = get_terms('article_section', $article_sections_args);
        // Get all terms for Article Section taxonomy
        $show_sections = array();
        // Start empty array to inject sections that can be shown in discover page
        $show_sections_ids = array();
        // empty array to use later for wp query to search posts in these terms only
        foreach ($article_sections as $show_section) {
            $show_in_discover_page = get_field('show_in_discover_page', 'article_section_' . $show_section->term_id);
            // get the show in discover page for current term
            /*
             * If the term has the option set to 'yes' for show in discover page then add
             * Term Object to the show sections and term ids to show_section_ids
             */
            if ($show_in_discover_page == 'yes') {
                $show_sections[] = $show_section;
                $show_sections_ids[] = $show_section->term_id;
            }
        }
        $article_sections = $show_sections;
        // Reassign article_sections to use later on
        /**
         * Spotlight Article Section Category
         * Get the latest post and add it to the top section articles with
         * a spotlight attribute to use in FE
         */
        $spotlight_article_section = get_field('spotlight_category', $response['page']->id);
        // Arguments for the WP_Query
        $spotlight_article_args = array('post_type' => 'tls_articles', 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => array(array('taxonomy' => 'article_section', 'field' => 'term_id', 'terms' => $spotlight_article_section)));
        // WP_Query for the Top Article in current section term
        $spotlight_article_query = new WP_Query($spotlight_article_args);
        // Get the first article returned from Query
        $spotlight_article = $spotlight_article_query->posts[0];
        // Add Article ID into the spotlight_articles array
        $top_section_articles[] = $spotlight_article->ID;
        // Get Taxonomies
        $spotlight_article_sections = wp_get_post_terms($spotlight_article->ID, 'article_section');
        $spotlight_article_visibility = wp_get_post_terms($spotlight_article->ID, 'article_visibility');
        // Get all custom fields
        $spotlight_article_custom_fields = get_post_custom($spotlight_article->ID);
        // Get Specific Custom Fields from the Custom Fields
        $spotlight_article_teaser = $spotlight_article_custom_fields['teaser_summary'][0];
        $spotlight_full_image = get_field('field_54e4d4a5b009b', $spotlight_article->ID);
        $spotlight_thumbnail_image = get_field('field_54e4d481b009a', $spotlight_article->ID);
        $spotlight_image = '';
        if ($spotlight_thumbnail_image) {
            $spotlight_image = $spotlight_thumbnail_image['url'];
        } else {
            if ($spotlight_full_image) {
                $spotlight_image = $spotlight_full_image['url'];
            }
        }
        // Add this article into top_articles array from the JSON Response Object
        $response['top_articles'][] = array('spotlight' => true, 'type' => 'article', 'id' => $spotlight_article->ID, 'url' => get_permalink($spotlight_article->ID), 'title' => get_the_title($spotlight_article->ID), 'author' => array('name' => get_the_author_meta('display_name', $spotlight_article->post_author), 'slug' => get_the_author_meta('slug', $spotlight_article->post_author)), 'custom_fields' => array('thumbnail_image_url' => $spotlight_image, 'teaser_summary' => !empty($spotlight_article_teaser) ?: tls_make_post_excerpt($spotlight_article, 30)), 'image_url' => $spotlight_image, 'taxonomy_article_section' => $spotlight_article_sections, 'taxonomy_article_section_url' => get_term_link($spotlight_article_sections[0]->term_id, $spotlight_article_sections[0]->taxonomy), 'taxonomy_article_visibility' => $spotlight_article_visibility, 'books' => get_field('books', $spotlight_article->ID));
        /**
         * Get All Other Top Articles per Article Section Category
         * Removing the article from the spotlight section
         */
        // Loop through each of the sections to make a WP_Query
        foreach ($article_sections as $section) {
            if ($section->term_id != $spotlight_article_section) {
                // Arguments for the WP_Query
                $top_section_article_args = array('post_type' => 'tls_articles', 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => array(array('taxonomy' => 'article_section', 'field' => 'term_id', 'terms' => $section->term_id)));
                // WP_Query for the Top Article in current section term
                $top_section_article_query = new WP_Query($top_section_article_args);
                // Get the first article returned from Query
                $top_section_article = $top_section_article_query->posts[0];
                // Add Article ID into the top_section_articles array
                $top_section_articles[] = $top_section_article->ID;
                // Get Taxonomies
                $top_section_article_section = wp_get_post_terms($top_section_article->ID, 'article_section');
                $top_section_article_visibility = wp_get_post_terms($top_section_article->ID, 'article_visibility');
                // Get all custom fields
                $top_section_article_custom_fields = get_post_custom($top_section_article->ID);
                // Get Specific Custom Fields from the Custom Fields
                $top_section_article_teaser = $top_section_article_custom_fields['teaser_summary'][0];
                if (empty($top_section_article_teaser)) {
                    $top_section_article_teaser = tls_make_post_excerpt($top_section_article->post_content, 30);
                }
                $top_section_full_image = get_field('field_54e4d4a5b009b', $top_section_article->ID);
                $top_section_thumbnail_image = get_field('field_54e4d481b009a', $top_section_article->ID);
                $top_section_image = '';
                if ($top_section_thumbnail_image) {
                    $top_section_image = $top_section_thumbnail_image['url'];
                } else {
                    if ($top_section_full_image) {
                        $top_section_image = $top_section_full_image['url'];
                    }
                }
                // Add this article into top_articles array from the JSON Response Object
                $response['top_articles'][] = array('type' => 'article', 'id' => $top_section_article->ID, 'url' => get_permalink($top_section_article->ID), 'title' => get_the_title($top_section_article->ID), 'author' => array('name' => get_the_author_meta('display_name', $top_section_article->post_author), 'slug' => get_the_author_meta('slug', $top_section_article->post_author)), 'custom_fields' => array('thumbnail_image_url' => $top_section_image, 'teaser_summary' => $top_section_article_teaser), 'image_url' => $top_section_image, 'taxonomy_article_section' => $top_section_article_section, 'taxonomy_article_section_url' => get_term_link($top_section_article_section[0]->term_id, $top_section_article_section[0]->taxonomy), 'taxonomy_article_visibility' => $top_section_article_visibility, 'books' => get_field('field_54edde1e60d80', $top_section_article->ID));
            }
        }
        // END Loop of top Articles from each Article Section
        /**
         * All articles excluding the ones in the Top Articles Section
         */
        // Set up paged variable for the query
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        // WP_Query Arguments
        $articles_archive_args = array('post_type' => array('tls_articles'), 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'post__not_in' => $top_section_articles, 'tax_query' => array(array('taxonomy' => 'article_section', 'field' => 'term_id', 'terms' => $show_sections_ids)));
        // Override query inside the $wp_query global to be able to use the JSON API get_posts
        $wp_query->query = $articles_archive_args;
        $articles_archive = $json_api->introspector->get_posts($wp_query->query);
        foreach ($articles_archive as $article_post) {
            $article_section_terms = wp_get_post_terms($article_post->id, 'article_section');
            $article_custom_fields = get_post_custom($article_post->id);
            $article_post_full_image = get_field('field_54e4d4a5b009b', $article_post->id);
            $article_post_thumbnail_image = get_field('field_54e4d481b009a', $article_post->id);
            $article_post_image = '';
            if ($article_post_thumbnail_image) {
                $article_post_image = $article_post_thumbnail_image['url'];
            } else {
                if ($article_post_full_image) {
                    $article_post_image = $article_post_full_image['url'];
                }
            }
            $article_post->custom_fields->thumbnail_image_url = $article_post_thumbnail_image['url'];
            $article_post->custom_fields->full_image_url = $article_post_full_image['url'];
            $article_post->image_url = $article_post_image;
            //$article_post->excerpt = (empty($article_custom_fields['teaser_summary'][0])) ? tls_make_post_excerpt($article_post->content, 30) : wp_strip_all_tags($article_custom_fields['teaser_summary'][0]); // Teaser Summary
            unset($article_post->excerpt);
            $article_post->type = 'article';
            $article_post->taxonomy_article_section_url = get_term_link($article_section_terms[0]->term_id, $article_section_terms[0]->taxonomy);
            $article_post->books = get_field('field_54edde1e60d80', $article_post->id);
        }
        // Update JSON Response Object for the main Articles Archive
        $response['count'] = count($articles_archive);
        $response['count_total'] = (int) $wp_query->found_posts;
        $response['pages'] = $wp_query->max_num_pages;
        $response['posts'] = $articles_archive;
    }
    return $response;
}