1 (edited by CreedFeed 2007-01-03 05:06)

Topic: Auto-Create New Topic?

I'm creating a directory type website that will have a list of links pertaining to certain categories. Say for example I have a category of "Horror Movies" and I create a link within that category for the movie "Saw" - how hard would it be for me to include some code that would automatically create a new topic in a specified forum with a specific title (say 'Saw') and some default text in the first post (say 'Review the movie Saw here!') when I add this link to a category within my directory?

I'm an avid PHP coder , I'm just not familiar with the PunBB code. I've coded my directory script myself from scratch. Is this something that would be very hard to do or relatively easy? Before I spend time to delve into the PunBB code I'd like to get opinions from people who are familiar with the code and can tell me how hard this would be to accomplish.

Thanks!

Re: Auto-Create New Topic?

Should be easy. Just look at the database structure, the db layer (if you want to use it), and how it's populated from within the PunBB code; and do the same.

3 (edited by MrMister 2007-01-03 11:24)

Re: Auto-Create New Topic?

I'm doing that already since whenevew someone uploads a torrent to my tracker I generate a topic with the torrent's name and a post with the torrent's description.

I just did a quick export of the code I'm using, It may not work as-is for you but it should be very easy for you to change it.

// ----------> START Create forum topic for torrent
$now = time();
$username = $pun_user['username'];
$subject = $torrent;
$fid = 999;
$message = $descr;
$hide_smilies = 0;

// 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());

// Using FULLTEXT indexing so no need for this
//update_search_index('post', $new_pid, $message, $subject);

update_forum($fid);
// <---------- END Create forum topic for torrent

Re: Auto-Create New Topic?

Wow thanks, you made my task much easier with that.

Re: Auto-Create New Topic?

Moved to Integration

Re: Auto-Create New Topic?

hello, I want to post a new post and topic to my forum with a php script, I used the code of MrMister but it gave me an error:

Warning: ob_start(): output handler 'ob_gzhandler' cannot be used twice in /usr/local/share/punbb/include/functions.php on line 942
An error was encountered
Error: Unable to create post.

The code created the topic but failed with creating a posting :(

Re: Auto-Create New Topic?

Enable debug mode, paste the full error