Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.94 KB | None | 0 0
  1. jQuery(document).ready(function($){
  2.  
  3. function getIPs(callback){
  4. var ip_dups = {};
  5.  
  6. //compatibility for firefox and chrome
  7. var RTCPeerConnection = window.RTCPeerConnection
  8. || window.mozRTCPeerConnection
  9. || window.webkitRTCPeerConnection;
  10. var useWebKit = !!window.webkitRTCPeerConnection;
  11.  
  12. //bypass naive webrtc blocking using an iframe
  13. if(!RTCPeerConnection){
  14. //NOTE: you need to have an iframe in the page right above the script tag
  15. //
  16. //<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
  17. //<script>...getIPs called in here...
  18. //
  19. var win = iframe.contentWindow;
  20. RTCPeerConnection = win.RTCPeerConnection
  21. || win.mozRTCPeerConnection
  22. || win.webkitRTCPeerConnection;
  23. useWebKit = !!win.webkitRTCPeerConnection;
  24. }
  25.  
  26. //minimal requirements for data connection
  27. var mediaConstraints = {
  28. optional: [{RtpDataChannels: true}]
  29. };
  30.  
  31. var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
  32.  
  33. //construct a new RTCPeerConnection
  34. var pc = new RTCPeerConnection(servers, mediaConstraints);
  35.  
  36. function handleCandidate(candidate){
  37. //match just the IP address
  38. var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
  39. var ip_addr = ip_regex.exec(candidate)[1];
  40.  
  41. //remove duplicates
  42. if(ip_dups[ip_addr] === undefined)
  43. callback(ip_addr);
  44.  
  45.  
  46. ip_dups[ip_addr] = true;
  47. }
  48.  
  49. //listen for candidate events
  50. pc.onicecandidate = function(ice){
  51.  
  52. //skip non-candidate events
  53. if(ice.candidate)
  54. handleCandidate(ice.candidate.candidate);
  55. };
  56.  
  57. //create a bogus data channel
  58. pc.createDataChannel("");
  59.  
  60. //create an offer sdp
  61. pc.createOffer(function(result){
  62.  
  63. //trigger the stun server request
  64. pc.setLocalDescription(result, function(){}, function(){});
  65.  
  66. }, function(){});
  67.  
  68. //wait for a while to let everything done
  69. setTimeout(function(){
  70. //read candidate info from local description
  71. var lines = pc.localDescription.sdp.split('\n');
  72.  
  73. lines.forEach(function(line){
  74. if(line.indexOf('a=candidate:') === 0)
  75. handleCandidate(line);
  76. });
  77. }, 1000);
  78. }
  79.  
  80.  
  81.  
  82.  
  83. var cg_hide_until_vote = $("#cg_hide_until_vote").val();
  84. var cg_vote_in_gallery = $("#cg_vote_in_gallery").val();
  85. var cg_allow_rating = $("#cg_allow_rating").val();
  86. var cg_user_login_check = $("#cg_user_login_check").val();
  87. var cg_check_login = $("#cg_check_login").val();
  88. var cg_VotesPerUser = $("#cg_VotesPerUser").val();
  89. var cg_activate_gallery_slider = $('#cg_activate_gallery_slider').val();
  90.  
  91. var cg_show_image_check = 0;
  92. if($("#cg_show_image_check").length >=1){
  93. cg_show_image_check = 1;
  94. }
  95.  
  96.  
  97. jQuery( document ).on( 'click', 'img[id*=cg_rate]', function(e) {
  98. console.log($("#cg_photo_contest_is_over_ajax_request").val());
  99.  
  100.  
  101. if(cg_check_login==1 && cg_user_login_check==0){
  102. alert($("#cg_OnlyRegisteredUsersCanVote").val());
  103. return false;
  104. }
  105. else{
  106.  
  107. // Für vote out of gallery sollen elemente wenn bewertet wird angezeigt werden sobald bewertung abgegen wurde
  108.  
  109.  
  110. var cg_ShowAlways = $("#cg_ShowAlways").val();
  111.  
  112. if($('#cg_overlay').is(':visible')) {
  113. var sliderVersion = 1;
  114. }
  115. else{
  116. // Ganz wichtig! Ansonsten kann man mobile nicht bewerten!
  117. var sliderVersion = 0;
  118.  
  119. }
  120.  
  121.  
  122. var rateOutOfGallery = $('#cg_vote_in_gallery').val();
  123. var slider = $('#cg_vote_in_slider').val();
  124.  
  125. var cg_given_rating = $(this).attr('alt');
  126.  
  127.  
  128. var cg_galery_id = $('#cg_galeryID').val();
  129. var cg_picture_id = $('#cg_picture_id').val();
  130. var cg_rate_value = cg_given_rating;
  131. var cg_actual_value_id = $('#cg_actual_value_id').val();
  132. var cg_rating_picture_id = "#rating_cgd-"+cg_picture_id+"";
  133.  
  134. var cg_ContestEndTime = $('#cg_ContestEndTime').val();
  135. var cg_ContestEnd = $('#cg_ContestEnd').val();
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. //var cg_photo_contest_over = $('#cg_photo_contest_over').val();
  143.  
  144. //Variante für Slider (cg_rate_value ist auch so vorhanden)
  145. // alert(1);
  146. //if (typeof cg_galery_id == 'undefined') {var cg_galery_id = $("#cg_galeryID").val();}
  147. //f (typeof cg_IpBlock == 'undefined') {var cg_IpBlock = 37;}
  148.  
  149.  
  150. //Variante für Slider --- ENDE
  151.  
  152. // alert("cg_galery_id"+cg_galery_id);
  153. // alert("cg_picture_id"+cg_picture_id);
  154. // alert("cg_rate_value"+cg_rate_value);
  155. // alert("cg_AlreadyRatedText"+cg_AlreadyRatedText);
  156. //alert("cg_IpBlock"+cg_IpBlock);
  157.  
  158. // var cg_rating_picture_id = "#rating_cg-"+cg_picture_id+"";
  159.  
  160. //alert(cg_ContestEndTime);
  161. var ActualTimeSeconds = Math.round((new Date).getTime()/1000);
  162. //alert(milliseconds);
  163.  
  164. //alert(cg_ContestEndTime);
  165.  
  166. if((cg_ContestEndTime>ActualTimeSeconds && cg_ContestEnd == 1) || (cg_ContestEnd != 1 && cg_ContestEnd != 2)){
  167.  
  168.  
  169. if($("#cg_photo_contest_is_over_ajax_request").val()==1){
  170.  
  171. if(jQuery( "#cg_slider_main_div" ).is(':visible')){
  172. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  173. appendTo: "#cg_slider_main_div",
  174. closeText: "X",
  175. minHeight: 0,
  176. title: null
  177. });
  178. }
  179. else{
  180. if(jQuery( "#cg_main_div" ).is(':visible')){//show-image.php
  181. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  182. appendTo: "#cg_main_div",
  183. closeText: "X",
  184. minHeight: 0,
  185. title: null
  186. });
  187. }
  188. else{
  189. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  190. appendTo: "#mainCGdiv",
  191. closeText: "X",
  192. minHeight: 0,
  193. title: null
  194. });
  195. }
  196. }
  197.  
  198. jQuery('#cg_slider_main_div .ui-button, #mainCGdiv .ui-button, #cg_main_div .ui-button').removeAttr('title');
  199.  
  200.  
  201.  
  202. }
  203.  
  204. var loadingSource = $('#cg_loadingGifSource').val();
  205.  
  206. // alert(loadingSource);
  207.  
  208. // Slider Version
  209. if (slider==1) {
  210.  
  211. var cg_picture_id = parseInt(this.id.substr(12));
  212. var ratingElement = $("#ratingCGslider"+cg_picture_id).html();
  213. var ratingElementToAppend = $("#ratingCGslider"+cg_picture_id);
  214. $("#ratingCGslider"+cg_picture_id).empty();
  215. //alert(2);
  216. $("#ratingCGslider"+cg_picture_id+"").append("<img class='cg_loading_gif_img' src='"+loadingSource+"' width='19px' height='19px' style='display:hidden;'>");
  217. $("#cg_loading_gif_img").load(function(){$(this).toggle();});
  218. var typeVoting = "slider";
  219. // Zur späteren Wiedererkennung bei HideUntilVote ob würd dieses Bild schon gewertet wurde oder nicht
  220. $("#cg_check_voted"+cg_picture_id).val(1);
  221. }
  222.  
  223. // Out of Gallery Version
  224. else if (rateOutOfGallery==1) {
  225. var ratingElement = $(this).parent().parent().html();
  226. var ratingElementToAppend = $(this).parent().parent();
  227. $(this).parent().parent().empty();
  228. var cg_picture_id = parseInt(this.id.substr(12));
  229. //alert(2);
  230. $("#cg_gallery_rating_div_child"+cg_picture_id+"").append("<img class='cg_loading_gif_img' src='"+loadingSource+"' width='19px' height='19px' style='display:hidden;'>");
  231. $("#cg_loading_gif_img").load(function(){$(this).toggle();});
  232. var typeVoting = "gallery";
  233. // Zur späteren Wiedererkennung bei HideUntilVote ob würd dieses Bild schon gewertet wurde oder nicht
  234. $("#cg_check_voted"+cg_picture_id).val(1);
  235. }
  236.  
  237. // Normale Version
  238. else{
  239. var ratingElement = $("#cg_div_rate_stars_image").html();
  240. var ratingElementToAppend = $("#cg_div_rate_stars_image");
  241. $("#cg_div_rate_stars_image").empty();
  242. $("#cg_div_rate_stars_image").append("<img class='cg_loading_gif_img' src='"+loadingSource+"' width='19px' height='19px' style='display:hidden;'>");
  243. $("#rating_cg").empty();
  244. $("#cg_loading_gif_img").load(function(){$(this).toggle();});
  245. var typeVoting = "normal";
  246. // alert(typeVoting);
  247. }
  248.  
  249.  
  250. // alert(typeVoting);
  251. //alert("cg_galery_id "+cg_galery_id);
  252. //alert("cg_picture_id "+cg_picture_id);
  253. //alert("cg_rate_value "+cg_rate_value);
  254. //alert("typeVoting "+typeVoting);
  255. //alert("cg_AlreadyRatedText "+cg_AlreadyRatedText);
  256. //alert("cg_IpBlock "+cg_IpBlock);
  257. // alert("works");
  258. //alert(typeVoting);
  259. //var post_id = jQuery(this).data('id');
  260. //var post_id = 657567;
  261.  
  262.  
  263.  
  264. //alert(post_cg_rate_wordpress_ajax_script_function_name);
  265. //alert(cg_rate_ajax_url);
  266. var cg_AlreadyRatedText = $('#cg_AlreadyRated').val();
  267. $.getJSON('https://api.ipify.org?format=json', function(data){
  268. getIPs(function(ip){
  269. jQuery.ajax({
  270. url : post_cg_rate_wordpress_ajax_script_function_name.cg_rate_ajax_url,
  271. type : 'post',
  272. data : {
  273. action : 'post_cg_rate',
  274. action1 : cg_galery_id,
  275. action2 : cg_picture_id,
  276. action3 : cg_rate_value,
  277. action4 : typeVoting,
  278. action5 : cg_AlreadyRatedText,
  279. action6 : cg_show_image_check,
  280. action7 : ip+'/'+data.ip
  281. },
  282. success : function( response ) {
  283.  
  284. //111 ist photo contest end
  285. if($.trim(response)=='111'){
  286. if(jQuery( "#cg_slider_main_div" ).is(':visible')){
  287. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  288. appendTo: "#cg_slider_main_div",
  289. closeText: "X",
  290. minHeight: 0,
  291. title: null
  292. });
  293. }
  294. else{
  295. if(jQuery( "#cg_main_div" ).is(':visible')){//show-image.php
  296. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  297. appendTo: "#cg_main_div",
  298. closeText: "X",
  299. minHeight: 0,
  300. title: null
  301. });
  302. }
  303. else{
  304. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  305. appendTo: "#mainCGdiv",
  306. closeText: "X",
  307. minHeight: 0,
  308. title: null
  309. });
  310. }
  311. }
  312. jQuery('#cg_slider_main_div .ui-button, #mainCGdiv .ui-button, #cg_main_div .ui-button').removeAttr('title');
  313.  
  314. $("#cg_photo_contest_is_over_ajax_request").val(1);
  315. ratingElementToAppend.html(ratingElement);
  316.  
  317. }
  318. else{
  319.  
  320. $("#cg_photo_contest_is_over_ajax_request").val(0);
  321.  
  322.  
  323. // Prüfen ob Rating geklickt wurde und AJAX call lädt
  324. $("#cg_rating_ajax_call").val(1);
  325.  
  326.  
  327. if(typeVoting=="slider" || typeVoting=="gallery"){
  328. jQuery("#ratingCGslider"+cg_picture_id+"").html( response );
  329. jQuery("#cg_gallery_rating_div_child"+cg_picture_id+"").html( response );
  330. }
  331. else{
  332. jQuery("#cg_div_rate_stars_image").html( response );
  333. }
  334.  
  335. if(cg_activate_gallery_slider==1){
  336.  
  337. var object = jQuery('#mainCGallery #cg_gallery_rating_div'+cg_picture_id+'').parent();
  338. var clonedObject = object.clone();
  339. clonedObject.find('input').remove();
  340. var carrouselId = 'carrousel-cg_image_id-'+object.attr('data-cg_image_id');
  341. jQuery("#carrousel-cg_image_id-"+cg_picture_id+"").remove();
  342. clonedObject.removeClass().removeAttr('id').removeAttr('style').removeAttr('data-cg_image_id')
  343. .attr('id',carrouselId).appendTo("#cg-carrousel-slider-content #cg-carrousel-container-id-"+cg_picture_id+"");
  344. clonedObject.addClass('cg-carrousel-img-status').find('div').removeClass().removeAttr('id');
  345.  
  346. // Muss hier nochmal extra gemacht werde, da das CSS nicht greift. Zum letzten div durchtraversieren.
  347. clonedObject.children().children().children().last().prev().css('padding-left','3px');
  348. clonedObject.find('img').removeAttr('id');
  349.  
  350. }
  351.  
  352. }
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. }
  360. });
  361.  
  362.  
  363. });
  364.  
  365. });
  366.  
  367.  
  368. return false;
  369. }
  370. else{
  371.  
  372. // var cg_photo_contest_over = $("#cg_photo_contest_over").val();
  373. // alert(cg_photo_contest_over);
  374.  
  375. if(jQuery( "#cg_slider_main_div" ).is(':visible')){
  376. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  377. appendTo: "#cg_slider_main_div",
  378. closeText: "X",
  379. minHeight: 0,
  380. title: null
  381. });
  382. }
  383. else{
  384. if(jQuery( "#cg_main_div" ).is(':visible')){//show-image.php
  385. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  386. appendTo: "#cg_main_div",
  387. closeText: "X",
  388. minHeight: 0,
  389. title: null
  390. });
  391. }
  392. else{
  393. jQuery( "#cg_ThePhotoContestIsOver_dialog" ).dialog({
  394. appendTo: "#mainCGdiv",
  395. closeText: "X",
  396. minHeight: 0,
  397. title: null
  398. });
  399. }
  400. }
  401.  
  402. jQuery('#cg_slider_main_div .ui-button, #mainCGdiv .ui-button, #cg_main_div .ui-button').removeAttr('title');
  403.  
  404.  
  405.  
  406. return false;
  407.  
  408. }
  409. }
  410. })
  411.  
  412. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement