' . sprintf(__("You add an average of %d images and thumbnails to your Media Library every month and you have a plan of %d images/month (and %d one-time images).%s"
. " You may need to upgrade your plan to have all your images optimized.", 'shortpixel-image-optimiser'), $average, $month_total, $onetime_remaining, ' ') . '
';
$message .= ' ';
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