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

Check thread information based on permissions?

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 15, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    This is the code I am using to retrieve thread information:
    Code:
    public function getThreads()
    {
    	$options = XenForo_Application::get('options');
    	$visitorID = XenForo_Visitor::getUserId();
    
    	$conditions = array(
    		'deleted' => false,
    		'moderated' => false,
    	);
    
    	$fetchOptions = array(
    		'join' => XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_USER,
    		'readUserId' => $visitorID,
    		'postCountUserId' => $visitorID,
    		'permissionCombinationId' => $visitorID,
    		'order' => 'last_post_date',
    		'orderDirection' => 'desc',
    		'limit' => $options->EWRporta_threadcount,
    	);
    
    	$threads = $this->getModelFromCache('XenForo_Model_Thread')->getThreads($conditions, $fetchOptions);
    
    	foreach ($threads AS &$thread)
    	{
    		$thread = $this->getModelFromCache('XenForo_Model_Thread')->prepareThread($thread, $thread);
    		$thread['canInlineMod'] = false;
    		$thread['canEditThread'] = false;
    	}
    
    	return $threads;
    }
    For some reason, its not excluding thread information that the user can't view... such as threads from private forums. It displays all threads, no matter the permission requirements of the forum.
     
  2. Indigo

    Indigo Active Member

    For the permissionCombinationId option, instead of $visitorID, try XenForo_Visitor::getInstance()->permission_combination_id;
     
  3. Jaxel

    Jaxel Well-Known Member

    people are saying that didnt work...
     
  4. Indigo

    Indigo Active Member

    Looks like there may be more steps involved. I started looking through the member controller's recent content action, then followed it through the search system and how it filters out non-viewable threads. I'll check into it and test it more closely later tomorrow, unless you get to it first. Unfortunately, from what I've glanced through, it doesn't look like there's an easy way to get "latest X threads user can view" in a single query, it instead just grabs a number of entries and removes ones you can't view. I'll have to take a closer look at the permission tables to see what can be done.
     
  5. ragtek

    ragtek Guest

    it's easy;)

    PHP:
    <?php

    class Ragtek_Feed_ControllerPublic_Feed extends XenForo_ControllerPublic_Abstract
    {
        public function 
    actionIndex()
        {
            
    $threadModel $this->_getThreadModel();
            
    $searchModel $this->_getSearchModel();
            
    $this->_routeMatch->setResponseType('rss');
            
    $fetchOptions = array(
                                
    'order' => 'last_post_date',
                                
    'orderDirection' => 'desc',
                                
    'limit' => 50
        
    );

            
    $threadKeys array_keys($threadModel->getThreads(array(
                
    'deleted' => false,
                
    'moderated' => false
                
    ), $fetchOptions
            
    ));

            
    $results = array();
            foreach (
    $threadKeys AS $threadId)
            {
                    
    $results[] = array('content_type' => 'thread''content_id' => $threadId);
            }

            
    $results $searchModel->getViewableSearchResults($results);
            
    $results $searchModel->getSearchResultsForDisplay($results);
            
    $viewParams = array(
                
    'results'   =>  $results
            
    );

            return 
    $this->responseView('Ragtek_Feed_View''forum_view'$viewParams);
        }

        
    /**
         * @return XenForo_Model_Thread
         */
        
    protected function _getThreadModel()
        {
            return 
    $this->getModelFromCache('XenForo_Model_Thread');
        }


        
    /**
         * @return XenForo_Model_Search
         */
        
    protected function _getSearchModel()
        {
            return 
    $this->getModelFromCache('XenForo_Model_Search');
        }
    }
    the important part is

    foreach ($threadKeys AS $threadId)
    {
    $results[] = array('content_type' => 'thread', 'content_id' => $threadId);
    }

    $results = $searchModel->getViewableSearchResults($results);




    donations are welcome for this peace of code:p
     
  6. Indigo

    Indigo Active Member

    Yeah, that's something like what I was looking at. The only thing is, though you set the limit to 50, I believe that getViewableSearchResults() will strip out threads you can't view, which can result in there being less threads than you asked for. So, if you set the limit to 5, and the latest 5 threads were in private forums, you'd get no results.
     
  7. ragtek

    ragtek Guest

    Yes, that's true, but that's what i've found in the xenforo code ("what's new" is using it)
     

Share This Page