Make WordPress Core


Ignore:
Timestamp:
03/11/2008 01:30:15 AM (16 years ago)
Author:
matt
Message:

See #5911. Hat tip: andy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r7218 r7228  
    824824<?php media_upload_form( $errors ); ?>
    825825
     826<script type="text/javascript">
     827<!--
     828jQuery(function($){
     829    var preloaded = $(".media-item.preloaded");
     830    if ( preloaded.length > 0 ) {
     831        preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
     832    }
     833    updateMediaForm();
     834});
     835-->
     836</script>
    826837<?php if ( $id && !is_wp_error($id) ) : ?>
     838<div id="media-items">
     839<?php echo get_media_items( $id, $errors ); ?>
     840</div>
     841<input type="submit" class="button savebutton" name="save" value="<?php _e('Save all changes'); ?>" />
     842
     843<?php elseif ( is_callable($callback) ) : ?>
     844
     845<div class="media-blank">
     846<p style="text-align:center"><?php _e('&mdash; OR &mdash;'); ?></p>
     847<h3><?php _e('From URL'); ?></h3>
     848</div>
     849
     850<div id="media-items">
     851<div class="media-item media-blank">
     852<?php echo call_user_func($callback); ?>
     853</div>
     854</div>
     855<input type="submit" class="button savebutton" name="save" value="<?php _e('Save all changes'); ?>" />
     856<?php
     857    endif;
     858}
     859
     860function media_upload_gallery_form($errors) {
     861    media_upload_header();
     862
     863    $post_id = intval($_REQUEST['post_id']);
     864
     865    $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id";
     866
     867?>
     868
    827869<script type="text/javascript">
    828870<!--
     
    836878-->
    837879</script>
     880
     881<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="gallery-form">
     882<?php wp_nonce_field('media-form'); ?>
     883<?php //media_upload_form( $errors ); ?>
     884
    838885<div id="media-items">
    839 <input type="submit" class="button savebutton" name="save" value="<?php _e('Save'); ?>" />
    840 <?php echo get_media_items( $id, $errors ); ?>
    841 <input type="submit" class="button savebutton" name="save" value="<?php _e('Save'); ?>" />
     886<?php echo get_media_items($post_id, $errors); ?>
    842887</div>
    843 
    844 <?php elseif ( is_callable($callback) ) : ?>
    845 
    846 <div class="media-blank">
    847 <p style="text-align:center"><?php _e('&mdash; OR &mdash;'); ?></p>
    848 <h3><?php _e('From URL'); ?></h3>
     888<input type="submit" class="button savebutton" name="save" value="<?php _e('Save all changes'); ?>" />
     889<input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php _e('Insert gallery into post'); ?>" />
     890<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
     891<input type="hidden" name="type" value="<?php echo $GLOBALS['type']; ?>" />
     892<input type="hidden" name="tab" value="<?php echo $GLOBALS['tab']; ?>" />
     893</form>
     894<?php
     895}
     896
     897function media_upload_library_form($errors) {
     898    global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
     899
     900    media_upload_header();
     901
     902    $post_id = intval($_REQUEST['post_id']);
     903
     904    $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id";
     905
     906    $_GET['paged'] = intval($_GET['paged']);
     907    if ( $_GET['paged'] < 1 )
     908        $_GET['paged'] = 1;
     909    $start = ( $_GET['paged'] - 1 ) * 10;
     910    if ( $start < 1 )
     911        $start = 0;
     912    add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
     913
     914    list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
     915
     916?>
     917
     918<form id="filter" action="" method="get">
     919<input type="hidden" name="type" value="<?php echo $type; ?>" />
     920<input type="hidden" name="tab" value="<?php echo $tab; ?>" />
     921<input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
     922<input type="hidden" name="post_mime_type" value="<?php echo wp_specialchars($_GET['post_mime_type'], true); ?>" />
     923
     924<div id="search-filter">
     925    <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
     926    <input type="submit" value="<?php _e( 'Search Media' ); ?>" class="button" />
    849927</div>
    850928
    851 <div id="media-items">
    852 <div class="media-item media-blank">
    853 <?php echo call_user_func($callback); ?>
     929<p>
     930<ul class="subsubsub">
     931<?php
     932$type_links = array();
     933$_num_posts = (array) wp_count_attachments();
     934$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
     935foreach ( $matches as $_type => $reals )
     936    foreach ( $reals as $real )
     937        $num_posts[$_type] += $_num_posts[$real];
     938$class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
     939$type_links[] = "<li><a href='" . remove_query_arg(array('post_mime_type', 'paged', 'm')) . "'$class>".__('All Types')."</a>";
     940foreach ( $post_mime_types as $mime_type => $label ) {
     941    $class = '';
     942
     943    if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
     944        continue;
     945
     946    if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
     947        $class = ' class="current"';
     948
     949    $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf($label[2], "<span id='$mime_type-counter'>{$num_posts[$mime_type]}</span>") . '</a>';
     950}
     951echo implode(' | </li>', $type_links) . '</li>';
     952unset($type_links);
     953?>
     954</ul>
     955</p>
     956
     957<div class="tablenav">
     958
     959<?php
     960$page_links = paginate_links( array(
     961    'base' => add_query_arg( 'paged', '%#%' ),
     962    'format' => '',
     963    'total' => ceil($wp_query->found_posts / 10),
     964    'current' => $_GET['paged']
     965));
     966
     967if ( $page_links )
     968    echo "<div class='tablenav-pages'>$page_links</div>";
     969?>
     970
     971<div style="float: left">
     972<?php
     973
     974$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";
     975
     976$arc_result = $wpdb->get_results( $arc_query );
     977
     978$month_count = count($arc_result);
     979
     980if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
     981<select name='m'>
     982<option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
     983<?php
     984foreach ($arc_result as $arc_row) {
     985    if ( $arc_row->yyear == 0 )
     986        continue;
     987    $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
     988
     989    if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
     990        $default = ' selected="selected"';
     991    else
     992        $default = '';
     993
     994    echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
     995    echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
     996    echo "</option>\n";
     997}
     998?>
     999</select>
     1000<?php } ?>
     1001
     1002<input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button-secondary" />
     1003
    8541004</div>
     1005
     1006<br style="clear:both;" />
    8551007</div>
    856 <?php
    857     endif;
    858 }
    859 
    860 function media_upload_gallery_form($errors) {
    861     media_upload_header();
    862 
    863     $post_id = intval($_REQUEST['post_id']);
    864 
    865     $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=gallery&post_id=$post_id";
    866 
    867 ?>
     1008</form>
     1009
     1010<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="library-form">
     1011
     1012<?php wp_nonce_field('media-form'); ?>
     1013<?php //media_upload_form( $errors ); ?>
    8681014
    8691015<script type="text/javascript">
     
    8791025</script>
    8801026
    881 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="gallery-form">
    882 <?php wp_nonce_field('media-form'); ?>
    883 <?php //media_upload_form( $errors ); ?>
    884 
    885 <div id="media-items">
    886 <?php echo get_media_items($post_id, $errors); ?>
    887 </div>
    888 <p class="submit">
    889     <input type="submit" class="submit insert-gallery" name="insert-gallery" value="<?php _e('Insert gallery into post'); ?>" />
    890 </p>
    891 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
    892 </form>
    893 <?php
    894 }
    895 
    896 function media_upload_library_form($errors) {
    897     global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
    898 
    899     media_upload_header();
    900 
    901     $post_id = intval($_REQUEST['post_id']);
    902 
    903     $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php";
    904 
    905     $_GET['paged'] = intval($_GET['paged']);
    906     if ( $_GET['paged'] < 1 )
    907         $_GET['paged'] = 1;
    908     $start = ( $_GET['paged'] - 1 ) * 10;
    909     if ( $start < 1 )
    910         $start = 0;
    911     add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
    912 
    913     list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
    914 
    915 ?>
    916 
    917 <form id="filter" action="" method="get">
    918 <input type="hidden" name="type" value="<?php echo $type; ?>" />
    919 <input type="hidden" name="tab" value="<?php echo $tab; ?>" />
    920 <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
    921 <input type="hidden" name="post_mime_type" value="<?php echo wp_specialchars($_GET['post_mime_type'], true); ?>" />
    922 
    923 <div id="search-filter">
    924     <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
    925     <input type="submit" value="<?php _e( 'Search Media' ); ?>" class="button" />
    926 </div>
    927 
    928 <p>
    929 <ul class="subsubsub">
    930 <?php
    931 $type_links = array();
    932 $_num_posts = (array) wp_count_attachments();
    933 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    934 foreach ( $matches as $type => $reals )
    935     foreach ( $reals as $real )
    936         $num_posts[$type] += $_num_posts[$real];
    937 $class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
    938 $type_links[] = "<li><a href='" . remove_query_arg(array('post_mime_type', 'paged', 'm')) . "'$class>".__('All Types')."</a>";
    939 foreach ( $post_mime_types as $mime_type => $label ) {
    940     $class = '';
    941 
    942     if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
    943         continue;
    944 
    945     if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
    946         $class = ' class="current"';
    947 
    948     $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf($label[2], "<span id='$mime_type-counter'>{$num_posts[$mime_type]}</span>") . '</a>';
    949 }
    950 echo implode(' | </li>', $type_links) . '</li>';
    951 unset($type_links);
    952 ?>
    953 </ul>
    954 </p>
    955 
    956 <div class="tablenav">
    957 
    958 <?php
    959 $page_links = paginate_links( array(
    960     'base' => add_query_arg( 'paged', '%#%' ),
    961     'format' => '',
    962     'total' => ceil($wp_query->found_posts / 10),
    963     'current' => $_GET['paged']
    964 ));
    965 
    966 if ( $page_links )
    967     echo "<div class='tablenav-pages'>$page_links</div>";
    968 ?>
    969 
    970 <div style="float: left">
    971 <?php
    972 
    973 $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";
    974 
    975 $arc_result = $wpdb->get_results( $arc_query );
    976 
    977 $month_count = count($arc_result);
    978 
    979 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
    980 <select name='m'>
    981 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
    982 <?php
    983 foreach ($arc_result as $arc_row) {
    984     if ( $arc_row->yyear == 0 )
    985         continue;
    986     $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
    987 
    988     if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
    989         $default = ' selected="selected"';
    990     else
    991         $default = '';
    992 
    993     echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
    994     echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
    995     echo "</option>\n";
    996 }
    997 ?>
    998 </select>
    999 <?php } ?>
    1000 
    1001 <input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button-secondary" />
    1002 
    1003 </div>
    1004 
    1005 <br style="clear:both;" />
    1006 </div>
    1007 </form>
    1008 
    1009 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="library-form">
    1010 
    1011 <?php wp_nonce_field('media-form'); ?>
    1012 <?php //media_upload_form( $errors ); ?>
    1013 
    1014 <script type="text/javascript">
    1015 <!--
    1016 jQuery(function($){
    1017     var preloaded = $(".media-item.preloaded");
    1018     if ( preloaded.length > 0 ) {
    1019         preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
    1020         updateMediaForm();
    1021     }
    1022 });
    1023 -->
    1024 </script>
    1025 
    10261027<div id="media-items">
    10271028<?php echo get_media_items(null, $errors); ?>
    10281029</div>
     1030<input type="submit" class="button savebutton" name="save" value="<?php _e('Save all changes'); ?>" />
    10291031<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
    10301032</form>
Note: See TracChangeset for help on using the changeset viewer.