Files
wyczarujprezent.pl/modules/leoelements/includes/controls/media.php
2024-10-28 22:14:22 +01:00

217 lines
6.1 KiB
PHP

<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @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() {
?>
<div class="elementor-control-field elementor-control-media">
<label class="elementor-control-title">{{{ data.label }}}</label>
<div class="elementor-units-choices">
<label class="elementor-units-choices-label elementor-control-media-alt"><?php Leo_Helper::_e('Alt') ?></label>
</div>
<div class="elementor-units-choices">
<label class="elementor-units-choices-label elementor-control-media-title"><?php Leo_Helper::_e('Title') ?></label>
</div>
<div class="elementor-units-choices">
<input type="radio" checked id="elementor-control-media-url-{{ data._cid }}" value="{{ data.controlValue.url }}">
<label class="elementor-units-choices-label elementor-control-media-url"><?php Leo_Helper::_e('Modify URL') ?></label>
</div>
<div class="elementor-control-input-wrapper elementor-aspect-ratio-219">
<div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area elementor-fit-aspect-ratio">
<div class="elementor-control-media-upload-button elementor-fit-aspect-ratio">
<i class="eicon-plus-circle" aria-hidden="true"></i>
</div>
<div class="elementor-control-media-area elementor-fit-aspect-ratio">
<div class="elementor-control-media__remove" title="<?php echo Leo_Helper::__( 'Remove', 'elementor' ); ?>">
<i class="eicon-trash"></i>
</div>
<# if( 'image' === data.media_type ) { #>
<div class="elementor-control-media__preview elementor-fit-aspect-ratio"></div>
<# } else if( 'video' === data.media_type ) { #>
<video class="elementor-control-media-video" preload="metadata"></video>
<i class="eicon-video-camera"></i>
<# } #>
</div>
<div class="elementor-control-media__tools">
<# if( 'image' === data.media_type ) { #>
<div class="elementor-control-media__tool elementor-control-media__replace"><?php echo Leo_Helper::__( 'Choose Image', 'elementor' ); ?></div>
<# } else if( 'video' === data.media_type ) { #>
<div class="elementor-control-media__tool elementor-control-media__replace"><?php echo Leo_Helper::__( 'Choose Video', 'elementor' ); ?></div>
<# } #>
</div>
</div>
</div>
<# if ( data.description ) { #>
<div class="elementor-control-field-description">{{{ data.description }}}</div>
<# } #>
<input type="hidden" data-setting="{{ data.name }}"/>
</div>
<?php
}
/**
* Get media control default settings.
*
* Retrieve the default settings of the media control. Used to return the default
* settings while initializing the media control.
*
* @since 1.0.0
* @access protected
*
* @return array Control default settings.
*/
protected function get_default_settings() {
return [
'label_block' => 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'] ) : '';
}
}