submit_post: Getting new topic instead of new post

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
usernick
Registered User
Posts: 4
Joined: Tue Jan 16, 2018 2:35 pm

submit_post: Getting new topic instead of new post

Post by usernick » Tue Jan 16, 2018 2:40 pm

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path='./';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$poll='';
$bitfield='';
$uid='';

        // more phpBB setup...need to replace the session data setup above
        // with a hack, i mean sql query, then array_merge it into $user->data
        // below. couldn't just setup a session for the user/bot we want to
        // post as? Credit to RMcGirr83 on phpbb community support forum
        $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE user_id = 1481';
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        // reset the current users info to that of the bot
        $user->data = array_merge($user->data, $row);
		
$message="message[b]message[/b]message";
$subject="subject2";

generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);

$data = array( 
    // General Posting Settings
    'forum_id'            => 2,    // The forum ID in which the post will be placed. (int)
    'topic_id'            => 1,    // Post a new topic or in an existing one? Set to 0 to create a new one, if not, specify your topic ID here instead.
    'icon_id'            => false,    // The Icon ID in which the post will be displayed with on the viewforum, set to false for icon_id. (int)

    // Defining Post Options
    'enable_bbcode'    => true,    // Enable BBcode in this post. (bool)
    'enable_smilies'    => true,    // Enabe smilies in this post. (bool)
    'enable_urls'        => true,    // Enable self-parsing URL links in this post. (bool)
    'enable_sig'        => true,    // Enable the signature of the poster to be displayed in the post. (bool)

    // Message Body
    'message'            => $message,        // Your text you wish to have submitted. It should pass through generate_text_for_storage() before this. (string)
    'message_md5'    => md5($message),// The md5 hash of your message

    // Values from generate_text_for_storage()
    'bbcode_bitfield'    => $bitfield,    // Value created from the generate_text_for_storage() function.
    'bbcode_uid'        => $uid,        // Value created from the generate_text_for_storage() function.

    // Other Options
    'post_edit_locked'    => 0,        // Disallow post editing? 1 = Yes, 0 = No
    'topic_title'        => $subject,    // Subject/Title of the topic. (string)
	
    // Email Notification Settings
    'notify_set'        => false,        // (bool)
    'notify'            => false,        // (bool)
    'post_time'         => 0,        // Set a specific time, use 0 to let submit_post() take care of getting the proper time (int)
    'forum_name'        => '',        // For identifying the name of the forum in a notification email. (string)

    // Indexing
    'enable_indexing'    => true,        // Allow indexing the post? (bool)

    // 3.0.6
    'force_approved_state'    => true, // Allow the post to be submitted without going into unapproved queue

    // 3.1-dev, overwrites force_approve_state
    'force_visibility'            => true, // Allow the post to be submitted without going into unapproved queue, or make it be deleted
);

$ret=submit_post('post','subject',$user->data['username'],POST_NORMAL,$poll,$data);
?>
Topic with topic_id=1 is present. Changing topic_id to another value does not change anything.
phpBB version 3.2.1

User avatar
Ger
Recognised Extension Developer
Posts: 1592
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: submit_post: Getting new topic instead of new post

Post by Ger » Tue Jan 16, 2018 3:09 pm

it says in your own code comment:
// Post a new topic or in an existing one? Set to 0 to create a new one,
My extensions: Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update and Modern Quote
Newest: Quoted Where + anonymize

Like my work? Buy me a coffee to keep it coming. :ugeek:
-Available for custom work-

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: submit_post: Getting new topic instead of new post

Post by posey » Tue Jan 16, 2018 3:31 pm

Ger wrote:
Tue Jan 16, 2018 3:09 pm
it says in your own code comment:
// Post a new topic or in an existing one? Set to 0 to create a new one,
And he means, he has it set to an existing topic, but still gets a new topic every time.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20852
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: submit_post: Getting new topic instead of new post

Post by RMcGirr83 » Tue Jan 16, 2018 4:11 pm

Code: Select all

$ret=submit_post('post','subject',$user->data['username'],POST_NORMAL,$poll,$data);
because s/he is posting instead of replying.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests