PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.11.1
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.11.1
4.7.4 4.7.5 4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 All 95 releases
cookiebot / addons / controller / addons / jetpack / widget / googleplus-badge-widget.php

googleplus-badge-widget.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.11.1, at addons/controller/addons/jetpack/widget/googleplus-badge-widget.php

244 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cookiebot_addons\controller\addons\jetpack\widget;
4
5 use cookiebot_addons\lib\Settings_Service_Interface;
6 use cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface;
7 use cookiebot_addons\lib\Cookie_Consent_Interface;
8 use cookiebot_addons\lib\buffer\Buffer_Output_Interface;
9
10 class Googleplus_Badge_Widget {
11
12 /**
13 * @var array list of supported cookie types
14 *
15 * @since 1.3.0
16 */
17 protected $cookie_types;
18
19 /**
20 * @var Settings_Service_Interface
21 *
22 * @since 1.3.0
23 */
24 protected $settings;
25
26 /**
27 * @var Script_Loader_Tag_Interface
28 *
29 * @since 1.3.0
30 */
31 protected $script_loader_tag;
32
33 /**
34 * @var Cookie_Consent_Interface
35 *
36 * @since 1.3.0
37 */
38 protected $cookie_consent;
39
40 /**
41 * @var Buffer_Output_Interface
42 *
43 * @since 1.3.0
44 */
45 protected $buffer_output;
46
47 /**
48 * Option name for jetpack addon
49 *
50 * @var string
51 */
52 public $widget_option;
53
54 /**
55 * Googleplus_Badge_Widget constructor.
56 *
57 * @param Settings_Service_Interface $settings
58 * @param Script_Loader_Tag_Interface $script_loader_tag
59 * @param Cookie_Consent_Interface $cookie_consent
60 * @param Buffer_Output_Interface $buffer_output
61 * @param $widget_option
62 *
63 * @version 1.8.0
64 * @since 1.2.0
65 */
66 public function __construct( Settings_Service_Interface $settings, Script_Loader_Tag_Interface $script_loader_tag, Cookie_Consent_Interface $cookie_consent, Buffer_Output_Interface $buffer_output, $widget_option ) {
67 $this->settings = $settings;
68 $this->script_loader_tag = $script_loader_tag;
69 $this->cookie_consent = $cookie_consent;
70 $this->buffer_output = $buffer_output;
71 $this->widget_option = $widget_option;
72 }
73
74 /**
75 * Load configuration
76 */
77 public function load_configuration() {
78 /**
79 * The widget is active
80 */
81 if ( is_active_widget( false, false, 'googleplus-badge', true ) ) {
82 /**
83 * The widget is enabled in Prior consent
84 */
85 if ( $this->is_widget_enabled() ) {
86 /**
87 * The visitor didn't check the required cookie types
88 */
89 if ( ! $this->cookie_consent->are_cookie_states_accepted( $this->get_widget_cookie_types() ) ) {
90 $this->cookie_types = $this->get_widget_cookie_types();
91
92 $this->disable_javascript_file();
93
94 if ( $this->is_widget_placeholder_enabled() ) {
95 add_action( 'jetpack_stats_extra', array( $this, 'display_div_message_to_go_to_consent_settings' ), 10, 2 );
96 }
97 }
98 }
99 }
100 }
101
102 public function get_label() {
103 return 'Google Plus Badge';
104 }
105
106 /**
107 * Returns widget option name
108 *
109 * @return string
110 *
111 * @since 1.8.0
112 */
113 public function get_widget_option_name() {
114 return 'googleplus_badge';
115 }
116
117 /**
118 * Returns cookie types for a widget
119 *
120 * @return mixed
121 *
122 * @since 1.8.0
123 */
124 public function get_widget_cookie_types() {
125 return $this->settings->get_widget_cookie_types( $this->widget_option, $this->get_widget_option_name() );
126 }
127
128 /**
129 * Checks if a widget is enabled
130 *
131 * @return mixed
132 *
133 * @since 1.8.0
134 */
135 public function is_widget_enabled() {
136 return $this->settings->is_widget_enabled( $this->widget_option, $this->get_widget_option_name() );
137 }
138
139 /**
140 * @return string
141 */
142 public function get_default_placeholder() {
143 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to enable google plus badge.';
144 }
145
146 /**
147 * Checks if a widget placeholder is enabled
148 *
149 * @return boolean true If widget placeholder is checked
150 * false If widget placeholder is not checked
151 *
152 * @since 1.8.0
153 */
154 public function is_widget_placeholder_enabled() {
155 return $this->settings->is_widget_placeholder_enabled( $this->widget_option, $this->get_widget_option_name() );
156 }
157
158 /**
159 * Checks if widget has existing placeholders
160 *
161 * @return mixed
162 *
163 * @since 1.8.0
164 */
165 public function widget_has_placeholder() {
166 return $this->settings->widget_has_placeholder( $this->widget_option, $this->get_widget_option_name() );
167 }
168
169 /**
170 * Returns all widget placeholders
171 *
172 * @return mixed
173 *
174 * @since 1.8.0
175 */
176 public function get_widget_placeholders() {
177 return $this->settings->get_widget_placeholders( $this->widget_option, $this->get_widget_option_name() );
178 }
179
180 /**
181 * returns widget placeholder
182 *
183 * @return mixed
184 *
185 * @since 1.8.0
186 */
187 public function get_widget_placeholder() {
188 return $this->settings->get_widget_placeholder( $this->widget_option, $this->get_widget_option_name(), $this->get_default_placeholder(), cookiebot_addons_output_cookie_types( $this->get_widget_cookie_types() ) );
189 }
190
191 /**
192 * Disable javascript file if marketing consent is not given
193 *
194 * @since 1.2.0
195 */
196 protected function disable_javascript_file() {
197 $this->script_loader_tag->add_tag( 'googleplus-widget', $this->cookie_types );
198 }
199
200 /**
201 * Show a messsage to go to consent settings
202 *
203 * @param $view string
204 * @param $widget string
205 *
206 * @since 1.2.0
207 */
208 public function display_div_message_to_go_to_consent_settings( $view, $widget ) {
209 if ( $widget === 'googleplus-badge' && $view === 'widget_view' ) {
210 if ( is_array( $this->cookie_types ) && count( $this->cookie_types ) > 0 ) {
211 $class_name = cookiebot_addons_cookieconsent_optout( $this->cookie_types );
212 ?>
213 <div class="<?php echo esc_attr( $class_name ); ?>">
214 <?php echo $this->get_widget_placeholder(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
215 </div>
216 <?php
217 }
218 }
219 }
220
221 /**
222 * Adds extra information under the label
223 *
224 * @return string
225 *
226 * @since 1.8.0
227 */
228 public function get_extra_information() {
229 return false;
230 }
231
232 /**
233 * Placeholder helper overlay in the settings page.
234 *
235 * @return string
236 *
237 * @since 1.8.0
238 */
239 public function get_placeholder_helper() {
240 return '<p>Merge tags you can use in the placeholder text:</p><ul><li>%cookie_types - Lists required cookie types</li><li>[renew_consent]text[/renew_consent] - link to display cookie settings in frontend</li></ul>';
241 }
242
243 }
244