Beispiel #1
0
function hocwp_loading_image($args = array())
{
    $name = hocwp_get_value_by_key($args, 'name', 'icon-loading-circle-16.gif');
    $class = hocwp_get_value_by_key($args, 'class');
    hocwp_add_string_with_space_before($class, 'img-loading');
    $alt = hocwp_get_value_by_key($args, 'alt');
    $display = hocwp_get_value_by_key($args, 'display', 'none');
    $style = 'display: ' . $display;
    $img = new HOCWP_HTML('img');
    $image_url = hocwp_get_image_url($name);
    $img->set_image_alt($alt);
    $img->set_class($class);
    $img->set_attribute('style', $style);
    $img->set_image_src($image_url);
    $img->output();
}
    public function widget($args, $instance)
    {
        $this->instance = $instance;
        $page_name = isset($instance['page_name']) ? $instance['page_name'] : '';
        $href = isset($instance['href']) ? $instance['href'] : '';
        $width = isset($instance['width']) ? $instance['width'] : $this->args['width'];
        $height = isset($instance['height']) ? $instance['height'] : $this->args['height'];
        $hide_cover = (bool) (isset($instance['hide_cover']) ? $instance['hide_cover'] : $this->args['hide_cover']);
        $show_facepile = (bool) (isset($instance['show_facepile']) ? $instance['show_facepile'] : $this->args['show_facepile']);
        $hide_cta = (bool) (isset($instance['hide_cta']) ? $instance['hide_cta'] : $this->args['hide_cta']);
        $small_header = (bool) (isset($instance['small_header']) ? $instance['small_header'] : $this->args['small_header']);
        $adapt_container_width = (bool) (isset($instance['adapt_container_width']) ? $instance['adapt_container_width'] : $this->args['adapt_container_width']);
        $fixed = hocwp_get_value_by_key($instance, 'fixed', $this->args['fixed']);
        $only_link = hocwp_get_value_by_key($instance, 'only_link', $this->args['only_link']);
        $button_text = hocwp_get_value_by_key($instance, 'button_text', $this->args['button_text']);
        $before_widget = hocwp_get_value_by_key($args, 'before_widget');
        $widget_class = '';
        if ($fixed) {
            hocwp_add_string_with_space_before($widget_class, 'fixed');
            $position = hocwp_get_value_by_key($instance, 'position', $this->args['position']);
            hocwp_add_string_with_space_before($widget_class, hocwp_sanitize_html_class($position));
        }
        $before_widget = hocwp_add_class_to_string('', $before_widget, $widget_class);
        $args['before_widget'] = $before_widget;
        $img = new HOCWP_HTML('img');
        $img->set_image_src(hocwp_get_image_url('icon-facebook-messenger-white-64.png'));
        $img->set_class('icon-messenger');
        hocwp_widget_before($args, $instance);
        if ($only_link) {
            if (!hocwp_is_url($href)) {
                $href = 'https://m.me/' . $href;
            }
            $span = new HOCWP_HTML('span');
            $span->set_text($button_text);
            $link_text = $img->build();
            $link_text .= $span->build();
            $a = new HOCWP_HTML('a');
            $a->add_class('button btn btn-facebook-messenger');
            $a->set_text($link_text);
            $a->set_href($href);
            $widget_html = $a->build();
        } else {
            $app_id = hocwp_get_wpseo_social_facebook_app_id();
            if (empty($app_id)) {
                hocwp_debug_log(__('Please set your Facebook APP ID first.', 'hocwp-theme'));
                return;
            }
            add_filter('hocwp_use_facebook_javascript_sdk', '__return_true');
            ?>
			<script type="text/javascript">
				window.fbAsyncInit = function () {
					FB.init({
						appId: '<?php 
            echo $app_id;
            ?>
',
						cookie: true,
						xfbml: true,
						version: 'v<?php 
            echo HOCWP_FACEBOOK_JAVASCRIPT_SDK_VERSION;
            ?>
'
					});
				};
			</script>
			<?php 
            $fanpage_args = array('page_name' => $page_name, 'href' => $href, 'width' => $width, 'height' => $height, 'tabs' => 'messages', 'hide_cover' => $hide_cover, 'show_facepile' => $show_facepile, 'hide_cta' => $hide_cta, 'small_header' => $small_header, 'adapt_container_width' => $adapt_container_width);
            ob_start();
            if ($fixed) {
                $fanpage_args['width'] = 300;
                ?>
				<div class="messenger-box module">
					<div class="module-header heading btn-facebook-messenger" title="<?php 
                echo $button_text;
                ?>
">
						<?php 
                $img->output();
                ?>
						<label><?php 
                echo $button_text;
                ?>
</label>
						<?php 
                if ('left' == $position || 'right' == $position) {
                    echo '<i class="fa fa-times" aria-hidden="true"></i>';
                    $span = new HOCWP_HTML('span');
                    $span->add_class('facebook-messenger-box-control');
                    $span->set_text($img);
                    $span->output();
                } else {
                    echo '<i class="fa fa-angle-up" aria-hidden="true"></i>';
                }
                ?>
					</div>
					<div class="module-body">
						<?php 
                hocwp_facebook_page_plugin($fanpage_args);
                ?>
					</div>
				</div>
				<?php 
            } else {
                hocwp_facebook_page_plugin($fanpage_args);
            }
            $widget_html = ob_get_clean();
        }
        $widget_html = apply_filters('hocwp_widget_facebook_messenger_html', $widget_html, $args, $instance, $this);
        echo $widget_html;
        hocwp_widget_after($args, $instance);
    }
Beispiel #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>';
        }
    }
}
Beispiel #4
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;
}
Beispiel #5
0
function hocwp_media_mime_type_icon($icon, $mime)
{
    $change_icon = apply_filters('hocwp_use_custom_mime_type_icon', false);
    if ($change_icon) {
        switch ($mime) {
            case 'application/pdf':
                $icon = hocwp_get_image_url('mime-types/icon-pdf.png');
                break;
            case 'application/vnd.ms-word.document.macroEnabled.12':
            case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
            case 'application/vnd.ms-word.template.macroEnabled.12':
            case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
            case 'application/msword':
                $icon = hocwp_get_image_url('mime-types/icon-doc.png');
                break;
            case 'application/rar':
                $icon = hocwp_get_image_url('mime-types/icon-rar.png');
                break;
            case 'application/zip':
                $icon = hocwp_get_image_url('mime-types/icon-zip.png');
                break;
            case 'application/x-gzip':
                $icon = hocwp_get_image_url('mime-types/icon-gz.png');
                break;
            case 'application/x-7z-compressed':
                $icon = hocwp_get_image_url('mime-types/icon-7z.png');
                break;
            case 'application/vnd.ms-excel.addin.macroEnabled.12':
            case 'application/vnd.ms-excel.template.macroEnabled.12':
            case 'application/vnd.ms-excel.sheet.binary.macroEnabled.12':
            case 'application/vnd.ms-excel.sheet.macroEnabled.12':
            case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
            case 'application/vnd.ms-excel':
                $icon = hocwp_get_image_url('mime-types/icon-xls.png');
                break;
        }
    }
    return $icon;
}
function hocwp_default_script_localize_object()
{
    $datepicker_icon = apply_filters('hocwp_datepicker_icon', HOCWP_URL . '/images/icon-datepicker-calendar.gif');
    $shortcodes = hocwp_get_all_shortcodes();
    $args = array('ajax_url' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('hocwp_nonce'), 'datepicker_icon' => $datepicker_icon, 'shortcodes' => $shortcodes, 'logged_in' => hocwp_bool_to_int(is_user_logged_in()), 'i18n' => array('jquery_undefined_error' => __('HocWP\'s JavaScript requires jQuery', 'hocwp-theme'), 'jquery_version_error' => sprintf(__('HocWP\'s JavaScript requires jQuery version %s or higher', 'hocwp-theme'), HOCWP_MINIMUM_JQUERY_VERSION), 'insert_media_title' => __('Insert media', 'hocwp-theme'), 'insert_media_button_text' => __('Use this media', 'hocwp-theme'), 'insert_media_button_texts' => __('Use these medias', 'hocwp-theme'), 'confirm_message' => __('Are you sure?', 'hocwp-theme'), 'disconnect_confirm_message' => __('Are you sure you want to disconnect?', 'hocwp-theme'), 'delete_confirm_message' => __('Are you sure you want to delete this?', 'hocwp-theme'), 'processing_text' => __('Processing...', 'hocwp-theme'), 'max_file_item_select_error' => __('You can not select more than %s files.', 'hocwp-theme')), 'ajax_loading' => '<p class="ajax-wrap"><img class="ajax-loading" src="' . hocwp_get_image_url('icon-loading-circle-light-full.gif') . '" alt=""></p>');
    return apply_filters('hocwp_default_script_object', $args);
}
Beispiel #7
0
function hocwp_term_get_thumbnail_url($args = array())
{
    if (hocwp_id_number_valid($args)) {
        $term_id = $args;
    } else {
        $term_id = hocwp_get_value_by_key($args, 'term_id');
    }
    $term = hocwp_get_value_by_key($args, 'term');
    if (!hocwp_id_number_valid($term_id)) {
        if (is_a($term, 'WP_Term')) {
            $term_id = $term->term_id;
        }
    }
    if (!hocwp_id_number_valid($term_id)) {
        $term_id = 0;
    }
    $value = get_term_meta($term_id, 'thumbnail', true);
    $use_default_term_thumbnail = apply_filters('hocwp_use_default_term_thumbnail', hocwp_get_value_by_key($args, 'use_default_thumbnail', true));
    $value = hocwp_sanitize_media_value($value);
    $value = $value['url'];
    $icon = false;
    if (empty($value)) {
        $icon_url = hocwp_get_term_icon($term_id);
        $value = $icon_url;
        if (!empty($value)) {
            $icon = true;
        }
    }
    if (!$icon) {
        if (empty($value)) {
            $from_parent = hocwp_get_value_by_key($args, 'from_parent');
            if ((bool) $from_parent) {
                $value = hocwp_term_get_thumbnail_url_helper($term, true);
            }
        }
        if (empty($value) && (bool) $use_default_term_thumbnail) {
            $value = hocwp_get_image_url('no-thumbnail.png');
        }
        $bfi_thumb = hocwp_get_value_by_key($args, 'bfi_thumb', true);
        if ((bool) $bfi_thumb) {
            $size = hocwp_sanitize_size($args);
            $params = array();
            $width = $size[0];
            if (hocwp_id_number_valid($width)) {
                $params['width'] = $width;
            }
            $height = $size[1];
            if (hocwp_id_number_valid($height)) {
                $params['height'] = $height;
            }
            $crop = hocwp_get_value_by_key($args, 'crop', true);
            $params['crop'] = $crop;
            if ($width > 0 || $height > 0) {
                $value = bfi_thumb($value, $params);
            }
        }
    }
    return apply_filters('hocwp_term_thumbnail', $value, $term_id);
}