Generic_AdminActions_Config.php
5.7 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
namespace W3TC;
class Generic_AdminActions_Config {
private $_config = null;
function __construct() {
$this->_config = Dispatcher::config();
}
/**
* Import config action
*
* @return void
*/
function w3tc_config_import() {
$error = '';
$config = new Config();
if ( !isset( $_FILES['config_file']['error'] ) ||
$_FILES['config_file']['error'] == UPLOAD_ERR_NO_FILE ) {
$error = 'config_import_no_file';
} elseif ( $_FILES['config_file']['error'] != UPLOAD_ERR_OK ) {
$error = 'config_import_upload';
} else {
$imported = $config->import( $_FILES['config_file']['tmp_name'] );
if ( !$imported ) {
$error = 'config_import_import';
}
}
if ( $error ) {
Util_Admin::redirect( array(
'w3tc_error' => $error
), true );
return;
}
Util_Admin::config_save( $this->_config, $config );
Util_Admin::redirect( array(
'w3tc_note' => 'config_import'
), true );
}
/**
* Export config action
*
* @return void
*/
function w3tc_config_export() {
$filename = substr( get_home_url(), strpos( get_home_url(), '//' )+2 );
@header( sprintf( __( 'Content-Disposition: attachment; filename=%s.json', 'w3-total-cache' ), $filename ) );
echo $this->_config->export();
die();
}
/**
* Reset config action
*
* @return void
*/
function w3tc_config_reset() {
$config = new Config();
$config->set_defaults();
Util_Admin::config_save( $this->_config, $config );
$config_state = Dispatcher::config_state();
$config_state->reset();
$config_state->save();
$config_state = Dispatcher::config_state_master();
$config_state->reset();
$config_state->save();
Util_Admin::redirect( array(
'w3tc_note' => 'config_reset'
), true );
}
/**
* Save preview option
*
* @return void
*/
function w3tc_config_preview_enable() {
$this->preview_production_copy( -1 );
Util_Environment::set_preview( true );
Util_Admin::redirect( array(
'w3tc_note' => 'preview_enable'
) );
}
/**
* Save preview option
*
* @return void
*/
function w3tc_config_preview_disable() {
$blog_id = Util_Environment::blog_id();
$preview_filename = Config::util_config_filename( $blog_id, true );
@unlink( $preview_filename );
Util_Environment::set_preview( false );
Util_Admin::redirect( array(
'w3tc_note' => 'preview_disable'
) );
}
/**
* Deploy preview settings action
*
* @return void
*/
function w3tc_config_preview_deploy() {
$this->preview_production_copy( 1 );
Util_Environment::set_preview( false );
Util_Admin::redirect( array(
'w3tc_note' => 'preview_deploy'
) );
}
/**
* Deploys the config file from a preview config file
*
* @param integer $direction +1: preview->production
* -1: production->preview
* @param boolean $remove_source remove source file
*/
private function preview_production_copy( $direction = 1 ) {
$blog_id = Util_Environment::blog_id();
$preview_filename = Config::util_config_filename( $blog_id, true );
$production_filename = Config::util_config_filename( $blog_id, false );
if ( $direction > 0 ) {
$src = $preview_filename;
$dest = $production_filename;
} else {
$src = $production_filename;
$dest = $preview_filename;
}
if ( !@copy( $src, $dest ) ) {
Util_Activation::throw_on_write_error( $dest );
}
}
/**
* Save dbcluster config action
*
* @return void
*/
function w3tc_config_dbcluster_config_save() {
$params = array( 'page' => 'w3tc_general' );
if ( !file_put_contents( W3TC_FILE_DB_CLUSTER_CONFIG,
stripslashes( $_REQUEST['newcontent'] ) ) ) {
try {
Util_Activation::throw_on_write_error( W3TC_FILE_DB_CLUSTER_CONFIG );
} catch ( \Exception $e ) {
$error = $e->getMessage();
Util_Admin::redirect_with_custom_messages( $params, array(
'dbcluster_save_failed' => $error ) );
}
}
Util_Admin::redirect_with_custom_messages( $params, null,
array( 'dbcluster_save' => __( 'Database Cluster configuration file has been successfully saved', 'w3-total-cache' ) ) );
}
/**
* Save support us action
*
* @return void
*/
function w3tc_config_save_support_us() {
$support = Util_Request::get_string( 'support' );
$tweeted = Util_Request::get_boolean( 'tweeted' );
$signmeup = Util_Request::get_boolean( 'signmeup' );
$track_usage = Util_Request::get_boolean( 'track_usage' );
$this->_config->set( 'common.support', $support );
$this->_config->set( 'common.tweeted', $tweeted );
if ( $track_usage )
$this->_config->set( 'common.track_usage', true );
if ( $signmeup ) {
if ( Util_Environment::is_w3tc_enterprise( $this->_config ) )
$license = 'enterprise';
elseif ( Util_Environment::is_w3tc_pro( $this->_config ) )
$license = 'pro';
else
$license = 'community';
$email = filter_input( INPUT_POST, 'email', FILTER_SANITIZE_EMAIL );
wp_remote_post( W3TC_MAILLINGLIST_SIGNUP_URL, array(
'body' => array( 'email' => $email, 'license' => $license )
) );
}
$this->_config->save();
Generic_AdminLinks::link_update( $this->_config );
Util_Admin::redirect( array(
'w3tc_note' => 'config_save'
) );
}
/**
* Update upload path action
*
* @return void
*/
function w3tc_config_update_upload_path() {
update_option( 'upload_path', '' );
Util_Admin::redirect();
}
public function w3tc_config_overloaded_disable( $http_key ) {
$c = Dispatcher::config();
$key = Util_Ui::config_key_from_http_name( $http_key );
$c->set( $key, false );
$c->save();
Util_Admin::redirect( array() );
}
public function w3tc_config_overloaded_enable( $http_key ) {
$c = Dispatcher::config();
$key = Util_Ui::config_key_from_http_name( $http_key );
$c->set( $key, true );
$c->save();
Util_Admin::redirect( array() );
}
}