PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 2.4.1
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v2.4.1
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 / cookiebot-addons-init.php
cookiebot / addons Last commit date
bin 7 years ago config 7 years ago controller 7 years ago js 7 years ago lib 7 years ago style 7 years ago tests 7 years ago view 7 years ago .travis.yml 7 years ago addons.json 7 years ago composer.json 7 years ago composer.lock 7 years ago cookiebot-addons-init.php 7 years ago
cookiebot-addons-init.php
209 lines
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 DI\ContainerBuilder;
9 use 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', '2.4.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 . 'lib/ioc/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( 'plugins_loaded', array(
117 new Plugin_Controller( $this->container->get( 'Settings_Service_Interface' ) ),
118 'load_active_addons'
119 ) );
120
121 /**
122 * Load settings config
123 *
124 * @since 1.1.0
125 */
126 $settings = new Settings_Config( $this->container->get( 'Settings_Service_Interface' ) );
127 $settings->load();
128 }
129
130 /**
131 * if the cookiebot is deactivated
132 * run this script to clean up addons.
133 *
134 * @since 2.2.0
135 */
136 public function cookiebot_deactivated() {
137 $settings_service = $this->container->get( 'Settings_Service_Interface' );
138 $settings_service->cookiebot_deactivated();
139 }
140
141 /**
142 * Loads plugins from json file
143 *
144 * All the addon plugins are defined there.
145 *
146 * The file is located at the root map of this plugin
147 *
148 * @since 1.3.0
149 */
150 protected function get_plugins() {
151 $file = file_get_contents( COOKIEBOT_ADDONS_DIR . 'addons.json' );
152 $this->plugins = json_decode( $file );
153 }
154
155 /**
156 * Build IoC container
157 *
158 * @since 1.3.0
159 */
160 protected function build_container() {
161 $builder = new ContainerBuilder();
162
163 $builder->addDefinitions(
164 array(
165 'Script_Loader_Tag_Interface' => DI\object( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag' ),
166 'Cookie_Consent_Interface' => DI\object( 'cookiebot_addons\lib\Cookie_Consent' ),
167 'Buffer_Output_Interface' => DI\object( 'cookiebot_addons\lib\buffer\Buffer_Output' ),
168 'plugins' => DI\value( $this->plugins )
169 )
170 );
171
172 $this->container = $builder->build();
173
174 $this->container->set( 'Settings_Service_Interface', DI\object( 'cookiebot_addons\lib\Settings_Service' )
175 ->constructor( $this->container ) );
176 }
177
178 /**
179 * Assign addon class to the container to use it later
180 *
181 * @throws DI\DependencyException
182 * @throws DI\NotFoundException
183 *
184 * @since 1.3.0
185 */
186 protected function assign_addons_to_container() {
187 /**
188 * Check plugins one by one and load addon configuration
189 */
190 foreach ( $this->plugins as $plugin_class => $plugin ) {
191 /**
192 * Load addon class to the container
193 */
194 $this->container->set( $plugin->class, \DI\object( $plugin->class )
195 ->constructor(
196 $this->container->get( 'Settings_Service_Interface' ),
197 $this->container->get( 'Script_Loader_Tag_Interface' ),
198 $this->container->get( 'Cookie_Consent_Interface' ),
199 $this->container->get( 'Buffer_Output_Interface' ) )
200 );
201 }
202 }
203 }
204
205 /**
206 * Initiate the cookiebot addons framework plugin
207 */
208 Cookiebot_Addons::instance();
209