| 1 |
<?php |
| 2 |
|
| 3 |
namespace cybot\cookiebot\settings\templates; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use function cybot\cookiebot\lib\include_view; |
| 7 |
|
| 8 |
class Legacy_Settings { |
| 9 |
|
| 10 |
|
| 11 |
private $options = array( |
| 12 |
'cookiebot-ruleset-id', |
| 13 |
'cookiebot-language', |
| 14 |
'cookiebot-front-language', |
| 15 |
'cookiebot-nooutput', |
| 16 |
'cookiebot-nooutput-admin', |
| 17 |
'cookiebot-output-logged-in', |
| 18 |
'cookiebot-ignore-scripts', |
| 19 |
'cookiebot-autoupdate', |
| 20 |
'cookiebot-script-tag-uc-attribute', |
| 21 |
'cookiebot-script-tag-cd-attribute', |
| 22 |
'cookiebot-cookie-blocking-mode', |
| 23 |
'cookiebot-iab', |
| 24 |
'cookiebot-tcf-version', |
| 25 |
'cookiebot-banner-enabled', |
| 26 |
'cookiebot-tcf-purposes', |
| 27 |
'cookiebot-tcf-special-purposes', |
| 28 |
'cookiebot-tcf-features', |
| 29 |
'cookiebot-tcf-special-features', |
| 30 |
'cookiebot-tcf-vendors', |
| 31 |
'cookiebot-tcf-disallowed', |
| 32 |
'cookiebot-tcf-ac-vendors', |
| 33 |
'cookiebot-ccpa', |
| 34 |
'cookiebot-ccpa-domain-group-id', |
| 35 |
'cookiebot-gtm', |
| 36 |
'cookiebot-gtm-id', |
| 37 |
'cookiebot-gtm-cookies', |
| 38 |
'cookiebot-data-layer', |
| 39 |
'cookiebot-gcm', |
| 40 |
'cookiebot-gcm-first-run', |
| 41 |
'cookiebot-gcm-url-passthrough', |
| 42 |
'cookiebot-gcm-cookies', |
| 43 |
'cookiebot-multiple-config', |
| 44 |
'cookiebot-second-banner-regions', |
| 45 |
'cookiebot-second-banner-id', |
| 46 |
'cookiebot-multiple-banners', |
| 47 |
); |
| 48 |
|
| 49 |
/** |
| 50 |
* @throws InvalidArgumentException |
| 51 |
*/ |
| 52 |
public function display() { |
| 53 |
$args = $this->get_all_legacy_options(); |
| 54 |
|
| 55 |
include_view( 'admin/common/templates/legacy.php', array( 'options' => $args ) ); |
| 56 |
} |
| 57 |
|
| 58 |
private function get_all_legacy_options() { |
| 59 |
$options = array(); |
| 60 |
foreach ( $this->options as $option ) { |
| 61 |
$option_value = get_option( $option ); |
| 62 |
if ( ! empty( $option_value ) ) { |
| 63 |
$options[ $option ] = $option_value; |
| 64 |
} |
| 65 |
} |
| 66 |
return $options; |
| 67 |
} |
| 68 |
|
| 69 |
public static function get_legacy_option( $option, $value ) { |
| 70 |
if ( is_array( $value ) ) { |
| 71 |
if ( $option === 'cookiebot-tcf-disallowed' ) { |
| 72 |
return self::get_tcf_disallowed_legacy( $value ); |
| 73 |
} elseif ( $option === 'cookiebot-multiple-banners' ) { |
| 74 |
return self::get_multiple_banners_legacy( $value ); |
| 75 |
} else { |
| 76 |
$html = ''; |
| 77 |
foreach ( $value as $key => $value ) { |
| 78 |
$html .= '<input type="hidden" value="' . $value . '" name="' . $option . '[' . $key . ']" />'; |
| 79 |
} |
| 80 |
return $html; |
| 81 |
} |
| 82 |
} else { |
| 83 |
return '<input type="hidden" value="' . $value . '" name="' . $option . '" />'; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
private static function get_tcf_disallowed_legacy( $value ) { |
| 88 |
$html = ''; |
| 89 |
foreach ( $value as $vendor => $restrictions ) { |
| 90 |
foreach ( $restrictions['purposes'] as $key => $purpose ) { |
| 91 |
$html .= '<input type="hidden" value="' . $purpose . '" name="cookiebot-tcf-disallowed[' . $vendor . '][purposes][' . $key . ']" />'; |
| 92 |
} |
| 93 |
} |
| 94 |
return $html; |
| 95 |
} |
| 96 |
|
| 97 |
private static function get_multiple_banners_legacy( $value ) { |
| 98 |
$html = ''; |
| 99 |
foreach ( $value as $key => $settings ) { |
| 100 |
$html .= '<input type="hidden" value="' . $settings['group'] . '" name="cookiebot-multiple-banners[' . $key . '][group]" />'; |
| 101 |
$html .= '<input type="hidden" value="' . $settings['region'] . '" name="cookiebot-multiple-banners[' . $key . '][region]" />'; |
| 102 |
} |
| 103 |
return $html; |
| 104 |
} |
| 105 |
} |
| 106 |
|