WordPress.org

Make WordPress Core

Changeset 10377


Ignore:
Timestamp:
01/19/2009 05:04:58 AM (9 years ago)
Author:
azaozz
Message:

Add support for automatic feed links in themes, props Viper007Bond, see #8878

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/classic/functions.php

    r8999 r10377  
    44 * @subpackage Classic_Theme
    55 */
     6
     7automatic_feed_links();
     8
    69if ( function_exists('register_sidebar') )
    710    register_sidebar(array(
  • trunk/wp-content/themes/classic/header.php

    r9376 r10377  
    1717    </style>
    1818
    19     <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
    20     <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
    21     <link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php bloginfo('atom_url'); ?>" />
    22 
    2319    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    2420    <?php wp_get_archives('type=monthly&format=link'); ?>
  • trunk/wp-content/themes/default/functions.php

    r10137 r10377  
    55 */
    66
    7 if ( function_exists('register_sidebar') )
    8     register_sidebar(array(
    9         'before_widget' => '<li id="%1$s" class="widget %2$s">',
    10         'after_widget' => '</li>',
    11         'before_title' => '<h2 class="widgettitle">',
    12         'after_title' => '</h2>',
    13     ));
     7automatic_feed_links();
     8
     9if ( function_exists('register_sidebar') ) {
     10    register_sidebar(array(
     11        'before_widget' => '<li id="%1$s" class="widget %2$s">',
     12        'after_widget' => '</li>',
     13        'before_title' => '<h2 class="widgettitle">',
     14        'after_title' => '</h2>',
     15    ));
     16}
    1417
    1518/** @ignore */
  • trunk/wp-content/themes/default/header.php

    r9376 r10377  
    1414
    1515<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    16 <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
    17 <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
    1816<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    1917
  • trunk/wp-includes/default-filters.php

    r10357 r10377  
    165165
    166166// Actions
     167add_action('wp_head', 'feed_links_extra', 3);
    167168add_action('wp_head', 'rsd_link');
    168169add_action('wp_head', 'wlwmanifest_link');
  • trunk/wp-includes/feed-atom-comments.php

    r10215 r10377  
    66 */
    77
    8 header('Content-Type: application/atom+xml; charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
    99echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>';
    1010?>
  • trunk/wp-includes/feed-atom.php

    r7772 r10377  
    66 */
    77
    8 header('Content-Type: application/atom+xml; charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
    99$more = 1;
    1010
  • trunk/wp-includes/feed-rdf.php

    r6493 r10377  
    66 */
    77
    8 header('Content-Type: application/rdf+xml; charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('rdf') . '; charset=' . get_option('blog_charset'), true);
    99$more = 1;
    1010
  • trunk/wp-includes/feed-rss.php

    r6493 r10377  
    66 */
    77
    8 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('rss') . '; charset=' . get_option('blog_charset'), true);
    99$more = 1;
    1010
  • trunk/wp-includes/feed-rss2-comments.php

    r10068 r10377  
    66 */
    77
    8 header('Content-Type: text/xml;charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
    99
    1010echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
  • trunk/wp-includes/feed-rss2.php

    r8619 r10377  
    66 */
    77
    8 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
     8header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
    99$more = 1;
    1010
  • trunk/wp-includes/feed.php

    r10332 r10377  
    509509}
    510510
     511/**
     512 * Return the content type for specified feed type.
     513 *
     514 * @package WordPress
     515 * @subpackage Feed
     516 * @since 2.8.0
     517 */
     518function feed_content_type( $type = '' ) {
     519    if ( empty($type) )
     520        $type = get_default_feed();
     521
     522    $types = array(
     523        'rss'  => 'application/rss+xml',
     524        'rss2' => 'application/rss+xml',
     525        'atom' => 'application/atom+xml',
     526        'rdf'  => 'application/rdf+xml',
     527    );
     528
     529    $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';
     530
     531    return apply_filters( 'feed_content_type', $content_type, $type );
     532}
     533
    511534?>
  • trunk/wp-includes/general-template.php

    r10356 r10377  
    13701370
    13711371/**
     1372 * Enable/disable automatic general feed link outputting.
     1373 *
     1374 * @since 2.8.0
     1375 *
     1376 * @param boolean $add Add or remove links. Defaults to true.
     1377 */
     1378function automatic_feed_links( $add = true ) {
     1379    if ( $add )
     1380        add_action( 'wp_head', 'feed_links', 2 );
     1381    else {
     1382        remove_action( 'wp_head', 'feed_links', 2 );
     1383        remove_action( 'wp_head', 'feed_links_extra', 3 );
     1384    }
     1385}
     1386
     1387/**
     1388 * Display the links to the general feeds.
     1389 *
     1390 * @since 2.8.0
     1391 *
     1392 * @param array $args Optional arguments.
     1393 */
     1394function feed_links( $args ) {
     1395    $defaults = array(
     1396        'seperator'   => _c('&raquo;|Seperator character feed titles in theme head'),
     1397        'rsstitle'    => __('%s Feed'),
     1398        'comstitle'   => __('%s Comments Feed'),
     1399    );
     1400
     1401    $args = wp_parse_args( $args, $defaults );
     1402
     1403    echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['rsstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link() . "\" />\n";
     1404    echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['comstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
     1405}
     1406
     1407/**
     1408 * Display the links to the extra feeds such as category feeds.
     1409 *
     1410 * @since 2.8.0
     1411 *
     1412 * @param array $args Optional arguments.
     1413 */
     1414function feed_links_extra( $args ) {
     1415    $defaults = array(
     1416        'seperator'   => _c('&raquo;|Seperator character feed titles in theme head'),
     1417        'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
     1418        'cattitle'    => __('%1$s %2$s %3$s Category Feed'),
     1419        'tagtitle'    => __('%1$s %2$s %3$s Tag Feed'),
     1420        'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
     1421        'searchtitle' => __('%1$s %2$s Search Results for &quot;%3$s&quot; Feed'),
     1422    );
     1423
     1424    $args = wp_parse_args( $args, $defaults );
     1425
     1426    if ( is_single() || is_page() ) {
     1427        $post = &get_post( $id = 0 );
     1428        if ( comments_open() || pings_open() || $post->comment_count > 0 )
     1429            echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['singletitle'], get_bloginfo('name'), $args['seperator'], get_the_title() ) . '" href="' . get_post_comments_feed_link( $post->ID ) . "\" />\n";
     1430    }
     1431
     1432    elseif ( is_category() ) {
     1433        $cat_id = intval( get_query_var('cat') );
     1434        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['cattitle'], get_bloginfo('name'), $args['seperator'], get_cat_name( $cat_id ) ) . '" href="' . get_category_feed_link( $cat_id ) . "\" />\n";
     1435    }
     1436
     1437    elseif ( is_tag() ) {
     1438        $tag_id = intval( get_query_var('tag_id') );
     1439        $tag = get_tag( $tag_id );
     1440        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['tagtitle'], get_bloginfo('name'), $args['seperator'], $tag->name ) . '" href="' . get_tag_feed_link( $tag_id ) . "\" />\n";
     1441    }
     1442
     1443    elseif ( is_author() ) {
     1444        $author_id = intval( get_query_var('author') );
     1445        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['authortitle'], get_bloginfo('name'), $args['seperator'], get_author_name( $author_id ) ) . '" href="' . get_author_feed_link( $author_id ) . "\" />\n";
     1446    }
     1447
     1448    elseif ( is_search() ) {
     1449        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['searchtitle'], get_bloginfo('name'), $args['seperator'], get_search_query() ) . '" href="' . get_search_feed_link() . "\" />\n";
     1450    }
     1451}
     1452
     1453/**
    13721454 * Display the link to the Really Simple Discovery service endpoint.
    13731455 *
  • trunk/wp-includes/link-template.php

    r10361 r10377  
    508508
    509509    if ( '' == $permalink_structure ) {
    510         $link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
     510        $link = trailingslashit( get_option('home') ) . "?feed=$feed&amp;cat=" . $cat_id;
    511511    } else {
    512512        $link = get_category_link($cat_id);
Note: See TracChangeset for help on using the changeset viewer.