How to submit a post to phpbb3 by a different user

February 9, 2009 at 11:51 am | In Blog, Website Development | Leave a Comment
Tags: , , ,

As part of the Integration of DirtMind with twitter I needed to be able to submit posts into my phpbb3 forum using a bot account to protect anonymity of my users when they’re tweeting their DirtyThoughts anonymously, and I didn’t want to use the anonymous/guest account because I wanted to generate hit counts etc. Here’s how I did it

        $poll = $uid = $bitfield = $options = '';   
        generate_text_for_storage($twitter_status, $uid, $bitfield, $options, true, true, true);

        $data = array(
           'forum_id'      => 11, //the subforum that my DirtyThoughts thread is in
           'icon_id'      => false,
           'topic_id'      => 435, //the thread to reply to
           'poster_id'      => 146, //the id of the DirtyThoughts user              

           'enable_bbcode'   => true,
           'enable_smilies'   => true,
           'enable_urls'      => true,
           'enable_sig'      => true,

           'message'      => $twitter_status,
           'message_md5'   => md5($twitter_status),

           'bbcode_bitfield'   => $bitfield,
           'bbcode_uid'      => $uid,

           'post_edit_locked'   => 0,
           'topic_title'      => '',
           'notify_set'      => false,
           'notify'         => false,
           'post_time'       => 0,
           'forum_name'      => '',
           'enable_indexing'   => true,          
        );          
        //store current user
        $old_user_id=$user->data['user_id'];
        $old_username=$user->data['username'];       
        $old_usercol=$user->data['user_colour'];       
        //change to bot
        $user->data['username']='DirtyThoughts';
        $user->data['user_id']= 146;
        $user->data['user_colour']= '';
        //make post
        submit_post('reply', 'Dirty Thought', 'DirtyThoughts', POST_NORMAL, $poll, $data, '');    
        //restore user
        $user->data['username']=$old_username;
        $user->data['user_id']= $old_user_id;
        $user->data['user_colour'] = $old_usercol;

Interestingly the submit_post function always uses the current user object to make a post, regardless of the settings in $data. To get around this I store the current userid, name and colour in variables  and switch to the bot values to make the post before returning the current users settings to their normal values.

No Comments Yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.