Exemplo n.º 1
0
 /**
  *
  * @since 0.0.1
  * @deprecated 3.5.0
  */
 public function hq_set_background_image()
 {
     if (!current_user_can('edit_theme_options') || !isset($_POST['attachment_id'])) {
         exit;
     }
     $attachment_id = absint($_POST['attachment_id']);
     /** This filter is documented in hq-admin/includes/media.php */
     $sizes = array_keys(apply_filters('image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size'))));
     $size = 'thumbnail';
     if (in_array($_POST['size'], $sizes)) {
         $size = esc_attr($_POST['size']);
     }
     update_post_meta($attachment_id, '_hq_attachment_is_custom_background', get_option('stylesheet'));
     $url = hq_get_attachment_image_src($attachment_id, $size);
     $thumbnail = hq_get_attachment_image_src($attachment_id, 'thumbnail');
     set_theme_mod('background_image', esc_url_raw($url[0]));
     set_theme_mod('background_image_thumb', esc_url_raw($thumbnail[0]));
     exit;
 }
Exemplo n.º 2
0
/**
 * Returns the Site Icon URL.
 *
 * @param  int    $size    Size of the site icon.
 * @param  string $url     Fallback url if no site icon is found.
 * @param  int    $blog_id Id of the blog to get the site icon for.
 * @return string          Site Icon URL.
 */
function get_site_icon_url($size = 512, $url = '', $blog_id = 0)
{
    if ($blog_id && is_multisite()) {
        $site_icon_id = get_blog_option($blog_id, 'site_icon');
    } else {
        $site_icon_id = get_option('site_icon');
    }
    if ($site_icon_id) {
        if ($size >= 512) {
            $size_data = 'full';
        } else {
            $size_data = array($size, $size);
        }
        $url_data = hq_get_attachment_image_src($site_icon_id, $size_data);
        if ($url_data) {
            $url = $url_data[0];
        }
    }
    return $url;
}
Exemplo n.º 3
0
        $header_image_width = get_theme_support('custom-header', 'width');
    } else {
        $header_image_width = HEADER_IMAGE_WIDTH;
    }
    ?>
                        <div id="page_img" align="center">
			<a href="<?php 
    echo esc_url(home_url('/'));
    ?>
">
				<?php 
    /*
     * The header image.
     * Check if this is a post or page, if it has a thumbnail, and if it's a big one
     */
    if (is_singular() && has_post_thumbnail($post->ID) && ($image = hq_get_attachment_image_src(get_post_thumbnail_id($post->ID), array($header_image_width, $header_image_width))) && $image[1] >= $header_image_width) {
        // Houston, we have a new header image!
        echo get_the_post_thumbnail($post->ID, 'post-thumbnail');
    } else {
        // Compatibility with versions of HiveQueen prior to 3.4.
        if (function_exists('get_custom_header')) {
            $header_image_width = get_custom_header()->width;
            $header_image_height = get_custom_header()->height;
        } else {
            $header_image_width = HEADER_IMAGE_WIDTH;
            $header_image_height = HEADER_IMAGE_HEIGHT;
        }
        ?>
					<img src="<?php 
        header_image();
        ?>
Exemplo n.º 4
0
/**
 * Prepares an attachment post object for JS, where it is expected
 * to be JSON-encoded and fit into an Attachment model.
 *
 * @since 0.0.1
 *
 * @param mixed $attachment Attachment ID or object.
 * @return array|void Array of attachment details.
 */
function hq_prepare_attachment_for_js($attachment)
{
    if (!($attachment = get_post($attachment))) {
        return;
    }
    if ('attachment' != $attachment->post_type) {
        return;
    }
    $meta = hq_get_attachment_metadata($attachment->ID);
    if (false !== strpos($attachment->post_mime_type, '/')) {
        list($type, $subtype) = explode('/', $attachment->post_mime_type);
    } else {
        list($type, $subtype) = array($attachment->post_mime_type, '');
    }
    $attachment_url = hq_get_attachment_url($attachment->ID);
    $response = array('id' => $attachment->ID, 'title' => $attachment->post_title, 'filename' => hq_basename(get_attached_file($attachment->ID)), 'url' => $attachment_url, 'link' => get_attachment_link($attachment->ID), 'alt' => get_post_meta($attachment->ID, '_hq_attachment_image_alt', true), 'author' => $attachment->post_author, 'description' => $attachment->post_content, 'caption' => $attachment->post_excerpt, 'name' => $attachment->post_name, 'status' => $attachment->post_status, 'uploadedTo' => $attachment->post_parent, 'date' => strtotime($attachment->post_date_gmt) * 1000, 'modified' => strtotime($attachment->post_modified_gmt) * 1000, 'menuOrder' => $attachment->menu_order, 'mime' => $attachment->post_mime_type, 'type' => $type, 'subtype' => $subtype, 'icon' => hq_mime_type_icon($attachment->ID), 'dateFormatted' => mysql2date(get_option('date_format'), $attachment->post_date), 'nonces' => array('update' => false, 'delete' => false, 'edit' => false), 'editLink' => false, 'meta' => false);
    $author = new HQ_User($attachment->post_author);
    $response['authorName'] = $author->display_name;
    if ($attachment->post_parent) {
        $post_parent = get_post($attachment->post_parent);
    } else {
        $post_parent = false;
    }
    if ($post_parent) {
        $parent_type = get_post_type_object($post_parent->post_type);
        if ($parent_type && $parent_type->show_ui && current_user_can('edit_post', $attachment->post_parent)) {
            $response['uploadedToLink'] = get_edit_post_link($attachment->post_parent, 'raw');
        }
        $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __('(no title)');
    }
    $attached_file = get_attached_file($attachment->ID);
    if (file_exists($attached_file)) {
        $bytes = filesize($attached_file);
        $response['filesizeInBytes'] = $bytes;
        $response['filesizeHumanReadable'] = size_format($bytes);
    }
    if (current_user_can('edit_post', $attachment->ID)) {
        $response['nonces']['update'] = hq_create_nonce('update-post_' . $attachment->ID);
        $response['nonces']['edit'] = hq_create_nonce('image_editor-' . $attachment->ID);
        $response['editLink'] = get_edit_post_link($attachment->ID, 'raw');
    }
    if (current_user_can('delete_post', $attachment->ID)) {
        $response['nonces']['delete'] = hq_create_nonce('delete-post_' . $attachment->ID);
    }
    if ($meta && 'image' === $type) {
        $sizes = array();
        /** This filter is documented in hq-admin/includes/media.php */
        $possible_sizes = apply_filters('image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')));
        unset($possible_sizes['full']);
        // Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
        // First: run the image_downsize filter. If it returns something, we can use its data.
        // If the filter does not return something, then image_downsize() is just an expensive
        // way to check the image metadata, which we do second.
        foreach ($possible_sizes as $size => $label) {
            /** This filter is documented in hq-includes/media.php */
            if ($downsize = apply_filters('image_downsize', false, $attachment->ID, $size)) {
                if (!$downsize[3]) {
                    continue;
                }
                $sizes[$size] = array('height' => $downsize[2], 'width' => $downsize[1], 'url' => $downsize[0], 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape');
            } elseif (isset($meta['sizes'][$size])) {
                if (!isset($base_url)) {
                    $base_url = str_replace(hq_basename($attachment_url), '', $attachment_url);
                }
                // Nothing from the filter, so consult image metadata if we have it.
                $size_meta = $meta['sizes'][$size];
                // We have the actual image size, but might need to further constrain it if content_width is narrower.
                // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
                list($width, $height) = image_constrain_size_for_editor($size_meta['width'], $size_meta['height'], $size, 'edit');
                $sizes[$size] = array('height' => $height, 'width' => $width, 'url' => $base_url . $size_meta['file'], 'orientation' => $height > $width ? 'portrait' : 'landscape');
            }
        }
        $sizes['full'] = array('url' => $attachment_url);
        if (isset($meta['height'], $meta['width'])) {
            $sizes['full']['height'] = $meta['height'];
            $sizes['full']['width'] = $meta['width'];
            $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
        }
        $response = array_merge($response, array('sizes' => $sizes), $sizes['full']);
    } elseif ($meta && 'video' === $type) {
        if (isset($meta['width'])) {
            $response['width'] = (int) $meta['width'];
        }
        if (isset($meta['height'])) {
            $response['height'] = (int) $meta['height'];
        }
    }
    if ($meta && ('audio' === $type || 'video' === $type)) {
        if (isset($meta['length_formatted'])) {
            $response['fileLength'] = $meta['length_formatted'];
        }
        $response['meta'] = array();
        foreach (hq_get_attachment_id3_keys($attachment, 'js') as $key => $label) {
            $response['meta'][$key] = false;
            if (!empty($meta[$key])) {
                $response['meta'][$key] = $meta[$key];
            }
        }
        $id = get_post_thumbnail_id($attachment->ID);
        if (!empty($id)) {
            list($src, $width, $height) = hq_get_attachment_image_src($id, 'full');
            $response['image'] = compact('src', 'width', 'height');
            list($src, $width, $height) = hq_get_attachment_image_src($id, 'thumbnail');
            $response['thumb'] = compact('src', 'width', 'height');
        } else {
            $src = hq_mime_type_icon($attachment->ID);
            $width = 48;
            $height = 64;
            $response['image'] = compact('src', 'width', 'height');
            $response['thumb'] = compact('src', 'width', 'height');
        }
    }
    if (function_exists('get_compat_media_markup')) {
        $response['compat'] = get_compat_media_markup($attachment->ID, array('in_modal' => true));
    }
    /**
     * Filter the attachment data prepared for JavaScript.
     *
     * @since 0.0.1
     *
     * @param array      $response   Array of prepared attachment data.
     * @param int|object $attachment Attachment ID or object.
     * @param array      $meta       Array of attachment meta data.
     */
    return apply_filters('hq_prepare_attachment_for_js', $response, $attachment, $meta);
}
Exemplo n.º 5
0
    /**
     * Display second step of custom header image page.
     *
     * @since 0.0.1
     */
    public function step_2()
    {
        check_admin_referer('custom-header-upload', '_hqnonce-custom-header-upload');
        if (!current_theme_supports('custom-header', 'uploads')) {
            hq_die(__('Cheatin&#8217; uh?'), 403);
        }
        if (empty($_POST) && isset($_GET['file'])) {
            $attachment_id = absint($_GET['file']);
            $file = get_attached_file($attachment_id, true);
            $url = hq_get_attachment_image_src($attachment_id, 'full');
            $url = $url[0];
        } elseif (isset($_POST)) {
            $data = $this->step_2_manage_upload();
            $attachment_id = $data['attachment_id'];
            $file = $data['file'];
            $url = $data['url'];
        }
        if (file_exists($file)) {
            list($width, $height, $type, $attr) = getimagesize($file);
        } else {
            $data = hq_get_attachment_metadata($attachment_id);
            $height = isset($data['height']) ? $data['height'] : 0;
            $width = isset($data['width']) ? $data['width'] : 0;
            unset($data);
        }
        $max_width = 0;
        // For flex, limit size of image displayed to 1500px unless theme says otherwise
        if (current_theme_supports('custom-header', 'flex-width')) {
            $max_width = 1500;
        }
        if (current_theme_supports('custom-header', 'max-width')) {
            $max_width = max($max_width, get_theme_support('custom-header', 'max-width'));
        }
        $max_width = max($max_width, get_theme_support('custom-header', 'width'));
        // If flexible height isn't supported and the image is the exact right size
        if (!current_theme_supports('custom-header', 'flex-height') && !current_theme_supports('custom-header', 'flex-width') && $width == get_theme_support('custom-header', 'width') && $height == get_theme_support('custom-header', 'height')) {
            // Add the meta-data
            if (file_exists($file)) {
                hq_update_attachment_metadata($attachment_id, hq_generate_attachment_metadata($attachment_id, $file));
            }
            $this->set_header_image(compact('url', 'attachment_id', 'width', 'height'));
            /**
             * Fires after the header image is set or an error is returned.
             *
             * @since 0.0.1
             *
             * @param string $file          Path to the file.
             * @param int    $attachment_id Attachment ID.
             */
            do_action('hq_create_file_in_uploads', $file, $attachment_id);
            // For replication
            return $this->finished();
        } elseif ($width > $max_width) {
            $oitar = $width / $max_width;
            $image = hq_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-' . basename($file), $file));
            if (!$image || is_hq_error($image)) {
                hq_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
            }
            /** This filter is documented in hq-admin/custom-header.php */
            $image = apply_filters('hq_create_file_in_uploads', $image, $attachment_id);
            // For replication
            $url = str_replace(basename($url), basename($image), $url);
            $width = $width / $oitar;
            $height = $height / $oitar;
        } else {
            $oitar = 1;
        }
        ?>

<div class="wrap">
<h1><?php 
        _e('Crop Header Image');
        ?>
</h1>

<form method="post" action="<?php 
        echo esc_url(add_query_arg('step', 3));
        ?>
">
	<p class="hide-if-no-js"><?php 
        _e('Choose the part of the image you want to use as your header.');
        ?>
</p>
	<p class="hide-if-js"><strong><?php 
        _e('You need JavaScript to choose a part of the image.');
        ?>
</strong></p>

	<div id="crop_image" style="position: relative">
		<img src="<?php 
        echo esc_url($url);
        ?>
" id="upload" width="<?php 
        echo $width;
        ?>
" height="<?php 
        echo $height;
        ?>
" />
	</div>

	<input type="hidden" name="x1" id="x1" value="0"/>
	<input type="hidden" name="y1" id="y1" value="0"/>
	<input type="hidden" name="width" id="width" value="<?php 
        echo esc_attr($width);
        ?>
"/>
	<input type="hidden" name="height" id="height" value="<?php 
        echo esc_attr($height);
        ?>
"/>
	<input type="hidden" name="attachment_id" id="attachment_id" value="<?php 
        echo esc_attr($attachment_id);
        ?>
" />
	<input type="hidden" name="oitar" id="oitar" value="<?php 
        echo esc_attr($oitar);
        ?>
" />
	<?php 
        if (empty($_POST) && isset($_GET['file'])) {
            ?>
	<input type="hidden" name="create-new-attachment" value="true" />
	<?php 
        }
        ?>
	<?php 
        hq_nonce_field('custom-header-crop-image');
        ?>

	<p class="submit">
	<?php 
        submit_button(__('Crop and Publish'), 'primary', 'submit', false);
        ?>
	<?php 
        if (isset($oitar) && 1 == $oitar && (current_theme_supports('custom-header', 'flex-height') || current_theme_supports('custom-header', 'flex-width'))) {
            submit_button(__('Skip Cropping, Publish Image as Is'), 'secondary', 'skip-cropping', false);
        }
        ?>
	</p>
</form>
</div>
		<?php 
    }