Skip to content

Commit

Permalink
Implement cookies plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
luhas21 committed Apr 11, 2024
1 parent b1e0749 commit 38c2436
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 7 deletions.
157 changes: 157 additions & 0 deletions plugins/goout-events/css/cookies.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
.goout-cookie-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,.5);
}
.goout-cookie-popup {
color: #0c0c0c;
position: absolute;
width: 80%;
max-width: 30rem;
max-height: 100%;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
background: #fff;
font-family: 'Libre Franklin', sans-serif;
padding: 0 1.5rem;
overflow: auto;
}
.goout-cookie-popup a {
text-decoration: underline;
color: #0c0c0c;
}
.goout-cookie-header {
text-align: center;
font-size: 1.5rem;
margin-top: 3rem;
margin-bottom: 1rem;
font-weight: 600;
}
.goout-cookie-close {
position: absolute;
right: 0;
width: 3rem;
height: 3rem;
top: 0;
cursor: pointer;
}
.goout-cookie-close:after {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: "×";
font-size: 2rem;
color: #999;
line-height: 3rem;
text-align: center;
}
.goout-cookie-intro span {
text-decoration: underline;
cursor: pointer;
}
.goout-cookie-intro span:hover,.goout-cookie-intro span:focus {
text-decoration: none;
}
.goout-cookie-confirm {
width: 100%;
height: 3rem;
line-height: 3rem;
margin-bottom: 2.5rem;
background: #f78564;
color: #fff;
text-align: center;
cursor: pointer;
transition: all .1s ease-out;
}
.goout-cookie-confirm:hover,.goout-cookie-confirm:focus {
opacity: 0.8;
}
.goout-cookie-secondary {
width: 100%;
margin: 1rem 0;
padding: .5rem 0;
text-align: center;
color: #999;
cursor: pointer;
transition: all .1s ease-out;
}
.goout-cookie-secondary:hover,.goout-cookie-secondary:focus {
color: #383838;
}
.goout-cookie-d-none {
display: none;
}
.goout-cookie-settings {
margin: 1rem 0 2rem;
}
.goout-cookie-settings-switch {
display: flex;
margin: 1.5rem 0;
}
.goout-cookie-settings-switch span {
flex-grow: 1;
padding-right: 1.5rem;
}
.goout-cookie-switch {
position: relative;
display: inline-block;
width: 2.5rem;
height: 1.5rem;
flex-shrink: 0;
align-self: center;
}
.goout-cookie-switch input {
opacity: 0;
width: 0;
height: 0;
}
.goout-cookie-switch .toggle {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #999;
transition: .4s;
border-radius: 1.5rem;
}
.goout-cookie-switch .toggle:before {
position: absolute;
content: "";
height: 1rem;
width: 1rem;
left: .25rem;
bottom: .25rem;
background-color: #fff;
transition: .4s;
border-radius: 50%;
}
.goout-cookie-switch input:checked+.toggle {
background-color: #f78564;
}
.goout-cookie-switch input:focus+.toggle {
box-shadow: 0 0 1px #383838;
}
.goout-cookie-switch input:checked+.toggle:before {
transform: translateX(1rem);
}
.goout-cookie-settings-button {
position: fixed;
left: 7px;
bottom: 0;
padding: 1px 7px 0 7px;
border: solid 1px #999;
border-radius: 7px 7px 0 0;
color: #555;
background-color: #fefefe;
text-align: center;
font-style: italic;
cursor: pointer;
}
12 changes: 9 additions & 3 deletions plugins/goout-events/goout-events-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
// Insert CSS files
function add_custom_css() {
wp_enqueue_style('custom-style', plugins_url('css/styles.css', __FILE__));
if (get_option('use_cookies') == 'on') {
wp_enqueue_style('goout-events-cookies-styles', plugins_url('css/cookies.css', __FILE__));
}
}
add_action('wp_enqueue_scripts', 'add_custom_css');
function add_custom_admin_css() {
wp_enqueue_style('custom-admin-style', plugins_url('css/styles.css', __FILE__));
}

add_action('admin_enqueue_scripts', 'add_custom_admin_css');
add_action('wp_enqueue_scripts', 'add_custom_css');

// Insert JS files
// Register scripts for admin pages
Expand All @@ -31,7 +33,11 @@ function goout_events_load_admin_scripts() {

// Register scripts for front end
function enqueue_goout_events_load_scripts() {
wp_enqueue_script('goout-events-scripts', plugins_url('/js/scripts.js', __FILE__));
wp_enqueue_script('goout-events-scripts', plugins_url('/js/goout-scripts.js', __FILE__));
if (get_option('use_cookies') == 'on') {
wp_enqueue_script('cookies-script', 'https://static.goout.net/cookie-plugin/goout-cookie.umd.js', array(), null, false);
wp_enqueue_script('goout-events-cookies-scripts', plugins_url('js/goout-cookies.js', __FILE__));
}
}
add_action('wp_enqueue_scripts','enqueue_goout_events_load_scripts');

Expand Down
2 changes: 1 addition & 1 deletion plugins/goout-events/js/goout-admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log('AHOJ, tady script pro administraci na stránce typu příspěvku "dates"');
console.log('PLUGIN BACKEND SCRIPT');

(function($) {
'use strict';
Expand Down
60 changes: 60 additions & 0 deletions plugins/goout-events/js/goout-cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Cookies Scripts

console.log('COOKIES SCRIPT');

lang = 'cs';
function trackingAccepted() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://c.seznam.cz/js/rc.js';

document.head.appendChild(script);
var retargetingConf = {
rtgId: 21191,
};
if (window.rc && window.rc.retargetingHit) {
window.rc.retargetingHit(retargetingConf);
}
}

goOutCookie.init({
lang: lang,
accepted: trackingAccepted,
dataLayer: window.dataLayer,
showSettingsButton: true,
showSettingsID: 'cookie-settings',
customLink: '/cookie-policy/',
});

/*
function loadCookieScripts() {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', get_field('google_analytics_id'), {
'ad_storage': getCookie('goout-tracking_ad_storage') || 'denied',
'analytics_storage': getCookie('goout-tracking_analytics_storage') || 'denied',
'ad_user_data': getCookie('goout-tracking_ad_user_data') || 'denied',
'ad_personalization': getCookie('goout-tracking_ad_personalization') || 'denied',
});
ga('send', 'pageview');
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '862504247105662');
fbq('track', "PageView");
var script = document.createElement("script");
script.type = "text/javascript";
script.innerHTML = "(function(w,d,s,l,i){w[l]=w[l]||[];var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-NGVQ6TQ');";
document.body.appendChild(script);
}
loadCookieScripts();
*/
1 change: 1 addition & 0 deletions plugins/goout-events/js/goout-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('PLUGIN FRONTEND SCRIPT');
1 change: 0 additions & 1 deletion plugins/goout-events/js/scripts.js

This file was deleted.

92 changes: 90 additions & 2 deletions plugins/goout-events/options-basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function goout_custom_menu() {
add_submenu_page('basic_settings_page', __("Nastavení fesstivalu", "t"), __("Nastavení festivalu", "t"), "manage_options", 'festival_settings_page', 'festival_settings_page');
} else if (get_option('basic_website_type') == 'exhibition') {
add_submenu_page('basic_settings_page', __("Nastavení výstavy", "t"), __("Nastavení výstavy", "t"), "manage_options", 'exhibition_settings_page', 'exhibition_settings_page');
} else if (get_option('basic_website_type') == 'goout-feed') {
add_submenu_page('basic_settings_page', __("GoOut Feed", "t"), __("GoOut Feed", "t"), "manage_options", 'goout-feed_settings_page', 'goout-feed_settings_page');
}
add_submenu_page('basic_settings_page', __("Sociální sítě", "t"), __("Sociální sítě", "t"), "manage_options", 'socials_settings_page', 'socials_settings_page');
add_submenu_page('basic_settings_page', __("Cookies", "t"), __("Nastavení Cookies", "t"), "manage_options", 'cookies_settings_page', 'cookies_settings_page');
}

function custom_menu_styles() {
Expand Down Expand Up @@ -61,6 +64,18 @@ function socials_settings_page() {
<?php
}

function cookies_settings_page() {
?>
<div class="wrap">
<h2><?php _e('GoOut - Nastavení cookies', 't'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields('cookies_settings_group'); ?>
<?php do_settings_sections('cookies_settings_page'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}

function basic_settings() {
//// Basic settings sections registration
Expand Down Expand Up @@ -127,7 +142,7 @@ function basic_settings() {
}
add_action("admin_init", "basic_settings");

function social_settings() {
function socials_settings() {

//// Social networks sections registration

Expand Down Expand Up @@ -170,7 +185,42 @@ function social_settings() {
add_settings_field("video_link", __("Odkaz na úvodní youtube video", "t"), "display_video_link", "socials_settings_page", "section_app_links");
register_setting("socials_settings_group", "video_link");
}
add_action("admin_init", "social_settings");
add_action("admin_init", "socials_settings");


function cookies_settings() {

//// cookie networks sections registration

// Section "Základní nastavení Cookies" registration
add_settings_section("section_cookies_usage", __("Základní nastavení Cookies", "t"), null, "cookies_settings_page");

// Cookie usage turn on/field
add_settings_field("use_cookies", __("Podpora Cookies", "t"), "display_use_cookies", "cookies_settings_page", "section_cookies_usage");
register_setting("cookies_settings_group", "use_cookies");


// Section "Kódy pro Cookies" registration
add_settings_section("section_cookies_codes", __("Kódy pro Cookies", "t"), null, "cookies_settings_page");

// Sklick ID field
add_settings_field("sklick_code", __("Sklik ID", "t"), "display_sklick_id", "cookies_settings_page", "section_cookies_codes");
register_setting("cookies_settings_group", "sklick_code");

// Facebook Pixel ID field
add_settings_field("facebook_pixel_id", __("Kód Facebook", "t"), "display_facebook_pixel_id", "cookies_settings_page", "section_cookies_codes");
register_setting("cookies_settings_group", "facebook_pixel_id");

// Google Analytics ID field
add_settings_field("google_analytics_id", __("Google Analytics ID", "t"), "display_google_analytics_id", "cookies_settings_page", "section_cookies_codes");
register_setting("cookies_settings_group", "google_analytics_id");

// Google Ads ID field
add_settings_field("google_ads_id", __("Kód Instagram", "t"), "display_google_ads_id", "cookies_settings_page", "section_cookies_codes");
register_setting("cookies_settings_group", "google_ads_id");
}
add_action("admin_init", "cookies_settings");


// Basic website type settings fields functions

Expand Down Expand Up @@ -341,5 +391,43 @@ function display_video_link() {
<?php
}

function display_use_cookies() {
$use_cookies = get_option("use_cookies");
?>
<input type="checkbox" name="use_cookies" <?php echo checked('on', $use_cookies, false); ?> /> <?php _e('Pro zapnutí podpory Cookies zaškrtněte.', 't'); ?>
<?php
}

function display_sklick_id() {
$sklick_id = get_option("sklick_id");
?>
<input type="text" name="sklick_id" value="<?php echo esc_attr($sklick_id); ?>" style="width: 300px;" />
<p class="description"><?php _e('Zadejte ID pro Sklick.', 't'); ?></p>
<?php
}

function display_facebook_pixel_id() {
$facebook_pixel_id = get_option("facebook_pixel_id");
?>
<input type="text" name="facebook_pixel_id" value="<?php echo esc_attr($facebook_pixel_id); ?>" style="width: 300px;" />
<p class="description"><?php _e('Zadejte ID pro Facebook Pixel.', 't'); ?></p>
<?php
}

function display_google_analytics_id() {
$google_analytics_id = get_option("google_analytics_id");
?>
<input type="text" name="google_analytics_id" value="<?php echo esc_attr($google_analytics_id); ?>" style="width: 300px;" />
<p class="description"><?php _e('Zadejte ID pro Google Analytics', 't'); ?></p>
<?php
}

function display_google_ads_id() {
$google_ads_id = get_option("google_ads_id");
?>
<input type="text" name="google_ads_id" value="<?php echo esc_attr($google_ads_id); ?>" style="width: 300px;" />
<p class="description"><?php _e('Zadejte ID pro Google Ads.', 't'); ?></p>
<?php
}

?>

0 comments on commit 38c2436

Please sign in to comment.