var ERRO_1='O arquivo selecionado não é válido. Ele deve ser em jpg, gif ou png.'; var ERRO_2='Por favor, selecione uma imagem. Sua imagem deve ser em jpg, png ou gif.'; var ERRO_3='URL inválida. A url deve apotar para um arquivo jpg, png ou gif.'; var ERRO_4='Por favor, insira uma url para uma foto, ou envie um arquivo de seu computador.'; var FOTO_1='Foto 1 - '; var FOTO_2='Foto 2 - '; var UPLOAD_BUTTON='Carregar'; var usar_foto_camera='Usar esta Foto'; var tirar_outra_foto='Tirar outra Foto'; var FBLANGSELECTED='pt_BR'; var SELECT_A_FRIEND='Escolha um dos Amigos abaixo:'; var dominio_images='https://s3.amazonaws.com/scrapee/'; var SHARE_FACEBOOK='Compartilhar foto'; var slashes=''; var LEGAIS_LINK='molduras-para-fotos'; var MORE_FRAMES='+ Molduras'; var TESTES_FACEBOOK_LINK='testes-para-facebook'; var TESTES_FACEBOOK='Testes para Facebook'; var REPETIR_TESTE='Tentar Novamente'; var TRY_AGAIN='Tentar Novamente'; var OBTENDO_PERFIL_FACEBOOK='Obtendo Perfil'; var CALCULANDO_RESULTADOS='Carregando...'; var CARREGANDO_RESULTADO_TESTE='Processando Imagem...'; var SELECT_ALBUM='Selecione um Album de Fotos'; var TOTAL_ALBUMS_REQUIRED='Você precisa ter no mínimo um album'; var MIN_PHOTOS_REQUIRED='Marque no mínimo uma foto. Não é possível utilizar fotos de álbuns diferentes! Máximo de Fotos: '; var NEXT_STEP='Próxima Etapa'; var BACK_TO_ALBUMS='Voltar para Álbuns'; var MAX_PHOTOS_REACHED='Quantia máxima de fotos permitidas atingido!'; var NEED_TO_SELECT_1_PHOTO='Necessário selecionar no mínimo uma foto'; function onoff(id) { var el = document.getElementById(id); el.style.display = (el.style.display=="") ? "none" : ""; } function showdiv(divname){ $('.f1_upload_process').show(); } function stopUpload(success){ var result = ''; document.getElementById('f1_upload_process').style.visibility = 'hidden'; return true; } function startUpload(){ // document.getElementById('f1_upload_process').style.visibility = 'visible'; //$('#f1_upload_process').setStyle({ display: 'block' }); jQuery('#f1_upload_process').show(); //return true; } function CheckForm () { var errorMsg = ""; var ok = true; var extensoesOk = ",.gif,.jpg,.png,jpeg,"; var extensao = "," + document.form.file.value.substr( document.form.file.value.length - 4 ).toLowerCase() + ","; if( extensoesOk.indexOf( extensao ) == -1 ){ errorMsg += ERRO_1+"\n"; } if (document.form.file.value == ""){ errorMsg = ERRO_2; } //startUpload(); if (errorMsg != ""){ errorMsg += alert(errorMsg + "\n"); $("#uploading_div").hide(); $("#uploadform").show(); return false; } return true; } function CheckForm2() { var errorMsg = ""; var ok = true; var extensoesOk = ",.gif,.jpg,.png,jpeg,"; var extensao = "," + document.form2.urlfile.value.substr( document.form2.urlfile.value.length - 4 ).toLowerCase() + ","; if( extensoesOk.indexOf( extensao ) == -1 ){ //errorMsg += ERRO_3+"\n"; } if (document.form2.urlfile.value == ""){ errorMsg = ERRO_4; } if (errorMsg != ""){ errorMsg += alert(errorMsg + "\n"); $("#uploading_div").hide(); $("#uploadform").show(); return false; } return true; } function CheckForm3 () { var errorMsg = ""; var ok = true; var extensoesOk = ",.gif,.jpg,.png,jpeg,"; var extensao = "," + document.form.file.value.substr( document.form.file.value.length - 4 ).toLowerCase() + ","; var extensao2 = "," + document.form.file2.value.substr( document.form.file2.value.length - 4 ).toLowerCase() + ","; if( extensoesOk.indexOf( extensao ) == -1 ){ errorMsg += FOTO_1+ERRO_1+"\n"; } if( extensoesOk.indexOf( extensao2 ) == -1 ){ errorMsg += FOTO_2+ERRO_1+"\n"; } if (document.form.file.value == ""){ errorMsg += FOTO_1+ERRO_2+"\n"; } if (document.form.file2.value == ""){ errorMsg += FOTO_2+ERRO_2+"\n"; } if (errorMsg != ""){ errorMsg += alert(errorMsg + "\n"); return false; } startUpload(); return true; } var showloja=false; function espandebuscape(){ var getWidth = $('#toolbarHolder').width(); $('#feedback').animate({right: -getWidth}, 500); setInterval('exchange_buscapebutton_show()',1000); } function closebuscape(){ var getWidth = $('#toolbarHolder').width(); $('#feedback').animate({right: -688}, 500); setInterval('exchange_buscapebutton()',1000); } function exchange_buscapebutton_show(){ $('#enabled_showbuscape').hide(); $('#disabled_showbuscape').css('display', 'inline'); } function exchange_buscapebutton(){ $('#enabled_showbuscape').css('display', 'inline'); $('#disabled_showbuscape').hide(); } /* scripts responsaveis pelo pegar fotos do facebook */ function voltarlbums(){ $("#loading_wheel").show(); $("#carousel").hide(); $('#carousel').load('/get_facebook_albums.php',function() { $("#carousel").show(); jQuery('#mycarousel').jcarousel(); $("#loading_wheel").hide(); //$('#carousel').css("visibility", "visible"); }); } jQuery(document).ready(function($) { voltarlbums(); }) function loadalbum(id){ $("#loading_wheel").show(); $("#carousel").hide(); // $("a.a_album").click(function () { // url: "fb_album_photos.aspx?cmd=album_photos&album_id=" + $(this).attr('name') + "&r=" + Math.random(), $('#carousel').load('/get_facebook_photos.php?album_id='+id,function() { $("#carousel").show(); jQuery('#mycarousel').jcarousel(); $("#loading_wheel").hide(); // alert(id); }); // }); } function uploadfoto(url){ $("#loading_wheel").show(); $("#carousel").hide(); $('#urlfile').val(url); $('#formopt').val('2'); $('.submit_upload').val(UPLOAD_BUTTON); $('#form2').submit(); } $( "#snap" ).click(function() { $(".photo_buttons").hide(); context.drawImage(video, 0, 0, 640, 480); $( "#canvas" ).remove(); $( "#video" ).remove(); var dataURL = canvas.toDataURL('image/jpeg',0.6); $('.canvasdiv').html('
'); }); $(function() { var UploadPhototoServer=function(){ $(".upload_buttons_camera").hide(); $(".upload_from_camera").html('

Uploading

'); $.post( "/receiveimageb64.php",{ imgBase64:$('#taken_photo').prop('src')},function( data ) { //$(".upload_from_camera").html(''); // $(".upload_buttons_camera").show(); var json = $.parseJSON(data); if(json.success==false){ alert("Não foi possível fazer upload da Foto. Tente Novamente!"); $(".upload_from_camera").html(''); $(".upload_buttons_camera").show(); //bootbox.alert("Não foi possível fazer upload da Foto. Tente Novamente!", function() {}); }else{ if(json.imageurl){ $("#urlfile").val(json.imageurl); $( "#form2" ).submit(); //$(".cameravideo").hide(); }else{ alert("Não foi possível fazer upload da Foto. Tente Novamente!"); } } }); } var takePhoto=function(){ // Put event listeners into place $(".canvasdiv").html(''); // Grab elements, create settings, etc. canvas = document.getElementById("canvas"), context = canvas.getContext("2d"), video = document.getElementById("video"), videoObj = { "video": true }, errBack = function(error) { console.log("Video capture error: ", error.code); }; // Put video listeners into place if(navigator.getUserMedia) { // Standard navigator.getUserMedia(videoObj, function(stream) { video.src = stream; $(".cameravideo").slideDown(); video.play(); }, errBack); } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed navigator.webkitGetUserMedia(videoObj, function(stream){ video.src = window.webkitURL.createObjectURL(stream); video.play(); $(".cameravideo").slideDown(); }, errBack); } else if(navigator.mozGetUserMedia) { // Firefox-prefixed navigator.mozGetUserMedia(videoObj, function(stream){ video.src = window.URL.createObjectURL(stream); video.play(); $(".cameravideo").slideDown(); }, errBack); }else{ alert('O navegador que você está usando não suporte este recurso!'); } } $( "#cancelphoto" ).click(function() { $(".cameravideo").slideUp(); //context.drawImage(video, 0, 0, 640, 480); }); $( ".take-photo-camera").click(function() { takePhoto(); //context.drawImage(video, 0, 0, 640, 480); }); $('.cameravideo').on('click','#takeanotherphoto', function(e) { $(".photo_buttons").show(); takePhoto(); }); $('.cameravideo').on('click','#usethisphoto', function(e) { UploadPhototoServer(); }); }); var json_data; var Scrapee = { facebookcallback: function(response){ if (response.status === 'connected') { // Logged into your app and Facebook. //testAPI(); } else if (response.status === 'not_authorized') { // The person is logged into Facebook, but not your app. document.getElementById('status').innerHTML = 'Please log ' + 'into this app.'; } else { // The person is not logged into Facebook, so we're not sure if // they are logged into this app or not. document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.'; } }, showlogin:function(){ $(".loginfacebook").show(); }, setup: function() { window.fbAsyncInit = function() { FB.init({ appId : '388433369414755', xfbml : true, version : 'v2.4' }); FB.getLoginStatus(function(response) { $(".gplusloggin").show(); $(".loadingbts").hide(); if (response.status === 'connected') { accesstoken=response.authResponse.accessToken; Scrapee.check_permissions(testConfig.scope); } else if (response.status === 'not_authorized') { if(testConfig.montagem_id){ Scrapee.showlogin(); forcelogin=true; return; } if(isCallBack){ alert("Necessário aceitar todas as permissões! You must accept all permissions requested!"); ga('send', 'event', 'permissions','not-authorized-login'); window.location.href = testConfig.permalink; }else{ if(testConfig.start){ window.location.replace(testConfig.redirect_url); } } } else { if(testConfig.montagem_id){ Scrapee.showlogin(); forcelogin=true; return; } window.location.replace(testConfig.redirect_url); } }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/"+FBLANGSELECTED+"/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); }, check_permissions: function(permissions) { FB.api('/me/permissions', function(response_perm) { var perms = response_perm.data; var permission_arr = permissions.split(","); var permissions_given=true; var permitted_list = []; for (var fbperm in perms) { if (perms[fbperm].status == 'granted') { permitted_list.push(perms[fbperm].permission); } } for(var i in permission_arr){ if(permitted_list.indexOf(permission_arr[i]) > -1){ //do nothing }else{ permissions_given=false; } } if(testConfig.start==true){ if (permissions_given) { forcelogin=false; //Scrapee.showlogin(); ga('send', 'event', 'teste',testConfig.permalink); Scrapee.getUserPicture(); return; } else { if(isCallBack){ alert("Necessário aceitar todas as permissões! You must accept all permissions requested!"); ga('send', 'event', 'permissions','permissions-not-given'); window.location.href = testConfig.permalink; }else{ window.location.href = testConfig.redirect_url; } //Scrapee.showlogin(); //forcelogin=true; return false; } }else{ if (permissions_given) { forcelogin=false; Scrapee.showlogin(); return; } else { Scrapee.showlogin(); forcelogin=true; return; } } }); }, login: function() { if(forcelogin===true){ FB.login(function(response) { if (response.authResponse) { forcelogin=false; var permsneeded = testConfig.scope.split(','); for (var pprm in permsneeded) { if( response.authResponse.grantedScopes.indexOf(permsneeded[pprm]) === -1){ forcelogin=true; alert('É necessário conceder todas as permissões requeridas'); return; } } accesstoken=response.authResponse.accessToken; Scrapee.getUserPicture(); ga('send', 'event', 'teste',testConfig.permalink); } else { ga('send', 'event', 'facebook','logincancelled'); } },{scope:testConfig.scope,return_scopes: true,auth_type: 'rerequest'}); }else{ Scrapee.getUserPicture(); } }, ShareonFace:function(){ e.preventDefault(); FB.ui( { method: 'share', href: "http://www.scrapee.net", }, // callback function(response) { if (response && !response.error_code) { //alert('Posting completed.'); } else { //alert('Error while posting.'); } } ); }, parsePost:function(post){ if ("likes" in post){ for (i in post.likes.data){ if("id" in post.likes.data[i]){ var friend_id=post.likes.data[i].id; var friend_name=post.likes.data[i].name; var inserted=false; for (j in friends_array){ if (friends_array[j].id == friend_id) { friends_array[j].weight += 1; inserted=true; break } } if(inserted==false && friend_id!=testConfig.userid){ var friendtoadd = { id: friend_id, weight: 1, name: friend_name } friends_array.push(friendtoadd); } } } } if ("comments" in post){ for (i in post.comments.data){ if("from" in post.comments.data[i]){ var friend_id=post.comments.data[i].from.id; var friend_name=post.comments.data[i].from.name; var inserted=false; for (j in friends_array){ if (friends_array[j].id == friend_id) { friends_array[j].weight += 2; inserted=true; break } } if(inserted==false && friend_id!=testConfig.userid){ var friendtoadd = { id: friend_id, weight: 2, name: friend_name } friends_array.push(friendtoadd); } } } } }, sortFriends:function(){ if(friends_array.length==0){ friends_array.push({ id: testConfig.userid, name: testConfig.username }); }else{ friends_array.sort(function(e, t) { return e.weight > t.weight ? 1 : t.weight > e.weight ? -1 : 0 }) } friends_array.reverse(); }, FetchUserFriends:function(callback) { FB.api("/me/friends?limit=35&fields=name,id", function(response) { try { if (response && response.data && response.data.length > 0) { for (var f in response.data) { var friendtoadd = { id: response.data[f].id, weight:3, } friends_array.push(friendtoadd); } } } catch (err) { console.log("aconteceu erro aqui"); } callback(); }); }, FetchTopFriends:function(limit,total_friends,return_total){ Scrapee.hideInterface(); FB.api("/me/posts?fields=likes,comments,from,type&limit="+limit, function (response) { if(response.error){ Scrapee.showInterface(); return; } data = response.data; for (i in data) post = data[i],Scrapee.parsePost(post); Scrapee.sortFriends(); friends_array=friends_array.slice(0,total_friends); function randOrd(){ return (Math.round(Math.random())-0.5); } if(testConfig.format=="fetchbestfriends"){ Scrapee.sortFriends(); }else{ friends_array.sort(randOrd); } friends_array=friends_array.slice(0,return_total); var lastid=friends_array[friends_array.length-1].id; if(friends_array.length < return_total){ } var data = []; if(testConfig.total_friends>0){ for (i in friends_array) { data.push({ method: 'GET', relative_url: friends_array[i].id + '?fields=id,name,first_name,last_name,gender,picture.width('+testConfig.width+')' }); } FB.api('/', 'post', { batch: data }, function(response) { if (!response || response.error || response == "error") { if (response) { Scrapee.showInterface(); return; } else { console.log("no error found"); } if (typeof error_callback !== "undefined") { Scrapee.showInterface(); return; } } else { var response_with_friends = []; for (var i = 0; i < response.length; i++) { var data = $.parseJSON(response[i].body); if (data.error || data == "error") { continue; } data.url = $.parseJSON(response[i].body).picture.data.url; data.picture=''; response_with_friends.push(data); } if(testConfig.filterbygender){ var newfriendsarray=[]; for (var i = 0; i < response_with_friends.length; i++) { if(response_with_friends[i].gender==undefined || response_with_friends[i].gender!=testConfig.filterbygender){ response_with_friends.splice(i,1); }else{ newfriendsarray.push(response_with_friends[i]); } } response_with_friends=[]; response_with_friends=newfriendsarray; if(response_with_friends.length < 1){ Scrapee.showInterface(); } } friends_array=response_with_friends; json_data=JSON.stringify(friends_array); if(testConfig.canselect==true){ $('.albumsarea').html("
"+SELECT_A_FRIEND+"
"); $("#loading").hide(); $('.albumsarea').show(); for (i in friends_array){ $('.albumsarea').append('
'+friends_array[i].name+'
'); } }else{ Scrapee.getResult(testConfig.image,testConfig.username); } } }); }else{ //else if < 25 amigos for (i in friends_array) { data.push({ method: 'GET', relative_url: friends_array[i].id + '?fields=id,name,first_name,last_name,gender' }); data.push({ method: 'GET', relative_url: friends_array[i].id + '/picture?height=320&width=320&return_ssl_resources=0&type=large&redirect=false' }); } FB.api('/', 'post', { batch: data.slice(0,50) }, function(response) { console.log(response); return; if (!response || response.error || response == "error") { if (response) { console.log("ocorreu um erro"); Scrapee.showInterface(); return; } else { console.log("no error found"); } if (typeof error_callback !== "undefined") { Scrapee.showInterface(); return; } } else { var response_with_friends = []; for (var i = 0; i < response.length; i++) { if (i % 2) { try { var data = $.parseJSON(response[i - 1].body); if (data.error || data == "error") { continue; } data.url = $.parseJSON(response[i].body).data.url; } catch (err) { Scrapee.showInterface(); return; if (typeof error_callback !== "undefined") { //than show interface } } response_with_friends.push(data); } } friends_array=response_with_friends; json_data=JSON.stringify(friends_array); Scrapee.getResult(testConfig.image,testConfig.username); } }); } /* end fetch from this brackets */ } ); }, getUserPicture: function(){ FB.api('/me?fields=id,name,gender', function(response) { testConfig.userid=response.id testConfig.username=response.name; testConfig.gender=response.gender; if(response.error){ window.location.reload(); result; } if(testConfig.format=="normal"){ FB.api("/"+response.id+"/picture?height=400&width=400", function (response) { if (response && !response.error) { if(response.data.url){ Scrapee.getResult(response.data.url,testConfig.username); }else{ alert("Ocorreu um Erro! Tente Novamente"); } } } ); }else if(testConfig.format=="montagemvariasfotos"){ Scrapee.getAlbums(); }else if(testConfig.format=="fetchuserphotos"){ FB.api("/"+response.id+"/picture?height=320&width=320", function (response) { if (response && !response.error) { if(response.data.url){ testConfig.image=response.data.url; Scrapee.getUserPhotos(); }else{ alert("Ocorreu um Erro! Tente Novamente"); Scrapee.showInterface(); } } } ); }else if(testConfig.format=="fetchprofilepics"){ FB.api("/"+response.id+"/picture?height=320&width=320", function (response) { if (response && !response.error) { if(response.data.url){ testConfig.image=response.data.url; Scrapee.getProfilePics(); }else{ alert("Ocorreu um Erro! Tente Novamente"); Scrapee.showInterface(); } } } ); }else if(testConfig.format=="fromfriends"){ Scrapee.FetchTopFriends(100,3,1); }else if(testConfig.format=="ramdomfriend"){ Scrapee.FetchTopFriends(100,30,1); }else if(testConfig.format=="fetchfriends"){ FB.api("/"+response.id+"/picture?height=320&width=320", function (response) { if (response && !response.error) { if(response.data.url){ testConfig.image=response.data.url; Scrapee.FetchUserFriends(function(){Scrapee.FetchTopFriends(testConfig.totalposts,50,testConfig.total_friends)}); }else{ alert("Ocorreu um Erro! Tente Novamente"); Scrapee.showInterface(); } } } ); }else if(testConfig.format=="fetchbestfriends"){ FB.api("/"+response.id+"/picture?height=320&width=320", function (response) { if (response && !response.error) { if(response.data.url){ testConfig.image=response.data.url; Scrapee.FetchTopFriends(100,30,testConfig.total_friends); }else{ alert("Ocorreu um Erro! Tente Novamente"); Scrapee.showInterface(); } } } ); } }); }, hideInterface:function(){ $("#show_resultado").show(); $("#loading").show(); $("#showcontent").hide(); $(".loginfacebook").hide(); $(".gplusloggin").hide(); $(".sharefacehome").hide(); if(testConfig.format=="montagemvariasfotos"){ $(".albumsarea").hide(); } }, showInterface:function(){ if(testConfig.format=="montagemvariasfotos"){ $(".albumsarea").html(""); } $("#show_resultado").hide(); $("#loading").hide(); $("#showcontent").show(); $(".loginfacebook").show(); $(".gplusloggin").show(); window.location.href = testConfig.permalink; }, hideFrameInterface:function(){ $("#uploading_div").show(); $("#uploadform").hide(); $(".loginfacebook").hide(); $(".sharefacehome").hide(); }, showFrameInterface:function(){ $("#uploading_div").hide(); $("#uploadform").show(); $("#showcontent").hide(); }, getResult:function(file,username){ if(typeof testConfig.montagem_id !== 'undefined') { Scrapee.hideFrameInterface(); $.post( "/photoframefromface.php", { imageurl:file,montagem_id:testConfig.montagem_id}, function( data ) { var json = data,result = JSON && JSON.parse(json) || $.parseJSON(json); if(result.foto){ $("#conteudo_frame").hide(); $("#showcontent").html('

'+SHARE_FACEBOOK+'


'+MORE_FRAMES+' | '+TESTES_FACEBOOK+''); $("#conteudo_btfb").html(TRY_AGAIN); ga('send', 'event', 'moldurafromface',testConfig.permalink); }else{ Scrapee.showFrameInterface(); alert('Ocorreu um erro! Tente novamente mais tarde'); ga('send', 'event', 'moldurafromface',"erro_gerar_moldura"); } }); return; } Scrapee.hideInterface(); $("#show_resultado").html(OBTENDO_PERFIL_FACEBOOK); setTimeout(function(){ $("#show_resultado").html(CALCULANDO_RESULTADOS); }, 3000); $.post( "/generatetestes.php", { imageurl:file,name:testConfig.username,testeid:testConfig.testid,userid:testConfig.userid,friendid:testConfig.friendid,friendname:testConfig.friendname,json_data:json_data,gender:testConfig.gender}, function( data ) { if(!data){ Scrapee.showInterface(); return; } var json = data,result = JSON && JSON.parse(json) || $.parseJSON(json); $("#show_resultado").html(CARREGANDO_RESULTADO_TESTE); if(result.foto){ if(result.isvideo!=null){ document.cookie="mylastpicture="+result.foto+";path=/"; Scrapee.scrapepages('/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?newvideo=true'); setTimeout(function(){location.href='/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?video=true'} ,2000); }else if(result.isanimation!=null){ document.cookie="mylastpicture="+result.foto+";path=/"; Scrapee.scrapepages('/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?newanimation=true'); setTimeout(function(){location.href='/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?animation=true'} ,2000); }else if(result.ispuzzle!=null){ document.cookie="mylastpicture="+result.foto+";path=/"; Scrapee.scrapepages('/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?newpuzzle=true'); setTimeout(function(){location.href='/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?puzzle=true'} ,2000); }else{ document.cookie="mylastpicture="+result.foto+";path=/"; Scrapee.scrapepages('/result/'+result.username+'/'+result.url+'/'+result.redirectid+'?newpage=true'); setTimeout(function(){location.href='/result/'+result.username+'/'+result.url+'/'+result.redirectid} ,2000); } }else{ //Scrapee.showInterface(); window.location.href = testConfig.permalink; //alert('Ocorreu um erro! Tente novamente mais tarde'); ga('send', 'event', 'teste',"erro_gerar_image_teste"); } }) .fail(function() { window.location.href = testConfig.permalink; //Scrapee.showInterface(); }); }, getResultGPlus:function(file,username){ Scrapee.hideInterface(); $( ".shareongp" ).remove(); $("#sharebuttondiv").html(''); $("#show_resultado").html(OBTENDO_PERFIL_FACEBOOK); setTimeout(function(){ $("#show_resultado").html(CALCULANDO_RESULTADOS); }, 3000); $.post( "/generatetestes.php", { imageurl:file,name:testConfig.username,testeid:testConfig.testid,userid:testConfig.userid}, function( data ) { var json = data,result = JSON && JSON.parse(json) || $.parseJSON(json); $("#show_resultado").html(CARREGANDO_RESULTADO_TESTE); if(result.foto){ $("#showcontent").html(''); Scrapee.showInterface(); $("#sharebuttondiv").html('
Compartilhar
'); gapi.plus.go(); $("#sharebuttondiv").show(); $(".mybutton").hide(); $(".loginfacebook").hide(); document.cookie="mylastpicture="+result.foto; }else{ Scrapee.showInterface(); alert('Ocorreu um erro! Tente novamente mais tarde'); } }); }, getAlbums:function( callback ) { $("#showcontent").hide(); $(".loginfacebook").hide(); $(".gplusloggin").hide(); $(".sharefacehome").hide(); $('.albumsarea').hide(); $("#loading").show(); FB.api("/me/albums", function (response) { if (response && !response.error) { var hassomephoto=false; $('.albumsarea').html("
"+SELECT_ALBUM+"
"); $("#loading").hide(); $('.albumsarea').show(); for (i in response.data){ hassomephoto=true; $('.albumsarea').append('
'+response.data[i].name+'
'); } if(hassomephoto==false){ alert(TOTAL_ALBUMS_REQUIRED); Scrapee.showInterface(); return; } } } ); }, getProfilePics:function( callback ) { $("#loading").show(),Scrapee.hideInterface(); FB.api("/me/albums", function (response) { if (response && !response.error) { var hassomephoto=false; for (i in response.data){ hassomephoto=true; if(response.data[i].name=='Profile Pictures'){ Scrapee.parseProfilePics(response.data[i].id); } } if(hassomephoto==false){ alert(TOTAL_ALBUMS_REQUIRED); Scrapee.showInterface(); return; } } } ); }, parseProfilePics:function( albumId, callback ) { var profilepics=[]; var keyslist=[]; FB.api('/'+albumId+'/photos?limit=100', {fields: 'id,source,created_time'}, function(response) { for (i in response.data){ var created_time_var=response.data[i].created_time.split("-"); var cretedtime=created_time_var[0]; if(testConfig.GetAllPics){ keyslist.push(created_time_var[0]); var profilephoto = { url:response.data[i].source,name:created_time_var[0].toString()}; profilepics.push(profilephoto); }else{ if(keyslist.indexOf(cretedtime) > -1){ //do nothing avoiding duplicates }else{ keyslist.push(created_time_var[0]); var profilephoto = { url:response.data[i].source,name:created_time_var[0].toString()}; profilepics.push(profilephoto); } } } if(testConfig.FirstAndLast){ profilepics=[]; created_time_var=response.data[0].created_time.split("-"); cretedtime=created_time_var[0]; profilephoto = { url:response.data[0].source,name:created_time_var[0].toString()}; profilepics.push(profilephoto); created_time_var=response.data[response.data.length-1].created_time.split("-"); cretedtime=created_time_var[0]; profilephoto = { url:response.data[response.data.length-1].source,name:created_time_var[0].toString()}; profilepics.push(profilephoto); profilepics.reverse(); } profilepics=profilepics.slice(0,testConfig.total_friends); json_data=JSON.stringify(profilepics); Scrapee.getResult(); } ); }, getUserPhotos:function(callback){ $("#loading").show(),Scrapee.hideInterface();var userphotosarray=[]; FB.api('/me/photos?type=uploaded', {fields: 'source,created_time,name,id,likes.summary(true)',limit:300,since:testConfig.since,until:testConfig.until}, function(response) { for(i in response.data){ if(response.data[i].id){ if(response.data[i].likes){ var thislikes=response.data[i].likes.summary.total_count }else{ var thislikes=0; } userphotosarray.push( { id: response.data[i].id, url: response.data[i].source, likes: thislikes }); } } if(testConfig.filter=="ultimas"){ }else if(testConfig.filter=="primeiras"){ userphotosarray.reverse(); }else if(testConfig.filter=="ramdom"){ function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } shuffle(userphotosarray); }else{ userphotosarray.sort(function(e, t) { return e.likes > t.likes ? 1 : t.likes > e.likes ? -1 : 0}); userphotosarray.reverse(); } userphotosarray=userphotosarray.slice(0,testConfig.total_friends); json_data=JSON.stringify(userphotosarray); Scrapee.getResult(testConfig.image); } ); } , getPhotos:function( albumId, callback ) { $("#loading").show(); $('.albumsarea').hide(); FB.api( '/'+albumId+'/photos', {fields: 'id,source,images'}, function(response) { $('.albumsarea').html('
'); for (i in response.data){ var thisalbumimages=response.data[i].images.pop().source; $('.albumsarea').append('
'); } $('.albumsarea').show(); $("#loading").hide(); $('.albumsarea').append('
'+BACK_TO_ALBUMS+' '+NEXT_STEP+''); } ); } } $(function() { if (typeof testConfig !== 'undefined' && (testConfig.start==true || testConfig.montagem_id>0)) { console.log("chegou até aqui"); Scrapee.setup(); } $( ".testediv" ).on( "click",".selectafriend",function(e) { e.preventDefault(); $('.albumsarea').hide(); friends_array=[]; var friendtoadd = { id: 0,weight: 0,url:$(this).data("url"),name:$(this).data("nome")} friends_array.push(friendtoadd); json_data=JSON.stringify(friends_array); scrollTo(0,100); Scrapee.getResult(testConfig.image,testConfig.username); }); $("#getAlbums").click(function(e) { Scrapee.getAlbums(); e.preventDefault(); }); $(".loginfacebook").click(function() { Scrapee.login(); }); $(".FaceProfilePic").click(function() { alert('clicket'); Scrapee.setup(); }); $('.albumsarea').on('click','.album', function(e) { e.preventDefault(); var thisalbumid=$(this).data("albumid"); Scrapee.getPhotos(thisalbumid); }); $('.albumsarea').on('click','.backalbums', function(e) { e.preventDefault(); Scrapee.getAlbums(); }); $('.albumsarea').on('click','.photofromalbums', function(e) { e.preventDefault(); if($(this).hasClass("selectedphoto")){ $(this).removeClass("selectedphoto"); }else{ if($(".selectedphoto").length>=testConfig.total_friends){ alert(MAX_PHOTOS_REACHED); }else{ $(this).addClass("selectedphoto"); } } }); $('.albumsarea').on('click','.selectedphotos', function(e) { if($(".selectedphoto").length>0){ $(".selectedphoto").each(function( index ) { var friendtoadd = { id: 0,weight: 0,url:$(this).data("url")} friends_array.push(friendtoadd); }); json_data=JSON.stringify(friends_array); Scrapee.getResult(); }else{ alert(NEED_TO_SELECT_1_PHOTO); } }); }); function onSignInCallback(resp) { if(resp.status.method=="PROMPT"){ gapi.client.load('plus', 'v1', apiClientLoaded); ga('send', 'event', 'googleplus','entrou'); } } function apiClientLoaded() { gapi.client.plus.people.get({userId: 'me'}).execute(handleEmailResponse); } function handleEmailResponse(resp) { testConfig.username=resp.displayName; testConfig.userid=resp.id; Scrapee.getResultGPlus(resp.image.url+'0',resp.displayName); }