web/wp-content/plugins/bbpress/includes/admin/topics.php
changeset 196 5e8dcbe22c24
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * bbPress Topics Admin Class
       
     5  *
       
     6  * @package bbPress
       
     7  * @subpackage Administration
       
     8  */
       
     9 
       
    10 // Exit if accessed directly
       
    11 if ( !defined( 'ABSPATH' ) ) exit;
       
    12 
       
    13 if ( !class_exists( 'BBP_Topics_Admin' ) ) :
       
    14 /**
       
    15  * Loads bbPress topics admin area
       
    16  *
       
    17  * @package bbPress
       
    18  * @subpackage Administration
       
    19  * @since bbPress (r2464)
       
    20  */
       
    21 class BBP_Topics_Admin {
       
    22 
       
    23 	/** Variables *************************************************************/
       
    24 
       
    25 	/**
       
    26 	 * @var The post type of this admin component
       
    27 	 */
       
    28 	private $post_type = '';
       
    29 
       
    30 	/** Functions *************************************************************/
       
    31 
       
    32 	/**
       
    33 	 * The main bbPress topics admin loader
       
    34 	 *
       
    35 	 * @since bbPress (r2515)
       
    36 	 *
       
    37 	 * @uses BBP_Topics_Admin::setup_globals() Setup the globals needed
       
    38 	 * @uses BBP_Topics_Admin::setup_actions() Setup the hooks and actions
       
    39 	 * @uses BBP_Topics_Admin::setup_help() Setup the help text
       
    40 	 */
       
    41 	public function __construct() {
       
    42 		$this->setup_globals();
       
    43 		$this->setup_actions();
       
    44 	}
       
    45 
       
    46 	/**
       
    47 	 * Setup the admin hooks, actions and filters
       
    48 	 *
       
    49 	 * @since bbPress (r2646)
       
    50 	 * @access private
       
    51 	 *
       
    52 	 * @uses add_action() To add various actions
       
    53 	 * @uses add_filter() To add various filters
       
    54 	 * @uses bbp_get_forum_post_type() To get the forum post type
       
    55 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
    56 	 * @uses bbp_get_reply_post_type() To get the reply post type
       
    57 	 */
       
    58 	private function setup_actions() {
       
    59 
       
    60 		// Add some general styling to the admin area
       
    61 		add_action( 'bbp_admin_head',        array( $this, 'admin_head'       ) );
       
    62 
       
    63 		// Messages
       
    64 		add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
       
    65 
       
    66 		// Topic column headers.
       
    67 		add_filter( 'manage_' . $this->post_type . '_posts_columns',        array( $this, 'topics_column_headers' ) );
       
    68 
       
    69 		// Topic columns (in post row)
       
    70 		add_action( 'manage_' . $this->post_type . '_posts_custom_column',  array( $this, 'topics_column_data' ), 10, 2 );
       
    71 		add_filter( 'post_row_actions',                                     array( $this, 'topics_row_actions' ), 10, 2 );
       
    72 
       
    73 		// Topic metabox actions
       
    74 		add_action( 'add_meta_boxes', array( $this, 'attributes_metabox'      ) );
       
    75 		add_action( 'save_post',      array( $this, 'attributes_metabox_save' ) );
       
    76 
       
    77 		// Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
       
    78 		add_action( 'load-edit.php',  array( $this, 'toggle_topic'        ) );
       
    79 		add_action( 'admin_notices',  array( $this, 'toggle_topic_notice' ) );
       
    80 
       
    81 		// Anonymous metabox actions
       
    82 		add_action( 'add_meta_boxes', array( $this, 'author_metabox'      ) );
       
    83 		add_action( 'save_post',      array( $this, 'author_metabox_save' ) );
       
    84 
       
    85 		// Add ability to filter topics and replies per forum
       
    86 		add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown'  ) );
       
    87 		add_filter( 'bbp_request',           array( $this, 'filter_post_rows' ) );
       
    88 
       
    89 		// Contextual Help
       
    90 		add_action( 'load-edit.php',     array( $this, 'edit_help' ) );
       
    91 		add_action( 'load-post-new.php', array( $this, 'new_help'  ) );
       
    92 	}
       
    93 
       
    94 	/**
       
    95 	 * Should we bail out of this method?
       
    96 	 *
       
    97 	 * @since bbPress (r4067)
       
    98 	 * @return boolean
       
    99 	 */
       
   100 	private function bail() {
       
   101 		if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) )
       
   102 			return true;
       
   103 
       
   104 		return false;
       
   105 	}
       
   106 
       
   107 	/**
       
   108 	 * Admin globals
       
   109 	 *
       
   110 	 * @since bbPress (r2646)
       
   111 	 * @access private
       
   112 	 */
       
   113 	private function setup_globals() {
       
   114 		$this->post_type = bbp_get_topic_post_type();
       
   115 	}
       
   116 
       
   117 	/** Contextual Help *******************************************************/
       
   118 
       
   119 	/**
       
   120 	 * Contextual help for bbPress topic edit page
       
   121 	 *
       
   122 	 * @since bbPress (r3119)
       
   123 	 * @uses get_current_screen()
       
   124 	 */
       
   125 	public function edit_help() {
       
   126 
       
   127 		if ( $this->bail() ) return;
       
   128 
       
   129 		// Overview
       
   130 		get_current_screen()->add_help_tab( array(
       
   131 			'id'		=> 'overview',
       
   132 			'title'		=> __( 'Overview', 'bbpress' ),
       
   133 			'content'	=>
       
   134 				'<p>' . __( 'This screen displays the individual topics on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
       
   135 		) );
       
   136 
       
   137 		// Screen Content
       
   138 		get_current_screen()->add_help_tab( array(
       
   139 			'id'		=> 'screen-content',
       
   140 			'title'		=> __( 'Screen Content', 'bbpress' ),
       
   141 			'content'	=>
       
   142 				'<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
       
   143 				'<ul>' .
       
   144 					'<li>' . __( 'You can hide/display columns based on your needs and decide how many topics to list per screen using the Screen Options tab.',                                                                                                                                'bbpress' ) . '</li>' .
       
   145 					'<li>' . __( 'You can filter the list of topics by topic status using the text links in the upper left to show All, Published, or Trashed topics. The default view is to show all topics.',                                                                                 'bbpress' ) . '</li>' .
       
   146 					'<li>' . __( 'You can refine the list to show only topics from a specific month by using the dropdown menus above the topics list. Click the Filter button after making your selection. You also can refine the list by clicking on the topic creator in the topics list.', 'bbpress' ) . '</li>' .
       
   147 				'</ul>'
       
   148 		) );
       
   149 
       
   150 		// Available Actions
       
   151 		get_current_screen()->add_help_tab( array(
       
   152 			'id'		=> 'action-links',
       
   153 			'title'		=> __( 'Available Actions', 'bbpress' ),
       
   154 			'content'	=>
       
   155 				'<p>' . __( 'Hovering over a row in the topics list will display action links that allow you to manage your topic. You can perform the following actions:', 'bbpress' ) . '</p>' .
       
   156 				'<ul>' .
       
   157 					'<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that topic. You can also reach that screen by clicking on the topic title.',                                                                                 'bbpress' ) . '</li>' .
       
   158 					'<li>' . __( '<strong>Trash</strong> removes your topic from this list and places it in the trash, from which you can permanently delete it.',                                                                                       'bbpress' ) . '</li>' .
       
   159 					'<li>' . __( '<strong>Spam</strong> removes your topic from this list and places it in the spam queue, from which you can permanently delete it.',                                                                                   'bbpress' ) . '</li>' .
       
   160 					'<li>' . __( '<strong>Preview</strong> will show you what your draft topic will look like if you publish it. View will take you to your live site to view the topic. Which link is available depends on your topic&#8217;s status.', 'bbpress' ) . '</li>' .
       
   161 					'<li>' . __( '<strong>Close</strong> will mark the selected topic as &#8217;closed&#8217; and disable the option to post new replies to the topic.',                                                                                 'bbpress' ) . '</li>' .
       
   162 					'<li>' . __( '<strong>Stick</strong> will keep the selected topic &#8217;pinned&#8217; to the top the parent forum topic list.',                                                                                                     'bbpress' ) . '</li>' .
       
   163 					'<li>' . __( '<strong>Stick <em>(to front)</em></strong> will keep the selected topic &#8217;pinned&#8217; to the top of ALL forums and be visable in any forums topics list.',                                                      'bbpress' ) . '</li>' .
       
   164 				'</ul>'
       
   165 		) );
       
   166 
       
   167 		// Bulk Actions
       
   168 		get_current_screen()->add_help_tab( array(
       
   169 			'id'		=> 'bulk-actions',
       
   170 			'title'		=> __( 'Bulk Actions', 'bbpress' ),
       
   171 			'content'	=>
       
   172 				'<p>' . __( 'You can also edit or move multiple topics to the trash at once. Select the topics you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.',           'bbpress' ) . '</p>' .
       
   173 				'<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected topics at once. To remove a topic from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>'
       
   174 		) );
       
   175 
       
   176 		// Help Sidebar
       
   177 		get_current_screen()->set_help_sidebar(
       
   178 			'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
       
   179 			'<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>',     'bbpress' ) . '</p>' .
       
   180 			'<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>',  'bbpress' ) . '</p>'
       
   181 		);
       
   182 	}
       
   183 
       
   184 	/**
       
   185 	 * Contextual help for bbPress topic edit page
       
   186 	 *
       
   187 	 * @since bbPress (r3119)
       
   188 	 * @uses get_current_screen()
       
   189 	 */
       
   190 	public function new_help() {
       
   191 
       
   192 		if ( $this->bail() ) return;
       
   193 
       
   194 		$customize_display = '<p>' . __( 'The title field and the big topic editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>';
       
   195 
       
   196 		get_current_screen()->add_help_tab( array(
       
   197 			'id'      => 'customize-display',
       
   198 			'title'   => __( 'Customizing This Display', 'bbpress' ),
       
   199 			'content' => $customize_display,
       
   200 		) );
       
   201 
       
   202 		get_current_screen()->add_help_tab( array(
       
   203 			'id'      => 'title-topic-editor',
       
   204 			'title'   => __( 'Title and Topic Editor', 'bbpress' ),
       
   205 			'content' =>
       
   206 				'<p>' . __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
       
   207 				'<p>' . __( '<strong>Topic Editor</strong> - Enter the text for your topic. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your topic text. You can insert media files by clicking the icons above the topic editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular topic editor.', 'bbpress' ) . '</p>'
       
   208 		) );
       
   209 
       
   210 		$publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your topic in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a topic or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a topic to be published in the future or backdate a topic.', 'bbpress' ) . '</p>';
       
   211 
       
   212 		if ( current_theme_supports( 'topic-formats' ) && topic_type_supports( 'topic', 'topic-formats' ) ) {
       
   213 			$publish_box .= '<p>' . __( '<strong>topic Format</strong> - This designates how your theme will display a specific topic. For example, you could have a <em>standard</em> blog topic with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each topic format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>';
       
   214 		}
       
   215 
       
   216 		if ( current_theme_supports( 'topic-thumbnails' ) && topic_type_supports( 'topic', 'thumbnail' ) ) {
       
   217 			$publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your topic without inserting it. This is usually useful only if your theme makes use of the featured image as a topic thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
       
   218 		}
       
   219 
       
   220 		get_current_screen()->add_help_tab( array(
       
   221 			'id'      => 'topic-attributes',
       
   222 			'title'   => __( 'Topic Attributes', 'bbpress' ),
       
   223 			'content' =>
       
   224 				'<p>' . __( 'Select the attributes that your topic should have:', 'bbpress' ) . '</p>' .
       
   225 				'<ul>' .
       
   226 					'<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the topic belongs to. Select the forum or category from the dropdown, or leave the default (No Forum) to post the topic without an assigned forum.', 'bbpress' ) . '</li>' .
       
   227 					'<li>' . __( '<strong>Topic Type</strong> dropdown indicates the sticky status of the topic. Selecting the super sticky option would stick the topic to the front of your forums, i.e. the topic index, sticky option would stick the topic to its respective forum. Selecting normal would not stick the topic anywhere.', 'bbpress' ) . '</li>' .
       
   228 				'</ul>'
       
   229 		) );
       
   230 
       
   231 		get_current_screen()->add_help_tab( array(
       
   232 			'id'      => 'publish-box',
       
   233 			'title'   => __( 'Publish Box', 'bbpress' ),
       
   234 			'content' => $publish_box,
       
   235 		) );
       
   236 
       
   237 		get_current_screen()->add_help_tab( array(
       
   238 			'id'      => 'discussion-settings',
       
   239 			'title'   => __( 'Discussion Settings', 'bbpress' ),
       
   240 			'content' =>
       
   241 				'<p>' . __( '<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they&#8217;ll be notified automatically using pingbacks, and this field is unnecessary.', 'bbpress' ) . '</p>' .
       
   242 				'<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the topic, you can see them here and moderate them.', 'bbpress' ) . '</p>'
       
   243 		) );
       
   244 
       
   245 		get_current_screen()->set_help_sidebar(
       
   246 			'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
       
   247 			'<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>',    'bbpress' ) . '</p>' .
       
   248 			'<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
       
   249 		);
       
   250 	}
       
   251 
       
   252 	/**
       
   253 	 * Add the topic attributes metabox
       
   254 	 *
       
   255 	 * @since bbPress (r2744)
       
   256 	 *
       
   257 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   258 	 * @uses add_meta_box() To add the metabox
       
   259 	 * @uses do_action() Calls 'bbp_topic_attributes_metabox'
       
   260 	 */
       
   261 	public function attributes_metabox() {
       
   262 
       
   263 		if ( $this->bail() ) return;
       
   264 
       
   265 		add_meta_box (
       
   266 			'bbp_topic_attributes',
       
   267 			__( 'Topic Attributes', 'bbpress' ),
       
   268 			'bbp_topic_metabox',
       
   269 			$this->post_type,
       
   270 			'side',
       
   271 			'high'
       
   272 		);
       
   273 
       
   274 		do_action( 'bbp_topic_attributes_metabox' );
       
   275 	}
       
   276 
       
   277 	/**
       
   278 	 * Pass the topic attributes for processing
       
   279 	 *
       
   280 	 * @since bbPress (r2746)
       
   281 	 *
       
   282 	 * @param int $topic_id Topic id
       
   283 	 * @uses current_user_can() To check if the current user is capable of
       
   284 	 *                           editing the topic
       
   285 	 * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
       
   286 	 *                    topic id and parent id
       
   287 	 * @return int Parent id
       
   288 	 */
       
   289 	public function attributes_metabox_save( $topic_id ) {
       
   290 
       
   291 		if ( $this->bail() ) return $topic_id;
       
   292 
       
   293 		// Bail if doing an autosave
       
   294 		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
       
   295 			return $topic_id;
       
   296 
       
   297 		// Bail if not a post request
       
   298 		if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
       
   299 			return $topic_id;
       
   300 
       
   301 		// Nonce check
       
   302 		if ( empty( $_POST['bbp_topic_metabox'] ) || !wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) )
       
   303 			return $topic_id;
       
   304 
       
   305 		// Bail if current user cannot edit this topic
       
   306 		if ( !current_user_can( 'edit_topic', $topic_id ) )
       
   307 			return $topic_id;
       
   308 
       
   309 		// Get the forum ID
       
   310 		$forum_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
       
   311 
       
   312 		// Formally update the topic
       
   313 		bbp_update_topic( $topic_id, $forum_id );
       
   314 
       
   315 		// Stickies
       
   316 		if ( !empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {
       
   317 
       
   318 			// What's the haps?
       
   319 			switch ( $_POST['bbp_stick_topic'] ) {
       
   320 
       
   321 				// Sticky in this forum
       
   322 				case 'stick'   :
       
   323 					bbp_stick_topic( $topic_id );
       
   324 					break;
       
   325 
       
   326 				// Super sticky in all forums
       
   327 				case 'super'   :
       
   328 					bbp_stick_topic( $topic_id, true );
       
   329 					break;
       
   330 
       
   331 				// Normal
       
   332 				case 'unstick' :
       
   333 				default        :
       
   334 					bbp_unstick_topic( $topic_id );
       
   335 					break;
       
   336 			}
       
   337 		}
       
   338 
       
   339 		// Allow other fun things to happen
       
   340 		do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id );
       
   341 
       
   342 		return $topic_id;
       
   343 	}
       
   344 
       
   345 	/**
       
   346 	 * Add the author info metabox
       
   347 	 *
       
   348 	 * @since bbPress (r2828)
       
   349 	 *
       
   350 	 * @uses bbp_get_topic() To get the topic
       
   351 	 * @uses bbp_get_reply() To get the reply
       
   352 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   353 	 * @uses bbp_get_reply_post_type() To get the reply post type
       
   354 	 * @uses add_meta_box() To add the metabox
       
   355 	 * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
       
   356 	 *                    id
       
   357 	 */
       
   358 	public function author_metabox() {
       
   359 
       
   360 		if ( $this->bail() ) return;
       
   361 
       
   362 		// Bail if post_type is not a topic
       
   363 		if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) )
       
   364 			return;
       
   365 
       
   366 		// Add the metabox
       
   367 		add_meta_box(
       
   368 			'bbp_author_metabox',
       
   369 			__( 'Author Information', 'bbpress' ),
       
   370 			'bbp_author_metabox',
       
   371 			$this->post_type,
       
   372 			'side',
       
   373 			'high'
       
   374 		);
       
   375 
       
   376 		do_action( 'bbp_author_metabox', get_the_ID() );
       
   377 	}
       
   378 
       
   379 	/**
       
   380 	 * Save the author information for the topic
       
   381 	 *
       
   382 	 * @since bbPress (r2828)
       
   383 	 *
       
   384 	 * @param int $post_id Topic or reply id
       
   385 	 * @uses bbp_get_topic() To get the topic
       
   386 	 * @uses bbp_get_reply() To get the reply
       
   387 	 * @uses current_user_can() To check if the current user can edit the
       
   388 	 *                           topic or reply
       
   389 	 * @uses bbp_filter_author_post_data() To filter the author data
       
   390 	 * @uses update_post_meta() To update the anonymous user data
       
   391 	 * @uses do_action() Calls 'bbp_author_metabox_save' with the topic id and
       
   392 	 *                    anonymous data
       
   393 	 * @return int Topic or reply id
       
   394 	 */
       
   395 	public function author_metabox_save( $post_id ) {
       
   396 
       
   397 		if ( $this->bail() ) return $post_id;
       
   398 
       
   399 		// Bail if no post_id
       
   400 		if ( empty( $post_id ) )
       
   401 			return $post_id;
       
   402 
       
   403 		// Bail if doing an autosave
       
   404 		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
       
   405 			return $post_id;
       
   406 
       
   407 		// Bail if not a post request
       
   408 		if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
       
   409 			return $post_id;
       
   410 
       
   411 		// Bail if user cannot edit topics
       
   412 		if ( !current_user_can( 'edit_topic', $post_id ) )
       
   413 			return $post_id;
       
   414 
       
   415 		$anonymous_data = bbp_filter_anonymous_post_data();
       
   416 
       
   417 		update_post_meta( $post_id, '_bbp_anonymous_name',    $anonymous_data['bbp_anonymous_name']    );
       
   418 		update_post_meta( $post_id, '_bbp_anonymous_email',   $anonymous_data['bbp_anonymous_email']   );
       
   419 		update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
       
   420 
       
   421 		do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
       
   422 
       
   423 		return $post_id;
       
   424 	}
       
   425 
       
   426 	/**
       
   427 	 * Add some general styling to the admin area
       
   428 	 *
       
   429 	 * @since bbPress (r2464)
       
   430 	 *
       
   431 	 * @uses bbp_get_forum_post_type() To get the forum post type
       
   432 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   433 	 * @uses bbp_get_reply_post_type() To get the reply post type
       
   434 	 * @uses sanitize_html_class() To sanitize the classes
       
   435 	 * @uses do_action() Calls 'bbp_admin_head'
       
   436 	 */
       
   437 	public function admin_head() {
       
   438 
       
   439 		if ( $this->bail() ) return;
       
   440 
       
   441 		?>
       
   442 
       
   443 		<style type="text/css" media="screen">
       
   444 		/*<![CDATA[*/
       
   445 
       
   446 			strong.label {
       
   447 				display: inline-block;
       
   448 				width: 60px;
       
   449 			}
       
   450 
       
   451 			.column-bbp_forum_topic_count,
       
   452 			.column-bbp_forum_reply_count,
       
   453 			.column-bbp_topic_reply_count,
       
   454 			.column-bbp_topic_voice_count {
       
   455 				width: 8% !important;
       
   456 			}
       
   457 
       
   458 			.column-author,
       
   459 			.column-bbp_reply_author,
       
   460 			.column-bbp_topic_author {
       
   461 				width: 10% !important;
       
   462 			}
       
   463 
       
   464 			.column-bbp_topic_forum,
       
   465 			.column-bbp_reply_forum,
       
   466 			.column-bbp_reply_topic {
       
   467 				width: 10% !important;
       
   468 			}
       
   469 
       
   470 			.column-bbp_forum_freshness,
       
   471 			.column-bbp_topic_freshness {
       
   472 				width: 10% !important;
       
   473 			}
       
   474 
       
   475 			.column-bbp_forum_created,
       
   476 			.column-bbp_topic_created,
       
   477 			.column-bbp_reply_created {
       
   478 				width: 15% !important;
       
   479 			}
       
   480 
       
   481 			.status-closed {
       
   482 				background-color: #eaeaea;
       
   483 			}
       
   484 
       
   485 			.status-spam {
       
   486 				background-color: #faeaea;
       
   487 			}
       
   488 
       
   489 		/*]]>*/
       
   490 		</style>
       
   491 
       
   492 		<?php
       
   493 	}
       
   494 
       
   495 	/**
       
   496 	 * Toggle topic
       
   497 	 *
       
   498 	 * Handles the admin-side opening/closing, sticking/unsticking and
       
   499 	 * spamming/unspamming of topics
       
   500 	 *
       
   501 	 * @since bbPress (r2727)
       
   502 	 *
       
   503 	 * @uses bbp_get_topic() To get the topic
       
   504 	 * @uses current_user_can() To check if the user is capable of editing
       
   505 	 *                           the topic
       
   506 	 * @uses wp_die() To die if the user isn't capable or the post wasn't
       
   507 	 *                 found
       
   508 	 * @uses check_admin_referer() To verify the nonce and check referer
       
   509 	 * @uses bbp_is_topic_open() To check if the topic is open
       
   510 	 * @uses bbp_close_topic() To close the topic
       
   511 	 * @uses bbp_open_topic() To open the topic
       
   512 	 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or
       
   513 	 *                              super sticky
       
   514 	 * @uses bbp_unstick_topic() To unstick the topic
       
   515 	 * @uses bbp_stick_topic() To stick the topic
       
   516 	 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
       
   517 	 * @uses bbp_unspam_topic() To unmark the topic as spam
       
   518 	 * @uses bbp_spam_topic() To mark the topic as spam
       
   519 	 * @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post
       
   520 	 *                    data, action and message
       
   521 	 * @uses add_query_arg() To add custom args to the url
       
   522 	 * @uses wp_safe_redirect() Redirect the page to custom url
       
   523 	 */
       
   524 	public function toggle_topic() {
       
   525 
       
   526 		if ( $this->bail() ) return;
       
   527 
       
   528 		// Only proceed if GET is a topic toggle action
       
   529 		if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam' ) ) && !empty( $_GET['topic_id'] ) ) {
       
   530 			$action    = $_GET['action'];            // What action is taking place?
       
   531 			$topic_id  = (int) $_GET['topic_id'];    // What's the topic id?
       
   532 			$success   = false;                      // Flag
       
   533 			$post_data = array( 'ID' => $topic_id ); // Prelim array
       
   534 			$topic     = bbp_get_topic( $topic_id );
       
   535 
       
   536 			// Bail if topic is missing
       
   537 			if ( empty( $topic ) )
       
   538 				wp_die( __( 'The topic was not found!', 'bbpress' ) );
       
   539 
       
   540 			if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here?
       
   541 				wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
       
   542 
       
   543 			switch ( $action ) {
       
   544 				case 'bbp_toggle_topic_close' :
       
   545 					check_admin_referer( 'close-topic_' . $topic_id );
       
   546 
       
   547 					$is_open = bbp_is_topic_open( $topic_id );
       
   548 					$message = true == $is_open ? 'closed' : 'opened';
       
   549 					$success = true == $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id );
       
   550 
       
   551 					break;
       
   552 
       
   553 				case 'bbp_toggle_topic_stick' :
       
   554 					check_admin_referer( 'stick-topic_' . $topic_id );
       
   555 
       
   556 					$is_sticky = bbp_is_topic_sticky( $topic_id );
       
   557 					$is_super  = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false;
       
   558 					$message   = true == $is_sticky ? 'unsticked'     : 'sticked';
       
   559 					$message   = true == $is_super  ? 'super_sticked' : $message;
       
   560 					$success   = true == $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super );
       
   561 
       
   562 					break;
       
   563 
       
   564 				case 'bbp_toggle_topic_spam'  :
       
   565 					check_admin_referer( 'spam-topic_' . $topic_id );
       
   566 
       
   567 					$is_spam = bbp_is_topic_spam( $topic_id );
       
   568 					$message = true == $is_spam ? 'unspammed' : 'spammed';
       
   569 					$success = true == $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id );
       
   570 
       
   571 					break;
       
   572 			}
       
   573 
       
   574 			$message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID );
       
   575 
       
   576 			if ( false == $success || is_wp_error( $success ) )
       
   577 				$message['failed'] = '1';
       
   578 
       
   579 			// Do additional topic toggle actions (admin side)
       
   580 			do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $message );
       
   581 
       
   582 			// Redirect back to the topic
       
   583 			$redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) );
       
   584 			wp_safe_redirect( $redirect );
       
   585 
       
   586 			// For good measure
       
   587 			exit();
       
   588 		}
       
   589 	}
       
   590 
       
   591 	/**
       
   592 	 * Toggle topic notices
       
   593 	 *
       
   594 	 * Display the success/error notices from
       
   595 	 * {@link BBP_Admin::toggle_topic()}
       
   596 	 *
       
   597 	 * @since bbPress (r2727)
       
   598 	 *
       
   599 	 * @uses bbp_get_topic() To get the topic
       
   600 	 * @uses bbp_get_topic_title() To get the topic title of the topic
       
   601 	 * @uses esc_html() To sanitize the topic title
       
   602 	 * @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with
       
   603 	 *                        message, topic id, notice and is it a failure
       
   604 	 */
       
   605 	public function toggle_topic_notice() {
       
   606 
       
   607 		if ( $this->bail() ) return;
       
   608 
       
   609 		// Only proceed if GET is a topic toggle action
       
   610 		if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_topic_toggle_notice'] ) && in_array( $_GET['bbp_topic_toggle_notice'], array( 'opened', 'closed', 'super_sticked', 'sticked', 'unsticked', 'spammed', 'unspammed' ) ) && !empty( $_GET['topic_id'] ) ) {
       
   611 			$notice     = $_GET['bbp_topic_toggle_notice'];         // Which notice?
       
   612 			$topic_id   = (int) $_GET['topic_id'];                  // What's the topic id?
       
   613 			$is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
       
   614 
       
   615 			// Bais if no topic_id or notice
       
   616 			if ( empty( $notice ) || empty( $topic_id ) )
       
   617 				return;
       
   618 
       
   619 			// Bail if topic is missing
       
   620 			$topic = bbp_get_topic( $topic_id );
       
   621 			if ( empty( $topic ) )
       
   622 				return;
       
   623 
       
   624 			$topic_title = esc_html( bbp_get_topic_title( $topic->ID ) );
       
   625 
       
   626 			switch ( $notice ) {
       
   627 				case 'opened'    :
       
   628 					$message = $is_failure == true ? sprintf( __( 'There was a problem opening the topic "%1$s".',           'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully opened.',           'bbpress' ), $topic_title );
       
   629 					break;
       
   630 
       
   631 				case 'closed'    :
       
   632 					$message = $is_failure == true ? sprintf( __( 'There was a problem closing the topic "%1$s".',           'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully closed.',           'bbpress' ), $topic_title );
       
   633 					break;
       
   634 
       
   635 				case 'super_sticked' :
       
   636 					$message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title );
       
   637 					break;
       
   638 
       
   639 				case 'sticked'   :
       
   640 					$message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s".',          'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked.',          'bbpress' ), $topic_title );
       
   641 					break;
       
   642 
       
   643 				case 'unsticked' :
       
   644 					$message = $is_failure == true ? sprintf( __( 'There was a problem unsticking the topic "%1$s".',        'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unsticked.',        'bbpress' ), $topic_title );
       
   645 					break;
       
   646 
       
   647 				case 'spammed'   :
       
   648 					$message = $is_failure == true ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.',   'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully marked as spam.',   'bbpress' ), $topic_title );
       
   649 					break;
       
   650 
       
   651 				case 'unspammed' :
       
   652 					$message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title );
       
   653 					break;
       
   654 			}
       
   655 
       
   656 			// Do additional topic toggle notice filters (admin side)
       
   657 			$message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure );
       
   658 
       
   659 			?>
       
   660 
       
   661 			<div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
       
   662 				<p style="line-height: 150%"><?php echo $message; ?></p>
       
   663 			</div>
       
   664 
       
   665 			<?php
       
   666 		}
       
   667 	}
       
   668 
       
   669 	/**
       
   670 	 * Manage the column headers for the topics page
       
   671 	 *
       
   672 	 * @since bbPress (r2485)
       
   673 	 *
       
   674 	 * @param array $columns The columns
       
   675 	 * @uses apply_filters() Calls 'bbp_admin_topics_column_headers' with
       
   676 	 *                        the columns
       
   677 	 * @return array $columns bbPress topic columns
       
   678 	 */
       
   679 	public function topics_column_headers( $columns ) {
       
   680 
       
   681 		if ( $this->bail() ) return $columns;
       
   682 
       
   683 		$columns = array(
       
   684 			'cb'                    => '<input type="checkbox" />',
       
   685 			'title'                 => __( 'Topics',    'bbpress' ),
       
   686 			'bbp_topic_forum'       => __( 'Forum',     'bbpress' ),
       
   687 			'bbp_topic_reply_count' => __( 'Replies',   'bbpress' ),
       
   688 			'bbp_topic_voice_count' => __( 'Voices',    'bbpress' ),
       
   689 			'bbp_topic_author'      => __( 'Author',    'bbpress' ),
       
   690 			'bbp_topic_created'     => __( 'Created',   'bbpress' ),
       
   691 			'bbp_topic_freshness'   => __( 'Freshness', 'bbpress' )
       
   692 		);
       
   693 
       
   694 		return apply_filters( 'bbp_admin_topics_column_headers', $columns );
       
   695 	}
       
   696 
       
   697 	/**
       
   698 	 * Print extra columns for the topics page
       
   699 	 *
       
   700 	 * @since bbPress (r2485)
       
   701 	 *
       
   702 	 * @param string $column Column
       
   703 	 * @param int $topic_id Topic id
       
   704 	 * @uses bbp_get_topic_forum_id() To get the forum id of the topic
       
   705 	 * @uses bbp_forum_title() To output the topic's forum title
       
   706 	 * @uses apply_filters() Calls 'topic_forum_row_actions' with an array
       
   707 	 *                        of topic forum actions
       
   708 	 * @uses bbp_get_forum_permalink() To get the forum permalink
       
   709 	 * @uses admin_url() To get the admin url of post.php
       
   710 	 * @uses add_query_arg() To add custom args to the url
       
   711 	 * @uses bbp_topic_reply_count() To output the topic reply count
       
   712 	 * @uses bbp_topic_voice_count() To output the topic voice count
       
   713 	 * @uses bbp_topic_author_display_name() To output the topic author name
       
   714 	 * @uses get_the_date() Get the topic creation date
       
   715 	 * @uses get_the_time() Get the topic creation time
       
   716 	 * @uses esc_attr() To sanitize the topic creation time
       
   717 	 * @uses bbp_get_topic_last_active_time() To get the time when the topic was
       
   718 	 *                                    last active
       
   719 	 * @uses do_action() Calls 'bbp_admin_topics_column_data' with the
       
   720 	 *                    column and topic id
       
   721 	 */
       
   722 	function topics_column_data( $column, $topic_id ) {
       
   723 
       
   724 		if ( $this->bail() ) return;
       
   725 
       
   726 		// Get topic forum ID
       
   727 		$forum_id = bbp_get_topic_forum_id( $topic_id );
       
   728 
       
   729 		// Populate column data
       
   730 		switch ( $column ) {
       
   731 
       
   732 			// Forum
       
   733 			case 'bbp_topic_forum' :
       
   734 
       
   735 				// Output forum name
       
   736 				if ( !empty( $forum_id ) ) {
       
   737 
       
   738 					// Forum Title
       
   739 					$forum_title = bbp_get_forum_title( $forum_id );
       
   740 					if ( empty( $forum_title ) ) {
       
   741 						$forum_title = __( 'No Forum', 'bbpress' );
       
   742 					}
       
   743 
       
   744 					// Output the title
       
   745 					echo $forum_title;
       
   746 
       
   747 				} else {
       
   748 					_e( '(No Forum)', 'bbpress' );
       
   749 				}
       
   750 
       
   751 				break;
       
   752 
       
   753 			// Reply Count
       
   754 			case 'bbp_topic_reply_count' :
       
   755 				bbp_topic_reply_count( $topic_id );
       
   756 				break;
       
   757 
       
   758 			// Reply Count
       
   759 			case 'bbp_topic_voice_count' :
       
   760 				bbp_topic_voice_count( $topic_id );
       
   761 				break;
       
   762 
       
   763 			// Author
       
   764 			case 'bbp_topic_author' :
       
   765 				bbp_topic_author_display_name( $topic_id );
       
   766 				break;
       
   767 
       
   768 			// Freshness
       
   769 			case 'bbp_topic_created':
       
   770 				printf( __( '%1$s <br /> %2$s', 'bbpress' ),
       
   771 					get_the_date(),
       
   772 					esc_attr( get_the_time() )
       
   773 				);
       
   774 
       
   775 				break;
       
   776 
       
   777 			// Freshness
       
   778 			case 'bbp_topic_freshness' :
       
   779 				$last_active = bbp_get_topic_last_active_time( $topic_id, false );
       
   780 				if ( !empty( $last_active ) ) {
       
   781 					echo $last_active;
       
   782 				} else {
       
   783 					_e( 'No Replies', 'bbpress' ); // This should never happen
       
   784 				}
       
   785 
       
   786 				break;
       
   787 
       
   788 			// Do an action for anything else
       
   789 			default :
       
   790 				do_action( 'bbp_admin_topics_column_data', $column, $topic_id );
       
   791 				break;
       
   792 		}
       
   793 	}
       
   794 
       
   795 	/**
       
   796 	 * Topic Row actions
       
   797 	 *
       
   798 	 * Remove the quick-edit action link under the topic title and add the
       
   799 	 * content and close/stick/spam links
       
   800 	 *
       
   801 	 * @since bbPress (r2485)
       
   802 	 *
       
   803 	 * @param array $actions Actions
       
   804 	 * @param array $topic Topic object
       
   805 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   806 	 * @uses bbp_topic_content() To output topic content
       
   807 	 * @uses bbp_get_topic_permalink() To get the topic link
       
   808 	 * @uses bbp_get_topic_title() To get the topic title
       
   809 	 * @uses current_user_can() To check if the current user can edit or
       
   810 	 *                           delete the topic
       
   811 	 * @uses bbp_is_topic_open() To check if the topic is open
       
   812 	 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
       
   813 	 * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a
       
   814 	 *                              super sticky
       
   815 	 * @uses get_post_type_object() To get the topic post type object
       
   816 	 * @uses add_query_arg() To add custom args to the url
       
   817 	 * @uses remove_query_arg() To remove custom args from the url
       
   818 	 * @uses wp_nonce_url() To nonce the url
       
   819 	 * @uses get_delete_post_link() To get the delete post link of the topic
       
   820 	 * @return array $actions Actions
       
   821 	 */
       
   822 	public function topics_row_actions( $actions, $topic ) {
       
   823 
       
   824 		if ( $this->bail() ) return $actions;
       
   825 
       
   826 		unset( $actions['inline hide-if-no-js'] );
       
   827 
       
   828 		// Show view link if it's not set, the topic is trashed and the user can view trashed topics
       
   829 		if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() == $topic->post_status ) && current_user_can( 'view_trash' ) )
       
   830 			$actions['view'] = '<a href="' . bbp_get_topic_permalink( $topic->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
       
   831 
       
   832 		// Only show the actions if the user is capable of viewing them :)
       
   833 		if ( current_user_can( 'moderate', $topic->ID ) ) {
       
   834 
       
   835 			// Close
       
   836 			// Show the 'close' and 'open' link on published and closed posts only
       
   837 			if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) {
       
   838 				$close_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID ) );
       
   839 				if ( bbp_is_topic_open( $topic->ID ) )
       
   840 					$actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . _x( 'Close', 'Close a Topic', 'bbpress' ) . '</a>';
       
   841 				else
       
   842 					$actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Open this topic',  'bbpress' ) . '">' . _x( 'Open',  'Open a Topic',  'bbpress' ) . '</a>';
       
   843 			}
       
   844 
       
   845 			// Dont show sticky if topic links is spam or trash
       
   846 			if ( !bbp_is_topic_spam( $topic->ID ) && !bbp_is_topic_trash( $topic->ID ) ) {
       
   847 
       
   848 				// Sticky
       
   849 				$stick_uri  = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_'  . $topic->ID ) );
       
   850 				if ( bbp_is_topic_sticky( $topic->ID ) ) {
       
   851 					$actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . __( 'Unstick', 'bbpress' ) . '</a>';
       
   852 				} else {
       
   853 					$super_uri        = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_'  . $topic->ID ) );
       
   854 					$actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Stick this topic to its forum', 'bbpress' ) . '">' . __( 'Stick', 'bbpress' ) . '</a> (<a href="' . $super_uri . '" title="' . esc_attr__( 'Stick this topic to front', 'bbpress' ) . '">' . __( 'to front', 'bbpress' ) . '</a>)';
       
   855 				}
       
   856 			}
       
   857 
       
   858 			// Spam
       
   859 			$spam_uri  = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_'  . $topic->ID ) );
       
   860 			if ( bbp_is_topic_spam( $topic->ID ) )
       
   861 				$actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
       
   862 			else
       
   863 				$actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this topic as spam',    'bbpress' ) . '">' . __( 'Spam',     'bbpress' ) . '</a>';
       
   864 
       
   865 		}
       
   866 
       
   867 		// Do not show trash links for spam topics, or spam links for trashed topics
       
   868 		if ( current_user_can( 'delete_topic', $topic->ID ) ) {
       
   869 			if ( bbp_get_trash_status_id() == $topic->post_status ) {
       
   870 				$post_type_object   = get_post_type_object( bbp_get_topic_post_type() );
       
   871 				$actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . wp_nonce_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) ) ), admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $topic->ID ) ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
       
   872 			} elseif ( EMPTY_TRASH_DAYS ) {
       
   873 				$actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
       
   874 			}
       
   875 
       
   876 			if ( bbp_get_trash_status_id() == $topic->post_status || !EMPTY_TRASH_DAYS ) {
       
   877 				$actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
       
   878 			} elseif ( bbp_get_spam_status_id() == $topic->post_status ) {
       
   879 				unset( $actions['trash'] );
       
   880 			}
       
   881 		}
       
   882 
       
   883 		return $actions;
       
   884 	}
       
   885 
       
   886 	/**
       
   887 	 * Add forum dropdown to topic and reply list table filters
       
   888 	 *
       
   889 	 * @since bbPress (r2991)
       
   890 	 *
       
   891 	 * @uses bbp_get_reply_post_type() To get the reply post type
       
   892 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   893 	 * @uses bbp_dropdown() To generate a forum dropdown
       
   894 	 * @return bool False. If post type is not topic or reply
       
   895 	 */
       
   896 	public function filter_dropdown() {
       
   897 
       
   898 		if ( $this->bail() ) return;
       
   899 
       
   900 		// Add Empty Spam button
       
   901 		if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
       
   902 			wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
       
   903 			$title = esc_attr__( 'Empty Spam', 'bbpress' );
       
   904 			submit_button( $title, 'button-secondary apply', 'delete_all', false );
       
   905 		}
       
   906 
       
   907 		// Get which forum is selected
       
   908 		$selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
       
   909 
       
   910 		// Show the forums dropdown
       
   911 		bbp_dropdown( array(
       
   912 			'selected'  => $selected,
       
   913 			'show_none' => __( 'In all forums', 'bbpress' )
       
   914 		) );
       
   915 	}
       
   916 
       
   917 	/**
       
   918 	 * Adjust the request query and include the forum id
       
   919 	 *
       
   920 	 * @since bbPress (r2991)
       
   921 	 *
       
   922 	 * @param array $query_vars Query variables from {@link WP_Query}
       
   923 	 * @uses is_admin() To check if it's the admin section
       
   924 	 * @uses bbp_get_topic_post_type() To get the topic post type
       
   925 	 * @uses bbp_get_reply_post_type() To get the reply post type
       
   926 	 * @return array Processed Query Vars
       
   927 	 */
       
   928 	function filter_post_rows( $query_vars ) {
       
   929 
       
   930 		if ( $this->bail() ) return $query_vars;
       
   931 
       
   932 		// Add post_parent query_var if one is present
       
   933 		if ( !empty( $_GET['bbp_forum_id'] ) ) {
       
   934 			$query_vars['meta_key']   = '_bbp_forum_id';
       
   935 			$query_vars['meta_value'] = $_GET['bbp_forum_id'];
       
   936 		}
       
   937 
       
   938 		// Return manipulated query_vars
       
   939 		return $query_vars;
       
   940 	}
       
   941 
       
   942 	/**
       
   943 	 * Custom user feedback messages for topic post type
       
   944 	 *
       
   945 	 * @since bbPress (r3080)
       
   946 	 *
       
   947 	 * @global int $post_ID
       
   948 	 * @uses bbp_get_topic_permalink()
       
   949 	 * @uses wp_post_revision_title()
       
   950 	 * @uses esc_url()
       
   951 	 * @uses add_query_arg()
       
   952 	 *
       
   953 	 * @param array $messages
       
   954 	 *
       
   955 	 * @return array
       
   956 	 */
       
   957 	public function updated_messages( $messages ) {
       
   958 		global $post_ID;
       
   959 
       
   960 		if ( $this->bail() ) return $messages;
       
   961 
       
   962 		// URL for the current topic
       
   963 		$topic_url = bbp_get_topic_permalink( $post_ID );
       
   964 
       
   965 		// Current topic's post_date
       
   966 		$post_date = bbp_get_global_post_field( 'post_date', 'raw' );
       
   967 
       
   968 		// Messages array
       
   969 		$messages[$this->post_type] = array(
       
   970 			0 =>  '', // Left empty on purpose
       
   971 
       
   972 			// Updated
       
   973 			1 =>  sprintf( __( 'Topic updated. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
       
   974 
       
   975 			// Custom field updated
       
   976 			2 => __( 'Custom field updated.', 'bbpress' ),
       
   977 
       
   978 			// Custom field deleted
       
   979 			3 => __( 'Custom field deleted.', 'bbpress' ),
       
   980 
       
   981 			// Topic updated
       
   982 			4 => __( 'Topic updated.', 'bbpress' ),
       
   983 
       
   984 			// Restored from revision
       
   985 			// translators: %s: date and time of the revision
       
   986 			5 => isset( $_GET['revision'] )
       
   987 					? sprintf( __( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
       
   988 					: false,
       
   989 
       
   990 			// Topic created
       
   991 			6 => sprintf( __( 'Topic created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
       
   992 
       
   993 			// Topic saved
       
   994 			7 => __( 'Topic saved.', 'bbpress' ),
       
   995 
       
   996 			// Topic submitted
       
   997 			8 => sprintf( __( 'Topic submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
       
   998 
       
   999 			// Topic scheduled
       
  1000 			9 => sprintf( __( 'Topic scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
       
  1001 					// translators: Publish box date format, see http://php.net/date
       
  1002 					date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),
       
  1003 					strtotime( $post_date ) ),
       
  1004 					$topic_url ),
       
  1005 
       
  1006 			// Topic draft updated
       
  1007 			10 => sprintf( __( 'Topic draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
       
  1008 		);
       
  1009 
       
  1010 		return $messages;
       
  1011 	}
       
  1012 }
       
  1013 endif; // class_exists check
       
  1014 
       
  1015 /**
       
  1016  * Setup bbPress Topics Admin
       
  1017  *
       
  1018  * This is currently here to make hooking and unhooking of the admin UI easy.
       
  1019  * It could use dependency injection in the future, but for now this is easier.
       
  1020  *
       
  1021  * @since bbPress (r2596)
       
  1022  *
       
  1023  * @uses BBP_Forums_Admin
       
  1024  */
       
  1025 function bbp_admin_topics() {
       
  1026 	bbpress()->admin->topics = new BBP_Topics_Admin();
       
  1027 }