class-bulk.php
4 years ago
class-cdn.php
4 years ago
class-dashboard.php
4 years ago
class-directory.php
4 years ago
class-integrations.php
4 years ago
class-lazy.php
4 years ago
class-nextgen.php
4 years ago
class-settings.php
4 years ago
class-tools.php
4 years ago
class-tutorials.php
4 years ago
class-upgrade.php
4 years ago
class-webp.php
4 years ago
class-dashboard.php
404 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dashboard page class: Dashboard extends Abstract_Page. |
| 4 | * |
| 5 | * @since 3.8.6 |
| 6 | * @package Smush\App\Pages |
| 7 | */ |
| 8 | |
| 9 | namespace Smush\App\Pages; |
| 10 | |
| 11 | use Smush\App\Abstract_Page; |
| 12 | use Smush\App\Interface_Page; |
| 13 | use Smush\Core\Settings; |
| 14 | use WP_Smush; |
| 15 | |
| 16 | if ( ! defined( 'WPINC' ) ) { |
| 17 | die; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Class Dashboard |
| 22 | */ |
| 23 | class Dashboard extends Abstract_Page implements Interface_Page { |
| 24 | |
| 25 | /** |
| 26 | * Function triggered when the page is loaded before render any content. |
| 27 | */ |
| 28 | public function on_load() {} |
| 29 | |
| 30 | /** |
| 31 | * Enqueue scripts. |
| 32 | * |
| 33 | * @since 3.9.0 |
| 34 | * |
| 35 | * @param string $hook Hook from where the call is made. |
| 36 | */ |
| 37 | public function enqueue_scripts( $hook ) { |
| 38 | // Scripts for Configs. |
| 39 | $this->enqueue_configs_scripts(); |
| 40 | |
| 41 | // Scripts for Tutorials. |
| 42 | $this->enqueue_tutorials_scripts(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Register meta boxes. |
| 47 | */ |
| 48 | public function register_meta_boxes() { |
| 49 | if ( ! is_multisite() || ( is_multisite() && ! is_network_admin() ) ) { |
| 50 | $this->add_meta_box( |
| 51 | 'dashboard/summary', |
| 52 | null, |
| 53 | array( $this, 'summary_meta_box' ), |
| 54 | null, |
| 55 | null, |
| 56 | 'summary', |
| 57 | array( |
| 58 | 'box_class' => 'sui-box sui-summary', |
| 59 | 'box_content_class' => false, |
| 60 | ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Meta boxes on the left side. |
| 66 | */ |
| 67 | |
| 68 | if ( self::should_render( 'bulk' ) ) { |
| 69 | $this->add_meta_box( |
| 70 | 'dashboard/bulk', |
| 71 | __( 'Bulk Smush', 'wp-smushit' ), |
| 72 | array( $this, 'bulk_compress_meta_box' ), |
| 73 | null, |
| 74 | null, |
| 75 | 'box-dashboard-left' |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | if ( self::should_render( 'integrations' ) ) { |
| 80 | $this->add_meta_box( |
| 81 | 'dashboard/integrations', |
| 82 | __( 'Integrations', 'wp-smushit' ), |
| 83 | array( $this, 'integrations_meta_box' ), |
| 84 | null, |
| 85 | null, |
| 86 | 'box-dashboard-left' |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | if ( self::should_render( 'webp' ) ) { |
| 91 | $this->add_meta_box( |
| 92 | 'dashboard/webp', |
| 93 | __( 'Local WebP', 'wp-smushit' ), |
| 94 | array( $this, 'local_webp_meta_box' ), |
| 95 | array( $this, 'local_webp_meta_box_header' ), |
| 96 | null, |
| 97 | 'box-dashboard-left' |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | if ( self::should_render( 'tools' ) ) { |
| 102 | $this->add_meta_box( |
| 103 | 'dashboard/tools', |
| 104 | __( 'Tools', 'wp-smushit' ), |
| 105 | array( $this, 'tools_meta_box' ), |
| 106 | null, |
| 107 | null, |
| 108 | 'box-dashboard-left' |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Meta boxes on the right side. |
| 114 | */ |
| 115 | if ( ! WP_Smush::is_pro() ) { |
| 116 | $this->add_meta_box( |
| 117 | 'dashboard/upsell/upsell', |
| 118 | __( 'Smush Pro', 'wp-smushit' ), |
| 119 | array( $this, 'upsell_meta_box' ), |
| 120 | array( $this, 'upsell_meta_box_header' ), |
| 121 | null, |
| 122 | 'box-dashboard-right' |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | if ( self::should_render( 'directory' ) ) { |
| 127 | $this->add_meta_box( |
| 128 | 'dashboard/directory', |
| 129 | __( 'Directory Smush', 'wp-smushit' ), |
| 130 | array( $this, 'directory_compress_meta_box' ), |
| 131 | null, |
| 132 | null, |
| 133 | 'box-dashboard-right' |
| 134 | ); |
| 135 | } |
| 136 | |
| 137 | if ( self::should_render( 'lazy_load' ) ) { |
| 138 | $this->add_meta_box( |
| 139 | 'dashboard/lazy-load', |
| 140 | __( 'Lazy Load', 'wp-smushit' ), |
| 141 | array( $this, 'lazy_load_meta_box' ), |
| 142 | null, |
| 143 | null, |
| 144 | 'box-dashboard-right' |
| 145 | ); |
| 146 | } |
| 147 | |
| 148 | if ( self::should_render( 'cdn' ) ) { |
| 149 | $this->add_meta_box( |
| 150 | 'dashboard/cdn', |
| 151 | __( 'CDN', 'wp-smushit' ), |
| 152 | array( $this, 'cdn_meta_box' ), |
| 153 | array( $this, 'cdn_meta_box_header' ), |
| 154 | null, |
| 155 | 'box-dashboard-right' |
| 156 | ); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Summary meta box. |
| 162 | * |
| 163 | * @since 3.8.6 |
| 164 | */ |
| 165 | public function summary_meta_box() { |
| 166 | $upsell_url_cdn = add_query_arg( |
| 167 | array( |
| 168 | 'utm_source' => 'smush', |
| 169 | 'utm_medium' => 'plugin', |
| 170 | 'utm_campaign' => 'summary_cdn', |
| 171 | ), |
| 172 | $this->upgrade_url |
| 173 | ); |
| 174 | |
| 175 | $upsell_url_webp = add_query_arg( |
| 176 | array( |
| 177 | 'utm_source' => 'smush', |
| 178 | 'utm_medium' => 'plugin', |
| 179 | 'utm_campaign' => 'summary_local_webp', |
| 180 | ), |
| 181 | $this->upgrade_url |
| 182 | ); |
| 183 | |
| 184 | $core = WP_Smush::get_instance()->core(); |
| 185 | |
| 186 | $uncompressed_count = $core->total_count - $core->smushed_count - $core->skipped_count; |
| 187 | |
| 188 | $resize_count = $core->get_savings( 'resize', false, false, true ); |
| 189 | |
| 190 | $args = array( |
| 191 | 'cdn_status' => WP_Smush::get_instance()->core()->mod->cdn->status(), |
| 192 | 'is_cdn' => $this->settings->get( 'cdn' ), |
| 193 | 'is_lazy_load' => $this->settings->get( 'lazy_load' ), |
| 194 | 'is_local_webp' => $this->settings->get( 'webp_mod' ), |
| 195 | 'remaining' => count( get_option( 'wp-smush-resmush-list', array() ) ) + max( $uncompressed_count, 0 ), |
| 196 | 'resize_count' => ! $resize_count ? 0 : $resize_count, |
| 197 | 'upsell_url_cdn' => $upsell_url_cdn, |
| 198 | 'upsell_url_webp' => $upsell_url_webp, |
| 199 | 'webp_configured' => true === WP_Smush::get_instance()->core()->mod->webp->is_configured(), |
| 200 | ); |
| 201 | |
| 202 | $this->view( 'dashboard/summary-meta-box', $args ); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Bulk compress meta box. |
| 207 | * |
| 208 | * @since 3.8.6 |
| 209 | */ |
| 210 | public function bulk_compress_meta_box() { |
| 211 | $uncompressed = count( WP_Smush::get_instance()->core()->get_unsmushed_attachments() ); |
| 212 | $resmush_count = count( get_option( 'wp-smush-resmush-list', array() ) ); |
| 213 | |
| 214 | $upsell_url = add_query_arg( |
| 215 | array( |
| 216 | 'utm_source' => 'smush', |
| 217 | 'utm_medium' => 'plugin', |
| 218 | 'utm_campaign' => 'dashboard_bulk_smush', |
| 219 | ), |
| 220 | $this->upgrade_url |
| 221 | ); |
| 222 | |
| 223 | $args = array( |
| 224 | 'uncompressed' => $uncompressed + $resmush_count, |
| 225 | 'upsell_url' => $upsell_url, |
| 226 | ); |
| 227 | |
| 228 | $this->view( 'dashboard/bulk/meta-box', $args ); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Integrations meta box. |
| 233 | * |
| 234 | * @since 3.8.6 |
| 235 | */ |
| 236 | public function integrations_meta_box() { |
| 237 | $upsell_url = add_query_arg( |
| 238 | array( |
| 239 | 'utm_source' => 'smush', |
| 240 | 'utm_medium' => 'plugin', |
| 241 | 'utm_campaign' => 'dashboard_integrations', |
| 242 | ), |
| 243 | $this->upgrade_url |
| 244 | ); |
| 245 | |
| 246 | $integration_fields = $this->settings->get_integrations_fields(); |
| 247 | |
| 248 | $key = array_search( 'js_builder', $integration_fields, true ); |
| 249 | if ( $key ) { |
| 250 | unset( $integration_fields[ $key ] ); |
| 251 | } |
| 252 | |
| 253 | $args = array( |
| 254 | 'basic_features' => Settings::$basic_features, |
| 255 | 'fields' => $integration_fields, |
| 256 | 'is_pro' => WP_Smush::is_pro(), |
| 257 | 'settings' => $this->settings->get(), |
| 258 | 'upsell_url' => $upsell_url, |
| 259 | ); |
| 260 | |
| 261 | $this->view( 'dashboard/integrations-meta-box', $args ); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Local WebP meta box. |
| 266 | * |
| 267 | * @since 3.8.6 |
| 268 | */ |
| 269 | public function local_webp_meta_box() { |
| 270 | $upsell_url = add_query_arg( |
| 271 | array( |
| 272 | 'utm_source' => 'smush', |
| 273 | 'utm_medium' => 'plugin', |
| 274 | 'utm_campaign' => 'smush-dashboard-local-webp-upsell', |
| 275 | ), |
| 276 | $this->upgrade_url |
| 277 | ); |
| 278 | |
| 279 | $webp = WP_Smush::get_instance()->core()->mod->webp; |
| 280 | |
| 281 | $args = array( |
| 282 | 'is_configured' => $webp->get_is_configured_with_error_message(), |
| 283 | 'is_webp_active' => $this->settings->get( 'webp_mod' ), |
| 284 | 'upsell_url' => $upsell_url, |
| 285 | ); |
| 286 | |
| 287 | $this->view( 'dashboard/webp/meta-box', $args ); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Local WebP meta box footer. |
| 292 | * |
| 293 | * @since 3.8.6 |
| 294 | */ |
| 295 | public function local_webp_meta_box_header() { |
| 296 | $title = __( 'Local WebP', 'wp-smushit' ); |
| 297 | $this->view( 'dashboard/webp/meta-box-header', compact( 'title' ) ); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Toole meta box. |
| 302 | * |
| 303 | * @since 3.8.6 |
| 304 | */ |
| 305 | public function tools_meta_box() { |
| 306 | $is_resize_detection = $this->settings->get( 'detection' ); |
| 307 | $this->view( 'dashboard/tools-meta-box', compact( 'is_resize_detection' ) ); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Directory compress meta box. |
| 312 | * |
| 313 | * @since 3.8.6 |
| 314 | */ |
| 315 | public function directory_compress_meta_box() { |
| 316 | $images = WP_Smush::get_instance()->core()->mod->dir->get_image_errors(); |
| 317 | |
| 318 | $args = array( |
| 319 | 'images' => array_slice( $images, 0, 4 ), |
| 320 | 'errors' => WP_Smush::get_instance()->core()->mod->dir->get_image_errors_count(), |
| 321 | ); |
| 322 | |
| 323 | $this->view( 'dashboard/directory-meta-box', $args ); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Upsell meta box. |
| 328 | * |
| 329 | * @since 3.8.6 |
| 330 | */ |
| 331 | public function upsell_meta_box() { |
| 332 | $upsell_url = add_query_arg( |
| 333 | array( |
| 334 | 'utm_source' => 'smush', |
| 335 | 'utm_medium' => 'plugin', |
| 336 | 'utm_campaign' => 'smush-dashboard-upsell', |
| 337 | ), |
| 338 | $this->upgrade_url |
| 339 | ); |
| 340 | |
| 341 | $this->view( 'dashboard/upsell/meta-box', compact( 'upsell_url' ) ); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Upsell meta box header. |
| 346 | * |
| 347 | * @since 3.8.6 |
| 348 | */ |
| 349 | public function upsell_meta_box_header() { |
| 350 | $title = esc_html__( 'Smush Pro', 'wp-smushit' ); |
| 351 | $this->view( 'dashboard/upsell/meta-box-header', compact( 'title' ) ); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Lazy load meta box. |
| 356 | * |
| 357 | * @since 3.8.6 |
| 358 | */ |
| 359 | public function lazy_load_meta_box() { |
| 360 | $settings = $this->settings->get_setting( 'wp-smush-lazy_load' ); |
| 361 | |
| 362 | $args = array( |
| 363 | 'is_lazy_load' => $this->settings->get( 'lazy_load' ), |
| 364 | 'media_types' => isset( $settings['format'] ) ? $settings['format'] : array(), |
| 365 | ); |
| 366 | |
| 367 | $this->view( 'dashboard/lazy-load-meta-box', $args ); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * CDN meta box. |
| 372 | * |
| 373 | * @since 3.8.6 |
| 374 | */ |
| 375 | public function cdn_meta_box() { |
| 376 | $upsell_url = add_query_arg( |
| 377 | array( |
| 378 | 'utm_source' => 'smush', |
| 379 | 'utm_medium' => 'plugin', |
| 380 | 'utm_campaign' => 'smush-dashboard-cdn-upsell', |
| 381 | ), |
| 382 | $this->upgrade_url |
| 383 | ); |
| 384 | |
| 385 | $args = array( |
| 386 | 'cdn_status' => WP_Smush::get_instance()->core()->mod->cdn->status(), |
| 387 | 'is_webp' => $this->settings->get( 'webp' ), |
| 388 | 'upsell_url' => $upsell_url, |
| 389 | ); |
| 390 | |
| 391 | $this->view( 'dashboard/cdn/meta-box', $args ); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * CDN meta box header. |
| 396 | * |
| 397 | * @since 3.8.6 |
| 398 | */ |
| 399 | public function cdn_meta_box_header() { |
| 400 | $title = esc_html__( 'CDN', 'wp-smushit' ); |
| 401 | $this->view( 'dashboard/cdn/meta-box-header', compact( 'title' ) ); |
| 402 | } |
| 403 | } |
| 404 |