1/* 2Plugin Name: Twitter Feed 3Written by: Crivos - (http://www.crivos.com) 4Version: 0.1 5*/ 6 7;(function($, window){ 8 9var twitterFeed = { 10 11 options: { 12 id: "", 13 count: 1, 14 URL: theme_settings.twitter_feed, 15 wrapper: "tweet" 16 }, 17 18 initialize: function( options ) { 19 this.options = $.extend( {}, this.options, options ); 20 this.build(); 21 22 return this; 23 }, 24 25 build: function() { 26 27 var $this = this; 28 29 var showdirecttweets = false; 30 var showretweets = true; 31 var showtweetlinks = true; 32 var showprofilepic = true; 33 34 $.getJSON($this.options.URL, { 35 username: $this.options.id, 36 count: $this.options.count 37 }, 38 function (feeds) { 39 40 var feedHTML = ''; 41 var displayCounter = 1; 42 for (var i = 0; i < feeds.length; i++) { 43 var tweetscreenname = feeds[i].user.name; 44 var tweetusername = feeds[i].user.screen_name; 45 var profileimage = feeds[i].user.profile_image_url_https; 46 var status = feeds[i].text; 47 var isaretweet = false; 48 var isdirect = false; 49 var tweetid = feeds[i].id_str; 50 51 if (typeof feeds[i].retweeted_status != 'undefined') { 52 profileimage = feeds[i].retweeted_status.user.profile_image_url_https; 53 tweetscreenname = feeds[i].retweeted_status.user.name; 54 tweetusername = feeds[i].retweeted_status.user.screen_name; 55 tweetid = feeds[i].retweeted_status.id_str 56 isaretweet = true; 57 }; 58 59 //Check to see if the tweet is a direct message 60 if (feeds[i].text.substr(0, 1) == "@") { 61 isdirect = true; 62 } 63 64 if (((showretweets == true) || ((isaretweet == false) && (showretweets == false))) && ((showdirecttweets == true) || ((showdirecttweets == false) && (isdirect == false)))) { 65 if ((feeds[i].text.length > 1) && (displayCounter <= $this.options.count)) { 66 if (showtweetlinks == true) { 67 status = $this.addLink(status); 68 } 69 70 feedHTML += '<i class="icon-twitter"></i> ' + status + ' <a class="time" href="https://twitter.com/' + tweetusername + '/status/' + tweetid + '">' + $this.relativeTime(feeds[i].created_at) + '</a>'; 71 72 displayCounter++; 73 } 74 } 75 } 76 77 $("#" + $this.options.wrapper).html(feedHTML); 78 }); 79 80 }, 81 82 addLink: function(data) { 83 84 //Add link to all http:// links within tweets 85 data = data.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function (url) { 86 return '<a href="' + url + '" >' + url + '</a>'; 87 }); 88 89 //Add link to @usernames used within tweets 90 data = data.replace(/\B@([_a-z0-9]+)/ig, function (reply) { 91 return '<a href="http://twitter.com/' + reply.substring(1) + '" style="font-weight:lighter;" >' + reply.charAt(0) + reply.substring(1) + '</a>'; 92 }); 93 94 return data; 95 96 }, 97 98 relativeTime: function(timeValue) { 99 100 var values = timeValue.split(" "); 101 timeValue = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; 102 var parsed_date = Date.parse(timeValue); 103 var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); 104 var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); 105 var shortdate = timeValue.substr(4, 2) + " " + timeValue.substr(0, 3); 106 delta = delta + (relative_to.getTimezoneOffset() * 60); 107 108 if (delta < 60) { 109 return '1m'; 110 } else if (delta < 120) { 111 return '1m'; 112 } else if (delta < (60 * 60)) { 113 return (parseInt(delta / 60)).toString() + 'm'; 114 } else if (delta < (120 * 60)) { 115 return '1h'; 116 } else if (delta < (24 * 60 * 60)) { 117 return (parseInt(delta / 3600)).toString() + 'h'; 118 } else if (delta < (48 * 60 * 60)) { 119 return shortdate; 120 } else { 121 return shortdate; 122 } 123 124 } 125 126}; 127 128// Compatibility with old function 129window.getTwitters = function(wrapper, options) { 130 options.wrapper = wrapper; 131 twitterFeed.initialize(options); 132} 133 134})(jQuery, window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.