FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » adding a 'simple' thing to FUD
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
adding a 'simple' thing to FUD [message #20010] Tue, 21 September 2004 14:10 Go to next message
johed802 is currently offline  johed802   Sweden
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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #20024 is a reply to message #20010] Wed, 22 September 2004 07:23 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Sorry but.. exactly where is that script? I don't have it on my computer, and I can't find it on this site. Do I need a special version of the forum for this script?
Re: adding a 'simple' thing to FUD [message #20029 is a reply to message #20024] Wed, 22 September 2004 13:50 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #20077 is a reply to message #20029] Fri, 24 September 2004 12:49 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
I can't upgrade the version of the forum. I did so many changes to my forum that it would take forever to patch it. I'm going to have to stick with this *unsafe* function.

This code above creates a new thread; I can see it in the tables _thread and _msg, but not in the thread view in the forum. This is the problem. Of course, I can add stuff like inserting a row in the table _thread_view. Then the thread appears in the thread view, but, when clicking on the thread it's empty. The sender is appears as Anonymous Coward which is also wrong...

What code do I need to add in order for the posted msg to work? I noticed that the body of the msg is on the disk in the messages/ directory. Any ideas?

/Johan
Re: adding a 'simple' thing to FUD [message #20078 is a reply to message #20077] Fri, 24 September 2004 14:19 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
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? Confused

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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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
icon10.gif  Re: adding a 'simple' thing to FUD [message #20122 is a reply to message #20120] Mon, 27 September 2004 12:46 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Thanx bro Smile
icon5.gif  Re: adding a 'simple' thing to FUD [message #20134 is a reply to message #20120] Tue, 28 September 2004 10:48 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
One more thing though...

I don't get very good formatting on the text in the msg I want to produce. If I want to use newlines and special swedish characters like ä (ä), how do I do that?
 $msg_post->body = "Hej och välkommen till testforumet\n\nDetta är en ny rad\nNew line";


I guess there should be some formatting function somewhere.

thnx
/Johan
Re: adding a 'simple' thing to FUD [message #20139 is a reply to message #20134] Tue, 28 September 2004 13:12 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
tags_to_html() function inside post_proc.inc.t

FUDforum Core Developer
icon5.gif  Re: adding a 'simple' thing to FUD [message #20147 is a reply to message #20139] Wed, 29 September 2004 07:57 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
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 #20151 is a reply to message #20147] Wed, 29 September 2004 12:22 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Instead of all the additional stuff simply call $msg_post->approve()

FUDforum Core Developer
Re: adding a 'simple' thing to FUD [message #20152 is a reply to message #20151] Wed, 29 September 2004 13:30 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Ilia wrote on Wed, 29 September 2004 14:22

Instead of all the additional stuff simply call $msg_post->approve()


This results in i major malfunction for me; the page turns blank. I guess my version of the forum can't handle that function call.

Anyway, the only problem is the swedish characters. Newlines work now thanx to this line:
$msg_post->body = apply_custom_replace($msg_post->body);

I think I need my swedish letters written on a windows system. Now I create a file in linux containing swedish letters and those are different from windows. Maybe something like this?

/Johan
Re: adding a 'simple' thing to FUD [message #20184 is a reply to message #20152] Thu, 30 September 2004 22:37 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 #20194 is a reply to message #20184] Fri, 01 October 2004 12:02 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Ilia wrote on Fri, 01 October 2004 00:37

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.


Would you mind posting that code here? I was unable to install the latest FUD. The install script halted because it couldn't find some function for unpacking. Maybe my php version is too old? Confused
Re: adding a 'simple' thing to FUD [message #20198 is a reply to message #20194] Fri, 01 October 2004 13:59 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Here you go.

FUDforum Core Developer
Re: adding a 'simple' thing to FUD [message #20199 is a reply to message #20198] Fri, 01 October 2004 14:36 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
thanx Smile I will review it
Re: adding a 'simple' thing to FUD [message #20282 is a reply to message #20199] Wed, 06 October 2004 07:54 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
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

Re: adding a 'simple' thing to FUD [message #20286 is a reply to message #20282] Wed, 06 October 2004 16:16 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Did you change {SQL_TABLE_PREFIX} to your forum's table prefix?

FUDforum Core Developer
Re: adding a 'simple' thing to FUD [message #20300 is a reply to message #20286] Thu, 07 October 2004 06:49 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Ilia wrote on Wed, 06 October 2004 18:16

Did you change {SQL_TABLE_PREFIX} to your forum's table prefix?


No, I don't have to. It's translated to the correct table prefix via GLOBALS.php and then the resulting php-file ends up in the theme/ directory. My code is taken from register.php.t in the src/ directory.
Re: adding a 'simple' thing to FUD [message #20302 is a reply to message #20286] Thu, 07 October 2004 09:40 Go to previous messageGo to next message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Hi!

I'm thinking.. since I can't do my reply the usual way (using add_reply (...) ), I might try to do it in an "unsafe" way. Maybe I should just insert into the msg table and adjust it a bit. The big problem is I don't know exactly how to write the body of the msg on disc. I saw this code in the file imsg_edt.inc.t:
$file_id = write_body($this->body, $length, $offset);

I think i know what $length is, but what is $offset? How do you calculate this variable? Is this related to the foff field in the msg table in the DB?

thnx
/Johan
Re: adding a 'simple' thing to FUD [message #20304 is a reply to message #20300] Thu, 07 October 2004 12:50 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Who told you that it is translated automatically? Smile

It only is translated if it is compiled by template generation code.


FUDforum Core Developer
Re: adding a 'simple' thing to FUD [message #20306 is a reply to message #20304] Thu, 07 October 2004 13:32 Go to previous message
johed802 is currently offline  johed802   Sweden
Messages: 24
Registered: September 2004
Karma: 0
Junior Member
Nevemind everything works now Smile (so far...)
I "complie" via the web: Theme management -> compile theme, so the translation isn't a problem for me.

/Johan
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: New script: fudbox.php
Next Topic: How do I get error messages?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 18:22:19 GMT 2024

Total time taken to generate the page: 0.02393 seconds