PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.6.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.6.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
432 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 $data_attr = apply_filters('shopengine/group_btns/optional_tooltip_data_attr', '');
278
279 ?>
280 <div class="loop-product--btns" <?php echo esc_attr($data_attr)?>>
281 <div class="loop-product--btns-inner">
282 <?php woocommerce_template_loop_add_to_cart(); ?>
283 </div>
284 </div>
285 <?php
286 }
287 ?>
288
289 </div>
290 <?php
291 }
292
293 public static function _product_sale_end_date($settings) {
294 $date = get_post_meta(get_the_id(), '_sale_price_dates_to', true);
295 if(!empty($date)) :
296 $formatted_date = date("Y-m-d", $date);
297 $config = [
298 'days' => esc_html__('Days', 'shopengine'),
299 'hours' => esc_html__('Hours', 'shopengine'),
300 'minutes' => esc_html__('Minutes', 'shopengine'),
301 'seconds' => esc_html__('Seconds', 'shopengine'),
302 ];
303
304 ?>
305 <div data-prefix="<?php echo !empty($settings['counter_prefix']) ? $settings['counter_prefix'] : ''; ?>"
306 class="product-end-sale-timer <?php echo !empty($settings['counter_position']) ? 'counter-position-' . esc_attr($settings['counter_position']) : ''; ?>"
307 data-config='<?php echo json_encode($config); ?>'
308 data-date="<?php echo esc_attr($formatted_date); ?>"></div>
309 <?php
310 endif;
311 }
312
313 public static function _product_category($settings = null) {
314 global $product;
315
316 $terms = get_the_terms($product->get_id(), 'product_cat');
317 $terms_count = count($terms);
318
319 if($terms_count > 0) {
320 echo "<div class='product-category'><ul>";
321 foreach($terms as $key => $term) {
322 $sperator = $key !== ($terms_count - 1) ? ',' : '';
323 echo "<li><a href='" . get_term_link($term->term_id) . "'>" . esc_html($term->name) . $sperator . "</a></li>";
324 }
325 echo "</ul></div>";
326 }
327 }
328
329 public static function _discount_percentage($settings = null) {
330 global $product;
331
332 $product_data = $product->get_data();
333 $show_tag = (isset($settings['show_tag']) && !empty($settings['show_tag'])) ? esc_attr($settings['show_tag']) : 'yes';
334 $output = '';
335 if($show_tag == 'yes' && !empty($product_data['regular_price']) && $product_data['sale_price']) {
336 $percentage = round((($product_data['regular_price'] - $product_data['sale_price']) / $product_data['regular_price']) * 100);
337
338 return $percentage;
339 }
340
341 return '';
342 }
343
344
345 public static function _product_title($settings = null) {
346 ?>
347 <h3 class='product-title'>
348 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
349 </h3>
350 <?php
351 }
352
353 public static function _product_rating($settings = null) {
354
355 global $product;
356 ?>
357 <div class="product-rating">
358 <?php
359 if($product->get_rating_count() > 0) {
360 woocommerce_template_loop_rating();
361 } else {
362 echo sprintf('<div class="star-rating">%1$s</div>', wc_get_star_rating_html(0, 0));
363 }
364
365 // review count
366 echo sprintf('<span class="rating-count">(%1$s)</span>', $product->get_review_count());
367 ?>
368 </div>
369 <?php
370 }
371
372
373 public static function _product_price($settings = null) {
374 ?>
375 <div class="product-price">
376 <?php woocommerce_template_single_price(); ?>
377 </div>
378 <?php
379 }
380
381 public static function _product_description($settings = null) {
382 global $product;
383 $product_data = $product->get_data($product->get_id());
384 ?>
385 <div class="prodcut-description">
386 <?php echo apply_filters('shopengine_product_short_description', $product_data['description']); ?>
387 </div>
388
389 <?php
390 }
391
392 public static function _product_buttons($settings = null) {
393 if($settings['shopengine_group_btns'] !== 'yes'): ?>
394 <div class="add-to-cart-bt">
395 <?php woocommerce_template_loop_add_to_cart(); ?>
396 </div>
397 <?php endif;
398 }
399
400
401 /**
402 * todo - check the keys for refund and cancelled [wc-cancelled, wc-refunded ]
403 *
404 * @param $product_id
405 * @param int $variation_id
406 * @return int
407 */
408 public static function get_total_sale_count($product_id, $variation_id = 0) {
409
410 global $wpdb;
411
412 $qry = 'SELECT sum(lookup.product_qty) as total FROM `'.$wpdb->prefix.'wc_order_product_lookup` as lookup';
413 $qry .=' LEFT JOIN '.$wpdb->prefix.'wc_order_stats AS stat on lookup.order_id = stat.order_id ';
414 $qry .=' WHERE `product_id` = '.intval($product_id).' and variation_id = '.intval($variation_id);
415 $qry .= ' and stat.status NOT IN (\'wc-cancelled\', \'wc-refunded\') ;';
416 $result = $wpdb->get_row($qry);
417 $total = is_object($result) ? $result->total : 0;
418
419 return intval( $total ) ;
420 }
421
422
423 public static function is_guest_checkout_allowed() {
424
425 return 'yes' === get_option('woocommerce_enable_guest_checkout');
426 }
427
428 public static function is_login_allowed_during_checkout() {
429
430 return 'yes' === get_option('woocommerce_enable_checkout_login_reminder');
431 }
432 }