XF 1.5 How to get current node ID from a visitor

Jarvis901

Member
Hi!

The plugin I'm working on gets executed when a user makes post/thread. I'm trying to make it where it is only executed in certain nodes. Is there a good way to get node ID in a similar fashion as "XenForo_Visitor::getInstance()". I tried to find a method similar to getNodeID() but I couldn't find anything.

Thanks
 
It depends by used controller. You should get post/thread array data, post will contain thread id and node id perhaps. Thread array will be contain 100% node_id element. Tell us more precisely about your addon, give code parts
 
Thanks for the info.

I will need to omit quite a few things here but essentially I'm trying to execute a function here

DataWriter\DiscussionMessage\Post

Code:
protected function _messagePreSave()
{

parent::_messagePreSave();

      $node_id = '';

      $exclude_list = XenForo_Application::get('options')->exclusion_list;

      (sudo) if node_id is not in exclude_list { then do something }
 
Thanks for the info.

I will need to omit quite a few things here but essentially I'm trying to execute a function here

DataWriter\DiscussionMessage\Post

PHP:
protected function _messagePreSave()
{

parent::_messagePreSave();

      $node_id = '';

      $exclude_list = XenForo_Application::get('options')->exclusion_list;

      (sudo) if node_id is not in exclude_list { then do something }

Why did you choose datawriter class to do something?
Maybe more correctly overridy actionAddReply() function in XenForo_ControllerPublic_Thread?

PHP:
$parent = parent::actionAddReply();
if ($parent instanceof XenForo_ControllerResponse_Redirect || $parent instanceof XenForo_ControllerResponse_View)
{
    $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
    $ftpHelper = $this->getHelper('ForumThreadPost');
    list($threadFetchOptions, $forumFetchOptions) = $this->_getThreadForumFetchOptions();
    list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions);
    if ($forum['node_id'] == X)
    {
        // do smth
    }
}

return $parent;
 
Thanks for the info.

I will need to omit quite a few things here but essentially I'm trying to execute a function here

DataWriter\DiscussionMessage\Post

Code:
protected function _messagePreSave()
{

parent::_messagePreSave();

      $node_id = '';

      $exclude_list = XenForo_Application::get('options')->exclusion_list;

      (sudo) if node_id is not in exclude_list { then do something }

This code may work.

Code:
$forumInfo = $this->getExtraData('forumInfo');

$nodeId = isset($forumInfo['node_id']) ? $forumInfo['node_id'] : false;
 
@PatM

Thank you very much! That piece of code worked beautifully.

@grisha2217

It's something that needed to be done before a post is actually made. I'm not sure if it's the right way but it kind of make sense in my head and it works so far.
 
Back
Top Bottom