1if (typeof Object.create !== 'function') { 2 Object.create = function(obj) { 3 function F() {} 4 F.prototype = obj; 5 return new F(); 6 }; 7} 8 9(function($, window, document, undefined) { 10 var SOCIALFEED_BROKEN_IMAGE = '//storage.googleapis.com/i.addblock.net/img_broken.png'; 11 12 $.fn.socialfeed = function(_options) { 13 14 15 var defaults = { 16 plugin_folder: '', // a folder in which the plugin is located (with a slash in the end) 17 //template: 'template.html', // a path to the template file 18 show_media: false, // show images of attachments if available 19 media_min_width: 300, 20 length: 500, // maximum length of post message shown 21 date_format: 'll', 22 element:'' 23 }; 24 //--------------------------------------------------------------------------------- 25 var options = $.extend(defaults, _options), 26 container = $(this), 27 //template, 28 social_networks = ['facebook', 'instagram', 'vk', 'google', 'blogspot', 'twitter', 'pinterest', 'rss'], 29 posts_to_load_count = 0, 30 loaded_post_count = 0; 31 // container.empty().css('display', 'block'); 32 //--------------------------------------------------------------------------------- 33 34 //--------------------------------------------------------------------------------- 35 // This function performs consequent data loading from all of the sources by calling corresponding functions 36 function calculatePostsToLoadCount() { 37 social_networks.forEach(function(network) { 38 if (options[network]) { 39 if (options[network].accounts) { 40 if(options[network].accounts[0] && options[network].accounts[0] != 'undefined') { 41 posts_to_load_count += options[network].limit; 42 } 43 // posts_to_load_count += options[network].limit * options[network].accounts.length; 44 } else if (options[network].urls ){ 45 posts_to_load_count += options[network].limit * options[network].urls.length; 46 } else { 47 posts_to_load_count += options[network].limit; 48 } 49 } 50 }); 51 } 52 53 calculatePostsToLoadCount(); 54 55 function fireCallback() { 56 var fire = true; 57 /*$.each(Object.keys(loaded), function() { 58 if (loaded[this] > 0) 59 fire = false; 60 });*/ 61 if (fire && options.callback) { 62 options.callback(); 63 } 64 } 65 66 var Utility = { 67 request: function(url, callback) { 68 $.ajax({ 69 url: url, 70 dataType: 'jsonp', 71 success: callback 72 }); 73 }, 74 get_request: function(url, callback) { 75 $.get(url, callback, 'json'); 76 }, 77 wrapLinks: function(string, social_network) { 78 var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; 79 if (social_network === 'google-plus') { 80 string = string.replace(/(@|#)([a-z0-9_]+['])/ig, Utility.wrapGoogleplusTagTemplate); 81 } else { 82 string = string.replace(exp, Utility.wrapLinkTemplate); 83 } 84 return string; 85 }, 86 wrapLinkTemplate: function(string) { 87 return '<a target="_blank" href="' + string + '">' + string + '<\/a>'; 88 }, 89 wrapGoogleplusTagTemplate: function(string) { 90 return '<a target="_blank" href="https://plus.google.com/s/' + string + '" >' + string + '<\/a>'; 91 }, 92 shorten: function(string) { 93 string = $.trim(string); 94 if (string.length > options.length) { 95 return jQuery.trim(string).substring(0, options.length).split(" ").slice(0, -1).join(" ") + "..."; 96 } else { 97 return string; 98 } 99 },
100 stripHTML: function(string) { 101 if (typeof string === "undefined" || string === null) { 102 return ''; 103 } 104 return string.replace(/(<([^>]+)>)|nbsp;|\s{2,}|/ig, ""); 105 }, 106 drawOrgContent: function() { 107 var container_selector = ($('.' + options.element + ' [data-matrix-loop="true"]').length > 0) ? `.${options.element} [data-matrix-loop="true"]` : `.${options.element} [data-loop="true"]`; 108 var $container = $(container_selector); 109 $container.removeAttr('style').addClass('listprogress-end'); 110 $container.html(options.org_content).hide().fadeIn(200); 111 }, 112 drawEmptyContent: function(msg) { 113 var $container = ($('.' + options.element + ' [data-matrix-loop="true"]').length > 0)? $('.' + options.element + ' [data-matrix-loop="true"]') : $('.' + options.element + ' [data-loop="true"]'); 114 if(msg) { 115 $container.addClass('empty-feed'); 116 $container.html('<div class="recomm-socialfeed-text">' + msg + '</div>').hide().fadeIn(200); 117 } 118 }, 119 checkEmptyData: function(social_network,error) { 120 options.check_get_data[social_network] = true; 121 122 var check = true; 123 $.each(options.check_get_data,function(k,v) { 124 if(!v) check = false; 125 }); 126 127 if(error) { 128 Utility.drawOrgContent(); 129 130 if(typeof MODE != 'undefined' && (MODE == 'config' || MODE == 'demo')) { 131 $(this).showModalFlat('INFORMATION', $.lang[LANG]['config.sns.feed-permission-error'], true, false, '', 'ok'); 132 var el_seq = ($('.' + options.element).attr('data-id')) ? $('.' + options.element).attr('data-id') : ''; 133 if(el_seq) { 134 var settings = (social_network == 'instagram') ? { instagram : '' } : { twitter : '' }; 135 $.post('/template/settings',{ sid : SID, settings : JSON.stringify(settings), el : el_seq, key: 'sns'}, function(data) { 136 checkError(data); 137 },'json'); 138 } 139 } 140 return ''; 141 } 142 143 if(check && loaded_post_count == 0 && options[social_network].accounts) { 144 Utility.drawEmptyContent($.lang[LANG]["board.no-posts"]); 145 } 146 147 } 148 }; 149 150 function SocialFeedPost(social_network, data) { 151 // console.log(social_network,data); 152 this.content = data; 153 this.content.social_network = social_network; 154 this.content.attachment = (this.content.attachment === undefined) ? '' : this.content.attachment; 155 this.content.time_ago = data.dt_create.fromNow(); 156 this.content.date = data.dt_create.format(options.date_format); 157 this.content.dt_create = this.content.dt_create.valueOf(); 158 this.content.text = Utility.wrapLinks(Utility.shorten(data.message + ' ' + data.description), data.social_network); 159 this.content.moderation_passed = (options.moderation) ? options.moderation(this.content) : true; 160 161 Feed[social_network].posts.push(this); 162 } 163 SocialFeedPost.prototype = { 164 render: function() { 165 var rendered_html = this.content; 166 var data = this.content; 167 var container_selector = ($('.' + options.element + ' [data-matrix-loop="true"]').length > 0) ? `.${options.element} [data-matrix-loop="true"]` : `.${options.element} [data-loop="true"]`; 168 var $container = $(container_selector); 169 // console.log('container_selector',container_selector, options); 170 var $node = $(options.template); 171 172 $node 173 .attr('social-feed-id',data.id) 174 .attr('dt-create',data.dt_create) 175 .addClass('social-feed-element'); 176 177 if(!data.moderation_passed) 178 $node.addClass('hide'); 179 180 if(data.social_network == 'twitter') { 181 var http_reg = /^http:\/\//; 182 var f_link = (http_reg.test(data.link)) ? data.link.replace(http_reg,'https://') : data.link; 183 var f_author_link = (http_reg.test(data.author_link)) ? data.author_link.replace(http_reg,'https://') : data.author_link; 184 var f_author_picture = (http_reg.test(data.author_picture)) ? data.author_picture.replace(http_reg,'https://') : data.author_picture; 185 186 $node.find('[data-feed-link]').attr('href', f_link); 187 $node.find('[data-feed-author-link]').attr('href', f_author_link); 188 $node.find('[data-feed-author-picture]').attr('src', f_author_picture); 189 } else if(data.social_network == 'instagram') { 190 $node.find('[data-feed-link]').attr('href', data.link); 191 $node.find('[data-feed-author-link]').attr('href', data.author_link); 192 $node.find('[data-feed-author-picture]').addClass('disabled'); 193 } else { 194 $node.find('[data-feed-link]').attr('href', data.link); 195 $node.find('[data-feed-author-link]').attr('href', data.author_link); 196 $node.find('[data-feed-author-picture]').attr('src', data.author_picture); 197 } 198 $node.find('[data-feed-author-name]').text(data.author_name); 199 $node.find('[data-feed-time-ago]').text(data.time_ago); 200 $node.find('[data-feed-text]').html(data.text); 201 $node.find('[data-feed-icon]').html("<i class='fa fa-" + data.social_network + "'></i>"); 202 203 $img = (data.attachment) ? $(data.attachment) : ""; 204 var attrSrc = ($img) ? $img.attr('src') : ""; 205 206 attrSrc = (typeof attrSrc != 'undefined' && attrSrc) ? String(attrSrc) : ''; 207 if(attrSrc == 'undefined' || attrSrc == 'null') attrSrc = ''; 208 attrSrc = (attrSrc.indexOf('http://') != -1) ? attrSrc.replace('http://','//') : attrSrc; 209 210 $node.find('[data-feed-attachment]').removeClass('hide'); 211 $node.find('.post-content').removeClass('text-only'); 212 if(attrSrc) { 213 $node.find('[data-feed-attachment]').attr('src',attr
213Src).attr('onerror', "this.onerror=null;this.src='" + SOCIALFEED_BROKEN_IMAGE + "';"); 214 var img = new Image(); 215 img.src = attrSrc; 216 img.onerror = function() { 217 $('img[src="' + $(this).attr('src') + '"]').attr('src', SOCIALFEED_BROKEN_IMAGE); 218 } 219 img.onload = function() { 220 if(this.width>this.height) { 221 $('img[src="' + $(this).attr('src') + '"]').css({ 222 'min-width' : 'initial', 223 'max-width' : 'none', 224 'min-height' : '100%', 225 'max-height' : '100%' 226 }); 227 } else if(this.width<this.height) { 228 $('img[src="' + $(this).attr('src') + '"]').css({ 229 'min-width' : '100%', 230 'max-width' : '100%', 231 'min-height' : 'initial', 232 'max-height' : 'none' 233 }); 234 } else { 235 $('img[src="' + $(this).attr('src') + '"]').css({ 236 'max-height' : '100%', 237 'max-width' : '100%' 238 }); 239 } 240 } 241 } else { 242 $node.find('[data-feed-attachment]').addClass('hide'); 243 $node.find('.post-content').addClass('text-only'); 244 } 245 rendered_html = $node.outerHTML(); 246 $('.' + options.element + ' .listprogress').remove().fadeOut(200); 247 if ($container.children('[social-feed-id=' + data.id + ']').length !== 0) { 248 return false; 249 } 250 251 if ($container.children().length === 0) { 252 $container.append(rendered_html).fadeIn(200); 253 } else { 254 var i = 0, 255 insert_index = -1; 256 $.each($container.children(), function() { 257 if ($(this).attr('dt-create') < data.dt_create) { 258 insert_index = i; 259 return false; 260 } 261 i++; 262 }); 263 264 $container.append(rendered_html).fadeIn(200); 265 if (insert_index >= 0) { 266 insert_index++; 267 var before = $container.children('div:nth-child(' + insert_index + ')'), 268 current = $container.children('div:last-child'); 269 $(current).insertBefore(before); 270 } 271 272 } 273 274 275 if (options.media_min_width) { 276 var query = '[social-feed-id=' + data.id + '] img.attachment'; 277 var image = $(query); 278 279 // preload the image 280 var height, width = ''; 281 var img = new Image(); 282 var imgSrc = image.attr("src"); 283 284 $(img).load(function() { 285 if (img.width < options.media_min_width) { 286 image.hide(); 287 } 288 // garbage collect img 289 delete img; 290 291 }).error(function() { 292 // image couldnt be loaded 293 image.hide(); 294 295 }).attr({ 296 src: imgSrc 297 }); 298 299 } 300 loaded_post_count++; 301 302 // if (loaded_post_count == posts_to_load_count) { 303 if (loaded_post_count == options.total) { 304 fireCallback(); 305 } 306 307 } 308 309 }; 310 311 var Feed = { 312 template: false, 313 init: function() { 314 $('.'+options.element).find('.recomm-socialfeed-text').remove(); 315 if($('.'+options.element).find('.social-feed-container[data-loop="true"]').length > 0) $('.'+options.element).find('.social-feed-container[data-loop="true"]').removeClass('empty-feed').removeClass('listprogress-end'); 316 if($('.'+options.element).find('.social-feed-container[data-matrix-loop="true"]').length > 0) $('.'+options.element).find('.social-feed-container[data-matrix-loop="true"]').removeClass('empty-feed').removeClass('listprogress-end'); 317 318 if(!options.check_empty) { 319 320 var tmp_social = (typeof property == 'undefined') ? SOCIAL : property.SOCIAL, 321 checkInstagramOldVer = (typeof options.instagram.accounts != 'undefined' 322 && options.instagram.accounts[0] != '' 323 && typeof tmp_social.instagram != 'undefined' && tmp_social.instagram.oldversion === true 324 && options.instagram.accounts[0] == tmp_social.instagram.id 325 ) ? true : false;
326 327 Feed.getTemplate(function() { 328 social_networks.forEach(function(network) { 329 330 if (options[network] && typeof options.check_get_data[network] != 'undefined') { 331 if ( options[network].accounts && options[network].accounts[0] != '') { 332 //loaded[network] = 0; 333 options[network].accounts.forEach(function(account) { 334 //loaded[network]++; 335 if(checkInstagramOldVer) { 336 if(typeof MODE != 'undefined' && (MODE == 'config' || MODE == 'demo')) { 337 $(this).showModalFlat('INFORMATION', $.lang[LANG]['config.sns.instargram.oldversion.API'], true, false, '', 'ok'); 338 Utility.drawEmptyContent($.lang[LANG]["config.sns.instargram.oldversion.API"]); 339 } else { 340 Utility.checkEmptyData(network); 341 } 342 } else if (account.length > 0) { 343 Feed[network].getData(account); 344 } else { 345 Utility.checkEmptyData(network); 346 } 347 }); 348 } else if ( options[network].urls ) { 349 options[network].urls.forEach(function(url) { 350 Feed[network].getData(url); 351 }); 352 } 353 } 354 }); 355 }); 356 } else { 357 Utility.drawOrgContent(); 358 fireCallback(); 359 } 360 361 }, 362 getTemplate: function(callback) { 363 if (Feed.template) 364 return callback(); 365 else { 366 Feed.template = ''; 367 return callback(); 368 } 369 }, 370 twitter: { 371 posts: [], 372 loaded: false, 373 api: '/socialfeed/twitter', 374 375 getData: function(account) { 376 // var cb = new Codebird(); 377 // cb.setConsumerKey(options.twitter.consumer_key, options.twitter.consumer_secret); 378 379 // // Allow setting your own proxy with Codebird 380 // if (options.twitter.proxy !== undefined) { 381 // cb.setProxy(options.twitter.proxy); 382 // } 383 384 switch (account[0]) { 385 case '@': 386 var userid = account.substr(1); 387 Utility.get_request(Feed.twitter.api + '/timeline/' + userid + '/' + options.twitter.limit, Feed.twitter.utility.getPosts); 388 // cb.__call( 389 // "statuses_userTimeline", 390 // "id=" + userid + "&count=" + options.twitter.limit, 391 // Feed.twitter.utility.getPosts, 392 // true // this parameter required 393 // ); 394 break; 395 case '#': 396 var hashtag = account.substr(1); 397 Utility.get_request(Feed.twitter.api + '/search/' + hashtag + '/' + options.twitter.limit, Feed.twitter.utility.getPosts); 398 // cb.__call( 399 // "search_tweets", 400 // "q=" + hashtag + "&count=" + options.twitter.limit, 401 // function(reply) { 402 // Feed.twitter.utility.getPosts(reply.statuses); 403 // }, 404 // true // this parameter required 405 // ); 406 break; 407 default: 408 } 409 }, 410 utility: { 411 getPosts: function(json) { 412 // console.log(json); 413 if (json.length > 0) { 414 options.total += json.length; 415 $.each(json, function() { 416 var element = this; 417 var post = new SocialFeedPost('twitter', Feed.twitter.utility.unifyPostData(element)); 418 post.render(); 419 }); 420 } else { 421 Utility.checkEmptyData('twitter'); //empty data, 422 } 423 }, 424 unifyPostData: function(element) { 425 var post = {};
426 if (element.id) { 427 post.id = element.id; 428 //prevent a moment.js console warning due to Twitter's poor date format. 429 post.dt_create = moment(new Date(element.created_at)); 430 post.author_link = 'http://twitter.com/' + element.user.screen_name; 431 post.author_picture = element.user.profile_image_url; 432 post.post_url = post.author_link + '/status/' + element.id_str; 433 post.author_name = element.user.name; 434 post.message = element.text; 435 post.description = ''; 436 post.link = 'http://twitter.com/' + element.user.screen_name + '/status/' + element.id_str; 437 438 if (options.show_media === true) { 439 if (element.entities.media && element.entities.media.length > 0) { 440 var image_url = element.entities.media[0].media_url; 441 if (image_url) { 442 post.attachment = '<img class="attachment" src="' + image_url + '" />'; 443 } 444 } 445 } 446 } 447 return post; 448 } 449 } 450 }, 451 facebook: { 452 posts: [], 453 graph: 'https://graph.facebook.com/', 454 loaded: false, 455 getData: function(account) { 456 457 var proceed = function(request_url){ 458 Utility.request(request_url, Feed.facebook.utility.getPosts); 459 }; 460 var fields = '?fields=id,from,name,message,created_time,story,description,link'; 461 fields += (options.show_media === true)?',picture,object_id':''; 462 var request_url, limit = '&limit=' + options.facebook.limit,
463 query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 464 switch (account[0]) { 465 case '@': 466 var username = account.substr(1); 467 Feed.facebook.utility.getUserId(username, function(userdata) { 468 if (userdata.id !== '') { 469 request_url = Feed.facebook.graph + 'v2.4/' + userdata.id + '/posts'+ fields + limit + query_extention; 470 proceed(request_url); 471 } 472 }); 473 break; 474 case '!': 475 var page = account.substr(1); 476 request_url = Feed.facebook.graph + 'v2.4/' + page + '/feed'+ fields + limit + query_extention; 477 proceed(request_url); 478 break; 479 default: 480 proceed(request_url); 481 } 482 }, 483 utility: { 484 getUserId: function(username, callback) {
485 var query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 486 var url = 'https://graph.facebook.com/' + username + '?' + query_extention; 487 488 var result = ''; 489 $.get(url, callback, 'json'); 490 }, 491 prepareAttachment: function(element) { 492 var image_url = element.picture; 493 if (image_url.indexOf('_b.') !== -1) { 494 //do nothing it is already big 495 } else if (image_url.indexOf('safe_image.php') !== -1) { 496 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'url'); 497 498 } else if (image_url.indexOf('app_full_proxy.php') !== -1) { 499 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'src'); 500 501 } else if (element.object_id) { 502 image_url = Feed.facebook.graph + element.id + '/picture/?type=normal'; 503 } 504 return '<img class="attachment" src="' + image_url + '" />'; 505 }, 506 getExternalImageURL: function(image_url, parameter) { 507 image_url = decodeURIComponent(image_url).split(parameter + '=')[1]; 508 if (image_url.indexOf('fbcdn-sphotos') === -1) { 509 return image_url.split('&')[0]; 510 } else { 511 return image_url; 512 } 513 514 }, 515 getPosts: function(json) { 516 if (json['data']) { 517 json['data'].forEach(function(element) { 518 var post = new SocialFeedPost('facebook', Feed.facebook.utility.unifyPostData(element)); 519 post.render(); 520 }); 521 } 522 }, 523 unifyPostData: function(element) { 524 var post = {}, 525 text = (element.message) ? element.message : element.story; 526 527 post.id = element.id; 528 post.dt_create = moment(element.created_time); 529 post.author_link = 'http://facebook.com/' + element.from.id; 530 post.author_picture = Feed.facebook.graph + element.from.id + '/picture'; 531 post.author_name = element.from.name; 532 post.name = element.name || ""; 533 post.message = (text) ? text : ''; 534 post.description = (element.description) ? element.description : ''; 535 post.link = (element.link) ? element.link : 'http://facebook.com/' + element.from.id; 536 537 if (options.show_media === true) { 538 if (element.picture) { 539 var attachment = Feed.facebook.utility.prepareAttachment(element); 540 if (attachment) { 541 post.attachment = attachment; 542 } 543 } 544 } 545 return post; 546 } 547 } 548 }, 549 google: { 550 posts: [], 551 loaded: false, 552 api: 'https://www.googleapis.com/plus/v1/', 553 getData: function(account) { 554 var request_url; 555 switch (account[0]) { 556 case '#': 557 var hashtag = account.substr(1); 558 request_url = Feed.google.api + 'activities?query=' + hashtag + '&key=' + options.google.access_token + '&maxResults=' + options.google.limit; 559 Utility.get_request(request_url, Feed.google.utility.getPosts); 560 break; 561 case '@': 562 var username = account.substr(1); 563 request_url = Feed.google.api + 'people/' + username + '/activities/public?key=' + options.google.access_token + '&maxResults=' + options.google.limit; 564 Utility.get_request(request_url, Feed.google.utility.getPosts); 565 break; 566 default: 567 } 568 }, 569 utility: { 570 getPosts: function(json) { 571 if (json.items) { 572 $.each(json.items, function(i) { 573 var post = new SocialFeedPost('google', Feed.google.utility.unifyPostData(json.items[i])); 574 post.render(); 575 }); 576 } 577 }, 578 unifyPostData: function(element) { 579 var post = {}; 580
581 post.id = element.id; 582 post.attachment = ''; 583 post.description = ''; 584 post.dt_create = moment(element.published); 585 post.author_link = element.actor.url; 586 post.author_picture = element.actor.image.url; 587 post.author_name = element.actor.displayName; 588 589 if (options.show_media === true) { 590 if (element.object.attachments) { 591 $.each(element.object.attachments, function() { 592 var image = ''; 593 if (this.fullImage) { 594 image = this.fullImage.url; 595 } else { 596 if (this.objectType === 'album') { 597 if (this.thumbnails && this.thumbnails.length > 0) { 598 if (this.thumbnails[0].image) { 599 image = this.thumbnails[0].image.url; 600 } 601 } 602 } 603 } 604 post.attachment = '<img class="attachment" src="' + image
604+ '"/>'; 605 }); 606 } 607 } 608 post.message = element.title; 609 post.link = element.url; 610 611 return post; 612 } 613 } 614 }, 615 instagram: { 616 posts: [], 617 api: 'https://graph.instagram.com/v21.0/', 618 loaded: false, 619 getData: function(account) { 620 var url; 621 if(typeof account != 'undefined' && account && typeof options.instagram.access_token != 'undefined') { 622 var instagram_fields = 'id,media_type,media_url,permalink,thumbnail_url,caption,timestamp,username,children{id,media_type,media_url,thumbnail_url,permalink}'; 623 var instagram_limit = (typeof options.instagram.limit != 'undefined') ? options.instagram.limit : 5; 624 url = Feed.instagram.api + account + '/media?fields=' + encodeURIComponent(instagram_fields) + '&limit=' + instagram_limit + '&access_token='
624+ options.instagram.access_token; 625 Utility.request(url, Feed.instagram.utility.getImages); 626 } 627 }, 628 utility: { 629 getImages: function(json) { 630 if (typeof json.data != 'undefined' && json.data.length > 0) { 631 options.total += json.data.length; 632 json.data.forEach(function(element) { 633 var post = new SocialFeedPost('instagram', Feed.instagram.utility.unifyPostData(element)); 634 post.render(); 635 }); 636 } else { 637 var error = ''; 638 if(typeof json.error != 'undefined' && json.error) { 639 error = 'error message: ' + json.error.message + ', ' + json.error.type + ', ' + json.error.code; 640 } 641 Utility.checkEmptyData('instagram',error); //empty data, 642 } 643 }, 644 getMediaUrl: function(element) { 645 if(element.media_type == 'VIDEO' && typeof element.thumbnail_url != 'undefined' && element.thumbnail_url) return element.thumbnail_url; 646 if(typeof element.media_url != 'undefined' && element.media_url) return element.media_url; 647 648 if(element.media_type == 'CAROUSEL_ALBUM' 649 && typeof element.children != 'undefined' 650 && typeof element.children.data != 'undefined' 651 && element.children.data.length > 0 652 ) { 653 for(var i = 0; i < element.children.data.length; i++) { 654 var child = element.children.data[i]; 655 if(child.media_type == 'VIDEO' && typeof child.thumbnail_url != 'undefined' && child.thumbnail_url) return child.thumbnail_url; 656 if(typeof child.media_url != 'undefined' && child.media_url) return child.media_url; 657 } 658 } 659 660 return (typeof element.thumbnail_url != 'undefined' && element.thumbnail_url) ? element.thumbnail_url : SOCIALFEED_BROKEN_IMAGE; 661 }, 662 unifyPostData: function(element) { 663 var post = {}; 664 post.id = element.id; 665 post.dt_create = moment(new Date(element.timestamp)); 666 post.author_link = '//instagram.com/' + element.username; 667 post.author_name = element.username; 668 post.message = (typeof element.caption != 'undefined' && element.caption) ? element.caption : ''; 669 post.description = ''; 670 post.link = element.permalink; 671 if (options.show_media) { 672 var img_url = Feed.instagram.utility.getMediaUrl(element); 673 post.attachment = '<img class="attachment" src="' + img_url + '' + '" />'; 674 } 675 return post; 676 } 677 } 678 }, 679 vk: { 680 posts: [], 681 loaded: false, 682 base: 'http://vk.com/', 683 api: 'https://api.vk.com/method/', 684 user_json_template: 'https://api.vk.com/method/' + 'users.get?fields=first_name,%20last_name,%20screen_name,%20photo&uid=', 685 group_json_template: 'https://api.vk.com/method/' + 'groups.getById?fields=first_name,%20last_name,%20screen_name,%20photo&gid=', 686 getData: function(account) { 687 var request_url; 688 689 switch (account[0]) { 690 case '@': 691 var username = account.substr(1); 692 request_url = Feed.vk.api + 'wall.get?owner_id=' + username + '&filter=' + options.vk.source + '&count=' + options.vk.limit + '&callback=?'; 693 Utility.get_request(request_url, Feed.vk.utility.getPosts); 694 break; 695 case '#': 696 var hashtag = account.substr(1); 697 request_url = Feed.vk.api + 'newsfeed.search?q=' + hashtag + '&count=' + options.vk.limit + '&callback=?'; 698 Utility.get_request(request_url, Feed.vk.utility.getPosts); 699 break; 700 default: 701 } 702 }, 703 utility: { 704 getPosts: function(json) { 705 if (json.response) { 706 $.each(json.response, function() { 707 if (this != parseInt(this) && this.post_type === 'post') { 708 var owner_id = (this.owner_id) ? this.owner_id : this.from_id, 709 vk_wall_owner_url = (owner_id > 0) ? (Feed.vk.user_json_template + owner_id + '&callback=?') : (Feed.vk.group_json_template + (-1) * owner_id + '&callback=?'), 710 element = this; 711 Utility.get_request(vk_wall_owner_url, function(wall_owner) { 712 Feed.vk.utility.unifyPostData(wall_owner, element, json); 713 }); 714 } 715 }); 716 } 717 }, 718 unifyPostData: function(wall_owner, element, json) { 719 var post = {}; 720
721 post.id = element.id; 722 post.dt_create = moment.unix(element.date); 723 post.description = ' '; 724 post.message = Utility.stripHTML(element.text); 725 if (options.show_media) { 726 if (element.attachment) { 727 if (element.attachment.type === 'link') 728 post.attachment = '<img class="attachment" src="' + element.attachment.link.image_src + '" />'; 729 if (element.attachment.type === 'video') 730 post.attachment = '<img class="attachment" src="' + element.attachment.video.image_big + '" />'; 731 if (element.attachment.type === 'photo') 732 post.attachment = '<img class="attachment" src="' + element.attachment.photo.src_big + '" />'; 733 } 734 } 735 736 if (element.from_id > 0) { 737 var vk_user_json = Feed.vk.user_json_template + element.from_id + '&callback=?'; 738 Utility.get_request(vk_user_json, function(user_json) { 739 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getUser(user_json, post, element, json)); 740 vk_post.render(); 741 }); 742 743 } else { 744 var vk_group_json = Feed.vk.group_json_template + (-1) * element.from_id + '&callback=?'; 745 Utility.get_request(vk_group_json, function(user_json) { 746 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getGroup(user_json, post, element, json)); 747 vk_post.render(); 748 }); 749 } 750 }, 751 getUser: function(user_json, post, element, json) { 752 post.author_name = user_json.response[0].first_name + ' ' + user_json.response[0].last_name; 753 post.author_picture = user_json.response[0].photo; 754 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 755 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall' + element.from_id + '_' + element.id; 756 757 return post; 758 }, 759 getGroup: function(user_json, post, element, json) { 760 post.author_name = user_json.response[0].name; 761 post.author_picture = user_json.response[0].photo; 762 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 763 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall-' + user_json.response[0].gid + '_' + element.id; 764 765 return post; 766 } 767 } 768 }, 769 blogspot: { 770 loaded: false, 771 getData: function(account) { 772 var url; 773 774 switch (account[0]) { 775 case '@': 776 var username = account.substr(1); 777 url = 'http://' + username + '.blogspot.com/feeds/posts/default?alt=json-in-script&callback=?'; 778 request(url, getPosts); 779 break; 780 default: 781 } 782 }, 783 utility: { 784 getPosts: function(json) { 785 $.each(json.feed.entry, function() { 786 var post = {}, 787 element = this; 788 post.id = element.id['$t'].replace(/[^a-z0-9]/gi, ''); 789 post.dt_create = moment((element.published['$t'])); 790 post.author_link = element.author[0]['uri']['$t']; 791 post.author_picture = 'http:' + element.author[0]['gd$image']['src']; 792 post.author_name = element.author[0]['name']['$t']; 793 post.message = element.title['$t'] + '</br></br>' + stripHTML(element.content['$t']); 794 post.description = ''; 795 post.link = element.link.pop().href; 796 797 if (options.show_media) { 798 if (element['media$thumbnail']) { 799 post.attachment = '<img class="attachment" src="' + element['media$thumbnail']['url'] + '" />'; 800 } 801 } 802 803 post.render(); 804 805 }); 806 } 807 } 808 }, 809 pinterest: { 810 posts: [], 811 loaded: false, 812 apiv1: 'https://api.pinterest.com/v1/', 813 814 getData: function(account) { 815 var request_url, 816 limit = 'limit=' + options.pinterest.limit, 817 fields = 'fields=id,created_at,link,note,creator(url,first_name,last_name,image),image', 818 query_extention = fields + '&access_token='
818+ options.pinterest.access_token + '&' + limit + '&callback=?'; 819 switch (account[0]) { 820 case '@': 821 var username = account.substr(1); 822 if (username === 'me') { 823 request_url = Feed.pinterest.apiv1 + 'me/pins/?' + query_extention; 824 } else { 825 request_url = Feed.pinterest.apiv1 + 'boards/' + username + '/pins?' + query_extention; 826 } 827 break; 828 default: 829 } 830 Utility.request(request_url, Feed.pinterest.utility.getPosts); 831 }, 832 utility: { 833 834 getPosts: function(json) { 835 json.data.forEach(function(element) { 836 var post = new SocialFeedPost('pinterest', Feed.pinterest.utility.unifyPostData(element)); 837 post.render(); 838 }); 839 }, 840 841 unifyPostData: function(element){ 842 var post = {}; 843 844 post.id = element.id; 845 post.dt_create= moment(element.created_at); 846 post.author_link = element.creator.url; 847 post.author_picture = element.creator.image['60x60' ].url; 848 post.author_name = element.creator.first_name + element.creator.last_name; 849 post.message = element.note; 850 post.description = ''; 851 post.social_network = 'pinterest'; 852 post.link = element.link ? element.link : 'https://www.pinterest.com/pin/' + element.id; 853 if (options.show_media) { 854 post.attachment = '<img class="attachment" src="' + element.image['original'].url + '" />'; 855 } 856 return post; 857 } 858 } 859 }, 860 rss : { 861 posts: [], 862 loaded: false, 863 api : 'https://query.yahooapis.com/v1/public/yql?q=', 864 datatype: 'json', 865 866 getData: function(url) { 867 var limit = options.rss.limit, 868 yql = encodeURIComponent('select entry FROM feednormalizer where url=\'' + url + '\' AND output=\'atom_1.0\' | truncate(count=' + limit + ')' ), 869 request_url = Feed.rss.api + yql + '&format=json&callback=?'; 870 871 Utility.request(request_url, Feed.rss.utility.getPosts, Feed.rss.datatype); 872 }, 873 utility: { 874 875 getPosts: function(json) { 876 if (json.query.count > 0 ){ 877 $.each(json.query.results.feed, function(index, element) { 878 var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element)); 879 post.render(); 880 }); 881 } 882 }, 883 884 unifyPostData: function(index, element){ 885 886 var item = element; 887 888 if ( element.entry !== undefined ){ 889 item = element.entry; 890 } 891 var post = {}; 892 893 post.id = '"' + item.id + '"'; 894 post.dt_create= moment(item.published, 'YYYY-MM-DDTHH:mm:ssZ', 'en'); 895 896 post.author_link = ''; 897 post.author_picture = ''; 898 post.author_name = ''; 899 if( item.creator !== undefined ){ 900 post.author_name = item.creator; 901 } 902 post.message = item.title; 903 post.description = ''; 904 if( item.summary !== undefined ){ 905 post.description = Utility.stripHTML(item.summary.content); 906 } 907 post.social_network = 'rss'; 908 post.link = item.link.href; 909 if (options.show_media && item.thumbnail !== undefined ) { 910 post.attachment = '<img class="attachment" src="' + item.thumbnail.url + '" />'; 911 } 912 return post; 913 } 914 } 915 } 916 }; 917 918 //make the plugin chainable 919 return this.each(function() { 920 // Initialization 921 Feed.init(); 922 if (options.update_period) { 923 setInterval(function() { 924 return Feed.init(); 925 }, options.update_period); 926 } 927 }) 928 }; 929 930})(jQuery); 931 932var updateFeed = function(el,snsObject,settings,callback) { 933 if(typeof el == 'undefined') { 934 alert('ë¸ëì ë³´ê° ììµëë¤.'); 935 return false;
936 } 937 938 let $matrixLoop = $('.' + el + ' [data-matrix-loop="true"]'); 939 var org_content = ($matrixLoop.length > 0)? $matrixLoop.children().outerHTML() : $('.' + el + ' [data-loop="true"]').children().outerHTML(), 940 render = ($matrixLoop.length > 0)? $matrixLoop.children().first().outerHTML() : $('.' + el + ' [data-loop="true"]').children().first().outerHTML(); 941 942 let elsettings = (typeof settings != 'undefined' && settings)? settings : ''; 943 944 var check_empty = true, 945 check_empty_sns = { 'twitter':true, 'instagram':true } 946 sns_data = {}; 947 948 $.each(snsObject, function(network, val) { 949 switch(typeof val) { 950 case 'string': 951 if(val != '') var new_value = String(val).split(','); 952 break; 953 954 case 'object': 955 if(!$.isEmptyObject(val)) var new_value = val; 956 break; 957 958 default: 959 break; 960 } 961 962 963 if(typeof new_value != 'undefined') { 964 sns_data[network] = new_value; 965 check_empty_sns[network] = false; 966 if(check_empty) check_empty = false; 967 } else { 968 sns_data[network] = ['']; 969 } 970 971 }); 972 973 var is_publish = (typeof MODE != 'undefined' && (MODE == 'config' || MODE == 'demo')) ? false : true, 974 el_seq = $('.' + el).attr('data-id'), 975 el_sid = (!is_publish) ? SID : property.SID, 976 postLength = $('.' + el).attr('data-feed-post-length'), 977 limit_twitter = $('.' + el).attr('data-feed-limit-twitter'), 978 limit_facebook = $('.' + el).attr('data-feed-limit-facebook'), 979 limit_instagram = $('.' + el).attr('data-feed-limit-instagram'); 980 981 var isGetData = false; 982 if (typeof MODE != 'undefined' && (MODE == 'config' || MODE == 'demo')) { 983 $.post('/template/element/type/get/seq/' + el_seq , { sid : el_sid }, function (data) { 984 checkError(data); 985 $.each(data, function(idx, val) { 986 $el_org = $(htmlspecialchars_decode(val.eltag)); 987 }); 988 isGetData = true; 989 },'json'); 990 } else { 991 992 if(typeof property.CONTENTS['el'+el_seq] != 'undefined' && typeof property.CONTENTS['el'+el_seq].element != 'undefined') { 993 $el_org = $(htmlspecialchars_decode(property.CONTENTS['el'+el_seq].element.eltag)); 994 isGetData = true; 995 } else { 996 var getContent = $.ajax({ url : '/template/element/type/get/seq/' + el_seq, data: { use : 'sns', publish:is_publish}, dataType: 'json', type: 'POST', async: false, cache: false }); 997 getContent.then(function(data) { 998 checkError(data); 999 var d = data[0]; 1000 $el_org = $(htmlspecialchars_decode(d.eltag)); 1001 isGetData = true; 1002 }); 1003 } 1004 1005 } 1006 1007 $('.' + el + ' .social-feed-container').html(''); 1008 if(isGetData) { 1009 1010 if(typeof $el_org != 'undefined' && $el_org){ 1011 org_content = ($el_org.find('[data-matrix-loop="true"]').length > 0)? $el_org.find('[data-matrix-loop="true"]').children().outerHTML() : $el_org.find('[data-loop="true"]').children().outerHTML(); 1012 render = ($el_org.find('[data-matrix-loop="true"]').length > 0)? $el_org.find('[data-matrix-loop="true"]').children().first().outerHTML() : $el_org.find('[data-loop="true"]').children().first().outerHTML(); 1013 } 1014 1015 postLength = (typeof postLength == 'undefined') ? 100 : Number(postLength); 1016 limit_twitter = (typeof limit_twitter == 'undefined') ? 5 : Number(limit_twitter); 1017 limit_facebook = (typeof limit_facebook == 'undefined') ? 5 : Number(limit_facebook); 1018 limit_instagram = (typeof limit_instagram == 'undefined') ? 5 : Number(limit_instagram); 1019 1020 $('.' + el + ' .social-feed-container').socialfeed({ 1021 twitter: { 1022 accounts: sns_data.twitter, 1023 limit: limit_twitter, 1024 consumer_key: 'QADNXUZUxht1MHSRU6tX7DkNk', // make sure to have your app read-only 1025 consumer_secret: 'fN6g65F8yAdXel7ttzMDntfSXWAVJHQlivkMhGWZ0599iiSPjQ', // make sure to have your app read-only 1026 }, 1027 facebook: { 1028 accounts: sns_data.facebook, 1029 limit: limit_facebook, 1030 access_token: '110859402598144|9eab5eed1805d2c74d696ef151c32ea5' 1031 }, 1032 instagram: { 1033 accounts: ( typeof sns_data.instagram == 'object' && 1034 typeof sns_data.instagram.id != 'undefined' && 1035 sns_data.instagram.id 1036 ) ? String(sns_data.instagram.id).split(' ') : sns_data.instagram, 1037 limit: limit_instagram, 1038 access_token: ( typeof sns_data.instagram == 'object' && 1039 typeof sns_data.instagram.token != 'undefined' && 1040 sns_data.instagram.token 1041 ) ? sns_data.instagram.token : '3150770084.2bca826.5e2ded8c9d40478d8f35dc584045f11c', 1042 //3150770084.2bca826.5e2ded8c9d40478d8f35dc584045f11c <= before version code 1043 }, 1044 // GENERAL SETTINGS 1045 length: postLength, 1046 show_media: true, 1047 template: render, 1048 org_content: org_content, 1049 element: el, 1050 check_empty: check_empty, 1051 check_get_data: { 'twitter': check_empty_sns.twitter, 'instagram': check_empty_sns.instagram }, 1052 total: 0, 1053 moderation: function(content) { 1054 return (content.text) ? content.text.indexOf('fuck') == -1 : true; 1055 }, 1056 callback: function() { 1057 var post_count = $('.'+el+' .social-feed-container').children().length; 1058 var feed_view = (typeof $('.'+el).attr('data-feed-view') != 'undefined') ? Number($('.'+el).attr('data-feed-view')) : 0; 1059 1060 if($('.'+el).find('[data-matrix-loop="true"]').length > 0) { 1061 feed_view = $('.'+el+' .social-feed-element:visible').length; 1062 1063 $('.'+el+' .data-feed-load-more').fadeIn(200); 1064 if(feed_view > 0 && feed_view >= this.total) $('.'+el+' .data-feed-load-more').fadeOut(200); 1065 1066 if(typeof elsettings.list_type != 'undefined' && elsettings.list_type == 's') { 1067 let mode = ($('#el-blockConfig.open').length > 0)? 'c' : 'r'; 1068 $.contentsSlider.ready(el_seq).then(() => {$.contentsSlider.init(el_seq, elsettings, mode)}); 1069 } 1070 1071 if($('#el-blockConfig.open').length > 0) { 1072 setTimeout(function(){ 1073 console.log('blockConfigModal'); 1074 $.blockConfigModal(); 1075 }, 200); 1076 } 1077 } else { 1078 $('.'+el+' .data-feed-load-more').fadeIn(200); 1079 if(feed_view>0 && feed_view>=this.total) $('.'+el+' .data-feed-load-more').fadeOut(200); 1080 } 1081 } 1082 }); 1083 } 1084 1085 if(typeof callback == 'function') callback(); 1086 1087};
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.