C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\imagify\classes\Webp\Display.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
namespace Imagify\Webp;

defined'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Display webp images on the site.
 *
 * @since  1.9
 * @author Grégory Viguier
 */
class Display {
    use \
Imagify\Traits\InstanceGetterTrait;

    
/**
     * Server conf object.
     *
     * @var    \Imagify\WriteFile\WriteFileInterface
     * @since  1.9
     * @access protected
     * @author Grégory Viguier
     */
    
protected $server_conf;

    
/**
     * Init.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     */
    
public function init() {
        
add_filter'imagify_settings_on_save',   [ $this'maybe_add_rewrite_rules' ] );
        
add_action'imagify_settings_webp_info', [ $this'maybe_add_webp_info' ] );
        
add_action'imagify_activation',         [ $this'activate' ] );
        
add_action'imagify_deactivation',       [ $this'deactivate' ] );

        
Picture\Display::get_instance()->init();
        
RewriteRules\Display::get_instance()->init();
    }

    
/** ----------------------------------------------------------------------------------------- */
    /** HOOKS =================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * If display webp images, add the webp type to the .htaccess/etc file.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     *
     * @param  array $values The option values.
     * @return array
     */
    
public function maybe_add_rewrite_rules$values ) {
        
$old_value = (bool) get_imagify_option'display_webp' );
        
// See \Imagify_Options->validate_values_on_update() for why we use 'convert_to_webp' here.
        
$new_value = ! empty( $values['display_webp'] ) && ! empty( $values['convert_to_webp'] );

        if ( 
$old_value === $new_value ) {
            
// No changes.
            
return $values;
        }

        if ( ! 
$this->get_server_conf() ) {
            return 
$values;
        }

        if ( 
$new_value ) {
            
// Add the webp file type.
            
$result $this->get_server_conf()->add();
        } else {
            
// Remove the webp file type.
            
$result $this->get_server_conf()->remove();
        }

        if ( ! 
is_wp_error$result ) ) {
            return 
$values;
        }

        
// Display an error message.
        
if ( is_multisite() && strposwp_get_referer(), network_admin_url'/' ) ) === ) {
            \
Imagify_Notices::get_instance()->add_network_temporary_notice$result->get_error_message() );
        } else {
            \
Imagify_Notices::get_instance()->add_site_temporary_notice$result->get_error_message() );
        }

        return 
$values;
    }

    
/**
     * If the conf file is not writable, add a warning.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     */
    
public function maybe_add_webp_info() {
        
$conf $this->get_server_conf();

        if ( ! 
$conf ) {
            return;
        }

        
$writable $conf->is_file_writable();

        if ( ! 
is_wp_error$writable ) ) {
            return;
        }

        
$rules $conf->get_new_contents();

        if ( ! 
$rules ) {
            
// Uh?
            
return;
        }

        echo 
'<br/>';

        
printf(
            
/* translators: %s is a file name. */
            
esc_html__'Imagify does not seem to be able to edit or create a %s file, you will have to add the following lines manually to it:''imagify' ),
            
'<code>' $this->get_file_pathtrue ) . '</code>'
        
);

        echo 
'<pre class="code">' esc_html$rules ) . '</pre>';
    }

    
/**
     * Add rules on plugin activation.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     */
    
public function activate() {
        
$conf $this->get_server_conf();

        if ( ! 
$conf ) {
            return;
        }
        if ( ! 
get_imagify_option'display_webp' ) ) {
            return;
        }
        if ( 
is_wp_error$conf->is_file_writable() ) ) {
            return;
        }

        
$conf->add();
    }

    
/**
     * Remove rules on plugin deactivation.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     */
    
public function deactivate() {
        
$conf $this->get_server_conf();

        if ( ! 
$conf ) {
            return;
        }
        if ( ! 
get_imagify_option'display_webp' ) ) {
            return;
        }

        
$file_path  $conf->get_file_path();
        
$filesystem = \Imagify_Filesystem::get_instance();

        if ( ! 
$filesystem->exists$file_path ) ) {
            return;
        }
        if ( ! 
$filesystem->is_writable$file_path ) ) {
            return;
        }

        
$conf->remove();
    }

    
/** ----------------------------------------------------------------------------------------- */
    /** TOOLS =================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Get the path to the directory conf file.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $relative True to get a path relative to the site’s root.
     * @return string|bool    The file path. False on failure.
     */
    
public function get_file_path$relative false ) {
        if ( ! 
$this->get_server_conf() ) {
            return 
false;
        }

        
$file_path $this->get_server_conf()->get_file_path();

        if ( 
$relative ) {
            return \
Imagify_Filesystem::get_instance()->make_path_relative$file_path );
        }

        return 
$file_path;
    }

    
/**
     * Get the webp display method by validating the given value.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     *
     * @param  array $values The option values.
     * @return string        'picture' or 'rewrite'.
     */
    
public function get_display_webp_method$values ) {
        
$options = \Imagify_Options::get_instance();
        
$default $options->get_default_values();
        
$default $default['display_webp_method'];
        
$method  = ! empty( $values['display_webp_method'] ) ? $values['display_webp_method'] : '';

        return 
$options->sanitize_and_validate'display_webp_method'$method$default );
    }

    
/**
     * Get the server conf instance.
     * Note: nothing needed for nginx.
     *
     * @since  1.9
     * @access public
     * @author Grégory Viguier
     *
     * @return \Imagify\WriteFile\WriteFileInterface
     */
    
protected function get_server_conf() {
        global 
$is_apache$is_iis7;

        if ( isset( 
$this->server_conf ) ) {
            return 
$this->server_conf;
        }

        if ( 
$is_apache ) {
            
$this->server_conf = new Apache();
        } elseif ( 
$is_iis7 ) {
            
$this->server_conf = new IIS();
        } else {
            
$this->server_conf false;
        }

        return 
$this->server_conf;
    }
}
x

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