PluginProbe
Cookie Bar / trunk
Cookie Bar vtrunk
trunk 1.8.9 2.0 2.1 2.2 2.3
cookie-bar / cookie-bar.php

cookie-bar.php in Cookie Bar trunk, at cookie-bar.php

461 lines 18.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Cookie Bar
4 Plugin URI: https://www.brontobytes.com/blog/cookie-bar-free-wordpress-plugin/
5 Description: Cookie Bar allows you to discreetly inform visitors that your website uses cookies.
6 Author: Brontobytes
7 Author URI: https://www.brontobytes.com/
8 Version: 2.3
9 License: GPLv2
10 */
11
12 if ( ! defined( 'ABSPATH' ) )
13 exit;
14
15 function cookie_bar_menu() {
16 add_options_page('Cookie Bar Settings', 'Cookie Bar', 'administrator', 'cookie-bar-settings', 'cookie_bar_settings_page');
17 }
18 add_action('admin_menu', 'cookie_bar_menu');
19
20
21 add_filter( 'plugin_action_links', 'cookie_bar_settings_plugin_link', 10, 2 );
22
23 function cookie_bar_settings_plugin_link( $links, $file )
24 {
25 if ( $file == plugin_basename(dirname(__FILE__) . '/cookie-bar.php') )
26 {
27 /*
28 * Insert the link at the beginning
29 */
30 // $in = '<a href="options-general.php?page=cookie-bar-settings">' . __('Settings','mtt') . '</a>';
31 // array_unshift($links, $in);
32
33 /*
34 * Insert at the end
35 */
36 $links[] = '<a href="options-general.php?page=cookie-bar-settings">'.__('Settings','mtt').'</a>';
37 }
38 return $links;
39 }
40
41 function cookie_bar_settings_page() {
42
43 $cookie_bar_show_for_logged_out_users_only_option = get_option('cookie_bar_show_for_logged_out_users_only');
44 $cookie_bar_show_on_top = get_option('cookie_bar_show_on_top');
45
46 ?>
47 <script>
48 jQuery(document).ready(function($){
49 $(".cookie_bar_btn_bg_colour").wpColorPicker();
50 $(".cookie_bar_btn_font_colour").wpColorPicker();
51 $(".cookie_bar_bar_bg_colour").wpColorPicker();
52 $(".cookie_bar_bar_font_colour").wpColorPicker();
53 });
54 </script>
55 <style type="text/css" >
56 .wrap.cookie_bar_settings {
57 max-width: 960px;
58 padding: 26px 30px 30px;
59 background: #fff;
60 border-radius: 12px;
61 box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
62 }
63
64 .wrap.cookie_bar_settings h1 {
65 margin-bottom: 10px;
66 }
67
68 .cookie_bar_settings__intro {
69 max-width: 760px;
70 margin: 0 0 18px;
71 color: #50575e;
72 font-size: 14px;
73 line-height: 1.6;
74 }
75
76 .cookie_bar_settings__panel {
77 margin-top: 20px;
78 }
79
80 .wrap.cookie_bar_settings .form-table {
81 margin-top: 0;
82 }
83
84 .wrap.cookie_bar_settings .form-table th {
85 width: 220px;
86 padding: 20px 20px 20px 0;
87 }
88
89 .wrap.cookie_bar_settings .form-table td {
90 padding: 15px 10px;
91 }
92
93 .wrap.cookie_bar_settings fieldset label {
94 display: block;
95 margin: 0 0 10px;
96 line-height: 1.4;
97 }
98
99 .wrap.cookie_bar_settings input[type="text"] {
100 width: 100%;
101 max-width: 520px;
102 }
103
104 .wrap.cookie_bar_settings input[size="4"] {
105 width: 70px;
106 }
107
108 .wrap.cookie_bar_settings .description {
109 max-width: 620px;
110 margin-top: 8px;
111 color: #646970;
112 }
113
114 .wrap.cookie_bar_settings code {
115 display: block;
116 max-width: 620px;
117 margin-top: 10px;
118 padding: 12px;
119 overflow-x: auto;
120 white-space: pre-wrap;
121 background: #f6f7f7;
122 border: 1px solid #dcdcde;
123 }
124
125 .wrap.cookie_bar_settings .cookie_bar_settings__divider th {
126 padding: 10px 0;
127 }
128
129 .wrap.cookie_bar_settings .cookie_bar_settings__divider hr {
130 max-width: none;
131 margin: 0;
132 border: 0;
133 border-top: 1px solid #dcdcde;
134 }
135
136 .cookie_bar_settings__footer {
137 margin-top: 20px;
138 color: #50575e;
139 }
140
141 .cookie_bar_settings__brand {
142 display: inline-block;
143 margin-top: 4px;
144 }
145
146 .cookie_bar_settings__brand img {
147 width: 100px;
148 height: auto;
149 vertical-align: middle;
150 }
151
152 @media screen and (max-width: 782px) {
153 .wrap.cookie_bar_settings {
154 padding: 18px;
155 border-radius: 10px;
156 }
157
158 .cookie_bar_settings__panel {
159 margin-top: 16px;
160 }
161
162 .wrap.cookie_bar_settings .form-table th,
163 .wrap.cookie_bar_settings .form-table td {
164 display: block;
165 width: auto;
166 padding: 12px 0;
167 }
168
169 .wrap.cookie_bar_settings .form-table th {
170 padding-bottom: 0;
171 }
172
173 .wrap.cookie_bar_settings input[type="text"] {
174 max-width: 100%;
175 }
176 }
177
178 </style>
179 <div class="wrap cookie_bar_settings">
180 <h1><?php _e('Cookie Bar Settings', 'cookie-bar'); ?></h1>
181 <div class="cookie_bar_settings__intro">
182 <p><?php _e('Cookie Bar allows you to discreetly inform visitors that your website uses cookies.
183
184 This is to notify your visitors that you are using cookies and does not control which or if cookies are set. Your cookies are set in any case.', 'cookie-bar'); ?></p>
185 </div>
186 <div class="cookie_bar_settings__panel">
187 <form method="post" action="options.php">
188 <?php settings_fields( 'cookie-bar-settings' ); ?>
189 <?php do_settings_sections( 'cookie-bar-settings' ); ?>
190 <table class="form-table">
191 <tr valign="top">
192 <th scope="row"><?php _e('Expiration', 'cookie-bar'); ?></th>
193 <td>
194 <?php $expiration_type = "custom";
195 $option_type = get_option('cookie_bar_expiration_type');
196 if (isset($option_type) && $option_type === "never") {
197 $expiration_type = "never";
198 }
199
200 $expiration_custom_date = "30";
201 $option_custom_date = get_option('cookie_bar_days_to_expire');
202 $option_custom_date = preg_replace('/\D/', '', isset($option_custom_date) ? $option_custom_date : '');
203
204 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
205 $expiration_custom_date = $option_custom_date;
206 }
207 ?>
208 <fieldset>
209 <label><input type="radio" onclick="handleClick_type(this);" name="cookie_bar_expiration_type" <?php if ($expiration_type=="never") echo "checked";?> value="never"> <?php _e('Never expire (until cookies are cleared)', 'cookie-bar'); ?></label>
210 <label><input type="radio" onclick="handleClick_type(this);" name="cookie_bar_expiration_type" <?php if ($expiration_type=="custom") echo "checked";?> value="custom"> <?php _e('Custom expiration', 'cookie-bar'); ?></label>
211 <div class="cookie_bar_days_to_expire">
212 <input type="text" size="4" name="cookie_bar_days_to_expire" value="<?php echo esc_html( $expiration_custom_date ); ?>" /> <?php _e('days', 'cookie-bar'); ?>
213 </div>
214 </fieldset>
215
216
217 </td>
218
219 </tr>
220 <tr class="cookie_bar_settings__divider">
221 <th colspan="2" >
222 <hr />
223 </th>
224 </tr>
225 <tr valign="top">
226 <th scope="row"><?php _e('Cookie Bar message', 'cookie-bar'); ?></th>
227 <td><input type="text" size="100" name="cookie_bar_message" value="<?php echo esc_html( get_option('cookie_bar_message') ); ?>" /> <div class="description"><?php _e('HTML allowed. Example:', 'cookie-bar'); ?><code><?php echo esc_html('By continuing to browse this site, you agree to our <a href="https://aboutcookies.com/" target="_blank" rel="nofollow">use of cookies</a>.'); ?></code></div></td>
228 </tr>
229 <tr valign="top">
230 <th scope="row"><?php _e('Button text', 'cookie-bar'); ?></th>
231 <td><input type="text" size="20" name="cookie_bar_button" value="<?php echo esc_attr( get_option('cookie_bar_button') ); ?>" /> <p class="description"><?php _e('E.g.: I understand', 'cookie-bar'); ?></p></td>
232 </tr>
233 <tr class="cookie_bar_settings__divider">
234 <th colspan="2" >
235 <hr />
236 </th>
237 </tr>
238 <tr valign="top">
239 <th scope="row"><?php _e('Button background colour', 'cookie-bar'); ?></th>
240 <td><input type="text" name="cookie_bar_btn_bg_colour" value="<?php echo esc_attr( get_option('cookie_bar_btn_bg_colour') ); ?>" class="cookie_bar_btn_bg_colour" data-default-color="#45AE52" /></td>
241 </tr>
242 <tr valign="top">
243 <th scope="row"><?php _e('Button font colour', 'cookie-bar'); ?></th>
244 <td><input type="text" name="cookie_bar_btn_font_colour" value="<?php echo esc_attr( get_option('cookie_bar_btn_font_colour') ); ?>" class="cookie_bar_btn_font_colour" data-default-color="#ffffff" /></td>
245 </tr>
246 <tr valign="top">
247 <th scope="row"><?php _e('Bar background colour', 'cookie-bar'); ?></th>
248 <td><input type="text" name="cookie_bar_bar_bg_colour" value="<?php echo esc_attr( get_option('cookie_bar_bar_bg_colour') ); ?>" class="cookie_bar_bar_bg_colour" data-default-color="#2e363f" /></td>
249 </tr>
250 <tr valign="top">
251 <th scope="row"><?php _e('Bar font colour', 'cookie-bar'); ?></th>
252 <td><input type="text" name="cookie_bar_bar_font_colour" value="<?php echo esc_attr( get_option('cookie_bar_bar_font_colour') ); ?>" class="cookie_bar_bar_font_colour" data-default-color="#ffffff" /></td>
253 </tr>
254 <tr class="cookie_bar_settings__divider">
255 <th colspan="2" >
256 <hr />
257 </th>
258 </tr>
259 <tr valign="top">
260 <th scope="row"><?php _e('Show for logged out users only', 'cookie-bar'); ?></th>
261 <td><input type="checkbox" name="cookie_bar_show_for_logged_out_users_only" <?php if ($cookie_bar_show_for_logged_out_users_only_option == "1") echo "checked";?> value="1" ></td>
262 </tr>
263
264 <tr valign="top">
265 <th scope="row"><?php _e('Display at the top', 'cookie-bar'); ?></th>
266 <td><input type="checkbox" name="cookie_bar_show_on_top" <?php if ($cookie_bar_show_on_top == "1") echo "checked";?> value="1" ></td>
267 </tr>
268
269 </table>
270 <script type="text/javascript" >
271
272 function handleClick_type(type_) {
273
274 if( type_.value == "custom")
275 {
276
277 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
278
279 for (var i = 0; i < tracking_code_gtag.length; i ++) {
280 tracking_code_gtag[i].style.display = 'block';
281 }
282
283 }
284 else if( type_.value == "never")
285 {
286 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
287
288 for (var i = 0; i < tracking_code_gtag.length; i ++) {
289 tracking_code_gtag[i].style.display = 'none';
290 }
291 }
292 }
293
294 <?php if ($expiration_type == "never") { ?>
295 handleClick_type({ value: "never" });
296 <?php } else { ?>
297 handleClick_type({ value: "custom" });
298 <?php } ?>
299
300 </script>
301
302 <?php submit_button(); ?>
303 </form>
304 </div>
305 <div class="cookie_bar_settings__footer">
306 <p><?php _e('We are very happy to be able to provide this and other', 'cookie-bar'); ?> <a target="_blank" href="https://www.brontobytes.com/blog/c/wordpress-plugins/"><?php _e('free WordPress plugins', 'cookie-bar'); ?></a>.</p>
307 <p><?php _e('Plugin developed by', 'cookie-bar'); ?> <a href="https://www.brontobytes.com/" target="_blank" >Brontobytes</a></p>
308 <a class="cookie_bar_settings__brand" href="https://www.brontobytes.com/" target="_blank"><img src="<?php echo plugins_url( 'images/brontobytes.svg', __FILE__ ) ?>" alt="Web hosting provider"></a>
309 </div>
310 </div>
311 <?php }
312
313 function cookie_bar_settings() {
314 register_setting( 'cookie-bar-settings', 'cookie_bar_message' );
315 register_setting( 'cookie-bar-settings', 'cookie_bar_button' );
316 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_bg_colour' );
317 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_font_colour' );
318 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_bg_colour' );
319 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_font_colour' );
320 register_setting( 'cookie-bar-settings', 'cookie_bar_days_to_expire' );
321 register_setting( 'cookie-bar-settings', 'cookie_bar_expiration_type' );
322 register_setting( 'cookie-bar-settings', 'cookie_bar_show_for_logged_out_users_only' );
323 register_setting( 'cookie-bar-settings', 'cookie_bar_show_on_top' );
324
325 }
326 add_action( 'admin_init', 'cookie_bar_settings' );
327
328 function cookie_bar_deactivation() {
329 delete_option( 'cookie_bar_message' );
330 delete_option( 'cookie_bar_button' );
331 delete_option( 'cookie_bar_btn_bg_colour' );
332 delete_option( 'cookie_bar_btn_font_colour' );
333 delete_option( 'cookie_bar_bar_bg_colour' );
334 delete_option( 'cookie_bar_bar_font_colour' );
335 delete_option( 'cookie_bar_days_to_expire' );
336 delete_option( 'cookie_bar_expiration_type' );
337 delete_option( 'cookie_bar_show_for_logged_out_users_only' );
338 delete_option( 'cookie_bar_show_on_top' );
339
340 }
341 register_deactivation_hook( __FILE__, 'cookie_bar_deactivation' );
342
343 function cookie_bar_dependencies() {
344 wp_register_script( 'cookie-bar-js', plugins_url('js/cookie-bar.js', __FILE__), array('jquery'), time(), false );
345 wp_enqueue_script( 'cookie-bar-js' );
346 wp_register_style( 'cookie-bar-css', plugins_url('css/cookie-bar.css', __FILE__) );
347 wp_enqueue_style( 'cookie-bar-css' );
348 }
349 add_action( 'wp_enqueue_scripts', 'cookie_bar_dependencies' );
350
351 class cookie_bar_languages {
352 public static function loadTextDomain() {
353 load_plugin_textdomain('cookie-bar', false, dirname(plugin_basename(__FILE__ )) . '/languages/');
354 }
355 }
356
357
358 $allowed_html = array(
359 'a' => array(
360 'href' => array(),
361 'title' => array(),
362 'target' => array(),
363 'class' => array(),
364 'id' => array(),
365 'rel' => array(),
366 ),
367 'br' => array(),
368 'em' => array(),
369 'strong' => array(),
370 );
371
372
373 add_action('plugins_loaded', array('cookie_bar_languages', 'loadTextDomain'));
374
375 function cookie_bar_color_picker( $hook_suffix ) {
376 // first check that $hook_suffix is appropriate for your admin page
377 wp_enqueue_style( 'wp-color-picker' );
378 wp_enqueue_script( 'cookie-bar-color-picker', plugins_url('js/cookie-bar.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
379 }
380 add_action( 'admin_enqueue_scripts', 'cookie_bar_color_picker' );
381
382 function cookie_bar() {
383 global $allowed_html;
384
385 $cookie_bar_message_output = get_option( 'cookie_bar_message' );
386 $cookie_bar_button_output = esc_attr( get_option('cookie_bar_button') );
387 $cookie_bar_btn_font_colour = esc_attr( get_option('cookie_bar_btn_font_colour') );
388 $cookie_bar_bar_bg_colour = esc_attr( get_option('cookie_bar_bar_bg_colour') );
389 $cookie_bar_bar_font_colour = esc_attr( get_option('cookie_bar_bar_font_colour') );
390 $cookie_bar_show_for_logged_out_users_only = esc_attr( get_option('cookie_bar_show_for_logged_out_users_only') );
391 $cookie_bar_show_on_top = esc_attr( get_option('cookie_bar_show_on_top') );
392
393 $expiration_type = "custom";
394 $option_type = get_option('cookie_bar_expiration_type');
395 if (isset($option_type) && $option_type === "never") {
396 $expiration_type = "never";
397 }
398
399 $expiration_custom_date = "30";
400 $option_custom_date = get_option('cookie_bar_days_to_expire');
401 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
402 $expiration_custom_date = $option_custom_date;
403 }
404
405 if ( empty( $cookie_bar_message_output ) ) $cookie_bar_message_output = 'By continuing to browse this site, you agree to our <a href="https://aboutcookies.com/" target="_blank" rel="nofollow">use of cookies</a>.';
406 if ( empty( $cookie_bar_button_output ) ) $cookie_bar_button_output = "I Understand";
407 ?>
408 <style type="text/css" >
409 <?php
410 if (isset($cookie_bar_btn_font_colour) && (!empty($cookie_bar_btn_font_colour))) {
411 ?>
412 button#euCookieAcceptWP { color : <?php echo $cookie_bar_btn_font_colour ?>; }
413 <?php
414 }
415
416 if (isset($cookie_bar_bar_bg_colour) && (!empty($cookie_bar_bar_bg_colour))) {
417 ?>
418 #eu-cookie-bar { background-color : <?php echo $cookie_bar_bar_bg_colour ?>; }
419 <?php
420 }
421
422
423 if (isset($cookie_bar_bar_font_colour) && (!empty($cookie_bar_bar_font_colour))) {
424 ?>
425 #eu-cookie-bar , #eu-cookie-bar a { color : <?php echo $cookie_bar_bar_font_colour ?>; }
426 <?php
427 }
428
429
430 if (isset($cookie_bar_show_on_top) && (!empty($cookie_bar_show_on_top))) {
431 ?>
432 #eu-cookie-bar
433 {
434 position: fixed;
435 top: 0;
436 height: 30px;
437 z-index: 999999999999999;
438 }
439 <?php
440 }
441
442
443
444 ?>
445
446
447
448
449 </style>
450 <?php if($cookie_bar_show_for_logged_out_users_only) {
451 if(is_user_logged_in()) {
452 return;
453 }
454 } ?>
455 <!-- Cookie Bar -->
456 <div id="eu-cookie-bar"><?php echo wp_kses( $cookie_bar_message_output, $allowed_html ); ?> <button id="euCookieAcceptWP" <?php if (get_option('cookie_bar_btn_bg_colour') == true) { ?> style="background:<?php echo esc_html( get_option('cookie_bar_btn_bg_colour') ); ?>;" <?php } ?> onclick="euSetCookie('euCookiesAcc', true, <?php if($expiration_type === 'never' ) {echo '4000';} if($expiration_type === "custom" ) {echo $expiration_custom_date;} ?>); euAcceptCookiesWP();"><?php echo wp_kses($cookie_bar_button_output, $allowed_html); ?></button></div>
457 <!-- End Cookie Bar -->
458 <?php
459 }
460 add_action( 'wp_footer', 'cookie_bar', 10 );
461