Warning: Constant smpush_logs_mode already defined in /data03/virt985/domeenid/www.fireworks.ee/htdocs/wp-content/plugins/smio-push-notification/class.controller.php on line 705

Warning: Cannot modify header information - headers already sent by (output started at /data03/virt985/domeenid/www.fireworks.ee/htdocs/wp-content/plugins/smio-push-notification/class.controller.php:705) in /data03/virt985/domeenid/www.fireworks.ee/htdocs/wp-content/plugins/smio-push-notification/class.build.profile.php on line 58
"use strict"; var smpush_isPushEnabled = false; let firebaseInitialized = false; var devicetype = smpush_browser(); var settings = JSON.parse('{"chrome":1,"firefox":0,"opera":1,"edge":1,"samsung":1,"safari":0}'); smpush_debug(devicetype); function smpush_debug(error, object) { if(0 == 1){ if(typeof object !== "undefined"){ console.log(error, object); } else { console.log(error); } } } function smpush_endpoint_subscribe(subscriptionId, oldToken) { if(subscriptionId == ""){ return false; } smpush_setCookie("smpush_desktop_request", "true", 365); smpush_setCookie("smpush_device_token", subscriptionId, 60); var data = {}; data["device_token"] = subscriptionId; data["device_type"] = devicetype; data["firebase"] = 1; data["active"] = 1; data["latitude"] = (smpush_getCookie("smart_push_smio_coords_latitude") != "")? smpush_getCookie("smart_push_smio_coords_latitude") : ""; data["longitude"] = (smpush_getCookie("smart_push_smio_coords_longitude") != "")? smpush_getCookie("smart_push_smio_coords_longitude") : ""; var subsChannels = []; jQuery("input.smpush_desktop_channels_subs:checked").each(function(index) { subsChannels.push(jQuery(this).val()); }); subsChannels = subsChannels.join(","); if(jQuery(".smpush-push-subscriptions-button").length > 0 && jQuery("#smpush_subscription_form").length == 0){ var apiService = "channels_subscribe"; data["channels_id"] = subsChannels; } else if(oldToken && oldToken != ""){ var apiService = "refresh_token"; data["device_old_token"] = oldToken; } else{ var apiService = "savetoken"; } smpushDestroyReqWindow(false); jQuery.ajax({ method: "POST", url: "https://fireworks.ee/?smpushcontrol="+apiService, data: data }) .done(function( msg ) { smpushWelcomeMSG(); jQuery(".smpush-push-subscriptions-button").attr("disabled","disabled"); jQuery(".smpush-push-subscriptions-button").html("Salvestatud"); smpush_debug("Data Sent"); if(0 == 1){ smpushUpdateGPS(); } smpush_link_user_cookies(); }); } function smpush_endpoint_unsubscribe(subscriptionId) { jQuery("#smpushIconRequest").smiotooltipster("content","Telli meie teavitused ja oled alati kurisis heade pakkumiste ja loosimistega! Teavitused saab tühistada igal ajal."); if(subscriptionId == ""){ return false; } jQuery.ajax({ method: "POST", url: "https://fireworks.ee/?smpushcontrol=deletetoken", data: { device_token: subscriptionId, device_type: devicetype, firebase: 1} }) .done(function( msg ) { smpush_debug("Data Sent"); smpush_setCookie("smpush_linked_user", "false", -1); smpush_setCookie("smpush_safari_device_token", "false", -1); smpush_setCookie("smpush_device_token", "false", -1); smpush_setCookie("smpush_desktop_request", "false", -1); smpush_setCookie("smpush_desktop_welcmsg_seen", "false", -1); smpush_setCookie("smpush_desktop_blocked", "true", 365); location.reload(); }); } function smpush_test_browser(){ if("safari" in window && "pushNotification" in window.safari){ return true; } if (typeof(ServiceWorkerRegistration) != "undefined" && ("showNotification" in ServiceWorkerRegistration.prototype)) { return true; } if(Notification.permission === "denied"){ return false; } return false; } function smpush_browser() { if("safari" in window){ return "safari"; } if (navigator.userAgent.indexOf(" OPR/") >= 0) { return "opera"; } if (navigator.userAgent.indexOf("Edge") >= 0) { return "edge"; } if (navigator.userAgent.match(/chrome/i)) { return "chrome"; } if (navigator.userAgent.match(/SamsungBrowser/i)) { return "samsung"; } if (navigator.userAgent.match(/firefox/i)) { return "firefox"; } } function smpush_bootstrap_init(){ jQuery(".smpush-push-resubscribe-button").click(function() { smpush_debug("resubscribe clicked."); if(smpush_getCookie("smpush_desktop_blocked") == "true" && "native" == "subs_page"){ smpush_setCookie("smpush_desktop_blocked", "false", -1); window.location.reload(false); } }); if(settings[devicetype] == 0){ smpush_debug("Browser support is closed by admin settings"); return; } var pushSupported = smpush_test_browser(); if(! pushSupported){ smpushDrawUnSupportedPopup(); smpush_debug("Browser not support push notification"); return; } if(smpush_getCookie("smpush_desktop_request") != "true" && smpush_getCookie("smpush_desktop_blocked") != "true"){ jQuery("body").append(""); setTimeout(function(){ smpushDrawReqWindow() }, 3000); } else{ smpush_link_user_cookies(); if(0 == 1){ smpushUpdateGPS(); } } setTimeout(function(){ smpushDrawReqIcon(); if ("safari" in window) { smpushSafari(); } else { smpushGeko(); } }, 3000); } function smpushUpdateGPS(){ if(smpush_getCookie("smpush_device_token") != "" && smpush_getCookie("smart_push_smio_coords_latitude") == ""){ if (! navigator.geolocation) { smpush_debug("Geolocation is not supported for this Browser/OS."); return; } var geoSuccess = function(startPos) { smpush_debug(startPos.coords.latitude); smpush_debug(startPos.coords.longitude); smpush_setCookie("smart_push_smio_coords_latitude", startPos.coords.latitude, (1/24)); smpush_setCookie("smart_push_smio_coords_longitude", startPos.coords.longitude, (1/24)); smpush_endpoint_subscribe(smpush_getCookie("smpush_device_token"), ""); }; var geoError = function(error) { smpush_debug("Error occurred. Error code: " + error.code); /*0: unknown error, 1: permission denied, 2: position unavailable (error response from location provider), 3: timed out*/ }; navigator.geolocation.getCurrentPosition(geoSuccess); } } function smpushDestroyReqWindow(dismiss){ jQuery("#smart_push_smio_window").remove(); jQuery("#smart_push_smio_overlay").remove(); if(dismiss){ var requestAgainPeriod = 1; } else{ var requestAgainPeriod = 365; } smpush_setCookie("smpush_desktop_request", "true", requestAgainPeriod); if("0" == "2" && jQuery("#SMIOPayToReadButton").length > 0 && smpush_getCookie("smpush_device_token") != ""){ location.reload(); } } function smpushHidePopup(){ if("0" == "1"){ smpushDrawUnSupportedPopup(); } else { smpushDestroyReqWindow(true); } } function smpushDrawNotifyPopup(){ if("0" != "1")return; jQuery("#smart_push_smio_window").remove(); jQuery("#smart_push_smio_overlay").remove(); jQuery("body").append('

Telli meie teavitused ja oled alati kursis loosimiste ja teiste heade pakkumistega!

'); document.getElementById("smart_push_smio_overlay").style.opacity = "0.9"; document.getElementById("smart_push_smio_window").style.position = "fixed"; if("0" == "1"){ document.getElementById("smart_push_smio_overlay").style.display = "block"; } document.getElementById("smart_push_smio_window").style.display = "block"; document.getElementById("smart_push_smio_window").style.left = ((window.innerWidth/2) - (document.getElementById("smart_push_smio_window").offsetWidth/2)) + "px"; document.getElementById("smart_push_smio_window").style.top = ((window.innerHeight/2) - (document.getElementById("smart_push_smio_window").offsetHeight/2)) + "px"; } function smpushDrawUnSupportedPopup(){ if("0" != "1")return; jQuery("#smart_push_smio_window").remove(); jQuery("#smart_push_smio_overlay").remove(); jQuery("body").append('

Telli meie teavitused ja oled alati kursis loosimiste ja teiste heade pakkumistega!

'); document.getElementById("smart_push_smio_overlay").style.opacity = "0.9"; document.getElementById("smart_push_smio_window").style.position = "fixed"; if("0" == "1"){ document.getElementById("smart_push_smio_overlay").style.display = "block"; } document.getElementById("smart_push_smio_window").style.display = "block"; document.getElementById("smart_push_smio_window").style.left = ((window.innerWidth/2) - (document.getElementById("smart_push_smio_window").offsetWidth/2)) + "px"; document.getElementById("smart_push_smio_window").style.top = ((window.innerHeight/2) - (document.getElementById("smart_push_smio_window").offsetHeight/2)) + "px"; document.getElementById("smart_push_smio_allow").style.display = "none"; } function smpushIntializePopupBox(){ jQuery("#smart_push_smio_window").remove(); jQuery("#smart_push_smio_overlay").remove(); jQuery("body").append('

Telli meie teavitused ja oled alati kursis loosimiste ja teiste heade pakkumistega!

Sa võid igal hetkel loobuda teavitustest muutes veebilehitseja seadeid.

'); document.getElementById("smart_push_smio_overlay").style.opacity = "0.9"; document.getElementById("smart_push_smio_window").style.position = "fixed"; if("0" == "1"){ document.getElementById("smart_push_smio_overlay").style.display = "block"; } document.getElementById("smart_push_smio_window").style.display = "block"; var position = "topcenter"; if(position == "topright"){ document.getElementById("smart_push_smio_window").style.right = "10px"; document.getElementById("smart_push_smio_window").style.top = "10px"; } else if(position == "topleft"){ document.getElementById("smart_push_smio_window").style.left = "10px"; document.getElementById("smart_push_smio_window").style.top = "10px"; } else if(position == "bottomright"){ document.getElementById("smart_push_smio_window").style.bottom = "10px"; document.getElementById("smart_push_smio_window").style.right = "10px"; } else if(position == "bottomleft"){ document.getElementById("smart_push_smio_window").style.left = "10px"; document.getElementById("smart_push_smio_window").style.bottom = "10px"; } else if(position == "topcenter"){ document.getElementById("smart_push_smio_window").style.left = ((window.innerWidth/2) - (document.getElementById("smart_push_smio_window").offsetWidth/2)) + "px"; document.getElementById("smart_push_smio_window").style.top = "0"; } else{ document.getElementById("smart_push_smio_window").style.left = ((window.innerWidth/2) - (document.getElementById("smart_push_smio_window").offsetWidth/2)) + "px"; document.getElementById("smart_push_smio_window").style.top = ((window.innerHeight/2) - (document.getElementById("smart_push_smio_window").offsetHeight/2)) + "px"; } } function smpushDrawReqWindow(){ if("native" == "popup"){ smpushIntializePopupBox(); } else if("native" == "subs_page"){ } else{ if("0" == "1"){ jQuery("body").append('
'); } jQuery("body").append(""); } } function smpushDrawReqIcon(){ if("0" == "1" || smpush_getCookie("smpush_desktop_blocked") == "true"){ jQuery("body").append("

Telli meie teavitused ja oled alati kurisis heade pakkumiste ja loosimistega! Teavitused saab tühistada igal ajal.

By proceeding in this form you will receive our marketing notifications and agree to our #Privacy Policy# and #Terms of Use#

"); jQuery("body").append(""); } else if("native" == "icon" || smpush_getCookie("smpush_desktop_blocked") == "true"){ jQuery("body").append(""); } else{ return; } if("0" == "1"){ jQuery("body").append('
'); } jQuery("body").append(""); smpushTooltip(); jQuery(".smpush-push-remove-block").click(function() { smpush_debug("remove block clicked."); if(smpush_getCookie("smpush_desktop_blocked") == "true"){ smpush_setCookie("smpush_desktop_blocked", "false", -1); } }); } function smpush_link_user_cookies() { if(smpush_getCookie("smpush_fresh_linked_user") != "" && smpush_getCookie("smpush_linked_user") == "" && smpush_getCookie("smpush_device_token") != ""){ smpush_endpoint_subscribe(smpush_getCookie("smpush_device_token"), ""); smpush_setCookie("smpush_linked_user", "true", 15); smpush_setCookie("smpush_fresh_linked_user", "", -1); } } function smpushWelcomeMSG(){ if(smpush_getCookie("smpush_desktop_welcmsg_seen") == "true"){ return; } if("0" == "1"){ setTimeout(function(){ window.location=""; }, 4000); } if("0" == "0"){return;} smpush_setCookie("smpush_desktop_welcmsg_seen", "true", 365); if("safari" in window){ var n = new Notification( "", { "body": "", "tag" : "" } ); n.onclick = function () { this.close(); window.open("", "_blank"); }; } else{ navigator.serviceWorker.ready.then(function(registration) { registration.showNotification("", { icon: "", body: "", tag: "", data: {target: ""}, requireInteraction: true }); }); } } function smpush_setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/"; } function smpush_getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(";"); for(var i=0; i"); }); } function smpush_sendSubscriptionToServer(subscriptionId, old_token) { smpush_debug("sending to server...", subscriptionId); smpush_endpoint_subscribe(subscriptionId, old_token); } function smpush_unsubscribe() { smpush_setCookie("smpush_desktop_request", "true", 10); var pushButton = jQuery(".smpush-push-permission-button"); pushButton.attr("disabled", "disabled"); smpush_getScripts([ "https://www.gstatic.com/firebasejs/7.18.0/firebase-app.js", "https://www.gstatic.com/firebasejs/7.18.0/firebase-messaging.js" ], 0, function () { var smpush_firebaseConfig = JSON.parse('{"apiKey":"AIzaSyA4tLJ1NDmn8xVVbHRzwmlscvRQ9Lmli7Q","authDomain":"rufilutulestikud-ee.firebaseapp.com","databaseURL":"https://rufilutulestikud-ee.firebaseio.com","projectId":"rufilutulestikud-ee","storageBucket":"rufilutulestikud-ee.appspot.com","messagingSenderId":"316350657088","appId":"1:316350657088:web:e33cce62d40d010d51a5a5"}'); const smpushFirebase = firebase.initializeApp(smpush_firebaseConfig, "smpushFirebase"); const smpushMessaging = smpushFirebase.messaging("smpushFirebase"); navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) { smpushMessaging.useServiceWorker(serviceWorkerRegistration); smpushMessaging.getToken().then((currentToken) => { smpushMessaging.deleteToken(currentToken); smpush_endpoint_unsubscribe(currentToken); smpush_isPushEnabled = false; pushButton.removeAttr("disabled"); pushButton.html("Telli head pakkumised"); }).catch(function (e) { smpush_debug("failed unsubscribe...", e); return; }); }); }); } function smpush_getScripts2(scripts, callback) { var progress = 0; scripts.forEach(function(script) { jQuery.getScript(script, function () { if (++progress == scripts.length) callback(); }); }); } function smpush_getScripts(scripts, cursor, callback) { if(cursor === scripts.length){ callback(); return; } smpush_debug("loaded " + scripts[cursor]); jQuery.getScript(scripts[cursor], function () { smpush_getScripts(scripts, (cursor+1), callback); }); } function smpush_subscribe() { if(smpush_getCookie("smpush_desktop_blocked") == "true" && "0" == "0"){ smpush_debug("User unsubscribed using unsubscrib button"); return; } var pushButton = jQuery(".smpush-push-permission-button"); pushButton.attr("disabled","disabled"); if(firebaseInitialized){ smpush_sendSubscriptionToServer(smpush_getCookie("smpush_device_token")); return; } smpush_getScripts([ "https://www.gstatic.com/firebasejs/7.18.0/firebase-app.js", "https://www.gstatic.com/firebasejs/7.18.0/firebase-messaging.js" ], 0, function () { var smpush_firebaseConfig = JSON.parse('{"apiKey":"AIzaSyA4tLJ1NDmn8xVVbHRzwmlscvRQ9Lmli7Q","authDomain":"rufilutulestikud-ee.firebaseapp.com","databaseURL":"https://rufilutulestikud-ee.firebaseio.com","projectId":"rufilutulestikud-ee","storageBucket":"rufilutulestikud-ee.appspot.com","messagingSenderId":"316350657088","appId":"1:316350657088:web:e33cce62d40d010d51a5a5"}'); const smpushFirebase = firebase.initializeApp(smpush_firebaseConfig, "smpushFirebase"); const smpushMessaging = smpushFirebase.messaging("smpushFirebase"); firebaseInitialized = true; navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { smpushMessaging.useServiceWorker(serviceWorkerRegistration); smpushMessaging.requestPermission().then(function() { smpush_debug("Notification permission granted."); smpushMessaging.getToken().then((currentToken) => { if (currentToken) { smpush_debug("Token fetched.", currentToken); smpush_isPushEnabled = true; pushButton.html("Loobu tellimusest"); jQuery("#smpushIconRequest").smiotooltipster("content","Tühista heade pakkumiste teavitused."); pushButton.removeAttr("disabled"); if(smpush_getCookie("smpush_device_token") != "" && smpush_getCookie("smpush_device_token") != currentToken){ smpush_sendSubscriptionToServer(currentToken, smpush_getCookie("smpush_device_token")); } else if(smpush_getCookie("smpush_device_token") == "") { smpush_sendSubscriptionToServer(currentToken, ""); } } else { smpush_debug("No Instance ID token available. Request permission to generate one."); } }).catch((err) => { smpush_debug("An error occurred while retrieving token. ", err); }); }).catch(function(err) { if (Notification.permission === "denied") { smpush_isPushEnabled = false; smpush_debug("Permission for Notifications is denied"); smpushHidePopup(); pushButton.attr("disabled","disabled"); smpush_endpoint_unsubscribe(smpush_getCookie("smpush_device_token")); } else { smpush_debug(err); } }); smpushMessaging.onMessage((spayload) => { smpush_debug("Message received. ", spayload); let payload = spayload.notification; if (typeof(payload.command) != "undefined" && payload.command != "") { eval(payload.command); } serviceWorkerRegistration.showNotification(payload.title, payload); }); smpushMessaging.onTokenRefresh(() => { smpushMessaging.getToken().then((refreshedToken) => { smpush_debug("Token refreshed.", refreshedToken); smpush_sendSubscriptionToServer(currentToken, smpush_getCookie("smpush_device_token")); }).catch((err) => { smpush_debug("Unable to retrieve refreshed token ", err); }); }); }); }); } function smpush_initialiseState() { if (!("showNotification" in ServiceWorkerRegistration.prototype)) { smpush_debug("Notifications aren't supported."); return; } if (Notification.permission === "denied") { smpushHidePopup(); smpush_debug("The user has blocked notifications."); smpush_endpoint_unsubscribe(smpush_getCookie("smpush_device_token")); return; } if (!("PushManager" in window)) { smpush_debug("Push messaging isn't supported."); return; } jQuery(".smpush-push-permission-button").removeAttr("disabled"); if (Notification.permission === "granted") { smpush_subscribe(); } else if (Notification.permission === "default" && "native" == "native") { smpush_subscribe(); } } function smpushGeko(){ self.addEventListener("notificationclick", function(event) { smpush_debug("notificationclick. ", event); if (typeof(event.notification.data.click) != "undefined" && event.notification.data.click != "") { eval(event.notification.data.click); } if (typeof(event.action) != "undefined" && event.action != "") { eval(event.notification.data.actions[event.action]); return; } if(event.notification.data.target == ""){ return; } event.waitUntil(clients.matchAll({ type: "window" }).then(function(clientList) { for (let i = 0; i < clientList.length; i++) { let client = clientList[i]; if (client.url === event.notification.data.target && "focus" in client) { return client.focus(); } } if (clients.openWindow) { return clients.openWindow(event.notification.data.target); } })); event.notification.close(); }); if ("serviceWorker" in navigator) { navigator.serviceWorker.register("https://fireworks.ee/smart_firebase_sw.js").then(smpush_initialiseState).catch(function(error){ smpush_debug(error); }); } else { smpush_debug("Service workers aren't supported in this browser."); } if(jQuery(".smpush-push-permission-button").length < 1){ return false; } jQuery(".smpush-push-permission-button").click(function() { smpush_debug("clicked.", smpush_isPushEnabled); if (smpush_isPushEnabled) { smpush_unsubscribe(); } else { smpush_subscribe(); } }); jQuery(".smpush-push-subscriptions-button").click(function() { smpush_subscribe(); }); } function smpushSafari(){ var pushButton = jQuery(".smpush-push-permission-button"); pushButton.removeAttr("disabled"); if(smpush_getCookie("smpush_safari_device_token") != ""){ pushButton.html("Loobu tellimusest"); jQuery("#smpushIconRequest").smiotooltipster("content","Tühista heade pakkumiste teavitused."); } else{ pushButton.html("Telli head pakkumised"); } pushButton.click(function() { var permissionData = window.safari.pushNotification.permission(""); smpushCheckRemotePermission(permissionData); }); jQuery(".smpush-push-subscriptions-button").click(function() { var permissionData = window.safari.pushNotification.permission(""); smpushCheckRemotePermission(permissionData); }); if("native" == "native"){ document.getElementsByClassName("smpush-push-permission-button")[0].click(); } } var smpushCheckRemotePermission = function (permissionData) { var pushButton = jQuery(".smpush-push-permission-button"); if (permissionData.permission === "default") { window.safari.pushNotification.requestPermission( "https://fireworks.ee/push/safari", "", {}, smpushCheckRemotePermission ); } else if (permissionData.permission === "denied") { if(smpush_getCookie("smpush_safari_device_token") != ""){ smpush_endpoint_unsubscribe(smpush_getCookie("smpush_safari_device_token")); } smpush_setCookie("smpush_desktop_request", "true", 10); smpush_setCookie("smpush_safari_device_token", "false", -1); smpush_setCookie("smpush_device_token", "false", -1); smpushHidePopup(); } else if (permissionData.permission === "granted") { smpushDestroyReqWindow(false); if(smpush_getCookie("smpush_safari_device_token") != ""){ smpush_endpoint_unsubscribe(smpush_getCookie("smpush_safari_device_token")); smpush_setCookie("smpush_desktop_request", "true", 10); smpush_setCookie("smpush_safari_device_token", "false", -1); smpush_setCookie("smpush_device_token", "false", -1); smpush_setCookie("smpush_desktop_welcmsg_seen", "false", -1); pushButton.attr("disabled","disabled"); jQuery(".smpush-push-subscriptions-button").attr("disabled","disabled"); jQuery(".smpush-push-subscriptions-button").html("Salvestatud"); } else{ if(smpush_getCookie("smpush_safari_device_token") == ""){ smpush_setCookie("smpush_safari_device_token", permissionData.deviceToken, 365); smpush_endpoint_subscribe(permissionData.deviceToken, ""); } else{ smpushDestroyReqWindow(false); } pushButton.attr("disabled","disabled"); jQuery(".smpush-push-subscriptions-button").attr("disabled","disabled"); jQuery(".smpush-push-subscriptions-button").html("Salvestatud"); } } };