aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/feedwriter/FeedItem.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/libraries/feedwriter/FeedItem.php')
-rw-r--r--inc/3rdparty/libraries/feedwriter/FeedItem.php190
1 files changed, 190 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php
new file mode 100644
index 00000000..6761eb0e
--- /dev/null
+++ b/inc/3rdparty/libraries/feedwriter/FeedItem.php
@@ -0,0 +1,190 @@
1<?php
2 /**
3 * Univarsel Feed Writer
4 *
5 * FeedItem class - Used as feed element in FeedWriter class
6 *
7 * @package UnivarselFeedWriter
8 * @author Anis uddin Ahmad <anisniit@gmail.com>
9 * @link http://www.ajaxray.com/projects/rss
10 */
11 class FeedItem
12 {
13 private $elements = array(); //Collection of feed elements
14 private $version;
15
16 /**
17 * Constructor
18 *
19 * @param contant (RSS1/RSS2/ATOM) RSS2 is default.
20 */
21 function __construct($version = RSS2)
22 {
23 $this->version = $version;
24 }
25
26 /**
27 * Set element (overwrites existing elements with $elementName)
28 *
29 * @access public
30 * @param srting The tag name of an element
31 * @param srting The content of tag
32 * @param array Attributes(if any) in 'attrName' => 'attrValue' format
33 * @return void
34 */
35 public function setElement($elementName, $content, $attributes = null)
36 {
37 if (isset($this->elements[$elementName])) {
38 unset($this->elements[$elementName]);
39 }
40 $this->addElement($elementName, $content, $attributes);
41 }
42
43 /**
44 * Add an element to elements array
45 *
46 * @access public
47 * @param srting The tag name of an element
48 * @param srting The content of tag
49 * @param array Attributes(if any) in 'attrName' => 'attrValue' format
50 * @return void
51 */
52 public function addElement($elementName, $content, $attributes = null)
53 {
54 $i = 0;
55 if (isset($this->elements[$elementName])) {
56 $i = count($this->elements[$elementName]);
57 } else {
58 $this->elements[$elementName] = array();
59 }
60 $this->elements[$elementName][$i]['name'] = $elementName;
61 $this->elements[$elementName][$i]['content'] = $content;
62 $this->elements[$elementName][$i]['attributes'] = $attributes;
63 }
64
65 /**
66 * Set multiple feed elements from an array.
67 * Elements which have attributes cannot be added by this method
68 *
69 * @access public
70 * @param array array of elements in 'tagName' => 'tagContent' format.
71 * @return void
72 */
73 public function addElementArray($elementArray)
74 {
75 if(! is_array($elementArray)) return;
76 foreach ($elementArray as $elementName => $content)
77 {
78 $this->addElement($elementName, $content);
79 }
80 }
81
82 /**
83 * Return the collection of elements in this feed item
84 *
85 * @access public
86 * @return array
87 */
88 public function getElements()
89 {
90 return $this->elements;
91 }
92
93 // Wrapper functions ------------------------------------------------------
94
95 /**
96 * Set the 'dscription' element of feed item
97 *
98 * @access public
99 * @param string The content of 'description' element
100 * @return void
101 */
102 public function setDescription($description)
103 {
104 $tag = ($this->version == ATOM)? 'summary' : 'description';
105 $this->setElement($tag, $description);
106 }
107
108 /**
109 * @desc Set the 'title' element of feed item
110 * @access public
111 * @param string The content of 'title' element
112 * @return void
113 */
114 public function setTitle($title)
115 {
116 $this->setElement('title', $title);
117 }
118
119 /**
120 * Set the 'date' element of feed item
121 *
122 * @access public
123 * @param string The content of 'date' element
124 * @return void
125 */
126 public function setDate($date)
127 {
128 if(! is_numeric($date))
129 {
130 $date = strtotime($date);
131 }
132
133 if($this->version == ATOM)
134 {
135 $tag = 'updated';
136 $value = date(DATE_ATOM, $date);
137 }
138 elseif($this->version == RSS2)
139 {
140 $tag = 'pubDate';
141 $value = date(DATE_RSS, $date);
142 }
143 else
144 {
145 $tag = 'dc:date';
146 $value = date("Y-m-d", $date);
147 }
148
149 $this->setElement($tag, $value);
150 }
151
152 /**
153 * Set the 'link' element of feed item
154 *
155 * @access public
156 * @param string The content of 'link' element
157 * @return void
158 */
159 public function setLink($link)
160 {
161 if($this->version == RSS2 || $this->version == RSS1)
162 {
163 $this->setElement('link', $link);
164 }
165 else
166 {
167 $this->setElement('link','',array('href'=>$link));
168 $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));
169 }
170
171 }
172
173 /**
174 * Set the 'encloser' element of feed item
175 * For RSS 2.0 only
176 *
177 * @access public
178 * @param string The url attribute of encloser tag
179 * @param string The length attribute of encloser tag
180 * @param string The type attribute of encloser tag
181 * @return void
182 */
183 public function setEncloser($url, $length, $type)
184 {
185 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
186 $this->setElement('enclosure','',$attributes);
187 }
188
189 } // end of class FeedItem
190?>