2013-07-18 11:30:00 -04:00
|
|
|
<?php
|
|
|
|
require 'info.php';
|
|
|
|
|
2013-07-18 12:06:26 -04:00
|
|
|
function catalog_build($action, $settings, $board) {
|
|
|
|
global $config;
|
|
|
|
|
2013-07-18 11:30:00 -04:00
|
|
|
// Possible values for $action:
|
|
|
|
// - all (rebuild everything, initialization)
|
|
|
|
// - news (news has been updated)
|
|
|
|
// - boards (board list changed)
|
2013-07-18 12:06:26 -04:00
|
|
|
// - post (a reply has been made)
|
|
|
|
// - post-thread (a thread has been made)
|
2013-07-18 11:30:00 -04:00
|
|
|
|
2013-07-18 12:06:26 -04:00
|
|
|
$boards = explode(' ', $settings['boards']);
|
|
|
|
|
|
|
|
if ($action == 'all') {
|
2013-07-18 11:30:00 -04:00
|
|
|
foreach ($boards as $board) {
|
2013-07-18 12:06:26 -04:00
|
|
|
$b = new Catalog();
|
|
|
|
$b->build($settings, $board);
|
2013-07-18 11:30:00 -04:00
|
|
|
}
|
2013-08-25 23:26:41 -04:00
|
|
|
} elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') && in_array($board, $boards)) {
|
2013-07-18 12:06:26 -04:00
|
|
|
$b = new Catalog();
|
|
|
|
$b->build($settings, $board);
|
2013-07-18 11:30:00 -04:00
|
|
|
}
|
2013-07-18 12:06:26 -04: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 11:30:00 -04:00
|
|
|
global $config, $board;
|
|
|
|
|
2013-07-18 12:06:26 -04:00
|
|
|
openBoard($board_name);
|
|
|
|
|
2013-07-18 11:30:00 -04:00
|
|
|
$recent_images = array();
|
|
|
|
$recent_posts = array();
|
|
|
|
$stats = array();
|
|
|
|
|
2014-08-08 16:36:36 -04:00
|
|
|
$query = query(sprintf("SELECT *, `id` AS `thread_id`,
|
2014-08-08 16:48:38 -04:00
|
|
|
(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,
|
2014-08-08 16:36:36 -04:00
|
|
|
(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,
|
|
|
|
'%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC",
|
|
|
|
$board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());
|
2013-07-18 11:30:00 -04:00
|
|
|
|
2013-07-31 20:51:43 -04:00
|
|
|
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
2013-07-18 11:30:00 -04: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-03 19:20:12 -04: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-08-08 16:48:38 -04:00
|
|
|
if (isset($post['files'])) {
|
2014-04-27 09:48:47 -04:00
|
|
|
$files = json_decode($post['files']);
|
2014-09-16 16:10:54 -04:00
|
|
|
|
|
|
|
if ($files[0]->file == 'deleted') {
|
|
|
|
if (count($files) > 1) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (($file == $files[0]) || ($file->file == 'deleted')) continue;
|
|
|
|
$post['file'] = $config['uri_thumb'] . $file->thumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($post['file'])) $post['file'] = $config['image_deleted'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$post['file'] = $config['image_deleted'];
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 19:15:18 -04:00
|
|
|
else if($files[0]->thumb == 'spoiler') {
|
|
|
|
$post['file'] = '/' . $config['spoiler_image'];
|
|
|
|
}
|
2014-09-16 16:10:54 -04:00
|
|
|
else {
|
2014-04-27 09:48:47 -04:00
|
|
|
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
|
2014-08-08 16:48:38 -04:00
|
|
|
}
|
2014-09-16 16:10:54 -04:00
|
|
|
}
|
2014-04-29 18:13:04 -04:00
|
|
|
|
2014-09-16 16:10:54 -04:00
|
|
|
if (empty($post['image_count'])) $post['image_count'] = 0;
|
2013-07-18 11:30:00 -04:00
|
|
|
$recent_posts[] = $post;
|
|
|
|
}
|
|
|
|
|
2015-03-27 17:37:42 -04:00
|
|
|
$required_scripts = array('js/jquery.min.js', 'js/catalog.js');
|
2014-06-12 13:26:21 -04:00
|
|
|
|
|
|
|
foreach($required_scripts as $i => $s) {
|
|
|
|
if (!in_array($s, $config['additional_javascript']))
|
|
|
|
$config['additional_javascript'][] = $s;
|
|
|
|
}
|
|
|
|
|
2013-07-18 12:06:26 -04:00
|
|
|
file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', Array(
|
2013-07-18 11:30:00 -04: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 12:06:26 -04:00
|
|
|
)));
|
2013-07-18 11:30:00 -04:00
|
|
|
}
|
|
|
|
};
|