/** * @param ContentInterface|PosterInterface $item * * @return bool */ public function isParent($item) { if (!$this->logged()) { return false; } return (bool) array_intersect([$this->getId(), $this->getUserId()], [$item->getId(), $item->getParentId(), $item->getParentUserId()]); }
/** * 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; }
/** * @param string $feedType * @param ContentInterface $about * @param array $params * * @return Feed * @throws \InvalidArgumentException */ public function addItemFeed($feedType, ContentInterface $about, $params = []) { list($privacyType, $privacyValue) = $about->getPrivacy('view'); $poster = app()->find($about->getPosterType(), $about->getPosterId()); $parent = app()->find($about->getParentType(), $about->getParentId()); $story = null; $hashtag = null; $peopletag = null; $story = $about->getStory(); $peopletag = $about->getPeople(); if (!empty($story)) { $hashtag = $this->getHashTagsInStory($story); } // parse story content to load hash tags. $feed = new Feed(['feed_type' => $feedType, 'poster_id' => $about->getPosterId(), 'poster_type' => $about->getPosterType(), 'parent_id' => $about->getParentId(), 'parent_type' => $about->getParentType(), 'about_id' => $about->getId(), 'about_type' => $about->getType(), 'privacy_type' => (int) $privacyType, 'privacy_value' => (int) $privacyValue, 'created_at' => KENDO_DATE_TIME, 'params_text' => json_encode($params)]); $feed->save(); $feed->validate(true, false); /** * add feed to hashtag list */ if (!empty($hashtag)) { foreach ($hashtag as $tag) { $this->addHashTag($feed, $tag); } } $this->putFeedToStream($feed, $poster, $parent, $peopletag); app()->notificationService()->subscribe($poster, $about); return $feed; }