] ) ) { $_imgopt_stats_last_run = esc_html__( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] ); } else { $_imgopt_stats_last_run = esc_html__( 'based on previously fetched data', 'autoptimize' ); } $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', '; // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats. $_imgopt_notice .= sprintf( esc_html__( 'you can click %1$shere to refresh your quota status%2$s', 'autoptimize' ), '', ').' ); } // and make the full notice filterable. $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice ); return array( 'status' => $_stat['Status'], 'notice' => $_imgopt_notice, ); } } return false; } public static function get_imgopt_status_notice_wrapper() { // needed for notice being shown in autoptimizeCacheChecker.php. $self = new self(); return $self->get_imgopt_status_notice(); } /** * Get img provider stats (used to display notice). * * @param bool $_refresh Should the stats be forcefully refreshed or not. */ public function query_img_provider_stats( $_refresh = false ) { if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) && apply_filters( 'autoptimize_filter_imgopt_status_shortpixel', true ) ) { $url = ''; $stat_dom = 'https://no-cdn.shortpixel.ai/'; $endpoint = $stat_dom . 'read-domain/'; $domain = AUTOPTIMIZE_SITE_DOMAIN; // make sure parse_url result makes sense, keeping $url empty if not. if ( $domain && ! empty( $domain ) ) { $url = $endpoint . $domain; if ( true === $_refresh ) { $url = $url . '/refresh'; } } $url = apply_filters( 'autoptimize_filter_imgopt_stat_url', $url ); // only do the remote call if $url is not empty to make sure no parse_url // weirdness results in useless calls. if ( ! empty( $url ) ) { $response = wp_remote_get( $url ); if ( ! is_wp_error( $response ) ) { if ( '200' == wp_remote_retrieve_response_code( $response ) ) { $stats = json_decode( wp_remote_retrieve_body( $response ), true ); autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats ); } } } } } public static function get_img_provider_stats() { // wrapper around query_img_provider_stats() so we can get to $this->options from cronjob() in autoptimizeCacheChecker. $self = new self(); return $self->query_img_provider_stats(); } /** * Determines and returns the service launch status. * * @return bool */ public function launch_ok() { static $launch_status = null; if ( null === $launch_status ) { $avail_imgopt = ''; if ( is_array( $this->options ) && array_key_exists( 'availabilities', $this->options ) && is_array( $this->options['availabilities'] ) && array_key_exists( 'extra_imgopt', $this->options['availabilities'] ) ) { $avail_imgopt = $this->options['availabilities']['extra_imgopt']; } $magic_number = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 ); $has_launched = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' ); $launch_status = false; if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) { $launch_status = true; if ( ! $has_launched ) { autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' ); } } } return $launch_status; } public static function launch_ok_wrapper() { // needed for "plug" notice in autoptimizeMain.php. $self = new self(); return $self->launch_ok(); } public function get_imgopt_provider_userstatus() { static $_provider_userstatus = null; if ( is_null( $_provider_userstatus ) ) { $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); if ( is_array( $_stat ) ) { if ( array_key_exists( 'Status', $_stat ) ) { $_provider_userstatus['Status'] = $_stat['Status']; } else { // if no stats then we assume all is well. $_provider_userstatus['Status'] = 2; } if ( array_key_exists( 'timestamp', $_stat ) ) { $_provider_userstatus['timestamp'] = $_stat['timestamp']; } else { // if no timestamp then we return "". $_provider_userstatus['timestamp'] = ''; } } else { // no provider_stat yet, assume/ return all OK. $_provider_userstatus['Status'] = 2; $_provider_userstatus['timestamp'] = ''; } } return $_provider_userstatus; } }