Ticket #3572: 3572.9.patch
File 3572.9.patch, 57.6 KB (added by , 7 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments-edit.php
1 <?php namespace DevHub; 2 /** 3 * The Template for editing user contributed notes. 4 * 5 * This template is used if the current user can edit a note. 6 * The global post data is set with the pre_get_posts action. 7 * 8 * @package wporg-developer 9 */ 10 11 get_header(); 12 13 $comment_id = get_query_var( 'edit_user_note' ); 14 $comment = get_comment( $comment_id ); 15 $post = get_queried_object(); 16 $post_id = get_queried_object_id(); 17 $can_user_edit = \DevHub\can_user_edit_note( $comment_id ); 18 19 if ( ! ( $comment && $post && $post_id && $can_user_edit ) ) { 20 // Bail if the current user can't edit this note, or if 21 // the comment or global post data is not found. 22 include get_404_template(); 23 return; 24 } 25 26 $is_parent = $comment->comment_parent ? true : false; 27 $parent = $is_parent ? get_comment( $comment->comment_parent ) : false; 28 $post_url = get_permalink( $post_id ); 29 $post_title = single_post_title( '', false ); 30 $post_types = get_parsed_post_types( 'labels' ); 31 $type_single = get_post_type_object( $post->post_type )->labels->singular_name; 32 $type_url = get_post_type_archive_link( $post->post_type ); 33 $type_label = $post_types[ $post->post_type ]; 34 $ref_url = get_site_section_url(); 35 $ref_link = "<a href='{$ref_url}'>Reference</a>"; 36 $post_link = "<a href='{$post_url}'>{$post_title}</a>"; 37 $note_link = "<a href='{$post_url}#comment-{$comment_id}'>note {$comment_id}</a>"; 38 $type_link = "<a href='{$type_url}'>{$type_label}</a>"; 39 40 $parent_link = ''; 41 $parent_author = ''; 42 if ( $is_parent && isset( $parent->comment_ID ) ) { 43 $parent_author = get_note_author_link( $parent ); 44 $parent_label = sprintf( __('note %d', 'wporg'), $parent->comment_ID ); 45 $parent_link = "<a href='{$post_url}#comment-{$parent->comment_ID}'>{$parent_label}</a>"; 46 } 47 48 add_filter( 'breadcrumb_trail_items', function($items) use ( $ref_link, $type_link, $post_link, $note_link ) { 49 $items[] = $ref_link; 50 $items[] = $type_link; 51 $items[] = $post_link; 52 $items[] = $note_link; 53 $items[] = __('Edit', 'wporg'); 54 return $items; 55 } ); 56 ?> 57 58 <div id="content-area" <?php body_class( 'code-reference' ); ?>> 59 60 <?php breadcrumb_trail( array( 'show_title' => false ) ); ?> 61 62 <main id="main" class="site-main" role="main"> 63 <h1><?php printf( __( 'Edit Note %d', 'wporg' ), $comment_id ); ?></h1> 64 65 <p> 66 <?php if ( $is_parent ) : ?> 67 <?php 68 /* translators: 1: comment title, 2: comment author name, 3: reference type (function, class, method, hook), 4: post title */ 69 printf( __( 'This is a feedback note to %1$s by %2$s for the %3$s %4$s.', 'wporg' ), $parent_link, $parent_author, strtolower( $type_single ), $post_link ); 70 ?> 71 <?php else : ?> 72 <?php 73 /* translators: 1: reference type (function, class, method, hook), 2: post title */ 74 printf( __( 'This is a note for the %1$s %2$s.', 'wporg' ), strtolower( $type_single ), $post_link ); ?> 75 <?php endif; ?> 76 77 <?php echo ' ' . __( "You can edit this note as long as it's in moderation.", 'wporg' ); ?> 78 </p> 79 <?php 80 if ( $is_parent ) { 81 echo \DevHub_User_Submitted_Content::wp_editor_feedback( $comment, 'show', true ); 82 } else { 83 $args = \DevHub_User_Submitted_Content::comment_form_args( $comment, 'edit'); 84 comment_form( $args ); 85 } 86 ?> 87 88 </main><!-- #main --> 89 </div><!-- #primary --> 90 <?php get_footer(); ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments.php
45 45 } else { 46 46 $ordered_comments = wporg_developer_get_ordered_notes(); 47 47 if ( $ordered_comments ) { 48 $feedback_editor = array_filter( wp_list_pluck( $ordered_comments, 'show_editor') );49 48 wporg_developer_list_notes( $ordered_comments, array( 'avatar_size' => 32 ) ); 50 49 } 51 50 } … … 64 63 65 64 <?php if ( \DevHub\is_parsed_post_type() && DevHub\can_user_post_note( true, get_the_ID() ) ) : ?> 66 65 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> 66 <?php if ( is_user_logged_in() ) : ?> 67 <?php 68 /* Hide the add user note link by default. 69 * It will be displayed by Javascript. 70 * If Javascript is disabled the comment form is displayed and the link stays hidden. 71 */ 72 ?> 73 <p id="add-user-note" style="display: none;"><a href="<?php echo user_trailingslashit( get_permalink() ) . '#respond'; ?>"><?php _e( 'Have a note or feedback to contribute?', 'wporg' ); ?></a></p> 74 <?php endif; ?> 69 75 70 76 <?php 71 $args = array( 72 'logged_in_as' => '<p class="logged-in-as">' 73 . sprintf( 74 /* translators: 1: user profile link, 2: accessibility text, 3: user name, 4: logout URL */ 75 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 76 'https://profiles.wordpress.org/' . esc_attr( wp_get_current_user()->user_nicename ), 77 /* translators: %s: user name */ 78 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), 79 $user_identity, 80 wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) ) 81 ) 82 . '</p><p><ul><li>' 83 . __( 'Notes should supplement code reference entries, for example examples, tips, explanations, use-cases, and best practices.', 'wporg' ) 84 . '</li><li>' 85 . __( 'Feedback can be to report errors or omissions with the documentation on this page. Such feedback will not be publicly posted.', 'wporg' ) 86 . '</li><li>' 87 /* translators: 1: php button, 2: js button, 3: inline code button */ 88 . sprintf( 89 __( 'You can enter text and code. Use the %1$s, %2$s, or %3$s buttons to wrap code snippets.', 'wporg' ), 90 '<span class="text-button">php</span>', 91 '<span class="text-button">js</span>', 92 '<span class="text-button">' . __( 'inline code', 'wporg' ) . '</span>' 93 ) 94 . '</li></ul></p>', 95 'comment_notes_after' => '<p>' 96 . __( 'Submission Notes:', 'wporg' ) 97 . '<ul><li>' 98 . __( 'This form is not for support requests, discussions, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' ) 99 . '</li><li>' 100 . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.', 'wporg' ) 101 . '</li><li class="user-notes-are-gpl">' 102 . sprintf( 103 /* translators: 1: GFDL link */ 104 __( '<strong>NOTE:</strong> All contributions are licensed under %s and are moderated before appearing on the site.', 'wporg' ), 105 '<a href="https://gnu.org/licenses/fdl.html">GFDL</a>' 106 ) 107 . '</li></ul></p>', 108 'label_submit' => __( 'Add Note or Feedback', 'wporg' ), 109 'cancel_reply_link' => '', 110 'must_log_in' => '<p>' . sprintf( 111 __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ), 112 'https://login.wordpress.org/?redirect_to=' . urlencode( get_comments_link() ) 113 ) . '</p>', 114 'title_reply' => '', //'Add Example' 115 'title_reply_to' => '', 116 ); 117 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 ) ) { 77 if ( class_exists( 'DevHub_User_Submitted_Content' ) ) { 78 $args = \DevHub_User_Submitted_Content::comment_form_args(); 129 79 comment_form( $args ); 130 80 } 131 81 ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
56 56 require __DIR__ . '/inc/user-content-voting.php'; 57 57 58 58 /** 59 * Editing for user-submitted content. 60 */ 61 require __DIR__ . '/inc/user-content-edit.php'; 62 63 /** 59 64 * CLI commands custom post type and importer. 60 65 */ 61 66 require __DIR__ . '/inc/cli.php'; -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
113 113 114 114 // Check if the current page is a reply to a note. 115 115 $reply_id = 0; 116 if ( isset( $_GET['replytocom'] ) && $_GET['replytocom'] ) { 116 if ( isset( $_GET['replytocom'] ) && $_GET['replytocom'] ) { 117 /* Javascript uses preventDefault() when clicking links with '?replytocom={comment_ID}' 118 * We assume Javascript is disabled when visiting a page with this query var. 119 * There are no consequences if Javascript is enabled. 120 */ 117 121 $reply_id = absint( $_GET['replytocom'] ); 118 122 } 119 123 … … 142 146 $comments[ $key ]->child_notes = array_reverse( $children[ $comment->comment_ID ] ); 143 147 } 144 148 145 if ( ! $show_editor && ( $reply_id && ( $reply_id === (int) $comment->comment_ID ) ) ) { 146 // Show the editor when replying to this parent comment 149 if ( ! $show_editor && ( $reply_id && ( $reply_id === (int) $comment->comment_ID ) ) ) { 150 /* The query var 'replytocom' is used and the value is the same as the current comment ID. 151 * We show the editor for the current comment because we assume Javascript is disabled. 152 * If Javascript is not disabled the editor is hidden (as normal) by the class 'hide-if-js'. 153 */ 147 154 $comments[ $key ]->show_editor = true; 148 155 $show_editor = true; 149 156 } … … 164 171 * @param array $args Comment display arguments. 165 172 */ 166 173 function wporg_developer_list_notes( $comments, $args ) { 174 $is_user_content = class_exists( 'DevHub_User_Submitted_Content' ); 167 175 $is_user_logged_in = is_user_logged_in(); 168 176 $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; 177 $is_user_verified = $is_user_logged_in && $can_user_post_note; 178 179 $args['updated_note'] = 0; 180 if ( isset( $_GET['updated-note'] ) && $_GET['updated-note'] ) { 181 $args['updated_note'] = absint( $_GET['updated-note'] ); 182 } 171 183 172 184 foreach ( $comments as $comment ) { 173 185 … … 176 188 // Display parent comment. 177 189 wporg_developer_user_note( $comment, $args, 1 ); 178 190 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"; 191 /* Use hide-if-js class to hide the feedback section if Javascript is enabled. 192 * Users can display the section with Javascript. 193 */ 194 echo "<section id='feedback-{$comment_id}' class='feedback hide-if-js'>\n"; 182 195 183 196 // Display child comments. 184 197 if ( ! empty( $comment->child_notes ) ) { … … 192 205 } 193 206 194 207 // 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. 208 if ( $is_user_content && $is_user_verified ) { 209 /* Show the feedback editor if we're replying to a note and Javascript is disabled. 210 * If Javascript is enabled the editor is hidden (as normal) by the 'hide-if-js' class. 211 */ 197 212 $display = $comment->show_editor ? 'show' : 'hide'; 198 213 echo DevHub_User_Submitted_Content::wp_editor_feedback( $comment, $display ); 199 214 } … … 202 217 // Feedback links to log in, add feedback or show feedback. 203 218 echo "<footer class='feedback-links' >\n"; 204 219 if ( $can_user_post_note ) { 205 echo "EEE";206 220 $feedback_link = trailingslashit( get_permalink() ) . "?replytocom={$comment_id}#feedback-editor-{$comment_id}"; 207 221 $display = ''; 208 $aria = '';209 222 if ( ! $is_user_logged_in ) { 210 223 $class = 'login'; 211 224 $feedback_text = __( 'Log in to add feedback', 'wporg' ); … … 213 226 } else { 214 227 $class ='add'; 215 228 $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 229 218 // Hide 'add feedback' link if editor is displayed. 219 $display = $display_editor && $comment->show_editor ? ' style="display:none"' : ''; 230 /* Hide the feedback link if the current user is logged in and the 231 * feedback editor is displayed (because Javascript is disabled). 232 * If Javascript is enabled the editor is hidden and the feedback link is displayed (as normal). 233 */ 234 $display = $is_user_verified && $comment->show_editor ? ' style="display:none"' : ''; 220 235 } 221 echo '<a class="feedback-' . $class . '" href="' . esc_url( $feedback_link ) . '"' . $display . $aria .' rel="nofollow">' . $feedback_text . '</a>';236 echo '<a role="button" class="feedback-' . $class . '" href="' . esc_url( $feedback_link ) . '"' . $display . ' rel="nofollow">' . $feedback_text . '</a>'; 222 237 } 223 238 224 239 // close parent list item … … 240 255 $GLOBALS['comment'] = $comment; 241 256 $GLOBALS['comment_depth'] = $depth; 242 257 258 static $note_number = 0; 259 243 260 $approved = ( 0 < (int) $comment->comment_approved ) ? true : false; 244 261 $is_parent = ( 0 === (int) $comment->comment_parent ) ? true : false; 245 262 $is_voting = class_exists( 'DevHub_User_Contributed_Notes_Voting' ); 246 263 $count = $is_voting ? (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' ) : 0; 247 264 $curr_user_note = $is_voting ? (bool) DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID ) : false; 265 $edited_note_id = isset( $args['updated_note'] ) ? $args['updated_note'] : 0; 266 $is_edited_note = ( $edited_note_id === (int) $comment->comment_ID ); 267 $note_author = \DevHub\get_note_author_link( $comment ); 268 $can_edit_note = \DevHub\can_user_edit_note( $comment->comment_ID ); 269 $has_edit_cap = current_user_can( 'edit_comment', $comment->comment_ID ); 248 270 249 // C lasses271 // CSS Classes 250 272 $comment_class = array(); 251 273 252 274 if ( -1 > $count ) { … … 261 283 $comment_class[] = 'user-note-moderated'; 262 284 } 263 285 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 286 $date = sprintf( _x( '%1$s ago', '%1$s = human-readable time difference', 'wporg' ), 280 287 human_time_diff( get_comment_time( 'U' ), 281 288 current_time( 'timestamp' ) ) … … 285 292 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 286 293 287 294 <?php if ( $is_parent ) : ?> 288 <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php _e( 'Skip to note content', 'wporg'); ?></a>295 <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php printf( __( 'Skip to note %d content', 'wporg' ), ++ $note_number ); ?></a> 289 296 <header class="comment-meta"> 290 297 291 298 <?php … … 300 307 echo get_avatar( $comment, $args['avatar_size'] ); 301 308 } 302 309 303 printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $ comment_author_link) );310 printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $note_author ) ); 304 311 ?> 305 312 306 313 </span> 307 314 — 308 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">315 <a class="comment-date" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 309 316 <time datetime="<?php comment_time( 'c' ); ?>"> 310 317 <?php echo $date; ?> 311 318 </time> 312 319 </a> 313 320 <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">— ', '</span>' ); ?> 321 <?php if ( ! $has_edit_cap && $can_edit_note ) : ?> 322 — <span class="comment-author-edit-link"> 323 <a class="comment-edit-link" href="<?php echo site_url( "/reference/comment/edit/{$comment->comment_ID}" ); ?>"><?php _e( 'Edit', 'wporg' ); ?></a> 324 </span> 325 <?php endif; ?> 326 <?php if ( $can_edit_note && $is_edited_note ) : ?> 327 — <span class="comment-edited"> 328 <?php _e( 'edited', 'wporg' ); ?> 329 </span> 330 <?php endif; ?> 314 331 <?php if ( ! $approved ) : ?> 315 332 — <span class="comment-awaiting-moderation"><?php _e( 'awaiting moderation', 'wporg' ); ?></span> 316 333 <?php endif; ?> … … 325 342 comment_text(); 326 343 } else { 327 344 $text = get_comment_text() . ' — '; 328 $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $ comment_author_link) ) . ' — ';329 $text .= ' <a href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">';345 $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $note_author ) ) . ' — '; 346 $text .= ' <a class="comment-date" href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; 330 347 $text .= '<time datetime="' . get_comment_time( 'c' ) . '">' . $date . '</time></a>'; 331 348 332 if ( current_user_can( 'edit_comment', $comment->comment_ID )) {349 if ( $has_edit_cap ) { 333 350 $text .= ' — <a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) .'">'; 334 351 $text .= __( 'Edit', 'wporg' ) . '</a>'; 352 } elseif ( $can_edit_note ) { 353 $text .= ' — <a class="comment-edit-link" href="' . site_url( "/reference/comment/edit/{$comment->comment_ID}" ) . '">'; 354 $text .= __( 'Edit', 'wporg' ) . '</a>'; 335 355 } 336 356 357 if( $can_edit_note && $is_edited_note ) { 358 $text .= ' — <span class="comment-edited">' . __( 'edited', 'wporg' ) . '</span>'; 359 } 360 337 361 if ( ! $approved ) { 338 362 $text .= ' — <span class="comment-awaiting-moderation">' . __( 'awaiting moderation', 'wporg' ) . '</span>'; 339 363 } … … 1397 1421 } 1398 1422 1399 1423 /** 1424 * Indicates if the current user can edit a user contibuted note. 1425 * 1426 * A user can only edit their own notes if it's in moderation and 1427 * if it's a note for a parsed post type. 1428 * 1429 * Users with the 'edit_comment' capability can edit 1430 * all notes from a parsed post type (regardless if it's in moderation). 1431 * 1432 * @param integer $note_id Note ID. 1433 * @return bool True if the current user can edit notes. 1434 */ 1435 function can_user_edit_note( $note_id = 0 ) { 1436 $user = get_current_user_id(); 1437 $note = get_comment( $note_id ); 1438 if ( ! $user || ! $note ) { 1439 return false; 1440 } 1441 1442 $post_id = isset( $note->comment_post_ID ) ? (int) $note->comment_post_ID : 0; 1443 $is_note_author = isset( $note->user_id ) && ( (int) $note->user_id === $user ); 1444 $is_approved = isset( $note->comment_approved ) && ( 0 < (int) $note->comment_approved ); 1445 $can_edit_notes = isset( $note->comment_ID ) && current_user_can( 'edit_comment', $note->comment_ID ); 1446 $is_parsed_type = is_parsed_post_type( get_post_type( $post_id ) ); 1447 1448 if ( $is_parsed_type && ( $can_edit_notes || ( $is_note_author && ! $is_approved ) ) ) { 1449 return true; 1450 } 1451 1452 return false; 1453 } 1454 1455 /** 1456 * Get the note author link to the profiles.wordpress.org author's URL. 1457 * 1458 * @param WP_Comment|int $comment Comment object or comment ID. 1459 * @return string The HTML link to the profiles.wordpress.org author's URL. 1460 */ 1461 function get_note_author_link( $comment ) { 1462 return get_note_author( $comment, true ); 1463 } 1464 1465 /** 1466 * Get the note author nicename. 1467 * 1468 * @param WP_Comment|int $comment Comment object or comment ID. 1469 * @param bool $link. Whether to return a link to the author's profiles. Default false. 1470 * @return string The comment author name or HTML link. 1471 */ 1472 function get_note_author( $comment, $link = false ) { 1473 $comment = get_comment( $comment ); 1474 $user_id = isset( $comment->user_id ) ? $comment->user_id : 0; 1475 $commenter = get_user_by( 'id', $comment->user_id ); 1476 $author = ''; 1477 1478 if ( $user_id && isset( $commenter->user_nicename ) ) { 1479 $url = 'https://profiles.wordpress.org/' . sanitize_key( $commenter->user_nicename ) . '/'; 1480 $author = get_the_author_meta( 'display_name', $comment->user_id ); 1481 } else { 1482 $url = isset( $comment->comment_author_url ) ? $comment->comment_author_url : ''; 1483 $author = isset( $comment->comment_author ) ? $comment->comment_author : ''; 1484 } 1485 1486 if ( $link && ( $url && $author ) ) { 1487 $author = "<a href='$url' rel='external nofollow' class='url'>$author</a>"; 1488 } 1489 1490 return $author; 1491 } 1492 1493 /** 1400 1494 * Gets the summary. 1401 1495 * 1402 1496 * The summary (aka short description) is stored in the 'post_excerpt' field. -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-edit.php
1 <?php 2 /** 3 * Code Reference edit user submitted content (comments, notes, etc). 4 * 5 * Allows users to edit top level and child comments from parsed post types. 6 * 7 * @package wporg-developer 8 */ 9 10 /** 11 * Class to handle editing user submitted content. 12 */ 13 class DevHub_User_Content_Edit { 14 15 /** 16 * Initializer 17 */ 18 public static function init() { 19 add_action( 'init', array( __CLASS__, 'do_init' ) ); 20 } 21 22 /** 23 * Handles adding hooks to enable editing comments. 24 * Adds rewrite rules for editing comments in the front end. 25 */ 26 public static function do_init() { 27 // Add the edit user note rewrite rule 28 add_rewrite_rule( 'reference/comment/edit/([0-9]{1,})/?$', 'index.php?edit_user_note=$matches[1]', 'top' ); 29 30 // Update comment if there is an edit comment request 31 self::update_comment(); 32 33 // Add edit_user_note query var for editing. 34 add_filter( 'query_vars', array( __CLASS__, 'comment_query_var' ) ); 35 36 // Redirect to home page if the edit request is invalid. 37 add_action( 'template_redirect', array( __CLASS__, 'redirect_invalid_edit_request' ) ); 38 39 // Include the comment edit template. 40 add_filter( 'template_include', array( __CLASS__, 'template_include' ) ); 41 42 // Set the post_type and post id for use in the comment edit template. 43 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); 44 } 45 46 /** 47 * Add the edit_user_note query var to the public query vars. 48 * 49 * @param array $query_vars Array with public query vars. 50 * @return array Public query vars. 51 */ 52 public static function comment_query_var( $query_vars ) { 53 $query_vars[] = 'edit_user_note'; 54 return $query_vars; 55 } 56 57 /** 58 * Update a comment after editing. 59 */ 60 public static function update_comment() { 61 62 if ( is_admin() || ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) ) { 63 return; 64 } 65 66 $comment_data = wp_unslash( $_POST ); 67 68 $defaults = array( 69 'update_user_note', 70 '_wpnonce', 71 'comment_ID', 72 'comment', 73 'comment_parent', 74 'comment_post_ID' 75 ); 76 77 foreach ( $defaults as $value ) { 78 if ( ! isset( $comment_data[ $value ] ) ) { 79 // Return if any of the $_POST keys are missing. 80 return; 81 } 82 } 83 84 $comment = trim( (string) $comment_data['comment'] ); 85 if ( ! $comment ) { 86 // Bail and provide a way back to the edit form if a comment is empty. 87 $msg = __( '<strong>ERROR</strong>: please type a comment.', 'wporg' ); 88 $args = array( 'response' => 200, 'back_link' => true ); 89 wp_die( '<p>' . $msg . '</p>', __( 'Comment Submission Failure', 'wporg' ), $args ); 90 } 91 92 $updated = 0; 93 $post_id = absint( $comment_data['comment_post_ID'] ); 94 $comment_id = absint( $comment_data['comment_ID'] ); 95 $can_user_edit = DevHub\can_user_edit_note( $comment_id ); 96 $action = 'update_user_note_' . $comment_id; 97 $nonce = wp_verify_nonce( $comment_data['_wpnonce'], $action ); 98 99 if ( $nonce && $can_user_edit ) { 100 $comment_data['comment_content'] = $comment; 101 $updated = wp_update_comment( $comment_data ); 102 } 103 104 $location = get_permalink( $post_id ); 105 if ( $updated && $location ) { 106 $commment_updated = '?updated-note=' . $comment_id . '#comment-' . $comment_id; 107 wp_safe_redirect( $location . $commment_updated ); 108 exit; 109 } 110 } 111 112 /** 113 * Redirects to the home page if the edit request is invalid for the current user. 114 * 115 * Redirects if the comment doesn't exist. 116 * Redirects if the comment is not for a parsed post type. 117 * Redirects if the current user is not the comment author. 118 * Redirects if a comment is already approved. 119 * 120 * Doesn't redirect for users with the edit_comment capability. 121 */ 122 public static function redirect_invalid_edit_request() { 123 $comment_id = absint( get_query_var( 'edit_user_note' ) ); 124 if ( ! $comment_id ) { 125 // Not a query for editing a note. 126 return; 127 } 128 129 if ( ! DevHub\can_user_edit_note( $comment_id ) ) { 130 wp_redirect( home_url( '/reference' ) ); 131 exit(); 132 } 133 } 134 135 /** 136 * Use the 'comments-edit.php' template for editing comments. 137 * 138 * The current user has already been verified in the template_redirect action. 139 * 140 * @param string $template Template to include. 141 * @return string Template to include. 142 */ 143 public static function template_include( $template ) { 144 $comment_id = absint( get_query_var( 'edit_user_note' ) ); 145 if ( ! $comment_id ) { 146 // Not a query for editing a note. 147 return $template; 148 } 149 150 $comment_template = get_query_template( "comments-edit" ); 151 if ( $comment_template ) { 152 $template = $comment_template; 153 } 154 return $template; 155 } 156 157 /** 158 * Sets the post and post type for an edit request. 159 * 160 * Trows a 404 if the current user can't edit the requested note. 161 * 162 * @param WP_Query $query The WP_Query instance (passed by reference) 163 */ 164 public static function pre_get_posts( $query ) { 165 $comment_id = absint( get_query_var( 'edit_user_note' ) ); 166 167 if ( is_admin() || ! ( $query->is_main_query() && $comment_id ) ) { 168 // Not a query for editing a note. 169 return; 170 } 171 172 if ( DevHub\can_user_edit_note( $comment_id ) ) { 173 $comment = get_comment( $comment_id ); 174 if ( isset( $comment->comment_post_ID ) ) { 175 $query->is_singular = true; 176 $query->is_single = true; 177 $query->set( 'post_type', get_post_type( $comment->comment_post_ID ) ); 178 $query->set( 'p', $comment->comment_post_ID ); 179 180 return; 181 } 182 } 183 184 // Set 404 if a user can't edit a note. 185 $query->set_404(); 186 } 187 188 } // DevHub_User_Content_Edit 189 190 DevHub_User_Content_Edit::init(); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php
50 50 remove_filter( 'comment_text', 'capital_P_dangit', 31 ); 51 51 52 52 // Enable shortcodes for comments 53 add_filter( 'comment_text', 'do_shortcode' );53 add_filter( 'comment_text', 'do_shortcode' ); 54 54 55 55 // Customize allowed tags 56 56 add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'wp_kses_allowed_html' ), 10, 2 ); … … 67 67 // Allowed HTML for an edited child comment (There is no decent hook to filter child comments only) 68 68 add_action( 'edit_comment', array( __CLASS__, 'comment_edit_allowed_html' ) ); 69 69 70 // Adds hidden fields to a comment form for editing 71 add_filter( 'comment_form_submit_field', array( __CLASS__, 'add_hidden_fields' ), 10, 2 ); 70 72 } 71 73 72 74 /** … … 148 150 ); 149 151 150 152 $allowed_protocols = array( 'http', 'https' ); 153 $comment_content = wp_kses( $comment_content, $allowed_html, $allowed_protocols ); 151 154 152 $comment_content = wp_kses( $comment_content, $allowed_html, $allowed_protocols );153 $commentdata['comment_content'] = preg_replace( '/\r?\n|\r/', ' ', $comment_content );155 // Replace newlines with a space. 156 $commentdata['comment_content'] = preg_replace( '/\r?\n|\r/', ' ', $comment_content ); 154 157 155 158 return $commentdata; 156 159 } … … 167 170 wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'jquery', 'quicktags' ), '20180323', true ); 168 171 wp_enqueue_script( 'wporg-developer-user-notes-feedback', get_template_directory_uri() . '/js/user-notes-feedback.js', array( 'jquery', 'quicktags' ), '20180323', true ); 169 172 wp_localize_script( 'wporg-developer-user-notes-feedback', 'wporg_note_feedback', array( 170 'show' => __( 'Show Feedback', 'wporg' ),171 'hide' => __( 'Hide Feedback', 'wporg' ),173 'show' => __( 'Show Feedback', 'wporg' ), 174 'hide' => __( 'Hide Feedback', 'wporg' ), 172 175 ) ); 173 176 } 174 177 } … … 176 179 /** 177 180 * Sets the default language for SyntaxHighlighter shortcode. 178 181 * 179 * @param 182 * @param array $atts Shortcode attributes. 180 183 * @return array 181 184 */ 182 185 public static function syntaxhighlighter_shortcodeatts( $atts ) { … … 187 190 /** 188 191 * Subverts capital_P_dangit for SyntaxHighlighter shortcode. 189 192 * 190 * @param 193 * @param string $code 191 194 * @return string 192 195 */ 193 196 public static function syntaxhighlighter_precode( $code ) { … … 195 198 } 196 199 197 200 /** 201 * Add hidden fields to the comment form if the context is 'edit' 202 * 203 * @param string $submit_field HTML string with the submit button fields. 204 * @param array $args Arguments for the comment form. 205 * @return HTML string with the submit button fields. 206 */ 207 public static function add_hidden_fields( $submit_field, $args ) { 208 $context = isset( $args['context'] ) ? $args['context'] : ''; 209 $comment = isset( $args['comment_edit'] ) ? $args['comment_edit'] : false; 210 if ( ! ( $comment && ( 'edit' === $context ) ) ) { 211 return $submit_field; 212 } 213 214 $comment_id = isset( $comment->comment_ID ) ? $comment->comment_ID : 0; 215 216 return $submit_field . self::get_edit_fields( $comment_id, $instance = 0 ); 217 } 218 219 /** 220 * Get the comment form arguments by context. 221 * 222 * @param WP_Comment|false $comment Comment object or false. Default false. 223 * @param string $context Context of arguments. Accepts 'edit' or empty string. 224 * @return array Array with comment form arguments. 225 */ 226 public static function comment_form_args( $comment = false, $context = '' ) { 227 $label = _x( 'Add Note or Feedback', 'noun', 'wporg' ); 228 if ( 'edit' === $context ) { 229 $label = _x( 'Edit Note', 'noun', 'wporg' ); 230 } 231 232 $user_identity = wp_get_current_user(); 233 234 $args = array( 235 'logged_in_as' => '<p class="logged-in-as">' 236 . sprintf( 237 /* translators: 1: user profile link, 2: accessibility text, 3: user name, 4: logout URL */ 238 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 239 'https://profiles.wordpress.org/' . esc_attr( $user_identity->user_nicename ), 240 /* translators: %s: user name */ 241 esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity->display_name ) ), 242 $user_identity->display_name, 243 wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) ) 244 ) 245 . '</p><p><ul><li>' 246 . __( 'Notes should supplement code reference entries, for example examples, tips, explanations, use-cases, and best practices.', 'wporg' ) 247 . '</li><li>' 248 . __( 'Feedback can be to report errors or omissions with the documentation on this page. Such feedback will not be publicly posted.', 'wporg' ) 249 . '</li><li>' 250 /* translators: 1: php button, 2: js button, 3: inline code button */ 251 . sprintf( 252 __( 'You can enter text and code. Use the %1$s, %2$s, or %3$s buttons to wrap code snippets.', 'wporg' ), 253 '<span class="text-button">php</span>', 254 '<span class="text-button">js</span>', 255 '<span class="text-button">' . __( 'inline code', 'wporg' ) . '</span>' 256 ) 257 . '</li></ul></p>', 258 'comment_notes_after' => '<p>' . __( 'Submission Notes:', 'wporg' ) . '</p>' . self::get_editor_rules(), 259 'label_submit' => $label, 260 'cancel_reply_link' => '', 261 'must_log_in' => '<p>' . sprintf( 262 __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ), 263 'https://login.wordpress.org/?redirect_to=' . urlencode( get_comments_link() ) 264 ) . '</p>', 265 'title_reply' => '', //'Add Example' 266 'title_reply_to' => '', 267 ); 268 269 if ( class_exists( 'DevHub_Note_Preview' ) ) { 270 $args['comment_notes_after'] = DevHub_Note_Preview::comment_preview() . $args['comment_notes_after']; 271 $args['class_form'] = "comment-form tab-container"; 272 } 273 274 $args['comment_field'] = self::wp_editor_comments( $label, $comment ); 275 $args['context'] = $context; 276 $args['comment_edit'] = $comment; 277 278 if ( $comment && ( 'edit' === $context ) ) { 279 $comment_id = isset( $comment->comment_ID ) ? $comment->comment_ID : 0; 280 $post_id = isset( $comment->comment_post_ID ) ? $comment->comment_post_ID : 0; 281 282 $args['action'] = get_permalink( $post_id ) . '#comment-' . $comment_id; 283 } 284 285 return $args; 286 } 287 288 /** 198 289 * Capture an {@see wp_editor()} instance as the 'User Contributed Notes' comment form. 199 290 * 200 291 * Uses output buffering to capture the editor instance for use with the {@see comments_form()}. 201 292 * 293 * @param string $label Label used for the editor. 294 * @param WP_Comment|false $comment Comment object or false. Default false. 202 295 * @return string HTML output for the wp_editor-ized comment form. 203 296 */ 204 public static function wp_editor_comments() { 297 public static function wp_editor_comments( $label, $comment = false ) { 298 $content = isset( $comment->comment_content ) ? trim( $comment->comment_content ) : ''; 299 300 // wp_kses() converts htmlspecialchars in source code. 301 $content = $content ? htmlspecialchars_decode( $content ) : ''; 302 205 303 ob_start(); 206 echo '<h3><label for="comment">' . _x( 'Add Note or Feedback', 'noun', 'wporg' ). '</label></h3>';304 echo '<h3><label for="comment">' . $label . '</label></h3>'; 207 305 208 306 if ( class_exists( 'DevHub_Note_Preview' ) ) { 209 echo '<ul class="tablist" style="display:none;">';307 echo "<ul class='tablist' style='display: none;'>"; 210 308 echo '<li><a href="#comment-form-comment">' . __( 'Write', 'wporg' ) . '</a></li>'; 211 309 echo '<li><a href="#comment-preview">' . __( 'Preview', 'wporg' ) . '</a></li></ul>'; 212 310 } 213 311 214 $style = '<style type="text/css">';215 ob_start();216 include get_stylesheet_directory() . '/stylesheets/editor-style.css';217 $style .= ob_get_clean();218 $style .=' </style>';219 220 312 echo '<div class="comment-form-comment tab-section" id="comment-form-comment">'; 221 wp_editor( '', 'comment', array(222 'media_buttons' => false,223 'editor_css' => $style,224 'textarea_name' => 'comment',225 'textarea_rows' => 8,226 'quicktags' => array(227 'buttons' => 'strong,em,ul,ol,li'228 ),229 'teeny' => true,230 'tinymce' => false,231 ) );313 wp_editor( $content, 'comment', array( 314 'media_buttons' => false, 315 'editor_css' => self::get_editor_style(), 316 'textarea_name' => 'comment', 317 'textarea_rows' => 8, 318 'quicktags' => array( 319 'buttons' => 'strong,em,ul,ol,li' 320 ), 321 'teeny' => true, 322 'tinymce' => false, 323 ) ); 232 324 echo '</div>'; 233 325 return ob_get_clean(); 234 326 } … … 238 330 * 239 331 * Uses output buffering to capture the editor instance. 240 332 * 333 * @param WP_Comment|false $comment Comment object or false. Default false. 334 * @param string $display Display the editor. Default 'show'. 335 * @param bool $edit True if the editor used for editing a note. Default false. 241 336 * @return string HTML output for the wp_editor-ized feedback form. 242 337 */ 243 public static function wp_editor_feedback( $comment, $display = 'show', $ content = '') {338 public static function wp_editor_feedback( $comment, $display = 'show', $edit = false ) { 244 339 245 340 if ( ! ( isset( $comment->comment_ID ) && absint( $comment->comment_ID ) ) ) { 246 341 return ''; … … 251 346 static $instance = 0; 252 347 $instance++; 253 348 254 $display = ( 'hide' === $display ) ? ' style="display: none;"' : ''; 255 $title = __( 'Add feedback to this note', 'wporg' ); 256 $form_type = ''; 257 $button_text = __( 'Add Feedback', 'wporg' ); 349 $display = ( 'hide' === $display ) ? ' style="display: none;"' : ''; 350 $parent = $comment_id; 351 $action = site_url( '/wp-comments-post.php' ); 352 $title = __( 'Add feedback to this note', 'wporg' ); 353 $button_text = __( 'Add Feedback', 'wporg' ); 354 $post_id = isset( $comment->comment_post_ID ) ? $comment->comment_post_ID : get_the_ID(); 355 $content = ''; 356 $form_type = ''; 357 $note_link = ''; 358 $class = ''; 258 359 259 if ( $content ) { 260 $title = __( 'Edit feedback', 'wporg' ); 261 $form_type = '-edit'; 262 $button_text = __( 'Edit Feedback', 'wporg' ); 263 } 360 if ( $edit ) { 361 $content = isset( $comment->comment_content ) ? $comment->comment_content : ''; 362 $title = __( 'Edit feedback', 'wporg' ); 363 $form_type = '-edit'; 364 $button_text = __( 'Edit Note', 'wporg' ); 365 $post_url = get_permalink( $post_id ); 366 $action = $post_url ? $post_url . '#comment-' . $comment_id : ''; 367 $parent = isset( $comment->comment_parent ) ? $comment->comment_parent : 0; 368 $parent_author = \DevHub\get_note_author( $parent ); 369 $class = ' edit-feedback-editor'; 264 370 371 if ( $parent && $post_url && $parent_author ) { 372 $post_url = $post_url . '#comment-' . $parent; 373 $parent_note = sprintf( __( 'note %d', 'wporg' ), $parent ); 374 375 /* translators: 1: note, 2: note author name */ 376 $note_link = sprintf( __( '%1$s by %2$s', 'wporg' ), "<a href='{$post_url}'>{$parent_note}</a>", $parent_author ); 377 } 378 } 379 265 380 $allowed_tags = ''; 266 381 foreach ( array( '<strong>', '<em>', '<code>', '<a>' ) as $tag ) { 267 382 $allowed_tags .= '<code>' . htmlentities( $tag ) . '</code>, '; … … 268 383 } 269 384 270 385 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"; 386 echo "<div id='feedback-editor-{$comment_id}' class='feedback-editor{$class}'{$display}>\n"; 387 if ( ! $edit ) { 388 echo "<p class='feedback-editor-title'>{$title}</p>\n"; 389 } 274 390 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 ) ); 391 echo "<form id='feedback-form-{$instance}{$form_type}' class='feedback-form' method='post' action='{$action}' name='feedback-form-{$instance}'>\n"; 392 echo self::get_editor_rules( 'feedback', $note_link ); 393 wp_editor( $content, 'feedback-' . $instance, array( 394 'media_buttons' => false, 395 'textarea_name' => 'comment', 396 'textarea_rows' => 3, 397 'quicktags' => array( 398 'buttons' => 'strong,em' 399 ), 400 'editor_css' => self::get_editor_style(), 401 'teeny' => true, 402 'tinymce' => false, 403 ) ); 285 404 286 405 echo '<p><strong>' . __( 'Note', 'wporg' ) . '</strong>: ' . __( 'No newlines allowed', 'wporg' ) . '. '; 287 406 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"; 407 echo "<p><input id='submit-{$instance}' class='submit' type='submit' value='{$button_text}' name='submit-{$instance}'>\n"; 408 echo "<input type='hidden' name='comment_post_ID' value='{$post_id}' id='comment_post_ID-{$instance}' />\n"; 409 echo "<input type='hidden' name='comment_parent' id='comment_parent-{$instance}' value='{$parent}' />\n"; 410 411 if ( $edit ) { 412 echo self::get_edit_fields( $comment_id, $instance ); 413 } 414 291 415 echo "</p>\n</form>\n</div><!-- #feedback-editor-{$comment_id} -->\n"; 292 416 return ob_get_clean(); 293 417 } 294 418 419 /** 420 * Get the rules list for the comment form. 421 * 422 * @param string $context Accepts 'feedback' or empty sring 423 * @return string Editor rules. 424 */ 425 public static function get_editor_rules( $context = '', $note_link = '' ) { 426 $license_rule = sprintf( 427 /* translators: 1: GFDL link */ 428 __( '<strong>NOTE:</strong> All contributions are licensed under %s and are moderated before appearing on the site.', 'wporg' ), 429 '<a href="https://gnu.org/licenses/fdl.html">GFDL</a>' 430 ); 431 432 if ( 'feedback' === $context ) { 433 $feedback_rule = __( 'Use this form to report errors or to add additional information to this note.', 'wporg' ); 434 if ( $note_link ) { 435 $feedback_rule = sprintf( __( 'Use this form to report errors or to add additional information to %s.', 'wporg' ), $note_link ); 436 } 437 438 return '<ul><li>' 439 . __( 'Feedback is part of the documentation.', 'wporg' ) . ' ' 440 . $feedback_rule 441 . '</li><li>' 442 . __( 'This form is not for support requests, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' ) 443 . '</li><li class="user-notes-are-gpl">' 444 . $license_rule 445 . '</li></ul>'; 446 } 447 448 return '<ul><li>' 449 . __( 'This form is not for support requests, discussions, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' ) 450 . '</li><li>' 451 . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.', 'wporg' ) 452 . '</li><li class="user-notes-are-gpl">' 453 . $license_rule 454 . '</li></ul>'; 455 } 456 457 /** 458 * Get the editor styles. 459 * 460 * @return string Editor styles. 461 */ 462 public static function get_editor_style() { 463 $style = '<style type="text/css">'; 464 ob_start(); 465 include get_stylesheet_directory() . '/stylesheets/editor-style.css'; 466 $style .= ob_get_clean(); 467 $style .= ' </style>'; 468 return $style; 469 } 470 471 /** 472 * Get the hidden input fields HTML used for editing a note. 473 * 474 * @param int $comment_id Comment ID. 475 * @param integer $instance Comment form instance number used in HTML id's. 476 * @return string Hidden input fields HTML. 477 */ 478 public static function get_edit_fields( $comment_id, $instance = 0 ) { 479 $fields = "<input type='hidden' name='comment_ID' id='comment_ID-{$instance}' value='{$comment_id}' />\n"; 480 $fields .= "<input type='hidden' name='update_user_note' id='update_user_note-{$instance}' value='1' />\n"; 481 $fields .= wp_nonce_field( 'update_user_note_' . $comment_id, '_wpnonce', true, false ); 482 483 return $fields; 484 } 485 295 486 } // DevHub_User_Submitted_Content 296 487 297 488 DevHub_User_Submitted_Content::init(); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-feedback.js
4 4 return; 5 5 } 6 6 7 var wpAdminBar = 0; 7 8 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>' ); 9 var feedbackToggle = $( '<a role="button" class="feedback-toggle" href="#">' + options.show + '</a>' ); 10 10 var hash = window.location.hash; 11 11 12 12 // Check if the fragment identifier is a comment ID (e.g. #comment-63) … … 15 15 } 16 16 17 17 $( '.feedback-editor' ).each( function() { 18 // Hide feedback editors with hide-if-js class 19 $( this ).not('.edit-feedback-editor').addClass( 'hide-if-js' ); 20 $( this ).removeAttr("style"); 18 21 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 22 // Add quicktag 'inline code' button to editor. 25 23 var id = $( this ).find( 'textarea' ).attr( 'id' ); 26 24 if ( id.length ) { … … 37 35 var feedback = $( this ).find( '.feedback' ); 38 36 var toggle = feedbackToggle.clone(); 39 37 38 var feedback_id = 'feedback-' + getCommentID( $(this) ); 40 39 toggle.attr( { 41 40 'aria-expanded': 'false', 42 'aria-controls': 'feedback-' + getCommentID( $(this) )41 'aria-controls': feedback_id 43 42 } ); 44 43 45 44 // Set text to 'Hide Feedback' if feedback is displayed … … 47 46 toggle.text( options.hide ); 48 47 } 49 48 50 feedbackLinks.find( '.feedback-add' ).show(); 49 var editor_id = 'feedback-editor-' + getCommentID( $(this) ); 50 51 // Display hidden add feedback link and add aria 52 feedbackLinks.find( '.feedback-add' ).removeAttr("style").attr( { 53 'aria-expanded': 'false', 54 'aria-controls': editor_id 55 } ); 56 51 57 feedbackLinks.append( toggle ); 52 58 } 53 59 54 60 if ( feedbackLinks.length ) { 55 // Move feedback links before feedback.61 // Move the feedback links before the feedback section. 56 62 var clonedElements = feedbackLinks.clone().children(); 57 63 var feedbackLinksTop = $( '<div class="feedback-links"></div>' ).append( clonedElements ); 58 64 $( this ).find( '.feedback' ).first().before( feedbackLinksTop ); 65 66 // Hide the bottom feedback links. 59 67 feedbackLinks.addClass( 'bottom hide-if-js' ); 60 68 } 61 69 } ); … … 67 75 68 76 // Removes added elements 69 77 function resetComment( el ) { 70 71 78 var children = el.find( 'ul.children' ); 72 79 if ( !children.length ) { 73 80 el.find( '.feedback-toggle' ).remove(); … … 78 85 79 86 // Show hidden child comments if the fragment identifier is a comment ID (e.g. #comment-63). 80 87 $( document ).ready( function() { 81 88 wpAdminBar = $('#wpadminbar').length ? 32 : 0 82 89 var childComments = $( '.comment' ).find( 'ul.children' ); 83 90 84 if ( ! ( hash.length && childComments.length ) ) {91 if ( ! ( hash.length && childComments.length ) ) { 85 92 return; 86 93 } 87 94 88 var hashComment = childComments.find( hash ).first(); 89 if ( hashComment.length ) { 90 // Child comment exists. 95 var hashComment = childComments.find( hash + '.depth-2' ).first(); 96 if ( ! hashComment.length ) { 97 return; 98 } 99 // Child comment exists. 91 100 92 93 94 95 96 101 var parent = hashComment.closest( '.comment.depth-1' ); 102 if ( parent.find( '.feedback' ).hasClass( 'hide-if-js' ) ) { 103 // Show child comments. 104 parent.find( '.feedback-toggle' ).first().trigger( 'click' ); 105 } 97 106 98 // Scroll to the child comment.99 100 101 102 103 } 107 // Scroll to child comment and adjust for admin bar 108 var pos = hashComment.offset(); 109 $( 'html,body' ).animate( { 110 scrollTop: pos.top - wpAdminBar 111 }, 1 ); 112 104 113 } ); 105 114 106 // Show/Hide feedback toggle link.115 // Click event for Show/Hide feedback toggle link. 107 116 $( document ).on( 'click', '.feedback-toggle', function( e ) { 108 117 e.preventDefault(); 109 118 … … 130 139 scrollTop: pos.top - wpAdminBar 131 140 }, 1000 ); 132 141 133 // Addfeedback links at the bottom if there are over 3 feedback notes.142 // Show feedback links at the bottom if there are over 3 feedback notes. 134 143 var children = parent.find( 'ul.children > li' ); 135 144 if ( 3 < children.length ) { 136 145 var feedbackLinks = parent.find( '.feedback-links.bottom' ); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-preview.js
20 20 text = ''; 21 21 processing = false; 22 22 23 // Show tabs with Javascript. 24 $( '#commentform .tablist').show(); 25 23 26 if ( textarea.length && preview.length && tabs.length ) { 24 27 25 28 // Append spinner to preview tab -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes.js
6 6 ( function( $ ) { 7 7 8 8 var commentForm = $( '.comment-form textarea' ); 9 var add_user_note = $( '#add-user-note' ); 10 var hash = window.location.hash; 11 var wpAdminBar = 0; 9 12 10 if ( !commentForm.length ) { 11 return; 13 // Check if the fragment identifier is a comment ID (e.g. #comment-63) 14 if ( ! hash.match( /#comment\-[0-9]+$/ ) ) { 15 hash = ''; 12 16 } 13 17 18 // Scroll to top level comments 19 $( document ).ready( function() { 20 wpAdminBar = $( '#wpadminbar' ).length ? 32 : 0; 21 if( ! wpAdminBar || ! hash ) { 22 return; 23 } 24 25 var hashComment = $('#comments').find( hash + '.depth-1' ).first(); 26 if( ! hashComment.length ) { 27 return; 28 } 29 30 // Scroll to top level comment and adjust for admin bar. 31 var pos = hashComment.offset(); 32 $( 'html,body' ).animate( { 33 scrollTop: pos.top - wpAdminBar 34 }, 1 ); 35 } ); 36 37 // Scroll to comment if comment date link is clicked 38 $( '#comments' ).on( 'click', '.comment-date', function( e ) { 39 // Scroll to comment and adjust for admin bar 40 // Add 16px for child comments 41 var pos = $( this ).offset(); 42 $( 'html,body' ).animate( { 43 scrollTop: pos.top - wpAdminBar - 16 44 }, 1 ); 45 } ); 46 14 47 function showCommentForm() { 48 if( add_user_note.length ) { 49 add_user_note.hide(); 50 } 51 15 52 $( '#respond' ).show(); 16 $( '#add-user-note' ).hide();17 53 18 var wpAdminBar = $( '#page.admin-bar' ).length ? 32 : 0;19 54 var target = $( '#commentform #add-note-or-feedback' ); 20 55 if ( target.length ) { 21 56 var pos = target.offset(); … … 28 63 } 29 64 } 30 65 31 $( '#respond, #add-user-note' ).toggle(); 66 if ( ! commentForm.length ) { 67 return; 68 } 69 70 71 if( add_user_note.length ) { 72 add_user_note.show(); 73 74 // Hide by default if #add-user-note exists 75 $( '#respond' ).hide(); 76 } 77 32 78 $( '#add-user-note, .table-of-contents a[href="#add-note-or-feedback"]' ).click( function( e ) { 33 79 e.preventDefault(); 34 80 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss
1137 1137 opacity: 1; 1138 1138 } 1139 1139 1140 .comment-awaiting-moderation { 1140 .comment-awaiting-moderation, 1141 .comment-edited { 1141 1142 background-color: #fff8e5; 1142 1143 padding: .2em .5em; 1144 margin-right: .5em; 1143 1145 border-radius: 3px; 1144 1146 border: 1px solid #ffb900; 1145 1147 } 1146 1148 1147 .depth-2 .comment-awaiting-moderation { 1149 .depth-2 .comment-awaiting-moderation, 1150 .depth-2 .comment-edited { 1148 1151 display: inline-block; 1149 1152 margin: 2px 0; 1150 1153 } … … 1170 1173 .comment-list li.depth-1, 1171 1174 #comment-preview { 1172 1175 border: 1px solid #dfdfdf; 1173 border-radius: 2px; 1176 border-radius: 2px; 1177 width: 100%; 1174 1178 } 1175 1179 1176 1180 // Feedback … … 1362 1366 padding: 0 5px; 1363 1367 } 1364 1368 1365 .comment-form ul {1369 .comment-form ul, .feedback-form ul { 1366 1370 margin-left: 1.5em; 1367 1371 } 1372 1373 .feedback-form ul li { 1374 margin: 0; 1375 overflow: visible; 1376 } 1368 1377 } 1369 1378 1370 1379 &.single-post { -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css
1514 1514 opacity: 1; 1515 1515 } 1516 1516 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 { 1517 .devhub-wrap .single-wp-parser-function .comment-awaiting-moderation, 1518 .devhub-wrap .single-wp-parser-function .comment-edited, .devhub-wrap .single-wp-parser-method .comment-awaiting-moderation, 1519 .devhub-wrap .single-wp-parser-method .comment-edited, .devhub-wrap .single-wp-parser-hook .comment-awaiting-moderation, 1520 .devhub-wrap .single-wp-parser-hook .comment-edited, .devhub-wrap .single-wp-parser-class .comment-awaiting-moderation, 1521 .devhub-wrap .single-wp-parser-class .comment-edited { 1518 1522 background-color: #fff8e5; 1519 1523 padding: .2em .5em; 1524 margin-right: .5em; 1520 1525 border-radius: 3px; 1521 1526 border: 1px solid #ffb900; 1522 1527 } 1523 1528 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 { 1529 .devhub-wrap .single-wp-parser-function .depth-2 .comment-awaiting-moderation, 1530 .devhub-wrap .single-wp-parser-function .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-method .depth-2 .comment-awaiting-moderation, 1531 .devhub-wrap .single-wp-parser-method .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-hook .depth-2 .comment-awaiting-moderation, 1532 .devhub-wrap .single-wp-parser-hook .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-class .depth-2 .comment-awaiting-moderation, 1533 .devhub-wrap .single-wp-parser-class .depth-2 .comment-edited { 1525 1534 display: inline-block; 1526 1535 margin: 2px 0; 1527 1536 } … … 1561 1570 .devhub-wrap .single-wp-parser-class #comment-preview { 1562 1571 border: 1px solid #dfdfdf; 1563 1572 border-radius: 2px; 1573 width: 100%; 1564 1574 } 1565 1575 1566 1576 .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 { … … 1735 1745 padding: 0 5px; 1736 1746 } 1737 1747 1738 .devhub-wrap .single-wp-parser-function .comment-form ul, .devhub-wrap .single-wp-parser- method .comment-form ul, .devhub-wrap .single-wp-parser-hook .comment-form ul, .devhub-wrap .single-wp-parser-class .comment-form ul {1748 .devhub-wrap .single-wp-parser-function .comment-form ul, .devhub-wrap .single-wp-parser-function .feedback-form ul, .devhub-wrap .single-wp-parser-method .comment-form ul, .devhub-wrap .single-wp-parser-method .feedback-form ul, .devhub-wrap .single-wp-parser-hook .comment-form ul, .devhub-wrap .single-wp-parser-hook .feedback-form ul, .devhub-wrap .single-wp-parser-class .comment-form ul, .devhub-wrap .single-wp-parser-class .feedback-form ul { 1739 1749 margin-left: 1.5em; 1740 1750 } 1741 1751 1752 .devhub-wrap .single-wp-parser-function .feedback-form ul li, .devhub-wrap .single-wp-parser-method .feedback-form ul li, .devhub-wrap .single-wp-parser-hook .feedback-form ul li, .devhub-wrap .single-wp-parser-class .feedback-form ul li { 1753 margin: 0; 1754 overflow: visible; 1755 } 1756 1742 1757 .devhub-wrap.single-post .comment-list, 1743 1758 .devhub-wrap.single-post .comment-list ol { 1744 1759 list-style: none;