Skip to content

Commit

Permalink
Merge pull request #331 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
Shinichi69 authored Dec 28, 2021
2 parents facfacf + d9313d9 commit d56a6d1
Show file tree
Hide file tree
Showing 73 changed files with 3,208 additions and 3,532 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/Import/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function _prepareForm()
'title' => __('Import Type'),
'values' => $this->_importType->toOptionArray(),
'required' => true,
'onchange' => 'mpBlogImport.initImportFieldsSet();'
'onchange' => 'mpBlogImport.initImportFieldsSet()'
]);

$fieldsetList = $this->_importType->toOptionArray();
Expand Down
9 changes: 5 additions & 4 deletions Block/Adminhtml/Widget/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* Class Collection
* @package Mageplaza\Blog\Model\ResourceModel\PostLike
* Class Number
* @package Mageplaza\Blog\Block\Adminhtml\Widget
*/
class Number extends Column
{
Expand All @@ -37,8 +37,9 @@ class Number extends Column
*/
public function prepareElementHtml(AbstractElement $element)
{
$html = '<input type="text" name="' . $element->getName() . '" id="' . $element->getId() . '"
class=" input-text admin__control-text required-entry _required validate-digits" value="' . $element->getValue() . '">';
$html = '<input type="text" name="' . $element->getName() . '" id="' . $element->getId()
. '" class=" input-text admin__control-text required-entry _required validate-digits" value="'
. $element->getValue() . '">';
$element->setData('value', '');
$element->setData('after_element_html', $html);

Expand Down
19 changes: 11 additions & 8 deletions Block/Category/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace Mageplaza\Blog\Block\Category;

use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Phrase;
use Mageplaza\Blog\Block\Adminhtml\Category\Tree;
use Mageplaza\Blog\Block\Frontend;
Expand All @@ -35,19 +35,22 @@
class Widget extends Frontend
{
/**
* @return mixed
* @throws NoSuchEntityException
* @return mixed|null
*/
public function getTree()
{
$tree = ObjectManager::getInstance()->create(Tree::class);
$tree = $tree->getTree(null, $this->store->getStore()->getId());
try {
$tree = ObjectManager::getInstance()->create(Tree::class);
$tree = $tree->getTree(null, $this->store->getStore()->getId());

return $tree;
return $tree;
} catch (Exception $e) {
return null;
}
}

/**
* @param $tree
* @param array $tree
*
* @return Phrase|string
*/
Expand Down Expand Up @@ -82,7 +85,7 @@ public function getCategoryTreeHtml($tree)
}

/**
* @param $category
* @param string $category
*
* @return string
*/
Expand Down
138 changes: 78 additions & 60 deletions Block/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
use Mageplaza\Blog\Model\CommentFactory;
use Mageplaza\Blog\Model\Config\Source\AuthorStatus;
use Mageplaza\Blog\Model\LikeFactory;
use Mageplaza\Blog\Model\Post;
use Mageplaza\Blog\Model\PostFactory;
use Mageplaza\Blog\Model\PostLikeFactory;

/**
* Class Frontend
*
* @package Mageplaza\Blog\Block
*/
class Frontend extends Template
Expand Down Expand Up @@ -231,18 +231,21 @@ public function isBlogEnabled()
}

/**
* @param $content
* @param string $content
*
* @return string
* @throws Exception
*/
public function getPageFilter($content)
{
return $this->filterProvider->getPageFilter()->filter((string) $content);
try {
return $this->filterProvider->getPageFilter()->filter((string) $content);
} catch (Exception $e) {
return '';
}
}

/**
* @param $image
* @param string $image
* @param string $type
*
* @return string
Expand All @@ -257,7 +260,7 @@ public function getImageUrl($image, $type = Image::TEMPLATE_MEDIA_TYPE_POST)
}

/**
* @param $urlKey
* @param string|Object $urlKey
* @param null $type
*
* @return string
Expand All @@ -275,55 +278,58 @@ public function getRssUrl($urlKey, $type = null)
}

/**
* @param $post
* @param Post $post
*
* @return Phrase|string
* @throws Exception
*/
public function getPostInfo($post)
{
$likeCollection = $this->postLikeFactory->create()->getCollection();
$couldLike = $likeCollection->addFieldToFilter('post_id', $post->getId())
->addFieldToFilter('action', '1')->count();
$html = __(
'<i class="mp-blog-icon mp-blog-calendar-times"></i> %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 = '<a class="mp-info" href="' . $author->getUrl() . '">'
. $this->escapeHtml($author->getName()) . '</a>';
$html .= __('| <i class="mp-blog-icon mp-blog-user"></i> %1', $aTag);
}

if ($this->getCommentinPost($post)) {
$html .= __(
'| <i class="mp-blog-icon mp-blog-comments" aria-hidden="true"></i> %1',
$this->getCommentinPost($post)
try {
$likeCollection = $this->postLikeFactory->create()->getCollection();
$couldLike = $likeCollection->addFieldToFilter('post_id', $post->getId())
->addFieldToFilter('action', '1')->count();
$html = __(
'<i class="mp-blog-icon mp-blog-calendar-times"></i> %1',
$this->getDateFormat($post->getPublishDate())
);
}

if ($post->getViewTraffic()) {
$html .= __(
'| <i class="mp-blog-icon mp-blog-traffic" aria-hidden="true"></i> %1',
$post->getViewTraffic()
);
}

if ($couldLike > 0) {
$html .= __('| <i class="mp-blog-icon mp-blog-thumbs-up" aria-hidden="true"></i> %1', $couldLike);
if ($categoryPost = $this->getPostCategoryHtml($post)) {
$html .= __('| Posted in %1', $categoryPost);
}

$author = $this->helperData->getAuthorByPost($post);
if ($author && $author->getName() && $this->helperData->showAuthorInfo()) {
$aTag = '<a class="mp-info" href="' . $author->getUrl() . '">'
. $this->escapeHtml($author->getName()) . '</a>';
$html .= __('| <i class="mp-blog-icon mp-blog-user"></i> %1', $aTag);
}

if ($this->getCommentinPost($post)) {
$html .= __(
'| <i class="mp-blog-icon mp-blog-comments" aria-hidden="true"></i> %1',
$this->getCommentinPost($post)
);
}

if ($post->getViewTraffic()) {
$html .= __(
'| <i class="mp-blog-icon mp-blog-traffic" aria-hidden="true"></i> %1',
$post->getViewTraffic()
);
}

if ($couldLike > 0) {
$html .= __('| <i class="mp-blog-icon mp-blog-thumbs-up" aria-hidden="true"></i> %1', $couldLike);
}
} catch (Exception $e) {
$html = '';
}

return $html;
}

/**
* @param $post
* @param Post $post
*
* @return int
*/
Expand All @@ -335,44 +341,56 @@ public function getCommentinPost($post)
}

/**
* get list category html of post
* Get list category html of post
*
* @param $post
* @param Post $post
*
* @return null|string
* @return string|null
*/
public function getPostCategoryHtml($post)
{
if (!$post->getCategoryIds()) {
return null;
}

$categories = $this->helperData->getCategoryCollection($post->getCategoryIds());
$categoryHtml = [];
foreach ($categories as $_cat) {
$categoryHtml[] = '<a class="mp-info" href="' . $this->helperData->getBlogUrl(
$_cat,
HelperData::TYPE_CATEGORY
) . '">' . $_cat->getName() . '</a>';

try {
if (!$post->getCategoryIds()) {
return null;
}

$categories = $this->helperData->getCategoryCollection($post->getCategoryIds());
foreach ($categories as $_cat) {
$categoryHtml[] = '<a class="mp-info" href="'
. $this->helperData->getBlogUrl(
$_cat,
HelperData::TYPE_CATEGORY
)
. '">' . $_cat->getName() . '</a>';
}
} catch (Exception $e) {
return null;
}

return implode(', ', $categoryHtml);
}

/**
* @param $date
* @param string $date
* @param bool $monthly
*
* @return false|string
* @throws Exception
* @return false|string|null
*/
public function getDateFormat($date, $monthly = false)
{
return $this->helperData->getDateFormat($date, $monthly);
try {
$date = $this->helperData->getDateFormat($date, $monthly);
} catch (Exception $e) {
$date = null;
}

return $date;
}

/**
* @param $image
* @param string $image
* @param null $size
* @param string $type
*
Expand Down
14 changes: 9 additions & 5 deletions Block/Html/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ public function getHref()
*/
public function getLabel()
{
if ($this->helper->getBlogConfig('general/name') == "") {
return __("Blog");
}

return $this->helper->getBlogConfig('general/name');
return $this->helper->getBlogConfig('general/name') ? : __('Blog');
}

/**
Expand All @@ -85,4 +81,12 @@ public function getHtmlSiteMapUrl()
{
return $this->helper->getBlogUrl('sitemap');
}

/**
* @return Data
*/
public function getHelperData()
{
return $this->helper;
}
}
Loading

0 comments on commit d56a6d1

Please sign in to comment.