<?php
	/*
	Plugin Name: Simple GDPR
	Plugin URI: http://cellarweb.com/wordpress-plugins/
	Description: Simple process to create a 'cookies are OK' banner/button; assumes that site cannot be accessed unless you agree. Creates a privacy page based on US Better Business Bureau recommendations (your country might have different requirements). Also allows for use of Google Analytics via server-side request, to allow analytics tracking if ad-blocking is enabled by the visitor. 
	Version: 1.30
	Tested up to: 5.9
	Requires at least: 4.9.6
	PHP Version: 5.3
	Author: Rick Hellewell - CellarWeb.com
	Author URI: http://CellarWeb.com
	License: GPLv2 or later
	License URI: http://www.gnu.org/licenses/gpl-2.0.html
	License for CookieConsent code: MIT License https://cookieconsent.insites.com/documentation/license/
	 */

	/*
	Copyright (c) 2016-2019 by Rick Hellewell and CellarWeb.com
	All Rights Reserved

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License, version 2, as
	published by the Free Software Foundation.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA

	 */

	// ----------------------------------------------------------------
	// increase time allowed for process to run; more time required for large site
	set_time_limit(300); // 5 minutes
	// increase allowable memory, for large sites, especially with email
	ini_set('memory_limit', '256M');

	// ----------------------------------------------------------------
	// Let's get started!
	global $atts; // used for the shortcode parameters
	define("SGDPR_version", "1.30 (10 Mar 2021)");
	// check for required versions of WP and PHP
	$min_wp = '4.9.6';
	$min_php = '5.4';
	if (!SGDPR_is_requirements_met($min_wp, $min_php)) {
		add_action('admin_init', 'SGDPR_disable_plugin');
		add_action('admin_notices', 'SGDPR_show_notice_disabled_plugin');
		add_action('network_admin_init', 'SGDPR_disable_plugin');
		add_action('network_admin_notices', 'SGDPR_show_notice_disabled_plugin');
		SGDPR_deregister();
		return;
	}
	// create page after theme and other stuff loaded                                                 
	add_filter('after_setup_theme','SGDPR_create_privacy_page');  
	function SGDPR_create_privacy_page()
	{
		if ($_POST['create_privacy_page'] == 'Create Generic Privacy Page') {
			$blog_page_content = SGDPR_privacy_page_content();
			$blog_page = array(
				'post_type' => 'page',
				'post_title' => 'Privacy Page',
				'post_content' => $blog_page_content,
				'post_status' => 'publish',
				'post_author' => 1,
				'post_slug' => 'privacy_page'
			);
			$blog_page_id = wp_insert_post($blog_page);
			if ($blog_page_id) {
				add_action('admin_notices', 'SGDPR_page_created_notice');
				add_action('network_admin_notices', 'SGDPR_page_created_notice');
				return $blog_page_id;
			} else {
				add_action('admin_notices', 'SGDPR_page_not_created_notice');
				add_action('network_admin_notices', 'SGDPR_page_not_created_notice');
				return false;
			}
		}
		return;
	}

	// insert into the header the code to display the banner
	add_action('wp_head', 'SGDPR_the_header');

	// Check whether the button on the admin/settings page has been pressed
	if (isset($_POST['SGDPR_button']) == 'SGDPR_button') {
		// SGDPR_sanitize all POST variables
		$_POST = filter_input_array(INPUT_POST, FILTER_SGDPR_sanitize_STRING);
		$_GET = filter_input_array(INPUT_GET, FILTER_SGDPR_sanitize_STRING);
		// the button has been pressed, so we do something that the button is supposed to do
		add_action('admin_init', "SGDPR_site_show_posts");
	}

	// if we want to display an admin notice
	function SGDPR_notice_page_created($msg = "an admin message")
	{

		echo '<div class="notice notice-success is-dismissible">' . $msg . '</div>';
		return;
	}
	// ----------------------------------------------------------------
	function SGDPR_output_empty()
	{
		return;
	}

	// remove the 'thank you' and WP version number from the admin footer,
	// because it sometimes overwriting the settings page after the HTML is created
	function SGDPR_remove_admin_footer()
	{
		return '';
	}

	add_filter('admin_footer_text', 'SGDPR_remove_admin_footer', 999);
	add_filter('update_footer', 'SGDPR_remove_admin_footer', 999);

	// Add settings link on plugin page
	function SGDPR_settings_link($links)
	{
		$settings_link = '<a href="options-general.php?page=SGDPR_settings" title="Simple GDPR">Simple GDPR Settings</a>';
		array_unshift($links, $settings_link);
		return $links;
	}

	$plugin = plugin_basename(__FILE__);
	add_filter("plugin_action_links_$plugin", 'SGDPR_settings_link');

	//  build the class for all of this
	class SGDPR_settings_page
	{
		/**
		 * Holds the values to be used in the fields callbacks
		 */
		private $options;

		/**
		 * Start up
		 */
		public function __construct()
		{
			add_action('admin_menu', array($this, 'SGDPR_add_plugin_page'));
			add_action('admin_init', array($this, 'SGDPR_page_init'));
		}

		/**
		 * Add options page
		 */
		public function SGDPR_add_plugin_page()
		{
			// This page will be under "Settings"
			add_options_page(
				'Settings Admin',
				'Simple GDPR Settings',
				'manage_options',
				'SGDPR_settings',
				array($this, 'SGDPR_create_admin_page')
			);
		}

		/**
		 * Options page callback
		 */
		public function SGDPR_create_admin_page()
		{
			// Set class property
			$this->options = get_option('SGDPR_options');
		?>

<div class="wrap"> 
	<!--<h1>Simple GDPR Options</h1>-->
	<?php  SGDPR_info_top(); ?>
	<?php //SGDPR_print_section_info(); ?>
	<form method="post" action="options.php">
		<?php
        	// This prints out all hidden setting fields
        			settings_fields('SGDPR_my_option_group');
        			do_settings_sections('SGDPR_settings');
        			submit_button();
        		?>
	</form>
	<?php SGDPR_info_bottom();?>
</div>
<?php
	}

		/**
		 * Register and add settings
		 */
		public function SGDPR_page_init()
		{
			register_setting(
				'SGDPR_my_option_group', // Option group
				'SGDPR_options', // Option name
				array($this, 'SGDPR_sanitize') // SGDPR_sanitize
			);

			add_settings_section(
				'SGDPR_setting_section_id', // ID
				'Simple GDPR Settings', // Title
				array($this, 'SGDPR_print_section_info'), // Callback
				'SGDPR_settings' // Page
			);

			add_settings_field(
				'SGDPR_privacy_page_name',
				'Privacy Page name',
				array($this, 'SGDPR_privacy_url_callback'),
				'SGDPR_settings',
				'SGDPR_setting_section_id',
				array('fieldsize' => '50', 'fieldmax' => '50')
			);

			add_settings_field(
				'SGDPR_add_link_to_footer', // ID
				'Add Privacy Page link to footer', // Title
				array($this, 'SGDPR_add_link_to_footer_callback'), // Callback
				'SGDPR_settings', // Page
				'SGDPR_setting_section_id' // Section
			);

			add_settings_field(
				'SGDPR_GA_ID_number', // ID
				'Google Analytics ID Number', // Title
				array($this, 'SGDPR_GA_ID_number_callback'), // Callback
				'SGDPR_settings', // Page
				'SGDPR_setting_section_id' // Section
			);
		}

		/**
		 * SGDPR_sanitize each setting field as needed
		 *
		 * @param array $input Contains all settings fields as array keys
		 */
		public function SGDPR_sanitize($input)
		{
			$new_input = array();
			if (isset($input['SGDPR_GA_ID_number'])) {
				$new_input['SGDPR_GA_ID_number'] = sanitize_text_field($input['SGDPR_GA_ID_number']);
			} else {$new_input['SGDPR_GA_ID_number']='';}

			if (isset($input['SGDPR_privacy_page_name'])) {
				$new_input['SGDPR_privacy_page_name'] = sanitize_text_field($input['SGDPR_privacy_page_name']);
			} else {$new_input['SGDPR_privacy_page_name']='';} 

			if (isset($input['SGDPR_add_link_to_footer'])) {
				$new_input['SGDPR_add_link_to_footer'] = "1";} else { $new_input['SGDPR_add_link_to_footer'] = "0";}

			// also update the WP/core privacy setting option
			SGDpR_save_wp_core_privacy_page_id();

			return $new_input;
		}

		/**
		 * Print the Section text
		 */
		public function SGDPR_print_section_info()
		{
			print '<p>Simple GDPR creates the "Cookie and Privacy Terms" Acceptance message and button at the top of all pages on your site, and stores a cookie that keeps track of that setting for the user. The message will continue to display on all pages until the visitor clicks the "OK" button. It will redisplay once a year, or after the visitor removes or deletes the "acceptance" cookie.</p><p>If you enter a Google Analytics ID Number, the plugin will use server-side commands to capture basic Google Analytics information to your GA account. This allows analytics tracking for visitors that have ad-blockers, an advantage over the \'normal\' GA process of using client-side JavaScript code.</p><p>The Privacy Page name should be the page that contains your Privacy Page terms; you can create that page by clicking the yellow button. After creation, you can modify the page content if you wish. You can also display the Privacy Page link in the footer of all pages.</p><p>Please see the Disclaimer information below for additional information.</p>';
		}

		/**
		 * Get the settings option array and print one of its values
		 */
		public function SGDPR_GA_ID_number_callback()
		{
			printf(
				'<input type="text" id="SGDPR_GA_ID_number"
				 name="' . 
				 $SGDPR_options["SGDPR_GA_ID_number"] .
				 '" value="%s" size="20" maxlength="20"
				  />',
				isset($this->options['SGDPR_GA_ID_number']) ? esc_attr($this->options['SGDPR_GA_ID_number']) : ''
			);
			print(' Enter your GA ID number; it is not verified. If you don\'t want GA tracking, or use another process, leave this blank. Note that the standard GA JavaScript code might be blocked by ad blockers, so we use a server-side process to allow basic tracking for visitors with ad blocking enabled on their browser.');
		}

		// content checkbox callback
		public function SGDPR_add_link_to_footer_callback() {
			printf(
				"<input type='checkbox' id='SGDPR_add_link_to_footer' name='SGDPR_options['SGDPR_add_link_to_footer]' value='%s' " . checked('1', $this->options['SGDPR_add_link_to_footer'], false) . " />",
				isset($this->options['SGDPR_add_link_to_footer']) ? '1' : '0');
			print(' Enable to add Privacy Page link to site footer. The link will use the Privacy Page stored in Settings, Privacy.');
		}

		/**
		 * Get the settings option array and print one of its values
		 */
		public function SGDPR_privacy_url_callback()
		{
			$selected_page_option = get_option('SGDPR_options');
			$selected_page_id = $selected_page_option['SGDPR_privacy_page_name'];
			//echo "the id = " . $selected_page_id . "<br>";
			if ($selected_page_id) {
				$selected_page = get_the_title($selected_page_id);
			}
			printf(
				wp_dropdown_pages(array('echo' => 0, 'post_type' => 'page', 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'selected' => $selected_page_id, 'name' => "SGDPR_options['SGDPR_privacy_page_name']", )),
				isset($this->options['SGDPR_privacy_page_name']) ? esc_attr($this->options['SGDPR_privacy_page_name']) : ''
			);
			print(' Select the name of your Privacy Page. This will be used to create the link in the GDPR message.&nbsp;&nbsp;This also changes the Privacy page in the Settings, Privacy screen. Note that if you change the Privacy Page Name in Settings, Privacy, you will need to change it on this page also.');
		}
	}

	if (is_admin()) {
		$my_settings_page = new SGDPR_settings_page();
	}

	// end of the class stuff

	// ----------------------------------------------------------------------------
	// supporting functions
	// ----------------------------------------------------------------------------
	//  display the top info part of the settings page
	// ----------------------------------------------------------------------------
	function SGDPR_info_top()
	{
	?>
<div class="wrap" >
	<h2></h2>
	<!-- placeholder for any WP admin status messages -->
	<hr />
	<!-- next is text to display under the plugin banner text -->
	<div style="background-color:#9FE8FF;padding-left:15px;padding-bottom:10px;margin-bottom:15px;"> <br />
		<h1 align="center">Simple GDPR</h1>
		<p align="center">Adds a simple GDPR Compliance message and button to your site. Optionally allows you to add server-side Google Analytics.</p>
		<!-- next displays the plugin version stuff -->
		<h5>Version <?php echo SGDPR_version; ?></h5>
	</div>
	<hr />
	<!-- next is the information/description of the plugin; displays under the banner -->
	<?php //SGDPR_button_admin_page();?>
</div>
<?php
	}

	// ----------------------------------------------------------------------------
	// display the copyright info part of the adminpage
	// ----------------------------------------------------------------------------
	function SGDPR_info_bottom()
	{
		SGDPR_create_page_button();  // show the create the privacy page button
		// print copyright with current year, never needs updating
		$xstartyear = "2016";
		$xname = "Rick Hellewell";
		$xcompanylink1 = ' <a href="http://CellarWeb.com" title="CellarWeb" >CellarWeb.com</a>';
		echo '<hr><div style="background-color:#9FE8FF;padding-left:15px;padding:10px 0 10px 0;margin:15px 0 15px 0;">
    <p align="center"><strong>Copyright &copy; ' . $xstartyear . '- ' . date("Y") . ' by ' . $xname . ' and ' . $xcompanylink1;
		echo ' , All Rights Reserved. Released under GPL2 license. <a href="http://cellarweb.com/contact-us/" target="_blank" title="Contact Us">Contact us page</a>.</strong></p></div><hr>';
		return;
	}

	// ----------------------------------------------------------------------------
	function SGDPR_button_admin_page()
	{
		// This function creates the output for the admin page.
		// It also checks the value of the $_POST variable to see whether
		// there has been a form submission.
		// The check_admin_referer is a WordPress function that does some security
		// checking and is recommended good practice.
		global $SGDPR_submit_html; // text for html button
		global $SGDPR_submit_create_page; // text for html button
		// General check for user permissions.
		if (!current_user_can('manage_options')) {
			wp_die(__('You do not have sufficient privileges to access this page.'));
		}
		// Start building the page
		echo '<div class="wrap">';
		echo '<hr>';
		echo '<div style="border:thin solid #000; padding: 5px 15px 5px 15px;margin-left: 15px;max-width:800px;list-style:none !important;">';
		echo "<p>A simple way to add GDPR compliance to your site. Adds a banner to all pages that must be clicked to 'actively acknowledge' acceptance of use of cookies and tracking. Will also add server-side Google Anlaytics, for those visitors that use ad-blocking, if you fill in your GA user ID below and Save Settings.</p>";

		// form starts here if we want a button to do anything
		echo '<form action="options.php" method="post">';
		settings_fields('SGDPR_options');
		do_settings_section('SGDPR_options');

	?>
<?php
	submit_button($SGDPR_submit_html, 'button-primary', 'SGDPR_button');
		echo '</form>';
		// end of the form
		echo "<hr style=\"border-top: 3px solid #2ebc57;\" />";

	?>
<?php

		echo '<hr>';
	}

	// ----------------------------------------------------------------------------
	// ----------------------------------------------------------------------------
	// register/deregister/uninstall hooks
	register_activation_hook(__FILE__, 'SGDPR_register');
	register_deactivation_hook(__FILE__, 'SGDPR_deregister');
	register_uninstall_hook(__FILE__, 'SGDPR_uninstall');

	// register/deregister/uninstall options (even though there aren't options)
	function SGDPR_register()
	{
		return;
	}

	function SGDPR_deregister()
	{
		return;
	}

	function SGDPR_uninstall()
	{
		return;
	}

	//----------------------------------------------------------------------------
	// delete old generated files
	function SGDPR_delete_old_files()
	{
		return true;
	}

	// ----------------------------------------------------------------------------
	// debugging function to show array values nicely formatted; not used; for debugging
	function SGDPR_show_array($xarray = array())
	{
		echo "<pre>";
		print_r($xarray);
		echo "</pre>";
		$x = "<pre>" . print_r($xarray) . "</pre>";
		return $x;
	}

	// ----------------------------------------------------------------------------
	// check if at least WP 4.6 and PHP version at least 5.3
	// based on https://www.sitepoint.com/preventing-wordpress-plugin-incompatibilities/
	function SGDPR_is_requirements_met($min_wp = '4.6', $min_php = '5.3')
	{
		// Check for WordPress version
		if (version_compare(get_bloginfo('version'), $min_wp, '<')) {
			return false;
		}
		// Check the PHP version
		if (version_compare(PHP_VERSION, $min_php, '<')) {
			return false;
		}
		return true;
	}

	// ----------------------------------------------------------------------------
	// disable plugin if WP/PHP versions are not enough
	function SGDPR_disable_plugin()
	{
		if (is_plugin_active(plugin_basename(__FILE__))) {
			deactivate_plugins(plugin_basename(__FILE__));
			// Hide the default "Plugin activated" notice
			if (isset($_GET['activate'])) {
				unset($_GET['activate']);
			}
		}
	}

	// ----------------------------------------------------------------------------
	// show notice that plugin was deactivated because WP/PHP versions not enough
	function SGDPR_show_notice_disabled_plugin()
	{
		echo '<div class="notice notice-error is-dismissible"><h3><strong>Simple GDPR</strong></h3><p> cannot be activated - requires at least WordPress 4.6 and PHP 5.3.&nbsp;&nbsp;&nbsp;Plugin automatically deactivated.</p></div>';
		return;
	}

	// ----------------------------------------------------------------------------
	// admin notice if something failed
	function SGDPR_admin_notice_generic_error($theerrors = array('Something did not work correctly!'))
	{
		foreach ($the_errors as $the_error) {
			echo "<div class='notice notice-error is-dismissible'><h3><strong>Simple GDPR</strong></h3><p> - Error: $the_error .</p></div>";
		}
		return;
	}

	// ----------------------------------------------------------------------------
	// this adds the two functions to the head section via the hook for public pages
	function SGDPR_the_header()
	{
		SGDPR_cookie_compliance();	// shows the cookie acceptance notice if needed
		$SGDPR_analytics_ID = '';
		$SGDPR_options = get_option('SGDPR_options');
		$SGDPR_GA_ID = $SGDPR_options['SGDPR_GA_ID_number'];
		// do server-side analytics if enabled by a GA ID on settings screen
		if ($SGDPR_GA_ID) {
			SGDPR_set_cookie();
			SGDPR_analytics($SGDPR_GA_ID);
		}
		return;
	}

	//------------------------------------------------------------------------------
	// new version to allow analytics on adblock pages by using server-side post
	function SGDPR_analytics($SGDPR_GA_ID)
	{
		// get the GA ID from the options table
		$url = 'https://www.google-analytics.com/collect?';
		if (empty($SGDPR_GA_ID)) {return false;}
		if (! $_COOKIE['GA_user_id']) {
			SGDPR_set_cookie();
		}
		$pagename = basename(get_permalink());  // current page name, WP-style
		if (wp_get_referer()) {$page_referrer = wp_get_referer();} else {$page_referrer = "";}
		$page_referrer = urlencode($page_referrer);
		$post_array = array(
			'v' => 1,				// version #, required
			't' => 'pageview',		// hit type, required
			'tid' => $SGDPR_GA_ID,	// the account it, required
			'cid' => $_COOKIE['GA_user_id'],	// client ID, should be same for each visitor during their session
			'dp' => '/' . $pagename,	// page name
			'aip' => 1,		//anonymize IP, optional
			'ds' => 'web', 	// datasource, optional, set to 'web'
			'dr' => $page_referrer,		// referring page
 			'uip' => $_SERVER['REMOTE_ADDR'],	 // used for geo data in analytics	
			'z' => SGDPR_guidv4() , 	// cache buster, MUST BE LAST parameter!
	);
		$fields_string = http_build_query($post_array);
		// send the post via wp_remote_post
		$response = wp_remote_post($url . $fields_string);
		return $result;
	}

//------------------------------------------------------------------------------
// creates a guid for use by the GA post to send unique user id
	function SGDPR_guidv4()
	{
		if (function_exists('com_create_guid') === true) {
			return trim(com_create_guid(), '{}');
		}

		$data = openssl_random_pseudo_bytes(16);
		$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
		$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
		return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
	}

	//------------------------------------------------------------------------------
	// if we can't find the consent cookie, then ... 
	if (! $_COOKIE['cookieconsent_status']) {
		add_action('after_header','SGDPR_cookie_compliance'); 	// add the compliance message
		add_action('wp_enqueue_scripts', 'SGDPR_cookie_script');	// add the compliance script
		add_action('wp_enqueue_scripts', 'SGDPR_cookie_css');		// add the compliance css
	}

	//------------------------------------------------------------------------------
	// GDPF compliance from https://cookieconsent.insites.com/
	// their javascript used under MIT license
	function SGDPR_cookie_compliance()
	{
		global $SGDPR_learn_more_url;
		// figure out the privacy page name from the saved options
		$selected_page_option = get_option('SGDPR_options');
		$selected_page_id = $selected_page_option['SGDPR_privacy_page_name'];
		if ($selected_page_id) {
			$SGDPR_learn_more_url = site_url() . '/' . get_the_title($selected_page_id);
		} else { $SGDPR_learn_more_url = site_url();}
	?>
<!-- display the consent message using the API after page is loaded --> 
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
 "palette": {
 "popup": {
"background": "#237afc"
 },
 "button": {
"background": "#f1d600",
"text": "#000"
 }
 },
 "position": "top",
 "content": {
 "dismiss": "I agree - OK with me! (Click here)",
    "message": "This website uses cookies to ensure you get the best experience on our website. We may also store personal information (name, email) if you add comments to the site, or if you use our Contact form. By browsing our site, you agree to our use of cookies and storage of other personal information. Click the 'I agree' button to agree and continue viewing our site. Or, ",
    "href" : "<?php echo $SGDPR_learn_more_url; ?>",
 }
})});
</script>
<?php

		return;
	}
	//------------------------------------------------------------------------------
	// these enqueue the JS and CSS; included in the plugin dist
		function SGDPR_cookie_script() {
			wp_enqueue_script('cookieconsent_js', plugin_dir_url( __FILE__ ) . 'js/cookieconsent/cookieconsent.min.js');
		}
		function SGDPR_cookie_css(){
			wp_enqueue_style('cookieconsent_css', plugin_dir_url( __FILE__ ) . 'js/cookieconsent/cookieconsent.min.css');
			wp_enqueue_style('cookieconsent_css_extra', plugin_dir_url( __FILE__ ) . 'css/consent_extra.css');
		}

	//------------------------------------------------------------------------------
	// generic content if we create the privacy page
	function SGDPR_privacy_page_content()
	{
		$page_content = "
<h3>Privacy Notice</h3>
<p>This privacy notice discloses the privacy practices for this site. This privacy notice applies solely to information collected by this website. It will notify you of the following: What personally identifiable information is collected from you through the website, how it is used and with whom it may be shared.
<ul>
    <li>What choices are available to you regarding the use of your data.</li>
    <li>The security procedures in place to protect the misuse of your information.</li>
    <li>How you can correct any inaccuracies in the information.</li>
</ul>
<h3>Information Collection, Use, and Sharing</h3>
<p>We are the sole owners of the information collected on this site. We only have access to/collect information that you voluntarily give us via email, of by accessing our site, or other direct contact from you. We will not sell or rent this information to anyone. We will use your information to respond to you, regarding the reason you contacted us.</p>

<p>We will not share your information with any third party outside of our organization, other than as necessary to fulfill your request, e.g. to ship an order. Unless you ask us not to, we may contact you via email in the future to tell you about specials, new products or services, or changes to this privacy policy.</p>
<h3>Your Access to and Control Over Information</h3>
<p>You may opt out of any future contacts from us at any time. You can do the following at any time by contacting us via the email address or phone number given on our website:</p>
<ul>
    <li>See what data we have about you, if any.</li>
    <li>Change/correct any data we have about you.</li>
    <li>Have us delete any data we have about you.</li>
    <li>Express any concern you have about our use of your data.</li>
</ul>
<h3>Security</h3>
<p>We take precautions to protect your information. When you submit sensitive information via the website, your information is protected both online and offline.
</p>
<p>Wherever we collect sensitive information (such as credit card data), that information is encrypted and transmitted to us in a secure way. You can verify this by looking for a lock icon in the address bar and looking for <strong>https</strong> at the beginning of the address of the Web page.</p>
<p>While we use encryption to protect sensitive information transmitted online, we also protect your information offline. Only employees who need the information to perform a specific job (for example, billing or customer service) are granted access to personally identifiable information.</p>
<p>The computers/servers in which we store personally identifiable information are kept in a secure environment.</p>
<h3>Cookies</h3>
<p>We use cookies on this site. A cookie is a piece of data stored on a site visitor hard drive to help us improve your access to our site and identify repeat visitors to our site. For instance, when we use a cookie to identify you, you would not have to log in a password more than once, thereby saving time while on our site. Cookies can also enable us to track and target the interests of our users to enhance the experience on our site. Usage of a cookie is in no way linked to any personally identifiable information on our site.</p>
<h3>Sharing</h3>
<p>We share aggregated demographic information with our partners and advertisers. This is not linked to any personal information that can identify any individual person.</p>
<h3>Links</h3>
<p>This website contains links to other sites. Please be aware that we are not responsible for the content or privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of any other site that collects personally identifiable information.</p>
<h3>Contacting Us</h3>
<p>If you feel that we are not abiding by this privacy policy, you should contact us immediately via our Contact page.
</p>";

		return $page_content;
	}
	//------------------------------------------------------------------------------
	// plugin settings functions for data to be displayed, gathered, and stored
	//------------------------------------------------------------------------------
	// ------------------------------------------------------------------
	// Add all your sections, fields and settings during admin_init
	// ------------------------------------------------------------------
	//

	function SGDPR_settings_api_init()
	{
		// Add the section to reading settings so we can add our
		// fields to it
		add_settings_section(
			'SGDPR_setting_section',
			'Simple GDPR Settings',
			'SGDPR_setting_section_callback_function',
			''
		);

		// Add the field with the names and function to use for our new
		// settings, put it in our new section
		add_settings_field(
			'SGDPR_privacy_page_name',
			'Your Privacy Page name',
			'SGDPR_privacy_page_name_callback_function',
			'reading',
			'SGDPR_setting_section'
		);

		// Register our setting so that $_POST handling is done for us and
		// our callback function just has to echo the <input>
		register_setting('SGDPR_options', 'SGDPR_privacy_page_name');
	} // SGDPR_settings_api_init()

	// adds the above function on plugin settings page load
	add_action('admin_init', 'SGDPR_settings_api_init');

	// ------------------------------------------------------------------
	// Settings section callback function
	// ------------------------------------------------------------------
	//
	// This function is needed if we added a new section. This function
	// will be run at the start of our section
	//

	function SGDPR_setting_section_callback_function()
	{
		echo '<p>Settings for Simple GDPR</p>';
	}

	// ------------------------------------------------------------------
	// Callback function for our example setting
	// ------------------------------------------------------------------
	//
	// creates a checkbox true/false option. Other types are surely possible
	//

	function SGDPR_privacy_page_name_callback_function()
	{
		echo '<input name="Your Privacy Page name" id="SGDPR_privacy_page_name" type="text" value="" class="code"size="50" maxlength="50" /> Enter the full URL of your Privacy terms page';
	}

	// ----------------------------------------------------------------------------
	// creates the button to create the generic privacy page
	function SGDPR_create_page_button()
	{; //  SGDPR_show_test_button($SGDPR_bitly_token);
	?>
<hr />
<p>Click this button to create a generic Privacy Page. Note: each button press will create a new page called 'Privacy Page', so you may get extra ones. Save changes first.</p>
<form method="post" name="create_privacy_page" id="create_privacy_page" action="" >
	<input type="submit" name="create_privacy_page" id="create_privacy_page" value="Create Generic Privacy Page" style="background-color:yellow;"/>
</form>
<?php
	SGDPR_disclaimer();
	return $blog_page_id;}

	// ----------------------------------------------------------------------------
	// created the page successfully, so show an admin notice
	function SGDPR_page_created_notice()
	{
		echo '<div class="notice notice-success is-dismissible"><p><strong>Success!</strong> Created the new page called "Privacy Page". You can edit this page if needed. Check for duplicate pages if you have done that more than once.</p><p>Make sure you select the Privacy Page below and save changes. You should also add the new Privacy Page to your main menu.</div>';
		return;
	}
	// ----------------------------------------------------------------------------
	// whoops! didn't create the privacy page, so show the admin notice
	function SGDPR_page_not_created_notice()
	{
		echo '<div class="notice notice-error is-dismissible"><strong>Yikes!</strong>Wasn\'t able to create the Privacy Page !</p></div>';
		return;
	}
	// ----------------------------------------------------------------------------
	// show the disclaimer text on the plugin settings page
	function SGDPR_disclaimer() {
	?>
<hr>
<p><strong>Disclaimer</strong>: This plugin may not provide full protection for your site, depending on how your site stores and uses personal data. We think our technique meets the basic notification requirements of GDPR, but you should consult with your legal advisors for guidance on what your site needs to do for GDPR compliance. The plugin does not have reporting capabilities; use the WP Settings, Privacy page for managing your visitor's personal information. Here is the 'official' GDPR site: <a href="https://www.eugdpr.org/" target="_blank">https://www.eugdpr.org/</a> . </p>
<p>For reference:</p>
<ul style="list-style:disc;margin-left:15px;">
	<li>We use the code from the Cookie Consent site at <a href="https://cookieconsent.insites.com/" target="_blank">https://cookieconsent.insites.com/</a> to display the Acceptance message and track user response (via a cookie) to the message notice.</li>
	<li>For the generic Privacy Page we generate, we use the guidance from the US Better Business Bureau at <a href="https://www.bbb.org/reno/for-businesses/sample-privacy-policy/" target="_blank">https://www.bbb.org/reno/for-businesses/sample-privacy-policy/</a>. </li>
	<li>If you use Google Analytics, then you should be aware of their privacy policy, which could apply to your use of GA; see it here <a href="https://www.google.com/analytics/terms/us.html" target="_blank">https://www.google.com/analytics/terms/us.html</a> </li>
	<li>This plugin does not store any visitor's personal information on your server, except cookies on the visitor's browser. If you have enabled Google Analytics, additional cookies are stored in the visitor's browser.</li>
</ul>
<p>We suggest that you consult with your legal advisor for specific methods and messages needed for GDPR compliance on your site.<em> We provide no warranty or guarantee of GDPR compliance. We are not providing any legal advice. We are not responsible in any way for your use of our suggested GDPR solution.</em> Your mileage may vary. Objects in mirror are closer than you expect. All aspirin is alike. Professional driver on a closed course.</p>
<?php	
	
	return;
}

	// ----------------------------------------------------------------------------
	// need to set the cookies before anything else
	
	add_action( 'sanitize_comment_cookies', 'SGDPR_set_cookie',99 );

function SGDPR_set_cookie() {
			if (! $_COOKIE['GA_user_id']) {
				// some themes cause a 'headers already sent' message, so we bypass it here
				// by turning off that error message while we set the cookie.
				// see https://stackoverflow.com/a/26154061/1466973
				$previousErrorLevel = error_reporting();
				error_reporting(\E_ERROR);
				setcookie('GA_user_id', SGDPR_guidv4(),time()+(3600*24*30),'/');
				error_reporting($previousErrorLevel);
			}
	

return;
}
	// ----------------------------------------------------------------------------
	// update the WP/core privacy page ID in options
	function SGDpR_save_wp_core_privacy_page_id() {
	// maybe a hook into the options-saved-success?

		//plugin settings have been saved. This updates the WP/core privacy page id number
		update_option('wp_page_for_privacy_policy', $_POST['SGDPR_options']['SGDPR_privacy_page_name']);
		return;
	}
	// ----------------------------------------------------------------------------------
	// enable footer display of privacy page link, only if set
	$SGDPR_options = get_option('SGDPR_options');
	$insert_footer = $SGDPR_options['SGDPR_add_link_to_footer'];
	if ($insert_footer) {
		add_action('wp_head', 'gdpr_add_privacy_to_footer', 109);
	}
	function gdpr_add_privacy_to_footer() {
		$the_privacy_link = get_the_privacy_policy_link('<div align="center">', '</div>');
	?>
<script type="text/javascript">
    jQuery(document).ready(function($){
    var the_link = '<?php echo $the_privacy_link; ?>';
    $("#footer").append(the_link);
    });
    </script>
<?php
	return;
	}

	// ===============================================================================
	// ALL DONE!!
	// ===============================================================================


