Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
This commit is contained in:
commit
8c72c8a432
53
templates/themes/sitemap/info.php
Normal file
53
templates/themes/sitemap/info.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
$theme = Array();
|
||||||
|
|
||||||
|
// Theme name
|
||||||
|
$theme['name'] = 'Sitemap Generator';
|
||||||
|
// Description (you can use Tinyboard markup here)
|
||||||
|
$theme['description'] = 'Generates an XML sitemap to help search engines find all threads and pages.';
|
||||||
|
$theme['version'] = 'v1.0';
|
||||||
|
|
||||||
|
// Theme configuration
|
||||||
|
$theme['config'] = Array();
|
||||||
|
|
||||||
|
$theme['config'][] = Array(
|
||||||
|
'title' => 'Sitemap Path',
|
||||||
|
'name' => 'path',
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => 'sitemap.xml',
|
||||||
|
'size' => '20'
|
||||||
|
);
|
||||||
|
|
||||||
|
$theme['config'][] = Array(
|
||||||
|
'title' => 'URL prefix',
|
||||||
|
'name' => 'url',
|
||||||
|
'type' => 'text',
|
||||||
|
'comment' => '(with trailing slash)',
|
||||||
|
'default' => 'http://' . $_SERVER['HTTP_HOST'] . $config['root'],
|
||||||
|
'size' => '20'
|
||||||
|
);
|
||||||
|
|
||||||
|
$theme['config'][] = Array(
|
||||||
|
'title' => 'Thread change frequency',
|
||||||
|
'name' => 'changefreq',
|
||||||
|
'type' => 'text',
|
||||||
|
'comment' => '(eg. "hourly", "daily", etc.)',
|
||||||
|
'default' => 'hourly',
|
||||||
|
'size' => '20'
|
||||||
|
);
|
||||||
|
|
||||||
|
$__boards = listBoards();
|
||||||
|
$__default_boards = Array();
|
||||||
|
foreach ($__boards as $__board)
|
||||||
|
$__default_boards[] = $__board['uri'];
|
||||||
|
|
||||||
|
$theme['config'][] = Array(
|
||||||
|
'title' => 'Boards',
|
||||||
|
'name' => 'boards',
|
||||||
|
'type' => 'text',
|
||||||
|
'comment' => '(boards to include; space seperated)',
|
||||||
|
'size' => 24,
|
||||||
|
'default' => implode(' ', $__default_boards)
|
||||||
|
);
|
||||||
|
|
||||||
|
$theme['build_function'] = 'sitemap_build';
|
19
templates/themes/sitemap/sitemap.xml
Normal file
19
templates/themes/sitemap/sitemap.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% filter remove_whitespace %}
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
{% for board in boards %}
|
||||||
|
<url>
|
||||||
|
<loc>{{ settings.url ~ (config.board_path | format(board)) ~ config.file_index }}</loc>
|
||||||
|
</url>
|
||||||
|
{% endfor %}
|
||||||
|
{% for board, thread_list in threads %}
|
||||||
|
{% for thread in thread_list %}
|
||||||
|
<url>
|
||||||
|
<loc>{{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ (config.file_page | format(thread.thread_id)) }}</loc>
|
||||||
|
<lastmod>{{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }}</lastmod>
|
||||||
|
<changefreq>{{ settings.changefreq }}</changefreq>
|
||||||
|
</url>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</urlset>
|
||||||
|
{% endfilter %}
|
28
templates/themes/sitemap/theme.php
Normal file
28
templates/themes/sitemap/theme.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
require 'info.php';
|
||||||
|
|
||||||
|
function sitemap_build($action, $settings) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// Possible values for $action:
|
||||||
|
// - all (rebuild everything, initialization)
|
||||||
|
// - news (news has been updated)
|
||||||
|
// - boards (board list changed)
|
||||||
|
// - post (a post has been made)
|
||||||
|
|
||||||
|
$boards = explode(' ', $settings['boards']);
|
||||||
|
|
||||||
|
$threads = array();
|
||||||
|
|
||||||
|
foreach ($boards as $board) {
|
||||||
|
$query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM `posts_%s` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM `posts_%s` WHERE `thread` IS NULL", $board, $board)) or error(db_error());
|
||||||
|
$threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_write($settings['path'], Element('themes/sitemap/sitemap.xml', Array(
|
||||||
|
'settings' => $settings,
|
||||||
|
'config' => $config,
|
||||||
|
'threads' => $threads,
|
||||||
|
'boards' => $boards,
|
||||||
|
)));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user