Compare commits

...

2 commits

Author SHA1 Message Date
e67c21e69c Bump version 1.5.1 2019-07-25 15:02:19 +02:00
cb16f5d79a Fix parser degli eventi per ai1ec 2.5.39 2019-07-25 15:01:36 +02:00
3 changed files with 43 additions and 40 deletions

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="xm24.digitigrafo.it" version="1.5.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="xm24.digitigrafo.it" version="1.5.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>I love XM24</name>
<description>
Spazio Sociale Autogestito XM24, Bolognina (BO): info, eventi, comunicati.. I love XM24, iloveXM24

View file

@ -1,6 +1,6 @@
var ai1ec = (function(){
var API = {}, json = [], events = [];
//Categorie di eventi
API.cats = {
single: 34,
@ -12,60 +12,60 @@ var ai1ec = (function(){
endChar = uid.indexOf('@');
return uid.substr(initChar+1, uid.length - uid.substr(endChar -1).length - initChar );
};
};
//Parser di un evento dell'array tornato da getXmlData
API.event = {
getId : function(event) {
return event.uid ? getCleanId(event.uid) : null;
return event.properties.uid ? getCleanId(event.properties.uid.text) : null;
},
getTitle : function(event) {
return event.summary || null;
return event.properties.summary.text || null;
},
getDescription : function(event) {
return event.description || "";
return event.properties.description.text || "";
},
getInitDate : function(event) {
return event.dtstart && event.dtstart._ ? event.dtstart._ : "";
return event.properties.dtstart && event.properties.dtstart["date-time"] ? event.properties.dtstart["date-time"] : "";
},
getEndDate : function(event) {
return event.dtend && event.dtend._ ? event.dtend._ : "";
return event.properties.dtend && event.properties.dtend["date-time"] ? event.properties.dtend["date-time"] : "";
},
getCats : function(event) {
return event.categories || "";
return event.properties.categories.text || "";
},
getTags : function(event) {
return event["x-tags"] && event["x-tags"]._ ? event["x-tags"]._ : "";
return event.properties["x-tags"] && event.properties["x-tags"]._ ? event.properties["x-tags"]._ : "";
},
getUrl : function(event) {
return event.url && event.url.$ && event.url.$.uri ? event.url.$.uri : "";
return event.properties.url && event.properties.url.uri && event.properties.url.uri ? event.properties.url.uri : "";
},
getContact : function(event) {
return event.contact || "";
return event.properties.contact || "";
},
getGeo : function(event) {
return event.geo || "";
return event.properties.location.text || "";
},
//Regole per gli eventi ripetitivi
getRule : function(event) {
return event.rrule || "";
return event.properties.rrule || "";
},
getImage : function(event){
return event['x-wp-images-url'] || "";
},
getImage : function(event){
return event.properties['x-wp-images-url'] && event.properties['x-wp-images-url'].unknown ? event.properties['x-wp-images-url'].unknown : "";
},
};
var getXmlData = function(url, catId, callback) {
$.ajax({
url: url,
@ -73,7 +73,7 @@ var ai1ec = (function(){
method: 'GET',
success: function(res) {
json[catId] = $.xml2json(res);
events[catId] = json[catId]["#document"].vcalendar.vevent;
events[catId] = json[catId]["#document"].icalendar.vcalendar.components.vevent;
console.log(events[catId]);
return callback(events[catId]);
},
@ -83,13 +83,13 @@ var ai1ec = (function(){
}
});
};
var getDefaultUrl = function(catId){
catId = catId || API.cats.single;
return API.remote.site + API.remote.q + "&" + API.remote.catq + catId + "&" + API.remote.xmlq;
}
};
//Oggetto che gestisce attività remote
API.remote = {
site : 'http://www.ecn.org/xm24',
@ -99,20 +99,20 @@ var ai1ec = (function(){
xmlq : 'xml=true',
win : 'window=true',
//post_ids
//Torna un array con tutti gli eventi organizzati da xm24, un array vuoto se errore.
getAllEvents : function(catId, callback) {
var url = getDefaultUrl(catId);
getXmlData(url, catId, callback);
},
},
//Torna un array con gli eventi tra -30 e +30 giorni da oggi, un array vuoto se errore.
getLastEvents : function(catId, callback) {
var url = getDefaultUrl(catId) + '&' + API.remote.win;
getXmlData(url, catId, callback);
},
},
}
return API;
})();

View file

@ -63,6 +63,9 @@
for (i = 0; i < xml.childNodes.length; i++) {
node = xml.childNodes[i];
if (node.nodeName === "#comment")
continue;
if (node.nodeType === 1) {
if (node.attributes.length === 0 && node.childElementCount === 0){
@ -116,7 +119,7 @@
}
var root = {};
if (xml.attributes && xml.attributes.length === 0 && xml.childElementCount === 0){
root[xml.nodeName] = normalize(xml.textContent, options);
} else {
@ -133,4 +136,4 @@
} else if (typeof window !== 'undefined') {
window.xml2json = xml2json;
}
})();
})();