/svntrunk/bp-forums/bbpress/bb-admin/posts.php

https://bitbucket.org/simplemediacode/bptrunk · PHP · 195 lines · 158 code · 37 blank · 0 comment · 19 complexity · f20a7e13120e941e4db33d933b1694cd MD5 · raw file

  1. <?php
  2. require_once('admin.php');
  3. if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) {
  4. bb_check_admin_referer( 'post-bulk' );
  5. $post_ids = array_map( 'absint', $_POST['post'] );
  6. $count = 0;
  7. $action = trim( $_POST['action'] );
  8. switch ( $action ) {
  9. case 'delete' :
  10. foreach ( $post_ids as $post_id ) {
  11. $count += (int) (bool) bb_delete_post( $post_id, 1 );
  12. }
  13. $query_vars = array( 'message' => 'deleted', 'count' => $count );
  14. break;
  15. case 'undelete' :
  16. foreach ( $post_ids as $post_id ) {
  17. $count += (int) (bool) bb_delete_post( $post_id, 0 );
  18. }
  19. $query_vars = array( 'message' => 'undeleted', 'count' => $count );
  20. break;
  21. default :
  22. if ( $action )
  23. $query_vars = apply_filters( "bulk_post__$action", array(), $post_ids, $action );
  24. break;
  25. }
  26. bb_safe_redirect( add_query_arg( $query_vars ) );
  27. exit;
  28. }
  29. if ( !empty( $_GET['message'] ) ) {
  30. $message_count = isset( $_GET['count'] ) ? (int) $_GET['count'] : 1;
  31. switch ( (string) $_GET['message'] ) {
  32. case 'undeleted':
  33. bb_admin_notice( sprintf( _n( '<strong>Post undeleted.</strong>', '<strong>%s posts undeleted.</strong>', $message_count ), bb_number_format_i18n( $message_count ) ) );
  34. break;
  35. case 'deleted':
  36. bb_admin_notice( sprintf( _n( '<strong>Post deleted.</strong>', '<strong>%s posts deleted.</strong>', $message_count ), bb_number_format_i18n( $message_count ) ) );
  37. break;
  38. case 'spammed':
  39. bb_admin_notice( sprintf( _n( '<strong>Post spammed.</strong>', '<strong>%s posts spammed.</strong>', $message_count ), bb_number_format_i18n( $message_count ) ) );
  40. break;
  41. case 'unspammed-normal':
  42. bb_admin_notice( sprintf( _n( '<strong>Post removed from spam.</strong> It is now a normal post.', '<strong>%s posts removed from spam.</strong> They are now normal posts.', $message_count ), bb_number_format_i18n( $message_count ) ) );
  43. break;
  44. case 'unspammed-deleted':
  45. bb_admin_notice( sprintf( _n( '<strong>Post removed from spam.</strong> It is now a deleted post.', '<strong>%s posts removed from spam.</strong> They are nowdeleted posts.', $message_count ), bb_number_format_i18n( $message_count ) ) );
  46. break;
  47. }
  48. }
  49. $ip_available = false;
  50. if ( bb_current_user_can( 'view_by_ip' ) ) {
  51. $ip_available = true;
  52. } elseif (isset($_GET['poster_ip'])) {
  53. unset( $_GET['poster_ip'] );
  54. }
  55. $bb_admin_body_class = ' bb-admin-posts';
  56. bb_get_admin_header();
  57. if ( !bb_current_user_can('browse_deleted') )
  58. die(__("Now how'd you get here? And what did you think you'd being doing?")); //This should never happen.
  59. add_filter( 'get_topic_where', 'bb_no_where' );
  60. add_filter( 'get_topic_link', 'bb_make_link_view_all' );
  61. add_filter( 'post_edit_uri', 'bb_make_link_view_all' );
  62. $post_query = new BB_Query_Form( 'post', array( 'post_status' => 'normal', 'count' => true, 'per_page' => 20 ) );
  63. $bb_posts =& $post_query->results;
  64. $total = $post_query->found_rows;
  65. ?>
  66. <div class="wrap">
  67. <h2><?php _e( 'Posts' ); ?>
  68. <?php
  69. $h2_search = $post_query->get( 'post_text' );
  70. $h2_forum = $post_query->get( 'forum_id' );
  71. $h2_tag = $post_query->get( 'tag_id' );
  72. $h2_author = $post_query->get( 'post_author_id' );
  73. $h2_search = $h2_search ? ' ' . sprintf( __('containing &#8220;%s&#8221;'), esc_html( $h2_search ) ) : '';
  74. $h2_forum = $h2_forum ? ' ' . sprintf( __('in &#8220;%s&#8221;') , get_forum_name( $h2_forum ) ) : '';
  75. $h2_tag = $h2_tag ? ' ' . sprintf( __('with tag &#8220;%s&#8221;'), esc_html( bb_get_tag_name( $h2_tag ) ) ) : '';
  76. $h2_author = $h2_author ? ' ' . sprintf( __('by %s') , esc_html( get_user_name( $h2_author ) ) ) : '';
  77. if ($ip_available) {
  78. $h2_ip = $post_query->get( 'poster_ip' );
  79. $h2_ip = $h2_ip ? ' ' . sprintf( __('from IP address %s'), esc_html( $h2_ip ) ) : '';
  80. } else {
  81. $h2_ip = '';
  82. }
  83. if ( $h2_search || $h2_forum || $h2_tag || $h2_author || $h2_ip ) {
  84. echo '<span class="subtitle">';
  85. printf( __( '%1$s%2$s%3$s%4$s%5$s' ), $h2_search, $h2_forum, $h2_tag, $h2_author, $h2_ip );
  86. echo '</span>';
  87. }
  88. ?>
  89. </h2>
  90. <?php
  91. do_action( 'bb_admin_notices' );
  92. $post_query->form( array( 'poster_ip' => $ip_available, 'tag' => true, 'post_author' => true, 'post_status' => true, 'submit' => __( 'Filter' ) ) );
  93. $bulk_actions = array(
  94. 'delete' => __( 'Delete' ),
  95. 'undelete' => __( 'Undelete' ),
  96. );
  97. if ( is_numeric( $bulk_action = $post_query->get( 'post_status' ) ) ) {
  98. switch ( $bulk_action ) {
  99. case 0 :
  100. unset( $bulk_actions['undelete'] );
  101. break;
  102. case 1 :
  103. unset( $bulk_actions['delete'] );
  104. }
  105. }
  106. unset( $bulk_action );
  107. do_action_ref_array( 'bulk_post_actions', array( &$bulk_actions, &$post_query ) );
  108. ?>
  109. <div class="clear"></div>
  110. <form class="table-form bulk-form" method="post" action="">
  111. <fieldset>
  112. <select name="action">
  113. <option><?php _e( 'Bulk Actions' ); ?></option>
  114. <?php foreach ( $bulk_actions as $value => $label ) : ?>
  115. <option value="<?php echo esc_attr( $value ); ?>"><?php echo esc_html( $label ); ?></option>
  116. <?php endforeach; ?>
  117. </select>
  118. <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" class="button submit-input" />
  119. <?php bb_nonce_field( 'post-bulk' ); ?>
  120. </fieldset>
  121. <div class="tablenav">
  122. <?php if ( $total ) : ?>
  123. <div class="tablenav-pages">
  124. <span class="displaying-num"><?php echo $displaying_num = sprintf(
  125. __( '%1$s to %2$s of %3$s' ),
  126. bb_number_format_i18n( ( $page - 1 ) * $post_query->get( 'per_page' ) + 1 ),
  127. $page * $post_query->get( 'per_page' ) < $total ? bb_number_format_i18n( $page * $post_query->get( 'per_page' ) ) : '<span class="total-type-count">' . bb_number_format_i18n( $total ) . '</span>',
  128. '<span class="total-type-count">' . bb_number_format_i18n( $total ) . '</span>'
  129. ); ?></span><span class="displaying-pages">
  130. <?php
  131. $_page_link_args = array(
  132. 'page' => $page,
  133. 'total' => $total,
  134. 'per_page' => $post_query->get( 'per_page' ),
  135. 'mod_rewrite' => false,
  136. 'prev_text' => __( '&laquo;' ),
  137. 'next_text' => __( '&raquo;' )
  138. );
  139. echo $page_number_links = get_page_number_links( $_page_link_args );
  140. ?></span>
  141. <div class="clear"></div>
  142. </div>
  143. <?php endif; ?>
  144. </div>
  145. <div class="clear"></div>
  146. <?php bb_admin_list_posts(); ?>
  147. </form>
  148. <div class="tablenav bottom">
  149. <?php if ( $total ) : ?>
  150. <div class="tablenav-pages">
  151. <span class="displaying-pages"><?php echo $page_number_links; ?></span>
  152. <div class="clear"></div>
  153. </div>
  154. <?php endif; ?>
  155. </div>
  156. <div class="clear"></div>
  157. </div>
  158. <?php bb_get_admin_footer(); ?>