/**
* @return string
*/
public function actionIndex()
{
/* @var $postType PostType */
/* @var $post Post */
/* @var $taxonomies Taxonomy[] */
/* @var $taxonomy Taxonomy */
/* @var $lastMedia Media */
$response = Yii::$app->response;
$response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
$response->format = $response::FORMAT_RAW;
$postTypes = PostType::find()->select(['id', 'post_type_slug'])->all();
$taxonomies = Taxonomy::find()->select(['id', 'taxonomy_slug'])->all();
$items = [];
foreach ($postTypes as $postType) {
if (!isset($this->_option['post_type'][$postType->id]['enable']) || !$this->_option['post_type'][$postType->id]['enable']) {
continue;
}
if ($post = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one()) {
$lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
$query = $postType->getPosts()->andWhere(['post_status' => 'publish']);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
for ($i = 1; $i <= $pages->pageCount; $i++) {
$items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'p', 'slug' => $postType->post_type_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
}
}
}
foreach ($taxonomies as $taxonomy) {
if (!isset($this->_option['taxonomy'][$taxonomy->id]['enable']) || !$this->_option['taxonomy'][$taxonomy->id]['enable']) {
continue;
}
if ($terms = $taxonomy->terms) {
$post = Post::find()->from(['post' => Post::tableName()])->innerJoinWith(['terms' => function ($query) {
/* @var $query \yii\db\ActiveQuery */
$query->from(['term' => Term::tableName()]);
}])->where(['IN', 'term.id', ArrayHelper::getColumn($terms, 'id')])->andWhere(['post.post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC])->one();
if ($post) {
$query = $taxonomy->getTerms();
$lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
for ($i = 1; $i <= $pages->pageCount; $i++) {
$items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'c', 'slug' => $taxonomy->taxonomy_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
}
}
}
}
if (isset($this->_option['media']['enable']) && $this->_option['media']['enable']) {
$query = Media::find();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
if ($lastMedia = $query->orderBy(['id' => SORT_DESC])->one()) {
$lastmod = new \DateTime($lastMedia->media_modified, new \DateTimeZone(Option::get('time_zone')));
for ($i = 1; $i <= $pages->pageCount; $i++) {
$items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'm', 'slug' => 'media', 'page' => $i]), 'lastmod' => $lastmod->format('r')];
}
}
}
return $this->renderPartial('index', ['items' => $items]);
}