New feed_link functions. Deprecate rss_link functions. Make default feed pluggable. Props rubys. see #5328

git-svn-id: http://svn.automattic.com/wordpress/trunk@6365 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-12-06 19:58:15 +00:00
parent 028a159440
commit 83afcae858
7 changed files with 151 additions and 115 deletions

View File

@ -366,7 +366,7 @@ function wp_list_authors($args = '') {
$defaults = array(
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '', 'echo' => true
'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
);
$r = wp_parse_args( $args, $defaults );

View File

@ -247,7 +247,7 @@ function wp_list_categories($args = '') {
'order' => 'ASC', 'show_last_update' => 0,
'style' => 'list', 'show_count' => 0,
'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '',
'child_of' => 0, 'feed' => '', 'feed_type' => '',
'feed_image' => '', 'exclude' => '',
'hierarchical' => true, 'title_li' => __('Categories'),
'echo' => 1

View File

@ -599,7 +599,7 @@ class Walker_Category extends Walker {
if ( empty($feed_image) )
$link .= '(';
$link .= '<a href="' . get_category_rss_link( 0, $category->term_id, $category->slug ) . '"';
$link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
if ( empty($feed) )
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';

View File

@ -729,4 +729,24 @@ function get_linkcatname($id = 0) {
return $cat->name;
}
function comments_rss_link($link_text = 'Comments RSS', $deprecated = '') {
post_comments_feed_link($link_text);
}
function get_category_rss_link($echo = false, $cat_ID, $deprecated = '') {
$link = get_category_feed_link($cat_ID, $feed = 'rss2');
if ( $echo )
echo $link;
return $link;
}
function get_author_rss_link($echo = false, $author_id, $deprecated = '') {
$link = get_author_feed_link($author_id);
if ( $echo )
echo $link;
return $link;
}
?>

View File

@ -5,11 +5,14 @@ function get_bloginfo_rss($show = '') {
return apply_filters('get_bloginfo_rss', convert_chars($info));
}
function bloginfo_rss($show = '') {
echo apply_filters('bloginfo_rss', get_bloginfo_rss($show));
}
function get_default_feed() {
return apply_filters('default_feed', 'rss2');
}
function get_wp_title_rss($sep = '&#187;') {
$title = wp_title($sep, false);
if ( is_wp_error( $title ) )
@ -80,103 +83,24 @@ function comment_link() {
echo get_comment_link();
}
function get_comment_author_rss() {
return apply_filters('comment_author_rss', get_comment_author() );
}
function comment_author_rss() {
echo get_comment_author_rss();
}
function comment_text_rss() {
$comment_text = get_comment_text();
$comment_text = apply_filters('comment_text_rss', $comment_text);
echo $comment_text;
}
function comments_rss_link($link_text = 'Comments RSS', $deprecated = '') {
$url = get_post_comments_feed_link();
echo "<a href='$url'>$link_text</a>";
}
function comments_rss($deprecated = '') {
return get_post_comments_feed_link();
}
function get_author_rss_link($echo = false, $author_id, $author_nicename) {
$author_id = (int) $author_id;
$permalink_structure = get_option('permalink_structure');
if ( '' == $permalink_structure ) {
$link = get_option('home') . '?feed=rss2&amp;author=' . $author_id;
} else {
$link = get_author_posts_url($author_id, $author_nicename);
$link = trailingslashit($link) . user_trailingslashit('feed', 'feed');
}
$link = apply_filters('author_feed_link', $link);
if ( $echo )
echo $link;
return $link;
}
/** get_category_feed_link() - Get the feed link for a given category
*
* Returns a link to the feed for all post in a given category. A specific feed can be requested
* or left blank to get the default feed.
*
* @package WordPress
* @subpackage Feed
* @since 2.4
*
* @param int $cat_id ID of a category
* @param string $feed Feed type
* @return string Link to the feed for the category specified by $cat_id
*/
function get_category_feed_link($cat_id, $feed = 'rss2') {
$cat_id = (int) $cat_id;
$category = get_category($cat_id);
if ( empty($category) || is_wp_error($category) )
return false;
$permalink_structure = get_option('permalink_structure');
if ( '' == $permalink_structure ) {
$link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
} else {
$link = get_category_link($cat_id);
if( 'rss2' == $feed )
$feed_link = 'feed';
else
$feed_link = "feed/$feed";
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
}
$link = apply_filters('category_feed_link', $link, $feed);
return $link;
}
function get_category_rss_link($echo = false, $cat_ID, $deprecated = '') {
$link = get_category_feed_link($cat_ID, 'rss2');
if ( $echo )
echo $link;
return $link;
}
function get_the_category_rss($type = 'rss') {
$categories = get_the_category();
$tags = get_the_tags();
@ -209,37 +133,10 @@ function get_the_category_rss($type = 'rss') {
return apply_filters('the_category_rss', $the_list, $type);
}
function the_category_rss($type = 'rss') {
echo get_the_category_rss($type);
}
function get_tag_feed_link($tag_id, $feed = 'rss2') {
$tag_id = (int) $tag_id;
$tag = get_tag($tag_id);
if ( empty($tag) || is_wp_error($tag) )
return false;
$permalink_structure = get_option('permalink_structure');
if ( '' == $permalink_structure ) {
$link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
} else {
$link = get_tag_link($tag->term_id);
if ( 'rss2' == $feed )
$feed_link = 'feed';
else
$feed_link = "feed/$feed";
$link = $link . user_trailingslashit($feed_link, 'feed');
}
$link = apply_filters('tag_feed_link', $link, $feed);
return $link;
}
function html_type_rss() {
$type = get_bloginfo('html_type');
if (strpos($type, 'xhtml') !== false)

View File

@ -863,7 +863,7 @@ function do_feed() {
$feed = preg_replace( '/^_+/', '', $feed );
if ( $feed == '' || $feed == 'feed' )
$feed = 'rss2';
$feed = get_default_feed();
$hook = 'do_feed_' . $feed;
do_action( $hook, $wp_query->is_comment_feed );

View File

@ -230,7 +230,7 @@ function get_day_link($year, $month, $day) {
}
}
function get_feed_link($feed='rss2') {
function get_feed_link($feed = '') {
global $wp_rewrite;
$permalink = $wp_rewrite->get_feed_permastruct();
@ -240,13 +240,16 @@ function get_feed_link($feed='rss2') {
$permalink = $wp_rewrite->get_comment_feed_permastruct();
}
if ( 'rss2' == $feed )
if ( get_default_feed() == $feed )
$feed = '';
$permalink = str_replace('%feed%', $feed, $permalink);
$permalink = preg_replace('#/+#', '/', "/$permalink");
$output = get_option('home') . user_trailingslashit($permalink, 'feed');
} else {
if ( empty($feed) )
$feed = get_default_feed();
if ( false !== strpos($feed, 'comments_') )
$feed = str_replace('comments_', 'comments-', $feed);
@ -256,15 +259,18 @@ function get_feed_link($feed='rss2') {
return apply_filters('feed_link', $output, $feed);
}
function get_post_comments_feed_link($post_id = '', $feed = 'rss2') {
function get_post_comments_feed_link($post_id = '', $feed = '') {
global $id;
if ( empty($post_id) )
$post_id = (int) $id;
if ( empty($feed) )
$feed = get_default_feed();
if ( '' != get_option('permalink_structure') ) {
$url = trailingslashit( get_permalink($post_id) ) . 'feed';
if ( 'rss2' != $feed )
if ( $feed != get_default_feed() )
$url .= "/$feed";
$url = user_trailingslashit($url, 'single_feed');
} else {
@ -278,6 +284,119 @@ function get_post_comments_feed_link($post_id = '', $feed = 'rss2') {
return apply_filters('post_comments_feed_link', $url);
}
/** post_comments_feed_link() - Output the comment feed link for a post.
*
* Prints out the comment feed link for a post. Link text is placed in the
* anchor. If no link text is specified, default text is used. If no post ID
* is specified, the current post is used.
*
* @package WordPress
* @subpackage Feed
* @since 2.4
*
* @param string Descriptive text
* @param int Optional post ID. Default to current post.
* @return string Link to the comment feed for the current post
*/
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
$url = get_post_comments_feed_link($post_id, $feed);
if ( empty($link_text) )
$link_text = __('Comments Feed');
echo "<a href='$url'>$link_text</a>";
}
function get_author_feed_link( $author_id, $feed = '' ) {
$author_id = (int) $author_id;
$permalink_structure = get_option('permalink_structure');
if ( empty($feed) )
$feed = get_default_feed();
if ( '' == $permalink_structure ) {
$link = get_option('home') . '?feed=rss2&amp;author=' . $author_id;
} else {
$link = get_author_posts_url($author_id, $author_nicename);
$link = trailingslashit($link) . user_trailingslashit('feed', 'feed');
}
$link = apply_filters('author_feed_link', $link);
return $link;
}
/** get_category_feed_link() - Get the feed link for a given category
*
* Returns a link to the feed for all post in a given category. A specific feed can be requested
* or left blank to get the default feed.
*
* @package WordPress
* @subpackage Feed
* @since 2.4
*
* @param int $cat_id ID of a category
* @param string $feed Feed type
* @return string Link to the feed for the category specified by $cat_id
*/
function get_category_feed_link($cat_id, $feed = '') {
$cat_id = (int) $cat_id;
$category = get_category($cat_id);
if ( empty($category) || is_wp_error($category) )
return false;
if ( empty($feed) )
$feed = get_default_feed();
$permalink_structure = get_option('permalink_structure');
if ( '' == $permalink_structure ) {
$link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
} else {
$link = get_category_link($cat_id);
if( $feed == get_default_feed() )
$feed_link = 'feed';
else
$feed_link = "feed/$feed";
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
}
$link = apply_filters('category_feed_link', $link, $feed);
return $link;
}
function get_tag_feed_link($tag_id, $feed = '') {
$tag_id = (int) $tag_id;
$tag = get_tag($tag_id);
if ( empty($tag) || is_wp_error($tag) )
return false;
$permalink_structure = get_option('permalink_structure');
if ( empty($feed) )
$feed = get_default_feed();
if ( '' == $permalink_structure ) {
$link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
} else {
$link = get_tag_link($tag->term_id);
if ( $feed == get_default_feed() )
$feed_link = 'feed';
else
$feed_link = "feed/$feed";
$link = $link . user_trailingslashit($feed_link, 'feed');
}
$link = apply_filters('tag_feed_link', $link, $feed);
return $link;
}
function get_edit_post_link( $id = 0 ) {
$post = &get_post( $id );