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

Getting the forum number from the URI

Discussion in 'XenForo Development Discussions' started by AndyB, Feb 10, 2014.

  1. AndyB

    AndyB Well-Known Member

    I'm creating an add-on which is extending the DataWriter_preSave().

    When a member is creating a new thread, I would like to be able to throw a error message if they are in the incorrect forum, so I need to get the forum number from the URI.

    I can do this using the PHP command:

    $var $_SERVER['REQUEST_URI'];
    After I get $var I parse for the forum number, but this is messy.

    It would be great if I could use an existing XF command designed for this purpose. I have tried the following without success:

    $nodeId $this->_input->filterSingle('node_id'XenForo_Input::UINT);
    Thank you.
  2. Syndol

    Syndol Guest

    I hope I'm not missing your point here, but if you are dealing with thread creation then why not extend XenForo_DataWriter_Discussion_Thread
    You can then get the forum id thus:
    if ($this->isInsert())
    $forumId $this->get('node_id');
    I assume you are checking the message content in order to find out if they are posting in the correct forum?!

    Would it not be simpler to run your check in function actionAddThread() ?
    Last edited by a moderator: Feb 10, 2014
    AndyB likes this.
  3. AndyB

    AndyB Well-Known Member

    Hi Syndol,

    Thank you for your assistance.

    I ended up extending ControllerPublic_Forum::actionCreateThread. This way I can throw the error before the user wastes time typing in a message.

    I still ended up parsing the URL using the $_SERVER['REQUEST_URI'] command, but I assume that's the only way to get the current forum ID.
  4. xf_phantom

    xf_phantom Well-Known Member

    $nodeId $this->_input->filterSingle('node_id'XenForo_Input::UINT);
    Should work inside the controller.
    Syndol likes this.
  5. Syndol

    Syndol Guest

    Well if all you want to do is prevent them from creating the thread all together then why not extend function canPostThreadInForum() in XenForo_Model_Forum
    That way the create thread button will not even appear if they cannot post.
    AndyB and xf_phantom like this.
  6. AndyB

    AndyB Well-Known Member

    Thank you, Syndol.

    I sure do appreciate the very good suggestions.

    The add-on which I have created is designed to force new users to make their first post be in an Introduction forum. My thinking is that once they are approved they really should see the same links (Reply, Create Thread etc..) as any other member. The error message is thrown once they try to create a new thread in anything other than the Introduction forum.
    Syndol likes this.
  7. James

    James Well-Known Member

    Is this not possible by creating a user upgrade? <1 posts and you can only post in Introductions, >1 post and you upgrade them?
  8. Syndol

    Syndol Guest

    That makes sense. I was just suggesting other stuff as I was not sure where you were going with this.
    True, but the user will not get a message explaining why they cannot post there (unless you create a notification of course).
  9. AndyB

    AndyB Well-Known Member

    Hi James,

    Thank you for the suggestion. I prefer to have one user group for all my members. It just keeps things simple that way.
  10. AndyB

    AndyB Well-Known Member

    Yes I have code to handle a new Reply as well. :)
  11. xf_phantom

    xf_phantom Well-Known Member

    my code won't work for everybody:whistle: (not everybody is including the node_id in the url)
    This should do it:
    $forumId $this->_input->filterSingle('node_id'XenForo_Input::UINT);
    $forumName $this->_input->filterSingle('node_name'XenForo_Input::STRING);
    $ftpHelper $this->getHelper('ForumThreadPost');
    $forum $ftpHelper->assertForumValidAndViewable($forumId $forumId $forumName);

    $nodeId $forum['node_id'];
    AndyB likes this.

Share This Page