| Current Path : /home/poneycluc/www/modules/mod_advanced_cookies/ |
| Current File : /home/poneycluc/www/modules/mod_advanced_cookies/helper.php |
<?php
use Joomla\CMS\Factory;
/**
* @version $Id$
* @package Advanced Cookies
* @copyright Copyright (C) 2019 HOB-France.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: https://www.hob-france.com/
* @author email info@hob-fr.com
* @developer Mihaly Varga - michel.varga@hob-fr.com
*/
defined('_JEXEC') or die('Restricted access');
class ModAdvancedCookiesHelper
{
protected $color = array();
protected $text = array();
public static function getValidationKey($params)
{
$licenseEmail = $params->get('license_email');
return $validation = array('key' => "", 'email' => $licenseEmail);
}
/*
* POST http://licences.hob-fr.com/api/auth
* Identification
* Verify the license and the expiration date.
*
* To the verification we need the email address and the userToken.
* E-mail and Password -> GET from getLicenseKey function
*
* */
public static function infos_licence($licensePrd, $licenseEmail)
{
$url = JUri::base();
$tUrl = parse_url($url);
$sUrl = $tUrl['host'];
$tDomainParts = explode(".", $sUrl);
$tDomain = array_slice($tDomainParts, -2, 2);
$domain = implode(".", $tDomain);
$status = self::checkCacheLimit();
if($status==1) return false;
if($status==2) return true;
//POST the email and the password to get Authorization
self::storeNewCacheLimit(0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$token = $domain."-".$licensePrd;
$params = array(
"key" => $licenseEmail,
"token" => md5($token)
);
$urlCall = "https://www.joomhob.com/index.php?option=com_hob_control&task=control.infos_licence";
curl_setopt($ch, CURLOPT_URL, $urlCall);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = json_decode(curl_exec($ch));
if(is_object($result)) {
if (isset($result->error) && isset($result->status)) {
if ($result->error==false && $result->status=="active") {
$license_expire = $result->end_date;
$time = strtotime(str_replace('/', '-', $license_expire));
$day1 = date_create(date('Y-m-d', $time));
$day2 = date_create(date("Y-m-d", strtotime("now")));
$day_left = date_diff($day2, $day1);
self::storeNewCacheLimit($day_left->days);
return $day_left->days;
} else {
return false;
}
} else {
return false;
}
}else {
return false;
}
}
public static function getSessionOption($params)
{
$session_option = htmlspecialchars($params->get('service_session'));
return $session_option;
}
/**
* get tab states to display or not corresponding blocks in the modal
* @param object $params
* @return array
*/
public static function getServicesTabsState($params)
{
$tServicesState = array();
if( !$params->get('service_google_analytics') && !$params->get('service_google_ads') ) {
$tServicesState['tab1'] = 0;
} else {
$tServicesState['tab1'] = 1;
}
if( !$params->get('service_google_maps') && !$params->get('service_calameo') &&
!$params->get('service_recaptcha_v2') && !$params->get('service_recaptcha_v3') &&
!$params->get('service_chatbot') && !$params->get('service_mailchimp') ) {
$tServicesState['tab2'] = 0;
} else {
$tServicesState['tab2'] = 1;
}
if( !$params->get('service_facebook') && !$params->get('service_twitter') &&
!$params->get('service_google_plus') && !$params->get('service_linkedin') &&
!$params->get('service_pinterest') && !$params->get('service_instagram') &&
!$params->get('service_youtube') && !$params->get('service_vimeo') && !$params->get('service_dailymotion') ) {
$tServicesState['tab3'] = 0;
} else {
$tServicesState['tab3'] = 1;
}
return $tServicesState;
}
public static function getPosition($params)
{
$position = htmlspecialchars($params->get('position'));
if (!$position) {
$position = 'top';
}
return $position;
}
public static function getCookieBtnSettings($params)
{
$position = htmlspecialchars($params->get('cookie_button_position'));
$text = htmlspecialchars($params->get('cookie_button_text'));
$position_mode = htmlspecialchars($params->get('cookie_button_position_style'));
$display_mode = $params->get('cookie_button_show_hide');
if(!$position){
$position = 'left';
}
if(!$position_mode){
$position_mode = 'fixed';
}
if(!$text){
$text = 'Cookies';
}
return array('position'=>$position, 'text'=>$text, 'position_mode'=>$position_mode, 'display_mode'=>$display_mode);
}
public static function getExpiration($params)
{
$expiration = $params->get('expiration');
if (!$expiration || $expiration <= 0) {
$expiration = 30;
}
return $expiration;
}
public static function getText($params)
{
$banner_text = htmlspecialchars($params->get('banner_text',JText::_('MOD_HOB_RGPD_DEFAULT_TEXT_BANNER')));
$app = JFactory::getApplication();
$sitename = htmlspecialchars($app->get('sitename'), ENT_QUOTES, 'UTF-8');
$search = array('[SITENAME]','[COOKIE_DURATION]');
$replace = array($sitename,$params->get('expiration',30));
$banner_text = str_replace($search,$replace,$banner_text);
$btn_ok_text = htmlspecialchars($params->get('button_accept'));
$btn_setting_text = htmlspecialchars($params->get('button_settings'));
$btn_refuse_text = htmlspecialchars($params->get('button_refuse',JText::_('MOD_HOB_RGPD_REFUSE_BUTTON_TEXT_LABEL_DEFAULT')));
$readmore_text = htmlspecialchars($params->get('readmore_text',JText::_('MOD_HOB_RGPD_LEARN_MORE_TEXT_LABEL')));
return $text = array($banner_text,
$btn_ok_text,
$btn_refuse_text,
$btn_setting_text,
$readmore_text
);
}
public static function getColor($params)
{
$background_color = $params->get('modbgbar');
$text_color = $params->get('modcolortext');
$link_text_color = $params->get('modcolorlinktext');
$accept_btn_color = $params->get('modcolorbtnaccept','#0065af');
$accept_btn_border_color = $params->get('modcolorbtnacceptborder','#0065af');
$accept_btn_text_color = $params->get('modcolortextbtnaccept','#ffffff');
$custom_btn_color = $params->get('modcolorbtncustom');
$custom_btn_text_color = $params->get('modcolortextbtncustom');
$custom_btn_border_color = $params->get('modcolorbtncustomborder');
$deny_btn_color = $params->get('modcolorbtndeny','#0065af');
$deny_btn_border_color = $params->get('modcolorbtndenyborder','#0065af');
$deny_btn_text_color = $params->get('modcolortextbtndeny','#ffffff');
return $color = array($background_color,
$text_color,
$accept_btn_color,
$accept_btn_border_color,
$accept_btn_text_color,
$custom_btn_color,
$custom_btn_border_color,
$custom_btn_text_color,
$link_text_color,
$deny_btn_color,
$deny_btn_border_color,
$deny_btn_text_color
);
}
public static function getLicenceActivation($params)
{
return $license_activation = htmlspecialchars($params->get('license_activation'));
}
public static function getUrl($params)
{
return $banner_link_url = $params->get('url_link_banner');
}
public static function getServices($params){
$check = "3c646976207374796c653d22666c6f61743a20726967687".
"43b20636c6561723a20626f74683b222069643d22686f625f666565745f646976223e3c73".
"70616e2069643d22686f625f6665657422207374796c653d22636f6c6f723a20626c61636".
"b21696d706f7274616e743b223e26233136393b436f70797269676874203c61207374796c".
"653d22666f6e742d73697a653a203134707821696d706f7274616e743b20636f6c6f723a2".
"06d656469756d626c756521696d706f7274616e743b2220687265663d2268747470733a2f".
"2f7777772e686f622d6672616e63652e636f6d2f636f6d706f73616e74732d6a6f6f6d6c6".
"12f726770642d6a6f6f6d6c612e68746d6c22207469746c653d2252475044204a6f6f6d6c".
"61223e20484f42204672616e63652053657276696365732c20457870657274204a6f6f6d6".
"c613c2f613e3c2f7370616e3e3c2f6469763e";
$services = $params->get('service',$check);
return $services;
}
public static function getCookieDescription($params)
{
$cookies_fonctionnels = $params->get('cat1_description');
$cookies_audience = $params->get('cat2_description');
$cookies_interactif = $params->get('cat3_description');
$cookies_reseax = $params->get('cat4_description');
$cookies_autre = $params->get('cat5_description');
return $cookie_category = array(
$cookies_fonctionnels,
$cookies_audience,
$cookies_interactif,
$cookies_reseax,
$cookies_autre);
}
public static function getSwitcher($params)
{
$google_analytics = $params->get('service_google_analytics');
$google_ads = $params->get('service_google_ads');
$google_maps = $params->get('service_google_maps');
$calemeo = $params->get('service_calameo');
$reCaptcha_v2 = $params->get('service_recaptcha_v2');
$reCaptcha_v3 = $params->get('service_recaptcha_v3');
$charBot = $params->get('service_chatbot');
$mailChimp = $params->get('service_mailchimp');
$facebook = $params->get('service_facebook');
$twitter = $params->get('service_twitter');
$google_plus = $params->get('service_google_plus');
$linkedin = $params->get('service_linkedin');
$pintrest = $params->get('service_pinterest');
$instagram = $params->get('service_instagram');
$youtube = $params->get('service_youtube');
$vimeo = $params->get('service_vimeo');
$daylimotion = $params->get('service_dailymotion');
return $switcher = array($google_analytics, $google_ads, $google_maps, $calemeo, $reCaptcha_v2, $reCaptcha_v3, $charBot, $mailChimp, $facebook, $twitter, $google_plus, $linkedin, $pintrest, $instagram, $youtube, $vimeo, $daylimotion);
}
public static function getCollapseText($params)
{
$google_analytics = $params->get('service_google_analytics_collapse');
$google_ads = $params->get('service_google_ads_collapse');
$google_maps = $params->get('service_google_maps_collapse');
$calemeo = $params->get('service_calameo_collapse');
$reCaptcha_v2 = $params->get('service_recaptcha_v2_collapse');
$reCaptcha_v3 = $params->get('service_recaptcha_v3_collapse');
$charBot = $params->get('service_chatbot_collapse');
$mailChimp = $params->get('service_mailchimp_collapse');
$facebook = $params->get('service_facebook_collapse');
$twitter = $params->get('service_twitter_collapse');
$google_plus = $params->get('service_google_plus_collapse');
$linkedin = $params->get('service_linkedin_collapse');
$pinterest = $params->get('service_pinterest_collapse');
$instagram = $params->get('service_instagram_collapse');
$youtube = $params->get('service_youtube_collapse');
$vimeo = $params->get('service_vimeo_collapse');
$daylimotion = $params->get('service_dailymotion_collapse');
return $collapse = array(
"google_analytics" => $google_analytics,
"google_ads" => $google_ads,
"google_maps" => $google_maps,
"calemeo" => $calemeo,
"reCaptcha_v2" => $reCaptcha_v2,
"reCaptcha_v3" => $reCaptcha_v3,
"charBot" => $charBot,
"mailChimp" => $mailChimp,
"facebook" => $facebook,
"twitter" => $twitter,
"google_plus" => $google_plus,
"linkedin" => $linkedin,
"pinterest" => $pinterest,
"instagram" => $instagram,
"youtube" => $youtube,
"vimeo" => $vimeo,
"dailymotion" => $daylimotion);
}
public static function setPositionStyle($params)
{
//Set the position of the banner as in the setting
if (self::getPosition($params) == 'top') {
return $position_style = '.hob_banner{'
. 'top : 0!important;'
. '-webkit-animation-name: animateup;'
. '-webkit-animation-duration: 0.8s;'
. 'animation-name: animateup;'
. 'animation-duration: 0.8s'
. '}';
} else {
return $position_style = '.hob_banner{'
. 'bottom : 0!important;'
. '-webkit-animation-name: animatedown;'
. '-webkit-animation-duration: 0.8s;'
. 'animation-name: animatedown;'
. 'animation-duration: 0.8s'
. '}';
}
}
public static function setBannercolor($params)
{
//set the color of the banner as in the setting
$banner_color_style = '.hob_banner{'
. 'background-color: ' . self::getColor($params)[0] . '!important;'
. '}';
return $banner_color_style;
}
public static function setBannerTextcolor($params)
{
//set the color of the banner text "<p>"
$banner_text_color_style = '.text_banner{'
. 'color:' . self::getColor($params)[1] . '!important;'
. '}';
return $banner_text_color_style;
}
public static function setBannerLinkTextcolor($params)
{
//set the color of the link in the main banner
$banner_link_text_color_style = '.info_link{'
. 'color:' . self::getColor($params)[8] . '!important;'
. '}';
return $banner_link_text_color_style;
}
public static function setCopyrightTextColor($params)
{
//set the copyright text color
$copyright_text_color_style = '#hob_copyright{'
. 'color:' . self::getColor($params)[1] . '!important;'
. '}';
return $copyright_text_color_style;
}
public static function setcopyrigthLinkTextcolor($params)
{
//set the copyright link color
$copyright_link_text_color_style = '#hob_copyright a{'
. 'color:' . self::getColor($params)[8] . '!important;'
. '}';
return $copyright_link_text_color_style;
}
public static function setOkButtonStyle($params)
{
//set the OK button style in the Banner
$btn_ok_style = '.btn_ok{'
. 'background-color: ' . self::getColor($params)[2] . '!important;'
. 'border: 2px solid' . self::getColor($params)[3] . '!important;'
. 'color:' . self::getColor($params)[4] . '!important;'
. '}'
. '.btn_ok:hover{'
. 'filter: opacity(50%);'
. 'background-color: ' . self::getColor($params)[2] . '!important;'
. 'border: 2px solid' . self::getColor($params)[3] . '!important;'
. 'color:' . self::getColor($params)[4] . '!important;'
. '}';
return $btn_ok_style;
}
public static function setDenyButtonStyle($params)
{
//set the OK button style in the Banner
$btn_deny_style = '.btn_deny{'
. 'background-color: ' . self::getColor($params)[9] . '!important;'
. 'border: 2px solid' . self::getColor($params)[10] . '!important;'
. 'color:' . self::getColor($params)[11] . '!important;'
. '}'
. '.btn_deny:hover{'
. 'filter: opacity(50%);'
. 'background-color: ' . self::getColor($params)[9] . '!important;'
. 'border: 2px solid' . self::getColor($params)[10] . '!important;'
. 'color:' . self::getColor($params)[11] . '!important;'
. '}';
return $btn_deny_style;
}
public static function setSettingButtonStyle($params)
{
//set the Setting button style in the Banner
$btn_setting_style = '.btn_settings{'
. 'background-color: ' . self::getColor($params)[5] . '!important;'
. 'border: 2px solid' . self::getColor($params)[6] . '!important;'
. 'color:' . self::getColor($params)[7] . '!important;'
. '}'
. '.btn_settings:hover{'
. 'filter: opacity(50%);'
. 'background-color: ' . self::getColor($params)[5] . '!important;'
. 'border: 2px solid' . self::getColor($params)[6] . '!important;'
. 'color:' . self::getColor($params)[7] . '!important;'
. '}';
return $btn_setting_style;
}
public static function setCookieBtnPosition($params){
$btn_setting_position='#setting{'.self::getCookieBtnSettings($params)['position'].': 10px;'.
' position: '.self::getCookieBtnSettings($params)['position_mode'].';'
.'}';
return $btn_setting_position;
}
public static function setSecondSettingButtonStyle($params)
{
//set the Small Setting button style
$btn_setting2_style = '#setting_btn{'
. 'background-color: ' . self::getColor($params)[2] . '!important;'
. 'border: 2px solid' . self::getColor($params)[3] . '!important;'
. 'color:' . self::getColor($params)[4] . '!important;'
. '}'
. '.btn_settings:hover{'
. '}';
return $btn_setting2_style;
}
public static function setModalHeadcolor($params)
{
//set the color of the modal header as in the setting
$modal_head_color_style = '.hob_modal-header{'
. 'background-color: ' . self::getColor($params)[0] . '!important;'
. '}';
return $modal_head_color_style;
}
public static function setModalHeadTextcolor($params)
{
$modal_head_text_color_style = '#modalLabel{'
. 'color:' . self::getColor($params)[1] . '!important;'
. '}';
return $modal_head_text_color_style;
}
public static function setmodalOpenScript()
{
$openScript = '
function openCookie(evt, cookieName) {
var i;
var tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
var tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cookieName).style.display = "block";
evt.currentTarget.className += " active";
}
';
return $openScript;
}
public static function hob()
{
$hob = '<div id="hob_div_copyright">
<span id="hob_copyright">© Copyright<a href="https://www.hob-france.com/composants-joomla/rgpd-joomla.html" title="RGPD Joomla"> HOB France Services, Expert Joomla</a></span>
</div>';
return $hob;
}
protected static function checkCacheLimit() {
$session = Factory::getSession();
$ts = $session->get("ts_advcookies", null);
if($ts>0) return 2;
if($ts===0) return 1;
$fileName = JPATH_ROOT."/media/ts_advcookies.cache";
$fileDir = dirname($fileName);
if ( ! is_writable($fileDir)) {
$session->set("ts_advcookies", 0);
return 1;
} else {
if(file_exists("$fileName")) {
$handle = fopen($fileName, "rb");
$contentDelay = fread($handle, filesize($fileName));
$tDelay = explode(":", $contentDelay);
if(is_array($tDelay) && isset($tDelay[0]) && isset($tDelay[1]) && $tDelay[0]<(time())) {
return 0; //=cache non-expir�
} else {
if(is_array($tDelay) && isset($tDelay[0]) && isset($tDelay[1]) && $tDelay[1]>0)
return 2; //=cache expir� et nb jours>0
else
return 1; //=cache expir� et nb jours==0
}
} else {
return 0;
}
}
}
protected static function storeNewCacheLimit($value=0) {
$fileName = JPATH_ROOT."/media/ts_advcookies.cache";
if(@touch($fileName)) {
$tsDelay = time()+(24*60*60);
$fp = fopen($fileName, 'w');
fwrite($fp, $tsDelay.":".$value);
} else {
// no file access, set cache in session to limit calls
$session = Factory::getSession();
$session->set("ts_advcookies", $value);
}
}
}