Skip to:
Content

bbPress.org

Changeset 2390


Ignore:
Timestamp:
01/13/2010 09:47:16 PM (12 years ago)
Author:
filosofo
Message:

Adding most anon posting functionality; fixes #1239

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-admin/options-discussion.php

    r2264 r2390  
    1010    if (!isset($_POST['enable_pingback'])) {
    1111        $_POST['enable_pingback'] = false;
     12    }
     13
     14    if (!isset($_POST['enable_loginless'])) {
     15        $_POST['enable_loginless'] = false;
    1216    }
    1317   
     
    3943}
    4044
    41 $remote_options = array(
     45$general_options = array(
    4246    'enable_pingback' => array(
    4347        'title' => __( 'Enable Pingbacks' ),
     
    4650            1 => __( 'Allow link notifications from other sites.' )
    4751        )
     52    ),
     53
     54    'enable_loginless' => array(
     55        'title' => __( 'Enable Login-less Posting' ),
     56        'type' => 'checkbox',
     57        'options' => array(
     58            1 => __( 'Allow users to create topics and posts without logging in.' )
     59        ),
    4860    ),
    4961);
     
    102114    <fieldset>
    103115<?php
    104 foreach ( $remote_options as $option => $args ) {
     116foreach ( $general_options as $option => $args ) {
    105117    bb_option_form_element( $option, $args );
    106118}
  • trunk/bb-includes/functions.bb-meta.php

    r2387 r2390  
    466466        'wp_plugins_cookie_path',
    467467        'wordpress_mu_primary_blog_id',
     468        'enable_loginless',
    468469        'enable_xmlrpc',
    469470        'enable_pingback',
  • trunk/bb-includes/functions.bb-posts.php

    r2388 r2390  
    22
    33/* Posts */
     4
     5/**
     6 * 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.
     9 *
     10 * @param string $ip Comment IP.
     11 * @param string $email Comment author email address.
     12 * @param string $date MySQL time string.
     13 */
     14function bb_check_comment_flood( $ip = '', $email = '', $date = '' ) {
     15    global $bbdb;
     16    $user_id = (int) $user_id;
     17    $throttle_time = bb_get_option( 'throttle_time' );
     18
     19    if ( bb_current_user_can('manage_options') || empty( $throttle_time ) ) {
     20        return;
     21    }
     22
     23    $hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 );
     24
     25    if ( bb_is_user_logged_in() ) {
     26        $bb_current_user = bb_get_current_user();
     27       
     28        if ( isset($bb_current_user->data->last_posted) && time() < $bb_current_user->data->last_posted + $throttle_time && ! bb_current_user_can('throttle') ) {
     29            if ( defined('DOING_AJAX') && DOING_AJAX ) {
     30                die(__('Slow down; you move too fast.'));
     31            } else {
     32                bb_die(__('Slow down; you move too fast.'));
     33            }
     34        }
     35    } else {
     36        // todo: add logic for non-logged-in users
     37    }
     38}
     39
     40/**
     41 * Get the current, non-logged-in commenter data.
     42 * @return array The associative array of author, email, and url data.
     43 */
     44function bb_get_current_commenter() {
     45    // 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');
     59}
    460
    561function bb_get_post( $post_id ) {
     
    301357    extract( wp_parse_args( $args, $defaults ) );
    302358
     359    if ( isset( $post_author ) ) {
     360        $post_author = sanitize_user($post_author);
     361    }
     362
     363    if ( isset( $post_email ) ) {
     364        $post_email = sanitize_email($post_email);
     365    }
     366
     367    if ( isset( $post_url ) ) {
     368        $post_url = esc_url($post_url);
     369    }
     370
    303371    if ( !$topic = get_topic( $topic_id ) )
    304372        return false;
    305373
    306     if ( !$user = bb_get_user( $poster_id ) )
     374    if ( bb_is_login_required() && ! $user = bb_get_user( $poster_id ) )
    307375        return false;
    308376
     
    331399        $post_id = $topic_last_post_id = (int) $bbdb->insert_id;
    332400
     401        // if user not logged in, save user data as meta data
     402        if ( ! bb_is_user_logged_in() && ! bb_is_login_required() ) {
     403            bb_update_meta($post_id, 'post_author', $post_author, 'post');
     404            bb_update_meta($post_id, 'post_email', $post_email, 'post');
     405            bb_update_meta($post_id, 'post_url', $post_url, 'post');
     406        }
     407
    333408        if ( 0 == $post_status ) {
    334409            $topic_time = $post_time;
    335             $topic_last_poster = $poster_id;
    336             $topic_last_poster_name = $user->user_login;
     410            $topic_last_poster = ( ! bb_is_user_logged_in() && ! bb_is_login_required() ) ? -1 : $poster_id;
     411            $topic_last_poster_name = ( ! bb_is_user_logged_in() && ! bb_is_login_required() ) ? $post_author : $user->user_login;
    337412
    338413            $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->forums SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id ) );
  • trunk/bb-includes/functions.bb-template.php

    r2387 r2390  
    292292
    293293    if (
     294        ( false === bb_is_login_required() ) ||
    294295        ( bb_is_topic() && bb_current_user_can( 'write_post', $topic->topic_id ) && ( $page == $last_page || !$last_page_only ) ) ||
    295296        ( !bb_is_topic() && bb_current_user_can( 'write_topic', isset( $forum->forum_id ) ? $forum->forum_id : 0 ) )
     
    426427function bb_is_forum() {
    427428    return 'forum-page' == bb_get_location();
     429}
     430
     431/**
     432 * Whether a user is required to log in in order to create posts and forums.
     433 * @return bool Whether a user must be logged in.
     434 */
     435function bb_is_login_required() {
     436    return ! (bool) bb_get_option('enable_loginless');
    428437}
    429438
     
    17361745    elseif ( $title = bb_get_post_meta( 'pingback_title' ) )
    17371746        return apply_filters( 'bb_get_pingback_title', $title, $post_id );
     1747    elseif ( $title = bb_get_post_meta( 'post_author' ) )
     1748        return apply_filters( 'get_post_author', $title, 0, $post_id );
    17381749    else
    17391750        return apply_filters( 'get_post_author', __('Anonymous'), 0, $post_id );
     
    17441755        echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>';
    17451756    } elseif ( $link = bb_get_post_meta( 'pingback_uri' )) {
     1757        echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>';
     1758    } elseif ( $link = bb_get_post_meta( 'post_url' ) ) {
    17461759        echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>';
    17471760    } else {
  • trunk/bb-post.php

    r2075 r2390  
    22require('./bb-load.php');
    33
    4 bb_auth('logged_in');
     4if ( bb_is_login_required() ) {
     5    bb_auth('logged_in');
     6}
    57
    6 if ( $throttle_time = bb_get_option( 'throttle_time' ) )
    7     if ( isset($bb_current_user->data->last_posted) && time() < $bb_current_user->data->last_posted + $throttle_time && !bb_current_user_can('throttle') )
    8         bb_die(__('Slow down; you move too fast.'));
     8bb_check_comment_flood();
    99
    1010if ( !$post_content = trim($_POST['post_content']) )
    1111    bb_die(__('You need to actually submit some content!'));
    1212
     13$post_author = $post_email = $post_url = '';
     14
     15if ( ! bb_is_user_logged_in() ) {
     16    if ( bb_is_login_required() ) {
     17        bb_die(__('You are not allowed to post.  Are you logged in?'));
     18    } else {
     19        if ( ! $post_author = trim($_POST['author']) ) {
     20            bb_die(__('You need to submit your name!'));
     21        } elseif ( ! $post_email = trim($_POST['email']) ) {
     22            bb_die(__('You need to submit your email!'));
     23        }
     24
     25        if ( ! empty( $_POST['url'] ) ) {
     26            $post_url = trim($_POST['url']);
     27        }
     28    }
     29}
     30
     31
     32
     33
    1334if ( isset($_POST['topic']) && $forum_id = (int) $_POST['forum_id'] ) {
    14     if ( !bb_current_user_can('write_posts') )
     35    if ( bb_is_login_required() && ! bb_current_user_can('write_posts') )
    1536        bb_die(__('You are not allowed to post.  Are you logged in?'));
    1637
    17     if ( !bb_current_user_can( 'write_topic', $forum_id ) )
     38    if ( bb_is_login_required() && ! bb_current_user_can( 'write_topic', $forum_id ) )
    1839        bb_die(__('You are not allowed to write new topics.'));
    1940
     
    3354}
    3455
    35 if ( !bb_current_user_can( 'write_post', $topic_id ) )
     56if ( bb_is_login_required() && ! bb_current_user_can( 'write_post', $topic_id ) )
    3657    bb_die(__('You are not allowed to post.  Are you logged in?'));
    3758
     
    3960    bb_die(__('This topic has been closed'));
    4061
    41 $post_id = bb_new_post( $topic_id, $_POST['post_content'] );
     62$post_data = array(
     63    'post_text' => stripslashes($_POST['post_content']),
     64    'topic_id' => $topic_id,
     65);
     66
     67foreach( array('post_author', 'post_email', 'post_url') as $field ) {
     68    if ( ! empty( $$field ) ) {
     69        $post_data[$field] = $$field;
     70    }
     71}
     72
     73$post_id = bb_insert_post($post_data);
    4274
    4375$tags  = trim( $_POST['tags']  );
  • trunk/bb-templates/kakumei/post-form.php

    r2351 r2390  
    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 ?>
     30
    831<p id="post-form-post-container">
    932    <label for="post_content"><?php _e('Post'); ?>
  • trunk/bb-templates/kakumei/style.css

    r2349 r2390  
    593593.postform label { display: block; }
    594594
     595.postform #author,
     596.postform #email,
    595597.postform #topic,
    596 .postform #tags-input {
     598.postform #tags-input,
     599.postform #url {
    597600    margin: 5px 0;
    598601    padding: 5px;
Note: See TracChangeset for help on using the changeset viewer.