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