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