PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.1.3
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.1.3
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / utils / helper.php
shopengine / utils Last commit date
controls-helper.php 4 years ago elementor-data-map.php 4 years ago helper.php 4 years ago notice.php 5 years ago
helper.php
421 lines
1 <?php
2
3 namespace ShopEngine\Utils;
4
5 use ShopEngine\Core\Builders\Action;
6
7 defined('ABSPATH') || exit;
8
9 /**
10 * Global helper class.
11 *
12 * @since 1.0.0
13 */
14 class Helper {
15
16 public static function conditional_enqueue_quickview($template_type = 'quick_view') {
17
18 $idd = get_option(Action::PK__SHOPENGINE_TEMPLATE . '__' . $template_type, 0);
19
20 $tm = get_post_modified_time('U', false, $idd);
21
22 if(!empty($idd)) {
23
24 $url = Helper::get_elementor_css_uri($idd);
25
26 wp_enqueue_style('quickview-fly-' . $idd, $url, [], $tm);
27
28 /**
29 * If shop page is not designed with shopengine but quickview is then some css is missing
30 * to resolve this we are enqueueing the elementor css
31 */
32 wp_enqueue_style('elementor-frontend');
33 wp_enqueue_script('wc-add-to-cart-variation');
34 wp_enqueue_script('zoom');
35
36 /**
37 * photoswipe only load only on product single page but quickview can be load anywhere
38 * to resolve this we are enqueueing the photoswipe css, js and template
39 */
40 wp_enqueue_style('photoswipe');
41 wp_enqueue_style('photoswipe-default-skin');
42 wp_enqueue_script('photoswipe');
43 wp_enqueue_script('photoswipe-ui-default');
44 add_action( 'wp_footer', 'woocommerce_photoswipe' );
45 }
46 }
47
48 public static function get_elementor_css_uri($pid) {
49
50 global $blog_id;
51
52 $wp_upload_dir = wp_upload_dir(null, false);
53
54 $base = $wp_upload_dir['baseurl'] . '/elementor/css/';
55
56 return set_url_scheme($base . 'post-' . $pid . '.css');
57 }
58
59
60 /**
61 * Auto generate classname from path.
62 *
63 * @since 1.0.0
64 * @access public
65 */
66 public static function make_classname($dirname) {
67 $dirname = pathinfo($dirname, PATHINFO_FILENAME);
68 $class_name = explode('-', $dirname);
69 $class_name = array_map('ucfirst', $class_name);
70 $class_name = implode('_', $class_name);
71
72 return $class_name;
73 }
74
75 public static function kses($raw) {
76
77 $allowed_tags = [
78 'a' => [
79 'class' => [],
80 'href' => [],
81 'rel' => [],
82 'title' => [],
83 ],
84 'abbr' => [
85 'title' => [],
86 ],
87 'b' => [],
88 'blockquote' => [
89 'cite' => [],
90 ],
91 'cite' => [
92 'title' => [],
93 ],
94 'code' => [],
95 'del' => [
96 'datetime' => [],
97 'title' => [],
98 ],
99 'dd' => [],
100 'div' => [
101 'class' => [],
102 'title' => [],
103 'style' => [],
104 ],
105 'dl' => [],
106 'dt' => [],
107 'em' => [],
108 'h1' => [
109 'class' => [],
110 ],
111 'h2' => [
112 'class' => [],
113 ],
114 'h3' => [
115 'class' => [],
116 ],
117 'h4' => [
118 'class' => [],
119 ],
120 'h5' => [
121 'class' => [],
122 ],
123 'h6' => [
124 'class' => [],
125 ],
126 'i' => [
127 'class' => [],
128 ],
129 'img' => [
130 'alt' => [],
131 'class' => [],
132 'height' => [],
133 'src' => [],
134 'width' => [],
135 ],
136 'li' => [
137 'class' => [],
138 ],
139 'ol' => [
140 'class' => [],
141 ],
142 'p' => [
143 'class' => [],
144 ],
145 'q' => [
146 'cite' => [],
147 'title' => [],
148 ],
149 'span' => [
150 'class' => [],
151 'title' => [],
152 'style' => [],
153 ],
154 'iframe' => [
155 'width' => [],
156 'height' => [],
157 'scrolling' => [],
158 'frameborder' => [],
159 'allow' => [],
160 'src' => [],
161 ],
162 'strike' => [],
163 'br' => [],
164 'strong' => [],
165 'data-wow-duration' => [],
166 'data-wow-delay' => [],
167 'data-wallpaper-options' => [],
168 'data-stellar-background-ratio' => [],
169 'ul' => [
170 'class' => [],
171 ],
172 ];
173
174 if(function_exists('wp_kses')) { // WP is here
175 return wp_kses($raw, $allowed_tags);
176 } else {
177 return $raw;
178 }
179 }
180
181 public static function kspan($text) {
182 return str_replace(['{', '}'], ['<span>', '</span>'], self::kses($text));
183 }
184
185 public static function category_list_by_taxonomy($taxonomy = '') {
186 $query_args = [
187 'orderby' => 'ID',
188 'order' => 'DESC',
189 'hide_empty' => 1,
190 'taxonomy' => $taxonomy,
191 ];
192
193 $categories = get_categories($query_args);
194
195 return $categories;
196 }
197
198 public static function trim_words($text, $num_words) {
199 return wp_trim_words($text, $num_words, '');
200 }
201
202 public static function array_push_assoc($array, $key, $value) {
203 $array[$key] = $value;
204
205 return $array;
206 }
207
208 public static function render($content) {
209 if(stripos($content, "shopengine-has-lisence") !== false) {
210 return null;
211 }
212
213 return $content;
214 }
215
216 public static function render_elementor_content($content_id) {
217 $elementor_instance = \Elementor\Plugin::instance();
218
219 return $elementor_instance->frontend->get_builder_content_for_display($content_id);
220 }
221
222 public static function esc_options($str, $options = [], $default = '') {
223 if(!in_array($str, $options)) {
224 return $default;
225 }
226
227 return $str;
228 }
229
230 public static function img_meta($id) {
231 $attachment = get_post($id);
232 if($attachment == null || $attachment->post_type != 'attachment') {
233 return null;
234 }
235
236 return [
237 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
238 'caption' => $attachment->post_excerpt,
239 'description' => $attachment->post_content,
240 'href' => get_permalink($attachment->ID),
241 'src' => $attachment->guid,
242 'title' => $attachment->post_title,
243 ];
244 }
245
246 public static function _product_tag_sale_badge($settings = null) {
247 global $product;
248 $terms = get_the_terms(get_the_ID(), 'product_tag');
249
250 $badge_position = (isset($settings['badge_position']) && !empty($settings['badge_position'])) ? esc_attr($settings['badge_position']) : 'top-right';
251 $badge_align = (isset($settings['badge_align']) && !empty($settings['badge_align'])) ? esc_attr($settings['badge_align']) : 'horizontal';
252
253 if($product->is_on_sale() || !empty($terms)) : ?>
254 <div class="product-tag-sale-badge position-<?php echo $badge_position; ?> align-<?php echo $badge_align; ?>">
255 <ul>
256 <?php if(!empty($terms)) : $term = $terms[0];
257 $bg = get_term_meta($term->term_id, 'shopengine_tag_bg_color', true);
258 ?>
259 <?php if(!empty(self::_discount_percentage())) : ?>
260 <li class="badge no-link off"><?php echo '-' . esc_html(self::_discount_percentage()) . '%'; ?></li>
261 <?php endif; ?>
262 <li class="badge tag">
263 <a <?php if(!empty($bg)) : ?>style="background-color:<?php echo esc_attr($bg); ?>" <?php endif; ?>
264 href="<?php echo get_term_link($term->term_id); ?>"><?php echo esc_html($term->name); ?></a>
265 </li>
266 <?php endif;
267
268 if($product->is_on_sale()) {
269 echo "<li class='badge no-link sale'>" . esc_html__('Sale!', 'shopengine') . "</li>";
270 }
271 ?>
272 </ul>
273 </div>
274 <?php
275 endif;
276 }
277
278
279 public static function _product_image($settings = null) {
280 global $product;
281 ?>
282 <div class='product-thumb'>
283 <a href="<?php echo get_the_permalink(); ?>">
284 <?php echo woocommerce_get_product_thumbnail($product->get_id()); ?>
285 </a>
286
287 <!-- end sale date -->
288 <?php
289 if(!empty($settings['counter_position']) && $settings['counter_position'] == 'image') {
290 self::_product_sale_end_date($settings);
291 }
292 ?>
293 <!-- tag and sale badge -->
294 <?php self::_product_tag_sale_badge($settings); ?>
295
296 <!-- show group buttons -->
297 <?php
298 if(isset($settings['shopengine_group_btns']) && $settings['shopengine_group_btns'] === 'yes') {
299 ?>
300 <div class="loop-product--btns">
301 <div class="loop-product--btns-inner">
302 <?php woocommerce_template_loop_add_to_cart(); ?>
303 </div>
304 </div>
305 <?php
306 }
307 ?>
308
309 </div>
310 <?php
311 }
312
313 public static function _product_sale_end_date($settings) {
314 $date = get_post_meta(get_the_id(), '_sale_price_dates_to', true);
315 if(!empty($date)) :
316 $formatted_date = date("Y-m-d", $date);
317 $config = [
318 'days' => esc_html__('Days', 'shopengine'),
319 'hours' => esc_html__('Hours', 'shopengine'),
320 'minutes' => esc_html__('Minutes', 'shopengine'),
321 'seconds' => esc_html__('Seconds', 'shopengine'),
322 ];
323
324 ?>
325 <div data-prefix="<?php echo !empty($settings['counter_prefix']) ? $settings['counter_prefix'] : ''; ?>"
326 class="product-end-sale-timer <?php echo !empty($settings['counter_position']) ? 'counter-position-' . esc_attr($settings['counter_position']) : ''; ?>"
327 data-config='<?php echo json_encode($config); ?>'
328 data-date="<?php echo esc_attr($formatted_date); ?>"></div>
329 <?php
330 endif;
331 }
332
333 public static function _product_category($settings = null) {
334 global $product;
335
336 $terms = get_the_terms(get_the_ID(), 'product_cat');
337 $terms_count = count($terms);
338
339 if($terms_count > 0) {
340 echo "<div class='product-category'><ul>";
341 foreach($terms as $key => $term) {
342 $sperator = $key !== ($terms_count - 1) ? ',' : '';
343 echo "<li><a href='" . get_term_link($term->term_id) . "'>" . esc_html($term->name) . $sperator . "</a></li>";
344 }
345 echo "</ul></div>";
346 }
347 }
348
349 public static function _discount_percentage($settings = null) {
350 global $product;
351
352 $product_data = $product->get_data();
353 $show_tag = (isset($settings['show_tag']) && !empty($settings['show_tag'])) ? esc_attr($settings['show_tag']) : 'yes';
354 $output = '';
355 if($show_tag == 'yes' && !empty($product_data['regular_price']) && $product_data['sale_price']) {
356 $percentage = round((($product_data['regular_price'] - $product_data['sale_price']) / $product_data['regular_price']) * 100);
357
358 return $percentage;
359 }
360
361 return '';
362 }
363
364
365 public static function _product_title($settings = null) {
366 ?>
367 <h3 class='product-title'>
368 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
369 </h3>
370 <?php
371 }
372
373 public static function _product_rating($settings = null) {
374
375 global $product;
376 ?>
377 <div class="product-rating">
378 <?php
379 if($product->get_rating_count() > 0) {
380 woocommerce_template_loop_rating();
381 } else {
382 echo sprintf('<div class="star-rating">%1$s</div>', wc_get_star_rating_html(0, 0));
383 }
384
385 // review count
386 echo sprintf('<span class="rating-count">(%1$s)</span>', $product->get_review_count());
387 ?>
388 </div>
389 <?php
390 }
391
392
393 public static function _product_price($settings = null) {
394 ?>
395 <div class="product-price">
396 <?php woocommerce_template_single_price(); ?>
397 </div>
398 <?php
399 }
400
401 public static function _product_description($settings = null) {
402 global $product;
403 $product_data = $product->get_data($product->get_id());
404 ?>
405 <div class="prodcut-description">
406 <?php echo apply_filters('shopengine_product_short_description', $product_data['description']); ?>
407 </div>
408
409 <?php
410 }
411
412 public static function _product_buttons($settings = null) {
413 if($settings['shopengine_group_btns'] !== 'yes'): ?>
414 <div class="add-to-cart-bt">
415 <?php woocommerce_template_loop_add_to_cart(); ?>
416 </div>
417 <?php endif;
418 }
419
420 }
421