PluginProbe ʕ •ᴥ•ʔ
Premium Addons for Elementor – Powerful Elementor Templates & Widgets / 4.10.79
Premium Addons for Elementor – Powerful Elementor Templates & Widgets v4.10.79
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
controls 1 year ago pa-display-conditions 1 year ago templates 1 year ago acf-helper.php 1 year ago addons-cross-cp.php 1 year ago addons-integration.php 1 year ago assets-manager.php 1 year ago class-pa-core.php 1 year ago class-premium-template-tags.php 1 year ago helper-functions.php 1 year ago live-editor-modal.php 1 year ago module-base.php 1 year ago pa-nav-menu-walker.php 1 year ago
assets-manager.php
751 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 * Sets Edit Time upon editor save.
79 *
80 * @access public
81 * @since 4.6.1
82 */
83 public function handle_post_save( $post_id ) {
84
85 if ( wp_doing_cron() ) {
86 return;
87 }
88
89 // The post is saved, then we need to remove the assets related to it.
90 $this->set_post_id( $post_id );
91 self::remove_files();
92
93 update_option( 'pa_edit_time', strtotime( 'now' ) );
94 }
95
96 /**
97 * Mange Post Data.
98 *
99 * @access public
100 * @since 4.6.1
101 *
102 * @param array $data post data.
103 * @param int|string $post_id post id.
104 *
105 * @return array
106 */
107 public function manage_post_data( $data, $post_id ) {
108
109 if ( ! self::$is_updated ) {
110 $pa_elems = $this->extract_pa_elements( $data );
111
112 self::$temp_ids[] = $post_id;
113 self::$temp_elements = array_unique( array_merge( self::$temp_elements, $pa_elems ) );
114 }
115
116 return $data;
117 }
118
119 /**
120 * Set post unique id.
121 *
122 * @access public
123 * @since 4.6.1
124 *
125 * @param int|string $id post id.
126 */
127 public function set_post_id( $id = 'default' ) {
128
129 $post_id = 'default' === $id ? 'pa_assets_' . get_queried_object_id() : 'pa_assets_' . $id;
130
131 if ( null === self::$post_id ) {
132 self::$post_id = Helper_Functions::generate_unique_id( $post_id );
133 }
134 }
135
136 /**
137 * Extracts PA Elements.
138 *
139 * @access public
140 * @since 4.6.1
141 *
142 * @param array $data post data.
143 *
144 * @return array
145 */
146 public function extract_pa_elements( $data ) {
147
148 if ( empty( $data ) ) {
149 return array();
150 }
151
152 $pa_names = Admin_Helper::get_pa_elements_names();
153
154 $social_revs = array(
155 'premium-yelp-reviews',
156 'premium-google-reviews',
157 'premium-facebook-reviews',
158 );
159
160 $pa_elems = array();
161
162 Plugin::$instance->db->iterate_data(
163 $data,
164 function ( $element ) use ( &$pa_elems, $pa_names, $social_revs ) {
165
166 if ( isset( $element['elType'] ) ) {
167
168 if ( 'widget' === $element['elType'] && isset( $element['widgetType'] ) ) {
169
170 $widget_type = ( 'global' === $element['widgetType'] && ! empty( $element['templateID'] ) ) ? $this->get_global_widget_type( $element['templateID'] ) : $element['widgetType'];
171
172 if ( in_array( $widget_type, $pa_names, true ) && ! in_array( $widget_type, $pa_elems, true ) ) {
173
174 $widget_type = in_array( $widget_type, $social_revs, true ) ? 'premium-reviews' : $widget_type;
175
176 if ( in_array( $widget_type, array( 'premium-twitter-feed', 'premium-facebook-feed' ), true ) && ! in_array( 'social-common', $pa_elems, true ) ) {
177 array_push( $pa_elems, 'social-common' );
178 }
179
180 array_push( $pa_elems, $widget_type );
181
182 if ( 'premium-woo-products' === $widget_type ) {
183 $papro_activated = apply_filters( 'papro_activated', false );
184
185 if ( $papro_activated ) {
186 array_push( $pa_elems, 'premium-woo-products-pro' );
187 }
188 }
189 }
190 }
191 }
192 }
193 );
194
195 return $pa_elems;
196 }
197
198 /**
199 * Get Global Wiget Type.
200 *
201 * @access public
202 * @since 4.6.1
203 * @link https://code.elementor.com/methods/elementor-templatelibrary-manager-get_template_data/
204 * @param int $temp_id template it.
205 *
206 * @return string|void
207 */
208 public function get_global_widget_type( $temp_id ) {
209
210 $temp_data = Plugin::$instance->templates_manager->get_template_data(
211 array(
212 'source' => 'local',
213 'template_id' => $temp_id,
214 )
215 );
216
217 if ( is_wp_error( $temp_data ) || ! $temp_data || empty( $temp_data ) ) {
218 return;
219 }
220
221 if ( ! isset( $temp_data['content'] ) || empty( $temp_data['content'] ) ) {
222 return;
223 }
224
225 return $temp_data['content'][0]['widgetType'];
226 }
227
228 /**
229 * Sets Assets Variables.
230 * Sets Post ID & Is_updated Flag.
231 *
232 * @access public
233 * @since 4.6.1
234 */
235 public function set_assets_vars() {
236
237 $is_edit_mode = Helper_Functions::is_edit_mode();
238
239 if ( ! $this->is_built_with_elementor() || $is_edit_mode ) {
240 return;
241 }
242
243 $this->set_post_id();
244
245 self::$is_updated = self::is_ready_for_generate();
246 }
247
248 /**
249 * Is Built With Elementor.
250 *
251 * @access public
252 * @since 4.6.1
253 *
254 * @return boolean
255 */
256 public function is_built_with_elementor() {
257
258 if ( ! class_exists( 'Elementor\Plugin' ) ) {
259 return false;
260 }
261
262 $type = get_post_type();
263
264 if ( 'page' !== $type && 'post' !== $type ) {
265 return false;
266 }
267
268 $current_id = get_the_ID();
269
270 if ( ! $current_id || $current_id < 0 ) {
271 return false;
272 }
273
274 $document = Plugin::$instance->documents->get( get_the_ID() );
275
276 if ( ! $document ) {
277 return false;
278 }
279
280 return $document->is_built_with_elementor();
281 }
282
283 /**
284 * Check if assets is updated.
285 *
286 * @access public
287 * @since 4.6.1
288 *
289 * @return boolean
290 */
291 public static function is_ready_for_generate() {
292
293 $editor_time = get_option( 'pa_edit_time', false );
294
295 // If no post/page was saved after the feature is enabled.
296 if ( ! $editor_time ) {
297 update_option( 'pa_edit_time', strtotime( 'now' ) );
298 }
299
300 $post_edit_time = get_option( 'pa_edit_' . self::$post_id, false );
301
302 // 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.
303 // In this case, we need to load the default assets until the elements in the page needs to be cached first.
304 if ( ! $post_edit_time || (int) $editor_time !== (int) $post_edit_time ) {
305 // A change was made in the page elements, then we need to force the assets to be regenerated
306 self::remove_files();
307 return false;
308 }
309
310 return true;
311 }
312
313 /**
314 * Cached post assets.
315 *
316 * Update post options in db on page load.
317 *
318 * @access public
319 * @since 4.6.1
320 */
321 public function cache_post_assets() {
322
323 $is_edit_mode = Helper_Functions::is_edit_mode();
324 $cond = $this->is_built_with_elementor() && ! $is_edit_mode;
325
326 if ( ! self::$is_updated && $cond ) {
327 update_option( 'pa_elements_' . self::$post_id, self::$temp_elements, false );
328 update_option( 'pa_edit_' . self::$post_id, get_option( 'pa_edit_time' ), false );
329 }
330 }
331
332 /**
333 * Delete Cached Options.
334 * Delete post options from db on post delete.
335 *
336 * @access public
337 * @since 4.6.1
338 *
339 * @param int $post_id post id.
340 */
341 public function delete_cached_options( $post_id ) {
342
343 $id = substr( md5( 'pa_assets_' . $post_id ), 0, 9 );
344
345 delete_option( 'pa_elements_' . $id );
346 delete_option( 'pa_edit_' . $id );
347 }
348
349 /**
350 * Generate Assets files.
351 * Adds assets into pa-frontend(|-rtl).min.(js|css).
352 *
353 * @access public
354 * @since 4.6.1
355 *
356 * @param string $ext assets extensions (js|css).
357 */
358 public static function generate_asset_file( $ext ) {
359
360 $direction = is_rtl() && 'css' === $ext ? 'rtl-' : '';
361 $main_file_name = Helper_Functions::get_safe_path( PREMIUM_ASSETS_PATH . '/pa-frontend-' . $direction . self::$post_id . '.min.' . $ext );
362
363 // If the file already exists, then there is no need to regenerate a new one.
364 if ( file_exists( $main_file_name ) ) {
365 return;
366 }
367
368 $content = self::get_asset_file_content( $ext );
369
370 // If no premium elements exist on the page, then don't generate files
371 if ( empty( $content ) || 'empty' === $content ) {
372 return 'empty';
373 }
374
375 if ( 'css' === $ext && is_rtl() ) {
376 $rtl_file_name = Helper_Functions::get_safe_path( PREMIUM_ASSETS_PATH . '/pa-frontend-rtl-' . self::$post_id . '.min.css' );
377 }
378
379 if ( ! file_exists( PREMIUM_ASSETS_PATH ) ) {
380 wp_mkdir_p( PREMIUM_ASSETS_PATH );
381 }
382
383 if ( 'css' === $ext ) {
384
385 if ( is_rtl() ) {
386
387 if ( empty( $content['rtl'] ) ) {
388 return 'empty';
389 }
390
391 // Make sure to delete the file before creating the new one.
392 file_put_contents( $rtl_file_name, '@charset "UTF-8";' . $content['rtl'] ); // phpcs:ignore
393
394 } else {
395
396 if ( empty( $content['main'] ) ) {
397 return 'empty';
398 }
399
400 file_put_contents( $main_file_name, '@charset "UTF-8";' . $content['main'] ); // phpcs:ignore
401 }
402 } else {
403 file_put_contents( $main_file_name, $content ); // phpcs:ignore
404 }
405 }
406
407
408 /**
409 * Clear cached file.
410 * Delete file if it exists.
411 *
412 * @access public
413 * @since 4.6.1
414 *
415 * @param string $file_name file name.
416 */
417 public static function clear_cached_file( $file_name ) {
418
419 if ( file_exists( $file_name ) ) {
420 wp_delete_file( $file_name );
421 }
422 }
423
424 /**
425 * Remove files
426 *
427 * @since 4.6.1
428 */
429 public static function remove_files() {
430
431 $ext = array( 'css', 'js' );
432
433 foreach ( $ext as $e ) {
434
435 $path = PREMIUM_ASSETS_PATH . '/pa-frontend-' . self::$post_id . '.min.' . $e;
436
437 if ( 'css' === $e ) {
438 $rtl_path = PREMIUM_ASSETS_PATH . '/pa-frontend-rtl-' . self::$post_id . '.min.' . $e;
439 self::clear_cached_file( $rtl_path );
440 }
441
442 self::clear_cached_file( $path );
443 }
444 }
445
446 /**
447 * Get Asset File Content.
448 *
449 * Collects pa/papro widgets assets.
450 *
451 * @access public
452 * @since 4.6.1
453 *
454 * @param string $ext js|css.
455 *
456 * @return string|array $content
457 */
458 public static function get_asset_file_content( $ext ) {
459
460 // Get the cached elements of the current post/page.
461 $pa_elements = get_option( 'pa_elements_' . self::$post_id, array() );
462
463 if ( empty( $pa_elements ) ) {
464 return '';
465 }
466
467 $content = '';
468
469 if ( 'css' === $ext ) {
470 $rtl_content = '';
471 }
472
473 $pa_elements = self::prepare_pa_elements( $pa_elements, $ext );
474
475 foreach ( $pa_elements as $element ) {
476
477 $path = self::get_file_path( $element, $ext );
478
479 if ( ! $path ) {
480 continue;
481 }
482
483 $file_content = self::get_file_content( $path );
484
485 if ( 'not_found' === $file_content ) {
486 continue;
487 }
488
489 if ( 'empty' === $file_content ) {
490 return 'empty';
491 }
492
493 $content .= $file_content;
494
495 if ( 'css' === $ext && is_rtl() ) {
496 $rtl_path = self::get_file_path( $element, $ext, '-rtl' );
497 $rtl_content .= self::get_file_content( $rtl_path );
498 }
499 }
500
501 if ( 'css' === $ext ) {
502
503 $content = array(
504 'main' => $content,
505 'rtl' => $rtl_content,
506 );
507
508 // Fix: at-rule or selector expected css error.
509 $content = str_replace( '@charset "UTF-8";', '', $content );
510 }
511
512 return $content;
513 }
514
515 /**
516 * Prepare PA Elements.
517 *
518 * @access public
519 * @since 4.6.1
520 *
521 * @param array $elements post elements.
522 * @param string $ext js|css.
523 *
524 * @return array
525 */
526 public static function prepare_pa_elements( $elements, $ext ) {
527
528 if ( 'css' === $ext ) {
529 $common_assets = self::has_free_elements( $elements ) ? array( 'common' ) : array();
530 $common_assets = self::has_pro_elements( $elements ) ? array_merge( $common_assets, array( 'common-pro' ) ) : $common_assets;
531
532 $elements = array_merge( $elements, $common_assets );
533 $indep_elements = array(
534 'premium-world-clock',
535 );
536
537 } else {
538 $indep_elements = array(
539 'social-common',
540 'premium-hscroll',
541 'premium-facebook-feed',
542 'premium-behance-feed',
543 'premium-lottie',
544 'premium-vscroll',
545 'premium-hscroll',
546 'premium-nav-menu',
547 'premium-addon-maps',
548 'premium-woo-products',
549 'premium-woo-products-pro',
550 'premium-mini-cart',
551 'premium-woo-cta',
552 // 'premium-addon-testimonials',
553 'premium-smart-post-listing',
554 'premium-addon-pricing-table',
555 'premium-addon-image-separator',
556 'premium-notifications',
557 );
558
559 }
560
561 $elements = array_diff( $elements, $indep_elements );
562
563 return $elements;
564 }
565
566 /**
567 * Get File Content.
568 *
569 * @param string $path file path.
570 *
571 * @return string
572 */
573 public static function get_file_content( $path ) {
574
575 $file_content = rplg_urlopen( $path );
576
577 if ( isset( $file_content['code'] ) ) {
578
579 if ( 404 === $file_content['code'] ) {
580 return 'not_found';
581 }
582
583 if ( in_array( $file_content['code'], array( 0, 401, 403 ), true ) ) {
584 return 'empty';
585 }
586 }
587
588 return self::clean_content( $file_content['data'] );
589 }
590
591 /**
592 * Clean Content
593 * Removes Page Html if it's returned as result.
594 *
595 * @param string $content file content.
596 *
597 * @return string
598 */
599 public static function clean_content( $content ) {
600
601 if ( strpos( $content, '<!DOCTYPE' ) ) {
602 $content = 'empty';
603 }
604
605 // if ( strpos( $content, '<!doctype html>' ) ) {
606 // $content = explode( '<!doctype html>', $content )[0];
607 // }
608
609 return $content;
610 }
611
612 /**
613 * Get File Path.
614 * Construct file path.
615 *
616 * @param string $element pa element name.
617 * @param string $ext file extension ( js|css).
618 * @param string $dir post dir (-rtl|'').
619 *
620 * @return string file path.
621 */
622 public static function get_file_path( $element, $ext, $dir = '' ) {
623
624 $is_pro = self::is_pro_widget( $element );
625
626 $papro_activated = apply_filters( 'papro_activated', false ) && version_compare( PREMIUM_PRO_ADDONS_VERSION, '2.7.1', '>' );
627
628 if ( ! $papro_activated && $is_pro ) {
629 return false;
630 }
631
632 $element = str_replace( '-addon', '', $element );
633
634 $path = $is_pro ? PREMIUM_PRO_ADDONS_URL : PREMIUM_ADDONS_URL;
635
636 return $path . 'assets/frontend/min-' . $ext . '/' . $element . $dir . '.min.' . $ext;
637 }
638
639 /**
640 * Is Pro Widget.
641 * Checks if the widget is pro.
642 *
643 * @access public
644 * @since 4.6.1
645 *
646 * @param string $widget widget name.
647 *
648 * @return bool
649 */
650 public static function is_pro_widget( $widget ) {
651
652 $pro_names = array_merge( array( 'common-pro', 'premium-reviews', 'premium-woo-products-pro', 'social-common' ), self::get_pro_widgets_names() );
653
654 return in_array( $widget, $pro_names, true );
655 }
656
657 /**
658 * Has Pro Elements.
659 * Check if the post has pa pro elements.
660 *
661 * @access public
662 * @since 4.6.1
663 *
664 * @param array $post_elems post elements.
665 *
666 * @return boolean
667 */
668 public static function has_pro_elements( $post_elems ) {
669
670 $papro_elems = self::get_pro_widgets_names();
671 $has_pro = array_intersect( $post_elems, $papro_elems ) ? true : false;
672
673 return $has_pro;
674 }
675
676 /**
677 * Has Free Elements.
678 * Check if the post has pa elements.
679 *
680 * @access public
681 * @since 4.6.1
682 *
683 * @param array $post_elems post elements.
684 *
685 * @return boolean
686 */
687 public static function has_free_elements( $post_elems ) {
688
689 $pa_elems = Admin_Helper::get_free_widgets_names();
690
691 // add some other pro widgets.
692 $pa_elems = array_merge(
693 $pa_elems,
694 array(
695 'premium-smart-post-listing',
696 'premium-addon-instagram-feed',
697 'premium-notbar',
698 'premium-addon-flip-box',
699 'premium-addon-icon-box',
700 'premium-addon-magic-section',
701 'premium-whatsapp-chat',
702 )
703 );
704
705 $has_free = array_intersect( $post_elems, $pa_elems ) ? true : false;
706
707 return $has_free;
708 }
709
710 /**
711 * Get Pro Widgets Names.
712 *
713 * @access public
714 * @since 4.6.1
715 *
716 * @return array
717 */
718 public static function get_pro_widgets_names() {
719
720 $pro_elems = Admin_Helper::get_pro_elements();
721 $pro_names = array();
722
723 foreach ( $pro_elems as $element ) {
724 if ( isset( $element['name'] ) ) {
725 array_push( $pro_names, $element['name'] );
726 }
727 }
728
729 return $pro_names;
730 }
731
732 /**
733 * Creates and returns an instance of the class.
734 *
735 * @since 4.6.1
736 * @access public
737 *
738 * @return object
739 */
740 public static function get_instance() {
741
742 if ( ! isset( self::$instance ) ) {
743
744 self::$instance = new self();
745
746 }
747
748 return self::$instance;
749 }
750 }
751