Ticket #1239: loginless_posting.1.1239.diff
File loginless_posting.1.1239.diff, 11.7 KB (added by , 14 years ago) |
---|
-
bb-templates/kakumei/style.css
592 592 593 593 .postform label { display: block; } 594 594 595 .postform #author, 596 .postform #email, 595 597 .postform #topic, 596 .postform #tags-input { 598 .postform #tags-input, 599 .postform #url { 597 600 margin: 5px 0; 598 601 padding: 5px; 599 602 width: 724px; … … 1008 1011 1009 1012 p.submit input:active { 1010 1013 border-color: rgb(0, 100, 0); 1011 } 1012 No newline at end of file 1014 } -
bb-templates/kakumei/post-form.php
5 5 </label> 6 6 </p> 7 7 <?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 8 31 <p id="post-form-post-container"> 9 32 <label for="post_content"><?php _e('Post'); ?> 10 33 <textarea name="post_content" cols="50" rows="8" id="post_content" tabindex="3"></textarea> -
bb-includes/functions.bb-posts.php
2 2 3 3 /* Posts */ 4 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 */ 14 function 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 */ 44 function 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 } 60 5 61 function bb_get_post( $post_id ) { 6 62 global $bbdb; 7 63 $post_id = (int) $post_id; … … 300 356 $defaults['throttle'] = true; 301 357 extract( wp_parse_args( $args, $defaults ) ); 302 358 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 303 371 if ( !$topic = get_topic( $topic_id ) ) 304 372 return false; 305 373 306 if ( !$user = bb_get_user( $poster_id ) )374 if ( bb_is_login_required() && ! $user = bb_get_user( $poster_id ) ) 307 375 return false; 308 376 309 377 $topic_id = (int) $topic->topic_id; … … 330 398 $bbdb->insert( $bbdb->posts, compact( $fields ) ); 331 399 $post_id = $topic_last_post_id = (int) $bbdb->insert_id; 332 400 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 333 408 if ( 0 == $post_status ) { 334 409 $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; 337 412 338 413 $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->forums SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id ) ); 339 414 $bbdb->update( -
bb-includes/functions.bb-template.php
291 291 do_action( 'pre_post_form' ); 292 292 293 293 if ( 294 ( false === bb_is_login_required() ) || 294 295 ( bb_is_topic() && bb_current_user_can( 'write_post', $topic->topic_id ) && ( $page == $last_page || !$last_page_only ) ) || 295 296 ( !bb_is_topic() && bb_current_user_can( 'write_topic', isset( $forum->forum_id ) ? $forum->forum_id : 0 ) ) 296 297 ) { … … 427 428 return 'forum-page' == bb_get_location(); 428 429 } 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 */ 435 function bb_is_login_required() { 436 return ! (bool) bb_get_option('enable_loginless'); 437 } 438 430 439 function bb_is_tags() { 431 440 return 'tag-page' == bb_get_location(); 432 441 } … … 1735 1744 return apply_filters( 'get_post_author', $user->display_name, $user->ID, $post_id ); 1736 1745 elseif ( $title = bb_get_post_meta( 'pingback_title' ) ) 1737 1746 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 ); 1738 1749 else 1739 1750 return apply_filters( 'get_post_author', __('Anonymous'), 0, $post_id ); 1740 1751 } … … 1744 1755 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1745 1756 } elseif ( $link = bb_get_post_meta( 'pingback_uri' )) { 1746 1757 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1758 } elseif ( $link = bb_get_post_meta( 'post_url' ) ) { 1759 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1747 1760 } else { 1748 1761 post_author( $post_id ); 1749 1762 } -
bb-includes/functions.bb-meta.php
465 465 'wp_admin_cookie_path', 466 466 'wp_plugins_cookie_path', 467 467 'wordpress_mu_primary_blog_id', 468 'enable_loginless', 468 469 'enable_xmlrpc', 469 470 'enable_pingback', 470 471 'throttle_time', -
bb-post.php
1 1 <?php 2 2 require('./bb-load.php'); 3 3 4 bb_auth('logged_in'); 4 if ( bb_is_login_required() ) { 5 bb_auth('logged_in'); 6 } 5 7 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.')); 8 bb_check_comment_flood(); 9 9 10 10 if ( !$post_content = trim($_POST['post_content']) ) 11 11 bb_die(__('You need to actually submit some content!')); 12 12 13 $post_author = $post_email = $post_url = ''; 14 15 if ( ! 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 13 34 if ( 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') ) 15 36 bb_die(__('You are not allowed to post. Are you logged in?')); 16 37 17 if ( !bb_current_user_can( 'write_topic', $forum_id ) )38 if ( bb_is_login_required() && ! bb_current_user_can( 'write_topic', $forum_id ) ) 18 39 bb_die(__('You are not allowed to write new topics.')); 19 40 20 41 bb_check_admin_referer( 'create-topic' ); … … 32 53 bb_check_admin_referer( 'create-post_' . $topic_id ); 33 54 } 34 55 35 if ( !bb_current_user_can( 'write_post', $topic_id ) )56 if ( bb_is_login_required() && ! bb_current_user_can( 'write_post', $topic_id ) ) 36 57 bb_die(__('You are not allowed to post. Are you logged in?')); 37 58 38 59 if ( !topic_is_open( $topic_id ) ) 39 60 bb_die(__('This topic has been closed')); 40 61 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 ); 42 66 67 foreach( 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); 74 43 75 $tags = trim( $_POST['tags'] ); 44 76 bb_add_topic_tags( $topic_id, $tags ); 45 77 -
bb-admin/options-discussion.php
10 10 if (!isset($_POST['enable_pingback'])) { 11 11 $_POST['enable_pingback'] = false; 12 12 } 13 14 if (!isset($_POST['enable_loginless'])) { 15 $_POST['enable_loginless'] = false; 16 } 13 17 14 18 // Deal with avatars checkbox when it isn't checked 15 19 if (!isset($_POST['avatars_show'])) { … … 38 42 bb_admin_notice( __( '<strong>Settings saved.</strong>' ) ); 39 43 } 40 44 41 $ remote_options = array(45 $general_options = array( 42 46 'enable_pingback' => array( 43 47 'title' => __( 'Enable Pingbacks' ), 44 48 'type' => 'checkbox', … … 46 50 1 => __( 'Allow link notifications from other sites.' ) 47 51 ) 48 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 ), 60 ), 49 61 ); 50 62 51 63 $bb_get_option_avatars_show = create_function( '$a', 'return 1;' ); … … 101 113 <form class="settings" method="post" action="<?php bb_uri( 'bb-admin/options-discussion.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ); ?>"> 102 114 <fieldset> 103 115 <?php 104 foreach ( $ remote_options as $option => $args ) {116 foreach ( $general_options as $option => $args ) { 105 117 bb_option_form_element( $option, $args ); 106 118 } 107 119 ?>