diff --git a/css/settings.css b/css/settings.css index bdaa5aad..4508d778 100644 --- a/css/settings.css +++ b/css/settings.css @@ -137,7 +137,7 @@ padding: 30px 90px 30px 30px; } .feedzy-accordion-item .feedzy-accordion__step-number{ - padding-bottom: 10px; + padding-bottom: 10px; } .feedzy-accordion-item .feedzy-accordion__step-title{ color: #050505; @@ -2246,4 +2246,45 @@ li.draggable-item .components-panel__body-toggle.components-button{ } .fz-chat-cpt-action .error-message { right: 40px !important; -} \ No newline at end of file +} + +.feedzy-sale { + margin-bottom: 20px; + display: flex; +} + +.feedzy-sale a { + position: relative; +} + +.feedzy-sale img { + width: 100%; +} + +.feedzy-sale .feedzy-urgency { + position: absolute; + + top: 10%; + left: 1.5%; + + color: #FFF; + font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", sans-serif; + font-size: 14px; + font-style: normal; + font-weight: 700; + line-height: normal; + letter-spacing: 0.3px; + text-transform: uppercase; +} + +@media(max-width: 480px) { + .feedzy-sale .feedzy-urgency { + font-size: 7px; + } +} + +@media (min-width: 481px) and (max-width: 1024px) { + .feedzy-sale .feedzy-urgency { + font-size: 10px; + } +} diff --git a/img/black-friday-banner.png b/img/black-friday-banner.png new file mode 100644 index 00000000..66af6ad3 Binary files /dev/null and b/img/black-friday-banner.png differ diff --git a/includes/feedzy-rss-feeds-limited-offers.php b/includes/feedzy-rss-feeds-limited-offers.php new file mode 100644 index 00000000..271413bf --- /dev/null +++ b/includes/feedzy-rss-feeds-limited-offers.php @@ -0,0 +1,450 @@ + + */ + public $offer_metadata = array(); + + /** + * Timeline for the offers. + * + * @var array[] + */ + public $timelines = array( + 'bf' => array( + 'start' => '2023-10-10 00:00:00', + 'end' => '2023-11-27 23:59:00', + ), // TODO: Add the correct date. + ); + + /** + * LimitedOffers constructor. + */ + public function __construct() { + try { + if ( $this->is_deal_active( 'bf' ) ) { + $this->activate_bff(); + } + } catch ( Exception $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( $e->getMessage() ); // phpcs:ignore + } + } + } + + /** + * Load hooks for the dashboard. + * + * @return void + */ + public function load_dashboard_hooks() { + add_filter( 'themeisle_products_deal_priority', array( $this, 'add_priority' ) ); + add_action( 'admin_notices', array( $this, 'render_notice') ); + add_action( 'wp_ajax_dismiss_themeisle_sale_notice_feedzy', array( $this, 'disable_notification_ajax' ) ); + } + + /** + * Check if we have an active deal. + * + * @return bool True if the deal is active. + */ + public function is_active() { + return ! empty( $this->active ); + } + + /** + * Activate the Black Friday deal. + * + * @return void + */ + public function activate_bff() { + $this->active = 'bf'; + + $this->offer_metadata = array( + 'bannerUrl' => FEEDZY_ABSURL . 'img/black-friday-banner.png', + 'bannerAlt' => 'Feedzy Black Friday Sale', + 'linkDashboard' => tsdk_utmify( 'https://themeisle.com/plugins/feedzy-rss-feeds/blackfriday', 'blackfridayltd23', 'dashboard' ), + 'linkGlobal' => tsdk_utmify( 'https://themeisle.com/plugins/feedzy-rss-feeds/blackfriday', 'blackfridayltd23', 'globalnotice' ), + 'urgencyText' => 'Hurry Up! Only ' . $this->get_remaining_time_for_deal( $this->get_active_deal() ) . ' left', + ); + } + + /** + * Get the slug of the active deal. + * + * @return string Active deal. + */ + public function get_active_deal() { + return $this->active; + } + + /** + * Check if the deal is active with the given slug. + * + * @param string $slug Slug of the deal. + * + * @throws Exception When date is invalid. + */ + public function is_deal_active( $slug ) { + + if ( empty( $slug ) || ! array_key_exists( $slug, $this->timelines ) ) { + return false; + } + + return $this->check_date_range( $this->timelines[ $slug ]['start'], $this->timelines[ $slug ]['end'] ); + } + + /** + * Get the remaining time for the deal in a human readable format. + * + * @param string $slug Slug of the deal. + * @return string Remaining time for the deal. + */ + public function get_remaining_time_for_deal( $slug ) { + if ( empty( $slug ) || ! array_key_exists( $slug, $this->timelines ) ) { + return ''; + } + + try { + $end_date = new DateTime( $this->timelines[ $slug ]['end'], new DateTimeZone( 'GMT' ) ); + $current_date = new DateTime( 'now', new DateTimeZone( 'GMT' ) ); + $diff = $end_date->diff( $current_date ); + + if ( $diff->days > 0 ) { + return $diff->format( '%a days' ); + } + + if ( $diff->h > 0 ) { + return $diff->format( '%h hours' ); + } + + if ( $diff->i > 0 ) { + return $diff->format( '%i minutes' ); + } + + return $diff->format( '%s seconds' ); + } catch ( Exception $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( $e->getMessage() ); // phpcs:ignore + } + } + + return ''; + } + + /** + * Check if the current date is in the range of the offer. + * + * @param string $start Start date. + * @param string $end End date. + * + * @return bool True if the current date is in the range of the offer. + * + * @throws Exception When date is invalid. + */ + public function check_date_range( $start, $end ) { + + $start_date = new DateTime( $start, new DateTimeZone( 'GMT' ) ); + $end_date = new DateTime( $end, new DateTimeZone( 'GMT' ) ); + $current_date = new DateTime( 'now', new DateTimeZone( 'GMT' ) ); + + return $start_date <= $current_date && $current_date <= $end_date; + } + + /** + * Get the localized data for the plugin. + * + * @return array Localized data. + */ + public function get_localized_data() { + return array_merge( + array( + 'active' => $this->is_active(), + 'dealSlug' => $this->get_active_deal(), + 'remainingTime' => $this->get_remaining_time_for_deal( $this->get_active_deal() ), + 'urgencyText' => 'Hurry Up! Only ' . $this->get_remaining_time_for_deal( $this->get_active_deal() ) . ' left', + ), + $this->offer_metadata + ); + } + + /** + * Disable the notification via ajax. + * + * @return void + */ + public function disable_notification_ajax() { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'dismiss_themeisle_sale_notice_feedzy' ) ) { + wp_die( esc_html( __( 'Invalid nonce! Refresh the page and try again.', 'feedzy-rss-feeds' ) ) ); + } + + // We record the time and the plugin of the dismissed notification. + update_option( $this->wp_option_dismiss_notification_key_base . $this->active, 'feedzy_' . $this->active . '_' . current_time( 'Y_m_d' ) ); + wp_die( 'success' ); + } + + /** + * Render the dashboard banner. + * + * @return void + */ + public function render_notice() { + + if ( ! $this->has_priority() ) { + return; + } + + // Do not show this notice on the particular pages because it will interfere with the promotion from big banner. + if ( function_exists( 'get_current_screen' ) ) { + $screen = get_current_screen(); + if ( + ( $screen->base === 'edit' && ( $screen->post_type === 'feedzy_imports' || $screen->post_type === 'feedzy_categories' ) ) || + 'feedzy_page_feedzy-settings' === $screen->id + ) { + return; + } + } + + $message = 'Feedzy Black Friday Sale - Save big with a Lifetime License of Feedzy Agency Plan. Only 100 licenses, for a limited time!'; + + ?> + +
+
+ + + Combined Shape + Created with Sketch. + + + + + + + + + + + + + + +
+ + wp_option_dismiss_notification_key_base . $this->active, false ); + } + + /** + * Add product priority to the filter. + * + * @param array $products Registered products. + * @return array Array enhanced with Neve priority. + */ + public function add_priority( $products ) { + + $products['feedzy'] = 2; + + if ( function_exists( 'get_current_screen' ) ) { + $screen = get_current_screen(); + if ( + ( $screen->base === 'edit' && ( $screen->post_type === 'feedzy_imports' || $screen->post_type === 'feedzy_categories' ) ) || + 'feedzy_page_feedzy-settings' === $screen->id + ) { + // Small hack to supress rendering of other notices in those pages. + $products['feedzy'] = -2; + } + } + + return $products; + } + + /** + * Check if the current product has priority. + * Use this for conditional rendering if you want to show the banner only for one product. + * + * @return bool True if the current product has priority. + */ + public function has_priority() { + $products = apply_filters( 'themeisle_products_deal_priority', array() ); + + if ( empty( $products ) ) { + return true; + } + + $highest_priority = array_search( min( $products ), $products, true ); + return 'feedzy' === $highest_priority; + } + + /** + * Render the banner. + * + * @return void + */ + public function render_banner() { + + if ( ! function_exists( 'get_current_screen' ) ) { + return; + } + + $screen = get_current_screen(); + if ( $screen->base !== 'edit' || + ( $screen->post_type !== 'feedzy_imports' && $screen->post_type !== 'feedzy_categories' ) ) { + return; + } + + ?> + +
+ + <?php echo esc_attr( ! empty( $this->offer_metadata['bannerAlt'] ) ? $this->offer_metadata['bannerAlt'] : '' ); ?> +
+ offer_metadata['urgencyText'] ) ? $this->offer_metadata['urgencyText'] : '' ); ?> +
+
+
+ load_banner(); + if ( $offer->is_active() && $offer->can_show_dashboard_banner() ) { + $offer->load_dashboard_hooks(); + } + } + } /** diff --git a/includes/layouts/settings.php b/includes/layouts/settings.php index 148ab239..3d575055 100644 --- a/includes/layouts/settings.php +++ b/includes/layouts/settings.php @@ -7,6 +7,10 @@ $show_button = true; $help_btn_url = 'https://docs.themeisle.com/category/712-feedzy'; + + $offer = new Feedzy_Rss_Feeds_Limited_Offers(); + $offer_data = feedzy_is_pro() ? array() : $offer->get_localized_data(); + if ( 'headers' === $active_tab ) { $help_btn_url = 'https://docs.themeisle.com/article/713-how-to-change-user-agent-in-feedzy'; } elseif ( 'proxy' === $active_tab ) { @@ -27,6 +31,14 @@

error ); ?>

+ +
+ + <?php echo esc_html( $offer_data['bannerAlt'] ); ?> +
+
+
+
@@ -197,7 +209,7 @@ class="">">
-
+