diff options
| author | czaks <marcin@6irc.net> | 2013-07-17 22:17:37 -0400 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2013-07-17 22:17:37 -0400 |
| commit | 8c72c8a43232f137256fa170c889ba330ebba7af (patch) | |
| tree | 3e91b94489627a774971dbb09f84bfaaa1465a75 | |
| parent | dd4aea54312b288dbfe885be87148f8df116047a (diff) | |
| parent | 7e95e80c25e2f35b8a49ebd73f95671b0233be6f (diff) | |
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
| -rw-r--r-- | templates/themes/sitemap/info.php | 53 | ||||
| -rw-r--r-- | templates/themes/sitemap/sitemap.xml | 19 | ||||
| -rw-r--r-- | templates/themes/sitemap/theme.php | 28 |
3 files changed, 100 insertions, 0 deletions
diff --git a/templates/themes/sitemap/info.php b/templates/themes/sitemap/info.php new file mode 100644 index 00000000..e16448ee --- /dev/null +++ b/templates/themes/sitemap/info.php @@ -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'; diff --git a/templates/themes/sitemap/sitemap.xml b/templates/themes/sitemap/sitemap.xml new file mode 100644 index 00000000..733da607 --- /dev/null +++ b/templates/themes/sitemap/sitemap.xml @@ -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 %}
\ No newline at end of file diff --git a/templates/themes/sitemap/theme.php b/templates/themes/sitemap/theme.php new file mode 100644 index 00000000..372d292d --- /dev/null +++ b/templates/themes/sitemap/theme.php @@ -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, + ))); + } |
