Skip to content
Snippets Groups Projects

Fix massive regression introduced in previous commit.

Merged echicken requested to merge (removed):rss-atom into master
1 file
+ 44
98
Compare changes
  • Side-by-side
  • Inline
+ 44
98
@@ -109,111 +109,53 @@
@@ -109,111 +109,53 @@
Array of { type : String, url : String, length : Number } objects
Array of { type : String, url : String, length : Number } objects
for any <enclosure> elements in the item.
for any <enclosure> elements in the item.
Item.extra (Object)
If the item/entry contains additional elements not provided for
above, they are tacked on to this object in case you may need
to access them. Presumably these will all be E4X XML objects.
*/
*/
load("http.js");
load("http.js");
// This is really not the way to do things, but meh.
const Item = function (i) {
var toLocal = function(xmlObject) {
for each(var element in xmlObject) {
this.id = i.guid.length() ? i.guid[0].toString() : (i.id.length() ? i.id[0].toString() : '');
element.setName(element.localName());
this.title = ''; // uh ...
toLocal(element);
this.date = i.pubDate.length() ? i.pubDate[0].toString() : (i.updated.length() ? i.updated[0].toString() : '');
}
this.author = i.author.length() ? i.author.toString() : '';
}
this.body = i.description.length() ? i.description[0].toString() : (i.summary.length() ? i.summary[0].toString() : '');
this.content = i.encoded.length() ? i.encoded.toString() : '';
var Feed = function (url, follow_redirects) {
this.link = i.link.length() ? skipsp(truncsp(i.link[0].toString())) : '';
this.enclosures = [];
var Item = function Item(xmlObject) {
var enclosures = i.enclosure.length();
this.id = "";
for (var n = 0; n < enclosures; n++) {
this.title = "";
this.enclosures.push({
this.date = "";
type: i.enclosure[n].attribute('type'),
this.author = "";
url: i.enclosure[n].attribute('url'),
this.body = "";
length: parseInt(i.enclosure[n].attribute('length'), 10),
this.content = "";
});
this.link = "";
this.enclosures = [];
this.extra = {};
for each(var element in xmlObject) {
switch (element.name()) {
case 'guid':
case 'id':
this.id = element;
break;
case 'pubDate':
case 'updated':
this.date = element;
break;
case 'author':
this.author = element.text();
break;
case 'description':
case 'summary':
this.body = element;
break;
case 'link':
this.link = skipsp(truncsp(element.text()));
break;
case 'encoded':
this.content = element;
break;
case 'enclosure':
this.enclosures.push({
type: element.attribute('type'),
url: element.attribute("url"),
length: parseInt(element.attribute('length'), 10),
});
break;
default:
this.extra[element.name()] = element;
}
}
}
}
var Channel = function (xmlObject) {
}
this.title = "a";
this.description = "";
this.link = "";
this.updated = "";
this.items = [];
if (typeof xmlObject.title != "undefined") this.title = xmlObject.title;
const Channel = function (c) {
if (typeof xmlObject.description != "undefined") {
this.title = c.title.length() ? c.title[0].toString() : '';
this.description = xmlObject.description;
this.description = c.description.length() ? c.description[0].toString() : (c.subtitle.length() ? c.subtitle[0].toString() : '');
} else if (typeof xmlObject.subtitle != "undefined") {
this.link = c.link.length() ? skipsp(truncsp(c.link[0].toString())) : '';
this.description = xmlObject.subtitle;
this.updated = c.lastBuildDate.length() ? c.lastBuildDate[0].toString() : (c.updated.length() ? c.updated[0].toString() : '');
}
this.items = [];
// To do: deal with multiple links
var items = c.item.length();
if (typeof xmlObject.link != "undefined") this.link = skipsp(truncsp(xmlObject.link.text()));
for (var n = 0; n < items; n++) {
this.items.push(new Item(c.item[n]));
if (typeof xmlObject.lastBuildDate != "undefined") {
}
this.updated = xmlObject.lastBuildDate;
} else if (typeof xmlObject.updated != "undefined") {
this.updated = xmlObject.updated;
}
var items = xmlObject.elements("item");
var entries = c.entry.length();
for each(var item in items) {
for (var n = 0; n < entries; n++) {
this.items.push(new Item(item));
this.items.push(new Item(c.entry[n]));
}
}
var entries = xmlObject.elements("entry");
}
for each(var entry in entries) {
this.items.push(new Item(entry));
}
}
const Feed = function (url, follow_redirects) {
this.channels = [];
this.channels = [];
@@ -221,14 +163,17 @@ var Feed = function (url, follow_redirects) {
@@ -221,14 +163,17 @@ var Feed = function (url, follow_redirects) {
var httpRequest = new HTTPRequest();
var httpRequest = new HTTPRequest();
httpRequest.follow_redirects = follow_redirects || 0;
httpRequest.follow_redirects = follow_redirects || 0;
var response = httpRequest.Get(url);
var response = httpRequest.Get(url);
if (typeof response == "undefined" || response == "") throw "Empty response from server.";
if (typeof response == "undefined" || response == "") {
 
throw new Error('Empty response from server.');
 
}
var feed = new XML(response.replace(/^<\?xml.*\?>/g, ""));
var feed = new XML(response.replace(/^<\?xml.*\?>/g, ""));
toLocal(feed); // This is shitty
httpRequest = undefined;
 
response = undefined;
switch (feed.localName()) {
switch (feed.localName()) {
case "rss":
case "rss":
var channels = feed.elements("channel");
var channels = feed.channel.length();
for each(var element in channels) {
for (var n = 0; n < channels; n++) {
this.channels.push(new Channel(element));
this.channels.push(new Channel(feed.channel[n]));
}
}
break;
break;
case "feed":
case "feed":
@@ -237,6 +182,7 @@ var Feed = function (url, follow_redirects) {
@@ -237,6 +182,7 @@ var Feed = function (url, follow_redirects) {
default:
default:
break;
break;
}
}
 
feed = undefined;
}
}
this.load();
this.load();
Loading