| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* JCH Optimize - Performs several front-end optimizations for fast downloads |
| 5 |
* |
| 6 |
* @package jchoptimize/wordpress-platform |
| 7 |
* @author Samuel Marshall <samuel@jch-optimize.net> |
| 8 |
* @copyright Copyright (c) 2025 Samuel Marshall / JCH Optimize |
| 9 |
* @license GNU/GPLv3, or later. See LICENSE file |
| 10 |
* |
| 11 |
* If LICENSE file missing, see <http://www.gnu.org/licenses/>. |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace JchOptimize\WordPress\Model; |
| 15 |
|
| 16 |
use JchOptimize\Core\Registry; |
| 17 |
use JchOptimize\WordPress\Plugin\Updater; |
| 18 |
|
| 19 |
use function add_query_arg; |
| 20 |
use function admin_url; |
| 21 |
use function strlen; |
| 22 |
|
| 23 |
class NotificationIcons |
| 24 |
{ |
| 25 |
public function __construct(private Registry $params, private Updater $updater) |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
public function getNotificationIcons(): array |
| 30 |
{ |
| 31 |
$buttons = []; |
| 32 |
|
| 33 |
$buttons[0]['link'] = admin_url('update-core.php'); |
| 34 |
$buttons[0]['icon'] = 'fa fa-plug'; |
| 35 |
$buttons[0]['id'] = 'plugin-status'; |
| 36 |
|
| 37 |
if($this->updater->updateAvailable()) { |
| 38 |
$buttons[0]['class'] = ['danger']; |
| 39 |
$buttons[0]['name'] = __('Plugin update available', 'jch-optimize'); |
| 40 |
} else { |
| 41 |
$buttons[0]['class'] = ['success']; |
| 42 |
$buttons[0]['name'] = __('Plugin is up to date', 'jch-optimize'); |
| 43 |
} |
| 44 |
|
| 45 |
$configurationsUrl = add_query_arg( |
| 46 |
['page' => 'jch_optimize', 'tab' => 'configurations'], |
| 47 |
admin_url('options-general.php') |
| 48 |
); |
| 49 |
|
| 50 |
if (JCH_PRO) { |
| 51 |
$buttons[1]['id'] = 'download-id-status'; |
| 52 |
$buttons[1]['link'] = "{$configurationsUrl}#general"; |
| 53 |
$buttons[1]['icon'] = 'fa fa-id-badge'; |
| 54 |
|
| 55 |
if (strlen($this->params->get('pro_downloadid', '')) < 32) { |
| 56 |
$buttons[1]['class'] = ['danger']; |
| 57 |
$buttons[1]['name'] = __('Download ID missing', 'jch-optimize'); |
| 58 |
} else { |
| 59 |
$buttons[1]['class'] = ['success']; |
| 60 |
$buttons[1]['name'] = __('Download ID entered', 'jch-optimize'); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
$buttons[2]['id'] = 'page-cache-status'; |
| 65 |
$buttons[2]['link'] = "{$configurationsUrl}#page-cache"; |
| 66 |
$buttons[2]['icon'] = 'fa fa-archive'; |
| 67 |
|
| 68 |
if ($this->params->get('cache_enable')) { |
| 69 |
$buttons[2]['class' ] = ['success']; |
| 70 |
$buttons[2]['name'] = __('Page Cache enabled', 'jch-optimize'); |
| 71 |
} else { |
| 72 |
$buttons[2]['class'] = ['danger']; |
| 73 |
$buttons[2]['name'] = __('Page Cache disabled', 'jch-optimize'); |
| 74 |
} |
| 75 |
|
| 76 |
return $buttons; |
| 77 |
} |
| 78 |
} |
| 79 |
|