2005-01-07 23:01:59 +01:00
|
|
|
<?php
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* WordPress Feed API
|
|
|
|
*
|
|
|
|
* Many of the functions used in here belong in The Loop, or The Loop for the
|
|
|
|
* Feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
*/
|
2005-01-07 23:01:59 +01:00
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* RSS container for the bloginfo function.
|
|
|
|
*
|
|
|
|
* You can retrieve anything that you can using the get_bloginfo() function.
|
|
|
|
* Everything will be stripped of tags and characters converted, when the values
|
|
|
|
* are retrieved for use in the feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 1.5.1
|
|
|
|
* @uses apply_filters() Calls 'get_bloginfo_rss' hook with two parameters.
|
|
|
|
* @see get_bloginfo() For the list of possible values to display.
|
|
|
|
*
|
|
|
|
* @param string $show See get_bloginfo() for possible values.
|
|
|
|
* @return string
|
|
|
|
*/
|
2005-02-25 16:52:28 +01:00
|
|
|
function get_bloginfo_rss($show = '') {
|
|
|
|
$info = strip_tags(get_bloginfo($show));
|
2008-02-07 19:01:33 +01:00
|
|
|
return apply_filters('get_bloginfo_rss', convert_chars($info), $show);
|
2005-02-25 16:52:28 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display RSS container for the bloginfo function.
|
|
|
|
*
|
|
|
|
* You can retrieve anything that you can using the get_bloginfo() function.
|
|
|
|
* Everything will be stripped of tags and characters converted, when the values
|
|
|
|
* are retrieved for use in the feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 0.71
|
|
|
|
* @uses apply_filters() Calls 'bloginfo_rss' hook with two parameters.
|
|
|
|
* @see get_bloginfo() For the list of possible values to display.
|
|
|
|
*
|
|
|
|
* @param string $show See get_bloginfo() for possible values.
|
|
|
|
*/
|
2005-02-25 16:52:28 +01:00
|
|
|
function bloginfo_rss($show = '') {
|
2008-02-07 19:01:33 +01:00
|
|
|
echo apply_filters('bloginfo_rss', get_bloginfo_rss($show), $show);
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the default feed.
|
|
|
|
*
|
|
|
|
* The default feed is 'rss2', unless a plugin changes it through the
|
|
|
|
* 'default_feed' filter.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.5
|
|
|
|
* @uses apply_filters() Calls 'default_feed' hook on the default feed string.
|
|
|
|
*
|
|
|
|
* @return string Default feed, or for example 'rss2', 'atom', etc.
|
|
|
|
*/
|
2007-12-06 20:58:15 +01:00
|
|
|
function get_default_feed() {
|
|
|
|
return apply_filters('default_feed', 'rss2');
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the blog title for the feed title.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.2.0
|
|
|
|
* @uses apply_filters() Calls 'get_wp_title_rss' hook on title.
|
|
|
|
* @uses wp_title() See function for $sep parameter usage.
|
|
|
|
*
|
|
|
|
* @param string $sep Optional.How to separate the title. See wp_title() for more info.
|
|
|
|
* @return string Error message on failure or blog title on success.
|
|
|
|
*/
|
2007-02-24 08:33:29 +01:00
|
|
|
function get_wp_title_rss($sep = '»') {
|
|
|
|
$title = wp_title($sep, false);
|
2007-09-18 18:32:22 +02:00
|
|
|
if ( is_wp_error( $title ) )
|
|
|
|
return $title->get_error_message();
|
2007-02-24 08:33:29 +01:00
|
|
|
$title = apply_filters('get_wp_title_rss', $title);
|
|
|
|
return $title;
|
|
|
|
}
|
2006-12-07 04:57:23 +01:00
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the blog title for display of the feed title.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.2.0
|
|
|
|
* @uses apply_filters() Calls 'wp_title_rss' on the blog title.
|
|
|
|
* @see wp_title() $sep parameter usage.
|
|
|
|
*
|
|
|
|
* @param string $sep Optional.
|
|
|
|
*/
|
2007-03-29 03:29:09 +02:00
|
|
|
function wp_title_rss($sep = '»') {
|
|
|
|
echo apply_filters('wp_title_rss', get_wp_title_rss($sep));
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the current post title for the feed.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.0.0
|
|
|
|
* @uses apply_filters() Calls 'the_title_rss' on the post title.
|
|
|
|
*
|
|
|
|
* @return string Current post title.
|
|
|
|
*/
|
2005-12-15 23:20:06 +01:00
|
|
|
function get_the_title_rss() {
|
2005-01-07 23:01:59 +01:00
|
|
|
$title = get_the_title();
|
|
|
|
$title = apply_filters('the_title_rss', $title);
|
2005-12-15 23:20:06 +01:00
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the post title in the feed.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 0.71
|
|
|
|
* @uses get_the_title_rss() Used to retrieve current post title.
|
|
|
|
*/
|
2005-12-15 23:20:06 +01:00
|
|
|
function the_title_rss() {
|
|
|
|
echo get_the_title_rss();
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
2009-09-28 16:36:48 +02:00
|
|
|
* Retrieve the post content for feeds.
|
2008-07-03 17:23:22 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2009-09-28 16:36:48 +02:00
|
|
|
* @since 2.9.0
|
|
|
|
* @uses apply_filters() Calls 'the_content_feed' on the content before processing.
|
|
|
|
* @see get_the_content()
|
|
|
|
*
|
|
|
|
* @param string $feed_type The type of feed. rss2 | atom | rss | rdf
|
2008-07-03 17:23:22 +02:00
|
|
|
*/
|
2009-09-28 16:36:48 +02:00
|
|
|
function get_the_content_feed($feed_type = null) {
|
|
|
|
if ( !$feed_type )
|
|
|
|
$feed_type = get_default_feed();
|
2008-07-03 17:23:22 +02:00
|
|
|
|
2009-09-28 16:36:48 +02:00
|
|
|
$content = apply_filters('the_content', get_the_content());
|
2005-01-07 23:01:59 +01:00
|
|
|
$content = str_replace(']]>', ']]>', $content);
|
2009-09-28 16:36:48 +02:00
|
|
|
return apply_filters('the_content_feed', $content, $feed_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the post content for feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.9.0
|
|
|
|
* @uses apply_filters() Calls 'the_content_feed' on the content before processing.
|
|
|
|
* @see get_the_content()
|
|
|
|
*
|
|
|
|
* @param string $feed_type The type of feed. rss2 | atom | rss | rdf
|
|
|
|
*/
|
|
|
|
function the_content_feed($feed_type = null) {
|
2010-07-06 22:41:07 +02:00
|
|
|
echo get_the_content_feed($feed_type);
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the post excerpt for the feed.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 0.71
|
|
|
|
* @uses apply_filters() Calls 'the_excerpt_rss' hook on the excerpt.
|
|
|
|
*/
|
2005-01-07 23:01:59 +01:00
|
|
|
function the_excerpt_rss() {
|
2007-09-13 23:27:26 +02:00
|
|
|
$output = get_the_excerpt();
|
2005-01-07 23:01:59 +01:00
|
|
|
echo apply_filters('the_excerpt_rss', $output);
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the permalink to the post for use in feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.3.0
|
|
|
|
* @uses apply_filters() Call 'the_permalink_rss' on the post permalink
|
|
|
|
*/
|
2007-08-21 20:27:45 +02:00
|
|
|
function the_permalink_rss() {
|
2010-05-26 19:47:29 +02:00
|
|
|
echo esc_url( apply_filters('the_permalink_rss', get_permalink() ));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the link to the comments for the current post in an xml safe way
|
2010-06-02 22:04:07 +02:00
|
|
|
*
|
2010-05-26 19:47:29 +02:00
|
|
|
* @since 3.0.0
|
|
|
|
* @return none
|
|
|
|
*/
|
|
|
|
function comments_link_feed() {
|
|
|
|
echo esc_url( get_comments_link() );
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the feed GUID for the current comment.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2010-12-01 20:24:38 +01:00
|
|
|
* @since 2.5.0
|
2009-01-20 21:55:03 +01:00
|
|
|
*
|
|
|
|
* @param int|object $comment_id Optional comment object or id. Defaults to global comment object.
|
2008-07-03 17:23:22 +02:00
|
|
|
*/
|
2009-01-20 21:55:03 +01:00
|
|
|
function comment_guid($comment_id = null) {
|
2010-05-26 20:30:51 +02:00
|
|
|
echo esc_url( get_comment_guid($comment_id) );
|
2008-02-06 23:33:21 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the feed GUID for the current comment.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2010-12-01 20:24:38 +01:00
|
|
|
* @since 2.5.0
|
2008-07-03 17:23:22 +02:00
|
|
|
*
|
2009-01-20 21:55:03 +01:00
|
|
|
* @param int|object $comment_id Optional comment object or id. Defaults to global comment object.
|
2008-07-03 17:23:22 +02:00
|
|
|
* @return bool|string false on failure or guid for comment on success.
|
|
|
|
*/
|
2009-01-20 21:55:03 +01:00
|
|
|
function get_comment_guid($comment_id = null) {
|
|
|
|
$comment = get_comment($comment_id);
|
2008-02-06 23:33:21 +01:00
|
|
|
|
|
|
|
if ( !is_object($comment) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the link to the comments.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
2005-01-31 11:06:12 +01:00
|
|
|
function comment_link() {
|
2009-05-18 18:00:33 +02:00
|
|
|
echo esc_url( get_comment_link() );
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the current comment author for use in the feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.0.0
|
|
|
|
* @uses apply_filters() Calls 'comment_author_rss' hook on comment author.
|
|
|
|
* @uses get_comment_author()
|
|
|
|
*
|
|
|
|
* @return string Comment Author
|
|
|
|
*/
|
2005-12-15 23:20:06 +01:00
|
|
|
function get_comment_author_rss() {
|
|
|
|
return apply_filters('comment_author_rss', get_comment_author() );
|
|
|
|
}
|
2006-12-07 04:57:23 +01:00
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the current comment author in the feed.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2005-01-07 23:01:59 +01:00
|
|
|
function comment_author_rss() {
|
2005-12-15 23:20:06 +01:00
|
|
|
echo get_comment_author_rss();
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the current comment content for use in the feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 1.0.0
|
|
|
|
* @uses apply_filters() Calls 'comment_text_rss' filter on comment content.
|
|
|
|
* @uses get_comment_text()
|
|
|
|
*/
|
2005-01-07 23:01:59 +01:00
|
|
|
function comment_text_rss() {
|
|
|
|
$comment_text = get_comment_text();
|
|
|
|
$comment_text = apply_filters('comment_text_rss', $comment_text);
|
|
|
|
echo $comment_text;
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Retrieve all of the post categories, formatted for use in feeds.
|
|
|
|
*
|
|
|
|
* All of the categories for the current post in the feed loop, will be
|
|
|
|
* retrieved and have feed markup added, so that they can easily be added to the
|
|
|
|
* RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.1.0
|
2008-08-09 07:36:14 +02:00
|
|
|
* @uses apply_filters()
|
2008-07-03 17:23:22 +02:00
|
|
|
*
|
2009-11-17 17:27:36 +01:00
|
|
|
* @param string $type Optional, default is the type returned by get_default_feed().
|
2008-07-03 17:23:22 +02:00
|
|
|
* @return string All of the post categories for displaying in the feed.
|
|
|
|
*/
|
2009-11-17 17:27:36 +01:00
|
|
|
function get_the_category_rss($type = null) {
|
|
|
|
if ( empty($type) )
|
|
|
|
$type = get_default_feed();
|
2010-11-12 22:53:15 +01:00
|
|
|
$categories = get_the_category();
|
2007-08-29 23:10:20 +02:00
|
|
|
$tags = get_the_tags();
|
2006-10-13 15:49:39 +02:00
|
|
|
$the_list = '';
|
2007-08-29 23:10:20 +02:00
|
|
|
$cat_names = array();
|
|
|
|
|
|
|
|
$filter = 'rss';
|
|
|
|
if ( 'atom' == $type )
|
|
|
|
$filter = 'raw';
|
|
|
|
|
|
|
|
if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
|
2007-09-04 01:32:58 +02:00
|
|
|
$cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
|
2007-08-29 23:10:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
|
2007-09-04 01:32:58 +02:00
|
|
|
$cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
|
2007-08-29 23:10:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$cat_names = array_unique($cat_names);
|
|
|
|
|
|
|
|
foreach ( $cat_names as $cat_name ) {
|
2006-10-13 15:49:39 +02:00
|
|
|
if ( 'rdf' == $type )
|
2009-03-10 19:25:04 +01:00
|
|
|
$the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
|
2007-09-01 10:33:08 +02:00
|
|
|
elseif ( 'atom' == $type )
|
2009-05-05 21:43:53 +02:00
|
|
|
$the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), esc_attr( $cat_name ) );
|
2006-10-13 15:49:39 +02:00
|
|
|
else
|
2009-04-24 18:57:27 +02:00
|
|
|
$the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
|
2006-10-13 15:49:39 +02:00
|
|
|
}
|
2007-08-29 23:10:20 +02:00
|
|
|
|
2006-10-13 15:49:39 +02:00
|
|
|
return apply_filters('the_category_rss', $the_list, $type);
|
2006-09-26 20:05:06 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the post categories in the feed.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 0.71
|
|
|
|
* @see get_the_category_rss() For better explanation.
|
|
|
|
*
|
2009-11-17 17:27:36 +01:00
|
|
|
* @param string $type Optional, default is the type returned by get_default_feed().
|
2008-07-03 17:23:22 +02:00
|
|
|
*/
|
2009-11-17 17:27:36 +01:00
|
|
|
function the_category_rss($type = null) {
|
2006-09-26 20:05:06 +02:00
|
|
|
echo get_the_category_rss($type);
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the HTML type based on the blog setting.
|
|
|
|
*
|
|
|
|
* The two possible values are either 'xhtml' or 'html'.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.2.0
|
|
|
|
*/
|
2007-01-25 09:37:26 +01:00
|
|
|
function html_type_rss() {
|
2007-01-25 09:48:18 +01:00
|
|
|
$type = get_bloginfo('html_type');
|
2007-03-07 06:29:15 +01:00
|
|
|
if (strpos($type, 'xhtml') !== false)
|
2007-01-25 09:37:26 +01:00
|
|
|
$type = 'xhtml';
|
|
|
|
else
|
|
|
|
$type = 'html';
|
|
|
|
echo $type;
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the rss enclosure for the current post.
|
|
|
|
*
|
|
|
|
* Uses the global $post to check whether the post requires a password and if
|
|
|
|
* the user has the password for the post. If not then it will return before
|
|
|
|
* displaying.
|
|
|
|
*
|
|
|
|
* Also uses the function get_post_custom() to get the post's 'enclosure'
|
|
|
|
* metadata field and parses the value to display the enclosure(s). The
|
|
|
|
* enclosure(s) consist of enclosure HTML tag(s) with a URI and other
|
|
|
|
* attributes.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Template
|
|
|
|
* @since 1.5.0
|
|
|
|
* @uses apply_filters() Calls 'rss_enclosure' hook on rss enclosure.
|
|
|
|
* @uses get_post_custom() To get the current post enclosure metadata.
|
|
|
|
*/
|
2005-01-07 23:01:59 +01:00
|
|
|
function rss_enclosure() {
|
2008-09-03 21:54:14 +02:00
|
|
|
if ( post_password_required() )
|
2006-10-13 15:49:39 +02:00
|
|
|
return;
|
2005-03-22 18:49:19 +01:00
|
|
|
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) get_post_custom() as $key => $val) {
|
2007-02-24 00:47:57 +01:00
|
|
|
if ($key == 'enclosure') {
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) $val as $enc ) {
|
2009-02-21 07:14:52 +01:00
|
|
|
$enclosure = explode("\n", $enc);
|
2008-12-09 19:03:31 +01:00
|
|
|
|
2008-11-03 21:19:38 +01:00
|
|
|
//only get the the first element eg, audio/mpeg from 'audio/mpeg mpga mp2 mp3'
|
2009-02-21 07:14:52 +01:00
|
|
|
$t = preg_split('/[ \t]/', trim($enclosure[2]) );
|
2008-12-09 19:03:31 +01:00
|
|
|
$type = $t[0];
|
|
|
|
|
2008-11-03 21:19:38 +01:00
|
|
|
echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . $type . '" />' . "\n");
|
2005-01-07 23:01:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:23:22 +02:00
|
|
|
/**
|
|
|
|
* Display the atom enclosure for the current post.
|
|
|
|
*
|
|
|
|
* Uses the global $post to check whether the post requires a password and if
|
|
|
|
* the user has the password for the post. If not then it will return before
|
|
|
|
* displaying.
|
|
|
|
*
|
|
|
|
* Also uses the function get_post_custom() to get the post's 'enclosure'
|
|
|
|
* metadata field and parses the value to display the enclosure(s). The
|
|
|
|
* enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Template
|
|
|
|
* @since 2.2.0
|
|
|
|
* @uses apply_filters() Calls 'atom_enclosure' hook on atom enclosure.
|
|
|
|
* @uses get_post_custom() To get the current post enclosure metadata.
|
|
|
|
*/
|
2007-02-24 00:47:57 +01:00
|
|
|
function atom_enclosure() {
|
2008-09-03 21:54:14 +02:00
|
|
|
if ( post_password_required() )
|
2007-02-24 00:47:57 +01:00
|
|
|
return;
|
|
|
|
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) get_post_custom() as $key => $val ) {
|
2007-02-24 00:47:57 +01:00
|
|
|
if ($key == 'enclosure') {
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) $val as $enc ) {
|
2007-02-24 00:47:57 +01:00
|
|
|
$enclosure = split("\n", $enc);
|
2007-02-24 07:30:51 +01:00
|
|
|
echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
|
2007-02-24 00:47:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 17:42:30 +02:00
|
|
|
/**
|
2008-07-03 17:23:22 +02:00
|
|
|
* Determine the type of a string of data with the data formatted.
|
2007-12-28 22:21:50 +01:00
|
|
|
*
|
|
|
|
* Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.
|
2007-10-19 17:42:30 +02:00
|
|
|
*
|
|
|
|
* In the case of WordPress, text is defined as containing no markup,
|
|
|
|
* xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
|
|
|
|
*
|
|
|
|
* Container div tags are added to xhtml values, per section 3.1.1.3.
|
|
|
|
*
|
2007-12-28 22:21:50 +01:00
|
|
|
* @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
|
|
|
|
*
|
2007-10-19 17:42:30 +02:00
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
2008-02-10 08:59:34 +01:00
|
|
|
* @since 2.5
|
2007-10-19 17:42:30 +02:00
|
|
|
*
|
2008-07-03 17:23:22 +02:00
|
|
|
* @param string $data Input string
|
|
|
|
* @return array array(type, value)
|
2007-10-19 17:42:30 +02:00
|
|
|
*/
|
|
|
|
function prep_atom_text_construct($data) {
|
|
|
|
if (strpos($data, '<') === false && strpos($data, '&') === false) {
|
|
|
|
return array('text', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$parser = xml_parser_create();
|
|
|
|
xml_parse($parser, '<div>' . $data . '</div>', true);
|
|
|
|
$code = xml_get_error_code($parser);
|
|
|
|
xml_parser_free($parser);
|
|
|
|
|
|
|
|
if (!$code) {
|
2007-12-28 22:21:50 +01:00
|
|
|
if (strpos($data, '<') === false) {
|
|
|
|
return array('text', $data);
|
|
|
|
} else {
|
|
|
|
$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
|
|
|
|
return array('xhtml', $data);
|
|
|
|
}
|
2007-10-19 17:42:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($data, ']]>') == false) {
|
|
|
|
return array('html', "<![CDATA[$data]]>");
|
|
|
|
} else {
|
|
|
|
return array('html', htmlspecialchars($data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-11 19:18:22 +01:00
|
|
|
/**
|
2008-07-03 17:23:22 +02:00
|
|
|
* Display the link for the currently displayed feed in a XSS safe way.
|
2008-03-11 19:18:22 +01:00
|
|
|
*
|
2008-07-03 17:23:22 +02:00
|
|
|
* Generate a correct link for the atom:self element.
|
2008-03-11 19:18:22 +01:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.5
|
|
|
|
*/
|
|
|
|
function self_link() {
|
2010-01-04 18:23:29 +01:00
|
|
|
$host = @parse_url(home_url());
|
2008-11-19 00:04:42 +01:00
|
|
|
$host = $host['host'];
|
2009-05-18 18:00:33 +02:00
|
|
|
echo esc_url(
|
2008-11-18 09:24:17 +01:00
|
|
|
'http'
|
2008-09-21 22:41:25 +02:00
|
|
|
. ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://'
|
2008-11-19 00:04:42 +01:00
|
|
|
. $host
|
2008-11-18 09:24:17 +01:00
|
|
|
. stripslashes($_SERVER['REQUEST_URI'])
|
|
|
|
);
|
2008-03-11 19:18:22 +01:00
|
|
|
}
|
|
|
|
|
2009-01-19 06:04:58 +01:00
|
|
|
/**
|
|
|
|
* Return the content type for specified feed type.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
|
|
|
function feed_content_type( $type = '' ) {
|
|
|
|
if ( empty($type) )
|
|
|
|
$type = get_default_feed();
|
|
|
|
|
|
|
|
$types = array(
|
2009-05-16 07:15:21 +02:00
|
|
|
'rss' => 'application/rss+xml',
|
|
|
|
'rss2' => 'application/rss+xml',
|
|
|
|
'rss-http' => 'text/xml',
|
2009-01-19 06:04:58 +01:00
|
|
|
'atom' => 'application/atom+xml',
|
2009-05-16 07:15:21 +02:00
|
|
|
'rdf' => 'application/rdf+xml'
|
2009-01-19 06:04:58 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';
|
|
|
|
|
|
|
|
return apply_filters( 'feed_content_type', $content_type, $type );
|
|
|
|
}
|
|
|
|
|
2009-02-28 02:50:47 +01:00
|
|
|
/**
|
|
|
|
* Build SimplePie object based on RSS or Atom feed from URL.
|
|
|
|
*
|
|
|
|
* @since 2.8
|
|
|
|
*
|
|
|
|
* @param string $url URL to retrieve feed
|
|
|
|
* @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
|
|
|
|
*/
|
2009-02-27 20:32:50 +01:00
|
|
|
function fetch_feed($url) {
|
|
|
|
require_once (ABSPATH . WPINC . '/class-feed.php');
|
|
|
|
|
|
|
|
$feed = new SimplePie();
|
|
|
|
$feed->set_feed_url($url);
|
|
|
|
$feed->set_cache_class('WP_Feed_Cache');
|
2009-03-03 18:41:01 +01:00
|
|
|
$feed->set_file_class('WP_SimplePie_File');
|
2009-12-22 13:48:40 +01:00
|
|
|
$feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url));
|
|
|
|
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
|
2009-02-27 20:32:50 +01:00
|
|
|
$feed->init();
|
|
|
|
$feed->handle_content_type();
|
|
|
|
|
2009-02-28 02:50:47 +01:00
|
|
|
if ( $feed->error() )
|
|
|
|
return new WP_Error('simplepie-error', $feed->error());
|
|
|
|
|
2009-02-27 20:32:50 +01:00
|
|
|
return $feed;
|
|
|
|
}
|