PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.5.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.5.0
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 3.5.0 3.6.0 All 93 releases
cookiebot / addons / controller / addons / jetpack / widget / facebook-widget.php

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

248 lines 6.0 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 /**
11 * This class is used to add cookiebot consent to facebook widget
12 *
13 * @since 1.2.0
14 */
15 class Facebook_Widget {
16
17 /**
18 * @var array list of supported cookie types
19 *
20 * @since 1.3.0
21 */
22 protected $cookie_types;
23
24 /**
25 * @var Settings_Service_Interface
26 *
27 * @since 1.3.0
28 */
29 protected $settings;
30
31 /**
32 * @var Script_Loader_Tag_Interface
33 *
34 * @since 1.3.0
35 */
36 protected $script_loader_tag;
37
38 /**
39 * @var Cookie_Consent_Interface
40 *
41 * @since 1.3.0
42 */
43 protected $cookie_consent;
44
45 /**
46 * @var Buffer_Output_Interface
47 *
48 * @since 1.3.0
49 */
50 protected $buffer_output;
51
52 /**
53 * Option name for jetpack addon
54 *
55 * @var string
56 */
57 public $widget_option;
58
59 /**
60 * Facebook_Widget constructor.
61 *
62 * @param Settings_Service_Interface $settings
63 * @param Script_Loader_Tag_Interface $script_loader_tag
64 * @param Cookie_Consent_Interface $cookie_consent
65 * @param Buffer_Output_Interface $buffer_output
66 * @param string $widget_option
67 *
68 * @version 1.8.0
69 * @since 1.2.0
70 */
71 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 ) {
72 $this->settings = $settings;
73 $this->script_loader_tag = $script_loader_tag;
74 $this->cookie_consent = $cookie_consent;
75 $this->buffer_output = $buffer_output;
76 $this->widget_option = $widget_option;
77 }
78
79 public function load_configuration() {
80 /**
81 * The widget is active
82 */
83 if ( is_active_widget( false, false, 'facebook-likebox', true ) ) {
84 /**
85 * The widget is enabled in Prior consent
86 */
87 if ( $this->is_widget_enabled() ) {
88 /**
89 * The visitor didn't check the required cookie types
90 */
91 if ( ! $this->cookie_consent->are_cookie_states_accepted( $this->get_widget_cookie_types() ) ) {
92 /**
93 * Manipulate script attribute
94 */
95 $this->add_consent_attribute_to_facebook_embed_javascript();
96
97 /**
98 * Display placeholder if allowed in the backend settings
99 */
100 if ( $this->is_widget_placeholder_enabled() ) {
101 add_action( 'jetpack_stats_extra', array( $this, 'cookie_consent_div' ), 10, 2 );
102 }
103 }
104 }
105 }
106 }
107
108 public function get_label() {
109 return 'Facebook';
110 }
111
112 /**
113 * Returns widget option name
114 *
115 * @return string
116 *
117 * @since 1.8.0
118 */
119 public function get_widget_option_name() {
120 return 'facebook';
121 }
122
123 /**
124 * Returns cookie types for a widget
125 *
126 * @return mixed
127 *
128 * @since 1.8.0
129 */
130 public function get_widget_cookie_types() {
131 return $this->settings->get_widget_cookie_types( $this->widget_option, $this->get_widget_option_name() );
132 }
133
134 /**
135 * Checks if a widget is enabled
136 *
137 * @return mixed
138 *
139 * @since 1.8.0
140 */
141 public function is_widget_enabled() {
142 return $this->settings->is_widget_enabled( $this->widget_option, $this->get_widget_option_name() );
143 }
144
145 /**
146 * @return string
147 */
148 public function get_default_placeholder() {
149 return 'Please accept [renew_consent]%cookie_types[/renew_consent] cookies to see facebook widget.';
150 }
151
152 /**
153 * Checks if a widget placeholder is enabled
154 *
155 * @return boolean true If widget placeholder is checked
156 * false If widget placeholder is not checked
157 *
158 * @since 1.8.0
159 */
160 public function is_widget_placeholder_enabled() {
161 return $this->settings->is_widget_placeholder_enabled( $this->widget_option, $this->get_widget_option_name() );
162 }
163
164 /**
165 * Checks if widget has existing placeholders
166 *
167 * @return mixed
168 *
169 * @since 1.8.0
170 */
171 public function widget_has_placeholder() {
172 return $this->settings->widget_has_placeholder( $this->widget_option, $this->get_widget_option_name() );
173 }
174
175 /**
176 * Returns all widget placeholders
177 *
178 * @return mixed
179 *
180 * @since 1.8.0
181 */
182 public function get_widget_placeholders() {
183 return $this->settings->get_widget_placeholders( $this->widget_option, $this->get_widget_option_name() );
184 }
185
186 /**
187 * returns widget placeholder
188 *
189 * @return mixed
190 *
191 * @since 1.8.0
192 */
193 public function get_widget_placeholder() {
194 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() ) );
195 }
196
197
198 /**
199 * Tag external Facebook javascript file with cookiebot consent.
200 *
201 * @since 1.2.0
202 */
203 protected function add_consent_attribute_to_facebook_embed_javascript() {
204 $this->script_loader_tag->add_tag( 'jetpack-facebook-embed', $this->get_widget_cookie_types() );
205 }
206
207 /**
208 * Show consent message when the consent is not given.
209 *
210 * @param $view string
211 * @param $widget string
212 *
213 * @since 1.6.0
214 */
215 public function cookie_consent_div( $view, $widget ) {
216 if ( $widget == 'facebook-likebox' && $view == 'widget_view' ) {
217 if ( is_array( $this->get_widget_cookie_types() ) && count( $this->get_widget_cookie_types() ) > 0 ) {
218 echo '<div class="cookieconsent-optout-' . cookiebot_addons_get_one_cookie_type( $this->get_widget_cookie_types() ) . '">
219 ' . $this->get_widget_placeholder() . '
220 </div>';
221 }
222 }
223 }
224
225 /**
226 * Adds extra information under the label
227 *
228 * @return string
229 *
230 * @since 1.8.0
231 */
232 public function get_extra_information() {
233 return '<p>' . __( 'Facebook widget.', 'cookiebot-addons' ) . '</p>';
234 }
235
236 /**
237 * Placeholder helper overlay in the settings page.
238 *
239 * @return string
240 *
241 * @since 1.8.0
242 */
243 public function get_placeholder_helper() {
244 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>';
245 }
246
247 }
248