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