diff -r c7c0fbc09788 -r 5e8dcbe22c24 web/wp-content/plugins/bbpress/includes/admin/replies.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/bbpress/includes/admin/replies.php Tue Dec 04 18:43:10 2012 -0800 @@ -0,0 +1,955 @@ +setup_globals(); + $this->setup_actions(); + } + + /** + * Setup the admin hooks, actions and filters + * + * @since bbPress (r2646) + * @access private + * + * @uses add_action() To add various actions + * @uses add_filter() To add various filters + * @uses bbp_get_forum_post_type() To get the forum post type + * @uses bbp_get_topic_post_type() To get the topic post type + * @uses bbp_get_reply_post_type() To get the reply post type + */ + private function setup_actions() { + + // Add some general styling to the admin area + add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); + + // Messages + add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); + + // Reply column headers. + add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'replies_column_headers' ) ); + + // Reply columns (in post row) + add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'replies_column_data' ), 10, 2 ); + add_filter( 'post_row_actions', array( $this, 'replies_row_actions' ), 10, 2 ); + + // Reply metabox actions + add_action( 'add_meta_boxes', array( $this, 'reply_attributes_metabox' ) ); + add_action( 'save_post', array( $this, 'reply_attributes_metabox_save' ) ); + + // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed + add_action( 'load-edit.php', array( $this, 'toggle_reply' ) ); + add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) ); + + // Anonymous metabox actions + add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); + add_action( 'save_post', array( $this, 'author_metabox_save' ) ); + + // Add ability to filter topics and replies per forum + add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) ); + add_filter( 'bbp_request', array( $this, 'filter_post_rows' ) ); + + // Contextual Help + add_action( 'load-edit.php', array( $this, 'edit_help' ) ); + add_action( 'load-post-new.php', array( $this, 'new_help' ) ); + } + + /** + * Should we bail out of this method? + * + * @since bbPress (r4067) + * @return boolean + */ + private function bail() { + if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) ) + return true; + + return false; + } + + /** + * Admin globals + * + * @since bbPress (r2646) + * @access private + */ + private function setup_globals() { + $this->post_type = bbp_get_reply_post_type(); + } + + /** Contextual Help *******************************************************/ + + /** + * Contextual help for bbPress reply edit page + * + * @since bbPress (r3119) + * @uses get_current_screen() + */ + public function edit_help() { + + if ( $this->bail() ) return; + + // Overview + get_current_screen()->add_help_tab( array( + 'id' => 'overview', + 'title' => __( 'Overview', 'bbpress' ), + 'content' => + '
' . __( 'This screen provides access to all of your replies. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '
' + ) ); + + // Screen Content + get_current_screen()->add_help_tab( array( + 'id' => 'screen-content', + 'title' => __( 'Screen Content', 'bbpress' ), + 'content' => + '' . __( 'You can customize the display of this screen’s contents in a number of ways:', 'bbpress' ) . '
' . + '' . __( 'Hovering over a row in the replies list will display action links that allow you to manage your reply. You can perform the following actions:', 'bbpress' ) . '
' . + '' . __( 'You can also edit or move multiple replies to the trash at once. Select the replies 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' ) . '
' . + '' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected replies at once. To remove a reply from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '
' + ) ); + + // Help Sidebar + get_current_screen()->set_help_sidebar( + '' . __( 'For more information:', 'bbpress' ) . '
' . + '' . __( 'bbPress Documentation', 'bbpress' ) . '
' . + '' . __( 'bbPress Support Forums', 'bbpress' ) . '
' + ); + } + + /** + * Contextual help for bbPress reply edit page + * + * @since bbPress (r3119) + * @uses get_current_screen() + */ + public function new_help() { + + if ( $this->bail() ) return; + + $customize_display = '' . __( 'The title field and the big reply 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' ) . '
'; + + get_current_screen()->add_help_tab( array( + 'id' => 'customize-display', + 'title' => __( 'Customizing This Display', 'bbpress' ), + 'content' => $customize_display, + ) ); + + get_current_screen()->add_help_tab( array( + 'id' => 'title-reply-editor', + 'title' => __( 'Title and Reply Editor', 'bbpress' ), + 'content' => + '' . __( 'Title - Enter a title for your reply. After you enter a title, you’ll see the permalink below, which you can edit.', 'bbpress' ) . '
' . + '' . __( 'Reply Editor - Enter the text for your reply. 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 reply text. You can insert media files by clicking the icons above the reply 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 reply editor.', 'bbpress' ) . '
' + ) ); + + $publish_box = '' . __( 'Publish - You can set the terms of publishing your reply 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 reply 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 reply to be published in the future or backdate a reply.', 'bbpress' ) . '
'; + + if ( current_theme_supports( 'reply-formats' ) && reply_type_supports( 'reply', 'reply-formats' ) ) { + $publish_box .= '' . __( 'reply Format - This designates how your theme will display a specific reply. For example, you could have a standard blog reply with a title and paragraphs, or a short aside that omits the title and contains a short text blurb. Please refer to the Codex for descriptions of each reply format. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '
'; + } + + if ( current_theme_supports( 'reply-thumbnails' ) && reply_type_supports( 'reply', 'thumbnail' ) ) { + $publish_box .= '' . __( 'Featured Image - This allows you to associate an image with your reply without inserting it. This is usually useful only if your theme makes use of the featured image as a reply thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '
'; + } + + get_current_screen()->add_help_tab( array( + 'id' => 'reply-attributes', + 'title' => __( 'Reply Attributes', 'bbpress' ), + 'content' => + '' . __( 'Select the attributes that your reply should have:', 'bbpress' ) . '
' . + '' . __( 'Send Trackbacks - Trackbacks are a way to notify legacy blog systems that you’ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they’ll be notified automatically using pingbacks, and this field is unnecessary.', 'bbpress' ) . '
' . + '' . __( 'Discussion - You can turn comments and pings on or off, and if there are comments on the reply, you can see them here and moderate them.', 'bbpress' ) . '
' + ) ); + + get_current_screen()->set_help_sidebar( + '' . __( 'For more information:', 'bbpress' ) . '
' . + '' . __( 'bbPress Documentation', 'bbpress' ) . '
' . + '' . __( 'bbPress Support Forums', 'bbpress' ) . '
' + ); + } + + /** + * Add the reply attributes metabox + * + * @since bbPress (r2746) + * + * @uses bbp_get_reply_post_type() To get the reply post type + * @uses add_meta_box() To add the metabox + * @uses do_action() Calls 'bbp_reply_attributes_metabox' + */ + public function reply_attributes_metabox() { + + if ( $this->bail() ) return; + + add_meta_box ( + 'bbp_reply_attributes', + __( 'Reply Attributes', 'bbpress' ), + 'bbp_reply_metabox', + $this->post_type, + 'side', + 'high' + ); + + do_action( 'bbp_reply_attributes_metabox' ); + } + + /** + * Pass the reply attributes for processing + * + * @since bbPress (r2746) + * + * @param int $reply_id Reply id + * @uses current_user_can() To check if the current user is capable of + * editing the reply + * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the + * reply id and parent id + * @return int Parent id + */ + public function reply_attributes_metabox_save( $reply_id ) { + + if ( $this->bail() ) return $reply_id; + + // Bail if doing an autosave + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) + return $reply_id; + + // Bail if not a post request + if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) + return $reply_id; + + // Check action exists + if ( empty( $_POST['action'] ) ) + return $reply_id; + + // Nonce check + if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) + return $reply_id; + + // Current user cannot edit this reply + if ( !current_user_can( 'edit_reply', $reply_id ) ) + return $reply_id; + + // Get the reply meta post values + $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; + $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id ); + + // Formally update the reply + bbp_update_reply( $reply_id, $topic_id, $forum_id ); + + // Allow other fun things to happen + do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id ); + + return $reply_id; + } + + /** + * Add the author info metabox + * + * Allows editing of information about an author + * + * @since bbPress (r2828) + * + * @uses bbp_get_topic() To get the topic + * @uses bbp_get_reply() To get the reply + * @uses bbp_get_topic_post_type() To get the topic post type + * @uses bbp_get_reply_post_type() To get the reply post type + * @uses add_meta_box() To add the metabox + * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply + * id + */ + public function author_metabox() { + + if ( $this->bail() ) return; + + // Bail if post_type is not a reply + if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) + return; + + // Add the metabox + add_meta_box( + 'bbp_author_metabox', + __( 'Author Information', 'bbpress' ), + 'bbp_author_metabox', + $this->post_type, + 'side', + 'high' + ); + + do_action( 'bbp_author_metabox', get_the_ID() ); + } + + /** + * Save the author information for the topic/reply + * + * @since bbPress (r2828) + * + * @param int $post_id Topic or reply id + * @uses bbp_get_topic() To get the topic + * @uses bbp_get_reply() To get the reply + * @uses current_user_can() To check if the current user can edit the + * topic or reply + * @uses bbp_filter_anonymous_post_data() To filter the anonymous user data + * @uses update_post_meta() To update the anonymous user data + * @uses do_action() Calls 'bbp_author_metabox_save' with the reply id and + * anonymous data + * @return int Topic or reply id + */ + public function author_metabox_save( $post_id ) { + + if ( $this->bail() ) return $post_id; + + // Bail if no post_id + if ( empty( $post_id ) ) + return $post_id; + + // Bail if not a post request + if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) + return $post_id; + + // Bail if doing an autosave + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) + return $post_id; + + // Bail if user cannot edit replies or reply is not anonymous + if ( !current_user_can( 'edit_reply', $post_id ) ) + return $post_id; + + $anonymous_data = bbp_filter_anonymous_post_data(); + + update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] ); + update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] ); + update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] ); + + do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data ); + + return $post_id; + } + + /** + * Add some general styling to the admin area + * + * @since bbPress (r2464) + * + * @uses bbp_get_forum_post_type() To get the forum post type + * @uses bbp_get_topic_post_type() To get the topic post type + * @uses bbp_get_reply_post_type() To get the reply post type + * @uses sanitize_html_class() To sanitize the classes + * @uses do_action() Calls 'bbp_admin_head' + */ + public function admin_head() { + + if ( $this->bail() ) return; + + ?> + + + + bail() ) return; + + // Only proceed if GET is a reply toggle action + if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) { + $action = $_GET['action']; // What action is taking place? + $reply_id = (int) $_GET['reply_id']; // What's the reply id? + $success = false; // Flag + $post_data = array( 'ID' => $reply_id ); // Prelim array + + // Get reply and die if empty + $reply = bbp_get_reply( $reply_id ); + if ( empty( $reply ) ) // Which reply? + wp_die( __( 'The reply was not found!', 'bbpress' ) ); + + if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here? + wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); + + switch ( $action ) { + case 'bbp_toggle_reply_spam' : + check_admin_referer( 'spam-reply_' . $reply_id ); + + $is_spam = bbp_is_reply_spam( $reply_id ); + $message = $is_spam ? 'unspammed' : 'spammed'; + $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id ); + + break; + } + + $success = wp_update_post( $post_data ); + $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID ); + + if ( false == $success || is_wp_error( $success ) ) + $message['failed'] = '1'; + + // Do additional reply toggle actions (admin side) + do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message ); + + // Redirect back to the reply + $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) ); + wp_safe_redirect( $redirect ); + + // For good measure + exit(); + } + } + + /** + * Toggle reply notices + * + * Display the success/error notices from + * {@link BBP_Admin::toggle_reply()} + * + * @since bbPress (r2740) + * + * @uses bbp_get_reply() To get the reply + * @uses bbp_get_reply_title() To get the reply title of the reply + * @uses esc_html() To sanitize the reply title + * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with + * message, reply id, notice and is it a failure + */ + public function toggle_reply_notice() { + + if ( $this->bail() ) return; + + // Only proceed if GET is a reply toggle action + if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_reply_toggle_notice'] ) && in_array( $_GET['bbp_reply_toggle_notice'], array( 'spammed', 'unspammed' ) ) && !empty( $_GET['reply_id'] ) ) { + $notice = $_GET['bbp_reply_toggle_notice']; // Which notice? + $reply_id = (int) $_GET['reply_id']; // What's the reply id? + $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure? + + // Empty? No reply? + if ( empty( $notice ) || empty( $reply_id ) ) + return; + + // Get reply and bail if empty + $reply = bbp_get_reply( $reply_id ); + if ( empty( $reply ) ) + return; + + $reply_title = esc_html( bbp_get_reply_title( $reply->ID ) ); + + switch ( $notice ) { + case 'spammed' : + $message = $is_failure == true ? sprintf( __( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title ); + break; + + case 'unspammed' : + $message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title ); + break; + } + + // Do additional reply toggle notice filters (admin side) + $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure ); + + ?> + +