Plugin Directory

source: gdpr-cookie-compliance/tags/4.15.1/class-moove-gdpr-content.php

Last change on this file was 3102142, checked in by MooveAgency, 4 weeks ago

Version 4.15.1 released

  • Property svn:executable set to *
File size: 34.3 KB
Line 
1<?php
2/**
3 * Moove_GDPR_Content File Doc Comment
4 *
5 * @category Moove_GDPR_Content
6 * @package   gdpr-cookie-compliance
7 * @author    Moove Agency
8 */
9
10if ( ! defined( 'ABSPATH' ) ) {
11        exit;
12} // Exit if accessed directly
13
14
15/**
16 * Moove_GDPR_Content Class Doc Comment
17 *
18 * @category Class
19 * @package  Moove_Controller
20 * @author   Moove Agency
21 */
22class Moove_GDPR_Content {
23
24        /**
25         * Construct
26         */
27        public function __construct() {
28
29        }
30
31        /**
32         * Integration Extensions
33         */
34        public static function gdpr_extend_integration_snippets( $cache_array, $gdpr_options ) {
35                $gdin_values        = isset( $gdpr_options['gdin_values'] ) ? json_decode( $gdpr_options['gdin_values'], true ) : array();
36                if ( $gdin_values && ! empty( $gdin_values ) && is_array( $gdin_values ) ) :
37                        $gdin_modules       = gdpr_get_integration_modules( $gdpr_options, $gdin_values );
38                        foreach ( $gdin_modules as $_gdin_module_slug => $_gdin_module ) :
39                                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && $_gdin_module['status'] ) :
40                                        $cache_array = apply_filters( 'gdpr_insert_integration_' . $_gdin_module_slug . '_snippet', $cache_array, $_gdin_module );
41                                endif;
42                        endforeach;
43                endif;
44                return $cache_array;
45        }
46
47        public static function gdpr_insert_integration_ga_snippet( $cache_array, $_gdin_module ) {
48                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
49                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
50                        if ( $cookie_cat_n ) :
51                                ob_start();
52                                ?>
53                                <!-- Google tag (gtag.js) -->
54                                <script src="https://www.googletagmanager.com/gtag/js?id=<?php echo $_gdin_module['tacking_id']; ?>" data-type="gdpr-integration"></script>
55                                <script data-type="gdpr-integration">
56                                  window.dataLayer = window.dataLayer || [];
57                                  function gtag(){dataLayer.push(arguments);}
58                                  gtag('js', new Date());
59
60                                  gtag('config', '<?php echo $_gdin_module['tacking_id']; ?>');
61                                </script>
62                                <?php
63                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
64                        endif;
65                endif;
66                return $cache_array;
67        }
68
69        public static function gdpr_insert_integration_ga4_snippet( $cache_array, $_gdin_module ) {
70                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
71                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
72                        if ( $cookie_cat_n ) :
73                                ob_start();
74                                ?>
75                                <!-- Google tag (gtag.js) - Google Analytics 4 -->
76                                <script src="https://www.googletagmanager.com/gtag/js?id=<?php echo $_gdin_module['tacking_id']; ?>" data-type="gdpr-integration"></script>
77                                <script data-type="gdpr-integration">
78                                  window.dataLayer = window.dataLayer || [];
79                                  function gtag(){dataLayer.push(arguments);}
80                                  gtag('js', new Date());
81
82                                  gtag('config', '<?php echo $_gdin_module['tacking_id']; ?>');
83                                </script>
84                                <?php
85                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
86                        endif;
87                endif;
88                return $cache_array;
89        }
90
91        public static function gdpr_insert_integration_gtm_snippet( $cache_array, $_gdin_module ) {
92                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
93                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
94                        if ( $cookie_cat_n ) :
95                                ob_start();
96                                ?>
97                                <!-- Google Tag Manager -->
98                                <script data-type="gdpr-integration">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
99                                new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
100                                j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
101                                'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
102                                })(window,document,'script','dataLayer','<?php echo $_gdin_module['tacking_id']; ?>');</script>
103                                <!-- End Google Tag Manager -->
104                                <?php
105                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
106                                ob_start();
107                                ?>
108                                <!-- Google Tag Manager (noscript) -->
109                                <noscript data-type="gdpr-integration"><iframe src="https://www.googletagmanager.com/ns.html?id=<?php echo $_gdin_module['tacking_id']; ?>"
110                                height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
111                                <!-- End Google Tag Manager (noscript) -->
112                                <?php
113                                $cache_array[$cookie_cat_n]['body'] .= ob_get_clean();
114                        endif;
115                endif;
116                return $cache_array;
117        }
118
119        public static function gdpr_google_consent_mode2_snippet(){
120                $gdpr_default_content = new Moove_GDPR_Content();
121        $option_name          = $gdpr_default_content->moove_gdpr_get_option_name();
122                $gdpr_options         = get_option( $option_name );
123                $gdin_values                    = isset( $gdpr_options['gdin_values'] ) ? json_decode( $gdpr_options['gdin_values'], true ) : array();
124        $gdin_modules           = gdpr_get_integration_modules( $gdpr_options, $gdin_values );
125        if ( isset( $gdin_modules['gtmc2'] ) && isset( $gdin_modules['gtmc2']['tacking_id'] ) && $gdin_modules['gtmc2']['status'] ) :
126                        ?>
127                                <script>
128                                  // Define dataLayer and the gtag function.
129                                  window.dataLayer = window.dataLayer || [];
130                                  function gtag(){dataLayer.push(arguments);}
131
132                                  // Set default consent to 'denied' as a placeholder
133                                  // Determine actual values based on your own requirements
134                                  gtag('consent', 'default', {
135                                    'ad_storage': 'denied',
136                                    'ad_user_data': 'denied',
137                                    'ad_personalization': 'denied',
138                                    'analytics_storage': 'denied',
139                                    'personalization_storage': 'denied',
140                                                'security_storage': 'denied',
141                                                'functionality_storage': 'denied',
142                                                'wait_for_update': '<?php echo apply_filters( 'gdpr_cc_gtm2_wait_for_update', '2000' ) ?>'
143                                  });
144                                </script>
145
146                                <!-- Google Tag Manager -->
147                                <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
148                                new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
149                                j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
150                                'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
151                                })(window,document,'script','dataLayer','<?php echo $gdin_modules['gtmc2']['tacking_id']; ?>');</script>
152                                <!-- End Google Tag Manager -->
153                        <?php
154                endif;
155        }
156
157        public static function gdpr_insert_integration_gtmc2_snippet( $cache_array, $_gdin_module ) {
158                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
159                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
160                        if ( $cookie_cat_n ) :
161                                ob_start();
162                                ?>
163                                <script>
164                                        gtag('consent', 'update', {
165                              'ad_storage': 'granted',
166                                    'ad_user_data': 'granted',
167                                    'ad_personalization': 'granted',
168                                    'analytics_storage': 'granted',
169                                    'personalization_storage': 'granted',
170                                                'security_storage': 'granted',
171                                                'functionality_storage': 'granted',
172                            });
173
174                            dataLayer.push({
175                                         'event': 'cookie_consent_update'
176                                        });
177                                </script>       
178                                <?php
179                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
180                                ob_start();
181                        endif;
182                endif;
183                return $cache_array;
184        }
185
186        public static function gdpr_insert_integration_gadc_snippet( $cache_array, $_gdin_module ) {
187                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
188                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
189                        if ( $cookie_cat_n ) :
190                                ob_start();
191                                ?>
192                                <!-- Global site tag (gtag.js) - Google Ads -->
193                                <script type="text/javascript" data-type="gdpr-integration" src="https://www.googletagmanager.com/gtag/js?id=<?php echo $_gdin_module['tacking_id']; ?>"></script>
194                                <script data-type="gdpr-integration">
195                                  window.dataLayer = window.dataLayer || [];
196                                  function gtag(){dataLayer.push(arguments);}
197                                  gtag('js', new Date());
198
199                                  gtag('config', '<?php echo $_gdin_module['tacking_id']; ?>');
200                                </script>
201                                <!-- End Google Ads -->
202                                <?php
203                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();                               
204                        endif;
205                endif;
206                return $cache_array;
207        }
208
209        public static function gdpr_insert_integration_fbp_snippet( $cache_array, $_gdin_module ) {
210                if ( isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
211                        $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
212                        if ( $cookie_cat_n ) :
213                                ob_start();
214                                ?>
215                                <!-- Facebook Pixel Code -->
216                                <script data-type="gdpr-integration">
217                                  !function(f,b,e,v,n,t,s)
218                                  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
219                                  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
220                                  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
221                                  n.queue=[];t=b.createElement(e);t.async=!0;
222                                  t.src=v;s=b.getElementsByTagName(e)[0];
223                                  s.parentNode.insertBefore(t,s)}(window, document,'script',
224                                  'https://connect.facebook.net/en_US/fbevents.js');
225                                  fbq('init', '<?php echo $_gdin_module['tacking_id']; ?>');
226                                  fbq('track', 'PageView');
227                                </script>
228                                <?php
229                                $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
230                              �� ob_start();
231                                ?>
232                                <noscript data-type="gdpr-integration">
233                                  <img height="1" width="1" style="display:none"
234                                       src="https://www.facebook.com/tr?id=<?php echo $_gdin_module['tacking_id']; ?>&ev=PageView&noscript=1"/>
235                                </noscript>
236                                <!-- End Facebook Pixel Code -->
237                                <?php
238                                $cache_array[$cookie_cat_n]['body'] .= ob_get_clean();
239                        endif;
240                endif;
241                return $cache_array;
242        }
243
244        public static function gdpr_insert_integration_gtm4wp_snippet( $cache_array, $_gdin_module ) {
245                if ( defined('GTM4WP_OPTIONS') && defined ( 'GTM4WP_OPTION_GTM_PLACEMENT' ) && defined ( 'GTM4WP_PLACEMENT_OFF' ) ) :
246      $storedoptions = (array) get_option( GTM4WP_OPTIONS );
247                        if ( ( isset( $storedoptions[GTM4WP_OPTION_GTM_PLACEMENT] ) && $storedoptions[GTM4WP_OPTION_GTM_PLACEMENT] === GTM4WP_PLACEMENT_OFF ) && isset( $_gdin_module['tacking_id'] ) && $_gdin_module['tacking_id'] && intval( $_gdin_module['cookie_cat'] ) ) :
248                                $cookie_cat_n = intval( $_gdin_module['cookie_cat'] ) === 2 ? 'thirdparty' : ( intval( $_gdin_module['cookie_cat'] ) === 3 ? 'advanced' : '' );
249                                if ( $cookie_cat_n && ! $gtm4wp_container_code_written ) :
250                                        ob_start();
251                                        ?>
252                                        <!-- Google Tag Manager -->
253                                        <script data-type="gdpr-integration">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
254                                        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
255                                        j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
256                                        'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
257                                        })(window,document,'script','dataLayer','<?php echo $_gdin_module['tacking_id']; ?>');</script>
258                                        <!-- End Google Tag Manager -->
259                                        <?php
260                                        $cache_array[$cookie_cat_n]['header'] .= ob_get_clean();
261                                        ob_start();
262                                        ?>
263                                        <!-- Google Tag Manager (noscript) -->
264                                        <noscript data-type="gdpr-integration"><iframe src="https://www.googletagmanager.com/ns.html?id=<?php echo $_gdin_module['tacking_id']; ?>"
265                                        height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
266                                        <!-- End Google Tag Manager (noscript) -->
267                                        <?php
268                                        $cache_array[$cookie_cat_n]['body'] .= ob_get_clean();
269                                        $gtm4wp_container_code_written = true;
270                                endif;
271                        endif;
272                endif;
273                return $cache_array;
274        }
275
276        /**
277         * Privacy Overview Tab Content
278         *
279         * @return string Filtered Content
280         */
281        public function moove_gdpr_get_privacy_overview_content() {
282                $_content = '<p>' . __( 'This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.', 'gdpr-cookie-compliance' ) . '</p>';
283                return $_content;
284        }
285
286        /**
287         * Returns the GDPR activation key
288         * @param string $option_key Option key.
289         *
290         */
291        public function gdpr_get_activation_key( $option_key ) {
292                $value = get_option( $option_key );
293                if ( is_multisite() && ! $value ) :
294                        $_value = function_exists( 'get_site_option' ) ? get_site_option( $option_key ) : false;
295                        if ( $_value ) :
296                                $main_blog_id = get_main_site_id();
297                                if ( $main_blog_id ) :
298                                        switch_to_blog( $main_blog_id );
299                                        update_option(
300                                                $option_key,
301                                                $_value
302                                        );
303                                        restore_current_blog();
304                                        delete_site_option( $option_key );
305                                        $value = $_value;
306                                endif;
307                        endif;
308                endif; 
309                return $value;
310        }
311
312        /**
313         * JavaScript localize extension
314         */
315        public static function moove_gdpr_get_localize_scripts() {
316                $loc_data      = array();
317                $gdpr_loc_data = apply_filters( 'gdpr_extend_loc_data', $loc_data );
318                return $gdpr_loc_data;
319        }
320
321        /**
322         * Strict Necessary Tab Content
323         *
324         * @return string Filtered Content
325         */
326        public function moove_gdpr_get_strict_necessary_content() {
327                $_content = '<p>' . __( 'Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.', 'gdpr-cookie-compliance' ) . '</p>';
328                return $_content;
329        }
330
331        /**
332         * Strict Necessary Warning Message
333         *
334         * @return string Filtered Content
335         */
336        public function moove_gdpr_get_strict_necessary_warning() {
337                $_content          = '';
338                $options_name      = $this->moove_gdpr_get_option_name();
339                $gdpr_options      = get_option( $options_name );
340                $wpml_lang_options = $this->moove_gdpr_get_wpml_lang();
341
342                if ( ! isset( $gdpr_options[ 'moove_gdpr_strictly_necessary_cookies_warning' . $wpml_lang_options ] ) ) :
343                        $_content = __( 'If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.', 'gdpr-cookie-compliance' );
344                endif;
345                return $_content;
346        }
347
348        /**
349         * Advanced Cookies Tab Content
350         *
351         * @return string Filtered Content
352         */
353        public function moove_gdpr_get_advanced_cookies_content() {
354                $_content = '<p>' . __( 'This website uses the following additional cookies:</p><p>(List the cookies that you are using on the website here.)', 'gdpr-cookie-compliance' ) . '</p>';
355                return $_content;
356        }
357
358        /**
359         * Third Party Cookies Tab Content
360         *
361         * @return string Filtered Content
362         */
363        public function moove_gdpr_get_third_party_content() {
364                $_content  = '<p>' . __( 'This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.', 'gdpr-cookie-compliance' );
365                $_content .= '<p>' . __( 'Keeping this cookie enabled helps us to improve our website.', 'gdpr-cookie-compliance' ) . '</p>';
366                return $_content;
367        }
368
369        /**
370         * Cookie Policy Tab Content
371         *
372         * @return string Filtered Content
373         */
374        public function moove_gdpr_get_cookie_policy_content() {
375                $privacy_policy_page = get_option( 'wp_page_for_privacy_policy' );
376                $privacy_policy_link = $privacy_policy_page ? esc_url( get_permalink( $privacy_policy_page ) ) : false;
377                $privacy_policy_link = $privacy_policy_link ? $privacy_policy_link : '#';
378
379                $_content = '<p>' . sprintf( __( 'More information about our [privacy_link]Cookie Policy[/privacy_link]', 'gdpr-cookie-compliance' ), $privacy_policy_link ) . '</p>';
380                $_content = str_replace( '[privacy_link]', '<a href="' . $privacy_policy_link . '" target="_blank">', $_content );
381                $_content = str_replace( '[/privacy_link]', '</a>', $_content );
382
383                return $_content;
384        }
385
386        /**
387         * Cookie Policy Tab Content
388         *
389         * @return string Filtered Content
390         */
391        public function moove_gdpr_ifb_content() {
392                $_content  = '<h2>' . __( 'This content is blocked', 'gdpr-cookie-compliance' );
393                $_content .= '<p>' . __( 'Please enable the cookies to view this content', 'gdpr-cookie-compliance' );
394                $_content .= '<br><br>';
395                $_content .= '[accept]' . esc_html__( 'Accept', 'gdpr-cookie-compliance' ) . '[/accept] ';
396                $_content .= '[setting]' . esc_html__( 'Adjust your settings', 'gdpr-cookie-compliance' ) . '[/setting] ';
397                return $_content;
398        }
399
400
401
402        /**
403         * Get option name
404         */
405        public function moove_gdpr_get_option_name() {
406                return 'moove_gdpr_plugin_settings';
407        }
408
409        /**
410         * Get option name
411         */
412        public function moove_gdpr_get_key_name() {
413                return 'moove_gdpr_plugin_key';
414        }
415
416        /**
417         * Get strict secondary notice
418         */
419        public function moove_gdpr_get_secondary_notice() {
420                $_content          = '';
421                $options_name      = $this->moove_gdpr_get_option_name();
422                $gdpr_options      = get_option( $options_name );
423                $wpml_lang_options = $this->moove_gdpr_get_wpml_lang();
424                if ( ! isset( $gdpr_options[ 'moove_gdpr_modal_strictly_secondary_notice' . $wpml_lang_options ] ) ) :
425                        $_content = __( 'Please enable Strictly Necessary Cookies first so that we can save your preferences!', 'gdpr-cookie-compliance' );
426                endif;
427                return $_content;
428        }
429
430        /**
431         * Get WMPL language code
432         */
433        public function moove_gdpr_get_wpml_lang( $type = 'code' ) {
434                if ( function_exists( 'trp_get_languages' ) && isset( $_GET['gdpr-lang'] ) && is_admin() ) :
435                        $lang_code = sanitize_text_field( wp_unslash( $_GET['gdpr-lang'] ) );
436                        if ( $type === 'code' ) :
437                                return $lang_code;
438                        else :
439                                $trp_languages = trp_get_languages();
440                                return isset( $trp_languages[$lang_code] ) ? $trp_languages[$lang_code] : '';
441                        endif;
442                elseif ( class_exists( 'Falang' ) && isset( $_GET['gdpr-lang'] ) && is_admin() ) :
443                        $lang_code = sanitize_text_field( wp_unslash( $_GET['gdpr-lang'] ) );
444                        if ( $type === 'code' ) :
445                                return $lang_code;
446                        else :
447                                $falang_languages               = Falang()->get_model()->get_languages_list();
448                                $lang_name                                              = $lang_code;
449                                foreach ( $falang_languages as $language ) :
450                                        $_code                  = isset( $language->locale ) ? $language->locale : ( isset( $language->slug ) ? $language->slug : '' );
451                                        $lang_name      = $_code === $lang_code && isset( $language->name ) ? $language->name : $lang_name;
452                                endforeach;
453                                return $lang_name;
454                        endif;
455                else :
456                        if ( function_exists( 'trp_get_languages' ) ) :
457                                $trp_languages = trp_get_languages();
458                                global $TRP_LANGUAGE;
459                                return $type === 'code' ? $TRP_LANGUAGE : $trp_languages[ $TRP_LANGUAGE ];
460                        elseif ( class_exists( 'Falang' ) ) :
461                                $current_language = Falang()->get_current_language();
462                                if ( $type === 'code' ) :
463                                        $lang = isset( $current_language->locale ) ? $current_language->locale : ( isset( $current_language->slug ) ? $current_language->slug : '' );
464                                else :
465                                        $lang = isset( $current_language->name ) ? $current_language->name : '';
466                                endif;
467                                return $lang;
468                        elseif ( defined( 'ICL_LANGUAGE_CODE' ) ) :
469                                $language_code = ICL_LANGUAGE_CODE;
470                                if ( ICL_LANGUAGE_CODE === 'all' ) :
471                                        if ( function_exists( 'pll_default_language' ) ) :
472                                                $language_code = pll_default_language();
473                                        elseif ( class_exists( 'SitePress' ) ) :
474                                                global $sitepress;
475                                                $language_code = $sitepress->get_default_language();
476                                        endif;
477                                endif;
478                                return '_' . $language_code;
479                        elseif ( isset( $GLOBALS['q_config']['language'] ) ) :
480                                return $GLOBALS['q_config']['language'];
481                        elseif ( function_exists( 'wpm_get_user_language' ) ) :
482                                return wpm_get_user_language();
483                        endif;
484                endif;
485                return '';
486        }
487
488        /**
489         * Licence token
490         */
491        public function get_license_token() {
492                $license_token = trailingslashit( site_url() );
493                return $license_token;
494        }
495
496        /**
497         * Licence hash
498         */
499        public function get_license_hash() {
500                $license_token = is_multisite() ? trailingslashit( network_home_url() ) : trailingslashit( site_url() );
501                return $license_token;
502        }
503
504        /**
505         * PHP Cookie Checker, available from version 1.3.0
506         */
507        public function gdpr_get_php_cookies() {
508                $cookies_accepted = array(
509                        'strict'     => false,
510                        'thirdparty' => false,
511                        'advanced'   => false,
512                );
513                if ( isset( $_COOKIE['moove_gdpr_popup'] ) ) :
514                        $cookies         = sanitize_text_field( wp_unslash( $_COOKIE['moove_gdpr_popup'] ) );
515                        $cookies_decoded = json_decode( wp_unslash( $cookies ), true );
516                        if ( $cookies_decoded && is_array( $cookies_decoded ) && ! empty( $cookies_decoded ) ) :
517                                $cookies_accepted = array(
518                                        'strict'     => isset( $cookies_decoded['strict'] ) && intval( $cookies_decoded['strict'] ) === 1 ? true : false,
519                                        'thirdparty' => isset( $cookies_decoded['thirdparty'] ) && intval( $cookies_decoded['thirdparty'] ) === 1 ? true : false,
520                                        'advanced'   => isset( $cookies_decoded['advanced'] ) && intval( $cookies_decoded['advanced'] ) === 1 ? true : false,
521                                );
522                endif;
523        else :
524                $options_name      = $this->moove_gdpr_get_option_name();
525                $gdpr_options      = get_option( $options_name );
526                $wpml_lang_options = $this->moove_gdpr_get_wpml_lang();
527
528                $strictly_functionality = isset( $gdpr_options['moove_gdpr_strictly_necessary_cookies_functionality'] ) && intval( $gdpr_options['moove_gdpr_strictly_necessary_cookies_functionality'] ) ? intval( $gdpr_options['moove_gdpr_strictly_necessary_cookies_functionality'] ) : 1;
529                $thirdparty_default     = isset( $gdpr_options['moove_gdpr_third_party_cookies_enable_first_visit'] ) && intval( $gdpr_options['moove_gdpr_third_party_cookies_enable_first_visit'] ) ? intval( $gdpr_options['moove_gdpr_third_party_cookies_enable_first_visit'] ) : 0;
530                $advanced_default       = isset( $gdpr_options['moove_gdpr_advanced_cookies_enable_first_visit'] ) && intval( $gdpr_options['moove_gdpr_advanced_cookies_enable_first_visit'] ) ? intval( $gdpr_options['moove_gdpr_advanced_cookies_enable_first_visit'] ) : 0;
531
532                if ( 1 === $strictly_functionality ) :
533                        if ( 1 === $thirdparty_default || 1 === $advanced_default ) :
534                                $strict_default = 1;
535                        else :
536                                $strict_default = 0;
537                        endif;
538                else :
539                        $strict_default = 1;
540                endif;
541
542                $cookies_accepted = array(
543                        'strict'     => $strict_default,
544                        'thirdparty' => $thirdparty_default,
545                        'advanced'   => $advanced_default,
546                );
547
548        endif;
549        return $cookies_accepted;
550        }
551
552        /**
553         * GDPR Licence action button
554         *
555         * @param array  $response Response.
556         * @param string $gdpr_key GDPR Key.
557         */
558        public static function gdpr_licence_action_button( $response, $gdpr_key ) {
559                $type = isset( $response['type'] ) ? $response['type'] : false;
560                if ( 'expired' === $type || 'activated' === $type || 'max_activation_reached' === $type ) :
561                        if ( 'activated' !== $type ) :
562                                ?>
563                                <br />
564                                <button type="submit" name="gdpr_activate_license" class="button button-primary button-inverse">
565                                        <?php esc_html_e( 'Activate', 'gdpr-cookie-compliance' ); ?>
566                                </button>
567                                <?php
568                        endif;
569                elseif ( 'invalid' === $type ) :
570                        ?>
571                        <br />
572                        <button type="submit" name="gdpr_activate_license" class="button button-primary button-inverse">
573                                <?php esc_html_e( 'Activate', 'gdpr-cookie-compliance' ); ?>
574                        </button>
575                        <?php
576                else :
577                        ?>
578                        <br />
579                        <button type="submit" name="gdpr_activate_license" class="button button-primary button-inverse">
580                                <?php esc_html_e( 'Activate', 'gdpr-cookie-compliance' ); ?>
581                        </button>
582                        <br /><br />
583                        <hr />
584                        <h4 style="margin-bottom: 0;"><?php esc_html_e( 'Buy licence', 'gdpr-cookie-compliance' ); ?></h4>
585                        <p>
586                                <?php
587                                $store_link = __( 'You can buy licences from our [store_link]online store[/store_link].', 'gdpr-cookie-compliance' );
588                                $store_link = str_replace( '[store_link]', '<a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="gdpr_admin_link">', $store_link );
589                                $store_link = str_replace( '[/store_link]', '</a>', $store_link );
590                                apply_filters( 'gdpr_cc_keephtml', $store_link, true );
591                                ?>
592                        </p>
593                        <p>
594                                <a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="button button-primary">Buy Now</a>
595                        </p>
596                        <br />
597                        <hr />
598                        <?php
599                endif;
600        }
601
602        /**
603         * Licence input key
604         *
605         * @param array  $response Response.
606         * @param string $gdpr_key GDPR Key.
607         */
608        public static function gdpr_licence_input_field( $response, $gdpr_key ) {
609                $type = isset( $response['type'] ) ? $response['type'] : false;
610                if ( 'expired' === $type ) :
611                        // LICENSE EXPIRED.
612                        ?>
613                        <tr>
614                                <th scope="row" style="padding: 0 0 10px 0;">
615                                        <hr />
616                                        <h4 style="margin-bottom: 0;"><?php esc_html_e( 'Renew your licence', 'gdpr-cookie-compliance' ); ?></h4>
617                                        <p><?php esc_html_e( 'Your licence has expired. You will not receive the latest updates and features unless you renew your licence.', 'gdpr-cookie-compliance' ); ?></p>
618                                        <a href="<?php echo esc_attr( MOOVE_SHOP_URL ); ?>?renew=<?php echo esc_attr( $response['key'] ); ?>" target="_blank" class="button button-primary">Renew Licence</a>
619                                        <br /><br />
620                                        <hr />
621
622                                        <h4 style="margin-bottom: 0;"><?php esc_html_e( 'Enter new licence key', 'gdpr-cookie-compliance' ); ?></h4>
623                                </th>
624                        </tr>
625                        <tr>
626                                <td style="padding: 0;">
627                                        <input name="moove_gdpr_license_key" required min="35" type="text" id="moove_gdpr_license_key" value="" class="regular-text">
628                                </td>
629                        </tr>
630                        <?php
631                elseif ( 'activated' === $type || 'max_activation_reached' === $type ) :
632                        // LICENSE ACTIVATED.
633                        ?>
634                        <tr>
635                                <th scope="row" style="padding: 0 0 10px 0;">
636                                        <hr />
637                                        <h4 style="margin-bottom: 0;"><?php esc_html_e( 'Buy more licences', 'gdpr-cookie-compliance' ); ?></h4>
638                                        <p>
639                                                <?php
640                                                $store_link = __( 'You can buy more licences from our [store_link]online store[/store_link].', 'gdpr-cookie-compliance' );
641                                                $store_link = str_replace( '[store_link]', '<a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="gdpr_admin_link">', $store_link );
642                                                $store_link = str_replace( '[/store_link]', '</a>', $store_link );
643                                                apply_filters( 'gdpr_cc_keephtml', $store_link, true );
644                                                ?>
645                                        </p>
646                                        <p>
647                                                <a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="button button-primary">
648                                                        Buy Now
649                                                </a>
650                                        </p>
651                                        <br />
652                                        <hr />
653                                </th>
654                        </tr>
655                        <?php 
656                                if ( 'max_activation_reached' === $type ) : ?>
657                                        <tr>
658                                                <th scope="row" style="padding: 0 0 10px 0;">
659                                                        <label><?php esc_html_e( 'Enter a new licence key:', 'gdpr-cookie-compliance' ); ?></label>
660                                                </th>
661                                        </tr>
662                                        <tr>
663                                                <td style="padding: 0;">
664                                                        <input name="moove_gdpr_license_key" required min="35" type="text" id="moove_gdpr_license_key" value="" class="regular-text">
665                                                </td>
666                                        </tr>
667                                <?php
668                        endif;
669                elseif ( 'invalid' === $type ) :
670                        ?>
671                        <tr>
672                                <th scope="row" style="padding: 0 0 10px 0;">
673                                        <hr />
674                                        <h4 style="margin-bottom: 0;"><?php esc_html_e( 'Buy licence', 'gdpr-cookie-compliance' ); ?></h4>
675                                        <p>
676                                                <?php
677                                                $store_link = __( 'You can buy licences from our [store_link]online store[/store_link].', 'gdpr-cookie-compliance' );
678                                                $store_link = str_replace( '[store_link]', '<a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="gdpr_admin_link">', $store_link );
679                                                $store_link = str_replace( '[/store_link]', '</a>', $store_link );
680                                                apply_filters( 'gdpr_cc_keephtml', $store_link, true );
681                                                ?>
682                                        </p>
683                                        <p>
684                                                <a href="https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/" target="_blank" class="button button-primary">Buy Now</a>
685                                        </p>
686                                        <br />
687                                        <hr />
688                                </th>
689                        </tr>
690                        <tr>
691                                <th scope="row" style="padding: 0 0 10px 0;">
692                                        <label><?php esc_html_e( 'Enter your licence key:', 'gdpr-cookie-compliance' ); ?></label>
693                                </th>
694                        </tr>
695                        <tr>
696                                <td style="padding: 0;">
697                                        <input name="moove_gdpr_license_key" required min="35" type="text" id="moove_gdpr_license_key" value="" class="regular-text">
698                                </td>
699                        </tr>
700                        <?php
701                else :
702                        ?>
703                        <tr>
704                                <th scope="row" style="padding: 0 0 10px 0;">
705                                        <label><?php esc_html_e( 'Enter licence key:', 'gdpr-cookie-compliance' ); ?></label>
706                                </th>
707                        </tr>
708                        <tr>
709                                <td style="padding: 0;">
710                                        <input name="moove_gdpr_license_key" required min="35" type="text" id="moove_gdpr_license_key" value="" class="regular-text">
711                                </td>
712                        </tr>
713                        <?php
714                endif;
715        }
716
717        /**
718         * GDPR Alert Box
719         *
720         * @param string $type Type.
721         * @param array  $response Response.
722         * @param string $gdpr_key GDPR Key.
723         */
724        public static function gdpr_get_alertbox( $type, $response, $gdpr_key ) {
725                if ( 'error' === $type ) :
726                        $messages = isset( $response['message'] ) && is_array( $response['message'] ) ? implode( '</p><p>', $response['message'] ) : '';
727                        if ( isset( $response['type'] ) && ( $response['type'] === 'inactive' || $response['type'] === 'max_activation_reached' || $response['type'] === 'suspended' ) ) :
728                                $gdpr_default_content = new Moove_GDPR_Content();
729                                $option_key           = $gdpr_default_content->moove_gdpr_get_key_name();
730                                $gdpr_key             = $gdpr_default_content->gdpr_get_activation_key( $option_key );
731
732                                update_option(
733                                        $option_key,
734                                        array(
735                                                'key'          => $response['key'],
736                                                'deactivation' => strtotime( 'now' ),
737                                        )
738                                );
739                                $gdpr_key = $gdpr_default_content->gdpr_get_activation_key( $option_key );
740                        endif;
741                        ?>
742                        <div class="gdpr-admin-alert gdpr-admin-alert-error">
743                                <div class="gdpr-alert-content">       
744                                        <div class="gdpr-licence-key-wrap">
745                                                <p><?php esc_html_e( 'License key:', 'gdpr-cookie-compliance' ); ?>:
746                                                <strong><?php echo esc_attr( apply_filters( 'gdpr_licence_key_visibility', isset( $response['key'] ) ? $response['key'] : ( isset( $gdpr_key['key'] ) ? $gdpr_key['key'] : $gdpr_key ) ) ); ?></strong>                                                         
747                                                </p>
748                                        </div>
749                                        <!-- .gdpr-licence-key-wrap -->
750                                        <p><?php apply_filters( 'gdpr_cc_keephtml', $messages, true ); ?></p>
751                                </div>
752                                <span class="dashicons dashicons-dismiss"></span>
753                        </div>
754                        <!--  .gdpr-admin-alert gdpr-admin-alert-success -->
755                        <?php
756                else :
757                        $messages = isset( $response['message'] ) && is_array( $response['message'] ) ? implode( '</p><p>', $response['message'] ) : '';
758                        ?>
759                        <div class="gdpr-admin-alert gdpr-admin-alert-success">   
760                                <div class="gdpr-alert-content">
761                                        <div class="gdpr-licence-key-wrap">
762                                                <p><?php esc_html_e( 'License key:', 'gdpr-cookie-compliance' ); ?>:
763                                                <strong><?php echo esc_attr( apply_filters( 'gdpr_licence_key_visibility', isset( $response['key'] ) ? $response['key'] : ( isset( $gdpr_key['key'] ) ? $gdpr_key['key'] : $gdpr_key ) ) ); ?></strong>                                                         
764                                                </p>
765                                        </div>
766                                        <!-- .gdpr-licence-key-wrap -->                                 
767                                        <p><?php apply_filters( 'gdpr_cc_keephtml', $messages, true ); ?></p>
768                                </div>
769                                <span class="dashicons dashicons-yes-alt"></span>
770                        </div>
771                        <!--  .gdpr-admin-alert gdpr-admin-alert-success -->
772                        <?php
773                endif;
774                do_action( 'gdpr_plugin_updater_notice' );
775        }
776
777        /**
778         * GDPR Update Alert
779         *
780         * @return void
781         */
782        public static function gdpr_premium_update_alert() {
783
784                $plugins     = get_site_transient( 'update_plugins' );
785                $lm          = new Moove_GDPR_License_Manager();
786                $plugin_slug = $lm->get_add_on_plugin_slug();
787
788                if ( isset( $plugins->response[ $plugin_slug ] ) && is_plugin_active( $plugin_slug ) ) :
789                        $version = $plugins->response[ $plugin_slug ]->new_version;
790
791                        $current_user = wp_get_current_user();
792                        $user_id      = isset( $current_user->ID ) ? $current_user->ID : 0;
793                        $dismiss      = get_option( 'gdpr_hide_update_notice_' . $user_id );
794
795                        if ( isset( $plugins->response[ $plugin_slug ]->package ) && ! $plugins->response[ $plugin_slug ]->package ) :
796                                $gdpr_default_content = new Moove_GDPR_Content();
797                                $option_key           = $gdpr_default_content->moove_gdpr_get_key_name();
798                                $gdpr_key             = $gdpr_default_content->gdpr_get_activation_key( $option_key );
799                                $license_key          = isset( $gdpr_key['key'] ) ? sanitize_text_field( $gdpr_key['key'] ) : false;
800                                $renew_link           = MOOVE_SHOP_URL . '?renew=' . $license_key;
801                                $license_manager      = admin_url( 'admin.php' ) . '?page=moove-gdpr_licence';
802                                $purchase_link        = 'https://www.mooveagency.com/wordpress-plugins/gdpr-cookie-compliance/';
803                                $notice_text          = '';
804                                if ( $license_key && isset( $gdpr_key['activation'] ) ) :
805                                        // Expired.
806                                        $notice_text = 'Update is not available until you <a href="' . $renew_link . '" target="_blank">renew your licence</a>. You can also update your licence key in the <a href="' . $license_manager . '">Licence Manager</a>.';
807                                elseif ( $license_key && isset( $gdpr_key['deactivation'] ) ) :
808                                        // Deactivated.
809                                        $notice_text = 'Update is not available until you <a href="' . $purchase_link . '" target="_blank">purchase a licence</a>. You can also update your licence key in the <a href="' . $license_manager . '">Licence Manager</a>.';
810                                elseif ( ! $license_key ) :
811                                        // No license key installed.
812                                        $notice_text = 'Update is not available until you <a href="' . $purchase_link . '" target="_blank">purchase a licence</a>. You can also update your licence key in the <a href="' . $license_manager . '">Licence Manager</a>.';
813                                endif;
814                                ?>
815                        <div class="gdpr-cookie-alert gdpr-cookie-update-alert" style="display: inline-block;">
816                                <h4>
817                                        <?php esc_html_e( 'There is a new version of GDPR Cookie Compliance - Premium Add-On.', 'gdpr-cookie-compliance' ); ?></h4>
818                                <p><?php apply_filters( 'gdpr_cc_keephtml', $notice_text, true ); ?></p>
819                        </div>
820                        <!--  .gdpr-cookie-alert -->
821                                <?php
822                endif;
823        endif;
824        }
825
826        /**
827         * Licence Action Buttons
828         */
829        public static function gdpr_cc_licence_manager_action_button( $show_title = true ) {
830                if ( function_exists('is_multisite') && is_multisite() ) :
831                        $is_bulk_view   = isset( $_GET['view'] );
832                        $button_view            = $is_bulk_view ? '' : '&view=bulk';
833                        ?>
834                        <div class="gdpr-multisite-bal">
835                                <?php if ( $show_title ) : ?>
836                                        <h3><?php esc_html_e( 'Bulk Multisite Activation', 'gdpr-cookie-compliance' ); ?></h3>
837                                        <p><?php esc_html_e( 'You can activate the Licence Key on all your subsites using the tool below.', 'gdpr-cookie-compliance' ); ?></p>
838                                        <a href="<?php echo esc_url( admin_url( 'admin.php?page=moove-gdpr_licence&tab=licence' . $button_view ) ); ?>" class="button button-primary button-inverse">
839                                                <?php 
840                                                        if ( ! $is_bulk_view ) : 
841                                                                esc_html_e( 'Bulk Licence Activation', 'gdpr-cookie-compliance' );
842                                                        else :
843                                                                esc_html_e( 'Single Activation', 'gdpr-cookie-compliance' );
844                                                        endif;
845                                                ?>
846                                        </a>
847                                <?php elseif ( $is_bulk_view ) : ?>
848                                        <a href="<?php echo esc_url( admin_url( 'admin.php?page=moove-gdpr_licence&tab=licence' . $button_view ) ); ?>" class="button button-primary button-inverse">
849                                                <?php esc_html_e( 'Single Activation', 'gdpr-cookie-compliance' ); ?>
850                                        </a>
851                                <?php endif; ?>
852
853                        </div>
854                        <!-- .gdpr-multisite-bal -->
855                        <?php
856                endif;
857        }
858}
859new Moove_GDPR_Content();
Note: See TracBrowser for help on using the repository browser.