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

Custom New Thread/Post Listener

Discussion in 'XenForo Development Discussions' started by viaBowl, Aug 26, 2013.

  1. viaBowl

    viaBowl Member

    Where's the best place or best practice in creating a listener to execute code when a new thread is created?

    Does some examples exist?
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    You need to use load_class_controller and extend XenForo_ControllerPublic_Thread / XenForo_ControllerPublic_Forum.

    Several add-ons have done it, I believe [bd] Bank does it.
     
  3. viaBowl

    viaBowl Member

    grr. More specifically... I'm wanting to copy the first post in a new thread to another database after its created.
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    You should read through the classes, and you'll figure out how XenForo is adding posts. You can then quickly and easily learn how to copy them.
     
  5. viaBowl

    viaBowl Member

    maybe i'm missing something. My add-on is quite basic, and here's the code:

    PHP:
    class XFtoWP_ControllerPublic_Forum extends XFCP_ControllerPublic_Forum
    {
        public function 
    actionAddThread()
        {
            
    $response parent::actionAddThread();
           
    // do something here...

        
    }
    }
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    And what's wrong with it? Without more code and a specific error, it's slightly difficult to advise you on which way to go.
     
  7. Nobita.Kun

    Nobita.Kun Well-Known Member

  8. viaBowl

    viaBowl Member

    well... for testing purposes, i tried an email function to see what i get, and even junk code to trigger an error, nothing happens.
     
  9. Jeremy

    Jeremy XenForo Moderator Staff Member

  10. viaBowl

    viaBowl Member

    okay, and my file structure should be /library/MyAddon/ControllerPublic.php, correct?
     
  11. Jeremy

    Jeremy XenForo Moderator Staff Member

    No, your class is XFtoWP_ControllerPublic_Forum. You'll change the underscores to slashes and add .php. So, XFtoWP/ControllerPublic/Forum.php. However, your problem is in your XFCP class.
     
  12. viaBowl

    viaBowl Member

    Please forgive my ignorance. 12 years of vbulletin syndrome are hard to shake.
     
  13. viaBowl

    viaBowl Member

    ok... /library/XFtoWP/Forum.php

    PHP:
    class XFtoWP_ControllerPublic_Forum extends Xenforo_ControllerPublic_Forum
    {
        public function 
    actionAddThread()
        {
            
    $response parent::actionAddThread();
            
    // my custom code here....
        
    }
    }
    and nothing still.
     
  14. Jeremy

    Jeremy XenForo Moderator Staff Member

    Reread my post. You have placed the file in the wrong location. You also do not extend XenForo classes directly. You need to use the XenForo Class Proxy system as described in my resource. Have you created a listener?
     
  15. viaBowl

    viaBowl Member

    nope. Someone should write a SDK with sample code. :(
     
  16. Jeremy

    Jeremy XenForo Moderator Staff Member

    The code is well documented, and resources exist to explain nearly everything. The resource listed above will walk you through it.
     
  17. viaBowl

    viaBowl Member

    I've done all that, and still get nothing.
     
  18. Jeremy

    Jeremy XenForo Moderator Staff Member

    Then you've missed a step. Have you added the listener in the ACP?
     
  19. viaBowl

    viaBowl Member

    yup yup
     
  20. Jeremy

    Jeremy XenForo Moderator Staff Member

    Then you'll need to post the code you are using, it's location and any errors you're getting.
     

Share This Page