web/wp-content/plugins/bbpress/includes/admin/metaboxes.php
changeset 196 5e8dcbe22c24
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * bbPress Admin Metaboxes
       
     5  *
       
     6  * @package bbPress
       
     7  * @subpackage Administration
       
     8  */
       
     9 
       
    10 /** Dashboard *****************************************************************/
       
    11 
       
    12 /**
       
    13  * bbPress Dashboard Right Now Widget
       
    14  *
       
    15  * Adds a dashboard widget with forum statistics
       
    16  *
       
    17  * @since bbPress (r2770)
       
    18  *
       
    19  * @uses bbp_get_version() To get the current bbPress version
       
    20  * @uses bbp_get_statistics() To get the forum statistics
       
    21  * @uses current_user_can() To check if the user is capable of doing things
       
    22  * @uses bbp_get_forum_post_type() To get the forum post type
       
    23  * @uses bbp_get_topic_post_type() To get the topic post type
       
    24  * @uses bbp_get_reply_post_type() To get the reply post type
       
    25  * @uses get_admin_url() To get the administration url
       
    26  * @uses add_query_arg() To add custom args to the url
       
    27  * @uses do_action() Calls 'bbp_dashboard_widget_right_now_content_table_end'
       
    28  *                    below the content table
       
    29  * @uses do_action() Calls 'bbp_dashboard_widget_right_now_table_end'
       
    30  *                    below the discussion table
       
    31  * @uses do_action() Calls 'bbp_dashboard_widget_right_now_discussion_table_end'
       
    32  *                    below the discussion table
       
    33  * @uses do_action() Calls 'bbp_dashboard_widget_right_now_end' below the widget
       
    34  */
       
    35 function bbp_dashboard_widget_right_now() {
       
    36 
       
    37 	// Get the statistics and extract them
       
    38 	extract( bbp_get_statistics(), EXTR_SKIP ); ?>
       
    39 
       
    40 	<div class="table table_content">
       
    41 
       
    42 		<p class="sub"><?php _e( 'Discussion', 'bbpress' ); ?></p>
       
    43 
       
    44 		<table>
       
    45 
       
    46 			<tr class="first">
       
    47 
       
    48 				<?php
       
    49 					$num  = $forum_count;
       
    50 					$text = _n( 'Forum', 'Forums', $forum_count, 'bbpress' );
       
    51 					if ( current_user_can( 'publish_forums' ) ) {
       
    52 						$link = add_query_arg( array( 'post_type' => bbp_get_forum_post_type() ), get_admin_url( null, 'edit.php' ) );
       
    53 						$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
    54 						$text = '<a href="' . $link . '">' . $text . '</a>';
       
    55 					}
       
    56 				?>
       
    57 
       
    58 				<td class="first b b-forums"><?php echo $num; ?></td>
       
    59 				<td class="t forums"><?php echo $text; ?></td>
       
    60 
       
    61 			</tr>
       
    62 
       
    63 			<tr>
       
    64 
       
    65 				<?php
       
    66 					$num  = $topic_count;
       
    67 					$text = _n( 'Topic', 'Topics', $topic_count, 'bbpress' );
       
    68 					if ( current_user_can( 'publish_topics' ) ) {
       
    69 						$link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit.php' ) );
       
    70 						$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
    71 						$text = '<a href="' . $link . '">' . $text . '</a>';
       
    72 					}
       
    73 				?>
       
    74 
       
    75 				<td class="first b b-topics"><?php echo $num; ?></td>
       
    76 				<td class="t topics"><?php echo $text; ?></td>
       
    77 
       
    78 			</tr>
       
    79 
       
    80 			<tr>
       
    81 
       
    82 				<?php
       
    83 					$num  = $reply_count;
       
    84 					$text = _n( 'Reply', 'Replies', $reply_count, 'bbpress' );
       
    85 					if ( current_user_can( 'publish_replies' ) ) {
       
    86 						$link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), get_admin_url( null, 'edit.php' ) );
       
    87 						$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
    88 						$text = '<a href="' . $link . '">' . $text . '</a>';
       
    89 					}
       
    90 				?>
       
    91 
       
    92 				<td class="first b b-replies"><?php echo $num; ?></td>
       
    93 				<td class="t replies"><?php echo $text; ?></td>
       
    94 
       
    95 			</tr>
       
    96 
       
    97 			<?php if ( bbp_allow_topic_tags() ) : ?>
       
    98 
       
    99 				<tr>
       
   100 
       
   101 					<?php
       
   102 						$num  = $topic_tag_count;
       
   103 						$text = _n( 'Topic Tag', 'Topic Tags', $topic_tag_count, 'bbpress' );
       
   104 						if ( current_user_can( 'manage_topic_tags' ) ) {
       
   105 							$link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit-tags.php' ) );
       
   106 							$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
   107 							$text = '<a href="' . $link . '">' . $text . '</a>';
       
   108 						}
       
   109 					?>
       
   110 
       
   111 					<td class="first b b-topic_tags"><span class="total-count"><?php echo $num; ?></span></td>
       
   112 					<td class="t topic_tags"><?php echo $text; ?></td>
       
   113 
       
   114 				</tr>
       
   115 
       
   116 			<?php endif; ?>
       
   117 
       
   118 			<?php do_action( 'bbp_dashboard_widget_right_now_content_table_end' ); ?>
       
   119 
       
   120 		</table>
       
   121 
       
   122 	</div>
       
   123 
       
   124 
       
   125 	<div class="table table_discussion">
       
   126 
       
   127 		<p class="sub"><?php _e( 'Users &amp; Moderation', 'bbpress' ); ?></p>
       
   128 
       
   129 		<table>
       
   130 
       
   131 			<tr class="first">
       
   132 
       
   133 				<?php
       
   134 					$num  = $user_count;
       
   135 					$text = _n( 'User', 'Users', $user_count, 'bbpress' );
       
   136 					if ( current_user_can( 'edit_users' ) ) {
       
   137 						$link = get_admin_url( null, 'users.php' );
       
   138 						$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
   139 						$text = '<a href="' . $link . '">' . $text . '</a>';
       
   140 					}
       
   141 				?>
       
   142 
       
   143 				<td class="b b-users"><span class="total-count"><?php echo $num; ?></span></td>
       
   144 				<td class="last t users"><?php echo $text; ?></td>
       
   145 
       
   146 			</tr>
       
   147 
       
   148 			<?php if ( isset( $topic_count_hidden ) ) : ?>
       
   149 
       
   150 				<tr>
       
   151 
       
   152 					<?php
       
   153 						$num  = $topic_count_hidden;
       
   154 						$text = _n( 'Hidden Topic', 'Hidden Topics', $topic_count_hidden, 'bbpress' );
       
   155 						$link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit.php' ) );
       
   156 						if ( '0' != $num ) {
       
   157 							$link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
       
   158 						}
       
   159                         $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $num  . '</a>';
       
   160 						$text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $text . '</a>';
       
   161 					?>
       
   162 
       
   163 					<td class="b b-hidden-topics"><?php echo $num; ?></td>
       
   164 					<td class="last t hidden-replies"><?php echo $text; ?></td>
       
   165 
       
   166 				</tr>
       
   167 
       
   168 			<?php endif; ?>
       
   169 
       
   170 			<?php if ( isset( $reply_count_hidden ) ) : ?>
       
   171 
       
   172 				<tr>
       
   173 
       
   174 					<?php
       
   175 						$num  = $reply_count_hidden;
       
   176 						$text = _n( 'Hidden Reply', 'Hidden Replies', $reply_count_hidden, 'bbpress' );
       
   177 						$link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), get_admin_url( null, 'edit.php' ) );
       
   178 						if ( '0' != $num ) {
       
   179 							$link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
       
   180 						}
       
   181                         $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $num  . '</a>';
       
   182 						$text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $text . '</a>';
       
   183 					?>
       
   184 
       
   185 					<td class="b b-hidden-replies"><?php echo $num; ?></td>
       
   186 					<td class="last t hidden-replies"><?php echo $text; ?></td>
       
   187 
       
   188 				</tr>
       
   189 
       
   190 			<?php endif; ?>
       
   191 
       
   192 			<?php if ( bbp_allow_topic_tags() && isset( $empty_topic_tag_count ) ) : ?>
       
   193 
       
   194 				<tr>
       
   195 
       
   196 					<?php
       
   197 						$num  = $empty_topic_tag_count;
       
   198 						$text = _n( 'Empty Topic Tag', 'Empty Topic Tags', $empty_topic_tag_count, 'bbpress' );
       
   199 						$link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit-tags.php' ) );
       
   200 						$num  = '<a href="' . $link . '">' . $num  . '</a>';
       
   201 						$text = '<a class="waiting" href="' . $link . '">' . $text . '</a>';
       
   202 					?>
       
   203 
       
   204 					<td class="b b-hidden-topic-tags"><?php echo $num; ?></td>
       
   205 					<td class="last t hidden-topic-tags"><?php echo $text; ?></td>
       
   206 
       
   207 				</tr>
       
   208 
       
   209 			<?php endif; ?>
       
   210 
       
   211 			<?php do_action( 'bbp_dashboard_widget_right_now_discussion_table_end' ); ?>
       
   212 
       
   213 		</table>
       
   214 
       
   215 	</div>
       
   216 
       
   217 	<?php do_action( 'bbp_dashboard_widget_right_now_table_end' ); ?>
       
   218 
       
   219 	<div class="versions">
       
   220 
       
   221 		<span id="wp-version-message">
       
   222 			<?php printf( __( 'You are using <span class="b">bbPress %s</span>.', 'bbpress' ), bbp_get_version() ); ?>
       
   223 		</span>
       
   224 
       
   225 	</div>
       
   226 
       
   227 	<br class="clear" />
       
   228 
       
   229 	<?php
       
   230 
       
   231 	do_action( 'bbp_dashboard_widget_right_now_end' );
       
   232 }
       
   233 
       
   234 /** Forums ********************************************************************/
       
   235 
       
   236 /**
       
   237  * Forum metabox
       
   238  *
       
   239  * The metabox that holds all of the additional forum information
       
   240  *
       
   241  * @since bbPress (r2744)
       
   242  *
       
   243  * @uses bbp_is_forum_closed() To check if a forum is closed or not
       
   244  * @uses bbp_is_forum_category() To check if a forum is a category or not
       
   245  * @uses bbp_is_forum_private() To check if a forum is private or not
       
   246  * @uses bbp_dropdown() To show a dropdown of the forums for forum parent
       
   247  * @uses do_action() Calls 'bbp_forum_metabox'
       
   248  */
       
   249 function bbp_forum_metabox() {
       
   250 
       
   251 	// Post ID
       
   252 	$post_id     = get_the_ID();
       
   253 	$post_parent = bbp_get_global_post_field( 'post_parent', 'raw'  );
       
   254 	$menu_order  = bbp_get_global_post_field( 'menu_order',  'edit' );
       
   255 
       
   256 	/** Type ******************************************************************/
       
   257 
       
   258 	?>
       
   259 
       
   260 	<p>
       
   261 		<strong class="label"><?php _e( 'Type:', 'bbpress' ); ?></strong>
       
   262 		<label class="screen-reader-text" for="bbp_forum_type_select"><?php _e( 'Type:', 'bbpress' ) ?></label>
       
   263 		<?php bbp_form_forum_type_dropdown( $post_id ); ?>
       
   264 	</p>
       
   265 
       
   266 	<?php
       
   267 
       
   268 	/** Status ****************************************************************/
       
   269 
       
   270 	?>
       
   271 
       
   272 	<p>
       
   273 		<strong class="label"><?php _e( 'Status:', 'bbpress' ); ?></strong>
       
   274 		<label class="screen-reader-text" for="bbp_forum_status_select"><?php _e( 'Status:', 'bbpress' ) ?></label>
       
   275 		<?php bbp_form_forum_status_dropdown( $post_id ); ?>
       
   276 	</p>
       
   277 
       
   278 	<?php
       
   279 
       
   280 	/** Visibility ************************************************************/
       
   281 
       
   282 	?>
       
   283 
       
   284 	<p>
       
   285 		<strong class="label"><?php _e( 'Visibility:', 'bbpress' ); ?></strong>
       
   286 		<label class="screen-reader-text" for="bbp_forum_visibility_select"><?php _e( 'Visibility:', 'bbpress' ) ?></label>
       
   287 		<?php bbp_form_forum_visibility_dropdown( $post_id ); ?>
       
   288 	</p>
       
   289 
       
   290 	<hr />
       
   291 
       
   292 	<?php
       
   293 
       
   294 	/** Parent ****************************************************************/
       
   295 
       
   296 	?>
       
   297 
       
   298 	<p>
       
   299 		<strong class="label"><?php _e( 'Parent:', 'bbpress' ); ?></strong>
       
   300 		<label class="screen-reader-text" for="parent_id"><?php _e( 'Forum Parent', 'bbpress' ); ?></label>
       
   301 		<?php bbp_dropdown( array(
       
   302 			'post_type'          => bbp_get_forum_post_type(),
       
   303 			'selected'           => $post_parent,
       
   304 			'child_of'           => '0',
       
   305 			'numberposts'        => -1,
       
   306 			'orderby'            => 'title',
       
   307 			'order'              => 'ASC',
       
   308 			'walker'             => '',
       
   309 			'exclude'            => $post_id,
       
   310 
       
   311 			// Output-related
       
   312 			'select_id'          => 'parent_id',
       
   313 			'tab'                => bbp_get_tab_index(),
       
   314 			'options_only'       => false,
       
   315 			'show_none'          => __( '&mdash; No parent &mdash;', 'bbpress' ),
       
   316 			'none_found'         => false,
       
   317 			'disable_categories' => false,
       
   318 			'disabled'           => ''
       
   319 		) ); ?>
       
   320 	</p>
       
   321 
       
   322 	<p>
       
   323 		<strong class="label"><?php _e( 'Order:', 'bbpress' ); ?></strong>
       
   324 		<label class="screen-reader-text" for="menu_order"><?php _e( 'Forum Order', 'bbpress' ); ?></label>
       
   325 		<input name="menu_order" type="number" step="1" size="4" id="menu_order" value="<?php echo esc_attr( $menu_order ); ?>" />
       
   326 	</p>
       
   327 
       
   328 	<?php
       
   329 	wp_nonce_field( 'bbp_forum_metabox_save', 'bbp_forum_metabox' );
       
   330 	do_action( 'bbp_forum_metabox', $post_id );
       
   331 }
       
   332 
       
   333 /** Topics ********************************************************************/
       
   334 
       
   335 /**
       
   336  * Topic metabox
       
   337  *
       
   338  * The metabox that holds all of the additional topic information
       
   339  *
       
   340  * @since bbPress (r2464)
       
   341  *
       
   342  * @uses bbp_get_topic_forum_id() To get the topic forum id
       
   343  * @uses do_action() Calls 'bbp_topic_metabox'
       
   344  */
       
   345 function bbp_topic_metabox() {
       
   346 
       
   347 	// Post ID
       
   348 	$post_id = get_the_ID(); ?>
       
   349 
       
   350 	<p>
       
   351 		<strong class="label"><?php _e( 'Type:', 'bbpress' ); ?></strong>
       
   352 		<label class="screen-reader-text" for="bbp_stick_topic"><?php _e( 'Topic Type', 'bbpress' ); ?></label>
       
   353 		<?php bbp_topic_type_select( array( 'topic_id' => $post_id ) ); ?>
       
   354 	</p>
       
   355 
       
   356 	<p>
       
   357 		<strong class="label"><?php _e( 'Forum:', 'bbpress' ); ?></strong>
       
   358 		<label class="screen-reader-text" for="parent_id"><?php _e( 'Forum', 'bbpress' ); ?></label>
       
   359 		<?php bbp_dropdown( array(
       
   360 			'post_type'          => bbp_get_forum_post_type(),
       
   361 			'selected'           => bbp_get_topic_forum_id( $post_id ),
       
   362 			'child_of'           => '0',
       
   363 			'numberposts'        => -1,
       
   364 			'orderby'            => 'title',
       
   365 			'order'              => 'ASC',
       
   366 			'walker'             => '',
       
   367 			'exclude'            => '',
       
   368 
       
   369 			// Output-related
       
   370 			'select_id'          => 'parent_id',
       
   371 			'tab'                => bbp_get_tab_index(),
       
   372 			'options_only'       => false,
       
   373 			'show_none'          => __( '&mdash; No parent &mdash;', 'bbpress' ),
       
   374 			'none_found'         => false,
       
   375 			'disable_categories' => current_user_can( 'edit_forums' ),
       
   376 			'disabled'           => ''
       
   377 		) ); ?>
       
   378 	</p>
       
   379 
       
   380 	<?php
       
   381 	wp_nonce_field( 'bbp_topic_metabox_save', 'bbp_topic_metabox' );
       
   382 	do_action( 'bbp_topic_metabox', $post_id );
       
   383 }
       
   384 
       
   385 /** Replies *******************************************************************/
       
   386 
       
   387 /**
       
   388  * Reply metabox
       
   389  *
       
   390  * The metabox that holds all of the additional reply information
       
   391  *
       
   392  * @since bbPress (r2464)
       
   393  *
       
   394  * @uses bbp_get_topic_post_type() To get the topic post type
       
   395  * @uses do_action() Calls 'bbp_reply_metabox'
       
   396  */
       
   397 function bbp_reply_metabox() {
       
   398 
       
   399 	// Post ID
       
   400 	$post_id = get_the_ID();
       
   401 
       
   402 	// Get some meta
       
   403 	$reply_topic_id = bbp_get_reply_topic_id( $post_id );
       
   404 	$reply_forum_id = bbp_get_reply_forum_id( $post_id );
       
   405 
       
   406 	// Allow individual manipulation of reply forum
       
   407 	if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) : ?>
       
   408 
       
   409 		<p>
       
   410 			<strong class="label"><?php _e( 'Forum:', 'bbpress' ); ?></strong>
       
   411 			<label class="screen-reader-text" for="bbp_forum_id"><?php _e( 'Forum', 'bbpress' ); ?></label>
       
   412 			<?php bbp_dropdown( array(
       
   413 				'post_type'          => bbp_get_forum_post_type(),
       
   414 				'selected'           => $reply_forum_id,
       
   415 				'child_of'           => '0',
       
   416 				'numberposts'        => -1,
       
   417 				'orderby'            => 'title',
       
   418 				'order'              => 'ASC',
       
   419 				'walker'             => '',
       
   420 				'exclude'            => '',
       
   421 
       
   422 				// Output-related
       
   423 				'select_id'          => 'bbp_forum_id',
       
   424 				'tab'                => bbp_get_tab_index(),
       
   425 				'options_only'       => false,
       
   426 				'show_none'          => __( '&mdash; No parent &mdash;', 'bbpress' ),
       
   427 				'none_found'         => false,
       
   428 				'disable_categories' => current_user_can( 'edit_forums' ),
       
   429 				'disabled'           => ''
       
   430 			) ); ?>
       
   431 		</p>
       
   432 
       
   433 	<?php endif; ?>
       
   434 
       
   435 	<p>
       
   436 		<strong class="label"><?php _e( 'Topic:', 'bbpress' ); ?></strong>
       
   437 		<label class="screen-reader-text" for="parent_id"><?php _e( 'Topic', 'bbpress' ); ?></label>
       
   438 		<input name="parent_id" id="bbp_topic_id" type="text" value="<?php echo esc_attr( $reply_topic_id ); ?>" />
       
   439 	</p>
       
   440 
       
   441 	<?php
       
   442 	wp_nonce_field( 'bbp_reply_metabox_save', 'bbp_reply_metabox' );
       
   443 	do_action( 'bbp_reply_metabox', $post_id );
       
   444 }
       
   445 
       
   446 /** Users *********************************************************************/
       
   447 
       
   448 /**
       
   449  * Anonymous user information metabox
       
   450  *
       
   451  * @since bbPress (r2828)
       
   452  *
       
   453  * @uses bbp_is_reply_anonymous() To check if reply is anonymous
       
   454  * @uses bbp_is_topic_anonymous() To check if topic is anonymous
       
   455  * @uses get_the_ID() To get the global post ID
       
   456  * @uses get_post_meta() To get the author user information
       
   457  */
       
   458 function bbp_author_metabox() {
       
   459 
       
   460 	// Post ID
       
   461 	$post_id = get_the_ID();
       
   462 
       
   463 	// Show extra bits if topic/reply is anonymous
       
   464 	if ( bbp_is_reply_anonymous( $post_id ) || bbp_is_topic_anonymous( $post_id ) ) : ?>
       
   465 
       
   466 		<p>
       
   467 			<strong class="label"><?php _e( 'Name:', 'bbpress' ); ?></strong>
       
   468 			<label class="screen-reader-text" for="bbp_anonymous_name"><?php _e( 'Name', 'bbpress' ); ?></label>
       
   469 			<input type="text" id="bbp_anonymous_name" name="bbp_anonymous_name" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_name', true ) ); ?>" />
       
   470 		</p>
       
   471 
       
   472 		<p>
       
   473 			<strong class="label"><?php _e( 'Email:', 'bbpress' ); ?></strong>
       
   474 			<label class="screen-reader-text" for="bbp_anonymous_email"><?php _e( 'Email', 'bbpress' ); ?></label>
       
   475 			<input type="text" id="bbp_anonymous_email" name="bbp_anonymous_email" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_email', true ) ); ?>" />
       
   476 		</p>
       
   477 
       
   478 		<p>
       
   479 			<strong class="label"><?php _e( 'Website:', 'bbpress' ); ?></strong>
       
   480 			<label class="screen-reader-text" for="bbp_anonymous_website"><?php _e( 'Website', 'bbpress' ); ?></label>
       
   481 			<input type="text" id="bbp_anonymous_website" name="bbp_anonymous_website" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_anonymous_website', true ) ); ?>" />
       
   482 		</p>
       
   483 
       
   484 	<?php endif; ?>
       
   485 
       
   486 	<p>
       
   487 		<strong class="label"><?php _e( 'IP:', 'bbpress' ); ?></strong>
       
   488 		<label class="screen-reader-text" for="bbp_author_ip_address"><?php _e( 'IP Address', 'bbpress' ); ?></label>
       
   489 		<input type="text" id="bbp_author_ip_address" name="bbp_author_ip_address" value="<?php echo esc_attr( get_post_meta( $post_id, '_bbp_author_ip', true ) ); ?>" disabled="disabled" />
       
   490 	</p>
       
   491 
       
   492 	<?php
       
   493 
       
   494 	do_action( 'bbp_author_metabox', $post_id );
       
   495 }