postFactory->create(); $id = $this->getRequest()->getParam('id'); $historyId = $this->getRequest()->getParam('historyId'); if ($historyId) { $history = $this->helperData->getFactoryByType(Data::TYPE_HISTORY)->create()->load($historyId); $post = $this->helperData->getFactoryByType(Data::TYPE_POST)->create()->load($history->getPostId()); $data = $history->getData(); $post->addData($data); } elseif ($id) { $post->load($id); } $this->setPost($post); } /** * @return bool */ public function getRelatedMode() { return (int) $this->helperData->getPostViewPageConfig('related_mode') === 1 ? true : false; } /** * @param $value * * @return string */ public function getDecrypt($value) { return $this->enc->decrypt($value); } /** * @return mixed */ protected function getBlogObject() { return $this->getPost(); } /** * check customer is logged in or not */ public function isLoggedIn() { return $this->helperData->isLogin(); } /** * @return string */ public function checkRss() { return $this->helperData->getBlogUrl('post/rss'); } /** * @param $topic * * @return string */ public function getTopicUrl($topic) { return $this->helperData->getBlogUrl($topic, Data::TYPE_TOPIC); } /** * @param $tag * * @return string */ public function getTagUrl($tag) { return $this->helperData->getBlogUrl($tag, Data::TYPE_TAG); } /** * @param $category * * @return string */ public function getCategoryUrl($category) { return $this->helperData->getBlogUrl($category, Data::TYPE_CATEGORY); } /** * Get the store-specific SEO title with the post name as fallback. * * @return string */ public function getPostMetaTitle() { return (string) ($this->helperData->getMetaTitleByStoreId($this->getPost()->getMetaTitle()) ?: $this->getPost()->getName()); } /** * Get the store-specific SEO description with the short description as fallback. * * @return string */ public function getPostMetaDescription() { $storeId = (int) $this->store->getStore()->getId(); return (string) ($this->getMetaFieldByStoreId($this->getPost()->getMetaDescription(), $storeId) ?: $this->getPost()->getShortDescription()); } /** * @param $code * * @return mixed */ public function helperComment($code) { return $this->helperData->getBlogConfig('comment/' . $code); } /** * get comments tree html * * @return mixed */ public function getCommentsHtml() { return $this->commentTree; } /** * @param $userId * * @return CustomerInterface * @throws LocalizedException * @throws NoSuchEntityException */ public function getUserComment($userId) { return $this->customerRepository->getById($userId); } /** * @param $cmtId * * @return int|string */ public function getCommentLikes($cmtId) { $likes = $this->likeFactory->create() ->getCollection() ->addFieldToFilter('comment_id', $cmtId) ->getSize(); return $likes ?: ''; } /** * @param $cmtId * * @return bool */ public function isLiked($cmtId) { if ($this->helperData->isLogin()) { $customerId = $this->helperData->getCustomerIdByContext(); $likes = $this->likeFactory->create()->getCollection(); foreach ($likes as $like) { if ($like->getEntityId() == $customerId && $like->getCommentId() == $cmtId) { return true; } } } return false; } /** * @param $postId * * @return array */ public function getPostComments($postId) { $result = []; $comments = $this->cmtFactory->create()->getCollection() ->addFieldToFilter('main_table.post_id', $postId); foreach ($comments as $comment) { $result[] = $comment->getData(); } return $result; } /** * @param $postId * @param $action * * @return int */ public function getPostLike($postId, $action) { /** @var PostLike $postLike */ $postLike = $this->postLikeFactory->create(); return $postLike->getCollection()->addFieldToFilter('post_id', $postId) ->addFieldToFilter('action', $action)->count(); } /** * @param $comment * * @return string */ public function commentHtml($comment) { $html = ''; foreach (explode("\n", trim($comment)) as $value) { $html .= '
' . $this->escapeHtml($value) . '
'; } return $html; } /** * @param $comments * @param $cmtId * * @throws LocalizedException * @throws NoSuchEntityException */ public function getCommentsTree($comments, $cmtId) { $this->commentTree .= '