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

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

346 lines 14.8 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.2
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 $option_custom_date = preg_replace('/\D/', '', isset($option_custom_date) ? $option_custom_date : '');
99
100 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
101 $expiration_custom_date = $option_custom_date;
102 }
103 ?>
104 <input type="radio" name="cookie_bar_expiration_type" <?php if ($expiration_type=="never") echo "checked";?> value="never">Never expire (until cookies are cleared)
105 <br/>
106 <input type="radio" name="cookie_bar_expiration_type" <?php if ($expiration_type=="custom") echo "checked";?> value="custom">Custom expiration
107 <div class="cookie_bar_days_to_expire">
108 <input type="text" size="4" name="cookie_bar_days_to_expire" value="<?php echo esc_html( $expiration_custom_date ); ?>" /> days
109 </div>
110
111
112 </td>
113
114 </tr>
115 <tr>
116 <th colspan="2" >
117 <hr style="max-width: 205px; margin-left: 0;" />
118 </th>
119 </tr>
120 <tr valign="top">
121 <th scope="row"><?php _e('Cookie Bar message', 'cookie-bar'); ?></th>
122 <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>
123 </tr>
124 <tr valign="top">
125 <th scope="row"><?php _e('Button text', 'cookie-bar'); ?></th>
126 <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>
127 </tr>
128 <tr>
129 <th colspan="2" >
130 <hr style="max-width: 205px; margin-left: 0;" />
131 </th>
132 </tr>
133 <tr valign="top">
134 <th scope="row"><?php _e('Button background colour', 'cookie-bar'); ?></th>
135 <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>
136 </tr>
137 <tr valign="top">
138 <th scope="row"><?php _e('Button font colour', 'cookie-bar'); ?></th>
139 <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>
140 </tr>
141 <tr valign="top">
142 <th scope="row"><?php _e('Bar background colour', 'cookie-bar'); ?></th>
143 <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>
144 </tr>
145 <tr valign="top">
146 <th scope="row"><?php _e('Bar font colour', 'cookie-bar'); ?></th>
147 <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>
148 </tr>
149 <tr>
150 <th colspan="2" >
151 <hr style="max-width: 205px; margin-left: 0;" />
152 </th>
153 </tr>
154 <tr valign="top">
155 <th scope="row"><?php _e('Show for logged out users only', 'cookie-bar'); ?></th>
156 <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>
157 </tr>
158
159 <tr valign="top">
160 <th scope="row"><?php _e('Display at the top', 'cookie-bar'); ?></th>
161 <td><input type="checkbox" name="cookie_bar_show_on_top" <?php if ($cookie_bar_show_on_top == "1") echo "checked";?> value="1" ></td>
162 </tr>
163
164 </table>
165 <script type="text/javascript" >
166
167 function handleClick_type(type_) {
168
169 if( type_.value == "custom")
170 {
171
172 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
173
174 for (var i = 0; i < tracking_code_gtag.length; i ++) {
175 tracking_code_gtag[i].style.display = 'block';
176 }
177
178 }
179 else if( type_.value == "never")
180 {
181 var tracking_code_gtag = document.getElementsByClassName('cookie_bar_days_to_expire');
182
183 for (var i = 0; i < tracking_code_gtag.length; i ++) {
184 tracking_code_gtag[i].style.display = 'none';
185 }
186 }
187 }
188
189 </script>
190
191 <?php submit_button(); ?>
192 </form>
193 <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>
194 <p>Plugin developed by <a href="https://www.brontobytes.com/" target="_blank" >Brontobytes</a></p>
195 <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>
196 </div>
197 <?php }
198
199 function cookie_bar_settings() {
200 register_setting( 'cookie-bar-settings', 'cookie_bar_message' );
201 register_setting( 'cookie-bar-settings', 'cookie_bar_button' );
202 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_bg_colour' );
203 register_setting( 'cookie-bar-settings', 'cookie_bar_btn_font_colour' );
204 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_bg_colour' );
205 register_setting( 'cookie-bar-settings', 'cookie_bar_bar_font_colour' );
206 register_setting( 'cookie-bar-settings', 'cookie_bar_days_to_expire' );
207 register_setting( 'cookie-bar-settings', 'cookie_bar_expiration_type' );
208 register_setting( 'cookie-bar-settings', 'cookie_bar_show_for_logged_out_users_only' );
209 register_setting( 'cookie-bar-settings', 'cookie_bar_show_on_top' );
210
211 }
212 add_action( 'admin_init', 'cookie_bar_settings' );
213
214 function cookie_bar_deactivation() {
215 delete_option( 'cookie_bar_message' );
216 delete_option( 'cookie_bar_button' );
217 delete_option( 'cookie_bar_btn_bg_colour' );
218 delete_option( 'cookie_bar_btn_font_colour' );
219 delete_option( 'cookie_bar_bar_bg_colour' );
220 delete_option( 'cookie_bar_bar_font_colour' );
221 delete_option( 'cookie_bar_days_to_expire' );
222 delete_option( 'cookie_bar_expiration_type' );
223 delete_option( 'cookie_bar_show_for_logged_out_users_only' );
224 delete_option( 'cookie_bar_show_on_top' );
225
226 }
227 register_deactivation_hook( __FILE__, 'cookie_bar_deactivation' );
228
229 function cookie_bar_dependencies() {
230 wp_register_script( 'cookie-bar-js', plugins_url('js/cookie-bar.js', __FILE__), array('jquery'), time(), false );
231 wp_enqueue_script( 'cookie-bar-js' );
232 wp_register_style( 'cookie-bar-css', plugins_url('css/cookie-bar.css', __FILE__) );
233 wp_enqueue_style( 'cookie-bar-css' );
234 }
235 add_action( 'wp_enqueue_scripts', 'cookie_bar_dependencies' );
236
237 class cookie_bar_languages {
238 public static function loadTextDomain() {
239 load_plugin_textdomain('cookie-bar', false, dirname(plugin_basename(__FILE__ )) . '/languages/');
240 }
241 }
242
243
244 $allowed_html = array(
245 'a' => array(
246 'href' => array(),
247 'title' => array(),
248 'target' => array(),
249 'class' => array(),
250 'id' => array(),
251 'rel' => array(),
252 ),
253 'br' => array(),
254 'em' => array(),
255 'strong' => array(),
256 );
257
258
259 add_action('plugins_loaded', array('cookie_bar_languages', 'loadTextDomain'));
260
261 function cookie_bar_color_picker( $hook_suffix ) {
262 // first check that $hook_suffix is appropriate for your admin page
263 wp_enqueue_style( 'wp-color-picker' );
264 wp_enqueue_script( 'cookie-bar-color-picker', plugins_url('js/cookie-bar.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
265 }
266 add_action( 'admin_enqueue_scripts', 'cookie_bar_color_picker' );
267
268 function cookie_bar() {
269 global $allowed_html;
270
271 $cookie_bar_message_output = get_option( 'cookie_bar_message' );
272 $cookie_bar_button_output = esc_attr( get_option('cookie_bar_button') );
273 $cookie_bar_btn_font_colour = esc_attr( get_option('cookie_bar_btn_font_colour') );
274 $cookie_bar_bar_bg_colour = esc_attr( get_option('cookie_bar_bar_bg_colour') );
275 $cookie_bar_bar_font_colour = esc_attr( get_option('cookie_bar_bar_font_colour') );
276 $cookie_bar_show_for_logged_out_users_only = esc_attr( get_option('cookie_bar_show_for_logged_out_users_only') );
277 $cookie_bar_show_on_top = esc_attr( get_option('cookie_bar_show_on_top') );
278
279 $expiration_type = "custom";
280 $option_type = get_option('cookie_bar_expiration_type');
281 if (isset($option_type) && $option_type === "never") {
282 $expiration_type = "never";
283 }
284
285 $expiration_custom_date = "30";
286 $option_custom_date = get_option('cookie_bar_days_to_expire');
287 if (isset($option_custom_date) && (!empty($option_custom_date)) ) {
288 $expiration_custom_date = $option_custom_date;
289 }
290
291 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>.';
292 if ( empty( $cookie_bar_button_output ) ) $cookie_bar_button_output = "I Understand";
293 ?>
294 <style type="text/css" >
295 <?php
296 if (isset($cookie_bar_btn_font_colour) && (!empty($cookie_bar_btn_font_colour))) {
297 ?>
298 button#euCookieAcceptWP { color : <?php echo $cookie_bar_btn_font_colour ?>; }
299 <?php
300 }
301
302 if (isset($cookie_bar_bar_bg_colour) && (!empty($cookie_bar_bar_bg_colour))) {
303 ?>
304 #eu-cookie-bar { background-color : <?php echo $cookie_bar_bar_bg_colour ?>; }
305 <?php
306 }
307
308
309 if (isset($cookie_bar_bar_font_colour) && (!empty($cookie_bar_bar_font_colour))) {
310 ?>
311 #eu-cookie-bar , #eu-cookie-bar a { color : <?php echo $cookie_bar_bar_font_colour ?>; }
312 <?php
313 }
314
315
316 if (isset($cookie_bar_show_on_top) && (!empty($cookie_bar_show_on_top))) {
317 ?>
318 #eu-cookie-bar
319 {
320 position: fixed;
321 top: 0;
322 height: 30px;
323 z-index: 999999999999999;
324 }
325 <?php
326 }
327
328
329
330 ?>
331
332
333
334
335 </style>
336 <?php if($cookie_bar_show_for_logged_out_users_only) {
337 if(is_user_logged_in()) {
338 return;
339 }
340 } ?>
341 <!-- Cookie Bar -->
342 <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>
343 <!-- End Cookie Bar -->
344 <?php
345 }
346 add_action( 'wp_footer', 'cookie_bar', 10 );