• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Where are posts created inside XenForo?

RastaLulz

Well-known member
#1
Hello,

I'm trying to hard code something into XenForo so that when someone creates a post, it will show up in the shout box. But I don't know exactly where the function is for inserting a post, or which file it is in.

Basically what I want to do is add another MySQL query in the create post function to add a shout when someone makes a post.
 

Fuhrmann

Well-known member
#2
You can extend the XenForo_ControllerPublic_Thread using the action "actionAddReply()".

The file is here: library/XenForo/ControllerPubic/Thread.php

And extend too the XenForo_ControllerPublic_Forum in the action "actionAddThread()".
The file is here: library/XenForo/ControllerPubic/Forum.php
 

RastaLulz

Well-known member
#3
Not exactly how any of this really works..

I tried adding the following query in the actionAddReply() function in library/XenForo/ControllerPubic/Thread.php:
PHP:
        $writer->save();

          /*
            $db = $this->_getDb();

            $db->query("INSERT INTO xf_dbtech_xfshout_shout
      (userid, dateline, message, message_parsed, type, pmuserid, notification, forumid, instanceid, chatroomid) VALUES
      ('1', '1318639882', 'Hello world, I just posted..', 'Hello world, I just posted..', '1', '0', '', '0', '1', '0')");
      */
But I get the following error (the post is still submitted) and the query doesn't execute:


I tested the query in phpMyAdmin, so I know it's good. Sorry for being such a total newbie.
 

Fuhrmann

Well-known member
#5
Since XFShoutBox has own DataWriter you could use something like this:

// Init the datawriter
$dw = XenForo_DataWriter::create('DBTech_xFShout_DataWriter_Shout');
$dw->set('userid', $userId);
$dw->set('dateline', XenForo_Application::$time);
$dw->set('message', 'Hello world i just posted...');
$dw->set('message_parsed', 'Hello world, I just posted..');
...
...
...
..
...
$dw->save();
 

RastaLulz

Well-known member
#6
Since XFShoutBox has own DataWriter you could use something like this:

// Init the datawriter
$dw = XenForo_DataWriter::create('DBTech_xFShout_DataWriter_Shout');
$dw->set('userid', $userId);
$dw->set('dateline', XenForo_Application::$time);
$dw->set('message', 'Hello world i just posted...');
$dw->set('message_parsed', 'Hello world, I just posted..');
...
...
...
..
...
$dw->save();
One more question.

Is there a way to get the thread title without having to use a SQL query in actionAddReply()?
 

Fuhrmann

Well-known member
#7
One more question.

Is there a way to get the thread title without having to use a SQL query in actionAddReply()?
Yes, you can use this:

$threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);

$visitor = XenForo_Visitor::getInstance();
$ftpHelper = $this->getHelper('ForumThreadPost');
$threadFetchOptions = array('readUserId' => $visitor['user_id']);
list($thread) = $ftpHelper->assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions);

Then use th e $thread['title'] to show the title. With this you will have all fields of the thread to use.

I think it works, did'n test. You can use $visitor['username'] too..