class-borlabs-cookie.php
6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* WPSL / Borlabs Cookie class
*
* @author Tijmen Smit
* @since 2.2.22
*/
if ( !defined( 'ABSPATH' ) ) exit;
if ( !class_exists( 'WPSL_Borlabs_Cookie' ) ) {
class WPSL_Borlabs_Cookie {
/**
* Class constructor
*/
public function __construct() {
if ( !is_admin() ) {
if (defined('BORLABS_COOKIE_VERSION') && version_compare(BORLABS_COOKIE_VERSION, '2.0', '>=')) {
add_filter( 'borlabsCookie/contentBlocker/modify/content/wpstorelocator', array( $this, 'update_content_blocker' ), 10, 2 );
} else {
add_filter( 'borlabsCookie/bct/modify_content/wpstorelocator', array( $this, 'update_content_blocker_backwards_compatibility' ), 10, 2 );
}
}
}
/**
* Check if the 'wpstorelocator' blocked content type exists.
* If this is not the case, then we create it.
*
* @since 2.2.22
* @return void
*/
public function maybe_enable_bct() {
$wpsl_bct_data = BorlabsCookieHelper()->getBlockedContentTypeDataByTypeId( 'wpstorelocator' );
if ( !$wpsl_bct_data ) {
$this->enable();
}
}
/**
* Add support for the delayed loading of the
* Google Maps library in the Borlabs Cookies plugin
* by adding a 'wpstorelocator' blocked content type.
*
* @since 2.2.22
* @return void
*/
public function enable() {
/**
* First, we delete old Blocked Content Types with the id wpstorelocator.
* If the id doesn't exist, nothing happens.
*
* Doing so ensures that both plugins work as intended.
*/
BorlabsCookieHelper()->deleteBlockedContentType( 'wpstorelocator' );
// Add new Blocked Content Type wpstorelocator - if the BCT exists nothing happens
BorlabsCookieHelper()->addBlockedContentType(
'wpstorelocator',
'WP Store Locator',
'',
[],
'<div class="borlabs-cookie-bct bc-bct-iframe bc-bct-google-maps">
<p class="bc-thumbnail"><img src="%%thumbnail%%" alt="%%name%%"></p>
<div class="bc-text">
<p>' . _x( 'To protect your personal data, your connection to Google Maps has been blocked.<br>Click on <strong>Load map</strong> to unblock Google Maps.<br>By loading the map you accept the privacy policy of Google.<br>More information about Google\'s privacy policy can be found here <a href="https://policies.google.com/privacy?hl=en&gl=en" target="_blank" rel="nofollow">Google - Privacy & Terms</a> . ', 'Borlabs Cookie', 'wpsl' ) . '</p>
<p><label><input type="checkbox" name="unblockAll" value="1" checked> ' . _x( 'Do not block Google Maps in the future anymore.', 'Borlabs Cookie', 'wpsl' ) . '</label>
<a role="button" data-borlabs-cookie-unblock>' . _x( 'Load map', 'Borlabs Cookie', 'wpsl' ) . '</a></p>
</div>
</div>',
'',
'',
[
'responsiveIframe' => false,
],
true,
true
);
}
/**
* Remove the 'wpstorelocator' blocked content type
* from the Borlabs Cookie plugin.
*
* @since 2.2.22
*/
public function disable() {
if ( function_exists('BorlabsCookieHelper' ) ) {
BorlabsCookieHelper()->deleteBlockedContentType( 'wpstorelocator' );
}
}
/**
* modifyWPStoreLocatorContentBlockerBackwardsCompatibility function.
*
* @since 2.2.233
* @param mixed $id
* @param mixed $content
* @return void
*/
public function update_content_blocker_backwards_compatibility( $id, $content ) {
return $this->update_content_blocker($content);
}
/**
* modifyWPStoreLocatorContentBlocker function.
*
* @since 2.2.22
* @param mixed $content
* @param mixed $atts
* @return void
*/
public function update_content_blocker( $content, $atts = [] ) {
// Get settings of the Blocked Content Type
$wpsl_data = BorlabsCookieHelper()->getBlockedContentTypeDataByTypeId( 'wpstorelocator' );
// Workaround, fixed in newer versions of Borlabs Cookie
if ( !isset($wpsl_data['settings']['unblockAll'] ) ) {
$wpsl_data['settings']['unblockAll'] = false;
}
BorlabsCookieHelper()->updateBlockedContentTypeJavaScript(
'wpstorelocator',
'var myScriptTag = document.createElement("script"); myScriptTag.type = "text/javascript"; myScriptTag.src = "https://maps.google.com/maps/api/js' . wpsl_get_gmap_api_params( "browser_key" ) .'";jQuery("body").append(myScriptTag);',
'initWpslMap();',
$wpsl_data['settings']
);
// Default thumbnail
$thumbnail = BORLABS_COOKIE_PLUGIN_URL.'images/bct-google-maps.png';
// Get the title which was maybe set via title-attribute in a shortcode
$title = BorlabsCookieHelper()->getCurrentTitleOfBlockedContentType();
// If no title was set use the Blocked Content Type name as title
if ( empty( $title ) ) {
$title = $wpsl_data['name'];
}
// Replace text variables
if (!empty($atts)) {
foreach ($atts as $key => $value) {
$wpsl_data['previewHTML'] = str_replace('%%'.$key.'%%', $value, $wpsl_data['previewHTML']);
}
}
$wpsl_data['previewHTML'] = str_replace(
[
'%%name%%',
'%%thumbnail%%',
'%%privacy_policy_url%%',
],
[
$title,
$thumbnail,
$wpsl_data['privacyPolicyURL'],
],
$wpsl_data['previewHTML']
);
/* Return the HTML that displays the information, that the original content was blocked */
return $wpsl_data['previewHTML'];
}
}
new WPSL_Borlabs_Cookie();
}