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