Created
March 26, 2020 17:08
-
-
Save NazarenkoDenis/e6f40eae22b4404f3fd6fa8cb2a5da16 to your computer and use it in GitHub Desktop.
vendor/mirasvit/module-seo/src/SeoSitemap/Repository/Provider/FishPig/BlogProvider.php
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
<?php | |
namespace Mirasvit\SeoSitemap\Repository\Provider\FishPig; | |
use Magento\Framework\DataObject; | |
use Magento\Framework\ObjectManagerInterface; | |
use Magento\Sitemap\Helper\Data as DataHelper; | |
use Mirasvit\SeoSitemap\Api\Repository\ProviderInterface; | |
class BlogProvider implements ProviderInterface | |
{ | |
private $objectManager; | |
private $dataHelper; | |
public function __construct( | |
ObjectManagerInterface $objectManager, | |
DataHelper $dataHelper | |
) { | |
$this->objectManager = $objectManager; | |
$this->dataHelper = $dataHelper; | |
} | |
public function getModuleName() | |
{ | |
return 'FishPig_WordPress'; | |
} | |
public function isApplicable() | |
{ | |
return true; | |
} | |
public function getTitle() | |
{ | |
return __('Blog'); | |
} | |
public function initSitemapItem($storeId) | |
{ | |
$result = []; | |
$result[] = new DataObject([ | |
'changefreq' => $this->dataHelper->getPageChangefreq($storeId), | |
'priority' => $this->dataHelper->getPagePriority($storeId), | |
'collection' => $this->getItems($storeId), | |
]); | |
return $result; | |
} | |
public function getItems($storeId) | |
{ | |
$items = []; | |
try { | |
$emulation = $this->objectManager->create('Magento\Store\Model\App\Emulation'); | |
$emulation->startEnvironmentEmulation($storeId, 'frontend', true); | |
$collection = $this->objectManager->get('FishPig\WordPress\Model\ResourceModel\Post\Collection'); | |
$collection->addIsViewableFilter(); | |
$emulation->stopEnvironmentEmulation(); | |
foreach ($collection as $key => $post) { | |
$url = $post->getUrl(); | |
$url = parse_url($url, PHP_URL_PATH); | |
$url = ltrim($url, '/'); | |
$items[] = new DataObject([ | |
'id' => $post->getId(), | |
'url' => $url, | |
'title' => $post->getName(), | |
'updated_at' => $post->getPostModifiedDate(), | |
]); | |
} | |
} catch (\Exception $e) { | |
} | |
return $items; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment