1. 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?

Discussion in 'XenForo Development Discussions' started by RastaLulz, Oct 15, 2011.

  1. RastaLulz

    RastaLulz Well-Known Member

    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.
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    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 likes this.
  3. RastaLulz

    RastaLulz Well-Known Member

    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:
    [​IMG]

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

    James Well-Known Member

    What does the javascript console say?
     
  5. Fuhrmann

    Fuhrmann Well-Known Member

    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 likes this.
  6. RastaLulz

    RastaLulz Well-Known Member

    One more question.

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

    Fuhrmann Well-Known Member

    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..
     
    RastaLulz likes this.

Share This Page