2013-07-17 10:17:28 -04:00
< ? php
require 'info.php' ;
2013-07-18 12:06:26 -04:00
function sitemap_build ( $action , $settings , $board ) {
2013-07-17 10:17:28 -04:00
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)
2013-07-18 12:06:26 -04:00
// - thread (a thread has been made)
2015-04-02 23:57:39 -04:00
if ( $action != 'all' ) {
if ( $action != 'post-thread' && $action != 'post-delete' )
return ;
2013-07-18 12:06:26 -04:00
2015-04-02 23:57:39 -04:00
if ( isset ( $settings [ 'regen_time' ]) && $settings [ 'regen_time' ] > 0 ) {
if ( $last_gen = @ filemtime ( $settings [ 'path' ])) {
if ( time () - $last_gen < ( int ) $settings [ 'regen_time' ])
return ; // Too soon
}
2013-08-28 04:30:01 -04:00
}
}
2015-04-02 23:57:39 -04:00
if ( $config [ 'smart_build' ]) {
file_unlink ( $settings [ 'path' ]);
}
else {
$boards = explode ( ' ' , $settings [ 'boards' ]);
2013-08-28 04:30:01 -04:00
2015-04-02 23:57:39 -04:00
$threads = array ();
2013-07-17 10:17:28 -04:00
2015-04-02 23:57:39 -04:00
foreach ( $boards as $board ) {
$query = query ( sprintf ( " SELECT `id`, `id` AS `thread_id`, `slug`, (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 );
}
2013-07-17 10:17:28 -04:00
2015-04-02 23:57:39 -04:00
file_write ( $settings [ 'path' ], Element ( 'themes/sitemap/sitemap.xml' , Array (
'settings' => $settings ,
'config' => $config ,
'threads' => $threads ,
'boards' => $boards ,
)));
}
2013-07-17 10:17:28 -04:00
}