Plugin Directory

Changeset 2876443


Ignore:
Timestamp:
03/08/2023 11:49:32 AM (3 years ago)
Author:
viaads
Message:

Small Object Changes

Location:
viaads
Files:
16 added
9 edited

Legend:

Unmodified
Added
Removed
  • viaads/trunk/hooks/addCart.php

    r2850359 r2876443  
    2424        }
    2525
    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) {
    2829            return;
    2930        }
    30         $cookieValue = sanitize_text_field($_COOKIE[ 'ViaAds' ]);
    3131
    32         $cookieValues = explode( "//", $cookieValue );
    3332        $data = new stdClass();
    3433
     
    5857        global $current_user;
    5958        get_currentuserinfo();
    60         $email = ( string )$current_user->user_email;
     59        $email = strtolower(( string )$current_user->user_email);
    6160        $customer = new stdClass();
    6261        if ( strlen( $email ) > 4 ) {
    6362            $customer->Email = $email;
    6463        } else {
    65             $customer->Email = $cookieValues[ 1 ];
     64            $customer->Email = strtolower($cookieValues->Email);
    6665        }
    6766
    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;
    7072        $data->customer = $customer;
    7173
  • viaads/trunk/hooks/orderHooks.php

    r2866634 r2876443  
    2323        }
    2424
    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), "/");
    2929        }
    3030
     
    6767        $order_billing_address->country = $order->get_billing_country();
    6868        $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());
    7070        $order_object->Billing_address = $order_billing_address;
    7171
     
    8181        $order_shipping_address->country = $order->get_shipping_country();
    8282        $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());
    8484        $order_object->Shipping_address = $order_shipping_address;
    8585
     
    150150        // Customer
    151151        $customer = new stdClass();
    152         $customer->Email = $order->get_billing_email();
     152        $customer->Email = strtolower($order->get_billing_email());
    153153        $orderFinal->customer = $customer;
    154154
  • viaads/trunk/hooks/pageLook.php

    r2858453 r2876443  
    2424        $product = wc_get_product($product_id);
    2525
    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) {
    2829            return;
    2930        }
    3031
    31         $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);
    32 
    33         $cookieValues = explode("//", $cookieValue);
    3432        $data = new stdClass();
    3533
     
    5957        global $current_user;
    6058        get_currentuserinfo();
    61         $email = ( string )$current_user->user_email;
     59        $email = strtolower(( string )$current_user->user_email);
    6260        $customer = new stdClass();
    6361        if (strlen($email) > 4) {
    6462            $customer->Email = $email;
    6563        } else {
    66             $customer->Email = $cookieValues[1];
     64            $customer->Email = strtolower($cookieValues->Email);
    6765        }
    6866
    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;
    7172        $data->Customer = $customer;
    7273
  • viaads/trunk/hooks/removeCart.php

    r2850359 r2876443  
    2727        }
    2828
    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) {
    3132            return;
    3233        }
    3334
    34         $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);
    35 
    36         $cookieValues = explode("//", $cookieValue);
    3735        $data = new stdClass();
    3836
     
    6260        global $current_user;
    6361        get_currentuserinfo();
    64         $email = ( string )$current_user->user_email;
     62        $email = strtolower(( string )$current_user->user_email);
    6563        $customer = new stdClass();
    6664        if (strlen($email) > 4) {
    6765            $customer->Email = $email;
    6866        } else {
    69             $customer->Email = $cookieValues[1];
     67            $customer->Email = strtolower($cookieValues->Email);
    7068        }
    7169
    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;
    7475        $data->customer = $customer;
    7576
  • viaads/trunk/js/viaads_handleEmailGuid.js

    r2866883 r2876443  
    1 setDefaultCookie();
     1try {
     2    setDefaultCookie();
    23
    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=/;';
    1322            }
    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: ""
    1834            }
    19            
    20             document.cookie = "ViaAds=" + guid + "//" + mail + "//" + window.location.search.split("emailGuid=")[1] + "; max-age=34560000; path=/;";
    21         }
    22     }, 2000);
    23 }
    2435
    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            //}
    3047        }
    3148    }
     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));
    32163}
    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  
    44Requires at least: 5.4
    55Tested up to: 6.1
    6 Stable tag: 1.1.5
     6Stable tag: 1.1.6
    77Requires PHP: 7.0
    88License: GPLv3
  • viaads/trunk/sync.php

    r2869496 r2876443  
    55use stdClass;
    66use DateTime;
    7 use DateTimeZone;
    87use Exception;
    98use WC_Product_Factory;
     
    8685    foreach ($productCollection as $product) {
    8786        $product_object = new stdClass();
     87        // Product Id
    8888        $product_object->WebshopProductId = "{$product->get_id()}";
    89         // Image
     89        // Images
    9090        $imageArray = array();
    9191        $image_object = new stdClass();
     
    118118        }
    119119        $product_object->Categories = $categories;
    120 
     120        // Review Count
    121121        $product_object->RatingCount = $product->get_review_count();
     122        // Rating
    122123        $product_object->AverageRating = $product->get_average_rating();
     124        // Name
    123125        $product_object->Name = $product->get_name();
     126        // Permalink
    124127        $product_object->Permalink = get_permalink($product->get_id());
    125128        // SKU
     
    140143        $product_object->RelatedProductIds = [];
    141144        // Up Sell Product Ids
    142         $product_object->UpSellProductIds = $product->get_upsell_ids();
     145        $product_object->UpSellProductIds = array_map('strval', $product->get_upsell_ids());
    143146        // 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());
    145148        // Slug
    146149        $product_object->Slug = $product->get_slug();
     
    323326    }
    324327
    325     //Test
    326     /*$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 
    331328    $orders = [];
    332329    foreach ($orderCollection as $order) {
     
    357354            $order_object->vat_percentage = $vat_percentage;
    358355
    359 
    360356            // Last Modified
    361357            $lastModifiedGmt = new DateTime($order->get_date_modified());
     
    372368            $order_billing_address->country = $order->get_billing_country();
    373369            $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());
    375371            $order_object->Billing_address = $order_billing_address;
    376 
    377372
    378373            // Shipping Address
     
    386381            $order_shipping_address->country = $order->get_shipping_country();
    387382            $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());
    389384            $order_object->Shipping_address = $order_shipping_address;
    390385
     
    415410                $order_item_object->Sku = $item->get_product()->get_sku();
    416411                // Price
    417                 //$order_item_object->Price = number_format( $item->get_subtotal() / $item->get_quantity(), 2, ".", "" );
    418412                $order_item_object->Price = $item->get_subtotal() / $item->get_quantity();
    419413                // Quantity
    420414                $order_item_object->Quantity = round($item->get_quantity());
    421415                // Total
    422                 //$order_item_object->Total_price = number_format( $item->get_total(), 2, ".", "" );
    423416                $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
    425418                $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
    427420                $order_item_object->Total_price_tax_included = $item->get_total() + $item->get_total_tax();
    428421
    429 
    430 
     422                // Refunds
    431423                if(count($refundItems) > 0) {
    432424                    foreach ($refundItems as $refund) {
     
    456448            // Customer
    457449            $customer = new stdClass();
    458             $customer->Email = $order->get_billing_email();
     450            $customer->Email = strtolower($order->get_billing_email());
    459451            $orderFinal->customer = $customer;
    460452
  • viaads/trunk/userAgent.php

    r2831385 r2876443  
    1111    $version = "";
    1212
    13     //First get the platform?
     13    // Platform
    1414    if ( preg_match( '/linux/i', $u_agent ) ) {
    1515        $platform = 'linux';
     
    2121    }
    2222
    23     // Next get the name of the useragent yes seperately and for good reason
     23    // Useragent name
    2424    if ( preg_match( '/MSIE/i', $u_agent ) && !preg_match( '/Opera/i', $u_agent ) ) {
    2525        $bname = 'Internet Explorer';
     
    4646    }
    4747
    48     // finally get the correct version number
     48    // Version number
    4949    $known = array( 'Version', $ub, 'other' );
    5050    $pattern = '#(?<browser>' . join( '|', $known ) .
     
    5454    }
    5555
    56     // see how many we have
    5756    $i = count( $matches[ 'browser' ] );
    5857    if ( $i != 1 ) {
    59         //we will have two since we are not using 'other' argument yet
    6058        //see if version is before or after the name
    6159        if ( strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub ) ) {
  • viaads/trunk/viaads.php

    r2869496 r2876443  
    33 * Plugin Name: ViaAds
    44 * Description: Plugin der muliggør forbindelsen til ViaAds / Plug-in enabling the connection to ViaAds.
    5  * Version: 1.1.5
     5 * Version: 1.1.6
    66 * Author: ViaAds
    77 * Author URI: https://www.viaads.dk/
     
    1010 **/
    1111
    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 */
     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 */
    2626
    2727namespace ViaAds;
     
    4444    include(plugin_dir_path(__FILE__) . 'hooks/orderHooks.php');
    4545}
    46 ?>
Note: See TracChangeset for help on using the changeset viewer.