PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.3
Elementor Website Builder – more than just a page builder v3.1.3
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 / core / base / module.php

module.php in Elementor Website Builder – more than just a page builder 3.1.3, at core/base/module.php

305 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Base;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor module.
10 *
11 * An abstract class that provides the needed properties and methods to
12 * manage and handle modules in inheriting classes.
13 *
14 * @since 1.7.0
15 * @abstract
16 */
17 abstract class Module extends Base_Object {
18
19 /**
20 * Module class reflection.
21 *
22 * Holds the information about a class.
23 *
24 * @since 1.7.0
25 * @access private
26 *
27 * @var \ReflectionClass
28 */
29 private $reflection;
30
31 /**
32 * Module components.
33 *
34 * Holds the module components.
35 *
36 * @since 1.7.0
37 * @access private
38 *
39 * @var array
40 */
41 private $components = [];
42
43 /**
44 * Module instance.
45 *
46 * Holds the module instance.
47 *
48 * @since 1.7.0
49 * @access protected
50 *
51 * @var Module
52 */
53 protected static $_instances = [];
54
55 /**
56 * Get module name.
57 *
58 * Retrieve the module name.
59 *
60 * @since 1.7.0
61 * @access public
62 * @abstract
63 *
64 * @return string Module name.
65 */
66 abstract public function get_name();
67
68 /**
69 * Instance.
70 *
71 * Ensures only one instance of the module class is loaded or can be loaded.
72 *
73 * @since 1.7.0
74 * @access public
75 * @static
76 *
77 * @return Module An instance of the class.
78 */
79 public static function instance() {
80 $class_name = static::class_name();
81
82 if ( empty( static::$_instances[ $class_name ] ) ) {
83 static::$_instances[ $class_name ] = new static();
84 }
85
86 return static::$_instances[ $class_name ];
87 }
88
89 /**
90 * @since 2.0.0
91 * @access public
92 * @static
93 */
94 public static function is_active() {
95 return true;
96 }
97
98 /**
99 * Class name.
100 *
101 * Retrieve the name of the class.
102 *
103 * @since 1.7.0
104 * @access public
105 * @static
106 */
107 public static function class_name() {
108 return get_called_class();
109 }
110
111 public static function get_experimental_data() {
112 return [];
113 }
114
115 /**
116 * Clone.
117 *
118 * Disable class cloning and throw an error on object clone.
119 *
120 * The whole idea of the singleton design pattern is that there is a single
121 * object. Therefore, we don't want the object to be cloned.
122 *
123 * @since 1.7.0
124 * @access public
125 */
126 public function __clone() {
127 // Cloning instances of the class is forbidden
128 _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
129 }
130
131 /**
132 * Wakeup.
133 *
134 * Disable unserializing of the class.
135 *
136 * @since 1.7.0
137 * @access public
138 */
139 public function __wakeup() {
140 // Unserializing instances of the class is forbidden
141 _doing_it_wrong( __FUNCTION__, esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
142 }
143
144 /**
145 * @since 2.0.0
146 * @access public
147 */
148 public function get_reflection() {
149 if ( null === $this->reflection ) {
150 $this->reflection = new \ReflectionClass( $this );
151 }
152
153 return $this->reflection;
154 }
155
156 /**
157 * Add module component.
158 *
159 * Add new component to the current module.
160 *
161 * @since 1.7.0
162 * @access public
163 *
164 * @param string $id Component ID.
165 * @param mixed $instance An instance of the component.
166 */
167 public function add_component( $id, $instance ) {
168 $this->components[ $id ] = $instance;
169 }
170
171 /**
172 * @since 2.3.0
173 * @access public
174 * @return Module[]
175 */
176 public function get_components() {
177 return $this->components;
178 }
179
180 /**
181 * Get module component.
182 *
183 * Retrieve the module component.
184 *
185 * @since 1.7.0
186 * @access public
187 *
188 * @param string $id Component ID.
189 *
190 * @return mixed An instance of the component, or `false` if the component
191 * doesn't exist.
192 */
193 public function get_component( $id ) {
194 if ( isset( $this->components[ $id ] ) ) {
195 return $this->components[ $id ];
196 }
197
198 return false;
199 }
200
201 /**
202 * Get assets url.
203 *
204 * @since 2.3.0
205 * @access protected
206 *
207 * @param string $file_name
208 * @param string $file_extension
209 * @param string $relative_url Optional. Default is null.
210 * @param string $add_min_suffix Optional. Default is 'default'.
211 *
212 * @return string
213 */
214 final protected function get_assets_url( $file_name, $file_extension, $relative_url = null, $add_min_suffix = 'default' ) {
215 static $is_test_mode = null;
216
217 if ( null === $is_test_mode ) {
218 $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
219 }
220
221 if ( ! $relative_url ) {
222 $relative_url = $this->get_assets_relative_url() . $file_extension . '/';
223 }
224
225 $url = $this->get_assets_base_url() . $relative_url . $file_name;
226
227 if ( 'default' === $add_min_suffix ) {
228 $add_min_suffix = ! $is_test_mode;
229 }
230
231 if ( $add_min_suffix ) {
232 $url .= '.min';
233 }
234
235 return $url . '.' . $file_extension;
236 }
237
238 /**
239 * Get js assets url
240 *
241 * @since 2.3.0
242 * @access protected
243 *
244 * @param string $file_name
245 * @param string $relative_url Optional. Default is null.
246 * @param string $add_min_suffix Optional. Default is 'default'.
247 *
248 * @return string
249 */
250 final protected function get_js_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default' ) {
251 return $this->get_assets_url( $file_name, 'js', $relative_url, $add_min_suffix );
252 }
253
254 /**
255 * Get css assets url
256 *
257 * @since 2.3.0
258 * @access protected
259 *
260 * @param string $file_name
261 * @param string $relative_url Optional. Default is null.
262 * @param string $add_min_suffix Optional. Default is 'default'.
263 * @param bool $add_direction_suffix Optional. Default is `false`
264 *
265 * @return string
266 */
267 final protected function get_css_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false ) {
268 static $direction_suffix = null;
269
270 if ( ! $direction_suffix ) {
271 $direction_suffix = is_rtl() ? '-rtl' : '';
272 }
273
274 if ( $add_direction_suffix ) {
275 $file_name .= $direction_suffix;
276 }
277
278 return $this->get_assets_url( $file_name, 'css', $relative_url, $add_min_suffix );
279 }
280
281 /**
282 * Get assets base url
283 *
284 * @since 2.6.0
285 * @access protected
286 *
287 * @return string
288 */
289 protected function get_assets_base_url() {
290 return ELEMENTOR_URL;
291 }
292
293 /**
294 * Get assets relative url
295 *
296 * @since 2.3.0
297 * @access protected
298 *
299 * @return string
300 */
301 protected function get_assets_relative_url() {
302 return 'assets/';
303 }
304 }
305