This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
+120
View File
@@ -0,0 +1,120 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Category;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Phrase;
use Mageplaza\Blog\Helper\Data;
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
/**
* Class Listpost
* @package Mageplaza\Blog\Block\Category
*/
class Listpost extends \Mageplaza\Blog\Block\Listpost
{
/**
* @var string
*/
protected $_category;
/**
* Override this function to apply collection for each type
*
* @return Collection|null
* @throws NoSuchEntityException
*/
protected function getCollection()
{
if ($category = $this->getBlogObject()) {
return $this->helperData->getPostCollection(Data::TYPE_CATEGORY, $category->getId());
}
return null;
}
/**
* @return mixed
*/
protected function getBlogObject()
{
if (!$this->_category) {
$id = $this->getRequest()->getParam('id');
if ($id) {
$category = $this->helperData->getObjectByParam($id, null, Data::TYPE_CATEGORY);
if ($category && $category->getId()) {
$this->_category = $category;
}
}
}
return $this->_category;
}
/**
* @inheritdoc
* @throws LocalizedException
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
$category = $this->getBlogObject();
$categoryName = preg_replace('/[^A-Za-z0-9\-]/', ' ', $category->getName());
if ($category) {
$breadcrumbs->addCrumb($category->getUrlKey(), [
'label' => __($categoryName),
'title' => __($categoryName)
]);
}
}
}
/**
* @param $meta
*
* @return array|Phrase|string
* @throws NoSuchEntityException
*/
public function getBlogTitle($meta = false)
{
$blogTitle = parent::getBlogTitle($meta);
$category = $this->getBlogObject();
if (!$category) {
return $blogTitle;
}
if ($meta) {
if ($this->helperData->getMetaTitleByStoreId($category->getMetaTitle())) {
$blogTitle[] = $this->helperData->getMetaTitleByStoreId($category->getMetaTitle());
} else {
$blogTitle[] = ucfirst($category->getName());
}
return $blogTitle;
}
return ucfirst($category->getName());
}
}
+229
View File
@@ -0,0 +1,229 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Category;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Blog\Api\Data\CategoryInterface;
use Mageplaza\Blog\Helper\Data as HelperData;
use Mageplaza\Blog\Model\Category;
use Mageplaza\Blog\Model\CategoryFactory;
use Mageplaza\Blog\Model\ResourceModel\Category\Collection;
use Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory;
/**
* Class Widget
* @package Mageplaza\Blog\Block\Category
*/
class Menu extends Template
{
/**
* @var CollectionFactory
*/
protected $categoryCollection;
/**
* @var CategoryFactory
*/
protected $category;
/**
* @var HelperData
*/
protected $helper;
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* Menu constructor.
*
* @param Context $context
* @param CollectionFactory $collectionFactory
* @param CategoryFactory $categoryFactory
* @param HelperData $helperData
* @param StoreManagerInterface $storeManager
* @param array $data
*/
public function __construct(
Context $context,
CollectionFactory $collectionFactory,
CategoryFactory $categoryFactory,
HelperData $helperData,
StoreManagerInterface $storeManager,
array $data = []
) {
$this->categoryCollection = $collectionFactory;
$this->category = $categoryFactory;
$this->helper = $helperData;
$this->storeManager = $storeManager;
parent::__construct($context, $data);
}
/**
* @param $id
*
* @return CategoryInterface[]
* @throws NoSuchEntityException
*/
public function getChildCategory($id)
{
$collection = $this->categoryCollection->create()->addAttributeToFilter('parent_id', $id)
->addAttributeToFilter('enabled', '1');
$this->helper->addStoreFilter($collection, $this->storeManager->getStore()->getId());
return $collection->getItems();
}
/**
* @return Collection
* @throws NoSuchEntityException
*/
public function getCollections()
{
$collection = $this->categoryCollection->create()
->addAttributeToFilter('level', '1')->addAttributeToFilter('enabled', '1')->setOrder('position','ASC');
return $this->helper->addStoreFilter($collection, $this->storeManager->getStore()->getId());
}
/**
* @param Category $parentCategory
*
* @return string
*/
public function getMenuHtml($parentCategory)
{
$categoryUrl = $this->helper->getBlogUrl($parentCategory, HelperData::TYPE_CATEGORY);
$html = '<li class="level' . $parentCategory->getLevel()
. ' category-item ui-menu-item" role="presentation">'
. '<a href="' . $categoryUrl . '" class="ui-corner-all" tabindex="-1" role="menuitem">'
. '<span>' . $parentCategory->getName() . '</span></a>';
$childCategorys = $this->getChildCategory($parentCategory->getId());
if (count($childCategorys) > 0) {
$html .= '<ul class="level' . $parentCategory->getLevel() . ' submenu ui-menu ui-widget'
. ' ui-widget-content ui-corner-all"'
. ' role="menu" aria-expanded="false" style="display: none; top: 47px; left: -0.15625px;"'
. ' aria-hidden="true">';
/** @var Category $childCategory */
foreach ($childCategorys as $childCategory) {
$html .= $this->getMenuHtml($childCategory);
}
$html .= '</ul>';
}
$html .= '</li>';
return $html;
}
/**
* @param Category $parentCategory
*
* @return string
*/
public function getPortoMenuHtml($parentCategory)
{
$categoryUrl = $this->helper->getBlogUrl($parentCategory, HelperData::TYPE_CATEGORY);
$html = '<li class="ui-menu-item level' . $parentCategory->getLevel() . ' parent" role="presentation">'
. '<div class="open-children-toggle"></div>'
. '<a href="' . $categoryUrl . '" class="ui-corner-all" tabindex="-1" role="menuitem">'
. '<span>' . $parentCategory->getName() . '</span></a>';
$childCategories = $this->getChildCategory($parentCategory->getId());
if (count($childCategories) > 0) {
$html .= '<ul class="subchildmenu level' . $parentCategory->getLevel() . ''
. ' ui-widget-content ui-corner-all"'
. ' role="menu" aria-expanded="false"'
. ' aria-hidden="true">';
/** @var Category $childCategory */
foreach ($childCategories as $childCategory) {
$html .= $this->getMenuHtml($childCategory);
}
$html .= '</ul>';
}
$html .= '</li>';
return $html;
}
/**
* @return \Magento\Framework\Phrase|mixed
* @throws NoSuchEntityException
*/
public function getBlogHomePageTitle()
{
return $this->helper->getBlogConfig('display/name', $this->helper->getCurrentStoreId()) ?: __('Blog');
}
/**
* @return string
*/
public function getBlogHomeUrl()
{
return $this->helper->getBlogUrl('');
}
public function getBlogUrlByUrlKey($urlKey)
{
return $this->helper->getBlogUrl($urlKey, HelperData::TYPE_CATEGORY);
}
public function getChildDataCate($category)
{
$childCategorys = $this->getChildCategory($category->getId());
$childCategoryData = [];
if (count($childCategorys) > 0) {
foreach ($childCategorys as $childCategory) {
$childCategoryUrl = $this->getBlogUrlByUrlKey($childCategory->getUrlKey());
array_push($childCategoryData,
[
"name" => $childCategory->getName(),
"id" => "mg-blog" . $childCategory->getId(),
"url" => $childCategoryUrl,
"image" => false,
"has_active" => false,
"is_active" => false,
"is_category" => true,
"is_parent_active" => true,
"position" => null,
"path" => "1/2/38",
"childData" => $this->getChildDataCate($childCategory)
]
);
}
return $childCategoryData;
} else {
return [];
}
}
}
+96
View File
@@ -0,0 +1,96 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Category;
use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Phrase;
use Mageplaza\Blog\Block\Adminhtml\Category\Tree;
use Mageplaza\Blog\Block\Frontend;
use Mageplaza\Blog\Helper\Data;
/**
* Class Widget
* @package Mageplaza\Blog\Block\Category
*/
class Widget extends Frontend
{
/**
* @return mixed|null
*/
public function getTree()
{
try {
$tree = ObjectManager::getInstance()->create(Tree::class);
$tree = $tree->getTree(null, $this->store->getStore()->getId());
return $tree;
} catch (Exception $e) {
return null;
}
}
/**
* @param array $tree
*
* @return Phrase|string
*/
public function getCategoryTreeHtml($tree)
{
if (!$tree) {
return __('No Categories.');
}
$html = '';
foreach ($tree as $value) {
if (!$value) {
continue;
}
if ($value['enabled']) {
$level = count(explode('/', ($value['path'])));
$hasChild = isset($value['children']) && $level < 4;
$html .= '<ul class="block-content menu-categories category-level'
. $level . '" style="margin-bottom:0px;margin-top:8px;">';
$html .= '<li class="category-item">';
$html .= $hasChild ? '<i class="fa fa-plus-square-o mp-blog-expand-tree-' . $level . '"></i>' : '';
$html .= '<a class="list-categories" href="' . $this->getCategoryUrl($value['url']) . '">';
$html .= '<i class="fa fa-folder-open-o">&nbsp;&nbsp;</i>';
$html .= ucfirst($value['text']) . '</a>';
$html .= $hasChild ? $this->getCategoryTreeHtml($value['children']) : '';
$html .= '</li>';
$html .= '</ul>';
}
}
return $html;
}
/**
* @param string $category
*
* @return string
*/
public function getCategoryUrl($category)
{
return $this->helperData->getBlogUrl($category, Data::TYPE_CATEGORY);
}
}