-
+ 5403C9FF616259F4927CC55A812B565E3D66A3D2940E069E470A0D773A0662F102D3EDCE7328BFCB76EB4F87EBA1B4B9BE7C05887A8B896AE4D6F9839B7FBE36
mp-wp/wp-admin/upload.php
(0 . 0)(1 . 435)
58566 <?php
58567 /**
58568 * Media Library administration panel.
58569 *
58570 * @package WordPress
58571 * @subpackage Administration
58572 */
58573
58574 /** WordPress Administration Bootstrap */
58575 require_once('admin.php');
58576 wp_enqueue_script( 'wp-ajax-response' );
58577 wp_enqueue_script( 'jquery-ui-draggable' );
58578 wp_enqueue_script( 'jquery-ui-resizable' );
58579
58580 if (!current_user_can('upload_files'))
58581 wp_die(__('You do not have permission to upload files.'));
58582
58583 if ( isset($_GET['find_detached'] ) ) {
58584 check_admin_referer('bulk-media');
58585
58586 if ( ! current_user_can('edit_posts') )
58587 wp_die( __('You are not allowed to scan for lost attachments.') );
58588
58589 $all_posts = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'post' OR post_type = 'page'");
58590 $all_att = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'attachment'");
58591
58592 $lost = array();
58593 foreach ( (array) $all_att as $att ) {
58594 if ( $att->post_parent > 0 && ! in_array($att->post_parent, $all_posts) )
58595 $lost[] = $att->ID;
58596 }
58597 $_GET['detached'] = 1;
58598
58599 } elseif ( isset($_GET['found_post_id']) && isset($_GET['media']) ) {
58600 check_admin_referer('bulk-media');
58601
58602 if ( ! ( $parent_id = (int) $_GET['found_post_id'] ) )
58603 return;
58604
58605 $parent = &get_post($parent_id);
58606 if ( !current_user_can('edit_post', $parent_id) )
58607 wp_die( __('You are not allowed to edit this post.') );
58608
58609 $attach = array();
58610 foreach( (array) $_GET['media'] as $att_id ) {
58611 $att_id = (int) $att_id;
58612
58613 if ( !current_user_can('edit_post', $att_id) )
58614 continue;
58615
58616 $attach[] = $att_id;
58617 }
58618
58619 if ( ! empty($attach) ) {
58620 $attach = implode(',', $attach);
58621 $attached = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ($attach)", $parent_id) );
58622 }
58623
58624 if ( isset($attached) ) {
58625 $location = 'upload.php';
58626 if ( $referer = wp_get_referer() ) {
58627 if ( false !== strpos($referer, 'upload.php') )
58628 $location = $referer;
58629 }
58630
58631 $location = add_query_arg( array( 'detached' => 1, 'attached' => $attached ) , $location );
58632 wp_redirect($location);
58633 exit;
58634 }
58635
58636 } elseif ( isset($_GET['action']) && isset($_GET['media']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
58637 check_admin_referer('bulk-media');
58638 $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
58639
58640 if ( 'delete' == $doaction ) {
58641 foreach( (array) $_GET['media'] as $post_id_del ) {
58642 $post_del = & get_post($post_id_del);
58643
58644 if ( !current_user_can('delete_post', $post_id_del) )
58645 wp_die( __('You are not allowed to delete this post.') );
58646
58647 if ( $post_del->post_type == 'attachment' )
58648 if ( ! wp_delete_attachment($post_id_del) )
58649 wp_die( __('Error in deleting...') );
58650 }
58651
58652 $location = 'upload.php';
58653 if ( $referer = wp_get_referer() ) {
58654 if ( false !== strpos($referer, 'upload.php') )
58655 $location = $referer;
58656 }
58657
58658 $location = add_query_arg('message', 2, $location);
58659 $location = remove_query_arg('posted', $location);
58660 wp_redirect($location);
58661 exit;
58662 }
58663 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
58664 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
58665 exit;
58666 }
58667
58668 $title = __('Media Library');
58669 $parent_file = 'upload.php';
58670
58671 if ( ! isset( $_GET['paged'] ) || $_GET['paged'] < 1 )
58672 $_GET['paged'] = 1;
58673
58674 if ( isset($_GET['detached']) ) {
58675
58676 if ( !empty($lost) ) {
58677 $start = ( $_GET['paged'] - 1 ) * 50;
58678 $page_links_total = ceil(count($lost) / 50);
58679 $lost = implode(',', $lost);
58680
58681 $orphans = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" );
58682 } else {
58683 $start = ( $_GET['paged'] - 1 ) * 25;
58684 $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent < 1 LIMIT $start, 25" );
58685 $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25);
58686 }
58687
58688 $post_mime_types = array(
58689 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image (%s)', 'Images (%s)')),
58690 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio (%s)', 'Audio (%s)')),
58691 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video (%s)', 'Video (%s)')),
58692 );
58693 $post_mime_types = apply_filters('post_mime_types', $post_mime_types);
58694
58695 $avail_post_mime_types = get_available_post_mime_types('attachment');
58696
58697 if ( isset($_GET['post_mime_type']) && !array_intersect( (array) $_GET['post_mime_type'], array_keys($post_mime_types) ) )
58698 unset($_GET['post_mime_type']);
58699
58700 } else {
58701 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
58702 }
58703
58704 require_once('admin-header.php'); ?>
58705
58706 <?php
58707 if ( isset($_GET['posted']) && (int) $_GET['posted'] ) {
58708 $_GET['message'] = '1';
58709 $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
58710 }
58711
58712 if ( isset($_GET['attached']) && (int) $_GET['attached'] ) {
58713 $attached = (int) $_GET['attached'];
58714 $message = sprintf( __ngettext('Reattached %d attachment', 'Reattached %d attachments', $attached), $attached );
58715 $_SERVER['REQUEST_URI'] = remove_query_arg(array('attached'), $_SERVER['REQUEST_URI']);
58716 }
58717
58718 $messages[1] = __('Media attachment updated.');
58719 $messages[2] = __('Media deleted.');
58720 $messages[3] = __('Error saving media attachment.');
58721
58722 if ( isset($_GET['message']) && (int) $_GET['message'] ) {
58723 $message = $messages[$_GET['message']];
58724 $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
58725 }
58726 ?>
58727
58728 <?php do_action('restrict_manage_posts'); ?>
58729
58730 <div class="wrap">
58731 <?php screen_icon(); ?>
58732 <h2><?php echo wp_specialchars( $title );
58733 if ( isset($_GET['s']) && $_GET['s'] )
58734 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', wp_specialchars( get_search_query() ) ); ?>
58735 </h2>
58736
58737 <?php
58738 if ( isset($message) ) { ?>
58739 <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
58740 <?php
58741 }
58742 ?>
58743
58744 <ul class="subsubsub">
58745 <?php
58746 $type_links = array();
58747 $_num_posts = (array) wp_count_attachments();
58748 $_total_posts = array_sum( $_num_posts );
58749 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
58750 foreach ( $matches as $type => $reals )
58751 foreach ( $reals as $real )
58752 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
58753
58754 $class = empty($_GET['post_mime_type']) && ! isset($_GET['detached']) ? ' class="current"' : '';
58755 $type_links[] = "<li><a href='upload.php'$class>" . sprintf( __ngettext( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts ), number_format_i18n( $_total_posts ) ) . '</a>';
58756 foreach ( $post_mime_types as $mime_type => $label ) {
58757 $class = '';
58758
58759 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
58760 continue;
58761
58762 if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
58763 $class = ' class="current"';
58764
58765 $type_links[] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( __ngettext( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
58766 }
58767 $class = isset($_GET['detached']) ? ' class="current"' : '';
58768 $type_links[] = '<li><a href="upload.php?detached=1"' . $class . '>' . __('Unattached') . '</a>';
58769
58770 echo implode( " |</li>\n", $type_links) . '</li>';
58771 unset($type_links);
58772 ?>
58773 </ul>
58774
58775 <form class="search-form" action="" method="get">
58776 <p class="search-box">
58777 <label class="hidden" for="media-search-input"><?php _e( 'Search Media' ); ?>:</label>
58778 <input type="text" class="search-input" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
58779 <input type="submit" value="<?php _e( 'Search Media' ); ?>" class="button" />
58780 </p>
58781 </form>
58782
58783 <form id="posts-filter" action="" method="get">
58784 <div class="tablenav">
58785 <?php
58786 if ( ! isset($page_links_total) )
58787 $page_links_total = $wp_query->max_num_pages;
58788
58789 $page_links = paginate_links( array(
58790 'base' => add_query_arg( 'paged', '%#%' ),
58791 'format' => '',
58792 'prev_text' => __('«'),
58793 'next_text' => __('»'),
58794 'total' => $page_links_total,
58795 'current' => $_GET['paged']
58796 ));
58797
58798 if ( $page_links ) : ?>
58799 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
58800 number_format_i18n( ( $_GET['paged'] - 1 ) * $wp_query->query_vars['posts_per_page'] + 1 ),
58801 number_format_i18n( min( $_GET['paged'] * $wp_query->query_vars['posts_per_page'], $wp_query->found_posts ) ),
58802 number_format_i18n( $wp_query->found_posts ),
58803 $page_links
58804 ); echo $page_links_text; ?></div>
58805 <?php endif; ?>
58806
58807 <div class="alignleft actions">
58808 <select name="action" class="select-action">
58809 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
58810 <option value="delete"><?php _e('Delete'); ?></option>
58811 <?php if ( isset($orphans) ) { ?>
58812 <option value="attach"><?php _e('Attach to a post'); ?></option>
58813 <?php } ?>
58814 </select>
58815 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
58816 <?php wp_nonce_field('bulk-media'); ?>
58817
58818 <?php
58819 if ( ! is_singular() && ! isset($_GET['detached']) ) {
58820 $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";
58821
58822 $arc_result = $wpdb->get_results( $arc_query );
58823
58824 $month_count = count($arc_result);
58825
58826 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) : ?>
58827 <select name='m'>
58828 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
58829 <?php
58830 foreach ($arc_result as $arc_row) {
58831 if ( $arc_row->yyear == 0 )
58832 continue;
58833 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
58834
58835 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
58836 $default = ' selected="selected"';
58837 else
58838 $default = '';
58839
58840 echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
58841 echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
58842 echo "</option>\n";
58843 }
58844 ?>
58845 </select>
58846 <?php endif; // month_count ?>
58847
58848 <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
58849
58850 <?php } // ! is_singular ?>
58851
58852 <?php if ( isset($_GET['detached']) ) { ?>
58853 <input type="submit" id="find_detached" name="find_detached" value="<?php _e('Scan for lost attachments'); ?>" class="button-secondary" />
58854 <?php } ?>
58855
58856 </div>
58857
58858 <br class="clear" />
58859 </div>
58860
58861 <div class="clear"></div>
58862
58863 <?php if ( isset($orphans) ) { ?>
58864 <table class="widefat" cellspacing="0">
58865 <thead>
58866 <tr>
58867 <th scope="col" class="check-column"><input type="checkbox" /></th>
58868 <th scope="col"></th>
58869 <th scope="col"><?php echo _c('Media|media column header'); ?></th>
58870 <th scope="col"><?php echo _c('Date Added|media column header'); ?></th>
58871 </tr>
58872 </thead>
58873
58874 <tfoot>
58875 <tr>
58876 <th scope="col" class="check-column"><input type="checkbox" /></th>
58877 <th scope="col"></th>
58878 <th scope="col"><?php echo _c('Media|media column header'); ?></th>
58879 <th scope="col"><?php echo _c('Date Added|media column header'); ?></th>
58880 </tr>
58881 </tfoot>
58882
58883 <tbody id="the-list" class="list:post">
58884 <?php
58885 if ( $orphans ) {
58886 foreach ( $orphans as $post ) {
58887 $class = 'alternate' == $class ? '' : 'alternate';
58888 $att_title = wp_specialchars( _draft_or_post_title($post->ID) );
58889 ?>
58890 <tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top">
58891 <th scope="row" class="check-column"><input type="checkbox" name="media[]" value="<?php echo $post->ID; ?>" /></th>
58892
58893 <td class="media-icon"><?php
58894 if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) { ?>
58895 <a href="media.php?action=edit&attachment_id=<?php echo $post->ID; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php echo $thumb; ?></a>
58896 <?php } ?></td>
58897
58898 <td><strong><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php echo $att_title; ?></a></strong><br />
58899 <?php echo strtoupper(preg_replace('/^.*?\.(\w+)$/', '$1', get_attached_file($post->ID))); ?>
58900
58901 <p>
58902 <?php
58903 $actions = array();
58904 if ( current_user_can('edit_post', $post->ID) )
58905 $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
58906 if ( current_user_can('delete_post', $post->ID) )
58907 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this attachment '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this attachment '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
58908 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . attribute_escape(sprintf(__('View "%s"'), $title)) . '" rel="permalink">' . __('View') . '</a>';
58909 if ( current_user_can('edit_post', $post->ID) )
58910 $actions['attach'] = '<a href="#the-list" onclick="findPosts.open(\'media[]\',\''.$post->ID.'\');return false;">'.__('Attach').'</a>';
58911 $action_count = count($actions);
58912 $i = 0;
58913 foreach ( $actions as $action => $link ) {
58914 ++$i;
58915 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
58916 echo "<span class='$action'>$link$sep</span>";
58917 } ?>
58918 </p></td>
58919
58920 <?php if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
58921 $t_time = $h_time = __('Unpublished');
58922 } else {
58923 $t_time = get_the_time(__('Y/m/d g:i:s A'));
58924 $m_time = $post->post_date;
58925 $time = get_post_time( 'G', true );
58926 if ( ( abs($t_diff = time() - $time) ) < 86400 ) {
58927 if ( $t_diff < 0 )
58928 $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
58929 else
58930 $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
58931 } else {
58932 $h_time = mysql2date(__('Y/m/d'), $m_time);
58933 }
58934 } ?>
58935 <td><?php echo $h_time ?></td>
58936 </tr>
58937 <?php }
58938
58939 } else { ?>
58940 <tr><td colspan="5"><?php _e('No posts found.') ?></td></tr>
58941 <?php } ?>
58942 </tbody>
58943 </table>
58944
58945 <?php find_posts_div();
58946
58947 } else {
58948 include( 'edit-attachment-rows.php' );
58949 } ?>
58950
58951 <div id="ajax-response"></div>
58952
58953 <div class="tablenav">
58954
58955 <?php
58956 if ( $page_links )
58957 echo "<div class='tablenav-pages'>$page_links_text</div>";
58958 ?>
58959
58960 <div class="alignleft actions">
58961 <select name="action2" class="select-action">
58962 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
58963 <option value="delete"><?php _e('Delete'); ?></option>
58964 <?php if ( isset($orphans) ) { ?>
58965 <option value="attach"><?php _e('Attach to a post'); ?></option>
58966 <?php } ?>
58967 </select>
58968 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
58969 </div>
58970
58971 <br class="clear" />
58972 </div>
58973 </form>
58974 <br class="clear" />
58975
58976 </div>
58977
58978 <script type="text/javascript">
58979 /* <![CDATA[ */
58980 (function($){
58981 $(document).ready(function(){
58982 $('#doaction, #doaction2').click(function(e){
58983 if ( $('select[name^="action"]').val() == 'delete' ) {
58984 var m = '<?php echo js_escape(__("You are about to delete the selected attachments.\n 'Cancel' to stop, 'OK' to delete.")); ?>';
58985 return showNotice.warn(m);
58986 } else if ( $('select[name^="action"]').val() == 'attach' ) {
58987 e.preventDefault();
58988 findPosts.open();
58989 }
58990 });
58991 });
58992 })(jQuery);
58993 columns.init('upload');
58994 /* ]]> */
58995 </script>
58996
58997 <?php
58998
58999 include('admin-footer.php');
59000 ?>