public function form($instance) { $this->instance = $instance; $title = hocwp_get_value_by_key($instance, 'title'); $icon = hocwp_get_value_by_key($instance, 'icon'); $icon = hocwp_sanitize_media_value($icon); $icon_hover = hocwp_get_value_by_key($instance, 'icon_hover'); $icon_hover = hocwp_sanitize_media_value($icon_hover); $icon_html = hocwp_get_value_by_key($instance, 'icon_html'); $link = hocwp_get_value_by_key($instance, 'link'); $text = hocwp_get_value_by_key($instance, 'text'); $title_link = hocwp_get_value_by_key($instance, 'title_link', hocwp_get_value_by_key($this->args, 'title_link')); hocwp_field_widget_before($this->admin_args['class']); hocwp_widget_field_title($this->get_field_id('title'), $this->get_field_name('title'), $title); $args = array('id' => $this->get_field_id('icon'), 'name' => $this->get_field_name('icon'), 'value' => $icon['url'], 'label' => __('Icon:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_media_upload', $args); $args = array('id' => $this->get_field_id('icon_hover'), 'name' => $this->get_field_name('icon_hover'), 'value' => $icon_hover['url'], 'label' => __('Icon hover:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_media_upload', $args); $args = array('id' => $this->get_field_id('icon_html'), 'name' => $this->get_field_name('icon_html'), 'value' => $icon_html, 'label' => __('Icon HTML:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_text', $args); $args = array('id' => $this->get_field_id('link'), 'name' => $this->get_field_name('link'), 'value' => $link, 'label' => __('Link:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_text', $args); $args = array('id' => $this->get_field_id('text'), 'name' => $this->get_field_name('text'), 'value' => $text, 'label' => __('Text:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_textarea', $args); $args = array('id' => $this->get_field_id('title_link'), 'name' => $this->get_field_name('title_link'), 'value' => $title_link, 'label' => __('Display title as link?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); hocwp_field_widget_after(); }
function hocwp_get_login_logo_url() { $user_login = hocwp_option_get_object_from_list('user_login'); $url = ''; if (hocwp_object_valid($user_login)) { $option = $user_login->get(); $logo = hocwp_get_value_by_key($option, 'logo'); $logo = hocwp_sanitize_media_value($logo); $url = $logo['url']; } if (empty($url)) { $theme_setting = hocwp_option_get_object_from_list('theme_setting'); if (hocwp_object_valid($theme_setting)) { $option = $theme_setting->get(); $logo = hocwp_get_value_by_key($option, 'logo'); $logo = hocwp_sanitize_media_value($logo); $url = $logo['url']; } } return $url; }
public function widget($args, $instance) { $this->instance = $instance; $title_text = isset($instance['title']) ? $instance['title'] : ''; $first_char = hocwp_get_first_char($title_text); if ('!' === $first_char) { $title_text = ltrim($title_text, '!'); } $banner_image = isset($instance['banner_image']) ? $instance['banner_image'] : ''; $banner_url = isset($instance['banner_url']) ? $instance['banner_url'] : ''; $banner_image = hocwp_sanitize_media_value($banner_image); $banner_image = $banner_image['url']; if (!empty($banner_image)) { hocwp_widget_before($args, $instance); $img = new HOCWP_HTML('img'); $img->set_image_src($banner_image); $img->set_image_alt($title_text); $img->set_class('hocwp-banner-image'); $html = $img->build(); if (!empty($banner_url)) { $a = new HOCWP_HTML('a'); $a->set_class('hocwp-banner-link'); $a->set_attribute('title', $title_text); $a->set_href($banner_url); $a->set_text($html); $nofollow = hocwp_get_value_by_key($instance, 'nofollow', hocwp_get_value_by_key($this->args, 'nofollow')); if ((bool) $nofollow) { $a->set_attribute('rel', 'nofollow'); } $html = $a->build(); } $widget_html = apply_filters('hocwp_widget_banner_html', $html, $args, $instance, $this); echo $widget_html; hocwp_widget_after($args, $instance); } }
function hocwp_sanitize_bookmark_link_image($bookmarks) { if (!is_array($bookmarks)) { return $bookmarks; } foreach ($bookmarks as $bookmark) { $thumbnail = hocwp_get_link_meta($bookmark->link_id, 'thumbnail'); $thumbnail = hocwp_sanitize_media_value($thumbnail); $thumbnail = $thumbnail['url']; if (!empty($thumbnail)) { $bookmark->link_image = $thumbnail; } } return $bookmarks; }
function hocwp_get_footer_logo_url() { $result = hocwp_theme_get_option('footer_logo'); $result = hocwp_sanitize_media_value($result); $result = $result['url']; return $result; }
function hocwp_show_ads($args = array()) { $ads = $args; $position = ''; if (!is_object($args)) { if (!is_array($args)) { $args = array('position' => $args); } $position = hocwp_get_value_by_key($args, 'position'); if (!empty($position)) { $random = (bool) hocwp_get_value_by_key($args, 'random'); $current_datetime = date(hocwp_get_date_format()); $current_datetime = strtotime($current_datetime); $query_args = array('post_type' => 'hocwp_ads', 'posts_per_page' => 1, 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('key' => 'expire', 'compare' => 'NOT EXISTS'), array('key' => 'expire', 'value' => '', 'compare' => '='), array('key' => 'expire', 'value' => 0, 'type' => 'numeric'), array('key' => 'expire', 'value' => $current_datetime, 'type' => 'numeric', 'compare' => '>=')), array('key' => 'active', 'value' => 1, 'type' => 'numeric'))); if ($random) { $query_args['orderby'] = 'rand'; } $ads = hocwp_get_post_by_meta('position', $position, $query_args); if ($ads->have_posts()) { $posts = $ads->posts; $ads = array_shift($posts); } } } if (hocwp_is_post($ads) && 'hocwp_ads' == $ads->post_type) { $code = hocwp_get_post_meta('code', $ads->ID); if (empty($code)) { $image = hocwp_get_post_meta('image', $ads->ID); $image = hocwp_sanitize_media_value($image); $image = $image['url']; if (!empty($image)) { $img = new HOCWP_HTML('img'); $img->set_image_src($image); $url = hocwp_get_post_meta('url', $ads->ID); if (!empty($url)) { $a = new HOCWP_HTML('a'); $a->set_href($url); $a->set_text($img); $code = $a->build(); } else { $code = $img->build(); } } } if (!empty($code)) { $class = hocwp_get_value_by_key($args, 'class'); hocwp_add_string_with_space_before($class, 'hocwp-ads text-center ads'); if (!empty($position)) { hocwp_add_string_with_space_before($class, 'position-' . $position); $position = hocwp_sanitize_html_class($position); $class = hocwp_add_more_class($class, $position); } hocwp_add_string_with_space_before($class, $ads->post_name); $div = new HOCWP_HTML('div'); $div->set_class($class); $div->set_text($code); $html = $div->build(); $html = apply_filters('hocwp_ads_html', $html, $ads_or_args = $args); echo $html; } } }
function hocwp_sanitize_media_value_ajax_callback() { $id = isset($_POST['id']) ? $_POST['id'] : 0; $url = isset($_POST['url']) ? $_POST['url'] : ''; $result = array('id' => $id, 'url' => $url); $result = hocwp_sanitize_media_value($result); echo json_encode($result); exit; }
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 save_term_data($term_id) { $taxonomy = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : ''; $fields = $this->get_fields(); foreach ($fields as $field) { $type = isset($field['type']) ? $field['type'] : 'default'; $name = isset($field['field_args']['name']) ? $field['field_args']['name'] : ''; if (empty($name)) { continue; } $value = hocwp_sanitize_form_post($name, $type); hocwp_term_update_meta($term_id, $name, $value); if ('thumbnail' == $name) { if ('product_cat' == $taxonomy && hocwp_wc_installed()) { $value = hocwp_sanitize_media_value($value); $id = $value['id']; if (hocwp_id_number_valid($id)) { hocwp_term_update_meta($term_id, 'thumbnail_id', $id); } else { hocwp_term_update_meta($term_id, 'thumbnail_id', ''); } } } } return $term_id; }
function hocwp_theme_post_column_content_partner($column, $post_id) { $post = get_post($post_id); if ('partner' == $post->post_type) { if ('url' == $column) { echo hocwp_get_post_meta($column, $post_id); } elseif ('thumbnail' == $column) { $thumbnail = hocwp_get_post_meta($column, $post_id); $thumbnail = hocwp_sanitize_media_value($thumbnail); $thumbnail = $thumbnail['url']; if (!empty($thumbnail)) { $img = new HOCWP_HTML('img'); $img->set_image_src($thumbnail); $img->output(); } } } }
function hocwp_get_media_option_url($value) { $value = hocwp_sanitize_media_value($value); return $value['url']; }
function hocwp_theme_get_logo_url() { $logo = hocwp_theme_get_option('logo'); $logo = hocwp_sanitize_media_value($logo); return $logo['url']; }
function hocwp_field_media_upload_simple($args = array()) { hocwp_field_sanitize_args($args); $id = hocwp_get_value_by_key($args, 'id'); $name = hocwp_get_value_by_key($args, 'name'); if (empty($name)) { _e('Please setup name for this field.', 'hocwp-theme'); return; } $value = hocwp_get_value_by_key($args, 'value'); $value = hocwp_sanitize_media_value($value); $media_url = $value['url']; $btn_insert_class = 'btn-insert-media simple'; $btn_remove_class = 'btn-remove simple'; $img = ''; if (!empty($value['url'])) { hocwp_add_string_with_space_before($btn_insert_class, 'hidden'); $image = new HOCWP_HTML('img'); $image->set_attribute('src', $media_url); if (isset($value['is_image']) && !(bool) $value['is_image']) { $type_icon = hocwp_get_value_by_key($value, 'type_icon'); if (!empty($type_icon)) { $image->set_attribute('src', $type_icon); } } $img = $image->build(); } else { hocwp_add_string_with_space_before($btn_remove_class, 'hidden'); } ?> <p class="hide-if-no-js"> <span class="media-preview"><?php echo $img; ?> </span> <a class="<?php echo $btn_insert_class; ?> " href="#" title="<?php _e('Set image', 'hocwp-theme'); ?> "><?php _e('Set image', 'hocwp-theme'); ?> </a> <a class="<?php echo $btn_remove_class; ?> " href="#" title="<?php _e('Remove image', 'hocwp-theme'); ?> "><?php _e('Remove image', 'hocwp-theme'); ?> </a> <input id="<?php echo $id; ?> _url" type="hidden" value="<?php echo $value['url']; ?> " name="<?php echo $name; ?> [url]" class="media-url"> <input id="<?php echo $id; ?> _id" type="hidden" value="<?php echo $value['id']; ?> " name="<?php echo $name; ?> [id]" class="media-id"> </p> <?php }
function hocwp_term_icon_html($term_id, $default = '') { $icon = hocwp_get_term_icon($term_id); $icon = hocwp_sanitize_media_value($icon); $icon = $icon['url']; if (empty($icon)) { $icon = $default; } if (hocwp_string_contain($icon, 'fa') || hocwp_string_contain($icon, '</i>')) { echo $icon; } else { if (!empty($icon)) { $img = new HOCWP_HTML('img'); $img->set_image_src($icon); $img->output(); } } }