tenweb-speed-optimizer
/
vendor
/
10web-utils
/
tenweb-image-optimizer
/
src
/
TenWebIO
/
Views
/
LogsView.php
tenweb-speed-optimizer
/
vendor
/
10web-utils
/
tenweb-image-optimizer
/
src
/
TenWebIO
/
Views
Last commit date
LogsView.php
2 years ago
LogsView.php
162 lines
| 1 | <?php |
| 2 | namespace TenWebIO\Views; |
| 3 | |
| 4 | use TenWebIO\CompressDataService; |
| 5 | use TenWebIO\Config; |
| 6 | use TenWebIO\Logs; |
| 7 | use TenWebIO\Settings; |
| 8 | use TenWebIO\Utils; |
| 9 | |
| 10 | class LogsView |
| 11 | { |
| 12 | private $config; |
| 13 | private $compress_data_service; |
| 14 | |
| 15 | /** |
| 16 | * @return void |
| 17 | */ |
| 18 | public function __construct() |
| 19 | { |
| 20 | $this->compress_data_service = new CompressDataService(); |
| 21 | $this->config = new Config(); |
| 22 | add_action('admin_menu', array($this, 'menu')); |
| 23 | add_action('admin_init', array($this, 'init')); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return void |
| 28 | */ |
| 29 | public function menu() |
| 30 | { |
| 31 | add_submenu_page('', 'Image Optimizer', 'Logs', 'manage_options', TENWEBIO_PREFIX . '_logs', array($this, 'view')); |
| 32 | } |
| 33 | |
| 34 | public function init() |
| 35 | { |
| 36 | if (isset($_POST["clear_logs"])) { |
| 37 | check_admin_referer('nonce_' . TENWEBIO_PREFIX, 'nonce_' . TENWEBIO_PREFIX); |
| 38 | Logs::clearLogs(); |
| 39 | } else if (isset($_POST["clear_settings"])) { |
| 40 | check_admin_referer('nonce_' . TENWEBIO_PREFIX, 'nonce_' . TENWEBIO_PREFIX); |
| 41 | Settings::purgeCompressSettings(); |
| 42 | delete_site_option(TENWEBIO_PREFIX . '_running_compress_bulk'); |
| 43 | } else if (isset($_POST["save_configs"])) { |
| 44 | check_admin_referer('nonce_' . TENWEBIO_PREFIX, 'nonce_' . TENWEBIO_PREFIX); |
| 45 | $this->config->save($_POST); |
| 46 | } else if (isset($_POST["cancel_compress"])) { |
| 47 | check_admin_referer('nonce_' . TENWEBIO_PREFIX, 'nonce_' . TENWEBIO_PREFIX); |
| 48 | Utils::finishQueue('bulk'); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return void |
| 54 | */ |
| 55 | public function view() |
| 56 | { |
| 57 | $logs = Logs::getLogs(); |
| 58 | $compress_logs = $this->compress_data_service->getNotCompressedNumbers(true); |
| 59 | ?> |
| 60 | <div> |
| 61 | <div> |
| 62 | <h1>Compress Report:</h1> |
| 63 | <div> |
| 64 | <table class="wp-list-table widefat fixed striped pages"> |
| 65 | <tr> |
| 66 | <td>Not optimized full</td> |
| 67 | <td><?php echo $compress_logs['not_optimized']['full']; ?></td> |
| 68 | </tr> |
| 69 | <tr> |
| 70 | <td>Not optimized thumbs</td> |
| 71 | <td><?php echo $compress_logs['not_optimized']['thumbs']; ?></td> |
| 72 | </tr> |
| 73 | <tr> |
| 74 | <td>Not optimized other</td> |
| 75 | <td><?php echo $compress_logs['not_optimized']['other']; ?></td> |
| 76 | </tr> |
| 77 | <tr> |
| 78 | <td>Last optimized total</td> |
| 79 | <td><?php echo $compress_logs['last_optimized']['size']; ?> |
| 80 | (<?php echo $compress_logs['last_optimized']['percent']; ?>%) |
| 81 | </td> |
| 82 | </tr> |
| 83 | </table> |
| 84 | <br><br> |
| 85 | </div> |
| 86 | </div> |
| 87 | <form |
| 88 | method="post" |
| 89 | id="logs_form" |
| 90 | action=""> |
| 91 | <?php wp_nonce_field('nonce_' . TENWEBIO_PREFIX, 'nonce_' . TENWEBIO_PREFIX); ?> |
| 92 | <h1>Configs</h1> |
| 93 | <table class="wp-list-table widefat fixed striped pages"> |
| 94 | <tr> |
| 95 | <td>Debug mode</td> |
| 96 | <td><input type="checkbox" value="1" id="iowd_config_debug" |
| 97 | name="debug_mode" <?php echo $this->config->getDebugMode() ? 'checked="checked"' : ''; ?>> |
| 98 | </td> |
| 99 | </tr> |
| 100 | <tr> |
| 101 | <td>Images count limit for restart</td> |
| 102 | <td><input type="text" value="<?php echo $this->config->getImagesLimitForRestart(); ?>" |
| 103 | id="iowd_config_images_limit_for_restart" |
| 104 | name="images_limit_for_restart"></td> |
| 105 | </tr> |
| 106 | <tr> |
| 107 | <td>Queue chunk images limit</td> |
| 108 | <td><input type="text" value="<?php echo $this->config->getQueueChunkImagesLimit(); ?>" |
| 109 | id="iowd_config_queue_chunk_images_limit" |
| 110 | name="queue_chunk_images_limit"></td> |
| 111 | </tr> |
| 112 | <tr> |
| 113 | <td>Stat chunk images limit</td> |
| 114 | <td><input type="text" value="<?php echo $this->config->getStatChunkImagesLimit(); ?>" |
| 115 | id="iowd_config_stat_chunk_images_limit" |
| 116 | name="stat_chunk_images_limit"></td> |
| 117 | </tr> |
| 118 | <tr> |
| 119 | <td>Auto optimize with rest</td> |
| 120 | <td><input type="checkbox" value="1" id="iowd_config_auto_optimize_with_rest" |
| 121 | name="auto_optimize_with_rest" <?php echo $this->config->getAutoOptimizeWithRest() ? 'checked="checked"' : ''; ?>> |
| 122 | </td> |
| 123 | </tr> |
| 124 | <tr> |
| 125 | <td>Compress only full size</td> |
| 126 | <td><input type="checkbox" value="1" id="iowd_compress_only_full_size" |
| 127 | name="compress_only_full_size" <?php echo $this->config->getCompressOnlyFullSize() ? 'checked="checked"' : ''; ?>> |
| 128 | </td> |
| 129 | </tr> |
| 130 | </table> |
| 131 | <br> |
| 132 | <input type="submit" class="button action" value="Clear Logs" name="clear_logs"> |
| 133 | <input type="submit" class="button action" value="Clear Settings" name="clear_settings"> |
| 134 | <input type="submit" class="button action" value="Save Configs" name="save_configs"> |
| 135 | <input type="submit" class="button action" value="Cancel running compress" name="cancel_compress"> |
| 136 | </form> |
| 137 | <h1>Optimization Logs</h1> |
| 138 | <table class="wp-list-table widefat fixed striped pages"> |
| 139 | <thead> |
| 140 | <tr> |
| 141 | <th>Type</th> |
| 142 | <th>Key</th> |
| 143 | <th>Message</th> |
| 144 | <th>Date</th> |
| 145 | </tr> |
| 146 | </thead> |
| 147 | <?php foreach ($logs as $key => $log) { ?> |
| 148 | <tr> |
| 149 | <td><?php echo !empty($log["type"]) ? $log["type"] : 'log'; ?></td> |
| 150 | <td><?php echo $key; ?></td> |
| 151 | <td><?php echo $log["msg"]; ?></td> |
| 152 | <td><?php echo $log["date"]; ?></td> |
| 153 | </tr> |
| 154 | <?php } ?> |
| 155 | </table> |
| 156 | </div> |
| 157 | |
| 158 | <?php |
| 159 | } |
| 160 | |
| 161 | } |
| 162 |