PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.11.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.11.2
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 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / addons / lib / buffer / buffer-output-tag.php
cookiebot / addons / lib / buffer Last commit date
buffer-output-interface.php 7 years ago buffer-output-tag-interface.php 7 years ago buffer-output-tag.php 4 years ago buffer-output.php 4 years ago
buffer-output-tag.php
148 lines
1 <?php
2
3 namespace cookiebot_addons\lib\buffer;
4
5 class Buffer_Output_Tag implements Buffer_Output_Tag_Interface {
6
7 /**
8 * Hook priority
9 *
10 * @var integer
11 *
12 * @since 1.1.0
13 */
14 public $priority;
15
16 /**
17 * Hook tag name
18 *
19 * @var string
20 *
21 * @since 1.2.0
22 */
23 public $tag;
24
25 /**
26 * Keywords to allow in the scripts
27 *
28 * @var array array
29 *
30 * @since 1.2.0
31 */
32 private $keywords;
33
34 /**
35 * Transient unique name
36 *
37 * @var string
38 *
39 * @since 1.1.0
40 */
41 private $transient_name;
42
43 /**
44 *
45 * Use transient cache
46 *
47 * @var boolean
48 *
49 * @since 1.2.0
50 */
51 private $use_cache;
52
53 /**
54 * Cookiebot_Buffer_Output_Tag constructor.
55 *
56 * @param $tag
57 * @param $priority
58 * @param array $keywords
59 * @param boolean $use_cache
60 *
61 * @since 1.2.0
62 */
63 public function __construct( $tag, $priority, $keywords = array(), $use_cache = true ) {
64 $this->tag = $tag;
65 $this->priority = $priority;
66 $this->keywords = $keywords;
67
68 $this->transient_name = "cookiebot_output_buffer_{$tag}_{$priority}";
69
70 $this->set_use_cache( $use_cache );
71 }
72
73 /**
74 * Merges new keywords in existence keywords variable
75 *
76 * @param $keywords
77 *
78 * @since 1.2.0
79 */
80 public function merge_keywords( $keywords ) {
81 $this->keywords = array_merge( $this->keywords, $keywords );
82 }
83
84 /**
85 * Set use cache
86 *
87 * @param $use_cache
88 */
89 public function set_use_cache( $use_cache ) {
90 $this->use_cache = $use_cache;
91 }
92
93 /**
94 * Start reading the buffer/output
95 *
96 * @since 1.1.0
97 */
98 public function cookiebot_start_buffer() {
99 ob_start( array( $this, 'manipulate_script' ) );
100 }
101
102 /**
103 * Stop reading the output and output buffered data through manipulate script filter.
104 *
105 * @since 1.1.0
106 */
107 public function cookiebot_stop_buffer() {
108 ob_end_flush();
109 }
110
111 /**
112 * Manipulate google analytic scripts to cookiebot and return it back
113 *
114 * @param $buffer
115 *
116 * @return null|string|string[]
117 *
118 * @since 1.1.0
119 */
120 public function manipulate_script( $buffer ) {
121 /**
122 * Get wp head scripts from the cache
123 */
124 if ( $this->use_cache ) {
125 $updated_scripts = get_transient( $this->transient_name );
126 }
127
128 /**
129 * If cache is not set then build it
130 */
131 if ( ! $this->use_cache || $updated_scripts === false ) {
132 /**
133 * Get all scripts and add cookieconsent if it does match with the criterion
134 */
135 $updated_scripts = cookiebot_addons_manipulate_script( $buffer, $this->keywords );
136
137 if ( $this->use_cache ) {
138 /**
139 * Set cache for 15 minutes
140 */
141 set_transient( $this->transient_name, $updated_scripts, 60 * 15 );
142 }
143 }
144
145 return $updated_scripts;
146 }
147 }
148