PageSourceSearch

https://davidgreenfoodconsultancy.com/vendor/twitterjs/twitter.js

js davidgreenfoodconsultancy.com collected 2026-10-09 03:53:17 UTC 3,633 bytes, 127 lines download raw bytes

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

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.