adding a 'simple' thing to FUD [message #20010] |
Tue, 21 September 2004 14:10 |
johed802
Messages: 24 Registered: September 2004
Karma: 0
|
Junior Member |
|
|
Hi!
I'm trying to add some functionality to the forum. When a user registers to the forum, I want to create a new thread for this user at the same time. I added some code to the file register.php; a function called add_topic which is called right after add_user. In my function I use this object: $msg_post = new fud_msg_edit. An object that is used when posting.
This actually works to some extent. At least if I look in the DB afterwards I can see that it put new stuff in _threads, and _msg, and even put stuff on the file in the messages directory in the 'data_root'. My problem is that this new thread doesn't appear in the thread list. I noticed that no data was put into the table _thread_view. This might be the problem. Should I do this 'manually'or what? Did I miss some function from the msg object? My add_topic function can be seen here, I copied a lot of code from the file post.php.t:
function add_topic ($id)
{
$msg_post = new fud_msg_edit;
/* Process Message Data */
$msg_post->poster_id = $id;
$msg_post->poll_id = $pl_id;
$msg_post->subject = "welcome to the forum!";
$msg_post->body = "bla bla bla ...";
$msg_post->body = apply_custom_replace($msg_post->body);
$msg_post->body = nl2br(htmlspecialchars($msg_post->body));
fud_wordwrap($msg_post->body); //?
$msg_post->subject = htmlspecialchars(apply_custom_replace($msg_post->subject));
// trying to create a thread
$create_thread = 1;
$msg_post->add(1, 0, "N", "N", "N", FALSE);
user_register_forum_view(1);
rebuild_forum_view(1, 1); // do i need to?
}
Any ideas?
Thanx in advance!
|
|
|
Re: adding a 'simple' thing to FUD [message #20013 is a reply to message #20010] |
Tue, 21 September 2004 15:48 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
I recommend using fudapi (can be found inside the scripts/ directory). This script has "safe" API functions for creating topics, replies etc...
FUDforum Core Developer
|
|
|
|
Re: adding a 'simple' thing to FUD [message #20029 is a reply to message #20024] |
Wed, 22 September 2004 13:50 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
looks inside the forum's scripts/ directory, if you don't see it there you need to upgrade to a later version of the forum.
FUDforum Core Developer
|
|
|
|
Re: adding a 'simple' thing to FUD [message #20078 is a reply to message #20077] |
Fri, 24 September 2004 14:19 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
You need to add entry to thread view and you need to make sure that thread & msg table entries refence one another.
FUDforum Core Developer
|
|
|
Re: adding a 'simple' thing to FUD [message #20119 is a reply to message #20078] |
Mon, 27 September 2004 12:12 |
johed802
Messages: 24 Registered: September 2004
Karma: 0
|
Junior Member |
|
|
Hi again,
they actually reference one another. I think this code takes care of that:
$msg_post->add(1, 0, "N", "N", "N", FALSE);
I have to insert into the thread_view table in order to see the new tread, but as I said, I can only see it in thread view, not in the 'tree' view.
One thing that puzzles me is the tmp column in th thread_view table. What does in mean? What does it do?
thnx
/Johan
[Updated on: Mon, 27 September 2004 12:15] Report message to a moderator
|
|
|
Re: adding a 'simple' thing to FUD [message #20120 is a reply to message #20119] |
Mon, 27 September 2004 12:42 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
The tmp column is a "dummy" column that is used during quick population of the table.
As far as the tree view not showing the message, make sure that you did $msg->approve(); after add.
FUDforum Core Developer
|
|
|
|
|
|
Re: adding a 'simple' thing to FUD [message #20147 is a reply to message #20139] |
Wed, 29 September 2004 07:57 |
johed802
Messages: 24 Registered: September 2004
Karma: 0
|
Junior Member |
|
|
My swedish characters still look really bad... this is my code. Any other suggestions?
function add_topic ($id)
{
$msg_post = new fud_msg_edit;
/* Process Message Data */
$msg_post->poster_id = $id;
$msg_post->subject = "Välkommen till testforum_";
$msg_post->body = "Välkommen till forumet\n\nHär kan du göra lite av varje Å-Ä-Ö";
$msg_post->body = tags_to_html($msg_post->body);
$msg_post->subject = tags_to_html($msg_post->subject);
$msg_post->add(1, 0, "N", "N", "N", FALSE);
//additional stuff
q("insert into {SQL_TABLE_PREFIX}thread_view (forum_id, page, thread_id) select '1','1', max(id) from {SQL_TABLE_PREFIX}thread");
$result = uq("select max(id) from {SQL_TABLE_PREFIX}msg");
$var = db_rowarr($result);
if(isset($var[0])){
q("update {SQL_TABLE_PREFIX}msg set approved='Y' where id = ".$var[0]);
}
}
thnx
/Johan
[Updated on: Wed, 29 September 2004 11:46] Report message to a moderator
|
|
|
|
|
Re: adding a 'simple' thing to FUD [message #20184 is a reply to message #20152] |
Thu, 30 September 2004 22:37 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
You can try passing the text through htmlentities() function.
Another solution is to review code inside fudapi's message creation function and copy the code from there.
FUDforum Core Developer
|
|
|
|
|
|
Re: adding a 'simple' thing to FUD [message #20282 is a reply to message #20199] |
Wed, 06 October 2004 07:54 |
johed802
Messages: 24 Registered: September 2004
Karma: 0
|
Junior Member |
|
|
Hi!
Now I'm interested in creating a reply to a given thread. I have this code so far:
$reply_msg = new fud_msg_edit;
$reply_msg->poster_id = $id;
$reply_msg->subject = "a reply";
$reply_msg->body = "body of msg";
$reply_msg->add_reply(151, 118, "", "", TRUE); //118=thread_id, 151=msg id
$result = uq("select max(id) from {SQL_TABLE_PREFIX}msg");
$var = db_rowarr($result);
if(isset($var[0])){
$reply_msg->approve($var[0], FALSE);
}
The problem is that it creates a separate thread for this, not a reply. Any ideas on how to create a simple reply to a thread?
[Updated on: Wed, 06 October 2004 12:40] Report message to a moderator
|
|
|
|
|
|
|
|