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

git-svn-id: http://svn.automattic.com/wordpress/trunk@8653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-15 15:40:35 +00:00
parent 02f5232d6e
commit 2955c83e99
4 changed files with 106 additions and 25 deletions

View File

@ -520,10 +520,27 @@ function media_upload_library() {
return wp_iframe( 'media_upload_library_form', $errors );
}
// produce HTML for the image alignment radio buttons with the specified one checked
function image_align_input_fields($post, $checked='') {
$alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
if ( !array_key_exists($checked, $alignments) )
$checked = 'none';
$out = array();
foreach ($alignments as $name => $label) {
$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='none'".
( $checked == $name ? " checked='checked'" : "" ) .
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>";
}
return join("\n", $out);
}
// produce HTML for the size radio buttons with the specified one checked
function image_size_input_fields($post, $checked='') {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
$sizes = array();
$size_names = array('thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
foreach ( $size_names as $size => $name) {
@ -555,6 +572,27 @@ function image_size_input_fields($post, $checked='') {
);
}
// produce HTML for the Link URL buttons with the default link type as specified
function image_link_input_fields($post, $url_type='') {
$file = wp_get_attachment_url($post->ID);
$link = get_attachment_link($post->ID);
$url = '';
if ( $url_type == 'file' )
$url = $file;
elseif ( $url_type == 'post' )
$url = $link;
return "<input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br />
<button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
<button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
<button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
<script type='text/javascript'>
jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
</script>\n";
}
function image_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
$form_fields['post_title']['required'] = true;
@ -567,17 +605,10 @@ function image_attachment_fields_to_edit($form_fields, $post) {
$form_fields['align'] = array(
'label' => __('Alignment'),
'input' => 'html',
'html' => "
<input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
<label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
<input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
<label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
<input type='radio' name='attachments[$post->ID][align]' id='image-align-center-$post->ID' value='center' />
<label for='image-align-center-$post->ID' class='align image-align-center-label'>" . __('Center') . "</label>
<input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
<label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
'html' => image_align_input_fields($post, get_option('image_default_align')),
);
$form_fields['image-size'] = image_size_input_fields($post);
$form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
}
return $form_fields;
}
@ -654,14 +685,7 @@ function get_attachment_fields_to_edit($post, $errors = null) {
'url' => array(
'label' => __('Link URL'),
'input' => 'html',
'html' => "
<input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
<button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
<button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
<button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
<script type='text/javascript'>
jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
</script>\n",
'html' => image_link_input_fields($post, get_option('image_default_link_type')),
'helps' => __('Enter a link URL or click above for presets.'),
),
'menu_order' => array(
@ -1312,6 +1336,10 @@ function type_form_image() {
$alt_help = __('Also used as alternate text for the image');
}
$default_align = get_option('image_default_align');
if ( empty($default_align) )
$default_align = 'none';
return '
<table class="describe"><tbody>
<tr>
@ -1341,13 +1369,13 @@ function type_form_image() {
<tr class="align">
<th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
<td class="field">
<input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" />
<input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
<label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
<input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" />
<input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
<label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
<input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" />
<input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
<label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
<input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" />
<input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
<label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
</td>
</tr>

View File

@ -262,6 +262,13 @@ function populate_options() {
add_option('large_size_w', 1024);
add_option('large_size_h', 1024);
// 2.7
add_option('large_size_w', 1024);
add_option('large_size_h', 1024);
add_option('image_default_link_type', 'file');
add_option('image_default_size', '');
add_option('image_default_align', '');
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
foreach ($unusedoptions as $option) :

View File

@ -71,6 +71,52 @@ include('admin-header.php');
<input name="large_size_h" type="text" id="large_size_h" value="<?php form_option('large_size_h'); ?>" size="6" />
</fieldset></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Default image size') ?></th>
<td><fieldset><legend class="hidden"><?php _e('Default image size') ?></legend>
<?php
$size_names = array('' => 'Auto', 'thumbnail' => 'Thumbnail', 'medium' => 'Medium', 'large' => 'Large', 'full' => 'Full size');
foreach ($size_names as $size => $name) { ?>
<input type="radio" name="image_default_size" id="image_default_size_<?php echo $size; ?>" value="<?php echo $size; ?>"<?php echo (get_option('image_default_size') == $size ? ' checked="checked"' : ''); ?> />
<label for="image_default_size_<?php echo $size; ?>"><?php _e($name); ?></label>
<?php
}
?>
</fieldset></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Default image alignment') ?></th>
<td><fieldset><legend class="hidden"><?php _e('Default image alignment') ?></legend>
<?php
$alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
foreach ($alignments as $align => $name) { ?>
<input type="radio" name="image_default_align" id="image_default_align_<?php echo $align; ?>" value="<?php echo $align; ?>"<?php echo (get_option('image_default_align') == $align ? ' checked="checked"' : ''); ?> />
<label for="image_default_align_<?php echo $align; ?>"><?php _e($name); ?></label>
<?php
}
?>
</fieldset></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Default image links') ?></th>
<td><fieldset><legend class="hidden"><?php _e('Default image links') ?></legend>
<?php
$link_types = array('' => 'None', 'post' => 'Post URL', 'file' => 'File');
foreach ($link_types as $type => $name) { ?>
<input type="radio" name="image_default_link_type" id="image_default_link_type_<?php echo $type; ?>" value="<?php echo $type; ?>"<?php echo (get_option('image_default_link_type') == $type ? ' checked="checked"' : ''); ?> />
<label for="image_default_link_type_<?php echo $type; ?>"><?php _e($name); ?></label>
<?php
}
?>
</fieldset></td>
</tr>
</table>
@ -99,7 +145,7 @@ include('admin-header.php');
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="hack_file,use_linksupdate,uploads_use_yearmonth_folders,upload_path,upload_url_path,thumbnail_size_w,thumbnail_size_h,thumbnail_crop,medium_size_w,medium_size_h" />
<input type="hidden" name="page_options" value="hack_file,use_linksupdate,uploads_use_yearmonth_folders,upload_path,upload_url_path,thumbnail_size_w,thumbnail_size_h,thumbnail_crop,medium_size_w,medium_size_h,image_default_size,image_default_align,image_default_link_type" />
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" class="button" />
</p>
</form>

View File

@ -15,6 +15,6 @@ $wp_version = '2.7-bleeding';
*
* @global int $wp_db_version
*/
$wp_db_version = 8586;
$wp_db_version = 8645;
?>