Skip to:
Content

bbPress.org

Changeset 2670


Ignore:
Timestamp:
12/03/2010 10:48:46 AM (16 years ago)
Author:
johnjamesjacoby
Message:

First pass at anonymous posting. Fixes #1363 props !Kaspace from Google Code-in

Location:
branches/plugin
Files:
1 added
7 edited

Legend:

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

    r2651 r2670  
    311311<?php if ( bbp_is_forum() || bbp_is_topic() || bbp_is_reply() ) : ?>
    312312
    313                         .column-author, .column-bbp_forum_topic_count, .column-bbp_forum_reply_count, .column-bbp_topic_forum, .column-bbp_topic_reply_count, .column-bbp_topic_voice_count, .column-bbp_reply_topic, .column-bbp_reply_forum { width: 10% !important; }
    314                         .column-bbp_forum_freshness, .column-bbp_topic_freshness, .column-bbp_reply_posted { width: 15% !important; }
     313                        .column-author, .column-bbp_forum_topic_count, .column-bbp_forum_reply_count, .column-bbp_topic_forum, .column-bbp_topic_reply_count, .column-bbp_topic_voice_count, .column-bbp_reply_forum { width: 10% !important; }
     314                        .column-bbp_forum_freshness, .column-bbp_topic_freshness, .column-bbp_reply_posted, .column-bbp_topic_author, .column-bbp_reply_author, .column-bbp_reply_topic { width: 15% !important; }
    315315
    316316<?php endif; ?>
     
    455455                        'bbp_topic_reply_count' => __( 'Replies', 'bbpress' ),
    456456                        'bbp_topic_voice_count' => __( 'Voices', 'bbpress' ),
    457                         'author'                => __( 'Author', 'bbpress' ),
     457                        'bbp_topic_author'      => __( 'Author', 'bbpress' ),
    458458                        'bbp_topic_freshness'   => __( 'Freshness', 'bbpress' )
    459459                );
     
    510510                                break;
    511511
     512                        // Author
     513                        case 'bbp_topic_author' :
     514                                bbp_topic_author_display_name ( $topic_id );
     515                                break;
     516
    512517                        // Freshness
    513518                        case 'bbp_topic_freshness' :
     
    557562                        'bbp_reply_forum'       => __( 'Forum', 'bbpress' ),
    558563                        'bbp_reply_topic'       => __( 'Topic', 'bbpress' ),
    559                         'author'                => __( 'Author', 'bbpress' ),
     564                        'bbp_reply_author'      => __( 'Author', 'bbpress' ),
    560565                        'bbp_reply_posted'      => __( 'Posted' , 'bbpress' ),
    561566                );
     
    622627                                //echo '<div class="row-actions">' . implode( ' | ', $formatted_actions ) . '</div>';
    623628
     629                                break;
     630
     631                        // Author
     632                        case 'bbp_reply_author' :
     633                                bbp_reply_author_display_name ( $reply_id );
    624634                                break;
    625635
  • branches/plugin/bbp-includes/bbp-functions.php

    r2668 r2670  
    9595
    9696                // Check users ability to create new reply
    97                 if ( !current_user_can( 'publish_replies' ) || ( !is_user_logged_in() && !bbp_allow_anonymous() ) )
    98                         return false;
     97                if ( !$is_anonymous = bbp_is_anonymous() )
     98                        if ( !current_user_can( 'publish_replies' ) )
     99                                return false;
    99100
    100101                // Nonce check
     
    133134
    134135                        // Insert reply
    135                         $reply_id = wp_insert_post( $reply_data );
    136 
     136                        $reply_id         = wp_insert_post( $reply_data );
     137                        $reply_data['ID'] = $reply_id;
     138
     139                        // If anonymous post, store name, email and website in post_meta
     140                        // @todo - validate
     141                        if ( true == $is_anonymous ) {
     142                                add_post_meta( $reply_id, '_bbp_anonymous_name',    $_POST['bbp_anonymous_name'],    false );
     143                                add_post_meta( $reply_id, '_bbp_anonymous_email',   $_POST['bbp_anonymous_email'],   false );
     144                                add_post_meta( $reply_id, '_bbp_anonymous_website', $_POST['bbp_anonymous_website'], false );
     145                                add_post_meta( $reply_id, '_bbp_anonymous_ip',      $_POST['bbp_anonymous_ip'],      false );
     146                        }
     147                       
    137148                        // Update counts, etc...
    138149                        do_action( 'bbp_new_reply', $reply_data );
     
    177188
    178189                // Check users ability to create new topic
    179                 if ( !current_user_can( 'publish_topics' ) || ( !is_user_logged_in() && !bbp_allow_anonymous() ) )
    180                         return false;
     190                if ( !$is_anonymous = bbp_is_anonymous() )
     191                        if ( !current_user_can( 'publish_topics' ) )
     192                                return false;
    181193
    182194                // Nonce check
     
    229241                        $topic_id = wp_insert_post( $topic_data );
    230242
     243                        // If anonymous post, store name, email and website in post_meta
     244                        // @todo - validation
     245                        if ( true == $is_anonymous ) {
     246                                add_post_meta( $topic_id, '_bbp_anonymous_name',    $_POST['bbp_anonymous_name'],    false );
     247                                add_post_meta( $topic_id, '_bbp_anonymous_email',   $_POST['bbp_anonymous_email'],   false );
     248                                add_post_meta( $topic_id, '_bbp_anonymous_website', $_POST['bbp_anonymous_website'], false );
     249                                add_post_meta( $topic_id, '_bbp_anonymous_ip',      $_POST['bbp_anonymous_ip'],      false );
     250                        }
     251                       
    231252                        // Update counts, etc...
    232253                        do_action( 'bbp_new_topic', $topic_data );
     
    551572 * @return bool True on success, false on failure
    552573 */
    553 function bbp_notify_subscribers ( $reply_id = 0 ) {
     574function bbp_notify_subscribers ( $args = '' ) {
    554575        global $bbp, $wpdb;
    555576
     
    557578                return false;
    558579
    559         if ( !$reply = get_post( $reply_id ) )
     580        $defaults = array (
     581                'ID'            => bbp_get_reply_id(),
     582                'post_author'   => bbp_get_current_user_id(),
     583                'post_title'    => '',
     584                'post_content'  => '',
     585                'post_parent'   => '',
     586                'post_status'   => 'publish',
     587                'post_type'     => $bbp->reply_id
     588        );
     589
     590        $args = wp_parse_args( $args, $defaults );
     591
     592        if ( !$reply = get_post( $args['ID'] ) )
    560593                return false;
    561594
     
    568601        $reply_id = $reply->ID;
    569602        $topic_id = $topic->ID;
    570 
    571         if ( !$poster_name = get_the_author_meta( 'display_name', $reply->post_author ) )
    572                 return false;
    573603
    574604        do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id );
  • branches/plugin/bbp-includes/bbp-template.php

    r2668 r2670  
    13251325                $topic_id = bbp_get_topic_id( $topic_id );
    13261326
    1327                 return apply_filters( 'bbp_get_topic_author', get_the_author() );
     1327                if ( get_post_field( 'post_author', $topic_id ) )
     1328                        $author = get_the_author();
     1329                else
     1330                        $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
     1331
     1332                return apply_filters( 'bbp_get_topic_author', $author );
    13281333        }
    13291334
     
    13951400                $topic_id = bbp_get_topic_id( $topic_id );
    13961401
    1397                 return apply_filters( 'bbp_get_topic_author_id', esc_attr( get_the_author_meta( 'display_name' ) ) );
     1402                // Check for anonymous user
     1403                if ( $author_id = get_post_field( 'post_author', $topic_id ) )
     1404                        $author_name = get_the_author_meta( 'display_name', $author_id );
     1405                else
     1406                        $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
     1407
     1408                return apply_filters( 'bbp_get_topic_author_id', esc_attr( $author_name ) );
    13981409        }
    13991410
     
    14651476                $topic_id = bbp_get_topic_id( $topic_id );
    14661477
    1467                 return apply_filters( 'bbp_get_topic_author_url', get_author_posts_url( get_post_field( 'post_author', $topic_id ) ) );
     1478                // Check for anonymous user
     1479                if ( $author_id = get_post_field( 'post_author', $topic_id ) )
     1480                        $author_url = get_author_posts_url( $author_id );
     1481                else
     1482                        $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );
     1483
     1484                return apply_filters( 'bbp_get_topic_author_url', $author_url );
    14681485        }
    14691486
     
    23922409                $reply_id = bbp_get_reply_id( $reply_id );
    23932410
    2394                 return apply_filters( 'bbp_get_reply_author', get_the_author() );
     2411                if ( get_post_field( 'post_author', $reply_id ) )
     2412                        $author = get_the_author();
     2413                else
     2414                        $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
     2415
     2416                return apply_filters( 'bbp_get_reply_author', $author );
    23952417        }
    23962418
     
    24622484                $reply_id = bbp_get_reply_id( $reply_id );
    24632485
    2464                 return apply_filters( 'bbp_get_reply_author_id', esc_attr( get_the_author_meta( 'display_name' ) ) );
     2486                // Check for anonymous user
     2487                if ( $author_id = get_post_field( 'post_author', $reply_id ) )
     2488                        $author_name = get_the_author_meta( 'display_name', $author_id );
     2489                else
     2490                        $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
     2491
     2492                return apply_filters( 'bbp_get_reply_author_id', esc_attr( $author_name ) );
    24652493        }
    24662494
     
    25322560                $reply_id = bbp_get_reply_id( $reply_id );
    25332561
    2534                 return apply_filters( 'bbp_get_reply_author_url', get_author_posts_url( get_post_field( 'post_author', $reply_id ) ) );
     2562                // Check for anonymous user
     2563                if ( $author_id = get_post_field( 'post_author', $reply_id ) )
     2564                        $author_url = get_author_posts_url( $author_id );
     2565                else
     2566                        $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true );
     2567
     2568                return apply_filters( 'bbp_get_reply_author_url', $author_url );
    25352569        }
    25362570
     
    28582892
    28592893        return apply_filters( 'bbp_is_user_home', $retval, $current_user );
     2894}
     2895
     2896/**
     2897 * bbp_is_anonymous ()
     2898 *
     2899 * Return true if anonymous is allowed and user is not logged in.
     2900 * Return false if anonymous is not allowed or user is logged in
     2901 *
     2902 * @return bool
     2903 */
     2904function bbp_is_anonymous () {
     2905        if ( !is_user_logged_in() && bbp_allow_anonymous() )
     2906                $is_anonymous = true;
     2907        else
     2908                $is_anonymous = false;
     2909
     2910        return apply_filters( 'bbp_is_anonymous', $is_anonymous );
    28602911}
    28612912
     
    31003151                        $current_user_id = $current_user->ID;
    31013152                else
    3102                         $current_user_id = -1;
     3153                        $current_user_id = 0;
    31033154
    31043155                return apply_filters( 'bbp_get_current_user_id', $current_user_id );
  • branches/plugin/bbp-themes/bbp-twentyten/form-bbp_reply.php

    r2668 r2670  
    1414
    1515                                <div class="alignleft">
     16
     17                                        <?php get_template_part( 'form', 'bbp_anonymous' ); ?>
     18
    1619                                        <p>
    1720                                                <label for="bbp_reply_content"><?php _e( 'Reply:', 'bbpress' ); ?></label><br />
    18                                                 <textarea id="bbp_reply_content" tabindex="3" name="bbp_reply_content" cols="52" rows="6"></textarea>
     21                                                <textarea id="bbp_reply_content" tabindex="8" name="bbp_reply_content" cols="52" rows="6"></textarea>
    1922                                        </p>
    2023
    2124                                        <p>
    2225                                                <label for="bbp_topic_tags"><?php _e( 'Tags:', 'bbpress' ); ?></label><br />
    23                                                 <input id="bbp_topic_tags" type="text" value="" tabindex="5" size="40" name="bbp_topic_tags" id="post_tags" />
     26                                                <input id="bbp_topic_tags" type="text" value="" tabindex="10" size="40" name="bbp_topic_tags" id="post_tags" />
    2427                                        </p>
    2528
    26                                         <?php if ( bbp_is_subscriptions_active() ) : ?>
     29                                        <?php if ( bbp_is_subscriptions_active() && !bbp_is_anonymous() ) : ?>
    2730
    2831                                                <p>
    29                                                         <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe"<?php checked( true, bbp_is_user_subscribed() ); ?> tabindex="7" />
     32                                                        <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe"<?php checked( true, bbp_is_user_subscribed() ); ?> tabindex="12" />
    3033                                                        <label for="bbp_topic_subscription"><?php _e( 'Notify me of follow-up replies via email', 'bbpress' ); ?></label>
    3134                                                </p>
     
    3437
    3538                                        <p align="right">
    36                                                 <button type="submit" tabindex="9" id="bbp_reply_submit" name="bbp_reply_submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
     39                                                <button type="submit" tabindex="14" id="bbp_reply_submit" name="bbp_reply_submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
    3740                                        </p>
    3841                                </div>
  • branches/plugin/bbp-themes/bbp-twentyten/form-bbp_topic.php

    r2668 r2670  
    1414
    1515                                <div class="alignleft">
     16
     17                                        <?php get_template_part( 'form', 'bbp_anonymous' ); ?>
     18
    1619                                        <p>
    1720                                                <label for="bbp_topic_title"><?php _e( 'Title:', 'bbpress' ); ?></label><br />
    18                                                 <input type="text" id="bbp_topic_title" value="" tabindex="1" size="40" name="bbp_topic_title" />
     21                                                <input type="text" id="bbp_topic_title" value="" tabindex="8" size="40" name="bbp_topic_title" />
    1922                                        </p>
    2023
    2124                                        <p>
    2225                                                <label for="bbp_topic_content"><?php _e( 'Topic:', 'bbpress' ); ?></label><br />
    23                                                 <textarea id="bbp_topic_content" tabindex="3" name="bbp_topic_content" cols="52" rows="6"></textarea>
     26                                                <textarea id="bbp_topic_content" tabindex="10" name="bbp_topic_content" cols="52" rows="6"></textarea>
    2427                                        </p>
    2528
    2629                                        <p>
    2730                                                <label for="bbp_topic_tags"><?php _e( 'Tags:', 'bbpress' ); ?></label><br />
    28                                                 <input type="text" value="" tabindex="5" size="40" name="bbp_topic_tags" id="post_tags" />
     31                                                <input type="text" value="" tabindex="12" size="40" name="bbp_topic_tags" id="post_tags" />
    2932                                        </p>
    3033
     
    3841                                        <?php endif; ?>
    3942
    40                                         <?php if ( bbp_is_subscriptions_active() ) : ?>
     43                                        <?php if ( bbp_is_subscriptions_active() && !bbp_is_anonymous() ) : ?>
    4144
    4245                                                <p>
    43                                                         <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" tabindex="9" />
     46                                                        <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" tabindex="16" />
    4447                                                        <label for="bbp_topic_subscription"><?php _e( 'Notify me of follow-up replies via email', 'bbpress' ); ?></label>
    4548                                                </p>
     
    4851
    4952                                        <p align="right">
    50                                                 <button type="submit" tabindex="11" id="bbp_topic_submit" name="bbp_topic_submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
     53                                                <button type="submit" tabindex="18" id="bbp_topic_submit" name="bbp_topic_submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
    5154                                        </p>
    5255                                </div>
  • branches/plugin/bbp-themes/bbp-twentyten/loop-bbp_replies.php

    r2667 r2670  
    6161                                                        printf (
    6262                                                                '<a href="%1$s" title="%2$s">%3$s</a>',
    63                                                                 get_author_posts_url( get_the_author_meta( 'ID' ) ),
    64                                                                 sprintf( __( 'View %s\'s profile' ), bbp_get_reply_author_display_name() ),
     63                                                                bbp_get_reply_author_url(),
     64                                                                sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s Website' ), bbp_get_reply_author_display_name() ),
    6565                                                                bbp_get_reply_author_avatar( 0, 80 )
    6666                                                        );
  • branches/plugin/bbp-themes/bbp-twentyten/single-bbp_topic.php

    r2668 r2670  
    6868                                                                                <td class="bbp-topic-author">
    6969
    70                                                                                         <?php bbp_topic_author_avatar( 0, 100 ); ?>
     70                                                                                        <?php
     71                                                                                                // @todo - abstract
     72                                                                                                printf (
     73                                                                                                        '<a href="%1$s" title="%2$s">%3$s</a>',
     74                                                                                                        bbp_get_topic_author_url(),
     75                                                                                                        sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s Website' ), bbp_get_topic_author_display_name() ),
     76                                                                                                        bbp_get_topic_author_avatar( 0, 100 )
     77                                                                                                );
     78                                                                                        ?>
    7179
    7280                                                                                </td>
Note: See TracChangeset for help on using the changeset viewer.