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);
}
Exemple #2
0
function hocwp_crop_image($args = array())
{
    $attachment_id = hocwp_get_value_by_key($args, 'attachment_id');
    $url = hocwp_get_value_by_key($args, 'url');
    $base_url = '';
    if (!hocwp_id_number_valid($attachment_id) && !empty($url)) {
        $attachment_id = hocwp_get_media_id($url);
    }
    if (!hocwp_id_number_valid($attachment_id)) {
        if (empty($url)) {
            return new WP_Error('crop_image_size', __('Attachment ID is not valid.', 'hocwp-theme'));
        } else {
            $cropped = $url;
        }
    } else {
        $file_path = hocwp_get_media_file_path($attachment_id);
        $width = hocwp_get_value_by_key($args, 'width');
        $height = hocwp_get_value_by_key($args, 'height');
        $size = hocwp_get_image_sizes($attachment_id);
        $size = hocwp_sanitize_size($size);
        if (empty($width) && empty($height)) {
            $cropped = $file_path;
        } else {
            if (empty($width)) {
                $width = $size[0];
            }
            if (empty($height)) {
                $height = $size[1];
            }
            $x = apply_filters('hocwp_crop_image_x', 0, $args);
            $y = apply_filters('hocwp_crop_image_y', 0, $args);
            $x = hocwp_get_value_by_key($args, 'x', $x);
            $y = hocwp_get_value_by_key($args, 'y', $y);
            $dest_file = hocwp_get_value_by_key($args, 'dest_file', '');
            $path_info = pathinfo($file_path);
            if (empty($dest_file)) {
                $upload_dir = hocwp_get_upload_folder_details();
                $base_path = apply_filters('hocwp_custom_thumbnail_base_path', untrailingslashit($upload_dir['path']) . '/hocwp/thumbs/', $args);
                if (!file_exists($base_path)) {
                    wp_mkdir_p($base_path);
                }
                $base_url = apply_filters('hocwp_custom_thumbnail_base_url', untrailingslashit($upload_dir['url']) . '/hocwp/thumbs/', $args);
                $filename = $path_info['filename'];
                $dest_file = $base_path . str_replace($filename, $filename . '-' . $width . '-' . $height, basename($file_path));
            }
            $crop_args = array('source' => get_attached_file($attachment_id), 'dest' => $dest_file, 'width' => $width, 'height' => $height, 'x' => $x, 'y' => $y);
            $crop_args = wp_parse_args($args, $crop_args);
            if (file_exists($dest_file)) {
                $override = hocwp_get_value_by_key($args, 'override', false);
                if ($override) {
                    unlink($dest_file);
                    $cropped = hocwp_crop_image_helper($crop_args);
                } else {
                    $cropped = $dest_file;
                }
            } else {
                $cropped = hocwp_crop_image_helper($crop_args);
            }
        }
    }
    if (file_exists($cropped)) {
        $output = hocwp_get_value_by_key($args, 'output', 'url');
        if ('url' == $output) {
            $cropped = hocwp_media_path_to_url($attachment_id, $cropped, $base_url);
        }
    } else {
        $cropped = $url;
    }
    return apply_filters('hocwp_crop_image', $cropped, $args);
}
Exemple #3
0
function hocwp_post_thumbnail($args = array())
{
    $post_id = isset($args['post_id']) ? $args['post_id'] : '';
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    if (post_password_required($post_id) || is_attachment()) {
        return;
    }
    $args['post_id'] = $post_id;
    $transient_name = hocwp_build_transient_name('hocwp_cache_post_thumbnail_%s', $args);
    if (false === ($html = get_transient($transient_name))) {
        $cache = hocwp_get_value_by_key($args, 'cache', HOUR_IN_SECONDS);
        $thumbnail_url = hocwp_get_value_by_key($args, 'thumbnail_url');
        if (empty($thumbnail_url)) {
            $large_size = hocwp_get_value_by_key($args, 'large_size');
            if ($large_size) {
                $thumbnail_url = get_post_meta($post_id, 'large_thumbnail', true);
                $thumbnail_url = hocwp_sanitize_media_value($thumbnail_url);
                $thumbnail_url = $thumbnail_url['url'];
                if (empty($thumbnail_url)) {
                    $thumbnail_url = hocwp_get_post_thumbnail_url($post_id);
                }
            } else {
                $thumbnail_url = hocwp_get_post_thumbnail_url($post_id);
            }
        }
        if (empty($thumbnail_url)) {
            return;
        }
        $bfi_thumb = isset($args['bfi_thumb']) ? $args['bfi_thumb'] : true;
        $bfi_thumb = apply_filters('hocwp_use_bfi_thumb', $bfi_thumb, $post_id);
        $size = hocwp_sanitize_size($args);
        $width = $size[0];
        $height = $size[1];
        $enlarge = apply_filters('hocwp_enlarge_post_thumbnail_on_mobile', false);
        if ($enlarge && wp_is_mobile()) {
            $ratio = 600 / $width;
            $ratio = round($ratio);
            if ($ratio > 1) {
                $width *= $ratio;
                $height *= $ratio;
            }
        }
        $original = $thumbnail_url;
        if ($bfi_thumb) {
            $params = isset($args['params']) ? $args['params'] : array();
            if (is_numeric($width) && $width > 0) {
                $params['width'] = $width;
            }
            if (is_numeric($height) && $height > 0) {
                $params['height'] = $height;
            }
            $bfi_url = apply_filters('hocwp_pre_bfi_thumb', '', $thumbnail_url, $params);
            if (empty($bfi_url)) {
                if ($width > 0 || $height > 0) {
                    $bfi_url = bfi_thumb($thumbnail_url, $params);
                }
            }
            if (!empty($bfi_url)) {
                $thumbnail_url = $bfi_url;
            }
        }
        $img = new HOCWP_HTML('img');
        if (is_numeric($width) && $width > 0) {
            $img->set_attribute('width', $size[0]);
        }
        if (is_numeric($height) && $height > 0) {
            $img->set_attribute('height', $size[1]);
        }
        $img->set_attribute('data-original', $original);
        $lazyload = hocwp_get_value_by_key($args, 'lazyload', false);
        $img->set_attribute('alt', get_the_title($post_id));
        $img->set_class('attachment-post-thumbnail wp-post-image img-responsive');
        $img->set_attribute('src', $thumbnail_url);
        $centered = (bool) hocwp_get_value_by_key($args, 'centered', false);
        if ($centered) {
            $img->add_class('centered');
        }
        $bk_img = '';
        if ((bool) $lazyload) {
            $img->set_wrap_tag('noscript');
            $bk_img = $img->build();
            $img->set_wrap_tag('');
            $loading_icon = hocwp_get_value_by_key($args, 'loading_icon');
            if (!hocwp_is_image($loading_icon)) {
                $loading_icon = hocwp_get_image_url('transparent.gif');
            }
            $img->set_image_src($loading_icon);
            $img->set_attribute('data-original', $thumbnail_url);
            $img->add_class('lazyload');
        }
        $only_image = hocwp_get_value_by_key($args, 'only_image');
        if ((bool) $only_image) {
            $html = $img->build();
            if ((bool) $lazyload) {
                $html = $bk_img;
            }
        } else {
            $before = hocwp_get_value_by_key($args, 'before');
            $after = hocwp_get_value_by_key($args, 'after');
            $permalink = hocwp_get_value_by_key($args, 'permalink', get_permalink($post_id));
            $loop = isset($args['loop']) ? $args['loop'] : true;
            $custom_html = isset($args['custom_html']) ? $args['custom_html'] : '';
            $icon_video = hocwp_get_value_by_key($args, 'icon_video');
            if (true === $icon_video) {
                $icon_video = '<i class="fa fa-play-circle-o" aria-hidden="true"></i>';
            }
            $fancybox = (bool) hocwp_get_value_by_key($args, 'fancybox');
            $a = new HOCWP_HTML('a');
            $a->set_href($permalink);
            if (!empty($icon_video) && is_string($icon_video) && empty($custom_html)) {
                $a->set_text($icon_video);
                $custom_html = $a->build();
            }
            $icon_image = hocwp_get_value_by_key($args, 'icon_image');
            if (true === $icon_image) {
                $icon_image = '<i class="fa fa-camera" aria-hidden="true"></i>';
            }
            if (!empty($icon_image) && is_string($icon_image) && empty($custom_html)) {
                $a->set_text($icon_image);
                $custom_html = $a->build();
            }
            $cover = hocwp_get_value_by_key($args, 'cover');
            $schema = '';
            if (current_theme_supports('hocwp-schema')) {
                ob_start();
                ?>
				<meta itemprop="url" content="<?php 
                echo $thumbnail_url;
                ?>
">
				<meta itemprop="width" content="<?php 
                echo $width;
                ?>
">
				<meta itemprop="height" content="<?php 
                echo $height;
                ?>
">
				<?php 
                $schema = ob_get_clean();
            }
            $html = $before;
            if (is_singular() && !$loop) {
                ob_start();
                ?>
				<div class="post-thumbnail entry-thumb"<?php 
                hocwp_html_tag_attributes('div', 'entry_thumb');
                ?>
>
					<?php 
                $img->output();
                if ((bool) $lazyload) {
                    echo $bk_img;
                }
                echo $custom_html;
                echo $schema;
                ?>
				</div>
				<?php 
                $html = ob_get_clean();
            } else {
                if (!empty($custom_html)) {
                    $html .= '<div class="thumbnail-wrap">';
                }
                $class = 'post-thumbnail-loop entry-thumb post-thumbnail';
                $atts = '';
                if ($fancybox) {
                    hocwp_add_string_with_space_before($class, 'fancybox');
                    $atts = ' data-fancybox-group="gallery"';
                    $atts .= ' rel="gallery"';
                    $permalink = $original;
                }
                ob_start();
                ?>
				<a class="<?php 
                echo $class;
                ?>
"<?php 
                echo $atts;
                ?>
 href="<?php 
                echo $permalink;
                ?>
"
				   aria-hidden="true"<?php 
                hocwp_html_tag_attributes('a', 'entry_thumb');
                ?>
>
					<?php 
                $img->output();
                if ((bool) $lazyload) {
                    echo $bk_img;
                }
                if ($cover) {
                    echo '<span class="cover"></span>';
                }
                echo $schema;
                ?>
				</a>
				<?php 
                $html .= ob_get_clean();
                $html .= $custom_html;
                if (!empty($custom_html)) {
                    $html .= '</div>';
                }
            }
            $html .= $after;
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, $cache);
        }
    }
    echo $html;
}
 public function widget($args, $instance)
 {
     $this->instance = $instance;
     $before_widget = hocwp_get_value_by_key($args, 'before_widget');
     $taxonomy = $this->get_taxonomy_from_instance($instance);
     $taxonomies = array();
     $widget_class = '';
     foreach ($taxonomy as $tax) {
         $tax = hocwp_get_value_by_key($tax, 'value');
         if (!empty($tax)) {
             $taxonomies[] = $tax;
             hocwp_add_string_with_space_before($widget_class, hocwp_sanitize_html_class($tax));
         }
     }
     $before_widget = hocwp_add_class_to_string('', $before_widget, $widget_class);
     $args['before_widget'] = $before_widget;
     $in_current_post = (bool) hocwp_get_value_by_key($instance, 'in_current_post', hocwp_get_value_by_key($this->args, 'in_current_post'));
     if ($in_current_post && (!is_singular() || is_page())) {
         return;
     }
     if ($in_current_post) {
         $post_id = get_the_ID();
         $current_post = get_post($post_id);
         $obj_taxs = get_object_taxonomies($current_post->post_type);
         $has_tax = false;
         foreach ($taxonomies as $tax) {
             foreach ($obj_taxs as $tax_name) {
                 if ($tax == $tax_name) {
                     $has_tax = true;
                     break;
                 }
             }
         }
         if (!$has_tax) {
             return;
         }
         $before_widget = hocwp_add_class_to_string('', $before_widget, 'in-current-post');
         $args['before_widget'] = $before_widget;
     }
     $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number'));
     if (0 > $number) {
         $number = 0;
     }
     $thumbnail_size = hocwp_get_value_by_key($instance, 'thumbnail_size', hocwp_get_value_by_key($this->args, 'thumbnail_size'));
     $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
     $full_width_item = hocwp_get_value_by_key($instance, 'full_width_item', hocwp_get_value_by_key($this->args, 'full_width_item'));
     $show_count = hocwp_get_value_by_key($instance, 'show_count', hocwp_get_value_by_key($this->args, 'show_count'));
     $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail'));
     $only_thumbnail = hocwp_get_value_by_key($instance, 'only_thumbnail', hocwp_get_value_by_key($this->args, 'only_thumbnail'));
     $order = hocwp_get_value_by_key($instance, 'order', hocwp_get_value_by_key($this->args, 'order'));
     $orderby = hocwp_get_value_by_key($instance, 'orderby', hocwp_get_value_by_key($this->args, 'orderby'));
     $count_format = hocwp_get_value_by_key($instance, 'count_format', hocwp_get_value_by_key($this->args, 'count_format'));
     $different_name = (bool) hocwp_get_value_by_key($instance, 'different_name', hocwp_get_value_by_key($this->args, 'different_name'));
     $hide_empty = hocwp_get_value_by_key($instance, 'hide_empty', hocwp_get_value_by_key($this->args, 'hide_empty'));
     $only_parent = hocwp_get_value_by_key($instance, 'only_parent', hocwp_get_value_by_key($this->args, 'only_parent'));
     $child_of_current = hocwp_get_value_by_key($instance, 'child_of_current', hocwp_get_value_by_key($this->args, 'child_of_current'));
     $child_of_parent = hocwp_get_value_by_key($instance, 'child_of_parent', hocwp_get_value_by_key($this->args, 'child_of_parent'));
     $parent_as_title = hocwp_get_value_by_key($instance, 'parent_as_title', hocwp_get_value_by_key($this->args, 'parent_as_title'));
     if ($hide_thumbnail) {
         $only_thumbnail = false;
     }
     $defaults = array('order' => $order, 'orderby' => $orderby, 'number' => absint($number));
     if (0 == $hide_empty || !(bool) $hide_empty) {
         $defaults['hide_empty'] = 0;
     } else {
         $defaults['hide_empty'] = 1;
     }
     if ($only_parent) {
         $defaults['parent'] = 0;
     }
     if ($in_current_post && is_singular()) {
         $terms = wp_get_post_terms(get_the_ID(), $taxonomies);
     } elseif (($child_of_current || $child_of_parent) && is_tax()) {
         $current_term = hocwp_term_get_current();
         $tax_args = array('child_of' => $current_term->term_id);
         $tax_args = wp_parse_args($tax_args, $defaults);
         unset($tax_args['parent']);
         $terms = hocwp_get_terms($current_term->taxonomy, $tax_args);
         if ($child_of_parent) {
             if (!hocwp_array_has_value($terms) && hocwp_id_number_valid($current_term->parent)) {
                 $parent = hocwp_term_get_top_most_parent($current_term);
                 $tax_args['child_of'] = $parent->term_id;
                 $terms = hocwp_get_terms($parent->taxonomy, $tax_args);
             }
         }
     } else {
         $terms = hocwp_get_terms($taxonomies, $defaults);
     }
     if (($in_current_post || $child_of_current) && !hocwp_array_has_value($terms)) {
         return;
     }
     if ($parent_as_title && is_tax()) {
         $current_term = hocwp_term_get_current();
         if (hocwp_id_number_valid($current_term->parent)) {
             $parent = hocwp_term_get_top_most_parent($current_term);
             $instance['title'] = $parent->name;
         } elseif ($child_of_current) {
             $instance['title'] = $current_term->name;
         }
     }
     hocwp_widget_before($args, $instance);
     ob_start();
     if (hocwp_array_has_value($terms)) {
         $count_terms = count($terms);
         $html = '<ul class="list-unstyled list-terms">';
         $count = 0;
         foreach ($terms as $term) {
             $item_class = 'term-item';
             hocwp_add_string_with_space_before($item_class, hocwp_sanitize_html_class('tax-' . $term->taxonomy));
             if (!(bool) $hide_thumbnail) {
                 hocwp_add_string_with_space_before($item_class, 'show-thumbnail');
             }
             if ((bool) $only_thumbnail) {
                 hocwp_add_string_with_space_before($item_class, 'only-thumbnail');
             }
             $full_width = hocwp_widget_item_full_width_result($full_width_item, $count_terms, $count);
             if ($full_width) {
                 hocwp_add_string_with_space_before($item_class, 'full-width');
             }
             if ((bool) $show_count) {
                 hocwp_add_string_with_space_before($item_class, 'show-count');
             } else {
                 hocwp_add_string_with_space_before($item_class, 'no-count');
             }
             $html .= '<li class="' . $item_class . '">';
             if (!(bool) $hide_thumbnail) {
                 $html .= hocwp_term_get_thumbnail_html(array('term' => $term, 'width' => $thumbnail_size[0], $thumbnail_size[1], 'bfi_thumb' => false));
             }
             if (!(bool) $only_thumbnail) {
                 $term_name = $term->name;
                 if ($different_name) {
                     $term_name = hocwp_term_get_name($term);
                 }
                 $html .= '<a class="term-name" href="' . get_term_link($term) . '">' . $term_name . '</a>';
                 if ((bool) $show_count && !empty($count_format)) {
                     $html .= ' <span class="count">' . str_replace('%TERM_COUNT%', $term->count, $count_format) . '</span>';
                 }
             }
             $html .= '</li>';
             $count++;
         }
         $html .= '</ul>';
         echo $html;
     } else {
         _e('Sorry, nothing found.', 'hocwp-theme');
     }
     $widget_html = ob_get_clean();
     $widget_html = apply_filters('hocwp_widget_term_html', $widget_html, $args, $instance, $this);
     echo $widget_html;
     hocwp_widget_after($args, $instance);
 }
    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;
    }
function hocwp_wc_single_product_image_html($html, $post_id)
{
    $thumbnail_zoom = hocwp_wc_single_product_thumbnail_zooming();
    if ($thumbnail_zoom) {
        global $post, $product;
        if (has_post_thumbnail()) {
            $image_ids = $product->get_gallery_attachment_ids();
            $count = count($image_ids);
            $gallery = $count > 0 ? '[product-gallery]' : '';
            $thumb_id = get_post_thumbnail_id();
            $props = wc_get_product_attachment_props($thumb_id, $post);
            $image_url = $props['url'];
            $size = get_option('shop_single_image_size');
            $size = hocwp_sanitize_size($size);
            $size = apply_filters('single_product_large_thumbnail_size', $size);
            $args = array('title' => $props['title'], 'alt' => $props['alt']);
            $image = get_the_post_thumbnail($post, 'full', $args);
            $html = sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto%s">%s</a>', esc_url($image_url), esc_attr($props['caption']), $gallery, $image);
            $html = apply_filters('hocwp_wc_single_product_image_html', $html, $post->ID);
        }
    }
    return $html;
}
function hocwp_field_size($args = array())
{
    $args = hocwp_field_sanitize_args($args);
    $field_class = $args['class'];
    $id_width = isset($args['id_width']) ? $args['id_width'] : '';
    $id_height = isset($args['id_height']) ? $args['id_height'] : '';
    $name_width = isset($args['name_width']) ? $args['name_width'] : '';
    $name_height = isset($args['name_height']) ? $args['name_height'] : '';
    $value = isset($args['value']) ? (array) $args['value'] : array(0, 0);
    $value = hocwp_sanitize_size($value);
    if (!hocwp_array_has_value($value)) {
        $value = array(0, 0);
    }
    hocwp_add_string_with_space_before($field_class, 'hocwp-number image-size');
    $sep = isset($args['sep']) ? $args['sep'] : '<span>x</span>';
    $id = explode('_', $id_width);
    $id = hocwp_sanitize_array($id);
    //$last = array_pop($id);
    $args['id'] = implode('_', $id);
    $args['label_class'] = 'label-input-size';
    hocwp_field_before($args);
    $input_args = array('id' => $id_width, 'field_class' => $field_class, 'name' => $name_width, 'autocomplete' => false, 'value' => isset($value[0]) ? $value[0] : 0, 'only' => true);
    hocwp_field_input_number($input_args);
    echo $sep;
    $input_args['id'] = $id_height;
    $input_args['name'] = $name_height;
    $input_args['value'] = isset($value[1]) ? $value[1] : (isset($value[0]) ? $value[0] : 0);
    hocwp_field_input_number($input_args);
    hocwp_field_after($args);
}
Exemple #8
0
function hocwp_term_get_thumbnail_html($args = array())
{
    $thumb_url = hocwp_term_get_thumbnail_url($args);
    $result = '';
    $term = hocwp_get_value_by_key($args, 'term');
    if (!empty($thumb_url)) {
        $taxonomy = hocwp_get_value_by_key($args, 'taxonomy');
        if (!is_a($term, 'WP_Term')) {
            $term_id = hocwp_get_value_by_key($args, 'term_id');
            if (hocwp_id_number_valid($term_id) && !empty($taxonomy)) {
                $term = get_term($term_id, $taxonomy);
            }
        }
        if (is_a($term, 'WP_Term')) {
            $taxonomy = $term->taxonomy;
            $size = hocwp_sanitize_size($args);
            $link = hocwp_get_value_by_key($args, 'link', true);
            $show_name = hocwp_get_value_by_key($args, 'show_name');
            $img = new HOCWP_HTML('img');
            $img->set_image_src($thumb_url);
            if ($size[0] > 0) {
                $img->set_attribute('width', $size[0]);
            }
            if ($size[1] > 0) {
                $img->set_attribute('height', $size[1]);
            }
            $class = 'img-responsive wp-term-image';
            $slug = $term->taxonomy;
            hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($slug) . '-thumb');
            $img->set_class($class);
            $link_text = $img->build();
            if ((bool) $show_name) {
                $link_text .= '<span class="term-name">' . $term->name . '</span>';
            }
            $a = new HOCWP_HTML('a');
            $a->set_class('term-link ' . hocwp_sanitize_html_class($taxonomy));
            $a->set_text($link_text);
            $a->set_attribute('title', $term->name);
            $a->set_href(get_term_link($term));
            if (!(bool) $link) {
                $result = $img->build();
            } else {
                $result = $a->build();
            }
        }
    }
    return apply_filters('hocwp_term_thumbnail_html', $result, $term);
}