Skip to content

Commit 1585556

Browse files
authored
Merge pull request #16 from KozakSerhii/9902-HTML-sitemap-v2
9902 html sitemap v2
2 parents 3b0afe9 + 3d8bb1e commit 1585556

File tree

76 files changed

+1852
-1958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1852
-1958
lines changed

Block/AbstractBlock.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magefan\HtmlSitemap\Block;
12+
13+
use Magento\Framework\View\Element\Template;
14+
use Magefan\HtmlSitemap\Model\Config;
15+
16+
abstract class AbstractBlock extends Template
17+
{
18+
19+
/**
20+
* @var Config
21+
*/
22+
protected $config;
23+
24+
/**
25+
* AbstractBlock constructor.
26+
* @param Template\Context $context
27+
* @param Config $config
28+
* @param array $data
29+
*/
30+
public function __construct(
31+
Template\Context $context,
32+
Config $config,
33+
array $data = []
34+
) {
35+
parent::__construct($context, $data);
36+
$this->config = $config;
37+
}
38+
39+
/**
40+
* @var string
41+
*/
42+
protected $type = '';
43+
44+
/**
45+
* @return mixed
46+
* @throws \Magento\Framework\Exception\NoSuchEntityException
47+
*/
48+
abstract protected function getCollection();
49+
50+
/**
51+
* @return array|mixed|null
52+
* @throws \Magento\Framework\Exception\NoSuchEntityException
53+
*/
54+
abstract public function getItems();
55+
56+
/**
57+
* @return bool
58+
*/
59+
public function showBlockTitle(): bool
60+
{
61+
return false;
62+
}
63+
64+
/**
65+
* @return int
66+
*/
67+
protected function getPageSize(): int
68+
{
69+
return 0;
70+
}
71+
72+
/**
73+
* @return bool
74+
* @throws \Magento\Framework\Exception\NoSuchEntityException
75+
*/
76+
public function showViewMore(): bool
77+
{
78+
if ($this->config->getBlockViewMore($this->type)
79+
&& $this->getPageSize() && count($this->getCollection()) >= $this->getPageSize()
80+
) {
81+
return true;
82+
}
83+
return false;
84+
}
85+
86+
/**
87+
* @return string
88+
*/
89+
abstract public function getCurrentTypeHtmlSitemapUrl();
90+
91+
/**
92+
* @return string
93+
*/
94+
public function getBlockTitle(): string
95+
{
96+
return (string)$this->config->getBlockTitle($this->type);
97+
}
98+
}

Block/Additional/AbstractLinks.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magefan\HtmlSitemap\Block\Additional;
12+
13+
use Magento\Framework\DataObject;
14+
use Magefan\HtmlSitemap\Block\AbstractBlock;
15+
16+
abstract class AbstractLinks extends AbstractBlock
17+
{
18+
/**
19+
* @var string
20+
*/
21+
protected $type = 'additionallinks';
22+
23+
/**
24+
* @return array
25+
*/
26+
protected function getCollection()
27+
{
28+
$k = 'collection';
29+
if (null === $this->getData($k)) {
30+
$i = 0;
31+
$pageSize = $this->getPageSize();
32+
$collection = [];
33+
$links = $this->config->getAdditionalLinks() ?: '';
34+
$links = str_replace(["\n", "\r"], [PHP_EOL, PHP_EOL], $links);
35+
$links = explode(PHP_EOL, $links);
36+
foreach ($links as $link) {
37+
$link = trim($link);
38+
$link = trim($link, '/');
39+
if (!$link) {
40+
continue;
41+
}
42+
43+
$linkData = explode('|', $link);
44+
45+
$url = trim($linkData[0]);
46+
47+
if (in_array($url, $this->config->getIgnoredLinks(null, false))) {
48+
continue;
49+
}
50+
51+
$collection[] = new DataObject([
52+
'url' => $linkData[0],
53+
'name' => isset($linkData[1]) ? $linkData[1] : $linkData[0]
54+
]);
55+
$i++;
56+
57+
if ($i >= $pageSize) {
58+
break;
59+
}
60+
61+
}
62+
63+
$this->setData($k, $collection);
64+
}
65+
return $this->getData($k);
66+
}
67+
68+
/**
69+
* @return mixed
70+
* @throws \Magento\Framework\Exception\NoSuchEntityException
71+
*/
72+
public function getItems()
73+
{
74+
$k = 'items';
75+
if (null === $this->getData($k)) {
76+
$items = [];
77+
foreach ($this->getCollection() as $collectionItem) {
78+
$item = new DataObject([
79+
'url' => $collectionItem->getUrl(),
80+
'name' => $collectionItem->getName(),
81+
'object' => $collectionItem
82+
]);
83+
$items[] = $item;
84+
}
85+
$this->setData($k, $items);
86+
}
87+
88+
return $this->getData($k);
89+
}
90+
91+
/**
92+
* @return string
93+
*/
94+
public function getCurrentTypeHtmlSitemapUrl()
95+
{
96+
return $this->getUrl('htmlsitemap/additional/links');
97+
}
98+
}

Block/Additional/Additional.php

Lines changed: 0 additions & 151 deletions
This file was deleted.

Block/Additional/Links.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Magefan\HtmlSitemap\Block\Additional;
12+
13+
class Links extends AbstractLinks
14+
{
15+
use \Magefan\HtmlSitemap\Block\Type\Block;
16+
}

Block/Adminhtml/System/Config/Form/Info.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
/**
33
* Copyright © Magefan (support@magefan.com). All rights reserved.
44
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
57
*/
68

9+
declare(strict_types=1);
10+
711
namespace Magefan\HtmlSitemap\Block\Adminhtml\System\Config\Form;
812

913
class Info extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info

0 commit comments

Comments
 (0)