Skip to:
Content

bbPress.org

Changeset 2453


Ignore:
Timestamp:
07/01/2010 09:12:10 PM (16 years ago)
Author:
chrishajer
Message:

Fixes for anonymous posting. Fixes #1244. Props Nightgunner5, GautamGupta

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/defaults.bb-filters.php

    r2430 r2453  
    163163add_action( 'bb_new_post', 'bb_notify_subscribers' );
    164164
     165add_action( 'post_form_pre_post', 'bb_anonymous_post_form' );
     166
    165167unset( $filters, $filter );
  • trunk/bb-includes/functions.bb-capabilities.php

    r2147 r2453  
    2626    if ( empty($bb_current_user) ) {
    2727        $retvalue = false;
     28        if ( ( $capability == 'write_topic' || $capability == 'write_topics' ) && !bb_is_login_required() )
     29            $retvalue = true;
     30        if ( ( $capability == 'write_topic' || $capability == 'write_topics' ) && !bb_is_login_required() )
     31            $retvalue = true;
    2832    } else {
    2933        $retvalue = call_user_func_array(array(&$bb_current_user, 'has_cap'), $args);
  • trunk/bb-includes/functions.bb-deprecated.php

    r2363 r2453  
    11811181    }
    11821182}
     1183
     1184function bb_get_current_commenter() {
     1185    bb_log_deprecated( 'function', __FUNCTION__, 'bb_get_current_poster' );
     1186    extract( bb_get_current_poster() );
     1187    return array( 'comment_author' => $post_author, 'comment_email' => $post_author_email, 'comment_author_url' => $post_author_url );
     1188}
  • trunk/bb-includes/functions.bb-meta.php

    r2452 r2453  
    298298            break;
    299299        case 'version':
    300             return '1.1-alpha-2452'; // Don't filter
     300            return '1.1-alpha-2453'; // Don't filter
    301301            break;
    302302        case 'bb_db_version' :
  • trunk/bb-includes/functions.bb-posts.php

    r2452 r2453  
    55/**
    66 * Check to make sure that a user is not making too many posts in a short amount of time.
    7  *
    8  * @todo Add logic for users not logged in.
    97 *
    108 * @param string $ip Comment IP.
     
    2018        return;
    2119    }
    22 
    23     $hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 );
    2420
    2521    if ( bb_is_user_logged_in() ) {
     
    3430        }
    3531    } else {
    36         // todo: add logic for non-logged-in users
     32        if ( ( $last_posted = bb_get_transient($_SERVER['REMOTE_ADDR'] . '_last_posted') ) && time() < $last_posted + $throttle_time ) {
     33            if ( defined('DOING_AJAX') && DOING_AJAX ) {
     34                die(__('Slow down; you move too fast.'));
     35            } else {
     36                bb_die(__('Slow down; you move too fast.'));
     37            }
     38        }
    3739    }
    3840}
    3941
    4042/**
    41  * Get the current, non-logged-in commenter data.
     43 * Get the current, non-logged-in poster data.
    4244 * @return array The associative array of author, email, and url data.
    4345 */
    44 function bb_get_current_commenter() {
     46function bb_get_current_poster() {
    4547    // Cookies should already be sanitized.
    46     $comment_author = '';
    47     if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) )
    48         $comment_author = $_COOKIE['comment_author_'.COOKIEHASH];
    49 
    50     $comment_author_email = '';
    51     if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) )
    52         $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];
    53 
    54     $comment_author_url = '';
    55     if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) )
    56         $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH];
    57 
    58     return compact('comment_author', 'comment_author_email', 'comment_author_url');
     48    $post_author = '';
     49    if ( isset( $_COOKIE['post_author_'.COOKIEHASH] ) )
     50        $post_author = $_COOKIE['post_author_'.COOKIEHASH];
     51
     52    $post_author_email = '';
     53    if ( isset( $_COOKIE['post_author_email_'.COOKIEHASH] ) )
     54        $post_author_email = $_COOKIE['post_author_email_'.COOKIEHASH];
     55
     56    $post_author_url = '';
     57    if ( isset( $_COOKIE['post_author_url_'.COOKIEHASH] ) )
     58        $post_author_url = $_COOKIE['post_author_url_'.COOKIEHASH];
     59
     60    return compact( 'post_author', 'post_author_email', 'post_author_url' );
    5961}
    6062
     
    412414
    413415        // if user not logged in, save user data as meta data
    414         if ( ! bb_is_user_logged_in() && ! bb_is_login_required() ) {
     416        if ( !$user ) {
    415417            bb_update_meta($post_id, 'post_author', $post_author, 'post');
    416418            bb_update_meta($post_id, 'post_email', $post_email, 'post');
     
    440442    bb_update_topic_voices( $topic_id );
    441443   
    442     if ( $throttle && !bb_current_user_can( 'throttle' ) )
    443         bb_update_usermeta( $poster_id, 'last_posted', time() );
     444    if ( $throttle && !bb_current_user_can( 'throttle' ) ) {
     445        if ( $user )
     446            bb_update_usermeta( $poster_id, 'last_posted', time() );
     447        else
     448            bb_set_transient( $_SERVER['REMOTE_ADDR'] . '_last_posted', time() );
     449    }
    444450
    445451    wp_cache_delete( $topic_id, 'bb_topic' );
  • trunk/bb-includes/functions.bb-template.php

    r2440 r2453  
    331331    echo "\n" . '</fieldset>' . "\n" . '</form>' . "\n";
    332332    do_action('post_edit_form');
     333}
     334
     335function bb_anonymous_post_form() {
     336    if ( !bb_is_user_logged_in() && !bb_is_login_required() )
     337        bb_load_template( 'post-form-anonymous.php' );
    333338}
    334339
     
    12031208function get_topic_last_poster( $id = 0 ) {
    12041209    $topic = get_topic( get_topic_id( $id ) );
    1205     $user_display_name = get_user_display_name($topic->topic_last_poster);
     1210    $user_display_name = get_post_author( $topic->topic_last_post_id );
    12061211    return apply_filters( 'get_topic_last_poster', $user_display_name, $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID
    12071212}
     
    12141219function get_topic_author( $id = 0 ) {
    12151220    $topic = get_topic( get_topic_id( $id ) );
    1216     $user_display_name = get_user_display_name($topic->topic_poster);
     1221    $first_post = bb_get_first_post( $topic );
     1222    $user_display_name = get_post_author( $first_post->post_id );
    12171223    return apply_filters( 'get_topic_author', $user_display_name, $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID
    12181224}
     
    16011607        $url = bb_get_uri(null, array('new' => 1));
    16021608
    1603     if ( !bb_is_user_logged_in() )
     1609    if ( !bb_is_user_logged_in() && bb_is_login_required() )
    16041610        $url = bb_get_uri('bb-login.php', array('redirect_to' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS);
    16051611    elseif ( bb_is_forum() || bb_is_topic() ) {
     
    17621768    if ( $user = bb_get_user( get_post_author_id( $post_id ) ) )
    17631769        return apply_filters( 'get_post_author', $user->display_name, $user->ID, $post_id );
    1764     elseif ( $title = bb_get_post_meta( 'pingback_title' ) )
     1770    elseif ( $title = bb_get_post_meta( 'pingback_title', $post_id ) )
    17651771        return apply_filters( 'bb_get_pingback_title', $title, $post_id );
    1766     elseif ( $title = bb_get_post_meta( 'post_author' ) )
     1772    elseif ( $title = bb_get_post_meta( 'post_author', $post_id ) )
    17671773        return apply_filters( 'get_post_author', $title, 0, $post_id );
    17681774    else
  • trunk/bb-includes/functions.bb-topics.php

    r2425 r2453  
    176176    $forum_id = (int) $forum->forum_id;
    177177
    178     if ( !$user = bb_get_user( $topic_poster ) )
    179         if ( !$user = bb_get_user( $topic_poster_name, array( 'by' => 'login' ) ) )
    180             return false;
    181     $topic_poster = $user->ID;
    182     $topic_poster_name = $user->user_login;
    183 
    184     if ( !$last_user = bb_get_user( $topic_last_poster ) )
    185         if ( !$last_user = bb_get_user( $topic_last_poster_name, array( 'by' => 'login' ) ) )
    186             return false;
    187     $topic_last_poster = $last_user->ID;
    188     $topic_last_poster_name = $last_user->user_login;
     178    if ( bb_is_user_logged_in() || bb_is_login_required() ) {
     179        if ( !$user = bb_get_user( $topic_poster ) )
     180            if ( !$user = bb_get_user( $topic_poster_name, array( 'by' => 'login' ) ) )
     181                return false;
     182        $topic_poster = $user->ID;
     183        $topic_poster_name = $user->user_login;
     184
     185        if ( !$last_user = bb_get_user( $topic_last_poster ) )
     186            if ( !$last_user = bb_get_user( $topic_last_poster_name, array( 'by' => 'login' ) ) )
     187                return false;
     188        $topic_last_poster = $last_user->ID;
     189        $topic_last_poster_name = $last_user->user_login;
     190    }
    189191
    190192    if ( in_array( 'topic_title', $fields ) ) {
     
    235237
    236238// Deprecated: expects $title to be pre-escaped
    237 function bb_new_topic( $title, $forum, $tags = '' ) {
     239function bb_new_topic( $title, $forum, $tags = '', $args = '' ) {
    238240    $title = stripslashes( $title );
    239241    $tags  = stripslashes( $tags );
    240242    $forum = (int) $forum;
    241     return bb_insert_topic( array( 'topic_title' => $title, 'forum_id' => $forum, 'tags' => $tags ) );
     243    return bb_insert_topic( wp_parse_args( $args ) + array( 'topic_title' => $title, 'forum_id' => $forum, 'tags' => $tags ) );
    242244}
    243245
  • trunk/bb-post.php

    r2415 r2453  
    4747        bb_die(__('Please enter a topic title'));
    4848
    49     $topic_id = bb_new_topic( $topic, $forum_id, $tags );
     49    $args = array();
     50
     51    if ( isset( $post_author ) )
     52        $args['topic_poster_name'] = $args['topic_last_poster_name'] = $post_author;
     53
     54    $topic_id = bb_new_topic( $topic, $forum_id, $tags, $args );
    5055
    5156} elseif ( isset($_POST['topic_id'] ) ) {
     
    8994    wp_redirect( bb_get_uri(null, null, BB_URI_CONTEXT_HEADER) );
    9095exit;
    91 
    92 ?>
  • trunk/bb-templates/kakumei/post-form.php

    r2390 r2453  
    66</p>
    77<?php endif; do_action( 'post_form_pre_post' ); ?>
    8 <?php if ( ! bb_is_user_logged_in() && ! bb_is_login_required() )  :
    9     $current_commenter = bb_get_current_commenter();
    10 ?>
    11     <p id="post-form-author-container">
    12         <label for="author"><?php _e('Author (required)'); ?>
    13             <input type="text" name="author" id="author" size="50" aria-required="true" value="<?php echo esc_attr($current_commenter['comment_author']); ?>" />
    14         </label>
    15     </p>
    16 
    17     <p id="post-form-email-container">
    18         <label for="email"><?php _e('Email (required)'); ?>
    19             <input type="text" name="email" id="email" size="50" aria-required="true" value="<?php echo esc_attr($current_commenter['comment_author_email']); ?>" />
    20         </label>
    21     </p>
    22 
    23     <p id="post-form-url-container">
    24         <label for="url"><?php _e('URL'); ?>
    25             <input type="text" name="url" id="url" size="50" aria-required="true" value="<?php echo esc_attr($current_commenter['comment_author_url']); ?>" />
    26         </label>
    27 
    28     </p>
    29 <?php endif; // end user not logged in but logins aren't required ?>
    308
    319<p id="post-form-post-container">
Note: See TracChangeset for help on using the changeset viewer.