Beispiel #1
0
/**
 * Retrieve HTML content of attachment image with link.
 *
 * @since 2.0.0
 * @deprecated 2.5.0
 * @deprecated Use wp_get_attachment_link()
 * @see wp_get_attachment_link()
 *
 * @param int $id Optional. Post ID.
 * @param bool $fullsize Optional, default is false. Whether to use full size image.
 * @param array $max_dims Optional. Max image dimensions.
 * @param bool $permalink Optional, default is false. Whether to include permalink to image.
 * @return string
 */
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false)
{
    _deprecated_function(__FUNCTION__, '2.5', 'wp_get_attachment_link()');
    $id = (int) $id;
    $_post = get_post($id);
    if ('attachment' != $_post->post_type || !($url = wp_get_attachment_url($_post->ID))) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
    return "<a href='{$url}' title='{$post_title}'>{$innerHTML}</a>";
}
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false)
{
    $id = (int) $id;
    $_post =& get_post($id);
    if ('attachment' != $_post->post_type || !($url = wp_get_attachment_url($_post->ID))) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = attribute_escape($_post->post_title);
    $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
    return "<a href='{$url}' title='{$post_title}'>{$innerHTML}</a>";
}
function wp_upload_display( $dims = false, $href = '' ) {
	global $post;
	$id = get_the_ID();
	$attachment_data = wp_get_attachment_metadata( $id );
	$is_image = (int) wp_attachment_is_image();
	if ( !isset($attachment_data['width']) && $is_image ) {
		if ( $image_data = getimagesize( get_attached_file( $id ) ) ) {
			$attachment_data['width'] = $image_data[0];
			$attachment_data['height'] = $image_data[1];
			wp_update_attachment_metadata( $id, $attachment_data );
		}
	}
	if ( isset($attachment_data['width']) )
		list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);

	ob_start();
		the_title();
		$post_title = attribute_escape(ob_get_contents());
	ob_end_clean();
	$post_content = attribute_escape(apply_filters( 'content_edit_pre', $post->post_content ));

	$class = 'text';
	$innerHTML = get_attachment_innerHTML( $id, false, $dims );
	if ( $image_src = get_attachment_icon_src() ) {
		$image_rel = wp_make_link_relative($image_src);
		$innerHTML = '&nbsp;' . str_replace($image_src, $image_rel, $innerHTML);
		$class = 'image';
	}

	$src_base = wp_get_attachment_url();
	$src = wp_make_link_relative( $src_base );
	$src_base = str_replace($src, '', $src_base);

	$r = '';

	if ( $href )
		$r .= "<a id='file-link-$id' href='$href' title='$post_title' class='file-link $class'>\n";
	if ( $href || $image_src )
		$r .= "\t\t\t$innerHTML";
	if ( $href )
		$r .= "</a>\n";
	$r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
	$r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='$src' />\n";
	$r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-$id' id='attachment-url-base-$id' value='$src_base' />\n";

	if ( !$thumb_base = wp_get_attachment_thumb_url() )
		$thumb_base = wp_mime_type_icon();
	if ( $thumb_base ) {
		$thumb_rel = wp_make_link_relative( $thumb_base );
		$thumb_base = str_replace( $thumb_rel, '', $thumb_base );
		$r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$thumb_rel' />\n";
		$r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$thumb_base' />\n";
	}

	$r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-$id' id='attachment-is-image-$id' value='$is_image' />\n";

	if ( isset($width) ) {
		$r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n";
		$r .= "\t\t\t\t<input type='hidden' name='attachment-height-$id' id='attachment-height-$id' value='$height' />\n";
	}
	$r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-$id' id='attachment-page-url-$id' value='" . get_attachment_link( $id ) . "' />\n";
	$r .= "\t\t\t\t<input type='hidden' name='attachment-title-$id' id='attachment-title-$id' value='$post_title' />\n";
	$r .= "\t\t\t\t<input type='hidden' name='attachment-description-$id' id='attachment-description-$id' value='$post_content' />\n";
	$r .= "\t\t\t</p>\n\t\t</div>\n";
	return $r;
}
Beispiel #4
0
function wp_upload_display($dims = false, $href = '')
{
    global $post;
    $id = get_the_ID();
    $attachment_data = wp_get_attachment_metadata($id);
    $is_image = (int) wp_attachment_is_image();
    $filesystem_path = get_attached_file($id);
    if (!isset($attachment_data['width']) && $is_image) {
        if ($image_data = getimagesize($filesystem_path)) {
            $attachment_data['width'] = $image_data[0];
            $attachment_data['height'] = $image_data[1];
            wp_update_attachment_metadata($id, $attachment_data);
        }
    }
    if (isset($attachment_data['width'])) {
        list($width, $height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);
    }
    $post_title = attribute_escape(the_title('', '', false));
    $post_content = attribute_escape(apply_filters('content_edit_pre', $post->post_content));
    $class = 'text';
    $innerHTML = get_attachment_innerHTML($id, false, $dims);
    if ($image_src = get_attachment_icon_src()) {
        $image_rel = wp_make_link_relative($image_src);
        $innerHTML = '&nbsp;' . str_replace($image_src, $image_rel, $innerHTML);
        $class = 'image';
    }
    $src_base = wp_get_attachment_url();
    $src = wp_make_link_relative($src_base);
    $src_base = str_replace($src, '', $src_base);
    if (!trim($post_title)) {
        $post_title = basename($src);
    }
    $r = '';
    if ($href) {
        $r .= "<a id='file-link-{$id}' href='{$href}' title='{$post_title}' class='file-link {$class}'>\n";
    }
    if ($href || $image_src) {
        $r .= "\t\t\t{$innerHTML}";
    }
    if ($href) {
        $r .= "</a>\n";
    }
    $size = @filesize($filesystem_path);
    if (!empty($size)) {
        $r .= "\t\t\t\t<span class='upload-file-size'>" . size_format($size) . "</span>\n";
    }
    $r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
    $r .= "\t\t\t\t<input type='hidden' name='attachment-url-{$id}' id='attachment-url-{$id}' value='{$src}' />\n";
    $r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-{$id}' id='attachment-url-base-{$id}' value='{$src_base}' />\n";
    if (!($thumb_base = wp_get_attachment_thumb_url())) {
        $thumb_base = wp_mime_type_icon();
    }
    if ($thumb_base) {
        $thumb_rel = wp_make_link_relative($thumb_base);
        $thumb_base = str_replace($thumb_rel, '', $thumb_base);
        $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-{$id}' id='attachment-thumb-url-{$id}' value='{$thumb_rel}' />\n";
        $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-{$id}' id='attachment-thumb-url-base-{$id}' value='{$thumb_base}' />\n";
    }
    $r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-{$id}' id='attachment-is-image-{$id}' value='{$is_image}' />\n";
    if (isset($width)) {
        $r .= "\t\t\t\t<input type='hidden' name='attachment-width-{$id}' id='attachment-width-{$id}' value='{$width}' />\n";
        $r .= "\t\t\t\t<input type='hidden' name='attachment-height-{$id}' id='attachment-height-{$id}' value='{$height}' />\n";
    }
    $r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-{$id}' id='attachment-page-url-{$id}' value='" . get_attachment_link($id) . "' />\n";
    $r .= "\t\t\t\t<input type='hidden' name='attachment-title-{$id}' id='attachment-title-{$id}' value='{$post_title}' />\n";
    $r .= "\t\t\t\t<input type='hidden' name='attachment-description-{$id}' id='attachment-description-{$id}' value='{$post_content}' />\n";
    $r .= "\t\t\t</p>\n\t\t</div>\n";
    return $r;
}
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
	$id = (int) $id;
	$_post = & get_post($id);

	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url() )
		return __('Missing Attachment');

	$post_title = attribute_escape($_post->post_title);

	$innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
	return "<a href='$url' title='$post_title'>$innerHTML</a>";
}
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false)
{
    $id = (int) $id;
    $_post =& get_post($id);
    if ('attachment' != $_post->post_status || '' == $_post->guid) {
        return __('Missing Attachment');
    }
    if (!empty($_post->guid)) {
        $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
        return "<a href=\"{$_post->guid}\" title=\"{$_post->post_title}\" >{$innerHTML}</a>";
    } else {
        $p .= __('Missing attachment');
    }
    return $p;
}