MyBB Community Forums

Full Version: Post a new thread on a MyBB forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basically, I have a program in Delphi which POSTs data to a MyBB script on a server, when the MyBB script recieves that POSTed data it is supposed pass that data onto a MyBB forum and use it to post a new thread.

The only problem is I have no idea how to do the second part which is sending the data to the MyBB forum.
Potential problems I can see is:
- Logging in?
- Thread title and thread content?

Also I need to search the forum before posting, like if a certain thread title already exists then it posts a new post but if the thread title does not already exist then it posts a new thread.

I've had a look at API's but the only thing I've found is APIs which return forum data rather than POST forum data so I'm a bit lost on what to do now. Can anyone help? Thanks a million!
The only way I can think of doing it is sending it straight to the database. Have a look at newthread.php and newreply.php to see how mybb handles new posts/threads though to make sure you're sending everything required.
(2012-07-05, 05:54 AM)Alex Smith Wrote: [ -> ]The only way I can think of doing it is sending it straight to the database. Have a look at newthread.php and newreply.php to see how mybb handles new posts/threads though to make sure you're sending everything required.

I wonder if it would be possible by adjusting the formĀ“s plugin. I think if you would examine that plugin you could figure out a way to post the information to a forum.

http://mybbsource.com/mods.php?act=view&id=170

That one could be a great start for this.
(2012-07-03, 08:08 PM)KillerKlient Wrote: [ -> ]Basically, I have a program in Delphi which POSTs data to a MyBB script on a server, when the MyBB script recieves that POSTed data it is supposed pass that data onto a MyBB forum and use it to post a new thread.

The only problem is I have no idea how to do the second part which is sending the data to the MyBB forum.
Potential problems I can see is:
- Logging in?
- Thread title and thread content?

Also I need to search the forum before posting, like if a certain thread title already exists then it posts a new post but if the thread title does not already exist then it posts a new thread.

I've had a look at API's but the only thing I've found is APIs which return forum data rather than POST forum data so I'm a bit lost on what to do now. Can anyone help? Thanks a million!

Why don't you just use the MyBBIntegrator constructor?

This code snippet that i made is an example of the MyBBIntegrator:
<?php
define('IN_MYBB', NULL);
require_once 'relative/path/to/the/forum/global.php';
require_once 'relative/path/to/the/MyBB Integrator class';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);

$data = array(
    'subject' => $_POST['subject'],
    'uid' => $MyBBI->mybb->user['uid'],
    'username' => $MyBBI->mybb->user['username'],
    'message' => $_POST['message']
);

$threadName = $data['subject'];

$query = $MyBBI->db->query('SELECT `subject` FROM '.TABLE_PREFIX.'threads WHERE `subject` LIKE \'%'.$MyBBI->dbEscape($threadName).'%\' '); 

if(!$query){
 die('Query failed for some reason');
}

//validate the threadname and decide whether it exists or not
if($query == $threadName){
    echo "Looks like that thread already exists with that name..";
    print_r($threadName); // the data returned from the query
}
else
{
//Oh well, seems like the thread hasn't been created yet, woohoo! Now we are free to create a thread with the given name
$create = $MyBBI->createThread($data);
?>
Thanks for the responses guys, they have been very useful. I will go ahead and try them out and I'll let you know how it goes.

I'll try out the MyBB integrator first because I don't want to be messing directly with the database incase it corrupts some data for MyBB. If the user isn't logged in then how can I make a login script and/or find the uid of the user?

Also I managed to post a thread and the current code uses my web browsers stored login data if I am correct? Also assuming that the fid = 40, the query you have for checking if the thread already exists doesn't seem to work Confused. Can you have a look at it for me as I really don't understand it.

Basically if the thread already exists I need to create a new post, but if the thread does not already exist then I need to create a new thread.