PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.1
Elementor Website Builder – more than just a page builder v3.34.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / controls / gallery.php

gallery.php in Elementor Website Builder – more than just a page builder 3.34.1, at includes/controls/gallery.php

209 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Utils\Hints;
5 use Elementor\Modules\DynamicTags\Module as TagsModule;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor gallery control.
13 *
14 * A base control for creating gallery chooser control. Based on the WordPress
15 * media library galleries. Used to select images from the WordPress media library.
16 *
17 * @since 1.0.0
18 */
19 class Control_Gallery extends Base_Data_Control {
20
21 /**
22 * Get gallery control type.
23 *
24 * Retrieve the control type, in this case `gallery`.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @return string Control type.
30 */
31 public function get_type() {
32 return 'gallery';
33 }
34
35 public function on_export( $settings ) {
36 foreach ( $settings as $attachment ) {
37 if ( ! empty( $attachment['url'] ) ) {
38 do_action( 'elementor/templates/collect_media_url', $attachment['url'], $attachment );
39 }
40 }
41
42 return $settings;
43 }
44
45 /**
46 * Import gallery images.
47 *
48 * Used to import gallery control files from external sites while importing
49 * Elementor template JSON file, and replacing the old data.
50 *
51 * @since 1.0.0
52 * @access public
53 *
54 * @param array $settings Control settings.
55 *
56 * @return array Control settings.
57 */
58 public function on_import( $settings ) {
59 foreach ( $settings as &$attachment ) {
60 if ( empty( $attachment['url'] ) ) {
61 continue;
62 }
63
64 $local_file_path = \Elementor\TemplateLibrary\Classes\Media_Mapper::get_local_file_path( $attachment['url'] );
65 $imported_attachment = false;
66
67 if ( $local_file_path !== $attachment['url'] && file_exists( $local_file_path ) ) {
68 $imported_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import_local_file( $local_file_path );
69 }
70
71 if ( ! $imported_attachment ) {
72 $imported_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( $attachment );
73 }
74
75 $attachment = $imported_attachment;
76 }
77
78 // Filter out attachments that don't exist
79 $settings = array_filter( $settings );
80
81 return $settings;
82 }
83
84 /**
85 * Render gallery control output in the editor.
86 *
87 * Used to generate the control HTML in the editor using Underscore JS
88 * template. The variables for the class are available using `data` JS
89 * object.
90 *
91 * @since 1.0.0
92 * @access public
93 */
94 public function content_template() {
95 ?>
96 <div class="elementor-control-field">
97 <div class="elementor-control-title">{{{ data.label }}}</div>
98 <div class="elementor-control-input-wrapper">
99 <# if ( data.description ) { #>
100 <div class="elementor-control-field-description">{{{ data.description }}}</div>
101 <# } #>
102 <div class="elementor-control-media__content elementor-control-tag-area">
103 <div class="elementor-control-gallery-status elementor-control-dynamic-switcher-wrapper">
104 <span class="elementor-control-gallery-status-title"></span>
105 <button class="elementor-control-gallery-clear elementor-control-unit-1 tooltip-target" data-tooltip="<?php echo esc_attr__( 'Clear gallery', 'elementor' ); ?>" aria-label="<?php echo esc_attr__( 'Clear gallery', 'elementor' ); ?>">
106 <i class="eicon-trash-o" aria-hidden="true"></i>
107 </button>
108 </div>
109 <div class="elementor-control-gallery-content">
110 <div class="elementor-control-gallery-thumbnails" tabindex="0"></div>
111 <div class="elementor-control-gallery-edit">
112 <span><i class="eicon-pencil" aria-hidden="true"></i></span>
113 <span class="elementor-screen-only"><?php echo esc_html__( 'Edit gallery', 'elementor' ); ?></span>
114 </div>
115 <button class="elementor-button elementor-control-gallery-add tooltip-target" data-tooltip="<?php echo esc_attr__( 'Add Images', 'elementor' ); ?>" aria-label="<?php echo esc_attr__( 'Add Images', 'elementor' ); ?>">
116 <i class="eicon-plus-circle" aria-hidden="true"></i>
117 </button>
118 </div>
119 </div>
120
121 <?php
122 /*
123 ?>
124 <div class="elementor-control-media__warnings" role="alert" style="display: none;">
125 <?php
126 Hints::get_notice_template( [
127 'type' => 'warning',
128 'content' => esc_html__( 'This image doesn’t contain ALT text - which is necessary for accessibility and SEO.', 'elementor' ),
129 'icon' => true,
130 ] );
131 ?>
132 </div>
133 <?php
134 */ ?>
135 <?php $this->maybe_display_io_hints(); ?>
136 </div>
137 </div>
138 <?php
139 }
140
141 private function maybe_display_io_hints() {
142 if ( Hints::should_display_hint( 'image-optimization' ) ) {
143 $content_text = esc_html__( 'Optimize your images to enhance site performance by using Image Optimizer.', 'elementor' );
144 $button_text = Hints::is_plugin_installed( 'image-optimization' ) ? esc_html__( 'Activate Plugin', 'elementor' ) : esc_html__( 'Install Plugin', 'elementor' );
145 $action_url = Hints::get_plugin_action_url( 'image-optimization' );
146 } elseif ( Hints::should_display_hint( 'image-optimization-connect' ) ) {
147 $content_text = esc_html__( "This image isn't optimized. You need to connect your Image Optimizer account first.", 'elementor' );
148 $button_text = esc_html__( 'Connect Now', 'elementor' );
149 $action_url = admin_url( 'admin.php?page=image-optimization-settings' );
150 } else {
151 return;
152 }
153
154 ?>
155 <div class="elementor-control-media__promotions" role="alert" style="display: none;">
156 <?php
157 Hints::get_notice_template( [
158 'display' => ! Hints::is_dismissed( 'image-optimization' ),
159 'type' => 'info',
160 'content' => $content_text,
161 'icon' => true,
162 'dismissible' => 'image_optimizer_hint',
163 'button_text' => $button_text,
164 'button_event' => 'image_optimizer_hint',
165 'button_data' => [
166 'action_url' => $action_url,
167 ],
168 ] ); ?>
169 </div>
170 <?php
171 }
172
173 /**
174 * Get gallery control default settings.
175 *
176 * Retrieve the default settings of the gallery control. Used to return the
177 * default settings while initializing the gallery control.
178 *
179 * @since 1.0.0
180 * @access protected
181 *
182 * @return array Control default settings.
183 */
184 protected function get_default_settings() {
185 return [
186 'label_block' => true,
187 'dynamic' => [
188 'categories' => [ TagsModule::GALLERY_CATEGORY ],
189 'returnType' => 'object',
190 ],
191 ];
192 }
193
194 /**
195 * Get gallery control default values.
196 *
197 * Retrieve the default value of the gallery control. Used to return the default
198 * values while initializing the gallery control.
199 *
200 * @since 1.0.0
201 * @access public
202 *
203 * @return array Control default value.
204 */
205 public function get_default_value() {
206 return [];
207 }
208 }
209