/************************************************************************************************************************************ * fb.wall Facebook Wall jQuery Plguin * * @author: Daniel Benkenstein / neosmart GmbH * @version: 1.2.7 * @Last Update: 06.06.2011 * @licence: MIT (http://www.opensource.org/licenses/mit-license.php) * GPL (http://www.gnu.org/licenses/gpl.html) * @documentation: http://www.neosmart.de/social-media/facebook-wall * @feedback: http://www.neosmart.de/blog/jquery-plugin-facebook-wall * ************************************************************************************************************************************/ (function($) { $.fn.fbWall = function(options) { var opts = $.extend({}, $.fn.fbWall.defaults, options); var meta = this; return meta.each(function() { $this = $(this); var o = $.meta ? $.extend({}, opts, $this.data()) : opts; var output = ''; var avatarBaseURL; var baseData; var graphURL = "https://graph.facebook.com/"; /****************************************************************************************************** * Load base data ******************************************************************************************************/ meta.addClass('fb-wall').addClass('loading').html(''); $.ajax({ url: graphURL+o.id+'?access_token='+o.accessToken, dataType: "jsonp", success: function(data, textStatus, XMLHttpRequest){ initBase(data); } }); /****************************************************************************************************** * Load feed data ******************************************************************************************************/ var initBase = function(data){ baseData = data; if(data==false){ meta.removeClass('loading').html('The alias you requested do not exist: '+o.id); return false; }; if(data.error){ meta.removeClass('loading').html(data.error.message); return false; }; var type = (o.showGuestEntries=='true'||o.showGuestEntries==true) ? 'feed' : 'posts'; $.ajax({ url: graphURL+o.id+"/"+type+"?limit="+o.max+'&access_token='+o.accessToken, dataType: "jsonp", success:function (data, textStatus, XMLHttpRequest) { meta.removeClass('loading'); initWall(data); } }); } /****************************************************************************************************** * Parse feed data / wall ******************************************************************************************************/ var initWall = function(data){ data = data.data; var max = data.length; var thisAvatar, isBase, hasBaseLink, thisDesc; for(var k=0;k' : '
'; output += ''; output += ''; output += ''; output += '
'; output += ''; output += ''+data[k].from.name+' '; output += modText(data[k].message); output += ''; // Media ----------------------------------------------------------------------------------------------------------------------------------- if(exists(data[k].picture)||exists(data[k].link)||exists(data[k].caption)||exists(data[k].description)){ output += exists(data[k].picture) ? '
' : '
'; if(exists(data[k].picture)){ if(exists(data[k].link)) output += ''; output += ''; if(exists(data[k].link)) output += ''; } output += '
'; if(exists(data[k].name)) output += ''+data[k].name+''; if(exists(data[k].caption)) output += ''+data[k].caption+''; if(exists(data[k].properties)){ for(var p=0;p'+formatDate(data[k].properties[p].text)+'
' : '
'+data[k].properties[p].text+'
'; } if(exists(data[k].description)){ thisDesc = modText(data[k].description); if(thisDesc.length>299)thisDesc=thisDesc.substr(0,thisDesc.lastIndexOf(' '))+' ...'; output += ''+thisDesc+''; } output += '
'; output += '
'; } output += ''; if(exists(data[k].icon)) output += ''; output += formatDate(data[k].created_time)+''; // Likes ------------------------------------------------------------------------------------------------------------------------------- if(exists(data[k].likes)){ if(parseInt(data[k].likes.count)==1){ output += ''; } else { output += ''; } } // Comments ------------------------------------------------------------------------------------------------------------------------------- if(exists(data[k].comments) && exists(data[k].comments.data) && (o.showComments==true||o.showComments=='true')){ output += '
'; for(var c=0;c'; output += ''; output += ''; output += ''; output += ''+data[k].comments.data[c].from.name+' '; output += modText(data[k].comments.data[c].message); output += ''+formatDate(data[k].comments.data[c].created_time)+''; output += ''; output += ''; } output += '
'; } output += '
'; output += '
'; output += '
'; } } // No data found -------------------------------------------------------------------------------------------- if(max==0){ output += '
'; output += ''; output += '
'; output += ''+baseData.name+' '+o.translateErrorNoData+''; output += '
'; output += '
'; } meta.hide().html(output).fadeIn(700); } /****************************************************************************************************** * Get Avatar URLs ******************************************************************************************************/ function getAvatarURL(id){ var avatarURL; if(id==baseData.id){ avatarURL = (o.useAvatarAlternative) ? o.avatarAlternative : graphURL+id+'/picture?type=square'; } else{ avatarURL = (o.useAvatarExternal) ? o.avatarExternal : graphURL+id+'/picture?type=square'; } return avatarURL; } /****************************************************************************************************** * Parse dateStr as formatted date * @return: if dateStr can't be parsed as Date, return dateStr ******************************************************************************************************/ function formatDate(dateStr){ var year, month, day, hour, minute, dateUTC, date, ampm, d, time; var iso = (dateStr.indexOf(' ')==-1&&dateStr.substr(4,1)=='-'&&dateStr.substr(7,1)=='-'&&dateStr.substr(10,1)=='T') ? true : false; if(iso){ year = dateStr.substr(0,4); month = parseInt((dateStr.substr(5,1)=='0') ? dateStr.substr(6,1) : dateStr.substr(5,2))-1; day = dateStr.substr(8,2); hour = dateStr.substr(11,2); minute = dateStr.substr(14,2); dateUTC = Date.UTC(year, month, day, hour, minute); date = new Date(dateUTC); }else{ d = dateStr.split(' '); if(d.length!=6||d[4]!='at') return dateStr; time = d[5].split(':'); ampm = time[1].substr(2); minute = time[1].substr(0,2); hour = parseInt(time[0]); if(ampm=='pm')hour+=12; date = new Date(d[1]+' '+d[2]+' '+d[3] +' '+ hour+':'+minute); date.setTime(date.getTime()-(1000*60*60*7)); } day = (date.getDate()<10)?'0'+date.getDate():date.getDate(); month = date.getMonth(); var year = date.getFullYear(); var yearString = ''; if (currentYear > year) { yearString = ' de ' + year; } hour = date.getHours(); minute = (date.getMinutes()<10)?'0'+date.getMinutes():date.getMinutes(); if(o.timeConversion==12){ ampm = (hour<12) ? 'am' : 'pm'; if(hour==0)hour==12; else if(hour>12)hour=hour-12; if(hour<10)hour='0'+hour; return day+' de '+ months[month] +yearString+ o.translateAt +hour+':'+minute+' '+ampm; } return day+' de '+ months[month] +yearString+' '+o.translateAt+' '+hour+':'+minute; } /****************************************************************************************************** * Helper Function ******************************************************************************************************/ function exists(data){ if(!data || data==null || data=='undefined' || typeof(data)=='undefined') return false; else return true; } function modText(text){ return nl2br(autoLink(escapeTags(text))); } function escapeTags(str){ return str.replace(//g,'>'); } function nl2br(str){ return str.replace(/(\r\n)|(\n\r)|\r|\n/g,"
"); } function autoLink(str){ return str.replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '$1'); } }); }; /****************************************************************************************************** * Defaults ******************************************************************************************************/ $.fn.fbWall.defaults = { avatarAlternative: '../../images/redsociales/avatar-alternative.jpg', avatarExternal: '../../images/redsociales/avatar-external.jpg', id: 'Migrar.org', max: 5, showComments: true, showGuestEntries: false, translateAt: 'a la(s)', translateLikeThis: 'les gusta esto', translateLikesThis: 'le gusta esto', translateErrorNoData: 'no ha compartido ninguna informaciĆ³n.', translatePeople: 'personas', timeConversion: 24, useAvatarAlternative: false, useAvatarExternal: false, accessToken: '158371891005160|bVWy9motGWGzJQTR18Ij-XAKmFI' }; })(jQuery); var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; var currentYear = new Date().getFullYear();