PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 / shapes.php

shapes.php in Elementor Website Builder – more than just a page builder 4.2.0, at includes/shapes.php

307 lines 7.8 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 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor shapes.
10 *
11 * Elementor shapes handler class is responsible for setting up the supported
12 * shape dividers.
13 *
14 * @since 1.3.0
15 */
16 class Shapes {
17
18 /**
19 * The exclude filter.
20 */
21 const FILTER_EXCLUDE = 'exclude';
22
23 /**
24 * The include filter.
25 */
26 const FILTER_INCLUDE = 'include';
27
28 /**
29 * Shapes.
30 *
31 * Holds the list of supported shapes.
32 *
33 * @since 1.3.0
34 * @access private
35 * @static
36 *
37 * @var array A list of supported shapes.
38 */
39 private static $shapes;
40
41 /**
42 * Get shapes.
43 *
44 * Retrieve a shape from the lists of supported shapes. If no shape specified
45 * it will return all the supported shapes.
46 *
47 * @since 1.3.0
48 * @access public
49 * @static
50 *
51 * @param array $shape Optional. Specific shape. Default is `null`.
52 *
53 * @return array The specified shape or a list of all the supported shapes.
54 */
55 public static function get_shapes( $shape = null ) {
56 if ( null === self::$shapes ) {
57 self::init_shapes();
58 }
59
60 if ( $shape ) {
61 return isset( self::$shapes[ $shape ] ) ? self::$shapes[ $shape ] : null;
62 }
63
64 return self::$shapes;
65 }
66
67 /**
68 * Filter shapes.
69 *
70 * Retrieve shapes filtered by a specific condition, from the list of
71 * supported shapes.
72 *
73 * @since 1.3.0
74 * @access public
75 * @static
76 *
77 * @param string $by Specific condition to filter by.
78 * @param string $filter Optional. Comparison condition to filter by.
79 * Default is `include`.
80 *
81 * @return array A list of filtered shapes.
82 */
83 public static function filter_shapes( $by, $filter = self::FILTER_INCLUDE ) {
84 return array_filter(
85 self::get_shapes(), function( $shape ) use ( $by, $filter ) {
86 return self::FILTER_INCLUDE === $filter xor empty( $shape[ $by ] );
87 }
88 );
89 }
90
91 /**
92 * Get shape path.
93 *
94 * For a given shape, retrieve the file path.
95 *
96 * @since 1.3.0
97 * @access public
98 * @static
99 *
100 * @param string $shape The shape.
101 * @param bool $is_negative Optional. Whether the file name is negative or
102 * not. Default is `false`.
103 *
104 * @return string Shape file path.
105 */
106 public static function get_shape_path( $shape, $is_negative = false ) {
107 if ( ! isset( self::$shapes[ $shape ] ) ) {
108 return '';
109 }
110
111 if ( isset( self::$shapes[ $shape ]['path'] ) ) {
112 $path = self::$shapes[ $shape ]['path'];
113 return ( $is_negative ) ? str_replace( '.svg', '-negative.svg', $path ) : $path;
114 }
115
116 $file_name = $shape;
117
118 if ( $is_negative ) {
119 $file_name .= '-negative';
120 }
121
122 return ELEMENTOR_PATH . 'assets/shapes/' . $file_name . '.svg';
123 }
124
125 /**
126 * Init shapes.
127 *
128 * Set the supported shapes.
129 *
130 * @since 1.3.0
131 * @access private
132 * @static
133 */
134 private static function init_shapes() {
135 $native_shapes = [
136 'mountains' => [
137 'title' => esc_html_x( 'Mountains', 'Shapes', 'elementor' ),
138 'image' => ELEMENTOR_ASSETS_URL . 'shapes/mountains.svg',
139 'has_flip' => true,
140 ],
141 'drops' => [
142 'title' => esc_html_x( 'Drops', 'Shapes', 'elementor' ),
143 'image' => ELEMENTOR_ASSETS_URL . 'shapes/drops.svg',
144 'has_negative' => true,
145 'has_flip' => true,
146 'height_only' => true,
147 ],
148 'clouds' => [
149 'title' => esc_html_x( 'Clouds', 'Shapes', 'elementor' ),
150 'image' => ELEMENTOR_ASSETS_URL . 'shapes/clouds.svg',
151 'has_negative' => true,
152 'has_flip' => true,
153 'height_only' => true,
154 ],
155 'zigzag' => [
156 'title' => esc_html_x( 'Zigzag', 'Shapes', 'elementor' ),
157 'image' => ELEMENTOR_ASSETS_URL . 'shapes/zigzag.svg',
158 ],
159 'pyramids' => [
160 'title' => esc_html_x( 'Pyramids', 'Shapes', 'elementor' ),
161 'image' => ELEMENTOR_ASSETS_URL . 'shapes/pyramids.svg',
162 'has_negative' => true,
163 'has_flip' => true,
164 ],
165 'triangle' => [
166 'title' => esc_html_x( 'Triangle', 'Shapes', 'elementor' ),
167 'image' => ELEMENTOR_ASSETS_URL . 'shapes/triangle.svg',
168 'has_negative' => true,
169 ],
170 'triangle-asymmetrical' => [
171 'title' => esc_html_x( 'Triangle Asymmetrical', 'Shapes', 'elementor' ),
172 'image' => ELEMENTOR_ASSETS_URL . 'shapes/triangle-asymmetrical.svg',
173 'has_negative' => true,
174 'has_flip' => true,
175 ],
176 'tilt' => [
177 'title' => esc_html_x( 'Tilt', 'Shapes', 'elementor' ),
178 'image' => ELEMENTOR_ASSETS_URL . 'shapes/tilt.svg',
179 'has_flip' => true,
180 'height_only' => true,
181 ],
182 'opacity-tilt' => [
183 'title' => esc_html_x( 'Tilt Opacity', 'Shapes', 'elementor' ),
184 'image' => ELEMENTOR_ASSETS_URL . 'shapes/opacity-tilt.svg',
185 'has_flip' => true,
186 ],
187 'opacity-fan' => [
188 'title' => esc_html_x( 'Fan Opacity', 'Shapes', 'elementor' ),
189 'image' => ELEMENTOR_ASSETS_URL . 'shapes/opacity-fan.svg',
190 ],
191 'curve' => [
192 'title' => esc_html_x( 'Curve', 'Shapes', 'elementor' ),
193 'image' => ELEMENTOR_ASSETS_URL . 'shapes/curve.svg',
194 'has_negative' => true,
195 ],
196 'curve-asymmetrical' => [
197 'title' => esc_html_x( 'Curve Asymmetrical', 'Shapes', 'elementor' ),
198 'image' => ELEMENTOR_ASSETS_URL . 'shapes/curve-asymmetrical.svg',
199 'has_negative' => true,
200 'has_flip' => true,
201 ],
202 'waves' => [
203 'title' => esc_html_x( 'Waves', 'Shapes', 'elementor' ),
204 'image' => ELEMENTOR_ASSETS_URL . 'shapes/waves.svg',
205 'has_negative' => true,
206 'has_flip' => true,
207 ],
208 'wave-brush' => [
209 'title' => esc_html_x( 'Waves Brush', 'Shapes', 'elementor' ),
210 'image' => ELEMENTOR_ASSETS_URL . 'shapes/wave-brush.svg',
211 'has_flip' => true,
212 ],
213 'waves-pattern' => [
214 'title' => esc_html_x( 'Waves Pattern', 'Shapes', 'elementor' ),
215 'image' => ELEMENTOR_ASSETS_URL . 'shapes/waves-pattern.svg',
216 'has_flip' => true,
217 ],
218 'book' => [
219 'title' => esc_html_x( 'Book', 'Shapes', 'elementor' ),
220 'image' => ELEMENTOR_ASSETS_URL . 'shapes/book.svg',
221 'has_negative' => true,
222 ],
223 'split' => [
224 'title' => esc_html_x( 'Split', 'Shapes', 'elementor' ),
225 'image' => ELEMENTOR_ASSETS_URL . 'shapes/split.svg',
226 'has_negative' => true,
227 ],
228 'arrow' => [
229 'title' => esc_html_x( 'Arrow', 'Shapes', 'elementor' ),
230 'image' => ELEMENTOR_ASSETS_URL . 'shapes/arrow.svg',
231 'has_negative' => true,
232 ],
233 ];
234
235 self::$shapes = array_merge( $native_shapes, self::get_additional_shapes() );
236 }
237
238 /**
239 * Get Additional Shapes
240 *
241 * Used to add custom shapes to elementor.
242 *
243 * @since 2.5.0
244 *
245 * @return array
246 */
247 private static function get_additional_shapes() {
248 static $additional_shapes = null;
249
250 if ( null !== $additional_shapes ) {
251 return $additional_shapes;
252 }
253
254 $additional_shapes = [];
255
256 /**
257 * Additional shapes.
258 *
259 * Filters the shapes used by Elementor to add additional shapes.
260 *
261 * @since 2.0.1
262 *
263 * @param array $additional_shapes Additional Elementor shapes.
264 */
265 $additional_shapes = apply_filters( 'elementor/shapes/additional_shapes', $additional_shapes );
266
267 // BC for addons that add additional shapes the old way using `url` instead of `image`.
268 foreach ( $additional_shapes as $shape_name => $shape_settings ) {
269 if ( ! isset( $shape_settings['image'] ) && isset( $shape_settings['url'] ) ) {
270 $additional_shapes[ $shape_name ]['image'] = $shape_settings['url'];
271 }
272 }
273
274 return $additional_shapes;
275 }
276
277 /**
278 * Get Additional Shapes For Config
279 *
280 * Used to set additional shape paths for editor
281 *
282 * @since 2.5.0
283 *
284 * @return array|bool
285 */
286 public static function get_additional_shapes_for_config() {
287 $additional_shapes = self::get_additional_shapes();
288 if ( empty( $additional_shapes ) ) {
289 return false;
290 }
291
292 $additional_shapes_config = [];
293 foreach ( $additional_shapes as $shape_name => $shape_settings ) {
294 if ( ! isset( $shape_settings['url'] ) ) {
295 continue;
296 }
297 $additional_shapes_config[ $shape_name ] = $shape_settings['url'];
298 }
299
300 if ( empty( $additional_shapes_config ) ) {
301 return false;
302 }
303
304 return $additional_shapes_config;
305 }
306 }
307