Skip to content

Commit f2da88c

Browse files
authored
Merge pull request #9 from iamapinan/dev
update feature and fix security issue
2 parents 3e7fd88 + bf51b56 commit f2da88c

17 files changed

+704
-343
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ You can edit the term page and publish on your website with elegant and powerful
2323
* Display user PDPA Status on user list
2424
* Multi language support (Thai, English) more translate is accept
2525

26+
### Roadmap
27+
28+
* Allow user to request profile data.
29+
* Allow user to request to delete account.
30+
* Allow user to allow consent again.
31+
* User page.
32+
2633
### Contributors.
2734
- **Apinan Woratrakun** *as developer* <iamapinan@gmail.com>, <https://facebook.com/9apinan>, <https://ioblog.me>
2835
- **Aeknarin Sirisub** *as technical privacy system desgin* <https://www.facebook.com/swodsman>
2936

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

3239
### Special Thank
33-
* Thai Programmer Association
34-
35-
![assets/pdpa-consent-logo.jpg](assets/pdpa-consent-sm.jpg)
40+
* Thai Programmer Association

admin.php

Lines changed: 162 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

11-
Class AdminOption {
11+
Class pdpa_consent_admin_option {
1212
private $plugin_info = array();
1313
private $capability = 'manage_options';
1414
private $options;
@@ -19,20 +19,21 @@
1919
public function __construct() {
2020
$this->plugin_info = get_plugin_data( PDPA_PATH . 'pdpa-consent.php' );
2121
$this->locale = get_locale();
22-
$this->page_id = get_option('pdpa-page-id') ? get_option('pdpa-page-id') : 0;
22+
$this->page_id = get_option('pdpa-consent-page-id') ? get_option('pdpa-consent-page-id') : 0;
2323
$this->page_name = __('pdpa-term', 'pdpa-consent');
2424
add_action( 'admin_menu', array($this, 'pdpa_admin_menu') );
2525
add_action( 'admin_init', array($this, 'admin_option_setup') );
26+
add_action( 'admin_enqueue_scripts', array( $this, 'pdpa_enqueue_color_picker' ) );
2627
}
2728

2829
private function serialize_html($html, $settings = [ 'website_name' => '', 'site_description' => '', 'list_data' => '', 'site_address' => '', 'site_contact' => '', 'site_email' => '' ]) {
29-
$settings['list_data'] = str_replace("\n", "</li><li>", esc_attr($settings['list_data']) );
30-
$html = str_replace('[service]', esc_attr($settings['website_name']), $html);
30+
$settings['list_data'] = str_replace("\n", "</li><li>", esc_html($settings['list_data']) );
31+
$html = str_replace('[service]', esc_html($settings['website_name']), $html);
3132
$html = str_replace('[description]', esc_attr($settings['site_description']), $html);
3233
$html = str_replace('[list_data]', $settings['list_data'], $html);
33-
$html = str_replace('[address]', esc_attr($settings['site_address']), $html);
34-
$html = str_replace('[contact]', esc_attr($settings['site_contact']), $html);
35-
$html = str_replace('[email]', esc_attr($settings['site_email']), $html);
34+
$html = str_replace('[address]', esc_html($settings['site_address']), $html);
35+
$html = str_replace('[contact]', esc_html($settings['site_contact']), $html);
36+
$html = str_replace('[email]', esc_html($settings['site_email']), $html);
3637
return $html;
3738
}
3839

@@ -53,15 +54,22 @@ public function generate_post_from_template() {
5354
'post_author' => 1,
5455
'post_type' => 'page'
5556
);
57+
5658
$page_id = wp_insert_post( $page_details );
57-
add_option( 'pdpa-page-id', $page_id );
59+
add_option( 'pdpa-consent-page-id', $page_id );
5860
}
5961

6062
function pdpa_admin_menu() {
6163
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 );
6264
}
6365

66+
function pdpa_enqueue_color_picker( $hook_suffix ) {
67+
wp_enqueue_style( 'wp-color-picker' );
68+
wp_enqueue_script( 'pdpa-script', plugins_url('assets/pdpa-admin-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
69+
}
70+
6471
function pdpa_admin_option() {
72+
6573
if(isset($_POST)) {
6674
$this->generate_post_from_template();
6775
}
@@ -86,17 +94,20 @@ function pdpa_admin_option() {
8694
<?php
8795
}
8896

89-
function admin_option_setup() {
97+
function admin_option_setup () {
98+
9099
register_setting(
91100
'_pdpa_setting_group', // option_group
92-
'_option_name', // option_name
101+
'_option_name' // option_name
93102
);
103+
94104
add_settings_section(
95105
'_pdpa_setting_section', // id
96106
__( 'PDPA Consent setup','pdpa-consent' ), // title
97107
array( $this, '_section_fields' ), // callback
98108
'settings' // page
99109
);
110+
100111
}
101112

102113
public function _section_fields() {
@@ -119,6 +130,54 @@ public function _section_fields() {
119130
'settings', // page
120131
'_pdpa_setting_section' // section
121132
);
133+
/***
134+
* Future functions
135+
*
136+
137+
add_settings_field(
138+
'allow_user_reset', // id
139+
__( 'Allow user to reset consent','pdpa-consent' ), // title
140+
array( $this, 'allow_user_reset_callback' ), // callback
141+
'settings', // page
142+
'_pdpa_setting_section' // section
143+
);
144+
add_settings_field(
145+
'allow_user_delete', // id
146+
__( 'Allow user to delete account','pdpa-consent' ), // title
147+
array( $this, 'allow_user_delete_callback' ), // callback
148+
'settings', // page
149+
'_pdpa_setting_section' // section
150+
);
151+
add_settings_field(
152+
'allow_user_download', // id
153+
__( 'Allow user to download profile','pdpa-consent' ), // title
154+
array( $this, 'allow_user_download_callback' ), // callback
155+
'settings', // page
156+
'_pdpa_setting_section' // section
157+
);
158+
*/
159+
160+
add_settings_field(
161+
'is_darkmode', // id
162+
__( 'Use dark theme','pdpa-consent' ), // title
163+
array( $this, 'is_darkmode_callback' ), // callback
164+
'settings', // page
165+
'_pdpa_setting_section' // section
166+
);
167+
add_settings_field(
168+
'allow_button_color', // id
169+
__( 'Allow button color','pdpa-consent' ), // title
170+
array( $this, 'allow_button_color_callback' ), // callback
171+
'settings', // page
172+
'_pdpa_setting_section' // section
173+
);
174+
add_settings_field(
175+
'not_allow_button_color', // id
176+
__( 'Not allow button color','pdpa-consent' ), // title
177+
array( $this, 'not_allow_button_color_callback' ), // callback
178+
'settings', // page
179+
'_pdpa_setting_section' // section
180+
);
122181
add_settings_field(
123182
'popup_type', // id
124183
__( 'Notification popup type','pdpa-consent' ), // title
@@ -177,7 +236,7 @@ public function _section_fields() {
177236
);
178237
add_settings_field(
179238
'custom_css', // id
180-
__( 'Custom CSS','pdpa-consent' ), // title
239+
__( 'CSS Class','pdpa-consent' ), // title
181240
array( $this, 'custom_css_callback' ), // callback
182241
'settings', // page
183242
'_pdpa_setting_section' // section
@@ -186,9 +245,10 @@ public function _section_fields() {
186245

187246
function url_callback() {
188247
printf(
189-
'<a href="/?p=%s">%s</a>' ,
248+
'<a href="/?p=%s">%s</a>&nbsp;<a href="%s"><span class="dashicons dashicons-edit"></span></a>' ,
190249
$this->page_id,
191-
get_site_url().'/'.$this->page_name
250+
esc_url(get_site_url().'/?p='.$this->page_id),
251+
esc_url(get_admin_url().'post.php?post='.get_option('pdpa-consent-page-id').'&action=edit')
192252
);
193253
}
194254
function is_enable_callback() {
@@ -197,73 +257,149 @@ function is_enable_callback() {
197257
$this->options['is_enable'] == true ? 'checked' : ''
198258
);
199259
}
260+
function allow_user_reset_callback() {
261+
printf(
262+
'<input type="checkbox" name="_option_name[allow_user_reset]" id="allow_user_reset" value="1" %s>' ,
263+
$this->options['allow_user_reset'] == true ? 'checked' : ''
264+
);
265+
}
266+
function allow_user_delete_callback() {
267+
printf(
268+
'<input type="checkbox" name="_option_name[allow_user_delete]" id="allow_user_delete" value="1" %s>' ,
269+
$this->options['allow_user_delete'] == true ? 'checked' : ''
270+
);
271+
}
272+
function allow_user_download_callback() {
273+
printf(
274+
'<input type="checkbox" name="_option_name[allow_user_download]" id="allow_user_download" value="1" %s>' ,
275+
$this->options['allow_user_download'] == true ? 'checked' : ''
276+
);
277+
}
278+
function is_darkmode_callback() {
279+
printf(
280+
'<input type="checkbox" name="_option_name[is_darkmode]" id="is_enable" value="1" %s>' ,
281+
$this->options['is_darkmode'] == true ? 'checked' : ''
282+
);
283+
}
284+
function allow_button_color_callback() {
285+
printf(
286+
'<input type="text" name="_option_name[allow_button_color]" id="allow_button_color" value="%s" class="pdpa-color-picker">' ,
287+
$this->options['allow_button_color']
288+
);
289+
}
290+
function not_allow_button_color_callback() {
291+
printf(
292+
'<input type="text" name="_option_name[not_allow_button_color]" id="not_allow_button_color" value="%s" class="pdpa-color-picker">' ,
293+
$this->options['not_allow_button_color']
294+
);
295+
}
200296
function popup_type_callback() {
201297
?>
202298
<select name="_option_name[popup_type]">
299+
<option value="top" <?php echo $this->options['popup_type'] == 'top' ? 'selected' : '';?>><?php _e('Top bar', 'pdpa-consent');?></option>
203300
<option value="center" <?php echo $this->options['popup_type'] == 'center' ? 'selected' : '';?>><?php _e('Center popup', 'pdpa-consent');?></option>
204301
<option value="bottom" <?php echo $this->options['popup_type'] == 'bottom' ? 'selected' : '';?>><?php _e('Bottom bar', 'pdpa-consent');?></option>
205-
<option value="top" <?php echo $this->options['popup_type'] == 'top' ? 'selected' : '';?>><?php _e('Top bar', 'pdpa-consent');?></option>
206302
</select>
207303
<?php
208304
}
209305

210306
function popup_message_callback() {
211307
printf(
212308
'<textarea class="regular-text" rows=4 name="_option_name[popup_message]" id="popup_message" required>%s</textarea>' ,
213-
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')
309+
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')
214310
);
215311
}
216312

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

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

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

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

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

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

262358
function custom_css_callback() {
263-
printf(
264-
'<textarea class="regular-text" rows=10 name="_option_name[custom_css]" id="custom_css" placeholder="%s">%s</textarea>',
265-
".consent-wrap {}\n.place-top {}\n.place-center {}\n.place-bottom {}\n.pdpa-consent-not-allow-button {}\n.pdpa-consent-allow-button {}",
266-
isset( $this->options['custom_css'] ) ? esc_attr( $this->options['custom_css']) : ''
267-
);
359+
?>
360+
<style>
361+
.pdpa-admin-table {
362+
border: 1px solid #eee;
363+
padding: 0px;
364+
}
365+
.pdpa-admin-table tr td:first-child {
366+
color: #a23a08;
367+
}
368+
.pdpa-admin-table td {
369+
padding: 8px 10px;
370+
border-bottom: 1px solid #eee;
371+
}
372+
</style>
373+
<table class='pdpa-admin-table'>
374+
<tr>
375+
<td>.pdpa-consent-wrap {}</td>
376+
<td><?php _e('For wrapper div element', 'pdpa-consent');?></td>
377+
</tr>
378+
<tr>
379+
<td>.pdpa-place-top {}</td>
380+
<td><?php _e('Make the box place to top bar', 'pdpa-consent');?></td>
381+
</tr>
382+
<tr>
383+
<td>.pdpa-place-center {}</td>
384+
<td><?php _e('Make the box place center the screen', 'pdpa-consent');?></td>
385+
</tr>
386+
<tr>
387+
<td>.pdpa-place-bottom {}</td>
388+
<td><?php _e('Make the box place to bottom bar');?></td>
389+
</tr>
390+
<tr>
391+
<td>.pdpa-consent-text {}</td>
392+
<td><?php _e('Style for message in the box');?></td>
393+
</tr>
394+
<tr>
395+
<td>.pdpa-consent-not-allow-button {}</td>
396+
<td><?php _e('Style for not allow button', 'pdpa-consent');?></td>
397+
</tr>
398+
<tr>
399+
<td>.pdpa-consent-allow-button {}</td>
400+
<td><?php _e('Style for allow button', 'pdpa-consent');?></td>
401+
</tr>
402+
</table>
403+
<?php
268404
}
269405
}

assets/pdpa-admin-script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jQuery(document).ready(() => {
2+
jQuery('.pdpa-color-picker').wpColorPicker();
3+
});

0 commit comments

Comments
 (0)