__('New Upload'),
'input' => 'html',
'html' => ""
);
return $form_fields;
}//async-upload
add_filter('attachment_fields_to_save', 'wp_ae_attachment_fields_to_save', 1, 2);
function wp_ae_attachment_fields_to_save($form_fields, $post){
$form_fields['ae-upload'] = array(
'label' => __('New Upload'),
'input' => 'html',
'html' => ""
);
return $form_fields;
}//async-upload
add_action('edit_attachment', 'wp_ae_edit_attachment');
function wp_ae_edit_attachment($id){
$thumbnail['w'] = get_option("thumbnail_size_w");
$thumbnail['h'] = get_option("thumbnail_size_h");
$thumbnail['c'] = get_option("thumbnail_crop");
$medium['w'] = get_option("medium_size_w");
$medium['h'] = get_option("medium_size_h");
$medium['c'] = get_option("medium_crop");
$files = array();
foreach ($_FILES['attachments'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files)){
$files[$i] = array();
}
$files[$i][$k] = $v['ae-upload'];
}
}
foreach( $files as $k => $file ){
if (!isset($file) || !is_uploaded_file($file["tmp_name"]) || $file["error"] != 0) {}
else{
$post = wp_get_single_post($k, ARRAY_A);
include_once('class.upload.php');
$uploads = wp_upload_dir($post['post_date']);
$handle = new Upload($file);
$handle->file_overwrite = true;
$handle->file_auto_rename = false;
$handle->file_new_name_body = $post['post_name'];
if ($handle->uploaded) {
$path = explode('/', get_attached_file($k, true) );
array_pop($path);
$path = join( '/', $path );
$imagedata = wp_get_attachment_metadata( $k );
$handle->process($uploads['path']);
if( $handle->file_is_image ){
$tmppath = $path . '/' . $imagedata['sizes']['thumbnail']['file'];
if( file_exists( $tmppath ) ){
@unlink( $tmppath );
}
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_ratio_crop = $thumbnail['c'];
$handle->image_x = $thumbnail['w'];
$handle->image_y = $thumbnail['h'];
$handle->file_new_name_body = $post['post_name'] . "-{$thumbnail['w']}x{$thumbnail['h']}";
$handle->process($uploads['path']);
$imagedata['sizes']['thumbnail']['file'] = $handle->file_dst_name;
$imagedata['sizes']['thumbnail']['width'] = $handle->image_dst_x;
$imagedata['sizes']['thumbnail']['height'] = $handle->image_dst_h;
$tmppath = $path . '/' . $imagedata['sizes']['medium']['file'];
if( file_exists( $tmppath ) ){
@unlink( $tmppath );
}
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_ratio_crop = $medium['c'];
$handle->image_x = $medium['w'];
$handle->image_y = $medium['h'];
$handle->file_new_name_body = $post['post_name'] . "-{$medium['w']}x{$medium['h']}";
$handle->process($uploads['path']);
$imagedata['sizes']['medium']['file'] = $handle->file_dst_name;
$imagedata['sizes']['medium']['width'] = $handle->image_dst_x;
$imagedata['sizes']['medium']['height'] = $handle->image_dst_h;
}
if ($handle->processed) {
wp_update_attachment_metadata($k, $imagedata );
$handle->clean();
} else {}
}
}
}
}
add_action('admin_head', 'wp_ae_add_js');
function wp_ae_add_js(){
$blogsurl = get_bloginfo('wpurl') . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/attachment-extender.php';
echo "
";
}
?>