launch_ok() ) { ?>
imgopt_active() ) {
$_imgopt_notice = '';
$_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
$_site_host = AUTOPTIMIZE_SITE_DOMAIN;
$_imgopt_upsell = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
$_imgopt_assoc = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
$_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
if ( is_array( $_stat ) ) {
if ( 1 == $_stat['Status'] ) {
// translators: "add more credits" will appear in a "a href".
$_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '
', '' );
} elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
// translators: "add more credits" will appear in a "a href".
$_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '
', '' );
// translators: "associate your domain" will appear in a "a href".
$_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough credits/ CDN quota remaining, then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '
', '' );
} elseif ( -3 == $_stat['Status'] ) {
// translators: "check the documentation here" will appear in a "a href".
$_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '
', '' );
} else {
$_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
// translators: "log in to check your account" will appear in a "a href".
$_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '
', '' );
}
// add info on freshness + refresh link if status is not 2 (good shape).
if ( 2 != $_stat['Status'] ) {
$_imgopt_stats_refresh_url = add_query_arg( array(
'page' => 'autoptimize_imgopt',
'refreshImgProvStats' => '1',
), admin_url( 'options-general.php' ) );
if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
$_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
} else {
$_imgopt_stats_last_run = __( '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( __( 'click %1$shere to refresh%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).
*/
public function query_img_provider_stats() {
if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
$url = '';
$endpoint = $this->get_imgopt_host() . '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;
}
$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 = $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;
}
}