WordPress.org

Plugin Directory

Changeset 378408


Ignore:
Timestamp:
04/28/11 14:43:21 (7 years ago)
Author:
johnfjohnf
Message:

Fix attaching video to post

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external-videos/trunk/ev-media-gallery.php

    r376751 r378408  
    3636 
    3737add_action('media_upload_external_videos', 'media_upload_external_videos'); 
     38// see media.php media_upload_library() to update 
    3839function media_upload_external_videos() { 
    3940    $errors = array(); 
     
    5152 
    5253 
     54// see media.php media_upload_library_form() to update 
    5355function media_upload_external_videos_form($errors) { 
    5456    global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; 
     
    8284    <label class="ev-screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> 
    8385    <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> 
    84     <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" /> 
     86    <?php submit_button( __( 'Search Media' ), 'button', '', false ); ?> 
    8587</p> 
     88 
     89<ul class="subsubsub"> 
     90<?php 
     91$type_links = array(); 
     92$_num_posts = (array) wp_count_attachments(); 
     93$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 
     94foreach ( $matches as $_type => $reals ) 
     95    foreach ( $reals as $real ) 
     96        if ( isset($num_posts[$_type]) ) 
     97            $num_posts[$_type] += $_num_posts[$real]; 
     98        else 
     99            $num_posts[$_type] = $_num_posts[$real]; 
     100// If available type specified by media button clicked, filter by that type 
     101if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { 
     102    $_GET['post_mime_type'] = $type; 
     103    list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); 
     104} 
     105if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) 
     106    $class = ' class="current"'; 
     107else 
     108    $class = ''; 
     109$type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; 
     110foreach ( $post_mime_types as $mime_type => $label ) { 
     111    $class = ''; 
     112 
     113    if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) 
     114        continue; 
     115 
     116    if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) 
     117        $class = ' class="current"'; 
     118 
     119    $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; 
     120} 
     121echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; 
     122unset($type_links); 
     123?> 
     124</ul> 
    86125 
    87126<div class="tablenav"> 
     
    131170</select> 
    132171<?php } ?> 
    133 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter &#187;' ) ); ?>" class="button-secondary" /> 
     172 
     173<?php submit_button( __( 'Filter &#187;' ), 'secondary', 'post-query-submit', false ); ?> 
    134174 
    135175</div> 
     
    161201</div> 
    162202<p class="ml-submit"> 
    163 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" /> 
     203<?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?> 
    164204<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
    165205</p> 
     
    176216    $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; 
    177217    $q['post_type'] = 'external-videos'; 
     218    $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit'; 
    178219    $media_per_page = (int) get_user_option( 'upload_per_page' ); 
    179220    if ( empty( $media_per_page ) || $media_per_page < 1 ) 
     
    187228        unset($q['post_mime_type']); 
    188229 
    189     wp($q); 
     230    if ( isset($q['detached']) ) 
     231        add_filter('posts_where', '_edit_attachments_query_helper'); 
     232 
     233    wp( $q ); 
     234 
     235    if ( isset($q['detached']) ) 
     236        remove_filter('posts_where', '_edit_attachments_query_helper'); 
    190237 
    191238    return array($post_mime_types, $avail_post_mime_types); 
     
    243290 
    244291add_filter('edit_posts_per_page', 'do_attach'); 
     292// see doaction in ./wp-admin/upload.php 
    245293function do_attach($per_page) { 
    246294    global $wpdb; 
    247295 
    248296    if ( isset($_GET['attached']) && (int) $_GET['attached'] ) { 
    249         error_log("Loading"); 
    250297        $attached = (int) $_GET['attached']; 
    251298        $message = sprintf( _n('Reattached %d attachment.', 'Reattached %d attachments.', $attached), $attached ); 
     
    256303    } 
    257304    elseif ( isset($_GET['found_post_id']) && isset($_GET['media'])  ) { 
    258         // TODO Do we need this? 
    259         check_admin_referer('bulk-posts'); 
    260  
    261         if ( ! ( $parent_id = (int) $_GET['found_post_id'] ) ) 
     305        $parent_id = (int) $_REQUEST['found_post_id']; 
     306        if ( !$parent_id ) 
    262307            return; 
    263308 
     
    279324        if ( ! empty($attach) ) { 
    280325            $attach = implode(',', $attach); 
    281             $attached = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'external-videos' AND ID IN ($attach)", $parent_id) ); 
     326            $attached = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'external-videos' AND ID IN ( $attach )", $parent_id) ); 
    282327        } 
    283328 
    284329        if ( isset($attached) ) { 
    285             $location = 'edit.php'; 
     330            $location = 'upload.php'; 
    286331            if ( $referer = wp_get_referer() ) { 
    287                 if ( false !== strpos($referer, 'edit.php') ) 
     332                if ( false !== strpos($referer, 'upload.php') ) 
    288333                    $location = $referer; 
    289334            } 
Note: See TracChangeset for help on using the changeset viewer.