Overview

Namespaces

  • Alpha
    • Controller
      • Front
    • Exception
    • Model
      • Type
    • Task
    • Util
      • Backup
      • Cache
      • Code
        • Highlight
        • Metric
      • Config
      • Convertor
      • Email
      • Extension
      • Feed
      • File
      • Graph
      • Helper
      • Http
        • Filter
        • Session
      • Image
      • Logging
      • Search
      • Security
    • View
      • Renderer
        • Html
        • Json
      • Widget

Classes

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