PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / core / components / not-connected-modal.php

not-connected-modal.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/core/components/not-connected-modal.php

109 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Core\Components;
4
5 use ImageOptimization\Classes\Utils;
6 use ImageOptimization\Modules\Settings\Module;
7 use ImageOptimization\Plugin;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Not_Connected_Modal {
14 const NOT_CONNECTED_MODAL_SLUG = 'image-optimizer-not-connected-modal';
15
16 public function render_not_connected_modal() {
17 add_thickbox(); ?>
18
19 <div
20 id="<?php echo esc_html( self::NOT_CONNECTED_MODAL_SLUG ); ?>"
21 style="display:none;"
22 >
23 <div class="image-optimizer__modal image-optimizer__modal--not-connected" data-modal-slug="<?php echo esc_attr( self::NOT_CONNECTED_MODAL_SLUG ); ?>">
24 <button class="image-optimizer__modal--not-connected-close">
25 <svg viewBox="0 0 24 24" width="24" height="24">
26 <path fill-rule="evenodd" clip-rule="evenodd" d="M18.5303 5.46967C18.8232 5.76256 18.8232 6.23744 18.5303 6.53033L6.53033 18.5303C6.23744 18.8232 5.76256 18.8232 5.46967 18.5303C5.17678 18.2374 5.17678 17.7626 5.46967 17.4697L17.4697 5.46967C17.7626 5.17678 18.2374 5.17678 18.5303 5.46967Z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M5.46967 5.46967C5.76256 5.17678 6.23744 5.17678 6.53033 5.46967L18.5303 17.4697C18.8232 17.7626 18.8232 18.2374 18.5303 18.5303C18.2374 18.8232 17.7626 18.8232 17.4697 18.5303L5.46967 6.53033C5.17678 6.23744 5.17678 5.76256 5.46967 5.46967Z"></path>
27 </svg>
28 </button>
29 <img src="<?php echo esc_url( plugins_url( 'assets/static/connect.jpg', dirname( __DIR__, 2 ) ) ); ?>" alt="<?php esc_html_e( 'Connect now', 'image-optimization' ); ?>">
30 <h2><?php esc_html_e( 'Let\'s start optimizing your images!', 'image-optimization' ); ?></h2>
31 <p><?php esc_html_e( 'Connect the Image Optimization plugin to speed up your site. We\'ll handle the rest.', 'image-optimization' ); ?></p>
32 <ul>
33 <li><?php esc_html_e( 'Boost site speed and compress images', 'image-optimization' ); ?></li>
34 <li><?php esc_html_e( 'Bulk optimization for faster processing', 'image-optimization' ); ?></li>
35 <li><?php esc_html_e( 'Convert to AVIF and WebP formats', 'image-optimization' ); ?></li>
36 <li><?php esc_html_e( 'Works across unlimited websites', 'image-optimization' ); ?></li>
37 </ul>
38 <a
39 href="<?php echo esc_url( admin_url( 'admin.php?page=' . Module::SETTING_BASE_SLUG . '&action=connect' ) ); ?>"
40 class="image-optimizer__modal--not-connected-connect"
41 >
42 <?php esc_html_e( 'Connect to start', 'image-optimization' ); ?>
43 </a>
44 </div>
45 </div>
46 <script>
47 jQuery( document ).ready( function( $ ) {
48 setTimeout(() => {
49 const TB_WIDTH = 630;
50 const TB_HEIGHT = 620;
51 const msInOneDay = 24 * 60 * 60 * 1000;
52 const time_dismissed = localStorage.getItem('<?php echo esc_js( self::NOT_CONNECTED_MODAL_SLUG ); ?>');
53 const show_notice = !time_dismissed || Date.now() - time_dismissed >= msInOneDay;
54 const $modal = $( '[data-modal-slug="<?php echo esc_js( self::NOT_CONNECTED_MODAL_SLUG ); ?>"]' );
55
56 if (show_notice) {
57 tb_show( '', `/?TB_inline&inlineId=<?php echo esc_js( self::NOT_CONNECTED_MODAL_SLUG ); ?>&height=${TB_HEIGHT - 40}&width=${TB_WIDTH - 30}&modal=true` );
58 $modal.parents('#TB_window')
59 .width(TB_WIDTH)
60 .height(TB_HEIGHT)
61 .css('margin-left', - TB_WIDTH / 2)
62 .css('margin-top', - TB_HEIGHT / 2)
63 .css('top', '50%');
64
65 const hideModal = (e) => {
66 e.preventDefault();
67 localStorage.setItem('<?php echo esc_js( self::NOT_CONNECTED_MODAL_SLUG ); ?>', Date.now().toString());
68 tb_remove();
69 }
70 const $connectButton = $modal.find( '.image-optimizer__modal--not-connected-connect' );
71 const $closeButton = $modal.find( '.image-optimizer__modal--not-connected-close' );
72
73 $connectButton.on( 'click', function (e) {
74 hideModal(e);
75 window.open( $( this ).attr( 'href' ), '_self' ).focus();
76 } );
77 $closeButton.on( 'click', function (e) {
78 hideModal(e);
79 } );
80 } else {
81 $modal.remove();
82 }
83 }, 0);
84 } );
85 </script>
86 <?php
87 }
88
89
90
91 public function __construct() {
92 add_action('current_screen', function () {
93 // @var ImageOptimizer/Modules/ConnectManager/Module
94 $module = Plugin::instance()->modules_manager->get_modules( 'connect-manager' );
95
96 if ( $module->connect_instance->is_connected() || ! Utils::user_is_admin() ) {
97 return;
98 }
99
100 if (
101 Utils::is_plugin_settings_page() ||
102 Utils::is_bulk_optimization_page()
103 ) {
104 add_action( 'admin_notices', [ $this, 'render_not_connected_modal' ] );
105 }
106 });
107 }
108 }
109