| @@ -1,38 +1,66 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 2 | +use Imagify\Bulk\Bulk; | |
| 3 | + | |
| 4 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 5 | ?> |
| 4 | 6 | |
| 5 | 7 | <div class="imagify-bulk-table"> |
| 6 | 8 | <div class="imagify-table-header imagify-flex imagify-vcenter imagify-resting"> |
| 7 | 9 | <div class="imagify-th-titles imagify-flex imagify-vcenter"> |
| 8 | - <span class="dashicons dashicons-<?php echo $data['icon']; ?>"></span> | |
| 10 | + <span class="dashicons dashicons-<?php echo esc_attr( $data['icon'] ); ?>"></span> | |
| 9 | 11 | <div class="imagify-th-titles"> |
| 10 | - <p class="imagify-th-title"><?php echo $data['title']; ?></p> | |
| 12 | + <p class="imagify-th-title"><?php echo esc_html( $data['title'] ); ?></p> | |
| 11 | 13 | </div> |
| 12 | 14 | </div> |
| 15 | + </div> | |
| 13 | 16 | |
| 14 | - <div class="imagify-th-action"> | |
| 15 | - <button class="button imagify-button-clean imagify-show-table-details" type="button" data-label-show="<?php esc_attr_e( 'View Details', 'imagify' ); ?>" data-label-hide="<?php esc_attr_e( 'Hide Details', 'imagify' ); ?>"> | |
| 16 | - <?php esc_html_e( 'View Details', 'imagify' ); ?> | |
| 17 | - <span class="dashicons dashicons-menu"></span> | |
| 18 | - </button> | |
| 19 | - </div> | |
| 20 | - </div> | |
| 17 | + <?php | |
| 18 | + $types = []; | |
| 19 | + $total = 0; | |
| 20 | + $remaining = 0; | |
| 21 | + $percentage = 0; | |
| 21 | 22 | |
| 23 | + foreach ( $data['groups'] as $group ) { | |
| 24 | + $types[ $group['group_id'] . '|' . $group['context'] ] = true; | |
| 25 | + | |
| 26 | + $transient = get_transient( "imagify_{$group['context']}_optimize_running" ); | |
| 27 | + | |
| 28 | + if ( false !== $transient ) { | |
| 29 | + $total += $transient['total']; | |
| 30 | + $remaining += $transient['remaining']; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | + if ( 0 !== $total ) { | |
| 35 | + $percentage = ( $total - $remaining ) / $total * 100; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $bulk = Bulk::get_instance(); | |
| 39 | + $aria_hidden = 'aria-hidden="true"'; | |
| 40 | + $hidden = 'hidden'; | |
| 41 | + $style = ''; | |
| 42 | + $display = ''; | |
| 43 | + | |
| 44 | + if ( | |
| 45 | + 0 !== $percentage | |
| 46 | + && | |
| 47 | + 100 !== $percentage | |
| 48 | + ) { | |
| 49 | + $percentage = round( $percentage ); | |
| 50 | + $aria_hidden = ''; | |
| 51 | + $hidden = ''; | |
| 52 | + $style = 'style="width:' . $percentage . '%;"'; | |
| 53 | + $display = 'style="display:block;"'; | |
| 54 | + } | |
| 55 | + ?> | |
| 56 | + | |
| 22 | 57 | <div class="imagify-bulk-table-content"> |
| 23 | 58 | <div class="imagify-bulk-table-container"> |
| 24 | - <table class="imagify-bulk-table-details hidden" aria-hidden="true"> | |
| 25 | - <thead> | |
| 26 | - </thead> | |
| 27 | - <tbody> | |
| 28 | - </tbody> | |
| 29 | - </table> | |
| 30 | - | |
| 31 | - <div aria-hidden="true" class="imagify-row-progress hidden"> | |
| 59 | + <div <?php echo $aria_hidden; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="imagify-row-progress <?php echo esc_attr( $hidden ); ?>" <?php echo $display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 32 | 60 | <div class="media-item"> |
| 33 | 61 | <div class="progress"> |
| 34 | - <div class="bar"><div class="percent">0%</div></div> | |
| 62 | + <div class="bar" <?php echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><div class="percent"><?php echo esc_html( $percentage ); ?>%</div></div> | |
| 35 | 63 | </div> |
| 36 | 64 | </div> |
| 37 | 65 | </div> |
| 38 | 66 | |
| @@ -50,11 +78,32 @@ | ||
| 50 | 78 | </thead> |
| 51 | 79 | <tbody> |
| 52 | 80 | <?php |
| 53 | 81 | foreach ( $data['groups'] as $group ) { |
| 54 | - $context_data = Imagify_Admin_Ajax_Post::get_instance()->get_bulk_instance( $group['context'] )->get_context_data(); | |
| 55 | - $group = array_merge( $group, $context_data ); | |
| 82 | + $context_data = $bulk->get_bulk_instance( $group['context'] )->get_context_data(); | |
| 83 | + $group = array_merge( $group, $context_data ); | |
| 84 | + $default_level = Imagify_Options::get_instance()->get( 'optimization_level' ); | |
| 56 | 85 | |
| 86 | + if ( Imagify_Options::get_instance()->get( 'lossless' ) ) { | |
| 87 | + $default_level = 0; | |
| 88 | + } | |
| 89 | + | |
| 90 | + $group['level'] = $default_level; | |
| 91 | + | |
| 92 | + $running = get_transient( "imagify_{$group['context']}_optimize_running" ); | |
| 93 | + | |
| 94 | + $group['spinner_class'] = 'hidden'; | |
| 95 | + $group['spinner_aria'] = 'aria-hidden="true"'; | |
| 96 | + $group['checkbox_class'] = ''; | |
| 97 | + $group['checkbox_aria'] = 'aria-hidden="false"'; | |
| 98 | + | |
| 99 | + if ( false !== $running ) { | |
| 100 | + $group['spinner_class'] = ''; | |
| 101 | + $group['spinner_aria'] = 'aria-hidden="false"'; | |
| 102 | + $group['checkbox_class'] = 'hidden'; | |
| 103 | + $group['checkbox_aria'] = 'aria-hidden="true"'; | |
| 104 | + } | |
| 105 | + | |
| 57 | 106 | $this->print_template( 'part-bulk-optimization-table-row-folder-type', $group ); |
| 58 | 107 | } |
| 59 | 108 | ?> |
| 60 | 109 | </tbody> |
| @@ -60,18 +109,5 @@ | ||
| 60 | 109 | </tbody> |
| 61 | 110 | </table> |
| 62 | 111 | </div><!-- .imagify-bulk-table-container --> |
| 63 | 112 | </div><!-- .imagify-bulk-table-content --> |
| 64 | - | |
| 65 | - <?php | |
| 66 | - foreach ( $data['groups'] as $group ) { | |
| 67 | - ?> | |
| 68 | - <script type="text/html" id="tmpl-imagify-file-header-<?php echo $group['group_id']; ?>"> | |
| 69 | - <?php $this->print_template( 'part-bulk-optimization-header-row-' . $group['group_id'] ); ?> | |
| 70 | - </script> | |
| 71 | - <script type="text/html" id="tmpl-imagify-file-row-<?php echo $group['group_id']; ?>"> | |
| 72 | - <?php $this->print_template( 'part-bulk-optimization-underscore-file-row-' . $group['group_id'] ); ?> | |
| 73 | - </script> | |
| 74 | - <?php | |
| 75 | - } | |
| 76 | - ?> | |
| 77 | 113 | </div> |