Skip to content

Commit

Permalink
sitemap пока без кеширования
Browse files Browse the repository at this point in the history
  • Loading branch information
visavi committed Dec 9, 2016
1 parent 56a4134 commit c379fae
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 35 deletions.
102 changes: 101 additions & 1 deletion app/modules/pages/sitemap.php
@@ -1,15 +1,115 @@
<?php

switch ($act):

/**
* Генерируем главную страницу
*/
case 'index':
$pages = [
'news.xml',
'blogs.xml',
'events.xml',
'topics.xml',
];
$locs = [];
foreach ($pages as $page) {
$locs[] = [
'loc' => App::setting('home').'/sitemap/'.$page,
'lastmod' => date('c', SITETIME),
];
}

App::view('sitemap/index', compact('locs'));
break;

/**
* Генерируем блоги
*/
case 'blogs':
$blogs = DBM::run()->select('blogs');

$locs = [];
foreach ($blogs as $blog) {

// Обновлено менее 1 месяца
$new = (SITETIME < $blog['time'] + 3600 * 24 * 30) ? true : false;

$locs[] = [
'loc' => App::setting('home').'/blog/blog?act=view&id='.$blog['id'],
'lastmod' => date('c', $blog['time']),
'changefreq' => $new ? 'weekly' : 'monthly',
'priority' => $new ? '1.0' : '0.8',
];
}
App::view('sitemap/url', compact('locs'));
break;
/**
* Генерируем новости
*/
case 'news':
$newses = DBM::run()->select('news');

$locs = [];
foreach ($newses as $news) {

// Обновлено менее 1 месяца
$new = (SITETIME < $news['time'] + 3600 * 24 * 30) ? true : false;

$locs[] = [
'loc' => App::setting('home').'/news/'.$news['id'],
'lastmod' => date('c', $news['time']),
'changefreq' => $new ? 'weekly' : 'monthly',
'priority' => $new ? '1.0' : '0.8',
];
}
App::view('sitemap/url', compact('locs'));
break;

/**
* Генерируем события
*/
case 'events':
$events = DBM::run()->select('events');

$locs = [];
foreach ($events as $event) {

// Обновлено менее 1 месяца
$new = (SITETIME < $event['time'] + 3600 * 24 * 30) ? true : false;

$locs[] = [
'loc' => App::setting('home').'/events?act=read&id='.$event['id'],
'lastmod' => date('c', SITETIME),
'changefreq' => $new ? 'weekly' : 'monthly',
'priority' => $new ? '1.0' : '0.8',
];
}
App::view('sitemap/url', compact('locs'));
break;

/**
* Генерируем темы форума
*/
case 'topics':
$topics = DBM::run()->select('topics');

$locs = [];
foreach ($topics as $topic) {

// Обновлено менее 1 месяца
$new = (SITETIME < $topic['last_time'] + 3600 * 24 * 30) ? true : false;

$locs[] = [
'loc' => App::setting('home').'/topic/'.$topic['id'],
'lastmod' => date('c', $topic['last_time']),
'changefreq' => $new ? 'weekly' : 'monthly',
'priority' => $new ? '1.0' : '0.8',
];
}
App::view('sitemap/url', compact('locs'));
break;

App::view('sitemap');
default:
App::abort(404);
endswitch;
1 change: 1 addition & 0 deletions app/routes.php
Expand Up @@ -13,6 +13,7 @@
$router->map('GET|POST', '/book/[edit:action]/[i:id]', '/modules/book/index.php');

$router->map('GET', '/sitemap.xml', '/modules/pages/sitemap.php');
$router->map('GET', '/sitemap/[a:action].xml', '/modules/pages/sitemap.php');

$router->map('GET', '/blog', '/modules/blog/index.php', 'blog');
$router->map('GET|POST', '/blog/active', '/modules/blog/active.php');
Expand Down
34 changes: 0 additions & 34 deletions app/views/sitemap.blade.php

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/sitemap/index.blade.php
@@ -0,0 +1,15 @@
<?php header("Content-type:application/xml; charset=utf-8"); ?>
<?= '<?xml version="1.0" encoding="utf-8"?>' ?>

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

@foreach($locs as $loc)

<sitemap>
<loc>{{ $loc['loc'] }}</loc>
<lastmod>{{ $loc['lastmod'] }}</lastmod>
</sitemap>

@endforeach

</sitemapindex>
17 changes: 17 additions & 0 deletions app/views/sitemap/url.blade.php
@@ -0,0 +1,17 @@
<?php header("Content-type:application/xml; charset=utf-8"); ?>
<?= '<?xml version="1.0" encoding="utf-8"?>' ?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

@foreach($locs as $loc)

<url>
<loc>{{ $loc['loc'] }}</loc>
<lastmod>{{ $loc['lastmod'] }}</lastmod>
<changefreq>{{ $loc['changefreq'] }}</changefreq>
<priority>{{ $loc['priority'] }}</priority>
</url>

@endforeach

</urlset>

0 comments on commit c379fae

Please sign in to comment.