PluginProbe ʕ •ᴥ•ʔ
Premium Addons for Elementor – Powerful Elementor Templates & Widgets / 4.10.10
Premium Addons for Elementor – Powerful Elementor Templates & Widgets v4.10.10
4.11.79 4.11.78 4.11.77 4.11.76 4.11.75 3.20.5 4.11.69 3.20.6 4.11.7 3.20.7 4.11.70 3.20.8 4.11.71 3.20.9 4.11.72 3.21.1 4.11.73 3.21.2 4.11.74 3.21.3 4.11.8 3.21.4 4.11.9 3.21.5 4.2.0 3.21.6 4.2.1 3.3.0 4.2.2 3.3.1 4.2.3 3.3.2 4.2.4 3.3.3 4.2.5 3.3.4 4.2.6 3.3.5 4.2.7 3.3.6 4.2.8 3.3.7 4.2.9 3.3.8 4.3.0 3.3.9 4.3.1 3.4.0 4.3.2 3.4.1 4.3.3 3.4.2 4.3.4 3.4.3 4.3.5 3.4.4 4.3.6 3.4.5 4.3.7 3.4.6 4.3.8 3.4.7 4.3.9 3.4.8 4.4.0 3.4.9 4.4.1 3.5.0 4.4.2 3.5.1 4.4.3 3.5.2 4.4.4 3.5.3 4.4.5 3.5.4 4.4.6 3.5.5 4.4.7 3.5.6 4.4.8 3.5.7 4.4.9 3.5.8 4.5.0 3.5.9 4.5.1 3.6.0 4.5.2 3.6.1 4.5.3 3.6.2 4.5.4 3.6.3 4.5.5 3.6.4 4.5.6 3.6.5 4.5.7 3.6.6 4.5.8 3.6.7 4.5.9 3.6.8 4.6.0 3.6.9 4.6.1 3.7.0 4.7.0 3.7.1 4.7.1 3.7.2 4.7.2 3.7.3 4.7.3 3.7.4 4.7.4 3.7.5 4.7.5 3.7.6 4.7.6 3.7.7 4.7.7 3.7.8 4.7.8 3.7.9 4.7.9 3.8.0 4.8.0 3.8.1 4.8.1 3.8.2 4.8.10 3.8.3 4.8.11 3.8.4 4.8.2 3.8.5 4.8.3 3.8.6 4.8.4 3.8.7 4.8.5 3.8.8 4.8.6 3.8.9 4.8.7 3.9.0 4.8.8 3.9.1 4.8.9 3.9.2 4.9.0 3.9.3 4.9.0-beta1 3.9.4 4.9.0-beta2 3.9.5 4.9.1 3.9.6 4.9.10 3.9.7 4.9.11 3.9.8 4.9.12 3.9.9 4.9.13 4.0.1 4.9.14 4.0.3 4.9.15 4.0.4 4.9.16 4.0.5 4.9.17 4.0.6 4.9.18 4.0.7 4.9.19 4.0.8 4.9.2 4.0.9 4.9.20 4.1.0 4.9.21 4.1.1 4.9.22 4.1.2 4.9.23 4.1.3 4.9.24 trunk 4.1.4 4.9.25 1.0 4.1.5 4.9.26 1.01 4.1.6 4.9.27 1.02 4.1.7 4.9.28 1.03 4.1.8 4.9.29 1.04 4.1.9 4.9.3 1.05 4.10.0 4.9.30 1.06 4.10.1 4.9.31 1.07 4.10.10 4.9.32 1.08 4.10.11 4.9.33 1.09 4.10.12 4.9.34 2.0 4.10.13 4.9.35 2.0.1 4.10.14 4.9.36 2.0.2 4.10.15 4.9.37 2.0.3 4.10.16 4.9.38 2.0.4 4.10.17 4.9.39 2.0.5 4.10.18 4.9.4 2.0.6 4.10.19 4.9.40 2.0.7 4.10.2 4.9.41 2.0.8 4.10.20 4.9.42 2.0.9 4.10.21 4.9.43 2.1.0 4.10.22 4.9.45 2.1.1 4.10.23 4.9.46 2.1.2 4.10.24 4.9.47 2.1.3 4.10.25 4.9.48 2.1.4 4.10.26 4.9.49 2.1.5 4.10.27 4.9.5 2.1.5-beta1 4.10.28 4.9.50 2.1.6 4.10.29 4.9.51 2.1.7 4.10.3 4.9.52 2.1.8 4.10.30 4.9.53 2.1.9 4.10.31 4.9.54 2.2.0 4.10.32 4.9.55 2.2.1 4.10.33 4.9.56 2.2.2 4.10.34 4.9.57 2.2.3 4.10.35 4.9.6 2.2.4 4.10.36 4.9.7 2.2.5 4.10.37 4.9.8 2.2.6 4.10.38 4.9.9 2.2.7 4.10.39 2.2.8 4.10.4 2.2.9 4.10.40 2.3.0 4.10.41 2.3.1 4.10.42 2.3.2 4.10.43 2.3.3 4.10.44 2.3.4 4.10.45 2.3.5 4.10.46 2.3.6 4.10.47 2.3.7 4.10.48 2.3.8 4.10.49 2.3.9 4.10.5 2.4.0 4.10.50 2.4.1 4.10.51 2.5.0 4.10.52 2.5.1 4.10.53 2.5.2 4.10.54 2.5.3 4.10.55 2.5.4 4.10.56 2.5.5 4.10.57 2.5.6 4.10.58 2.5.7 4.10.59 2.5.8 4.10.6 2.5.9 4.10.60 2.6.0 4.10.61 2.6.1 4.10.62 2.6.2 4.10.63 2.6.3 4.10.64 2.6.4 4.10.65 2.6.5 4.10.66 2.6.6 4.10.67 2.6.7 4.10.68 2.6.8 4.10.69 2.6.9 4.10.7 2.7.0 4.10.70 2.7.1 4.10.71 2.7.2 4.10.72 2.7.3 4.10.73 2.7.4 4.10.74 2.7.5 4.10.75 2.7.6 4.10.76 2.7.7 4.10.77 2.7.8 4.10.78 2.7.9 4.10.79 2.8.0 4.10.8 2.8.1 4.10.80 2.8.2 4.10.81 2.8.3 4.10.82 2.8.4 4.10.83 2.8.5 4.10.84 2.8.6 4.10.85 2.8.7 4.10.86 2.8.8 4.10.87 2.8.9 4.10.88 2.9.0 4.10.89 2.9.1 4.10.9 2.9.2 4.10.90 2.9.3 4.11.0 2.9.4 4.11.1 2.9.5 4.11.10 2.9.6 4.11.11 2.9.7 4.11.12 2.9.8 4.11.13 2.9.9 4.11.14 3.0.0 4.11.15 3.0.1 4.11.16 3.0.2 4.11.17 3.0.3 4.11.18 3.0.4 4.11.19 3.0.5 4.11.2 3.0.6 4.11.20 3.0.7 4.11.21 3.0.8 4.11.22 3.0.9 4.11.23 3.1.0 4.11.24 3.1.1 4.11.25 3.1.2 4.11.26 3.1.3 4.11.27 3.1.4 4.11.28 3.1.5 4.11.29 3.1.6 4.11.3 3.1.7 4.11.30 3.1.8 4.11.31 3.1.9 4.11.32 3.10.0 4.11.33 3.10.1 4.11.34 3.10.2 4.11.35 3.10.3 4.11.36 3.10.4 4.11.37 3.10.5 4.11.38 3.10.6 4.11.39 3.10.7 4.11.4 3.10.8 4.11.40 3.10.9 4.11.41 3.11.0 4.11.42 3.11.1 4.11.43 3.11.2 4.11.44 3.11.3 4.11.45 3.11.4 4.11.46 3.11.5 4.11.47 3.11.6 4.11.48 3.11.7 4.11.49 3.11.8 4.11.5 3.11.9 4.11.50 3.12.0 4.11.51 3.12.1 4.11.52 3.12.2 4.11.53 3.12.3 4.11.54 3.2.0 4.11.55 3.2.1 4.11.56 3.2.2 4.11.57 3.2.3 4.11.58 3.2.4 4.11.59 3.2.5 4.11.6 3.2.6 4.11.60 3.2.7 4.11.61 3.2.8 4.11.62 3.2.9 4.11.63 3.20.0 4.11.64 3.20.1 4.11.65 3.20.2 4.11.66 3.20.3 4.11.67 3.20.4 4.11.68
premium-addons-for-elementor / includes / assets-manager.php
premium-addons-for-elementor / includes Last commit date
compatibility 2 years ago controls 2 years ago pa-display-conditions 2 years ago templates 2 years ago acf-helper.php 2 years ago addons-cross-cp.php 2 years ago addons-integration.php 2 years ago assets-manager.php 2 years ago class-pa-core.php 2 years ago class-premium-template-tags.php 2 years ago helper-functions.php 2 years ago live-editor-modal.php 2 years ago module-base.php 2 years ago pa-nav-menu-walker.php 2 years ago
assets-manager.php
708 lines
1 <?php
2 /**
3 * PA Assets Manager.
4 */
5
6 namespace PremiumAddons\Includes;
7
8 use Elementor\Plugin;
9 use PremiumAddons\Includes\Helper_Functions;
10 use PremiumAddons\Admin\Includes\Admin_Helper;
11
12 require_once PREMIUM_ADDONS_PATH . 'widgets/dep/urlopen.php';
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * PA Assets Manager Class.
20 */
21 class Assets_Manager {
22
23 /**
24 * Class Instance.
25 *
26 * @var object|null instance.
27 */
28 private static $instance = null;
29
30 /**
31 * Post Id.
32 * Option Id.
33 *
34 * @var string|null post_id.
35 */
36 public static $post_id = null;
37
38 /**
39 * Templates ids loaded in a post.
40 *
41 * @var array temp_ids.
42 */
43 public static $temp_ids = array();
44
45 /**
46 * All elements loaded in a post.
47 *
48 * @var array temp_elements.
49 */
50 public static $temp_elements = array();
51
52 /**
53 * Is page assets updated.
54 *
55 * @var boolean is_updated.
56 */
57 public static $is_updated = null;
58
59 /**
60 * Class Constructor.
61 */
62 public function __construct() {
63
64 add_action( 'elementor/editor/after_save', array( $this, 'handle_post_save' ), 10, 2 );
65
66 // Check if the elments are cached.
67 add_action( 'wp', array( $this, 'set_assets_vars' ) );
68
69 // Save the elements on the current page.
70 add_filter( 'elementor/frontend/builder_content_data', array( $this, 'manage_post_data' ), 10, 2 );
71
72 add_action( 'wp_footer', array( $this, 'cache_post_assets' ) );
73
74 add_action( 'wp_trash_post', array( $this, 'delete_cached_options' ) );
75
76 }
77
78 /**
79 * Sets Edit Time upon editor save.
80 *
81 * @access public
82 * @since 4.6.1
83 */
84 public function handle_post_save( $post_id ) {
85
86 if ( wp_doing_cron() ) {
87 return;
88 }
89
90 // The post is saved, then we need to remove the assets related to it.
91 $this->set_post_id( $post_id );
92 self::remove_files();
93
94 update_option( 'pa_edit_time', strtotime( 'now' ) );
95 }
96
97 /**
98 * Mange Post Data.
99 *
100 * @access public
101 * @since 4.6.1
102 *
103 * @param array $data post data.
104 * @param int|string $post_id post id.
105 *
106 * @return array
107 */
108 public function manage_post_data( $data, $post_id ) {
109
110 if ( ! self::$is_updated ) {
111 $pa_elems = $this->extract_pa_elements( $data );
112
113 self::$temp_ids[] = $post_id;
114 self::$temp_elements = array_unique( array_merge( self::$temp_elements, $pa_elems ) );
115 }
116
117 return $data;
118 }
119
120 /**
121 * Set post unique id.
122 *
123 * @access public
124 * @since 4.6.1
125 *
126 * @param int|string $id post id.
127 */
128 public function set_post_id( $id = 'default' ) {
129
130 $post_id = 'default' === $id ? 'pa_assets_' . get_queried_object_id() : 'pa_assets_' . $id;
131
132 if ( null === self::$post_id ) {
133 self::$post_id = Helper_Functions::generate_unique_id( $post_id );
134 }
135 }
136
137 /**
138 * Extracts PA Elements.
139 *
140 * @access public
141 * @since 4.6.1
142 *
143 * @param array $data post data.
144 *
145 * @return array
146 */
147 public function extract_pa_elements( $data ) {
148
149 if ( empty( $data ) ) {
150 return array();
151 }
152
153 $pa_names = Admin_Helper::get_pa_elements_names();
154
155 $social_revs = array(
156 'premium-yelp-reviews',
157 'premium-google-reviews',
158 'premium-facebook-reviews',
159 );
160
161 $pa_elems = array();
162
163 Plugin::$instance->db->iterate_data(
164 $data,
165 function ( $element ) use ( &$pa_elems, $pa_names, $social_revs ) {
166
167 if ( isset( $element['elType'] ) ) {
168
169 if ( 'widget' === $element['elType'] && isset( $element['widgetType'] ) ) {
170
171 $widget_type = ( 'global' === $element['widgetType'] && ! empty( $element['templateID'] ) ) ? $this->get_global_widget_type( $element['templateID'] ) : $element['widgetType'];
172
173 if ( in_array( $widget_type, $pa_names, true ) && ! in_array( $widget_type, $pa_elems, true ) ) {
174
175 $widget_type = in_array( $widget_type, $social_revs, true ) ? 'premium-reviews' : $widget_type;
176
177 if ( in_array( $widget_type, array( 'premium-twitter-feed', 'premium-facebook-feed' ), true ) && ! in_array( 'social-common', $pa_elems, true ) ) {
178 array_push( $pa_elems, 'social-common' );
179 }
180
181 array_push( $pa_elems, $widget_type );
182
183 if ( 'premium-woo-products' === $widget_type ) {
184 $papro_activated = apply_filters( 'papro_activated', false );
185
186 if ( $papro_activated ) {
187 array_push( $pa_elems, 'premium-woo-products-pro' );
188 }
189 }
190 }
191 }
192 }
193 }
194 );
195
196 return $pa_elems;
197 }
198
199 /**
200 * Get Global Wiget Type.
201 *
202 * @access public
203 * @since 4.6.1
204 * @link https://code.elementor.com/methods/elementor-templatelibrary-manager-get_template_data/
205 * @param int $temp_id template it.
206 *
207 * @return string|void
208 */
209 public function get_global_widget_type( $temp_id ) {
210
211 $temp_data = Plugin::$instance->templates_manager->get_template_data(
212 array(
213 'source' => 'local',
214 'template_id' => $temp_id,
215 )
216 );
217
218 if ( is_wp_error( $temp_data ) || ! $temp_data || empty( $temp_data ) ) {
219 return;
220 }
221
222 if ( ! isset( $temp_data['content'] ) || empty( $temp_data['content'] ) ) {
223 return;
224 }
225
226 return $temp_data['content'][0]['widgetType'];
227 }
228
229 /**
230 * Sets Assets Variables.
231 * Sets Post ID & Is_updated Flag.
232 *
233 * @access public
234 * @since 4.6.1
235 */
236 public function set_assets_vars() {
237
238 $is_edit_mode = Helper_Functions::is_edit_mode();
239
240 if ( ! $this->is_built_with_elementor() || $is_edit_mode ) {
241 return;
242 }
243
244 $this->set_post_id();
245
246 self::$is_updated = self::is_ready_for_generate();
247 }
248
249 /**
250 * Is Built With Elementor.
251 *
252 * @access public
253 * @since 4.6.1
254 *
255 * @return boolean
256 */
257 public function is_built_with_elementor() {
258
259 if ( ! class_exists( 'Elementor\Plugin' ) ) {
260 return false;
261 }
262
263 $type = get_post_type();
264
265 if ( 'page' !== $type && 'post' !== $type ) {
266 return false;
267 }
268
269 $current_id = get_the_ID();
270
271 if ( ! $current_id || $current_id < 0 ) {
272 return false;
273 }
274
275 return Plugin::$instance->documents->get( get_the_ID() )->is_built_with_elementor();
276 }
277
278 /**
279 * Check if assets is updated.
280 *
281 * @access public
282 * @since 4.6.1
283 *
284 * @return boolean
285 */
286 public static function is_ready_for_generate() {
287
288 $editor_time = get_option( 'pa_edit_time', false );
289
290 // If no post/page was saved after the feature is enabled.
291 if ( ! $editor_time ) {
292 update_option( 'pa_edit_time', strtotime( 'now' ) );
293 }
294
295 $post_edit_time = get_option( 'pa_edit_' . self::$post_id, false );
296
297 // If the time of the last update is not equal to the time the current post was last changed. This means another post was saved, then load the default assets.
298 // In this case, we need to load the default assets until the elements in the page needs to be cached first.
299 if ( ! $post_edit_time || (int) $editor_time !== (int) $post_edit_time ) {
300 // A change was made in the page elements, then we need to force the assets to be regenerated
301 self::remove_files();
302 return false;
303 }
304
305 return true;
306 }
307
308 /**
309 * Cached post assets.
310 *
311 * Update post options in db on page load.
312 *
313 * @access public
314 * @since 4.6.1
315 */
316 public function cache_post_assets() {
317
318 $is_edit_mode = Helper_Functions::is_edit_mode();
319 $cond = $this->is_built_with_elementor() && ! $is_edit_mode;
320
321 if ( ! self::$is_updated && $cond ) {
322 update_option( 'pa_elements_' . self::$post_id, self::$temp_elements, false );
323 update_option( 'pa_edit_' . self::$post_id, get_option( 'pa_edit_time' ), false );
324 }
325 }
326
327 /**
328 * Delete Cached Options.
329 * Delete post options from db on post delete.
330 *
331 * @access public
332 * @since 4.6.1
333 *
334 * @param int $post_id post id.
335 */
336 public function delete_cached_options( $post_id ) {
337
338 $id = substr( md5( 'pa_assets_' . $post_id ), 0, 9 );
339
340 delete_option( 'pa_elements_' . $id );
341 delete_option( 'pa_edit_' . $id );
342
343 }
344
345 /**
346 * Generate Assets files.
347 * Adds assets into pa-frontend(|-rtl).min.(js|css).
348 *
349 * @access public
350 * @since 4.6.1
351 *
352 * @param string $ext assets extensions (js|css).
353 */
354 public static function generate_asset_file( $ext ) {
355
356 $direction = is_rtl() && 'css' === $ext ? 'rtl-' : '';
357 $main_file_name = Helper_Functions::get_safe_path( PREMIUM_ASSETS_PATH . '/pa-frontend-' . $direction . self::$post_id . '.min.' . $ext );
358
359 // If the file already exists, then there is no need to regenerate a new one.
360 if ( file_exists( $main_file_name ) ) {
361 return;
362 }
363
364 $content = self::get_asset_file_content( $ext );
365
366 // If no premium elements exist on the page, then don't generate files
367 if ( empty( $content ) ) {
368 return;
369 }
370
371 if ( 'css' === $ext && is_rtl() ) {
372 $rtl_file_name = Helper_Functions::get_safe_path( PREMIUM_ASSETS_PATH . '/pa-frontend-rtl-' . self::$post_id . '.min.css' );
373 }
374
375 if ( ! file_exists( PREMIUM_ASSETS_PATH ) ) {
376 wp_mkdir_p( PREMIUM_ASSETS_PATH );
377 }
378
379 if ( 'css' === $ext ) {
380
381 if ( is_rtl() ) {
382 // Make sure to delete the file before creating the new one.
383 file_put_contents( $rtl_file_name, '@charset "UTF-8";' . $content['rtl'] ); // phpcs:ignore
384 } else {
385 file_put_contents( $main_file_name, '@charset "UTF-8";' . $content['main'] ); // phpcs:ignore
386 }
387 } else {
388 file_put_contents( $main_file_name, $content ); // phpcs:ignore
389 }
390 }
391
392
393 /**
394 * Clear cached file.
395 * Delete file if it exists.
396 *
397 * @access public
398 * @since 4.6.1
399 *
400 * @param string $file_name file name.
401 */
402 public static function clear_cached_file( $file_name ) {
403
404 if ( file_exists( $file_name ) ) {
405 unlink( $file_name );
406 }
407 }
408
409 /**
410 * Remove files
411 *
412 * @since 4.6.1
413 */
414 public static function remove_files() {
415
416 $ext = array( 'css', 'js' );
417
418 foreach ( $ext as $e ) {
419
420 $path = PREMIUM_ASSETS_PATH . '/pa-frontend-' . self::$post_id . '.min.' . $e;
421
422 if ( 'css' === $e ) {
423 $rtl_path = PREMIUM_ASSETS_PATH . '/pa-frontend-rtl-' . self::$post_id . '.min.' . $e;
424 self::clear_cached_file( $rtl_path );
425 }
426
427 self::clear_cached_file( $path );
428 }
429
430 }
431
432 /**
433 * Get Asset File Content.
434 *
435 * Collects pa/papro widgets assets.
436 *
437 * @access public
438 * @since 4.6.1
439 *
440 * @param string $ext js|css.
441 *
442 * @return string|array $content
443 */
444 public static function get_asset_file_content( $ext ) {
445
446 // Get the cached elements of the current post/page.
447 $pa_elements = get_option( 'pa_elements_' . self::$post_id, array() );
448
449 if ( empty( $pa_elements ) ) {
450 return '';
451 }
452
453 $content = '';
454
455 if ( 'css' === $ext ) {
456 $rtl_content = '';
457 }
458
459 $pa_elements = self::prepare_pa_elements( $pa_elements, $ext );
460
461 foreach ( $pa_elements as $element ) {
462
463 $path = self::get_file_path( $element, $ext );
464
465 if ( ! $path ) {
466 continue;
467 }
468
469 $content .= self::get_file_content( $path );
470
471 if ( 'css' === $ext && is_rtl() ) {
472 $rtl_path = self::get_file_path( $element, $ext, '-rtl' );
473 $rtl_content .= self::get_file_content( $rtl_path );
474 }
475 }
476
477 if ( 'css' === $ext ) {
478
479 $content = array(
480 'main' => $content,
481 'rtl' => $rtl_content,
482 );
483
484 // Fix: at-rule or selector expected css error.
485 $content = str_replace( '@charset "UTF-8";', '', $content );
486 }
487
488 return $content;
489 }
490
491 /**
492 * Prepare PA Elements.
493 *
494 * @access public
495 * @since 4.6.1
496 *
497 * @param array $elements post elements.
498 * @param string $ext js|css.
499 *
500 * @return array
501 */
502 public static function prepare_pa_elements( $elements, $ext ) {
503
504 if ( 'css' === $ext ) {
505 $common_assets = self::has_free_elements( $elements ) ? array( 'common' ) : array();
506 $common_assets = self::has_pro_elements( $elements ) ? array_merge( $common_assets, array( 'common-pro' ) ) : $common_assets;
507
508 $elements = array_merge( $elements, $common_assets );
509 $indep_elements = array(
510 'premium-world-clock'
511 );
512
513 } else {
514 $indep_elements = array(
515 'social-common',
516 'premium-hscroll',
517 'premium-facebook-feed',
518 'premium-behance-feed',
519 'premium-lottie',
520 'premium-vscroll',
521 'premium-hscroll',
522 'premium-nav-menu',
523 'premium-addon-maps',
524 'premium-woo-products-pro',
525 'premium-addon-testimonials',
526 'premium-smart-post-listing',
527 'premium-addon-pricing-table',
528 'premium-addon-image-separator',
529 'premium-notifications',
530 );
531
532 }
533
534 $elements = array_diff( $elements, $indep_elements );
535
536 return $elements;
537 }
538
539 /**
540 * Get File Content.
541 *
542 * @param string $path file path.
543 *
544 * @return string
545 */
546 public static function get_file_content( $path ) {
547
548 $file_content = rplg_urlopen( $path );
549
550 if ( isset( $file_content['code'] ) ) {
551 if ( in_array( $file_content['code'], array( 404, 401 ), true ) ) {
552 return '';
553 }
554 }
555
556 return self::clean_content( $file_content['data'] );
557 }
558
559 /**
560 * Clean Content
561 * Removes Page Html if it's returned as result.
562 *
563 * @param string $content file content.
564 *
565 * @return string
566 */
567 public static function clean_content( $content ) {
568
569 if ( strpos( $content, '<!DOCTYPE html>' ) ) {
570 $content = explode( '<!DOCTYPE html>', $content )[0];
571 }
572
573 if ( strpos( $content, '<!doctype html>' ) ) {
574 $content = explode( '<!doctype html>', $content )[0];
575 }
576
577 return $content;
578 }
579
580 /**
581 * Get File Path.
582 * Construct file path.
583 *
584 * @param string $element pa element name.
585 * @param string $ext file extension ( js|css).
586 * @param string $dir post dir (-rtl|'').
587 *
588 * @return string file path.
589 */
590 public static function get_file_path( $element, $ext, $dir = '' ) {
591
592 $is_pro = self::is_pro_widget( $element );
593
594 $papro_activated = apply_filters( 'papro_activated', false ) && version_compare( PREMIUM_PRO_ADDONS_VERSION, '2.7.1', '>' );
595
596 if ( ! $papro_activated && $is_pro ) {
597 return false;
598 }
599
600 $element = str_replace( '-addon', '', $element );
601
602 $path = $is_pro ? PREMIUM_PRO_ADDONS_URL : PREMIUM_ADDONS_URL;
603
604 return $path . 'assets/frontend/min-' . $ext . '/' . $element . $dir . '.min.' . $ext;
605 }
606
607 /**
608 * Is Pro Widget.
609 * Checks if the widget is pro.
610 *
611 * @access public
612 * @since 4.6.1
613 *
614 * @param string $widget widget name.
615 *
616 * @return bool
617 */
618 public static function is_pro_widget( $widget ) {
619
620 $pro_names = array_merge( array( 'common-pro', 'premium-reviews', 'premium-woo-products-pro', 'social-common' ), self::get_pro_widgets_names() );
621
622 return in_array( $widget, $pro_names, true );
623 }
624
625 /**
626 * Has Pro Elements.
627 * Check if the post has pa pro elements.
628 *
629 * @access public
630 * @since 4.6.1
631 *
632 * @param array $post_elems post elements.
633 *
634 * @return boolean
635 */
636 public static function has_pro_elements( $post_elems ) {
637
638 $papro_elems = self::get_pro_widgets_names();
639 $has_pro = array_intersect( $post_elems, $papro_elems ) ? true : false;
640
641 return $has_pro;
642 }
643
644 /**
645 * Has Free Elements.
646 * Check if the post has pa elements.
647 *
648 * @access public
649 * @since 4.6.1
650 *
651 * @param array $post_elems post elements.
652 *
653 * @return boolean
654 */
655 public static function has_free_elements( $post_elems ) {
656
657 $pa_elems = Admin_Helper::get_free_widgets_names();
658
659 // add smart post listing
660 $pa_elems[] = 'premium-smart-post-listing';
661 $pa_elems[] = 'premium-addon-instagram-feed';
662
663 $has_free = array_intersect( $post_elems, $pa_elems ) ? true : false;
664
665 return $has_free;
666 }
667
668 /**
669 * Get Pro Widgets Names.
670 *
671 * @access public
672 * @since 4.6.1
673 *
674 * @return array
675 */
676 public static function get_pro_widgets_names() {
677
678 $pro_elems = Admin_Helper::get_pro_elements();
679 $pro_names = array();
680
681 foreach ( $pro_elems as $element ) {
682 if ( isset( $element['name'] ) ) {
683 array_push( $pro_names, $element['name'] );
684 }
685 }
686
687 return $pro_names;
688 }
689
690 /**
691 * Creates and returns an instance of the class.
692 *
693 * @since 4.6.1
694 * @access public
695 *
696 * @return object
697 */
698 public static function get_instance() {
699
700 if ( ! isset( self::$instance ) ) {
701
702 self::$instance = new self();
703
704 }
705
706 return self::$instance;
707 }
708 }