diff options
author | Maryana Rozhankivska <mariroz@mr.lviv.ua> | 2014-04-02 20:55:19 +0300 |
---|---|---|
committer | Maryana Rozhankivska <mariroz@mr.lviv.ua> | 2014-04-02 20:55:19 +0300 |
commit | 182faf2696b38502d4784efc3f84f2f00290343f (patch) | |
tree | 619e725c1820773dcd8bb1fe9cbd07c0c325e865 /inc/3rdparty | |
parent | 22db488d21bc23dc28fc2d60574803525fe53b53 (diff) | |
download | wallabag-182faf2696b38502d4784efc3f84f2f00290343f.tar.gz wallabag-182faf2696b38502d4784efc3f84f2f00290343f.tar.zst wallabag-182faf2696b38502d4784efc3f84f2f00290343f.zip |
import without cron
Diffstat (limited to 'inc/3rdparty')
-rwxr-xr-x[-rw-r--r--] | inc/3rdparty/libraries/feedwriter/FeedWriter.php | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/inc/3rdparty/libraries/feedwriter/FeedWriter.php b/inc/3rdparty/libraries/feedwriter/FeedWriter.php index adb2526c..5d16e765 100644..100755 --- a/inc/3rdparty/libraries/feedwriter/FeedWriter.php +++ b/inc/3rdparty/libraries/feedwriter/FeedWriter.php | |||
@@ -9,9 +9,9 @@ define('JSONP', 3, true); | |||
9 | * Genarate RSS2 or JSON (original: RSS 1.0, RSS2.0 and ATOM Feed) | 9 | * Genarate RSS2 or JSON (original: RSS 1.0, RSS2.0 and ATOM Feed) |
10 | * | 10 | * |
11 | * Modified for FiveFilters.org's Full-Text RSS project | 11 | * Modified for FiveFilters.org's Full-Text RSS project |
12 | * to allow for inclusion of hubs, JSON output. | 12 | * to allow for inclusion of hubs, JSON output. |
13 | * Stripped RSS1 and ATOM support. | 13 | * Stripped RSS1 and ATOM support. |
14 | * | 14 | * |
15 | * @package UnivarselFeedWriter | 15 | * @package UnivarselFeedWriter |
16 | * @author Anis uddin Ahmad <anisniit@gmail.com> | 16 | * @author Anis uddin Ahmad <anisniit@gmail.com> |
17 | * @link http://www.ajaxray.com/projects/rss | 17 | * @link http://www.ajaxray.com/projects/rss |
@@ -26,32 +26,32 @@ define('JSONP', 3, true); | |||
26 | private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA | 26 | private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA |
27 | private $xsl = null; // stylesheet to render RSS (used by Chrome) | 27 | private $xsl = null; // stylesheet to render RSS (used by Chrome) |
28 | private $json = null; // JSON object | 28 | private $json = null; // JSON object |
29 | 29 | ||
30 | private $version = null; | 30 | private $version = null; |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Constructor | 33 | * Constructor |
34 | * | 34 | * |
35 | * @param constant the version constant (RSS2 or JSON). | 35 | * @param constant the version constant (RSS2 or JSON). |
36 | */ | 36 | */ |
37 | function __construct($version = RSS2) | 37 | function __construct($version = RSS2) |
38 | { | 38 | { |
39 | $this->version = $version; | 39 | $this->version = $version; |
40 | 40 | ||
41 | // Setting default value for assential channel elements | 41 | // Setting default value for assential channel elements |
42 | $this->channels['title'] = $version . ' Feed'; | 42 | $this->channels['title'] = $version . ' Feed'; |
43 | $this->channels['link'] = 'http://www.ajaxray.com/blog'; | 43 | $this->channels['link'] = 'http://www.ajaxray.com/blog'; |
44 | 44 | ||
45 | //Tag names to encode in CDATA | 45 | //Tag names to encode in CDATA |
46 | $this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary'); | 46 | $this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary'); |
47 | } | 47 | } |
48 | 48 | ||
49 | public function setFormat($format) { | 49 | public function setFormat($format) { |
50 | $this->version = $format; | 50 | $this->version = $format; |
51 | } | 51 | } |
52 | 52 | ||
53 | // Start # public functions --------------------------------------------- | 53 | // Start # public functions --------------------------------------------- |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Set a channel element | 56 | * Set a channel element |
57 | * @access public | 57 | * @access public |
@@ -63,11 +63,11 @@ define('JSONP', 3, true); | |||
63 | { | 63 | { |
64 | $this->channels[$elementName] = $content ; | 64 | $this->channels[$elementName] = $content ; |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Set multiple channel elements from an array. Array elements | 68 | * Set multiple channel elements from an array. Array elements |
69 | * should be 'channelName' => 'channelContent' format. | 69 | * should be 'channelName' => 'channelContent' format. |
70 | * | 70 | * |
71 | * @access public | 71 | * @access public |
72 | * @param array array of channels | 72 | * @param array array of channels |
73 | * @return void | 73 | * @return void |
@@ -75,30 +75,30 @@ define('JSONP', 3, true); | |||
75 | public function setChannelElementsFromArray($elementArray) | 75 | public function setChannelElementsFromArray($elementArray) |
76 | { | 76 | { |
77 | if(! is_array($elementArray)) return; | 77 | if(! is_array($elementArray)) return; |
78 | foreach ($elementArray as $elementName => $content) | 78 | foreach ($elementArray as $elementName => $content) |
79 | { | 79 | { |
80 | $this->setChannelElement($elementName, $content); | 80 | $this->setChannelElement($elementName, $content); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Genarate the actual RSS/JSON file | 85 | * Genarate the actual RSS/JSON file |
86 | * | 86 | * |
87 | * @access public | 87 | * @access public |
88 | * @return void | 88 | * @return void |
89 | */ | 89 | */ |
90 | public function genarateFeed() | 90 | public function genarateFeed() |
91 | { | 91 | { |
92 | if ($this->version == RSS2) { | 92 | if ($this->version == RSS2) { |
93 | header('Content-type: text/xml; charset=UTF-8'); | 93 | // header('Content-type: text/xml; charset=UTF-8'); |
94 | // this line prevents Chrome 20 from prompting download | 94 | // this line prevents Chrome 20 from prompting download |
95 | // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss | 95 | // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss |
96 | header('X-content-type-options: nosniff'); | 96 | // header('X-content-type-options: nosniff'); |
97 | } elseif ($this->version == JSON) { | 97 | } elseif ($this->version == JSON) { |
98 | header('Content-type: application/json; charset=UTF-8'); | 98 | // header('Content-type: application/json; charset=UTF-8'); |
99 | $this->json = new stdClass(); | 99 | $this->json = new stdClass(); |
100 | } elseif ($this->version == JSONP) { | 100 | } elseif ($this->version == JSONP) { |
101 | header('Content-type: application/javascript; charset=UTF-8'); | 101 | // header('Content-type: application/javascript; charset=UTF-8'); |
102 | $this->json = new stdClass(); | 102 | $this->json = new stdClass(); |
103 | } | 103 | } |
104 | $this->printHead(); | 104 | $this->printHead(); |
@@ -109,10 +109,10 @@ define('JSONP', 3, true); | |||
109 | echo json_encode($this->json); | 109 | echo json_encode($this->json); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Create a new FeedItem. | 114 | * Create a new FeedItem. |
115 | * | 115 | * |
116 | * @access public | 116 | * @access public |
117 | * @return object instance of FeedItem class | 117 | * @return object instance of FeedItem class |
118 | */ | 118 | */ |
@@ -121,24 +121,24 @@ define('JSONP', 3, true); | |||
121 | $Item = new FeedItem($this->version); | 121 | $Item = new FeedItem($this->version); |
122 | return $Item; | 122 | return $Item; |
123 | } | 123 | } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Add a FeedItem to the main class | 126 | * Add a FeedItem to the main class |
127 | * | 127 | * |
128 | * @access public | 128 | * @access public |
129 | * @param object instance of FeedItem class | 129 | * @param object instance of FeedItem class |
130 | * @return void | 130 | * @return void |
131 | */ | 131 | */ |
132 | public function addItem($feedItem) | 132 | public function addItem($feedItem) |
133 | { | 133 | { |
134 | $this->items[] = $feedItem; | 134 | $this->items[] = $feedItem; |
135 | } | 135 | } |
136 | 136 | ||
137 | // Wrapper functions ------------------------------------------------------------------- | 137 | // Wrapper functions ------------------------------------------------------------------- |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Set the 'title' channel element | 140 | * Set the 'title' channel element |
141 | * | 141 | * |
142 | * @access public | 142 | * @access public |
143 | * @param srting value of 'title' channel tag | 143 | * @param srting value of 'title' channel tag |
144 | * @return void | 144 | * @return void |
@@ -147,59 +147,59 @@ define('JSONP', 3, true); | |||
147 | { | 147 | { |
148 | $this->setChannelElement('title', $title); | 148 | $this->setChannelElement('title', $title); |
149 | } | 149 | } |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * Add a hub to the channel element | 152 | * Add a hub to the channel element |
153 | * | 153 | * |
154 | * @access public | 154 | * @access public |
155 | * @param string URL | 155 | * @param string URL |
156 | * @return void | 156 | * @return void |
157 | */ | 157 | */ |
158 | public function addHub($hub) | 158 | public function addHub($hub) |
159 | { | 159 | { |
160 | $this->hubs[] = $hub; | 160 | $this->hubs[] = $hub; |
161 | } | 161 | } |
162 | 162 | ||
163 | /** | 163 | /** |
164 | * Set XSL URL | 164 | * Set XSL URL |
165 | * | 165 | * |
166 | * @access public | 166 | * @access public |
167 | * @param string URL | 167 | * @param string URL |
168 | * @return void | 168 | * @return void |
169 | */ | 169 | */ |
170 | public function setXsl($xsl) | 170 | public function setXsl($xsl) |
171 | { | 171 | { |
172 | $this->xsl = $xsl; | 172 | $this->xsl = $xsl; |
173 | } | 173 | } |
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Set self URL | 176 | * Set self URL |
177 | * | 177 | * |
178 | * @access public | 178 | * @access public |
179 | * @param string URL | 179 | * @param string URL |
180 | * @return void | 180 | * @return void |
181 | */ | 181 | */ |
182 | public function setSelf($self) | 182 | public function setSelf($self) |
183 | { | 183 | { |
184 | $this->self = $self; | 184 | $this->self = $self; |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Set the 'description' channel element | 188 | * Set the 'description' channel element |
189 | * | 189 | * |
190 | * @access public | 190 | * @access public |
191 | * @param srting value of 'description' channel tag | 191 | * @param srting value of 'description' channel tag |
192 | * @return void | 192 | * @return void |
193 | */ | 193 | */ |
194 | public function setDescription($desciption) | 194 | public function setDescription($desciption) |
195 | { | 195 | { |
196 | $tag = ($this->version == ATOM)? 'subtitle' : 'description'; | 196 | $tag = ($this->version == ATOM)? 'subtitle' : 'description'; |
197 | $this->setChannelElement($tag, $desciption); | 197 | $this->setChannelElement($tag, $desciption); |
198 | } | 198 | } |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * Set the 'link' channel element | 201 | * Set the 'link' channel element |
202 | * | 202 | * |
203 | * @access public | 203 | * @access public |
204 | * @param srting value of 'link' channel tag | 204 | * @param srting value of 'link' channel tag |
205 | * @return void | 205 | * @return void |
@@ -208,10 +208,10 @@ define('JSONP', 3, true); | |||
208 | { | 208 | { |
209 | $this->setChannelElement('link', $link); | 209 | $this->setChannelElement('link', $link); |
210 | } | 210 | } |
211 | 211 | ||
212 | /** | 212 | /** |
213 | * Set the 'image' channel element | 213 | * Set the 'image' channel element |
214 | * | 214 | * |
215 | * @access public | 215 | * @access public |
216 | * @param srting title of image | 216 | * @param srting title of image |
217 | * @param srting link url of the imahe | 217 | * @param srting link url of the imahe |
@@ -222,14 +222,14 @@ define('JSONP', 3, true); | |||
222 | { | 222 | { |
223 | $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url)); | 223 | $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url)); |
224 | } | 224 | } |
225 | 225 | ||
226 | // End # public functions ---------------------------------------------- | 226 | // End # public functions ---------------------------------------------- |
227 | 227 | ||
228 | // Start # private functions ---------------------------------------------- | 228 | // Start # private functions ---------------------------------------------- |
229 | 229 | ||
230 | /** | 230 | /** |
231 | * Prints the xml and rss namespace | 231 | * Prints the xml and rss namespace |
232 | * | 232 | * |
233 | * @access private | 233 | * @access private |
234 | * @return void | 234 | * @return void |
235 | */ | 235 | */ |
@@ -247,10 +247,10 @@ define('JSONP', 3, true); | |||
247 | $this->json->rss = array('@attributes' => array('version' => '2.0')); | 247 | $this->json->rss = array('@attributes' => array('version' => '2.0')); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | /** | 251 | /** |
252 | * Closes the open tags at the end of file | 252 | * Closes the open tags at the end of file |
253 | * | 253 | * |
254 | * @access private | 254 | * @access private |
255 | * @return void | 255 | * @return void |
256 | */ | 256 | */ |
@@ -258,14 +258,14 @@ define('JSONP', 3, true); | |||
258 | { | 258 | { |
259 | if ($this->version == RSS2) | 259 | if ($this->version == RSS2) |
260 | { | 260 | { |
261 | echo '</channel>',PHP_EOL,'</rss>'; | 261 | echo '</channel>',PHP_EOL,'</rss>'; |
262 | } | 262 | } |
263 | // do nothing for JSON | 263 | // do nothing for JSON |
264 | } | 264 | } |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * Creates a single node as xml format | 267 | * Creates a single node as xml format |
268 | * | 268 | * |
269 | * @access private | 269 | * @access private |
270 | * @param string name of the tag | 270 | * @param string name of the tag |
271 | * @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format | 271 | * @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format |
@@ -273,22 +273,22 @@ define('JSONP', 3, true); | |||
273 | * @return string formatted xml tag | 273 | * @return string formatted xml tag |
274 | */ | 274 | */ |
275 | private function makeNode($tagName, $tagContent, $attributes = null) | 275 | private function makeNode($tagName, $tagContent, $attributes = null) |
276 | { | 276 | { |
277 | if ($this->version == RSS2) | 277 | if ($this->version == RSS2) |
278 | { | 278 | { |
279 | $nodeText = ''; | 279 | $nodeText = ''; |
280 | $attrText = ''; | 280 | $attrText = ''; |
281 | if (is_array($attributes)) | 281 | if (is_array($attributes)) |
282 | { | 282 | { |
283 | foreach ($attributes as $key => $value) | 283 | foreach ($attributes as $key => $value) |
284 | { | 284 | { |
285 | $attrText .= " $key=\"$value\" "; | 285 | $attrText .= " $key=\"$value\" "; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | $nodeText .= "<{$tagName}{$attrText}>"; | 288 | $nodeText .= "<{$tagName}{$attrText}>"; |
289 | if (is_array($tagContent)) | 289 | if (is_array($tagContent)) |
290 | { | 290 | { |
291 | foreach ($tagContent as $key => $value) | 291 | foreach ($tagContent as $key => $value) |
292 | { | 292 | { |
293 | $nodeText .= $this->makeNode($key, $value); | 293 | $nodeText .= $this->makeNode($key, $value); |
294 | } | 294 | } |
@@ -297,7 +297,7 @@ define('JSONP', 3, true); | |||
297 | { | 297 | { |
298 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent); | 298 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent); |
299 | $nodeText .= htmlspecialchars($tagContent); | 299 | $nodeText .= htmlspecialchars($tagContent); |
300 | } | 300 | } |
301 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>"; | 301 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>"; |
302 | $nodeText .= "</$tagName>"; | 302 | $nodeText .= "</$tagName>"; |
303 | return $nodeText . PHP_EOL; | 303 | return $nodeText . PHP_EOL; |
@@ -321,7 +321,7 @@ define('JSONP', 3, true); | |||
321 | } | 321 | } |
322 | return ''; // should not get here | 322 | return ''; // should not get here |
323 | } | 323 | } |
324 | 324 | ||
325 | private function json_keys(array $array) { | 325 | private function json_keys(array $array) { |
326 | $new = array(); | 326 | $new = array(); |
327 | foreach ($array as $key => $val) { | 327 | foreach ($array as $key => $val) { |
@@ -334,7 +334,7 @@ define('JSONP', 3, true); | |||
334 | } | 334 | } |
335 | return $new; | 335 | return $new; |
336 | } | 336 | } |
337 | 337 | ||
338 | /** | 338 | /** |
339 | * @desc Print channels | 339 | * @desc Print channels |
340 | * @access private | 340 | * @access private |
@@ -344,7 +344,7 @@ define('JSONP', 3, true); | |||
344 | { | 344 | { |
345 | //Start channel tag | 345 | //Start channel tag |
346 | if ($this->version == RSS2) { | 346 | if ($this->version == RSS2) { |
347 | echo '<channel>' . PHP_EOL; | 347 | echo '<channel>' . PHP_EOL; |
348 | // add hubs | 348 | // add hubs |
349 | foreach ($this->hubs as $hub) { | 349 | foreach ($this->hubs as $hub) { |
350 | //echo $this->makeNode('link', '', array('rel'=>'hub', 'href'=>$hub, 'xmlns'=>'http://www.w3.org/2005/Atom')); | 350 | //echo $this->makeNode('link', '', array('rel'=>'hub', 'href'=>$hub, 'xmlns'=>'http://www.w3.org/2005/Atom')); |
@@ -356,7 +356,7 @@ define('JSONP', 3, true); | |||
356 | echo '<link rel="self" href="'.htmlspecialchars($this->self).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL; | 356 | echo '<link rel="self" href="'.htmlspecialchars($this->self).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL; |
357 | } | 357 | } |
358 | //Print Items of channel | 358 | //Print Items of channel |
359 | foreach ($this->channels as $key => $value) | 359 | foreach ($this->channels as $key => $value) |
360 | { | 360 | { |
361 | echo $this->makeNode($key, $value); | 361 | echo $this->makeNode($key, $value); |
362 | } | 362 | } |
@@ -364,26 +364,26 @@ define('JSONP', 3, true); | |||
364 | $this->json->rss['channel'] = (object)$this->json_keys($this->channels); | 364 | $this->json->rss['channel'] = (object)$this->json_keys($this->channels); |
365 | } | 365 | } |
366 | } | 366 | } |
367 | 367 | ||
368 | /** | 368 | /** |
369 | * Prints formatted feed items | 369 | * Prints formatted feed items |
370 | * | 370 | * |
371 | * @access private | 371 | * @access private |
372 | * @return void | 372 | * @return void |
373 | */ | 373 | */ |
374 | private function printItems() | 374 | private function printItems() |
375 | { | 375 | { |
376 | foreach ($this->items as $item) { | 376 | foreach ($this->items as $item) { |
377 | $itemElements = $item->getElements(); | 377 | $itemElements = $item->getElements(); |
378 | 378 | ||
379 | echo $this->startItem(); | 379 | echo $this->startItem(); |
380 | 380 | ||
381 | if ($this->version == JSON || $this->version == JSONP) { | 381 | if ($this->version == JSON || $this->version == JSONP) { |
382 | $json_item = array(); | 382 | $json_item = array(); |
383 | } | 383 | } |
384 | 384 | ||
385 | foreach ($itemElements as $thisElement) { | 385 | foreach ($itemElements as $thisElement) { |
386 | foreach ($thisElement as $instance) { | 386 | foreach ($thisElement as $instance) { |
387 | if ($this->version == RSS2) { | 387 | if ($this->version == RSS2) { |
388 | echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); | 388 | echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); |
389 | } elseif ($this->version == JSON || $this->version == JSONP) { | 389 | } elseif ($this->version == JSON || $this->version == JSONP) { |
@@ -406,10 +406,10 @@ define('JSONP', 3, true); | |||
406 | } | 406 | } |
407 | } | 407 | } |
408 | } | 408 | } |
409 | 409 | ||
410 | /** | 410 | /** |
411 | * Make the starting tag of channels | 411 | * Make the starting tag of channels |
412 | * | 412 | * |
413 | * @access private | 413 | * @access private |
414 | * @return void | 414 | * @return void |
415 | */ | 415 | */ |
@@ -417,14 +417,14 @@ define('JSONP', 3, true); | |||
417 | { | 417 | { |
418 | if ($this->version == RSS2) | 418 | if ($this->version == RSS2) |
419 | { | 419 | { |
420 | echo '<item>' . PHP_EOL; | 420 | echo '<item>' . PHP_EOL; |
421 | } | 421 | } |
422 | // nothing for JSON | 422 | // nothing for JSON |
423 | } | 423 | } |
424 | 424 | ||
425 | /** | 425 | /** |
426 | * Closes feed item tag | 426 | * Closes feed item tag |
427 | * | 427 | * |
428 | * @access private | 428 | * @access private |
429 | * @return void | 429 | * @return void |
430 | */ | 430 | */ |
@@ -432,10 +432,10 @@ define('JSONP', 3, true); | |||
432 | { | 432 | { |
433 | if ($this->version == RSS2) | 433 | if ($this->version == RSS2) |
434 | { | 434 | { |
435 | echo '</item>' . PHP_EOL; | 435 | echo '</item>' . PHP_EOL; |
436 | } | 436 | } |
437 | // nothing for JSON | 437 | // nothing for JSON |
438 | } | 438 | } |
439 | 439 | ||
440 | // End # private functions ---------------------------------------------- | 440 | // End # private functions ---------------------------------------------- |
441 | } \ No newline at end of file | 441 | } \ No newline at end of file |