/** * Check privacy control * * @param ContentInterface $content * @param string $action etc: activity.comment, blog.view, activity.like, activity.follow * * @return bool */ public function check(ContentInterface $content, $action) { $viewerId = app()->auth()->getId(); $parentId = $content->getParentId(); $isRegistered = $viewerId > 0; list($type, $value) = $content->getPrivacy($action); if ($this->debug) { echo sprintf('[%s,%s,%s]', $action, $type, $value); } if (!$isRegistered) { return $type == RELATION_TYPE_ANYONE; } /** * always */ if (in_array($type, [RELATION_TYPE_ANYONE, RELATION_TYPE_REGISTERED])) { return true; } /** * Check match user id */ if ($content->viewerIsPoster()) { return true; } /** * load relation between theme. */ $list = app()->relation()->getListRelationIdBetween($parentId, $viewerId); /** * check membership of viewer & content */ if (!empty($list[$value])) { return true; } /** * check membership member of members. it's hard to check theme. */ if (RELATION_TYPE_MEMBER_OF_MEMBER == $type) { return app()->relation()->isMemberOfMember($parentId, $viewerId); } return false; }