Topic: PHP Script to post a topic on punbb forum

Excuse me if I'm on the wrong forum, but this seemed to be the correct one for my question.

I am looking for a simple script to post a topic into a punbb forum (the forum is on my server and I have access to the MySQL database).

Any help is appreciated.

Re: PHP Script to post a topic on punbb forum

So this is what I did from the code I found in post.php.

It does post a topic, but I want to know if it is correctly done.

I have no idea what $fid is.

require(PUN_ROOT . 'include/search_idx.php');

        $fid = 1;//isset($_GET['fid']) ? intval($_GET['fid']) : 0;
        $now = time();
        $hide_smilies = 1;
        $subject = "test subject";
        $message = "test message";

        // Create the topic
        $db->query('INSERT INTO ' . $db->prefix . 'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\'' . $db->escape($username) . '\', \'' . $db->escape($subject) . '\', ' . $now . ', ' . $now.', \'' . $db->escape($username) . '\', ' . $fid. ')') or error('Unable to create topic', __FILE__, __LINE__, $db->error());
        $new_tid = $db->insert_id();

        // Create the post ("topic post")
        $db->query('INSERT INTO ' . $db->prefix . 'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\'' . $db->escape($username) . '\', '.$pun_user['id'] . ', \'' . get_remote_address() . '\', \'' . $db->escape($message) . '\', \'' . $hide_smilies . '\', ' . $now . ', ' . $new_tid . ')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
        
        $new_pid = $db->insert_id();

        // Update the topic with last_post_id
        $db->query('UPDATE ' . $db->prefix . 'topics SET last_post_id=' . $new_pid.' WHERE id=' . $new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());

        update_search_index('post', $new_pid, $message, $subject);

        update_forum($fid);

3 (edited by Lennart3 2008-07-19 19:21)

Re: PHP Script to post a topic on punbb forum

The topics I make with that script seems to always be "new posts". Any idea why this is? Or is it just a coincidence?

Edit:
After I logged out and in again, they were "read" as they should be.

Re: PHP Script to post a topic on punbb forum

Are you using version 1.2.x ?  It appears so.  Otherwise (if you are using 1.3) you should use the query builder.

$fid is the forum id in which the topic is created.

Assuming it is 1.2.x, any new topic will be new because the default unread mark behavior of 1.2 is unexpected.  It is based on the time of the topic compared to the last visit time so it is really a new topic mark not an unread mark.  If you never want them to be new, maybe you could update the person's last login time.  Not sure you really want to do this.  There is an extension on punres for better unread marks.