Alpha Framework alpha--util--feeds
[ class tree: alpha--util--feeds ] [ index: alpha--util--feeds ] [ all elements ]

Source for file Atom.inc

Documentation is available at Atom.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/feeds/AlphaFeed.inc';
  4.  
  5. /**
  6.  * Atom class for syndication
  7.  * 
  8.  * @package alpha::util::feeds
  9.  * @since 1.0
  10.  * @author John Collins <dev@alphaframework.org>
  11.  * @version $Id: Atom.inc 1341 2011-03-17 15:02:02Z johnc $
  12.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  13.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  14.  *  All rights reserved.
  15.  * 
  16.  *  <pre>
  17.  *  Redistribution and use in source and binary forms, with or
  18.  *  without modification, are permitted provided that the
  19.  *  following conditions are met:
  20.  * 
  21.  *  * Redistributions of source code must retain the above
  22.  *    copyright notice, this list of conditions and the
  23.  *    following disclaimer.
  24.  *  * Redistributions in binary form must reproduce the above
  25.  *    copyright notice, this list of conditions and the
  26.  *    following disclaimer in the documentation and/or other
  27.  *    materials provided with the distribution.
  28.  *  * Neither the name of the Alpha Framework nor the names
  29.  *    of its contributors may be used to endorse or promote
  30.  *    products derived from this software without specific
  31.  *    prior written permission.
  32.  *   
  33.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  34.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  35.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  36.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  38.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  40.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  42.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  43.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  44.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.  *  </pre>
  47.  *  
  48.  */
  49. class Atom extends AlphaFeed {
  50.     /**
  51.      * The XML namespace
  52.      * 
  53.      * @var string 
  54.      * @since 1.0
  55.      */
  56.     protected $nameSpace = 'http://www.w3.org/2005/Atom';
  57.  
  58.     /**
  59.      * The actual root tag used in each feed type
  60.      * 
  61.      * @var string 
  62.      * @since 1.0
  63.      */
  64.     protected $rootTag = '<feed xmlns="http://www.w3.org/2005/Atom" />';
  65.     
  66.     /**
  67.      * If the feed format has a channel or not
  68.      * 
  69.      * @var boolean 
  70.      * @since 1.0
  71.      */
  72.     protected $hasChannel = false;
  73.     
  74.     /**
  75.      * Maps the tags to the feed-specific tags
  76.      * 
  77.      * @var array 
  78.      * @since 1.0
  79.      */
  80.     protected $tagMap = array('item'=>'entry','feeddesc'=>'subtitle','itemdesc'=>'summary');
  81.         
  82.     /**
  83.      * (non-PHPdoc)
  84.      * @see alpha/util/feeds/AlphaFeed::createLink()
  85.      */
  86.     protected function createLink($parent$url{
  87.         $link $this->rssDoc->createElementNS($this->nameSpace'link');
  88.         $parent->appendChild($link);
  89.         $link->setAttribute('href'$url);
  90.     }
  91.     
  92.     /**
  93.      * Constructor to create a new Atom feed
  94.      * 
  95.      * @param string $title 
  96.      * @param string $url 
  97.      * @param string $description 
  98.      * @param string $pubDate 
  99.      * @param integer $id 
  100.      * @since 1.0
  101.      */
  102.     public function __construct($title$url$description$pubDate null$id null{
  103.         if(empty($id))
  104.             $id $url;
  105.         if(empty($pubDate))
  106.             $pubDate date("Y-m-d");
  107.         parent::__construct($title$url$description$pubDate$id);
  108.     }
  109.     
  110.     /**
  111.      * Adds an auther to a feed
  112.      * 
  113.      * @param string $name The name of the author.
  114.      * @since 1.0
  115.      */
  116.     public function addAuthor($name{
  117.         $author $this->rssDoc->createElementNS($this->nameSpace'author');
  118.         
  119.         $this->docElement->appendChild($author);
  120.         $namenode $this->rssDoc->createElementNS($this->nameSpace'name'$name);
  121.         $author->appendChild($namenode);
  122.     }
  123.     
  124.     /**
  125.      * (non-PHPdoc)
  126.      * @see alpha/util/feeds/AlphaFeed::addItem()
  127.      */
  128.     protected function addItem($title$link$description=null$pubDate null$id null{
  129.         if(empty($id))
  130.             $id $link;
  131.         if(empty($pubDate))
  132.             $pubDate date("Y-m-d");
  133.         
  134.         parent::addItem($title$link$description$pubDate$id);
  135.     }
  136. }
  137.  
  138. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:52 +0000 by phpDocumentor 1.4.3