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