-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b3ed43
commit 0ce370f
Showing
52 changed files
with
2,787 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan (support@magefan.com). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
|
||
namespace Magefan\HtmlSitemap\Block\Additional; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Magefan\HtmlSitemap\Model\Config; | ||
|
||
class Additional extends Template | ||
{ | ||
const XML_PATH_TO_ADDITIONAL_BLOCK_TITLE = 'mfhs/additionallinks/title'; | ||
const XML_PATH_TO_ADDITIONAL_LINKS = 'mfhs/additionallinks/links'; | ||
const XML_PATH_TO_ADDITIONAL_LINKS_LIMIT = 'mfhs/additionallinks/maxnumberlinks'; | ||
const XML_PATH_TO_ADDITIONAL_LINKS_MORE = 'mfhs/additionallinks/displaymore'; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Additional constructor. | ||
* @param Template\Context $context | ||
* @param Config $config | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
Config $config, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBlockTitle() | ||
{ | ||
return (string)$this->config->getConfig(self::XML_PATH_TO_ADDITIONAL_BLOCK_TITLE); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
protected function getAdditionalLinks() | ||
{ | ||
return $this->config->getConfig(self::XML_PATH_TO_ADDITIONAL_LINKS); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function showViewMore() | ||
{ | ||
if ($this->config->getConfig(self::XML_PATH_TO_ADDITIONAL_LINKS_MORE) | ||
&& count($this->getAllLinksArray())> $this->config->getConfig(self::XML_PATH_TO_ADDITIONAL_LINKS_LIMIT) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getLinksArray() | ||
{ | ||
$linksStr = $this->getAdditionalLinks(); | ||
$links = preg_split('/\r+/', $linksStr); | ||
$linksArray = []; | ||
$pageSize = $this->config->getConfig(self::XML_PATH_TO_ADDITIONAL_LINKS_LIMIT); | ||
|
||
$i = 0; | ||
if (!empty($links)) { | ||
foreach ($links as $link) { | ||
if ($i >= $pageSize) { | ||
break; | ||
} | ||
if ($link !='') { | ||
$linkElements = explode('|', $link); | ||
|
||
if ($linkElements[0] == '/') { | ||
$linkElements[0] = ''; | ||
} | ||
|
||
if (!in_array(trim($linkElements[0]), $this->config->getIgnoredLinks(null, false))) { | ||
$linksArray[] =['url' => $linkElements[0],'title' => trim($linkElements[1], '()')] ; | ||
$i++; | ||
} | ||
} | ||
} | ||
} | ||
return (array) $linksArray; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAllLinksArray() | ||
{ | ||
$linksStr = $this->getAdditionalLinks(); | ||
$links = preg_split('/\r+/', $linksStr); | ||
$linksArray = []; | ||
|
||
if (!empty($links)) { | ||
foreach ($links as $link) { | ||
if ($link !='') { | ||
$linkElements = explode('|', $link); | ||
|
||
if ($linkElements[0] == '/') { | ||
$linkElements[0] = ''; | ||
} | ||
|
||
if (!in_array(trim($linkElements[0]), $this->config->getIgnoredLinks(null, false))) { | ||
$linksArray[] =['url' => $linkElements[0],'title' => trim($linkElements[1], '()')] ; | ||
} | ||
} | ||
} | ||
} | ||
return (array) $linksArray; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSortOrder() | ||
{ | ||
return $this->config->getSortOrder('additionallinks'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan (support@magefan.com). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
|
||
namespace Magefan\HtmlSitemap\Block\Adminhtml\System\Config\Form; | ||
|
||
class Info extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info | ||
{ | ||
/** | ||
* Return extension url | ||
* @return string | ||
*/ | ||
protected function getModuleUrl() | ||
{ | ||
return 'https://mage' . 'fan.com?utm_source=m2admin_html_sitemap_config&utm_medium=link&utm_campaign=regular'; | ||
} | ||
/** | ||
* Return extension title | ||
* @return string | ||
*/ | ||
protected function getModuleTitle() | ||
{ | ||
return 'Magefan HtmlSitemap Extension'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan (support@magefan.com). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
|
||
namespace Magefan\HtmlSitemap\Block\Blog; | ||
|
||
use Magefan\HtmlSitemap\Model\Config; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magefan\HtmlSitemap\Model\BlogFactory; | ||
|
||
class Category extends Template | ||
{ | ||
const XML_PATH_TO_BLOG_CATEGORY_TITLE = 'mfhs/blogcategorylinks/title'; | ||
const XML_PATH_TO_BLOG_CATEGORY_DEPTH = 'mfhs/blogcategorylinks/maxdepth'; | ||
const XML_PATH_TO_BLOG_CATEGORY_VIEW_MORE = 'mfhs/blogcategorylinks/displaymore'; | ||
const XML_PATH_TO_BLOG_CATEGORY_LIMIT = 'mfhs/blogcategorylinks/maxnumberlinks'; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $ignoredLinks; | ||
|
||
/** | ||
* @var BlogFactory | ||
*/ | ||
private $blogFactory; | ||
|
||
/** | ||
* Category constructor. | ||
* @param Template\Context $context | ||
* @param Config $config | ||
* @param StoreManagerInterface $storeManager | ||
* @param BlogFactory $blogFactory | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
Config $config, | ||
StoreManagerInterface $storeManager, | ||
BlogFactory $blogFactory, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->config = $config; | ||
$this->storeManager = $storeManager; | ||
$this->blogFactory = $blogFactory; | ||
$this->ignoredLinks = $config->getIgnoredLinks(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBlockTitle() | ||
{ | ||
return (string)$this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_TITLE); | ||
} | ||
|
||
/** | ||
* @return bool | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function showViewMore() | ||
{ | ||
if ($this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_VIEW_MORE) | ||
&& count($this->getAllGroupedChildes())> $this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_LIMIT) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getGroupedChildes() | ||
{ | ||
$pageSize = $this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_LIMIT); | ||
$k = 'grouped_childs'; | ||
if (!$this->hasData($k)) { | ||
$array = $this->blogFactory->createCategoryCollection() | ||
->addActiveFilter() | ||
->addStoreFilter($this->_storeManager->getStore()->getId()); | ||
if (!empty($this->ignoredLinks)) { | ||
$array->addFieldToFilter('identifier', ['nin' => $this->config->getIgnoredLinks()]); | ||
} | ||
$array = $array->setOrder('position')->setPageSize($pageSize)->getTreeOrderedArray(); | ||
foreach ($array as $key => $item) { | ||
$maxDepth = $this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_DEPTH); | ||
if ($maxDepth > 0 && $item->getLevel() >= $maxDepth) { | ||
unset($array[$key]); | ||
} | ||
} | ||
|
||
$this->setData($k, $array); | ||
} | ||
|
||
return $this->getData($k); | ||
} | ||
|
||
/** | ||
* Get grouped categories | ||
* @return array | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getAllGroupedChildes() | ||
{ | ||
$k = 'all_grouped_childes'; | ||
if (!$this->hasData($k)) { | ||
$array = $this->blogFactory->createCategoryCollection() | ||
->addActiveFilter() | ||
->addStoreFilter($this->_storeManager->getStore()->getId()); | ||
if (!empty($this->ignoredLinks)) { | ||
$array->addFieldToFilter('identifier', ['nin' => $this->config->getIgnoredLinks()]); | ||
} | ||
$array = $array->setOrder('position')->getTreeOrderedArray(); | ||
foreach ($array as $key => $item) { | ||
$maxDepth = $this->config->getConfig(self::XML_PATH_TO_BLOG_CATEGORY_DEPTH); | ||
if ($maxDepth > 0 && $item->getLevel() >= $maxDepth) { | ||
unset($array[$key]); | ||
} | ||
} | ||
|
||
$this->setData($k, $array); | ||
} | ||
|
||
return $this->getData($k); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSortOrder() | ||
{ | ||
return $this->config->getSortOrder('blogcategorylinks'); | ||
} | ||
|
||
public function toHtml() | ||
{ | ||
if (!$this->config->isBlogEnabled()) { | ||
return ''; | ||
} | ||
return parent::toHtml(); // TODO: Change the autogenerated stub | ||
} | ||
} |
Oops, something went wrong.