Skip to content

Instantly share code, notes, and snippets.

@but1head

but1head/sitemap localizator Secret

Created Jan 31, 2018
Embed
What would you like to do?
<?php
$output = "";
$resources = $modx->runSnippet('pdoResources', [
'parents' => 0,
'limit' => 0,
'leftJoin' => '{
"localizator" : {
"class" : "localizatorContent",
"alias" : "localizator",
"on" : "localizator.resource_id = modResource.id"
}
}',
'select' => '{ "localizator" : "modResource.*, localizator.*, modResource.id" }',
'where' => [
'localizator.key' => $modx->localizator_key,
'localizator.active' => 1,
],
'return' => 'json',
]);
if($resources) {
$resources = json_decode($resources);
foreach($resources as $resource) {
$url = $modx->config['site_url'] . $resource->uri;
$changefreq = 'weekly';
$priority = '0.5';
// дата изменения
$lastmod = date('Y-m-d', $resource->editedon ?: $resource->createdon);
/* if($row['last_review_date']){
$date = new DateTime($row['last_review_date']);
$lastmod = $date->format('Y-m-d');
} */
// пометка ежечастного обноавления, id категорий
if(in_array($resource->parent, [195, 2, 138, 196, 197, 198, 199, 24])) $changefreq = 'hourly';
// приоретитет
if(in_array($resource->id, [2, 24, 138])) $priority = '1.0';
$output .= "
<url>
<loc>{$url}</loc>
<lastmod>{$lastmod}</lastmod>
<changefreq>{$changefreq}</changefreq>
<priority>{$priority}</priority>
</url>
";
}
}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment