Changeset 13093 for trunk/wp-includes/post-template.php
- Timestamp:
- 02/13/2010 06:39:51 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post-template.php
r13032 r13093 954 954 955 955 /** 956 * Retrieve HTML content of attachment image with link.957 *958 * @since 2.0.0959 * @deprecated Use {@link wp_get_attachment_link()}960 * @see wp_get_attachment_link() Use instead.961 *962 * @param int $id Optional. Post ID.963 * @param bool $fullsize Optional, default is false. Whether to use full size image.964 * @param array $max_dims Optional. Max image dimensions.965 * @param bool $permalink Optional, default is false. Whether to include permalink to image.966 * @return string967 */968 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {969 $id = (int) $id;970 $_post = & get_post($id);971 972 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )973 return __('Missing Attachment');974 975 if ( $permalink )976 $url = get_attachment_link($_post->ID);977 978 $post_title = esc_attr($_post->post_title);979 980 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);981 return "<a href='$url' title='$post_title'>$innerHTML</a>";982 }983 984 /**985 * Retrieve icon URL and Path.986 *987 * @since 2.1.0988 * @deprecated Use {@link wp_get_attachment_image_src()}989 * @see wp_get_attachment_image_src() Use instead.990 *991 * @param int $id Optional. Post ID.992 * @param bool $fullsize Optional, default to false. Whether to have full image.993 * @return array Icon URL and full path to file, respectively.994 */995 function get_attachment_icon_src( $id = 0, $fullsize = false ) {996 $id = (int) $id;997 if ( !$post = & get_post($id) )998 return false;999 1000 $file = get_attached_file( $post->ID );1001 1002 if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {1003 // We have a thumbnail desired, specified and existing1004 1005 $src_file = basename($src);1006 $class = 'attachmentthumb';1007 } elseif ( wp_attachment_is_image( $post->ID ) ) {1008 // We have an image without a thumbnail1009 1010 $src = wp_get_attachment_url( $post->ID );1011 $src_file = & $file;1012 $class = 'attachmentimage';1013 } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {1014 // No thumb, no image. We'll look for a mime-related icon instead.1015 1016 $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );1017 $src_file = $icon_dir . '/' . basename($src);1018 }1019 1020 if ( !isset($src) || !$src )1021 return false;1022 1023 return array($src, $src_file);1024 }1025 1026 /**1027 * Retrieve HTML content of icon attachment image element.1028 *1029 * @since 2.0.01030 * @deprecated Use {@link wp_get_attachment_image()}1031 * @see wp_get_attachment_image() Use instead of.1032 *1033 * @param int $id Optional. Post ID.1034 * @param bool $fullsize Optional, default to false. Whether to have full size image.1035 * @param array $max_dims Optional. Dimensions of image.1036 * @return string HTML content.1037 */1038 function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {1039 $id = (int) $id;1040 if ( !$post = & get_post($id) )1041 return false;1042 1043 if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )1044 return false;1045 1046 list($src, $src_file) = $src;1047 1048 // Do we need to constrain the image?1049 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {1050 1051 $imagesize = getimagesize($src_file);1052 1053 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {1054 $actual_aspect = $imagesize[0] / $imagesize[1];1055 $desired_aspect = $max_dims[0] / $max_dims[1];1056 1057 if ( $actual_aspect >= $desired_aspect ) {1058 $height = $actual_aspect * $max_dims[0];1059 $constraint = "width='{$max_dims[0]}' ";1060 $post->iconsize = array($max_dims[0], $height);1061 } else {1062 $width = $max_dims[1] / $actual_aspect;1063 $constraint = "height='{$max_dims[1]}' ";1064 $post->iconsize = array($width, $max_dims[1]);1065 }1066 } else {1067 $post->iconsize = array($imagesize[0], $imagesize[1]);1068 $constraint = '';1069 }1070 } else {1071 $constraint = '';1072 }1073 1074 $post_title = esc_attr($post->post_title);1075 1076 $icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";1077 1078 return apply_filters( 'attachment_icon', $icon, $post->ID );1079 }1080 1081 /**1082 * Retrieve HTML content of image element.1083 *1084 * @since 2.0.01085 * @deprecated Use {@link wp_get_attachment_image()}1086 * @see wp_get_attachment_image() Use instead.1087 *1088 * @param int $id Optional. Post ID.1089 * @param bool $fullsize Optional, default to false. Whether to have full size image.1090 * @param array $max_dims Optional. Dimensions of image.1091 * @return string1092 */1093 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {1094 $id = (int) $id;1095 if ( !$post = & get_post($id) )1096 return false;1097 1098 if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))1099 return $innerHTML;1100 1101 1102 $innerHTML = esc_attr($post->post_title);1103 1104 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);1105 }1106 1107 /**1108 956 * Wrap attachment in <<p>> element before content. 1109 957 *
Note: See TracChangeset
for help on using the changeset viewer.