Your IP : 216.73.216.219


Current Path : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/cookie_commander/
Upload File :
Current File : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/cookie_commander/cookie_commander.php

<?php defined('_JEXEC') or die();
/////////////////////////////////////////////////////////////////////////////////////////////
/** 
* Cookie Commander
* 
* @author : Lab5 - Dennis Riegelsberger
* @authorUrl : https://lab5.ch
* @copyright : Copyright (C) 2018+  Lab5 - Dennis Riegelsberger. All rights reserved.
* @license : GNU/GPL General Public License version 2 or later
* @project : https://lab5.ch/cookie-commander
* @on JED : https://extensions.joomla.org/extensions/extension/site-management/cookie-control/lab5-cookie-commander/
* 
* Built with <3 
* Lab5
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
/**
 * @CHANGELOG :
 * * 2020.08.10 : Great overhaul
 */ 
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////// 

			// ++ destroy all cookies via JS  !!	 ++ destroy all cookies via JS  !!	 ++ destroy all cookies via JS  !!
			
			// $piwik->disableCookieSupport();

			// https://api.joomla.org/cms-3/classes/Joomla.CMS.Input.Cookie.html
			// https://forum.matomo.org/t/will-opt-out-delete-persistent-cookies/12610
			// What are the cookies created by Matomo JavaScript Tracking client? 
			// https://matomo.org/faq/general/faq_146/ 
		
			/* * * * * * * * * * * * * 						
				// Get cookie data
				$value        = $inputCookie->get($name = 'myCookie', $defaultValue = null);

				// Check that cookie exists
				$cookieExists = ($value !== null);

				// Set cookie data
				$inputCookie->set($name = 'myCookie', $value = '123', $expire = 0);

			* * * * * * * * * * * * */ 
			
			require_once( __DIR__ . '/' . 'params.import.php' );
			require( __DIR__ . '/' . 'function.pathing.php' );  // NOT require_once !

/////////////////////////////////////////////////////////////////////////////////////////////
if ( self::$this->params->get('cw_on', false )) : 
if(  in_array( JFactory::getDocument()->_type, ["html","error"] ) ) {
/////////////////////////////////////////////////////////////////////////////////////////////
					 
					if(!isset($doc)) $doc = JFactory::getDocument();
					self::$xstor->cccookies->cookie_switches = array(); 
					$PROCESSED_COOKIES = array(); 
					$PROCESSED_COOKIES[] = self::$xstor->cooco->consentCookieName; // dieses immer ignorieren
					$jinput = JFactory::getApplication()->input; 
					
					self::$xstor->cccookies->COOKIES = JFactory::getApplication()->input->cookie;
					self::$xstor->cccookies->SESSION = JFactory::getSession();

					
					//////////////////////////////////////////////////
					$kill_cookie_func = function ( $name ){
					//////////////////////////////////////////////////
										
												/* * * * * * * * * * * * * 				 
												// Remove cookie
												$inputCookie->set('myCookie', null, time() - 1);
												* * * * * * * * * * * * */ 
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1);
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1, '', false, true);
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1, '', false, false);
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1, '/', false, true);
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1, '/', false, false);
												self::$xstor->cccookies->COOKIES->set($name, null, - 1);
												self::$xstor->cccookies->COOKIES->set($name, null, - 1, '', false, true);
												self::$xstor->cccookies->COOKIES->set($name, null, - 1, '', false, false);
												self::$xstor->cccookies->COOKIES->set($name, null, - 1, '/', false, true);
												self::$xstor->cccookies->COOKIES->set($name, null, - 1, '/', false, false);
												
											 // echo "DELETECOOKIE:".$name;
												
												// setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
												
												self::$xstor->cccookies->COOKIES->set($name, null, time() - 1);
												@setcookie( $name, null, -1, '/' );
												@setcookie( $name, null, -1 );
												unset($_COOKIE[$name]);  

					}; ///////////////////////////////////////////////
					// Load Cookie Settings 
					//////////////////////////////////////////////////
					
								$default_values_set = array(); // if none is selected => all shall be selected ( default ) 
								$cookie_plugins = array();
								$cookie_plugins['sessionprotect'] =  'internal_sessionprotect' ;  
								
								$ccpaths = (self::$xstor->getCCPaths)();
								// echo "\n<br>" . $ccpaths->dPath;
								// echo "\n<br>" . $ccpaths->tPath;
					
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								// LOAD FROM LOCAL ( PLUGIN) 
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
									
											$cookiePath = __DIR__ . "/tmpl" ; // just simpler
											// $cookiePath = $ccpaths->dPath ; // correct
											//////////////////////////////////////////////////
											if (file_exists($cookiePath)) {  // die('YES:'.$tPath );
														
														foreach (glob( $cookiePath."/"."cookie.*.php" ) as $filename){
																
																preg_match( "#cookie\.(.*)\.php#",  basename($filename), $name );
																$COOKIENAME = $name[1];
																$cookie_plugins[$COOKIENAME] = 
																$default_values_set[] = 'plugin_'.$COOKIENAME;
																// echo $COOKIENAME."\n";
														}
											}
											
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								// LOAD ( OVERRIDES AND EXTENDING FILES ) FROM TEMPLATE 
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
										
											$template = \JFactory::getApplication()->getTemplate();
											$cookiePath = $ccpaths->tPath ;
											// OLD: $cookiePath = JPATH_THEMES . '/' . $template . '/html/plg_' . $this->_type . '_' . $this->_name . '/cookie_commander';
											//////////////////////////////////////////////////
											if (file_exists($cookiePath)) {  // die('YES:'.$tPath );
														
														foreach (glob( $cookiePath."/"."cookie.*.php" ) as $filename){
																
																preg_match( "#cookie\.(.*)\.php#",  basename($filename), $name );
																$COOKIENAME = $name[1];
																$cookie_plugins[$COOKIENAME] = 
																$default_values_set[] = 'template_'.$template.'_'.$COOKIENAME;
																// $cookie_plugins[$COOKIENAME] = 'tpl_override';
																// echo $COOKIENAME."\n";
														}
											}
											
								///////////////////////////////////////////////////////////
								unset($cookiePath, $template);
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								
				
								
								/////////////////////////////////////
								// Default value, of not set :
								/////////////////////////////////////
								
										if( gettype( self::$xstor->cooco->cookie_selection ) != 'array' OR count( self::$xstor->cooco->cookie_selection ) < 1 ){
						
													self::$xstor->cooco->cookie_selection = $default_values_set;
										}
								
								/////////////////////////////////////
								// Internal  :
								/////////////////////////////////////
				
										self::$xstor->cooco->cookie_selection[] = "internal_sessionprotect";
								
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								// LOOP trou Cookie - Plugins/Switches
								foreach ( $cookie_plugins as $COOKIENAME => $system_name ) :
								if( in_array( $system_name, self::$xstor->cooco->cookie_selection )) :
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
									  
												//////////////////////////////////////////////////
												// Mark as processed, so it will be skipped on further actions.
												//////////////////////////////////////////////////
														
															$PROCESSED_COOKIES[] = $COOKIENAME; 

												//////////////////////////////////////////////////
												// Default-Value setzten :
												//////////////////////////////////////////////////
												
															self::$xstor->cccookies->cookie_switches[$COOKIENAME] = ( self::$xstor->cooco->modusOperandi == 'optout' ) ? '1' : '0'; 
			 
												//////////////////////////////////////////////////
												// Load Cookie data :
												//////////////////////////////////////////////////
															
															// cookies preferred => during dev (='both') effects can be tested by manipulating cookies.
															if( self::$xstor->cccookies->STORM == 'both' OR self::$xstor->cccookies->STORM == 'cookie' ){	
															
																		$value = 
																		self::$xstor->cccookies->COOKIES->get($COOKIENAME, $default = null); 
															}else{ 
																		$value = 
																		self::$xstor->cccookies->SESSION->get( $COOKIENAME, $default = null ); 
															}
															
															if( $value !== null ){ // Check that cookie exists
															
																	if( $value == '1' ){ self::$xstor->cccookies->cookie_switches[$COOKIENAME] = '1'; }
																	if( $value == '0' ){  self::$xstor->cccookies->cookie_switches[$COOKIENAME] = '0'; }
															}
															
												//////////////////////////////////////////////////
												// POST Vari gesendet -> Status verändern : 
												//////////////////////////////////////////////////
													
															$allow = $jinput->get( $COOKIENAME , null, 'INT' ); 
															if(gettype($allow) !== 'NULL'){

																		self::$xstor->cccookies->cookie_switches[$COOKIENAME] = ( $allow === 1 ) ? '1' : '0'; 
															}
												
												//////////////////////////////////////////////////
												// Cookie specific :
												//////////////////////////////////////////////////
												//////////////////////////////////////////////////
																
																$cookie = new stdClass();
																$cookie->name = $COOKIENAME;
																$cookie->status = self::$xstor->cccookies->cookie_switches[$COOKIENAME];
																$cookie->whitelist = $PROCESSED_COOKIES;
																$cookie->allcookies = JFactory::getApplication()->input->cookie->getArray(); 
																
																if( $cookie->name == "sessionprotect" ){
																	
																		$tpl_cookie_path = 
																		__DIR__ . '/internal/cookie.sessionprotect.php'; 
																		
																}else{
																	
																		$tpl_cookie_path = (self::$xstor->getCCLayoutPath)( 'cookie.'.$cookie->name ); 
																	
																}
																
																/////////////////////////////////// 
																$params = self::$xstor->cooco; 

																		include( $tpl_cookie_path ); 
								
																self::$xstor->cooco = $params;
																/////////////////////////////////// 
																
																self::$xstor->cccookies->cookie_switches[$COOKIENAME] = $cookie->status;
																$PROCESSED_COOKIES = $cookie->whitelist;
															
												//////////////////////////////////////////////////
												//////////////////////////////////////////////////
												// Cookie final setzten :
												//////////////////////////////////////////////////
												
															$expire = 0 ;
															if( (int)self::$xstor->cooco->expireDays > 0 ){
															$expire =strtotime("+".(int)self::$xstor->cooco->expireDays." days");
															}
															
															$value = self::$xstor->cccookies->cookie_switches[$COOKIENAME] ;
								
															if( self::$xstor->cccookies->STORM == 'both' OR self::$xstor->cccookies->STORM == 'session' ){	
																		
																		self::$xstor->cccookies->SESSION->set( $COOKIENAME, $value );
															}
															// cookies preferred => during dev (='both') effects can be tested by manipulating cookies.
															if( self::$xstor->cccookies->STORM == 'both' OR self::$xstor->cccookies->STORM == 'cookie' ){	
																			
																		self::$xstor->cccookies->COOKIES->set( $COOKIENAME, $value, $expire, '/' );
															}
								
															// self::$xstor->cccookies->COOKIES->set( $COOKIENAME, $value, $expire, '/' ); 
											
												//////////////////////////////////////////////////
												unset($value, $expire, $allow, $COOKIENAME);
												
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								endif; // eof :  if activated
								endforeach; ///////////////////////////////////////////////////////////////////////////////////////
								unset($cookie_plugins, $cookie_name, $tpl_cookie_path);
								//////////////////////////////////////////////////////////////////////////////////////////////////////////////
								
							
					//////////////////////////////////////////////////
					// Cookie-Bar Cookie 
					//////////////////////////////////////////////////
					
								/* * * * * * * * * * * * * * * 
									Cookie-Bar Cookie wird im moment in jedem Fall als Cookie gespeichert
								* * * * * * * * * * * * * * */ 
								
								// if( self::$xstor->cccookies->STORM == 'both' OR self::$xstor->cccookies->STORM == 'session' ){	
												
												// $cookiebarcookie = 
												// self::$xstor->cccookies->SESSION->get( self::$xstor->cooco->consentCookieName, $default = null );
								// }else{
												$cookiebarcookie = 
												self::$xstor->cccookies->COOKIES->get(self::$xstor->cooco->consentCookieName, $default = null);
								// }
								// die("cookiebarcookie:".$cookiebarcookie );
								
								// $cookiebarcookie = ($cookiebarcookie !== null); // Check that cookie exists
								
								if( !$cookiebarcookie OR  $cookiebarcookie === 'undecided' OR  self::$xstor->cooco->showMode == 'always' ):
												
												$lebase = str_replace( JPATH_SITE, '', __DIR__ ); 
												$lebase = JURI::root(true) .str_replace( DIRECTORY_SEPARATOR, '/', $lebase ); 
												
												// JS 
												$doc->addScriptDeclaration( " var $ = jQuery; " );
												$doc->addScript( $lebase.'/assets/jquery.cookiebar.js'); 
												
												// CSS 
												$CSS = "
												#".self::$xstor->cooco->idCookieBar.".fixed {position:fixed; top:0; left:0; width:100%;}
												#".self::$xstor->cooco->idCookieBar.".fixed.bottom {bottom:0; top:auto;} ";
												$doc->addStyleDeclaration( $CSS );
												if(self::$xstor->cooco->cc_load_css){
													$doc->addStyleSheet( $lebase.'/assets/jquery.cookiebar.css');
													require( __DIR__ .'/cookie_commander.CSS.php' );
												}
												
												// JS  
												require( __DIR__ .'/cookie_commander.JS.php' );
												
												// HTML  - BAR 
												require( __DIR__ .'/cookie_commander.bar.HTML.php' );
												
												if( self::$xstor->cooco->showMode != 'never' ){
												}
												
								endif;
				
					//////////////////////////////////////////////////
					unset($lebase,$JS,$filename,$name,$COOKIENAME,$loadcookiebar, $cookiePath, $template);
					
} ///////////////////////////////////////////////////////////////////////////////////////////
endif;