Changeset 12055 for trunk/wp-admin/includes/media.php
- Timestamp:
- 10/19/2009 05:09:41 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r12051 r12055 99 99 * @return unknown 100 100 */ 101 function get_image_send_to_editor($id, $ alt, $title, $align, $url='', $rel = false, $size='medium') {101 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { 102 102 103 103 $htmlalt = ( empty($alt) ) ? $title : $alt; … … 110 110 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; 111 111 112 $html = apply_filters( 'image_send_to_editor', $html, $id, $ alt, $title, $align, $url, $size);112 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); 113 113 114 114 return $html; … … 149 149 * @return unknown 150 150 */ 151 function image_add_caption( $html, $id, $ alt, $title, $align, $url, $size) {152 153 if ( empty($ alt) || apply_filters( 'disable_captions', '' ) )151 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { 152 153 if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) 154 154 return $html; 155 155 156 156 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; 157 157 158 preg_match( '/width="([0-9]+)/', $html, $matches ); 159 if ( ! isset($matches[1]) ) 158 if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) ) 160 159 return $html; 161 160 … … 166 165 $align = 'none'; 167 166 168 $alt = ! empty($alt) ? addslashes($alt) : '';169 170 167 $shcode = '[caption id="' . $id . '" align="align' . $align 171 . '" width="' . $width . '" caption="' . $alt. '"]' . $html . '[/caption]';168 . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]'; 172 169 173 170 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); 174 171 } 175 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7);172 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); 176 173 177 174 /** … … 432 429 $post = apply_filters('attachment_fields_to_save', $post, $attachment); 433 430 431 if ( isset($attachment['image_alt']) && !empty($attachment['image_alt']) ) { 432 $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); 433 if ( $image_alt != stripslashes($attachment['image_alt']) ) { 434 $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true ); 435 // update_meta expects slashed 436 update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) ); 437 } 438 } 439 434 440 if ( isset($post['errors']) ) { 435 441 $errors[$attachment_id] = $post['errors']; … … 440 446 wp_update_post($post); 441 447 442 foreach ( get_attachment_taxonomies($post) as $t ) 448 foreach ( get_attachment_taxonomies($post) as $t ) { 443 449 if ( isset($attachment[$t]) ) 444 450 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); 451 } 445 452 } 446 453 … … 890 897 function image_attachment_fields_to_edit($form_fields, $post) { 891 898 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 899 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); 900 if ( empty($alt) ) 901 $alt = ''; 902 892 903 $form_fields['post_title']['required'] = true; 893 $file = wp_get_attachment_url($post->ID); 894 895 $form_fields['image_url']['value'] = $file; 896 897 $form_fields['post_excerpt']['label'] = __('Caption'); 898 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image'); 899 900 $form_fields['post_content']['label'] = __('Description'); 904 905 $form_fields['image_alt'] = array( 906 'value' => $alt, 907 'label' => __('Alternate text'), 908 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”') 909 ); 901 910 902 911 $form_fields['align'] = array( … … 906 915 ); 907 916 908 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size')); 917 $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size') ); 918 919 } else { 920 unset( $form_fields['image_alt'] ); 909 921 } 910 922 return $form_fields; … … 968 980 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 969 981 $url = $attachment['url']; 970 971 if ( isset($attachment['align']) ) 972 $align = $attachment['align']; 973 else 974 $align = 'none'; 975 976 if ( !empty($attachment['image-size']) ) 977 $size = $attachment['image-size']; 978 else 979 $size = 'medium'; 980 982 $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; 983 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; 984 $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : ''; 981 985 $rel = ( $url == get_attachment_link($attachment_id) ); 982 986 983 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size );987 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); 984 988 } 985 989 … … 1011 1015 'post_title' => array( 1012 1016 'label' => __('Title'), 1013 'value' => $edit_post->post_title ,1017 'value' => $edit_post->post_title 1014 1018 ), 1019 'image_alt' => array(), 1015 1020 'post_excerpt' => array( 1016 1021 'label' => __('Caption'), 1017 'value' => $edit_post->post_excerpt ,1022 'value' => $edit_post->post_excerpt 1018 1023 ), 1019 1024 'post_content' => array( 1020 1025 'label' => __('Description'), 1021 1026 'value' => $edit_post->post_content, 1022 'input' => 'textarea' ,1027 'input' => 'textarea' 1023 1028 ), 1024 1029 'url' => array( … … 1026 1031 'input' => 'html', 1027 1032 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 1028 'helps' => __('Enter a link URL or click above for presets.') ,1033 'helps' => __('Enter a link URL or click above for presets.') 1029 1034 ), 1030 1035 'menu_order' => array( … … 1036 1041 'input' => 'html', 1037 1042 'html' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />", 1038 'value' => isset($edit_post->post_url) ? $edit_post->post_url : '',1039 'helps' => __('Location of the uploaded file.') ,1043 'value' => isset($edit_post->post_url) ? $edit_post->post_url : wp_get_attachment_url($post->ID), 1044 'helps' => __('Location of the uploaded file.') 1040 1045 ) 1041 1046 ); … … 1526 1531 1527 1532 insert : function() { 1528 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;1533 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; 1529 1534 1530 1535 if ( '' == f.src.value || '' == t.width ) return false; 1531 1536 1532 1537 if ( f.title.value ) { 1533 title = f.title.value.replace(/ ['"<>]+/g, '');1538 title = f.title.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 1534 1539 title = ' title="'+title+'"'; 1535 1540 } 1536 1541 1537 if ( f.alt.value ) { 1538 alt = f.alt.value.replace(/['"<>]+/g, ''); 1542 if ( f.alt.value ) 1543 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 1544 1539 1545 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?> 1540 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 1546 if ( f.caption.value ) 1547 caption = f.caption.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 1541 1548 <?php } ?> 1542 }1543 1549 1544 1550 cls = caption ? '' : ' class="'+t.align+'"'; … … 1916 1922 function type_url_form_image() { 1917 1923 1918 if ( apply_filters( 'disable_captions', '' ) ) { 1919 $alt = __('Alternate Text'); 1920 $alt_help = __('Alt text for the image, e.g. “The Mona Lisa”'); 1924 if ( !apply_filters( 'disable_captions', '' ) ) { 1925 $caption = ' 1926 <tr> 1927 <th valign="top" scope="row" class="label"> 1928 <span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span> 1929 </th> 1930 <td class="field"><input id="caption" name="caption" value="" type="text" /></td> 1931 </tr> 1932 '; 1921 1933 } else { 1922 $alt = __('Image Caption'); 1923 $alt_help = __('Also used as alternate text for the image'); 1934 $caption = ''; 1924 1935 } 1925 1936 … … 1943 1954 <span class="alignright"><abbr title="required" class="required">*</abbr></span> 1944 1955 </th> 1945 <td class="field">< p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>1956 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> 1946 1957 </tr> 1947 1958 1948 1959 <tr> 1949 1960 <th valign="top" scope="row" class="label"> 1950 <span class="alignleft"><label for="alt">' . $alt. '</label></span>1961 <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span> 1951 1962 </th> 1952 1963 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> 1953 <p class="help">' . $alt_help. '</p></td>1964 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> 1954 1965 </tr> 1955 1966 ' . $caption . ' 1956 1967 <tr class="align"> 1957 1968 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
Note: See TracChangeset
for help on using the changeset viewer.