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