admin-templates
1 year ago
base
1 year ago
container
1 year ago
controls
1 year ago
editor-templates
1 year ago
elements
1 year ago
interfaces
1 year ago
libraries
1 year ago
managers
1 year ago
settings
1 year ago
template-library
1 year ago
widgets
1 year ago
api.php
1 year ago
autoloader.php
1 year ago
beta-testers.php
3 years ago
compatibility.php
1 year ago
conditions.php
3 years ago
db.php
2 years ago
editor-assets-api.php
1 year ago
embed.php
1 year ago
fonts.php
1 year ago
frontend.php
1 year ago
heartbeat.php
3 years ago
maintenance-mode.php
2 years ago
maintenance.php
3 years ago
plugin.php
1 year ago
preview.php
1 year ago
rollback.php
3 years ago
shapes.php
1 year ago
stylesheet.php
1 year ago
tracker.php
1 year ago
user.php
2 years ago
utils.php
1 year ago
shapes.php
279 lines
| 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 | 'has_flip' => true, |
| 139 | ], |
| 140 | 'drops' => [ |
| 141 | 'title' => esc_html_x( 'Drops', 'Shapes', 'elementor' ), |
| 142 | 'has_negative' => true, |
| 143 | 'has_flip' => true, |
| 144 | 'height_only' => true, |
| 145 | ], |
| 146 | 'clouds' => [ |
| 147 | 'title' => esc_html_x( 'Clouds', 'Shapes', 'elementor' ), |
| 148 | 'has_negative' => true, |
| 149 | 'has_flip' => true, |
| 150 | 'height_only' => true, |
| 151 | ], |
| 152 | 'zigzag' => [ |
| 153 | 'title' => esc_html_x( 'Zigzag', 'Shapes', 'elementor' ), |
| 154 | ], |
| 155 | 'pyramids' => [ |
| 156 | 'title' => esc_html_x( 'Pyramids', 'Shapes', 'elementor' ), |
| 157 | 'has_negative' => true, |
| 158 | 'has_flip' => true, |
| 159 | ], |
| 160 | 'triangle' => [ |
| 161 | 'title' => esc_html_x( 'Triangle', 'Shapes', 'elementor' ), |
| 162 | 'has_negative' => true, |
| 163 | ], |
| 164 | 'triangle-asymmetrical' => [ |
| 165 | 'title' => esc_html_x( 'Triangle Asymmetrical', 'Shapes', 'elementor' ), |
| 166 | 'has_negative' => true, |
| 167 | 'has_flip' => true, |
| 168 | ], |
| 169 | 'tilt' => [ |
| 170 | 'title' => esc_html_x( 'Tilt', 'Shapes', 'elementor' ), |
| 171 | 'has_flip' => true, |
| 172 | 'height_only' => true, |
| 173 | ], |
| 174 | 'opacity-tilt' => [ |
| 175 | 'title' => esc_html_x( 'Tilt Opacity', 'Shapes', 'elementor' ), |
| 176 | 'has_flip' => true, |
| 177 | ], |
| 178 | 'opacity-fan' => [ |
| 179 | 'title' => esc_html_x( 'Fan Opacity', 'Shapes', 'elementor' ), |
| 180 | ], |
| 181 | 'curve' => [ |
| 182 | 'title' => esc_html_x( 'Curve', 'Shapes', 'elementor' ), |
| 183 | 'has_negative' => true, |
| 184 | ], |
| 185 | 'curve-asymmetrical' => [ |
| 186 | 'title' => esc_html_x( 'Curve Asymmetrical', 'Shapes', 'elementor' ), |
| 187 | 'has_negative' => true, |
| 188 | 'has_flip' => true, |
| 189 | ], |
| 190 | 'waves' => [ |
| 191 | 'title' => esc_html_x( 'Waves', 'Shapes', 'elementor' ), |
| 192 | 'has_negative' => true, |
| 193 | 'has_flip' => true, |
| 194 | ], |
| 195 | 'wave-brush' => [ |
| 196 | 'title' => esc_html_x( 'Waves Brush', 'Shapes', 'elementor' ), |
| 197 | 'has_flip' => true, |
| 198 | ], |
| 199 | 'waves-pattern' => [ |
| 200 | 'title' => esc_html_x( 'Waves Pattern', 'Shapes', 'elementor' ), |
| 201 | 'has_flip' => true, |
| 202 | ], |
| 203 | 'arrow' => [ |
| 204 | 'title' => esc_html_x( 'Arrow', 'Shapes', 'elementor' ), |
| 205 | 'has_negative' => true, |
| 206 | ], |
| 207 | 'split' => [ |
| 208 | 'title' => esc_html_x( 'Split', 'Shapes', 'elementor' ), |
| 209 | 'has_negative' => true, |
| 210 | ], |
| 211 | 'book' => [ |
| 212 | 'title' => esc_html_x( 'Book', 'Shapes', 'elementor' ), |
| 213 | 'has_negative' => true, |
| 214 | ], |
| 215 | ]; |
| 216 | |
| 217 | self::$shapes = array_merge( $native_shapes, self::get_additional_shapes() ); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Get Additional Shapes |
| 222 | * |
| 223 | * Used to add custom shapes to elementor. |
| 224 | * |
| 225 | * @since 2.5.0 |
| 226 | * |
| 227 | * @return array |
| 228 | */ |
| 229 | private static function get_additional_shapes() { |
| 230 | static $additional_shapes = null; |
| 231 | |
| 232 | if ( null !== $additional_shapes ) { |
| 233 | return $additional_shapes; |
| 234 | } |
| 235 | $additional_shapes = []; |
| 236 | /** |
| 237 | * Additional shapes. |
| 238 | * |
| 239 | * Filters the shapes used by Elementor to add additional shapes. |
| 240 | * |
| 241 | * @since 2.0.1 |
| 242 | * |
| 243 | * @param array $additional_shapes Additional Elementor shapes. |
| 244 | */ |
| 245 | $additional_shapes = apply_filters( 'elementor/shapes/additional_shapes', $additional_shapes ); |
| 246 | return $additional_shapes; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Get Additional Shapes For Config |
| 251 | * |
| 252 | * Used to set additional shape paths for editor |
| 253 | * |
| 254 | * @since 2.5.0 |
| 255 | * |
| 256 | * @return array|bool |
| 257 | */ |
| 258 | public static function get_additional_shapes_for_config() { |
| 259 | $additional_shapes = self::get_additional_shapes(); |
| 260 | if ( empty( $additional_shapes ) ) { |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | $additional_shapes_config = []; |
| 265 | foreach ( $additional_shapes as $shape_name => $shape_settings ) { |
| 266 | if ( ! isset( $shape_settings['url'] ) ) { |
| 267 | continue; |
| 268 | } |
| 269 | $additional_shapes_config[ $shape_name ] = $shape_settings['url']; |
| 270 | } |
| 271 | |
| 272 | if ( empty( $additional_shapes_config ) ) { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | return $additional_shapes_config; |
| 277 | } |
| 278 | } |
| 279 |