media-tab.php
153 lines
| 1 | <?php |
| 2 | global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
| 3 | |
| 4 | media_upload_header(); |
| 5 | |
| 6 | $post_id = intval($_REQUEST['post_id']); |
| 7 | |
| 8 | $form_action_url = admin_url("media-upload.php?type=$type&tab=<pluginname>&post_id=$post_id"); |
| 9 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
| 10 | $form_class = 'media-upload-form validate'; |
| 11 | |
| 12 | if ( get_user_setting('uploader') ) |
| 13 | $form_class .= ' html-uploader'; |
| 14 | $paged = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0; |
| 15 | if ( $paged < 1 ) |
| 16 | $paged = 1; |
| 17 | $start = ( $paged - 1 ) * 10; |
| 18 | if ( $start < 1 ) |
| 19 | $start = 0; |
| 20 | |
| 21 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
| 22 | ?> |
| 23 | <form id="filter" action="" method="get"> |
| 24 | <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> |
| 25 | <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> |
| 26 | <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
| 27 | <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> |
| 28 | |
| 29 | <p id="media-search"> |
| 30 | <label for="media-search-input"><?php _e('Search Media');?>:</label> |
| 31 | <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> |
| 32 | <?php submit_button( __( 'Search Media' ), 'button', '', false ); ?> |
| 33 | </p> |
| 34 | |
| 35 | <ul> |
| 36 | <?php |
| 37 | $type_links = array(); |
| 38 | $_num_posts = (array) wp_count_attachments(); |
| 39 | $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
| 40 | foreach ( $matches as $_type => $reals ) |
| 41 | foreach ( $reals as $real ) |
| 42 | if ( isset($num_posts[$_type]) ) |
| 43 | $num_posts[$_type] += $_num_posts[$real]; |
| 44 | else |
| 45 | $num_posts[$_type] = $_num_posts[$real]; |
| 46 | // If available type specified by media button clicked, filter by that type |
| 47 | if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { |
| 48 | $_GET['post_mime_type'] = $type; |
| 49 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
| 50 | } |
| 51 | if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
| 52 | $class = ''; |
| 53 | else |
| 54 | $class = ''; |
| 55 | $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; |
| 56 | foreach ( $post_mime_types as $mime_type => $label ) { |
| 57 | $class = ''; |
| 58 | |
| 59 | if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
| 60 | continue; |
| 61 | |
| 62 | if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
| 63 | $class = ''; |
| 64 | |
| 65 | $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>'; |
| 66 | } |
| 67 | echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; |
| 68 | unset($type_links); |
| 69 | ?> |
| 70 | </ul> |
| 71 | |
| 72 | <div> |
| 73 | |
| 74 | <?php |
| 75 | $page_links = paginate_links( array( |
| 76 | 'base' => add_query_arg( 'paged', '%#%' ), |
| 77 | 'format' => '', |
| 78 | 'prev_text' => __('«'), |
| 79 | 'next_text' => __('»'), |
| 80 | 'total' => ceil($wp_query->found_posts / 10), |
| 81 | 'current' => $paged |
| 82 | )); |
| 83 | |
| 84 | if ( $page_links ) |
| 85 | echo "<div class='tablenav-pages'>$page_links</div>"; |
| 86 | ?> |
| 87 | |
| 88 | <div> |
| 89 | <?php |
| 90 | |
| 91 | $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
| 92 | |
| 93 | $arc_result = $wpdb->get_results( $arc_query ); |
| 94 | |
| 95 | $month_count = count($arc_result); |
| 96 | |
| 97 | if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> |
| 98 | <select name='m'> |
| 99 | <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option> |
| 100 | <?php |
| 101 | foreach ($arc_result as $arc_row) { |
| 102 | if ( $arc_row->yyear == 0 ) |
| 103 | continue; |
| 104 | $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
| 105 | |
| 106 | if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) ) |
| 107 | $default = ' selected="selected"'; |
| 108 | else |
| 109 | $default = ''; |
| 110 | |
| 111 | echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
| 112 | echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); |
| 113 | echo "</option>\n"; |
| 114 | } |
| 115 | ?> |
| 116 | </select> |
| 117 | <?php } ?> |
| 118 | |
| 119 | <?php submit_button( __( 'Filter »' ), 'secondary', 'post-query-submit', false ); ?> |
| 120 | |
| 121 | </div> |
| 122 | |
| 123 | <br /> |
| 124 | </div> |
| 125 | </form> |
| 126 | |
| 127 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" id="<pluginname>-form"> |
| 128 | |
| 129 | <?php wp_nonce_field('media-form'); ?> |
| 130 | <?php //media_upload_form( $errors ); ?> |
| 131 | |
| 132 | <script type="text/javascript"> |
| 133 | <!-- |
| 134 | jQuery(function($){ |
| 135 | var preloaded = $(".media-item.preloaded"); |
| 136 | if ( preloaded.length > 0 ) { |
| 137 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
| 138 | updateMediaForm(); |
| 139 | } |
| 140 | }); |
| 141 | --> |
| 142 | </script> |
| 143 | |
| 144 | <div id="media-items"> |
| 145 | <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> |
| 146 | <?php echo get_media_items(null, $errors); ?> |
| 147 | </div> |
| 148 | <p> |
| 149 | <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?> |
| 150 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
| 151 | </p> |
| 152 | </form> |
| 153 |