Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/04/2012 02:17:31 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Admin:

  • Add nonce checks and additional sanity checks to converter, to prevent it being loaded or accessed outside of the converter screen.
  • Use 'load-' actions to conditionally load admin components on their respective screens.
  • Remove post_type checks that are no longer needed as a result of conditionally loading each component.
  • Use get_current_screen() to fill in any extra post_type checks.
  • Sweep through converter, make output more clean, add output method, and store last query in the DB in case of failure.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-replies.php

    r4034 r4053  
    2626         * @var The post type of this admin component
    2727         */
    28         var $post_type = '';
     28        private $post_type = '';
    2929
    3030        /** Functions *************************************************************/
     
    7676
    7777                // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
    78                 add_action( 'bbp_admin_init', array( $this, 'toggle_reply'        ) );
     78                add_action( 'load-edit.php', array( $this, 'toggle_reply'        ) );
    7979                add_action( 'admin_notices',  array( $this, 'toggle_reply_notice' ) );
    8080
     
    114114        public function edit_help() {
    115115
    116                 $current_screen = get_current_screen();
    117                 $post_type      = !empty( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : '';
    118 
    119                 // Bail if current screen could not be found
    120                 if ( empty( $current_screen ) )
    121                         return;
    122 
    123                 // Bail if not the reply post type
    124                 if ( $post_type != $this->post_type )
    125                         return;
    126 
    127116                // Overview
    128                 $current_screen->add_help_tab( array(
     117                get_current_screen()->add_help_tab( array(
    129118                        'id'            => 'overview',
    130119                        'title'         => __( 'Overview', 'bbpress' ),
     
    134123
    135124                // Screen Content
    136                 $current_screen->add_help_tab( array(
     125                get_current_screen()->add_help_tab( array(
    137126                        'id'            => 'screen-content',
    138127                        'title'         => __( 'Screen Content', 'bbpress' ),
     
    148137
    149138                // Available Actions
    150                 $current_screen->add_help_tab( array(
     139                get_current_screen()->add_help_tab( array(
    151140                        'id'            => 'action-links',
    152141                        'title'         => __( 'Available Actions', 'bbpress' ),
     
    163152
    164153                // Bulk Actions
    165                 $current_screen->add_help_tab( array(
     154                get_current_screen()->add_help_tab( array(
    166155                        'id'            => 'bulk-actions',
    167156                        'title'         => __( 'Bulk Actions', 'bbpress' ),
     
    172161
    173162                // Help Sidebar
    174                 $current_screen->set_help_sidebar(
     163                get_current_screen()->set_help_sidebar(
    175164                        '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
    176165                        '<p>' . __( '<a href="http://bbpress.org/documentation/" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
     
    187176        public function new_help() {
    188177
    189                 $current_screen = get_current_screen();
    190                 $post_type      = !empty( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : '';
    191 
    192                 // Bail if current screen could not be found
    193                 if ( empty( $current_screen ) )
    194                         return;
    195 
    196                 // Bail if not the reply post type
    197                 if ( $post_type != $this->post_type )
    198                         return;
    199 
    200178                $customize_display = '<p>' . __( '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' ) . '</p>';
    201179
    202                 $current_screen->add_help_tab( array(
     180                get_current_screen()->add_help_tab( array(
    203181                        'id'      => 'customize-display',
    204182                        'title'   => __( 'Customizing This Display', 'bbpress' ),
     
    206184                ) );
    207185
    208                 $current_screen->add_help_tab( array(
     186                get_current_screen()->add_help_tab( array(
    209187                        'id'      => 'title-reply-editor',
    210188                        'title'   => __( 'Title and Reply Editor', 'bbpress' ),
     
    224202                }
    225203
    226                 $current_screen->add_help_tab( array(
     204                get_current_screen()->add_help_tab( array(
    227205                        'id'      => 'reply-attributes',
    228206                        'title'   => __( 'Reply Attributes', 'bbpress' ),
     
    235213                ) );
    236214
    237                 $current_screen->add_help_tab( array(
     215                get_current_screen()->add_help_tab( array(
    238216                        'id'      => 'publish-box',
    239217                        'title'   => __( 'Publish Box', 'bbpress' ),
     
    241219                ) );
    242220
    243                 $current_screen->add_help_tab( array(
     221                get_current_screen()->add_help_tab( array(
    244222                        'id'      => 'discussion-settings',
    245223                        'title'   => __( 'Discussion Settings', 'bbpress' ),
     
    249227                ) );
    250228
    251                 $current_screen->set_help_sidebar(
     229                get_current_screen()->set_help_sidebar(
    252230                        '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
    253231                        '<p>' . __( '<a href="http://bbpress.org/documentation/" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
     
    308286                        return $reply_id;
    309287
    310                 // Bail if post_type is not a reply
    311                 if ( get_post_type( $reply_id ) != $this->post_type )
    312                         return $reply_id;
    313 
    314288                // Current user cannot edit this reply
    315289                if ( !current_user_can( 'edit_reply', $reply_id ) )
     
    347321
    348322                // Bail if post_type is not a reply
    349                 if ( ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) || ( get_post_type() != $this->post_type ) )
     323                if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) )
    350324                        return;
    351325
     
    393367                        return $post_id;
    394368
    395                 // Bail if post_type is not a topic or reply
    396                 if ( get_post_type( $post_id ) != $this->post_type )
    397                         return;
    398 
    399369                // Bail if user cannot edit replies or reply is not anonymous
    400370                if ( !current_user_can( 'edit_reply', $post_id ) )
     
    424394         */
    425395        function admin_head() {
    426 
    427                 if ( get_post_type() == $this->post_type ) : ?>
    428 
    429                         <style type="text/css" media="screen">
    430                         /*<![CDATA[*/
    431 
    432                                 .column-bbp_forum_topic_count,
    433                                 .column-bbp_forum_reply_count,
    434                                 .column-bbp_topic_reply_count,
    435                                 .column-bbp_topic_voice_count {
    436                                         width: 8% !important;
    437                                 }
    438 
    439                                 .column-author,
    440                                 .column-bbp_reply_author,
    441                                 .column-bbp_topic_author {
    442                                         width: 10% !important;
    443                                 }
    444 
    445                                 .column-bbp_topic_forum,
    446                                 .column-bbp_reply_forum,
    447                                 .column-bbp_reply_topic {
    448                                         width: 10% !important;
    449                                 }
    450 
    451                                 .column-bbp_forum_freshness,
    452                                 .column-bbp_topic_freshness {
    453                                         width: 10% !important;
    454                                 }
    455 
    456                                 .column-bbp_forum_created,
    457                                 .column-bbp_topic_created,
    458                                 .column-bbp_reply_created {
    459                                         width: 15% !important;
    460                                 }
    461 
    462                                 .status-closed {
    463                                         background-color: #eaeaea;
    464                                 }
    465 
    466                                 .status-spam {
    467                                         background-color: #faeaea;
    468                                 }
    469 
    470                         /*]]>*/
    471                         </style>
    472 
    473                 <?php endif;
    474 
     396                ?>
     397
     398                <style type="text/css" media="screen">
     399                /*<![CDATA[*/
     400
     401                        .column-bbp_forum_topic_count,
     402                        .column-bbp_forum_reply_count,
     403                        .column-bbp_topic_reply_count,
     404                        .column-bbp_topic_voice_count {
     405                                width: 8% !important;
     406                        }
     407
     408                        .column-author,
     409                        .column-bbp_reply_author,
     410                        .column-bbp_topic_author {
     411                                width: 10% !important;
     412                        }
     413
     414                        .column-bbp_topic_forum,
     415                        .column-bbp_reply_forum,
     416                        .column-bbp_reply_topic {
     417                                width: 10% !important;
     418                        }
     419
     420                        .column-bbp_forum_freshness,
     421                        .column-bbp_topic_freshness {
     422                                width: 10% !important;
     423                        }
     424
     425                        .column-bbp_forum_created,
     426                        .column-bbp_topic_created,
     427                        .column-bbp_reply_created {
     428                                width: 15% !important;
     429                        }
     430
     431                        .status-closed {
     432                                background-color: #eaeaea;
     433                        }
     434
     435                        .status-spam {
     436                                background-color: #faeaea;
     437                        }
     438
     439                /*]]>*/
     440                </style>
     441
     442                <?php
    475443        }
    476444
     
    815783        function filter_dropdown() {
    816784
    817                 // Bail if not viewing the topics list
    818                 if (
    819                                 // post_type exists in _GET
    820                                 empty( $_GET['post_type'] ) ||
    821 
    822                                 // post_type is reply or topic type
    823                                 ( $_GET['post_type'] != $this->post_type )
    824                         )
    825                         return;
    826 
    827785                // Add Empty Spam button
    828786                if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
     
    856814                global $pagenow;
    857815
    858                 // Avoid poisoning other requests
    859                 if (
    860                                 // Only look in admin
    861                                 !is_admin()                 ||
    862 
    863                                 // Make sure the current page is for post rows
    864                                 ( 'edit.php' != $pagenow  ) ||
    865 
    866                                 // Make sure we're looking for a post_type
    867                                 empty( $_GET['post_type'] ) ||
    868 
    869                                 // Make sure we're looking at bbPress topics
    870                                 ( $_GET['post_type'] != $this->post_type )
    871                         )
    872 
    873                         // We're in no shape to filter anything, so return
    874                         return $query_vars;
    875 
    876816                // Add post_parent query_var if one is present
    877817                if ( !empty( $_GET['bbp_forum_id'] ) ) {
     
    890830         *
    891831         * @global int $post_ID
    892          * @uses get_post_type()
    893832         * @uses bbp_get_topic_permalink()
    894833         * @uses wp_post_revision_title()
     
    902841        function updated_messages( $messages ) {
    903842                global $post_ID;
    904 
    905                 if ( get_post_type( $post_ID ) != $this->post_type )
    906                         return $messages;
    907843
    908844                // URL for the current topic
     
    962898 * Setup bbPress Replies Admin
    963899 *
     900 * This is currently here to make hooking and unhooking of the admin UI easy.
     901 * It could use dependency injection in the future, but for now this is easier.
     902 *
    964903 * @since bbPress (r2596)
    965904 *
     
    967906 */
    968907function bbp_admin_replies() {
     908        global $typenow;
     909
     910        if ( bbp_get_reply_post_type() == $typenow )
     911                return;
     912
    969913        bbpress()->admin->replies = new BBP_Replies_Admin();
    970914}
Note: See TracChangeset for help on using the changeset viewer.