1. 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 ?

Discussion in 'XenForo Development Discussions' started by Ghostaunt, Aug 21, 2015.

  1. Ghostaunt

    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
    ));
     

    Attached Files:

    • x1.PNG
      x1.PNG
      File size:
      50.6 KB
      Views:
      1
    • x2.PNG
      x2.PNG
      File size:
      11.8 KB
      Views:
      1
    • x3.PNG
      x3.PNG
      File size:
      12.6 KB
      Views:
      1
    • x4.PNG
      x4.PNG
      File size:
      26.1 KB
      Views:
      1
    • x5.PNG
      x5.PNG
      File size:
      25.1 KB
      Views:
      1
    Last edited: Aug 21, 2015
  2. Arty

    Arty Well-Known Member

    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'],
    
     
  3. Ghostaunt

    Ghostaunt Active Member

    Hello, and thanks for your reply.
    I tried it and it doesn't work.
     
  4. Arty

    Arty Well-Known Member

    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. Ghostaunt

    Ghostaunt Active Member

    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
     
  6. Arty

    Arty Well-Known Member

    Change
    Code:
    'limit' => $limit,
    to
    Code:
    'limit' => $limit * 2,
    and append this:
    Code:
        $last_posts = array_slice($last_posts, 0, $limit, true);
    
     
  7. Ghostaunt

    Ghostaunt Active Member

    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
     
  8. Arty

    Arty Well-Known Member

    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.
     
  9. Ghostaunt

    Ghostaunt Active Member

    Ok ok :)
    Thank you Arty, you save me a lot of time... :)
     

Share This Page