-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsocialstream.jquery.js
334 lines (284 loc) · 16.3 KB
/
socialstream.jquery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
* Widgets for Social Network photo stream.
*
* Author: Pixel Industry
* Website: http://pixel-industry.com
* Version: 1.4
*
*/
(function ($) {
$.fn.socialstream = function (options) {
var defaults = {
socialnetwork: 'flickr',
username: 'pixel-industry',
limit: 6,
overlay: true,
apikey: false,
accessToken: '',
picasaAlbumId: ''
};
var options = $.extend(defaults, options);
return this.each(function () {
var object = $(this);
switch (options.socialnetwork) {
case 'flickr':
object.append("<ul class=\"flickr-list\"></ul>")
$.getJSON("https://api.flickr.com/services/rest/?method=flickr.people.findByUsername&username=" + options.username + "&format=json&api_key=32ff8e5ef78ef2f44e6a1be3dbcf0617&jsoncallback=?", function (data) {
var user_id = data.user.nsid;
$.getJSON("https://api.flickr.com/services/rest/?method=flickr.photos.search&user_id=" + user_id + "&format=json&api_key=85145f20ba1864d8ff559a3971a0a033&per_page=" + options.limit + "&page=1&extras=url_sq&jsoncallback=?", function (data) {
$.each(data.photos.photo, function (num, photo) {
var photo_author = photo.owner;
var photo_title = photo.title;
var photo_src = photo.url_sq;
var photo_id = photo.id;
var photo_url = "https://www.flickr.com/photos/" + photo_author + "/" + photo_id;
var photo_container = $('<img/>').attr({
src: photo_src,
alt: photo_title
});
var url_container = $('<a/>').attr({
href: photo_url,
target: '_blank',
title: photo_title
});
var tmp = $(url_container).append(photo_container);
if (options.overlay) {
var overlay_div = $('<div/>').addClass('img-overlay');
$(url_container).append(overlay_div);
}
var li = $('<li/>').append(tmp);
$("ul", object).append(li);
})
});
});
break;
case 'pinterest':
var url = 'http://pinterest.com/' + options.username + '/feed.rss'
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(url) + "&num=" + options.limit + "&output=json_xml";
// Send request
$.getJSON(api, function (data) {
if (data.responseStatus == 200) {
var photofeed = data.responseData.feed;
var overlay_div = "";
if (!photofeed) {
return false;
}
var html_code = '<ul class=\"pinterest-list\">';
for (var i = 0; i < photofeed.entries.length; i++) {
var entry = photofeed.entries[i];
var $container = $("<div></div>");
$container.append(entry.content);
var url = "http://www.pinterest.com" + $container.find('a').attr('href');
var photo_url = $container.find('img').attr('src');
var photo_title = $container.find('p:nth-child(2)').html();
if (options.overlay) {
var overlay_div = '<div class="img-overlay"></div>';
}
html_code += '<li><a target="_blank" href="' + url + '" title="' + photo_title + '"><img src="' + photo_url + '"/>' + overlay_div + '</a></li>'
}
html_code += '</ul>';
$(object).append(html_code);
}
});
break;
case 'instagram':
object.append("<ul class=\"instagram-list\"></ul>")
// check if access token is set
if ((typeof (options.accessToken) != "undefined") && options.accessToken != "") {
var access_token = options.accessToken;
} else {
console.warn("Instagram Access Token is not set. Please enter it in plugin init call.");
return;
}
url = "https://api.instagram.com/v1/users/search?q=" + options.username + "&access_token=" + access_token + "&count=1&callback=?";
$.getJSON(url, function (data) {
$.each(data.data, function (i, shot) {
var instagram_username = shot.username;
if (instagram_username == options.username) {
var user_id = shot.id;
if (user_id != "") {
url = "https://api.instagram.com/v1/users/" + user_id + "/media/recent/?access_token=" + access_token + "&count=" + options.limit + "&callback=?";
$.getJSON(url, function (data) {
$.each(data.data, function (i, shot) {
var photo_src = shot.images.thumbnail.url;
var photo_url = shot.link;
var photo_title = "";
if (shot.caption != null) {
photo_title = shot.caption.text;
}
var photo_container = $('<img/>').attr({
src: photo_src,
alt: photo_title
});
var url_container = $('<a/>').attr({
href: photo_url,
target: '_blank',
title: photo_title
});
var tmp = $(url_container).append(photo_container);
if (options.overlay) {
var overlay_div = $('<div/>').addClass('img-overlay');
$(url_container).append(overlay_div);
}
var li = $('<li/>').append(tmp);
$("ul", object).append(li);
});
});
}
}
});
});
break;
case 'dribbble':
object.append("<ul class=\"dribbble-list\"></ul>")
// check if access token is set
if ((typeof (options.accessToken) != "undefined") && options.accessToken != "") {
var access_token = options.accessToken;
} else {
console.warn("Dribbble Access Token is not set. Please enter it in plugin init call.");
return;
}
$.getJSON("https://api.dribbble.com/v1/users/" + options.username + "/shots?access_token=" + access_token + "&callback=?", function (data) {
$.each(data.data, function (num, shot) {
if (num < options.limit) {
var photo_title = shot.title;
var photo_container = $('<img/>').attr({
src: shot.images.teaser,
alt: photo_title
});
var url_container = $('<a/>').attr({
href: shot.html_url,
target: '_blank',
title: photo_title
});
var tmp = $(url_container).append(photo_container);
if (options.overlay) {
var overlay_div = $('<div/>').addClass('img-overlay');
$(url_container).append(overlay_div);
}
var li = $('<li/>').append(tmp);
$("ul", object).append(li);
}
});
});
break;
case 'deviantart':
var url = 'http://backend.deviantart.com/rss.xml?type=deviation&q=by%3A' + options.username + '+sort%3Atime+meta%3Aall';
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(url) + "&num=" + options.limit + "&output=json_xml";
$.getJSON(api, function (data) {
if (data.responseStatus == 200) {
var photofeed = data.responseData.feed;
var overlay_div = "";
if (!photofeed) {
return false;
}
var html_code = '<ul class=\"deviantart-list\">';
for (var i = 0; i < photofeed.entries.length; i++) {
var entry = photofeed.entries[i];
var $container = $("<div></div>");
$container.append(entry.content);
var url = entry.link;
var photo_url = $container.find('img').attr('src');
// ignore smiley images
if (photo_url.indexOf("smile.gif") >= 0) {
continue;
}
var photo_title = entry.title.replace(/.jpg/g, "").replace(/-/g, " ").replace(/_/g, " ");
if (options.overlay) {
var overlay_div = '<div class="img-overlay"></div>';
}
html_code += '<li><a target="_blank" href="' + url + '" title="' + photo_title + '"><img src="' + photo_url + '"/>' + overlay_div + '</a></li>'
}
html_code += '</ul>';
$(object).append(html_code);
}
});
break;
case 'youtube':
var pid;
if (options.apikey) {
// Get Uploads Playlist
$.get(
"https://www.googleapis.com/youtube/v3/channels", {
part: 'contentDetails',
id: options.username,
key: options.apikey
},
function (data) {
$.each(data.items, function (i, item) {
//playlist id
pid = item.contentDetails.relatedPlaylists.uploads;
youtubeGetVids(pid);
});
}
);
}
//Get Videos
function youtubeGetVids(pid) {
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems", {
part: 'snippet',
maxResults: options.limit,
playlistId: pid,
key: options.apikey
},
function (data) {
var results;
var html_code = '<ul class=\"youtube-list\">';
// loop through videos
$.each(data.items, function (i, item) {
var photofeed = item.snippet.thumbnails.default.url;
var overlay_div = "";
if (!photofeed) {
return false;
}
// create container
var $container = $("<div></div>");
// get image url
var url = 'https://www.youtube.com/watch?v=' + item.snippet.resourceId.videoId;
// video title
var photo_title = item.snippet.title;
if (options.overlay) {
var overlay_div = '<div class="img-overlay"></div>';
}
// create html
html_code += '<li><a target="_blank" href="' + url + '" title="' + photo_title + '"><img src="' + photofeed + '"/>' + overlay_div + '</a></li>'
});
html_code += '</ul>';
// append html
$(object).append(html_code);
}
);
}
break;
case 'newsfeed':
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(options.username) + "&num=" + options.limit + "&output=json_xml";
$.getJSON(api, function (data) {
if (data.responseStatus == 200) {
var photofeed = data.responseData.feed;
var overlay_div = "";
if (!photofeed) {
return false;
}
var html_code = '<ul class=\"social-feed\">';
for (var i = 0; i < photofeed.entries.length; i++) {
var entry = photofeed.entries[i];
var $container = $("<div></div>");
$container.append(entry.content);
var url = entry.link;
var photo_url = $container.find('img').attr('src');
var photo_title = entry.title.replace(/.jpg/g, "").replace(/-/g, " ").replace(/_/g, " ");
if (options.overlay) {
var overlay_div = '<div class="img-overlay"></div>';
}
html_code += '<li><a target="_blank" href="' + url + '" title="' + photo_title + '"><img src="' + photo_url + '"/>' + overlay_div + '</a></li>'
}
html_code += '</ul>';
$(object).append(html_code);
}
});
break;
}
});
};
})(jQuery);