| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Settings\Banners; |
| 4 |
|
| 5 |
use ImageOptimization\Modules\Core\Components\Pointers; |
| 6 |
use Throwable; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class One_Million_Installs_Banner { |
| 13 |
const BANNER_POINTER_NAME = 'image_optimizer_one_million_installs_banner'; |
| 14 |
const POINTER_ACTION = 'image_optimizer_pointer_dismissed'; |
| 15 |
const POINTER_NONCE_KEY = 'image-optimization-pointer-dismissed'; |
| 16 |
|
| 17 |
public static function is_sale_time(): bool { |
| 18 |
$sale_start_time = gmmktime( 0, 0, 0, 4, 8, 2025 ); |
| 19 |
$sale_end_time = gmmktime( 23, 59, 59, 4, 30, 2025 ); |
| 20 |
|
| 21 |
$now_time = gmdate( 'U' ); |
| 22 |
|
| 23 |
return $now_time >= $sale_start_time && $now_time <= $sale_end_time; |
| 24 |
} |
| 25 |
|
| 26 |
public static function user_viewed_banner(): bool { |
| 27 |
return Pointers::is_dismissed( self::BANNER_POINTER_NAME ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Get banner markup |
| 32 |
* @throws Throwable |
| 33 |
*/ |
| 34 |
public static function get_banner( string $link ) { |
| 35 |
if ( ! self::is_sale_time() || self::user_viewed_banner() ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
$img = plugins_url( '/images/one-million-installs-banner.jpg', __FILE__ ); |
| 40 |
$url = admin_url( 'admin-ajax.php' ); |
| 41 |
$nonce = wp_create_nonce( self::POINTER_NONCE_KEY ); |
| 42 |
?> |
| 43 |
|
| 44 |
<div class="elementor-io-banner"> |
| 45 |
<div class="elementor-io-banner-container"> |
| 46 |
<img src="<?php echo esc_url( $img ); ?>" alt="One million installs banner"> |
| 47 |
|
| 48 |
<a href="<?php echo esc_url( $link ); ?>" target="_blank"> |
| 49 |
Claim discount |
| 50 |
</a> |
| 51 |
|
| 52 |
<button> |
| 53 |
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 54 |
<path fill-rule="evenodd" |
| 55 |
clip-rule="evenodd" |
| 56 |
d="M13.2803 1.28033C13.5732 0.987437 13.5732 0.512563 13.2803 0.21967C12.9874 -0.0732233 12.5126 -0.0732233 12.2197 0.21967L6.75 5.68934L1.28033 0.21967C0.987437 -0.0732233 0.512563 -0.0732233 0.21967 0.21967C-0.0732233 0.512563 -0.0732233 0.987437 0.21967 1.28033L5.68934 6.75L0.21967 12.2197C-0.0732233 12.5126 -0.0732233 12.9874 0.21967 13.2803C0.512563 13.5732 0.987437 13.5732 1.28033 13.2803L6.75 7.81066L12.2197 13.2803C12.5126 13.5732 12.9874 13.5732 13.2803 13.2803C13.5732 12.9874 13.5732 12.5126 13.2803 12.2197L7.81066 6.75L13.2803 1.28033Z" |
| 57 |
fill="white"/> |
| 58 |
</svg> |
| 59 |
</button> |
| 60 |
</div> |
| 61 |
</div> |
| 62 |
|
| 63 |
<style> |
| 64 |
.elementor-io-banner { |
| 65 |
overflow: hidden; |
| 66 |
margin-left: -20px; |
| 67 |
background: #05047e; |
| 68 |
} |
| 69 |
|
| 70 |
.elementor-io-banner-container { |
| 71 |
position: relative; |
| 72 |
max-width: 1200px; |
| 73 |
margin: 0 auto; |
| 74 |
display: flex; |
| 75 |
justify-content: end; |
| 76 |
align-items: center; |
| 77 |
direction: ltr; |
| 78 |
height: 80px; |
| 79 |
} |
| 80 |
|
| 81 |
.elementor-io-banner img { |
| 82 |
position: absolute; |
| 83 |
left: 0; |
| 84 |
top: 50%; |
| 85 |
transform: translateY(-50%); |
| 86 |
width: 100%; |
| 87 |
} |
| 88 |
|
| 89 |
.elementor-io-banner a { |
| 90 |
position: relative; |
| 91 |
display: inline-block; |
| 92 |
padding: 12px 24px; |
| 93 |
font-size: 18px; |
| 94 |
color: #000; |
| 95 |
background-color: #ff7be5; |
| 96 |
text-decoration: none; |
| 97 |
z-index: 2; |
| 98 |
} |
| 99 |
|
| 100 |
.elementor-io-banner button { |
| 101 |
position: relative; |
| 102 |
border: none; |
| 103 |
background: none; |
| 104 |
padding: 12px; |
| 105 |
margin: 0 24px; |
| 106 |
cursor: pointer; |
| 107 |
z-index: 2; |
| 108 |
} |
| 109 |
|
| 110 |
@media (max-width: 1170px) { |
| 111 |
.elementor-io-banner a { |
| 112 |
padding: 6px 12px; |
| 113 |
font-size: 14px; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
@media (max-width: 845px) { |
| 118 |
.elementor-io-banner button { |
| 119 |
margin: 0 6px; |
| 120 |
} |
| 121 |
} |
| 122 |
</style> |
| 123 |
|
| 124 |
<script> |
| 125 |
document.addEventListener('DOMContentLoaded', function () { |
| 126 |
const banner = document.querySelector('.elementor-io-banner'); |
| 127 |
const button = document.querySelector('.elementor-io-banner button'); |
| 128 |
|
| 129 |
const requestData = { |
| 130 |
action: "<?php echo esc_js( self::POINTER_ACTION ); ?>", |
| 131 |
nonce: "<?php echo esc_js( $nonce ); ?>", |
| 132 |
data: { |
| 133 |
pointer: "<?php echo esc_js( self::BANNER_POINTER_NAME ); ?>", |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
if (button) { |
| 138 |
button.addEventListener('click', function () { |
| 139 |
jQuery.ajax( |
| 140 |
{ |
| 141 |
url: '<?php echo esc_js( $url ); ?>', |
| 142 |
method: 'POST', |
| 143 |
data: requestData, |
| 144 |
success: () => banner.remove(), |
| 145 |
error: (error) => console.error('Error:', error), |
| 146 |
} |
| 147 |
); |
| 148 |
}); |
| 149 |
} |
| 150 |
}); |
| 151 |
|
| 152 |
</script> |
| 153 |
<?php |
| 154 |
} |
| 155 |
} |
| 156 |
|