Skip to content

Commit

Permalink
Merge pull request #9 from iamapinan/dev
Browse files Browse the repository at this point in the history
update feature and fix security issue
  • Loading branch information
iamapinan authored May 13, 2020
2 parents 3e7fd88 + bf51b56 commit f2da88c
Show file tree
Hide file tree
Showing 17 changed files with 704 additions and 343 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ You can edit the term page and publish on your website with elegant and powerful
* Display user PDPA Status on user list
* Multi language support (Thai, English) more translate is accept

### Roadmap

* Allow user to request profile data.
* Allow user to request to delete account.
* Allow user to allow consent again.
* User page.

### Contributors.
- **Apinan Woratrakun** *as developer* <[email protected]>, <https://facebook.com/9apinan>, <https://ioblog.me>
- **Aeknarin Sirisub** *as technical privacy system desgin* <https://www.facebook.com/swodsman>

[GNU 3.0 License](https://opensource.org/licenses/lgpl-3.0.html0)

### Special Thank
* Thai Programmer Association

![assets/pdpa-consent-logo.jpg](assets/pdpa-consent-sm.jpg)
* Thai Programmer Association
188 changes: 162 additions & 26 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

if ( ! defined( 'ABSPATH' ) ) exit;

Class AdminOption {
Class pdpa_consent_admin_option {
private $plugin_info = array();
private $capability = 'manage_options';
private $options;
Expand All @@ -19,20 +19,21 @@
public function __construct() {
$this->plugin_info = get_plugin_data( PDPA_PATH . 'pdpa-consent.php' );
$this->locale = get_locale();
$this->page_id = get_option('pdpa-page-id') ? get_option('pdpa-page-id') : 0;
$this->page_id = get_option('pdpa-consent-page-id') ? get_option('pdpa-consent-page-id') : 0;
$this->page_name = __('pdpa-term', 'pdpa-consent');
add_action( 'admin_menu', array($this, 'pdpa_admin_menu') );
add_action( 'admin_init', array($this, 'admin_option_setup') );
add_action( 'admin_enqueue_scripts', array( $this, 'pdpa_enqueue_color_picker' ) );
}

private function serialize_html($html, $settings = [ 'website_name' => '', 'site_description' => '', 'list_data' => '', 'site_address' => '', 'site_contact' => '', 'site_email' => '' ]) {
$settings['list_data'] = str_replace("\n", "</li><li>", esc_attr($settings['list_data']) );
$html = str_replace('[service]', esc_attr($settings['website_name']), $html);
$settings['list_data'] = str_replace("\n", "</li><li>", esc_html($settings['list_data']) );
$html = str_replace('[service]', esc_html($settings['website_name']), $html);
$html = str_replace('[description]', esc_attr($settings['site_description']), $html);
$html = str_replace('[list_data]', $settings['list_data'], $html);
$html = str_replace('[address]', esc_attr($settings['site_address']), $html);
$html = str_replace('[contact]', esc_attr($settings['site_contact']), $html);
$html = str_replace('[email]', esc_attr($settings['site_email']), $html);
$html = str_replace('[address]', esc_html($settings['site_address']), $html);
$html = str_replace('[contact]', esc_html($settings['site_contact']), $html);
$html = str_replace('[email]', esc_html($settings['site_email']), $html);
return $html;
}

Expand All @@ -53,15 +54,22 @@ public function generate_post_from_template() {
'post_author' => 1,
'post_type' => 'page'
);

$page_id = wp_insert_post( $page_details );
add_option( 'pdpa-page-id', $page_id );
add_option( 'pdpa-consent-page-id', $page_id );
}

function pdpa_admin_menu() {
add_menu_page( $this->plugin_info['Name'], __('PDPA Consent', 'pdpa-consent'), $this->capability, $this->plugin_info['TextDomain'], array($this, 'pdpa_admin_option'), 'dashicons-shield-alt', 81 );
}

function pdpa_enqueue_color_picker( $hook_suffix ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'pdpa-script', plugins_url('assets/pdpa-admin-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}

function pdpa_admin_option() {

if(isset($_POST)) {
$this->generate_post_from_template();
}
Expand All @@ -86,17 +94,20 @@ function pdpa_admin_option() {
<?php
}

function admin_option_setup() {
function admin_option_setup () {

register_setting(
'_pdpa_setting_group', // option_group
'_option_name', // option_name
'_option_name' // option_name
);

add_settings_section(
'_pdpa_setting_section', // id
__( 'PDPA Consent setup','pdpa-consent' ), // title
array( $this, '_section_fields' ), // callback
'settings' // page
);

}

public function _section_fields() {
Expand All @@ -119,6 +130,54 @@ public function _section_fields() {
'settings', // page
'_pdpa_setting_section' // section
);
/***
* Future functions
*
add_settings_field(
'allow_user_reset', // id
__( 'Allow user to reset consent','pdpa-consent' ), // title
array( $this, 'allow_user_reset_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
add_settings_field(
'allow_user_delete', // id
__( 'Allow user to delete account','pdpa-consent' ), // title
array( $this, 'allow_user_delete_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
add_settings_field(
'allow_user_download', // id
__( 'Allow user to download profile','pdpa-consent' ), // title
array( $this, 'allow_user_download_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
*/

add_settings_field(
'is_darkmode', // id
__( 'Use dark theme','pdpa-consent' ), // title
array( $this, 'is_darkmode_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
add_settings_field(
'allow_button_color', // id
__( 'Allow button color','pdpa-consent' ), // title
array( $this, 'allow_button_color_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
add_settings_field(
'not_allow_button_color', // id
__( 'Not allow button color','pdpa-consent' ), // title
array( $this, 'not_allow_button_color_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
);
add_settings_field(
'popup_type', // id
__( 'Notification popup type','pdpa-consent' ), // title
Expand Down Expand Up @@ -177,7 +236,7 @@ public function _section_fields() {
);
add_settings_field(
'custom_css', // id
__( 'Custom CSS','pdpa-consent' ), // title
__( 'CSS Class','pdpa-consent' ), // title
array( $this, 'custom_css_callback' ), // callback
'settings', // page
'_pdpa_setting_section' // section
Expand All @@ -186,9 +245,10 @@ public function _section_fields() {

function url_callback() {
printf(
'<a href="/?p=%s">%s</a>' ,
'<a href="/?p=%s">%s</a>&nbsp;<a href="%s"><span class="dashicons dashicons-edit"></span></a>' ,
$this->page_id,
get_site_url().'/'.$this->page_name
esc_url(get_site_url().'/?p='.$this->page_id),
esc_url(get_admin_url().'post.php?post='.get_option('pdpa-consent-page-id').'&action=edit')
);
}
function is_enable_callback() {
Expand All @@ -197,73 +257,149 @@ function is_enable_callback() {
$this->options['is_enable'] == true ? 'checked' : ''
);
}
function allow_user_reset_callback() {
printf(
'<input type="checkbox" name="_option_name[allow_user_reset]" id="allow_user_reset" value="1" %s>' ,
$this->options['allow_user_reset'] == true ? 'checked' : ''
);
}
function allow_user_delete_callback() {
printf(
'<input type="checkbox" name="_option_name[allow_user_delete]" id="allow_user_delete" value="1" %s>' ,
$this->options['allow_user_delete'] == true ? 'checked' : ''
);
}
function allow_user_download_callback() {
printf(
'<input type="checkbox" name="_option_name[allow_user_download]" id="allow_user_download" value="1" %s>' ,
$this->options['allow_user_download'] == true ? 'checked' : ''
);
}
function is_darkmode_callback() {
printf(
'<input type="checkbox" name="_option_name[is_darkmode]" id="is_enable" value="1" %s>' ,
$this->options['is_darkmode'] == true ? 'checked' : ''
);
}
function allow_button_color_callback() {
printf(
'<input type="text" name="_option_name[allow_button_color]" id="allow_button_color" value="%s" class="pdpa-color-picker">' ,
$this->options['allow_button_color']
);
}
function not_allow_button_color_callback() {
printf(
'<input type="text" name="_option_name[not_allow_button_color]" id="not_allow_button_color" value="%s" class="pdpa-color-picker">' ,
$this->options['not_allow_button_color']
);
}
function popup_type_callback() {
?>
<select name="_option_name[popup_type]">
<option value="top" <?php echo $this->options['popup_type'] == 'top' ? 'selected' : '';?>><?php _e('Top bar', 'pdpa-consent');?></option>
<option value="center" <?php echo $this->options['popup_type'] == 'center' ? 'selected' : '';?>><?php _e('Center popup', 'pdpa-consent');?></option>
<option value="bottom" <?php echo $this->options['popup_type'] == 'bottom' ? 'selected' : '';?>><?php _e('Bottom bar', 'pdpa-consent');?></option>
<option value="top" <?php echo $this->options['popup_type'] == 'top' ? 'selected' : '';?>><?php _e('Top bar', 'pdpa-consent');?></option>
</select>
<?php
}

function popup_message_callback() {
printf(
'<textarea class="regular-text" rows=4 name="_option_name[popup_message]" id="popup_message" required>%s</textarea>' ,
isset( $this->options['popup_message'] ) ? esc_attr( $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 included PDPA compiled.', 'pdpa-consent')
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')
);
}

function website_name_callback() {
printf(
'<input class="regular-text" type="text" name="_option_name[website_name]" id="website_name" value="%s" placeholder="%s" required>' ,
isset( $this->options['website_name'] ) ? esc_attr( $this->options['website_name']) : '',
isset( $this->options['website_name'] ) ? esc_html( $this->options['website_name']) : '',
__('Your website name or Company name', 'pdpa-consent')
);
}

function description_callback() {
printf(
'<input class="regular-text" type="text" name="_option_name[site_description]" id="site_description" value="%s">' ,
isset( $this->options['site_description'] ) ? esc_attr( $this->options['site_description']) : '',
isset( $this->options['site_description'] ) ? esc_html( $this->options['site_description']) : ''
);
}

function list_data_callback() {
printf(
'<textarea class="regular-text" rows=5 name="_option_name[list_data]" id="list_data" placeholder="%s" required>%s</textarea>' ,
__("Fullname\nBirthday\nEtc."),
isset( $this->options['list_data'] ) ? esc_attr( $this->options['list_data']) : ''
isset( $this->options['list_data'] ) ? esc_html( $this->options['list_data']) : ''
);
}

function address_callback() {
printf(
'<input class="regular-text" type="text" name="_option_name[site_address]" id="site_address" value="%s" required>' ,
isset( $this->options['site_address'] ) ? esc_attr( $this->options['site_address']) : '',
isset( $this->options['site_address'] ) ? esc_html( $this->options['site_address']) : ''
);
}

function contact_callback() {
printf(
'<input class="regular-text" type="text" name="_option_name[site_contact]" id="site_contact" value="%s" placeholder="%s">' ,
isset( $this->options['site_contact'] ) ? esc_attr( $this->options['site_contact']) : '',
isset( $this->options['site_contact'] ) ? esc_html( $this->options['site_contact']) : '',
__("Such as John Doe (081-111-1111)", 'pdpa-consent')
);
}

function email_callback() {
printf(
'<input class="regular-text" type="text" name="_option_name[site_email]" id="site_description" value="%s" required>' ,
isset( $this->options['site_email'] ) ? esc_attr( $this->options['site_email']) : '',
isset( $this->options['site_email'] ) ? esc_html( $this->options['site_email']) : ''
);
}

function custom_css_callback() {
printf(
'<textarea class="regular-text" rows=10 name="_option_name[custom_css]" id="custom_css" placeholder="%s">%s</textarea>',
".consent-wrap {}\n.place-top {}\n.place-center {}\n.place-bottom {}\n.pdpa-consent-not-allow-button {}\n.pdpa-consent-allow-button {}",
isset( $this->options['custom_css'] ) ? esc_attr( $this->options['custom_css']) : ''
);
?>
<style>
.pdpa-admin-table {
border: 1px solid #eee;
padding: 0px;
}
.pdpa-admin-table tr td:first-child {
color: #a23a08;
}
.pdpa-admin-table td {
padding: 8px 10px;
border-bottom: 1px solid #eee;
}
</style>
<table class='pdpa-admin-table'>
<tr>
<td>.pdpa-consent-wrap {}</td>
<td><?php _e('For wrapper div element', 'pdpa-consent');?></td>
</tr>
<tr>
<td>.pdpa-place-top {}</td>
<td><?php _e('Make the box place to top bar', 'pdpa-consent');?></td>
</tr>
<tr>
<td>.pdpa-place-center {}</td>
<td><?php _e('Make the box place center the screen', 'pdpa-consent');?></td>
</tr>
<tr>
<td>.pdpa-place-bottom {}</td>
<td><?php _e('Make the box place to bottom bar');?></td>
</tr>
<tr>
<td>.pdpa-consent-text {}</td>
<td><?php _e('Style for message in the box');?></td>
</tr>
<tr>
<td>.pdpa-consent-not-allow-button {}</td>
<td><?php _e('Style for not allow button', 'pdpa-consent');?></td>
</tr>
<tr>
<td>.pdpa-consent-allow-button {}</td>
<td><?php _e('Style for allow button', 'pdpa-consent');?></td>
</tr>
</table>
<?php
}
}
3 changes: 3 additions & 0 deletions assets/pdpa-admin-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jQuery(document).ready(() => {
jQuery('.pdpa-color-picker').wpColorPicker();
});
Loading

0 comments on commit f2da88c

Please sign in to comment.