kokjan/vendor/himiklab/yii2-sitemap-module/controllers/DefaultController.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2026-02-25 06:59:34 +00:00
<?php
/**
* @link https://github.com/himiklab/yii2-sitemap-module
* @copyright Copyright (c) 2014-2017 HimikLab
* @license http://opensource.org/licenses/MIT MIT
*/
namespace himiklab\sitemap\controllers;
use Yii;
use yii\web\Controller;
use yii\web\Response;
/**
* @author HimikLab
* @package himiklab\sitemap
*/
class DefaultController extends Controller
{
public function actionIndex()
{
/** @var \himiklab\sitemap\Sitemap $module */
$module = $this->module;
if (!$sitemapData = $module->cacheProvider->get($module->cacheKey)) {
$sitemapData = $module->buildSitemap();
}
Yii::$app->response->format = Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/xml');
if ($module->enableGzip) {
if (!$module->enableGzipedCache) {
$sitemapData = gzencode($sitemapData);
}
$headers->add('Content-Encoding', 'gzip');
$headers->add('Content-Length', strlen($sitemapData));
} elseif ($module->enableGzipedCache) {
$sitemapData = gzdecode($sitemapData);
}
return $sitemapData;
}
}