Adam Harley (Kawauso) (@kawauso)

Forum Replies Created

Viewing 25 replies - 76 through 100 (of 285 total)
  • @kawauso

    Member

    Both the “Freshness”/latest reply and normal links in the Search function should be including the page number in links, as that’s allowed for in the function used, get_topic_link() .

    Sort’ve worrying if it’s not including it! bbPress.org includes the page number…

    It’s not included for any page 1 links though.

    @kawauso

    Member
    In reply to: Page Breaks

    @kawauso

    Member

    https://bbpress.org/plugins/topic/bbpages/

    Broken apparently, but it’d be fixable if I knew what was wrong with it

    @kawauso

    Member

    For saving you’d have to do something server-side, probably easiest would be just to jack up the post-per-page or uncap it entirely, as it won’t save what’s already been loaded into the browser and edited.

    For printing and reading however, you could use AJAX to stitch all the pages together on the fly so it appears as one.

    In reply to: removing tags

    @kawauso

    Member

    Everything dynamic in bbPress/WordPress is stored in the database, and tags are stored in one table but referenced in others. Better to fix the underlying problem.

    @kawauso

    Member

    Do you mean what would be the best way client-wise (i.e. with no control over the server) or server-side?

    @kawauso

    Member

    <?php bb_profile_link( array( 'id' => $user->ID, 'text' => get_user_display_name( $user->ID ) ) ); ?>

    I’d guess… not really sure on the context where you’re putting it though, so I can’t really test

    @kawauso

    Member
    <?php

    function add_email_spec_meta( $arr ) {

    if( !bb_is_user_logged_in() || bb_current_user_can( 'edit_users' ) )
    return $arr;

    if( bb_get_location() != 'profile-page' || stripos( $_SERVER[ 'QUERY_STRING' ], 'tab=edit' ) !== false )
    return $arr;

    $arr['email_spec'] = $arr['user_email'];

    global $wp_users_object;

    $id = bb_get_current_user_info( 'id' );

    $meta_key = 'email_spec';

    $meta_value = bb_get_usermeta( $id, 'user_email' );

    $wp_users_object->update_meta( compact( 'id', 'meta_key', 'meta_value' ) );

    return $arr;

    }
    add_filter( 'get_profile_info_keys', 'add_email_spec_meta' );

    ?>

    In reply to: Some PHP help please

    @kawauso

    Member

    The cleanest way of doing this hasn’t been mentioned. Instead of using echo commands, it’s a lot easier to just wrap HTML.

    <?php if ( bb_is_user_logged_in() ) : ?>
    this
    <?php elseif : ?>
    not this
    <?php endif; ?>

    @kawauso

    Member

    Where do you want to add it relative to the current layout?

    @kawauso

    Member

    Add it to your theme’s front-page.php

    @kawauso

    Member

    Then write something yourself or pay someone else to, always a solution if you need something done fast in a volunteer community

    In reply to: Link Cloaking

    @kawauso

    Member
    <?php
    /*
    Plugin Name: Remove Links (conditional)
    Description: Removes links for non-registered users. Based on <a href="http://ckon.wordpress.com/2007/07/12/bbpress-plugin-bb-tweaks/">bb tweaks</a>.
    Plugin URI: https://bbpress.org/forums/topic/hide-links
    Version: 0.01
    */

    function bb_strip_links( $text ) {
    global $topic;

    $forums = array(
    1,
    2,
    3,
    );

    if ( !in_array( $topic->forum_id, $forums ) )
    return $text;

    if ( !bb_current_user_can( 'write_post' ) )
    $text = preg_replace('|<a (.+?)>(.+?)</a>|i', __('(Login or register to download)'), $text);

    return $text;

    }

    add_filter('post_text', 'bb_strip_links');

    ?>

    @kawauso

    Member

    Okay, after much lucky guessing with regards to the user object handling, I have an ALPHA VERSION of a plugin to do this. There’s nothing to stop spambots, this is purely a proof of concept, I’ll try adding a captcha or something later if necessary. Email verification sounds like a royal pain though. Save the files exactly where I’ve said and as ever, make sure you leave no whitespace around the PHP tags. Apart from that, please test it but it’s your own risk if you run it on a production server.

    my-plugins/register-post/load.php:

    <?php
    /*
    Plugin Name: Register & Post
    Description: Allows a user to register and make a post at the same time.
    Author: Kawauso
    Version: Alpha
    */

    // Add the post form
    add_action( 'post_post_form', 'register_post_form' );

    function register_post_form() {

    global $h2, $forum, $topic;

    if( bb_is_user_logged_in() )
    return;

    // Setup the register form

    $profile_info_keys = bb_get_profile_info_keys();

    unset( $profile_info_keys['first_name'], $profile_info_keys['last_name'], $profile_info_keys['display_name'], $profile_info_keys['occ'], $profile_info_keys['from'], $profile_info_keys['user_url'], $profile_info_keys['interest'] );

    $bb_register_error = new WP_Error;

    $user_login_error = $bb_register_error->get_error_message( 'user_login' );

    ?>
    <style type="text/css">p#post-form-forum-container{display:none}</style>
    <form class="postform post-form" id="postform" method="post" action="<?php bb_uri( 'my-plugins/register-post/create.php', null, BB_URI_CONTEXT_FORM_ACTION )?>">
    <h2 class="postform">Register and post?</h2>
    <fieldset>
    <table width="100%">
    <tr class="form-field form-required required<?php if ( $user_login_error ) echo ' form-invalid error'; ?>">
    <th scope="row">
    <label for="user_login"><?php _e('Username'); ?></label>
    <?php if ( $user_login_error ) echo "<em>$user_login_error</em>"; ?>
    </th>
    <td>
    <input name="user_login" type="text" id="user_login" size="30" maxlength="30" value="<?php echo $user_login; ?>" />
    </td>
    </tr>
    <?php

    if ( is_array($profile_info_keys) ) :
    foreach ( $profile_info_keys as $key => $label ) :
    $class = 'form-field';
    if ( $label[0] ) {
    $class .= ' form-required required';
    }
    if ( $profile_info_key_error = $bb_register_error->get_error_message( $key ) )
    $class .= ' form-invalid error';

    ?>

    <tr class="<?php echo $class?>">
    <th scope="row">
    <label for="<?php echo $key?>"><?php echo $label[1]?></label>
    <?php if ( $profile_info_key_error ) echo "<em>$profile_info_key_error</em>"; ?>
    </th>
    <td>
    <input name="<?php echo $key?>" type="text" id="<?php echo $key?>" size="30" maxlength="140" value="<?php echo $$key?>" />
    </td>
    </tr>

    <?php

    endforeach; // profile_info_keys
    endif; // profile_info_keys

    ?>
    </table>

    <br />

    <?php
    bb_load_template( 'post-form.php', array('h2' => $h2) );
    bb_nonce_field( bb_is_topic() ? 'create-post_' . $topic->topic_id : 'create-topic' );
    if ( bb_is_forum() ) {
    echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />' . "n";
    } elseif ( bb_is_topic() ) {
    echo '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "n";
    }
    echo "n</fieldset>n</form>n";

    }

    my-plugins/register-post/create.php:

    <?php

    require_once('../../bb-load.php');

    $profile_info_keys = bb_get_profile_info_keys();

    unset( $profile_info_keys['first_name'], $profile_info_keys['last_name'], $profile_info_keys['display_name'], $profile_info_keys['occ'], $profile_info_keys['from'], $profile_info_keys['user_url'], $profile_info_keys['interest'] );

    $user_login = '';
    $user_safe = true;

    $bb_register_error = new WP_Error;

    if ( $_POST && 'post' == strtolower($_SERVER['REQUEST_METHOD']) ) {
    $_POST = stripslashes_deep( $_POST );
    $_POST['user_login'] = trim( $_POST['user_login'] );
    $user_login = sanitize_user( $_POST['user_login'], true );
    if ( $user_login !== $_POST['user_login'] ) {
    $bad_input = true;
    if ( $user_login )
    $bb_register_error->add( 'user_login', sprintf( __( "%s is an invalid username. How's this one? <strong>%s</strong>" ), esc_html( $_POST['user_login'] ), $user_login ) );
    else
    $bb_register_error->add( 'user_login', sprintf( __( '%s is an invalid username.' ), esc_html( $_POST['user_login'] ) ) );
    }

    foreach ( $profile_info_keys as $key => $label ) {
    if ( is_string($$key) )
    $$key = esc_attr( $$key );
    elseif ( is_null($$key) )
    $$key = esc_attr( $_POST[$key] );

    if ( !$$key && $label[0] == 1 ) {
    $bad_input = true;
    $$key = false;
    $bb_register_error->add( $key, sprintf( __( '%s is required' ), $label[1] ) );
    }
    }

    if ( !$bad_input ) {

    // Invoke non-user post checks here
    if ( !$post_content = trim($_POST['post_content']) )
    bb_die(__('You need to actually submit some content!'));

    if ( isset($_POST['topic']) && $forum_id = (int) $_POST['forum_id'] ) {

    $topic = trim( $_POST['topic'] );

    if ('' == $topic)
    bb_die(__('Please enter a topic title'));

    } elseif ( isset($_POST['topic_id'] ) ) {
    $topic_id = (int) $_POST['topic_id'];
    bb_check_admin_referer( 'create-post_' . $topic_id );
    }

    if ( !topic_is_open( $topic_id ) )
    bb_die(__('This topic has been closed'));

    // Invoke registration
    $user_id = bb_new_user( $user_login, $_POST['user_email'], null );
    if ( is_wp_error( $user_id ) ) { // Error creating user

    foreach ( $user_id->get_error_codes() as $code )
    $bb_register_error->add( $code, $user_id->get_error_message( $code ) );

    if ( $bb_register_error->get_error_message( 'user_login' ) )
    $user_safe = false;

    } elseif ( $user_id ) { // Registration success

    foreach( $profile_info_keys as $key => $label )
    if ( strpos($key, 'user_') !== 0 && $$key !== '' )
    bb_update_usermeta( $user_id, $key, $$key );

    do_action('register_user', $user_id);

    // Create the current user object

    $wp_auth_object->set_current_user( $user_id );

    $bb_current_user = $wp_auth_object->current;

    // Do last minute post/topic checks
    if ( !empty($topic) && $forum_id = (int) $_POST['forum_id'] ) {

    if ( !bb_current_user_can('write_posts') )
    bb_die(__('You are not allowed to post. Are you logged in?'));

    if ( !bb_current_user_can( 'write_topic', $forum_id ) )
    bb_die(__('You are not allowed to write new topics.'));

    if ( !bb_current_user_can( 'write_topic', $forum_id ) )
    bb_die(__('You are not allowed to write new topics in this forum.'));

    bb_check_admin_referer( 'create-topic' );
    $topic_id = bb_new_topic( $topic, $forum_id, $tags );

    }

    if ( !bb_current_user_can( 'write_post', $topic_id ) )
    bb_die(__('You are not allowed to post in this topic.'));

    // Create the new post
    $post_id = bb_new_post( $topic_id, $_POST['post_content'] );

    $tags = trim( $_POST['tags'] );
    bb_add_topic_tags( $topic_id, $tags );

    $link = get_post_link( $post_id );

    $topic = get_topic( $topic_id, false );

    if ( $topic->topic_posts )
    $link = add_query_arg( 'replies', $topic->topic_posts, $link );

    do_action( 'bb-post.php', $post_id );

    if ( $post_id )
    wp_redirect( $link );
    else
    wp_redirect( bb_get_uri(null, null, BB_URI_CONTEXT_HEADER) );
    exit;
    }
    }
    }

    // If you've reached this point, there must have been an error

    $user_login_error = $bb_register_error->get_error_message( 'user_login' );

    if( empty( $user_login_error ) ) // For some reason, error strings are not always available (i.e. for invalid emails)
    $user_login_error = __( 'Something went wrong! Check what you entered and try again.' );

    bb_die( $user_login_error );

    @kawauso

    Member

    “Currently, plug-ins for both WordPress and bbPress, WordPress’ forum software solution are available.”

    *sigh*

    Apparently the bbPress plugin is still in alpha, as of about 10 days ago:

    http://forum.gigya.com/forum/Default.aspx?g=posts&m=1619

    The WordPress one is released though, so maybe it’d be fine under a WP/bbP integration setup

    @kawauso

    Member

    topic_author()

    @kawauso

    Member

    It matters when it’s involved with a filter or action that’s run on a processing page (that you don’t usually see), because if any text is passed it can’t send a redirect header for the nice pretty page you normally see straight away. Whatcha need an email for?

    @kawauso

    Member

    Output starts on line 3 of the plugin.. that’s either part of the description or the opening of the first function. Neither should generate anything. Check for whitespace around the PHP tags?

    @kawauso

    Member

    They should be the ones that you use for the database connection for WordPress, yes. If you need to double-check them, look at the wp-config.php and copy them from there.

    @kawauso

    Member

    Probably a good idea, let me know how this one works :P

    @kawauso

    Member
    <?php
    /*
    * Plugin Name: Say My Name
    * Plugin Description: Sends a notification email if someone mentions your name in a post (based on Notify Post by Thomas Klaiber).
    * Author: <a href="http://www.ellequadro.net">Matteo Crippa</a>, updated for bbPress 1.0 by Kawauso
    * Version: 0.2
    */

    function say_my_name ( $post_id, $args ) {

    global $bbdb, $topic;

    if ( isset( $args[ 'post_id' ] ) && false !== $args[ 'post_id' ] ) // Don't run on edits
    return;

    $post = strtolower( $args[ 'post_text' ] );

    $all_users = $bbdb->get_results( "SELECT * FROM $bbdb->users WHERE user_status=0" );

    foreach( $all_users as $userdata ) {

    if( !is_smn( $userdata->ID ) )
    continue;

    /* $notify = false;
    */ $display_name = strtolower( $userdata->display_name );

    /* if( strpos( $display_name, ' ' ) === false ) { // Use word-by-word searching if the display name is one word
    if( !isset( $words ) )
    $words = explode( ' ', $post ); // Only create the word list if necessary

    foreach ( $words as $word ) {

    if( $display_name == $word || "@$display_name" == $word ) {

    $notify = true;
    break;

    }

    }
    }

    else*/ if( strpos( " $post", " $display_name" ) !== false || strpos( " $post", " @$display_name" ) !== false) // Always require a leading space
    /* $notify = true;

    if( $notify ) */{

    $message = __( "Someone called you on: %1$s nn%2$s " );
    @mail( $userdata->user_email, bb_get_option( 'name' ) . ':' . __( 'Notification' ), sprintf( $message, $topic->topic_title, get_topic_link( $topic_id ) ), 'From: ' . bb_get_option( 'admin_email' ) );

    }

    }

    }
    add_action( 'bb_insert_post', 'say_my_name', 1, 2 );

    function smn_profile() {

    if( !bb_is_user_logged_in() )
    return;

    global $user_id;

    if( is_smn( $user_id ) )
    $checked = ' checked="checked"';
    else
    $checked = '';

    ?>
    </fieldset>
    <fieldset>
    <legend>Say My Name Notification</legend>
    <p><?php _e('If you want to get an email when someone call your name in a new post.')?></p>
    <table width="100%">
    <tr>
    <th width="21%" scope="row"><?php _e('Activate')?>:</th>
    <td width="79%"><input name="smn" id="smn" type="checkbox" value="1"<?php echo $checked?> /></td>
    </tr>
    </table>
    <?php
    }
    add_action( 'extra_profile_info', 'smn_profile' );

    function smn_edit() {
    global $user_id;

    if( $_POST[ 'smn' ] )
    bb_update_usermeta( $user_id, "smn", true );
    else
    bb_update_usermeta( $user_id, "smn", false );

    }
    add_action( 'profile_edited', 'smn_edit' );

    function is_smn ( $user_id ) {
    $user = bb_get_user( $user_id );
    if ( $user->smn )
    return true;
    else
    return false;
    }
    ?>

    Take out the /* */ around the commented out parts of the code if you want to re-enable the foreach() loop method for single word display names. I couldn’t find much of a difference in speed, but then again it might be quite different on a live server. You can also just delete all that code too if you want to make the file smaller :P I’ll upload this to the Extend section someday, along with the other plugin I keep meaning to finish and upload.

    Edit: Added support for @ :P

    This should be 100% case insensitive, but I’ve not tested with anything unicode. It’ll always look for a space before the name to avoid false positives, but if it’s at the very start of the post, it’ll still be detected.

    @kawauso

    Member

    Okay, I’ve managed to optimise the code for this a bit. I’m a bit stuck though.

    At the moment, it’s checking for usernames, rather than display names and checking word-by-word. That’s fine for usernames, because they’re essentially always one word, but display names can be more than one and I intend to use those.

    Explosion took 0.000307083129883 seconds

    Strpos took 3.00407409668E-5 seconds

    :D

    @kawauso

    Member

    Doesn’t look like it’d be too hard to update. That said, what’s broken?

    @kawauso

    Member

    All my code is written against 1.0.2 SVN, so it’s not 0.9-only :) and yeah, $allowed_tags is meant to be changed and then back again, not the cleanest way of doing things, but it should work. The copy that’s working live at the moment is below (I just realised I forgot to turn on the validation code too, oops):

    <?php
    /*
    Plugin Name: Restrict Topic Tags
    Description: Restricts tags to a pre-defined list.
    Author: Kawauso
    Version: 0.1.1
    */

    $allowed_tags = array(
    'test4',
    'test 3',
    'test3',
    'test2',
    );

    function restrict_topic_tags_form( $args = null )
    {
    $defaults = array( 'topic' => 0, 'submit' => __('Add »'), 'list_id' => 'tags-list' );
    $args = wp_parse_args( $args, $defaults );
    extract( $args, EXTR_SKIP );

    if ( !$topic = get_topic( get_topic_id( $topic ) ) ) {
    return false;
    }

    if ( !bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) {
    return false;
    }

    global $page, $allowed_tags;

    $current_tags = bb_get_topic_tags( $topic->topic_id );
    $allowed_tags = array_flip( $allowed_tags ); // CHANGE PLACES!
    foreach( $current_tags as $tag ) {
    if( isset( $allowed_tags[ $tag->name ] ) )
    unset( $allowed_tags[ $tag->name ] );
    }
    $allowed_tags = array_flip( $allowed_tags ); // CHANGE PLACES!

    if( is_array( $allowed_tags ) && !empty( $allowed_tags ) ) { ?>
    <form id="tag-form" method="post" action="<?php bb_uri('tag-add.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN); ?>" class="add:<?php echo esc_attr( $list_id ); ?>:">
    <p>
    <select name="tag" id="tag">
    <option value=""><?php _e("Select a tag")?></option>
    <?php foreach( $allowed_tags as $tag ) { ?>
    <option value="<?php echo $tag?>"><?php echo $tag?></option>
    <?php } ?>
    </select>
    <input type="hidden" name="id" value="<?php echo $topic->topic_id; ?>" />
    <input type="hidden" name="page" value="<?php echo $page; ?>" />
    <?php bb_nonce_field( 'add-tag_' . $topic->topic_id ); ?>
    <input type="submit" name="submit" id="tagformsub" value="<?php echo esc_attr( $submit ); ?>" />
    </p>
    </form>
    <?php
    } // End if

    } // End function

    function restrict_topic_tags( $tag ) {

    global $allowed_tags;

    if( !in_array( $tag, $allowed_tags ) )
    return array();

    return array($tag);
    }

    add_filter( 'bb_add_topic_tags', 'restrict_topic_tags' );

    @kawauso

    Member

    function do_action($tag, $arg = '')

    do_action() has an arguments variable as it’s 2nd argument, sorry for not being clearer. That’s passed when it runs an action function and if nothing is passed, it defaults to an empty string.

    $bb_table_prefix would be the prefix for the bbPress tables though, wouldn’t it? In the case of a WP/bbP integration, the bbPress user data is stored in the WordPress user tables, so those aren’t under the same prefix as the bbPress tables. Unless it changes automatically for WordPress user tables somehow?

Viewing 25 replies - 76 through 100 (of 285 total)