<?php
// Atom 1.0 feed generator for WordPress
// Distributed under the terms of the GNU General Public License v2
// Based on the Atom 0.3 generator for WP 1.5 <http://trac.wordpress.org/file/tags/1.5.1.3/wp-atom.php>
// the patch in trac by comatoast <http://trac.wordpress.org/ticket/1526>
// and modifications by Federico <http://511.dabomb.com.ar/testcase/atom1.0/atom-source.txt>
// Further modifications by Ben de Groot <http://d10e.net/>, version 15/12/2005
// See also http://dev.d10e.net/nb/2005/07/27/how-to-use-atom-10-with-wordpress

if (empty($feed)) {
    
$blog 1;
    
$feed 'atom';
    
$doing_rss 1;
    require(
'wp-blog-header.php');
}

// this function ideally should go into wp-includes/feed-functions.php
function atom_enclosure() {
    global 
$id$post;
    if (!empty(
$post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password)) return;

    
$custom_fields get_post_custom();
    if( 
is_array$custom_fields ) ) {
        while( list( 
$key$val ) = each$custom_fields ) ) {
            if( 
$key == 'enclosure' ) {
                if (
is_array($val)) {
                    foreach(
$val as $enc) {
                        
$enclosure split"\n"$enc );
                        print 
"<link rel=\"enclosure\" href=\"".trimhtmlspecialchars($enclosure]) )."\" length=\"".trim$enclosure] )."\" type=\"".trim$enclosure] )."\"/>\n";
                    }
                }
            }
        }
    }
}

header('Content-type: application/atom+xml; charset=' get_settings('blog_charset'), true);
$more 1;
?>
<?php 
echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'."\n"?>
<feed xmlns="http://www.w3.org/2005/Atom"
      xml:lang="<?php echo get_option('rss_language'); ?>"
      <?php do_action('atom_ns'); ?>>
    <title><?php bloginfo_rss('name'); ?></title>
    <subtitle><?php bloginfo_rss('description'); ?></subtitle>
    <id><?php bloginfo('url'); ?>/</id>
    <link rel="self" type="application/atom+xml" href="<?php bloginfo('atom_url'); ?>"/>
    <link rel="alternate" type="<?php bloginfo('html_type'); ?>" href="<?php bloginfo_rss('home'); ?>/"/>
    <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z'get_lastpostmodified('GMT'), false); ?></updated>
    <rights>Copyright <?php echo mysql2date('Y'get_lastpostdate('blog'), 0); ?></rights>
    <generator uri="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress</generator>
    <?php do_action('atom_head'); ?>
<?php $items_count 
0; if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <entry>
        <author>
            <name><?php the_author(); ?></name>
        </author>
        <title type="html"><![CDATA[ <?php the_title_rss(); ?> ]]></title>
        <link rel="alternate" type="<?php bloginfo('html_type'); ?>" href="<?php permalink_single_rss(); ?>"/>
        <id><?php permalink_single_rss(); ?></id>
        <published><?php echo get_post_time('Y-m-d\TH:i:s\Z'true); ?></published>
        <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z',$post->post_modified_gmt); ?></updated>
<?php
    $categories_path 
get_category_link(0);
    
$categories get_the_category();
    foreach (
$categories as $cat) { ?>
        <category scheme="<?php echo $categories_path?>"
                  term="<?php $foo "/" str_replace('/','\/',$categories_path) . "/";
                            echo 
preg_replace($foo,'',get_category_link($cat->cat_ID)); ?>"
                  label="<?php echo $cat->cat_name?>"/>
<?php ?>
        <summary type="html">
            <![CDATA[ <?php the_excerpt_rss(); ?> ]]>
        </summary>
<?php if ( !get_settings('rss_use_excerpt') ) : ?>
        <content type="html">
            <![CDATA[ <?php the_content(''0''?> ]]>
        </content>
        <?php atom_enclosure(); ?>
        <?php do_action('atom_entry'); ?>
<?php 
endif; ?>
    </entry>
<?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?>
</feed>