Skip to content

Commit

Permalink
Merge pull request #121 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
haitv282 authored Feb 22, 2022
2 parents df78f80 + 19bf204 commit 57abd78
Show file tree
Hide file tree
Showing 5 changed files with 466 additions and 518 deletions.
128 changes: 64 additions & 64 deletions Block/Adminhtml/SeoChecker/CheckButton.php
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
<?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://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_Seo
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license http://mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Block\Adminhtml\SeoChecker;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Mageplaza\Seo\Helper\Data;

/**
* Class CheckButton
* @package Mageplaza\Seo\Block\Adminhtml\SeoChecker
*/
class CheckButton implements ButtonProviderInterface
{
/**
* @var Data
*/
protected $helper;

/**
* CheckButton constructor.
*
* @param Data $helper
*/
public function __construct(Data $helper)
{
$this->helper = $helper;
}

/**
* @return array
*/
public function getButtonData()
{
if (!$this->helper->isEnabled()) {
return [];
}

return [
'label' => __('Check On-page'),
'class' => 'action-secondary save',
'on_click' => 'jQuery("#mageplaza-seo-form").attr("action", "https://seo.mageplaza.com").submit();',
'sort_order' => 85
];
}
}
<?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://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_Seo
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license http://mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Block\Adminhtml\SeoChecker;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Mageplaza\Seo\Helper\Data;

/**
* Class CheckButton
* @package Mageplaza\Seo\Block\Adminhtml\SeoChecker
*/
class CheckButton implements ButtonProviderInterface
{
/**
* @var Data
*/
protected $helper;

/**
* CheckButton constructor.
*
* @param Data $helper
*/
public function __construct(Data $helper)
{
$this->helper = $helper;
}

/**
* @return array
*/
public function getButtonData()
{
if (!$this->helper->isEnabled()) {
return [];
}

return [
'label' => __('PageSpeed Insight'),
'class' => 'action-secondary save',
'on_click' => 'jQuery("#mageplaza-seo-form").submit();',
'sort_order' => 85
];
}
}
84 changes: 13 additions & 71 deletions Block/Adminhtml/SeoChecker/CheckForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
use Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Json\Helper\Data as JsonData;
use Magento\Framework\View\Element\Template;
use Magento\Sitemap\Model\ResourceModel\Sitemap\Collection;
use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory;
use Magento\Framework\View\Element\Template\Context;
use Mageplaza\Seo\Helper\Data as SeoHelperData;

/**
Expand All @@ -39,7 +37,7 @@
*/
class CheckForm extends Template
{
const SEO_TOOL_URL = 'http://seo.mageplaza.com';
const SEO_TOOL_URL = 'https://pagespeed.web.dev/report';

/**
* @var string
Expand All @@ -61,16 +59,6 @@ class CheckForm extends Template
*/
protected $productFactory;

/**
* @var CollectionFactory
*/
protected $sitemapCollection;

/**
* @var JsonData
*/
protected $jsonHelper;

/**
* @var ProductRepositoryInterface
*/
Expand All @@ -89,36 +77,30 @@ class CheckForm extends Template
/**
* CheckForm constructor.
*
* @param Template\Context $context
* @param Context $context
* @param UrlBuilder $cmsUrl
* @param PageFactory $cmsPageFactory
* @param CollectionFactory $sitemapCollection
* @param JsonData $jsonHelper
* @param ProductFactory $productFactory
* @param ProductRepositoryInterface $productRepository
* @param CategoryRepositoryInterface $categoryRepository
* @param SeoHelperData $helper
* @param array $data
*/
public function __construct(
Template\Context $context,
UrlBuilder $cmsUrl,
PageFactory $cmsPageFactory,
CollectionFactory $sitemapCollection,
JsonData $jsonHelper,
ProductFactory $productFactory,
ProductRepositoryInterface $productRepository,
Context $context,
UrlBuilder $cmsUrl,
PageFactory $cmsPageFactory,
ProductFactory $productFactory,
ProductRepositoryInterface $productRepository,
CategoryRepositoryInterface $categoryRepository,
SeoHelperData $helper,
array $data = []
SeoHelperData $helper,
array $data = []
) {
$this->helper = $helper;
$this->productFactory = $productFactory;
$this->categoryRepository = $categoryRepository;
$this->cmsUrl = $cmsUrl;
$this->cmsPageFactory = $cmsPageFactory;
$this->sitemapCollection = $sitemapCollection;
$this->jsonHelper = $jsonHelper;
$this->productRepository = $productRepository;

parent::__construct($context, $data);
Expand All @@ -145,11 +127,11 @@ public function getLink()
case 'catalog_product_edit':
$urlModel = $this->productRepository->getById($id)->getUrlModel();
$product = $this->productFactory->create()->load($id)->setStoreId($storeId);
$url = $urlModel->getUrl($product, ['_query' => ['___store' => $storeCode]]);
$url = $urlModel->getUrl($product);
break;
case 'catalog_category_edit':
$category = $this->categoryRepository->get($id, $storeId);
$url = $category->getUrl(['_query' => ['___store' => $storeCode]]);
$url = $category->getUrl();
break;
case 'cms_page_edit':
$pageId = $this->_request->getParam('page_id');
Expand All @@ -162,48 +144,8 @@ public function getLink()
default:
$url = '';
}
return $url;
}

/**
* get site map links
*
* @return array
* @throws NoSuchEntityException
*/
public function sitemap()
{
$sitemapLinks = [];

/** @var Collection $sitemap */
$sitemap = $this->sitemapCollection->create();

$storeId = $this->_storeManager->getStore()->getId();
if ($storeId) {
$sitemap->addStoreFilter([$storeId]);
}

foreach ($sitemap as $item) {
$sitemapLinks[] = $this->getBaseUrl() . ltrim($item->getSitemapPath(), '/') . $item->getSitemapFilename();
}

return $sitemapLinks;
}

/**
* get Data to check
*
* @return string
* @throws NoSuchEntityException
*/
public function getSeoData()
{
$data = [];
$data['link'] = $this->getLink();
$data['sitemap'] = $this->sitemap();
$data['baseUrl'] = $this->getBaseUrl();

return SeoHelperData::jsonEncode($data);
return $url;
}

/**
Expand Down
Loading

0 comments on commit 57abd78

Please sign in to comment.