示例#1
0
function hocwp_get_feed_items($args = array())
{
    $url = hocwp_get_value_by_key($args, 'url');
    if (empty($url)) {
        return '';
    }
    $number = hocwp_get_value_by_key($args, 'number');
    $expiration = hocwp_get_value_by_key($args, 'expiration', 12 * HOUR_IN_SECONDS);
    $transient_name = 'hocwp_fetch_feed_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    if (hocwp_id_number_valid($number)) {
        $transient_name .= '_' . $number;
    }
    if (false === ($result = get_transient($transient_name))) {
        $items = hocwp_fetch_feed($args);
        if (hocwp_array_has_value($items)) {
            $result = array();
            foreach ($items as $item) {
                if (!hocwp_object_valid($item)) {
                    continue;
                }
                $description = $item->get_description();
                $thumbnail = hocwp_get_first_image_source($description);
                $description = wp_strip_all_tags($description);
                $content = $item->get_content();
                if (empty($thumbnail)) {
                    $thumbnail = hocwp_get_first_image_source($content);
                }
                $value = array('permalink' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date(), 'image_url' => $thumbnail, 'description' => $description, 'content' => $content);
                array_push($result, $value);
            }
            if (hocwp_array_has_value($result)) {
                set_transient($transient_name, $result, $expiration);
            }
        } else {
            return $items;
        }
    }
    return $result;
}
示例#2
0
function hocwp_get_post_thumbnail_url($post_id = '', $size = 'full')
{
    $result = '';
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    if (has_post_thumbnail($post_id)) {
        $thumbnail_id = get_post_thumbnail_id($post_id);
        if (hocwp_media_file_exists($thumbnail_id)) {
            $image_attributes = wp_get_attachment_image_src($thumbnail_id, $size);
            if ($image_attributes) {
                $result = $image_attributes[0];
            }
        }
    }
    if (empty($result)) {
        $result = get_post_meta($post_id, 'thumbnail_url', true);
    }
    $result = apply_filters('hocwp_post_thumbnail_pre_from_content', $result, $post_id, $size);
    if (empty($result)) {
        $post = get_post($post_id);
        if (hocwp_object_valid($post)) {
            $result = hocwp_get_first_image_source($post->post_content);
        }
    }
    $result = apply_filters('hocwp_post_pre_post_thumbnail', $result, $post_id);
    if (empty($result)) {
        $thumbnail = hocwp_option_get_value('writing', 'default_post_thumbnail');
        $thumbnail = hocwp_sanitize_media_value($thumbnail);
        $result = $thumbnail['url'];
    }
    if (empty($result)) {
        $no_thumbnail = HOCWP_URL . '/images/no-thumbnail.png';
        $no_thumbnail = apply_filters('hocwp_no_thumbnail_url', $no_thumbnail);
        $result = $no_thumbnail;
    }
    $result = apply_filters('hocwp_post_thumbnail', $result, $post_id);
    return $result;
}
function hocwp_get_all_image_from_string($data, $output = 'img')
{
    $output = trim($output);
    preg_match_all('/<img[^>]+>/i', $data, $matches);
    $matches = isset($matches[0]) ? $matches[0] : array();
    if (!hocwp_array_has_value($matches) && !empty($data)) {
        if (false !== strpos($data, '//') && (false !== strpos($data, '.jpg') || false !== strpos($data, '.png') || false !== strpos($data, '.gif'))) {
            $sources = explode(PHP_EOL, $data);
            if (hocwp_array_has_value($sources)) {
                foreach ($sources as $src) {
                    if (hocwp_is_image($src)) {
                        if ('img' == $output) {
                            $matches[] = '<img src="' . $src . '" alt="">';
                        } else {
                            $matches[] = $src;
                        }
                    }
                }
            }
        }
    } elseif ('img' != $output && hocwp_array_has_value($matches)) {
        $tmp = array();
        foreach ($matches as $img) {
            $src = hocwp_get_first_image_source($img);
            $tmp[] = $src;
        }
        $matches = $tmp;
    }
    return $matches;
}
示例#4
0
function hocwp_classifieds_pre_post_thumbnail($url, $post_id)
{
    if (empty($url)) {
        $gallery = hocwp_get_post_meta('gallery', $post_id);
        $url = hocwp_get_first_image_source($gallery);
    }
    return $url;
}
示例#5
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 
    }
}