Created
October 11, 2017 06:48
-
-
Save SergeyZaigraev/13505398546f044403365e82e8e78949 to your computer and use it in GitHub Desktop.
Custom sitemap runtime. Add new tag: changefreq, priority
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
<? | |
use Bitrix\Main\IO\File; | |
use Bitrix\Main\Text\Converter; | |
use Bitrix\Seo\SitemapRuntime; | |
class SitemapRuntimeCustom extends SitemapRuntime | |
{ | |
const ENTRY_TPL_NEW = '<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url>'; | |
public function __construct($PID, $fileName, $arSettings) | |
{ | |
parent::__construct($PID, $fileName, $arSettings); | |
} | |
public function addEntry($entry) | |
{ | |
if($this->isSplitNeeded()) | |
{ | |
$this->split(); | |
$this->addEntry($entry); | |
} | |
else | |
{ | |
if(!$this->partChanged) | |
{ | |
$this->addHeader(); | |
} | |
$this->putContents( | |
sprintf( | |
self::ENTRY_TPL_NEW, | |
Converter::getXmlConverter()->encode($entry['XML_LOC']), | |
Converter::getXmlConverter()->encode($entry['XML_LASTMOD']) | |
), self::APPEND | |
); | |
} | |
} | |
public function addFileEntry(File $f) | |
{ | |
if($f->isExists() && !$f->isSystem()) | |
{ | |
$this->addEntry(array( | |
'XML_LOC' => $this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null).$this->getFileUrl($f), | |
'XML_LASTMOD' => date('c', $f->getModificationTime()), | |
)); | |
} | |
} | |
public function addIBlockEntry($url, $modifiedDate) | |
{ | |
$this->addEntry(array( | |
'XML_LOC' => $this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null).$url, | |
'XML_LASTMOD' => date('c', $modifiedDate - \CTimeZone::getOffset()), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Добавляю к стандартному sitemap параметры: changefreq, priority