Commit 59546e45 authored by Шакарим Сапа's avatar Шакарим Сапа

Merge remote-tracking branch 'origin/master'

parents 825b95ff 8c62d8cc
......@@ -163,6 +163,7 @@ return [
'rules' => [
'contacts' => 'site/contacts',
['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],
['pattern' => 'sitemapg', 'route' => 'sitemap/default/google', 'suffix' => '.xml'],
'' => 'content/page/view',
'reviews' => 'reviews/review/index',
......
......@@ -59,7 +59,7 @@ class Sitemap extends Module
* @return string
* @throws \yii\base\InvalidConfigException
*/
public function buildSitemap()
public function buildSitemap($links = false)
{
$urls = $this->urls;
......@@ -85,7 +85,8 @@ class Sitemap extends Module
$sitemapData = $this->createControllerByID('default')->renderPartial('index', [
'urls' => $urls,
'langs' => $langs
'langs' => $langs,
'links' => $links
]);
$this->cacheProvider->set($this->cacheKey, $sitemapData, $this->cacheExpire);
......
......@@ -39,4 +39,28 @@ class DefaultController extends Controller
return $sitemapData;
}
public function actionGoogle()
{
/** @var \himiklab\sitemap\Sitemap $module */
$module = $this->module;
if (!$sitemapData = $module->cacheProvider->get($module->cacheKey))
{
$sitemapData = $module->buildSitemap(true);
}
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/xml');
if ($module->enableGzip)
{
$sitemapData = gzencode($sitemapData);
$headers->add('Content-Encoding', 'gzip');
$headers->add('Content-Length', strlen($sitemapData));
}
return $sitemapData;
}
}
......@@ -17,7 +17,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
<url>
<loc><?= yii\helpers\Url::to($url['loc'], true) ?></loc>
<?php if($langs) :
<?php if($links && $langs) :
foreach ($langs as $lang) : ?>
<xhtml:link rel="alternate" hreflang="<?=$lang->url?>" href="<?= yii\helpers\Url::to((!$lang->default?'/'.$lang->url:'').($url['loc']=='/'?'':'/'.$url['loc']), true) ?>"/>
<?php endforeach;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment