Pull Latest Threads

Ludachris

Well-known member
I like that feature in vB.

The search system has parameters for all of this. For example:

http://xenforo.com/community/search..._discussion=1&order=date&nodes[]=5&nodes[]=45

The problem is you have to specify a keyword or member name to search by. You can remove this requirement by editing this file:

library/XenForo/ControllerPublic/Search.php

Add the red code:

Rich (BB code):
    public function actionSearch()
    {
        // note: intentionally not post-only

        if (!XenForo_Visitor::getInstance()->canSearch())
        {
            throw $this->getNoPermissionResponseException();
        }

        $input = $this->_input->filter(array(
            'keywords' => XenForo_Input::STRING,
            'title_only' => XenForo_Input::UINT,
            'date' => XenForo_Input::DATE_TIME,
            'users' => XenForo_Input::STRING,
            'nodes' => array(XenForo_Input::UINT, 'array' => true),
            'child_nodes' => XenForo_Input::UINT,
            'user_content' => XenForo_Input::STRING,

            'order' => XenForo_Input::STRING,
            'group_discussion' => XenForo_Input::UINT
        ));
        $input['type'] = $this->_handleInputType($input);

        if (!$input['order'])
        {
            $input['order'] = 'date';
        }

        $origKeywords = $input['keywords'];
        $input['keywords'] = XenForo_Helper_String::censorString($input['keywords'], null, ''); // don't allow searching of censored stuff

        $visitorUserId = XenForo_Visitor::getUserId();
        $searchModel = $this->_getSearchModel();

        $constraints = $searchModel->getGeneralConstraintsFromInput($input, $errors);
        if ($errors)
        {
            return $this->responseError($errors);
        }

        if (!$input['type'] && $input['keywords'] === ''
            && count($constraints) == 1
            && !empty($constraints['user']) && count($constraints['user']) == 1
        )
        {
            // we're searching for messages by a single user
            $this->_request->setParam('user_id', reset($constraints['user']));
            return $this->responseReroute(__CLASS__, 'member');
        }
/*
        if ($input['keywords'] === '' && empty($constraints['user']))
        {
            // must have keyword or user constraint
            return $this->responseError(new XenForo_Phrase('please_specify_search_query_or_name_of_member'));
        }
*/
        $typeHandler = null;
        if ($input['type'])
        {
            if (is_array($input['type']))
            {
                $typeInfo = $input['type'];
                list($input['type'], $contentInfo) = each($input['type']);
                list($contentType, $contentId) = each($contentInfo);
            }

            $typeHandler = $searchModel->getSearchDataHandler($input['type']);
            if ($typeHandler)
            {
                $constraints = array_merge($constraints,
                    $typeHandler->getTypeConstraintsFromInput($this->_input)
                );
            }
        }

        $search = $searchModel->getExistingSearch(
            $input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], $visitorUserId
        );

        if (!$search)
        {
            $searcher = new XenForo_Search_Searcher($searchModel);

            if ($typeHandler)
            {
                $results = $searcher->searchType(
                    $typeHandler, $input['keywords'], $constraints, $input['order'], $input['group_discussion']
                );

                $userResults = array();
            }
            else
            {
                $results = $searcher->searchGeneral($input['keywords'], $constraints, $input['order']);

                $userResults = $this->_getUserSearch($input['keywords']);
            }

            if (!$results && !$userResults)
            {
                return $this->getNoSearchResultsResponse($searcher);
            }

            $warnings = $searcher->getErrors() + $searcher->getWarnings();

            $search = $searchModel->insertSearch(
                $results, $input['type'], $origKeywords, $constraints, $input['order'], $input['group_discussion'], $userResults,
                $warnings, $visitorUserId
            );
        }

        return $this->responseRedirect(
            XenForo_ControllerResponse_Redirect::SUCCESS,
            XenForo_Link::buildPublicLink('search', $search),
            ''
        );
    }
Now the above link will work.

The presentation is different (shown as search results) because it's using the search system instead of what's new. But it's an easy hack since the search system already has the needed criteria.
Hey @Jake Bunce , I had used your suggestion above successfully in XF 1.5 for years to remove the user name and keyword requirement in searches for preloaded search links. Should this file edit trick also work in 2.1? I can't seem to replicate it. The preloaded search string I'm using results in an error message that says "Please specify a search query or the name of a member" which leads me to believe that commenting out that code didn't do the trick.
 
Top