__('From Computer'), // handler function name => tab text ); return apply_filters('image_upload_tabs', $_default_tabs); } function the_image_upload_tabs() { $tabs = image_upload_tabs(); if ( !empty($tabs) ) { echo "\n"; } } function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { $html = get_image_tag($id, $alt, $title, $align, $rel, $size); $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; if ( $url ) $html = "$html"; elseif ( $size == 'thumb' || $size == 'medium' ) $html = ''.$html.''; $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url ); return $html; } function media_send_to_editor($html) { ?> false); $file = wp_handle_upload($_FILES[$file_id], $overrides); if ( isset($file['error']) ) return new wp_error( 'upload_error', $file['error'] ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = preg_replace('/\.[^.]+$/', '', basename($file)); $content = ''; // use image exif/iptc data for title and caption defaults if possible if ( $image_meta = @wp_read_image_metadata($file) ) { if ( trim($image_meta['title']) ) $title = $image_meta['title']; if ( trim($image_meta['caption']) ) $content = $image_meta['caption']; } // Construct the attachment array $attachment = array_merge( array( 'post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content, ), $post_data ); // Save the data $id = wp_insert_attachment($attachment, $file, $post_parent); if ( !is_wp_error($id) ) { wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); } return $id; } // wrap iframe content (produced by $content_func) in a doctype, html head/body etc // any additional function args will be passed to content_func function wp_iframe($content_func /* ... */) { ?> > <?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — WordPress " . __('Add media'). ''; } add_action( 'media_buttons', 'media_buttons' ); function media_buttons_head() { $siteurl = get_option('siteurl'); echo "\n"; } add_action( 'admin_print_scripts', 'media_buttons_head' ); function media_admin_css() { wp_admin_css('css/media'); } add_action('media_upload_multimedia', 'multimedia_upload_handler'); add_action('admin_head_image_upload_form', 'media_admin_css'); function multimedia_upload_handler() { if ( !current_user_can('upload_files') ) { return new wp_error( 'upload_not_allowed', __('You are not allowed to upload files.') ); } // no button click, we're just displaying the form if ( empty($_POST) ) return wp_iframe( 'multimedia_upload_form' ); check_admin_referer('multimedia-form'); // Insert multimedia button was clicked if ( !empty($_FILES) ) { // Upload File button was clicked $id = media_handle_upload('async-upload', $_REQUEST['post_id']); if ( is_wp_error($id) ) $errors['upload_error'] = $id; } if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { $post = $_post = get_post($attachment_id, ARRAY_A); if ( isset($attachment['post_content']) ) $post['post_content'] = $attachment['post_content']; if ( isset($attachment['post_title']) ) $post['post_title'] = $attachment['post_title']; if ( isset($attachment['post_excerpt']) ) $post['post_excerpt'] = $attachment['post_excerpt']; $post = apply_filters('attachment_fields_to_save', $post, $attachment); if ( isset($post['errors']) ) { $errors[$attachment_id] = $post['errors']; unset($post['errors']); } if ( $post != $_post ) wp_update_post($post); foreach ( get_attachment_taxonomies($post) as $t ) if ( isset($attachment[$t]) ) wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); } if ( isset($_POST['insert-multimedia']) ) return media_send_to_editor('[gallery]'); if ( isset($_POST['send']) ) { $send_id = (int) array_shift(array_keys($_POST['send'])); $attachment = $_POST['attachments'][$send_id]; $html = apply_filters('media_send_to_editor', get_the_attachment_link($send_id, 0, array(125,125), !empty($attachment['post_content'])), $send_id, $attachment); return media_send_to_editor($html); } wp_iframe( 'multimedia_upload_form', $errors ); } function get_multimedia_items( $post_id, $errors ) { $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=\"menu_order ASC, ID ASC\""); if ( empty($attachments) ) return ''; foreach ( $attachments as $id => $attachment ) { $output .= "\n
"; $output .= get_multimedia_item($id, isset($errors[$id]) ? $errors[$id] : null); $output .= "
\n
"; } return $output; } function get_attachment_taxonomies($attachment) { if ( is_int( $attachment ) ) $attachment = get_post($attachment); else if ( is_array($attachment) ) $attachment = (object) $attachment; if ( ! is_object($attachment) ) return array(); $filename = basename($attachment->guid); $objects = array('attachment'); if ( false !== strpos($filename, '.') ) $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); if ( !empty($attachment->post_mime_type) ) { $objects[] = 'attachment:' . $attachment->post_mime_type; if ( false !== strpos($attachment->post_mime_type, '/') ) foreach ( explode('/', $attachment->post_mime_type) as $token ) if ( !empty($token) ) $objects[] = "attachment:$token"; } $taxonomies = array(); foreach ( $objects as $object ) if ( $taxes = get_object_taxonomies($object) ) $taxonomies = array_merge($taxonomies, $taxes); return array_unique($taxonomies); } function image_attachment_fields_to_edit($form_fields, $post) { if ( substr($post->post_mime_type, 0, 5) == 'image' ) { $form_fields['post_title']['required'] = true; $form_fields['post_excerpt']['label'] = __('Description'); $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"'); $form_fields['post_content']['label'] = __('Long Description'); $thumb = wp_get_attachment_thumb_url(); $form_fields['_send']['url'] = array( 'label' => __('Link URL'), 'input' => 'html', 'html' => '', 'helps' => __('If filled, this will override the default link URL.'), ); $form_fields['_send']['align'] = array( 'label' => __('Alignment'), 'input' => 'html', 'html' => " \n", ); $form_fields['_send']['image-size'] = array( 'label' => __('Size'), 'input' => 'html', 'html' => " " . ( $thumb ? " " : '' ) . " ", ); } return $form_fields; } add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2); function image_attachment_fields_to_save($post, $attachment) { if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { if ( strlen(trim($post['post_title'])) == 0 ) { $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); } } return $post; } add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2); function image_media_send_to_editor($html, $attachment_id, $attachment) { $post =& get_post($attachment_id); if ( substr($post->post_mime_type, 0, 5) == 'image' ) { if ( !empty($attachment['url']) ) $url = $attachment['url']; elseif ( $rel = strlen(trim($post->post_content)) ) $url = get_attachment_link($attachment_id); else $url = wp_get_attachment_url($attachment_id); if ( isset($attachment['align']) ) $align = $attachment['align']; else $align = 'none'; if ( !empty($attachment['image-size']) ) $size = $attachment['image-size']; else $size = 'medium'; return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size); } return $html; } add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); function get_attachment_fields_to_edit($post, $errors = null) { if ( is_int($post) ) $post =& get_post($post); if ( is_array($post) ) $post = (object) $post; $edit_post = sanitize_post($post, 'edit'); $form_fields = array( 'post_title' => array( 'label' => __('Title'), 'value' => $edit_post->post_title, ), 'post_excerpt' => array( 'label' => __('Description'), 'value' => $edit_post->post_excerpt, ), 'post_content' => array( 'label' => __('Long description'), 'value' => $edit_post->post_content, 'input' => 'textarea', 'helps' => array(__('If filled, the default link URL will be the attachment permalink.')), ), ); foreach ( get_attachment_taxonomies($post) as $taxonomy ) { $t = (array) get_taxonomy($taxonomy); if ( empty($t['label']) ) $t['label'] = $taxonomy; if ( empty($t['args']) ) $t['args'] = array(); $terms = get_object_term_cache($post->ID, $taxonomy); if ( empty($terms) ) $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); $values = array(); foreach ( $terms as $term ) $values[] = $term->name; $t['value'] = join(', ', $values); $form_fields[$taxonomy] = $t; } // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) $form_fields = array_merge_recursive($form_fields, (array) $errors); $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post); return $form_fields; } function get_multimedia_item( $attachment_id, $errors = null, $send = true ) { $thumb_url = array_shift(get_attachment_icon_src( $attachment_id )); $title_label = __('Title'); $description_label = __('Description'); $tags_label = __('Tags'); $toggle_on = __('Show'); $toggle_off = __('Hide'); $post = get_post($attachment_id); $filename = basename($post->guid); $title = attribute_escape($post->post_title); $description = attribute_escape($post->post_content); if ( $_tags = get_the_tags($attachment_id) ) { foreach ( $_tags as $tag ) $tags[] = $tag->name; $tags = attribute_escape(join(', ', $tags)); } $form_fields = get_attachment_fields_to_edit($post, $errors); $class = empty($errors) ? 'startclosed' : 'startopen'; $item = " $toggle_on $toggle_off $filename \n"; $defaults = array( 'input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array(), ); $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id); $delete = __('Delete'); $save = ""; $send = ""; if ( empty($form_fields['save']) && empty($form_fields['_send']) ) { $form_fields['save'] = array('tr' => "\t\t\n"); } elseif ( empty($form_fields['save']) ) { $form_fields['save'] = array('tr' => "\t\t\n"); foreach ( $form_fields['_send'] as $id => $field ) $form_fields[$id] = $field; $form_fields['send'] = array('tr' => "\t\t"); } $hidden_fields = array(); foreach ( $form_fields as $id => $field ) { if ( $id{0} == '_' ) continue; if ( !empty($field['tr']) ) { $item .= $field['tr']; continue; } $field = array_merge($defaults, $field); $name = "attachments[$attachment_id][$id]"; if ( $field['input'] == 'hidden' ) { $hidden_fields[$name] = $field['value']; continue; } $required = $field['required'] ? '*' : ''; $item .= "\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n"; $extra_rows = array(); if ( !empty($field['errors']) ) foreach ( array_unique((array) $field['errors']) as $error ) $extra_rows['error'][] = $error; if ( !empty($field['helps']) ) foreach ( array_unique((array) $field['helps']) as $help ) $extra_rows['help'][] = $help; if ( !empty($field['extra_rows']) ) foreach ( $field['extra_rows'] as $class => $rows ) foreach ( (array) $rows as $html ) $extra_rows[$class][] = $html; foreach ( $extra_rows as $class => $rows ) foreach ( $rows as $html ) $item .= "\t\t\n"; } if ( !empty($form_fields['_final']) ) $item .= "\t\t\n"; $item .= "\t
$filename
$post->post_mime_type
" . mysql2date($post->post_date, get_option('time_format')) . "
" . apply_filters('multimedia_meta', '', $post) . "
$delete$save$send
$save
$delete$send
$required"; if ( !empty($field[$field['input']]) ) $item .= $field[$field['input']]; elseif ( $field['input'] == 'textarea' ) { $item .= ""; } else { $item .= ""; } $item .= "
$html
{$form_fields['_final']}
\n"; foreach ( $hidden_fields as $name => $value ) $item .= "\t\n"; return $item; } function multimedia_upload_form( $errors = null ) { $flash_action_url = get_option('siteurl') . '/wp-admin/async-upload.php?type=multimedia'; $form_action_url = get_option('siteurl') . '/wp-admin/media-upload.php?type=multimedia'; $post_id = intval($_REQUEST['post_id']); ?>

get_error_message(); ?>


__('People'), 'template' => __('People: %l'), 'helps' => __('Left to right, top to bottom.'), 'sort' => true, 'args' => array( 'orderby' => 'term_order' ) ) ); */ /* register_taxonomy('movie_director', 'attachment:video', array('label'=>__('Directors'), 'template'=>__('Directed by %l.'))); register_taxonomy('movie_producer', 'attachment:video', array('label'=>__('Producers'), 'template'=>__('Produced by %l.'))); register_taxonomy('movie_screenwriter', 'attachment:video', array('label'=>__('Screenwriter'), 'template'=>__('Screenplay by %l.'))); register_taxonomy('movie_actor', 'attachment:video', array('label'=>__('Cast'), 'template'=>array(__('Cast: %l.'))); register_taxonomy('movie_crew', 'attachment:video', array('label'=>__('Crew'), 'template'=>array(__('Crew: %l.'))); */ ?>