PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / trunk
Aruba HiSpeed Cache vtrunk
3.0.14 3.0.13 1.2.4 1.2.5 1.2.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.19 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3
aruba-hispeed-cache / src / AHSC_Functions.php
aruba-hispeed-cache / src Last commit date
APC 3 months ago Events 3 months ago Purger 3 months ago assets 3 months ago AHSC_Apc.php 3 months ago AHSC_Check.php 3 months ago AHSC_Config.php 2 months ago AHSC_Dboptimization.php 3 months ago AHSC_Functions.php 2 months ago AHSC_HtmlOptimizer.php 3 months ago AHSC_Lazyload.php 1 week ago AHSC_Preconnect.php 3 months ago AHSC_Static.php 2 months ago AHSC_Version.php 3 months ago AHSC_Warmer.php 3 months ago AHSC_XmlRPC.php 3 months ago index.php 3 months ago
AHSC_Functions.php
438 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 use ArubaSPA\HiSpeedCache\Debug\Logger;
6
7 /**
8 * operation at plugin activation
9 * @return void
10 */
11 function AHSC_activation( ) {
12 // controllo la presenza del wp-cli.
13 $is_cli = (defined('WP_CLI') && WP_CLI);
14 // Controllo se è una richiesta HTTP reale (admin)
15 $is_admin_ui = (
16 isset($_SERVER['REQUEST_METHOD']) &&
17 is_admin() &&
18 isset($_SERVER['REQUEST_URI']) &&
19 strpos(sanitize_url( wp_unslash($_SERVER['REQUEST_URI'])), 'plugins.php') !== false
20 );
21
22 if ($is_cli) {
23 // attivazione
24 AHSC_activation_operation();
25 } else{
26 if ($is_admin_ui) {
27 $check = AHSC_check();
28 if ( ! $check['is_aruba_server'] ) {
29 AHSC_deactivate_me();
30 wp_die( esc_attr( ahsc_get_check_notice( $check ) ), 'Aruba HiSpeed Cache dependency check', array( 'back_link' => true ) );
31 } else {
32 AHSC_activation_operation();
33 }
34 }
35 }
36 }
37
38 function AHSC_activation_operation(){
39 $options = AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'];
40 if ( ! $options ) {
41 $options = array_map(
42 function( $opt ) {
43 return $opt['default'];
44 },
45 AHSC_OPTIONS_LIST_DEFAULT
46 );
47 }
48 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'] , $options );
49 \update_site_option( 'aruba_hispeed_cache_version', AHSC_CONSTANT['ARUBA_HISPEED_CACHE_VERSION']);
50
51 AHSC_remove_htaccess();
52 if(array_key_exists('ahsc_static_cache',AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'])){
53 if(isset(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache'])){
54 if(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache']){
55 AHSC_edit_htaccess();
56 }
57 }
58 }
59 }
60 /**
61 * operation at plugin deactivation
62 * @return void
63 */
64 function AHSC_deactivation( ) {
65
66 \delete_site_option( 'aruba_hispeed_cache_options' );
67 \delete_site_option( 'aruba_hispeed_cache_version');
68 AHSC_remove_htaccess();
69 $file = WP_CONTENT_DIR . '/object-cache.php';
70 if ( file_exists( $file ) ) {
71 // phpcs:ignore
72 @unlink( $file );
73 }
74 }
75 /**
76 * operation at plugin check requirement
77 * @return void
78 */
79 function AHSC_deactivate_me() {
80 if ( \function_exists( 'deactivate_plugins' ) ) {
81 \deactivate_plugins( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_BASENAME']);
82 }
83 }
84 /**
85 * create Notice in plugin admin page
86 *
87 * @param $handle string notice html id
88 * @param $html_class string notice general class es error,warning etc.etc.
89 * @param $content string notice content
90 *
91 */
92 function AHSC_Notice_Render( $handle, $html_class, $content, $return=false) {
93 $HTML_CLASS = array(
94 'error' => 'notice notice-error',
95 'warning' => 'notice notice-warning',
96 'success' => 'notice notice-success',
97 'info ' => 'notice notice-info',
98 );
99
100 if(!$return){
101 printf(
102 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
103 esc_attr( $handle ),
104 esc_attr( $HTML_CLASS[$html_class] ),
105 wp_kses_post( $content )
106 );
107 }else{
108 return sprintf(
109 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
110 esc_attr( $handle ),
111 esc_attr( $HTML_CLASS[$html_class] ),
112 wp_kses_post( $content )
113 );
114 }
115 }
116
117 /**
118 * create link in plugin page
119 * @return void
120 */
121 function AHSC_plugin_action_links($actions){
122
123 $settings_link = \sprintf(
124 '<a href="%s">%s</a>',
125 (( ! is_multisite() ) ? admin_url( 'options-general.php?page=aruba-hispeed-cache') : network_admin_url('settings.php?page=aruba-hispeed-cache')) ,
126 \esc_html(__( 'Settings', 'aruba-hispeed-cache' ))
127 );
128
129 $support_link = \sprintf(
130 '<a href="%s" target="_blank">%s</a>',
131 AHSC_LOCALIZE_LINK['link_assistance'][strtolower(substr( get_bloginfo ( 'language' ), 0, 2 ))],
132 \esc_html(__( 'Customer support', 'aruba-hispeed-cache' ))
133 );
134
135 \array_unshift( $actions, $settings_link, $support_link );
136
137 return $actions;
138
139 }
140
141 if ( ! \function_exists( 'ahsc_get_site_home_url' ) ) {
142 /**
143 * Return the complete home url of site.
144 *
145 * @return string
146 */
147 function ahsc_get_site_home_url() {
148 $home_uri = \trailingslashit( \home_url() );
149
150 if ( \function_exists( 'icl_get_home_url' ) ) {
151 $home_uri = \trailingslashit( \icl_get_home_url() );
152 }
153
154 return $home_uri;
155 }
156 }
157 /*
158
159 if ( ! \function_exists( 'ahsc_save_options' ) ) {
160 **
161 * Save plugin options
162 *
163 * @return void
164 *
165 function ahsc_save_options( ) {
166 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) {
167 if ( isset( $_POST['ahsc_settings_save'] ) && isset( $_POST['ahs-settings-nonce'] ) && \wp_verify_nonce( \sanitize_key( \wp_unslash( $_POST['ahs-settings-nonce'] ) ), 'ahs-save-settings-nonce' ) ) {
168 $new_options = array();
169 //var_dump(ABSPATH . 'wp-config.php');
170 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
171 foreach ( array_keys( AHSC_OPTIONS_LIST ) as $opt_key ) {
172 if($opt_key==="ahsc_cron_status" ){
173
174 if(isset($_POST[ $opt_key ])){
175 //var_dump("non disabilito cron ");
176 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'false', array( 'raw' => true, 'normalize' => true ));
177 $new_options[ $opt_key ]= 'false';
178 }else{
179 //var_dump("disabilito cron ");
180 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'true', array( 'raw' => true, 'normalize' => true ));
181 $new_options[ $opt_key ]= 'true';
182 }
183
184 }elseif($opt_key==="ahsc_cron_time"){
185
186 if(isset($_POST[ $opt_key ])){
187 //var_dump("setto time ");
188 $wpc_transformer->update( 'constant', 'WP_CRON_LOCK_TIMEOUT', "'".absint($_POST[ $opt_key ])."'", array( 'raw' => true, 'normalize' => true ));
189 $new_options[ $opt_key ]= sanitize_text_field( wp_unslash($_POST[ $opt_key ]));
190 }else{
191 //var_dump("non setto time ");
192 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
193 }
194 }elseif($opt_key!=="ahsc_dns_preconnect_domains"){
195 $new_options[ $opt_key ] = ( isset( $_POST[ $opt_key ] ) ) ? true : false;
196 }else{
197 if(isset( $_POST[ $opt_key ] ) ){
198 $trans_domain_list = explode( "\n", trim( sanitize_text_field( wp_unslash($_POST[ $opt_key ])) ) );
199 foreach ( $trans_domain_list as $index => $string ) {
200 if ( strpos( $string, $_SERVER['SERVER_NAME'] ) !== false ) {
201 unset( $trans_domain_list[ $index ] );
202 }
203 }
204 $new_options[ $opt_key ] =$trans_domain_list;
205 }else{
206 $new_options[ $opt_key ] ="";
207 }
208 }
209 }
210
211 if ( \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options ) ) {
212 $content = \esc_html( __('Settings saved.', 'aruba-hispeed-cache') );
213 AHSC_Notice_Render('ahs_settings_saved', 'success',$content);
214 }
215 }
216 }
217 }
218 }
219
220 */
221 if ( ! \function_exists( 'ahsc_reset_options' ) ) {
222 /**
223 * Reset plugin options
224 *
225 * @return void
226 */
227 function ahsc_reset_options( ) {
228 $new_options = array();
229
230 foreach ( array_keys( AHSC_OPTIONS_LIST_DEFAULT ) as $opt_key ) {
231 $new_options[ $opt_key ] = AHSC_OPTIONS_LIST_DEFAULT[$opt_key]['default'];
232 }
233 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
234
235 $wpc_transformer->remove('constant', 'DISABLE_WP_CRON');
236 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
237
238 if ( isset( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ) &&
239 AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ){
240 // phpcs:ignore
241 @unlink( WP_CONTENT_DIR . '/object-cache.php' );
242 }
243
244 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options );
245
246 $content = \esc_html( __('Original settings restored.', 'aruba-hispeed-cache') );
247 return $content;
248
249 }
250 }
251
252
253 if ( ! \function_exists( 'ahsc_has_transient' ) ) {
254
255 /**
256 * It checks whether a transinet exists if yes, it returns the value otherwise it returns false.
257 *
258 * @param string $transient .
259 * @return mixed
260 */
261 function ahsc_has_transient( $transient ) {
262 $temp=$GLOBALS['_wp_using_ext_object_cache'];
263 $GLOBALS['_wp_using_ext_object_cache'] = false;
264 $transient_value = ( \is_multisite() ) ? \get_site_transient( (string) $transient ) : \get_transient( (string) $transient );
265 $_value=( false !== $transient_value ) ? $transient_value : false;;
266 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
267 return $_value;
268 }
269 }
270
271 if ( ! \function_exists( 'ahsc_set_transient' ) ) {
272
273 /**
274 * Undocumented function
275 *
276 * @param string $transient .
277 * @param mixed $value .
278 * @param integer $expiration .
279 * @return bool
280 */
281 function ahsc_set_transient( $transient, $value, $expiration = 0 ) {
282 $temp=$GLOBALS['_wp_using_ext_object_cache'];
283 $GLOBALS['_wp_using_ext_object_cache'] = false;
284 $_value=( \is_multisite() ) ?
285 \set_site_transient( $transient, $value, $expiration ) :
286 \set_transient( $transient, $value, $expiration );
287 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
288 return $_value;
289 }
290 }
291
292 if ( ! \function_exists( 'ahsc_delete_transient' ) ) {
293
294 /**
295 * Undocumented function
296 *
297 * @param string $transient .
298 * @return bool
299 */
300 function ahsc_delete_transient( $transient ) {
301 $temp=$GLOBALS['_wp_using_ext_object_cache'];
302 $GLOBALS['_wp_using_ext_object_cache'] = false;
303 if(class_exists('ArubaSPA\HiSpeedCache\Debug\Logger')) {
304 AHSC_log( 'hook::transient::delete', __NAMESPACE__ . '::' . __FUNCTION__, 'debug' );
305 // Logger.
306 }
307 $_value=( \is_multisite() ) ?
308 \delete_site_transient( $transient ) :
309 \delete_transient( $transient );
310 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
311 return $_value;
312 }
313 }
314
315 if ( ! \function_exists( 'ahsc_has_notice' ) ) {
316
317 /**
318 * Return bool if transient notice check is set.
319 *
320 * @param bool $remove Set to true to clean the transinte if present.
321 * @return mixed
322 *
323 * @SuppressWarnings(PHPMD.StaticAccess)
324 */
325 function ahsc_has_notice( $remove = null ) {
326 $has_notice = ahsc_has_transient( AHSC_CHECKER['transient_name'] );
327
328 if ( false !== $has_notice && true === $remove ) {
329 if ( \is_multisite() ) {
330 \delete_site_transient(AHSC_CHECKER['transient_name'] );
331 return false;
332 }
333
334 \delete_transient( AHSC_CHECKER['transient_name']);
335 return false;
336 }
337
338 return $has_notice;
339 }
340 }
341
342 if ( ! \function_exists( 'ahsc_get_debug_file_content' ) ) {
343 /**
344 * Return the contente of log file.
345 *
346 * @return string
347 */
348 function ahsc_get_debug_file_content() {
349 global $wp_filesystem,$logger;
350 \WP_Filesystem();
351 if (class_exists('ArubaSPA\HiSpeedCache\Debug\Logger') ) {
352 if ( \file_exists( Logger::get_log_file_path_name() ) ) {
353 return $wp_filesystem->get_contents( Logger::get_log_file_path_name() );
354 }
355 }
356 return false;
357 }
358 }
359
360 if ( ! \function_exists('ahsc_current_theme_is_fse_theme' ) ) {
361 /**
362 * The function checks if the current theme is a Full Site Editing (FSE) theme in PHP.
363 *
364 * @return bool value indicating whether the current theme is a Full Site Editing (FSE) theme.
365 */
366 function ahsc_current_theme_is_fse_theme() {
367 if ( function_exists( 'wp_is_block_theme' ) ) {
368 return (bool) wp_is_block_theme();
369 }
370 if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
371 return (bool) gutenberg_is_fse_theme();
372 }
373 return false;
374 }
375 }
376
377 /**
378 * Write a debug info in to file.
379 *
380 * @param string $message the messagge.
381 * @param string $name the name of message.
382 * @param string $type the type of log debug|info|warning|error.
383 * @return void
384 */
385 function AHSC_log( $message, $name = '', $type = 'info' ) {
386
387 if ( class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger') ) {
388
389 //die(var_export(Logger::$logger_ready,true));
390 switch ( $type ) {
391 case 'debug':
392 Logger::debug( $message, $name );
393 break;
394 case 'info':
395 Logger::info( $message, $name );
396 break;
397 case 'warning':
398 Logger::warning( $message, $name );
399 break;
400 case 'error':
401 Logger::error( $message, $name );
402 break;
403 }
404 }
405 }
406
407 /** Let's get rid of the annoying Site Health warning about no auto-updates. We don't want autoupdates because we want to do backups before updates!
408 */
409
410 add_filter('site_status_tests', function (array $test_type) {
411
412 unset($test_type['async']['background_updates']); // remove warning about Automatic background updates
413
414 return $test_type;
415 }, 10, 1);
416
417 if ( ! \function_exists('ahsc_check_debug_status' ) ) {
418
419 function ahsc_check_debug_status(){
420 $ahsc_debug_status=false;
421 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php', true );
422 $ahsc_db = false;
423 $ahsc_dbl = false;
424 if ($wpc_transformer->exists( 'constant', 'WP_DEBUG' )) {
425 $ahsc_db = filter_var($wpc_transformer->get_value('constant','WP_DEBUG'), FILTER_VALIDATE_BOOLEAN);
426 }
427 if ($wpc_transformer->exists( 'constant', 'WP_DEBUG_LOG' )) {
428 $ahsc_dbl = filter_var($wpc_transformer->get_value('constant','WP_DEBUG_LOG'), FILTER_VALIDATE_BOOLEAN);
429 }
430 if($ahsc_db || $ahsc_dbl ){
431 $ahsc_debug_status=true;
432
433 }
434 return $ahsc_debug_status;
435 }
436
437 }
438