/* Jappix - An open social platform These are the microblog JS scripts for Jappix ------------------------------------------------- License: AGPL Author: Vanaryon Last revision: 03/12/11 */ // Completes arrays of an entry's attached files function attachedMicroblog(selector, tFName, tFURL, tFThumb, tFSource, tFType, tFLength, tFEComments, tFNComments) { if($(selector).attr('title')) tFName.push($(selector).attr('title')); else tFName.push(''); if($(selector).attr('href')) tFURL.push($(selector).attr('href')); else tFURL.push(''); if($(selector).find('link[rel=self][title=thumb]:first').attr('href')) tFThumb.push($(selector).find('link[rel=self][title=thumb]:first').attr('href')); else tFThumb.push(''); if($(selector).attr('source')) tFSource.push($(selector).attr('source')); else tFSource.push(''); if($(selector).attr('type')) tFType.push($(selector).attr('type')); else tFType.push(''); if($(selector).attr('length')) tFLength.push($(selector).attr('length')); else tFLength.push(''); // Comments? var comments_href_c = $(selector).find('link[rel=replies][title=comments_file]:first').attr('href'); if(comments_href_c && comments_href_c.match(/^xmpp:(.+)\?;node=(.+)/)) { tFEComments.push(RegExp.$1); tFNComments.push(decodeURIComponent(RegExp.$2)); } else { tFEComments.push(''); tFNComments.push(''); } } // Displays a given microblog item function displayMicroblog(packet, from, hash, mode, way) { // Get some values var iParse = $(packet.getNode()).find('items item'); iParse.each(function() { // Initialize var tTitle, tFiltered, tTime, tDate, tStamp, tBody, tName, tID, tHash, tIndividual, tFEClick; // Arrays var tFName = []; var tFURL = []; var tFThumb = []; var tFSource = []; var tFType = []; var tFLength = []; var tFEComments = []; var tFNComments = []; var aFURL = []; var aFCat = []; // Get the values tDate = $(this).find('published').text(); tBody = $(this).find('body').text(); tID = $(this).attr('id'); tName = getBuddyName(from); tHash = 'update-' + hex_md5(tName + tDate + tID); // Read attached files with a thumb (place them at first) $(this).find('link[rel=enclosure]:has(link[rel=self][title=thumb])').each(function() { attachedMicroblog(this, tFName, tFURL, tFThumb, tFSource, tFType, tFLength, tFEComments, tFNComments); }); // Read attached files without any thumb $(this).find('link[rel=enclosure]:not(:has(link[rel=self][title=thumb]))').each(function() { attachedMicroblog(this, tFName, tFURL, tFThumb, tFSource, tFType, tFLength, tFEComments, tFNComments); }); // Get the repeat value var uRepeat = [$(this).find('source author name').text(), explodeThis(':', $(this).find('source author uri').text(), 1)]; var uRepeated = false; if(!uRepeat[0]) uRepeat = [getBuddyName(from), uRepeat[1]]; if(!uRepeat[1]) uRepeat = [uRepeat[0], from]; // Repeated? if(uRepeat[1] != from) uRepeated = true; // Get the comments node var entityComments, nodeComments; // Get the comments var comments_href = $(this).find('link[title=comments]:first').attr('href'); if(comments_href && comments_href.match(/^xmpp:(.+)\?;node=(.+)/)) { entityComments = RegExp.$1; nodeComments = decodeURIComponent(RegExp.$2); } // No comments node? if(!entityComments || !nodeComments) { entityComments = ''; nodeComments = ''; } // Get the stamp & time if(tDate) { tStamp = extractStamp(Date.jab2date(tDate)); tTime = relativeDate(tDate); } else { tStamp = getTimeStamp(); tTime = ''; } // Get the item geoloc var tGeoloc = ''; var sGeoloc = $(this).find('geoloc[xmlns=' + NS_GEOLOC + ']:first'); var gLat = sGeoloc.find('lat').text(); var gLon = sGeoloc.find('lon').text(); if(gLat && gLon) { tGeoloc += ''; // Human-readable name? var gHuman = humanPosition( sGeoloc.find('locality').text(), sGeoloc.find('region').text(), sGeoloc.find('country').text() ); if(gHuman) tGeoloc += gHuman.htmlEnc(); else tGeoloc += gLat.htmlEnc() + '; ' + gLon.htmlEnc(); tGeoloc += ''; } // Retrieve the message body tTitle = $(this).find('content[type=text]').text(); if(!tTitle) { // Legacy? tTitle = $(this).find('title:not(source > title)').text(); // Last chance? if(!tTitle) tTitle = tBody; } // Trim the content tTitle = trim(tTitle); // Any content? if(tTitle) { // Apply links to message body tFiltered = filterThisMessage(tTitle, tName.htmlEnc(), true); // Display the received message var html = '
'; // Is it a repeat? if(uRepeated) html += ''; html += '' + tName.htmlEnc() + ' ' + tFiltered + '
' + '' + tTime + tGeoloc + '
'; // Any file to display? if(tFURL.length) html += ''; // Generate an array of the files URL for(var a = 0; a < tFURL.length; a++) { // Not enough data? if(!tFURL[a]) continue; // Push the current URL! (YouTube or file) if(tFURL[a].match(/(\w{3,5})(:)(\S+)((\.youtube\.com\/watch(\?v|\?\S+v|\#\!v|\#\!\S+v)\=)|(youtu\.be\/))([^& ]+)((&\S)|(&\S)|\s|$)/gim)) { aFURL.push(trim(RegExp.$8)); aFCat.push('youtube'); } else if(canIntegrateBox(explodeThis('/', tFType[a], 1))) { aFURL.push(tFURL[a]); aFCat.push(fileCategory(explodeThis('/', tFType[a], 1))); } } // Add each file code for(var f = 0; f < tFURL.length; f++) { // Not enough data? if(!tFURL[f]) continue; // Get the file type var tFExt = explodeThis('/', tFType[f], 1); var tFCat = fileCategory(tFExt); var tFLink = tFURL[f]; // Youtube video? if(tFLink.match(/(\w{3,5})(:)(\S+)((\.youtube\.com\/watch(\?v|\?\S+v|\#\!v|\#\!\S+v)\=)|(youtu\.be\/))([^& ]+)((&\S)|(&\S)|\s|$)/gim)) { tFLink = trim(RegExp.$8); tFCat = 'youtube'; } // Supported image/video/sound if(canIntegrateBox(tFExt) || (tFCat == 'youtube')) tFEClick = 'onclick="return applyIntegrateBox(\'' + encodeOnclick(tFLink) + '\', \'' + encodeOnclick(tFCat) + '\', \'' + encodeOnclick(aFURL) + '\', \'' + encodeOnclick(aFCat) + '\', \'' + encodeOnclick(tFEComments) + '\', \'' + encodeOnclick(tFNComments) + '\', \'large\');" '; else tFEClick = ''; // Any thumbnail? if(tFThumb[f]) html += ''; else html += '' + tFName[f].htmlEnc() + ''; } if(tFURL.length) html += '
'; // It's my own notice, we can remove it! if(from == getXID()) html += ''; // Notice from another user else { // User profile html += ''; // If PEP is enabled if(enabledPEP()) html += ''; } html += '
' + filterThisMessage(current_body, current_name, true) + '
' + '