aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/feedwriter
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/libraries/feedwriter')
-rwxr-xr-xinc/3rdparty/libraries/feedwriter/FeedItem.php204
-rwxr-xr-xinc/3rdparty/libraries/feedwriter/FeedWriter.php453
2 files changed, 0 insertions, 657 deletions
diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php
deleted file mode 100755
index 40786598..00000000
--- a/inc/3rdparty/libraries/feedwriter/FeedItem.php
+++ /dev/null
@@ -1,204 +0,0 @@
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 $this->setElement('guid', $link);
165 }
166 else
167 {
168 $this->setElement('link','',array('href'=>$link));
169 $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));
170 }
171
172 }
173
174 /**
175 * Set the 'source' element of feed item
176 *
177 * @access public
178 * @param string The content of 'source' element
179 * @return void
180 */
181 public function setSource($link)
182 {
183 $attributes = array('url'=>$link);
184 $this->setElement('source', "wallabag",$attributes);
185 }
186
187 /**
188 * Set the 'encloser' element of feed item
189 * For RSS 2.0 only
190 *
191 * @access public
192 * @param string The url attribute of encloser tag
193 * @param string The length attribute of encloser tag
194 * @param string The type attribute of encloser tag
195 * @return void
196 */
197 public function setEncloser($url, $length, $type)
198 {
199 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
200 $this->setElement('enclosure','',$attributes);
201 }
202
203 } // end of class FeedItem
204?> \ No newline at end of file
diff --git a/inc/3rdparty/libraries/feedwriter/FeedWriter.php b/inc/3rdparty/libraries/feedwriter/FeedWriter.php
deleted file mode 100755
index 9446cddf..00000000
--- a/inc/3rdparty/libraries/feedwriter/FeedWriter.php
+++ /dev/null
@@ -1,453 +0,0 @@
1<?php
2define('RSS2', 1, true);
3define('JSON', 2, true);
4define('JSONP', 3, true);
5define('ATOM', 4, true);
6
7 /**
8 * Univarsel Feed Writer class
9 *
10 * Genarate RSS2 or JSON (original: RSS 1.0, RSS2.0 and ATOM Feed)
11 *
12 * Modified for FiveFilters.org's Full-Text RSS project
13 * to allow for inclusion of hubs, JSON output.
14 * Stripped RSS1 and ATOM support.
15 *
16 * @package UnivarselFeedWriter
17 * @author Anis uddin Ahmad <anisniit@gmail.com>
18 * @link http://www.ajaxray.com/projects/rss
19 */
20 class FeedWriter
21 {
22 private $self = null; // self URL - http://feed2.w3.org/docs/warning/MissingAtomSelfLink.html
23 private $hubs = array(); // PubSubHubbub hubs
24 private $channels = array(); // Collection of channel elements
25 private $items = array(); // Collection of items as object of FeedItem class.
26 private $data = array(); // Store some other version wise data
27 private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA
28 private $xsl = null; // stylesheet to render RSS (used by Chrome)
29 private $json = null; // JSON object
30
31 private $version = null;
32
33 /**
34 * Constructor
35 *
36 * @param constant the version constant (RSS2 or JSON).
37 */
38 function __construct($version = RSS2)
39 {
40 $this->version = $version;
41
42 // Setting default value for assential channel elements
43 $this->channels['title'] = $version . ' Feed';
44 $this->channels['link'] = 'http://www.ajaxray.com/blog';
45
46 //Tag names to encode in CDATA
47 $this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary');
48 }
49
50 public function setFormat($format) {
51 $this->version = $format;
52 }
53
54 // Start # public functions ---------------------------------------------
55
56 /**
57 * Set a channel element
58 * @access public
59 * @param srting name of the channel tag
60 * @param string content of the channel tag
61 * @return void
62 */
63 public function setChannelElement($elementName, $content)
64 {
65 $this->channels[$elementName] = $content ;
66 }
67
68 /**
69 * Set multiple channel elements from an array. Array elements
70 * should be 'channelName' => 'channelContent' format.
71 *
72 * @access public
73 * @param array array of channels
74 * @return void
75 */
76 public function setChannelElementsFromArray($elementArray)
77 {
78 if(! is_array($elementArray)) return;
79 foreach ($elementArray as $elementName => $content)
80 {
81 $this->setChannelElement($elementName, $content);
82 }
83 }
84
85 /**
86 * Genarate the actual RSS/JSON file
87 *
88 * @access public
89 * @return void
90 */
91 public function genarateFeed($withHeaders = true)
92 {
93 if ($withHeaders) {
94 if ($this->version == RSS2) {
95 header('Content-type: text/xml; charset=UTF-8');
96 // this line prevents Chrome 20 from prompting download
97 // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss
98 header('X-content-type-options: nosniff');
99 } elseif ($this->version == JSON) {
100 header('Content-type: application/json; charset=UTF-8');
101 } elseif ($this->version == JSONP) {
102 header('Content-type: application/javascript; charset=UTF-8');
103 }
104 }
105
106 if ($this->version == JSON || $this->version == JSONP) {
107 $this->json = new stdClass();
108 }
109
110
111 $this->printHead();
112 $this->printChannels();
113 $this->printItems();
114 $this->printTale();
115 if ($this->version == JSON || $this->version == JSONP) {
116 echo json_encode($this->json);
117 }
118 }
119
120 public function &getItems()
121 {
122 return $this->items;
123 }
124
125 /**
126 * Create a new FeedItem.
127 *
128 * @access public
129 * @return object instance of FeedItem class
130 */
131 public function createNewItem()
132 {
133 $Item = new FeedItem($this->version);
134 return $Item;
135 }
136
137 /**
138 * Add a FeedItem to the main class
139 *
140 * @access public
141 * @param object instance of FeedItem class
142 * @return void
143 */
144 public function addItem($feedItem)
145 {
146 $this->items[] = $feedItem;
147 }
148
149 // Wrapper functions -------------------------------------------------------------------
150
151 /**
152 * Set the 'title' channel element
153 *
154 * @access public
155 * @param srting value of 'title' channel tag
156 * @return void
157 */
158 public function setTitle($title)
159 {
160 $this->setChannelElement('title', $title);
161 }
162
163 /**
164 * Add a hub to the channel element
165 *
166 * @access public
167 * @param string URL
168 * @return void
169 */
170 public function addHub($hub)
171 {
172 $this->hubs[] = $hub;
173 }
174
175 /**
176 * Set XSL URL
177 *
178 * @access public
179 * @param string URL
180 * @return void
181 */
182 public function setXsl($xsl)
183 {
184 $this->xsl = $xsl;
185 }
186
187 /**
188 * Set self URL
189 *
190 * @access public
191 * @param string URL
192 * @return void
193 */
194 public function setSelf($self)
195 {
196 $this->self = $self;
197 }
198
199 /**
200 * Set the 'description' channel element
201 *
202 * @access public
203 * @param srting value of 'description' channel tag
204 * @return void
205 */
206 public function setDescription($description)
207 {
208 $tag = ($this->version == ATOM)? 'subtitle' : 'description';
209 $this->setChannelElement($tag, $description);
210 }
211
212 /**
213 * Set the 'link' channel element
214 *
215 * @access public
216 * @param srting value of 'link' channel tag
217 * @return void
218 */
219 public function setLink($link)
220 {
221 $this->setChannelElement('link', $link);
222 }
223
224 /**
225 * Set the 'image' channel element
226 *
227 * @access public
228 * @param srting title of image
229 * @param srting link url of the imahe
230 * @param srting path url of the image
231 * @return void
232 */
233 public function setImage($title, $link, $url)
234 {
235 $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url));
236 }
237
238 // End # public functions ----------------------------------------------
239
240 // Start # private functions ----------------------------------------------
241
242 /**
243 * Prints the xml and rss namespace
244 *
245 * @access private
246 * @return void
247 */
248 private function printHead()
249 {
250 if ($this->version == RSS2)
251 {
252 $out = '<?xml version="1.0" encoding="utf-8"?>'."\n";
253 if ($this->xsl) $out .= '<?xml-stylesheet type="text/xsl" href="'.htmlspecialchars($this->xsl).'"?>' . PHP_EOL;
254 $out .= '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL;
255 echo $out;
256 }
257 elseif ($this->version == JSON || $this->version == JSONP)
258 {
259 $this->json->rss = array('@attributes' => array('version' => '2.0'));
260 }
261 }
262
263 /**
264 * Closes the open tags at the end of file
265 *
266 * @access private
267 * @return void
268 */
269 private function printTale()
270 {
271 if ($this->version == RSS2)
272 {
273 echo '</channel>',PHP_EOL,'</rss>';
274 }
275 // do nothing for JSON
276 }
277
278 /**
279 * Creates a single node as xml format
280 *
281 * @access private
282 * @param string name of the tag
283 * @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format
284 * @param array Attributes(if any) in 'attrName' => 'attrValue' format
285 * @return string formatted xml tag
286 */
287 private function makeNode($tagName, $tagContent, $attributes = null)
288 {
289 if ($this->version == RSS2)
290 {
291 $nodeText = '';
292 $attrText = '';
293 if (is_array($attributes))
294 {
295 foreach ($attributes as $key => $value)
296 {
297 $attrText .= " $key=\"$value\" ";
298 }
299 }
300 $nodeText .= "<{$tagName}{$attrText}>";
301 if (is_array($tagContent))
302 {
303 foreach ($tagContent as $key => $value)
304 {
305 $nodeText .= $this->makeNode($key, $value);
306 }
307 }
308 else
309 {
310 //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent);
311 $nodeText .= htmlspecialchars($tagContent);
312 }
313 //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>";
314 $nodeText .= "</$tagName>";
315 return $nodeText . PHP_EOL;
316 }
317 elseif ($this->version == JSON || $this->version == JSONP)
318 {
319 $tagName = (string)$tagName;
320 $tagName = strtr($tagName, ':', '_');
321 $node = null;
322 if (!$tagContent && is_array($attributes) && count($attributes))
323 {
324 $node = array('@attributes' => $this->json_keys($attributes));
325 } else {
326 if (is_array($tagContent)) {
327 $node = $this->json_keys($tagContent);
328 } else {
329 $node = $tagContent;
330 }
331 }
332 return $node;
333 }
334 return ''; // should not get here
335 }
336
337 private function json_keys(array $array) {
338 $new = array();
339 foreach ($array as $key => $val) {
340 if (is_string($key)) $key = strtr($key, ':', '_');
341 if (is_array($val)) {
342 $new[$key] = $this->json_keys($val);
343 } else {
344 $new[$key] = $val;
345 }
346 }
347 return $new;
348 }
349
350 /**
351 * @desc Print channels
352 * @access private
353 * @return void
354 */
355 private function printChannels()
356 {
357 //Start channel tag
358 if ($this->version == RSS2) {
359 echo '<channel>' . PHP_EOL;
360 // add hubs
361 foreach ($this->hubs as $hub) {
362 //echo $this->makeNode('link', '', array('rel'=>'hub', 'href'=>$hub, 'xmlns'=>'http://www.w3.org/2005/Atom'));
363 echo '<link rel="hub" href="'.htmlspecialchars($hub).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL;
364 }
365 // add self
366 if (isset($this->self)) {
367 //echo $this->makeNode('link', '', array('rel'=>'self', 'href'=>$this->self, 'xmlns'=>'http://www.w3.org/2005/Atom'));
368 echo '<link rel="self" href="'.htmlspecialchars($this->self).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL;
369 }
370 //Print Items of channel
371 foreach ($this->channels as $key => $value)
372 {
373 echo $this->makeNode($key, $value);
374 }
375 } elseif ($this->version == JSON || $this->version == JSONP) {
376 $this->json->rss['channel'] = (object)$this->json_keys($this->channels);
377 }
378 }
379
380 /**
381 * Prints formatted feed items
382 *
383 * @access private
384 * @return void
385 */
386 private function printItems()
387 {
388 foreach ($this->items as $item) {
389 $itemElements = $item->getElements();
390
391 echo $this->startItem();
392
393 if ($this->version == JSON || $this->version == JSONP) {
394 $json_item = array();
395 }
396
397 foreach ($itemElements as $thisElement) {
398 foreach ($thisElement as $instance) {
399 if ($this->version == RSS2) {
400 echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']);
401 } elseif ($this->version == JSON || $this->version == JSONP) {
402 $_json_node = $this->makeNode($instance['name'], $instance['content'], $instance['attributes']);
403 if (count($thisElement) > 1) {
404 $json_item[strtr($instance['name'], ':', '_')][] = $_json_node;
405 } else {
406 $json_item[strtr($instance['name'], ':', '_')] = $_json_node;
407 }
408 }
409 }
410 }
411 echo $this->endItem();
412 if ($this->version == JSON || $this->version == JSONP) {
413 if (count($this->items) > 1) {
414 $this->json->rss['channel']->item[] = $json_item;
415 } else {
416 $this->json->rss['channel']->item = $json_item;
417 }
418 }
419 }
420 }
421
422 /**
423 * Make the starting tag of channels
424 *
425 * @access private
426 * @return void
427 */
428 private function startItem()
429 {
430 if ($this->version == RSS2)
431 {
432 echo '<item>' . PHP_EOL;
433 }
434 // nothing for JSON
435 }
436
437 /**
438 * Closes feed item tag
439 *
440 * @access private
441 * @return void
442 */
443 private function endItem()
444 {
445 if ($this->version == RSS2)
446 {
447 echo '</item>' . PHP_EOL;
448 }
449 // nothing for JSON
450 }
451
452 // End # private functions ----------------------------------------------
453 } \ No newline at end of file