This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,44 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class ApiNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_NO_APIKEY';
public function load()
{
$activationDate = \wpSPIO()->settings()->activationDate;
if (! $activationDate)
{
$activationDate = time();
\wpSPIO()->settings()->activationDate = $activationDate;
}
parent::load();
}
protected function checkTrigger()
{
if (\wpSPIO()->settings()->verifiedKey)
{
return false;
}
// If not key is verified.
return true;
}
protected function getMessage()
{
$message = "<p>" . __('To start the optimization process, you need to validate your API key on the '
. '<a href="options-general.php?page=wp-shortpixel-settings">ShortPixel Settings</a> page in your WordPress admin.','shortpixel-image-optimiser') . "
</p>
<p>" . __('If you do not have an API key yet, just fill out the form and a key will be created.','shortpixel-image-optimiser') . "</p>";
return $message;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use ShortPixel\Controller\AdminNoticesController as AdminNoticesController;
class ApiNoticeRepeat extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_NO_APIKEY_REPEAT';
protected $errorLevel = 'warning';
protected function checkTrigger()
{
if (\wpSPIO()->settings()->verifiedKey)
{
return false;
}
// Is set by general ApiNotice. If not set, don't bother with the repeat.
$activationDate = \wpSPIO()->settings()->activationDate;
if (! $activationDate)
{
return false;
}
$controller = AdminNoticesController::getInstance();
$firstNotice = $controller->getNoticeByKey('MSG_NO_APIKEY');
// Check if first notice is there, and not dismissed, then don't repeat.
if ($firstNotice->isDismissed() === false)
{
return false;
}
// After 6 hours
if (time() < $activationDate + (6 * HOUR_IN_SECONDS))
{
return false;
}
// If not key is verified and first one is dismissed, and not this one.
return true;
}
protected function getMessage()
{
$message = __("Action required! Please <a href='https://shortpixel.com/wp-apikey' target='_blank'>get your API key</a> to activate your ShortPixel plugin.",'shortpixel-image-optimiser');
return $message;
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use ShortPixel\Controller\AdminNoticesController as AdminNoticesController;
class ApiNoticeRepeatLong extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_NO_APIKEY_REPEAT_LONG';
protected $errorLevel = 'warning';
protected function checkTrigger()
{
if (\wpSPIO()->settings()->verifiedKey)
{
return false;
}
// Is set by general ApiNotice. If not set, don't bother with the repeat.
$activationDate = \wpSPIO()->settings()->activationDate;
if (! $activationDate)
{
return false;
}
$controller = AdminNoticesController::getInstance();
// Check the original
$firstNotice = $controller->getNoticeByKey('MSG_NO_APIKEY');
if ($firstNotice->isDismissed() === false)
{
return false;
}
// Check the Repeat.
$secondNotice = $controller->getNoticeByKey('MSG_NO_APIKEY_REPEAT');
if ($secondNotice->isDismissed() === false)
{
return false;
}
// After 3 days.
if (time() < $activationDate + (3 * DAY_IN_SECONDS))
{
return false;
}
// If not key is verified and first one is dismissed, and not this one.
return true;
}
protected function getMessage()
{
$message = __("Your image gallery is not optimized. It takes 2 minutes to <a href='https://shortpixel.com/wp-apikey' target='_blank'>get your API key</a> and activate your ShortPixel plugin.",'shortpixel-image-optimiser') . "<BR><BR>";
return $message;
}
}

View File

@ -0,0 +1,118 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use \ShortPixel\Controller\CacheController as CacheController;
use ShortPixel\ShortPixelLogger\ShortPixelLogger as Log;
class AvifNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_AVIF_ERROR';
protected $errorLevel = 'error';
protected $error_message;
protected $error_detail;
// Remove this.
public function __construct()
{
$this->callback = array($this, 'function_crash');
parent::__construct();
}
/*
public function function_crash()
{
echo 'Yall';
return false;
}
*/
protected function checkTrigger()
{
// No Automatic Trigger.
return false;
}
public function check()
{
$cache = new CacheController();
if (apply_filters('shortpixel/avifcheck/override', false) === true)
{ return; }
if ($cache->getItem('avif_server_check')->exists() === false)
{
$url = \WPSPIO()->plugin_url('res/img/test.avif');
$headers = get_headers($url);
$is_error = true;
$this->addData('headers', $headers);
// Defaults.
$this->error_message = __('AVIF server test failed. Your server may not be configured to display AVIF files correctly. Serving AVIF might cause your images not to load. Check your images, disable the AVIF option, or update your web server configuration.', 'shortpixel-image-optimiser');
$this->error_detail = __('The request did not return valid HTTP headers. Check if the plugin is allowed to access ' . $url, 'shortpixel-image-optimiser');
$contentType = null;
$response = $headers[0];
if (is_array($headers) )
{
foreach($headers as $index => $header)
{
if ( strpos(strtolower($header), 'content-type') !== false )
{
// This is another header that can interrupt.
if (strpos(strtolower($header), 'x-content-type-options') === false)
{
$contentType = $header;
}
}
}
// http not ok, redirect etc. Shouldn't happen.
if (is_null($response) || strpos($response, '200') === false)
{
$this->error_detail = sprintf(__('AVIF check could not be completed because the plugin could not retrieve %s %s %s. %s Please check the security/firewall settings and try again', 'shortpixel-image-optimiser'), '<a href="' . $url . '">', $url, '</a>', '<br>');
}
elseif(is_null($contentType) || strpos($contentType, 'avif') === false)
{
$this->error_detail = sprintf(__('The required Content-type header for AVIF files was not found. Please check this with your hosting and/or CDN provider. For more details on how to fix this issue, %s see this article %s', 'shortpixel_image_optimiser'), '<a href="https://shortpixel.com/blog/avif-mime-type-delivery-apache-nginx/" target="_blank"> ', '</a>');
}
else
{
$is_error = false;
}
}
if ($is_error)
{
if (is_null($this->notice) || $this->notice->isDismissed() === false)
{
$this->addManual();
}
}
else
{
$this->reset();
$item = $cache->getItem('avif_server_check');
$item->setValue(time());
$item->setExpires(MONTH_IN_SECONDS);
$cache->storeItemObject($item );
}
}
}
protected function getMessage()
{
$headers = $this->getData('headers');
$message = '<h4>' . $this->error_message . '</h4><p>' . $this->error_detail . '</p><p class="small">' . __('Returned headers for:<br>', 'shortpixel-image-optimiser') . print_r($headers, true) . '</p>';
return $message;
}
}

View File

@ -0,0 +1,219 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class CompatNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_COMPAT';
protected $errorLevel = 'warning';
protected function checkTrigger()
{
$conflictPlugins = $this->getConflictingPlugins();
if (count($conflictPlugins) > 0)
{
$this->addData('conflicts', $conflictPlugins);
return true;
}
else {
return false;
}
}
protected function getMessage()
{
$conflicts = $this->getData('conflicts');
if (! is_array($conflicts))
$conflicts = array();
$message = __("The following plugins are not compatible with ShortPixel and may cause unexpected results: ",'shortpixel-image-optimiser');
$message .= '<ul class="sp-conflict-plugins">';
foreach($conflicts as $plugin) {
//ShortPixelVDD($plugin);
$action = $plugin['action'];
$link = ( $action == 'Deactivate' )
? wp_nonce_url( admin_url( 'admin-post.php?action=shortpixel_deactivate_conflict_plugin&plugin=' . urlencode( $plugin['path'] ) ), 'sp_deactivate_plugin_nonce' )
: $plugin['href'];
$message .= '<li class="sp-conflict-plugins-list"><strong>' . $plugin['name'] . '</strong>';
$message .= '<a href="' . $link . '" class="button button-primary">' . $action . '</a>';
if($plugin['details']) $message .= '<br>';
if($plugin['details']) $message .= '<span>' . $plugin['details'] . '</span>';
}
$message .= "</ul>";
return $message;
}
protected function getConflictingPlugins() {
$settings = \wpSPIO()->settings();
$conflictPlugins = array(
'WP Smush - Image Optimization'
=> array(
'action'=>'Deactivate',
'data'=>'wp-smushit/wp-smush.php',
'page'=>'wp-smush-bulk'
),
'Imagify Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'imagify/imagify.php',
'page'=>'imagify'
),
'Compress JPEG & PNG images (TinyPNG)'
=> array(
'action'=>'Deactivate',
'data'=>'tiny-compress-images/tiny-compress-images.php',
'page'=>'tinify'
),
'Kraken.io Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'kraken-image-optimizer/kraken.php',
'page'=>'wp-krakenio'
),
'Optimus - WordPress Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'optimus/optimus.php',
'page'=>'optimus'
),
'Phoenix Media Rename' => array(
'action' => 'Deactivate',
'data' => 'phoenix-media-rename/phoenix-media-rename.php',
),
'EWWW Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'ewww-image-optimizer/ewww-image-optimizer.php',
'page'=>'ewww-image-optimizer%2F'
),
'EWWW Image Optimizer Cloud'
=> array(
'action'=>'Deactivate',
'data'=>'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
'page'=>'ewww-image-optimizer-cloud%2F'
),
'ImageRecycle pdf & image compression'
=> array(
'action'=>'Deactivate',
'data'=>'imagerecycle-pdf-image-compression/wp-image-recycle.php',
'page'=>'option-image-recycle'
),
'CheetahO Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'cheetaho-image-optimizer/cheetaho.php',
'page'=>'cheetaho'
),
'Zara 4 Image Compression'
=> array(
'action'=>'Deactivate',
'data'=>'zara-4/zara-4.php',
'page'=>'zara-4'
),
'CW Image Optimizer'
=> array(
'action'=>'Deactivate',
'data'=>'cw-image-optimizer/cw-image-optimizer.php',
'page'=>'cw-image-optimizer'
),
'Simple Image Sizes'
=> array(
'action'=>'Deactivate',
'data'=>'simple-image-sizes/simple_image_sizes.php'
),
'Regenerate Thumbnails and Delete Unused'
=> array(
'action' => 'Deactivate',
'data' => 'regenerate-thumbnails-and-delete-unused/regenerate_wpregenerate.php',
),
'Swift Performance'
=> array(
'action' => 'Deactivate',
'data' => 'swift-performance/performance.php',
),
'Swift AI'
=> array(
'action' => 'Deactivate',
'data' => 'swift-ai/main.php',
),
'Swift Performance Lite'
=> array(
'action' => 'Deactivate',
'data' => 'swift-performance-lite/performance.php',
),
//DEACTIVATED TEMPORARILY - it seems that the customers get scared.
/* 'Jetpack by WordPress.com - The Speed up image load times Option'
=> array(
'action'=>'Change Setting',
'data'=>'jetpack/jetpack.php',
'href'=>'admin.php?page=jetpack#/settings'
)
*/
);
if($settings->processThumbnails) {
$details = __('Details: recreating image files may require re-optimization of the resulting thumbnails, even if they were previously optimized. Please use <a href="https://wordpress.org/plugins/regenerate-thumbnails-advanced/" target="_blank">reGenerate Thumbnails Advanced</a> instead.','shortpixel-image-optimiser');
$conflictPlugins = array_merge($conflictPlugins, array(
'Regenerate Thumbnails'
=> array(
'action'=>'Deactivate',
'data'=>'regenerate-thumbnails/regenerate-thumbnails.php',
'page'=>'regenerate-thumbnails',
'details' => $details
),
'Force Regenerate Thumbnails'
=> array(
'action'=>'Deactivate',
'data'=>'force-regenerate-thumbnails/force-regenerate-thumbnails.php',
'page'=>'force-regenerate-thumbnails',
'details' => $details
)
));
}
$found = array();
foreach($conflictPlugins as $name => $path) {
$action = ( isset($path['action']) ) ? $path['action'] : null;
$data = ( isset($path['data']) ) ? $path['data'] : null;
$href = ( isset($path['href']) ) ? $path['href'] : null;
$page = ( isset($path['page']) ) ? $path['page'] : null;
$details = ( isset($path['details']) ) ? $path['details'] : null;
if(is_plugin_active($data)) {
// Local checks for things. If too much this needs some other impl.
if( $data == 'jetpack/jetpack.php' ){
$jetPackPhoton = get_option('jetpack_active_modules') ? in_array('photon', get_option('jetpack_active_modules')) : false;
if( !$jetPackPhoton ){ continue; }
}
if ($data == 'swift-performance/performance.php' || $data == 'swift-ai/main.php')
{
if (false === $this->checkSwiftActive())
{
continue;
}
}
$found[] = array( 'name' => $name, 'action'=> $action, 'path' => $data, 'href' => $href , 'page' => $page, 'details' => $details);
}
}
return $found;
}
private function checkSwiftActive()
{
if ( function_exists('swift3_check_option') && true == swift3_check_option('optimize-images', 'on'))
{
return true;
}
return false;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class LegacyNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_CONVERT_LEGACY';
protected function checkTrigger()
{
return false;
}
protected function getMessage()
{
$message = '<p><strong>' . __('ShortPixel has found items in the media library with an outdated optimization format!', 'shortpixel-image-optimiser') . '</strong></p>';
$message .= '<p>' . __('Prior to version 5.0, a different format was used to store ShortPixel optimization information. ShortPixel automatically migrates the media library items to the new format when they are opened. %s Please check if your images contain the optimization information after migration. %s Read more %s', 'shortpixel-image-optimiser') . '</p>';
$message .= '<p>' . __('It is recommended to migrate all items to the modern format by clicking the button below.', 'shortpixel-image-optimser') . '</p>';
$message .= '<p><a href="%s" class="button button-primary">%s</a></p>';
$read_link = esc_url('https://shortpixel.com/knowledge-base/article/539-spio-5-tells-me-to-convert-legacy-data-what-is-this');
$action_link = esc_url(admin_url('upload.php?page=wp-short-pixel-bulk&panel=bulk-migrate'));
$action_name = __('Migrate optimization data', 'shortpixel-image-optimiser');
$message = sprintf($message, '<br>', '<a href="' . $read_link . '" target="_blank">', '</a>', $action_link, $action_name);
return $message;
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use ShortPixel\ShortPixelLogger\ShortPixelLogger as Log;
class ListviewNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_LISTVIEW_ACTIVE';
public function __construct()
{
$this->include_screens[] = 'upload';
parent::__construct();
}
/*public function load()
{
parent::load();
// Reset this notice even when dismissed when condition changed.
if ($this->isDismissed() && $this->checkReset() === true)
{
$this->reset();
}
} */
protected function checkTrigger()
{
// Don't check for this, when not on this screen.
$screen_id = \wpSPIO()->env()->screen_id;
if ($screen_id !== 'upload')
{
return false;
}
if (! function_exists('wp_get_current_user') )
{
return false;
}
$viewMode = get_user_option('media_library_mode', get_current_user_id() );
if ($viewMode === "" || strlen($viewMode) == 0)
{
// If nothing is set, set it for them.
update_user_option( get_current_user_id(), 'media_library_mode', 'list' );
return false;
}
elseif ($viewMode !== "list")
{
return true;
}
else
{
if (is_object($this->getNoticeObj()))
$this->reset();
}
return false;
}
protected function checkReset()
{
if (! function_exists('wp_get_current_user') )
{
return false;
}
$current_user = wp_get_current_user();
$currentUserID = $current_user->ID;
$viewMode = get_user_meta($currentUserID, "wp_media_library_mode", true);
if ($viewMode == 'list')
{
return true;
}
return false;
}
protected function getMessage()
{
$message = sprintf(__('Now you can see ShortPixel Image Optimizer\'s actions and optimization data in Grid view too! Click on any image below and you can see the ShortPixel actions and menus in the popup that opens. However, the list view provides a better experience. Click now to %sswitch to the list view%s. ', 'shortpixel-image-optimiser'), '<a href="' . admin_url('upload.php?mode=list') . '">','</a>');
return $message;
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class NewExclusionFormat extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_EXCLUSION_WARNING';
protected function checkTrigger()
{
$patterns = \wpSPIO()->settings()->excludePatterns;
if (! is_array($patterns))
{
return false;
}
foreach($patterns as $index => $pattern)
{
if (! isset($pattern['apply']))
{
return true;
}
}
return false;
}
protected function getMessage()
{
$message = "<p>" . __('As of version 5.5.0, ShortPixel Image Optimiser also checks thumbnails for exclusions. This can change which images are optimized and which are excluded. Please check your exclusion rules on the '
. '<a href="options-general.php?page=wp-shortpixel-settings&part=adv-settings">ShortPixel Settings</a> page.','shortpixel-image-optimiser') . "
</p>";
return $message;
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class NextgenNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_INTEGRATION_NGGALLERY';
protected function checkTrigger()
{
$settings = \wpSPIO()->settings();
if (! $settings->verifiedKey)
{
return false; // no key, no integrations.
}
if (\wpSPIO()->env()->has_nextgen && ! $settings->includeNextGen)
{
return true;
}
return false;
}
protected function getMessage()
{
$url = esc_url(admin_url('options-general.php?page=wp-shortpixel-settings&part=adv-settings'));
$message = sprintf(__('You seem to be using NextGen Gallery. You can optimize your galleries with ShortPixel, but this is not currently enabled. To enable it, %sgo to settings and enable%s it!', 'shortpixel_image_optimiser'), '<a href="' . $url . '">', '</a>');
return $message;
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use ShortPixel\Controller\StatsController as StatsController;
use ShortPixel\Controller\AdminNoticesController as AdminNoticesController;
use ShortPixel\Controller\QuotaController as QuotaController;
class QuotaNoticeMonth extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_UPGRADE_MONTH';
public function load()
{
$this->callback = array(AdminNoticesController::getInstance(), 'proposeUpgradePopup');
parent::load();
}
protected function checkTrigger()
{
$quotaController = QuotaController::getInstance();
if ($quotaController->hasQuota() === false)
return false;
$quotaData = $quotaController->getQuota();
if ($this->monthlyUpgradeNeeded($quotaData) === false)
return false;
$this->addData('average', $this->getMonthAverage());
$this->addData('month_total', $quotaData->monthly->total);
$this->addData('onetime_remaining', $quotaData->onetime->remaining);
}
protected function getMessage()
{
$quotaController = QuotaController::getInstance();
$quotaData = $quotaController->getQuota();
$average = $this->getMonthAverage(); // $this->getData('average');
$month_total = $quotaData->monthly->total;// $this->getData('month_total');
$onetime_remaining = $quotaData->onetime->remaining; //$this->getData('onetime_remaining'); */
$message = '<p>' . sprintf(__("You add an average of <strong>%d images and thumbnails</strong> to your Media Library every month and you have <strong>a plan of %d images/month (and %d one-time images)</strong>.%s"
. " You may need to upgrade your plan to have all your images optimized.", 'shortpixel-image-optimiser'), $average, $month_total, $onetime_remaining, '<br>') . '</p>';
$message .= ' <button class="button button-primary" id="shortpixel-upgrade-advice" onclick="ShortPixel.proposeUpgrade()" style="margin-right:10px;"><strong>' . __('Show me the best available options', 'shortpixel-image-optimiser') . '</strong></button>';
return $message;
}
protected function CheckUpgradeNeeded($quotaData)
{
if (isset($quotaData->monthly->total) && !$quotaData->unlimited)
{
$monthAvg = $this->getMonthAvg($quotaData);
// +20 I suspect to not trigger on very low values of monthly use(?)
$threshold = $quotaData->monthly->total + ($quotaData->onetime->remaining / 6 ) +20;
if ($monthAvg > $threshold)
{
return true;
}
}
return false;
}
protected function getMonthAverage() {
$stats = StatsController::getInstance();
// Count how many months have some optimized images.
for($i = 4, $count = 0; $i>=1; $i--) {
if($count == 0 && $stats->find('period', 'months', $i) == 0)
{
continue;
}
$count++;
}
// Sum last 4 months, and divide by number of active months to get number of avg per active month.
return ($stats->find('period', 'months', 1) + $stats->find('period', 'months', 2) + $stats->find('period', 'months', 3) + $stats->find('period', 'months', 4) / max(1,$count));
}
protected function monthlyUpgradeNeeded($quotaData)
{
if (isset($quotaData->monthly->total))
{
$monthAvg = $this->getMonthAverage($quotaData);
// +20 I suspect to not trigger on very low values of monthly use(?)
$threshold = $quotaData->monthly->total + ($quotaData->onetime->remaining / 6 ) +20;
if ($monthAvg > $threshold)
{
return true;
}
}
return false;
}
} // class

View File

@ -0,0 +1,111 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use ShortPixel\Controller\StatsController as StatsController;
use ShortPixel\Controller\ApiKeyController as ApiKeyController;
use ShortPixel\Controller\AdminNoticesController as AdminNoticesController;
use ShortPixel\Controller\QuotaController as QuotaController;
class QuotaNoticeReached extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_QUOTA_REACHED';
protected $errorLevel = 'error';
public function load()
{
$this->callback = array(AdminNoticesController::getInstance(), 'proposeUpgradePopup');
parent::load();
}
protected function checkTrigger()
{
$quotaController = QuotaController::getInstance();
if ($quotaController->hasQuota() === true)
return false;
// $quotaData = $quotaController->getQuota();
$this->reset('MSG_UPGRADE_MONTH');
$this->reset('MSG_UPGRADE_BULK');
return true;
}
protected function getMessage()
{
$statsControl = StatsController::getInstance();
$averageCompression = $statsControl->getAverageCompression();
$quotaController = QuotaController::getInstance();
$keyControl = ApiKeyController::getInstance();
//$keyModel->loadKey();
$login_url = 'https://shortpixel.com/login/';
$friend_url = $login_url;
if ($keyControl->getKeyForDisplay())
{
$login_url .= $keyControl->getKeyForDisplay() . '/spio-unlimited';
$friend_url = $login_url . 'tell-a-friend';
}
$message = '<div class="sp-quota-exceeded-alert" id="short-pixel-notice-exceed">';
if($averageCompression) {
$message .= '<div style="float:right;">
<div class="bulk-progress-indicator" style="height: 110px">
<div style="margin-bottom:5px">' . __('Average image<br>reduction until now:','shortpixel-image-optimiser') . '</div>
<div id="sp-avg-optimization"><input type="text" id="sp-avg-optimization-dial" value="' . round($averageCompression) . '" class="dial percentDial" data-dialsize="60"></div>
<script>
jQuery(function() {
if (ShortPixel)
{
ShortPixel.percentDial("#sp-avg-optimization-dial", 60);
}
});
</script>
</div>
</div>';
}
$message .= '<h3>' . __('Quota Exceeded','shortpixel-image-optimiser') . '</h3>';
$quota = $quotaController->getQuota();
$creditsUsed = number_format($quota->monthly->consumed + $quota->onetime->consumed);
$totalOptimized = $statsControl->find('total', 'images');
$totalImagesToOptimize = number_format($statsControl->totalImagesToOptimize());
$message .= '<p>' . sprintf(__('The plugin has optimized <strong>%s images</strong> and has been stopped because it has reached the available quota limit.','shortpixel-image-optimiser'),
$creditsUsed);
if($totalImagesToOptimize > 0) {
$message .= sprintf(__('<strong> %s images and thumbnails</strong> have not been optimized by ShortPixel yet.','shortpixel-image-optimiser'), $totalImagesToOptimize );
}
$message .= sprintf('</p>
<div>
<button class="button button-primary" type="button" id="shortpixel-upgrade-advice" onclick="ShortPixel.proposeUpgrade()" style="margin-right:10px;"><strong>' . __('Show me the best available options', 'shortpixel-image-optimiser') . '</strong></button>
<a class="button button-primary" href="%s"
title="' . __('Go to My Account and choose a plan','shortpixel-image-optimiser') . '" target="_blank" style="margin-right:10px;">
<strong>' . __('Upgrade','shortpixel-image-optimiser') . '</strong>
</a>
<button type="button" name="checkQuota" class="button" onclick="ShortPixel.checkQuota()">'. __('Confirm new credits','shortpixel-image-optimiser') . '</button>
</div>', $login_url);
$message .= '</div>'; /// closing div
return $message;
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace ShortPixel\Model\AdminNotices;
class SmartcropNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_FEATURE_SMARTCROP';
public function __construct()
{
$this->exclude_screens[] = 'settings_page_wp-shortpixel-settings';
parent::__construct();
}
protected function checkTrigger()
{
$settings = \wpSPIO()->settings();
if (! $settings->verifiedKey)
{
return false; // no key, no integrations.
}
if (! $settings->useSmartcrop)
{
return true;
}
return false;
}
protected function checkReset()
{
$settings = \wpSPIO()->settings();
if ($settings->useSmartcrop == true)
{
return true;
}
return false;
}
protected function getMessage()
{
$link = 'https://shortpixel.com/knowledge-base/article/182-what-is-smart-cropping';
$link2 = 'https://shortpixel.com/blog/how-to-smart-crop-wordpress-images/#how-to-crop-wordpress-images-automatically-smart-solution';
$link3 = esc_url(admin_url('options-general.php?page=wp-shortpixel-settings'));
$message = sprintf(__('%s With ShortPixel you can now %ssmartly crop%s thumbnails on your website. This is especially useful for eCommerce websites %s(read more)%s. %s %s Enable the option on the %sShortPixel Settings%s page. %s', 'shortpixel-image-optimiser'),
'<p>' ,
'<a href="' . $link . '" target="_blank">', '</a>',
'<a href="' . $link2 . '" target="_blank">', '</a>',
'</p>', '<p>',
'<a href="' . $link3 . '" >', '</a>',
'</p>'
);
return $message;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace ShortPixel\Model\AdminNotices;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class UnlistedNotice extends \ShortPixel\Model\AdminNoticeModel
{
protected $key = 'MSG_UNLISTED_FOUND';
protected function checkTrigger()
{
return false;
}
// @todo This message is not properly stringF'ed.
protected function getMessage()
{
$settings = \wpSPIO()->settings();
//$unlisted = isset($settings->currentStats['foundUnlistedThumbs']) ? $settings->currentStats['foundUnlistedThumbs'] : null;
$unlisted_id = $this->getData('id');
$unlisted_name = $this->getData('name');
$unlistedFiles = (is_array($this->getData('filelist'))) ? $this->getData('filelist') : array();
$admin_url = esc_url(admin_url('options-general.php?page=wp-shortpixel-settings&part=adv-settings'));
$message = __("<p>ShortPixel has found thumbnails that are not registered in the metadata, but are present alongside the other thumbnails. These thumbnails could be created and needed by a plugin or the theme. Let ShortPixel optimize them too?</p>", 'shortpixel-image-optimiser');
$message .= '<p>' . __("For example, the image", 'shortpixel-image-optimiser') . '
<a href="post.php?post=' . $unlisted_id . '&action=edit" target="_blank">
' . $unlisted_name . '
</a> also has these thumbnails that are not listed in the metadata: ' . (implode(', ', $unlistedFiles)) . '
</p>';
$message .= '<p>' . sprintf(__('You can enable optimizing %s Unlisted Images %s in the %s settings %s', 'shortpixel-image-optimiser'), '<b>', '</b>', '<a href="'. $admin_url . '">','</a>') . '</p>';
return $message;
}
}