PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.6.6
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.6.6
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 6 years ago js 7 years ago lib 6 years ago style 7 years ago tests 6 years ago view 6 years ago .travis.yml 7 years ago addons.json 6 years ago composer.json 6 years ago composer.lock 6 years ago cookiebot-addons-init.php 6 years ago
cookiebot-addons-init.php
219 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', '3.6.6' );
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( '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
188 /**
189 * Assign addon class to the container to use it later
190 *
191 * @throws DI\DependencyException
192 * @throws DI\NotFoundException
193 *
194 * @since 1.3.0
195 */
196 protected function assign_addons_to_container() {
197 /**
198 * Check plugins one by one and load addon configuration
199 */
200 foreach ( $this->plugins as $plugin_class => $plugin ) {
201 /**
202 * Load addon class to the container
203 */
204 $this->container->set( $plugin->class, \DI\object( $plugin->class )
205 ->constructor(
206 $this->container->get( 'Settings_Service_Interface' ),
207 $this->container->get( 'Script_Loader_Tag_Interface' ),
208 $this->container->get( 'Cookie_Consent_Interface' ),
209 $this->container->get( 'Buffer_Output_Interface' ) )
210 );
211 }
212 }
213 }
214
215 /**
216 * Initiate the cookiebot addons framework plugin
217 */
218 Cookiebot_Addons::instance();
219