buffer
3 years ago
script_loader_tag
2 years ago
traits
3 years ago
Consent_API_Helper.php
2 years ago
Cookie_Consent.php
3 years ago
Cookie_Consent_Interface.php
4 years ago
Cookiebot_Activated.php
2 years ago
Cookiebot_Admin_Links.php
1 year ago
Cookiebot_Automatic_Updates.php
3 years ago
Cookiebot_Deactivated.php
4 years ago
Cookiebot_Javascript_Helper.php
1 year ago
Cookiebot_Review.php
1 year ago
Cookiebot_WP.php
1 year ago
Dependency_Container.php
3 years ago
Settings_Page_Tab.php
3 years ago
Settings_Service.php
3 years ago
Settings_Service_Interface.php
3 years ago
Supported_Languages.php
4 years ago
Supported_Regions.php
2 years ago
WP_Rocket_Helper.php
3 years ago
Widgets.php
3 years ago
global-deprecations.php
3 years ago
helper.php
2 years ago
Cookiebot_WP.php
257 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use cybot\cookiebot\addons\Cookiebot_Addons; |
| 6 | use cybot\cookiebot\admin_notices\Cookiebot_Notices; |
| 7 | use cybot\cookiebot\gutenberg\Cookiebot_Gutenberg_Declaration_Block; |
| 8 | use cybot\cookiebot\settings\Menu_Settings; |
| 9 | use cybot\cookiebot\settings\Network_Menu_Settings; |
| 10 | use cybot\cookiebot\widgets\Dashboard_Widget_Cookiebot_Status; |
| 11 | use DomainException; |
| 12 | use RuntimeException; |
| 13 | |
| 14 | class Cookiebot_WP { |
| 15 | const COOKIEBOT_PLUGIN_VERSION = '4.3.12'; |
| 16 | const COOKIEBOT_MIN_PHP_VERSION = '5.6.0'; |
| 17 | |
| 18 | /** |
| 19 | * @var Cookiebot_WP The single instance of the class |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | private static $instance = null; |
| 23 | |
| 24 | /** |
| 25 | * Main Cookiebot_WP Instance |
| 26 | * |
| 27 | * Ensures only one instance of Cookiebot_WP is loaded or can be loaded. |
| 28 | * |
| 29 | * @return Cookiebot_WP - Main instance |
| 30 | * @throws RuntimeException |
| 31 | * @version 1.0.0 |
| 32 | * @since 1.0.0 |
| 33 | * @static |
| 34 | */ |
| 35 | public static function instance() { |
| 36 | if ( is_null( self::$instance ) ) { |
| 37 | self::$instance = new self(); |
| 38 | } |
| 39 | |
| 40 | return self::$instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Cookiebot_WP Constructor. |
| 45 | * |
| 46 | * @throws RuntimeException |
| 47 | * @since 1.0.0 |
| 48 | * @access public |
| 49 | * @version 2.1.4 |
| 50 | */ |
| 51 | public function __construct() { |
| 52 | $this->throw_exception_if_php_version_is_incompatible(); |
| 53 | $this->cookiebot_init(); |
| 54 | register_activation_hook( __FILE__, array( new Cookiebot_Activated(), 'run' ) ); |
| 55 | register_deactivation_hook( __FILE__, array( new Cookiebot_Deactivated(), 'run' ) ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @throws RuntimeException |
| 60 | */ |
| 61 | private function throw_exception_if_php_version_is_incompatible() { |
| 62 | if ( version_compare( PHP_VERSION, self::COOKIEBOT_MIN_PHP_VERSION, '<' ) ) { |
| 63 | $message = sprintf( |
| 64 | // translators: The placeholder is for the COOKIEBOT_MIN_PHP_VERSION constant |
| 65 | __( 'The Cookiebot plugin requires PHP version %s or greater.', 'cookiebot' ), |
| 66 | self::COOKIEBOT_MIN_PHP_VERSION |
| 67 | ); |
| 68 | throw new DomainException( $message ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | public function cookiebot_init() { |
| 73 | Cookiebot_Addons::instance(); |
| 74 | add_action( 'init', array( $this, 'cookiebot_load_textdomain' ) ); |
| 75 | |
| 76 | if ( is_admin() ) { |
| 77 | ( new Menu_Settings() )->add_menu(); |
| 78 | if ( is_multisite() && is_plugin_active_for_network( 'cookiebot/cookiebot.php' ) ) { |
| 79 | ( new Network_Menu_Settings() )->add_menu(); |
| 80 | } |
| 81 | ( new Dashboard_Widget_Cookiebot_Status() )->register_hooks(); |
| 82 | ( new Cookiebot_Notices() )->register_hooks(); |
| 83 | ( new Cookiebot_Review() )->register_hooks(); |
| 84 | } |
| 85 | |
| 86 | ( new Consent_API_Helper() )->register_hooks(); |
| 87 | ( new Cookiebot_Javascript_Helper() )->register_hooks(); |
| 88 | ( new Cookiebot_Automatic_Updates() )->register_hooks(); |
| 89 | ( new Widgets() )->register_hooks(); |
| 90 | ( new Cookiebot_Gutenberg_Declaration_Block() )->register_hooks(); |
| 91 | ( new WP_Rocket_Helper() )->register_hooks(); |
| 92 | |
| 93 | $this->set_default_options(); |
| 94 | ( new Cookiebot_Admin_Links() )->register_hooks(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns true if an user is logged in and has an edit_themes capability |
| 99 | * |
| 100 | * @return bool |
| 101 | * |
| 102 | * @since 3.3.1 |
| 103 | * @version 3.4.1 |
| 104 | */ |
| 105 | public static function can_current_user_edit_theme() { |
| 106 | if ( is_user_logged_in() && |
| 107 | ( |
| 108 | current_user_can( 'edit_themes' ) || |
| 109 | current_user_can( 'edit_pages' ) || |
| 110 | current_user_can( 'edit_posts' ) |
| 111 | ) |
| 112 | ) { |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Loads translations textdomain |
| 121 | * |
| 122 | * @return void |
| 123 | */ |
| 124 | public function cookiebot_load_textdomain() { |
| 125 | load_textdomain( |
| 126 | 'cookiebot', |
| 127 | CYBOT_COOKIEBOT_PLUGIN_DIR . 'langs/cookiebot-' . get_locale() . '.mo' |
| 128 | ); |
| 129 | load_plugin_textdomain( 'cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs' ); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @return string |
| 134 | */ |
| 135 | public static function get_cbid() { |
| 136 | $network_setting = (string) get_site_option( 'cookiebot-cbid', '' ); |
| 137 | $setting = (string) get_option( 'cookiebot-cbid', $network_setting ); |
| 138 | |
| 139 | return empty( $setting ) ? $network_setting : $setting; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @return string |
| 144 | */ |
| 145 | public static function get_cookie_blocking_mode() { |
| 146 | $allowed_modes = array( 'auto', 'manual' ); |
| 147 | $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' ); |
| 148 | $setting = $network_setting === 'manual' ? |
| 149 | (string) get_option( 'cookiebot-cookie-blocking-mode', $network_setting ) : |
| 150 | $network_setting; |
| 151 | |
| 152 | return in_array( $setting, $allowed_modes, true ) ? $setting : 'manual'; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @return bool |
| 157 | */ |
| 158 | public static function check_network_auto_blocking_mode() { |
| 159 | $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode' ); |
| 160 | |
| 161 | return $network_setting === 'auto' ? true : false; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @return string |
| 166 | */ |
| 167 | public static function get_cookie_categories_status() { |
| 168 | return self::get_cookie_blocking_mode() === 'auto' ? 'disabled' : ''; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @return bool |
| 173 | */ |
| 174 | public static function is_cookie_category_selected( $option, $category ) { |
| 175 | $categories = get_option( $option ); |
| 176 | if ( ! $categories || ! is_array( $categories ) ) { |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | return in_array( $category, $categories, true ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Cookiebot_WP Check if Cookiebot is active in admin |
| 185 | * |
| 186 | * @version 4.2.8 |
| 187 | * @since 3.1.0 |
| 188 | */ |
| 189 | public static function cookiebot_disabled_in_admin() { |
| 190 | if ( ( is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) || |
| 191 | ( ! is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) || |
| 192 | ( ! is_network_admin() && get_option( 'cookiebot-nooutput-admin', false ) ) ) { |
| 193 | return true; |
| 194 | } |
| 195 | |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Cookiebot_WP Set default options |
| 201 | * |
| 202 | * @version 4.2.5 |
| 203 | * @since 4.2.5 |
| 204 | */ |
| 205 | private function set_default_options() { |
| 206 | $options = array( |
| 207 | 'cookiebot-nooutput-admin' => '1', |
| 208 | 'cookiebot-gcm' => '1', |
| 209 | ); |
| 210 | |
| 211 | foreach ( $options as $option => $default ) { |
| 212 | if ( get_option( $option ) === false && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) { |
| 213 | update_option( $option, $default ); |
| 214 | } |
| 215 | |
| 216 | if ( ( get_option( $option ) || get_option( $option ) !== false ) && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) { |
| 217 | update_option( $option . self::OPTION_FIRST_RUN_SUFFIX, '1' ); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | self::set_tcf_version(); |
| 222 | } |
| 223 | |
| 224 | private static function set_tcf_version() { |
| 225 | $iab_version = get_option( 'cookiebot-tcf-version' ); |
| 226 | if ( empty( $iab_version ) || $iab_version === 'IAB' ) { |
| 227 | update_option( 'cookiebot-tcf-version', 'TCFv2.2' ); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | public function set_settings_action_link( $actions ) { |
| 232 | $cblinks = array( |
| 233 | '<a href="' . esc_url( add_query_arg( 'page', 'cookiebot', admin_url( 'admin.php' ) ) ) . '">' . esc_html__( 'Dashboard', 'cookiebot' ) . '</a>', |
| 234 | ); |
| 235 | $actions = array_merge( $actions, $cblinks ); |
| 236 | return $actions; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @return string |
| 241 | */ |
| 242 | public static function get_manager_language() { |
| 243 | $locale = get_locale(); |
| 244 | $supported_langs = array( |
| 245 | 'de_DE' => 'de', |
| 246 | 'da_DK' => 'da', |
| 247 | 'fr_FR' => 'fr', |
| 248 | 'it_IT' => 'it', |
| 249 | 'es_ES' => 'es', |
| 250 | ); |
| 251 | |
| 252 | return array_key_exists( $locale, $supported_langs ) ? $supported_langs[ $locale ] : esc_html( 'en' ); |
| 253 | } |
| 254 | |
| 255 | const OPTION_FIRST_RUN_SUFFIX = '-first-run'; |
| 256 | } |
| 257 |