Changeset 2876443
- Timestamp:
- 03/08/2023 11:49:32 AM (3 years ago)
- Location:
- viaads
- Files:
-
- 16 added
- 9 edited
-
tags/1.1.6 (added)
-
tags/1.1.6/apikey.php (added)
-
tags/1.1.6/externalJS.php (added)
-
tags/1.1.6/handleEmailGuid.php (added)
-
tags/1.1.6/hooks (added)
-
tags/1.1.6/hooks/addCart.php (added)
-
tags/1.1.6/hooks/orderHooks.php (added)
-
tags/1.1.6/hooks/pageLook.php (added)
-
tags/1.1.6/hooks/removeCart.php (added)
-
tags/1.1.6/http.php (added)
-
tags/1.1.6/js (added)
-
tags/1.1.6/js/viaads_handleEmailGuid.js (added)
-
tags/1.1.6/readme.txt (added)
-
tags/1.1.6/sync.php (added)
-
tags/1.1.6/userAgent.php (added)
-
tags/1.1.6/viaads.php (added)
-
trunk/hooks/addCart.php (modified) (2 diffs)
-
trunk/hooks/orderHooks.php (modified) (4 diffs)
-
trunk/hooks/pageLook.php (modified) (2 diffs)
-
trunk/hooks/removeCart.php (modified) (2 diffs)
-
trunk/js/viaads_handleEmailGuid.js (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/sync.php (modified) (10 diffs)
-
trunk/userAgent.php (modified) (4 diffs)
-
trunk/viaads.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
viaads/trunk/hooks/addCart.php
r2850359 r2876443 24 24 } 25 25 26 //guid//email//emailGuid 27 if(!isset($_COOKIE[ 'ViaAds' ])) { 26 //Checking for cookie consent 27 $cookieValues = json_decode(base64_decode($_COOKIE['via_ads'])); 28 if (!$cookieValues->Consent) { 28 29 return; 29 30 } 30 $cookieValue = sanitize_text_field($_COOKIE[ 'ViaAds' ]);31 31 32 $cookieValues = explode( "//", $cookieValue );33 32 $data = new stdClass(); 34 33 … … 58 57 global $current_user; 59 58 get_currentuserinfo(); 60 $email = ( string )$current_user->user_email;59 $email = strtolower(( string )$current_user->user_email); 61 60 $customer = new stdClass(); 62 61 if ( strlen( $email ) > 4 ) { 63 62 $customer->Email = $email; 64 63 } else { 65 $customer->Email = $cookieValues[ 1 ];64 $customer->Email = strtolower($cookieValues->Email); 66 65 } 67 66 68 $customer->Session_id = $cookieValues[ 0 ]; 69 $customer->Email_guid = $cookieValues[ 2 ]; 67 $customer->Session_id = $cookieValues->Session; 68 $customer->Email_guid = $cookieValues->EG; 69 $customer->Fingerprint = $cookieValues->FP; 70 $customer->Fingerprint_old = $cookieValues->FPOld; 71 $customer->Fingerprint_raw = $cookieValues->FPRaw; 70 72 $data->customer = $customer; 71 73 -
viaads/trunk/hooks/orderHooks.php
r2866634 r2876443 23 23 } 24 24 25 if (isset($_COOKIE['ViaAds'])) {26 $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);27 $cookieValues = explode("//", $cookieValue);28 setcookie(" ViaAds", $cookieValues[0] . "//" . $order->get_billing_email() . "//" . $cookieValues[2], time() + (34560000), "/");25 $cookieValues = json_decode(base64_decode($_COOKIE['via_ads'])); 26 if ($cookieValues->Consent) { 27 $cookieValues->Email = strtolower($order->get_billing_email()); 28 setcookie("via_ads", base64_encode(json_encode($cookieValues)), time() + (34560000), "/"); 29 29 } 30 30 … … 67 67 $order_billing_address->country = $order->get_billing_country(); 68 68 $order_billing_address->phone_number = $order->get_billing_phone(); 69 $order_billing_address->email = $order->get_billing_email();69 $order_billing_address->email = strtolower($order->get_billing_email()); 70 70 $order_object->Billing_address = $order_billing_address; 71 71 … … 81 81 $order_shipping_address->country = $order->get_shipping_country(); 82 82 $order_shipping_address->phone_number = $order->get_shipping_phone(); 83 $order_shipping_address->email = $order->get_billing_email();83 $order_shipping_address->email = strtolower($order->get_billing_email()); 84 84 $order_object->Shipping_address = $order_shipping_address; 85 85 … … 150 150 // Customer 151 151 $customer = new stdClass(); 152 $customer->Email = $order->get_billing_email();152 $customer->Email = strtolower($order->get_billing_email()); 153 153 $orderFinal->customer = $customer; 154 154 -
viaads/trunk/hooks/pageLook.php
r2858453 r2876443 24 24 $product = wc_get_product($product_id); 25 25 26 //guid//email//emailGuid 27 if (!isset($_COOKIE['ViaAds'])) { 26 //Checking for cookie consent 27 $cookieValues = json_decode(base64_decode($_COOKIE['via_ads'])); 28 if (!$cookieValues->Consent) { 28 29 return; 29 30 } 30 31 31 $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);32 33 $cookieValues = explode("//", $cookieValue);34 32 $data = new stdClass(); 35 33 … … 59 57 global $current_user; 60 58 get_currentuserinfo(); 61 $email = ( string )$current_user->user_email;59 $email = strtolower(( string )$current_user->user_email); 62 60 $customer = new stdClass(); 63 61 if (strlen($email) > 4) { 64 62 $customer->Email = $email; 65 63 } else { 66 $customer->Email = $cookieValues[1];64 $customer->Email = strtolower($cookieValues->Email); 67 65 } 68 66 69 $customer->Session_id = $cookieValues[0]; 70 $customer->Email_guid = $cookieValues[2]; 67 $customer->Session_id = $cookieValues->Session; 68 $customer->Email_guid = $cookieValues->EG; 69 $customer->Fingerprint = $cookieValues->FP; 70 $customer->Fingerprint_old = $cookieValues->FPOld; 71 $customer->Fingerprint_raw = $cookieValues->FPRaw; 71 72 $data->Customer = $customer; 72 73 -
viaads/trunk/hooks/removeCart.php
r2850359 r2876443 27 27 } 28 28 29 //guid//email//emailGuid 30 if (!isset($_COOKIE['ViaAds'])) { 29 //Checking for cookie consent 30 $cookieValues = json_decode(base64_decode($_COOKIE['via_ads'])); 31 if (!$cookieValues->Consent) { 31 32 return; 32 33 } 33 34 34 $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);35 36 $cookieValues = explode("//", $cookieValue);37 35 $data = new stdClass(); 38 36 … … 62 60 global $current_user; 63 61 get_currentuserinfo(); 64 $email = ( string )$current_user->user_email;62 $email = strtolower(( string )$current_user->user_email); 65 63 $customer = new stdClass(); 66 64 if (strlen($email) > 4) { 67 65 $customer->Email = $email; 68 66 } else { 69 $customer->Email = $cookieValues[1];67 $customer->Email = strtolower($cookieValues->Email); 70 68 } 71 69 72 $customer->Session_id = $cookieValues[0]; 73 $customer->Email_guid = $cookieValues[2]; 70 $customer->Session_id = $cookieValues->Session; 71 $customer->Email_guid = $cookieValues->EG; 72 $customer->Fingerprint = $cookieValues->FP; 73 $customer->Fingerprint_old = $cookieValues->FPOld; 74 $customer->Fingerprint_raw = $cookieValues->FPRaw; 74 75 $data->customer = $customer; 75 76 -
viaads/trunk/js/viaads_handleEmailGuid.js
r2866883 r2876443 1 setDefaultCookie(); 1 try { 2 setDefaultCookie(); 2 3 3 if (window.location.search.includes("emailGuid=")) { 4 setInterval(function () { 5 let cookieAaccept = getCookie("ViaAds"); 6 if (cookieAaccept != undefined) { 7 setDefaultCookie(); 8 //guid//email//emailGuid 9 var cookieValues = cookieAaccept.split("//"); 10 var guid = cookieValues[0]; 11 if (guid == ""){ 12 guid = uuidv4(); 4 let cookieAccept = getCookie("via_ads"); 5 if (cookieAccept != undefined) { 6 //Check redirected from email 7 checkEmailGuid(); 8 } 9 10 function setDefaultCookie() { 11 let cookieAccept = getCookie("via_ads"); 12 if (cookieAccept == undefined) { 13 let email = ""; 14 let eg = ""; 15 16 let oldCookie = getCookie("ViaAds"); 17 if (oldCookie != undefined) { 18 let cookieValues = oldCookie.split("//"); 19 email = cookieValues[1] != undefined ? cookieValues[1] : ""; 20 eg = cookieValues[2] != undefined ? cookieValues[2] : ""; 21 document.cookie = 'ViaAds=; Max-Age=0; Path=/;'; 13 22 } 14 15 var mail = cookieValues[1]; 16 if (mail == "undefined"){ 17 mail = ""; 23 24 //Basic cookie 25 let cookie = { 26 Consent: false, 27 Session: uuidv4(), 28 Email: email.toLowerCase(), 29 EG: eg, 30 FP: "", 31 FPU: "", 32 FPOld: "", 33 FPRaw: "" 18 34 } 19 20 document.cookie = "ViaAds=" + guid + "//" + mail + "//" + window.location.search.split("emailGuid=")[1] + "; max-age=34560000; path=/;";21 }22 }, 2000);23 }24 35 25 function setDefaultCookie() { 26 let cookieAaccept = getCookie("ViaAds"); 27 if (cookieAaccept != undefined) { 28 if (cookieAaccept == "") { 29 document.cookie = "ViaAds=" + uuidv4() + "////; max-age=34560000; path=/;"; 36 fingerPrint(cookie); 37 } else { 38 let cookie = JSON.parse(atob(cookieAccept)); 39 //Check time for last fingerPrint update 40 const date1Timestamp = cookie.FPU; 41 const date2Timestamp = new Date().getTime() / 1000; 42 const difference = date2Timestamp - date1Timestamp; 43 const differenceInDays = Math.abs(difference / (60 * 60 * 24)); 44 //if (differenceInDays >= 3) { 45 fingerPrint(cookie); 46 //} 30 47 } 31 48 } 49 50 function getCookie(name) { 51 const value = `; ${document.cookie}`; 52 const parts = value.split(`; ${name}=`); 53 if (parts.length === 2) return decodeURIComponent(parts.pop().split(';').shift()); 54 } 55 56 function uuidv4() { 57 return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => 58 (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) 59 ); 60 } 61 62 function fingerPrint(cookie) { 63 let userAgent = navigator.userAgent; 64 let platForm = window.navigator.platform; 65 let cookieEnabled = window.navigator.cookieEnabled; 66 let timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; 67 let language = navigator.language; 68 let doNotTrack = window.navigator.doNotTrack; 69 let vendor = window.navigator.vendor; 70 let hardwareConcurrency = window.navigator.hardwareConcurrency; 71 //let acceptHeaders = na 72 console.log(userAgent); 73 74 //Audio 75 const audioContext = new (window.AudioContext || window.webkitAudioContext)(); 76 let audio = `${audioContext.destination.channelCount}|${audioContext.destination.channelCountMode}|${audioContext.destination.channelInterpretation}|`; 77 audio += `${audioContext.destination.maxChannelCount}|${audioContext.destination.numberOfInputs}|${audioContext.destination.numberOfOutputs}|`; 78 audio += `${audioContext.sampleRate}|${audioContext.state}`; 79 80 //Canvas 81 let canvas = canvasFingerPrint(); 82 let fingerPrint = `${userAgent}${platForm}${cookieEnabled}${timeZone}${language}${doNotTrack}${vendor}${hardwareConcurrency}${audio}${canvas}`; 83 hashFingerPrint(fingerPrint).then(r => { 84 if (cookie.FP != ""){ 85 cookie.FPOld = cookie.FP; 86 } 87 cookie.FP = r; 88 cookie.FPRaw = fingerPrint; 89 cookie.FPU = new Date().getTime() / 1000; 90 document.cookie = "via_ads=" + btoa(JSON.stringify(cookie)) + "; max-age=34560000; path=/;"; 91 //Check redirected from email 92 checkEmailGuid(); 93 }); 94 } 95 96 async function hashFingerPrint(message) { 97 const msgUint8 = new TextEncoder().encode(message); 98 const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); 99 const hashArray = Array.from(new Uint8Array(hashBuffer)); 100 const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); 101 return hashHex; 102 } 103 104 function canvasFingerPrint() { 105 const canvas = document.createElement("canvas"); 106 const ctx = canvas.getContext("2d"); 107 ctx.fillStyle = "rgb(255,0,255)"; 108 ctx.beginPath(); 109 ctx.rect(20, 20, 150, 100); 110 ctx.fill(); 111 ctx.stroke(); 112 ctx.closePath(); 113 ctx.beginPath(); 114 ctx.fillStyle = "rgb(0,255,255)"; 115 ctx.arc(50, 50, 50, 0, Math.PI * 2, true); 116 ctx.fill(); 117 ctx.stroke(); 118 ctx.closePath(); 119 120 txt = 'abz190#$%^@£éú'; 121 ctx.textBaseline = "top"; 122 ctx.font = '17px "Arial 17"'; 123 ctx.textBaseline = "alphabetic"; 124 ctx.fillStyle = "rgb(255,5,5)"; 125 ctx.rotate(.03); 126 ctx.fillText(txt, 4, 17); 127 ctx.fillStyle = "rgb(155,255,5)"; 128 ctx.shadowBlur=8; 129 ctx.shadowColor="red"; 130 ctx.fillRect(20,12,100,5); 131 132 // hashing function 133 src = canvas.toDataURL(); 134 hash = 0; 135 136 for (i = 0; i < src.length; i++) { 137 char = src.charCodeAt(i); 138 hash = ((hash<<5)-hash)+char; 139 hash = hash & hash; 140 } 141 142 return hash; 143 } 144 145 function checkEmailGuid() { 146 if (window.location.search.includes("emailGuid=")) { 147 let cookieAccept = getCookie("via_ads"); 148 let cookie = JSON.parse(atob(cookieAccept)); 149 cookie.EG = window.location.search.split("emailGuid=")[1]; 150 document.cookie = "via_ads=" + btoa(JSON.stringify(cookie)) + "; max-age=34560000; path=/;"; 151 } 152 } 153 } catch (err) { 154 let error = { 155 Error: err, 156 Url: window.location.href 157 } 158 const url = "https://integration.viaads.dk/error" 159 let xhr = new XMLHttpRequest() 160 xhr.open('POST', url, true) 161 xhr.setRequestHeader('Content-type', 'application/json;') 162 xhr.send(JSON.stringify(error)); 32 163 } 33 34 function getCookie(name) {35 const value = `; ${document.cookie}`;36 const parts = value.split(`; ${name}=`);37 if (parts.length === 2) return parts.pop().split(';').shift();38 }39 40 function uuidv4() {41 return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>42 (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)43 );44 } -
viaads/trunk/readme.txt
r2869496 r2876443 4 4 Requires at least: 5.4 5 5 Tested up to: 6.1 6 Stable tag: 1.1. 56 Stable tag: 1.1.6 7 7 Requires PHP: 7.0 8 8 License: GPLv3 -
viaads/trunk/sync.php
r2869496 r2876443 5 5 use stdClass; 6 6 use DateTime; 7 use DateTimeZone;8 7 use Exception; 9 8 use WC_Product_Factory; … … 86 85 foreach ($productCollection as $product) { 87 86 $product_object = new stdClass(); 87 // Product Id 88 88 $product_object->WebshopProductId = "{$product->get_id()}"; 89 // Image 89 // Images 90 90 $imageArray = array(); 91 91 $image_object = new stdClass(); … … 118 118 } 119 119 $product_object->Categories = $categories; 120 120 // Review Count 121 121 $product_object->RatingCount = $product->get_review_count(); 122 // Rating 122 123 $product_object->AverageRating = $product->get_average_rating(); 124 // Name 123 125 $product_object->Name = $product->get_name(); 126 // Permalink 124 127 $product_object->Permalink = get_permalink($product->get_id()); 125 128 // SKU … … 140 143 $product_object->RelatedProductIds = []; 141 144 // Up Sell Product Ids 142 $product_object->UpSellProductIds = $product->get_upsell_ids();145 $product_object->UpSellProductIds = array_map('strval', $product->get_upsell_ids()); 143 146 // Cross Sell Product Ids 144 $product_object->CrossSellProductIds = $product->get_cross_sell_ids();147 $product_object->CrossSellProductIds = array_map('strval', $product->get_cross_sell_ids()); 145 148 // Slug 146 149 $product_object->Slug = $product->get_slug(); … … 323 326 } 324 327 325 //Test326 /*$orderCollection = wc_get_orders( array(327 'date_modified' => date( 'Y-m-d', strtotime( date( "Y-m-d" ) . ' - 30 days' ) ) . '...'328 . date( 'Y-m-d', strtotime( date( "Y-m-d" ) . ' + 14 days' ) ),329 ) );*/330 331 328 $orders = []; 332 329 foreach ($orderCollection as $order) { … … 357 354 $order_object->vat_percentage = $vat_percentage; 358 355 359 360 356 // Last Modified 361 357 $lastModifiedGmt = new DateTime($order->get_date_modified()); … … 372 368 $order_billing_address->country = $order->get_billing_country(); 373 369 $order_billing_address->phone_number = $order->get_billing_phone(); 374 $order_billing_address->email = $order->get_billing_email();370 $order_billing_address->email = strtolower($order->get_billing_email()); 375 371 $order_object->Billing_address = $order_billing_address; 376 377 372 378 373 // Shipping Address … … 386 381 $order_shipping_address->country = $order->get_shipping_country(); 387 382 $order_shipping_address->phone_number = $order->get_shipping_phone(); 388 $order_shipping_address->email = $order->get_billing_email();383 $order_shipping_address->email = strtolower($order->get_billing_email()); 389 384 $order_object->Shipping_address = $order_shipping_address; 390 385 … … 415 410 $order_item_object->Sku = $item->get_product()->get_sku(); 416 411 // Price 417 //$order_item_object->Price = number_format( $item->get_subtotal() / $item->get_quantity(), 2, ".", "" );418 412 $order_item_object->Price = $item->get_subtotal() / $item->get_quantity(); 419 413 // Quantity 420 414 $order_item_object->Quantity = round($item->get_quantity()); 421 415 // Total 422 //$order_item_object->Total_price = number_format( $item->get_total(), 2, ".", "" );423 416 $order_item_object->Total_price = $item->get_total(); 424 // $order_item_object->Total_price_tax = number_format( $item->get_total_tax(), 2, ".", "" );417 // Total Tax 425 418 $order_item_object->Total_price_tax = $item->get_total_tax(); 426 // $order_item_object->Total_price_tax_included = number_format( $item->get_total() + $item->get_total_tax(), 2, ".", "" );419 // Total Tax included 427 420 $order_item_object->Total_price_tax_included = $item->get_total() + $item->get_total_tax(); 428 421 429 430 422 // Refunds 431 423 if(count($refundItems) > 0) { 432 424 foreach ($refundItems as $refund) { … … 456 448 // Customer 457 449 $customer = new stdClass(); 458 $customer->Email = $order->get_billing_email();450 $customer->Email = strtolower($order->get_billing_email()); 459 451 $orderFinal->customer = $customer; 460 452 -
viaads/trunk/userAgent.php
r2831385 r2876443 11 11 $version = ""; 12 12 13 // First get the platform?13 // Platform 14 14 if ( preg_match( '/linux/i', $u_agent ) ) { 15 15 $platform = 'linux'; … … 21 21 } 22 22 23 // Next get the name of the useragent yes seperately and for good reason23 // Useragent name 24 24 if ( preg_match( '/MSIE/i', $u_agent ) && !preg_match( '/Opera/i', $u_agent ) ) { 25 25 $bname = 'Internet Explorer'; … … 46 46 } 47 47 48 // finally get the correct version number48 // Version number 49 49 $known = array( 'Version', $ub, 'other' ); 50 50 $pattern = '#(?<browser>' . join( '|', $known ) . … … 54 54 } 55 55 56 // see how many we have57 56 $i = count( $matches[ 'browser' ] ); 58 57 if ( $i != 1 ) { 59 //we will have two since we are not using 'other' argument yet60 58 //see if version is before or after the name 61 59 if ( strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub ) ) { -
viaads/trunk/viaads.php
r2869496 r2876443 3 3 * Plugin Name: ViaAds 4 4 * Description: Plugin der muliggør forbindelsen til ViaAds / Plug-in enabling the connection to ViaAds. 5 * Version: 1.1. 55 * Version: 1.1.6 6 6 * Author: ViaAds 7 7 * Author URI: https://www.viaads.dk/ … … 10 10 **/ 11 11 12 /* 13 ViaAds is free software: you can redistribute it and/or modify14 it under the terms of the GNU General Public License as published by15 the Free Software Foundation, either version 2 of the License, or16 any later version.17 18 ViaAds is distributed in the hope that it will be useful,19 but WITHOUT ANY WARRANTY; without even the implied warranty of20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21 GNU General Public License for more details.22 23 You should have received a copy of the GNU General Public License24 along with ViaAds. If not, see https://www.gnu.org/licenses/gpl-2.0.html.25 */12 /** 13 * ViaAds is free software: you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation, either version 2 of the License, or 16 * any later version. 17 * 18 * ViaAds is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with ViaAds. If not, see https://www.gnu.org/licenses/gpl-2.0.html. 25 */ 26 26 27 27 namespace ViaAds; … … 44 44 include(plugin_dir_path(__FILE__) . 'hooks/orderHooks.php'); 45 45 } 46 ?>
Note: See TracChangeset
for help on using the changeset viewer.