Recent Topics

0.9.1: upgrading Atom 0.3 to Atom 1.0

Started by on Nov 11, 2005 – Contents updated: Nov 11, 2005

Nov 11, 2005 21:03    

The Atom feed is 0.3, which some consider to be obsolete. If you're interested in upgrading the feeder to 1.0, here's the patch:

If you still need the 0.3 feed, just name the patched files "atom1.php" and "atom1.comments.php"

Code

--- /root/b2evolution/blogs/xmlsrv/atom.php     2005-09-14 20:11:52.000000000 -0400
+++ atom.php    2005-11-11 14:57:00.621227861 -0500
@@ -23,29 +23,30 @@
        // header("Content-type: text/xml");
        echo '<?xml version="1.0" encoding="utf-8"?'.'>';
?>
-<feed version="0.3" xml:lang="<?php $Blog->disp( 'locale', 'xml' ) ?>" xmlns="http://purl.org/atom/ns#">
+<feed xml:lang="<?php $Blog->disp( 'locale', 'xml' ) ?>" xmlns="http://www.w3.org/2005/Atom">
        <title><?php
                $Blog->disp( 'name', 'xml' );
                single_cat_title( ' - ', 'xml' );
                single_month_title( ' - ', 'xml' );
                single_post_title( ' - ', 'xml' );
        ?></title>
-       <link rel="alternate" type="text/html" href="<?php $Blog->disp( 'blogurl', 'xml' ) ?>" />
-       <tagline><?php $Blog->disp( 'shortdesc', 'xml' ) ?></tagline>
-       <generator url="http://b2evolution.net/" version="<?php echo $b2_version ?>">b2evolution</generator>
-       <modified><?php $MainList->mod_date( 'isoZ', true ) ?></modified>
+       <link rel="self" type="text/html" href="<?php $Blog->disp( 'atom_url', 'xmlattr' ) ?>" />
+       <subtitle><?php $Blog->disp( 'shortdesc', 'xml' ) ?></subtitle>
+       <generator uri="http://b2evolution.net/" version="<?php echo $b2_version ?>">b2evolution</generator>
+       <updated><?php $MainList->mod_date( 'isoZ', true ) ?></updated>
+       <id><?php echo $baseurl . '/' ?></id>
        <?php while( $Item = $MainList->get_item() ) {  ?>
        <entry>
-               <title type="text/plain" mode="xml"><?php $Item->title( '', '', false, 'xml' ) ?></title>
+               <title type="text"><?php $Item->title( '', '', false, 'xml' ) ?></title>
                <link rel="alternate" type="text/html" href="<?php $Item->permalink( 'single' ) ?>" />
                <author>
                        <name><?php $Item->Author->prefered_name( 'xml' ) ?></name>
-                       <?php $Item->Author->url( '<url>', "</url>\n", 'xml' ) ?>
+                       <?php $Item->Author->url( '<uri>', "</uri>\n", 'xml' ) ?>
                </author>
                <id><?php $Item->permalink( 'single' ) ?></id>
-               <issued><?php $Item->issue_date( 'isoZ', true ) ?></issued>
-               <modified><?php $Item->mod_date( 'isoZ', true ) ?></modified>
-               <content type="text/html" mode="escaped"><![CDATA[<?php
+               <published><?php $Item->issue_date( 'isoZ', true ) ?></published>
+               <updated><?php $Item->mod_date( 'isoZ', true ) ?></updated>
+               <content type="html"><![CDATA[<?php
                        $Item->url_link( '<p>', '</p>' );
                        $Item->content()
                ?>]]></content>

Code

--- /root/b2evolution/blogs/xmlsrv/atom.comments.php    2005-09-14 20:11:52.000000000 -0400
+++ atom.comments.php   2005-11-11 15:00:26.733336130 -0500
@@ -22,7 +22,7 @@
        header("Content-type: application/atom+xml");
        echo '<?xml version="1.0" encoding="utf-8"?'.'>';
?>
-<feed version="0.3" xml:lang="<?php $Blog->disp( 'locale', 'xml' ) ?>" xmlns="http://purl.org/atom/ns#">
+<feed xml:lang="<?php $Blog->disp( 'locale', 'xml' ) ?>" xmlns="http://www.w3.org/2005/Atom">
        <title><?php
                $Blog->disp( 'name', 'xml' );
                single_cat_title( ' - ', 'xml' );
@@ -30,22 +30,23 @@
                single_post_title( ' - ', 'xml' );
                last_comments_title( ' - ', 'xml' ) ;
        ?></title>
-       <link rel="alternate" type="text/html" href="<?php $Blog->disp( 'lastcommentsurl', 'xml' ) ?>" />
-       <generator url="http://b2evolution.net/" version="<?php echo $b2_version ?>">b2evolution</generator>
-       <modified><?php echo gmdate('Y-m-d\TH:i:s\Z'); ?></modified>
+        <link rel="self" type="text/html" href="<?php $Blog->disp( 'comments_atom_url', 'xmlattr' ) ?>" />
+       <generator uri="http://b2evolution.net/" version="<?php echo $b2_version ?>">b2evolution</generator>
+       <updated><?php echo gmdate('Y-m-d\TH:i:s\Z'); ?></updated>
+        <id><?php echo $baseurl . '/' ?></id>
        <?php while( $Comment = $CommentList->get_next() )
        { // Loop through comments: ?>
        <entry>
-               <title type="text/plain" mode="xml"><?php echo format_to_output( T_('In response to:'), 'xml' ) ?> <?php $Comment->Item->title( '', '', false, 'xml' ) ?></title>
+               <title type="text"><?php echo format_to_output( T_('In response to:'), 'xml' ) ?> <?php $Comment->Item->title( '', '', false, 'xml' ) ?></title>
                <link rel="alternate" type="text/html" href="<?php $Comment->permalink() ?>" />
                <author>
                        <name><?php $Comment->author( '', '#', '', '#', 'xml' ) ?></name>
                        <?php $Comment->author_url( '', '<url>', "</url>\n", false ) ?>
                </author>
                <id><?php $Comment->permalink() ?></id>
-               <issued><?php $Comment->date( 'isoZ', true ); ?></issued>
-               <modified><?php $Comment->date( 'isoZ', true ); ?></modified>
-               <content type="text/html" mode="escaped"><![CDATA[<?php $Comment->content() ?>]]></content>
+               <published><?php $Comment->date( 'isoZ', true ); ?></published>
+               <updated><?php $Comment->date( 'isoZ', true ); ?></updated>
+               <content type="html"><![CDATA[<?php $Comment->content() ?>]]></content>
        </entry>
        <?php } // End of comment loop. ?>
</feed>

Nov 23, 2005 20:39

Thanks for the starting point. This will need a little more refinement though. I added some stuff in CVS. Will be in Phoenix too.

Aug 10, 2006 17:54

Nice. The only thing I had to change to get it to validate without warnings was the line

<link rel="self" type="text/html" href="<?php $Blog->disp( 'atom_url', 'xmlattr' ) ?>" />

to:

<link rel="self" type="application/atom+xml" href="<?php $Blog->disp( 'atom_url', 'xmlattr' ) ?>" />

Also I added the [URL=http://forums.b2evolution.net/viewtopic.php?t=4770]RSS cache hack[/URL]


Form is loading...

multiblog platform – This forum is powered by b2evolution CMS, a complete engine for your website.