posting/converting multiple topics?

Started by bloc, August 01, 2004, 02:59:32 PM

Previous topic - Next topic

bloc

I need to convert posts in a self-made blog system to topics/posts in SMF. They contain just date,author,subject and message + type.There are just two types, first post and answers to that (like the forum). Reason for this is to develop a simple blog-like posting-type within the forum instead..   

Is it possible to post multiple new topics/messages somehow? By using SQL I can put in subject/date and body from my blogposts, but there is surely more to consider?...

[Unknown]

#1
function smf_makePost($poster_id, $poster_name, $poster_email, $subject, $message, $icon, $board_id, $no_smileys = false)
{
global $sourcedir, $db_prefix, $user_info;

require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Post.php');
loadLanguage('Post');

$message = addslashes($message);
$subject = addslashes($subject);
$icon = addslashes($icon);
$poster_id = (int) $poster_id;
$poster_name = addslashes($poster_name);
$poster_email = addslashes($poster_email);
$board_id = (int) $board_id;
$no_smileys = $no_smileys ? '0' : '1';

preparsecode($message);

// Insert the post.
db_query("
INSERT INTO {$db_prefix}messages
(ID_BOARD, ID_MEMBER, subject, posterName, posterEmail, posterTime,
posterIP, smileysEnabled, body, icon)
VALUES ($board_id, $poster_id, '$subject', '$poster_name', '$poster_email', " . time() . ",
'$user_info[ip]', $no_smileys, '$message', '$icon')", __FILE__, __LINE__);
$ID_MSG = db_insert_id();

if ($ID_MSG <= 0)
return false;

// Insert the new topic.
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numViews)
VALUES ($board_id, $poster_id, $poster_id, $ID_MSG, $ID_MSG, 0)", __FILE__, __LINE__);
$topic = db_insert_id();

if ($topic <= 0)
{
// Fix the message with the topic.
db_query("
DELETE FROM {$db_prefix}messages
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);
return false;
}

// Fix the message with the topic id.
db_query("
UPDATE {$db_prefix}messages
SET ID_TOPIC = $topic
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);

db_query("
UPDATE {$db_prefix}boards
SET numPosts = numPosts + 1, numTopics = numTopics + 1
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);

trackStats(array('topics' => '+', 'posts' => '+'));
trackStats();
updateStats('topic');
updateStats('message');
updateLastMessages($board_id);

if (!empty($poster_id))
{
$request = db_query("
SELECT countPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);
list ($pcounter) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($pcounter))
updateMemberData($poster_id, array('posts' => 'posts + 1'));
}

return $topic;
}


Does not send notifications, but it should work.... no error checking.

-[Unknown]

bloc

Thank you for the quick reply!

This function is just what I needed. :)

[Unknown]

Fixed a small typo that had to do with smileys...

-[Unknown]

bloc

:) I see it...switch of the 0 and 1 .Thanks again.

Heatsink

Quote from: [Unknown] on August 01, 2004, 04:25:46 PM
function smf_makePost($poster_id, $poster_name, $poster_email, $subject, $message, $icon, $board_id, $no_smileys = false)

... snip ...



Does not send notifications, but it should work.... no error checking.

-[Unknown]

I've been using this code snippet for a while now to import Fidonet messages into my SMF forums. Now that I've been running it for a while, I've noticed how annoying it is to have lost the ability to thread messages so I want to implement some rudimentary threading.

Remember I said rudimentary :) - I'm going to do it based on subjects. We'll see how that goes and if it sucks then I'll do something with the message IDs. But for now this is what I want to try....

If I read this function right then, after the new message is inserted, the new record in the topics table is inserted. The auto_increment ID_TOPIC is then trapped and used to update the ID_TOPIC field of the newly inserted message.

So, originally I thought that I could query the messages table for a matching subject prior to the message insert. Assuming there was one, I could set the ID_TOPIC field in the message table to that topic id.

I then noticed that the topic id originally comes from an auto-incremented field in the topics table. Then I got scared I was going to blow up my whole install.

So here's my assumptions:

1. If a message is a reply, then no new record in the topics field is required, correct?

Meaning, that if I went with my scenario above and I was sucessful in retreiving a topic ID from the messages table prior to the insert, then I can use that topic id in the messages table and no update or insert on the topics table is required....yes?

Anything else I'm going to blow up if I do it this way?

Thanks!

Jon



[Unknown]

Yes, new topics only need to be inserted for new topics... :P ;).

I suggest also being aware of anything like "RE:" or etc... I don't know anything about Fidonet, though.

-[Unknown]

Heatsink

Quote from: [Unknown] on October 20, 2004, 02:49:05 AM
Yes, new topics only need to be inserted for new topics... :P ;).

I suggest also being aware of anything like "RE:" or etc... I don't know anything about Fidonet, though.

-[Unknown]

Excellent, thanks for the confirmation. With respect to "RE:"..good point. Some systems put it in and some don't...have to match on both accounts.

Thanks

Jon

Heatsink

Quote from: [Unknown] on October 20, 2004, 02:49:05 AM
Yes, new topics only need to be inserted for new topics... :P ;).

I suggest also being aware of anything like "RE:" or etc... I don't know anything about Fidonet, though.

-[Unknown]

Discovered something that blew up on me...when I manually assign the topic number, the topic counters don't get updated. Thus a thread with a single reply shows 0 replies and then when I delete that reply, it shows -1 replies which causes...well...all sorts of havoc.

I see some code in the function to do some updating, but I can't figure it out. The only piece of code that I've wrapped in an IF (and therefore doesn't execute for replies) is


db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numViews)
VALUES ($board_id, $poster_id, $poster_id, $ID_MSG, $ID_MSG, 0)", __FILE__, __LINE__);

$topic = db_insert_id();


Any ideas?

Thanks!

Jon

[Unknown]

function smf_makePost($poster_id, $poster_name, $poster_email, $subject, $message, $icon, $board_id, $no_smileys = false)
{
global $sourcedir, $db_prefix, $user_info;

require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Post.php');
loadLanguage('Post');

$message = addslashes($message);
$subject = addslashes($subject);
$icon = addslashes($icon);
$poster_id = (int) $poster_id;
$poster_name = addslashes($poster_name);
$poster_email = addslashes($poster_email);
$board_id = (int) $board_id;
$no_smileys = $no_smileys ? '0' : '1';

preparsecode($message);

if (blah)
{
// Figure out if you want a topic here, and put it in $topic.
$topic = (int) $topic;
}
else
$topic = 0;

// Insert the post.
db_query("
INSERT INTO {$db_prefix}messages
(ID_BOARD, ID_TOPIC, ID_MEMBER, subject, posterName, posterEmail, posterTime,
posterIP, smileysEnabled, body, icon)
VALUES ($board_id, $topic, $poster_id, '$subject', '$poster_name', '$poster_email', " . time() . ",
'$user_info[ip]', $no_smileys, '$message', '$icon')", __FILE__, __LINE__);
$ID_MSG = db_insert_id();

if ($ID_MSG <= 0)
return false;

if (empty($topic))
{
// Insert the new topic.
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numViews)
VALUES ($board_id, $poster_id, $poster_id, $ID_MSG, $ID_MSG, 0)", __FILE__, __LINE__);
$topic = db_insert_id();
}
else
{
db_query("
UPDATE {$db_prefix}topics
SET numReplies = numReplies + 1, ID_LAST_MSG = $ID_MSG, ID_MEMBER_UPDATED = $poster_id
WHERE ID_TOPIC = $topic
LIMIT 1", __FILE__, __LINE__);
}

if ($topic <= 0)
{
// Fix the message with the topic.
db_query("
DELETE FROM {$db_prefix}messages
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);
return false;
}

// Fix the message with the topic id.
db_query("
UPDATE {$db_prefix}messages
SET ID_TOPIC = $topic
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);

db_query("
UPDATE {$db_prefix}boards
SET numPosts = numPosts + 1, numTopics = numTopics + 1
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);

trackStats(array('topics' => '+', 'posts' => '+'));
trackStats();
updateStats('topic');
updateStats('message');
updateLastMessages($board_id);

if (!empty($poster_id))
{
$request = db_query("
SELECT countPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);
list ($pcounter) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($pcounter))
updateMemberData($poster_id, array('posts' => 'posts + 1'));
}

return $topic;
}


Something like that should probably work... even though I'm a bit worn out at the moment.

-[Unknown]

Heatsink

Quote from: [Unknown] on October 21, 2004, 02:14:18 AM
function smf_makePost($poster_id, $poster_name, $poster_email, $subject, $message, $icon, $board_id, $no_smileys = false)

...snip...

}


Something like that should probably work... even though I'm a bit worn out at the moment.

-[Unknown]

Thanks! I managed to muddle my way through it myself and caught the reply increment and the last message set, but I missed the modified by update.

Thanks..you guys rock :)


bmwheaven

Hi, just saw this topic, and now a got a new question...
I'm trying to implement this into my mambo site.
I want to add a forum topic everyime I add an article to mambo.
So now I found the function in the admin-system where the articles are added, and in the end of this function I want to call the smf_makePost function (I put that function in Sources/Post.php).

Now my question is, how do I call the function? everytime I try it I get errors like hacking attempt or open_basedir restriction.
What kind of includes do I have to use to call it without these errors?
I've been trying for a couple of hours, but I don't have a clue....

Please help.
Thanks alot!

Ilir
Sh*t happens
All the time

Heatsink

Quote from: bmwheaven on November 13, 2004, 02:37:09 PM

..snip..

Now my question is, how do I call the function? everytime I try it I get errors like hacking attempt or open_basedir restriction.
What kind of includes do I have to use to call it without these errors?
I've been trying for a couple of hours, but I don't have a clue....

I'm not involved in the development of the software at all, so someone that is may have a more correct answer. However, I can tell you that in order for it to work for me I had to do the following:

Define a variable named SMF and set it to 'true'

Include the following files:

Load.php
Errors.php
Subs.php

Hope that helps


bmwheaven

Owkay,
I tried that, now I dont get any errors anymore...
But still got other problems with the globals defined...
They seem to be empty, is there some instance I have to call?
So I mean, $sourcedir, $db_prefix and $userinfo are empty, why? They are declared as globals, but problem might be that they're not initialized.....
Help? :)
Sh*t happens
All the time

[Unknown]

I would suggest simply including SSI.php.... or, if not, at least Settings.php.

-[Unknown]

bmwheaven

Owkay,
thanks for the replies, but I still cannot figure it out...
This is what I have in my admin.content.php (that is the file that adds an article in mambo):
include ("/home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/SSI.php");
include ("/home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Settings.php");
// smf_makePost with id of user, title of the article, fulltext of the article, and boardid=6
$thetopic = smf_makePost($my->id, $row->title, $row->fulltext, 6);


Then I have this in the Post.php file in Sources folder:
function smf_makePost($poster_id, $subject, $message, $board_id, $no_smileys = false)
{
include ("/home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/SSI.php");
include ("/home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Settings.php");
global $sourcedir, $db_prefix, $user_info;

require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Post.php');
loadLanguage('Post');

// load minimal data for member
$memberResult = loadMemberData($poster_id, false, 'minimal');

$message = addslashes($message);
$subject = addslashes($subject);
$icon = "xx";
$poster_id = (int) $poster_id;
$poster_name = addslashes($memberResult['$poster_id']['options']['realName']);
$poster_email = addslashes($memberResult['$poster_id']['options']['emailAddress']);
$board_id = (int) $board_id;
$no_smileys = $no_smileys ? '0' : '1';

preparsecode($message);

// Insert the post.
db_query("
INSERT INTO {$db_prefix}messages
(ID_BOARD, ID_MEMBER, subject, posterName, posterEmail, posterTime,
posterIP, smileysEnabled, body, icon)
VALUES ($board_id, $poster_id, '$subject', '$poster_name', '$poster_email', " . time() . ",
'$user_info[ip]', $no_smileys, '$message', '$icon')", __FILE__, __LINE__);
$ID_MSG = db_insert_id();

if ($ID_MSG <= 0)
return false;

// Insert the new topic.
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numViews)
VALUES ($board_id, $poster_id, $poster_id, $ID_MSG, $ID_MSG, 0)", __FILE__, __LINE__);
$topic = db_insert_id();

if ($topic <= 0)
{
// Fix the message with the topic.
db_query("
DELETE FROM {$db_prefix}messages
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);
return false;
}

// Fix the message with the topic id.
db_query("
UPDATE {$db_prefix}messages
SET ID_TOPIC = $topic
WHERE ID_MSG = $ID_MSG
LIMIT 1", __FILE__, __LINE__);

db_query("
UPDATE {$db_prefix}boards
SET numPosts = numPosts + 1, numTopics = numTopics + 1
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);

trackStats(array('topics' => '+', 'posts' => '+'));
trackStats();
updateStats('topic');
updateStats('message');
updateLastMessages($board_id);

if (!empty($poster_id))
{
$request = db_query("
SELECT countPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $board_id
LIMIT 1", __FILE__, __LINE__);
list ($pcounter) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($pcounter))
updateMemberData($poster_id, array('posts' => 'posts + 1'));
}

return $topic;
}


Now I get these errors when adding an article in mambo admin:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Subs.php on line 167

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Load.php on line 107

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Load.php on line 109

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Subs.php on line 167

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Load.php on line 741

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Load.php on line 751

Warning: array_unshift(): The first argument should be an array in /home/httpd/vhosts/bmwheaven.bmwsport.net/httpdocs/components/com_smf/Sources/Load.php on line 820


And nothing is added to SMF... :(

Help? :)
Thanks ilir
Sh*t happens
All the time

bmwheaven

Anybody?
Maybe the SMF-guru himself? [Unknown]?
Sh*t happens
All the time

[Unknown]

Looks like it's not able to connect?  SSI is probably not loading because of the bridge...

-[Unknown]

bmwheaven

Could it also be that the variables are still empty?
Sh*t happens
All the time

Advertisement: