PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/edit-attachment-rows.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 239 lines | 204 code | 27 blank | 8 comment | 45 complexity | 5c6855e65ca75e231f1dfd7149e6605b MD5 | raw file
  1. <?php
  2. /**
  3. * Edit attachments table for inclusion in administration panels.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. // don't load directly
  9. if ( !defined('ABSPATH') )
  10. die('-1');
  11. if ( have_posts() ) { ?>
  12. <table class="widefat fixed" cellspacing="0">
  13. <thead>
  14. <tr>
  15. <?php print_column_headers('upload'); ?>
  16. </tr>
  17. </thead>
  18. <tfoot>
  19. <tr>
  20. <?php print_column_headers('upload', false); ?>
  21. </tr>
  22. </tfoot>
  23. <tbody id="the-list" class="list:post">
  24. <?php
  25. add_filter('the_title','esc_html');
  26. $alt = '';
  27. $posts_columns = get_column_headers('upload');
  28. $hidden = get_hidden_columns('upload');
  29. while ( have_posts() ) : the_post();
  30. if ( $is_trash && $post->post_status != 'trash' )
  31. continue;
  32. elseif ( !$is_trash && $post->post_status == 'trash' )
  33. continue;
  34. $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
  35. global $current_user;
  36. $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
  37. $att_title = _draft_or_post_title();
  38. ?>
  39. <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
  40. <?php
  41. foreach ($posts_columns as $column_name => $column_display_name ) {
  42. $class = "class=\"$column_name column-$column_name\"";
  43. $style = '';
  44. if ( in_array($column_name, $hidden) )
  45. $style = ' style="display:none;"';
  46. $attributes = "$class$style";
  47. switch($column_name) {
  48. case 'cb':
  49. ?>
  50. <th scope="row" class="check-column"><?php if ( current_user_can('edit_post', $post->ID) ) { ?><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /><?php } ?></th>
  51. <?php
  52. break;
  53. case 'icon':
  54. $attributes = 'class="column-icon media-icon"' . $style;
  55. ?>
  56. <td <?php echo $attributes ?>><?php
  57. if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) {
  58. if ( $is_trash ) echo $thumb;
  59. else {
  60. ?>
  61. <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
  62. <?php echo $thumb; ?>
  63. </a>
  64. <?php }
  65. }
  66. ?></td>
  67. <?php
  68. // TODO
  69. break;
  70. case 'media':
  71. ?>
  72. <td <?php echo $attributes ?>><strong><?php if ( $is_trash ) echo $att_title; else { ?><a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>"><?php echo $att_title; ?></a><?php } ?></strong>
  73. <p>
  74. <?php
  75. if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
  76. echo esc_html( strtoupper( $matches[1] ) );
  77. else
  78. echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
  79. ?>
  80. </p>
  81. <?php
  82. $actions = array();
  83. if ( current_user_can('edit_post', $post->ID) && !$is_trash )
  84. $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
  85. if ( current_user_can('delete_post', $post->ID) ) {
  86. if ( $is_trash )
  87. $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-attachment_' . $post->ID) . "'>" . __('Restore') . "</a>";
  88. elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH )
  89. $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID) . "'>" . __('Trash') . "</a>";
  90. if ( $is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) {
  91. $delete_ays = (!$is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : '';
  92. $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
  93. }
  94. }
  95. if ( !$is_trash ) {
  96. $title =_draft_or_post_title($post->post_parent);
  97. $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
  98. }
  99. $actions = apply_filters( 'media_row_actions', $actions, $post );
  100. $action_count = count($actions);
  101. $i = 0;
  102. echo '<div class="row-actions">';
  103. foreach ( $actions as $action => $link ) {
  104. ++$i;
  105. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  106. echo "<span class='$action'>$link$sep</span>";
  107. }
  108. echo '</div>';
  109. ?></td>
  110. <?php
  111. break;
  112. case 'author':
  113. ?>
  114. <td <?php echo $attributes ?>><?php the_author() ?></td>
  115. <?php
  116. break;
  117. case 'tags':
  118. ?>
  119. <td <?php echo $attributes ?>><?php
  120. $tags = get_the_tags();
  121. if ( !empty( $tags ) ) {
  122. $out = array();
  123. foreach ( $tags as $c )
  124. $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>";
  125. echo join( ', ', $out );
  126. } else {
  127. _e('No Tags');
  128. }
  129. ?></td>
  130. <?php
  131. break;
  132. case 'desc':
  133. ?>
  134. <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
  135. <?php
  136. break;
  137. case 'date':
  138. if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
  139. $t_time = $h_time = __('Unpublished');
  140. } else {
  141. $t_time = get_the_time(__('Y/m/d g:i:s A'));
  142. $m_time = $post->post_date;
  143. $time = get_post_time( 'G', true, $post, false );
  144. if ( ( abs($t_diff = time() - $time) ) < 86400 ) {
  145. if ( $t_diff < 0 )
  146. $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
  147. else
  148. $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
  149. } else {
  150. $h_time = mysql2date(__('Y/m/d'), $m_time);
  151. }
  152. }
  153. ?>
  154. <td <?php echo $attributes ?>><?php echo $h_time ?></td>
  155. <?php
  156. break;
  157. case 'parent':
  158. if ( $post->post_parent > 0 ) {
  159. if ( get_post($post->post_parent) ) {
  160. $title =_draft_or_post_title($post->post_parent);
  161. }
  162. ?>
  163. <td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?></td>
  164. <?php
  165. } else {
  166. ?>
  167. <td <?php echo $attributes ?>><?php _e('(Unattached)'); ?><br />
  168. <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a></td>
  169. <?php
  170. }
  171. break;
  172. case 'comments':
  173. $attributes = 'class="comments column-comments num"' . $style;
  174. ?>
  175. <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
  176. <?php
  177. $left = get_pending_comments_num( $post->ID );
  178. $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
  179. if ( $left )
  180. echo '<strong>';
  181. comments_number("<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
  182. if ( $left )
  183. echo '</strong>';
  184. ?>
  185. </div></td>
  186. <?php
  187. break;
  188. case 'actions':
  189. ?>
  190. <td <?php echo $attributes ?>>
  191. <a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>"><?php _e('Edit'); ?></a> |
  192. <a href="<?php the_permalink(); ?>"><?php _e('Get permalink'); ?></a>
  193. </td>
  194. <?php
  195. break;
  196. default:
  197. ?>
  198. <td <?php echo $attributes ?>><?php do_action('manage_media_custom_column', $column_name, $id); ?></td>
  199. <?php
  200. break;
  201. }
  202. }
  203. ?>
  204. </tr>
  205. <?php endwhile; ?>
  206. </tbody>
  207. </table>
  208. <?php } else { ?>
  209. <p><?php _e('No media attachments found.') ?></p>
  210. <?php
  211. } // end if ( have_posts() )
  212. ?>