News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

API question

Started by metalsoft, January 02, 2006, 04:58:32 PM

Previous topic - Next topic

metalsoft

Hi,

I was using IPB 1.3 so far and it has quite a good API. Especially the API function to create topics and posts are important for me. Now I had a look at the SMF API and there aren't many functions. It seems to be all about logging in and out ;-)

Then I had a look at the SSI.php but there are only functions to read something ( but quite useful, too ). So now my questions is: What is the easiest way to create a new Topic with an external php script ( but of course it's on the same server ) ?

Thanks in advanced for replies.

Greetz

Remaker

There are no api functions to allow you to add content (posts... ,topics) to the board.

You will have to "manually" insert the data in the database(direct query of the db) without the help of an api function(not so complicated but you will have to check out the structure a little bit, try searching here maybe you will find something)
Remaker - My blog - Actualitate.net

metalsoft

Hi,

I had a look into the post.php and the table structure is clear to me now.

I already customized the code a bit:


$board = 4 ; // My target board
$ID_MEMBER = 2 ; // My "News_Bot"
mysql_query("
INSERT INTO smf_messages
(ID_BOARD, ID_MEMBER, subject, posterName, posterEmail, posterTime,
posterIP, smileysEnabled, body, icon)
VALUES ('$board', '$ID_MEMBER' , '$text', 'News_Bot', '', " . time() . ",
'127.0.0.1', '1' , '$text', 'xx')");

$ID_MSG = mysql_insert_id();


if ($ID_MSG > 0)
{
// Insert the new topic.
mysql_query("
INSERT INTO smf_topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG)
VALUES ($board, $ID_MEMBER, $ID_MEMBER, $ID_MSG, $ID_MSG)" );

$topic = mysql_insert_id();
if ($topic > 0)
{
// Fix the message with the topic.
mysql_query("
UPDATE smf_messages
SET ID_TOPIC = $topic
WHERE ID_MSG = $ID_MSG
LIMIT 1");

// Increase the number of posts and topics on the board.
mysql_query("
UPDATE smf_boards
SET numPosts = numPosts + 1, numTopics = numTopics + 1
WHERE ID_BOARD = $board
LIMIT 1");


Ok up to this point it should work well.

But now there are some function calls:


// There's been a new topic AND a new post today.
trackStats(array('topics' => '+', 'posts' => '+'));

// Update all the stats so everyone knows about this new topic and message.
updateStats('topic');
updateStats('message');
updateLastMessages($board);


I had a look at those functions but I don't understand much of what they do. So I'm not sure if I can simply leave them out ... any help available out there ?

Advertisement: