How to call XF's 'create thread' function?

1. Where I'm at.
At best, I'm a self-taught procedural hack so OOP is slightly beyond me (I don't even understand the syntax most of the time). I can however, build (what I think) are some complicated things - albeit in ye olde procedural manner. But I can't for the life of me poke through XF's code and figure out what's actually going on.

I get lost in files, calling files that call other files in strange and unique ways that I don't understand. And when I do think I've found what I want, it seems there's not much in that file at all other than a "protected something = null", an empty "_construct" or a "this->that, over->here" none of which makes sense to me. I'm sure this is all relevant OO magic but as I said - it's somewhat beyond me.


2. What I'm trying to do.
I'm trying to build a content posting system (or rather, update one I built that worked with phpBB 2.0 to work with XF). Very simply, people who have access to our content system can post news & content pieces by entering the following information into a custom form:
  • Title
  • Message
  • Tags (comma delimited tags that relate to the news / content item)
  • Category
When the user is finished, they hit 'publish' and their information appears on our news page. However, it also creates a thread in the forum so that users can discuss the news item. This is where I've hit a snag.


3. How I'm trying to do it.
On a simple level, I have my own function that inserts the necessary information directly into the xf_thread and xf_post tables in the database. The thread appears when viewed in the forum and seems to work all right... but it's missing a few things. EG: the option to view the ip of the post doesn't appear - this seems to be related to the xf_ip table. And the 'last post' as seen in the forum index doesn't update (which means updating the xf_forum table as well).

I could of course, figure out where these are and update accordingly but it seems I'm re-inventing the wheel some-what. XF presumably has a built-in function it uses to make threads... if I can find out where it is and how it works, surely I can just call that and send my info through there, then rest easily knowing that XF has done everything XF needs to do.

I can then put my custom stuff (tags and a few other things I keep track of) in my own separate tables, link them to the thread with the appropriate id and all will be right with the world.


4. So, the question is...
Where (as in, what file / which folder?) is the XF "create thread" function and probably much more importantly, how do I call / use it? EG: If I have a $title and $message string, how would I call XF's create thread function to create a new thread using that info?
 
Replying to the question: I can tell that the "create thread" function is located at XenForo_ControllerPublic_Forum in the action actionAddThread. This file can be found in \library\XenForo\ControllerPublic\Forum.php.

You can take a look too at the actionCreateThread which display the form to create a new thread.
 
Top Bottom