| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Promotions; |
| 3 |
|
| 4 |
use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; |
| 5 |
use Elementor\Includes\EditorAssetsAPI; |
| 6 |
use Elementor\Utils; |
| 7 |
|
| 8 |
class PromotionData { |
| 9 |
protected EditorAssetsAPI $editor_assets_api; |
| 10 |
|
| 11 |
public function __construct( EditorAssetsAPI $editor_assets_api ) { |
| 12 |
$this->editor_assets_api = $editor_assets_api; |
| 13 |
} |
| 14 |
|
| 15 |
public function get_promotion_data( $force_request = false ): array { |
| 16 |
$assets_data = $this->transform_assets_data( $force_request ); |
| 17 |
|
| 18 |
return [ |
| 19 |
Utils::ANIMATED_HEADLINE => $this->get_animated_headline_data( $assets_data ), |
| 20 |
Utils::VIDEO_PLAYLIST => $this->get_video_playlist_data( $assets_data ), |
| 21 |
Utils::CTA => $this->get_cta_button_data( $assets_data ), |
| 22 |
Utils::IMAGE_CAROUSEL => $this->get_image_carousel_data( $assets_data ), |
| 23 |
Utils::TESTIMONIAL_WIDGET => $this->get_testimonial_widget_data( $assets_data ), |
| 24 |
]; |
| 25 |
} |
| 26 |
|
| 27 |
public function get_v4_promotions_data( $force_request = false ): array { |
| 28 |
$assets_data = $this->editor_assets_api->get_assets_data( $force_request ); |
| 29 |
|
| 30 |
if ( empty( $assets_data ) ) { |
| 31 |
return []; |
| 32 |
} |
| 33 |
|
| 34 |
$promotions = []; |
| 35 |
|
| 36 |
foreach ( $assets_data as $item ) { |
| 37 |
foreach ( $item as $key => $promotion ) { |
| 38 |
$promotions[ $key ] = [ |
| 39 |
'title' => esc_html( $promotion['title'] ?? '' ), |
| 40 |
'content' => esc_html( $promotion['content'] ?? '' ), |
| 41 |
'ctaUrl' => esc_url( $promotion['ctaUrl'] ?? '' ), |
| 42 |
'image' => esc_url( $promotion['image'] ?? '' ), |
| 43 |
]; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return $promotions; |
| 48 |
} |
| 49 |
|
| 50 |
private function transform_assets_data( $force_request = false ) { |
| 51 |
$assets_data = $this->editor_assets_api->get_assets_data( $force_request ); |
| 52 |
$transformed_data = []; |
| 53 |
|
| 54 |
foreach ( $assets_data as $asset ) { |
| 55 |
$transformed_data[ $asset['id'] ] = $asset['imageSrc']; |
| 56 |
} |
| 57 |
|
| 58 |
return $transformed_data; |
| 59 |
} |
| 60 |
|
| 61 |
private function get_animated_headline_data( $assets_data ) { |
| 62 |
$data = [ |
| 63 |
'image' => esc_url( $assets_data[ Utils::ANIMATED_HEADLINE ] ?? '' ), |
| 64 |
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ), |
| 65 |
'title' => esc_html__( 'Bring Headlines to Life', 'elementor' ), |
| 66 |
'description' => [ |
| 67 |
esc_html__( 'Highlight key messages dynamically.', 'elementor' ), |
| 68 |
esc_html__( 'Apply rotating effects to text.', 'elementor' ), |
| 69 |
esc_html__( 'Fully customize your headlines.', 'elementor' ), |
| 70 |
], |
| 71 |
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ), |
| 72 |
'upgrade_url' => 'https://go.elementor.com/go-pro-heading-widget-control/', |
| 73 |
]; |
| 74 |
|
| 75 |
return $this->filter_data( Utils::ANIMATED_HEADLINE, $data ); |
| 76 |
} |
| 77 |
|
| 78 |
private function get_video_playlist_data( $assets_data ) { |
| 79 |
$data = [ |
| 80 |
'image' => esc_url( $assets_data[ Utils::VIDEO_PLAYLIST ] ?? '' ), |
| 81 |
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ), |
| 82 |
'title' => esc_html__( 'Showcase Video Playlists', 'elementor' ), |
| 83 |
'description' => [ |
| 84 |
esc_html__( 'Embed videos with full control.', 'elementor' ), |
| 85 |
esc_html__( 'Adjust layout and playback settings.', 'elementor' ), |
| 86 |
esc_html__( 'Seamlessly customize video appearance.', 'elementor' ), |
| 87 |
], |
| 88 |
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ), |
| 89 |
'upgrade_url' => 'https://go.elementor.com/go-pro-video-widget-control/', |
| 90 |
]; |
| 91 |
|
| 92 |
return $this->filter_data( Utils::VIDEO_PLAYLIST, $data ); |
| 93 |
} |
| 94 |
|
| 95 |
private function get_cta_button_data( $assets_data ) { |
| 96 |
$data = [ |
| 97 |
'image' => esc_url( $assets_data[ Utils::CTA ] ?? '' ), |
| 98 |
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ), |
| 99 |
'title' => esc_html__( 'Boost Conversions with CTAs', 'elementor' ), |
| 100 |
'description' => [ |
| 101 |
esc_html__( 'Combine text, buttons, and images.', 'elementor' ), |
| 102 |
esc_html__( 'Add hover animations and CSS effects.', 'elementor' ), |
| 103 |
esc_html__( 'Create unique, interactive designs.', 'elementor' ), |
| 104 |
], |
| 105 |
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ), |
| 106 |
'upgrade_url' => 'https://go.elementor.com/go-pro-button-widget-control/', |
| 107 |
]; |
| 108 |
|
| 109 |
return $this->filter_data( Utils::CTA, $data ); |
| 110 |
} |
| 111 |
|
| 112 |
private function get_image_carousel_data( $assets_data ) { |
| 113 |
$data = [ |
| 114 |
'image' => esc_url( $assets_data[ Utils::IMAGE_CAROUSEL ] ?? '' ), |
| 115 |
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ), |
| 116 |
'title' => esc_html__( 'Design Custom Carousels', 'elementor' ), |
| 117 |
'description' => [ |
| 118 |
esc_html__( 'Create flexible custom carousels.', 'elementor' ), |
| 119 |
esc_html__( 'Adjust transitions and animations.', 'elementor' ), |
| 120 |
esc_html__( 'Showcase multiple items with style.', 'elementor' ), |
| 121 |
], |
| 122 |
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ), |
| 123 |
'upgrade_url' => 'https://go.elementor.com/go-pro-image-carousel-widget-control/', |
| 124 |
]; |
| 125 |
|
| 126 |
return $this->filter_data( Utils::IMAGE_CAROUSEL, $data ); |
| 127 |
} |
| 128 |
|
| 129 |
private function get_testimonial_widget_data( $assets_data ) { |
| 130 |
$data = [ |
| 131 |
'image' => esc_url( $assets_data[ Utils::TESTIMONIAL_WIDGET ] ?? '' ), |
| 132 |
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ), |
| 133 |
'title' => esc_html__( 'Upgrade Your Testimonials', 'elementor' ), |
| 134 |
'description' => [ |
| 135 |
esc_html__( 'Display reviews in a rotating carousel.', 'elementor' ), |
| 136 |
esc_html__( 'Boost credibility with dynamic testimonials.', 'elementor' ), |
| 137 |
esc_html__( 'Customize layouts for visual appeal.', 'elementor' ), |
| 138 |
], |
| 139 |
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ), |
| 140 |
'upgrade_url' => 'https://go.elementor.com/go-pro-testimonial-widget-control/', |
| 141 |
]; |
| 142 |
|
| 143 |
return $this->filter_data( Utils::TESTIMONIAL_WIDGET, $data ); |
| 144 |
} |
| 145 |
|
| 146 |
private function filter_data( $widget_name, $asset_data ): array { |
| 147 |
return Filtered_Promotions_Manager::get_filtered_promotion_data( $asset_data, "elementor/widgets/{$widget_name}/custom_promotion", 'upgrade_url' ); |
| 148 |
} |
| 149 |
} |
| 150 |
|