shapes.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor shapes.
  8. *
  9. * Elementor shapes handler class is responsible for setting up the supported
  10. * shape dividers.
  11. *
  12. * @since 1.3.0
  13. */
  14. class Shapes {
  15. /**
  16. * The exclude filter.
  17. */
  18. const FILTER_EXCLUDE = 'exclude';
  19. /**
  20. * The include filter.
  21. */
  22. const FILTER_INCLUDE = 'include';
  23. /**
  24. * Shapes.
  25. *
  26. * Holds the list of supported shapes.
  27. *
  28. * @since 1.3.0
  29. * @access private
  30. * @static
  31. *
  32. * @var array A list of supported shapes.
  33. */
  34. private static $shapes;
  35. /**
  36. * Get shapes.
  37. *
  38. * Retrieve a shape from the lists of supported shapes. If no shape specified
  39. * it will return all the supported shapes.
  40. *
  41. * @since 1.3.0
  42. * @access public
  43. * @static
  44. *
  45. * @param array $shape Optional. Specific shape. Default is `null`.
  46. *
  47. * @return array The specified shape or a list of all the supported shapes.
  48. */
  49. public static function get_shapes( $shape = null ) {
  50. if ( null === self::$shapes ) {
  51. self::init_shapes();
  52. }
  53. if ( $shape ) {
  54. return isset( self::$shapes[ $shape ] ) ? self::$shapes[ $shape ] : null;
  55. }
  56. return self::$shapes;
  57. }
  58. /**
  59. * Filter shapes.
  60. *
  61. * Retrieve shapes filtered by a specific condition, from the list of
  62. * supported shapes.
  63. *
  64. * @since 1.3.0
  65. * @access public
  66. * @static
  67. *
  68. * @param string $by Specific condition to filter by.
  69. * @param string $filter Optional. Comparison condition to filter by.
  70. * Default is `include`.
  71. *
  72. * @return array A list of filtered shapes.
  73. */
  74. public static function filter_shapes( $by, $filter = self::FILTER_INCLUDE ) {
  75. return array_filter(
  76. self::get_shapes(), function( $shape ) use ( $by, $filter ) {
  77. return self::FILTER_INCLUDE === $filter xor empty( $shape[ $by ] );
  78. }
  79. );
  80. }
  81. /**
  82. * Get shape path.
  83. *
  84. * For a given shape, retrieve the file path.
  85. *
  86. * @since 1.3.0
  87. * @access public
  88. * @static
  89. *
  90. * @param string $shape The shape.
  91. * @param bool $is_negative Optional. Whether the file name is negative or
  92. * not. Default is `false`.
  93. *
  94. * @return string Shape file path.
  95. */
  96. public static function get_shape_path( $shape, $is_negative = false ) {
  97. if ( isset( self::$shapes[ $shape ] ) && isset( self::$shapes[ $shape ]['path'] ) ) {
  98. return self::$shapes[ $shape ]['path'];
  99. }
  100. $file_name = $shape;
  101. if ( $is_negative ) {
  102. $file_name .= '-negative';
  103. }
  104. return ELEMENTOR_PATH . 'assets/shapes/' . $file_name . '.svg';
  105. }
  106. /**
  107. * Init shapes.
  108. *
  109. * Set the supported shapes.
  110. *
  111. * @since 1.3.0
  112. * @access private
  113. * @static
  114. */
  115. private static function init_shapes() {
  116. $native_shapes = [
  117. 'mountains' => [
  118. 'title' => _x( 'Mountains', 'Shapes', 'elementor' ),
  119. 'has_flip' => true,
  120. ],
  121. 'drops' => [
  122. 'title' => _x( 'Drops', 'Shapes', 'elementor' ),
  123. 'has_negative' => true,
  124. 'has_flip' => true,
  125. 'height_only' => true,
  126. ],
  127. 'clouds' => [
  128. 'title' => _x( 'Clouds', 'Shapes', 'elementor' ),
  129. 'has_negative' => true,
  130. 'has_flip' => true,
  131. 'height_only' => true,
  132. ],
  133. 'zigzag' => [
  134. 'title' => _x( 'Zigzag', 'Shapes', 'elementor' ),
  135. ],
  136. 'pyramids' => [
  137. 'title' => _x( 'Pyramids', 'Shapes', 'elementor' ),
  138. 'has_negative' => true,
  139. 'has_flip' => true,
  140. ],
  141. 'triangle' => [
  142. 'title' => _x( 'Triangle', 'Shapes', 'elementor' ),
  143. 'has_negative' => true,
  144. ],
  145. 'triangle-asymmetrical' => [
  146. 'title' => _x( 'Triangle Asymmetrical', 'Shapes', 'elementor' ),
  147. 'has_negative' => true,
  148. 'has_flip' => true,
  149. ],
  150. 'tilt' => [
  151. 'title' => _x( 'Tilt', 'Shapes', 'elementor' ),
  152. 'has_flip' => true,
  153. 'height_only' => true,
  154. ],
  155. 'opacity-tilt' => [
  156. 'title' => _x( 'Tilt Opacity', 'Shapes', 'elementor' ),
  157. 'has_flip' => true,
  158. ],
  159. 'opacity-fan' => [
  160. 'title' => _x( 'Fan Opacity', 'Shapes', 'elementor' ),
  161. ],
  162. 'curve' => [
  163. 'title' => _x( 'Curve', 'Shapes', 'elementor' ),
  164. 'has_negative' => true,
  165. ],
  166. 'curve-asymmetrical' => [
  167. 'title' => _x( 'Curve Asymmetrical', 'Shapes', 'elementor' ),
  168. 'has_negative' => true,
  169. 'has_flip' => true,
  170. ],
  171. 'waves' => [
  172. 'title' => _x( 'Waves', 'Shapes', 'elementor' ),
  173. 'has_negative' => true,
  174. 'has_flip' => true,
  175. ],
  176. 'wave-brush' => [
  177. 'title' => _x( 'Waves Brush', 'Shapes', 'elementor' ),
  178. 'has_flip' => true,
  179. ],
  180. 'waves-pattern' => [
  181. 'title' => _x( 'Waves Pattern', 'Shapes', 'elementor' ),
  182. 'has_flip' => true,
  183. ],
  184. 'arrow' => [
  185. 'title' => _x( 'Arrow', 'Shapes', 'elementor' ),
  186. 'has_negative' => true,
  187. ],
  188. 'split' => [
  189. 'title' => _x( 'Split', 'Shapes', 'elementor' ),
  190. 'has_negative' => true,
  191. ],
  192. 'book' => [
  193. 'title' => _x( 'Book', 'Shapes', 'elementor' ),
  194. 'has_negative' => true,
  195. ],
  196. ];
  197. $additional_shapes = [];
  198. /**
  199. * Additional shapes.
  200. *
  201. * Filters the shapes used by Elementor to add additional shapes.
  202. *
  203. * @since 2.0.1
  204. *
  205. * @param array $additional_shapes Additional Elementor fonts.
  206. */
  207. $additional_shapes = apply_filters( 'elementor/shapes/additional_shapes', $additional_shapes );
  208. self::$shapes = array_merge( $native_shapes, $additional_shapes );
  209. }
  210. }