/**
 * Renders a single feed item.
 *
 * @param int    $ID      The ID of the feed item to render
 * @param string $default The default text to return if something fails.
 * @return string The output
 * @since 4.6.6
 */
function wprss_render_feed_item($ID = NULL, $default = '', $args = array())
{
    $ID = $ID === NULL ? get_the_ID() : $ID;
    if (get_post_type($ID) !== 'wprss_feed_item' || is_feed()) {
        return $default;
    }
    // Prepare the options
    $general_settings = get_option('wprss_settings_general');
    $display_settings = wprss_get_display_settings($general_settings);
    $excerpts_settings = get_option('wprss_settings_excerpts');
    $thumbnails_settings = get_option('wprss_settings_thumbnails');
    $args = wp_parse_args($args, array('link_before' => '', 'link_after' => ''));
    $extra_options = apply_filters('wprss_template_extra_options', array(), $args);
    // Normalize the source_link option
    $source_link = isset($general_settings['source_link']) ? $general_settings['source_link'] : 0;
    // Declare each item in $args as its own variable
    extract($args, EXTR_SKIP);
    // Get the item meta
    $permalink = get_post_meta($ID, 'wprss_item_permalink', true);
    $enclosure = get_post_meta($ID, 'wprss_item_enclosure', true);
    $feed_source_id = get_post_meta($ID, 'wprss_feed_id', true);
    $link_enclosure = get_post_meta($feed_source_id, 'wprss_enclosure', true);
    $source_name = get_the_title($feed_source_id);
    $source_url = get_post_meta($feed_source_id, 'wprss_site_url', true);
    $timestamp = get_the_time('U', $ID);
    // Fallback for feeds created with older versions of the plugin
    if ($source_url === '') {
        $source_url = get_post_meta($feed_source_id, 'wprss_url', true);
    }
    // convert from Unix timestamp
    $date = wprss_date_i18n($timestamp);
    // Prepare the title
    $feed_item_title = get_the_title();
    $feed_item_title_link = $link_enclosure === 'true' && $enclosure !== '' ? $enclosure : $permalink;
    // Prepare the text that precedes the source
    $text_preceding_source = wprss_get_general_setting('text_preceding_source');
    $text_preceding_source = ltrim(__($text_preceding_source, WPRSS_TEXT_DOMAIN) . ' ');
    $text_preceding_date = wprss_get_general_setting('text_preceding_date');
    $text_preceding_date = ltrim(__($text_preceding_date, WPRSS_TEXT_DOMAIN) . ' ');
    do_action('wprss_get_post_data');
    $meta = $extra_options;
    $extra_meta = apply_filters('wprss_template_extra_meta', $meta, $args, $ID);
    ///////////////////////////////////////////////////////////////
    // BEGIN TEMPLATE
    // Prepare the output
    $output = '';
    // Begin output buffering
    ob_start();
    // Print the links before
    echo $link_before;
    // The Title
    $item_title = wprss_link_display($feed_item_title_link, $feed_item_title, wprss_get_general_setting('title_link'));
    $item_title = apply_filters('wprss_item_title', $item_title, $feed_item_title_link, $feed_item_title, wprss_get_general_setting('title_link'));
    echo $item_title;
    do_action('wprss_after_feed_item_title', $extra_meta, $display_settings, $ID);
    // FEED ITEM META
    echo '<div class="wprss-feed-meta">';
    // SOURCE
    if (wprss_get_general_setting('source_enable') == 1) {
        echo '<span class="feed-source">';
        $source_link_text = apply_filters('wprss_item_source_link', wprss_link_display($source_url, $source_name, $source_link));
        $source_link_text = $text_preceding_source . $source_link_text;
        echo $source_link_text;
        echo '</span>';
    }
    // DATE
    if (wprss_get_general_setting('date_enable') == 1) {
        echo '<span class="feed-date">';
        $date_text = apply_filters('wprss_item_date', $date);
        $date_text = $text_preceding_date . $date_text;
        echo $date_text;
        echo '</span>';
    }
    // AUTHOR
    $author = get_post_meta($ID, 'wprss_item_author', TRUE);
    if (wprss_get_general_setting('authors_enable') == 1 && $author !== NULL && is_string($author) && $author !== '') {
        echo '<span class="feed-author">';
        $author_text = apply_filters('wprss_item_author', $author);
        $author_prefix_text = apply_filters('wprss_author_prefix_text', 'By');
        _e($author_prefix_text, WPRSS_TEXT_DOMAIN);
        echo ' ' . $author_text;
        echo '</span>';
    }
    echo '</div>';
    // TIME AGO
    if (wprss_get_general_setting('date_enable') == 1 && wprss_get_general_setting('time_ago_format_enable') == 1) {
        $time_ago = human_time_diff($timestamp, time());
        echo '<div class="wprss-time-ago">';
        $time_ago_text = apply_filters('wprss_item_time_ago', $time_ago);
        printf(__('%1$s ago', WPRSS_TEXT_DOMAIN), $time_ago_text);
        echo '</div>';
    }
    // END TEMPLATE - Retrieve buffered output
    $output .= ob_get_clean();
    $output = apply_filters('wprss_single_feed_output', $output, $permalink);
    $output .= "{$link_after}";
    // Print the output
    return $output;
}
/**
 * Default template for feed items display
 *
 * @since 3.0
 */
function wprss_default_display_template($display_settings, $args, $feed_items)
{
    global $wp_query;
    global $paged;
    // Swap the current WordPress Query with our own
    $old_wp_query = $wp_query;
    $wp_query = $feed_items;
    // Prepare the options
    $general_settings = get_option('wprss_settings_general');
    $excerpts_settings = get_option('wprss_settings_excerpts');
    $thumbnails_settings = get_option('wprss_settings_thumbnails');
    $extra_options = apply_filters('wprss_template_extra_options', array(), $args);
    // Normalize the source_link option
    $source_link = isset($general_settings['source_link']) ? $general_settings['source_link'] : 0;
    // Declare each item in $args as its own variable
    extract($args, EXTR_SKIP);
    // Prepare the output
    $output = '';
    // Check if our current query returned any feed items
    if ($feed_items->have_posts()) {
        // PRINT LINKS BEFORE LIST OF FEED ITEMS
        $output .= "{$links_before}";
        // FOR EACH ITEM
        while ($feed_items->have_posts()) {
            // Prepare the item
            $feed_items->the_post();
            // Get the item meta
            $permalink = get_post_meta(get_the_ID(), 'wprss_item_permalink', true);
            $enclosure = get_post_meta(get_the_ID(), 'wprss_item_enclosure', true);
            $feed_source_id = get_post_meta(get_the_ID(), 'wprss_feed_id', true);
            $link_enclosure = get_post_meta($feed_source_id, 'wprss_enclosure', true);
            $source_name = get_the_title($feed_source_id);
            $source_url = get_post_meta($feed_source_id, 'wprss_site_url', true);
            $timestamp = get_the_time('U', get_the_ID());
            // Fallback for feeds created with older versions of the plugin
            if ($source_url === '') {
                $source_url = get_post_meta($feed_source_id, 'wprss_url', true);
            }
            // convert from Unix timestamp
            $date = wprss_date_i18n($timestamp);
            // Prepare the title
            $feed_item_title = get_the_title();
            $feed_item_title_link = $link_enclosure === 'true' && $enclosure !== '' ? $enclosure : $permalink;
            // Prepare the text that precedes the source
            $text_preceding_source = wprss_get_general_setting('text_preceding_source');
            $text_preceding_source = ltrim(__($text_preceding_source, WPRSS_TEXT_DOMAIN) . ' ');
            $text_preceding_date = wprss_get_general_setting('text_preceding_date');
            $text_preceding_date = ltrim(__($text_preceding_date, WPRSS_TEXT_DOMAIN) . ' ');
            do_action('wprss_get_post_data');
            $meta = $extra_options;
            $extra_meta = apply_filters('wprss_template_extra_meta', $meta, $args, get_the_ID());
            ///////////////////////////////////////////////////////////////
            // BEGIN TEMPLATE
            // Begin output buffering
            ob_start();
            // Print the links before
            echo $link_before;
            // The Title
            $item_title = wprss_link_display($feed_item_title_link, $feed_item_title, wprss_get_general_setting('title_link'));
            $item_title = apply_filters('wprss_item_title', $item_title, $feed_item_title_link, $feed_item_title, wprss_get_general_setting('title_link'));
            echo $item_title;
            do_action('wprss_after_feed_item_title', $extra_meta, $display_settings, get_the_ID());
            // FEED ITEM META
            ?>
                <div class="wprss-feed-meta">

                    <!-- SOURCE -->
                    <?php 
            if (wprss_get_general_setting('source_enable') == 1) {
                ?>
                        <span class="feed-source">
                            <?php 
                $source_link_text = apply_filters('wprss_item_source_link', wprss_link_display($source_url, $source_name, $source_link));
                ?>
                            <?php 
                $source_link_text = $text_preceding_source . $source_link_text;
                ?>
                            <?php 
                echo $source_link_text;
                ?>
                        </span>
                    <?php 
            }
            ?>

                    <!-- DATE -->
                    <?php 
            if (wprss_get_general_setting('date_enable') == 1) {
                ?>
                        <span class='feed-date'>
                            <?php 
                $date_text = apply_filters('wprss_item_date', $date);
                ?>
                            <?php 
                $date_text = $text_preceding_date . $date_text;
                ?>
                            <?php 
                echo $date_text;
                ?>
                        </span>
                    <?php 
            }
            ?>

                    <!-- AUTHOR -->
                    <?php 
            $author = get_post_meta(get_the_ID(), 'wprss_item_author', TRUE);
            if (wprss_get_general_setting('authors_enable') == 1 && $author !== NULL && is_string($author) && $author !== '') {
                ?>
                        <span class="feed-author">
                            <?php 
                $author_text = apply_filters('wprss_item_author', $author);
                $author_prefix_text = apply_filters('wprss_author_prefix_text', 'By');
                _e($author_prefix_text, WPRSS_TEXT_DOMAIN);
                echo ' ' . $author_text;
                ?>
                        </span>
                    <?php 
            }
            ?>

                </div>

                <?php 
            // TIME AGO
            if (wprss_get_general_setting('date_enable') == 1 && wprss_get_general_setting('time_ago_format_enable') == 1) {
                $time_ago = human_time_diff($timestamp, time());
                ?>
                    <div class="wprss-time-ago">
                        <?php 
                $time_ago_text = apply_filters('wprss_item_time_ago', $time_ago);
                ?>
						<?php 
                printf(__('%1$s ago', WPRSS_TEXT_DOMAIN), $time_ago_text);
                ?>
                    </div>
                    <?php 
            }
            // END TEMPLATE - Retrieve buffered output
            $output .= ob_get_clean();
            $output = apply_filters('wprss_single_feed_output', $output, $permalink);
            $output .= "{$link_after}";
        }
        // OUTPUT LINKS AFTER LIST OF FEED ITEMS
        $output .= "{$links_after}";
        // Add pagination if needed
        if (!isset($args['pagination']) || !in_array($args['pagination'], array('off', 'false', '0', 0))) {
            $output = apply_filters('wprss_pagination', $output);
        }
        // Filter the final output
        $output = apply_filters('feed_output', $output);
        // Print the output
        echo $output;
    } else {
        // Not items found message
        echo apply_filters('no_feed_items_found', __('No feed items found.', WPRSS_TEXT_DOMAIN));
    }
    // Reset the WordPress query
    $wp_query = $old_wp_query;
    wp_reset_postdata();
}