[RESOLVED] User Viewable Node List issue ?

Ghostaunt

Active member
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

  • x1.webp
    x1.webp
    34.6 KB · Views: 2
  • x2.webp
    x2.webp
    8.7 KB · Views: 2
  • x3.webp
    x3.webp
    8.3 KB · Views: 3
  • x4.webp
    x4.webp
    15.3 KB · Views: 2
  • x5.webp
    x5.webp
    19.4 KB · Views: 2
Last edited:
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'],
 
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]);
       }
     }
 
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
 
Change
Code:
'limit' => $limit,
to
Code:
'limit' => $limit * 2,
and append this:
Code:
    $last_posts = array_slice($last_posts, 0, $limit, true);
 
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
 
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.
 
Back
Top Bottom