balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

shapes.php (6390B)


      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 
    108 		if ( isset( self::$shapes[ $shape ] ) && isset( self::$shapes[ $shape ]['path'] ) ) {
    109 			$path = self::$shapes[ $shape ]['path'];
    110 			return ( $is_negative ) ? str_replace( '.svg', '-negative.svg', $path ) : $path;
    111 		}
    112 
    113 		$file_name = $shape;
    114 
    115 		if ( $is_negative ) {
    116 			$file_name .= '-negative';
    117 		}
    118 
    119 		return ELEMENTOR_PATH . 'assets/shapes/' . $file_name . '.svg';
    120 	}
    121 
    122 	/**
    123 	 * Init shapes.
    124 	 *
    125 	 * Set the supported shapes.
    126 	 *
    127 	 * @since 1.3.0
    128 	 * @access private
    129 	 * @static
    130 	 */
    131 	private static function init_shapes() {
    132 		$native_shapes = [
    133 			'mountains' => [
    134 				'title' => _x( 'Mountains', 'Shapes', 'elementor' ),
    135 				'has_flip' => true,
    136 			],
    137 			'drops' => [
    138 				'title' => _x( 'Drops', 'Shapes', 'elementor' ),
    139 				'has_negative' => true,
    140 				'has_flip' => true,
    141 				'height_only' => true,
    142 			],
    143 			'clouds' => [
    144 				'title' => _x( 'Clouds', 'Shapes', 'elementor' ),
    145 				'has_negative' => true,
    146 				'has_flip' => true,
    147 				'height_only' => true,
    148 			],
    149 			'zigzag' => [
    150 				'title' => _x( 'Zigzag', 'Shapes', 'elementor' ),
    151 			],
    152 			'pyramids' => [
    153 				'title' => _x( 'Pyramids', 'Shapes', 'elementor' ),
    154 				'has_negative' => true,
    155 				'has_flip' => true,
    156 			],
    157 			'triangle' => [
    158 				'title' => _x( 'Triangle', 'Shapes', 'elementor' ),
    159 				'has_negative' => true,
    160 			],
    161 			'triangle-asymmetrical' => [
    162 				'title' => _x( 'Triangle Asymmetrical', 'Shapes', 'elementor' ),
    163 				'has_negative' => true,
    164 				'has_flip' => true,
    165 			],
    166 			'tilt' => [
    167 				'title' => _x( 'Tilt', 'Shapes', 'elementor' ),
    168 				'has_flip' => true,
    169 				'height_only' => true,
    170 			],
    171 			'opacity-tilt' => [
    172 				'title' => _x( 'Tilt Opacity', 'Shapes', 'elementor' ),
    173 				'has_flip' => true,
    174 			],
    175 			'opacity-fan' => [
    176 				'title' => _x( 'Fan Opacity', 'Shapes', 'elementor' ),
    177 			],
    178 			'curve' => [
    179 				'title' => _x( 'Curve', 'Shapes', 'elementor' ),
    180 				'has_negative' => true,
    181 			],
    182 			'curve-asymmetrical' => [
    183 				'title' => _x( 'Curve Asymmetrical', 'Shapes', 'elementor' ),
    184 				'has_negative' => true,
    185 				'has_flip' => true,
    186 			],
    187 			'waves' => [
    188 				'title' => _x( 'Waves', 'Shapes', 'elementor' ),
    189 				'has_negative' => true,
    190 				'has_flip' => true,
    191 			],
    192 			'wave-brush' => [
    193 				'title' => _x( 'Waves Brush', 'Shapes', 'elementor' ),
    194 				'has_flip' => true,
    195 			],
    196 			'waves-pattern' => [
    197 				'title' => _x( 'Waves Pattern', 'Shapes', 'elementor' ),
    198 				'has_flip' => true,
    199 			],
    200 			'arrow' => [
    201 				'title' => _x( 'Arrow', 'Shapes', 'elementor' ),
    202 				'has_negative' => true,
    203 			],
    204 			'split' => [
    205 				'title' => _x( 'Split', 'Shapes', 'elementor' ),
    206 				'has_negative' => true,
    207 			],
    208 			'book' => [
    209 				'title' => _x( 'Book', 'Shapes', 'elementor' ),
    210 				'has_negative' => true,
    211 			],
    212 		];
    213 
    214 		self::$shapes = array_merge( $native_shapes, self::get_additional_shapes() );
    215 	}
    216 
    217 	/**
    218 	 * Get Additional Shapes
    219 	 *
    220 	 * Used to add custom shapes to elementor.
    221 	 *
    222 	 * @since 2.5.0
    223 	 *
    224 	 * @return array
    225 	 */
    226 	private static function get_additional_shapes() {
    227 		static $additional_shapes = null;
    228 
    229 		if ( null !== $additional_shapes ) {
    230 			return $additional_shapes;
    231 		}
    232 		$additional_shapes = [];
    233 		/**
    234 		 * Additional shapes.
    235 		 *
    236 		 * Filters the shapes used by Elementor to add additional shapes.
    237 		 *
    238 		 * @since 2.0.1
    239 		 *
    240 		 * @param array $additional_shapes Additional Elementor shapes.
    241 		 */
    242 		$additional_shapes = apply_filters( 'elementor/shapes/additional_shapes', $additional_shapes );
    243 		return $additional_shapes;
    244 	}
    245 
    246 	/**
    247 	 * Get Additional Shapes For Config
    248 	 *
    249 	 * Used to set additional shape paths for editor
    250 	 *
    251 	 * @since 2.5.0
    252 	 *
    253 	 * @return array|bool
    254 	 */
    255 	public static function get_additional_shapes_for_config() {
    256 		$additional_shapes = self::get_additional_shapes();
    257 		if ( empty( $additional_shapes ) ) {
    258 			return false;
    259 		}
    260 
    261 		$additional_shapes_config = [];
    262 		foreach ( $additional_shapes as $shape_name => $shape_settings ) {
    263 			if ( ! isset( $shape_settings['url'] ) ) {
    264 				continue;
    265 			}
    266 			$additional_shapes_config[ $shape_name ] = $shape_settings['url'];
    267 		}
    268 
    269 		if ( empty( $additional_shapes_config ) ) {
    270 			return false;
    271 		}
    272 
    273 		return $additional_shapes_config;
    274 	}
    275 }