Make WordPress Core


Ignore:
Timestamp:
03/12/2008 05:50:07 AM (16 years ago)
Author:
ryan
Message:

Attachment editing from mdawaffe. fixes #6181

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r7258 r7262  
    485485add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
    486486
     487function media_single_attachment_fields_to_edit( $form_fields, $post ) {
     488    unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
     489    return $form_fields;
     490}
     491
    487492function image_attachment_fields_to_save($post, $attachment) {
    488493    if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
     
    549554            'input'      => 'html',
    550555            'html'       => "
    551                 <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' />
     556                <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
    552557                <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
    553558                <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
     
    605610
    606611    foreach ( $attachments as $id => $attachment )
    607         if ( $item = get_media_item($id, isset($errors[$id]) ? $errors[$id] : null) )
     612        if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
    608613            $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div id='media-upload-error-$id'></div><div class='filename'></div><div class='progress'><div class='bar'></div></div>$item<div class='progress clickmask'></div>\n</div>";
    609614
     
    611616}
    612617
    613 function get_media_item( $attachment_id, $errors = null, $send = true, $delete = true ) {
     618function get_media_item( $attachment_id, $args = null ) {
     619    $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true );
     620    $args = wp_parse_args( $args, $default_args );
     621    extract( $args, EXTR_SKIP );
     622
    614623    global $post_mime_types;
    615624    if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
     
    644653    $form_fields = get_attachment_fields_to_edit($post, $errors);
    645654
    646     $class = empty($errors) ? 'startclosed' : 'startopen';
     655    if ( $toggle ) {
     656        $class = empty($errors) ? 'startclosed' : 'startopen';
     657        $toggle_links = "
     658    <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
     659    <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
     660    } else {
     661        $class = 'form-table';
     662        $toggle_links = '';
     663    }
     664
    647665    $item = "
    648666    $type
    649     <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
    650     <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>
     667    $toggle_links
    651668    <div class='filename new'>$filename</div>
    652     <table class='slidetoggle describe $class'><tbody>
     669    <table class='slidetoggle describe $class'>
     670        <tbody class='media-item-info'>
    653671        <tr>
    654             <td class='A1B1' rowspan='4' colspan='2'><img class='thumbnail' src='$thumb_url' alt='' /></td>
     672            <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
    655673            <td>$filename</td>
    656674        </tr>
    657         <tr><td>$post->post_mime_type</td></tr>
     675        <td>$post->post_mime_type</td></tr>
    658676        <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
    659         <tr><td>" . apply_filters('media_meta', '', $post) . "</tr></td>\n";
     677        <tr><td>" . apply_filters('media_meta', '', $post) . "</tr></td>
     678        </tbody>
     679        <tbody>\n";
    660680
    661681    $defaults = array(
     
    672692        $delete = "<a href='$delete_href' id='del[$attachment_id]' disabled='disabled' class='delete'>" . __('Delete') . "</button>";
    673693    if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
    674         $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td colspan='2'></td><td class='savesend'>$send $delete</td></tr>\n");
     694        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete</td></tr>\n");
    675695
    676696    $hidden_fields = array();
     
    693713        }
    694714
    695         $required = $field['required'] ? '<abbr title="required">*</abbr>' : '';
    696         $item .= "\t\t<tr class='$id'>\n\t\t\t<td class='label'><label for='$name'>{$field['label']}</label></td>\n\t\t\t<td class='required'>$required</td>\n\t\t\t<td class='field'>";
     715        $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
     716        $class  = $id;
     717        $class .= $field['required'] ? ' form-required' : '';
     718
     719        $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'>";
    697720        if ( !empty($field[$field['input']]) )
    698721            $item .= $field[$field['input']];
     
    702725            $item .= "<input type='text' id='$name' name='$name' value='" . wp_specialchars($field['value'], 1) . "' />";
    703726        }
     727        if ( !empty($field['helps']) )
     728            $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
    704729        $item .= "</td>\n\t\t</tr>\n";
    705730
     
    709734            foreach ( array_unique((array) $field['errors']) as $error )
    710735                $extra_rows['error'][] = $error;
    711 
    712         if ( !empty($field['helps']) )
    713             foreach ( array_unique((array) $field['helps']) as $help )
    714                 $extra_rows['help'][] = $help;
    715736
    716737        if ( !empty($field['extra_rows']) )
     
    721742        foreach ( $extra_rows as $class => $rows )
    722743            foreach ( $rows as $html )
    723                 $item .= "\t\t<tr><td colspan='2'></td><td class='$class'>$html</td></tr>\n";
     744                $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
    724745    }
    725746
    726747    if ( !empty($form_fields['_final']) )
    727         $item .= "\t\t<tr class='final'><td colspan='3'>{$form_fields['_final']}</td></tr>\n";
     748        $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
    728749    $item .= "\t</table>\n";
    729750
     
    10381059    <table class="describe"><tbody>
    10391060        <tr>
    1040             <td class="label"><label for="insertonly[src]">' . __('Image URL') . '</label></td>
    1041             <td class="required"><abbr title="required">*</abbr></td>
     1061            <th valign="top" scope="row" class="label">
     1062                <span class="alignleft"><label for="insertonly[src]">' . __('Image URL') . '</label></span>
     1063                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1064            </th>
    10421065            <td class="field"><input id="insertonly[src]" name="insertonly[src]" value="" type="text"></td>
    10431066        </tr>
    10441067        <tr>
    1045             <td class="label"><label for="insertonly[alt]">' . __('Description') . '</label></td>
    1046             <td class="required"><abbr title="required">*</abbr></td>
     1068            <th valign="top" scope="row" class="label">
     1069                <span class="alignleft"><label for="insertonly[alt]">' . __('Description') . '</label></span>
     1070                <span class="alignright"><abbr title="required">*</abbr></span>
     1071            </th>
    10471072            <td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text"></td>
    10481073        </tr>
    1049         <tr><td colspan="2"></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr>
     1074        <tr><td></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr>
    10501075        <tr class="align">
    1051             <td class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></td>
    1052             <td class="required"></td>
     1076            <th valign="top" scope="row" class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></th>
    10531077            <td class="field">
    10541078                <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio">
     
    10631087        </tr>
    10641088        <tr>
    1065             <td colspan="2"></td>
     1089            <td></td>
    10661090            <td>
    10671091                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     
    10761100    <table class="describe"><tbody>
    10771101        <tr>
    1078             <td class="label"><label for="insertonly[href]">' . __('Audio File URL') . '</label></td>
    1079             <td class="required"><abbr title="required">*</abbr></td>
     1102            <th valign="top" scope="row" class="label">
     1103                <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
     1104                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1105            </th>
    10801106            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
    10811107        </tr>
    10821108        <tr>
    1083             <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
    1084             <td class="required"><abbr title="required">*</abbr></td>
     1109            <th valign="top" scope="row" class="label">
     1110                <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
     1111                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1112            </th>
    10851113            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
    10861114        </tr>
    1087         <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
     1115        <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
    10881116        <tr>
    1089             <td colspan="2"></td>
     1117            <td></td>
    10901118            <td>
    10911119                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     
    11001128    <table class="describe"><tbody>
    11011129        <tr>
    1102             <td class="label"><label for="insertonly[href]">' . __('Video URL') . '</label></td>
    1103             <td class="required"><abbr title="required">*</abbr></td>
     1130            <th valign="top" scope="row" class="label">
     1131                <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
     1132                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1133            </th>
    11041134            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
    11051135        </tr>
    11061136        <tr>
    1107             <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
    1108             <td class="required"><abbr title="required">*</abbr></td>
     1137            <th valign="top" scope="row" class="label">
     1138                <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
     1139                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1140            </th>
    11091141            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
    11101142        </tr>
    1111         <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
     1143        <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
    11121144        <tr>
    1113             <td colspan="2"></td>
     1145            <td></td>
    11141146            <td>
    11151147                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     
    11241156    <table class="describe"><tbody>
    11251157        <tr>
    1126             <td class="label"><label for="insertonly[href]">' . __('URL') . '</label></td>
    1127             <td class="required"><abbr title="required">*</abbr></td>
     1158            <th valign="top" scope="row" class="label">
     1159                <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
     1160                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1161            </th>
    11281162            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
    11291163        </tr>
    11301164        <tr>
    1131             <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
    1132             <td class="required"><abbr title="required">*</abbr></td>
     1165            <th valign="top" scope="row" class="label">
     1166                <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
     1167                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1168            </th>
    11331169            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
    11341170        </tr>
    1135         <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
     1171        <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
    11361172        <tr>
    1137             <td colspan="2"></td>
     1173            <td></td>
    11381174            <td>
    11391175                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
Note: See TracChangeset for help on using the changeset viewer.