diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-04-11 17:22:04 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-04-11 17:22:04 +0200 |
commit | 4a74d9857cdb6116ce24df01b45176b92ad592c0 (patch) | |
tree | f8347803fe40f8b27218cbad8ed688c7dbf3a46e /inc/3rdparty/libraries | |
parent | 0d67b00d5d3b7ce1b76b639dcc65c415a5f13439 (diff) | |
parent | 7256e9e139eb07cdae1fbe3009454e6c7d9a8677 (diff) | |
download | wallabag-4a74d9857cdb6116ce24df01b45176b92ad592c0.tar.gz wallabag-4a74d9857cdb6116ce24df01b45176b92ad592c0.tar.zst wallabag-4a74d9857cdb6116ce24df01b45176b92ad592c0.zip |
Merge pull request #634 from wallabag/dev1.6.1b
1.6.1
Diffstat (limited to 'inc/3rdparty/libraries')
-rw-r--r-- | inc/3rdparty/libraries/feedwriter/FeedItem.php | 353 | ||||
-rwxr-xr-x | inc/3rdparty/libraries/feedwriter/FeedWriter.php | 839 |
2 files changed, 601 insertions, 591 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 |
diff --git a/inc/3rdparty/libraries/feedwriter/FeedWriter.php b/inc/3rdparty/libraries/feedwriter/FeedWriter.php index 5d16e765..df4c8b4b 100755 --- a/inc/3rdparty/libraries/feedwriter/FeedWriter.php +++ b/inc/3rdparty/libraries/feedwriter/FeedWriter.php | |||
@@ -18,424 +18,423 @@ define('JSONP', 3, true); | |||
18 | */ | 18 | */ |
19 | class FeedWriter | 19 | class FeedWriter |
20 | { | 20 | { |
21 | private $self = null; // self URL - http://feed2.w3.org/docs/warning/MissingAtomSelfLink.html | 21 | private $self = null; // self URL - http://feed2.w3.org/docs/warning/MissingAtomSelfLink.html |
22 | private $hubs = array(); // PubSubHubbub hubs | 22 | private $hubs = array(); // PubSubHubbub hubs |
23 | private $channels = array(); // Collection of channel elements | 23 | private $channels = array(); // Collection of channel elements |
24 | private $items = array(); // Collection of items as object of FeedItem class. | 24 | private $items = array(); // Collection of items as object of FeedItem class. |
25 | private $data = array(); // Store some other version wise data | 25 | private $data = array(); // Store some other version wise data |
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 |
58 | * @param srting name of the channel tag | 58 | * @param srting name of the channel tag |
59 | * @param string content of the channel tag | 59 | * @param string content of the channel tag |
60 | * @return void | 60 | * @return void |
61 | */ | 61 | */ |
62 | public function setChannelElement($elementName, $content) | 62 | public function setChannelElement($elementName, $content) |
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 |
74 | */ | 74 | */ |
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(); |
105 | $this->printChannels(); | 105 | $this->printChannels(); |
106 | $this->printItems(); | 106 | $this->printItems(); |
107 | $this->printTale(); | 107 | $this->printTale(); |
108 | if ($this->version == JSON || $this->version == JSONP) { | 108 | if ($this->version == JSON || $this->version == JSONP) { |
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 | */ |
119 | public function createNewItem() | 119 | public function createNewItem() |
120 | { | 120 | { |
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 |
145 | */ | 145 | */ |
146 | public function setTitle($title) | 146 | public function setTitle($title) |
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($description) |
195 | { | 195 | { |
196 | $tag = ($this->version == ATOM)? 'subtitle' : 'description'; | 196 | $this->setChannelElement('description', $description); |
197 | $this->setChannelElement($tag, $desciption); | 197 | } |
198 | } | 198 | |
199 | 199 | /** | |
200 | /** | 200 | * Set the 'link' channel element |
201 | * Set the 'link' channel element | 201 | * |
202 | * | 202 | * @access public |
203 | * @access public | 203 | * @param srting value of 'link' channel tag |
204 | * @param srting value of 'link' channel tag | 204 | * @return void |
205 | * @return void | 205 | */ |
206 | */ | 206 | public function setLink($link) |
207 | public function setLink($link) | 207 | { |
208 | { | 208 | $this->setChannelElement('link', $link); |
209 | $this->setChannelElement('link', $link); | 209 | } |
210 | } | 210 | |
211 | 211 | /** | |
212 | /** | 212 | * Set the 'image' channel element |
213 | * Set the 'image' channel element | 213 | * |
214 | * | 214 | * @access public |
215 | * @access public | 215 | * @param srting title of image |
216 | * @param srting title of image | 216 | * @param srting link url of the imahe |
217 | * @param srting link url of the imahe | 217 | * @param srting path url of the image |
218 | * @param srting path url of the image | 218 | * @return void |
219 | * @return void | 219 | */ |
220 | */ | 220 | public function setImage($title, $link, $url) |
221 | public function setImage($title, $link, $url) | 221 | { |
222 | { | 222 | $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url)); |
223 | $this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url)); | 223 | } |
224 | } | 224 | |
225 | 225 | // End # public functions ---------------------------------------------- | |
226 | // End # public functions ---------------------------------------------- | 226 | |
227 | 227 | // Start # private functions ---------------------------------------------- | |
228 | // Start # private functions ---------------------------------------------- | 228 | |
229 | 229 | /** | |
230 | /** | 230 | * Prints the xml and rss namespace |
231 | * Prints the xml and rss namespace | 231 | * |
232 | * | 232 | * @access private |
233 | * @access private | 233 | * @return void |
234 | * @return void | 234 | */ |
235 | */ | 235 | private function printHead() |
236 | private function printHead() | 236 | { |
237 | { | 237 | if ($this->version == RSS2) |
238 | if ($this->version == RSS2) | 238 | { |
239 | { | 239 | $out = '<?xml version="1.0" encoding="utf-8"?>'."\n"; |
240 | $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; |
241 | 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; |
242 | $out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL; | 242 | echo $out; |
243 | echo $out; | 243 | } |
244 | } | 244 | elseif ($this->version == JSON || $this->version == JSONP) |
245 | elseif ($this->version == JSON || $this->version == JSONP) | 245 | { |
246 | { | 246 | $this->json->rss = array('@attributes' => array('version' => '2.0')); |
247 | $this->json->rss = array('@attributes' => array('version' => '2.0')); | 247 | } |
248 | } | 248 | } |
249 | } | 249 | |
250 | 250 | /** | |
251 | /** | 251 | * Closes the open tags at the end of file |
252 | * Closes the open tags at the end of file | 252 | * |
253 | * | 253 | * @access private |
254 | * @access private | 254 | * @return void |
255 | * @return void | 255 | */ |
256 | */ | 256 | private function printTale() |
257 | private function printTale() | 257 | { |
258 | { | 258 | if ($this->version == RSS2) |
259 | if ($this->version == RSS2) | 259 | { |
260 | { | 260 | echo '</channel>',PHP_EOL,'</rss>'; |
261 | echo '</channel>',PHP_EOL,'</rss>'; | 261 | } |
262 | } | 262 | // do nothing for JSON |
263 | // do nothing for JSON | 263 | } |
264 | } | 264 | |
265 | 265 | /** | |
266 | /** | 266 | * Creates a single node as xml format |
267 | * Creates a single node as xml format | 267 | * |
268 | * | 268 | * @access private |
269 | * @access private | 269 | * @param string name of the tag |
270 | * @param string name of the tag | 270 | * @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 | 271 | * @param array Attributes(if any) in 'attrName' => 'attrValue' format |
272 | * @param array Attributes(if any) in 'attrName' => 'attrValue' format | 272 | * @return string formatted xml tag |
273 | * @return string formatted xml tag | 273 | */ |
274 | */ | 274 | private function makeNode($tagName, $tagContent, $attributes = null) |
275 | private function makeNode($tagName, $tagContent, $attributes = null) | 275 | { |
276 | { | 276 | if ($this->version == RSS2) |
277 | if ($this->version == RSS2) | 277 | { |
278 | { | 278 | $nodeText = ''; |
279 | $nodeText = ''; | 279 | $attrText = ''; |
280 | $attrText = ''; | 280 | if (is_array($attributes)) |
281 | if (is_array($attributes)) | 281 | { |
282 | { | 282 | foreach ($attributes as $key => $value) |
283 | foreach ($attributes as $key => $value) | 283 | { |
284 | { | 284 | $attrText .= " $key=\"$value\" "; |
285 | $attrText .= " $key=\"$value\" "; | 285 | } |
286 | } | 286 | } |
287 | } | 287 | $nodeText .= "<{$tagName}{$attrText}>"; |
288 | $nodeText .= "<{$tagName}{$attrText}>"; | 288 | if (is_array($tagContent)) |
289 | if (is_array($tagContent)) | 289 | { |
290 | { | 290 | foreach ($tagContent as $key => $value) |
291 | foreach ($tagContent as $key => $value) | 291 | { |
292 | { | 292 | $nodeText .= $this->makeNode($key, $value); |
293 | $nodeText .= $this->makeNode($key, $value); | 293 | } |
294 | } | 294 | } |
295 | } | 295 | else |
296 | else | 296 | { |
297 | { | 297 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent); |
298 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent); | 298 | $nodeText .= htmlspecialchars($tagContent); |
299 | $nodeText .= htmlspecialchars($tagContent); | 299 | } |
300 | } | 300 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>"; |
301 | //$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>"; | 301 | $nodeText .= "</$tagName>"; |
302 | $nodeText .= "</$tagName>"; | 302 | return $nodeText . PHP_EOL; |
303 | return $nodeText . PHP_EOL; | 303 | } |
304 | } | 304 | elseif ($this->version == JSON || $this->version == JSONP) |
305 | elseif ($this->version == JSON || $this->version == JSONP) | 305 | { |
306 | { | 306 | $tagName = (string)$tagName; |
307 | $tagName = (string)$tagName; | 307 | $tagName = strtr($tagName, ':', '_'); |
308 | $tagName = strtr($tagName, ':', '_'); | 308 | $node = null; |
309 | $node = null; | 309 | if (!$tagContent && is_array($attributes) && count($attributes)) |
310 | if (!$tagContent && is_array($attributes) && count($attributes)) | 310 | { |
311 | { | 311 | $node = array('@attributes' => $this->json_keys($attributes)); |
312 | $node = array('@attributes' => $this->json_keys($attributes)); | 312 | } else { |
313 | } else { | 313 | if (is_array($tagContent)) { |
314 | if (is_array($tagContent)) { | 314 | $node = $this->json_keys($tagContent); |
315 | $node = $this->json_keys($tagContent); | 315 | } else { |
316 | } else { | 316 | $node = $tagContent; |
317 | $node = $tagContent; | 317 | } |
318 | } | 318 | } |
319 | } | 319 | return $node; |
320 | return $node; | 320 | } |
321 | } | 321 | return ''; // should not get here |
322 | return ''; // should not get here | 322 | } |
323 | } | 323 | |
324 | 324 | private function json_keys(array $array) { | |
325 | private function json_keys(array $array) { | 325 | $new = array(); |
326 | $new = array(); | 326 | foreach ($array as $key => $val) { |
327 | foreach ($array as $key => $val) { | 327 | if (is_string($key)) $key = strtr($key, ':', '_'); |
328 | if (is_string($key)) $key = strtr($key, ':', '_'); | 328 | if (is_array($val)) { |
329 | if (is_array($val)) { | 329 | $new[$key] = $this->json_keys($val); |
330 | $new[$key] = $this->json_keys($val); | 330 | } else { |
331 | } else { | 331 | $new[$key] = $val; |
332 | $new[$key] = $val; | 332 | } |
333 | } | 333 | } |
334 | } | 334 | return $new; |
335 | return $new; | 335 | } |
336 | } | 336 | |
337 | 337 | /** | |
338 | /** | 338 | * @desc Print channels |
339 | * @desc Print channels | 339 | * @access private |
340 | * @access private | 340 | * @return void |
341 | * @return void | 341 | */ |
342 | */ | 342 | private function printChannels() |
343 | private function printChannels() | 343 | { |
344 | { | 344 | //Start channel tag |
345 | //Start channel tag | 345 | if ($this->version == RSS2) { |
346 | if ($this->version == RSS2) { | 346 | echo '<channel>' . PHP_EOL; |
347 | echo '<channel>' . PHP_EOL; | 347 | // add hubs |
348 | // add hubs | 348 | foreach ($this->hubs as $hub) { |
349 | foreach ($this->hubs as $hub) { | 349 | //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')); | 350 | echo '<link rel="hub" href="'.htmlspecialchars($hub).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL; |
351 | echo '<link rel="hub" href="'.htmlspecialchars($hub).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL; | 351 | } |
352 | } | 352 | // add self |
353 | // add self | 353 | if (isset($this->self)) { |
354 | if (isset($this->self)) { | 354 | //echo $this->makeNode('link', '', array('rel'=>'self', 'href'=>$this->self, 'xmlns'=>'http://www.w3.org/2005/Atom')); |
355 | //echo $this->makeNode('link', '', array('rel'=>'self', 'href'=>$this->self, 'xmlns'=>'http://www.w3.org/2005/Atom')); | 355 | 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; | 356 | } |
357 | } | 357 | //Print Items of channel |
358 | //Print Items of channel | 358 | foreach ($this->channels as $key => $value) |
359 | foreach ($this->channels as $key => $value) | 359 | { |
360 | { | 360 | echo $this->makeNode($key, $value); |
361 | echo $this->makeNode($key, $value); | 361 | } |
362 | } | 362 | } elseif ($this->version == JSON || $this->version == JSONP) { |
363 | } elseif ($this->version == JSON || $this->version == JSONP) { | 363 | $this->json->rss['channel'] = (object)$this->json_keys($this->channels); |
364 | $this->json->rss['channel'] = (object)$this->json_keys($this->channels); | 364 | } |
365 | } | 365 | } |
366 | } | 366 | |
367 | 367 | /** | |
368 | /** | 368 | * Prints formatted feed items |
369 | * Prints formatted feed items | 369 | * |
370 | * | 370 | * @access private |
371 | * @access private | 371 | * @return void |
372 | * @return void | 372 | */ |
373 | */ | 373 | private function printItems() |
374 | private function printItems() | 374 | { |
375 | { | 375 | foreach ($this->items as $item) { |
376 | foreach ($this->items as $item) { | 376 | $itemElements = $item->getElements(); |
377 | $itemElements = $item->getElements(); | 377 | |
378 | 378 | echo $this->startItem(); | |
379 | echo $this->startItem(); | 379 | |
380 | 380 | if ($this->version == JSON || $this->version == JSONP) { | |
381 | if ($this->version == JSON || $this->version == JSONP) { | 381 | $json_item = array(); |
382 | $json_item = array(); | 382 | } |
383 | } | 383 | |
384 | 384 | foreach ($itemElements as $thisElement) { | |
385 | foreach ($itemElements as $thisElement) { | 385 | foreach ($thisElement as $instance) { |
386 | foreach ($thisElement as $instance) { | 386 | if ($this->version == RSS2) { |
387 | if ($this->version == RSS2) { | 387 | echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); |
388 | echo $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); | 388 | } elseif ($this->version == JSON || $this->version == JSONP) { |
389 | } elseif ($this->version == JSON || $this->version == JSONP) { | 389 | $_json_node = $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); |
390 | $_json_node = $this->makeNode($instance['name'], $instance['content'], $instance['attributes']); | 390 | if (count($thisElement) > 1) { |
391 | if (count($thisElement) > 1) { | 391 | $json_item[strtr($instance['name'], ':', '_')][] = $_json_node; |
392 | $json_item[strtr($instance['name'], ':', '_')][] = $_json_node; | 392 | } else { |
393 | } else { | 393 | $json_item[strtr($instance['name'], ':', '_')] = $_json_node; |
394 | $json_item[strtr($instance['name'], ':', '_')] = $_json_node; | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | } | 397 | } |
398 | } | 398 | echo $this->endItem(); |
399 | echo $this->endItem(); | 399 | if ($this->version == JSON || $this->version == JSONP) { |
400 | if ($this->version == JSON || $this->version == JSONP) { | 400 | if (count($this->items) > 1) { |
401 | if (count($this->items) > 1) { | 401 | $this->json->rss['channel']->item[] = $json_item; |
402 | $this->json->rss['channel']->item[] = $json_item; | 402 | } else { |
403 | } else { | 403 | $this->json->rss['channel']->item = $json_item; |
404 | $this->json->rss['channel']->item = $json_item; | 404 | } |
405 | } | 405 | } |
406 | } | 406 | } |
407 | } | 407 | } |
408 | } | 408 | |
409 | 409 | /** | |
410 | /** | 410 | * Make the starting tag of channels |
411 | * Make the starting tag of channels | 411 | * |
412 | * | 412 | * @access private |
413 | * @access private | 413 | * @return void |
414 | * @return void | 414 | */ |
415 | */ | 415 | private function startItem() |
416 | private function startItem() | 416 | { |
417 | { | 417 | if ($this->version == RSS2) |
418 | if ($this->version == RSS2) | 418 | { |
419 | { | 419 | echo '<item>' . PHP_EOL; |
420 | echo '<item>' . PHP_EOL; | 420 | } |
421 | } | 421 | // nothing for JSON |
422 | // nothing for JSON | 422 | } |
423 | } | 423 | |
424 | 424 | /** | |
425 | /** | 425 | * Closes feed item tag |
426 | * Closes feed item tag | 426 | * |
427 | * | 427 | * @access private |
428 | * @access private | 428 | * @return void |
429 | * @return void | 429 | */ |
430 | */ | 430 | private function endItem() |
431 | private function endItem() | 431 | { |
432 | { | 432 | if ($this->version == RSS2) |
433 | if ($this->version == RSS2) | 433 | { |
434 | { | 434 | echo '</item>' . PHP_EOL; |
435 | echo '</item>' . PHP_EOL; | 435 | } |
436 | } | 436 | // nothing for JSON |
437 | // nothing for JSON | 437 | } |
438 | } | 438 | |
439 | 439 | // End # private functions ---------------------------------------------- | |
440 | // End # private functions ---------------------------------------------- | ||
441 | } \ No newline at end of file | 440 | } \ No newline at end of file |