Пример #1
0
function hocwp_option_reading_update($input)
{
    $breadcrumb_label = hocwp_get_value_by_key($input, 'breadcrumb_label');
    if (!empty($breadcrumb_label)) {
        $breadcrumb_label = hocwp_remove_last_char($breadcrumb_label, ':');
        $breadcrumb_label .= ':';
        $wpseo_internallinks = get_option('wpseo_internallinks');
        $wpseo_internallinks['breadcrumbs-prefix'] = $breadcrumb_label;
        update_option('wpseo_internallinks', $wpseo_internallinks);
    }
    $posts_per_page = hocwp_get_value_by_key($input, 'products_per_page');
    if (hocwp_is_positive_number($posts_per_page)) {
        update_option('hocwp_product_posts_per_page', $posts_per_page);
    }
}
Пример #2
0
function hocwp_shortcode_post_callback($atts = array(), $content = null)
{
    $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => '');
    $attributes = shortcode_atts($defaults, $atts);
    $transient_name = 'hocwp_shortcode_post_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $attributes);
    if (false === ($html = get_transient($transient_name))) {
        $order = $attributes['order'];
        $orderby = $attributes['orderby'];
        $by = $attributes['by'];
        $post_type = hocwp_string_to_array(',', $attributes['post_type']);
        $post_type = array_map('trim', $post_type);
        $offset = $attributes['offset'];
        $column = $attributes['column'];
        if (!hocwp_is_positive_number($column)) {
            $column = 1;
        }
        $number = $attributes['number'];
        $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column);
        $exclude_current = (bool) $attributes['exclude_current'];
        $display = $attributes['display'];
        $display = trim($display);
        $excerpt_length = $attributes['excerpt_length'];
        $post = $attributes['post'];
        $post = hocwp_find_post($post);
        $posts = $attributes['posts'];
        $posts = hocwp_string_to_array(',', $posts);
        $thumbnail_size = $attributes['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $interval = $attributes['interval'];
        if (hocwp_is_post($post)) {
            $display = 'full';
        }
        $class = 'hocwp-shortcode-post';
        hocwp_add_string_with_space_before($class, $order);
        hocwp_add_string_with_space_before($class, $by);
        hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display));
        if ('100%' == $display) {
            $class = hocwp_add_more_class($class, 'full-width');
        }
        hocwp_add_string_with_space_before($class, implode(' ', $post_type));
        $query = null;
        if (!hocwp_is_post($post)) {
            $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby);
            if (!empty($interval)) {
                hocwp_query_sanitize_date_query_args($interval, $args);
            }
            if ($exclude_current && is_singular()) {
                $post_id = get_the_ID();
                $args['post__not_in'] = array($post_id);
            }
            if (hocwp_array_has_value($posts)) {
                $args['post__in'] = $posts;
            }
            $query = hocwp_query_by($by, $args);
        } else {
            if (!hocwp_is_positive_number($excerpt_length)) {
                $excerpt_length = 200;
            }
        }
        if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) {
            $html = hocwp_shortcode_before($class, $attributes);
            $width = $thumbnail_size[0];
            if (hocwp_is_post($post)) {
                global $post;
                setup_postdata($post);
                ob_start();
                ?>
				<div class="one-post">
					<div <?php 
                post_class('', $post);
                ?>
>
						<?php 
                if ($width > 0) {
                    hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID));
                }
                hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post)));
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_entry_summary($excerpt_length);
                }
                ?>
					</div>
				</div>
				<?php 
                $html .= ob_get_clean();
                wp_reset_postdata();
            } else {
                $html .= '<div class="in-loop row-small">';
                $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes);
                if (empty($loop)) {
                    $count = 1;
                    $style = '';
                    if ('left' != $display && 'right' != $display) {
                        $style = 'width:' . hocwp_column_width_percentage($column);
                    }
                    while ($query->have_posts()) {
                        $query->the_post();
                        $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes);
                        if (empty($html_loop)) {
                            $item_class = 'item';
                            if (hocwp_is_last_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'last-item');
                            } elseif (hocwp_is_first_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'first-item');
                            }
                            ob_start();
                            ?>
							<div class="<?php 
                            echo $item_class;
                            ?>
" style="<?php 
                            echo $style;
                            ?>
">
								<div <?php 
                            post_class();
                            ?>
>
									<?php 
                            if ($width > 0) {
                                hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]));
                            }
                            hocwp_post_title_link();
                            if (hocwp_is_positive_number($excerpt_length)) {
                                hocwp_entry_summary($excerpt_length);
                            }
                            ?>
								</div>
							</div>
							<?php 
                            $html_loop = ob_get_clean();
                        }
                        $loop .= $html_loop;
                        $count++;
                    }
                    wp_reset_postdata();
                }
                $html .= $loop;
                $html .= '</div>';
            }
            $html .= hocwp_shortcode_after();
        } else {
            $html = '';
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, WEEK_IN_SECONDS);
        }
    }
    return apply_filters('hocwp_shortcode_post', $html, $attributes, $content);
}
Пример #3
0
function hocwp_slider_html($args = array())
{
    if (!is_array($args)) {
        $position = $args;
    } else {
        $position = hocwp_get_value_by_key($args, 'position');
    }
    $slider = hocwp_get_slider_by_position($position);
    if (hocwp_is_post($slider)) {
        $items = hocwp_get_post_meta('slider_items', $slider->ID);
        $order = hocwp_get_value_by_key($items, 'order');
        if (!empty($order)) {
            $order = explode(',', $order);
            $items = hocwp_get_value_by_key($items, 'items');
            $slider_class = 'hocwp-slider';
            $thumbs = (bool) hocwp_get_value_by_key($args, 'thumbs', false);
            if ($thumbs) {
                hocwp_add_string_with_space_before($slider_class, 'thumbs-paging');
            }
            hocwp_add_string_with_space_before($slider_class, hocwp_sanitize_html_class($position));
            $custom_arrow = hocwp_get_value_by_key($args, 'custom_arrow');
            if ($custom_arrow) {
                $slider_class = hocwp_add_more_class($slider_class, 'custom-arrow');
            }
            $fit_width = hocwp_get_post_meta('fit_width', $slider->ID);
            $fit_width = hocwp_int_to_bool($fit_width);
            $height = hocwp_get_post_meta('height', $slider->ID);
            if (!hocwp_is_positive_number($height)) {
                $height = 350;
            }
            $atts = array('data-height="' . $height . '"');
            if ($fit_width) {
                $atts[] = 'data-fit-width="1"';
            }
            $atts = implode(' ', $atts);
            if (!empty($atts)) {
                $atts = ' ' . $atts;
                $atts = rtrim($atts);
            }
            echo '<div class="' . $slider_class . '">';
            echo '<ul class="list-unstyled list-items slickslide list-inline"' . $atts . '>';
            $list_paging = '';
            $lazyload = hocwp_get_value_by_key($args, 'lazyload');
            foreach ($order as $item_id) {
                $item = hocwp_get_value_by_key($items, $item_id);
                if (hocwp_array_has_value($item)) {
                    $title = hocwp_get_value_by_key($item, 'title');
                    $link = hocwp_get_value_by_key($item, 'link');
                    $description = hocwp_get_value_by_key($item, 'description');
                    $image_url = hocwp_get_value_by_key($item, 'image_url');
                    $image_id = hocwp_get_value_by_key($item, 'image_id');
                    $image_url = hocwp_return_media_url($image_url, $image_id);
                    $img = new HOCWP_HTML('img');
                    $img->set_image_src($image_url);
                    $img->add_class('slider-image');
                    $li = new HOCWP_HTML('li');
                    $li->set_text($img);
                    $li->add_class('slider-item');
                    if ($lazyload) {
                        $li->add_class('lazyload');
                        $img->set_attribute('data-original', $image_url);
                        $img->set_image_src(hocwp_get_image_url('transparent.gif'));
                    }
                    $list_paging .= $li->build();
                    if (!empty($link)) {
                        $a = new HOCWP_HTML('a');
                        $a->set_href($link);
                        $a->set_text($img);
                        $li->set_text($a);
                    } else {
                        $li->set_text($img);
                    }
                    $li->output();
                }
            }
            echo '</ul>';
            if ($thumbs) {
                echo '<div class="thumbs-paging slick-thumbs">';
                echo '<ul class="list-unstyled list-paging">';
                echo $list_paging;
                echo '</ul>';
                echo '</div>';
            }
            echo '</div>';
        }
    }
}
Пример #4
0
function hocwp_product_price($post_id = null, $no_price = '', $args = array())
{
    $post_id = hocwp_return_post($post_id, 'id');
    $regular_price = hocwp_get_post_meta('regular_price', $post_id);
    $sale_price = hocwp_get_post_meta('sale_price', $post_id);
    $prices = hocwp_sanitize_product_price($regular_price, $sale_price, $post_id);
    $price = $prices['price'];
    $no_price_html = '<span class="no-price">' . __('Price', 'hocwp-theme') . ': <span class="amount">';
    $no_price_html .= __('Please call', 'hocwp-theme') . '</span></span>';
    $defaults = array('currency' => '$', 'currency_position' => 'left', 'decimals' => 2, 'dec_point' => '.', 'thousands_sep' => ',', 'no_price_html' => $no_price_html);
    $defaults = apply_filters('hocwp_product_price_defaults', $defaults);
    $args = wp_parse_args($args, $defaults);
    $no_price_html = $args['no_price_html'];
    if (empty($no_price)) {
        $no_price = $no_price_html;
    }
    if (!hocwp_is_positive_number($price)) {
        $price = $no_price;
    } else {
        $sale_price = $prices['sale_price'];
        $regular_price = $prices['regular_price'];
        $currency = hocwp_get_value_by_key($args, 'currency');
        $currency = apply_filters('hocwp_product_price_currency', $currency);
        $currency_position = hocwp_get_value_by_key($args, 'currency_position', 'left');
        $currency_position = apply_filters('hocwp_product_price_currency_position', $currency_position);
        $decimals = hocwp_get_value_by_key($args, 'decimals');
        $dec_point = hocwp_get_value_by_key($args, 'dec_point');
        $thousands_sep = hocwp_get_value_by_key($args, 'thousands_sep');
        $number_format = '%NUMBER%';
        if ('left' == $currency_position) {
            $number_format = '%CURRENCY%' . $number_format;
        } else {
            $number_format .= '%CURRENCY%';
        }
        $number_format = str_replace('%CURRENCY%', $currency, $number_format);
        $price = number_format($regular_price, $decimals, $dec_point, $thousands_sep);
        $price = str_replace('%NUMBER%', $price, $number_format);
        $price = hocwp_wrap_tag($price, 'span', 'amount');
        if (hocwp_is_positive_number($sale_price)) {
            $sale_price = number_format($sale_price, $decimals, $dec_point, $thousands_sep);
            $sale_price = str_replace('%NUMBER%', $sale_price, $number_format);
            $sale_price = hocwp_wrap_tag($sale_price, 'span', 'amount');
            $sale_price = hocwp_wrap_tag($sale_price, 'ins');
            $price = hocwp_wrap_tag($price, 'del');
            $price .= $sale_price;
        }
    }
    if (!empty($price)) {
        $price = hocwp_wrap_tag($price, 'p', 'price');
        echo $price;
    }
}
    public function list_post_html($args, $instance, WP_Query $query)
    {
        $post_type = $this->get_post_type_from_instance($instance);
        $post_types = array();
        foreach ($post_type as $fvdata) {
            $ptvalue = isset($fvdata['value']) ? $fvdata['value'] : '';
            if (!empty($ptvalue)) {
                $post_types[] = $ptvalue;
            }
        }
        $full_width_post = hocwp_get_value_by_key($instance, 'full_width_post', $this->args['full_width_post']);
        $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail'));
        $thumbnail_size = isset($instance['thumbnail_size']) ? $instance['thumbnail_size'] : $this->args['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length'];
        $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length'));
        $list_class = 'list-unstyled';
        foreach ($post_types as $ptvalue) {
            hocwp_add_string_with_space_before($list_class, 'list-' . $ptvalue . 's');
        }
        $list_class = apply_filters('hocwp_widget_post_list_class', $list_class, $args, $instance, $this);
        $widget_html = '<ul class="' . $list_class . '">';
        $loop_html = apply_filters('hocwp_widget_post_loop_html', '', $args, $instance, $this);
        if (empty($loop_html)) {
            $count = 0;
            ob_start();
            while ($query->have_posts()) {
                $query->the_post();
                $post_id = get_the_ID();
                $post = get_post($post_id);
                $class = 'a-widget-post';
                $full_width = false;
                if ('all' == $full_width_post) {
                    $full_width = true;
                } elseif ('first' == $full_width_post && 0 == $count) {
                    $full_width = true;
                } elseif ('last' == $full_width_post && $count == $query->post_count) {
                    $full_width = true;
                } elseif ('first_last' == $full_width_post && (0 == $count || $count == $query->post_count)) {
                    $full_width = true;
                } elseif ('odd' == $full_width_post && $count % 2 != 0) {
                    $full_width = true;
                } elseif ('even' == $full_width_post && $count % 2 == 0) {
                    $full_width = true;
                }
                if ($full_width) {
                    hocwp_add_string_with_space_before($class, 'full-width');
                }
                if ($hide_thumbnail) {
                    hocwp_add_string_with_space_before($class, 'hide-thumbnail');
                }
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_add_string_with_space_before($class, 'show-excerpt');
                } else {
                    hocwp_add_string_with_space_before($class, 'hide-excerpt');
                }
                ?>
				<li <?php 
                post_class($class);
                ?>
>
					<?php 
                do_action('hocwp_widget_post_before_post', $args, $instance, $this);
                if (!(bool) $hide_thumbnail) {
                    if ('coupon' == $post->post_type) {
                        echo '<div class="text-center code-data">';
                        $percent = hocwp_get_coupon_percent_label($post_id);
                        $text = hocwp_get_coupon_text_label($post_id);
                        $type_text = 'Website Coupons';
                        $type_term = hocwp_get_coupon_type_term($post_id);
                        if (is_a($type_term, 'WP_Term')) {
                            $type_text = $type_term->name;
                        }
                        $tmp = hocwp_get_coupon_type($post_id);
                        if (is_array($tmp)) {
                            $tmp = array_shift($tmp);
                            if (!empty($tmp)) {
                                $type_text = $tmp;
                            }
                        }
                        $price = hocwp_get_post_meta('price', $post_id);
                        $sale_price = hocwp_get_post_meta('sale_price', $post_id);
                        if (!empty($price) && !empty($sale_price) || empty($percent)) {
                            $percentage = hocwp_percentage($price, $sale_price);
                            $percent = $percentage . '%';
                            $text = 'OFF';
                        }
                        ?>
							<div class="txt"><?php 
                        echo $percent . ' ' . $text;
                        ?>
</div>
							<div class="type"><?php 
                        echo $type_text;
                        ?>
</div>
							<?php 
                        echo '</div>';
                    } else {
                        $thumbnail_args = array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]);
                        if ($full_width) {
                            unset($thumbnail_args['width']);
                            unset($thumbnail_args['height']);
                        }
                        hocwp_post_thumbnail($thumbnail_args);
                    }
                }
                do_action('hocwp_widget_post_before_post_title', $args, $instance, $this);
                hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length)));
                do_action('hocwp_widget_post_after_post_title', $args, $instance, $this);
                if (0 < $excerpt_length) {
                    $post_type = get_post_type($post_id);
                    if ('product' == $post_type && hocwp_wc_installed()) {
                        hocwp_wc_product_price(null, true);
                    } else {
                        hocwp_entry_summary($excerpt_length);
                    }
                }
                do_action('hocwp_widget_post_after_post', $args, $instance, $this);
                ?>
				</li>
				<?php 
                $count++;
            }
            wp_reset_postdata();
            $loop_html .= ob_get_clean();
        }
        $widget_html .= $loop_html;
        $widget_html .= '</ul>';
        return $widget_html;
    }
Пример #6
0
function hocwp_query_related_post($args = array())
{
    $post_id = absint(isset($args['post_id']) ? $args['post_id'] : get_the_ID());
    if ($post_id < 1) {
        return new WP_Query();
    }
    $current_post = get_post($post_id);
    if (!isset($args['post_type'])) {
        $args['post_type'] = $current_post->post_type;
    }
    $keep_current = (bool) hocwp_get_value_by_key($args, 'keep_current');
    $posts_per_page = hocwp_get_value_by_key($args, 'posts_per_page', hocwp_get_posts_per_page());
    $transient_name = 'hocwp_cache_post_' . $post_id . '_related_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    $cache = isset($args['cache']) ? $args['cache'] : true;
    $query = new WP_Query();
    if (!$cache || $cache && false === ($query = get_transient($transient_name))) {
        $taxonomies = get_post_taxonomies($post_id);
        $defaults = array();
        foreach ($taxonomies as $taxonomy) {
            $tax = get_taxonomy($taxonomy);
            if ((bool) $tax->hierarchical) {
                continue;
            }
            $term_ids = wp_get_post_terms($post_id, $taxonomies, array('fields' => 'ids'));
            if (hocwp_array_has_value($term_ids)) {
                $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids);
                $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults);
            }
        }
        if (hocwp_array_has_value($defaults)) {
            if (!$keep_current) {
                $defaults['post__not_in'] = array($post_id);
            }
            $defaults['tax_query']['relation'] = 'OR';
            $query_args = wp_parse_args($args, $defaults);
            $query = hocwp_query($query_args);
        }
        if (!is_a($query, 'WP_Query')) {
            $query = new WP_Query();
        }
        if ($query->post_count < $posts_per_page) {
            $missing = $posts_per_page - $query->post_count;
            $defaults = array();
            foreach ($taxonomies as $taxonomy) {
                $tax = get_taxonomy($taxonomy);
                if (!(bool) $tax->hierarchical) {
                    continue;
                }
                $term_ids = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'ids'));
                if (hocwp_array_has_value($term_ids)) {
                    $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids);
                    $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults);
                }
            }
            if (!$keep_current) {
                $defaults['post__not_in'] = array($post_id);
            }
            $defaults['tax_query']['relation'] = 'OR';
            $defaults['posts_per_page'] = $missing;
            unset($args['tax_query']);
            $args = wp_parse_args($args, $defaults);
            $cat_query = hocwp_query($args);
            $post_ids = array();
            if (hocwp_array_has_value($query->posts)) {
                foreach ($query->posts as $post) {
                    array_push($post_ids, $post->ID);
                }
            }
            if (hocwp_array_has_value($cat_query->posts)) {
                foreach ($cat_query->posts as $post) {
                    array_push($post_ids, $post->ID);
                }
            }
            $args['posts_per_page'] = $posts_per_page;
            $args['post__in'] = $post_ids;
            $args['orderby'] = 'post__in';
            $query = hocwp_query($args);
        }
        if (!$query->have_posts()) {
            unset($args['post__in']);
            unset($args['tax_query']);
            $args['orderby'] = 'date';
            $args['s'] = $current_post->post_title;
            $query = hocwp_query($args);
        }
        $cache_days = apply_filters('hocwp_related_post_cache_days', 3);
        if (!$query->have_posts()) {
            $cache_days = 1;
        }
        if (($cache || hocwp_is_positive_number($cache)) && $query->have_posts()) {
            if (!hocwp_is_positive_number($cache)) {
                $cache = $cache_days * DAY_IN_SECONDS;
            }
            set_transient($transient_name, $query, $cache);
        }
    }
    return $query;
}
function hocwp_setup_theme_kk_star_rating_legend($legend, $post_id)
{
    $edit = false;
    if (hocwp_string_contain($legend, '[total]')) {
        $edit = true;
    } elseif (hocwp_string_contain($legend, '[avg]')) {
        $edit = true;
    } elseif (hocwp_string_contain($legend, '[per]')) {
        $edit = true;
    } elseif (hocwp_string_contain($legend, '[s]')) {
        $edit = true;
    }
    if ($edit) {
        $id = $post_id;
        $title = get_the_title($id);
        $best = get_option('kksr_stars');
        $score = get_post_meta($id, '_kksr_ratings', true);
        if (!hocwp_is_positive_number($score)) {
            $score = 0;
        }
        if ($score) {
            $votes = get_post_meta($id, '_kksr_casts', true);
            if (!hocwp_is_positive_number($votes)) {
                $votes = 0;
            }
            $avg = $score ? round((double) ($score / $votes * ($best / 5)), 2) : 0;
            $per = $score ? round((double) ($score / $votes / 5 * 100), 2) : 0;
            $leg = str_replace('[total]', '<span property="ratingCount">' . $votes . '</span>', $legend);
            $leg = str_replace('[avg]', '<span property="ratingValue">' . $avg . '</span>', $leg);
            $leg = str_replace('[per]', $per . '%', $leg);
            $leg = str_replace('[s]', $votes == 1 ? '' : 's', $leg);
            $kksr_grs = get_option('kksr_grs');
            if ((bool) $kksr_grs) {
                $snippet = '<div vocab="http://schema.org/" typeof="Blog">';
                $snippet .= '<div property="name" class="kksr-title">' . $title . '</div>';
                $snippet .= '<div property="aggregateRating" typeof="AggregateRating">';
                $snippet .= $leg;
                $snippet .= '<meta property="bestRating" content="' . $best . '"/>';
                $snippet .= '<meta property="worstRating" content="1"/>';
                $snippet .= '</div>';
                $snippet .= '</div>';
                $leg = $snippet;
            }
            $legend = $leg;
        }
    }
    return $legend;
}
Пример #8
0
function hocwp_sanitize_product_price($regular, $sale, $id = '')
{
    $regular_price = '';
    if (hocwp_is_positive_number($regular)) {
        $regular_price = $regular;
    }
    $sale_price = '';
    if (hocwp_is_positive_number($sale) && $sale < $regular_price) {
        $sale_price = $sale;
    }
    $price = $regular_price;
    if (hocwp_is_positive_number($sale_price)) {
        $price = $sale_price;
    }
    $result = array('regular_price' => $regular_price, 'sale_price' => $sale_price, 'price' => $price);
    $result = apply_filters('hocwp_sanitize_product_price', $result, $regular, $sale, $id);
    return $result;
}
Пример #9
0
function hocwp_wc_sale_flash_filter($html, $post, $product)
{
    $use = (bool) get_option('hocwp_product_percentage_sale_flash');
    $use = apply_filters('hocwp_wc_product_percentage_sale_flash', $use, $post, $product);
    if ($use && hocwp_wc_is_sale($product->id) && hocwp_is_positive_number($product->sale_price)) {
        $html = '<span class="onsale">-' . hocwp_percentage($product->regular_price, $product->sale_price) . '%</span>';
    }
    $html = apply_filters('hocwp_wc_sale_flash', $html, $post, $product);
    return $html;
}
Пример #10
0
function hocwp_star_rating_result($args = array())
{
    if (!function_exists('wp_star_rating')) {
        require_once ABSPATH . 'wp-admin/includes/template.php';
    }
    $votes = 0;
    if (!isset($args['rating'])) {
        $id = hocwp_get_value_by_key($args, 'post_id', get_the_ID());
        $score = get_post_meta($id, '_kksr_ratings', true);
        if (!hocwp_is_positive_number($score)) {
            $score = 0;
        }
        if (!isset($args['number'])) {
            $votes = get_post_meta($id, '_kksr_casts', true);
            if (!hocwp_is_positive_number($votes)) {
                $votes = 0;
            }
        }
        $args['number'] = $votes;
        if ($votes != 0) {
            $avg = (double) ($score / $votes);
            $score = $score ? round($avg, 2) : 0;
        }
        $args['rating'] = $score;
    }
    $hide_empty = hocwp_get_value_by_key($args, 'hide_empty');
    if ($hide_empty) {
        $rating = $args['rating'];
        if (!hocwp_is_positive_number($rating)) {
            return;
        }
    }
    $before = hocwp_get_value_by_key($args, 'before');
    echo $before;
    wp_star_rating($args);
    $show_count = hocwp_get_value_by_key($args, 'show_count', true);
    $number = hocwp_get_value_by_key($args, 'number');
    $number = absint($number);
    if ($show_count) {
        echo '<span aria-hidden="true" class="num-ratings">(' . $number . ')</span>';
    }
    $after = hocwp_get_value_by_key($args, 'after');
    echo $after;
}
Пример #11
0
function hocwp_column_width_percentage($column)
{
    $width = '100';
    if (hocwp_is_positive_number($column)) {
        $width = round(100 / $column, 2);
    }
    if ($width > 100) {
        $width = 100;
    }
    $width .= '%';
    return $width;
}
Пример #12
0
function hocwp_post_gallery($args = array())
{
    $galleries = hocwp_get_value_by_key($args, 'galleries');
    $id = hocwp_get_value_by_key($args, 'id');
    $class = hocwp_get_value_by_key($args, 'class');
    hocwp_add_string_with_space_before($class, 'post-gallery module');
    if (!empty($id)) {
        $id = ' id="' . $id . '"';
    }
    $title = hocwp_get_value_by_key($args, 'title');
    if (!hocwp_array_has_value($galleries)) {
        if (is_string($args)) {
            $galleries = hocwp_get_all_image_from_string($args);
        } elseif (is_string($galleries) && !empty($galleries)) {
            $galleries = hocwp_get_all_image_from_string($galleries);
        } else {
            $galleries = $args;
        }
    }
    if (hocwp_array_has_value($galleries)) {
        ?>
		<div<?php 
        echo $id;
        ?>
 class="<?php 
        echo $class;
        ?>
">
			<?php 
        if (!empty($title)) {
            ?>
				<div class="module-header">
					<h4><?php 
            echo $title;
            ?>
</h4>
				</div>
				<?php 
        }
        ?>
			<div class="module-body">
				<div class="galleries">
					<ul class="gallery hocwp-gallery list-unstyled cS-hidden clearfix row">
						<?php 
        $column = hocwp_get_value_by_key($args, 'column');
        if (!hocwp_is_positive_number($column)) {
            $column = 2;
        }
        $pager = '';
        $count = 0;
        foreach ($galleries as $img) {
            $src = hocwp_get_first_image_source($img);
            if (!hocwp_is_image($src)) {
                continue;
            }
            $li = new HOCWP_HTML('li');
            $li->set_text($img);
            $li->set_attribute('data-thumb', $src);
            $li->add_class('col-xs-' . $column);
            $li->output();
        }
        ?>
					</ul>
				</div>
			</div>
		</div>
		<?php 
    }
}