コード例 #1
1
ファイル: functions.php プロジェクト: alicam/vanilla-theme
function image_setup($postid)
{
    global $post;
    $post = get_post($postid);
    // get url
    if (!preg_match('/<img ([^>]*)src=(\\"|\')(.+?)(\\2)([^>\\/]*)\\/*>/', $post->post_content, $matches)) {
        reset_colors($post);
        return false;
    }
    // url setup
    $post->image_url = $matches[3];
    if (!($post->image_url = preg_replace('/\\?w\\=[0-9]+/', '', $post->image_url))) {
        return false;
    }
    $post->image_url = clean_url($post->image_url, 'raw');
    $previous_md5 = get_post_meta($post->ID, 'image_md5', true);
    $previous_url = get_post_meta($post->ID, 'image_url', true);
    if (md5($post->image_tag) != $previous_md5 or $post->image_url != $previous_url) {
        reset_colors($post);
        add_post_meta($post->ID, 'image_url', $post->image_url);
        add_post_meta($post->ID, 'image_md5', md5($post->image_tag));
        //image tag setup
        $extra = $matches[1] . ' ' . $matches[5];
        $extra = preg_replace('/width=(\\"|\')[0-9]+(\\1)/', '', $extra);
        $extra = preg_replace('/height=(\\"|\')[0-9]+(\\1)/', '', $extra);
        $width = is_vertical($post->image_url) ? MIN_WIDTH : MAX_WIDTH;
        delete_post_meta($post->ID, 'image_tag');
        add_post_meta($post->ID, 'image_tag', '<img src="' . $post->image_url . '?w=' . $width . '" ' . $extra . ' />');
        // get colors
        get_all_colors($post);
        return false;
    }
    return true;
}
コード例 #2
0
function image_information_init($postid)
{
    global $post;
    $post = get_post($postid);
    // get url
    if (!preg_match('/<img ([^>]*)src=(\\"|\')(.+?)(\\2)([^>\\/]*)\\/*>/', $post->post_content, $matches)) {
        reset_post_colors($post);
        return false;
    }
    $post->image_url = $matches[3];
    if (!($post->image_url = preg_replace('/\\?w\\=[0-9]+/', '', $post->image_url))) {
        return false;
    }
    $post->image_url = clean_url($post->image_url, 'raw');
    $previous_url = get_post_meta($post->ID, 'image_url', true);
    if ($post->image_url != $previous_url) {
        //image tag setup
        $extra = $matches[1] . ' ' . $matches[5];
        $extra = preg_replace('/width=(\\"|\')[0-9]+(\\1)/', '', $extra);
        $extra = preg_replace('/height=(\\"|\')[0-9]+(\\1)/', '', $extra);
        $width = is_vertical($post->image_url) ? MIN_WIDTH : MAX_WIDTH;
        // reset
        reset_post_colors($post);
        add_post_meta($post->ID, 'image_url', $post->image_url);
        add_post_meta($post->ID, 'image_tag', '<img src="' . $post->image_url . '?w=' . $width . '" ' . $extra . ' />');
        // set colors
        $base = get_post_colors($post);
        if (add_post_meta($post->ID, 'image_colors_bg', $base->bg, false) && add_post_meta($post->ID, 'image_colors_fg', $base->fg, false)) {
            return false;
        }
    }
    return true;
}
コード例 #3
0
function header_function()
{
    global $vertical;
    if (!is_single() && is_home() && !is_archive()) {
        query_posts("what_to_show=posts&posts_per_page=1");
    }
    if (!is_archive() && !is_search()) {
        ?>
		<style type="text/css" media="screen">
		<?php 
        while (have_posts()) {
            the_post();
            // ececute the specific stylesheet
            print_stylesheet();
            // determine if an image is vertical or not
            if (is_vertical(image_url(true))) {
                $vertical = true;
            }
        }
        rewind_posts();
        ?>
		</style>
	<?php 
    }
}