Make WordPress Core


Ignore:
Timestamp:
08/15/2008 03:40:35 PM (18 years ago)
Author:
ryan
Message:

Image default options for size, alignment and link type. Props tellyworth. fixes #7520

File:
1 edited

Legend:

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

    r8612 r8653  
    521521}
    522522
     523// produce HTML for the image alignment radio buttons with the specified one checked
     524function image_align_input_fields($post, $checked='') {
     525       
     526        $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
     527        if ( !array_key_exists($checked, $alignments) )
     528                $checked = 'none';
     529       
     530        $out = array();
     531        foreach ($alignments as $name => $label) {
     532       
     533                $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='none'".
     534                        ( $checked == $name ? " checked='checked'" : "" ) .
     535                        " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>";
     536        }
     537        return join("\n", $out);
     538}
     539
     540// produce HTML for the size radio buttons with the specified one checked
    523541function image_size_input_fields($post, $checked='') {
    524542               
    525543                // get a list of the actual pixel dimensions of each possible intermediate version of this image
    526                 $sizes = array();
    527544                $size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
    528545               
    … …  
    556573}
    557574
     575// produce HTML for the Link URL buttons with the default link type as specified
     576function image_link_input_fields($post, $url_type='') {
     577
     578        $file = wp_get_attachment_url($post->ID);
     579        $link = get_attachment_link($post->ID);
     580
     581        $url = '';
     582        if ( $url_type == 'file' )
     583                $url = $file;
     584        elseif ( $url_type == 'post' )
     585                $url = $link;
     586       
     587        return "<input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br />
     588                                <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
     589                                <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
     590                                <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
     591                                <script type='text/javascript'>
     592                                jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
     593                                </script>\n";
     594}
     595
    558596function image_attachment_fields_to_edit($form_fields, $post) {
    559597        if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
    … …  
    568606                        'label' => __('Alignment'),
    569607                        'input' => 'html',
    570                         'html'  => "
    571                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
    572                                 <label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
    573                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
    574                                 <label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
    575                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-center-$post->ID' value='center' />
    576                                 <label for='image-align-center-$post->ID' class='align image-align-center-label'>" . __('Center') . "</label>
    577                                 <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
    578                                 <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
     608                        'html'  => image_align_input_fields($post, get_option('image_default_align')),
    579609                );
    580                 $form_fields['image-size'] = image_size_input_fields($post);
     610               
     611                $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
    581612        }
    582613        return $form_fields;
    … …  
    655686                        'label'      => __('Link URL'),
    656687                        'input'      => 'html',
    657                         'html'       => "
    658                                 <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
    659                                 <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
    660                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
    661                                 <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
    662                                 <script type='text/javascript'>
    663                                 jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
    664                                 </script>\n",
     688                        'html'       => image_link_input_fields($post, get_option('image_default_link_type')),
    665689                        'helps'      => __('Enter a link URL or click above for presets.'),
    666690                ),
    … …  
    13131337        }
    13141338
     1339        $default_align = get_option('image_default_align');
     1340        if ( empty($default_align) )
     1341                $default_align = 'none';
     1342               
    13151343        return '
    13161344        <table class="describe"><tbody>
    … …  
    13421370                        <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
    13431371                        <td class="field">
    1344                                 <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" />
     1372                                <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
    13451373                                <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
    1346                                 <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" />
     1374                                <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
    13471375                                <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
    1348                                 <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" />
     1376                                <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
    13491377                                <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
    1350                                 <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" />
     1378                                <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
    13511379                                <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
    13521380                        </td>
Note: See TracChangeset for help on using the changeset viewer.