Ticket #1504: 1504.1.patch
File 1504.1.patch, 41.4 KB (added by , 9 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments.php
32 32 <?php endif; // check for comment navigation ?> 33 33 34 34 <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. 38 39 * 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. 41 42 */ 42 43 if ( is_singular( 'post' ) ) { 43 44 wp_list_comments(); 44 45 } else { 45 46 $ordered_comments = wporg_developer_get_ordered_notes(); 46 47 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) ); 48 50 } 49 51 } 50 52 ?> … … 62 64 63 65 <?php if ( \DevHub\is_parsed_post_type() && DevHub\can_user_post_note( true, get_the_ID() ) ) : ?> 64 66 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 68 $add_note_style = !empty( $feedback_editor ) ? '' : 'display:none;'; ?> 69 <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> 66 70 67 <?php comment_form( array( 68 'class_form' => 'comment-form tab-container', 69 'comment_field' => DevHub_User_Submitted_Content::wp_editor_comments(), 70 'comment_notes_after' => DevHub_Note_Preview::comment_preview() . 71 '<p>' . 71 <?php 72 $args = array( 73 'comment_notes_after' => '<p>' . 72 74 __( 'Notes should supplement code reference entries, for example examples, tips, explanations, use-cases, and best practices.', 'wporg' ) . 73 75 '</p><p>' . 74 76 __( 'Feedback can be to report errors or omissions with the documentation on this page. Such feedback will not be publicly posted.', 'wporg' ) . … … 82 84 sprintf( __( '<strong>NOTE:</strong> All contributions are licensed under <a href="%s">GFDL</a> and are moderated before appearing on the site.', 'wporg' ), 'https://gnu.org/licenses/fdl.html' ) . 83 85 '</p>', 84 86 'label_submit' => __( 'Add Note or Feedback', 'wporg' ), 87 'cancel_reply_link' => '', 85 88 'must_log_in' => '<p>' . sprintf( 86 89 __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ), 87 90 'https://wordpress.org/support/bb-login.php?redirect_to=' . urlencode( get_comments_link() ) 88 91 ) . '</p>', 89 'title_reply' => '', //'Add Example' 90 ) ); ?> 92 'title_reply' => '', //'Add Example' 93 'title_reply_to' => '', 94 ); 95 96 if ( class_exists( 'DevHub_Note_Preview' ) ) { 97 $args['comment_notes_after'] = DevHub_Note_Preview::comment_preview() . $args['comment_notes_after']; 98 $args['class_form'] = 'comment-form tab-container'; 99 } 91 100 101 if( class_exists( 'DevHub_User_Submitted_Content') ) { 102 $args['comment_field'] = DevHub_User_Submitted_Content::wp_editor_comments(); 103 } 104 105 // Insert comment form if feedback form is not already used 106 if( empty( $feedback_editor ) ) { 107 comment_form( $args ); 108 } 109 ?> 92 110 <?php endif; ?> 93 111 94 112 <?php if ( ! \DevHub\is_parsed_post_type() && comments_open() ) : ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
75 75 if ( ! function_exists( 'wporg_developer_get_ordered_notes' ) ) : 76 76 /** 77 77 * Get contibuted notes ordered by vote 78 *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.82 78 * 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. 83 * 83 84 * @param integer $post_id Optional. Post id to get comments for 84 85 * @param array $args Arguments used for get_comments(). 85 86 * @return array Array with comment objects … … 92 93 $post_id = get_the_ID(); 93 94 } 94 95 95 $order = array();96 96 $defaults = array( 97 97 'post__in' => array( $post_id ), 98 98 'type' => 'comment', 99 99 'status' => 'approve', 100 100 'include_unapproved' => array_filter( array( get_current_user_id() ) ), 101 'parent' => false,102 101 ); 103 102 104 103 if ( is_super_admin() ) { 105 104 $defaults['status'] = 'all'; 106 105 } 107 106 108 $args = wp_parse_args( $args, $defaults ); 107 $args = wp_parse_args( $args, $defaults ); 108 $comments = get_comments( $args ); 109 109 110 $comments = get_comments( $args );111 112 110 if ( ! $comments ) { 113 111 return; 114 112 } 115 113 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 116 124 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 } 118 132 } 119 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 142 if ( array_key_exists( $comment->comment_ID, $children ) ) { 143 $comments[ $key ]->child_notes = array_reverse( $children[ $comment->comment_ID ] ); 144 } 145 146 if ( !$show_editor && ( $reply_id && ( $reply_id === (int) $comment->comment_ID ) ) ) { 147 // Show the editor when replying to this parent comment 148 $comments[ $key ]->show_editor = true; 149 $show_editor = true; 150 } 151 } 152 120 153 // sort the posts by votes 121 154 array_multisort( $order, SORT_DESC, $comments ); 122 155 … … 124 157 } 125 158 endif; 126 159 160 if ( !function_exists( 'wporg_developer_list_notes' ) ) : 161 /** 162 * List user contributed notes. 163 * 164 * @param array $comments Array with comment objects. 165 * @param array $args Comment display arguments. 166 * @return void 167 */ 168 function wporg_developer_list_notes( $comments, $args ) { 169 $is_user_logged_in = is_user_logged_in(); 170 $can_user_post_note = DevHub\can_user_post_note( true, get_the_ID() ); 171 $user_content = class_exists( 'DevHub_User_Submitted_Content' ); 172 $display_editor = $is_user_logged_in && $can_user_post_note && $user_content; 173 174 foreach ( $comments as $comment ) { 175 176 $comment_id = $comment->comment_ID; 177 178 // Display parent comment. 179 wporg_developer_user_note( $comment, $args, 1 ); 180 181 // Show or hide feedback notes. 182 $class = $comment->show_editor ? '' : ' hide-if-js'; 183 echo "<section id='feedback-{$comment_id}' class='feedback{$class}'>\n"; 184 185 // Display child comments. 186 if ( !empty( $comment->child_notes ) ) { 187 188 echo "<h4 class='feedback-title'>Feedback</h4>\n"; 189 echo "<ul class='children'>\n"; 190 foreach ( $comment->child_notes as $child_note ) { 191 wporg_developer_user_note( $child_note, $args, 2, $comment->show_editor ); 192 } 193 echo "</ul>\n"; 194 } 195 196 // Add a feedback form for logged in users. 197 if ( $display_editor ) { 198 // Show or hide the editor depending if we're replying to a note. 199 $display = $comment->show_editor ? 'show' : 'hide'; 200 echo DevHub_User_Submitted_Content::wp_editor_feedback( $comment, $display ); 201 } 202 echo "</section><!-- .feedback -->\n"; 203 204 // Feedback links to log in, add feedback or show feedback. 205 echo "<footer class='feedback-links' >\n"; 206 if ( $can_user_post_note ) { 207 $feedback_link = trailingslashit( get_permalink() ) . "?replytocom={$comment_id}#feedback-editor-{$comment_id}"; 208 $display = ''; 209 $aria = ''; 210 if ( !$is_user_logged_in ) { 211 $class = 'login'; 212 $feedback_text = __( 'Log in to add feedback', 'wporg' ); 213 $feedback_link = 'https://wordpress.org/support/bb-login.php?redirect_to=' . urlencode( $feedback_link ); 214 } else { 215 $class ='add'; 216 $feedback_text = __( 'Add feedback to this note', 'wporg' ); 217 $aria = " aria-expanded='false' aria_controls='feedback-editor-{$comment_id}' aria-label='" . esc_attr( $feedback_text ) . "'"; 218 219 // Hide 'add feedback' link if editor is displayed. 220 $display = $display_editor && $comment->show_editor ? ' style="display:none"' : ''; 221 } 222 echo '<a class="feedback-' . $class . '" href="' . esc_url( $feedback_link ) . '"' . $display . $aria .' rel="nofollow">' . $feedback_text . '</a>'; 223 } 224 225 // close parent list item 226 echo "</footer>\n</article><!-- .comment-body -->\n</li>\n"; 227 } 228 } 229 endif; 230 127 231 if ( ! function_exists( 'wporg_developer_user_note' ) ) : 128 232 /** 129 233 * Template for user contributed notes. 234 * 235 * @param object $comment Comment object. 236 * @param array $args Arguments. 237 * @param int $depth Nested comment depth. 238 * @return void 130 239 */ 131 240 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 ); 241 $GLOBALS['comment'] = $comment; 242 $GLOBALS['comment_depth'] = $depth; 135 243 244 $approved = ( 0 < (int) $comment->comment_approved ) ? true : false; 245 $is_parent = ( 0 === (int) $comment->comment_parent ) ? true : false; 246 $is_voting = class_exists( 'DevHub_User_Contributed_Notes_Voting' ); 247 $count = $is_voting ? (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' ) : 0; 248 $curr_user_note = $is_voting ? (bool) DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID ) : false; 249 250 // Classes 136 251 $comment_class = array(); 252 137 253 if ( -1 > $count ) { 138 254 $comment_class[] = 'bad-note'; 139 255 } 256 140 257 if ( $curr_user_note ) { 141 258 $comment_class[] = 'user-submitted-note'; 142 259 } 260 261 if ( !$approved ) { 262 $comment_class[] = 'user-note-moderated'; 263 } 264 265 // This would all be moot if core passed the $comment context for 'get_comment_author_link' filter 266 if ( $comment->user_id ) { 267 $commenter = get_user_by( 'id', $comment->user_id ); 268 $url = 'https://profiles.wordpress.org/' . esc_attr( $commenter->user_nicename ) . '/'; 269 $author = get_the_author_meta( 'display_name', $comment->user_id ); 270 } else { 271 $url = $comment->comment_author_url; 272 $author = $comment->comment_author; 273 } 274 275 $comment_author_link = $author; 276 if ( $url ) { 277 $comment_author_link = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; 278 } 279 280 $date = sprintf( _x( '%1$s ago', '%1$s = human-readable time difference', 'wporg' ), 281 human_time_diff( get_comment_time( 'U' ), 282 current_time( 'timestamp' ) ) 283 ); 143 284 ?> 285 <li id="comment-<?php comment_ID(); ?>" data-comment-id="<?php echo $comment->comment_ID; ?>" <?php comment_class( implode( ' ', $comment_class ) ); ?>> 286 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 144 287 145 <li id="comment-<?php comment_ID(); ?>" <?php comment_class( implode( ' ', $comment_class ) ); ?>> 146 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 147 <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php _e( 'Skip to note content', 'wporg' ); ?></a> 288 <?php if ( $is_parent ) : ?> 289 <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php _e( 'Skip to note content', 'wporg' ); ?></a> 148 290 <header class="comment-meta"> 149 <?php DevHub_User_Contributed_Notes_Voting::show_voting(); ?> 291 292 <?php 293 if ( $is_voting ) { 294 DevHub_User_Contributed_Notes_Voting::show_voting(); 295 } 296 ?> 150 297 <div class="comment-author vcard"> 151 298 <span class="comment-author-attribution"> 152 <?php if ( 0 != $args['avatar_size'] ) {153 echo get_avatar( $comment, $args['avatar_size'] );154 } ?>155 156 299 <?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 } 300 if ( 0 != $args['avatar_size'] ) { 301 echo get_avatar( $comment, $args['avatar_size'] ); 302 } 166 303 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 ) ); 304 printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) ); 177 305 ?> 178 306 179 307 </span> 180 308 — 181 309 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 182 310 <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 ?> 311 <?php echo $date; ?> 189 312 </time> 190 313 </a> 191 <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">— ', '</span>' ); ?> 314 <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">— ', '</span> ' ); ?> 315 <?php if ( !$approved ) : ?> 316 — <span class="comment-awaiting-moderation"><?php _e( 'awaiting moderation', 'wporg' ); ?></span> 317 <?php endif; ?> 318 192 319 </div> 193 320 </header> 194 321 <!-- .comment-metadata --> 322 <?php endif; ?> 195 323 196 324 <div class="comment-content" id="comment-content-<?php echo $comment->comment_ID; ?>"> 197 <?php comment_text(); ?> 198 </div> 199 <!-- .comment-content --> 325 <?php 326 if ( $is_parent ) { 327 comment_text(); 328 } else { 200 329 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; ?> 330 $text = get_comment_text() . ' — '; 331 $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) ) . ' — '; 332 $text .= ' <a href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; 333 $text .= '<time datetime="' . get_comment_time( 'c' ) . '">' . $date . '</time></a>'; 207 334 208 <?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 ) ) ); 335 if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) { 336 $text .= ' — <a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) .'">'; 337 $text .= __( 'Edit', 'wporg' ) . '</a>'; 338 } 339 340 if ( !$approved ) { 341 $text .= ' — <span class="comment-awaiting-moderation">' . __( 'awaiting moderation', 'wporg' ) . '</span>'; 342 } 343 344 echo apply_filters( 'comment_text', $text ); 345 } 216 346 ?> 217 </article><!-- .comment-body --> 218 <?php 347 </div><!-- .comment-content --> 348 349 <?php if ( !$is_parent ) : ?> 350 </article> 351 </li> 352 <?php endif; ?> 353 <?php 219 354 } 220 355 endif; // ends check for wporg_developer_user_note() 221 356 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php
40 40 // Remove reply to link 41 41 add_filter( 'comment_reply_link', '__return_empty_string' ); 42 42 43 // Remove cancel reply link 44 add_filter( 'cancel_comment_reply_link', '__return_empty_string' ); 45 43 46 // Disable smilie conversion 44 47 remove_filter( 'comment_text', 'convert_smilies', 20 ); 45 48 … … 58 61 // Tweak code contained in shortcode 59 62 add_filter( 'syntaxhighlighter_precode', array( __CLASS__, 'syntaxhighlighter_precode' ) ); 60 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' ) ); 69 61 70 } 62 71 63 72 /** … … 79 88 } 80 89 81 90 /** 91 * Updates edited child comments with allowed HTML. 92 * Allowed html is <strong>, <em>, <code> and <a>. 93 * 94 * @param int $comment_ID Comment ID. 95 */ 96 public static function comment_edit_allowed_html( $comment_ID ) { 97 98 // Get the edited comment. 99 $comment = get_comment( $comment_ID, ARRAY_A ); 100 if ( empty( $comment ) ) { 101 return; 102 } 103 104 if ( ( 0 === (int) $comment['comment_parent'] ) || empty( $comment['comment_content'] ) ) { 105 return; 106 } 107 108 $content = $comment['comment_content']; 109 $data = self::comment_new_allowed_html( $comment ); 110 111 if ( $data['comment_content'] !== $content ) { 112 $commentarr = array( 113 'comment_ID' => $data['comment_ID'], 114 'comment_content' => $data['comment_content'] 115 ); 116 117 // Update comment content. 118 wp_update_comment( $commentarr ); 119 } 120 } 121 122 /** 123 * Filter new child comments content with allowed HTML. 124 * Allowed html is <strong>, <em>, <code> and <a>. 125 * 126 * @param array $commentdata Array with comment data. 127 * @return array Array with filtered comment data. 128 */ 129 public static function comment_new_allowed_html( $commentdata ) { 130 $comment_parent = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0; 131 $comment_content = isset( $commentdata['comment_content'] ) ? trim( $commentdata['comment_content'] ) : ''; 132 133 if ( ( $comment_parent === 0 ) || !$comment_content ) { 134 return $commentdata; 135 } 136 137 $allowed_html = array( 138 'a' => array( 139 'href' => true, 140 'rel' => true, 141 'target' => true, 142 ), 143 'em' => array(), 144 'strong' => array(), 145 'code' => array(), 146 ); 147 148 $allowed_protocols = array( 'http', 'https' ); 149 150 $comment_content = wp_kses( $comment_content, $allowed_html, $allowed_protocols ); 151 $commentdata['comment_content'] = preg_replace( '/\r?\n|\r/', '', $comment_content ); 152 153 return $commentdata; 154 } 155 156 /** 82 157 * Enqueues scripts and styles. 83 158 */ 84 159 public static function scripts_and_styles() { … … 87 162 wp_enqueue_style( 'syntaxhighlighter-core' ); 88 163 wp_enqueue_style( 'syntaxhighlighter-theme-default' ); 89 164 90 wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'quicktags' ), '20160824', true ); 91 if ( get_option( 'thread_comments' ) ) { 92 wp_enqueue_script( 'comment-reply' ); 93 } 165 wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'jquery', 'quicktags' ), '20160809', true ); 166 wp_enqueue_script( 'wporg-developer-user-notes-feedback', get_template_directory_uri() . '/js/user-notes-feedback.js', array( 'jquery', 'quicktags' ), '20160809', true ); 167 wp_localize_script( 'wporg-developer-user-notes-feedback', 'wporg_note_feedback', array( 168 'show' => __( 'Show Feedback', 'wporg' ), 169 'hide' => __( 'Hide Feedback', 'wporg' ), 170 ) ); 94 171 } 95 172 } 96 173 … … 154 231 return ob_get_clean(); 155 232 } 156 233 234 /** 235 * Capture an {@see wp_editor()} instance as the 'User Contributed Notes' feedback form. 236 * 237 * Uses output buffering to capture the editor instance. 238 * 239 * @return string HTML output for the wp_editor-ized feedback form. 240 */ 241 public static function wp_editor_feedback( $comment, $display = 'show', $content = '' ) { 242 243 if ( !( isset( $comment->comment_ID ) && absint( $comment->comment_ID ) ) ) { 244 return ''; 245 } 246 247 $comment_id = absint( $comment->comment_ID ); 248 249 static $instance = 0; 250 $instance++; 251 252 $display = ( 'hide' === $display ) ? ' style="display: none;"' : ''; 253 $title = __( 'Add feedback to this note', 'wporg' ); 254 $form_type = ''; 255 $button_text = __( 'Add Feedback', 'wporg' ); 256 257 if ( !empty( $content ) ) { 258 $title = __( 'Edit feedback', 'wporg' ); 259 $form_type = '-edit'; 260 $button_text = __( 'Edit Feedback', 'wporg' ); 261 } 262 263 $allowed_tags = ''; 264 foreach ( array( '<strong>', '<em>', '<code>', '<a>' ) as $tag ) { 265 $allowed_tags .= '<code>' . htmlentities( $tag ) . '</code>, '; 266 } 267 268 ob_start(); 269 echo "<div id='feedback-editor-{$comment_id}' class='feedback-editor'{$display}>\n"; 270 echo "<p class='feedback-editor-title'>{$title}</p>\n"; 271 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"; 272 273 wp_editor( '', 'feedback-' . $instance, array( 274 'media_buttons' => false, 275 'textarea_name' => 'comment', 276 'textarea_rows' => 3, 277 'quicktags' => array( 278 'buttons' => 'strong,em' 279 ), 280 'teeny' => true, 281 'tinymce' => false, 282 ) ); 283 284 echo '<p><strong>' . __( 'Note', 'wporg' ) . '</strong>: ' . __( 'No newlines allowed', 'wporg' ) . '. '; 285 printf( __( 'Allowed tags: %s', 'wporg' ), trim( $allowed_tags, ', ' ) ) . "</p>\n"; 286 echo "<p><input id='submit-{$instance}' class='submit' type='submit' value='Add Feedback' name='submit-{$instance}'>\n"; 287 echo "<input type='hidden' name='comment_post_ID' value='" . get_the_ID() . "' id='comment_post_ID-{$instance}' />\n"; 288 echo "<input type='hidden' name='comment_parent' id='comment_parent-{$instance}' value='{$comment_id}' />\n"; 289 echo "</p>\n</form>\n</div><!-- #feedback-editor-{$comment_id} -->\n"; 290 return ob_get_clean(); 291 } 292 157 293 } // DevHub_User_Submitted_Content 158 294 159 295 DevHub_User_Submitted_Content::init(); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-feedback.js
1 ( function( $ ) { 2 3 if ( undefined === wporg_note_feedback ) { 4 return; 5 } 6 7 var options = wporg_note_feedback; 8 var wpAdminBar = $('#page.admin-bar').length ? 32 : 0; 9 var feedbackToggle = $( '<a class="feedback-toggle" href="#">' + options.show + '</a>' ); 10 var hash = window.location.hash; 11 12 // Check if the fragment identifier is a comment ID (e.g. #comment-63) 13 if ( !hash.match( /#comment\-[0-9]+$/ ) ) { 14 hash = ''; 15 } 16 17 $( '.feedback-editor' ).each( function() { 18 19 // Hide hidden editor with 'hide-if-js' class. 20 if( 'none' === $(this).css('display') ) { 21 $( this ).show().addClass( 'hide-if-js' ); 22 } 23 24 // Add quicktag 'inline code' button to editor. 25 var id = $( this ).find( 'textarea' ).attr( 'id' ); 26 if ( id.length ) { 27 QTags.addButton( 'inline-code', 'inline code', '<code>', '</code>', '', '', '', id ); 28 } 29 } ); 30 31 // Loop through feedback notes 32 $( '.comment' ).each( function() { 33 var feedbackLinks = $( this ).find( '.feedback-links' ); 34 var childComments = $( this ).find( 'ul.children' ); 35 36 if ( childComments.length && feedbackLinks.length ) { 37 var feedback = $( this ).find( '.feedback' ); 38 var toggle = feedbackToggle.clone(); 39 40 toggle.attr( { 41 'aria-expanded': 'false', 42 'aria-controls': 'feedback-' + getCommentID( $(this) ) 43 } ); 44 45 // Set text to 'Hide Feedback' if feedback is displayed 46 if ( !feedback.hasClass( 'hide-if-js' ) ) { 47 toggle.text( options.hide ); 48 } 49 50 feedbackLinks.find( '.feedback-add' ).show(); 51 feedbackLinks.append( toggle ); 52 } 53 54 if ( feedbackLinks.length ) { 55 // Move feedback links before feedback. 56 clonedElements = $( '<div class="feedback-links"></div>' ).append( feedbackLinks.clone().children() ); 57 58 $( this ).find( '.feedback' ).first().before( clonedElements ); 59 feedbackLinks.addClass( 'bottom hide-if-js' ); 60 } 61 } ); 62 63 // Returns comment ID from data attribute. 64 function getCommentID( el ) { 65 return $(el).is("[data-comment-id") ? el.data( 'comment-id' ) : 0; 66 } 67 68 // Removes added elements 69 function resetComment( el ) { 70 71 var children = el.find( 'ul.children' ); 72 if ( !children.length ) { 73 el.find( '.feedback-toggle' ).remove(); 74 } 75 76 el.find( '.feedback-links.bottom' ).addClass( 'hide-if-js' ); 77 } 78 79 // Show hidden child comments if the fragment identifier is a comment ID (e.g. #comment-63). 80 $( document ).ready( function() { 81 82 var childComments = $( '.comment' ).find( 'ul.children' ); 83 84 if ( !( hash.length && childComments.length ) ) { 85 return; 86 } 87 88 var hashComment = childComments.find( hash ).first(); 89 if ( hashComment.length ) { 90 // Child comment exists. 91 92 var parent = hashComment.closest( '.comment.depth-1' ); 93 if ( parent.find( '.feedback' ).hasClass( 'hide-if-js' ) ) { 94 // Show child comments. 95 parent.find( '.feedback-toggle' ).first().trigger( 'click' ); 96 } 97 98 // Scroll to the child comment. 99 var pos = hashComment.offset(); 100 $( 'html,body' ).animate( { 101 scrollTop: pos.top - wpAdminBar 102 }, 1 ); 103 } 104 } ); 105 106 // Show/Hide feedback toggle link. 107 $( document ).on( 'click', '.feedback-toggle', function( e ) { 108 e.preventDefault(); 109 110 var parent = $( this ).closest( '.comment.depth-1' ); 111 if ( !parent.length ) { 112 return; 113 } 114 115 resetComment( parent ); 116 var feedback = parent.find( '.feedback' ); 117 var toggleLinks = parent.find( '.feedback-toggle' ); 118 119 if ( feedback.hasClass( 'hide-if-js' ) ) { 120 // Feedback is hidden. 121 122 // Show feedback. 123 toggleLinks.text( options.hide ); 124 feedback.removeClass( 'hide-if-js' ); 125 toggleLinks.attr( 'aria-expanded', 'true' ); 126 127 // Go to the clicked feedback toggle link. 128 var pos = $( this ).offset(); 129 $( 'html,body' ).animate( { 130 scrollTop: pos.top - wpAdminBar 131 }, 1000 ); 132 133 // Add feedback links at the bottom if there are over 3 feedback notes. 134 var children = parent.find( 'ul.children > li' ); 135 if ( 3 < children.length ) { 136 var feedbackLinks = parent.find( '.feedback-links.bottom' ); 137 feedbackLinks.removeClass( 'hide-if-js' ); 138 } 139 140 } else { 141 // Hide feedback. 142 toggleLinks.text( options.show ); 143 feedback.addClass( 'hide-if-js' ); 144 toggleLinks.attr( 'aria-expanded', 'false' ); 145 146 // Hide editor. 147 var editor = feedback.find( '.feedback-editor' ); 148 editor.addClass( 'hide-if-js' ); 149 150 parent.find( '.feedback-add' ).attr( 'aria-expanded', 'false' ); 151 } 152 } ); 153 154 // Show editor when the add feedback link is clicked. 155 $( document ).on( 'click', '.feedback-add', function( e ) { 156 e.preventDefault(); 157 158 var parent = $( this ).closest( '.comment.depth-1' ); 159 if ( !parent.length ) { 160 return; 161 } 162 163 resetComment( parent ); 164 165 var feedback = parent.find( '.feedback' ); 166 var children = parent.find( 'ul.children' ); 167 var feedbackLinks = parent.find( '.feedback-add' ); 168 169 // Show feedback. 170 feedback.removeClass( 'hide-if-js' ); 171 feedbackLinks.attr( 'aria-expanded', 'true' ); 172 173 // Show the feedback editor. 174 var editor = feedback.find( '.feedback-editor' ); 175 editor.removeClass( 'hide-if-js' ); 176 177 // Change the toggle link text to 'Hide Feedback'. 178 var toggleLinks = parent.find( '.feedback-toggle' ); 179 if ( toggleLinks.length ) { 180 toggleLinks.attr( 'aria-expanded', 'true' ); 181 toggleLinks.text( options.hide ); 182 } 183 184 // If there are no child comments add a 'Hide Feedback' link. 185 if ( !children.length ) { 186 var hide = feedbackToggle.clone(); 187 hide.text( options.hide ); 188 hide.attr( { 189 'aria-expanded': 'true', 190 'aria-controls': 'feedback-' + getCommentID( parent ) 191 } ); 192 parent.find( '.feedback-links' ).append( hide ); 193 } 194 195 // Go to the feedback editor and give it focus. 196 var pos = editor.offset(); 197 $( 'html,body' ).animate( { 198 scrollTop: pos.top - wpAdminBar 199 }, 1000, function() { 200 editor.find( 'textarea' ).focus(); 201 } ); 202 } ); 203 204 } )( jQuery ); 205 No newline at end of file -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes.js
13 13 14 14 function showCommentForm() { 15 15 $( '#respond' ).show(); 16 $( '#add-user-note' ).hide();16 $( '#add-user-note' ).hide(); 17 17 18 var target = $( '#commentform #add-note-or-feedback' ); 18 var wpAdminBar = $('#page.admin-bar').length ? 32 : 0; 19 var target = $( '#commentform #add-note-or-feedback' ); 19 20 if ( target.length ) { 20 21 var pos = target.offset(); 21 22 22 23 $( 'html,body' ).animate( { 23 scrollTop: pos.top 24 scrollTop: pos.top - wpAdminBar 24 25 }, 1000 ); 25 26 } 26 27 } … … 37 38 } 38 39 39 40 // Add php and js buttons to QuickTags. 40 QTags.addButton( 'php', 'php', '[php]', '[/php]' );41 QTags.addButton( 'js', 'js', '[js]', '[/js]' );42 QTags.addButton( 'inline-code', 'inline code', '<code>', '</code>' );41 QTags.addButton( 'php', 'php', '[php]', '[/php]', '', '', '', 'comment' ); 42 QTags.addButton( 'js', 'js', '[js]', '[/js]', '', '', '', 'comment' ); 43 QTags.addButton( 'inline-code', 'inline code', '<code>', '</code>', '', '', '', 'comment' ); 43 44 44 45 // Override tab within user notes textarea to actually insert a tab character. 45 46 // Copied from code within core's wp-admin/js/common.js. -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss
1216 1216 opacity: 1; 1217 1217 } 1218 1218 1219 .comment-awaiting-moderation { 1220 background-color: #fff8e5; 1221 padding: .2em .5em; 1222 border-radius: 3px; 1223 border: 1px solid #ffb900; 1224 } 1225 1226 .depth-2 .comment-awaiting-moderation { 1227 display: inline-block; 1228 margin: 2px 0; 1229 } 1230 1219 1231 .comment-list, 1220 1232 .comment-list ol { 1221 1233 list-style: none; … … 1225 1237 1226 1238 .comment-list li, 1227 1239 #comment-preview { 1228 margin-top: 2.5rem;1240 margin-top: 3rem; 1229 1241 background: #fff; 1230 1242 overflow: auto; 1231 border: 1px solid #dfdfdf;1232 border-radius: 0 2px 2px 2px;1233 1243 1234 1244 article { 1235 1245 overflow: auto; 1236 1246 } 1237 1247 } 1238 1248 1249 .comment-list li.depth-1, 1250 #comment-preview { 1251 border: 1px solid #dfdfdf; 1252 border-radius: 2px; 1253 } 1254 1255 /* Feedback */ 1256 .comment-list li.depth-2 { 1257 border-top: 1px solid #dfdfdf; 1258 padding: 0; 1259 margin: 0; 1260 1261 .comment-content { 1262 padding: 1rem 0; 1263 } 1264 .comment-content p { 1265 margin-bottom: 0; 1266 font-size: .9em; 1267 } 1268 } 1269 1270 .comment ul.children { 1271 margin: 0 0 1.5em 0; 1272 border-bottom: 1px solid #dfdfdf; 1273 } 1274 1275 .feedback { 1276 width: 90%; 1277 float: right; 1278 margin-right: 1.5rem; 1279 } 1280 1281 .feedback-links { 1282 margin: 0 1.5rem 1em 1.5rem; 1283 font-size: 0.9em; 1284 clear:both; 1285 } 1286 1287 .feedback-editor-title, 1288 .feedback-title { 1289 font-size: 1.8rem; 1290 font-weight: 300; 1291 line-height: 2.2rem; 1292 margin-bottom: 1em; 1293 } 1294 1295 .feedback-toggle { 1296 margin: 0 0 0 1.5rem; 1297 display: inline-block; 1298 } 1299 1300 #wp-feedback-wrap { 1301 padding-bottom: 1em; 1302 } 1303 1239 1304 #comment-preview, 1240 1305 .js & .comment-form-comment { 1241 1306 margin-top: 0; … … 1304 1369 padding: 2rem 1.5rem .5rem; 1305 1370 } 1306 1371 1307 .comment-footer {1308 margin: 0 1em;1309 padding: 0 0 1em 0;1310 position: relative;1311 overflow: auto;1312 1313 a {1314 float: right;1315 }1316 1317 p {1318 margin-bottom: 0;1319 }1320 }1321 1322 1372 .comment-content ol { 1323 1373 list-style: decimal inside; 1324 1374 margin: 0 0 1.5em 0; -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css
1582 1582 word-wrap: break-word; 1583 1583 } 1584 1584 1585 .devhub-wrap.single-wp-parser-function, .devhub-wrap.single-wp-parser-method, .devhub-wrap.single-wp-parser-hook, .devhub-wrap.single-wp-parser-class { 1586 /* Feedback */ 1587 } 1588 1585 1589 .devhub-wrap.single-wp-parser-function .bad-note .comment-content, .devhub-wrap.single-wp-parser-method .bad-note .comment-content, .devhub-wrap.single-wp-parser-hook .bad-note .comment-content, .devhub-wrap.single-wp-parser-class .bad-note .comment-content { 1586 1590 opacity: .6; 1587 1591 } … … 1590 1594 opacity: 1; 1591 1595 } 1592 1596 1597 .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 { 1598 background-color: #fff8e5; 1599 padding: .2em .5em; 1600 border-radius: 3px; 1601 border: 1px solid #ffb900; 1602 } 1603 1604 .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 { 1605 display: inline-block; 1606 margin: 2px 0; 1607 } 1608 1593 1609 .devhub-wrap.single-wp-parser-function .comment-list, 1594 1610 .devhub-wrap.single-wp-parser-function .comment-list ol, .devhub-wrap.single-wp-parser-method .comment-list, 1595 1611 .devhub-wrap.single-wp-parser-method .comment-list ol, .devhub-wrap.single-wp-parser-hook .comment-list, … … 1605 1621 .devhub-wrap.single-wp-parser-method #comment-preview, .devhub-wrap.single-wp-parser-hook .comment-list li, 1606 1622 .devhub-wrap.single-wp-parser-hook #comment-preview, .devhub-wrap.single-wp-parser-class .comment-list li, 1607 1623 .devhub-wrap.single-wp-parser-class #comment-preview { 1608 margin-top: 2.5rem;1624 margin-top: 3rem; 1609 1625 background: #fff; 1610 1626 overflow: auto; 1611 border: 1px solid #dfdfdf;1612 border-radius: 0 2px 2px 2px;1613 1627 } 1614 1628 1615 1629 .devhub-wrap.single-wp-parser-function .comment-list li article, … … 1620 1634 overflow: auto; 1621 1635 } 1622 1636 1637 .devhub-wrap.single-wp-parser-function .comment-list li.depth-1, 1638 .devhub-wrap.single-wp-parser-function #comment-preview, .devhub-wrap.single-wp-parser-method .comment-list li.depth-1, 1639 .devhub-wrap.single-wp-parser-method #comment-preview, .devhub-wrap.single-wp-parser-hook .comment-list li.depth-1, 1640 .devhub-wrap.single-wp-parser-hook #comment-preview, .devhub-wrap.single-wp-parser-class .comment-list li.depth-1, 1641 .devhub-wrap.single-wp-parser-class #comment-preview { 1642 border: 1px solid #dfdfdf; 1643 border-radius: 2px; 1644 } 1645 1646 .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 { 1647 border-top: 1px solid #dfdfdf; 1648 padding: 0; 1649 margin: 0; 1650 } 1651 1652 .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 { 1653 padding: 1rem 0; 1654 } 1655 1656 .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 { 1657 margin-bottom: 0; 1658 font-size: .9em; 1659 } 1660 1661 .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 { 1662 margin: 0 0 1.5em 0; 1663 border-bottom: 1px solid #dfdfdf; 1664 } 1665 1666 .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 { 1667 width: 90%; 1668 float: right; 1669 margin-right: 1.5rem; 1670 } 1671 1672 .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 { 1673 margin: 0 1.5rem 1em 1.5rem; 1674 font-size: 0.9em; 1675 clear: both; 1676 } 1677 1678 .devhub-wrap.single-wp-parser-function .feedback-editor-title, 1679 .devhub-wrap.single-wp-parser-function .feedback-title, .devhub-wrap.single-wp-parser-method .feedback-editor-title, 1680 .devhub-wrap.single-wp-parser-method .feedback-title, .devhub-wrap.single-wp-parser-hook .feedback-editor-title, 1681 .devhub-wrap.single-wp-parser-hook .feedback-title, .devhub-wrap.single-wp-parser-class .feedback-editor-title, 1682 .devhub-wrap.single-wp-parser-class .feedback-title { 1683 font-size: 1.8rem; 1684 font-weight: 300; 1685 line-height: 2.2rem; 1686 margin-bottom: 1em; 1687 } 1688 1689 .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 { 1690 margin: 0 0 0 1.5rem; 1691 display: inline-block; 1692 } 1693 1694 .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 { 1695 padding-bottom: 1em; 1696 } 1697 1623 1698 .devhub-wrap.single-wp-parser-function #comment-preview, 1624 1699 .js .devhub-wrap.single-wp-parser-function .comment-form-comment, .devhub-wrap.single-wp-parser-method #comment-preview, 1625 1700 .js .devhub-wrap.single-wp-parser-method .comment-form-comment, .devhub-wrap.single-wp-parser-hook #comment-preview, … … 1684 1759 padding: 2rem 1.5rem .5rem; 1685 1760 } 1686 1761 1687 .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 {1688 margin: 0 1em;1689 padding: 0 0 1em 0;1690 position: relative;1691 overflow: auto;1692 }1693 1694 .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 {1695 float: right;1696 }1697 1698 .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 {1699 margin-bottom: 0;1700 }1701 1702 1762 .devhub-wrap.single-wp-parser-function .comment-content ol, .devhub-wrap.single-wp-parser-method .comment-content ol, .devhub-wrap.single-wp-parser-hook .comment-content ol, .devhub-wrap.single-wp-parser-class .comment-content ol { 1703 1763 list-style: decimal inside; 1704 1764 margin: 0 0 1.5em 0;