aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/feedwriter
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-05-29 18:54:06 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-05-29 18:54:06 +0200
commita9f5e572dde4f986a498d2fbe92a38a1b22f9595 (patch)
tree80b5bfc9836ae92cc4929a4d72ae0b2730e568bc /inc/3rdparty/libraries/feedwriter
parent96834a47b09985e1c82b82857fc108f20e8b8f2b (diff)
parent8038b38802769031e050c753fc0a388a2276629e (diff)
downloadwallabag-1.7.0.tar.gz
wallabag-1.7.0.tar.zst
wallabag-1.7.0.zip
Merge pull request #712 from wallabag/dev1.7.0
1.7, call me "Premium version"
Diffstat (limited to 'inc/3rdparty/libraries/feedwriter')
-rwxr-xr-x[-rw-r--r--]inc/3rdparty/libraries/feedwriter/FeedItem.php103
-rwxr-xr-xinc/3rdparty/libraries/feedwriter/FeedWriter.php40
2 files changed, 81 insertions, 62 deletions
diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php
index 3487423f..40786598 100644..100755
--- a/inc/3rdparty/libraries/feedwriter/FeedItem.php
+++ b/inc/3rdparty/libraries/feedwriter/FeedItem.php
@@ -1,7 +1,7 @@
1<?php 1<?php
2 /** 2 /**
3 * Univarsel Feed Writer 3 * Univarsel Feed Writer
4 * 4 *
5 * FeedItem class - Used as feed element in FeedWriter class 5 * FeedItem class - Used as feed element in FeedWriter class
6 * 6 *
7 * @package UnivarselFeedWriter 7 * @package UnivarselFeedWriter
@@ -12,20 +12,20 @@
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
@@ -38,11 +38,11 @@
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
@@ -61,11 +61,11 @@
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
@@ -73,15 +73,15 @@
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 */
@@ -89,68 +89,74 @@
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 $this->setElement('description', $description); 104 $tag = ($this->version == ATOM)? 'summary' : '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 }
131 132
132 if($this->version == RSS2) 133 if($this->version == ATOM)
134 {
135 $tag = 'updated';
136 $value = date(DATE_ATOM, $date);
137 }
138 elseif($this->version == RSS2)
133 { 139 {
134 $tag = 'pubDate'; 140 $tag = 'pubDate';
135 $value = date(DATE_RSS, $date); 141 $value = date(DATE_RSS, $date);
136 } 142 }
137 else 143 else
138 { 144 {
139 $tag = 'dc:date'; 145 $tag = 'dc:date';
140 $value = date("Y-m-d", $date); 146 $value = date("Y-m-d", $date);
141 } 147 }
142 148
143 $this->setElement($tag, $value); 149 $this->setElement($tag, $value);
144 } 150 }
145 151
146 /** 152 /**
147 * Set the 'link' element of feed item 153 * Set the 'link' element of feed item
148 * 154 *
149 * @access public 155 * @access public
150 * @param string The content of 'link' element 156 * @param string The content of 'link' element
151 * @return void 157 * @return void
152 */ 158 */
153 public function setLink($link) 159 public function setLink($link)
154 { 160 {
155 if($this->version == RSS2 || $this->version == RSS1) 161 if($this->version == RSS2 || $this->version == RSS1)
156 { 162 {
@@ -161,26 +167,27 @@
161 { 167 {
162 $this->setElement('link','',array('href'=>$link)); 168 $this->setElement('link','',array('href'=>$link));
163 $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:')); 169 $this->setElement('id', FeedWriter::uuid($link,'urn:uuid:'));
164 } 170 }
165 171
166 } 172 }
167 173
168 /** 174 /**
169 * Set the 'source' element of feed item 175 * Set the 'source' element of feed item
170 * 176 *
171 * @access public 177 * @access public
172 * @param string The content of 'source' element 178 * @param string The content of 'source' element
173 * @return void 179 * @return void
174 */ 180 */
175 public function setSource($link) 181 public function setSource($link)
176 { 182 {
177 $this->setElement('source', $link); 183 $attributes = array('url'=>$link);
184 $this->setElement('source', "wallabag",$attributes);
178 } 185 }
179 186
180 /** 187 /**
181 * Set the 'encloser' element of feed item 188 * Set the 'encloser' element of feed item
182 * For RSS 2.0 only 189 * For RSS 2.0 only
183 * 190 *
184 * @access public 191 * @access public
185 * @param string The url attribute of encloser tag 192 * @param string The url attribute of encloser tag
186 * @param string The length attribute of encloser tag 193 * @param string The length attribute of encloser tag
@@ -192,6 +199,6 @@
192 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type); 199 $attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
193 $this->setElement('enclosure','',$attributes); 200 $this->setElement('enclosure','',$attributes);
194 } 201 }
195 202
196 } // end of class FeedItem 203 } // end of class FeedItem
197?> \ No newline at end of file 204?> \ No newline at end of file
diff --git a/inc/3rdparty/libraries/feedwriter/FeedWriter.php b/inc/3rdparty/libraries/feedwriter/FeedWriter.php
index df4c8b4b..aa064afb 100755
--- a/inc/3rdparty/libraries/feedwriter/FeedWriter.php
+++ b/inc/3rdparty/libraries/feedwriter/FeedWriter.php
@@ -87,20 +87,26 @@ define('JSONP', 3, true);
87 * @access public 87 * @access public
88 * @return void 88 * @return void
89 */ 89 */
90 public function genarateFeed() 90 public function genarateFeed($withHeaders = true)
91 { 91 {
92 if ($this->version == RSS2) { 92 if ($withHeaders) {
93// header('Content-type: text/xml; charset=UTF-8'); 93 if ($this->version == RSS2) {
94 // this line prevents Chrome 20 from prompting download 94 header('Content-type: text/xml; charset=UTF-8');
95 // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss 95 // this line prevents Chrome 20 from prompting download
96// header('X-content-type-options: nosniff'); 96 // used by Google: https://news.google.com/news/feeds?ned=us&topic=b&output=rss
97 } elseif ($this->version == JSON) { 97 header('X-content-type-options: nosniff');
98// header('Content-type: application/json; charset=UTF-8'); 98 } elseif ($this->version == JSON) {
99 $this->json = new stdClass(); 99 header('Content-type: application/json; charset=UTF-8');
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 }
103 } 103 }
104
105 if ($this->version == JSON || $this->version == JSONP) {
106 $this->json = new stdClass();
107 }
108
109
104 $this->printHead(); 110 $this->printHead();
105 $this->printChannels(); 111 $this->printChannels();
106 $this->printItems(); 112 $this->printItems();
@@ -110,6 +116,11 @@ define('JSONP', 3, true);
110 } 116 }
111 } 117 }
112 118
119 public function &getItems()
120 {
121 return $this->items;
122 }
123
113 /** 124 /**
114 * Create a new FeedItem. 125 * Create a new FeedItem.
115 * 126 *
@@ -193,7 +204,8 @@ define('JSONP', 3, true);
193 */ 204 */
194 public function setDescription($description) 205 public function setDescription($description)
195 { 206 {
196 $this->setChannelElement('description', $description); 207 $tag = ($this->version == ATOM)? 'subtitle' : 'description';
208 $this->setChannelElement($tag, $description);
197 } 209 }
198 210
199 /** 211 /**
@@ -238,7 +250,7 @@ define('JSONP', 3, true);
238 { 250 {
239 $out = '<?xml version="1.0" encoding="utf-8"?>'."\n"; 251 $out = '<?xml version="1.0" encoding="utf-8"?>'."\n";
240 if ($this->xsl) $out .= '<?xml-stylesheet type="text/xsl" href="'.htmlspecialchars($this->xsl).'"?>' . PHP_EOL; 252 if ($this->xsl) $out .= '<?xml-stylesheet type="text/xsl" href="'.htmlspecialchars($this->xsl).'"?>' . PHP_EOL;
241 $out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL; 253 $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;
242 echo $out; 254 echo $out;
243 } 255 }
244 elseif ($this->version == JSON || $this->version == JSONP) 256 elseif ($this->version == JSON || $this->version == JSONP)