WordPress.org

Making WordPress.org

Changeset 724


Ignore:
Timestamp:
06/29/2014 08:41:47 AM (7 years ago)
Author:
coffee2code
Message:

Code Reference: add ability for users to submit code examples (via comments). See #180

Viewable by all, but temporarily only submittable by members of the site.

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

Legend:

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

    r554 r724  
    2323<div id="comments" class="comments-area">
    2424
    25     <?php // You can start editing here -- including this comment! ?>
    26 
    2725    <?php if ( have_comments() ) : ?>
    28         <h2 class="comments-title">
    29             <?php
    30                 printf( _nx( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'comments title', 'wporg' ),
    31                     number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
    32             ?>
    33         </h2>
    34 
    3526        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
    3627        <nav id="comment-nav-above" class="comment-navigation" role="navigation">
     
    6354    <?php endif; // have_comments() ?>
    6455
    65     <?php
    66         // If comments are closed and there are comments, let's leave a little note, shall we?
    67         if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    68     ?>
    69         <p class="no-comments"><?php _e( 'Comments are closed.', 'wporg' ); ?></p>
    70     <?php endif; ?>
     56    <p id="add-example" style="display:none;"><a href=""><?php _e( 'Have an example to add?', 'wporg' ); ?></a></p>
    7157
    72     <?php comment_form(); ?>
     58    <?php comment_form( array(
     59        'comment_field'       => '<p class="comment-form-comment"><label for="comment">' . _x( 'Add Example', 'noun', 'wporg' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
     60        'comment_notes_after' => '<p class="examples-are-gpl">' .
     61            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' ) .
     62            '</p><p>' .
     63            __( 'The entirety of your submission is considered a code example. Any included non-code text should be formatted as code comments.', 'wporg' ) .
     64            '</p>',
     65        'label_submit'        => __( 'Add Example', 'wporg' ),
     66        'must_log_in'         => '<p>' . sprintf( __( 'You must <a href="%s">log in</a> before being able to submit an example.', 'wporg' ), 'https://wordpress.org/support/bb-login.php' ) . '</p>',
     67        'title_reply'         =>  '', //'Add Example'
     68    ) ); ?>
    7369
    7470</div><!-- #comments -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php

    r714 r724  
    9696        <h2><?php _e( 'Learn More', 'wporg' ); ?></h2>
    9797    </section>
    98     <hr/>
    99     <section class="examples">
    100         <h2><?php _e( 'Examples', 'wporg' ); ?></h2>
    101     </section>
    10298    */ ?>
    10399
     
    145141    <?php endif; ?>
    146142
     143    <?php if ( have_comments() || ( comments_open() && is_user_member_of_blog() ) ) : ?>
     144    <hr/>
     145    <section class="examples">
     146        <h2><?php _e( 'Examples', 'wporg' ); ?></h2>
     147        <?php get_template_part( 'code-example' ); ?>
     148    </section>
     149    <?php endif; ?>
     150
    147151<?php endif; ?>
    148152
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php

    r687 r724  
    8282            <h2><?php _e( 'Learn More', 'wporg' ); ?></h2>
    8383        </section>
     84        */ ?>
     85
     86        <?php if ( have_comments() || ( comments_open() && is_user_member_of_blog() ) ) : ?>
    8487        <hr/>
    8588        <section class="examples">
    8689            <h2><?php _e( 'Examples', 'wporg' ); ?></h2>
     90            <?php get_template_part( 'code-example' ); ?>
    8791        </section>
    88         */ ?>
     92        <?php endif; ?>
     93
    8994    <?php endif; ?>
    9095
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r688 r724  
    5555
    5656    // Temporarily disable comments
    57     add_filter( 'comments_open', '__return_false' );
     57    //add_filter( 'comments_open', '__return_false' );
    5858
    5959    add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
     60
     61    treat_comments_as_examples();
    6062}
    6163
     
    350352    }
    351353
    352     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    353         wp_enqueue_script( 'comment-reply' );
    354     }
    355 }
     354    if ( is_singular() && comments_open() ) {
     355        wp_enqueue_script( 'wporg-developer-code-examples', get_template_directory_uri() . '/js/code-example.js', array(), '20140423', true );
     356        if ( get_option( 'thread_comments' ) ) {
     357            wp_enqueue_script( 'comment-reply' );
     358        }
     359    }
     360}
     361
     362/**
     363 * Handles adding/removing hooks to enable comments as examples.
     364 *
     365 * Mostly gives users greater permissions in terms of comment content.
     366 *
     367 * In order to submit code examples, users must be able to post with less restrictions.
     368 */
     369function treat_comments_as_examples() {
     370    // Restricts commenting to logged in users.
     371    add_filter( 'comments_open', __NAMESPACE__ . '\\prevent_invalid_comment_submissions', 10, 2 );
     372
     373    if ( ! current_user_can( 'unfiltered_html' ) ) {
     374        remove_filter( 'pre_comment_content', 'wp_filter_kses'      );
     375        add_filter(    'pre_comment_content', 'wp_filter_post_kses' );
     376    }
     377
     378    // Force comment registration to be true
     379    add_filter( 'pre_option_comment_registration', '__return_true' );
     380
     381    // Force comment moderation to be true
     382    add_filter( 'pre_option_comment_moderation',   '__return_true' );
     383
     384    // Remove reply to link
     385    add_filter( 'comment_reply_link',              '__return_empty_string' );
     386
     387/*  foreach ( array( 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
     388        add_filter( $filter, 'balanceTags', 50 );
     389    }*/
     390
     391    remove_filter( 'comment_text',        'capital_P_dangit',   31 );
     392
     393    remove_filter( 'comment_text',        'wptexturize'            );
     394    remove_filter( 'comment_text',        'convert_chars'          );
     395    remove_filter( 'comment_text',        'make_clickable',      9 );
     396    remove_filter( 'comment_text',        'force_balance_tags', 25 );
     397    remove_filter( 'comment_text',        'convert_smilies',    20 );
     398    remove_filter( 'comment_text',        'wpautop',            30 );
     399
     400    remove_filter( 'pre_comment_content', 'wp_rel_nofollow',    15 );
     401}
     402
     403/**
     404 * Disables commenting to invalid or non-users.
     405 *
     406 * @param bool  $status Default commenting status for post.
     407 * @return bool False if commenter isn't a user, otherwise the passed in status.
     408 */
     409function prevent_invalid_comment_submissions( $status, $post_id ) {
     410    if ( $_POST && ( ! is_user_logged_in() || ! is_user_member_of_blog() ) ) {
     411        return false;
     412    }
     413
     414    return $status;
     415}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r722 r724  
    9393                <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
    9494                <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     95                    <div class="comment-content code-example-container">
     96                        <pre class="brush: php; toolbar: false;"><?php echo htmlentities( get_comment_text() ); ?></pre>
     97                    </div>
     98                    <!-- .comment-content -->
     99
    95100                    <footer class="comment-meta">
    96101                        <div class="comment-author vcard">
     102                            <span class="comment-author-attribution">
    97103                            <?php if ( 0 != $args['avatar_size'] ) {
    98104                                echo get_avatar( $comment, $args['avatar_size'] );
    99105                            } ?>
    100                             <?php printf( __( '%s <span class="says">says:</span>', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
    101                         </div>
    102                         <!-- .comment-author -->
    103 
    104                         <div class="comment-metadata">
    105                             <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
     106
     107                            <?php
     108                                // This would all be moot if core passed the $comment context for 'get_comment_author_link' filter
     109                                if ( $comment->user_id ) {
     110                                    $commenter = get_user_by( 'id', $comment->user_id );
     111                                    $url = 'https://profiles.wordpress.org/' . esc_attr( $commenter->user_nicename ) . '/';
     112                                    $author = get_the_author_meta( 'display_name', $comment->user_id );
     113                                    $comment_author_link = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     114                                } else {
     115                                    $comment_author_link = '';
     116                                }
     117                                printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) );
     118                            ?>
     119
     120                            </span>
     121                            &mdash;
     122                            Added on <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    106123                                <time datetime="<?php comment_time( 'c' ); ?>">
    107124                                    <?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'wporg' ), get_comment_date(), get_comment_time() ); ?>
     
    113130
    114131                        <?php if ( '0' == $comment->comment_approved ) : ?>
    115                             <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'wporg' ); ?></p>
     132                            <p class="comment-awaiting-moderation"><?php _e( 'Your example is awaiting moderation.', 'wporg' ); ?></p>
    116133                        <?php endif; ?>
    117134                    </footer>
    118135                    <!-- .comment-meta -->
    119 
    120                     <div class="comment-content">
    121                         <?php comment_text(); ?>
    122                     </div>
    123                     <!-- .comment-content -->
    124136
    125137                    <?php
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r687 r724  
    899899        list-style: none;
    900900        margin: 0 0 1.5em 0;
    901         border-top: 1px solid #eee;
    902901        padding: 0;
    903902    }
     
    906905        padding: 24px 24px 0 24px;
    907906        padding: 1.5rem 1.5rem 0 1.5rem;
    908         border: 1px solid #eee;
    909         border-top: none;
     907        border: 0 solid #eee;
     908        border-bottom-width: 1px;
    910909        background: #fff;
     910    }
     911
     912    .comment-list li:first-child {
     913        padding-top: 0;
    911914    }
    912915
     
    915918        width: 2.5em;
    916919        height: 2.5em;
    917         margin: 0 1em 0.5em 0;
     920        margin: -0.5em 1em 0.5em 0;
    918921        padding: 0.125em;
    919922        border: 1px solid #eee;
     923    }
     924
     925    .comment-author-attribution {
     926        font-weight: bold;
    920927    }
    921928
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/single.php

    r594 r724  
    2020            <?php //wporg_developer_post_nav(); ?>
    2121
    22             <?php
    23                 // If comments are open or we have at least one comment, load up the comment template
    24                 if ( comments_open() || '0' != get_comments_number() ) :
    25                     comments_template();
    26                 endif;
    27             ?>
    28 
    2922        <?php endwhile; // end of the loop. ?>
    3023
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r687 r724  
    11011101  list-style: none;
    11021102  margin: 0 0 1.5em 0;
    1103   border-top: 1px solid #eee;
    11041103  padding: 0;
    11051104}
     
    11071106  padding: 24px 24px 0 24px;
    11081107  padding: 1.5rem 1.5rem 0 1.5rem;
    1109   border: 1px solid #eee;
    1110   border-top: none;
     1108  border: 0 solid #eee;
     1109  border-bottom-width: 1px;
    11111110  background: #fff;
     1111}
     1112.devhub-wrap .comment-list li {
     1113  padding-top: 0;
    11121114}
    11131115.devhub-wrap .comment-list .avatar {
     
    11151117  width: 2.5em;
    11161118  height: 2.5em;
    1117   margin: 0 1em 0.5em 0;
     1119  margin: -0.5em 1em 0.5em 0;
    11181120  padding: 0.125em;
    11191121  border: 1px solid #eee;
     1122}
     1123.devhub-wrap .comment-author-attribution {
     1124  font-weight: bold;
    11201125}
    11211126.devhub-wrap .comment-meta {
Note: See TracChangeset for help on using the changeset viewer.