* @copyright 2007-2022 Apollotheme * @license http://apollotheme.com - prestashop template provider */ namespace LeoElements; use LeoElements\Modules\DynamicTags\Module as TagsModule; use LeoElements\Leo_Helper; if ( ! defined( '_PS_VERSION_' ) ) { exit; // Exit if accessed directly. } /** * Elementor media control. * * A base control for creating a media chooser control. Based on the WordPress * media library. Used to select an image from the WordPress media library. * * @since 1.0.0 */ class Control_Media extends Control_Base_Multiple { /** * Get media control type. * * Retrieve the control type, in this case `media`. * * @since 1.0.0 * @access public * * @return string Control type. */ public function get_type() { return 'media'; } /** * Get media control default values. * * Retrieve the default value of the media control. Used to return the default * values while initializing the media control. * * @since 1.0.0 * @access public * * @return array Control default value. */ public function get_default_value() { return [ 'url' => '', 'id' => '', ]; } /** * Import media images. * * Used to import media control files from external sites while importing * Elementor template JSON file, and replacing the old data. * * @since 1.0.0 * @access public * * @param array $settings Control settings * * @return array Control settings. */ public function on_import( $settings ) { if ( empty( $settings['url'] ) ) { return $settings; } $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings ); if ( ! $settings ) { $settings = [ 'id' => '', 'url' => Utils::get_placeholder_image_src(), ]; } return $settings; } /** * Enqueue media control scripts and styles. * * Used to register and enqueue custom scripts and styles used by the media * control. * * @since 1.0.0 * @access public */ public function enqueue() {} /** * Render media control output in the editor. * * Used to generate the control HTML in the editor using Underscore JS * template. The variables for the class are available using `data` JS * object. * * @since 1.0.0 * @access public */ public function content_template() { ?>
<# if( 'image' === data.media_type ) { #>
<# } else if( 'video' === data.media_type ) { #> <# } #>
<# if( 'image' === data.media_type ) { #>
<# } else if( 'video' === data.media_type ) { #>
<# } #>
<# if ( data.description ) { #>
{{{ data.description }}}
<# } #>
true, 'media_type' => 'image', ]; } /** * Get media control image title. * * Retrieve the `title` of the image selected by the media control. * * @since 1.0.0 * @access public * @static * * @param array $attachment Media attachment. * * @return string Image title. */ public static function get_image_title( $attachment ) { return !empty( $instance['title'] ) ? Leo_Helper::esc_attr( $instance['title'] ) : ''; } /** * Get media control image alt. * * Retrieve the `alt` value of the image selected by the media control. * * @since 1.0.0 * @access public * @static * * @param array $instance Media attachment. * * @return string Image alt. */ public static function get_image_alt( $instance ) { return !empty( $instance['alt'] ) ? Leo_Helper::esc_attr( $instance['alt'] ) : ''; } }