PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.6 2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / admin / pages / class-rio-statistic.php
robin-image-optimizer / admin / pages Last commit date
class-rio-license.php 3 months ago class-rio-log.php 7 months ago class-rio-page.php 7 months ago class-rio-settings.php 7 months ago class-rio-statistic.php 7 months ago index.php 3 years ago
class-rio-statistic.php
360 lines
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Class WRIO_StatisticPage
9 * Класс отвечает за работу страницы статистики
10 */
11 class WRIO_StatisticPage extends WRIO_Page {
12
13 /**
14 * {@inheritdoc}
15 */
16 public $id = 'rio_general';
17
18 /**
19 * {@inheritdoc}
20 */
21 public $type = 'page';
22
23 /**
24 * {@inheritdoc}
25 */
26 public $plugin;
27
28 /**
29 * {@inheritdoc}
30 */
31 public $page_menu_position = 20;
32
33 /**
34 * {@inheritdoc}
35 */
36 public $page_menu_dashicon = 'dashicons-chart-line';
37
38 /**
39 * Menu icon for WordPress admin sidebar.
40 *
41 * @var string
42 */
43 public $menu_icon = 'dashicons-images-alt';
44
45 /**
46 * Position in WordPress admin menu (58 = between Comments and Appearance).
47 *
48 * @var string
49 */
50 public $menu_position = '58';
51
52 /**
53 * @var string
54 */
55 public $menu_target = null;
56
57 /**
58 * {@inheritdoc}
59 *
60 * @var null
61 */
62 public $page_parent_page = null;
63
64 /**
65 * @var bool
66 */
67 public $internal = false;
68
69 /**
70 * @var bool
71 */
72 public $add_link_to_plugin_actions = true;
73
74 /**
75 * Page type
76 *
77 * @since 1.3.0
78 * @var string
79 */
80 protected $scope = 'media-library';
81
82
83 /**
84 * @param WRIO_Plugin $plugin
85 */
86 public function __construct( WRIO_Plugin $plugin ) {
87 $this->menu_title = __( 'Robin Image Optimizer', 'robin-image-optimizer' );
88 $this->menu_sub_title = __( 'Optimize', 'robin-image-optimizer' );
89 $this->page_menu_short_description = __( 'Compress bulk of images', 'robin-image-optimizer' );
90 $this->plugin = $plugin;
91
92 parent::__construct( $plugin );
93
94 add_action( 'admin_enqueue_scripts', [ $this, 'print_i18n' ] );
95
96 add_filter( 'wbcr/factory/pages/impressive/print_all_notices', [ $this, 'register_limit_notice' ], 10, 2 );
97 }
98
99 /**
100 * @param $plugin
101 * @param $obj
102 *
103 * @return void|bool
104 */
105 public function register_limit_notice( $plugin, $obj ) {
106 if ( ( $this->plugin->getPluginName() !== $plugin->getPluginName() ) || ( 'rio_general' !== $obj->id ) ) {
107 return false;
108 }
109 }
110
111 /**
112 * Подменяем простраинство имен для меню плагина, если активирован плагин
113 * Меню текущего плагина будет добавлено в общее мен
114 *
115 * @return string
116 */
117 public function getMenuScope() {
118 if ( $this->clearfy_collaboration ) {
119 // $this->internal = true;
120
121 return 'wbcr_clearfy';
122 }
123
124 return 'robin-image-optimizer';
125 }
126
127 /**
128 * {@inheritdoc}
129 */
130 public function getMenuTitle() {
131 return $this->menu_title;
132 }
133
134 /**
135 * {@inheritdoc}
136 */
137 public function getPageTitle() {
138 return $this->clearfy_collaboration ? __( 'Image optimizer', 'robin-image-optimizer' ) : __( 'Bulk optimization', 'robin-image-optimizer' );
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 public function assets( $scripts, $styles ) {
145 parent::assets( $scripts, $styles );
146
147 $this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/base-statistic.css' );
148
149 $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/sweetalert2.js' );
150 $this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/sweetalert2.css' );
151 $this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/sweetalert-custom.css' );
152
153 $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/Chart.min.js' );
154 // $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/statistic.js' );
155
156 $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/modals.js', [ 'jquery' ], 'wrio-modals' );
157 $this->scripts->add(
158 WRIO_PLUGIN_URL . '/admin/assets/js/bulk-optimization.js',
159 [
160 'jquery',
161 'wrio-modals',
162 ]
163 );
164
165 $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/calculate-attachments.js' );
166
167 $this->scripts->add(
168 WRIO_PLUGIN_URL . '/admin/assets/js/bulk-conversion.js',
169 [
170 'jquery',
171 'wrio-modals',
172 ]
173 );
174
175 if ( defined( 'WBCR_CLEARFY_PLUGIN_ACTIVE' ) ) {
176 $this->styles->add( WCL_PLUGIN_URL . '/admin/assets/css/general.css' );
177 }
178 }
179
180 /**
181 * Print localization only current page
182 *
183 * @throws \Exception
184 * @since 1.3.0
185 */
186 public function print_i18n() {
187 $page = $this->plugin->request->get( 'page', null );
188
189 if ( $page !== $this->getResultId() ) {
190 return;
191 }
192
193 $backup = new WIO_Backup();
194
195 wp_enqueue_script( 'wio-statistic-page', WRIO_PLUGIN_URL . '/admin/assets/js/statistic.js', [ 'jquery' ], WRIO_Plugin::app()->getPluginVersion(), true );
196 wp_localize_script( 'wio-statistic-page', 'wrio_l18n_bulk_page', $this->get_i18n() );
197
198 wp_localize_script(
199 'wio-statistic-page',
200 'wrio_settings_bulk_page',
201 [
202 'is_premium' => wrio_is_license_activate(),
203 'is_network_admin' => WRIO_Plugin::app()->isNetworkAdmin() ? 1 : 0,
204 'is_writable_backup_dir' => $backup->isBackupWritable() ? 1 : 0,
205 'images_backup' => WRIO_Plugin::app()->getPopulateOption( 'backup_origin_images', false ) ? 1 : 0,
206 'need_migration' => wbcr_rio_has_meta_to_migrate() ? 1 : 0,
207 'scope' => $this->scope,
208 'optimization_nonce' => wp_create_nonce( 'bulk_optimization' ),
209 'conversion_nonce' => wp_create_nonce( 'bulk_conversion' ),
210 ]
211 );
212 }
213
214 /**
215 * {@inheritdoc}
216 */
217 public function showPageContent() {
218 $is_premium = wrio_is_license_activate();
219 $statistics = $this->get_statisctic_data();
220
221 $template_data = [
222 'is_premium' => $is_premium,
223 'scope' => $this->scope,
224 ];
225
226 // do_action( 'wbcr/rio/multisite_current_blog' );
227
228 // Page header
229 $this->view->print_template(
230 'part-page-header',
231 [
232 'title' => __( 'Image optimization dashboard', 'robin-image-optimizer' ),
233 'description' => __( 'Monitor image optimization statistics and run on demand or scheduled optimization.', 'robin-image-optimizer' ),
234 ],
235 $this
236 );
237
238 // Page tabs
239 $this->view->print_template( 'part-bulk-optimization-tabs', $template_data, $this );
240
241 ?>
242 <div class="wbcr-factory-page-group-body" style="padding:0; border-top: 1px solid #d4d4d4;">
243 <?php
244 // Servers
245 $this->view->print_template( 'part-bulk-optimization-servers', $template_data, $this );
246
247 // Total
248 $this->view->print_template(
249 'part-bulk-optimization-total',
250 array_merge(
251 $template_data,
252 [
253 'stats' => $statistics->get(),
254 ]
255 ),
256 $this
257 );
258
259 // Statistic
260 $this->view->print_template(
261 'part-bulk-optimization-statistic',
262 array_merge(
263 $template_data,
264 [
265 'stats' => $statistics->get(),
266 ]
267 ),
268 $this
269 );
270
271 // Optimization log
272 $this->view->print_template(
273 'part-bulk-optimization-log',
274 array_merge(
275 $template_data,
276 [
277 'process_log' => $statistics->get_last_optimized_images(),
278 ]
279 ),
280 $this
281 );
282 ?>
283 </div>
284 <script type="text/html" id="wrio-tmpl-bulk-optimization">
285 <?php $this->view->print_template( 'modal-bulk-optimization' ); ?>
286 </script>
287 <script type="text/html" id="wrio-tmpl-webp-conversion">
288 <?php $this->view->print_template( 'modal-webp-conversion' ); ?>
289 </script>
290 <?php
291 // do_action( 'wbcr/rio/multisite_restore_blog' );
292 }
293
294 /**
295 * @return object|\WRIO_Image_Statistic
296 * @since 1.3.0
297 */
298 protected function get_statisctic_data() {
299 return WRIO_Image_Statistic::get_instance();
300 }
301
302 /**
303 * @return array
304 * @since 1.3.0
305 */
306 protected function get_i18n() {
307 $modal_optimization_cron_button = __( 'Scheduled optimization', 'robin-image-optimizer' );
308 $modal_conversion_cron_button = __( 'Scheduled conversion', 'robin-image-optimizer' );
309 $modal_optimization_cron_button_stop = __( 'Stop schedule optimization', 'robin-image-optimizer' );
310 $modal_conversion_cron_button_stop = __( 'Stop schedule conversion', 'robin-image-optimizer' );
311
312 $optimize_type = WRIO_Plugin::app()->getOption( 'image_optimization_type', 'schedule' );
313 if ( wrio_is_license_activate() && $optimize_type === 'background' ) {
314 $modal_optimization_cron_button = __( 'Background optimization', 'robin-image-optimizer' );
315 $modal_conversion_cron_button = __( 'Background conversion', 'robin-image-optimizer' );
316 $modal_optimization_cron_button_stop = __( 'Stop background optimization', 'robin-image-optimizer' );
317 $modal_conversion_cron_button_stop = __( 'Stop background conversion', 'robin-image-optimizer' );
318 }
319
320 return [
321 'server_down_warning' => __( 'Your selected optimization server is down. This means that you cannot optimize images through this server. Try selecting another optimization server.', 'robin-image-optimizer' ),
322 // translators: the status of server.
323 'server_status_down' => __( 'Down', 'robin-image-optimizer' ),
324 // translators: the status of server.
325 'server_status_stable' => __( 'Stable', 'robin-image-optimizer' ),
326 'modal_error' => __( 'Error', 'robin-image-optimizer' ),
327 'modal_cancel' => __( 'Cancel', 'robin-image-optimizer' ),
328 'modal_confirm' => __( 'Confirm', 'robin-image-optimizer' ),
329
330 'modal_optimization_title' => __( 'Select optimization way', 'robin-image-optimizer' ),
331 'modal_optimization_manual_button' => __( 'Optimize now', 'robin-image-optimizer' ),
332 'modal_optimization_cron_button' => $modal_optimization_cron_button,
333 'modal_optimization_cron_button_stop' => $modal_optimization_cron_button_stop,
334 'optimization_complete' => __( 'All images from the media library are optimized.', 'robin-image-optimizer' ),
335 // translators: %s is the number of remaining images
336 'optimization_inprogress' => sprintf( __( 'Optimization in progress. %s images remaining.', 'robin-image-optimizer' ), '<span id="wio-total-unoptimized">%s</span>' ),
337 'modal_conversion_title' => __( 'Select conversion way', 'robin-image-optimizer' ),
338 'modal_conversion_manual_button' => __( 'Convert now', 'robin-image-optimizer' ),
339 'modal_conversion_cron_button' => $modal_conversion_cron_button,
340 'modal_conversion_cron_button_stop' => $modal_conversion_cron_button_stop,
341 'conversion_complete' => __( 'All images from the media library are optimized.', 'robin-image-optimizer' ),
342 // translators: %s is the number of remaining images
343 'conversion_inprogress' => sprintf( __( 'Conversion in progress. %s images remaining.', 'robin-image-optimizer' ), '<span id="wio-total-unoptimized">%s</span>' ),
344 'webp_button_start' => __( 'Convert to WebP', 'robin-image-optimizer' ),
345 'avif_button_start' => __( 'Convert to AVIF', 'robin-image-optimizer' ),
346 'modal_avif_conversion_title' => __( 'Select AVIF conversion way', 'robin-image-optimizer' ),
347
348 'need_migrations' => __( 'To start optimizing, you must complete migration from old plugin version.', 'robin-image-optimizer' ),
349 'leave_page_warning' => __( 'Optimization is still in progress. Are you sure you want to leave?', 'robin-image-optimizer' ),
350 'process_without_backup' => __( 'Do you want to start optimization without backup?', 'robin-image-optimizer' ),
351 'button_resume' => __( 'Resume', 'robin-image-optimizer' ),
352 'button_completed' => __( 'Completed', 'robin-image-optimizer' ),
353 'button_start' => __( 'Optimize', 'robin-image-optimizer' ),
354 'button_stop' => __( 'Stop', 'robin-image-optimizer' ),
355 // Don't Need a Parachute?
356 // If you keep this option deactivated, you won't be able to re-optimize your images to another compression level and restore your original images in case of need.
357 ];
358 }
359 }
360