Skip to content

Commit

Permalink
Merge pull request #22 from iamapinan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
iamapinan authored Jun 27, 2020
2 parents d1951ce + 36055f7 commit 600a5a0
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 60 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ You can edit the term page and publish on your website with elegant and powerful
* WordPress Bangkok friends

### Changelogs
### 1.0.9
* Add wp_footer hook support

### 1.0.8
* Fixed WP Super Cache issue.
Expand Down
8 changes: 6 additions & 2 deletions assets/pdpa-consent-user.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.pdpa_user_warp button {
padding: 10px 25px;
border-radius: 30px;
line-height: 20px;
font-size: 16px;
margin: 3px;
}
Expand All @@ -32,7 +33,6 @@
border-radius: 50%;
width: 96px;
height: 96px;
margin-top: 20px;
margin-left: 20px;
}

Expand All @@ -44,7 +44,7 @@
}
.profile-header-top .user_title h3 {
margin-bottom: 10px;
margin-top: 15px;
margin-top: 0px;
color: #fff;
}
.profile-header-top .user_title p {
Expand All @@ -57,3 +57,7 @@
.profile-header-top .user_title .status_bage {
color: #fff;
}
.pdpa_user_warp .user_data td, .pdpa_user_warp .user_data th {
border: 1px solid #ccc;
padding: 5px;
}
4 changes: 1 addition & 3 deletions assets/pdpa-consent-user.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions assets/pdpa-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

document.addEventListener("DOMContentLoaded", function () {
if (pdpa_ajax.consent_enable === "yes") {
if (pdpa_ajax.consent_enable === "yes" && pdpa_get_cookie() == null) {
document.getElementById("PDPANotAllow").addEventListener("click", function() {
pdpa_consent_call('pdpa-not-allow');
document.getElementById("pdpa_screen").style.display = 'none'
Expand All @@ -16,7 +16,6 @@ document.addEventListener("DOMContentLoaded", function () {
}
})


const pdpa_consent_call = (action_require) => {
var pdpa_request_data = new FormData();
pdpa_request_data.append("action", "pdpa_action");
Expand All @@ -30,15 +29,15 @@ const pdpa_consent_call = (action_require) => {
})
.then(function (response) {
//handle success
cookie_process(response.data);
pdpa_cookie_process(response.data);
})
.catch(function (response) {
//handle error
console.log(response);
});
}

const cookie_process = (d) => {
const pdpa_cookie_process = (d) => {
var cookie_string = '';
if (d.type == 'user_allow') {
cookie_string = d.cookie_name + "=1; expires=" + d.cookie_expire + "; domain=" + d.cookie_domain + "; path=/";
Expand All @@ -50,10 +49,11 @@ const cookie_process = (d) => {
} else {
console.log("error.", d)
}
console.log(cookie_string)
document.cookie = cookie_string;
}

const deleteAllCookies = () => {
const pdpa_delete_all_cookie = () => {
var cookies = document.cookie.split(";");

for (var i = 0; i < cookies.length; i++) {
Expand All @@ -62,4 +62,17 @@ const deleteAllCookies = () => {
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}

function pdpa_get_cookie() {
var cookieArr = document.cookie.split(";");

for(var i = 0; i < cookieArr.length; i++) {
var cookiePair = cookieArr[i].split("=");
if('pdpa_accepted' == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}

return null;
}
2 changes: 1 addition & 1 deletion assets/pdpa-consent.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
exit;
}

class pdpa_consent_admin_option
class PDPA_Admin
{
private $plugin_info = array();
private $capability = 'manage_options';
Expand Down Expand Up @@ -96,24 +96,17 @@ public function pdpa_admin_option()
$this->generate_post_from_template();
} ?>
<style>
.admin-page form {
padding: 15px;
background-color: #fff;
margin: 20px 20px;
border: 1px solid #e4e4e4;
border-radius: 4px;
box-shadow: 2px 2px 4px rgba(3, 3, 3, 0.03);
.wrap form {
margin-top: 20px;
}
.admin-page form th {
text-align: right;
}
.admin-page form h2 {
font-size: 18pt;
margin-top: 10px;
.wrap form h2 {
border-bottom: 1px solid #ccc;
padding-bottom: 15px;
}
</style>
<?php settings_errors(); ?>
<div class="admin-page">
<div class="wrap">
<h2><?php _e('PDPA Consent', 'pdpa-consent');?></h2>
<form method="post" action="options.php" id="pdpaConsent">
<?php
settings_fields('_pdpa_setting_group');
Expand Down Expand Up @@ -369,7 +362,7 @@ public function popup_type_callback()
public function popup_message_callback()
{
printf(
'<textarea class="regular-text" rows=4 name="pdpa_option[popup_message]" id="popup_message" required>%s</textarea>',
'<textarea class="large-text" rows=4 name="pdpa_option[popup_message]" id="popup_message" required>%s</textarea>',
isset($this->options['popup_message']) ? esc_html($this->options['popup_message']) : __('Your privacy is important to us. We need your data just for the important process of services. Please allow if you accept the term of privacy comply with PDPA.', 'pdpa-consent')
);
}
Expand All @@ -386,15 +379,15 @@ public function website_name_callback()
public function description_callback()
{
printf(
'<input class="regular-text" type="text" name="pdpa_option[site_description]" id="site_description" value="%s">',
'<input class="large-text" type="text" name="pdpa_option[site_description]" id="site_description" value="%s">',
isset($this->options['site_description']) ? esc_html($this->options['site_description']) : ''
);
}

public function list_data_callback()
{
printf(
'<textarea class="regular-text" rows=5 name="pdpa_option[list_data]" id="list_data" placeholder="%s" required>%s</textarea>',
'<textarea class="large-text" rows=5 name="pdpa_option[list_data]" id="list_data" placeholder="%s" required>%s</textarea>',
__("Fullname\nBirthday\nEtc."),
isset($this->options['list_data']) ? esc_html($this->options['list_data']) : ''
);
Expand All @@ -403,7 +396,7 @@ public function list_data_callback()
public function address_callback()
{
printf(
'<input class="regular-text" type="text" name="pdpa_option[site_address]" id="site_address" value="%s" required>',
'<input class="large-text" type="text" name="pdpa_option[site_address]" id="site_address" value="%s" required>',
isset($this->options['site_address']) ? esc_html($this->options['site_address']) : ''
);
}
Expand Down
11 changes: 8 additions & 3 deletions includes/frontends/user_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
<button id="pdpa-status-reset"><?php _e('Reset consent', 'pdpa-consent');?></button>
<button><?php _e('Delete account', 'pdpa-consent');?></button>
</div>
<pre>
<?php print_r($user_info->data);?>
</pre>
<table class="user_data">
<?php foreach($user_info->data as $user_key => $user_data):?>
<tr>
<th width=220><?php echo $user_key;?></th>
<td><?php echo json_encode($user_data);?></td>
</tr>
<?php endforeach;?>
</table>
<?php else: ?>
<div class="user_toolbar">
<button id="pdpa-status-reset"><?php _e('Reset consent', 'pdpa-consent');?></button>
Expand Down
50 changes: 32 additions & 18 deletions includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,39 @@
* (c) Apinan Woratrakun <[email protected]>
*/

function load_script()
{
wp_enqueue_style('pdpa-consent-user', plugins_url('pdpa-consent/assets/pdpa-consent-user.css'), array(), date('m', time()));
wp_enqueue_script('pdpa-consent-user', plugins_url('pdpa-consent/assets/pdpa-consent-user.js'), array(), date('m', time()));
}
Class PDPA_User {
function __construct() {
$this->load();
}

function user_page_shortcode($atts)
{
load_script();
function load() {
add_shortcode('pdpa_user_page', [$this, 'user_page_shortcode']);
}

$user_id = get_current_user_id();
$isLogin = is_user_logged_in();
$user_info = get_userdata($user_id);
function load_script()
{
$plugin_info = get_plugin_data(PDPA_PATH . 'pdpa-consent.php');

wp_enqueue_style('pdpa-consent-user', plugins_url('pdpa-consent/assets/pdpa-consent-user.css'), array(), $plugin_info['Version']);
wp_enqueue_script('pdpa-consent-user', plugins_url('pdpa-consent/assets/pdpa-consent-user.js'), array(), $plugin_info['Version'], true);
}

render_template('user_template', [
'user_id' => $user_id,
'user_info' => $user_info,
'is_login' => $isLogin
]);
}
function user_page_shortcode($atts)
{
$user_id = get_current_user_id();
$isLogin = is_user_logged_in();
$user_info = get_userdata($user_id);
$this->load_script();

add_shortcode('pdpa_user_page', 'user_page_shortcode');
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
$user_info->meta = get_user_meta( $user->ID );
}

render_template('user_template', [
'user_id' => $user_id,
'user_info' => $user_info,
'is_login' => $isLogin
]);
}
}
21 changes: 13 additions & 8 deletions pdpa-consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
Plugin Name: PDPA Consent
Description: PDPA Consent allows you to notify to the user to accept privacy terms. Comply with Thailand PDPA law.
Version: 1.0.8
Version: 1.0.9
Author: Apinan Woratrakun
Author URI: https://www.facebook.com/9apinan
Plugin URI: https://github.com/iamapinan/PDPA-Consent
Expand All @@ -30,7 +30,7 @@
// Includes
include_once(PDPA_PATH . 'includes/admin.php');
include_once(PDPA_PATH . 'includes/template.php');
// include_once(PDPA_PATH . 'includes/user.php');
include_once(PDPA_PATH . 'includes/user.php');

class PDPA_Consent
{
Expand All @@ -54,7 +54,8 @@ public function __construct()
$this->options = get_option('pdpa_option');

$this->init();
new pdpa_consent_admin_option;
new PDPA_Admin;
new PDPA_User;
}

public function init()
Expand All @@ -66,6 +67,8 @@ public function init()
// Add consent html to frontend
if (function_exists('wp_body_open')) {
add_action('wp_body_open', array( $this, 'add_consent'), 20);
} else {
add_action('wp_footer', array( $this, 'add_consent'), 20);
}

// Ajax request for logged in user
Expand Down Expand Up @@ -140,11 +143,11 @@ public function generate_pdpa_user_page()

public function pdpa_enqueue_scripts()
{
wp_enqueue_style('pdpa-consent', plugins_url('assets/pdpa-consent.css', __FILE__), array(), $this->plugin_info['Version']);
wp_enqueue_style($this->plugin_info['TextDomain'], plugins_url('assets/pdpa-consent.css', __FILE__), array(), $this->plugin_info['Version']);

// Register the script
wp_enqueue_script('pdpa_axios', plugins_url('assets/axios.min.js', __FILE__), array(), $this->plugin_info['Version'], true);
wp_register_script('pdpa_ajax_handle', plugins_url('assets/pdpa-consent.js', __FILE__), array(), $this->plugin_info['Version'], true);
wp_enqueue_script($this->plugin_info['TextDomain'], plugins_url('assets/axios.min.js', __FILE__), array(), $this->plugin_info['Version'], true);
wp_register_script('pdpa-script-base', plugins_url('assets/pdpa-consent.js', __FILE__), array(), $this->plugin_info['Version'], true);

// Localize the script with new data
$ajax_array = array(
Expand All @@ -155,11 +158,13 @@ public function pdpa_enqueue_scripts()
'pdpa_version' => $this->plugin_info['Version']
);

wp_localize_script('pdpa_ajax_handle', 'pdpa_ajax', $ajax_array);
wp_localize_script('pdpa-script-base', 'pdpa_ajax', $ajax_array);

// Enqueued script with localized data.
wp_enqueue_script('pdpa_ajax_handle');
wp_enqueue_script('pdpa-script-base');
}


/**
* Check is cookie set
*/
Expand Down
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: pdpa, gdpr, pdpa-consent, cookie, notice, notification, notify, cookie, co
Requires at least: 5.2
Requires PHP: 5.4.6
Tested up to: 5.4.1
Stable tag: 1.0.8
Stable tag: 1.0.9
License: GNU 3.0
License URI: https://opensource.org/licenses/lgpl-3.0.html

Expand Down Expand Up @@ -92,6 +92,8 @@ No questions yet.
3. screenshot-3.png

== Changelog ==
= 1.0.9 =
* Add wp_footer hook support

= 1.0.8 =
* Fixed WP Super Cache issue.
Expand Down

0 comments on commit 600a5a0

Please sign in to comment.