[geeklog-hg] geeklog: Fixed a bug where a link in a feed file was unusable (b...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat Feb 8 00:52:22 EST 2014


changeset 9480:37651ac8fc3f
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/37651ac8fc3f
user: Kenji ITO <mystralkk at gmail.com>
date: Sat Feb 08 14:51:36 2014 +0900
description:
Fixed a bug where a link in a feed file was unusable (bug #0001738) and did some refactoring

diffstat:

 system/classes/syndication/atom.feed.class.php      |  699 ++++++---------
 system/classes/syndication/feedparserbase.class.php |  463 +++++-----
 system/classes/syndication/parserfactory.class.php  |  460 +++++-----
 system/classes/syndication/rdf.feed.class.php       |  369 ++++----
 system/classes/syndication/rss.feed.class.php       |  843 +++++++++----------
 5 files changed, 1294 insertions(+), 1540 deletions(-)

diffs (truncated from 3129 to 300 lines):

diff -r 91d46279eee8 -r 37651ac8fc3f system/classes/syndication/atom.feed.class.php
--- a/system/classes/syndication/atom.feed.class.php	Wed Feb 05 23:38:02 2014 +0900
+++ b/system/classes/syndication/atom.feed.class.php	Sat Feb 08 14:51:36 2014 +0900
@@ -1,194 +1,302 @@
 <?php
-  /****************************************************************************/
-  /* atom.feed.class.php                                                      */
-  /*                                                                          */
-  /****************************************************************************/
-  /* Copyright (c) 2004 Michael Jervis (mike at fuckingbrit.com)                 */
-  /*                                                                          */
-  /* This software is licensed under the terms of the ZLIB License:           */
-  /*                                                                          */
-  /* This software is provided 'as-is', without any express or implied        */
-  /* warranty. In no event will the authors be held liable for any damages    */
-  /* arising from the use of this software.                                   */
-  /*                                                                          */
-  /* Permission is granted to anyone to use this software for any purpose,    */
-  /* including commercial applications, and to alter it and redistribute it   */
-  /* freely, subject to the following restrictions:                           */
-  /*                                                                          */
-  /*  1. The origin of this software must not be misrepresented; you must not */
-  /*     claim that you wrote the original software. If you use this software */
-  /*     in a product, an acknowledgment in the product documentation would be*/
-  /*     appreciated but is not required.                                     */
-  /*                                                                          */
-  /*  2. Altered source versions must be plainly marked as such, and must not */
-  /*     be misrepresented as being the original software.                    */
-  /*                                                                          */
-  /*  3. This notice may not be removed or altered from any source            */
-  /*     distribution.                                                        */
-  /****************************************************************************/
-  // $Id: atom.feed.class.php,v 1.14 2008/09/15 08:15:26 dhaun Exp $
 
-  /**
-    * Provides feed handlers for Atom 0.3 and Atom 1.0
-    *
-    * @author Michael Jervis (mike at fuckingbrit.com)
-    * @version 1.1
-    */
+/****************************************************************************/
+/* atom.feed.class.php                                                      */
+/*                                                                          */
+/****************************************************************************/
+/* Copyright (c) 2004 Michael Jervis (mike at fuckingbrit.com)                 */
+/*                                                                          */
+/* This software is licensed under the terms of the ZLIB License:           */
+/*                                                                          */
+/* This software is provided 'as-is', without any express or implied        */
+/* warranty. In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                   */
+/*                                                                          */
+/* Permission is granted to anyone to use this software for any purpose,    */
+/* including commercial applications, and to alter it and redistribute it   */
+/* freely, subject to the following restrictions:                           */
+/*                                                                          */
+/*  1. The origin of this software must not be misrepresented; you must not */
+/*     claim that you wrote the original software. If you use this software */
+/*     in a product, an acknowledgment in the product documentation would be*/
+/*     appreciated but is not required.                                     */
+/*                                                                          */
+/*  2. Altered source versions must be plainly marked as such, and must not */
+/*     be misrepresented as being the original software.                    */
+/*                                                                          */
+/*  3. This notice may not be removed or altered from any source            */
+/*     distribution.                                                        */
+/****************************************************************************/
+// $Id: atom.feed.class.php,v 1.14 2008/09/15 08:15:26 dhaun Exp $
 
-  /**
-   * atom03 provides reading and writing of Atom 0.3 format syndication feeds.
-   *
-   * @author Michael Jervis (mike at fuckingbrit.com)
-   * @copyright Michael Jervis 2004
-   * @abstract
-   */
-  class Atom03 extends FeedParserBase
-  {
-    /**
-      * @access private
-      * @var boolean
-      */
-    var $_inItem;
+/**
+* Provides feed handlers for Atom 0.3 and Atom 1.0
+*
+* @author Michael Jervis (mike at fuckingbrit.com)
+* @version 1.1
+*/
 
-    /**
-      * @access private
-      * @var array
-      */
-    var $_currentItem;
-
-    function Atom03()
+/**
+* atom10 provides reading and writing of Atom 1.0 format syndication feeds.
+*
+* @author Michael Jervis (mike at fuckingbrit.com)
+* @copyright Michael Jervis 2005
+* @abstract
+*/
+class Atom10 extends FeedParserBase
+{
+    public function __construct()
     {
-      $this->FeedParserBase();
-      $this->_inItem = false;
-    }
-
-    function _RFC3339Date($timestamp='')
-    {
-        $return = '';
-        if( !empty($timestamp) )
-        {
-            $return = strftime("%Y-%m-%dT%T", $timestamp);
-            $suffix = strftime("%z", $timestamp);
-        } else {
-            $return = strftime("%Y-%m-%dT%T");
-            $suffix = strftime("%z");
-        }
-        return $return.substr($suffix,0,3).':'.substr($suffix,3,2);
+        parent::__construct();
+        $this->namespaces = array('xmlns="http://www.w3.org/2005/Atom"');
     }
 
     /**
-      * Format an article into an Atom 0.3 <entry> tag.
-      *
-      * Takes an associative article array and turns it into an XML definition
-      * of an article. Uses merely title, link and summary.
-      *
-      * @param array $article Associative array describing an article.
-      */
-    function _formatArticle( $article )
+    * Format an article into an Atom 0.3 <entry> tag.
+    *
+    * Takes an associative article array and turns it into an XML definition
+    * of an article. Uses merely title, link and summary.
+    *
+    * @param array $article Associative array describing an article.
+    */
+    protected function _formatArticle(array $article)
     {
-      $xml = "<entry>\n";
-      $xml .= '<title mode="escaped">'.$this->_safeXML( $article['title'] )."</title>\n";
-      $xml .= '<link rel="alternate" type="text/html" href="'.$this->_safeXML( $article['link'] )."\"/>\n";
-      $xml .= '<id>'.htmlspecialchars( $article['link'] )."</id>\n";
-      $xml .= '<issued>'.$this->_RFC3339Date( $article['date'] )."</issued>\n";
-      $xml .= '<modified>'.$this->_RFC3339Date( $article['date'] )."</modified>\n";
-      if( array_key_exists( 'author', $article ) )
-      {
-        $xml .= "<author>\n<name>{$article['author']}</name>\n</author>\n";
-      }
-      if( array_key_exists( 'summary', $article ) )
-      {
-        if( !empty( $article['summary'] ) )
-        {
-          $xml .= '<content type="text/html" mode="escaped">'
-                          . $this->_safeXML ($article['summary'])
-                          . "</content>\n";
+        $xml = '<entry>' . self::LB
+             . '<title type="html">' . $this->_safeXML($article['title']) . '</title>' . self::LB
+             . '<link rel="alternate" type="text/html" href="' . $this->_safeXML($article['link'], false) . '"/>' . self::LB
+             . '<id>' . $this->_createId($article['link'], $article['date']) . '</id>' . self::LB
+             . '<published>' . $this->_RFC3339Date($article['date']) . '</published>' . self::LB
+             . '<updated>' . $this->_RFC3339Date($article['date']) . '</updated>' . self::LB;
+
+        if (array_key_exists('author', $article)) {
+            $xml .= '<author>' . self::LB
+                 .  '<name>' . $this->_safeXML($article['author']) . '</name>' . self::LB
+                 . '</author>' . self::LB;
         }
-      }
-      if( is_array( $this->extensions ) )
-      {
-        foreach( $this->extensions as $extendingTag )
-        {
-            $xml .= "$extendingTag\n";
+
+        if (array_key_exists('summary', $article) && !empty($article['summary'])) {
+            $xml .= '<content type="html">'
+                 .  $this->_safeXML($article['summary'])
+                 .  '</content>' . self::LB;
         }
-      }
-      $xml .= "</entry>\n";
-      return $xml;
+
+        if (is_array($this->extensions)) {
+            $xml .= implode(self::LB, $this->extensions) . self::LB;
+        }
+
+        $xml .= '</entry>' . self::LB;
+
+        return $xml;
+    }
+
+    protected function _createId($url, $date)
+    {
+        $start = strpos($url, '/') + 2;
+        $end   = strpos($url, '/', $start);
+        $tag   = 'tag:' . substr($url, $start, $end - $start)
+               . strftime(',%Y-%m-%d', $date) . ':' . substr($url, $end);
+
+        return $tag;
+    }
+
+    private function _RFC3339Date($timestamp = '')
+    {
+        if (empty($timestamp)) {
+            $timestamp = time();
+        }
+
+        return date(DateTime::ATOM, $timestamp);
     }
 
     /**
-      * Return the formatted start of a feed.
-      *
-      * This will start the xml and create header information about the feed
-      * itself.
-      */
-    function _feedHeader()
+    * Return the formatted start of a feed.
+    *
+    * This will start the xml and create header information about the feed
+    * itself.
+    */
+    protected function _feedHeader()
     {
-      $xml = '<?xml version="1.0" encoding="' . $this->encoding . '" ?>' . LB . LB
-           . '<feed version="0.3"  xmlns="http://purl.org/atom/ns#"'.$this->_injectNamespaces().'>' . LB
-           . '<title mode="escaped">' . $this->_safeXML( $this->title ) . '</title>' . LB
-           . '<tagline mode="escaped">' . $this->_safeXML( $this->description ) . '</tagline>' . LB
-           . '<link rel="alternate" type="text/html" href="' . $this->_safeXML( $this->sitelink ) . '"/>' . LB
-           . '<modified>'.$this->_RFC3339Date().'</modified>' . LB
-           . "<author>\n<name>" . $this->_safeXML( $this->title ) . '</name>' . LB
-           . '<email>' . $this->_safeXML( $this->sitecontact ) . "</email>\n</author>\n";
-      $xml .= $this->_injectExtendingTags();
-      return $xml;
+        $xml = parent::_feedHeader()
+             . '<feed' . $this->_injectNamespaces() . '>' . self::LB
+             . '<title type="text">' . $this->_safeXML($this->title) . '</title>' . self::LB
+             . '<subtitle type="text">' . $this->_safeXML($this->description) . '</subtitle>' . self::LB
+             . '<link rel="self" href="' . $this->_safeXML($this->url, false) . '"/>' . self::LB
+             . '<link rel="alternate" type="text/html" href="' . $this->_safeXML($this->sitelink, false) . '/"/>' . self::LB;
+
+
+        if ($this->feedlogo != '') {
+            $xml .= '<logo>' . $this->_safeXML($this->feedlogo) . '</logo>' . self::LB;
+        }
+
+        $xml .= '<id>' . $this->_safeXML($this->sitelink, false) . '/</id>' . self::LB
+             .  '<updated>' . $this->_RFC3339Date() . '</updated>' . self::LB
+             .  '<author>' . self::LB . '<name>' . $this->_safeXML($this->title) . '</name>' . self::LB
+             .  '<email>' . $this->_safeXML($this->sitecontact) . '</email>' . self::LB
+             .  '</author>' . self::LB
+             .  $this->_injectExtendingTags();
+
+        return $xml;
     }
 
     /**
-      * Return the formatted end of a feed.
-      *
-      * just closes things off nicely.
-      */
-    function _feedFooter()
+    * Return the formatted end of a feed.
+    *
+    * just closes things off nicely.
+    */
+    protected function _feedFooter()
     {
-      $xml = "</feed>\n";
-      return $xml;
+        return '</feed>' . self::LB;
     }
 
     /**
-      * Handle the begining of an XML element
-      *
-      * This is called from the parserfactory once the type of data has been
-      * determined. Standard XML_PARSER element handler.
-      *
-      * @author Michael Jervis (mike at fuckingbrit.com)
-      * @copyright Michael Jervis 2004
-      */
-    function startElement($parser, $name, $attributes)
+    * Handle the begining of an XML element
+    *
+    * This is called from the parserfactory once the type of data has been
+    * determined. Standard XML_PARSER element handler.
+    *
+    * @author Michael Jervis (mike at fuckingbrit.com)
+    * @copyright Michael Jervis 2004
+    */



More information about the geeklog-cvs mailing list