W3 Total Cache - Version 0.9.2.8

Version Description

  • Fixed /tmp file creation issue when saving settings
  • Fixed an issue with auto minify
  • Fixed an issue with New Relic API key verification
  • Fixed uncommon issue with require ObjectCache failing
  • Fixed uncommon open_basedir verification issue
  • Improved notification handling by modified WordPress FileSystem API implementation
  • Added PHP file handling to support cases not covered by default WordPress FileSystem API
Download this release

Release Info

Developer fredericktownes
Plugin Icon 128x128 W3 Total Cache
Version 0.9.2.8
Comparing to
See all releases

Code changes from version 0.9.2.7 to 0.9.2.8

inc/define.php CHANGED
@@ -5,7 +5,7 @@ if (!defined('ABSPATH')) {
5
  }
6
 
7
  define('W3TC', true);
8
- define('W3TC_VERSION', '0.9.2.7');
9
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
10
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
11
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
@@ -1433,36 +1433,6 @@ function w3_is_flushable_post($post, $module, $config) {
1433
  return apply_filters('w3tc_flushable_post', $flushable, $post, $module);
1434
  }
1435
 
1436
- /**
1437
- * @param $filename
1438
- * @param $content
1439
- * @return bool
1440
- */
1441
- function file_put_contents_atomic($filename, $content) {
1442
-
1443
- $temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
1444
- if (!($f = @fopen($temp, 'wb'))) {
1445
- $temp = W3TC_CACHE_TMP_DIR . DIRECTORY_SEPARATOR . uniqid('temp');
1446
- if (!($f = @fopen($temp, 'wb'))) {
1447
- trigger_error("file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING);
1448
- return false;
1449
- }
1450
- }
1451
-
1452
- fwrite($f, $content);
1453
- fclose($f);
1454
-
1455
- if (!@rename($temp, $filename)) {
1456
- @unlink($filename);
1457
- @rename($temp, $filename);
1458
- }
1459
- $chmod = 0644;
1460
- if (defined('FS_CHMOD_FILE'))
1461
- $chmod = FS_CHMOD_FILE;
1462
- @chmod($filename, $chmod);
1463
- return true;
1464
- }
1465
-
1466
  /**
1467
  * Takes seconds and converts to array('Nh ','Nm ', 'Ns ', 'Nms ') or "Nh Nm Ns Nms"
1468
  * @param $input
5
  }
6
 
7
  define('W3TC', true);
8
+ define('W3TC_VERSION', '0.9.2.8');
9
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
10
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
11
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
1433
  return apply_filters('w3tc_flushable_post', $flushable, $post, $module);
1434
  }
1435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1436
  /**
1437
  * Takes seconds and converts to array('Nh ','Nm ', 'Ns ', 'Nms ') or "Nh Nm Ns Nms"
1438
  * @param $input
inc/functions/activation.php CHANGED
@@ -98,15 +98,25 @@ function w3_throw_on_read_error($path) {
98
  * W3 writable error
99
  *
100
  * @param string $path
 
101
  * @throws FileOperationException
102
  */
103
- function w3_throw_on_write_error($path) {
104
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
105
-
 
 
 
 
 
 
 
 
 
106
  if (w3_check_open_basedir($path)) {
107
  $error = sprintf('<strong>%s</strong> could not be created, please run following ' .
108
- 'command:<br /><strong style="color: #f00;">chmod 777 %s</strong>', $path,
109
- (file_exists($path) ? $path : dirname($path)));
110
  } else {
111
  $error = sprintf('<strong>%s</strong> could not be created, <strong>open_basedir' .
112
  '</strong> restriction in effect, please check your php.ini settings:<br />' .
@@ -151,14 +161,10 @@ function w3_activation_create_required_files() {
151
  W3TC_CONFIG_DIR,
152
  W3TC_CACHE_CONFIG_DIR,
153
  W3TC_CACHE_TMP_DIR);
154
-
155
- foreach ($directories as $d) {
156
- if (!@is_dir($d)) {
157
- try{
158
- w3_wp_create_folder($d, 'direct');
159
- } catch(Exception $ex) {}
160
- }
161
- }
162
  }
163
 
164
  /**
@@ -208,6 +214,15 @@ function w3_copy_if_not_equal($source_filename, $destination_filename, $method =
208
  * @throws FileOperationException
209
  */
210
  function w3_wp_copy_file($source_filename, $destination_filename, $method = '', $url = '', $context = false) {
 
 
 
 
 
 
 
 
 
211
  w3_wp_request_filesystem_credentials($method, $url, $context);
212
 
213
  global $wp_filesystem;
@@ -227,31 +242,12 @@ function w3_wp_copy_file($source_filename, $destination_filename, $method = '',
227
  * @throws FileOperationException
228
  */
229
  function w3_wp_create_folder($folder, $method = '', $url = '', $context = false) {
230
- w3_wp_request_filesystem_credentials($method, $url, $context);
231
-
232
- global $wp_filesystem;
233
- if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
234
- throw new FileOperationException('Could not create folder:' . $folder, 'create', 'folder', $folder);
235
- }
236
- }
237
-
238
-
239
- /**
240
- * @param $folders
241
- * @param string $method Which method to use when creating
242
- * @param string $url Where to redirect after creation
243
- * @param bool|string $context folder to create folders in
244
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
245
- * @throws FileOperationException
246
- */
247
- function w3_wp_create_folders($folders, $method = '', $url = '', $context = false) {
248
- w3_wp_request_filesystem_credentials($method, $url, $context);
249
-
250
- global $wp_filesystem;
251
 
252
- foreach($folders as $folder) {
253
  if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
254
- throw new FileOperationException('Could not create folder: ' . $folder, 'create', 'folder', $folder);
255
  }
256
  }
257
  }
@@ -267,11 +263,25 @@ function w3_wp_create_folders($folders, $method = '', $url = '', $context = fals
267
  function w3_wp_delete_folders($folders, $method = '', $url = '', $context = false) {
268
  $delete_folders = array();
269
  foreach($folders as $folder) {
270
- if (is_dir($folder) && file_exists($folder))
271
  $delete_folders[] = $folder;
272
  }
273
  if (empty($delete_folders))
274
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  w3_wp_request_filesystem_credentials($method, $url, $context);
276
 
277
  global $wp_filesystem;
@@ -280,7 +290,7 @@ function w3_wp_delete_folders($folders, $method = '', $url = '', $context = fals
280
  w3_rmdir($folder);
281
  if (file_exists($folder))
282
  if (!$wp_filesystem->rmdir($folder, FS_CHMOD_DIR)) {
283
- throw new FileOperationException('Could not delete folder: ' . $folder, 'delete', 'folder', $folder);
284
  }
285
  }
286
  }
@@ -294,7 +304,7 @@ function w3_wp_delete_folders($folders, $method = '', $url = '', $context = fals
294
  * @throws FileOperationException
295
  */
296
  function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
297
- if (@unlink($file)) {
298
  w3_wp_request_filesystem_credentials($method, $url, false, $context = false);
299
 
300
  global $wp_filesystem;
@@ -305,28 +315,6 @@ function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
305
  }
306
  }
307
 
308
- /**
309
- * Copy files using WordPress filesystem functions.
310
- * @param $files
311
- * @param string $method Which method to use when creating
312
- * @param string $url Where to redirect after creation
313
- * @param bool|string $context folder to copy too
314
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
315
- * @throws FileOperationException
316
- */
317
- function w3_wp_copy_files($files, $method = '', $url = '', $context = false) {
318
- w3_wp_request_filesystem_credentials($method, $url, false, $context);
319
-
320
- global $wp_filesystem;
321
- foreach($files as $source_filename => $destination_filename) {
322
- $contents = $wp_filesystem->get_contents($source_filename);
323
-
324
- if (!$wp_filesystem->put_contents($destination_filename, $contents, FS_CHMOD_FILE)) {
325
- throw new FileOperationException('Could not create file: ' . $destination_filename, 'create', 'file', $destination_filename);
326
- }
327
- }
328
- }
329
-
330
  /**
331
  * Get WordPress filesystems credentials. Required for WP filesystem usage.
332
  * @param string $method Which method to use when creating
@@ -357,39 +345,6 @@ function w3_wp_request_filesystem_credentials($method = '', $url = '', $context
357
  }
358
  }
359
 
360
- /**
361
- * @param $add_in_files array with key as source and value as destination
362
- * @param $cache_folders value is the folder path
363
- * @param string $method Which method to use when creating
364
- * @param string $url Where to redirect after creation
365
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
366
- * @throws FileOperationException
367
- */
368
- function w3_create_missing_files_and_folders($add_in_files, $cache_folders, $method = '', $url = '') {
369
- if (empty($add_in_files) && empty($cache_folders))
370
- return;
371
-
372
- w3_wp_request_filesystem_credentials($method, $url);
373
-
374
- global $wp_filesystem;
375
-
376
- foreach($cache_folders as $folder) {
377
- if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
378
- throw new FileOperationException('Could not create folder:' . $folder, 'create', 'folder', $folder);
379
- }
380
- }
381
- foreach($add_in_files as $source_filename => $destination_filename) {
382
- $contents = $wp_filesystem->get_contents($source_filename);
383
-
384
- if (file_exists($destination_filename) && ! $wp_filesystem->delete($destination_filename))
385
- throw new FileOperationException('Could not delete file: ' . $destination_filename, 'delete', 'file', $destination_filename);
386
-
387
- if (!$wp_filesystem->put_contents($destination_filename, $contents, FS_CHMOD_FILE)) {
388
- throw new FileOperationException('Could not create file: ' . $destination_filename, 'create', 'file', $destination_filename);
389
- }
390
- }
391
- }
392
-
393
  /**
394
  * Create files
395
  * @param $files array(from file => to file)
@@ -398,10 +353,22 @@ function w3_create_missing_files_and_folders($add_in_files, $cache_folders, $met
398
  * @param bool|string path to folder where files should be created
399
  * @throws FileOperationException
400
  */
401
- function w3_create_files($files, $method = '', $url = '', $context = false) {
402
  if (empty($files))
403
  return;
404
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  w3_wp_request_filesystem_credentials($method, $url, $context);
406
 
407
  global $wp_filesystem;
@@ -419,47 +386,53 @@ function w3_create_files($files, $method = '', $url = '', $context = false) {
419
  }
420
 
421
  /**
422
- * Create folders
423
  * @param $folders array(folderpath1, folderpath2, ...)
424
  * @param string $method
425
  * @param string $url
 
 
426
  * @throws FileOperationException
427
  */
428
- function w3_create_folders($folders, $method = '', $url = '') {
429
- if (empty($add_in_files) && empty($folders))
430
  return;
431
 
432
- w3_wp_request_filesystem_credentials($method, $url);
 
 
 
 
 
 
 
 
 
 
433
 
434
  global $wp_filesystem;
435
 
436
  foreach($folders as $folder) {
437
- if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
438
- throw new FileOperationException('Could not create folder:' . $folder, 'create', 'folder', $folder);
439
  }
440
  }
441
  }
442
 
443
  /**
444
  * Tries to write file content
445
- * @param $filename path to file
446
- * @param $content data to write
447
  * @param string $method Which method to use when creating
448
  * @param string $url Where to redirect after creation
449
  * @param bool|string $context folder in which to write file
450
  * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
451
  * @throws FileOperationException
452
- * @return true;
453
  */
454
- function w3_write_to_file($filename, $content, $method = '', $url = '', $context = false) {
455
- if (is_writable($filename)) {
456
- if (@file_put_contents($filename, $content))
457
- return true;
458
- w3_wp_request_filesystem_credentials('direct');
459
- global $wp_filesystem;
460
- if ($wp_filesystem->put_contents($filename, $content))
461
- return true;
462
- }
463
 
464
  w3_wp_request_filesystem_credentials($method, $url, $context);
465
  $permissions = array(0644, 0664, 0666);
@@ -479,7 +452,7 @@ function w3_write_to_file($filename, $content, $method = '', $url = '', $context
479
 
480
  /**
481
  * Tries to read file content
482
- * @param $filename path to file
483
  * @param string $method Which method to use when creating
484
  * @param string $url Where to redirect after creation
485
  * @param bool|string $context folder to read from
@@ -487,7 +460,11 @@ function w3_write_to_file($filename, $content, $method = '', $url = '', $context
487
  * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
488
  * @throws FileOperationException
489
  */
490
- function w3_read_from_file($filename, $method = '', $url = '', $context = false) {
 
 
 
 
491
  w3_wp_request_filesystem_credentials($method, $url, $context);
492
 
493
  global $wp_filesystem;
@@ -511,6 +488,10 @@ function w3_read_from_file($filename, $method = '', $url = '', $context = false)
511
  function w3_chmod_dir($dir, $permission, $recursive = false, $method = '', $url = '', $context = false) {
512
  if (!is_dir($dir) || !file_exists($dir))
513
  return false;
 
 
 
 
514
  w3_wp_request_filesystem_credentials($method, $url, $context);
515
 
516
  global $wp_filesystem;
@@ -523,7 +504,7 @@ function w3_chmod_dir($dir, $permission, $recursive = false, $method = '', $url
523
  }
524
 
525
  /**
526
- * @param $file path to file
527
  * @param $permission
528
  * @param string $method
529
  * @param string $url
@@ -556,7 +537,7 @@ function w3_chmod_file($file, $permission, $method = '', $url = '', $context = f
556
  function w3_enable_maintenance_mode($time = null) {
557
  if (is_null($time))
558
  $time = 'time()';
559
- w3_write_to_file(w3_get_site_root() . '/.maintenance', "<?php \$upgrading = $time; ?>");
560
  }
561
 
562
  /**
98
  * W3 writable error
99
  *
100
  * @param string $path
101
+ * @param string[] $chmod_dirs Directories that should be chmod 777 inorder to write
102
  * @throws FileOperationException
103
  */
104
+ function w3_throw_on_write_error($path, $chmod_dirs = array()) {
105
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
106
+ $chmods = '';
107
+ if ($chmod_dirs) {
108
+ $chmods = '<ul>';
109
+ foreach($chmod_dirs as $dir) {
110
+ $chmods .= sprintf('<li><strong style="color: #f00;">chmod 777 %s</strong></li>', $dir);
111
+ }
112
+ } else {
113
+ $chmods = sprintf('<strong style="color: #f00;">chmod 777 %s</strong>',
114
+ (file_exists($path) ? $path : dirname($path)));
115
+ }
116
  if (w3_check_open_basedir($path)) {
117
  $error = sprintf('<strong>%s</strong> could not be created, please run following ' .
118
+ 'command:<br />%s', $path,
119
+ $chmods);
120
  } else {
121
  $error = sprintf('<strong>%s</strong> could not be created, <strong>open_basedir' .
122
  '</strong> restriction in effect, please check your php.ini settings:<br />' .
161
  W3TC_CONFIG_DIR,
162
  W3TC_CACHE_CONFIG_DIR,
163
  W3TC_CACHE_TMP_DIR);
164
+
165
+ try{
166
+ w3_wp_create_folders($directories, 'direct');
167
+ } catch(Exception $ex) {}
 
 
 
 
168
  }
169
 
170
  /**
214
  * @throws FileOperationException
215
  */
216
  function w3_wp_copy_file($source_filename, $destination_filename, $method = '', $url = '', $context = false) {
217
+ $contents = @file_get_contents($source_filename);
218
+ if ($contents) {
219
+ @file_put_contents($destination_filename, $contents);
220
+ }
221
+ if (@file_exists($destination_filename)) {
222
+ if (@file_get_contents($destination_filename) == $contents)
223
+ return;
224
+ }
225
+
226
  w3_wp_request_filesystem_credentials($method, $url, $context);
227
 
228
  global $wp_filesystem;
242
  * @throws FileOperationException
243
  */
244
  function w3_wp_create_folder($folder, $method = '', $url = '', $context = false) {
245
+ if (!@is_dir($folder) && !@w3_mkdir($folder)) {
246
+ w3_wp_request_filesystem_credentials($method, $url, $context);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
+ global $wp_filesystem;
249
  if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
250
+ throw new FileOperationException('Could not create directory:' . $folder, 'create', 'folder', $folder);
251
  }
252
  }
253
  }
263
  function w3_wp_delete_folders($folders, $method = '', $url = '', $context = false) {
264
  $delete_folders = array();
265
  foreach($folders as $folder) {
266
+ if (is_dir($folder))
267
  $delete_folders[] = $folder;
268
  }
269
  if (empty($delete_folders))
270
  return;
271
+
272
+ $removed = true;
273
+ foreach ($delete_folders as $folder) {
274
+ w3_rmdir($folder);
275
+ if (@is_dir($folder))
276
+ @rmdir($folder);
277
+ if (@is_dir($folder)) {
278
+ $removed = false;
279
+ break;
280
+ }
281
+ }
282
+
283
+ if ($removed)
284
+ return;
285
  w3_wp_request_filesystem_credentials($method, $url, $context);
286
 
287
  global $wp_filesystem;
290
  w3_rmdir($folder);
291
  if (file_exists($folder))
292
  if (!$wp_filesystem->rmdir($folder, FS_CHMOD_DIR)) {
293
+ throw new FileOperationException('Could not delete directory: ' . $folder, 'delete', 'folder', $folder);
294
  }
295
  }
296
  }
304
  * @throws FileOperationException
305
  */
306
  function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
307
+ if (!@unlink($file)) {
308
  w3_wp_request_filesystem_credentials($method, $url, false, $context = false);
309
 
310
  global $wp_filesystem;
315
  }
316
  }
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  /**
319
  * Get WordPress filesystems credentials. Required for WP filesystem usage.
320
  * @param string $method Which method to use when creating
345
  }
346
  }
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  /**
349
  * Create files
350
  * @param $files array(from file => to file)
353
  * @param bool|string path to folder where files should be created
354
  * @throws FileOperationException
355
  */
356
+ function w3_wp_create_files($files, $method = '', $url = '', $context = false) {
357
  if (empty($files))
358
  return;
359
 
360
+ $created = true;
361
+ foreach ($files as $source_filename => $destination_filename) {
362
+ $contents = @file_get_contents($source_filename);
363
+ if ($contents && !@file_put_contents($destination_filename, $contents)) {
364
+ $created = false;
365
+ break;
366
+ }
367
+ }
368
+
369
+ if ($created)
370
+ return;
371
+
372
  w3_wp_request_filesystem_credentials($method, $url, $context);
373
 
374
  global $wp_filesystem;
386
  }
387
 
388
  /**
389
+ * Create folders in wp content
390
  * @param $folders array(folderpath1, folderpath2, ...)
391
  * @param string $method
392
  * @param string $url
393
+ * @param bool|string $context folder to create folders in
394
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
395
  * @throws FileOperationException
396
  */
397
+ function w3_wp_create_folders($folders, $method = '', $url = '', $context = false) {
398
+ if (empty($folders))
399
  return;
400
 
401
+ $created = true;
402
+ foreach ($folders as $folder) {
403
+ if (!@is_dir($folder) && !@w3_mkdir_from($folder, WP_CONTENT_DIR)) {
404
+ $created = false;
405
+ break;
406
+ }
407
+ }
408
+ if ($created)
409
+ return;
410
+
411
+ w3_wp_request_filesystem_credentials($method, $url, $context);
412
 
413
  global $wp_filesystem;
414
 
415
  foreach($folders as $folder) {
416
+ if (!@is_dir($folder) && !$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
417
+ throw new FileOperationException('Could not create directory:' . $folder, 'create', 'folder', $folder);
418
  }
419
  }
420
  }
421
 
422
  /**
423
  * Tries to write file content
424
+ * @param string $filename path to file
425
+ * @param string $content data to write
426
  * @param string $method Which method to use when creating
427
  * @param string $url Where to redirect after creation
428
  * @param bool|string $context folder in which to write file
429
  * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
430
  * @throws FileOperationException
431
+ * @return bool;
432
  */
433
+ function w3_wp_write_to_file($filename, $content, $method = '', $url = '', $context = false) {
434
+ if (@file_put_contents($filename, $content))
435
+ return true;
 
 
 
 
 
 
436
 
437
  w3_wp_request_filesystem_credentials($method, $url, $context);
438
  $permissions = array(0644, 0664, 0666);
452
 
453
  /**
454
  * Tries to read file content
455
+ * @param string $filename path to file
456
  * @param string $method Which method to use when creating
457
  * @param string $url Where to redirect after creation
458
  * @param bool|string $context folder to read from
460
  * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
461
  * @throws FileOperationException
462
  */
463
+ function w3_wp_read_from_file($filename, $method = '', $url = '', $context = false) {
464
+ $content = @file_get_contents($filename);
465
+ if ($content)
466
+ return $content;
467
+
468
  w3_wp_request_filesystem_credentials($method, $url, $context);
469
 
470
  global $wp_filesystem;
488
  function w3_chmod_dir($dir, $permission, $recursive = false, $method = '', $url = '', $context = false) {
489
  if (!is_dir($dir) || !file_exists($dir))
490
  return false;
491
+
492
+ if (@chmod($dir, $permission))
493
+ return true;
494
+
495
  w3_wp_request_filesystem_credentials($method, $url, $context);
496
 
497
  global $wp_filesystem;
504
  }
505
 
506
  /**
507
+ * @param string $file path to file
508
  * @param $permission
509
  * @param string $method
510
  * @param string $url
537
  function w3_enable_maintenance_mode($time = null) {
538
  if (is_null($time))
539
  $time = 'time()';
540
+ w3_wp_write_to_file(w3_get_site_root() . '/.maintenance', "<?php \$upgrading = $time; ?>");
541
  }
542
 
543
  /**
inc/functions/file.php CHANGED
@@ -207,7 +207,7 @@ function w3_get_open_basedirs() {
207
 
208
  foreach ($open_basedirs as $open_basedir) {
209
  $open_basedir = trim($open_basedir);
210
- if ($open_basedir != '') {
211
  $result[] = w3_realpath($open_basedir);
212
  }
213
  }
@@ -240,14 +240,14 @@ function w3_check_open_basedir($path) {
240
 
241
  function w3_get_file_permissions($file) {
242
  if (function_exists('fileperms') && $fileperms = @fileperms($file)) {
243
- $fileperms = sprintf('0%o', 0777 & $fileperms);
244
  } else {
245
  clearstatcache();
246
  $stat=@stat($file);
247
  if ($stat)
248
- $fileperms = sprintf("0%o", 0777 & $stat['mode']);
249
  else
250
- $fileperms = 'unknown';
251
  }
252
  return $fileperms;
253
  }
207
 
208
  foreach ($open_basedirs as $open_basedir) {
209
  $open_basedir = trim($open_basedir);
210
+ if (!empty($open_basedir) && $open_basedir != '') {
211
  $result[] = w3_realpath($open_basedir);
212
  }
213
  }
240
 
241
  function w3_get_file_permissions($file) {
242
  if (function_exists('fileperms') && $fileperms = @fileperms($file)) {
243
+ $fileperms = 0777 & $fileperms;
244
  } else {
245
  clearstatcache();
246
  $stat=@stat($file);
247
  if ($stat)
248
+ $fileperms = 0777 & $stat['mode'];
249
  else
250
+ $fileperms = 0;
251
  }
252
  return $fileperms;
253
  }
inc/options/common/header.php CHANGED
@@ -17,16 +17,17 @@ jQuery(function($) {
17
  </div>
18
  <?php endforeach; ?>
19
 
20
- <?php if ($this->_rule_errors_autoinstall != ''): ?>
21
  <div class="error">
22
  <p>
23
  The following configuration changes are needed to ensure optimal performance:<br />
 
24
  <ul style="padding-left: 20px">
25
  <?php foreach ($this->_rule_errors as $error): ?>
26
  <li><?php echo $error[0]; ?></li>
27
  <?php endforeach; ?>
28
  </ul>
29
- </p>
30
  <p>
31
  If permission allow this can be done automatically, by clicking here:
32
  <?php echo $this->_rule_errors_autoinstall ?>.
@@ -35,16 +36,17 @@ jQuery(function($) {
35
  </div>
36
  <?php endif; ?>
37
 
38
- <?php if ($this->_rule_errors_root): ?>
39
  <div class="error">
40
  <p>
41
  The following configuration changes are needed to ensure optimal performance:<br />
 
42
  <ul style="padding-left: 20px">
43
  <?php foreach ($this->_rule_errors_root as $error): ?>
44
  <li><?php echo $error; ?></li>
45
  <?php endforeach; ?>
46
  </ul>
47
- </p>
48
  <?php if (isset($this->_ftp_form) && ($this->_use_ftp_form || $this->_rule_errors_root)): ?>
49
  <p>
50
  If permission allow this can be done using the <a href="#ftp_upload_form">FTP form</a> below. <?php echo $this->_rule_errors_root_hide; ?>
17
  </div>
18
  <?php endforeach; ?>
19
 
20
+ <?php if (!$this->_disable_cache_write_notification && $this->_rule_errors_autoinstall != ''): ?>
21
  <div class="error">
22
  <p>
23
  The following configuration changes are needed to ensure optimal performance:<br />
24
+ </p>
25
  <ul style="padding-left: 20px">
26
  <?php foreach ($this->_rule_errors as $error): ?>
27
  <li><?php echo $error[0]; ?></li>
28
  <?php endforeach; ?>
29
  </ul>
30
+
31
  <p>
32
  If permission allow this can be done automatically, by clicking here:
33
  <?php echo $this->_rule_errors_autoinstall ?>.
36
  </div>
37
  <?php endif; ?>
38
 
39
+ <?php if (!$this->_disable_file_operation_notification && $this->_rule_errors_root): ?>
40
  <div class="error">
41
  <p>
42
  The following configuration changes are needed to ensure optimal performance:<br />
43
+ </p>
44
  <ul style="padding-left: 20px">
45
  <?php foreach ($this->_rule_errors_root as $error): ?>
46
  <li><?php echo $error; ?></li>
47
  <?php endforeach; ?>
48
  </ul>
49
+
50
  <?php if (isset($this->_ftp_form) && ($this->_use_ftp_form || $this->_rule_errors_root)): ?>
51
  <p>
52
  If permission allow this can be done using the <a href="#ftp_upload_form">FTP form</a> below. <?php echo $this->_rule_errors_root_hide; ?>
inc/options/pgcache.php CHANGED
@@ -249,7 +249,7 @@
249
  <th><label>Compatibility mode</label></th>
250
  <td>
251
  <?php $this->checkbox('pgcache.compatibility') ?> Enable compatibility mode</label><br />
252
- <span class="description">Decreases performance by ~20% at scale in exchange for increasing interoperability with more hosting environemtns and WordPress idiosyncracies. This option should be enabled for most sites.</span>
253
  </td>
254
  </tr>
255
  <?php endif; ?>
249
  <th><label>Compatibility mode</label></th>
250
  <td>
251
  <?php $this->checkbox('pgcache.compatibility') ?> Enable compatibility mode</label><br />
252
+ <span class="description">Decreases performance by ~20% at scale in exchange for increasing interoperability with more hosting environemnts and WordPress idiosyncracies. This option should be enabled for most sites.</span>
253
  </td>
254
  </tr>
255
  <?php endif; ?>
inc/popup/cdn_purge.php CHANGED
@@ -8,9 +8,9 @@
8
  <?php switch ($this->_config->get_string('cdn.engine')):
9
  case 'cotendo': ?>
10
  <ul>
11
- <li><em>wp-content/themes/twentyten/images/headers/</em> &mdash; the folder itself (only when accessed directly without any file).</li>
12
- <li><em>wp-content/themes/twentyten/images/headers/*.</em> &mdash; all files in the folder with no extension, with all parameter variations.</li>
13
- <li><em>wp-content/themes/twentyten/images/headers/*.jpg</em> &mdash; all files in the folder whose extension is "jpg".</li>
14
  <li><em>wp-content/themes/twentyten/images/headers/path</em> &mdash; the specific file (when the file does not have an extension), and without parameters.</li>
15
  <li><em>wp-content/themes/twentyten/images/headers/path.jpg</em> &mdash; the specific file with its extension, and without parameters.</li>
16
  <li><em>wp-content/themes/twentyten/images/headers/path.jpg?*</em> &mdash; the specific file with its extension, with all variation of parameters.</li>
8
  <?php switch ($this->_config->get_string('cdn.engine')):
9
  case 'cotendo': ?>
10
  <ul>
11
+ <li><em>wp-content/themes/twentyten/images/headers/</em> &mdash; the directory itself (only when accessed directly without any file).</li>
12
+ <li><em>wp-content/themes/twentyten/images/headers/*.</em> &mdash; all files in the directory with no extension, with all parameter variations.</li>
13
+ <li><em>wp-content/themes/twentyten/images/headers/*.jpg</em> &mdash; all files in the directory whose extension is "jpg".</li>
14
  <li><em>wp-content/themes/twentyten/images/headers/path</em> &mdash; the specific file (when the file does not have an extension), and without parameters.</li>
15
  <li><em>wp-content/themes/twentyten/images/headers/path.jpg</em> &mdash; the specific file with its extension, and without parameters.</li>
16
  <li><em>wp-content/themes/twentyten/images/headers/path.jpg?*</em> &mdash; the specific file with its extension, with all variation of parameters.</li>
lib/W3/ConfigAdmin.php CHANGED
@@ -116,10 +116,15 @@ class W3_ConfigAdmin extends W3_ConfigBase {
116
  w3_mkdir_from(dirname($filename), WP_CONTENT_DIR);
117
  }
118
 
 
 
 
 
 
119
  if (!$this->_data_object->write($filename)) {
120
  if (is_dir(W3TC_CONFIG_DIR)) {
121
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
122
- w3_throw_on_write_error($filename);
123
  }
124
  }
125
  }
116
  w3_mkdir_from(dirname($filename), WP_CONTENT_DIR);
117
  }
118
 
119
+ if (!is_dir(dirname(W3TC_CACHE_TMP_DIR))) {
120
+ w3_require_once(W3TC_INC_DIR . '/functions/file.php');
121
+ w3_mkdir_from(dirname(W3TC_CACHE_TMP_DIR), WP_CONTENT_DIR);
122
+ }
123
+
124
  if (!$this->_data_object->write($filename)) {
125
  if (is_dir(W3TC_CONFIG_DIR)) {
126
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
127
+ w3_throw_on_write_error($filename, array(dirname($filename), W3TC_CACHE_TMP_DIR));
128
  }
129
  }
130
  }
lib/W3/ConfigData.php CHANGED
@@ -153,7 +153,7 @@ class W3_ConfigData {
153
  foreach ($this->data as $key => $value)
154
  $config .= $this->_write_item(1, $key, $value);
155
  $config .= ");";
156
- return @file_put_contents_atomic($filename, $config);
157
  }
158
 
159
 
@@ -210,4 +210,47 @@ class W3_ConfigData {
210
 
211
  return $item;
212
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
153
  foreach ($this->data as $key => $value)
154
  $config .= $this->_write_item(1, $key, $value);
155
  $config .= ");";
156
+ return @$this->file_put_contents_atomic($filename, $config);
157
  }
158
 
159
 
210
 
211
  return $item;
212
  }
213
+
214
+ /**
215
+ * @param $filename
216
+ * @param $content
217
+ * @return bool
218
+ */
219
+ function file_put_contents_atomic($filename, $content) {
220
+ if (is_dir(W3TC_CACHE_TMP_DIR) && is_writable(W3TC_CACHE_TMP_DIR)) {
221
+ $temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
222
+ } else {
223
+ trigger_error("file_put_contents_atomic() : error writing temporary file to '" . W3TC_CACHE_TMP_DIR . "'", E_USER_WARNING);
224
+ return false;
225
+ }
226
+
227
+ $chmod = 0644;
228
+ if (defined('FS_CHMOD_FILE'))
229
+ $chmod = FS_CHMOD_FILE;
230
+ @chmod($temp, $chmod);
231
+
232
+ if (!($f = @fopen($temp, 'wb'))) {
233
+ if (file_exists($temp))
234
+ @unlink($temp);
235
+ trigger_error("file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING);
236
+ return false;
237
+ }
238
+
239
+ fwrite($f, $content);
240
+ fclose($f);
241
+
242
+ if (!@rename($temp, $filename)) {
243
+ @unlink($filename);
244
+ @rename($temp, $filename);
245
+ }
246
+
247
+ if (file_exists($temp))
248
+ @unlink($temp);
249
+
250
+ $chmod = 0644;
251
+ if (defined('FS_CHMOD_FILE'))
252
+ $chmod = FS_CHMOD_FILE;
253
+ @chmod($filename, $chmod);
254
+ return true;
255
+ }
256
  }
lib/W3/ConfigKeys.php CHANGED
@@ -1121,11 +1121,11 @@ $keys = array(
1121
  ),
1122
  'cloudflare.ips.ip4' => array(
1123
  'type' => 'array',
1124
- 'default' => array()
1125
  ),
1126
  'cloudflare.ips.ip6' => array(
1127
  'type' => 'array',
1128
- 'default' => array()
1129
  ),
1130
 
1131
  'varnish.enabled' => array(
@@ -1643,7 +1643,7 @@ $keys = array(
1643
 
1644
  'minify.auto.filename_length' => array(
1645
  'type' => 'integer',
1646
- 'default' => 251
1647
  ),
1648
  'common.instance_id' => array(
1649
  'type' => 'integer',
1121
  ),
1122
  'cloudflare.ips.ip4' => array(
1123
  'type' => 'array',
1124
+ 'default' => array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18","190.93.240.1/20","188.114.96.0/20", "198.41.128.0/17")
1125
  ),
1126
  'cloudflare.ips.ip6' => array(
1127
  'type' => 'array',
1128
+ 'default' => array("2400:cb00::/32", "2606:4700::/32", "2803:f800::/32")
1129
  ),
1130
 
1131
  'varnish.enabled' => array(
1643
 
1644
  'minify.auto.filename_length' => array(
1645
  'type' => 'integer',
1646
+ 'default' => 150
1647
  ),
1648
  'common.instance_id' => array(
1649
  'type' => 'integer',
lib/W3/ConfigWriter.php CHANGED
@@ -156,7 +156,7 @@ class W3_ConfigWriter {
156
  if (!$this->_data->write($filename)) {
157
  if (is_dir(W3TC_CONFIG_DIR)) {
158
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
159
- w3_throw_on_write_error($filename);
160
  }
161
  } else {
162
  $this->flush_apc($filename);
156
  if (!$this->_data->write($filename)) {
157
  if (is_dir(W3TC_CONFIG_DIR)) {
158
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
159
+ w3_throw_on_write_error($filename, array(W3TC_CACHE_TMP_DIR, W3TC_CONFIG_DIR));
160
  }
161
  } else {
162
  $this->flush_apc($filename);
lib/W3/FileVerification.php CHANGED
@@ -56,7 +56,7 @@ class W3_FileVerification {
56
  , W3TC_ADDIN_FILE_OBJECT_CACHE);
57
  }
58
 
59
- if ($this->objectcache_check_old_add_in() || !$this->objectcache_check()) {
60
  $addin_files[W3TC_INSTALL_FILE_OBJECT_CACHE] = W3TC_ADDIN_FILE_OBJECT_CACHE;
61
  $addin_files_messages[] = sprintf('Object caching will not function properly: %s is not latest version.'
62
  , W3TC_ADDIN_FILE_OBJECT_CACHE);
56
  , W3TC_ADDIN_FILE_OBJECT_CACHE);
57
  }
58
 
59
+ if ($this->objectcache_installed() && ($this->objectcache_check_old_add_in() || !$this->objectcache_check())) {
60
  $addin_files[W3TC_INSTALL_FILE_OBJECT_CACHE] = W3TC_ADDIN_FILE_OBJECT_CACHE;
61
  $addin_files_messages[] = sprintf('Object caching will not function properly: %s is not latest version.'
62
  , W3TC_ADDIN_FILE_OBJECT_CACHE);
lib/W3/Minify.php CHANGED
@@ -973,11 +973,9 @@ class W3_Minify {
973
 
974
  $imploded = implode(',',$input);
975
  $config = w3_instance('W3_Config');
976
- if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
977
- if (function_exists('gzdeflate') || function_exists('gzcompress'))
978
- $fn_length = $config->get_integer('minify.auto.filename_length',251);
979
- else
980
- $fn_length = 251;
981
  } else {
982
  $dir = w3_cache_blog_dir('minify');
983
  $fn_length = 255-strlen($dir);
973
 
974
  $imploded = implode(',',$input);
975
  $config = w3_instance('W3_Config');
976
+ if (!W3TC_WIN) {
977
+ $fn_length = $config->get_integer('minify.auto.filename_length',150);
978
+ $fn_length = $fn_length>150 ? 150 : $fn_length;
 
 
979
  } else {
980
  $dir = w3_cache_blog_dir('minify');
981
  $fn_length = 255-strlen($dir);
lib/W3/Plugin/BrowserCacheAdmin.php CHANGED
@@ -696,7 +696,7 @@ class W3_Plugin_BrowserCacheAdmin extends W3_Plugin {
696
  }
697
 
698
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
699
- w3_write_to_file($path, $data);
700
  }
701
 
702
  /**
@@ -755,7 +755,7 @@ class W3_Plugin_BrowserCacheAdmin extends W3_Plugin {
755
  }
756
 
757
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
758
- w3_write_to_file($path, $data);
759
  }
760
 
761
  /**
@@ -796,7 +796,7 @@ class W3_Plugin_BrowserCacheAdmin extends W3_Plugin {
796
  $data = $this->erase_rules_cache($data);
797
 
798
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
799
- w3_write_to_file($path, $data);
800
  }
801
  }
802
  }
@@ -815,7 +815,7 @@ class W3_Plugin_BrowserCacheAdmin extends W3_Plugin {
815
  $data = $this->erase_rules_no404wp($data);
816
 
817
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
818
- w3_write_to_file($path, $data);
819
  }
820
  }
821
  }
696
  }
697
 
698
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
699
+ w3_wp_write_to_file($path, $data);
700
  }
701
 
702
  /**
755
  }
756
 
757
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
758
+ w3_wp_write_to_file($path, $data);
759
  }
760
 
761
  /**
796
  $data = $this->erase_rules_cache($data);
797
 
798
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
799
+ w3_wp_write_to_file($path, $data);
800
  }
801
  }
802
  }
815
  $data = $this->erase_rules_no404wp($data);
816
 
817
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
818
+ w3_wp_write_to_file($path, $data);
819
  }
820
  }
821
  }
lib/W3/Plugin/CdnAdmin.php CHANGED
@@ -994,7 +994,7 @@ WHERE p.post_type = "attachment" AND (pm.meta_value IS NOT NULL OR pm2.meta_valu
994
  }
995
 
996
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
997
- w3_write_to_file($path, $data);
998
  }
999
 
1000
  /**
@@ -1023,7 +1023,7 @@ WHERE p.post_type = "attachment" AND (pm.meta_value IS NOT NULL OR pm2.meta_valu
1023
  $data = $this->erase_rules($data);
1024
 
1025
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1026
- w3_write_to_file($path, $data);
1027
  }
1028
  }
1029
  }
994
  }
995
 
996
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
997
+ w3_wp_write_to_file($path, $data);
998
  }
999
 
1000
  /**
1023
  $data = $this->erase_rules($data);
1024
 
1025
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1026
+ w3_wp_write_to_file($path, $data);
1027
  }
1028
  }
1029
  }
lib/W3/Plugin/Minify.php CHANGED
@@ -165,6 +165,59 @@ class W3_Plugin_Minify extends W3_Plugin {
165
  $embed_extsrcjs = false;
166
 
167
  if ($this->_config->get_boolean('minify.auto')) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  if ($this->_config->get_boolean('minify.css.enable')) {
169
  $ignore_css_files = $this->_config->get_array('minify.reject.files.css');
170
  $files_to_minify = array();
@@ -218,59 +271,6 @@ class W3_Plugin_Minify extends W3_Plugin {
218
  $style = $this->get_style_custom($files_to_minify);
219
  $buffer = substr_replace($buffer, $style, $embed_pos, 0);
220
  }
221
-
222
- if ($this->_config->get_boolean('minify.js.enable')) {
223
- $ignore_js_files = $this->_config->get_array('minify.reject.files.js');
224
- $embed_type = $this->_config->get_string('minify.js.header.embed_type');
225
- $embed_type = $embed_type == 'extsrc' || $embed_type == 'asyncsrc'?'blocking':$embed_type;
226
-
227
- $embed_pos = strpos($buffer, '<!-- W3TC-include-js-head -->');
228
- $buffer = str_replace('<!-- W3TC-include-js-head -->', '', $buffer);
229
- if ($embed_pos === false) {
230
- preg_match('~<head(\s+[^<>]+)*>~Ui', $buffer, $match, PREG_OFFSET_CAPTURE);
231
- $embed_pos = strlen($match[0][0]) + $match[0][1];
232
- }
233
-
234
- $ignore_js_files = array_map('w3_normalize_file', $ignore_js_files);
235
- $files_to_minify = array();
236
- $handled_scripts = array();
237
- $script_tags = w3_extract_js2($buffer);
238
- $previous_file_was_ignored = false;
239
- foreach ($script_tags as $script_tag) {
240
- $tag_pos = strpos($buffer, $script_tag);
241
- $match = array();
242
- preg_match('~<script\s+[^<>]*src=["\']?([^"\']+)["\']?[^<>]*>\s*</script>~is', $script_tag, $match);
243
- $file = $match[1];
244
- $file = w3_normalize_file_minify2($file);
245
- $script_len = strlen($script_tag);
246
- if (!$this->_filter_files($file) || in_array($file, $handled_scripts)) {
247
- continue;
248
- }
249
- $handled_scripts[] = $file;
250
- if (in_array($file, $ignore_js_files)) {
251
- if ($tag_pos > $embed_pos) {
252
- if ($files_to_minify) {
253
- $script = $this->get_script_custom($files_to_minify, $embed_type);
254
- $buffer = substr_replace($buffer, $script, $embed_pos, 0);
255
- $files_to_minify = array();
256
- $script_len = $script_len +strlen($script);
257
- }
258
-
259
- $embed_pos = $embed_pos + $script_len;
260
- $previous_file_was_ignored = true;
261
- }
262
- } else {
263
- $buffer = substr_replace($buffer,'', $tag_pos, $script_len);
264
- if ($embed_pos > $tag_pos)
265
- $embed_pos -= $script_len;
266
- elseif ($previous_file_was_ignored)
267
- $embed_pos = $tag_pos;
268
- $files_to_minify[] = $file;
269
- }
270
- }
271
- $script = $this->get_script_custom($files_to_minify, $embed_type);
272
- $buffer = substr_replace($buffer, $script, $embed_pos, 0);
273
- }
274
  } else {
275
  if ($this->_config->get_boolean('minify.css.enable') && !in_array('include', $this->printed_styles)) {
276
  $style = $this->get_style_group('include');
165
  $embed_extsrcjs = false;
166
 
167
  if ($this->_config->get_boolean('minify.auto')) {
168
+ if ($this->_config->get_boolean('minify.js.enable')) {
169
+ $ignore_js_files = $this->_config->get_array('minify.reject.files.js');
170
+ $embed_type = $this->_config->get_string('minify.js.header.embed_type');
171
+ $embed_type = $embed_type == 'extsrc' || $embed_type == 'asyncsrc'?'blocking':$embed_type;
172
+
173
+ $embed_pos = strpos($buffer, '<!-- W3TC-include-js-head -->');
174
+ $buffer = str_replace('<!-- W3TC-include-js-head -->', '', $buffer);
175
+ if ($embed_pos === false) {
176
+ preg_match('~<head(\s+[^<>]+)*>~Ui', $buffer, $match, PREG_OFFSET_CAPTURE);
177
+ $embed_pos = strlen($match[0][0]) + $match[0][1];
178
+ }
179
+
180
+ $ignore_js_files = array_map('w3_normalize_file', $ignore_js_files);
181
+ $files_to_minify = array();
182
+ $handled_scripts = array();
183
+ $script_tags = w3_extract_js2($buffer);
184
+ $previous_file_was_ignored = false;
185
+ foreach ($script_tags as $script_tag) {
186
+ $tag_pos = strpos($buffer, $script_tag);
187
+ $match = array();
188
+ preg_match('~<script\s+[^<>]*src=["\']?([^"\']+)["\']?[^<>]*>\s*</script>~is', $script_tag, $match);
189
+ $file = $match[1];
190
+ $file = w3_normalize_file_minify2($file);
191
+ $script_len = strlen($script_tag);
192
+ if (!$this->_filter_files($file) || in_array($file, $handled_scripts)) {
193
+ continue;
194
+ }
195
+ $handled_scripts[] = $file;
196
+ if (in_array($file, $ignore_js_files)) {
197
+ if ($tag_pos > $embed_pos) {
198
+ if ($files_to_minify) {
199
+ $script = $this->get_script_custom($files_to_minify, $embed_type);
200
+ $buffer = substr_replace($buffer, $script, $embed_pos, 0);
201
+ $files_to_minify = array();
202
+ $script_len = $script_len +strlen($script);
203
+ }
204
+
205
+ $embed_pos = $embed_pos + $script_len;
206
+ $previous_file_was_ignored = true;
207
+ }
208
+ } else {
209
+ $buffer = substr_replace($buffer,'', $tag_pos, $script_len);
210
+ if ($embed_pos > $tag_pos)
211
+ $embed_pos -= $script_len;
212
+ elseif ($previous_file_was_ignored)
213
+ $embed_pos = $tag_pos;
214
+ $files_to_minify[] = $file;
215
+ }
216
+ }
217
+ $script = $this->get_script_custom($files_to_minify, $embed_type);
218
+ $buffer = substr_replace($buffer, $script, $embed_pos, 0);
219
+ }
220
+
221
  if ($this->_config->get_boolean('minify.css.enable')) {
222
  $ignore_css_files = $this->_config->get_array('minify.reject.files.css');
223
  $files_to_minify = array();
271
  $style = $this->get_style_custom($files_to_minify);
272
  $buffer = substr_replace($buffer, $style, $embed_pos, 0);
273
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  } else {
275
  if ($this->_config->get_boolean('minify.css.enable') && !in_array('include', $this->printed_styles)) {
276
  $style = $this->get_style_group('include');
lib/W3/Plugin/NewRelicAdmin.php CHANGED
@@ -61,12 +61,14 @@ class W3_Plugin_NewRelicAdmin extends W3_Plugin {
61
  * @var $nerser W3_NewRelicService
62
  */
63
  $nerser = w3_instance('W3_NewRelicService');
64
- $account_id = $nerser->get_account_id($api_key);
65
- if ($account_id) {
66
- $this->_config->set('newrelic.account_id', $account_id);
67
- $this->_config->save();
68
- echo $account_id;
69
- }
 
 
70
  die();
71
  }
72
 
@@ -83,12 +85,12 @@ class W3_Plugin_NewRelicAdmin extends W3_Plugin {
83
  $api_key = $config_master->get_string('newrelic.api_key');
84
  }
85
  $nerser = new W3_NewRelicService($api_key);
86
- if(empty($account_id) || $account_id == '')
87
- $account_id = $nerser->get_account_id();
88
  $newrelic_applications = array();
89
  try {
 
 
90
  $newrelic_applications = $nerser->get_applications($account_id);
91
- }catch(Exception $ex) {}
92
  echo json_encode($newrelic_applications);
93
  die();
94
  }
@@ -148,7 +150,7 @@ class W3_Plugin_NewRelicAdmin extends W3_Plugin {
148
  }
149
 
150
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
151
- w3_write_to_file($path, $data);
152
  }
153
 
154
  /**
61
  * @var $nerser W3_NewRelicService
62
  */
63
  $nerser = w3_instance('W3_NewRelicService');
64
+ try {
65
+ $account_id = $nerser->get_account_id($api_key);
66
+ if ($account_id) {
67
+ $this->_config->set('newrelic.account_id', $account_id);
68
+ $this->_config->save();
69
+ echo $account_id;
70
+ }
71
+ }catch (Exception $ex) {}
72
  die();
73
  }
74
 
85
  $api_key = $config_master->get_string('newrelic.api_key');
86
  }
87
  $nerser = new W3_NewRelicService($api_key);
 
 
88
  $newrelic_applications = array();
89
  try {
90
+ if(empty($account_id) || $account_id == '')
91
+ $account_id = $nerser->get_account_id();
92
  $newrelic_applications = $nerser->get_applications($account_id);
93
+ } catch (Exception $ex) {}
94
  echo json_encode($newrelic_applications);
95
  die();
96
  }
150
  }
151
 
152
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
153
+ w3_wp_write_to_file($path, $data);
154
  }
155
 
156
  /**
lib/W3/Plugin/PgCacheAdmin.php CHANGED
@@ -391,7 +391,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
391
  function enable_wp_cache() {
392
 
393
  $config_path = w3_get_wp_config_path();
394
- $config_data = w3_read_from_file($config_path);
395
 
396
  if ($config_data === false) {
397
  return false;
@@ -401,7 +401,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
401
  $new_config_data = preg_replace('~<\?(php)?~', "\\0\r\n/** Enable W3 Total Cache */\r\ndefine('WP_CACHE', true); // Added by W3 Total Cache\r\n", $new_config_data, 1);
402
 
403
  if ($new_config_data != $config_data) {
404
- w3_write_to_file($config_path, $new_config_data);
405
  }
406
 
407
  return true;
@@ -424,7 +424,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
424
  $new_config_data = $this->erase_wp_cache($config_data);
425
 
426
  if ($new_config_data != $config_data) {
427
- w3_write_to_file($config_path, $new_config_data);
428
  }
429
 
430
  return true;
@@ -1245,7 +1245,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
1245
  }
1246
 
1247
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1248
- w3_write_to_file($path, $data);
1249
  }
1250
 
1251
  /**
@@ -1308,7 +1308,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
1308
  }
1309
 
1310
  if ($use_fs) {
1311
- w3_write_to_file($path, $data);
1312
  } else {
1313
  if (!@file_put_contents($path, $data)) {
1314
  w3_throw_on_write_error($path);
@@ -1378,7 +1378,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
1378
  $data = $this->erase_rules_core($data);
1379
 
1380
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1381
- w3_write_to_file($path, $data);
1382
  }
1383
  }
1384
  }
@@ -1418,7 +1418,7 @@ class W3_Plugin_PgCacheAdmin extends W3_Plugin {
1418
  $data = $this->erase_rules_legacy($data);
1419
 
1420
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1421
- w3_write_to_file($path, $data);
1422
  }
1423
  }
1424
  }
391
  function enable_wp_cache() {
392
 
393
  $config_path = w3_get_wp_config_path();
394
+ $config_data = w3_wp_read_from_file($config_path);
395
 
396
  if ($config_data === false) {
397
  return false;
401
  $new_config_data = preg_replace('~<\?(php)?~', "\\0\r\n/** Enable W3 Total Cache */\r\ndefine('WP_CACHE', true); // Added by W3 Total Cache\r\n", $new_config_data, 1);
402
 
403
  if ($new_config_data != $config_data) {
404
+ w3_wp_write_to_file($config_path, $new_config_data);
405
  }
406
 
407
  return true;
424
  $new_config_data = $this->erase_wp_cache($config_data);
425
 
426
  if ($new_config_data != $config_data) {
427
+ w3_wp_write_to_file($config_path, $new_config_data);
428
  }
429
 
430
  return true;
1245
  }
1246
 
1247
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1248
+ w3_wp_write_to_file($path, $data);
1249
  }
1250
 
1251
  /**
1308
  }
1309
 
1310
  if ($use_fs) {
1311
+ w3_wp_write_to_file($path, $data);
1312
  } else {
1313
  if (!@file_put_contents($path, $data)) {
1314
  w3_throw_on_write_error($path);
1378
  $data = $this->erase_rules_core($data);
1379
 
1380
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1381
+ w3_wp_write_to_file($path, $data);
1382
  }
1383
  }
1384
  }
1418
  $data = $this->erase_rules_legacy($data);
1419
 
1420
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
1421
+ w3_wp_write_to_file($path, $data);
1422
  }
1423
  }
1424
  }
lib/W3/Plugin/TotalCacheAdmin.php CHANGED
@@ -158,6 +158,11 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
158
  */
159
  var $_ftp_form;
160
 
 
 
 
 
 
161
  /**
162
  * Runs plugin
163
  *
@@ -723,8 +728,10 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
723
  $old_value = (array) get_option('active_plugins');
724
 
725
  if ($new_value !== $old_value && in_array(W3TC_FILE, (array) $new_value) && in_array(W3TC_FILE, (array) $old_value)) {
726
- $this->_config->set('notes.plugins_updated', true);
727
- $this->_config->save();
 
 
728
  }
729
 
730
  return $new_value;
@@ -870,7 +877,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
870
  'pgcache_purge_page' => 'Unable to purge page.',
871
  'enable_cookie_domain' => sprintf('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', \'%s\');</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', ABSPATH, addslashes($cookie_domain)),
872
  'disable_cookie_domain' => sprintf('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', false);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', ABSPATH),
873
- 'cloudflare_api_request' => 'Unable to make CloudFlare API request.'
874
  );
875
 
876
  $note_messages = array(
@@ -975,18 +982,20 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
975
  try {
976
  $result_file = $w3_setup->try_create_wp_loader();
977
  } catch (TryException $ex) {
 
978
  $file_data = $w3_setup->w3tc_loader_file_data();
979
  $filename = $file_data['filename'];
980
  $data = $file_data['data'];
981
 
982
  $errors[] = sprintf('<p>Minify and support requests will not function because <strong>%s</strong>
983
- is outside the WordPress folder. The plugin needs to add file:
984
- <br /><em>%s</em> with the following content:</p>
985
  <pre>%s</pre>',
986
  dirname(W3TC_WP_LOADER), $filename,
987
  esc_textarea($data));
988
  $this->_ftp_form = $ex->getFtpForm();
989
  } catch (W3TCErrorException $ex) {
 
990
  $w3tc_error[] = $ex->getMessage();
991
  }
992
  }
@@ -997,7 +1006,9 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
997
  } catch (TryException $ex) {
998
  $add_in_files = $ex->getFiles();
999
  $this->_ftp_form = $ex->getFtpForm();
 
1000
  } catch (W3TCErrorException $ex) {
 
1001
  $w3tc_error[] = $ex->getMessage();
1002
  }
1003
 
@@ -1006,18 +1017,21 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1006
  } catch (TryException $ex) {
1007
  $cache_folders = $ex->getFiles();
1008
  $this->_ftp_form = $ex->getFtpForm();
 
1009
  } catch (W3TCErrorException $ex) {
1010
  $w3tc_error[] = $ex->getMessage();
 
1011
  } catch (TestException $ex) {
1012
  $results = $ex->getTestResults();
1013
  if (isset($results['permissions'])) {
1014
  $notes = array_merge($notes, $results['permissions']);
1015
  } else {
1016
- $errors[] = sprintf('<p>File and folder creation tests failed %s</p>
1017
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1018
  ,$this->button('View required changes', '', 'w3tc-show-required-changes')
1019
  , $w3_setup->format_test_result($results));
1020
  }
 
1021
  }
1022
 
1023
  if($add_in_files || $cache_folders) {
@@ -1060,12 +1074,12 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1060
  $folders .= '</ul>';
1061
  $errors[] = sprintf('<p><form method="POST" action="'.
1062
  esc_attr($_SERVER['REQUEST_URI']).'" style="display:inline;">
1063
- The plugin cannot create/save the config file to <strong>%s</strong>.
1064
- Folder could have wrong permissions.</p><p>Should the plugin remove the plugin
1065
- folders it has created and restart setup process? ' . wp_nonce_field('w3tc') .
1066
  '<input name="reset_folders" value="1" type="hidden" />
1067
- <input value="Yes, reset setup" type="submit" class="button-secondary"/>
1068
- </form></p><p>Folders that will be deleted:</p> %s'
1069
  , W3TC_CONFIG_DIR, $folders);
1070
  }
1071
  } catch(FilesystemCredentialException $ex) {
@@ -1075,8 +1089,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1075
  $not_installed .= '<li>' . $folder . '</li>';
1076
  $not_installed .= '</ul>';
1077
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1078
- $errors[] = sprintf('%s<p>Unfortunately we\'re not able to remove folders to complete
1079
- the reset for you automatically. Please enter FTP details
1080
  <a href="#ftp_upload_form">below</a> to complete the reset. %s</p>
1081
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
1082
  (($cache_folders) ? 'The <strong>%s</strong> directory is not write-able.': '') .
@@ -1095,8 +1108,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1095
  $not_installed .= '<li>' . $folder . '</li>';
1096
  $not_installed .= '</ul>';
1097
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1098
- $errors[] = sprintf('%s<p>Unfortunately we\'re not able to remove folders to complete
1099
- the reset for you automatically. %s</p>
1100
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1101
  , $headline
1102
  , $this->button('View required changes', '', 'w3tc-show-required-changes')
@@ -1105,8 +1117,10 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1105
  }
1106
  } catch (Exception $e) {}
1107
  }
1108
- } elseif (w3_get_blog_id() == 0
1109
- && (int)get_transient('test.verify_permissions') <= strtotime('-1 hours')) {
 
 
1110
  try {
1111
  $results = $w3_setup->test_file_writing();
1112
 
@@ -1114,7 +1128,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1114
  if (isset($results['permissions'])) {
1115
  $notes = array_merge($notes, $results['permissions']);
1116
  } else
1117
- $errors[] = sprintf('<p>File and folder creation tests failed %s</p>
1118
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1119
  , $this->button('View required changes', '', 'w3tc-show-required-changes')
1120
  , $w3_setup->format_test_result($results));
@@ -1124,28 +1138,22 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1124
  } catch(FilesystemCredentialException $ex) {
1125
  $form = $ex->ftp_form();
1126
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1127
- $errors[] = sprintf('%s<p>We need permission to change folder permissions for you
1128
- automatically. Please enter FTP details <a href="#ftp_upload_form">below</a>
1129
- to complete the reset. %s</p>
1130
- <div class="w3tc-required-changes" style="display:none">%s</div>',
1131
- $headline, WP_CONTENT_DIR, 'what is to be done');
1132
-
1133
- $this->_ftp_form = '<div id="ftp_upload_form" class="updated fade"
1134
- style="background: none;border: none;">' .
1135
  str_replace('class="wrap"', '',$form) . '</div>';
1136
  $this->_use_ftp_form = true;
1137
  } catch (FileOperationException $ex) {
1138
- $errors[] = '<p>Unfortunately we\'re not able to chmod folders to setup folders properly.</p>';
1139
-
1140
  }
1141
  }
1142
  }
1143
 
1144
- if (!$this->_config->own_config_exists() && empty($cache_folders) &&
1145
  strpos(W3_Request::get_string('page'), 'w3tc_') !== false)
1146
- $w3tc_error[] = sprintf('<strong>W3 Total Cache Error:</strong> Default settings are in use.
1147
- The configuration file could not be read or doesn\'t exist. Please %s to create the
1148
- file.'
1149
  , $this->button_link('save the settings'
1150
  , wp_nonce_url(sprintf('admin.php?page=%s&w3tc_save_config', $this->_page)
1151
  , 'w3tc')));
@@ -1326,10 +1334,10 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1326
  $this->_use_ftp_form = true;
1327
  $instruction = '. Please enter FTP details <a href="#ftp_upload_form">below</a> to complete the deactivation.';
1328
  } else {
1329
- $instruction = ' due to the <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">permission settings</a> on your files and folders.';
1330
  }
1331
  $headline = '<h2 id="w3tc">W3 Total Cache Error</h2>';
1332
- $errors[] = sprintf('%s<p>Unfortunately we\'re not able to remove folders and files or write to them to complete the uninstallation for you automatically%s %s</p>
1333
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
1334
  'This error message will automatically disappear once the change is successfully made.</p>
1335
  ',$headline, $instruction, $this->button('View required changes', '', 'w3tc-show-required-changes'), $error_list, WP_CONTENT_DIR);
@@ -1378,8 +1386,8 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1378
  /**
1379
  * Check for page cache availability
1380
  */
 
1381
  if ($this->_config->get_boolean('pgcache.enabled')) {
1382
-
1383
  if ((!defined('WP_CACHE') || !WP_CACHE)) {
1384
  try {
1385
  $w3_plugin_admin = w3_instance('W3_Plugin_PgCacheAdmin');
@@ -1392,13 +1400,16 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1392
  $ftp_message = ' Or use the <a href="#ftp_upload_form">FTP form</a> below.';
1393
  } elseif ($e instanceof FileOperationException) {
1394
  $file_operation_exception = true;
 
1395
  }
1396
- $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%s</strong>. %s', w3_get_wp_config_path(), $ftp_message) ;
 
1397
  }
1398
  }
1399
 
1400
  if (!$w3_verify->advanced_cache_check()) {
1401
- $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
 
1402
  } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
1403
  $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
1404
 
@@ -1534,7 +1545,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1534
  $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
1535
 
1536
  if ($w3_plugin_minify->check_rules_core()) {
1537
- if (!$this->test_rewrite_minify()) {
1538
  $this->_errors[] = 'It appears Minify <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess. Or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx).';
1539
  }
1540
 
@@ -1722,8 +1733,8 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1722
  * Check for database cache availability
1723
  */
1724
  if ($this->_config->get_boolean('dbcache.enabled')) {
1725
- if (!$w3_verify->db_check()) {
1726
- $this->_errors[] = sprintf('Database caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_DB);
1727
  }
1728
  }
1729
 
@@ -1731,8 +1742,8 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1731
  * Check for object cache availability
1732
  */
1733
  if ($this->_config->get_boolean('objectcache.enabled')) {
1734
- if (!$w3_verify->objectcache_check()) {
1735
- $this->_errors[] = sprintf('Object caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_OBJECT_CACHE);
1736
  }
1737
  }
1738
 
@@ -1819,13 +1830,13 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1819
  if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
1820
  $wp_content_mode = w3_get_file_permissions(WP_CONTENT_DIR);
1821
 
1822
- if ($wp_content_mode > 755) {
1823
  $this->_notes[] = sprintf('<strong>%s</strong> is write-able. When finished installing the plugin,
1824
  change the permissions back to the default: <strong>chmod 755 %s</strong>.
1825
  Permissions are currently %s. %s'
1826
  , WP_CONTENT_DIR
1827
  , WP_CONTENT_DIR
1828
- , w3_get_file_permissions(WP_CONTENT_DIR)
1829
  , $this->button_hide_note('Hide this message', 'wp_content_perms'));
1830
  }
1831
  }
@@ -1836,12 +1847,12 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
1836
  if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_changed_perms')) {
1837
  $perm = get_transient('w3tc_prev_permission');
1838
  $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
1839
- if ($perm && $perm != $current_perm && ($current_perm > 0755 || $perm < $current_perm)) {
1840
  $this->_notes[] = sprintf('<strong>%s</strong> permissions were changed during the setup process.
1841
  Permissions are currently %s.<br />To restore permissions run
1842
  <strong>chmod %s %s</strong>. %s'
1843
  , WP_CONTENT_DIR
1844
- , $current_perm
1845
  , $perm
1846
  , WP_CONTENT_DIR
1847
  , $this->button_hide_note('Hide this message', 'wp_content_changed_perms'));
@@ -2016,47 +2027,66 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
2016
  $this->_rule_errors_root = array();
2017
  }
2018
 
2019
- if (isset($file_operation_exception) && $file_operation_exception) {
 
 
2020
  $tech_message = '<ul>';
2021
  $core_rules_perms = '';
2022
- if (w3_get_file_permissions(w3_get_pgcache_rules_core_path()) != '0644')
2023
- $core_rules_perms = sprintf('File permissions are <strong>%s</strong> should be
2024
- <strong>0644</strong>.'
2025
- , w3_get_file_permissions(w3_get_pgcache_rules_core_path())
 
 
 
 
 
 
 
 
2026
  );
 
 
 
2027
  $wp_content_perms = '';
2028
- if (w3_get_file_permissions(WP_CONTENT_DIR) != '0755')
2029
- $wp_content_perms = sprintf('Folder permissions are <strong>%s</strong> should be
2030
- <strong>0755</strong>.'
2031
- , w3_get_file_permissions(WP_CONTENT_DIR)
2032
  );
2033
-
2034
  $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s'
2035
- ,w3_get_pgcache_rules_core_path()
2036
- ,$core_rules_perms
2037
- , w3_get_file_owner(w3_get_pgcache_rules_core_path())) .
2038
- '</li>' ;
 
2039
  $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s'
 
 
 
 
 
 
2040
  , WP_CONTENT_DIR
2041
  , $wp_content_perms
2042
  , w3_get_file_owner(WP_CONTENT_DIR)) .
2043
  '</li>' ;
2044
- $tech_message .= '<li>' . sprintf('File owner of current script: %s', w3_get_file_owner()) .
 
2045
  '</li>' ;
2046
  if (!(w3_get_file_owner() == w3_get_file_owner(w3_get_pgcache_rules_core_path()) &&
2047
  w3_get_file_owner() == w3_get_file_owner(WP_CONTENT_DIR)))
2048
- $tech_message .= '<li>The files and folders have different owners. They should have the same owners.
2049
  </li>';
2050
  $tech_message .= '</ul>';
2051
  $tech_message = '<div class="w3tc-technical-info" style="display:none">' . $tech_message . '</div>';
2052
  $w3tc_error[] = sprintf('<strong>W3 Total Cache Error:</strong> The plugin tried to edit, %s, but failed.
2053
- This means that the plugin cannot make the correct file/folder changes on its own.
2054
- Please review your
2055
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
2056
- file permissions</a> (file owner, rights ...).
2057
- Common cause is %s and %s having different owners or permissions. %s %s'
2058
- , w3_get_pgcache_rules_core_path()
2059
- , basename(w3_get_pgcache_rules_core_path())
2060
  , WP_CONTENT_DIR
2061
  , $this->button('View technical information', '', 'w3tc-show-technical-info')
2062
  ,$tech_message);
@@ -2069,8 +2099,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
2069
  foreach ($remove_results as $result) {
2070
  $this->_errors = array_merge($this->_errors, $result['errors']);
2071
  if (!isset($this->_ftp_form) && isset($result['ftp_form'])) {
2072
- $extra_ftp_message = 'Please enter FTP details <a href="#ftp_upload_form">below</a> to complete
2073
- the removal of disabled modules. ';
2074
  $this->_ftp_form = $result['ftp_form'];
2075
  $this->_use_ftp_form = true;
2076
  }
@@ -2853,16 +2882,10 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
2853
  ), true);
2854
  }
2855
 
2856
- if ($this->config_save($config, $this->_config_admin)) {
2857
- $this->redirect(array(
2858
- 'w3tc_note' => 'config_import'
2859
- ), true);
2860
-
2861
- } else {
2862
- $this->redirect(array(
2863
- 'w3tc_error' => 'config_save'
2864
- ), true);
2865
- }
2866
  }
2867
 
2868
  /**
@@ -2884,7 +2907,6 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
2884
  function action_config_reset() {
2885
  @$config = new W3_Config();
2886
  $config->set_defaults();
2887
-
2888
  $this->config_save($config, $this->_config_admin);
2889
  $this->redirect(array(
2890
  'w3tc_note' => 'config_reset'
@@ -2900,7 +2922,6 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
2900
  $this->_config->preview_production_copy(-1);
2901
  $this->_config_admin->set('previewmode.enabled', true);
2902
  $this->_config_admin->save();
2903
-
2904
  $this->redirect(array(
2905
  'w3tc_note' => 'preview_enable'
2906
  ));
@@ -3795,7 +3816,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
3795
  w3_throw_on_write_error(W3TC_FILE_DB_CLUSTER_CONFIG);
3796
  } catch (Exception $e) {
3797
  $error = $e->getMessage();
3798
- $this->redirect_with_custom_messages($params, array($error));
3799
  }
3800
  }
3801
 
@@ -4125,7 +4146,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
4125
  $config->set('newrelic.appname', $appname);
4126
  }
4127
  } else if ($method == 'manual' && $config->get_string('newrelic.appname')) {
4128
- if (strpos($config->get_string('newrelic.appname'), $newrelic_prefix) === false) {
4129
  $application_name = $newrelic_prefix . $config->get_string('newrelic.appname');
4130
  $config->set('newrelic.appname', $application_name);
4131
  } else
@@ -4522,7 +4543,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
4522
  $this->_config->save();
4523
  $this->redirect(array(
4524
  'w3tc_note' => 'config_save'
4525
- ), true);
4526
  }
4527
 
4528
  /**
@@ -4537,13 +4558,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
4537
  $this->_config->set('common.support', $support);
4538
  $this->_config->set('common.tweeted', $tweeted);
4539
 
4540
- try {
4541
- $this->_config->save();
4542
- }catch(Exception $ex) {
4543
- $this->redirect(array(
4544
- 'w3tc_error' => 'config_save'
4545
- ));
4546
- }
4547
 
4548
  $this->link_update();
4549
 
@@ -5412,9 +5427,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
5412
  if ($this->_config->get_string('pgcache.engine') == $type && $this->_config->get_boolean('pgcache.enabled')) {
5413
  $this->_config->set('notes.need_empty_pgcache', false);
5414
  $this->_config->set('notes.plugins_updated', false);
5415
-
5416
  $this->_config->save();
5417
-
5418
  $this->flush_pgcache();
5419
  }
5420
 
@@ -5432,9 +5445,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
5432
 
5433
  if ($this->_config->get_string('minify.engine') == $type && $this->_config->get_boolean('minify.enabled')) {
5434
  $this->_config->set('notes.need_empty_minify', false);
5435
-
5436
  $this->_config->save();
5437
-
5438
  $this->flush_minify();
5439
  }
5440
  }
@@ -5551,6 +5562,7 @@ class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
5551
  function flush_browser_cache() {
5552
  if ($this->_config->get_boolean('browsercache.enabled')) {
5553
  $this->_config->set('browsercache.timestamp', time());
 
5554
  $this->_config->save();
5555
  }
5556
  }
158
  */
159
  var $_ftp_form;
160
 
161
+ var $_disable_cache_write_notification = false;
162
+ var $_disable_add_in_files_notification = false;
163
+ var $_disable_minify_error_notification = false;
164
+ var $_disable_file_operation_notification = false;
165
+
166
  /**
167
  * Runs plugin
168
  *
728
  $old_value = (array) get_option('active_plugins');
729
 
730
  if ($new_value !== $old_value && in_array(W3TC_FILE, (array) $new_value) && in_array(W3TC_FILE, (array) $old_value)) {
731
+ $this->_config->set('notes.plugins_updated', true);
732
+ try {
733
+ $this->_config->save();
734
+ } catch(Exception $ex) {}
735
  }
736
 
737
  return $new_value;
877
  'pgcache_purge_page' => 'Unable to purge page.',
878
  'enable_cookie_domain' => sprintf('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', \'%s\');</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', ABSPATH, addslashes($cookie_domain)),
879
  'disable_cookie_domain' => sprintf('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', false);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', ABSPATH),
880
+ 'cloudflare_api_request' => 'Unable to make CloudFlare API request.',
881
  );
882
 
883
  $note_messages = array(
982
  try {
983
  $result_file = $w3_setup->try_create_wp_loader();
984
  } catch (TryException $ex) {
985
+ $this->_disable_minify_error_notification = true;
986
  $file_data = $w3_setup->w3tc_loader_file_data();
987
  $filename = $file_data['filename'];
988
  $data = $file_data['data'];
989
 
990
  $errors[] = sprintf('<p>Minify and support requests will not function because <strong>%s</strong>
991
+ is outside the WordPress directory. The plugin needs to add file:
992
+ <br /><em>%s</em> with the following contents:</p>
993
  <pre>%s</pre>',
994
  dirname(W3TC_WP_LOADER), $filename,
995
  esc_textarea($data));
996
  $this->_ftp_form = $ex->getFtpForm();
997
  } catch (W3TCErrorException $ex) {
998
+ $this->_disable_minify_error_notification = true;
999
  $w3tc_error[] = $ex->getMessage();
1000
  }
1001
  }
1006
  } catch (TryException $ex) {
1007
  $add_in_files = $ex->getFiles();
1008
  $this->_ftp_form = $ex->getFtpForm();
1009
+ $this->_disable_add_in_files_notification = true;
1010
  } catch (W3TCErrorException $ex) {
1011
+ $this->_disable_add_in_files_notification = true;
1012
  $w3tc_error[] = $ex->getMessage();
1013
  }
1014
 
1017
  } catch (TryException $ex) {
1018
  $cache_folders = $ex->getFiles();
1019
  $this->_ftp_form = $ex->getFtpForm();
1020
+ $this->_disable_cache_write_notification = true;
1021
  } catch (W3TCErrorException $ex) {
1022
  $w3tc_error[] = $ex->getMessage();
1023
+ $this->_disable_cache_write_notification = true;
1024
  } catch (TestException $ex) {
1025
  $results = $ex->getTestResults();
1026
  if (isset($results['permissions'])) {
1027
  $notes = array_merge($notes, $results['permissions']);
1028
  } else {
1029
+ $errors[] = sprintf('<p>File and directory creation tests failed %s</p>
1030
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1031
  ,$this->button('View required changes', '', 'w3tc-show-required-changes')
1032
  , $w3_setup->format_test_result($results));
1033
  }
1034
+ $this->_disable_cache_write_notification = true;
1035
  }
1036
 
1037
  if($add_in_files || $cache_folders) {
1074
  $folders .= '</ul>';
1075
  $errors[] = sprintf('<p><form method="POST" action="'.
1076
  esc_attr($_SERVER['REQUEST_URI']).'" style="display:inline;">
1077
+ The plugin cannot create / save the config file to <strong>%s</strong>.
1078
+ Directory may have incorrect permissions.</p><p>Should the plugin remove the plugin
1079
+ directories it has created and restart setup process? ' . wp_nonce_field('w3tc') .
1080
  '<input name="reset_folders" value="1" type="hidden" />
1081
+ <input value="Yes, restart setup" type="submit" class="button-secondary"/>
1082
+ </form></p><p>Directories that will be deleted:</p> %s'
1083
  , W3TC_CONFIG_DIR, $folders);
1084
  }
1085
  } catch(FilesystemCredentialException $ex) {
1089
  $not_installed .= '<li>' . $folder . '</li>';
1090
  $not_installed .= '</ul>';
1091
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1092
+ $errors[] = sprintf('%s<p>Directories could not be removed automatically. Please enter FTP details
 
1093
  <a href="#ftp_upload_form">below</a> to complete the reset. %s</p>
1094
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
1095
  (($cache_folders) ? 'The <strong>%s</strong> directory is not write-able.': '') .
1108
  $not_installed .= '<li>' . $folder . '</li>';
1109
  $not_installed .= '</ul>';
1110
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1111
+ $errors[] = sprintf('%s<p>Directories could not be removed automatically. %s</p>
 
1112
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1113
  , $headline
1114
  , $this->button('View required changes', '', 'w3tc-show-required-changes')
1117
  }
1118
  } catch (Exception $e) {}
1119
  }
1120
+ } elseif ((!defined('W3TC_DISABLE_VERIFY_PERMISSIONS') ||
1121
+ (defined('W3TC_DISABLE_VERIFY_PERMISSIONS') && !W3TC_DISABLE_VERIFY_PERMISSIONS)
1122
+ ) && w3_get_blog_id() == 0 && (int)get_transient('test.verify_permissions') <= strtotime('-1 hours')) {
1123
+ w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/activation.php');
1124
  try {
1125
  $results = $w3_setup->test_file_writing();
1126
 
1128
  if (isset($results['permissions'])) {
1129
  $notes = array_merge($notes, $results['permissions']);
1130
  } else
1131
+ $errors[] = sprintf('<p>File and directory creation tests failed %s</p>
1132
  <div class="w3tc-required-changes" style="display:none">%s</div>'
1133
  , $this->button('View required changes', '', 'w3tc-show-required-changes')
1134
  , $w3_setup->format_test_result($results));
1138
  } catch(FilesystemCredentialException $ex) {
1139
  $form = $ex->ftp_form();
1140
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
1141
+ $errors[] = sprintf('%s<p>The creation of cache / configuration files failed. <br />The directories with incorrect permissions are: <em>%s</em> and %s. Currently directory permissions are: %s. Please enter FTP details <a href="#ftp_upload_form">below</a> to automatically resolve the issue.</p>',
1142
+ $headline, W3TC_CACHE_DIR, W3TC_CONFIG_DIR, base_convert(w3_get_file_permissions(W3TC_CACHE_DIR), 10, 8));
1143
+
1144
+ $this->_ftp_form = '<div id="ftp_upload_form" class="updated fade" style="background:none;border:none;">' .
 
 
 
 
1145
  str_replace('class="wrap"', '',$form) . '</div>';
1146
  $this->_use_ftp_form = true;
1147
  } catch (FileOperationException $ex) {
1148
+ $errors[] = sprintf('<p>The creation of cache / configuration files failed. Unfortunately we\'re not able to change permissions from %s:<br /> <em>%s</em> <br /><em>%s</em><br />Directories typically should have at least 755 permissions. If it fails try 775 or 777 until this notification disappears.</p>',
1149
+ base_convert(w3_get_file_permissions(W3TC_CACHE_DIR), 10, 8), W3TC_CACHE_DIR, W3TC_CONFIG_DIR);
1150
  }
1151
  }
1152
  }
1153
 
1154
+ if (!$this->_disable_cache_write_notification && !$this->_config->own_config_exists() && empty($cache_folders) &&
1155
  strpos(W3_Request::get_string('page'), 'w3tc_') !== false)
1156
+ $w3tc_error[] = sprintf('<strong>W3 Total Cache Error:</strong> Default settings are in use. The configuration file could not be read or doesn\'t exist. Please %s to create the file.'
 
 
1157
  , $this->button_link('save the settings'
1158
  , wp_nonce_url(sprintf('admin.php?page=%s&w3tc_save_config', $this->_page)
1159
  , 'w3tc')));
1334
  $this->_use_ftp_form = true;
1335
  $instruction = '. Please enter FTP details <a href="#ftp_upload_form">below</a> to complete the deactivation.';
1336
  } else {
1337
+ $instruction = ' due to the <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">permission settings</a> on your files and directories.';
1338
  }
1339
  $headline = '<h2 id="w3tc">W3 Total Cache Error</h2>';
1340
+ $errors[] = sprintf('%s<p>Unfortunately directories and files could not be automatically removed to complete the uninstallation%s %s</p>
1341
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
1342
  'This error message will automatically disappear once the change is successfully made.</p>
1343
  ',$headline, $instruction, $this->button('View required changes', '', 'w3tc-show-required-changes'), $error_list, WP_CONTENT_DIR);
1386
  /**
1387
  * Check for page cache availability
1388
  */
1389
+ $wp_config_edit = false;
1390
  if ($this->_config->get_boolean('pgcache.enabled')) {
 
1391
  if ((!defined('WP_CACHE') || !WP_CACHE)) {
1392
  try {
1393
  $w3_plugin_admin = w3_instance('W3_Plugin_PgCacheAdmin');
1400
  $ftp_message = ' Or use the <a href="#ftp_upload_form">FTP form</a> below.';
1401
  } elseif ($e instanceof FileOperationException) {
1402
  $file_operation_exception = true;
1403
+ $wp_config_edit = true;
1404
  }
1405
+ if (!$this->_disable_add_in_files_notification)
1406
+ $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%s</strong>. %s', w3_get_wp_config_path(), $ftp_message) ;
1407
  }
1408
  }
1409
 
1410
  if (!$w3_verify->advanced_cache_check()) {
1411
+ if (!$this->_disable_add_in_files_notification)
1412
+ $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
1413
  } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
1414
  $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
1415
 
1545
  $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
1546
 
1547
  if ($w3_plugin_minify->check_rules_core()) {
1548
+ if (!$this->test_rewrite_minify() && (!w3_is_multisite() || (w3_is_multisite() && w3_get_blog_id() != 0))) {
1549
  $this->_errors[] = 'It appears Minify <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess. Or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx).';
1550
  }
1551
 
1733
  * Check for database cache availability
1734
  */
1735
  if ($this->_config->get_boolean('dbcache.enabled')) {
1736
+ if (!$this->_disable_add_in_files_notification && !$w3_verify->db_check()) {
1737
+ $this->_errors[] = sprintf('Database caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_DB);
1738
  }
1739
  }
1740
 
1742
  * Check for object cache availability
1743
  */
1744
  if ($this->_config->get_boolean('objectcache.enabled')) {
1745
+ if (!$this->_disable_add_in_files_notification && !$w3_verify->objectcache_check()) {
1746
+ $this->_errors[] = sprintf('Object caching is not available. The current add-in %s is either missing, an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_OBJECT_CACHE);
1747
  }
1748
  }
1749
 
1830
  if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
1831
  $wp_content_mode = w3_get_file_permissions(WP_CONTENT_DIR);
1832
 
1833
+ if ($wp_content_mode > 0755) {
1834
  $this->_notes[] = sprintf('<strong>%s</strong> is write-able. When finished installing the plugin,
1835
  change the permissions back to the default: <strong>chmod 755 %s</strong>.
1836
  Permissions are currently %s. %s'
1837
  , WP_CONTENT_DIR
1838
  , WP_CONTENT_DIR
1839
+ , base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8)
1840
  , $this->button_hide_note('Hide this message', 'wp_content_perms'));
1841
  }
1842
  }
1847
  if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_changed_perms')) {
1848
  $perm = get_transient('w3tc_prev_permission');
1849
  $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
1850
+ if ($perm && $perm != base_convert($current_perm, 10, 8) && ($current_perm > 0755 || $perm < base_convert($current_perm, 10, 8))) {
1851
  $this->_notes[] = sprintf('<strong>%s</strong> permissions were changed during the setup process.
1852
  Permissions are currently %s.<br />To restore permissions run
1853
  <strong>chmod %s %s</strong>. %s'
1854
  , WP_CONTENT_DIR
1855
+ , base_convert($current_perm, 10, 8)
1856
  , $perm
1857
  , WP_CONTENT_DIR
1858
  , $this->button_hide_note('Hide this message', 'wp_content_changed_perms'));
2027
  $this->_rule_errors_root = array();
2028
  }
2029
 
2030
+ $this->_disable_file_operation_notification = $this->_disable_add_in_files_notification || $this->_disable_cache_write_notification;
2031
+
2032
+ if (!$this->_disable_file_operation_notification && isset($file_operation_exception) && $file_operation_exception) {
2033
  $tech_message = '<ul>';
2034
  $core_rules_perms = '';
2035
+ if (w3_get_file_permissions(w3_get_wp_config_path()) != 0644)
2036
+ $core_config_perms = sprintf('File permissions are <strong>%s</strong>, however they should be
2037
+ <strong>644</strong>.'
2038
+ , base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8)
2039
+ );
2040
+ else
2041
+ $core_config_perms = sprintf('File permissions are <strong>%s</strong>', base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8));
2042
+
2043
+ if (w3_get_file_permissions(w3_get_pgcache_rules_core_path()) != 0644)
2044
+ $core_rules_perms = sprintf('File permissions are <strong>%s</strong>, however they should be
2045
+ <strong>644</strong>.'
2046
+ , base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8)
2047
  );
2048
+ else
2049
+ $core_rules_perms = sprintf('File permissions are <strong>%s</strong>', base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8));
2050
+
2051
  $wp_content_perms = '';
2052
+ if (w3_get_file_permissions(WP_CONTENT_DIR) != 0755)
2053
+ $wp_content_perms = sprintf('Directory permissions are <strong>%s</strong>, however they should be
2054
+ <strong>755</strong>.'
2055
+ , base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8)
2056
  );
 
2057
  $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s'
2058
+ ,w3_get_wp_config_path()
2059
+ ,$core_config_perms
2060
+ , w3_get_file_owner(w3_get_wp_config_path())) .
2061
+ '</li>' ;
2062
+
2063
  $tech_message .= '<li>' . sprintf('File: <strong>%s</strong> %s File owner: %s'
2064
+ ,w3_get_pgcache_rules_core_path()
2065
+ ,$core_rules_perms
2066
+ , w3_get_file_owner(w3_get_pgcache_rules_core_path())) .
2067
+ '</li>' ;
2068
+
2069
+ $tech_message .= '<li>' . sprintf('Directory: <strong>%s</strong> %s File owner: %s'
2070
  , WP_CONTENT_DIR
2071
  , $wp_content_perms
2072
  , w3_get_file_owner(WP_CONTENT_DIR)) .
2073
  '</li>' ;
2074
+
2075
+ $tech_message .= '<li>' . sprintf('Owner of current file: %s', w3_get_file_owner()) .
2076
  '</li>' ;
2077
  if (!(w3_get_file_owner() == w3_get_file_owner(w3_get_pgcache_rules_core_path()) &&
2078
  w3_get_file_owner() == w3_get_file_owner(WP_CONTENT_DIR)))
2079
+ $tech_message .= '<li>The files and directories have different ownership, they should have the same ownership.
2080
  </li>';
2081
  $tech_message .= '</ul>';
2082
  $tech_message = '<div class="w3tc-technical-info" style="display:none">' . $tech_message . '</div>';
2083
  $w3tc_error[] = sprintf('<strong>W3 Total Cache Error:</strong> The plugin tried to edit, %s, but failed.
2084
+ Files and directories cannot be modified. Please review your
 
2085
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
2086
+ file permissions</a>. A common cause is %s and %s having different ownership or permissions.
2087
+ %s %s'
2088
+ , $wp_config_edit ? w3_get_wp_config_path() : w3_get_pgcache_rules_core_path()
2089
+ , $wp_config_edit ? basename(w3_get_wp_config_path()) : basename(w3_get_pgcache_rules_core_path())
2090
  , WP_CONTENT_DIR
2091
  , $this->button('View technical information', '', 'w3tc-show-technical-info')
2092
  ,$tech_message);
2099
  foreach ($remove_results as $result) {
2100
  $this->_errors = array_merge($this->_errors, $result['errors']);
2101
  if (!isset($this->_ftp_form) && isset($result['ftp_form'])) {
2102
+ $extra_ftp_message = 'Please enter FTP details <a href="#ftp_upload_form">below</a> to remove the disabled modules. ';
 
2103
  $this->_ftp_form = $result['ftp_form'];
2104
  $this->_use_ftp_form = true;
2105
  }
2882
  ), true);
2883
  }
2884
 
2885
+ $this->config_save($config, $this->_config_admin);
2886
+ $this->redirect(array(
2887
+ 'w3tc_note' => 'config_import'
2888
+ ), true);
 
 
 
 
 
 
2889
  }
2890
 
2891
  /**
2907
  function action_config_reset() {
2908
  @$config = new W3_Config();
2909
  $config->set_defaults();
 
2910
  $this->config_save($config, $this->_config_admin);
2911
  $this->redirect(array(
2912
  'w3tc_note' => 'config_reset'
2922
  $this->_config->preview_production_copy(-1);
2923
  $this->_config_admin->set('previewmode.enabled', true);
2924
  $this->_config_admin->save();
 
2925
  $this->redirect(array(
2926
  'w3tc_note' => 'preview_enable'
2927
  ));
3816
  w3_throw_on_write_error(W3TC_FILE_DB_CLUSTER_CONFIG);
3817
  } catch (Exception $e) {
3818
  $error = $e->getMessage();
3819
+ $this->redirect_with_custom_messages($params, array($error));
3820
  }
3821
  }
3822
 
4146
  $config->set('newrelic.appname', $appname);
4147
  }
4148
  } else if ($method == 'manual' && $config->get_string('newrelic.appname')) {
4149
+ if ($newrelic_prefix != '' && strpos($config->get_string('newrelic.appname'), $newrelic_prefix) === false) {
4150
  $application_name = $newrelic_prefix . $config->get_string('newrelic.appname');
4151
  $config->set('newrelic.appname', $application_name);
4152
  } else
4543
  $this->_config->save();
4544
  $this->redirect(array(
4545
  'w3tc_note' => 'config_save'
4546
+ ), true);
4547
  }
4548
 
4549
  /**
4558
  $this->_config->set('common.support', $support);
4559
  $this->_config->set('common.tweeted', $tweeted);
4560
 
4561
+ $this->_config->save();
 
 
 
 
 
 
4562
 
4563
  $this->link_update();
4564
 
5427
  if ($this->_config->get_string('pgcache.engine') == $type && $this->_config->get_boolean('pgcache.enabled')) {
5428
  $this->_config->set('notes.need_empty_pgcache', false);
5429
  $this->_config->set('notes.plugins_updated', false);
 
5430
  $this->_config->save();
 
5431
  $this->flush_pgcache();
5432
  }
5433
 
5445
 
5446
  if ($this->_config->get_string('minify.engine') == $type && $this->_config->get_boolean('minify.enabled')) {
5447
  $this->_config->set('notes.need_empty_minify', false);
 
5448
  $this->_config->save();
 
5449
  $this->flush_minify();
5450
  }
5451
  }
5562
  function flush_browser_cache() {
5563
  if ($this->_config->get_boolean('browsercache.enabled')) {
5564
  $this->_config->set('browsercache.timestamp', time());
5565
+
5566
  $this->_config->save();
5567
  }
5568
  }
lib/W3/Plugins.php CHANGED
@@ -212,7 +212,7 @@ class W3_Plugins {
212
  $ftp_form = $e->ftp_form();
213
  }
214
  foreach($dirs as $folder)
215
- if (file_exists($folder))
216
  $errors[] = sprintf('Delete folder: <strong>%s</strong>',$folder);
217
 
218
  return array('errors' => $errors, 'ftp_form' => $ftp_form);
212
  $ftp_form = $e->ftp_form();
213
  }
214
  foreach($dirs as $folder)
215
+ if (@is_dir($folder))
216
  $errors[] = sprintf('Delete folder: <strong>%s</strong>',$folder);
217
 
218
  return array('errors' => $errors, 'ftp_form' => $ftp_form);
lib/W3/Setup.php CHANGED
@@ -8,7 +8,7 @@ class W3_Setup {
8
  const WPFS_CHMOD = 'wp filesystem chmod';
9
  private static $test_dir;
10
  function __construct() {
11
- self::$test_dir = W3TC_CACHE_DIR . DIRECTORY_SEPARATOR . '/test_dir';
12
  }
13
 
14
  function get_setup_message($cache_folders, $addin_files, $ftp_form) {
@@ -25,16 +25,18 @@ class W3_Setup {
25
 
26
  $not_installed .= '</ul>';
27
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
28
- $error = sprintf('%s<p>Unfortunately we\'re not able to create folders and files or write to them to complete
29
- the installation for you automatically. Please enter FTP details
30
- <a href="#ftp_upload_form">below</a> to complete the setup. %s</p>
31
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
32
  (($cache_folders || $addin_files) ?
33
  'Either the <strong>%s</strong> directory is not write-able or another caching plugin
34
  is installed.'
35
  : '') .
36
  'This error message will automatically disappear once the change is successfully made.</p>'
37
- , $headline, $this->button('View required changes', '', 'w3tc-show-required-changes')
 
 
38
  , $not_installed, WP_CONTENT_DIR);
39
  if ($pagenow == 'plugins.php') {
40
  $ftp_form = '<div id="ftp_upload_form" class="updated fade" style="background: none;border: none;">' .
@@ -72,11 +74,8 @@ class W3_Setup {
72
  }
73
 
74
  public function try_create_missing_files() {
75
- $prev_perm = get_transient('w3tc_prev_permission');
76
- if (!$prev_perm) {
77
- $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
78
- set_transient('w3tc_prev_permission', $prev_perm, 3600*24);
79
- }
80
  /**
81
  * @var $w3_verify W3_FileVerification
82
  */
@@ -87,10 +86,10 @@ class W3_Setup {
87
  return true;
88
  $addin_files = $result_verify['files'];
89
  $url = w3_is_network() ?
90
- network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general');
91
  try {
92
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
93
- w3_create_files($addin_files, '', $url);
94
  } catch(Exception $ex) {
95
  if ($ex instanceof FilesystemCredentialException) {
96
  throw new TryException('Could not create files', $result_verify, $ex->ftp_form());
@@ -102,20 +101,26 @@ class W3_Setup {
102
  if ($ex instanceof FilesystemCredentialException) {
103
  throw new TryException('Could not create files', $result_verify, $ex->ftp_form());
104
  } else {
105
- if ($ex instanceof FileOperationException && $ex->getOperation() == 'chmod') {
106
- $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
107
  throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Could not
108
- change permissions %d on %s back to original permissions %d.'
109
- , $current_perm, WP_CONTENT_DIR, $prev_perm));
110
  }else
111
- throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> %s<br />
 
 
 
 
 
112
  Verify that correct (server, S/FTP)
113
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
114
  file permissions</a>
115
- are set or set FS_CHMOD_* constants in wp-config.php
116
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
117
- Learn more</a>.'
118
- , $ex->getMessage()));
 
119
  }
120
  }
121
  }
@@ -124,11 +129,7 @@ class W3_Setup {
124
  }
125
 
126
  public function try_create_missing_folders() {
127
- $prev_perm = get_transient('w3tc_prev_permission');
128
- if (!$prev_perm) {
129
- $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
130
- set_transient('w3tc_prev_permission', $prev_perm, 3600);
131
- }
132
 
133
  /**
134
  * @var $w3_verify W3_FileVerification
@@ -139,47 +140,61 @@ class W3_Setup {
139
  if (empty($folders))
140
  return true;
141
  $url = w3_is_network() ?
142
- network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general');
 
143
  try {
144
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
145
- w3_create_folders($folders, '', $url);
146
  $results = $this->test_file_writing();
147
  } catch(Exception $ex) {
148
  if ($ex instanceof FilesystemCredentialException) {
149
- throw new TryException('Could not create folders', $folders, $ex->ftp_form());
150
  } else {
151
  try {
152
  $this->_try_create_missing_folders($folders, $url);
153
  $results = $this->test_file_writing();
154
  } catch(Exception $ex) {
155
  if ($ex instanceof FilesystemCredentialException) {
156
- throw new TryException('Could not create folders', $folders, $ex->ftp_form());
157
  } else {
158
- if ($ex instanceof FileOperationException && $ex->getOperation() == 'chmod') {
159
- $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
160
  throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Could not
161
- change permissions %d on %s back to original permissions %d.'
162
- , $current_perm, WP_CONTENT_DIR, $prev_perm));
163
- }else
164
- throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> %s<br />Verify
 
 
 
 
 
165
  that correct (server, S/FTP)
166
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
167
  file permissions</a>
168
- are set or set FS_CHMOD_* constants in wp-config.php
169
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
170
- Learn more</a>.'
171
- , $ex->getMessage()));
 
 
172
  }
173
  }
174
- if ($results)
175
- throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> %s<br />Verify that
176
- correct (server, S/FTP)
 
 
 
 
177
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
178
  file permissions</a>
179
  are set or set FS_CHMOD_* constants in wp-config.php
180
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
181
- Learn more</a>.'
182
- , $ex->getMessage()));
 
 
183
  }
184
  }
185
 
@@ -211,18 +226,21 @@ class W3_Setup {
211
  $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
212
  foreach ($permissions as $permission) {
213
  $result = true;
214
- if ($permission == $prev_perm)
215
  continue;
216
- if (!($result = @chmod(WP_CONTENT_DIR, $permission)))
217
- $result = w3_chmod_dir(WP_CONTENT_DIR, $permission);
 
 
218
  if ($result) {
219
  try {
220
- w3_create_folders($folders, '', $url);
221
  return true;
222
  }catch (Exception $ex) {}
223
  }
224
- if (!@chmod(WP_CONTENT_DIR, $prev_perm))
225
- w3_chmod_dir(WP_CONTENT_DIR, $prev_perm);
 
226
  }
227
  return true;
228
  }
@@ -232,23 +250,26 @@ class W3_Setup {
232
  $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
233
  foreach ($permissions as $permission) {
234
  $result = true;
235
- if ($permission == $prev_perm)
236
  continue;
237
- if (!($result = @chmod(WP_CONTENT_DIR, $permission)))
238
- $result = w3_chmod_dir(WP_CONTENT_DIR, $permission);
 
 
239
  if ($result) {
240
  try {
241
- w3_create_files($files, '', $url);
242
  return true;
243
  }catch (Exception $ex) {}
244
  }
245
- if (!@chmod(WP_CONTENT_DIR, $prev_perm))
246
- w3_chmod_dir(WP_CONTENT_DIR, $prev_perm);
 
247
  }
248
  return true;
249
  }
250
 
251
- public function test_file_writing() {
252
  $results = array();
253
  $permissions = array(0755, 0775, 0777);
254
  $test_result1 = $this->_test_cache_file_creation();
@@ -257,23 +278,27 @@ class W3_Setup {
257
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
258
  $prev_perm = w3_get_file_permissions(W3TC_CACHE_DIR);
259
  foreach ($permissions as $permission) {
260
- if ($permission == $prev_perm)
 
 
261
  continue;
262
- $result = w3_chmod_dir(W3TC_CACHE_DIR, $permission, true);
 
 
263
  if ($result) {
264
  $test_result1 = $this->_test_cache_file_creation();
265
  if ($test_result1['success']) {
266
  $c_fileowngrp = w3_get_file_owner(W3TC_CACHE_DIR);
267
  $d_fileowngrp = w3_get_file_owner();
268
 
269
- $results['permissions'][] = sprintf('Plugin changed permissions on: %s to %d from %s. <br />' .
270
  'Default file owner is %s, plugin created files is owned by %s.',
271
- W3TC_CACHE_DIR, decoct($permission), $prev_perm,
272
  $d_fileowngrp, $c_fileowngrp);
273
  break;
274
  }
275
  } else {
276
- $results[] = 'Folder does not exists: ' . W3TC_CACHE_DIR;
277
  }
278
  }
279
  }
@@ -284,23 +309,26 @@ class W3_Setup {
284
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
285
  $prev_perm = w3_get_file_permissions(W3TC_CONFIG_DIR);
286
  foreach ($permissions as $permission) {
287
- if ($permission == $prev_perm)
 
288
  continue;
289
- $result = w3_chmod_dir(W3TC_CONFIG_DIR, $permission);
 
 
290
  if ($result) {
291
  $test_result2 = $this->_test_w3tc_config_creation();
292
  if ($test_result2['success']) {
293
  $c_fileowngrp = w3_get_file_owner(W3TC_CONFIG_DIR);
294
  $d_fileowngrp = w3_get_file_owner();
295
 
296
- $results['permissions'][] = sprintf('Plugin changed permissions on: %s to %d from %s. <br />' .
297
  'Default file owner is %s, plugin created files is owned by %s.',
298
- W3TC_CONFIG_DIR, decoct($permission), $prev_perm,
299
  $d_fileowngrp, $c_fileowngrp);
300
  break;
301
  }
302
  } else {
303
- $results[] = 'Folder does not exists: ' . W3TC_CONFIG_DIR;
304
  }
305
  }
306
  }
@@ -308,12 +336,12 @@ class W3_Setup {
308
  foreach ($test_result1 as $test => $result) {
309
  if ($test == 'folder' && !$result)
310
  $results[] = sprintf('Could not mkdir: %s', self::$test_dir);
311
- elseif (!$result)
312
- $results[] = sprintf('Could not create file in %s using %s.', self::$test_dir, $test);
313
  }
314
 
315
  foreach ($test_result2 as $test => $result) {
316
- if (!$result)
317
  $results[] = sprintf('Could not create file in %s using %s.', W3TC_CONFIG_DIR, $test);
318
  }
319
 
@@ -466,7 +494,7 @@ class W3_Setup {
466
  network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general');
467
  try {
468
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
469
- $result = w3_write_to_file($filename, $data, $url);
470
  } catch(Exception $ex) {
471
  if ($ex instanceof FilesystemCredentialException) {
472
  throw new TryException('Could not create file', array($filename), $ex->ftp_form());
8
  const WPFS_CHMOD = 'wp filesystem chmod';
9
  private static $test_dir;
10
  function __construct() {
11
+ self::$test_dir = W3TC_CACHE_DIR . DIRECTORY_SEPARATOR . 'test_dir';
12
  }
13
 
14
  function get_setup_message($cache_folders, $addin_files, $ftp_form) {
25
 
26
  $not_installed .= '</ul>';
27
  $headline = $pagenow == 'plugins.php' ? '<h2 id="w3tc">W3 Total Cache Error</h2>': '';
28
+ $error = sprintf('%s<p>Files and directories could not be automatically created to complete the installation. Please enter FTP details
29
+ <a href="#ftp_upload_form">below</a> to complete the setup.
30
+ Also try <strong>chmod 777 %s</strong><br /> %s</p>
31
  <div class="w3tc-required-changes" style="display:none">%s</div><p>' .
32
  (($cache_folders || $addin_files) ?
33
  'Either the <strong>%s</strong> directory is not write-able or another caching plugin
34
  is installed.'
35
  : '') .
36
  'This error message will automatically disappear once the change is successfully made.</p>'
37
+ , $headline
38
+ , WP_CONTENT_DIR
39
+ ,$this->button('View required changes', '', 'w3tc-show-required-changes')
40
  , $not_installed, WP_CONTENT_DIR);
41
  if ($pagenow == 'plugins.php') {
42
  $ftp_form = '<div id="ftp_upload_form" class="updated fade" style="background: none;border: none;">' .
74
  }
75
 
76
  public function try_create_missing_files() {
77
+ $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
78
+
 
 
 
79
  /**
80
  * @var $w3_verify W3_FileVerification
81
  */
86
  return true;
87
  $addin_files = $result_verify['files'];
88
  $url = w3_is_network() ?
89
+ network_admin_url('plugins.php') : admin_url('plugins.php');
90
  try {
91
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
92
+ w3_wp_create_files($addin_files, '', $url);
93
  } catch(Exception $ex) {
94
  if ($ex instanceof FilesystemCredentialException) {
95
  throw new TryException('Could not create files', $result_verify, $ex->ftp_form());
101
  if ($ex instanceof FilesystemCredentialException) {
102
  throw new TryException('Could not create files', $result_verify, $ex->ftp_form());
103
  } else {
104
+ $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
105
+ if ($current_perm != $prev_perm && $ex instanceof FileOperationException && $ex->getOperation() == 'chmod') {
106
  throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Could not
107
+ change permissions %s on %s back to original permissions %s.'
108
+ , base_convert($current_perm, 10, 8), WP_CONTENT_DIR, base_convert($prev_perm, 10, 8)));
109
  }else
110
+ $missing_files = '<ul>';
111
+ foreach ($addin_files as $result)
112
+ $missing_files .= '<li>' . basename($result) . '</li>';
113
+ $missing_files.= '</ul>';
114
+
115
+ throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Moving missing files from <em>%s</em> to <em>%s</em> failed:%s
116
  Verify that correct (server, S/FTP)
117
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
118
  file permissions</a>
119
+ are set or set FS_CHMOD_* constants in wp-config.php and / or try adding <em>define(\'FS_METHOD\', \'direct\');</em> in wp-config.php
120
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
121
+ Learn more</a>. If all else fails, try <strong>chmod 777 %s</strong>'
122
+ , str_replace(dirname(WP_CONTENT_DIR), '', W3TC_INSTALL_DIR), basename(WP_CONTENT_DIR), $missing_files,
123
+ WP_CONTENT_DIR));
124
  }
125
  }
126
  }
129
  }
130
 
131
  public function try_create_missing_folders() {
132
+ $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
 
 
 
 
133
 
134
  /**
135
  * @var $w3_verify W3_FileVerification
140
  if (empty($folders))
141
  return true;
142
  $url = w3_is_network() ?
143
+ network_admin_url('plugins.php') : admin_url('plugins.php');
144
+
145
  try {
146
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
147
+ w3_wp_create_folders($folders, '', $url);
148
  $results = $this->test_file_writing();
149
  } catch(Exception $ex) {
150
  if ($ex instanceof FilesystemCredentialException) {
151
+ throw new TryException('Could not create directories', $folders, $ex->ftp_form());
152
  } else {
153
  try {
154
  $this->_try_create_missing_folders($folders, $url);
155
  $results = $this->test_file_writing();
156
  } catch(Exception $ex) {
157
  if ($ex instanceof FilesystemCredentialException) {
158
+ throw new TryException('Could not create directories', $folders, $ex->ftp_form());
159
  } else {
160
+ $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
161
+ if ($current_perm != $prev_perm && $ex instanceof FileOperationException && $ex->getOperation() == 'chmod') {
162
  throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Could not
163
+ revert permissions %s on %s back to original permissions %s.'
164
+ , base_convert($current_perm, 10, 8), WP_CONTENT_DIR, base_convert($prev_perm, 10, 8)));
165
+ }else {
166
+ $missing_folders = '<ul>';
167
+ foreach ($folders as $result)
168
+ $missing_folders .= '<li>' . str_replace(WP_CONTENT_DIR, '', $result) . '</li>';
169
+ $missing_folders .= '</ul>';
170
+
171
+ throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Failed to create missing directories in %s: %s Verify
172
  that correct (server, S/FTP)
173
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
174
  file permissions</a>
175
+ are set or set FS_CHMOD_* constants in wp-config.php and/or try adding <em>define(\'FS_METHOD\', \'direct\');</em> in wp-config.php
176
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
177
+ Learn more</a>. If all else fails, try <strong>chmod 777 %s</strong>'
178
+ , basename(WP_CONTENT_DIR), $missing_folders
179
+ , WP_CONTENT_DIR));
180
+ }
181
  }
182
  }
183
+ if ($results) {
184
+ $missing_folders = '<ul>';
185
+ foreach ($results as $result)
186
+ $missing_folders .= '<li>' . $result . '</li>';
187
+ $missing_folders .= '</ul>';
188
+ throw new W3TCErrorException(sprintf('<strong>W3 Total Cache Error:</strong> Failed to create missing directories in %s: %s
189
+ Verify that correct (server, S/FTP)
190
  <a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
191
  file permissions</a>
192
  are set or set FS_CHMOD_* constants in wp-config.php
193
  <a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions">
194
+ Learn more</a>. If all else fails, try <strong>chmod 777 %s</strong>'
195
+ , basename(WP_CONTENT_DIR), $missing_folders,
196
+ WP_CONTENT_DIR));
197
+ }
198
  }
199
  }
200
 
226
  $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
227
  foreach ($permissions as $permission) {
228
  $result = true;
229
+ if ($prev_perm > $permission)
230
  continue;
231
+
232
+ if ($permission != $prev_perm)
233
+ if (!($result = @chmod(WP_CONTENT_DIR, $permission)))
234
+ $result = w3_chmod_dir(WP_CONTENT_DIR, $permission);
235
  if ($result) {
236
  try {
237
+ w3_wp_create_folders($folders, '', $url);
238
  return true;
239
  }catch (Exception $ex) {}
240
  }
241
+ if ($permission != $prev_perm)
242
+ if (!@chmod(WP_CONTENT_DIR, $prev_perm))
243
+ w3_chmod_dir(WP_CONTENT_DIR, $prev_perm);
244
  }
245
  return true;
246
  }
250
  $prev_perm = w3_get_file_permissions(WP_CONTENT_DIR);
251
  foreach ($permissions as $permission) {
252
  $result = true;
253
+ if ($prev_perm > $permission)
254
  continue;
255
+
256
+ if ($permission != $prev_perm)
257
+ if (!($result = @chmod(WP_CONTENT_DIR, $permission)))
258
+ $result = w3_chmod_dir(WP_CONTENT_DIR, $permission);
259
  if ($result) {
260
  try {
261
+ w3_wp_create_files($files, '', $url);
262
  return true;
263
  }catch (Exception $ex) {}
264
  }
265
+ if ($permission != $prev_perm)
266
+ if (!@chmod(WP_CONTENT_DIR, $prev_perm))
267
+ w3_chmod_dir(WP_CONTENT_DIR, $prev_perm);
268
  }
269
  return true;
270
  }
271
 
272
+ public function test_file_writing($single = false) {
273
  $results = array();
274
  $permissions = array(0755, 0775, 0777);
275
  $test_result1 = $this->_test_cache_file_creation();
278
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
279
  $prev_perm = w3_get_file_permissions(W3TC_CACHE_DIR);
280
  foreach ($permissions as $permission) {
281
+ $result = true;
282
+
283
+ if ($prev_perm > $permission)
284
  continue;
285
+
286
+ if ($permission != $prev_perm)
287
+ $result = w3_chmod_dir(W3TC_CACHE_DIR, $permission, true);
288
  if ($result) {
289
  $test_result1 = $this->_test_cache_file_creation();
290
  if ($test_result1['success']) {
291
  $c_fileowngrp = w3_get_file_owner(W3TC_CACHE_DIR);
292
  $d_fileowngrp = w3_get_file_owner();
293
 
294
+ $results['permissions'][] = sprintf('Plugin changed permissions on: %s to %s from %s. <br />' .
295
  'Default file owner is %s, plugin created files is owned by %s.',
296
+ W3TC_CACHE_DIR, base_convert($permission, 10, 8), base_convert($prev_perm, 10, 8),
297
  $d_fileowngrp, $c_fileowngrp);
298
  break;
299
  }
300
  } else {
301
+ $results[] = 'Directory does not exist: ' . W3TC_CACHE_DIR;
302
  }
303
  }
304
  }
309
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
310
  $prev_perm = w3_get_file_permissions(W3TC_CONFIG_DIR);
311
  foreach ($permissions as $permission) {
312
+ $result = true;
313
+ if ($prev_perm > $permission)
314
  continue;
315
+
316
+ if ($permission != $prev_perm)
317
+ $result = w3_chmod_dir(W3TC_CONFIG_DIR, $permission);
318
  if ($result) {
319
  $test_result2 = $this->_test_w3tc_config_creation();
320
  if ($test_result2['success']) {
321
  $c_fileowngrp = w3_get_file_owner(W3TC_CONFIG_DIR);
322
  $d_fileowngrp = w3_get_file_owner();
323
 
324
+ $results['permissions'][] = sprintf('Plugin changed permissions on: %s to %s from %s. <br />' .
325
  'Default file owner is %s, plugin created files is owned by %s.',
326
+ W3TC_CONFIG_DIR, base_convert($permission, 10, 8), base_convert($prev_perm, 10, 8),
327
  $d_fileowngrp, $c_fileowngrp);
328
  break;
329
  }
330
  } else {
331
+ $results[] = 'Directory does not exist: ' . W3TC_CONFIG_DIR;
332
  }
333
  }
334
  }
336
  foreach ($test_result1 as $test => $result) {
337
  if ($test == 'folder' && !$result)
338
  $results[] = sprintf('Could not mkdir: %s', self::$test_dir);
339
+ elseif (!$result && $test != 'success')
340
+ $results[] = sprintf('Could not create file in %s using %s.' , self::$test_dir, $test);
341
  }
342
 
343
  foreach ($test_result2 as $test => $result) {
344
+ if (!$result && $test != 'success')
345
  $results[] = sprintf('Could not create file in %s using %s.', W3TC_CONFIG_DIR, $test);
346
  }
347
 
494
  network_admin_url('admin.php?page=w3tc_general') : admin_url('admin.php?page=w3tc_general');
495
  try {
496
  w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
497
+ $result = w3_wp_write_to_file($filename, $data, $url);
498
  } catch(Exception $ex) {
499
  if ($ex instanceof FilesystemCredentialException) {
500
  throw new TryException('Could not create file', array($filename), $ex->ftp_form());
lib/W3/Widget/NewRelic.php CHANGED
@@ -85,7 +85,7 @@ class W3_Widget_NewRelic extends W3_Plugin {
85
  $slowest_page_loads = array();
86
  $slowest_webtransaction = array();
87
  $slowest_database = array();
88
- $subscription_lvl = 'unknown. ';
89
  $can_use_metrics = false;
90
  if ($new_relic_configured && $new_relic_enabled) {
91
  try {
85
  $slowest_page_loads = array();
86
  $slowest_webtransaction = array();
87
  $slowest_database = array();
88
+ $subscription_lvl = __('unknown', 'w3-total-cache');
89
  $can_use_metrics = false;
90
  if ($new_relic_configured && $new_relic_enabled) {
91
  try {
pub/css/options.css CHANGED
@@ -279,7 +279,7 @@
279
  cursor: auto;
280
  }
281
 
282
- #pgcache_reject_roles label {
283
  margin-right: 15px;
284
  }
285
 
279
  cursor: auto;
280
  }
281
 
282
+ #pgcache_reject_roles label, #newrelic_accept_roles label, #cdn_reject_roles label {
283
  margin-right: 15px;
284
  }
285
 
pub/js/options.js CHANGED
@@ -375,18 +375,21 @@ jQuery(function() {
375
 
376
  jQuery.getJSON(ajaxurl, params, function(data) {
377
  var app_id_select = jQuery('#newrelic_application_id_dropdown');
 
378
  app_id_select.empty();
379
  app_id_select
380
  .append(jQuery("<option></option>")
381
  .attr("value",'')
382
  .text('-- Select Application --'));
383
-
384
  jQuery.each(data, function(key, value) {
385
  app_id_select
386
  .append(jQuery("<option></option>")
387
  .attr("value",key)
388
  .text(value));
 
389
  });
 
 
390
  });
391
  });
392
 
375
 
376
  jQuery.getJSON(ajaxurl, params, function(data) {
377
  var app_id_select = jQuery('#newrelic_application_id_dropdown');
378
+ var count = 0;
379
  app_id_select.empty();
380
  app_id_select
381
  .append(jQuery("<option></option>")
382
  .attr("value",'')
383
  .text('-- Select Application --'));
 
384
  jQuery.each(data, function(key, value) {
385
  app_id_select
386
  .append(jQuery("<option></option>")
387
  .attr("value",key)
388
  .text(value));
389
+ count++;
390
  });
391
+ if (count == 0)
392
+ alert('Could not retrieve any applications. Verify your API key.');
393
  });
394
  });
395
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: fredericktownes
3
  Tags: wpo, web performance optimization, performance, availability, scaling, scalability, user experience, cache, caching, page cache, css cache, js cache, db cache, disk cache, disk caching, database cache, http compression, gzip, deflate, minify, cdn, content delivery network, media library, performance, speed, multiple hosts, css, merge, combine, unobtrusive javascript, compress, optimize, optimizer, javascript, js, cascading style sheet, plugin, yslow, yui, google, google rank, google page speed, mod_pagespeed, new relic, newrelic, aws, s3, cloudfront, sns, elasticache, rds, flash media server, amazon web services, cloud files, rackspace, akamai, max cdn, netdna, limelight, cloudflare, mod_cloudflare, microsoft, microsoft azure, iis, nginx, litespeed, apache, varnish, xcache, apc, eacclerator, wincache, mysql, w3 total cache, batcache, wp cache, wp super cache, quick cache, wp minify, bwp-minify, buddypress
4
  Requires at least: 2.8
5
  Tested up to: 3.5.1
6
- Stable tag: 0.9.2.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -13,7 +13,7 @@ Easy Web Performance Optimization (WPO) using caching: browser, page, object, da
13
 
14
  The **only** WordPress Performance Optimization (WPO) framework; designed to improve user experience and page speed.
15
 
16
- Recommended by web hosts like: Page.ly, DreamHost, MediaTemple, Go Daddy, Host Gator and countless more.
17
 
18
  Trusted by countless companies like: AT&T, stevesouders.com, mattcutts.com, mashable.com, smashingmagazine.com, makeuseof.com, yoast.com, kiss925.com, pearsonified.com, lockergnome.com, johnchow.com, ilovetypography.com, webdesignerdepot.com, css-tricks.com and tens of thousands of others.
19
 
@@ -731,11 +731,21 @@ It's quite difficult to recall all of the innovators that have shared their thou
731
  Please reach out to all of these people and support their projects if you're so inclined.
732
 
733
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
734
  = 0.9.2.7 =
735
  * Fixed config file write in more hosting environments
736
  * Fixed legacy config file import on servers with hardened file permissions
737
  * Fixed page cache write cache rules in some environments
738
- * Fixed retina images
739
  * Fixed false positive notifications when permissions are not changed or same
740
  * Fixed minify help
741
  * Improved upgrade notifications
@@ -849,7 +859,7 @@ Please reach out to all of these people and support their projects if you're so
849
  * Improved minify filename path generation
850
  * Improved minify custom placement usage
851
  * Improved PHP 5 compability by removing deprecated functionality
852
- * Improved WP 3.4 and 3.5 compability by removing deprecated functions usage
853
  * Improved plugin by removing unnecessary ob_starts
854
  * Improved minify usage by returning old minify files while generating new
855
  * Improved update procedure by removing need to manually deactivate and reactivate plugin
@@ -1224,5 +1234,5 @@ Please reach out to all of these people and support their projects if you're so
1224
 
1225
  == Upgrade Notice ==
1226
 
1227
- = 0.9.2.6 =
1228
- Thanks for using W3 Total Cache! As always, this update is very strongly recommended. This release contains fixes for users improving compatibility across more hosting environments. We appreciate your patience and help as we move toward making updates more seamless. Unfortunately, it's not easy to upgrade "low level" functionality like server configurations. We do it because we're trying to give you the advantages that large corporations have, for free.
3
  Tags: wpo, web performance optimization, performance, availability, scaling, scalability, user experience, cache, caching, page cache, css cache, js cache, db cache, disk cache, disk caching, database cache, http compression, gzip, deflate, minify, cdn, content delivery network, media library, performance, speed, multiple hosts, css, merge, combine, unobtrusive javascript, compress, optimize, optimizer, javascript, js, cascading style sheet, plugin, yslow, yui, google, google rank, google page speed, mod_pagespeed, new relic, newrelic, aws, s3, cloudfront, sns, elasticache, rds, flash media server, amazon web services, cloud files, rackspace, akamai, max cdn, netdna, limelight, cloudflare, mod_cloudflare, microsoft, microsoft azure, iis, nginx, litespeed, apache, varnish, xcache, apc, eacclerator, wincache, mysql, w3 total cache, batcache, wp cache, wp super cache, quick cache, wp minify, bwp-minify, buddypress
4
  Requires at least: 2.8
5
  Tested up to: 3.5.1
6
+ Stable tag: 0.9.2.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
13
 
14
  The **only** WordPress Performance Optimization (WPO) framework; designed to improve user experience and page speed.
15
 
16
+ Recommended by web hosts like: Page.ly, Synthesis, DreamHost, MediaTemple, Go Daddy, Host Gator and countless more.
17
 
18
  Trusted by countless companies like: AT&T, stevesouders.com, mattcutts.com, mashable.com, smashingmagazine.com, makeuseof.com, yoast.com, kiss925.com, pearsonified.com, lockergnome.com, johnchow.com, ilovetypography.com, webdesignerdepot.com, css-tricks.com and tens of thousands of others.
19
 
731
  Please reach out to all of these people and support their projects if you're so inclined.
732
 
733
  == Changelog ==
734
+ = 0.9.2.8 =
735
+ * Fixed /tmp file creation issue when saving settings
736
+ * Fixed an issue with auto minify
737
+ * Fixed an issue with New Relic API key verification
738
+ * Fixed uncommon issue with require ObjectCache failing
739
+ * Fixed uncommon open_basedir verification issue
740
+ * Improved notification handling by modified WordPress FileSystem API implementation
741
+ * Added PHP file handling to support cases not covered by default WordPress FileSystem API
742
+
743
+
744
  = 0.9.2.7 =
745
  * Fixed config file write in more hosting environments
746
  * Fixed legacy config file import on servers with hardened file permissions
747
  * Fixed page cache write cache rules in some environments
748
+ * Fixed HiDPI images
749
  * Fixed false positive notifications when permissions are not changed or same
750
  * Fixed minify help
751
  * Improved upgrade notifications
859
  * Improved minify filename path generation
860
  * Improved minify custom placement usage
861
  * Improved PHP 5 compability by removing deprecated functionality
862
+ * Improved WordPress 3.4 and 3.5 compability by removing deprecated functions usage
863
  * Improved plugin by removing unnecessary ob_starts
864
  * Improved minify usage by returning old minify files while generating new
865
  * Improved update procedure by removing need to manually deactivate and reactivate plugin
1234
 
1235
  == Upgrade Notice ==
1236
 
1237
+ = 0.9.2.8 =
1238
+ Thanks for using W3 Total Cache! As always, this update is very strongly recommended. The recent releases attempted to use WordPress' built in support for managing files and folders and clearly has not worked. Since W3TC is a caching plugin, file management is a critical issue that will cause lots of issues if it doesn't work perfectly. This release is hopefully the last attempt to restore file management back to the reliability of previous versions (0.9.2.4 etc). We realize that having *any* problems is not acceptable, but caching means changing server behavior so while this plugin is still in pre-release we're trying to work on learning the lessons.
w3-total-cache.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
- Version: 0.9.2.7
6
  Plugin URI: http://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/w3edge
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
+ Version: 0.9.2.8
6
  Plugin URI: http://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/w3edge