C:\xampp\htdocs\landing\wp-content\plugins\wp-asset-clean-up\classes\FileSystem.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace WpAssetCleanUp;

use 
WpAssetCleanUp\OptimiseAssets\OptimizeCss;
use 
WpAssetCleanUp\OptimiseAssets\OptimizeJs;

/**
 * Class FileSystem
 * @package WpAssetCleanUp
 */
class FileSystem
{
    
/**
     * @return bool|\WP_Filesystem_Direct
     */
    
public static function init()
    {
        
// Set the permission constants if not already set.
        
if ( ! defined('FS_CHMOD_DIR') ) {
            
define('FS_CHMOD_DIR'fileperms(ABSPATH) & 0777 0755);
        }

        if ( ! 
defined('FS_CHMOD_FILE') ) {
            
define('FS_CHMOD_FILE'fileperms(ABSPATH 'index.php') & 0777 0644);
        }

        if (! 
defined('WPACU_FS_USED') && ! class_exists('\WP_Filesystem_Base') && ! class_exists('\WP_Filesystem_Direct')) {
            
$wpFileSystemBase   ABSPATH 'wp-admin/includes/class-wp-filesystem-base.php';
            
$wpFileSystemDirect ABSPATH 'wp-admin/includes/class-wp-filesystem-direct.php';

            if (
is_file($wpFileSystemBase) && is_file($wpFileSystemDirect)) {
                
// Make sure to use the 'direct' method as it's the most effective in this scenario
                
require_once ABSPATH 'wp-admin/includes/class-wp-filesystem-base.php';
                require_once 
ABSPATH 'wp-admin/includes/class-wp-filesystem-direct.php';
                
define('WPACU_FS_USED'true);
            } else {
                
// Do not use WordPress FileSystem Direct (fallback to default PHP functions)
                
define('WPACU_FS_USED'false);
            }
        }

        if (
defined('WPACU_FS_USED') && WPACU_FS_USED === true) {
            return new \
WP_Filesystem_Direct( new \StdClass() );
        }

        return 
false;
    }

    
/**
     * @param $localPathToFile
     * @param string $alter
     *
     * @return false|string
     */
    
public static function file_get_contents($localPathToFile$alter '')
    {
        
// ONLY relevant for CSS files
        
if ($alter === 'combine_css_imports') {
            
// This custom class does not minify as it's custom made for combining @import
            
$optimizer = new \WpAssetCleanUp\OptimiseAssets\CombineCssImports($localPathToFile);
            return 
$optimizer->minify();
        }

        
// Fallback
        
if (! self::init()) {
            return @
file_get_contents($localPathToFile);
        }

        return 
self::init()->get_contents($localPathToFile);
    }

    
/**
     * @param $localPathToFile
     * @param $contents
     *
     * @return bool|int|void
     */
    
public static function file_put_contents($localPathToFile$contents)
    {
        if ( (
strpos($localPathToFileWP_CONTENT_DIR OptimizeCss::getRelPathCssCacheDir()) !== false && ! is_dir(dirname($localPathToFile)))
            || (
strpos($localPathToFileWP_CONTENT_DIR OptimizeJs::getRelPathJsCacheDir()) !== false && ! is_dir(dirname($localPathToFile)))
            || (
strpos($localPathToFile'/_storage/_recent_items/') !== false && ! is_dir(dirname($localPathToFile)))
        ) {
            @
mkdir(dirname($localPathToFile), 0755true );
        }

        
// Fallback
        
if (! self::init()) {
            
$return = @file_put_contents($localPathToFile$contents);
        } else {
            
$return self::init()->put_contents$localPathToFile$contentsFS_CHMOD_FILE );
        }

        if (! 
$return) {
            
error_log('Asset CleanUp: Could not write to '.$localPathToFile);
        }

        return 
$return;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586