summaryrefslogtreecommitdiff
path: root/templates/themes/sitemap/theme.php
blob: 226f835755974a20474d8fe66ba389507442c28c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
	require 'info.php';
	
	function sitemap_build($action, $settings, $board) {
		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)
		//	- thread (a thread has been made)
		
		if ($action != 'post' && $action != 'post-thread')
			return;
		
		$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,
		)));
	}