" . $foundedCustomFields." Te ne tolgo ". $customFieldsChars); //Verify if an email field exist $foundedCustomEmailFields+=substr_count($message, "{email}"); $tempMessage=preg_replace("/{email}/", "", $tempMessage); $customEmailChars = $foundedCustomEmailFields*$persFieldEmailChars; if ($DEBUG == 1) error_log(" @ email pers => " . $foundedCustomEmailFields." Te ne tolgo: ".$customEmailChars); //Verify if a coupon exist if ($paramsToCheckMessage['coupon'] == 1) { $customCouponChars = $couponChars; } //Verify if a tool is selcted if ($paramsToCheckMessage['tool'] !='') { //Get tool type switch ($paramsToCheckMessage['tool']) { case strpos($paramsToCheckMessage['tool'], 'land') !== false: $tool = 'landing'; break; case strpos($paramsToCheckMessage['tool'], 'story') !== false: $tool = 'storytelling'; break; case strpos($paramsToCheckMessage['tool'], 'chat') !== false: $tool = 'chatBot'; break; case strpos($paramsToCheckMessage['tool'], 'movieTellings') !== false: $tool = 'movietelling'; case strpos($paramsToCheckMessage['tool'], 'optin') !== false: $tool = 'optin'; break; case strpos($paramsToCheckMessage['tool'], 'virtualAssistant') !== false: $tool = 'virtualAssistant'; break; } // Count chars to remove for this tool if ($paramsToCheckMessage['isAdaACtive']==1) { $toolAdditionalChars = $paramsToCheckMessage['adaShortlinkReservation']; } if( $tool == 'virtualAssistant' ){ $toolAdditionalChars = $paramsToCheckMessage[ 'virtualAssistantTrackLength' ]; } $foundedShortLinkFields+=substr_count($message, "{shortlink}"); // Set landingPage for sendingForMarketingApproval if($paramsToCheckMessage['mode'] == "sendingForMarketingApproval" && $foundedShortLinkFields == 0){ $foundedShortLinkFields = 1; } switch ($tool) { case 'landing': case 'landingPages': $toolFieldsChar = ($paramsToCheckMessage['landingDomainLenght'] + $toolAdditionalChars) * $foundedShortLinkFields; break; case 'storytelling': $toolFieldsChar = ($paramsToCheckMessage['stDomainLenght'] + $toolAdditionalChars) * $foundedShortLinkFields; break; case 'chatBot': $toolFieldsChar = ($paramsToCheckMessage['chatBotDomainLenght'] + $toolAdditionalChars) * $foundedShortLinkFields; break; case 'movietelling': $toolFieldsChar = ($paramsToCheckMessage['movieTellingDomainLenght'] + $toolAdditionalChars) * $foundedShortLinkFields; break; case 'virtualAssistant': $toolFieldsChar = ($paramsToCheckMessage['virtualAssistantDomainLenght'] + $toolAdditionalChars) * $foundedShortLinkFields; break; } $tempMessage = preg_replace("/{shortlink}/", "", $tempMessage); if ($DEBUG == 1) error_log("@ shortlink => " .$tool. " reserv => ".$toolAdditionalChars." ne tolgo => ".$toolFieldsChar); } $tempMessage=preg_replace(PATTERN_DOUBLE_CHAR, "XX", $tempMessage); // se lo user è francese ed non è stato inserito lo STOP 36173 nel corpo del messaggio if ($paramsToCheckMessage['userLanguage'] == 'fr' && !in_array("stopSms", $paramsToCheckMessage)) { $maxChars -= 11; } $messageLength = $maxChars - (mb_strlen($tempMessage, 'UTF-8') + $customFieldsChars + $customEmailChars + $toolFieldsChar + $customCouponChars); return $messageLength; } } function hex2rgba($color, $opacity = false) { $default = 'rgb(0,0,0)'; //Return default if no color provided if(empty($color)) return $default; //Sanitize $color if "#" is provided if ($color[0] == '#' ) { $color = substr( $color, 1 ); } //Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } //Convert hexadec to rgb $rgb = array_map('hexdec', $hex); //Check if opacity is set(rgba or rgb) if($opacity){ if(abs($opacity) > 1) $opacity = 1.0; $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; } else { $output = 'rgb('.implode(",",$rgb).')'; } //Return rgb(a) color string return $output; } function haveAdaActive($idPersonalData){ global $db; require_once(__DIR__.'/../classes/Memoizer.php'); require_once(__DIR__.'/../lib/Apcu.php'); $apcu = new \ApcWrapper(); $memoizer = new Memoizer\Memoizer($apcu); $ttlPhpCache = 60 * 30; // 30 minuti $keyPhpCache = "common_".$idPersonalData."_haveAdaActive"; $modulesPermission = $memoizer->memoize($keyPhpCache, $ttlPhpCache, function() use($db, $idPersonalData) { $modules = array("adaSubscription"); $sql = "SELECT * FROM modulesPermission INNER JOIN modulesType ON modulesPermission.idModulesType=modulesType.id INNER JOIN modules ON modulesType.idModule=modules.id WHERE modulesPermission.idPersonalData=:idPersonalData AND tag IN (:tag) AND (expirationDate >= DATE(now()) OR expirationDate IS NULL)"; $modulesPermission = $db ->query($sql,array("idPersonalData" => $idPersonalData, "tag" => $modules))->num_rows(); return $modulesPermission; }); if($modulesPermission==0){ return false; } else { return true; } } function addMetaDataToImg($src, $client){ $src = parse_url($src, PHP_URL_PATH); if (!$client->doesObjectExist(S3_BUCKET_NAME, $src)) { return; } $data = $client->getObject(array( 'Bucket' => S3_BUCKET_NAME, 'Key' => $src ) ); $request = array( 'Bucket' => S3_BUCKET_NAME, 'Key' => $src, 'CopySource' => $src, 'Body' => $data['Body'], 'ACL' => 'public-read', 'Metadata' => array( S3_META_OBJECT_ISUSED => 1 )); $result = $client->putObject($request); return $result; } function markImgAsUsed($src, $client) { return addMetaDataToImg($src, $client); } function checkAdaEnterprisePermission ($login, $db) { $dateAfterCheck = '01-09-2017'; //date dd-mm-yyyy (don't use slashes) //$countryToCheck = ['it']; //array comma separated //$tolerance = 0; // expressed in % $permissionZone = 50000; //Check if logged user has to pass checks //if(in_array($login->personalData['language'],$countryToCheck)) { if ($login->access['adaEnterprise'] || $login->hasRole('ADAXAnyActiveUser')) { return true; } else { //Calculate how many contacts this user has in address book $sql = " SELECT COUNT(address_book.id) AS totalContacts FROM dmm.address_book WHERE address_book.idVitalStatistic = :idPersonalData "; $result = $db->query($sql, array('idPersonalData' => $login->personalData['idPersonalData']))->fetch_one(); $userLimit = intval($permissionZone); //Calculate and add tolerance //$userLimit *= (1 + $tolerance / 100); //If user has less contacts than first zone or //if user creation date is antecedent than date after check //is allowed to see Lead Scoring $creationDate = new DateTime($login->personalData['insertDate']); $creationDate = $creationDate->format("d-m-Y"); if (intval($result['totalContacts']) <= $userLimit || (strtotime($creationDate) < strtotime($dateAfterCheck))) { return true; } else { return false; } } //} } function searchInMultidimensionalArray($value, $array, $fieldToSearch) { foreach ($array as $key => $val) { if ($val[$fieldToSearch] && $val[$fieldToSearch] === $value) { return $key; } } return null; } ?>upsert($name['table']['Visits'], array( $name['field']['TrackOperation'] => $idTrackOperation, $name['field']['ForTrack'] => $idForTrack, 'page_views' => 1 ), 'page_views = page_views + 1'); } else { // e incrementa con il moltiplicatori le page view //$constant=data_normalization($db, $idTrackOperation, $origin); $db->upsert($name['table']['Visits'], array( $name['field']['TrackOperation'] => $idTrackOperation, $name['field']['ForTrack'] => $idForTrack, 'page_views' => 1 ), 'page_views = page_views + 1'); } } function track_page_visit($db, $idTrackOperation, $idForTrack, $origin = 'ln') { $name = get_table_name($origin); $idForCookie = ($idTrackOperation==0) ? $idForTrack : $idTrackOperation; // verifica se esiste un cookie per questo page identifier if ($_COOKIE[hash_function($idForCookie, HASH_COOKIE_NAME)] == hash_function($idForCookie, HASH_COOKIE_CONTENT)){ // se esiste le page vists (visiatori unici) // non devono aumentare }else{ // se non esiste, crea il cookie setcookie(hash_function($idForCookie, HASH_COOKIE_NAME), hash_function($idForCookie, HASH_COOKIE_CONTENT), time()+SCADENZA_COOKIE, "/", $_SERVER['X-ADA-ORIGIN-HOST']); // setcookie(hash_function($idForCookie, HASH_COOKIE_NAME), hash_function($idForCookie, HASH_COOKIE_CONTENT), time()+SCADENZA_COOKIE, "/"); //$constant = data_normalization($db, $idTrackOperation, $origin); $constant = 1; if ($idTrackOperation==0) { // e incrementa di uno le page visists $db->query( "UPDATE ".$name['table']['Visits']." SET page_visits = page_visits + 1 WHERE ".$name['field']['ForTrack']." = :idForTrack ", array('idForTrack' => $idForTrack) ); } else { // e incrementa di uno le page visists $db->query( "UPDATE ".$name['table']['Visits']." SET page_visits = page_visits + 1*:constant WHERE ".$name['field']['TrackOperation']." = :idTrackOperation ", array('idTrackOperation' => $idTrackOperation, 'constant' => $constant) ); } } } // questa sezione ha bisogno di abilitare php_browscap.ini, segui le istruzioni che trovi nella cartella libs // private function get_or_insert_if_not_exists($db, $table, $name_field, $value){ $results = $db->query( "SELECT id FROM ".$table." WHERE ".$name_field." = :value", array('value' => $value) ); $id = $results->fetch_one('id'); if ($id) return $id; if ($value) $db->insert($table, array($name_field => $value), $id); return $id; } // private function get_platform_id($db, $platform){ return get_or_insert_if_not_exists($db, 'analyticsPlatforms', 'platform', $platform); } // private function get_browser_id($db, $browser){ return get_or_insert_if_not_exists($db, 'analyticsBrowsers', 'browser', $browser); } // private function get_table_name($origin) { switch ($origin) { case 'ln': default: $name['table']['Visits'] = "analyticsVisits"; $name['table']['PlatformsBrowsers'] = "analyticsPlatformsBrowsers"; $name['field']['TrackOperation'] = "idLandingTrackOperation"; $name['field']['ForTrack'] = "idLandingForTrack"; break; case 'st': $name['table']['Visits'] = "analyticsSTVisits"; $name['table']['PlatformsBrowsers'] = "analyticsSTPlatformsBrowsers"; $name['field']['TrackOperation'] = "idStoryTellingTrackOperation"; $name['field']['ForTrack'] = "idStoryTellingForTrack"; break; case 'cb': $name['table']['Visits'] = "analyticsCBVisits"; $name['table']['PlatformsBrowsers'] = "analyticsCBPlatformsBrowsers"; $name['table']['Geolocations'] = "analyticsCBGeolocations"; $name['field']['TrackOperation'] = "idChatBotTrackOperation"; $name['field']['ForTrack'] = "idChatBotForTrack"; break; case 'mt': $name['table']['Visits'] = "analyticsMTVisits"; $name['table']['PlatformsBrowsers'] = "analyticsMTPlatformsBrowsers"; $name['table']['Geolocations'] = "analyticsMTGeolocations"; $name['field']['TrackOperation'] = "idMovieTellingTrackOperation"; $name['field']['ForTrack'] = "idMovieTellingForTrack"; break; case 'landingPageAmp': $name['table']['Visits'] = "analyticsAMPVisits"; $name['table']['PlatformsBrowsers'] = "analyticsAMPPlatformsBrowsers"; $name['field']['TrackOperation'] = "idLandingTrackOperation"; $name['field']['ForTrack'] = "idLandingForTrack"; break; } return $name; } // pubblica function track_browser($db, $idTrackOperation, $idForTrack, $origin = 'ln'){ $name = get_table_name($origin); $idForCookie = ($idTrackOperation==0) ? $idForTrack : $idTrackOperation; require_once(__DIR__ . "/../../smssmart/lib/phpbrowscap/Browscap.php"); $browscap = new phpbrowscap\Browscap(); $browser = $browscap->getBrowser(null, true); $platform = $browser['Platform']; $browser = $browser['Browser']; if (!isset($_COOKIE[hash_function($idForCookie, HASH_COOKIE_NAME)]) || $_COOKIE[hash_function($idForCookie, HASH_COOKIE_NAME)] != hash_function($idForCookie, HASH_COOKIE_CONTENT)){ $platform_id = get_platform_id($db, $platform); $browser_id = get_browser_id($db, $browser); if ($platform_id && $browser_id) { $db->insert($name['table']['PlatformsBrowsers'], array( $name['field']['TrackOperation'] => $idTrackOperation, $name['field']['ForTrack'] => $idForTrack, 'platform_id' => $platform_id, 'browser_id' => $browser_id )); } } return ($browser != "FacebookExternalHit"); } ?>