当前位置: 首页>>代码示例>>PHP>>正文


PHP get_attachment_icon_src函数代码示例

本文整理汇总了PHP中get_attachment_icon_src函数的典型用法代码示例。如果您正苦于以下问题:PHP get_attachment_icon_src函数的具体用法?PHP get_attachment_icon_src怎么用?PHP get_attachment_icon_src使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_attachment_icon_src函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_attachment_icon

/**
 * Retrieve HTML content of icon attachment image element.
 *
 * @since 2.0.0
 * @deprecated 2.5.0
 * @deprecated Use wp_get_attachment_image()
 * @see wp_get_attachment_image()
 *
 * @param int $id Optional. Post ID.
 * @param bool $fullsize Optional, default to false. Whether to have full size image.
 * @param array $max_dims Optional. Dimensions of image.
 * @return string HTML content.
 */
function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false)
{
    _deprecated_function(__FUNCTION__, '2.5', 'wp_get_attachment_image()');
    $id = (int) $id;
    if (!($post = get_post($id))) {
        return false;
    }
    if (!($src = get_attachment_icon_src($post->ID, $fullsize))) {
        return false;
    }
    list($src, $src_file) = $src;
    // Do we need to constrain the image?
    if (($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file)) {
        $imagesize = getimagesize($src_file);
        if ($imagesize[0] > $max_dims[0] || $imagesize[1] > $max_dims[1]) {
            $actual_aspect = $imagesize[0] / $imagesize[1];
            $desired_aspect = $max_dims[0] / $max_dims[1];
            if ($actual_aspect >= $desired_aspect) {
                $height = $actual_aspect * $max_dims[0];
                $constraint = "width='{$max_dims[0]}' ";
                $post->iconsize = array($max_dims[0], $height);
            } else {
                $width = $max_dims[1] / $actual_aspect;
                $constraint = "height='{$max_dims[1]}' ";
                $post->iconsize = array($width, $max_dims[1]);
            }
        } else {
            $post->iconsize = array($imagesize[0], $imagesize[1]);
            $constraint = '';
        }
    } else {
        $constraint = '';
    }
    $post_title = esc_attr($post->post_title);
    $icon = "<img src='{$src}' title='{$post_title}' alt='{$post_title}' {$constraint}/>";
    return apply_filters('attachment_icon', $icon, $post->ID);
}
开发者ID:rkglug,项目名称:WordPress,代码行数:50,代码来源:deprecated.php

示例2: get_media_item

function get_media_item($attachment_id, $args = null)
{
    $default_args = array('errors' => null, 'send' => true, 'delete' => true, 'toggle' => true);
    $args = wp_parse_args($args, $default_args);
    extract($args, EXTR_SKIP);
    global $post_mime_types;
    if (($attachment_id = intval($attachment_id)) && ($thumb_url = get_attachment_icon_src($attachment_id))) {
        $thumb_url = $thumb_url[0];
    } else {
        return false;
    }
    $title_label = __('Title');
    $description_label = __('Description');
    $tags_label = __('Tags');
    $toggle_on = __('Show');
    $toggle_off = __('Hide');
    $post = get_post($attachment_id);
    $filename = basename($post->guid);
    $title = attribute_escape($post->post_title);
    $description = attribute_escape($post->post_content);
    if ($_tags = get_the_tags($attachment_id)) {
        foreach ($_tags as $tag) {
            $tags[] = $tag->name;
        }
        $tags = attribute_escape(join(', ', $tags));
    }
    if (isset($post_mime_types)) {
        $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
        $type = array_shift($keys);
        $type = "<input type='hidden' id='type-of-{$attachment_id}' value='" . attribute_escape($type) . "' />";
    }
    $form_fields = get_attachment_fields_to_edit($post, $errors);
    if ($toggle) {
        $class = empty($errors) ? 'startclosed' : 'startopen';
        $toggle_links = "\n\t<a class='toggle describe-toggle-on' href='#'>{$toggle_on}</a>\n\t<a class='toggle describe-toggle-off' href='#'>{$toggle_off}</a>";
    } else {
        $class = 'form-table';
        $toggle_links = '';
    }
    $display_title = !empty($title) ? $title : $filename;
    // $title shouldn't ever be empty, but just in case
    $item = "\n\t{$type}\n\t{$toggle_links}\n\t<div class='filename new'>{$display_title}</div>\n\t<table class='slidetoggle describe {$class}'>\n\t\t<thead class='media-item-info'>\n\t\t<tr>\n\t\t\t<td class='A1B1' rowspan='4'><img class='thumbnail' src='{$thumb_url}' alt='' /></td>\n\t\t\t<td>{$filename}</td>\n\t\t</tr>\n\t\t<tr><td>{$post->post_mime_type}</td></tr>\n\t\t<tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>\n\t\t<tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>\n\t\t</thead>\n\t\t<tbody>\n";
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array());
    $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post={$attachment_id}", 'delete-post_' . $attachment_id);
    if ($send) {
        $send = "<input type='submit' class='button' name='send[{$attachment_id}]' value='" . attribute_escape(__('Insert into Post')) . "' />";
    }
    if ($delete) {
        $delete = "<a href='{$delete_href}' id='del[{$attachment_id}]' disabled='disabled' class='delete'>" . __('Delete') . "</button>";
    }
    if (($send || $delete) && !isset($form_fields['buttons'])) {
        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>{$send} {$delete}</td></tr>\n");
    }
    $hidden_fields = array();
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        $name = "attachments[{$attachment_id}][{$id}]";
        if ($field['input'] == 'hidden') {
            $hidden_fields[$name] = $field['value'];
            continue;
        }
        $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
        $class = $id;
        $class .= $field['required'] ? ' form-required' : '';
        $item .= "\t\t<tr class='{$class}'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='{$name}'><span class='alignleft'>{$field['label']}</span><span class='alignright'>{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
        if (!empty($field[$field['input']])) {
            $item .= $field[$field['input']];
        } elseif ($field['input'] == 'textarea') {
            $item .= "<textarea type='text' id='{$name}' name='{$name}'>" . attribute_escape($field['value']) . "</textarea>";
        } else {
            $item .= "<input type='text' id='{$name}' name='{$name}' value='" . attribute_escape($field['value']) . "' />";
        }
        if (!empty($field['helps'])) {
            $item .= "<p class='help'>" . join("</p>\n<p class='help'>", array_unique((array) $field['helps'])) . '</p>';
        }
        $item .= "</td>\n\t\t</tr>\n";
        $extra_rows = array();
        if (!empty($field['errors'])) {
            foreach (array_unique((array) $field['errors']) as $error) {
                $extra_rows['error'][] = $error;
            }
        }
        if (!empty($field['extra_rows'])) {
            foreach ($field['extra_rows'] as $class => $rows) {
                foreach ((array) $rows as $html) {
                    $extra_rows[$class][] = $html;
                }
            }
        }
        foreach ($extra_rows as $class => $rows) {
            foreach ($rows as $html) {
                $item .= "\t\t<tr><td></td><td class='{$class}'>{$html}</td></tr>\n";
            }
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:media.php

示例3: get_media_item

/**
 * Retrieve HTML form for modifying the image attachment.
 *
 * @since unknown
 *
 * @param int $attachment_id Attachment ID for modification.
 * @param string|array $args Optional. Override defaults.
 * @return string HTML form for attachment.
 */
function get_media_item($attachment_id, $args = null)
{
    global $redir_tab;
    $default_args = array('errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true);
    $args = wp_parse_args($args, $default_args);
    extract($args, EXTR_SKIP);
    global $post_mime_types;
    if (($attachment_id = intval($attachment_id)) && ($thumb_url = get_attachment_icon_src($attachment_id))) {
        $thumb_url = $thumb_url[0];
    } else {
        return false;
    }
    $toggle_on = __('Show');
    $toggle_off = __('Hide');
    $post = get_post($attachment_id);
    $filename = basename($post->guid);
    $title = esc_attr($post->post_title);
    if ($_tags = get_the_tags($attachment_id)) {
        foreach ($_tags as $tag) {
            $tags[] = $tag->name;
        }
        $tags = esc_attr(join(', ', $tags));
    }
    $type = '';
    if (isset($post_mime_types)) {
        $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
        $type = array_shift($keys);
        $type = "<input type='hidden' id='type-of-{$attachment_id}' value='" . esc_attr($type) . "' />";
    }
    $form_fields = get_attachment_fields_to_edit($post, $errors);
    if ($toggle) {
        $class = empty($errors) ? 'startclosed' : 'startopen';
        $toggle_links = "\r\n\t<a class='toggle describe-toggle-on' href='#'>{$toggle_on}</a>\r\n\t<a class='toggle describe-toggle-off' href='#'>{$toggle_off}</a>";
    } else {
        $class = 'form-table';
        $toggle_links = '';
    }
    $display_title = !empty($title) ? $title : $filename;
    // $title shouldn't ever be empty, but just in case
    $display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : '';
    $gallery = isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab'] || isset($redir_tab) && 'gallery' == $redir_tab ? true : false;
    $order = '';
    foreach ($form_fields as $key => $val) {
        if ('menu_order' == $key) {
            if ($gallery) {
                $order = '<div class="menu_order"> <input class="menu_order_input" type="text" id="attachments[' . $attachment_id . '][menu_order]" name="attachments[' . $attachment_id . '][menu_order]" value="' . $val['value'] . '" /></div>';
            } else {
                $order = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . $val['value'] . '" />';
            }
            unset($form_fields['menu_order']);
            break;
        }
    }
    $item = "\r\n\t{$type}\r\n\t{$toggle_links}\r\n\t{$order}\r\n\t{$display_title}\r\n\t<table class='slidetoggle describe {$class}'>\r\n\t\t<thead class='media-item-info'>\r\n\t\t<tr>\r\n\t\t\t<td class='A1B1' rowspan='4'><img class='thumbnail' src='{$thumb_url}' alt='' /></td>\r\n\t\t\t<td>{$filename}</td>\r\n\t\t</tr>\r\n\t\t<tr><td>{$post->post_mime_type}</td></tr>\r\n\t\t<tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>\r\n\t\t<tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>\r\n\t\t</thead>\r\n\t\t<tbody>\n";
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array());
    $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post={$attachment_id}", 'delete-post_' . $attachment_id);
    if ($send) {
        $send = "<input type='submit' class='button' name='send[{$attachment_id}]' value='" . esc_attr__('Insert into Post') . "' />";
    }
    if ($delete) {
        $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_{$attachment_id}').style.display='block';return false;\">" . __('Delete') . "</a>";
    }
    if (($send || $delete) && !isset($form_fields['buttons'])) {
        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>{$send} {$delete}\r\n\t\t<div id=\"del_attachment_{$attachment_id}\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"{$delete_href}\" id=\"del[{$attachment_id}]\" class=\"delete\">" . __('Continue') . "</a>\r\n\t\t<a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
    }
    $hidden_fields = array();
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        $name = "attachments[{$attachment_id}][{$id}]";
        if ($field['input'] == 'hidden') {
            $hidden_fields[$name] = $field['value'];
            continue;
        }
        $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
        $aria_required = $field['required'] ? " aria-required='true' " : '';
        $class = $id;
        $class .= $field['required'] ? ' form-required' : '';
        $item .= "\t\t<tr class='{$class}'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='{$name}'><span class='alignleft'>{$field['label']}</span><span class='alignright'>{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
        if (!empty($field[$field['input']])) {
            $item .= $field[$field['input']];
        } elseif ($field['input'] == 'textarea') {
            $item .= "<textarea type='text' id='{$name}' name='{$name}'" . $aria_required . ">" . esc_html($field['value']) . "</textarea>";
        } else {
            $item .= "<input type='text' id='{$name}' name='{$name}' value='" . esc_attr($field['value']) . "'" . $aria_required . "/>";
//.........这里部分代码省略.........
开发者ID:Alenjandro,项目名称:data-my-share,代码行数:101,代码来源:media.php

示例4: wp_upload_display

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;
}
开发者ID:nurpax,项目名称:saastafi,代码行数:69,代码来源:upload.php

示例5: wp_upload_display

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;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:66,代码来源:upload-functions.php

示例6: get_attachment_icon

function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
	$id = (int) $id;
	if ( !$post = & get_post($id) )
		return false;

	if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )
		return false;

	list($src, $src_file) = $src;

	// Do we need to constrain the image?
	if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {

		$imagesize = getimagesize($src_file);

		if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
			$actual_aspect = $imagesize[0] / $imagesize[1];
			$desired_aspect = $max_dims[0] / $max_dims[1];

			if ( $actual_aspect >= $desired_aspect ) {
				$height = $actual_aspect * $max_dims[0];
				$constraint = "width='{$max_dims[0]}' ";
				$post->iconsize = array($max_dims[0], $height);
			} else {
				$width = $max_dims[1] / $actual_aspect;
				$constraint = "height='{$max_dims[1]}' ";
				$post->iconsize = array($width, $max_dims[1]);
			}
		} else {
			$post->iconsize = array($imagesize[0], $imagesize[1]);
		}
	}

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

	$icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";

	return apply_filters( 'attachment_icon', $icon, $post->ID );
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:39,代码来源:post-template.php

示例7: get_jw_playlist_item

/**
 * Retrieves a sepecific playlist item.  In this case it is a media attachment.
 * @global string $redir_tab The tab to redirect to.
 * @param int $attachment_id The id of the attachment we are retrieving.
 * @param array $args Any additional arguments for query the database.
 * @param int $current_playlist The currently selected playlist.
 * @return string The HTML representing the playlist item.
 */
function get_jw_playlist_item($attachment_id, $args, $current_playlist, $prefix = "")
{
    global $redir_tab, $p_items;
    if (($attachment_id = intval($attachment_id)) && ($thumb_url = get_attachment_icon_src($attachment_id))) {
        $thumb_url = $thumb_url[0];
    } else {
        return false;
    }
    $default_args = array('errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true);
    $args = wp_parse_args($args, $default_args);
    extract($args, EXTR_SKIP);
    $post = get_post($attachment_id);
    $filename = basename($post->guid);
    $title = esc_attr($post->post_title);
    if ($_tags = get_the_tags($attachment_id)) {
        foreach ($_tags as $tag) {
            $tags[] = $tag->name;
        }
        $tags = esc_attr(join(', ', $tags));
    }
    $post_mime_types = get_post_mime_types();
    $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
    $type = array_shift($keys);
    $type_html = "<input type='hidden' id='type-of-{$attachment_id}' value='" . esc_attr($type) . "' />";
    $form_fields = get_attachment_fields_to_edit($post, $errors);
    $display_title = !empty($title) ? $title : $filename;
    // $title shouldn't ever be empty, but just in case
    $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60) . "</span></div>" : '';
    $gallery = isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab'] || isset($redir_tab) && 'gallery' == $redir_tab ? true : false;
    $order = '';
    $checked = "";
    foreach ($p_items as $playlist_item) {
        if ($playlist_item == $attachment_id) {
            $checked = "checked='true'";
            break;
        }
    }
    foreach ($form_fields as $key => $val) {
        if ('menu_order' == $key) {
            if (true) {
                $order = '<div class="menu_order">';
                $order .= '<input class="menu_order_input" type="checkbox" id="' . $prefix . 'attachments[' . $attachment_id . '][enabled]" name="' . $prefix . 'attachments[' . $attachment_id . '][enabled]" value="' . $val['value'] . '"' . $checked . ' onclick="updatePlaylist(this);" /></div>';
            } else {
                $order = '<input type="hidden" name="' . $prefix . 'attachments[' . $attachment_id . '][menu_order]" value="' . $val['value'] . '" />';
            }
            unset($form_fields['menu_order']);
            break;
        }
    }
    $media_dims = '';
    $meta = wp_get_attachment_metadata($post->ID);
    if (is_array($meta) && array_key_exists('width', $meta) && array_key_exists('height', $meta)) {
        $media_dims .= "<span id='playlist-dims-{$post->ID}'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
    }
    $media_dims = apply_filters('media_meta', $media_dims, $post);
    $image_edit_button = '';
    if (gd_edit_image_support($post->post_mime_type)) {
        $nonce = wp_create_nonce("image_editor-{$post->ID}");
        $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open({$post->ID}, \"{$nonce}\")' class='button' value='" . esc_attr__('Edit image') . "' /> <img src='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' />";
    }
    $item = "\n\t{$type_html}\n\t{$toggle_links}\n\t{$order}\n\t{$display_title}\n  <table class='slidetoggle describe startclosed'>\n\t\t<thead class='media-item-info' id='media-head-{$post->ID}'>\n\t\t<tr>\n\t\t\t<td class='A1B1' id='thumbnail-head-{$post->ID}' rowspan='5'><img class='thumbnail' src='{$thumb_url}' alt='' /></td>\n\t\t\t<td><strong>" . __('File name:') . "</strong> {$filename}</td>\n\t\t</tr>\n\t\t<tr><td><strong>" . __('File type:') . "</strong> {$post->post_mime_type}</td></tr>\n\t\t<tr><td><strong>" . __('Upload date:') . "</strong> " . mysql2date(get_option('date_format'), $post->post_date) . "</td></tr>\n";
    if (!empty($media_dims)) {
        $item .= "<tr><td><strong>" . __('Dimensions:') . "</strong> {$media_dims}</td></tr>\n";
    }
    $item .= "\n\t\t<tr><td class='A1B1'>{$image_edit_button}</td></tr>\n\t\t</thead>\n\t\t<tbody>\n\t\t<tr><td colspan='2' class='imgedit-response' id='imgedit-response-{$post->ID}'></td></tr>\n\t\t<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-{$post->ID}'></td></tr>\n";
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array());
    $thumbnail = '';
    $calling_post_id = 0;
    if (isset($_GET['post_id'])) {
        $calling_post_id = $_GET['post_id'];
    } elseif (isset($_POST) && count($_POST)) {
        // Like for async-upload where $_GET['post_id'] isn't set
        $calling_post_id = $post->post_parent;
    }
    if ('image' == $type && $calling_post_id && current_theme_supports('post-thumbnails', get_post_type($calling_post_id)) && get_post_thumbnail_id($calling_post_id) != $attachment_id) {
        $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"{$attachment_id}\");return false;'>" . esc_html__("Use as thumbnail") . "</a>";
    }
    if (($send || $thumbnail || $delete) && !isset($form_fields['buttons'])) {
        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>{$send} {$thumbnail} {$delete}</td></tr>\n");
    }
    $hidden_fields = array();
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        $name = "attachments[{$attachment_id}][{$id}]";
        if ($field['input'] == 'hidden') {
//.........这里部分代码省略.........
开发者ID:thejimbirch,项目名称:unionrockyards,代码行数:101,代码来源:EmbedManager.php

示例8: make_file

 function make_file($name, $sid, $cftnum, $size, $hideKey, $label, $class, $style, $before, $after, $multipleButton, $relation, $mediaLibrary, $mediaPicker)
 {
     $options = $this->get_custom_field_template_data();
     $title = $name;
     $name = $this->sanitize_name($name);
     if (isset($_REQUEST['post']) && $_REQUEST['post'] > 0 && $_REQUEST['default'] != true) {
         $value = $this->get_post_meta($_REQUEST['post'], $title);
         $ct_value = count($value);
         if ($value) {
             $value = $value[$cftnum];
         }
     } else {
         $value = $default;
     }
     if (empty($ct_value)) {
         $ct_value = 1;
     }
     if ($hideKey == true) {
         $hide = ' class="hideKey"';
     }
     if (!empty($class)) {
         $class = ' class="' . $class . '"';
     }
     if (!empty($style)) {
         $style = ' style="' . $style . '"';
     }
     if (!empty($label) && $options['custom_field_template_replace_keys_by_labels']) {
         $title = stripcslashes($label);
     }
     if ($multipleButton == true && $ct_value == $cftnum) {
         $addfield .= '<div style="margin-top:-1em;">';
         $addfield .= '<a href="#clear" onclick="jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent()).find(' . "'input'" . ').val(' . "''" . ');jQuery(this).parent().css(' . "'visibility','hidden'" . ');jQuery(this).parent().prev().css(' . "'visibility','hidden'" . '); return false;">' . __('Add New', 'custom-field-template') . '</a>';
         $addfield .= '</div>';
     }
     if ($relation == true) {
         $tab = 'gallery';
     } else {
         $tab = 'library';
     }
     $media_upload_iframe_src = "media-upload.php";
     $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "{$media_upload_iframe_src}?type=image&tab=library");
     if ($mediaPicker == true) {
         $picker = __(' OR ', 'custom-field-template');
         $picker .= '<a href="' . $image_upload_iframe_src . '&post_id=' . $_REQUEST['post'] . '&TB_iframe=1&tab=' . $tab . '&cftid=' . $name . $sid . '_' . $cftnum . '"  class="thickbox" onclick="jQuery(' . "'#cft_clicked_id'" . ').val(' . "'" . $name . $sid . '_' . $cftnum . "'" . ');">' . __('Select by Media Picker', 'custom-field-template') . '</a>';
     }
     $out .= '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_file">' . '<dt><span' . $hide . '><label for="' . $name . $sid . '_' . $cftnum . '">' . $title . '</label></span>' . $addfield . '</dt>' . '<dd>';
     if (!empty($label) && !$options['custom_field_template_replace_keys_by_labels']) {
         $out .= '<p class="label">' . stripcslashes($label) . '</p>';
     }
     $out .= trim($before) . '<input id="' . $name . $sid . '_' . $cftnum . '" name="' . $name . '[' . $sid . '][]" type="file" size="' . $size . '"' . $class . $style . ' onchange="if (jQuery(this).val()) { jQuery(\'#cft_save_button\').attr(\'disabled\', true); jQuery(\'#post-preview\').hide(); } else { jQuery(\'#cft_save_button\').attr(\'disabled\', false); jQuery(\'#post-preview\').show(); }" />' . trim($after) . $picker;
     if (($value = intval($value)) && ($thumb_url = get_attachment_icon_src($value))) {
         $thumb_url = $thumb_url[0];
         $post = get_post($value);
         $filename = basename($post->guid);
         $title = attribute_escape(trim($post->post_title));
         if (!empty($mediaLibrary)) {
             $title = '<a href="' . $image_upload_iframe_src . '&post_id=' . $_REQUEST['post'] . '&TB_iframe=1&tab=' . $tab . '" class="thickbox">' . $title . '</a>';
         }
         $out .= '<p><label for="' . $name . $sid . '_' . $cftnum . '_delete"><input type="checkbox" name="' . $name . '_delete[' . $sid . '][' . $cftnum . ']" id="' . $name . $sid . '_' . $cftnum . '_delete" value="1" class="delete_file_checkbox" />' . __('Delete', 'custom-field-template') . '</label> <img src="' . $thumb_url . '" width="32" height="32" style="vertical-align:middle;" /> ' . $title . ' </p>';
         $out .= '<input type="hidden" id="' . $name . $sid . '_' . $cftnum . '_hide" name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="' . $value . '" />';
     } else {
         $out .= '<input type="hidden" id="' . $name . $sid . '_' . $cftnum . '_hide" name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="" />';
     }
     $out .= '</dd></dl>' . "\n";
     return $out;
 }
开发者ID:hypenotic,项目名称:slowfood,代码行数:66,代码来源:custom-field-template.php

示例9: get_thumb

 public function get_thumb($id, $size = 'full')
 {
     global $wp_version;
     /* Get the originally uploaded size path. */
     list($img_url, $img_path) = get_attachment_icon_src($id, true);
     if ($size == 'full') {
         return $img_url;
     }
     /* Attepmt to get custom intermediate size. */
     $img = image_get_intermediate_size($id, $size);
     //detail
     /* If custom intermediate size cannot be found, attempt to create it. */
     if (!$img) {
         /* Need to check to see if fullsize path can be found - sometimes this disappears during import/export. */
         if (!is_file($img_path)) {
             $wp_upload_dir = wp_upload_dir();
             $img_path = $wp_upload_dir['path'] . get_post_meta($id, '_wp_attached_file', true);
         }
         if (is_file($img_path)) {
             $new = image_resize($img_path, $this->detail_size[0], $this->detail_size[1], $this->detail_size[2]);
             if (!is_wp_error($new)) {
                 $meta = wp_generate_attachment_metadata($id, $img_path);
                 wp_update_attachment_metadata($id, $meta);
                 $img = image_get_intermediate_size($id, $size);
             }
         }
     }
     /* Custom intermediate size cannot be created, try for thumbnail. */
     if (!$img) {
         $img = image_get_intermediate_size($id, 'thumbnail');
         //echo "3:";print_r($img);
     }
     /* Thumbnail cannot be found, try fullsize. */
     if (!$img) {
         $img['url'] = wp_get_attachment_url($id);
     }
     /* Administration */
     if (isset($img['url']) && !empty($img['url'])) {
         return $img['url'];
     } else {
         if (is_admin()) {
             return $this->url . 'deleted-image.png';
         }
     }
     return false;
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:46,代码来源:custom-menu-images.php

示例10: wp_save_image

function wp_save_image($post_id)
{
    $msg = '';
    $success = $delete = $full_resized = false;
    $post = get_post($post_id);
    @ini_set('memory_limit', '256M');
    $img = load_image_to_edit($post);
    if (!is_resource($img)) {
        return 'error=' . __('Unable to create new image.');
    }
    $fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;
    $fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;
    $target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';
    if (!empty($_REQUEST['history'])) {
        $changes = json_decode(stripslashes($_REQUEST['history']));
        if ($changes) {
            $img = image_edit_apply_changes($img, $changes);
        }
    }
    if ($fwidth > 0 && $fheight > 0) {
        // scale the full size image
        $dst = wp_imagecreatetruecolor($fwidth, $fheight);
        if (imagecopyresampled($dst, $img, 0, 0, 0, 0, $fwidth, $fheight, imagesx($img), imagesy($img))) {
            imagedestroy($img);
            $img = $dst;
            $full_resized = true;
        }
    }
    if (!$changes && !$full_resized) {
        return 'error=' . __('Nothing to save, the image is not changed.');
    }
    $meta = wp_get_attachment_metadata($post_id, false, false);
    if (!is_array($meta)) {
        $meta = array();
    }
    if (!isset($meta['sizes']) || !is_array($meta['sizes'])) {
        $meta['sizes'] = array();
    }
    // generate new filename
    $path = get_attached_file($post_id);
    $path_parts = pathinfo52($path);
    $filename = $path_parts['filename'];
    $suffix = time() . rand(100, 999);
    while (true) {
        $filename = preg_replace('/-e([0-9]+)$/', '', $filename);
        $filename .= "-e{$suffix}";
        $new_filename = "{$filename}.{$path_parts['extension']}";
        $new_path = "{$path_parts['dirname']}/{$new_filename}";
        if (file_exists($new_path)) {
            $suffix++;
        } else {
            break;
        }
    }
    // save the full-size file, also needed to create sub-sizes
    if (!wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id)) {
        return 'error=' . __('Unable to save the image.');
    }
    if ('full' == $target || 'all' == $target || $full_resized) {
        $meta['sizes']["backup-{$suffix}-full"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
        $success = update_attached_file($post_id, $new_path);
        $meta['file'] = get_attached_file($post_id, true);
        // get the path unfiltered
        $meta['width'] = imagesx($img);
        $meta['height'] = imagesy($img);
        list($uwidth, $uheight) = wp_shrink_dimensions($meta['width'], $meta['height']);
        $meta['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
        if ($success && $target == 'all') {
            $sizes = apply_filters('intermediate_image_sizes', array('large', 'medium', 'thumbnail'));
        }
        $msg .= "full={$meta['width']}x{$meta['height']}!";
    } elseif (array_key_exists($target, $meta['sizes'])) {
        $sizes = array($target);
        $success = $delete = true;
    }
    if (isset($sizes)) {
        foreach ($sizes as $size) {
            if (isset($meta['sizes'][$size])) {
                $meta['sizes']["backup-{$suffix}-{$size}"] = $meta['sizes'][$size];
            }
            $resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop"));
            if ($resized) {
                $meta['sizes'][$size] = $resized;
            } else {
                unset($meta['sizes'][$size]);
            }
        }
    }
    if ($success) {
        wp_update_attachment_metadata($post_id, $meta);
        if ($target == 'thumbnail' || $target == 'all' || $target == 'full' && !array_key_exists('thumbnail', $meta['sizes'])) {
            if ($thumb_url = get_attachment_icon_src($post_id)) {
                $msg .= "thumbnail={$thumb_url[0]}";
            }
        }
    } else {
        $delete = true;
    }
    if ($delete) {
        $delpath = apply_filters('wp_delete_file', $new_path);
//.........这里部分代码省略.........
开发者ID:bluedanbob,项目名称:wordpress,代码行数:101,代码来源:image-edit.php


注:本文中的get_attachment_icon_src函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。