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 .= ''; } /** * get tag list * * @param Post $post * * @return string */ public function getTagList($post) { $tagCollection = $post->getSelectedTagsCollection(); $result = ''; if (!empty($tagCollection)) { $listTags = []; foreach ($tagCollection as $tag) { $listTags[] = '' . $tag->getName() . ''; } $result = implode(', ', $listTags); } return $result; } /** * @return string */ public function getLoginUrl() { return $this->customerUrl->getLoginUrl(); } /** * @return string */ public function getRegisterUrl() { return $this->customerUrl->getRegisterUrl(); } /** * @inheritdoc */ protected function _prepareLayout() { parent::_prepareLayout(); if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) { if ($catId = $this->getRequest()->getParam('cat')) { $category = $this->categoryFactory->create() ->load($catId); if ($category->getId()) { $breadcrumbs->addCrumb($category->getUrlKey(), [ 'label' => $category->getName(), 'title' => $category->getName(), 'link' => $this->helperData->getBlogUrl($category, Data::TYPE_CATEGORY) ]); } } $post = $this->getPost(); $breadcrumbs->addCrumb($post->getUrlKey(), [ 'label' => $post->getName(), 'title' => $post->getName() ]); } } /** * @param $meta * * @return array|Phrase|string * @throws NoSuchEntityException */ public function getBlogTitle($meta = false) { $blogTitle = parent::getBlogTitle($meta); $post = $this->getBlogObject(); if (!$post) { return $blogTitle; } if ($meta) { if ($this->helperData->getMetaTitleByStoreId($post->getMetaTitle())) { $blogTitle[] = $this->helperData->getMetaTitleByStoreId($post->getMetaTitle()); } else { $blogTitle[] = ucfirst($post->getName()); } return $blogTitle; } return ucfirst($post->getName()); } /** * @param $priority * @param $message * * @return string */ public function getMessagesHtml($priority, $message) { /** @var $messagesBlock Messages */ $messagesBlock = $this->_layout->createBlock(Messages::class); $messagesBlock->{$priority}(__($message)); return $messagesBlock->toHtml(); } }