class-wpml-tm-icl20-migration-status.php
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ICL20_Migration_Status {
const ICL_20_TS_ID = 67;
const ICL_LEGACY_TS_ID = 4;
const ICL_LEGACY_TS_SUID = '6ab1000a33e2cc9ecbcf6abc57254be8';
const ICL_20_TS_SUID = 'dd17d48516ca4bce0b83043583fabd2e';
private $installer_settings = array();
private $service;
public function __construct( $service ) {
$this->service = $service;
}
public function has_active_legacy_icl() {
return $this->has_active_service() && $this->get_ICL_LEGACY_TS_ID() === $this->service->id;
}
public function has_active_icl_20() {
return $this->has_active_service() && $this->get_ICL_20_TS_ID() === $this->service->id;
}
public function has_active_service() {
return (bool) $this->service;
}
public function get_ICL_LEGACY_TS_ID() {
if ( defined( 'WPML_TP_ICL_LEGACY_TS_ID' ) ) {
return WPML_TP_ICL_LEGACY_TS_ID;
}
return self::ICL_LEGACY_TS_ID;
}
public function get_ICL_20_TS_ID() {
if ( defined( 'WPML_TP_ICL_20_TS_ID' ) ) {
return WPML_TP_ICL_20_TS_ID;
}
return self::ICL_20_TS_ID;
}
public function get_ICL_LEGACY_TS_SUID() {
if ( defined( 'WPML_TP_ICL_LEGACY_TS_SUID' ) ) {
return WPML_TP_ICL_LEGACY_TS_SUID;
}
return self::ICL_LEGACY_TS_SUID;
}
public function get_ICL_20_TS_SUID() {
if ( defined( 'WPML_TP_ICL_20_TS_SUID' ) ) {
return WPML_TP_ICL_20_TS_SUID;
}
return self::ICL_20_TS_SUID;
}
public function is_preferred_service_legacy_ICL() {
return $this->has_preferred_service() && self::ICL_LEGACY_TS_SUID === $this->get_preferred_service();
}
public function set_preferred_service_to_ICL20() {
if ( $this->get_preferred_service() ) {
$this->installer_settings['repositories']['wpml']['ts_info']['preferred'] = $this->get_ICL_20_TS_SUID();
$this->update_installer_settings();
}
}
private function has_preferred_service() {
return ! in_array( $this->get_preferred_service(), array( 'clear', false ), true );
}
private function get_preferred_service() {
$installer_settings = $this->get_installer_settings();
if ( isset( $installer_settings['repositories']['wpml']['ts_info']['preferred'] )
&& 'clear' !== $installer_settings['repositories']['wpml']['ts_info']['preferred'] ) {
return $installer_settings['repositories']['wpml']['ts_info']['preferred'];
}
return false;
}
/**
* @return array
*/
private function get_installer_settings() {
if ( ! $this->installer_settings ) {
$raw_settings = get_option( 'wp_installer_settings', null );
if ( $raw_settings ) {
if ( is_array( $raw_settings ) ) { // backward compatibility 1.1
$this->installer_settings = $raw_settings;
} else {
$has_gz_support = function_exists( 'gzuncompress' ) && function_exists( 'gzcompress' );
$raw_settings = base64_decode( $raw_settings );
if ( $has_gz_support ) {
$raw_settings = gzuncompress( $raw_settings );
}
if ( $raw_settings ) {
/** @noinspection UnserializeExploitsInspection */
$this->installer_settings = unserialize( $raw_settings );
}
}
}
}
return $this->installer_settings;
}
private function update_installer_settings() {
$has_gz_support = function_exists( 'gzuncompress' ) && function_exists( 'gzcompress' );
$raw_settings = serialize( $this->installer_settings );
if ( $has_gz_support ) {
$raw_settings = gzcompress( $raw_settings );
}
if ( $raw_settings ) {
$raw_settings = base64_encode( $raw_settings );
update_option( 'wp_installer_settings', $raw_settings );
}
}
}