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

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

344 lines 14.7 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.0
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 {
57 background-color: #ffffff;
58 padding: 30px;
59 border-radius: 20px;
60 }
61
62 .postbox .inside h2, .wrap [class$="icon32"] + h2, .wrap h1, .wrap > h2:first-child {
63 padding: 0px;
64 }
65
66 @media screen and (max-width: 768px) {
67 input[type="text"] {
68 max-width: 200px !important;
69 ; }
70
71 xmp {
72 display: block;
73 white-space: pre-wrap;
74 }
75 }
76
77 </style>
78 <div class="wrap">
79 <h2><?php _e('Cookie Bar Settings', 'cookie-bar'); ?></h2>
80 <p><?php _e('Cookie Bar allows you to discreetly inform visitors that your website uses cookies.
81
82 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>
83 <form method="post" action="options.php">
84 <?php settings_fields( 'cookie-bar-settings' ); ?>
85 <?php do_settings_sections( 'cookie-bar-settings' ); ?>
86 <table class="form-table">
87 <tr valign="top">
88 <th scope="row"><?php _e('Expiration', 'cookie-bar'); ?></th>
89 <td>
90 <?php $expiration_type = "custom";
91 $option_type = get_option('cookie_bar_expiration_type');
92 if (isset($option_type) && $option_type === "never") {
93 $expiration_type = "never";
94 }
95
96 $expiration_custom_date = "30";
97 $option_custom_date = get_option('cookie_bar_days_to_expire');
98 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
99 $expiration_custom_date = $option_custom_date;
100 }
101 ?>
102 <input type="radio" name="cookie_bar_expiration_type" <?php if ($expiration_type=="never") echo "checked";?> value="never">Never expire (until cookies are cleared)
103 <br/>
104 <input type="radio" name="cookie_bar_expiration_type" <?php if ($expiration_type=="custom") echo "checked";?> value="custom">Custom expiration
105 <div class="cookie_bar_days_to_expire">
106 <input type="text" size="4" name="cookie_bar_days_to_expire" value="<?php echo esc_html( $expiration_custom_date ); ?>" /> days
107 </div>
108
109
110 </td>
111
112 </tr>
113 <tr>
114 <th colspan="2" >
115 <hr style="max-width: 205px; margin-left: 0;" />
116 </th>
117 </tr>
118 <tr valign="top">
119 <th scope="row"><?php _e('Cookie Bar message', 'cookie-bar'); ?></th>
120 <td><input type="text" size="100" name="cookie_bar_message" value="<?php echo esc_html( get_option('cookie_bar_message') ); ?>" /> <small>HTML allowed - E.g.:<xmp>By continuing to browse this site, you agree to our <a href="https://aboutcookies.com/" target="_blank" rel="nofollow">use of cookies</a>.</xmp></small></td>
121 </tr>
122 <tr valign="top">
123 <th scope="row"><?php _e('Button text', 'cookie-bar'); ?></th>
124 <td><input type="text" size="20" name="cookie_bar_button" value="<?php echo esc_attr( get_option('cookie_bar_button') ); ?>" /> <small>E.g.: I understand</small></td>
125 </tr>
126 <tr>
127 <th colspan="2" >
128 <hr style="max-width: 205px; margin-left: 0;" />
129 </th>
130 </tr>
131 <tr valign="top">
132 <th scope="row"><?php _e('Button background colour', 'cookie-bar'); ?></th>
133 <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>
134 </tr>
135 <tr valign="top">
136 <th scope="row"><?php _e('Button font colour', 'cookie-bar'); ?></th>
137 <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>
138 </tr>
139 <tr valign="top">
140 <th scope="row"><?php _e('Bar background colour', 'cookie-bar'); ?></th>
141 <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>
142 </tr>
143 <tr valign="top">
144 <th scope="row"><?php _e('Bar font colour', 'cookie-bar'); ?></th>
145 <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>
146 </tr>
147 <tr>
148 <th colspan="2" >
149 <hr style="max-width: 205px; margin-left: 0;" />
150 </th>
151 </tr>
152 <tr valign="top">
153 <th scope="row"><?php _e('Show for logged out users only', 'cookie-bar'); ?></th>
154 <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>
155 </tr>
156
157 <tr valign="top">
158 <th scope="row"><?php _e('Display at the top', 'cookie-bar'); ?></th>
159 <td><input type="checkbox" name="cookie_bar_show_on_top" <?php if ($cookie_bar_show_on_top == "1") echo "checked";?> value="1" ></td>
160 </tr>
161
162 </table>
163 <script type="text/javascript" >
164
165 function handleClick_type(type_) {
166
167 if( type_.value == "custom")
168 {
169
170 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
171
172 for (var i = 0; i < tracking_code_gtag.length; i ++) {
173 tracking_code_gtag[i].style.display = 'block';
174 }
175
176 }
177 else if( type_.value == "never")
178 {
179 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
180
181 for (var i = 0; i < tracking_code_gtag.length; i ++) {
182 tracking_code_gtag[i].style.display = 'none';
183 }
184 }
185 }
186
187 </script>
188
189 <?php submit_button(); ?>
190 </form>
191 <p>We are very happy to be able to provide this and other <a target="_blank" href="https://www.brontobytes.com/blog/c/wordpress-plugins/">free WordPress plugins</a>.</p>
192 <p>Plugin developed by <a href="https://www.brontobytes.com/" target="_blank" >Brontobytes</a></p>
193 <a href="https://www.brontobytes.com/" target="_blank"><img width="100" style="vertical-align:middle" src="<?php echo plugins_url( 'images/brontobytes.svg', __FILE__ ) ?>" alt="Web hosting provider"></a>
194 </div>
195 <?php }
196
197 function cookie_bar_settings() {
198 register_setting( 'cookie-bar-settings', 'cookie_bar_message' );
199 register_setting( 'cookie-bar-settings', 'cookie_bar_button' );
200 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_bg_colour' );
201 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_font_colour' );
202 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_bg_colour' );
203 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_font_colour' );
204 register_setting( 'cookie-bar-settings', 'cookie_bar_days_to_expire' );
205 register_setting( 'cookie-bar-settings', 'cookie_bar_expiration_type' );
206 register_setting( 'cookie-bar-settings', 'cookie_bar_show_for_logged_out_users_only' );
207 register_setting( 'cookie-bar-settings', 'cookie_bar_show_on_top' );
208
209 }
210 add_action( 'admin_init', 'cookie_bar_settings' );
211
212 function cookie_bar_deactivation() {
213 delete_option( 'cookie_bar_message' );
214 delete_option( 'cookie_bar_button' );
215 delete_option( 'cookie_bar_btn_bg_colour' );
216 delete_option( 'cookie_bar_btn_font_colour' );
217 delete_option( 'cookie_bar_bar_bg_colour' );
218 delete_option( 'cookie_bar_bar_font_colour' );
219 delete_option( 'cookie_bar_days_to_expire' );
220 delete_option( 'cookie_bar_expiration_type' );
221 delete_option( 'cookie_bar_show_for_logged_out_users_only' );
222 delete_option( 'cookie_bar_show_on_top' );
223
224 }
225 register_deactivation_hook( __FILE__, 'cookie_bar_deactivation' );
226
227 function cookie_bar_dependencies() {
228 wp_register_script( 'cookie-bar-js', plugins_url('js/cookie-bar.js', __FILE__), array('jquery'), time(), false );
229 wp_enqueue_script( 'cookie-bar-js' );
230 wp_register_style( 'cookie-bar-css', plugins_url('css/cookie-bar.css', __FILE__) );
231 wp_enqueue_style( 'cookie-bar-css' );
232 }
233 add_action( 'wp_enqueue_scripts', 'cookie_bar_dependencies' );
234
235 class cookie_bar_languages {
236 public static function loadTextDomain() {
237 load_plugin_textdomain('cookie-bar', false, dirname(plugin_basename(__FILE__ )) . '/languages/');
238 }
239 }
240
241
242 $allowed_html = array(
243 'a' => array(
244 'href' => array(),
245 'title' => array(),
246 'target' => array(),
247 'class' => array(),
248 'id' => array(),
249 'rel' => array(),
250 ),
251 'br' => array(),
252 'em' => array(),
253 'strong' => array(),
254 );
255
256
257 add_action('plugins_loaded', array('cookie_bar_languages', 'loadTextDomain'));
258
259 function cookie_bar_color_picker( $hook_suffix ) {
260 // first check that $hook_suffix is appropriate for your admin page
261 wp_enqueue_style( 'wp-color-picker' );
262 wp_enqueue_script( 'cookie-bar-color-picker', plugins_url('js/cookie-bar.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
263 }
264 add_action( 'admin_enqueue_scripts', 'cookie_bar_color_picker' );
265
266 function cookie_bar() {
267 global $allowed_html;
268
269 $cookie_bar_message_output = get_option( 'cookie_bar_message' );
270 $cookie_bar_button_output = esc_attr( get_option('cookie_bar_button') );
271 $cookie_bar_btn_font_colour = esc_attr( get_option('cookie_bar_btn_font_colour') );
272 $cookie_bar_bar_bg_colour = esc_attr( get_option('cookie_bar_bar_bg_colour') );
273 $cookie_bar_bar_font_colour = esc_attr( get_option('cookie_bar_bar_font_colour') );
274 $cookie_bar_show_for_logged_out_users_only = esc_attr( get_option('cookie_bar_show_for_logged_out_users_only') );
275 $cookie_bar_show_on_top = esc_attr( get_option('cookie_bar_show_on_top') );
276
277 $expiration_type = "custom";
278 $option_type = get_option('cookie_bar_expiration_type');
279 if (isset($option_type) && $option_type === "never") {
280 $expiration_type = "never";
281 }
282
283 $expiration_custom_date = "30";
284 $option_custom_date = get_option('cookie_bar_days_to_expire');
285 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
286 $expiration_custom_date = $option_custom_date;
287 }
288
289 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>.';
290 if ( empty( $cookie_bar_button_output ) ) $cookie_bar_button_output = "I Understand";
291 ?>
292 <style type="text/css" >
293 <?php
294 if (isset($cookie_bar_btn_font_colour) && (!empty($cookie_bar_btn_font_colour))) {
295 ?>
296 button#euCookieAcceptWP { color : <?php echo $cookie_bar_btn_font_colour ?>; }
297 <?php
298 }
299
300 if (isset($cookie_bar_bar_bg_colour) && (!empty($cookie_bar_bar_bg_colour))) {
301 ?>
302 #eu-cookie-bar { background-color : <?php echo $cookie_bar_bar_bg_colour ?>; }
303 <?php
304 }
305
306
307 if (isset($cookie_bar_bar_font_colour) && (!empty($cookie_bar_bar_font_colour))) {
308 ?>
309 #eu-cookie-bar , #eu-cookie-bar a { color : <?php echo $cookie_bar_bar_font_colour ?>; }
310 <?php
311 }
312
313
314 if (isset($cookie_bar_show_on_top) && (!empty($cookie_bar_show_on_top))) {
315 ?>
316 #eu-cookie-bar
317 {
318 position: fixed;
319 top: 0;
320 height: 30px;
321 z-index: 999999999999999;
322 }
323 <?php
324 }
325
326
327
328 ?>
329
330
331
332
333 </style>
334 <?php if($cookie_bar_show_for_logged_out_users_only) {
335 if(is_user_logged_in()) {
336 return;
337 }
338 } ?>
339 <!-- Cookie Bar -->
340 <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>
341 <!-- End Cookie Bar -->
342 <?php
343 }
344 add_action( 'wp_footer', 'cookie_bar', 10 );