post view for guests

Jim Boy

Well-known member
I'm trying to deteremine whether posts can be viewed by guests, including when the post is in a private node:

The code I have is

Code:
  $postmodel=XenForo_Model::create('XenForo_Model_Post');
  $post = $postmodel->getPostById($postid, array(
  'join' => XenForo_Model_Post::FETCH_USER | XenForo_Model_Post::FETCH_USER_PROFILE | XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_FORUM
  )
  );
  $userModel = XenForo_Model::create('XenForo_Model_User');
    $errorPhraseKey="";
   
  if (!empty($post) && $postmodel->canViewPost($post, $post, $post, $errorPhraseKey, null, $userModel->getVisitingGuestUser()))
  {
   

  return true;
  }
  return false;
but it returns a false positive when I use this in a restricted forum.

Any ideas what I am doing wrong? Is there a better way to go about this?
 
In fact what I would really love to do is get a better grip on permissions in general, for example whether a particular usergroup (which may not be associated with the visitor) has permissions against content, eg does a particular usergroup have permission to view a post on a restricted node completely irregardless of the impact of other permissions. How would that be called in a query?
 
Am I right in thinking that guest always has a permission_combination_id value of 1? If so, I think I can take it from there.
 
Top Bottom