PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.4.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.4.1
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 5 years ago helper.php 4 years ago notice.php 5 years ago
helper.php
429 lines
1 <?php
2
3 namespace ShopEngine\Utils;
4
5
6 defined('ABSPATH') || exit;
7
8 /**
9 * Global helper class.
10 *
11 * @since 1.0.0
12 */
13 class Helper {
14
15 public static function get_elementor_css_uri($pid) {
16
17 global $blog_id;
18
19 $wp_upload_dir = wp_upload_dir(null, false);
20
21 $base = $wp_upload_dir['baseurl'] . '/elementor/css/';
22
23 return set_url_scheme($base . 'post-' . $pid . '.css');
24 }
25
26 public static function add_to_url($url, $param) {
27 $info = parse_url( $url );
28 $query = [];
29
30 if(isset($info['query'])){
31 parse_str( $info['query'], $query );
32 }
33 return $info['scheme'] . '://' . $info['host'] . $info['path'] . '?' . http_build_query( $query ? array_merge( $query, $param ) : $param );
34 }
35
36
37 /**
38 * Auto generate classname from path.
39 *
40 * @since 1.0.0
41 * @access public
42 */
43 public static function make_classname($dirname) {
44 $dirname = pathinfo($dirname, PATHINFO_FILENAME);
45 $class_name = explode('-', $dirname);
46 $class_name = array_map('ucfirst', $class_name);
47 $class_name = implode('_', $class_name);
48
49 return $class_name;
50 }
51
52 public static function kses($raw) {
53
54 $allowed_tags = [
55 'a' => [
56 'class' => [],
57 'href' => [],
58 'rel' => [],
59 'title' => [],
60 ],
61 'abbr' => [
62 'title' => [],
63 ],
64 'b' => [],
65 'blockquote' => [
66 'cite' => [],
67 ],
68 'cite' => [
69 'title' => [],
70 ],
71 'code' => [],
72 'del' => [
73 'datetime' => [],
74 'title' => [],
75 ],
76 'dd' => [],
77 'div' => [
78 'class' => [],
79 'title' => [],
80 'style' => [],
81 ],
82 'dl' => [],
83 'dt' => [],
84 'em' => [],
85 'h1' => [
86 'class' => [],
87 ],
88 'h2' => [
89 'class' => [],
90 ],
91 'h3' => [
92 'class' => [],
93 ],
94 'h4' => [
95 'class' => [],
96 ],
97 'h5' => [
98 'class' => [],
99 ],
100 'h6' => [
101 'class' => [],
102 ],
103 'i' => [
104 'class' => [],
105 ],
106 'img' => [
107 'alt' => [],
108 'class' => [],
109 'height' => [],
110 'src' => [],
111 'width' => [],
112 ],
113 'li' => [
114 'class' => [],
115 ],
116 'ol' => [
117 'class' => [],
118 ],
119 'p' => [
120 'class' => [],
121 ],
122 'q' => [
123 'cite' => [],
124 'title' => [],
125 ],
126 'span' => [
127 'class' => [],
128 'title' => [],
129 'style' => [],
130 ],
131 'iframe' => [
132 'width' => [],
133 'height' => [],
134 'scrolling' => [],
135 'frameborder' => [],
136 'allow' => [],
137 'src' => [],
138 ],
139 'strike' => [],
140 'br' => [],
141 'strong' => [],
142 'data-wow-duration' => [],
143 'data-wow-delay' => [],
144 'data-wallpaper-options' => [],
145 'data-stellar-background-ratio' => [],
146 'ul' => [
147 'class' => [],
148 ],
149 ];
150
151 if(function_exists('wp_kses')) { // WP is here
152 return wp_kses($raw, $allowed_tags);
153 } else {
154 return $raw;
155 }
156 }
157
158 public static function kspan($text) {
159 return str_replace(['{', '}'], ['<span>', '</span>'], self::kses($text));
160 }
161
162 public static function category_list_by_taxonomy($taxonomy = '') {
163 $query_args = [
164 'orderby' => 'ID',
165 'order' => 'DESC',
166 'hide_empty' => 1,
167 'taxonomy' => $taxonomy,
168 ];
169
170 $categories = get_categories($query_args);
171
172 return $categories;
173 }
174
175 public static function trim_words($text, $num_words) {
176 return wp_trim_words($text, $num_words, '');
177 }
178
179 public static function array_push_assoc($array, $key, $value) {
180 $array[$key] = $value;
181
182 return $array;
183 }
184
185 public static function render($content) {
186 if(stripos($content, "shopengine-has-lisence") !== false) {
187 return null;
188 }
189
190 return $content;
191 }
192
193 public static function render_elementor_content($content_id) {
194 $elementor_instance = \Elementor\Plugin::instance();
195
196 return $elementor_instance->frontend->get_builder_content_for_display($content_id);
197 }
198
199 public static function esc_options($str, $options = [], $default = '') {
200 if(!in_array($str, $options)) {
201 return $default;
202 }
203
204 return $str;
205 }
206
207 public static function img_meta($id) {
208 $attachment = get_post($id);
209 if($attachment == null || $attachment->post_type != 'attachment') {
210 return null;
211 }
212
213 return [
214 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
215 'caption' => $attachment->post_excerpt,
216 'description' => $attachment->post_content,
217 'href' => get_permalink($attachment->ID),
218 'src' => $attachment->guid,
219 'title' => $attachment->post_title,
220 ];
221 }
222
223 public static function _product_tag_sale_badge($settings = null) {
224 global $product;
225 $terms = get_the_terms(get_the_ID(), 'product_tag');
226
227 $badge_position = (isset($settings['badge_position']) && !empty($settings['badge_position'])) ? esc_attr($settings['badge_position']) : 'top-right';
228 $badge_align = (isset($settings['badge_align']) && !empty($settings['badge_align'])) ? esc_attr($settings['badge_align']) : 'horizontal';
229
230 if($product->is_on_sale() || !empty($terms)) : ?>
231 <div class="product-tag-sale-badge position-<?php echo esc_attr($badge_position); ?> align-<?php echo esc_attr($badge_align); ?>">
232 <ul>
233 <?php if(!empty($terms)) : $term = $terms[0];
234 $bg = get_term_meta($term->term_id, 'shopengine_tag_bg_color', true);
235 ?>
236 <?php if(!empty(self::_discount_percentage())) : ?>
237 <li class="badge no-link off"><?php echo '-' . esc_html(self::_discount_percentage()) . '%'; ?></li>
238 <?php endif; ?>
239 <li class="badge tag">
240 <a <?php if(!empty($bg)) : ?>style="background-color:<?php echo esc_attr($bg); ?>" <?php endif; ?>
241 href="<?php echo get_term_link($term->term_id); ?>"><?php echo esc_html($term->name); ?></a>
242 </li>
243 <?php endif;
244
245 if($product->is_on_sale()) {
246 echo "<li class='badge no-link sale'>" . esc_html__('Sale!', 'shopengine') . "</li>";
247 }
248 ?>
249 </ul>
250 </div>
251 <?php
252 endif;
253 }
254
255
256 public static function _product_image($settings = null) {
257 global $product;
258 ?>
259 <div class='product-thumb'>
260 <a href="<?php echo get_the_permalink(); ?>">
261 <?php echo woocommerce_get_product_thumbnail($product->get_id()); ?>
262 </a>
263
264 <!-- end sale date -->
265 <?php
266 if(!empty($settings['counter_position']) && $settings['counter_position'] == 'image') {
267 self::_product_sale_end_date($settings);
268 }
269 ?>
270 <!-- tag and sale badge -->
271 <?php self::_product_tag_sale_badge($settings); ?>
272
273 <!-- show group buttons -->
274 <?php
275 if(isset($settings['shopengine_group_btns']) && $settings['shopengine_group_btns'] === 'yes') {
276 ?>
277 <div class="loop-product--btns">
278 <div class="loop-product--btns-inner">
279 <?php woocommerce_template_loop_add_to_cart(); ?>
280 </div>
281 </div>
282 <?php
283 }
284 ?>
285
286 </div>
287 <?php
288 }
289
290 public static function _product_sale_end_date($settings) {
291 $date = get_post_meta(get_the_id(), '_sale_price_dates_to', true);
292 if(!empty($date)) :
293 $formatted_date = date("Y-m-d", $date);
294 $config = [
295 'days' => esc_html__('Days', 'shopengine'),
296 'hours' => esc_html__('Hours', 'shopengine'),
297 'minutes' => esc_html__('Minutes', 'shopengine'),
298 'seconds' => esc_html__('Seconds', 'shopengine'),
299 ];
300
301 ?>
302 <div data-prefix="<?php echo !empty($settings['counter_prefix']) ? $settings['counter_prefix'] : ''; ?>"
303 class="product-end-sale-timer <?php echo !empty($settings['counter_position']) ? 'counter-position-' . esc_attr($settings['counter_position']) : ''; ?>"
304 data-config='<?php echo json_encode($config); ?>'
305 data-date="<?php echo esc_attr($formatted_date); ?>"></div>
306 <?php
307 endif;
308 }
309
310 public static function _product_category($settings = null) {
311 global $product;
312
313 $terms = get_the_terms(get_the_ID(), 'product_cat');
314 $terms_count = count($terms);
315
316 if($terms_count > 0) {
317 echo "<div class='product-category'><ul>";
318 foreach($terms as $key => $term) {
319 $sperator = $key !== ($terms_count - 1) ? ',' : '';
320 echo "<li><a href='" . get_term_link($term->term_id) . "'>" . esc_html($term->name) . $sperator . "</a></li>";
321 }
322 echo "</ul></div>";
323 }
324 }
325
326 public static function _discount_percentage($settings = null) {
327 global $product;
328
329 $product_data = $product->get_data();
330 $show_tag = (isset($settings['show_tag']) && !empty($settings['show_tag'])) ? esc_attr($settings['show_tag']) : 'yes';
331 $output = '';
332 if($show_tag == 'yes' && !empty($product_data['regular_price']) && $product_data['sale_price']) {
333 $percentage = round((($product_data['regular_price'] - $product_data['sale_price']) / $product_data['regular_price']) * 100);
334
335 return $percentage;
336 }
337
338 return '';
339 }
340
341
342 public static function _product_title($settings = null) {
343 ?>
344 <h3 class='product-title'>
345 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
346 </h3>
347 <?php
348 }
349
350 public static function _product_rating($settings = null) {
351
352 global $product;
353 ?>
354 <div class="product-rating">
355 <?php
356 if($product->get_rating_count() > 0) {
357 woocommerce_template_loop_rating();
358 } else {
359 echo sprintf('<div class="star-rating">%1$s</div>', wc_get_star_rating_html(0, 0));
360 }
361
362 // review count
363 echo sprintf('<span class="rating-count">(%1$s)</span>', $product->get_review_count());
364 ?>
365 </div>
366 <?php
367 }
368
369
370 public static function _product_price($settings = null) {
371 ?>
372 <div class="product-price">
373 <?php woocommerce_template_single_price(); ?>
374 </div>
375 <?php
376 }
377
378 public static function _product_description($settings = null) {
379 global $product;
380 $product_data = $product->get_data($product->get_id());
381 ?>
382 <div class="prodcut-description">
383 <?php echo apply_filters('shopengine_product_short_description', $product_data['description']); ?>
384 </div>
385
386 <?php
387 }
388
389 public static function _product_buttons($settings = null) {
390 if($settings['shopengine_group_btns'] !== 'yes'): ?>
391 <div class="add-to-cart-bt">
392 <?php woocommerce_template_loop_add_to_cart(); ?>
393 </div>
394 <?php endif;
395 }
396
397
398 /**
399 * todo - check the keys for refund and cancelled [wc-cancelled, wc-refunded ]
400 *
401 * @param $product_id
402 * @param int $variation_id
403 * @return int
404 */
405 public static function get_total_sale_count($product_id, $variation_id = 0) {
406
407 global $wpdb;
408
409 $qry = 'SELECT sum(lookup.product_qty) as total FROM `'.$wpdb->prefix.'wc_order_product_lookup` as lookup';
410 $qry .=' LEFT JOIN '.$wpdb->prefix.'wc_order_stats AS stat on lookup.order_id = stat.order_id ';
411 $qry .=' WHERE `product_id` = '.intval($product_id).' and variation_id = '.intval($variation_id);
412 $qry .= ' and stat.status NOT IN (\'wc-cancelled\', \'wc-refunded\') ;';
413 $result = $wpdb->get_row($qry);
414 $total = is_object($result) ? $result->total : 0;
415
416 return intval( $total ) ;
417 }
418
419
420 public static function is_guest_checkout_allowed() {
421
422 return 'yes' === get_option('woocommerce_enable_guest_checkout');
423 }
424
425 public static function is_login_allowed_during_checkout() {
426
427 return 'yes' === get_option('woocommerce_enable_checkout_login_reminder');
428 }
429 }