filterProvider = $filterProvider;
$this->cmtFactory = $commentFactory;
$this->likeFactory = $likeFactory;
$this->customerRepository = $customerRepository;
$this->helperData = $helperData;
$this->coreRegistry = $coreRegistry;
$this->dateTime = $dateTime;
$this->categoryFactory = $categoryFactory;
$this->postFactory = $postFactory;
$this->customerUrl = $customerUrl;
$this->postLikeFactory = $postLikeFactory;
$this->categoryOptions = $category;
$this->topicOptions = $topic;
$this->tagOptions = $tag;
$this->authorStatusType = $authorStatus;
$this->themeProvider = $themeProvider;
$this->store = $context->getStoreManager();
$this->enc = $enc;
parent::__construct($context, $data);
}
/**
* @return HelperData
*/
public function getBlogHelper()
{
return $this->helperData;
}
/**
* @return bool
*/
public function isBlogEnabled()
{
return $this->helperData->isEnabled();
}
/**
* @param string $content
*
* @return string
*/
public function getPageFilter($content)
{
try {
return $this->filterProvider->getPageFilter()->filter((string) $content);
} catch (Exception $e) {
return '';
}
}
/**
* @param string $image
* @param string $type
*
* @return string
* @throws NoSuchEntityException
*/
public function getImageUrl($image, $type = Image::TEMPLATE_MEDIA_TYPE_POST)
{
$imageHelper = $this->helperData->getImageHelper();
if ($image) {
$imageFile = $imageHelper->getMediaPath($image, $type);
}
return $image ? $this->helperData->getImageHelper()->getMediaUrl($imageFile) : '';
}
/**
* @param string|Object $urlKey
* @param null $type
*
* @return string
*/
public function getRssUrl($urlKey, $type = null)
{
if (is_object($urlKey)) {
$urlKey = $urlKey->getUrlKey();
}
$urlKey = ($type ? $type . '/' : '') . $urlKey;
$url = $this->helperData->getUrl($this->helperData->getRoute() . '/' . $urlKey);
return rtrim($url, '/') . '.xml';
}
/**
* @param Post $post
*
* @return Phrase|string
*/
public function getPostInfo($post)
{
try {
$likeCollection = $this->postLikeFactory->create()->getCollection();
$couldLike = $likeCollection->addFieldToFilter('post_id', $post->getId())
->addFieldToFilter('action', '1')->count();
$html = __(
' %1',
$this->getDateFormat($post->getPublishDate())
);
if ($categoryPost = $this->getPostCategoryHtml($post)) {
$html .= __('| Posted in %1', $categoryPost);
}
$author = $this->helperData->getAuthorByPost($post);
if ($author && $author->getName() && $this->helperData->showAuthorInfo()) {
$aTag = ''
. $this->escapeHtml($author->getName()) . '';
$html .= __('| %1', $aTag);
}
if ($this->getCommentinPost($post)) {
$html .= __(
'| %1',
$this->getCommentinPost($post)
);
}
if ($post->getViewTraffic()) {
$html .= __(
'| %1',
$post->getViewTraffic()
);
}
if ($couldLike > 0) {
$html .= __('| %1', $couldLike);
}
} catch (Exception $e) {
$html = '';
}
return $html;
}
/**
* @param Post $post
*
* @return int
*/
public function getCommentinPost($post)
{
$cmt = $this->cmtFactory->create()->getCollection()->addFieldToFilter('post_id', $post->getId());
return $cmt->count();
}
/**
* Get list category html of post
*
* @param Post $post
*
* @return string|null
*/
public function getPostCategoryHtml($post)
{
$categoryHtml = [];
try {
if (!$post->getCategoryIds()) {
return null;
}
$categories = $this->helperData->getCategoryCollection($post->getCategoryIds());
$count = 0;
foreach ($categories as $_cat) {
$count++;
$maximum = $this->helperData->getSidebarConfig('categories/maximum');
if ($maximum && $count > $maximum) {
continue;
}
$categoryHtml[] = '' . $_cat->getName() . '';
}
} catch (Exception $e) {
return null;
}
return implode(', ', $categoryHtml);
}
/**
* @param string $date
* @param bool $monthly
*
* @return false|string|null
*/
public function getDateFormat($date, $monthly = false)
{
try {
$date = $this->helperData->getDateFormat($date, $monthly);
} catch (Exception $e) {
$date = null;
}
return $date;
}
/**
* @param string $image
* @param null $size
* @param string $type
*
* @return string
* @throws NoSuchEntityException
*/
public function resizeImage($image, $size = null, $type = Image::TEMPLATE_MEDIA_TYPE_POST)
{
if (!$image) {
return $this->getDefaultImageUrl();
}
return $this->helperData->getImageHelper()->resizeImage($image, $size, $type);
}
/**
* get default image url
*/
public function getDefaultImageUrl()
{
return $this->getViewFileUrl('Mageplaza_Blog::media/images/mageplaza-logo-default.png');
}
/**
* @return string
*/
public function getDefaultAuthorImage()
{
return $this->getViewFileUrl('Mageplaza_Blog::media/images/no-artist-image.jpg');
}
}