class-bulk.php
2 years ago
class-cdn.php
2 years ago
class-dashboard.php
2 years ago
class-directory.php
2 years ago
class-integrations.php
2 years ago
class-lazy.php
2 years ago
class-nextgen.php
2 years ago
class-settings.php
2 years ago
class-tutorials.php
2 years ago
class-upgrade.php
2 years ago
class-webp.php
2 years ago
class-nextgen.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * NextGen admin view: Nextgen class |
| 4 | * |
| 5 | * @package Smush\App\Pages |
| 6 | */ |
| 7 | |
| 8 | namespace Smush\App\Pages; |
| 9 | |
| 10 | use Smush\App\Abstract_Page; |
| 11 | use Smush\App\Admin; |
| 12 | use WP_Smush; |
| 13 | |
| 14 | if ( ! defined( 'WPINC' ) ) { |
| 15 | die; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Nextgen |
| 20 | */ |
| 21 | class Nextgen extends Abstract_Page { |
| 22 | |
| 23 | /** |
| 24 | * Function triggered when the page is loaded before render any content. |
| 25 | */ |
| 26 | public function on_load() { |
| 27 | // Localize variables for NextGen Manage gallery page. |
| 28 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Render inner content. |
| 33 | */ |
| 34 | public function render_inner_content() { |
| 35 | $this->view( 'smush-nextgen-page' ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Register meta boxes. |
| 40 | */ |
| 41 | public function register_meta_boxes() { |
| 42 | $this->add_meta_box( |
| 43 | 'summary', |
| 44 | null, |
| 45 | array( $this, 'dashboard_summary_metabox' ), |
| 46 | null, |
| 47 | null, |
| 48 | 'summary', |
| 49 | array( |
| 50 | 'box_class' => 'sui-box sui-summary sui-summary-smush-metabox sui-summary-smush-nextgen', |
| 51 | 'box_content_class' => false, |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | $this->add_meta_box( |
| 56 | 'bulk', |
| 57 | __( 'Bulk Smush', 'wp-smushit' ), |
| 58 | array( $this, 'bulk_metabox' ), |
| 59 | array( $this, 'bulk_header_metabox' ), |
| 60 | null, |
| 61 | 'bulk', |
| 62 | array( |
| 63 | 'box_class' => 'sui-box bulk-smush-wrapper', |
| 64 | ) |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Enqueue Scripts on Manage Gallery page |
| 70 | */ |
| 71 | public function enqueue() { |
| 72 | $current_screen = get_current_screen(); |
| 73 | if ( ! empty( $current_screen ) && in_array( $current_screen->base, Admin::$plugin_pages, true ) ) { |
| 74 | WP_Smush::get_instance()->core()->nextgen->ng_admin->localize(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * NextGen summary meta box. |
| 81 | */ |
| 82 | public function dashboard_summary_metabox() { |
| 83 | $ng_stats = WP_Smush::get_instance()->core()->nextgen->ng_stats; |
| 84 | $global_stats = $ng_stats->get_global_stats(); |
| 85 | $lossy_enabled = $this->settings->get( 'lossy' ); |
| 86 | |
| 87 | $this->view( |
| 88 | 'nextgen/summary-meta-box', |
| 89 | array( |
| 90 | 'lossy_enabled' => $lossy_enabled, |
| 91 | 'image_count' => $ng_stats->get_array_value( $global_stats, 'count_images' ), |
| 92 | 'smushed_image_count' => $ng_stats->get_array_value( $global_stats, 'count_smushed' ), |
| 93 | 'super_smushed_count' => $ng_stats->get_array_value( $global_stats, 'count_supersmushed' ), |
| 94 | 'stats_human' => $ng_stats->get_array_value( $global_stats, 'human_bytes' ), |
| 95 | 'stats_percent' => $ng_stats->get_array_value( $global_stats, 'savings_percent'), |
| 96 | 'total_count' => $ng_stats->get_array_value( $global_stats, 'count_total' ), |
| 97 | 'percent_grade' => $ng_stats->get_array_value( $global_stats, 'percent_grade' ), |
| 98 | 'percent_metric' => $ng_stats->get_array_value( $global_stats, 'percent_metric' ), |
| 99 | 'percent_optimized' => $ng_stats->get_array_value( $global_stats, 'percent_optimized' ), |
| 100 | ) |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * NextGen bulk Smush header meta box. |
| 106 | */ |
| 107 | public function bulk_header_metabox() { |
| 108 | $this->view( |
| 109 | 'nextgen/meta-box-header', |
| 110 | array( |
| 111 | 'title' => __( 'Bulk Smush', 'wp-smushit' ), |
| 112 | ) |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * NextGen bulk Smush meta box. |
| 118 | */ |
| 119 | public function bulk_metabox() { |
| 120 | $ng_stats = WP_Smush::get_instance()->core()->nextgen->ng_stats; |
| 121 | $global_stats = $ng_stats->get_global_stats(); |
| 122 | |
| 123 | $url = add_query_arg( |
| 124 | array( |
| 125 | 'page' => 'smush#wp-smush-settings-box', |
| 126 | ), |
| 127 | admin_url( 'upload.php' ) |
| 128 | ); |
| 129 | |
| 130 | $this->view( |
| 131 | 'nextgen/meta-box', |
| 132 | array( |
| 133 | 'total_images_to_smush' => $ng_stats->get_array_value( $global_stats, 'remaining_count' ), |
| 134 | 'unsmushed_count' => $ng_stats->get_array_value( $global_stats, 'count_unsmushed'), |
| 135 | 'resmush_count' => $ng_stats->get_array_value( $global_stats, 'count_resmush'), |
| 136 | 'total_count' => $ng_stats->get_array_value( $global_stats, 'count_total'), |
| 137 | 'url' => $url, |
| 138 | ) |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | } |
| 143 |