PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.10.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.10.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 / cookiebot-addons-init.php

cookiebot-addons-init.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 3.10.0, at addons/cookiebot-addons-init.php

224 lines 5.3 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;
4
5 use cookiebot_addons\config\Settings_Config;
6 use cookiebot_addons\controller\Plugin_Controller;
7 use cookiebot_addons\lib\Settings_Service_Interface;
8 use Cybot\Dependencies\DI\ContainerBuilder;
9 use Cybot\Dependencies\DI;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 } // Exit if accessed directly
14
15
16 /**
17 * __DIR__ of this plugin
18 */
19 define( 'COOKIEBOT_ADDONS_DIR', __DIR__ . DIRECTORY_SEPARATOR );
20
21 define( 'COOKIEBOT_ADDONS_BASE_NAME', dirname( plugin_basename( __FILE__ ) ) );
22
23 /**
24 * Same version as the CookiebotWP
25 */
26 define( 'COOKIEBOT_ADDONS_VERSION', '3.9.0' );
27
28 /**
29 * Register autoloader to load files/classes dynamically
30 */
31 include_once COOKIEBOT_ADDONS_DIR . 'lib/autoloader.php';
32
33 /**
34 * Load global functions for this plugin
35 */
36 include_once COOKIEBOT_ADDONS_DIR . 'lib/helper.php';
37
38 /**
39 * Load composer
40 *
41 * "php-di/php-di": "5.0"
42 */
43 include_once COOKIEBOT_ADDONS_DIR . 'vendor/autoload.php';
44
45 class Cookiebot_Addons {
46
47 /**
48 * IoC Container - is used for dependency injections
49 *
50 * @var DI\Container
51 *
52 * @since 1.3.0
53 */
54 public $container;
55
56 /**
57 * List of all supported addons
58 *
59 * @var object
60 *
61 * @since 1.3.0
62 */
63 public $plugins;
64
65 /**
66 * @var Cookiebot_Addons The single instance of the class
67 * @since 1.0.0
68 */
69 protected static $_instance = null;
70
71 /**
72 * Main Cookiebot_WP Instance
73 *
74 * Ensures only one instance of Cookiebot_Addons is loaded or can be loaded.
75 *
76 * @version 2.2.0
77 * @since 2.2.0
78 * @static
79 *
80 * @return Cookiebot_Addons
81 */
82 public static function instance() {
83 if ( is_null( self::$_instance ) ) {
84 try {
85 self::$_instance = new self();
86 } catch ( DI\DependencyException $e ) {
87 echo 'Dependencies are not loaded.';
88 } catch ( DI\NotFoundException $e ) {
89 echo 'Dependencies are not found.';
90 }
91 }
92
93 return self::$_instance;
94 }
95
96 /**
97 * Cookiebot_Addons constructor.
98 *
99 * @throws DI\DependencyException
100 * @throws DI\NotFoundException
101 *
102 * @since 1.3.0
103 */
104 public function __construct() {
105 $this->get_plugins();
106 $this->build_container();
107 $this->assign_addons_to_container();
108
109 /**
110 * Load plugin controller to check if addons are active
111 * If active then load the plugin addon configuration class
112 * Else skip it
113 *
114 * @since 1.1.0
115 */
116 add_action( 'after_setup_theme', array(
117 new Plugin_Controller( $this->container->get( 'Settings_Service_Interface' ) ),
118 'load_active_addons',
119 ) );
120 /**
121 * Load settings config
122 *
123 * @since 1.1.0
124 */
125 $settings = new Settings_Config( $this->container->get( 'Settings_Service_Interface' ) );
126 $settings->load();
127 }
128
129 /**
130 * if the cookiebot is activated
131 * run this script to start up
132 *
133 * @since 2.2.0
134 */
135 public function cookiebot_activated() {
136 $settings_service = $this->container->get( 'Settings_Service_Interface' );
137 $settings_service->cookiebot_activated();
138 }
139
140 /**
141 * if the cookiebot is deactivated
142 * run this script to clean up addons.
143 *
144 * @since 2.2.0
145 */
146 public function cookiebot_deactivated() {
147 $settings_service = $this->container->get( 'Settings_Service_Interface' );
148 $settings_service->cookiebot_deactivated();
149 }
150
151 /**
152 * Loads plugins from json file
153 *
154 * All the addon plugins are defined there.
155 *
156 * The file is located at the root map of this plugin
157 *
158 * @since 1.3.0
159 */
160 protected function get_plugins() {
161 $file = file_get_contents( COOKIEBOT_ADDONS_DIR . 'addons.json' );
162 $this->plugins = apply_filters( 'cookiebot_addons_list', json_decode( $file ) );
163 }
164
165 /**
166 * Build IoC container
167 *
168 * @since 1.3.0
169 */
170 protected function build_container() {
171 $builder = new ContainerBuilder();
172
173 $builder->addDefinitions(
174 array(
175 'Script_Loader_Tag_Interface' => DI\object( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag' ),
176 'Cookie_Consent_Interface' => DI\object( 'cookiebot_addons\lib\Cookie_Consent' ),
177 'Buffer_Output_Interface' => DI\object( 'cookiebot_addons\lib\buffer\Buffer_Output' ),
178 'plugins' => DI\value( $this->plugins ),
179 )
180 );
181
182 $this->container = $builder->build();
183
184 $this->container->set( 'Settings_Service_Interface', DI\object( 'cookiebot_addons\lib\Settings_Service' )
185 ->constructor( $this->container ) );
186
187 $this->container->set( 'Theme_Settings_Service_Interface', DI\object( 'cookiebot_addons\lib\Theme_Settings_Service' )
188 ->constructor( $this->container ) );
189 }
190
191 /**
192 * Assign addon class to the container to use it later
193 *
194 * @throws DI\DependencyException
195 * @throws DI\NotFoundException
196 *
197 * @since 1.3.0
198 */
199 protected function assign_addons_to_container() {
200 /**
201 * Check plugins one by one and load addon configuration
202 */
203 foreach ( $this->plugins as $plugin_class => $plugin ) {
204 /**
205 * Load addon class to the container
206 */
207 $this->container->set( $plugin->class, DI\object( $plugin->class )
208 ->constructor(
209 isset( $plugin->is_theme ) && $plugin->is_theme
210 ? $this->container->get( 'Theme_Settings_Service_Interface' )
211 : $this->container->get( 'Settings_Service_Interface' ),
212 $this->container->get( 'Script_Loader_Tag_Interface' ),
213 $this->container->get( 'Cookie_Consent_Interface' ),
214 $this->container->get( 'Buffer_Output_Interface' ) )
215 );
216 }
217 }
218 }
219
220 /**
221 * Initiate the cookiebot addons framework plugin
222 */
223 Cookiebot_Addons::instance();
224