| 1 |
<?php |
| 2 |
|
| 3 |
namespace cybot\cookiebot\addons\controller; |
| 4 |
|
| 5 |
use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon; |
| 6 |
use cybot\cookiebot\lib\buffer\Buffer_Output_Interface; |
| 7 |
use cybot\cookiebot\lib\Settings_Service_Interface; |
| 8 |
use cybot\cookiebot\lib\Cookiebot_WP; |
| 9 |
use Exception; |
| 10 |
use function cybot\cookiebot\lib\cookiebot_addons_enabled_cache_plugin; |
| 11 |
use function cybot\cookiebot\lib\cookiebot_active; |
| 12 |
|
| 13 |
class Plugin_Controller { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
/** |
| 18 |
* @var Settings_Service_Interface |
| 19 |
*/ |
| 20 |
private $settings_service; |
| 21 |
|
| 22 |
/** |
| 23 |
* @param Settings_Service_Interface $settings_service |
| 24 |
*/ |
| 25 |
public function __construct( Settings_Service_Interface $settings_service ) { |
| 26 |
$this->settings_service = $settings_service; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @throws Exception |
| 31 |
*/ |
| 32 |
public function load_active_addons() { |
| 33 |
if ( ! cookiebot_active() ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Add notice for the user if any addons is enabled and cookie |
| 39 |
* blocking mode is set to auto. |
| 40 |
*/ |
| 41 |
if ( count( $this->settings_service->get_active_addons() ) > 0 && |
| 42 |
Cookiebot_WP::get_cookie_blocking_mode() === 'auto' && |
| 43 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 44 |
isset( $_GET['page'] ) && |
| 45 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 46 |
in_array( $_GET['page'], array( 'cookiebot', 'cookiebot-addons' ), true ) ) { |
| 47 |
add_action( |
| 48 |
'admin_notices', |
| 49 |
function () { |
| 50 |
echo '<div class="notice notice-warning"><p><strong>' . |
| 51 |
esc_html__( |
| 52 |
'You enabled Cookiebot™ auto blocking mode but still using addons', |
| 53 |
'cookiebot' |
| 54 |
) . |
| 55 |
'</strong><br>' . |
| 56 |
esc_html__( |
| 57 |
'In some occasions this may cause client side errors. If you notice any errors please try to disable Cookiebot™ addons or contact Cookiebot™ support.', |
| 58 |
'cookiebot' |
| 59 |
) . |
| 60 |
'</p></div>'; |
| 61 |
} |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
if ( Cookiebot_WP::cookiebot_disabled_in_admin() === true && is_admin() ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
$addons_enabled_counter = 0; |
| 70 |
/** @var Base_Cookiebot_Addon $addon */ |
| 71 |
foreach ( $this->settings_service->get_active_addons() as $addon ) { |
| 72 |
if ( ! $addon->cookie_consent->are_cookie_states_accepted( $addon->get_cookie_types() ) |
| 73 |
|| cookiebot_addons_enabled_cache_plugin() ) { |
| 74 |
$addon->load_addon_configuration(); |
| 75 |
++$addons_enabled_counter; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* After WordPress is fully loaded |
| 81 |
* |
| 82 |
* Run buffer output actions - this runs after scanning of every addons |
| 83 |
*/ |
| 84 |
add_action( 'parse_request', array( $this, 'run_buffer_output_manipulations' ) ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Runs every added action hooks to manipulate script tag |
| 89 |
* |
| 90 |
* @throws Exception |
| 91 |
* @since 1.3.0 |
| 92 |
*/ |
| 93 |
public function run_buffer_output_manipulations() { |
| 94 |
/** |
| 95 |
* @var $buffer_output Buffer_Output_Interface |
| 96 |
*/ |
| 97 |
$buffer_output = $this->settings_service->container->get( 'Buffer_Output_Interface' ); |
| 98 |
|
| 99 |
if ( $buffer_output->has_action() ) { |
| 100 |
$buffer_output->run_actions(); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|