/**
  * Builds a valid \<link /\> HTML tag to a feed (rss or atom).
  * Returns a link tag that browsers and news readers can use to auto-detect an
  * RSS or ATOM feed. The type can either be @e rss (default) or @e atom. You
  * can modify the LINK tag itself in @e $tag_options.
  *
  * @param string $model_or_url
  *   (optional) The source of the feed. Can be a custom URL, @e posts or @e
  *   comments. In the latter case, the source will be returned by
  *   AssetTagHelper::get_feed_url()
  *   Defaults to @e posts.
  * @param string $type
  *   (optional) The type of the feed. Could be @e rss or @e atom.
  *   Defaults to @e rss.
  * @param array $tag_options
  *   (optional) An array of HTML attributes to be added to the rendered tag.
  * @return @e string
  *   A valid \<link /\> HTML tag to a feed (rss or atom).
  *
  * @see AssetTagHelper::get_feed_url()
  * @see TagHelper::content_tag()
  *
  * @ingroup helperfunc
  *
  */
 public function auto_discovery_link_tag($model_or_url = "posts", $type = "rss", $additional_options = NULL)
 {
     $options = array("rel" => "alternate", "title" => strtoupper($type));
     switch ($type) {
         case "atom":
             $options['type'] = "application/atom+xml";
             break;
         case "rss":
         default:
             $type = "rss";
             $options['type'] = "application/rss+xml";
             break;
     }
     switch ($model_or_url) {
         case "posts":
         case "comments":
             $options['href'] = get_feed_url($model_or_url, $type);
             break;
         default:
             $options['href'] = $model_or_url;
     }
     if (is_array($additional_options)) {
         $options = array_merge($options, $additional_options);
     }
     return content_tag("link", NULL, $options);
 }
 function test_get_feed_url()
 {
     $this->assertEqual("mocked_rdf_url", get_feed_url("posts", "rdf"));
     $this->assertEqual("mocked_rss_url", get_feed_url("posts", "rss1"));
     $this->assertEqual("mocked_rss_url", get_feed_url("posts", "rss092"));
     $this->assertEqual("mocked_atom_url", get_feed_url("posts", "atom"));
     $this->assertEqual("mocked_rss2_url", get_feed_url("posts", "rss"));
     $this->assertEqual("mocked_rss2_url", get_feed_url("posts", "rss2"));
     $this->assertEqual("mocked_rss2_url", get_feed_url("posts", "whatever"));
     $this->assertEqual("mocked_comments_rss2_url", get_feed_url("comments", "rss2"));
     $this->assertEqual("mocked_comments_rss2_url", get_feed_url("comments", "whatever"));
 }
示例#3
0
/**
 * Return XML for full feed.
 * 
 * @param   array $feed_items Array of objects. Required attributes: ID (=post id), blog_id
 * @return  string
 */
function get_feed_xml($feed_items)
{
    global $post;
    $rss_language = Settings\get_site_option('language_slug');
    if (empty($rss_language) && defined('WPLANG')) {
        $rss_language = substr(WPLANG, 0, 2);
    }
    ob_start();
    echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>';
    ?>

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	<?php 
    do_action('rss2_ns');
    ?>
>

<channel>
	<title><?php 
    echo get_feed_title();
    ?>
</title>
	<atom:link href="<?php 
    echo get_feed_url();
    ?>
" rel="self" type="application/rss+xml" />
	<link><?php 
    echo get_feed_url();
    ?>
</link>
	<description><?php 
    echo get_feed_description();
    ?>
</description>
	<lastBuildDate><?php 
    echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), FALSE);
    ?>
</lastBuildDate>
	<language><?php 
    echo $rss_language;
    ?>
</language>
	<sy:updatePeriod><?php 
    echo apply_filters('rss_update_period', 'hourly');
    ?>
</sy:updatePeriod>
	<sy:updateFrequency><?php 
    echo apply_filters('rss_update_frequency', '1');
    ?>
</sy:updateFrequency>
	<?php 
    do_action('rss2_head');
    foreach ($feed_items as $feed_item) {
        switch_to_blog($feed_item->blog_id);
        $post = get_post($feed_item->ID);
        setup_postdata($post);
        ?>
		
		<item>
			<title><?php 
        the_title_rss();
        ?>
</title>
			<link><?php 
        the_permalink_rss();
        ?>
</link>
			<comments><?php 
        comments_link_feed();
        ?>
</comments>
			<pubDate><?php 
        echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', TRUE), FALSE);
        ?>
</pubDate>
			<dc:creator><?php 
        the_author();
        ?>
</dc:creator>
			<?php 
        the_category_rss('rss2');
        ?>
			
			<guid isPermaLink="false"><?php 
        the_guid();
        ?>
</guid>
	<?php 
        if (get_option('rss_use_excerpt')) {
            ?>
			<description><![CDATA[<?php 
            the_excerpt_rss();
            ?>
]]></description>
	<?php 
        } else {
            ?>
			<description><![CDATA[<?php 
            the_excerpt_rss();
            ?>
]]></description>
		<?php 
            $content = \Inpsyde\MultisiteFeed\get_the_content_feed('rss2');
            ?>
		<?php 
            if (strlen($content) > 0) {
                ?>
			<content:encoded><![CDATA[<?php 
                echo $content;
                ?>
]]></content:encoded>
		<?php 
            } else {
                ?>
			<content:encoded><![CDATA[<?php 
                the_excerpt_rss();
                ?>
]]></content:encoded>
		<?php 
            }
            ?>
	<?php 
        }
        ?>
			<wfw:commentRss><?php 
        echo esc_url(get_post_comments_feed_link(NULL, 'rss2'));
        ?>
</wfw:commentRss>
			<slash:comments><?php 
        echo get_comments_number();
        ?>
</slash:comments>
	<?php 
        rss_enclosure();
        do_action('rss2_item');
        ?>
		</item>
		
		<?php 
        restore_current_blog();
    }
    ?>
	
</channel>
</rss>
<?php 
    $xml = ob_get_contents();
    ob_end_clean();
    return $xml;
}