init
This commit is contained in:
+136
@@ -0,0 +1,136 @@
|
||||
<?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\Author;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Mageplaza\Blog\Helper\Data;
|
||||
use Mageplaza\Blog\Model\Config\Source\SideBarLR;
|
||||
use Mageplaza\Blog\Model\ResourceModel\Author\Collection as AuthorCollection;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package Mageplaza\Blog\Controller\Author
|
||||
*/
|
||||
class Information extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var ForwardFactory
|
||||
*/
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
protected $_helperBlog;
|
||||
|
||||
/**
|
||||
* @var AuthorCollection
|
||||
*/
|
||||
protected $authorCollection;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $customerSession;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
protected $coreRegistry;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
* @param AuthorCollection $authorCollection
|
||||
* @param Session $customerSession
|
||||
* @param Registry $coreRegistry
|
||||
* @param Data $helperData
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
ForwardFactory $resultForwardFactory,
|
||||
AuthorCollection $authorCollection,
|
||||
Session $customerSession,
|
||||
Registry $coreRegistry,
|
||||
Data $helperData
|
||||
) {
|
||||
$this->_helperBlog = $helperData;
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
$this->authorCollection = $authorCollection;
|
||||
$this->customerSession = $customerSession;
|
||||
$this->coreRegistry = $coreRegistry;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|Redirect|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$this->_helperBlog->setCustomerContextId();
|
||||
|
||||
if (!$this->_helperBlog->isEnabled() || !$this->_helperBlog->isEnabledAuthor()) {
|
||||
$resultRedirect->setPath('customer/account');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
if (!$this->_helperBlog->isAuthor()) {
|
||||
$this->coreRegistry->register('mp_author', $this->_helperBlog->getCurrentAuthor());
|
||||
|
||||
$page = $this->resultPageFactory->create();
|
||||
$page->getConfig()->setPageLayout(SideBarLR::LEFT);
|
||||
$page->getConfig()->getTitle()->set('Information Author');
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
if ($this->_helperBlog->isLogin()) {
|
||||
$resultRedirect->setPath('mpblog/*/signup');
|
||||
} else {
|
||||
$resultRedirect->setPath('customer/account');
|
||||
}
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<?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\Author;
|
||||
|
||||
use Exception;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Mageplaza\Blog\Helper\Data as HelperData;
|
||||
use Mageplaza\Blog\Helper\Image;
|
||||
use Mageplaza\Blog\Model\AuthorFactory;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package Mageplaza\Blog\Controller\Author
|
||||
*/
|
||||
class Register extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var ForwardFactory
|
||||
*/
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @var HelperData
|
||||
*/
|
||||
protected $_helperBlog;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $customerSession;
|
||||
|
||||
/**
|
||||
* @var Image
|
||||
*/
|
||||
protected $imageHelper;
|
||||
|
||||
/**
|
||||
* @var AuthorFactory
|
||||
*/
|
||||
protected $author;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
* @param Session $customerSession
|
||||
* @param Image $imageHelper
|
||||
* @param AuthorFactory $authorFactory
|
||||
* @param HelperData $helperData
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
ForwardFactory $resultForwardFactory,
|
||||
Session $customerSession,
|
||||
Image $imageHelper,
|
||||
AuthorFactory $authorFactory,
|
||||
HelperData $helperData
|
||||
) {
|
||||
$this->_helperBlog = $helperData;
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
$this->customerSession = $customerSession;
|
||||
$this->imageHelper = $imageHelper;
|
||||
$this->author = $authorFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|Redirect|ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getParams();
|
||||
$this->_helperBlog->setCustomerContextId();
|
||||
|
||||
if (!$this->_helperBlog->isEnabledAuthor()) {
|
||||
$resultRedirect->setPath('customer/account');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
if ($data) {
|
||||
if ($this->_helperBlog->isAuthor()) {
|
||||
$data = $this->prepareData($data);
|
||||
$author = $this->author->create()->addData($data);
|
||||
$notify = __('Register Successful');
|
||||
} else {
|
||||
$author = $this->_helperBlog->getCurrentAuthor();
|
||||
$data = $this->prepareData($data, $author);
|
||||
$author->addData($data);
|
||||
$notify = __('Author Edited Successful');
|
||||
}
|
||||
|
||||
try {
|
||||
$author->save();
|
||||
$resultRedirect->setPath('mpblog/*/information');
|
||||
$this->messageManager->addSuccessMessage($notify);
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Author.'));
|
||||
$resultRedirect->setPath('mpblog/*/signup');
|
||||
}
|
||||
}
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param null $author
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function prepareData($data, $author = null)
|
||||
{
|
||||
if ($author) {
|
||||
unset($data['status']);
|
||||
} else {
|
||||
$data['customer_id'] = $this->customerSession->getId();
|
||||
$data['type'] = '1';
|
||||
$data['status'] = $this->_helperBlog->getConfigGeneral('auto_approve');
|
||||
}
|
||||
|
||||
if ($this->getRequest()->getFiles()['image']['size'] > 0) {
|
||||
try {
|
||||
$this->imageHelper->uploadImage($data, 'image', Image::TEMPLATE_MEDIA_TYPE_AUTH);
|
||||
} catch (Exception $exception) {
|
||||
$data['image'] = isset($data['image']['value']) ? $data['image']['value'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['image']['delete'])) {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?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\Author;
|
||||
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Mageplaza\Blog\Helper\Data;
|
||||
use Mageplaza\Blog\Model\Config\Source\SideBarLR;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package Mageplaza\Blog\Controller\Author
|
||||
*/
|
||||
class Signup extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var ForwardFactory
|
||||
*/
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
protected $_helperBlog;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
* @param Data $helperData
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
ForwardFactory $resultForwardFactory,
|
||||
Data $helperData
|
||||
) {
|
||||
$this->_helperBlog = $helperData;
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|Redirect|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$this->_helperBlog->setCustomerContextId();
|
||||
|
||||
if (!$this->_helperBlog->isEnabled()
|
||||
|| !$this->_helperBlog->isEnabledAuthor()
|
||||
|| ($this->_helperBlog->isAuthor() && !$this->_helperBlog->getConfigGeneral('customer_approve') && !$this->_helperBlog->getPostViewPageConfig('enable_to_save'))) {
|
||||
$resultRedirect->setPath('customer/account');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
if ($this->_helperBlog->isAuthor() && $this->_helperBlog->getConfigGeneral('customer_approve')) {
|
||||
$page = $this->resultPageFactory->create();
|
||||
$page->getConfig()->setPageLayout(SideBarLR::LEFT);
|
||||
$page->getConfig()->getTitle()->set('Signup Author');
|
||||
|
||||
return $page;
|
||||
}
|
||||
if ($this->_helperBlog->isAuthor() && $this->_helperBlog->getPostViewPageConfig('enable_to_save')) {
|
||||
$resultRedirect->setPath('mpblog/post/save');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
if ($this->_helperBlog->isLogin()) {
|
||||
$resultRedirect->setPath('mpblog/*/information');
|
||||
} else {
|
||||
$resultRedirect->setPath('customer/account');
|
||||
}
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?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\Author;
|
||||
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Mageplaza\Blog\Helper\Data;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package Mageplaza\Blog\Controller\Author
|
||||
*/
|
||||
class View extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
public $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var ForwardFactory
|
||||
*/
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
protected $_helperBlog;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
* @param Data $helperData
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
ForwardFactory $resultForwardFactory,
|
||||
Data $helperData
|
||||
) {
|
||||
$this->_helperBlog = $helperData;
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$id = $this->getRequest()->getParam('id');
|
||||
$page = $this->resultPageFactory->create();
|
||||
$page->getConfig()->setPageLayout($this->_helperBlog->getSidebarLayout());
|
||||
|
||||
return ($id)
|
||||
? $page
|
||||
: $this->_redirect('noroute');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user