Making WordPress.org

Changeset 6910


Ignore:
Timestamp:
03/23/2018 09:59:23 PM (6 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add support for user feedback on submitted user notes.

Props keesiemeijer.
See #1504.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments.php

    r5239 r6910  
    3333
    3434        <ol class="comment-list">
    35             <?php
    36                 /* Loop through and list the comments. Tell wp_list_comments()
    37                  * to use wporg_developer_comment() to format the comments.
     35            <?php
     36                $feedback_editor = false;
     37
     38                /* Loop through and list the comments. Use wporg_developer_list_notes() to format the comments.
    3839                 * If you want to override this in a child theme, then you can
    39                  * define wporg_developer_comment() and that will be used instead.
    40                  * See wporg_developer_comment() in inc/template-tags.php for more.
     40                 * define wporg_developer_list_notes() and that will be used instead.
     41                 * See wporg_developer_list_notes() in inc/template-tags.php for more.
    4142                 */
    4243                if ( is_singular( 'post' ) ) {
     
    4546                    $ordered_comments = wporg_developer_get_ordered_notes();
    4647                    if ( $ordered_comments ) {
    47                         wp_list_comments( array( 'callback' => 'wporg_developer_user_note' ), $ordered_comments );
     48                        $feedback_editor = array_filter(  wp_list_pluck( $ordered_comments, 'show_editor') );
     49                        wporg_developer_list_notes( $ordered_comments, array( 'avatar_size' => 32 ) );
    4850                    }
    4951                }
     
    6365    <?php if ( \DevHub\is_parsed_post_type() && DevHub\can_user_post_note( true, get_the_ID() ) ) : ?>
    6466
    65         <p id="add-user-note" style="display:none;"><a href=""><?php _e( 'Have a note or feedback to contribute?', 'wporg' ); ?></a></p>
     67        <?php $add_note_style = empty( $feedback_editor ) ? 'display:none;' : ''; ?>
     68        <p id="add-user-note" style="<?php echo $add_note_style; ?>"><a href="<?php echo user_trailingslashit( get_permalink() ) . '#respond'; ?>"><?php _e( 'Have a note or feedback to contribute?', 'wporg' ); ?></a></p>
    6669
    67         <?php comment_form( array(
    68             'class_form'          => 'comment-form tab-container',
    69             'comment_field'       => DevHub_User_Submitted_Content::wp_editor_comments(),
     70        <?php
     71        $args = array(
    7072            'logged_in_as'        => '<p class="logged-in-as">'
    7173                . sprintf(
     
    9193                )
    9294                . '</li></ul></p>',
    93             'comment_notes_after' => DevHub_Note_Preview::comment_preview()
    94                 . '<p>'
    95                 . __( 'Submission Notes:', 'wporg' )
     95            'comment_notes_after' => '<p>'
     96                . __( 'Submission Notes:', 'wporg' )
    9697                . '<ul><li>'
    9798                . __( 'This form is not for support requests, discussions, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' )
     
    106107                . '</li></ul></p>',
    107108            'label_submit'        => __( 'Add Note or Feedback', 'wporg' ),
     109            'cancel_reply_link'   => '',
    108110            'must_log_in'         => '<p>' . sprintf(
    109111                __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ),
    110                 'https://wordpress.org/support/bb-login.php?redirect_to=' . urlencode( get_comments_link() )
     112                'https://login.wordpress.org/?redirect_to=' . urlencode( get_comments_link() )
    111113            ) . '</p>',
    112             'title_reply'         =>  '', //'Add Example'
    113         ) ); ?>
     114            'title_reply'         => '', //'Add Example'
     115            'title_reply_to'      => '',
     116        );
    114117
     118        if ( class_exists( 'DevHub_Note_Preview' ) ) {
     119            $args['comment_notes_after'] = DevHub_Note_Preview::comment_preview() . $args['comment_notes_after'];
     120            $args['class_form']          = 'comment-form tab-container';
     121        }
     122
     123        if ( class_exists( 'DevHub_User_Submitted_Content' ) ) {
     124            $args['comment_field'] = DevHub_User_Submitted_Content::wp_editor_comments();
     125        }
     126
     127        // Insert comment form if feedback form is not already used.
     128        if ( empty( $feedback_editor ) ) {
     129            comment_form( $args );
     130        }
     131        ?>
    115132    <?php endif; ?>
    116133
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r6512 r6910  
    7777         * Get contibuted notes ordered by vote
    7878         *
    79          * By default only top level comments are returned.
    80          * If child notes are included use wp_list_comments() or a custom walker for display.
    81          * unapproved notes for the current user are included.
     79         * Only the parent notes are ordered by vote count.
     80         * Child notes are added to to the parent note 'child_notes' property.
     81         * Unapproved notes for the current user are included.
     82         * Use `wporg_developer_list_notes()` to display the notes.
    8283         *
    8384         * @param integer $post_id Optional. Post id to get comments for
     
    9394            }
    9495
    95             $order    = array();
    9696            $defaults = array(
    9797                'post__in'           => array( $post_id ),
     
    9999                'status'             => 'approve',
    100100                'include_unapproved' => array_filter( array( get_current_user_id() ) ),
    101                 'parent'             => false,
    102101            );
    103102
     
    106105            }
    107106
    108             $args = wp_parse_args( $args, $defaults );
    109 
     107            $args     = wp_parse_args( $args, $defaults );
    110108            $comments = get_comments( $args );
    111109
     
    114112            }
    115113
     114            // Check if the current page is a reply to a note.
     115            $reply_id = 0;
     116            if ( isset( $_GET['replytocom'] ) && $_GET['replytocom'] ) {
     117                $reply_id = absint( $_GET['replytocom'] );
     118            }
     119
     120            $order = $children = array();
     121            $voting = class_exists( 'DevHub_User_Contributed_Notes_Voting' );
     122
     123            // Remove child notes and add the vote count order for parent notes.
    116124            foreach ( $comments as $key => $comment ) {
    117                 $order[ $key ] = (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' );
     125                if ( 0 === (int) $comment->comment_parent ) {
     126                    $vote_count    = $voting ? (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' ) : 0;
     127                    $order[ $key ] = $vote_count;
     128                } else {
     129                    unset( $comments[ $key ] );
     130                    $children[ $comment->comment_parent ][] = $comment;
     131                }
     132            }
     133
     134            $show_editor = false;
     135
     136            // Add children notes to their parents.
     137            foreach ( $comments as $key => $comment ) {
     138                $comments[ $key ]->child_notes = array();
     139                $comments[ $key ]->show_editor = false;
     140
     141                if ( array_key_exists( $comment->comment_ID, $children ) ) {
     142                    $comments[ $key ]->child_notes = array_reverse( $children[ $comment->comment_ID ] );
     143                }
     144
     145                if ( ! $show_editor && ( $reply_id && ( $reply_id === (int) $comment->comment_ID ) ) ) {
     146                    // Show the editor when replying to this parent comment
     147                    $comments[ $key ]->show_editor = true;
     148                    $show_editor = true;
     149                }
    118150            }
    119151
     
    124156        }
    125157    endif;
     158
     159    if ( ! function_exists( 'wporg_developer_list_notes' ) ) :
     160        /**
     161         * List user contributed notes.
     162         *
     163         * @param array   $comments Array with comment objects.
     164         * @param array   $args Comment display arguments.
     165         */
     166        function wporg_developer_list_notes( $comments, $args ) {
     167            $is_user_logged_in  = is_user_logged_in();
     168            $can_user_post_note = DevHub\can_user_post_note( true, get_the_ID() );
     169            $user_content       = class_exists( 'DevHub_User_Submitted_Content' );
     170            $display_editor     = $is_user_logged_in && $can_user_post_note && $user_content;
     171
     172            foreach ( $comments as $comment ) {
     173
     174                $comment_id = $comment->comment_ID;
     175
     176                // Display parent comment.
     177                wporg_developer_user_note( $comment, $args, 1 );
     178
     179                // Show or hide feedback notes.
     180                $class = $comment->show_editor ? '' : ' hide-if-js';
     181                echo "<section id='feedback-{$comment_id}' class='feedback{$class}'>\n";
     182
     183                // Display child comments.
     184                if ( ! empty( $comment->child_notes ) ) {
     185
     186                    echo "<h4 class='feedback-title'>Feedback</h4>\n";
     187                    echo "<ul class='children'>\n";
     188                    foreach ( $comment->child_notes as $child_note ) {
     189                        wporg_developer_user_note( $child_note, $args, 2, $comment->show_editor );
     190                    }
     191                    echo "</ul>\n";
     192                }
     193
     194                // Add a feedback form for logged in users.
     195                if ( $display_editor ) {
     196                    // Show or hide the editor depending if we're replying to a note.
     197                    $display = $comment->show_editor ? 'show' : 'hide';
     198                    echo DevHub_User_Submitted_Content::wp_editor_feedback( $comment, $display );
     199                }
     200                echo "</section><!-- .feedback -->\n";
     201
     202                // Feedback links to log in, add feedback or show feedback.
     203                echo "<footer class='feedback-links' >\n";
     204                if ( $can_user_post_note ) {
     205                    echo "EEE";
     206                    $feedback_link = trailingslashit( get_permalink() ) . "?replytocom={$comment_id}#feedback-editor-{$comment_id}";
     207                    $display       = '';
     208                    $aria          = '';
     209                    if ( ! $is_user_logged_in ) {
     210                        $class         = 'login';
     211                        $feedback_text = __( 'Log in to add feedback', 'wporg' );
     212                        $feedback_link = 'https://login.wordpress.org/?redirect_to=' . urlencode( $feedback_link );
     213                    } else {
     214                        $class         ='add';
     215                        $feedback_text = __( 'Add feedback to this note', 'wporg' );
     216                        $aria          = '';//" aria-expanded='false' aria_controls='feedback-editor-{$comment_id}' aria-label='" . esc_attr( $feedback_text ) . "'";
     217
     218                        // Hide 'add feedback' link if editor is displayed.
     219                        $display = $display_editor && $comment->show_editor ? ' style="display:none"' : '';
     220                    }
     221                    echo '<a class="feedback-' . $class . '" href="' . esc_url( $feedback_link ) . '"' . $display . $aria .' rel="nofollow">' . $feedback_text . '</a>';
     222                }
     223
     224                // close parent list item
     225                echo "</footer>\n</article><!-- .comment-body -->\n</li>\n";
     226            }
     227        }
     228    endif;
     229
    126230
    127231    if ( ! function_exists( 'wporg_developer_user_note' ) ) :
    128232        /**
    129233         * Template for user contributed notes.
     234         *
     235         * @param object $comment Comment object.
     236         * @param array  $args    Arguments.
     237         * @param int    $depth   Nested comment depth.
    130238         */
    131239        function wporg_developer_user_note( $comment, $args, $depth ) {
    132             $GLOBALS['comment'] = $comment;
    133             $count = (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' );
    134             $curr_user_note = DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID );
    135 
     240            $GLOBALS['comment']       = $comment;
     241            $GLOBALS['comment_depth'] = $depth;
     242
     243            $approved       = ( 0 < (int) $comment->comment_approved ) ? true : false;
     244            $is_parent      = ( 0 === (int) $comment->comment_parent ) ? true : false;
     245            $is_voting      = class_exists( 'DevHub_User_Contributed_Notes_Voting' );
     246            $count          = $is_voting ? (int)  DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' ) : 0;
     247            $curr_user_note = $is_voting ? (bool) DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID ) : false;
     248
     249            // Classes
    136250            $comment_class = array();
     251
    137252            if ( -1 > $count ) {
    138253                $comment_class[] = 'bad-note';
    139254            }
     255
    140256            if ( $curr_user_note ) {
    141257                $comment_class[] = 'user-submitted-note';
    142258            }
     259
     260            if ( ! $approved ) {
     261                $comment_class[] = 'user-note-moderated';
     262            }
     263
     264            // This would all be moot if core passed the $comment context for 'get_comment_author_link' filter.
     265            if ( $comment->user_id ) {
     266                $commenter = get_user_by( 'id', $comment->user_id );
     267                $url = 'https://profiles.wordpress.org/' . sanitize_key( $commenter->user_nicename ) . '/';
     268                $author = get_the_author_meta( 'display_name', $comment->user_id );
     269            } else {
     270                $url = $comment->comment_author_url;
     271                $author = $comment->comment_author;
     272            }
     273
     274            $comment_author_link = $author;
     275            if ( $url ) {
     276                $comment_author_link = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     277            }
     278
     279            $date = sprintf( _x( '%1$s ago', '%1$s = human-readable time difference', 'wporg' ),
     280                human_time_diff( get_comment_time( 'U' ),
     281                current_time( 'timestamp' ) )
     282            );
    143283            ?>
    144 
    145             <li id="comment-<?php comment_ID(); ?>" <?php comment_class( implode( ' ', $comment_class ) ); ?>>
     284            <li id="comment-<?php comment_ID(); ?>" data-comment-id="<?php echo $comment->comment_ID;  ?>" <?php comment_class( implode( ' ', $comment_class ) ); ?>>
    146285            <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     286
     287            <?php if ( $is_parent ) : ?>
    147288                <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php _e( 'Skip to note content', 'wporg' ); ?></a>
    148289                <header class="comment-meta">
    149                     <?php DevHub_User_Contributed_Notes_Voting::show_voting(); ?>
     290
     291                <?php
     292                if ( $is_voting ) {
     293                    DevHub_User_Contributed_Notes_Voting::show_voting();
     294                }
     295                ?>
    150296                    <div class="comment-author vcard">
    151297                        <span class="comment-author-attribution">
    152                         <?php if ( 0 != $args['avatar_size'] ) {
    153                                 echo get_avatar( $comment, $args['avatar_size'] );
    154                         } ?>
    155 
    156298                        <?php
    157                             // This would all be moot if core passed the $comment context for 'get_comment_author_link' filter
    158                             if ( $comment->user_id ) {
    159                                 $commenter = get_user_by( 'id', $comment->user_id );
    160                                 $url = 'https://profiles.wordpress.org/' . esc_attr( $commenter->user_nicename ) . '/';
    161                                 $author = get_the_author_meta( 'display_name', $comment->user_id );
    162                             } else {
    163                                 $url = $comment->comment_author_url;
    164                                 $author = $comment->comment_author;
    165                             }
    166 
    167                             $comment_author_link = '';
    168                             if ( $url ) {
    169                                 $comment_author_link = "<a href='$url' rel='external nofollow' class='url'>";
    170                             }
    171                             $comment_author_link .= $author;
    172                             if ( $url ) {
    173                                 $comment_author_link .= '</a>';
    174                             }
    175 
    176                             printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) );
     299                        if ( 0 != $args['avatar_size'] ) {
     300                            echo get_avatar( $comment, $args['avatar_size'] );
     301                        }
     302
     303                        printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) );
    177304                        ?>
    178305
     
    181308                        <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    182309                            <time datetime="<?php comment_time( 'c' ); ?>">
    183                             <?php
    184                                 printf( _x( '%1$s ago', '%1$s = human-readable time difference', 'wporg' ),
    185                                     human_time_diff( get_comment_time( 'U' ),
    186                                     current_time( 'timestamp' ) )
    187                                 );
    188                             ?>
     310                            <?php echo $date; ?>
    189311                            </time>
    190312                        </a>
    191313                        <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">&mdash; ', '</span>' ); ?>
     314                        <?php if ( ! $approved ) : ?>
     315                            &mdash; <span class="comment-awaiting-moderation"><?php _e( 'awaiting moderation', 'wporg' ); ?></span>
     316                        <?php endif; ?>
    192317                    </div>
    193318                </header>
    194319                <!-- .comment-metadata -->
     320            <?php endif; ?>
    195321
    196322                <div class="comment-content" id="comment-content-<?php echo $comment->comment_ID; ?>">
    197                     <?php comment_text(); ?>
    198                 </div>
    199                 <!-- .comment-content -->
    200 
    201                 <?php if ( '0' == $comment->comment_approved ) : ?>
    202                     <footer class="comment-footer">
    203                         <p class="comment-awaiting-moderation"><?php _e( 'Your note is awaiting moderation.', 'wporg' ); ?></p>
    204                     </footer>
    205                     <!-- .comment-footer -->
    206                 <?php endif; ?>
    207 
    208323                <?php
    209                     comment_reply_link( array_merge( $args, array(
    210                         'add_below' => 'div-comment',
    211                         'depth'     => $depth,
    212                         'max_depth' => $args['max_depth'],
    213                         'before'    => '<div class="reply">',
    214                         'after'     => '</div>',
    215                     ) ) );
     324                if ( $is_parent ) {
     325                    comment_text();
     326                } else {
     327                    $text = get_comment_text()  . ' &mdash; ';
     328                    $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) ) . ' &mdash; ';
     329                    $text .= ' <a href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
     330                    $text .= '<time datetime="' . get_comment_time( 'c' ) . '">' . $date . '</time></a>';
     331
     332                    if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
     333                        $text .= ' &mdash; <a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) .'">';
     334                        $text .= __( 'Edit', 'wporg' ) . '</a>';
     335                    }
     336
     337                    if ( ! $approved ) {
     338                        $text .= ' &mdash; <span class="comment-awaiting-moderation">' . __( 'awaiting moderation', 'wporg' ) . '</span>';
     339                    }
     340
     341                    echo apply_filters( 'comment_text', $text );
     342                }
    216343                ?>
    217             </article><!-- .comment-body -->
    218             <?php
     344                </div><!-- .comment-content -->
     345
     346            <?php if ( ! $is_parent ) : ?>
     347            </article>
     348            </li>
     349            <?php endif; ?>
     350        <?php
    219351        }
    220352    endif; // ends check for wporg_developer_user_note()
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php

    r5243 r6910  
    4141        add_filter( 'comment_reply_link',              '__return_empty_string' );
    4242
     43        // Remove cancel reply link
     44        add_filter( 'cancel_comment_reply_link',       '__return_empty_string' );
     45
    4346        // Disable smilie conversion
    4447        remove_filter( 'comment_text',                 'convert_smilies',    20 );
     
    5861        // Tweak code contained in shortcode
    5962        add_filter( 'syntaxhighlighter_precode',       array( __CLASS__, 'syntaxhighlighter_precode' ) );
     63
     64        // Allowed HTML for a new child comment
     65        add_filter( 'preprocess_comment',              array( __CLASS__, 'comment_new_allowed_html' ) );
     66
     67        // Allowed HTML for an edited child comment (There is no decent hook to filter child comments only)
     68        add_action( 'edit_comment',                    array( __CLASS__, 'comment_edit_allowed_html' ) );
    6069
    6170    }
     
    8089
    8190    /**
     91     * Updates edited child comments with allowed HTML.
     92     *
     93     * Allowed html is <strong>, <em>, <code> and <a>.
     94     *
     95     * @param int $comment_ID Comment ID.
     96     */
     97    public static function comment_edit_allowed_html( $comment_ID ) {
     98
     99        // Get the edited comment.
     100        $comment = get_comment( $comment_ID, ARRAY_A );
     101        if ( ! $comment ) {
     102            return;
     103        }
     104
     105        if ( ( 0 === (int) $comment['comment_parent'] ) || empty( $comment['comment_content'] ) ) {
     106            return;
     107        }
     108
     109        $content = $comment['comment_content'];
     110        $data    = self::comment_new_allowed_html( $comment );
     111
     112        if ( $data['comment_content'] !== $content ) {
     113            $commentarr = array(
     114                'comment_ID' => $data['comment_ID'],
     115                'comment_content' => $data['comment_content']
     116            );
     117
     118            // Update comment content.
     119            wp_update_comment( $commentarr );
     120        }
     121    }
     122
     123    /**
     124     * Filter new child comments content with allowed HTML.
     125     *
     126     * Allowed html is <strong>, <em>, <code> and <a>.
     127     *
     128     * @param array $commentdata Array with comment data.
     129     * @return array Array with filtered comment data.
     130     */
     131    public static function comment_new_allowed_html( $commentdata ) {
     132        $comment_parent  = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0;
     133        $comment_content = isset( $commentdata['comment_content'] ) ? trim( $commentdata['comment_content'] ) : '';
     134
     135        if ( ( $comment_parent === 0 ) || ! $comment_content ) {
     136            return $commentdata;
     137        }
     138
     139        $allowed_html = array(
     140            'a'      => array(
     141                'href'   => true,
     142                'rel'    => true,
     143                'target' => true,
     144            ),
     145            'em'     => array(),
     146            'strong' => array(),
     147            'code'   => array(),
     148        );
     149
     150        $allowed_protocols = array( 'http', 'https' );
     151
     152        $comment_content = wp_kses( $comment_content, $allowed_html, $allowed_protocols );
     153        $commentdata['comment_content'] = preg_replace( '/\r?\n|\r/', '', $comment_content );
     154
     155        return $commentdata;
     156    }
     157
     158    /**
    82159     * Enqueues scripts and styles.
    83160     */
     
    88165            wp_enqueue_style( 'syntaxhighlighter-theme-default' );
    89166
    90             wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'quicktags' ), '20170404', true );
    91             if ( get_option( 'thread_comments' ) ) {
    92                 wp_enqueue_script( 'comment-reply' );
    93             }
     167            wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'jquery', 'quicktags' ), '20170404', true );
     168            wp_enqueue_script( 'wporg-developer-user-notes-feedback', get_template_directory_uri() . '/js/user-notes-feedback.js', array( 'jquery', 'quicktags' ), '20170404eee', true );
     169            wp_localize_script( 'wporg-developer-user-notes-feedback', 'wporg_note_feedback', array(
     170                'show' => __( 'Show Feedback', 'wporg' ),
     171                'hide' => __( 'Hide Feedback', 'wporg' ),
     172            ) );
    94173        }
    95174    }
     
    155234    }
    156235
     236    /**
     237     * Capture an {@see wp_editor()} instance as the 'User Contributed Notes' feedback form.
     238     *
     239     * Uses output buffering to capture the editor instance.
     240     *
     241     * @return string HTML output for the wp_editor-ized feedback form.
     242     */
     243    public static function wp_editor_feedback( $comment, $display = 'show', $content = '' ) {
     244
     245        if ( ! ( isset( $comment->comment_ID ) && absint( $comment->comment_ID ) ) ) {
     246            return '';
     247        }
     248
     249        $comment_id = absint( $comment->comment_ID );
     250
     251        static $instance = 0;
     252        $instance++;
     253
     254        $display     = ( 'hide' === $display ) ? ' style="display: none;"' : '';
     255        $title       = __( 'Add feedback to this note', 'wporg' );
     256        $form_type   = '';
     257        $button_text = __( 'Add Feedback', 'wporg' );
     258
     259        if ( $content ) {
     260            $title       = __( 'Edit feedback', 'wporg' );
     261            $form_type   = '-edit';
     262            $button_text = __( 'Edit Feedback', 'wporg' );
     263        }
     264
     265        $allowed_tags = '';
     266        foreach ( array( '<strong>', '<em>', '<code>', '<a>' ) as $tag ) {
     267            $allowed_tags .= '<code>' . htmlentities( $tag ) . '</code>, ';
     268        }
     269
     270        ob_start();
     271        echo "<div id='feedback-editor-{$comment_id}' class='feedback-editor'{$display}>\n";
     272        echo "<p class='feedback-editor-title'>{$title}</p>\n";
     273        echo '<form id="feedback-form-' . $instance . $form_type . '" class="feedback-form" method="post" action="' . site_url( '/wp-comments-post.php' ) . '" name="feedback-form-' . $instance ."\">\n";
     274
     275        wp_editor( '', 'feedback-' . $instance, array(
     276            'media_buttons' => false,
     277            'textarea_name' => 'comment',
     278            'textarea_rows' => 3,
     279            'quicktags'     => array(
     280                'buttons' => 'strong,em'
     281            ),
     282            'teeny'         => true,
     283            'tinymce'       => false,
     284        ) );
     285
     286        echo '<p><strong>' . __( 'Note', 'wporg' ) . '</strong>: ' . __( 'No newlines allowed', 'wporg' ) . '. ';
     287        printf( __( 'Allowed tags: %s', 'wporg' ), trim( $allowed_tags, ', ' ) ) . "</p>\n";
     288        echo "<p><input id='submit-{$instance}' class='submit' type='submit' value='Add Feedback' name='submit-{$instance}'>\n";
     289        echo "<input type='hidden' name='comment_post_ID' value='" . get_the_ID() . "' id='comment_post_ID-{$instance}' />\n";
     290        echo "<input type='hidden' name='comment_parent' id='comment_parent-{$instance}' value='{$comment_id}' />\n";
     291        echo "</p>\n</form>\n</div><!-- #feedback-editor-{$comment_id} -->\n";
     292        return ob_get_clean();
     293    }
     294
    157295} // DevHub_User_Submitted_Content
    158296
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes.js

    r5240 r6910  
    1414    function showCommentForm() {
    1515        $( '#respond' ).show();
    16         $( '#add-user-note').hide();
     16        $( '#add-user-note' ).hide();
    1717
    18         var target = $( '#commentform' );
     18        var wpAdminBar = $( '#page.admin-bar' ).length ? 32 : 0;
     19        var target     = $( '#commentform #add-note-or-feedback' );
    1920        if ( target.length ) {
    2021            var pos = target.offset();
    2122
    2223            $( 'html,body' ).animate( {
    23                 scrollTop: pos.top
     24                scrollTop: pos.top - wpAdminBar
    2425            }, 1000 );
    2526
     
    4041
    4142    // Add php and js buttons to QuickTags.
    42     QTags.addButton( 'php', 'php', '[php]', '[/php]' );
    43     QTags.addButton( 'js', 'js', '[js]', '[/js]' );
    44     QTags.addButton( 'inline-code', 'inline code', '<code>', '</code>' );
     43    QTags.addButton( 'php', 'php', '[php]', '[/php]', '', '', '', 'comment' );
     44    QTags.addButton( 'js', 'js', '[js]', '[/js]', '', '', '', 'comment' );
     45    QTags.addButton( 'inline-code', 'inline code', '<code>', '</code>', '', '', '', 'comment' );
    4546
    4647    // Override tab within user notes textarea to actually insert a tab character.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r6825 r6910  
    11381138        }
    11391139
     1140        .comment-awaiting-moderation {
     1141            background-color: #fff8e5;
     1142            padding: .2em .5em;
     1143            border-radius: 3px;
     1144            border: 1px solid #ffb900;
     1145        }
     1146
     1147        .depth-2 .comment-awaiting-moderation {
     1148            display: inline-block;
     1149            margin: 2px 0;
     1150        }
     1151
    11401152        .comment-list,
    11411153        .comment-list ol {
     
    11471159        .comment-list li,
    11481160        #comment-preview {
    1149             margin-top: 2.5rem;
     1161            margin-top: 3rem;
    11501162            background: #fff;
    11511163            overflow: auto;
    1152             border: 1px solid #dfdfdf;
    1153             border-radius: 0 2px 2px 2px;
    11541164
    11551165            article {
    11561166                overflow: auto;
    11571167            }
     1168        }
     1169
     1170        .comment-list li.depth-1,
     1171        #comment-preview {
     1172            border: 1px solid #dfdfdf;
     1173            border-radius: 2px;
     1174        }
     1175
     1176        // Feedback
     1177        .comment-list li.depth-2 {
     1178            border-top: 1px solid #dfdfdf;
     1179            padding: 0;
     1180            margin: 0;
     1181
     1182            .comment-content {
     1183                padding: .9em 0;
     1184            }
     1185            .comment-content p {
     1186                margin-bottom: 0;
     1187                font-size: .9em;
     1188            }
     1189        }
     1190
     1191        .comment ul.children {
     1192            margin: 0 0 1.5em 0;
     1193            border-bottom: 1px solid #dfdfdf;
     1194        }
     1195
     1196        .feedback {
     1197            width: 90%;
     1198            float: right;
     1199            margin-right: 1.5rem;
     1200        }
     1201
     1202        .feedback-links {
     1203            margin: 0 1.5rem 1em 1.5rem;
     1204            font-size: 0.9em;
     1205            clear: both;
     1206        }
     1207
     1208        .feedback-editor-title,
     1209        .feedback-title {
     1210            font-size: 1.8rem;
     1211            font-weight: 300;
     1212            line-height: 2.2rem;
     1213            margin-bottom: 1em;
     1214        }
     1215
     1216        .feedback-toggle {
     1217            margin: 0 0 0 1.5rem;
     1218            display: inline-block;
     1219        }
     1220
     1221        #wp-feedback-wrap {
     1222            padding-bottom: 1em;
    11581223        }
    11591224
     
    11631228            border: 1px solid #ccc;
    11641229            border-radius: 0 3px 3px 3px;
    1165             clear:both;
     1230            clear: both;
    11661231        }
    11671232
     
    12241289            clear: both;
    12251290            padding: 2rem 1.5rem .5rem;
    1226         }
    1227 
    1228         .comment-footer {
    1229             margin: 0 1em;
    1230             padding: 0 0 1em 0;
    1231             position: relative;
    1232             overflow: auto;
    1233 
    1234             a {
    1235                 float: right;
    1236             }
    1237 
    1238             p {
    1239                 margin-bottom: 0;
    1240             }
    12411291        }
    12421292
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r6825 r6910  
    15151515}
    15161516
     1517.devhub-wrap .single-wp-parser-function .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-method .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-hook .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-class .comment-awaiting-moderation {
     1518  background-color: #fff8e5;
     1519  padding: .2em .5em;
     1520  border-radius: 3px;
     1521  border: 1px solid #ffb900;
     1522}
     1523
     1524.devhub-wrap .single-wp-parser-function .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-method .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-hook .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-class .depth-2 .comment-awaiting-moderation {
     1525  display: inline-block;
     1526  margin: 2px 0;
     1527}
     1528
    15171529.devhub-wrap .single-wp-parser-function .comment-list,
    15181530.devhub-wrap .single-wp-parser-function .comment-list ol, .devhub-wrap .single-wp-parser-method .comment-list,
     
    15301542.devhub-wrap .single-wp-parser-hook #comment-preview, .devhub-wrap .single-wp-parser-class .comment-list li,
    15311543.devhub-wrap .single-wp-parser-class #comment-preview {
    1532   margin-top: 2.5rem;
     1544  margin-top: 3rem;
    15331545  background: #fff;
    15341546  overflow: auto;
    1535   border: 1px solid #dfdfdf;
    1536   border-radius: 0 2px 2px 2px;
    15371547}
    15381548
     
    15431553.devhub-wrap .single-wp-parser-class #comment-preview article {
    15441554  overflow: auto;
     1555}
     1556
     1557.devhub-wrap .single-wp-parser-function .comment-list li.depth-1,
     1558.devhub-wrap .single-wp-parser-function #comment-preview, .devhub-wrap .single-wp-parser-method .comment-list li.depth-1,
     1559.devhub-wrap .single-wp-parser-method #comment-preview, .devhub-wrap .single-wp-parser-hook .comment-list li.depth-1,
     1560.devhub-wrap .single-wp-parser-hook #comment-preview, .devhub-wrap .single-wp-parser-class .comment-list li.depth-1,
     1561.devhub-wrap .single-wp-parser-class #comment-preview {
     1562  border: 1px solid #dfdfdf;
     1563  border-radius: 2px;
     1564}
     1565
     1566.devhub-wrap .single-wp-parser-function .comment-list li.depth-2, .devhub-wrap .single-wp-parser-method .comment-list li.depth-2, .devhub-wrap .single-wp-parser-hook .comment-list li.depth-2, .devhub-wrap .single-wp-parser-class .comment-list li.depth-2 {
     1567  border-top: 1px solid #dfdfdf;
     1568  padding: 0;
     1569  margin: 0;
     1570}
     1571
     1572.devhub-wrap .single-wp-parser-function .comment-list li.depth-2 .comment-content, .devhub-wrap .single-wp-parser-method .comment-list li.depth-2 .comment-content, .devhub-wrap .single-wp-parser-hook .comment-list li.depth-2 .comment-content, .devhub-wrap .single-wp-parser-class .comment-list li.depth-2 .comment-content {
     1573  padding: .9em 0;
     1574}
     1575
     1576.devhub-wrap .single-wp-parser-function .comment-list li.depth-2 .comment-content p, .devhub-wrap .single-wp-parser-method .comment-list li.depth-2 .comment-content p, .devhub-wrap .single-wp-parser-hook .comment-list li.depth-2 .comment-content p, .devhub-wrap .single-wp-parser-class .comment-list li.depth-2 .comment-content p {
     1577  margin-bottom: 0;
     1578  font-size: .9em;
     1579}
     1580
     1581.devhub-wrap .single-wp-parser-function .comment ul.children, .devhub-wrap .single-wp-parser-method .comment ul.children, .devhub-wrap .single-wp-parser-hook .comment ul.children, .devhub-wrap .single-wp-parser-class .comment ul.children {
     1582  margin: 0 0 1.5em 0;
     1583  border-bottom: 1px solid #dfdfdf;
     1584}
     1585
     1586.devhub-wrap .single-wp-parser-function .feedback, .devhub-wrap .single-wp-parser-method .feedback, .devhub-wrap .single-wp-parser-hook .feedback, .devhub-wrap .single-wp-parser-class .feedback {
     1587  width: 90%;
     1588  float: right;
     1589  margin-right: 1.5rem;
     1590}
     1591
     1592.devhub-wrap .single-wp-parser-function .feedback-links, .devhub-wrap .single-wp-parser-method .feedback-links, .devhub-wrap .single-wp-parser-hook .feedback-links, .devhub-wrap .single-wp-parser-class .feedback-links {
     1593  margin: 0 1.5rem 1em 1.5rem;
     1594  font-size: 0.9em;
     1595  clear: both;
     1596}
     1597
     1598.devhub-wrap .single-wp-parser-function .feedback-editor-title,
     1599.devhub-wrap .single-wp-parser-function .feedback-title, .devhub-wrap .single-wp-parser-method .feedback-editor-title,
     1600.devhub-wrap .single-wp-parser-method .feedback-title, .devhub-wrap .single-wp-parser-hook .feedback-editor-title,
     1601.devhub-wrap .single-wp-parser-hook .feedback-title, .devhub-wrap .single-wp-parser-class .feedback-editor-title,
     1602.devhub-wrap .single-wp-parser-class .feedback-title {
     1603  font-size: 1.8rem;
     1604  font-weight: 300;
     1605  line-height: 2.2rem;
     1606  margin-bottom: 1em;
     1607}
     1608
     1609.devhub-wrap .single-wp-parser-function .feedback-toggle, .devhub-wrap .single-wp-parser-method .feedback-toggle, .devhub-wrap .single-wp-parser-hook .feedback-toggle, .devhub-wrap .single-wp-parser-class .feedback-toggle {
     1610  margin: 0 0 0 1.5rem;
     1611  display: inline-block;
     1612}
     1613
     1614.devhub-wrap .single-wp-parser-function #wp-feedback-wrap, .devhub-wrap .single-wp-parser-method #wp-feedback-wrap, .devhub-wrap .single-wp-parser-hook #wp-feedback-wrap, .devhub-wrap .single-wp-parser-class #wp-feedback-wrap {
     1615  padding-bottom: 1em;
    15451616}
    15461617
     
    16071678  clear: both;
    16081679  padding: 2rem 1.5rem .5rem;
    1609 }
    1610 
    1611 .devhub-wrap .single-wp-parser-function .comment-footer, .devhub-wrap .single-wp-parser-method .comment-footer, .devhub-wrap .single-wp-parser-hook .comment-footer, .devhub-wrap .single-wp-parser-class .comment-footer {
    1612   margin: 0 1em;
    1613   padding: 0 0 1em 0;
    1614   position: relative;
    1615   overflow: auto;
    1616 }
    1617 
    1618 .devhub-wrap .single-wp-parser-function .comment-footer a, .devhub-wrap .single-wp-parser-method .comment-footer a, .devhub-wrap .single-wp-parser-hook .comment-footer a, .devhub-wrap .single-wp-parser-class .comment-footer a {
    1619   float: right;
    1620 }
    1621 
    1622 .devhub-wrap .single-wp-parser-function .comment-footer p, .devhub-wrap .single-wp-parser-method .comment-footer p, .devhub-wrap .single-wp-parser-hook .comment-footer p, .devhub-wrap .single-wp-parser-class .comment-footer p {
    1623   margin-bottom: 0;
    16241680}
    16251681
Note: See TracChangeset for help on using the changeset viewer.