This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,61 @@
<?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\Controller\Adminhtml\Topic;
use Exception;
use Magento\Framework\Controller\Result\Redirect;
use Mageplaza\Blog\Controller\Adminhtml\Topic;
/**
* Class Delete
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class Delete extends Topic
{
/**
* @return Redirect
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if ($id = $this->getRequest()->getParam('id')) {
try {
$this->topicFactory->create()
->load($id)
->delete();
$this->messageManager->addSuccessMessage(__('The Topic has been deleted.'));
} catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $id]);
return $resultRedirect;
}
} else {
$this->messageManager->addErrorMessage(__('Topic to delete was not found.'));
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
}
}
@@ -0,0 +1,95 @@
<?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\Controller\Adminhtml\Topic;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Mageplaza\Blog\Controller\Adminhtml\Topic;
use Mageplaza\Blog\Model\TopicFactory;
/**
* Class Edit
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class Edit extends Topic
{
/**
* Page factory
*
* @var PageFactory
*/
public $resultPageFactory;
/**
* Edit constructor.
*
* @param Context $context
* @param Registry $registry
* @param PageFactory $resultPageFactory
* @param TopicFactory $topicFactory
*/
public function __construct(
Context $context,
Registry $registry,
PageFactory $resultPageFactory,
TopicFactory $topicFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $registry, $topicFactory);
}
/**
* @return \Magento\Backend\Model\View\Result\Page|Redirect|Page
*/
public function execute()
{
/** @var \Mageplaza\Blog\Model\Topic $topic */
$topic = $this->initTopic();
if (!$topic) {
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*');
return $resultRedirect;
}
$data = $this->_session->getData('mageplaza_blog_topic_data', true);
if (!empty($data)) {
$topic->setData($data);
}
$this->coreRegistry->register('mageplaza_blog_topic', $topic);
/** @var \Magento\Backend\Model\View\Result\Page|Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Mageplaza_Blog::topic');
$resultPage->getConfig()->getTitle()->set(__('Topics'));
$title = $topic->getId() ? $topic->getName() : __('New Topic');
$resultPage->getConfig()->getTitle()->prepend($title);
return $resultPage;
}
}
@@ -0,0 +1,76 @@
<?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\Controller\Adminhtml\Topic;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
/**
* Class Index
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class Index extends Action
{
/**
* Page result factory
*
* @var PageFactory
*/
public $resultPageFactory;
/**
* Page factory
*
* @var \Magento\Backend\Model\View\Result\Page
*/
public $resultPage;
/**
* Index constructor.
*
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* execute the action
*
* @return \Magento\Backend\Model\View\Result\Page|Page
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('Topics')));
return $resultPage;
}
}
@@ -0,0 +1,130 @@
<?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\Controller\Adminhtml\Topic;
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Mageplaza\Blog\Model\Topic;
use Mageplaza\Blog\Model\TopicFactory;
use RuntimeException;
/**
* Class InlineEdit
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class InlineEdit extends Action
{
/**
* JSON Factory
*
* @var JsonFactory
*/
public $jsonFactory;
/**
* Topic Factory
*
* @var TopicFactory
*/
public $topicFactory;
/**
* InlineEdit constructor.
*
* @param Context $context
* @param JsonFactory $jsonFactory
* @param TopicFactory $topicFactory
*/
public function __construct(
Context $context,
JsonFactory $jsonFactory,
TopicFactory $topicFactory
) {
$this->jsonFactory = $jsonFactory;
$this->topicFactory = $topicFactory;
parent::__construct($context);
}
/**
* @return ResultInterface
*/
public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
$postItems = $this->getRequest()->getParam('items', []);
if (!($this->getRequest()->getParam('isAjax') && !empty($postItems))) {
return $resultJson->setData([
'messages' => [__('Please correct the data sent.')],
'error' => true,
]);
}
$key = array_keys($postItems);
$topicId = !empty($key) ? (int)$key[0] : '';
/** @var Topic $topic */
$topic = $this->topicFactory->create()->load($topicId);
try {
$topic->addData($postItems[$topicId])
->save();
} catch (LocalizedException $e) {
$messages[] = $this->getErrorWithTopicId($topic, $e->getMessage());
$error = true;
} catch (RuntimeException $e) {
$messages[] = $this->getErrorWithTopicId($topic, $e->getMessage());
$error = true;
} catch (Exception $e) {
$messages[] = $this->getErrorWithTopicId(
$topic,
__('Something went wrong while saving the Topic.')
);
$error = true;
}
return $resultJson->setData([
'messages' => $messages,
'error' => $error
]);
}
/**
* Add Topic id to error message
*
* @param Topic $topic
* @param string $errorText
*
* @return string
*/
public function getErrorWithTopicId(Topic $topic, $errorText)
{
return '[Topic ID: ' . $topic->getId() . '] ' . $errorText;
}
}
@@ -0,0 +1,92 @@
<?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\Controller\Adminhtml\Topic;
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\MassAction\Filter;
use Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory;
/**
* Class MassDelete
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class MassDelete extends Action
{
/**
* Mass Action Filter
*
* @var Filter
*/
public $filter;
/**
* Collection Factory
*
* @var CollectionFactory
*/
public $collectionFactory;
/**
* constructor
*
* @param Filter $filter
* @param CollectionFactory $collectionFactory
* @param Context $context
*/
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory
) {
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
}
/**
* @return $this|ResponseInterface|ResultInterface
* @throws LocalizedException
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
try {
$collection->walk('delete');
$this->messageManager->addSuccessMessage(__('Topics has been deleted.'));
} catch (Exception $e) {
$this->messageManager->addSuccessMessage(__('Something wrong when delete Topics.'));
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
}
@@ -0,0 +1,108 @@
<?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\Controller\Adminhtml\Topic;
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\MassAction\Filter;
use Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory;
/**
* Class MassStatus
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class MassStatus extends Action
{
/**
* Mass Action Filter
*
* @var Filter
*/
public $filter;
/**
* Collection Factory
*
* @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory
*/
public $collectionFactory;
/**
* MassStatus constructor.
*
* @param Context $context
* @param Filter $filter
* @param CollectionFactory $collectionFactory
*/
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory
) {
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
}
/**
* @return $this|ResponseInterface|ResultInterface
* @throws LocalizedException
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$status = (int)$this->getRequest()->getParam('status');
$topicUpdated = 0;
foreach ($collection as $topic) {
try {
$topic->setEnabled($status)
->save();
$topicUpdated++;
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException(
$e,
__('Something went wrong while updating status for %1.', $topic->getName())
);
}
}
if ($topicUpdated) {
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $topicUpdated));
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
}
@@ -0,0 +1,69 @@
<?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\Controller\Adminhtml\Topic;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Forward;
use Magento\Backend\Model\View\Result\ForwardFactory;
/**
* Class NewAction
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class NewAction extends Action
{
/**
* Redirect result factory
*
* @var ForwardFactory
*/
public $resultForwardFactory;
/**
* constructor
*
* @param ForwardFactory $resultForwardFactory
* @param Context $context
*/
public function __construct(
Context $context,
ForwardFactory $resultForwardFactory
) {
$this->resultForwardFactory = $resultForwardFactory;
parent::__construct($context);
}
/**
* forward to edit
*
* @return Forward
*/
public function execute()
{
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('edit');
return $resultForward;
}
}
@@ -0,0 +1,72 @@
<?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\Controller\Adminhtml\Topic;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\Layout;
use Magento\Framework\View\Result\LayoutFactory;
use Mageplaza\Blog\Controller\Adminhtml\Topic;
use Mageplaza\Blog\Model\TopicFactory;
/**
* Class Posts
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class Posts extends Topic
{
/**
* Result layout factory
*
* @var LayoutFactory
*/
public $resultLayoutFactory;
/**
* Posts constructor.
*
* @param LayoutFactory $resultLayoutFactory
* @param TopicFactory $postFactory
* @param Registry $registry
* @param Context $context
*/
public function __construct(
Context $context,
Registry $registry,
LayoutFactory $resultLayoutFactory,
TopicFactory $postFactory
) {
$this->resultLayoutFactory = $resultLayoutFactory;
parent::__construct($context, $registry, $postFactory);
}
/**
* @return Layout
*/
public function execute()
{
$this->initTopic(true);
return $this->resultLayoutFactory->create();
}
}
@@ -0,0 +1,30 @@
<?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\Controller\Adminhtml\Topic;
/**
* Class PostsGrid
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class PostsGrid extends Posts
{
}
+205
View File
@@ -0,0 +1,205 @@
<?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\Controller\Adminhtml\Topic;
use Exception;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Helper\Js;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Messages;
use Magento\Framework\View\LayoutFactory;
use Mageplaza\Blog\Controller\Adminhtml\Topic;
use Mageplaza\Blog\Model\TopicFactory;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Mageplaza\Blog\Helper\Data;
/**
* Class Save
* @package Mageplaza\Blog\Controller\Adminhtml\Topic
*/
class Save extends Topic
{
/**
* JS helper
*
* @var Js
*/
public $jsHelper;
/**
* Layout Factory
*
* @var LayoutFactory
*/
public $layoutFactory;
/**
* Result Json Factory
*
* @var JsonFactory
*/
public $resultJsonFactory;
/**
* @var Data
*/
public $_helperData;
/**
* Save constructor.
*
* @param Context $context
* @param Registry $registry
* @param Js $jsHelper
* @param LayoutFactory $layoutFactory
* @param JsonFactory $resultJsonFactory
* @param TopicFactory $topicFactory
* @param Data $helperData
*/
public function __construct(
Context $context,
Registry $registry,
Js $jsHelper,
LayoutFactory $layoutFactory,
JsonFactory $resultJsonFactory,
TopicFactory $topicFactory,
Data $helperData
) {
$this->jsHelper = $jsHelper;
$this->layoutFactory = $layoutFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->_helperData = $helperData;
parent::__construct($context, $registry, $topicFactory);
}
/**
* @return $this|ResponseInterface|Redirect|ResultInterface
*/
public function execute()
{
if ($this->getRequest()->getPost('return_session_messages_only')) {
$topic = $this->initTopic();
$topicPostData = $this->getRequest()->getPostValue();
$topicPostData['store_ids'] = 0;
$topicPostData['enabled'] = 1;
$this->_helperData->handleSeoValueBeforeSave($topicPostData);
$topic->addData($topicPostData);
try {
$topic->save();
$this->messageManager->addSuccessMessage(__('You saved the topic.'));
} catch (AlreadyExistsException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->_objectManager->get(LoggerInterface::class)->critical($e);
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->_objectManager->get(LoggerInterface::class)->critical($e);
} catch (Exception $e) {
$this->messageManager->addErrorMessage(__('Something went wrong while saving the topic.'));
$this->_objectManager->get(LoggerInterface::class)->critical($e);
}
$hasError = (bool) $this->messageManager->getMessages()->getCountByType(
MessageInterface::TYPE_ERROR
);
$topic->load($topic->getId());
$topic->addData([
'level' => 1,
'entity_id' => $topic->getId(),
'is_active' => $topic->getEnabled(),
'parent' => 0
]);
// to obtain truncated category name
/** @var $block Messages */
$block = $this->layoutFactory->create()->getMessagesBlock();
$block->setMessages($this->messageManager->getMessages(true));
/** @var Json $resultJson */
$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData(
[
'messages' => $block->getGroupedHtml(),
'error' => $hasError,
'category' => $topic->toArray(),
]
);
}
$resultRedirect = $this->resultRedirectFactory->create();
if ($data = $this->getRequest()->getPost('topic')) {
/** @var \Mageplaza\Blog\Model\Topic $topic */
$topic = $this->initTopic();
$this->_helperData->handleSeoValueBeforeSave($data);
$topic->setData($data);
if ($posts = $this->getRequest()->getPost('posts', false)) {
$topic->setPostsData($this->jsHelper->decodeGridSerializedInput($posts));
}
try {
$topic->save();
$this->messageManager->addSuccessMessage(__('The Topic has been saved.'));
$this->_getSession()->setData('mageplaza_blog_topic_data', false);
if ($this->getRequest()->getParam('back')) {
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $topic->getId(), '_current' => true]);
} else {
$resultRedirect->setPath('mageplaza_blog/*/');
}
return $resultRedirect;
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (RuntimeException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Topic.'));
}
$this->_getSession()->setData('mageplaza_blog_topic_data', $data);
$resultRedirect->setPath('mageplaza_blog/*/edit', ['id' => $topic->getId(), '_current' => true]);
return $resultRedirect;
}
$resultRedirect->setPath('mageplaza_blog/*/');
return $resultRedirect;
}
}