]> git.mjollnir.org Git - s9y.git/commitdiff
Atom 1.0 support
authorgarvinhicking <garvinhicking>
Mon, 8 Aug 2005 09:30:15 +0000 (09:30 +0000)
committergarvinhicking <garvinhicking>
Mon, 8 Aug 2005 09:30:15 +0000 (09:30 +0000)
docs/NEWS
include/functions.inc.php
include/functions_entries.inc.php
include/functions_permalinks.inc.php
include/plugin_internal.inc.php
index.php
rss.php

index 02f83f399e52abf9f5c57f359ba0e3eada639035..83a17088d5a79eca4f3548de51b7cdf2eee115fa 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,8 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Atom 1.0 feed support (garvinhicking)
+
     * Make template directory allow to contain subdirectories with more
       templates. This allows you to symbolically link the "additional_themes"
       CVS directory within your templates path, just like you can do
index d926ff3472abb309afbdbdae8dbaa20493e63121..04a9142389b040c08daf410c19db321b5e1fa6a9 100644 (file)
@@ -551,13 +551,15 @@ function serendipity_discover_rss($name, $ext) {
     }
 
     /* Detect version */
-    if ( $name == 'atom' || $ext == 'atom' ) {
+    if ($name == 'atom' || $name == 'atom10' || $ext == 'atom') {
+        $ver = 'atom1.0';
+    } elseif ($name == 'atom03') {
         $ver = 'atom0.3';
-    } elseif ( $name == 'opml' || $ext == 'opml' ) {
+    } elseif ($name == 'opml' || $ext == 'opml') {
         $ver = 'opml1.0';
-    } elseif ( $ext == 'rss' ) {
+    } elseif ($ext == 'rss') {
         $ver = '0.91';
-    } elseif ( $ext == 'rss1' ) {
+    } elseif ($ext == 'rss1') {
         $ver = '1.0';
     } else {
         $ver = $default;
index 40dd30e00a95830e1f202d149007fcb53387c6b1..789385d6d5cb20aef54fd59174d68eef6e7ed99e 100644 (file)
@@ -817,6 +817,47 @@ function serendipity_printEntries_rss($entries, $version, $comments = false, $fu
     </content>
 </entry>
 <?php
+            } elseif ($version == 'atom1.0') {
+                /*********** ATOM 1.0 FEED *************/
+?>
+<entry>
+    <link href="<?php echo $entryLink; ?>" rel="alternate" title="<?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?>" />
+    <author>
+        <name><?php echo serendipity_utf8_encode(htmlspecialchars($entry['author'])); ?></name>
+        <email><?php echo serendipity_utf8_encode(htmlspecialchars($entry['email'])); ?></email>
+    </author>
+
+    <published><?php echo gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entry['timestamp'])); ?></published>
+    <updated><?php echo gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entry['last_modified'])); ?></updated>
+    <wfw:comment><?php echo $serendipity['baseURL']; ?>wfwcomment.php?cid=<?php echo $id; ?></wfw:comment>
+
+<?php
+                    if ($comments === false) {
+?>
+    <slash:comments><?php echo $entry['comments']; ?></slash:comments>
+    <wfw:commentRss><?php echo $serendipity['baseURL']; ?>rss.php?version=<?php echo $version; ?>&amp;type=comments&amp;cid=<?php echo $id; ?></wfw:commentRss>
+<?php
+                    }
+
+                    foreach ($entry['categories'] AS $idx => $cat) { 
+                        $name = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); ?>
+                        <category scheme="<?php echo serendipity_categoryURL($cat, 'baseURL'); ?>" label="<?php echo $name; ?>" term="<?php echo $name; ?>" />
+<?php
+                    }
+?>
+
+    <id><?php echo $guid; ?></id>
+    <title type="html"><?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?></title>
+    <content type="xhtml" xml:base="<?php echo $serendipity['baseURL']; ?>">
+        <div xmlns="http://www.w3.org/1999/xhtml">
+<?php
+                    echo serendipity_utf8_encode($entry['body'].$ext);
+?>
+        </div>
+    </content>
+</entry>
+<?php
+
             } elseif ($version == '0.91' || $version == '2.0') {
                 /*********** BEGIN RSS 0.91/2.0 FEED *************/
 ?>
index 9a3a9a7f25ee10ad19d1fe7253448d031e7cb8fa..4a969a3fe154db70c9805f41ee5358b7c1819adc 100644 (file)
@@ -192,7 +192,7 @@ function serendipity_initPermalinks() {
      */
     @define('PAT_FILENAME',   '0-9a-z\.\_!;,\+\-');
     @define('PAT_CSS',        '@/(serendipity\.css|serendipity_admin\.css)@');
-    @define('PAT_FEED',       '@/(index|atom|rss|b2rss|b2rdf).(rss|rdf|rss2|xml)$@');
+    @define('PAT_FEED',       '@/(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml)@');
     @define('PAT_COMMENTSUB', '@/([0-9]+)[_\-][' . PAT_FILENAME . ']*\.html@i');
 
     return true;
index 1c9555026c83c3f6bad32ba114b08718af249090..971d3671c2e0689d09dc7765b07880704d1f2d5a 100644 (file)
@@ -546,6 +546,7 @@ class serendipity_syndication_plugin extends serendipity_plugin {
                                         'show_2.0',
                                         'show_2.0c',
                                         'show_atom0.3',
+                                        'show_atom1.0',
                                         'show_opml1.0',
                                         'show_feedburner',
                                         'seperator',
@@ -610,6 +611,13 @@ class serendipity_syndication_plugin extends serendipity_plugin {
                 $propbag->add('type',        'boolean');
                 $propbag->add('name',        SYNDICATION_PLUGIN_ATOM03);
                 $propbag->add('description', '');
+                $propbag->add('default',     'false');
+                break;
+
+            case 'show_atom0.3':
+                $propbag->add('type',        'boolean');
+                $propbag->add('name',        SYNDICATION_PLUGIN_ATOM10);
+                $propbag->add('description', '');
                 $propbag->add('default',     'true');
                 break;
 
@@ -758,8 +766,17 @@ class serendipity_syndication_plugin extends serendipity_plugin {
         if (serendipity_db_bool($this->get_config('show_atom0.3', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="ATOM/XML" style="border: 0px" /></a>
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom.xml', 'serendipityHTTPPath') ?>">ATOM 0.3 feed</a>
+            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom03.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="ATOM/XML" style="border: 0px" /></a>
+            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom03.xml', 'serendipityHTTPPath') ?>">ATOM 0.3 feed</a>
+        </div>
+<?php
+        }
+
+        if (serendipity_db_bool($this->get_config('show_atom1.0', true))) {
+?>
+        <div style="padding-bottom: 2px;">
+            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="ATOM/XML" style="border: 0px" /></a>
+            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath') ?>">ATOM 1.0 feed</a>
         </div>
 <?php
         }
@@ -839,6 +856,10 @@ class serendipity_syndication_plugin extends serendipity_plugin {
     </image>
 IMAGE;
 
+        $additional_fields['image_atom1.0'] = <<<IMAGE
+<icon>$img</icon>
+IMAGE;
+
         $additional_fields['image_rss1.0_channel'] = '<image rdf:resource="' . $img . '" />';
         $additional_fields['image_rss1.0_rdf'] = <<<IMAGE
 <image rdf:about="$img">
index 82251701d67cb4a21869427b0fd270e31524a1aa..f317b45e39c7522e2715ab6e89ed4ce042c0f0cd 100644 (file)
--- a/index.php
+++ b/index.php
@@ -236,7 +236,7 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
 } elseif (preg_match(PAT_PERMALINK_FEEDCATEGORIES, $uri, $matches) || preg_match(PAT_FEEDS, $uri)) {
     header('Content-Type: text/html; charset=utf-8');
 
-    if (preg_match('@/(index|atom|rss|comments|opml)\.(rss[0-9]?|rdf|rss|xml|atom)$@', $uri, $vmatches)) {
+    if (preg_match('@/(index|atom[0-9]*|rss|comments|opml)\.(rss[0-9]?|rdf|rss|xml|atom)@', $uri, $vmatches)) {
         list($_GET['version'], $_GET['type']) = serendipity_discover_rss($vmatches[1], $vmatches[2]);
     }
 
diff --git a/rss.php b/rss.php
index 55d8f7a6ec9ec393950e829626733dfc5ef6e954..3d05a547d67239ee53fddad7abbff135f0bbe27e 100644 (file)
--- a/rss.php
+++ b/rss.php
@@ -10,7 +10,7 @@ $description     = $serendipity['blogDescription'];
 $title           = $serendipity['blogTitle'];
 $comments        = FALSE;
 
-if ( empty($version) ) {
+if (empty($version)) {
     list($version) = serendipity_discover_rss($_GET['file'], $_GET['ext']);
 }
 
@@ -263,6 +263,42 @@ case 'atom0.3':
 HEAD;
 break;
 
+case 'atom1.0':
+    if (is_array($entries)) {
+        $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified']));
+    } else {
+        $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour());
+    }
+
+    if ($showMail) {
+        $head_mail = "<admin:errorReportsTo rdf:resource=\"mailto:{$metadata['email']}\" />";
+    } else {
+        $head_mail = '';
+    }
+
+    print <<<HEAD
+<feed
+   xmlns="http://www.w3.org/2005/Atom"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:admin="http://webns.net/mvcb/"
+   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
+   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
+    <link href="{$serendipity['baseURL']}rss.php?version=atom1.0" rel="self" title="{$metadata['title']}" type="application/x.atom+xml" />
+    <link href="{$serendipity['baseURL']}"                        rel="alternate"    title="{$metadata['title']}" type="text/html" />
+    <link href="{$serendipity['baseURL']}rss.php?version=2.0"     rel="alternate"    title="{$metadata['title']}" type="application/rss+xml" />
+    <title type="html">{$metadata['title']}</title>
+    <subtitle type="html">{$metadata['description']}</subtitle>
+    {$metadata['additional_fields']['image_atom1.0']}
+    <id>{$metadata['link']}</id>
+    <updated>$modified</updated>
+    <generator uri="http://www.s9y.org/" version="{$serendipity['version']}">Serendipity {$serendipity['version']} - http://www.s9y.org/</generator>
+    <dc:language>{$metadata['language']}</dc:language>
+    $head_mail
+
+HEAD;
+break;
+
 case 'opml1.0':
     if (is_array($entries)) {
         $modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified']));
@@ -301,6 +337,7 @@ case '1.0':
     }
     print '</rdf:RDF>';
     break;
+case 'atom1.0':
 case 'atom0.3':
     print '</feed>';
     break;