2013-07-18 17:30:00 +02:00
< ? php
require 'info.php' ;
2013-07-18 18:06:26 +02:00
function catalog_build ( $action , $settings , $board ) {
global $config ;
2013-07-18 17:30:00 +02:00
// Possible values for $action:
// - all (rebuild everything, initialization)
// - news (news has been updated)
// - boards (board list changed)
2013-07-18 18:06:26 +02:00
// - post (a reply has been made)
// - post-thread (a thread has been made)
2013-07-18 17:30:00 +02:00
2014-04-05 23:04:46 +02:00
if ( $settings [ 'all' ]) {
2014-04-23 23:59:41 +02:00
$boards = listBoards ( TRUE );
2014-04-05 23:04:46 +02:00
} else {
$boards = explode ( ' ' , $settings [ 'boards' ]);
}
2013-07-18 18:06:26 +02:00
if ( $action == 'all' ) {
2013-07-18 17:30:00 +02:00
foreach ( $boards as $board ) {
2013-07-18 18:06:26 +02:00
$b = new Catalog ();
$b -> build ( $settings , $board );
2013-07-18 17:30:00 +02:00
}
2014-04-05 23:04:46 +02:00
} elseif ( $action == 'post-thread' || ( $settings [ 'update_on_posts' ] && $action == 'post' ) || ( $settings [ 'update_on_posts' ] && $action == 'post-delete' ) && ( in_array ( $board , $boards ) | $settings [ 'all' ])) {
2013-07-18 18:06:26 +02:00
$b = new Catalog ();
$b -> build ( $settings , $board );
2013-07-18 17:30:00 +02:00
}
2013-07-18 18:06:26 +02:00
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Catalog {
public function build ( $settings , $board_name ) {
2013-07-18 17:30:00 +02:00
global $config , $board ;
2013-07-18 18:06:26 +02:00
openBoard ( $board_name );
2013-07-18 17:30:00 +02:00
$recent_images = array ();
$recent_posts = array ();
$stats = array ();
2014-04-30 00:13:04 +02:00
$query = query ( sprintf ( " SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `filehash` IS NOT NULL) AS `image_count`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `last_reply`, (SELECT `name` FROM ``posts_%s`` WHERE `thread` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `last_reply_name`, (SELECT `subject` FROM ``posts_%s`` WHERE `thread` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `last_reply_subject`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC " , $board_name , $board_name , $board_name , $board_name , $board_name , $board_name , $board_name )) or error ( db_error ());
2013-07-18 17:30:00 +02:00
2013-08-01 02:51:43 +02:00
while ( $post = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-07-18 17:30:00 +02:00
$post [ 'link' ] = $config [ 'root' ] . $board [ 'dir' ] . $config [ 'dir' ][ 'res' ] . sprintf ( $config [ 'file_page' ], ( $post [ 'thread' ] ? $post [ 'thread' ] : $post [ 'id' ]));
$post [ 'board_name' ] = $board [ 'name' ];
2014-05-04 01:20:12 +02:00
if ( $post [ 'embed' ] && preg_match ( '/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i' , $post [ 'embed' ], $matches )) {
$post [ 'youtube' ] = $matches [ 2 ];
}
2014-04-27 15:48:47 +02:00
if ( isset ( $post [ 'files' ]))
$files = json_decode ( $post [ 'files' ]);
2014-05-14 19:53:59 +02:00
if ( isset ( $files )) {
if ( $files [ 0 ] -> file == 'deleted' ) continue ;
$post [ 'file' ] = $config [ 'uri_thumb' ] . $files [ 0 ] -> thumb ;
}
2014-04-30 00:13:04 +02:00
if ( $settings [ 'use_tooltipster' ]) {
$post [ 'muhdifference' ] = ago ( time () - $post [ 'time' ]);
if ( $post [ 'last_reply' ])
$post [ 'last_reply_difference' ] = ago ( time () - $post [ 'last_reply' ]);
}
2013-07-18 17:30:00 +02:00
$recent_posts [] = $post ;
}
2013-07-18 18:06:26 +02:00
file_write ( $config [ 'dir' ][ 'home' ] . $board_name . '/catalog.html' , Element ( 'themes/catalog/catalog.html' , Array (
2013-07-18 17:30:00 +02:00
'settings' => $settings ,
'config' => $config ,
'boardlist' => createBoardlist (),
'recent_images' => $recent_images ,
'recent_posts' => $recent_posts ,
'stats' => $stats ,
'board' => $board_name ,
'link' => $config [ 'root' ] . $board [ 'dir' ]
2013-07-18 18:06:26 +02:00
)));
2013-07-18 17:30:00 +02:00
}
};