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

[RESOLVED] User Viewable Node List issue ?

#1
Hello

I have made a plugin that show all last threads in all forums, for the current user.
So first, I get all viewables node list from the current user, but there is an issue with this list.

In the list, I have node id which are private node.
I don't understand why.

So, user are can see thread TITLE in private node, but can't see thread CONTENT (has I want).
How can I do, to don't get this private node in the list please ?

Thanks

Here my code :
PHP:
$node_model = XenForo_Model::create('XenForo_Model_Node');
$nodes = array_keys($node_model->getViewableNodeList());

$thread_model = XenForo_Model::create( 'XenForo_Model_Thread' );
$last_posts = $thread_model->getModelFromCache('XenForo_Model_Thread')->getThreads(array(
'discussion_state' => 'visible',
'not_discussion_type' => 'redirect',
'deleted' => false,
'moderated' => false,
'node_id' => $nodes
), array(
'limit' => $limit,
'order' => 'post_date',
'orderDirection' => 'desc',
'join' => XenForo_Model_Thread::FETCH_USER
));
 

Attachments

Last edited:

Arty

Well-known member
#2
Try adding this at beginning of your code
Code:
$visitor = XenForo_Visitor::getInstance();
and this after 'join' row in array in last parameter
Code:
,
      'permissionCombinationId' => $visitor['permission_combination_id'],
 

Arty

Well-known member
#4
Also add this
Code:
    foreach ($last_posts AS $key => &$thread)
     {
       $thread['permissions'] = XenForo_Permission::unserializePermissions($thread['node_permission_cache']);

       if (!$threadModel->canViewThreadAndContainer($thread, $thread, $null, $thread['permissions']))
       {
         unset($last_posts[$key]);
       }
     }
 
#5
Yes it work, but now if i've requested 5 last thread i can get only 4, or 3, 2....
I think there is an other way to fix that :s

Thank you again
 

Arty

Well-known member
#6
Change
Code:
'limit' => $limit,
to
Code:
'limit' => $limit * 2,
and append this:
Code:
    $last_posts = array_slice($last_posts, 0, $limit, true);
 
#7
Yes I can do this ^^
You are very clever but I it's not very proper to do that.

I'll use this trick untill I find an other solution (if there is one...)
Thanks Arty
 

Arty

Well-known member
#8
XenForo does it that way as well. There is no way to check permissions while fetching rows, so it fetches 2 or 3 times more rows than needed, then removes extra rows.