| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Admin; |
| 4 |
|
| 5 |
/** |
| 6 |
* Base class for admin tabs. Extend this. |
| 7 |
* |
| 8 |
* Class AdminTab |
| 9 |
* |
| 10 |
* @package Codelight\GDPR\Admin |
| 11 |
*/ |
| 12 |
abstract class AdminTab implements AdminTabInterface |
| 13 |
{ |
| 14 |
/* @var string */ |
| 15 |
protected $slug; |
| 16 |
|
| 17 |
/* @var string */ |
| 18 |
protected $title; |
| 19 |
|
| 20 |
/** |
| 21 |
* @return string |
| 22 |
*/ |
| 23 |
public function getSlug() |
| 24 |
{ |
| 25 |
return $this->slug; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @return string |
| 30 |
*/ |
| 31 |
public function getTitle() |
| 32 |
{ |
| 33 |
return $this->title; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
public function getOptionsGroupName() |
| 40 |
{ |
| 41 |
return 'gdpr_' . $this->getSlug(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Register a setting on the admin page |
| 46 |
* |
| 47 |
* @param $optionName |
| 48 |
* @param string $args |
| 49 |
*/ |
| 50 |
public function registerSetting($optionName, $args = []) |
| 51 |
{ |
| 52 |
register_setting($this->getOptionsGroupName(), $optionName, $args); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Register a section on the admin page |
| 57 |
* |
| 58 |
* @param $name |
| 59 |
* @param $callback |
| 60 |
*/ |
| 61 |
public function registerSettingSection($id, $title, $callback = null) |
| 62 |
{ |
| 63 |
add_settings_section( |
| 64 |
$id, |
| 65 |
$title, |
| 66 |
$callback, |
| 67 |
$this->getOptionsGroupName() |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Register a setting field on the admin page |
| 73 |
* |
| 74 |
* @param $id |
| 75 |
* @param $title |
| 76 |
* @param $callback |
| 77 |
*/ |
| 78 |
public function registerSettingField($id, $title, $callback = null, $section = '', $args = []) |
| 79 |
{ |
| 80 |
add_settings_field( |
| 81 |
$id, |
| 82 |
$title, |
| 83 |
$callback, |
| 84 |
$this->getOptionsGroupName(), |
| 85 |
$section, |
| 86 |
$args |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Render the contents including settings fields, sections and submit button. |
| 92 |
* Trigger hooks for rendering content before and after the settings fields. |
| 93 |
* |
| 94 |
* @return string |
| 95 |
*/ |
| 96 |
public function renderContents() |
| 97 |
{ |
| 98 |
global $gdpr; |
| 99 |
$tabs = array("general", "cookie-popup", "consent", "privacy-policy", "do-not-sell", "support"); |
| 100 |
ob_start(); |
| 101 |
|
| 102 |
if (in_array($this->slug, $tabs)) { |
| 103 |
?> |
| 104 |
<style> |
| 105 |
.column { |
| 106 |
float: left; |
| 107 |
} |
| 108 |
.left { |
| 109 |
width: 75%; |
| 110 |
} |
| 111 |
|
| 112 |
.right { |
| 113 |
width: 25%; |
| 114 |
} |
| 115 |
|
| 116 |
/* Clear floats after the columns */ |
| 117 |
.row:after { |
| 118 |
content: ""; |
| 119 |
display: table; |
| 120 |
clear: both; |
| 121 |
} |
| 122 |
@media screen and (max-width: 600px) { |
| 123 |
.column { |
| 124 |
width: 100%; |
| 125 |
} |
| 126 |
} |
| 127 |
</style> |
| 128 |
<div class="row"> |
| 129 |
<div class="column left"> |
| 130 |
<?php |
| 131 |
} |
| 132 |
|
| 133 |
do_action("gdpr/tabs/{$this->getSlug()}/before", $this); |
| 134 |
settings_fields($this->getOptionsGroupName()); |
| 135 |
do_settings_sections($this->getOptionsGroupName()); |
| 136 |
do_action("gdpr/tabs/{$this->getSlug()}/after", $this); |
| 137 |
|
| 138 |
$this->renderSubmitButton(); |
| 139 |
|
| 140 |
if (in_array($this->slug, $tabs)) { |
| 141 |
?> |
| 142 |
</div> |
| 143 |
<div class="column right"> |
| 144 |
<div style="float:left;max-width:250px;margin:9px;margin-left:20px;margin-top:50px;"> |
| 145 |
<b>How to contact us?</b> |
| 146 |
<ul style="list-style:circle;margin-left:20px;"> |
| 147 |
<li> |
| 148 |
<a href="<?=gdpr('helpers')->data443()?>" target="_blank">Data443 (homepage)</a> |
| 149 |
</li> |
| 150 |
<li> |
| 151 |
<a href="<?=gdpr('helpers')->supportRequest()?>" target="_blank">Contact Support</a> |
| 152 |
</li> |
| 153 |
<li> |
| 154 |
<a href="https://www.facebook.com/data443/" target="_blank">Like us on Facebook</a> |
| 155 |
</li> |
| 156 |
<li> |
| 157 |
<a href="https://twitter.com/data443risk" target="_blank">Follow us on Twitter</a> |
| 158 |
</li> |
| 159 |
<li> |
| 160 |
<a href="<?=gdpr('helpers')->wordpressReview()?>" target="_blank">Rate us on WordPress</a> |
| 161 |
</li> |
| 162 |
</ul> |
| 163 |
<div style="border: solid 1px black;border-radius: 5px;background: #f2efe6;padding:10px;padding-bottom:30px;"> |
| 164 |
<p style="margin-top:0px;">Do you like this plugin?</p> |
| 165 |
<p>With the <b>PREMIUM</b> version you can have other awesome features:</p> |
| 166 |
|
| 167 |
<div style="clear:both; margin-top: 2px;"></div> |
| 168 |
<div> |
| 169 |
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px; margin-top:-3px;"> |
| 170 |
<img src="<?=$gdpr->PluginUrl?>/assets/images/tick.png" /> |
| 171 |
</div> |
| 172 |
<p style="margin-top:0px;">Custom Consent Text</p> |
| 173 |
</div> |
| 174 |
|
| 175 |
<div style="clear:both; margin-top: 2px;"></div> |
| 176 |
<div> |
| 177 |
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px; margin-top:-3px;"> |
| 178 |
<img src="<?=$gdpr->PluginUrl?>/assets/images/tick.png" /> |
| 179 |
</div> |
| 180 |
<p style="margin-top:0px;">Data Rectification</p> |
| 181 |
</div> |
| 182 |
|
| 183 |
<div style="clear:both; margin-top: 2px;"></div> |
| 184 |
<div> |
| 185 |
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px; margin-top:-3px;"> |
| 186 |
<img src="<?=$gdpr->PluginUrl?>/assets/images/tick.png" /> |
| 187 |
</div> |
| 188 |
<p style="margin-top:0px;">Custom relative URLs for the Privacy Policy and other files</p> |
| 189 |
</div> |
| 190 |
|
| 191 |
<div style="clear:both;"></div> |
| 192 |
<div style="height:10px;"></div> |
| 193 |
<div style="float:right;"><a href="<?=gdpr('helpers')->premiumStore()?>" target="_blank">Get PREMIUM now >></a></div> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
</div> |
| 197 |
</div> |
| 198 |
<?php |
| 199 |
} |
| 200 |
return ob_get_clean(); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Render WP's default submit button |
| 205 |
*/ |
| 206 |
public function renderSubmitButton() |
| 207 |
{ |
| 208 |
submit_button(_x('Save', '(Admin)', 'gdpr-framework')); |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Enqueue scripts, run the child class init function, trigger action for adding custom stuff |
| 213 |
*/ |
| 214 |
public function setup() |
| 215 |
{ |
| 216 |
// Automatically run the 'enqueue' method if it exists |
| 217 |
if (method_exists($this, 'enqueue')) { |
| 218 |
add_action('admin_enqueue_scripts', [$this, 'enqueue']); |
| 219 |
} |
| 220 |
|
| 221 |
$this->init(); |
| 222 |
|
| 223 |
// This hook can be used for registering custom settings |
| 224 |
do_action("gdpr/tabs/{$this->getSlug()}/init", $this); |
| 225 |
|
| 226 |
// Render the admin notices |
| 227 |
add_action('admin_notices', [$this, 'renderAdminNotices']); |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Render success notices via admin_notice action |
| 232 |
*/ |
| 233 |
public function renderAdminNotices() |
| 234 |
{ |
| 235 |
if ('tools_page_privacy' !== get_current_screen()->base) { |
| 236 |
return; |
| 237 |
} |
| 238 |
|
| 239 |
if (!isset($_REQUEST['gdpr_notice'])) { |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
if ('policy_generated' === $_REQUEST['gdpr_notice']) { |
| 244 |
$message = _x('Policy generated!', '(Admin)', 'gdpr-framework'); |
| 245 |
$class = 'notice notice-success'; |
| 246 |
} |
| 247 |
|
| 248 |
echo gdpr('view')->render('admin/notice', compact('message', 'class')); |
| 249 |
} |
| 250 |
} |
| 251 |
|