Skip to content

Instantly share code, notes, and snippets.

@SergeyZaigraev
Created October 11, 2017 06:48
Show Gist options
  • Save SergeyZaigraev/13505398546f044403365e82e8e78949 to your computer and use it in GitHub Desktop.
Save SergeyZaigraev/13505398546f044403365e82e8e78949 to your computer and use it in GitHub Desktop.
Custom sitemap runtime. Add new tag: changefreq, priority
<?
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()),
));
}
}
@SergeyZaigraev
Copy link
Author

Добавляю к стандартному sitemap параметры: changefreq, priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment