How to get node_id when extending XenForo_ControllerPublic_Abstract

Note that as soon as I type a character into the title input box, I get the error. So I think the AJAX that normally brings up the Similar Threads results is somehow conflicting.
 
This is my Route Prefix code:

PHP:
<?php

class Andy_SimilarThreads_Route_Prefix_SimilarThreads implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('Andy_SimilarThreads_ControllerPublic_Forum', 'Index', $routePath);
	}
}

?>

If I comment out the return line I don't get the error message. But then the AJAX stops working.
 
ah, i see, you create a new route named "similarthreads" with the controller "Andy_SimilarThreads_ControllerPublic_Forum", meanwhile you're extending XenForo_ControllerPublic_Forum with the same class, so it doesn't make any sense.
 
Originally I was extending the XenForo_ControllerPublic_Abstract but asked why I was extend that. So upon suggestion I changed it to extend XenForo_ControllerPublic_Forum which works, but I'm still not able to get the node_id. Then it was suggested that try extending using XFCP which appears to not work due to the conflict in the route that I create in the same controller.
 
Last edited:
I put the code back as I had it, that is I'm extending the XenForo_ControllerPublic_Abstract.

I was able to get the node_id by using the following code in my model.

PHP:
$visitor = XenForo_Visitor::getInstance();
$userId = $visitor['user_id'];	
 
$params = $this->_getDb()->fetchOne("
SELECT params
FROM xf_session_activity
WHERE user_id = '$userId'
AND controller_action = 'CreateThread'
");

if ($params != '') 
{
    $pos1 = strpos($params,'node_id=');
    
    if (is_numeric($pos1))
    {
        $currentNodeId = substr($params,8);
    }
}
 
Hi Andy,
If you want to extends XenForo_ControllerPublic_Forum, use another class because Andy_SimilarThreads_ControllerPublic_Forum was using for the route "similarthreads". But i don't think you need to create new route, just extending the XenForo_ControllerPublic_Forum and create new action. Here are my suggestions.

- Extending XenForo_ControllerPublic_Forum and add an action (ie: SimilarThreads), so it could be access via http://yourdomain/forums/forum.1/similar-threads.
- Using TMC add the action url via data attribute to the input thread title (ie data-checkUrl="{xen:link forum/similar-threads, $forum}").
- Change your AJAX url in the js file.
Code:
XenForo.ajax(
                $('base').attr('href') + 'similarthreads/',
                $form.serializeArray(),
                function(ajaxData, textStatus)
...............
to
Code:
XenForo.ajax(
                $title.data('checkUrl'),
                { title: $title.val() },
                function(ajaxData, textStatus)
................
- So in your new action you can get the node_id and thread title as well.
PHP:
public function actionSimilarThreads()
{
        $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);

        $forumId = $forum['node_id'];
        $title= $this->_input->filterSingle('title', XenForo_Input::STRING);

        // your code goes here
}
- You don't need to write new SQL queries for this, you can fetch all your results by using XenForo_Model_Thread.
 
Hi Andy,
If you want to extends XenForo_ControllerPublic_Forum, use another class because Andy_SimilarThreads_ControllerPublic_Forum was using for the route "similarthreads". But i don't think you need to create new route, just extending the XenForo_ControllerPublic_Forum and create new action. Here are my suggestions.

Hi Milano,

Thank you kindly for taking the time to look at this problem and suggesting a solution.

I think the main issue is the route prefix is conflicting with any attempt to extend the XenForo_ControllerPublic_Forum with a Code Event Listener using XFCP. Look at post #22 and you see it does something to the ControllerPublic_Forum which I think is the conflict.
 
Top Bottom