1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-25 13:54:51 +01:00
vichan/templates/themes/catalog/theme.php

143 lines
4.7 KiB
PHP
Raw Normal View History

2013-07-18 17:30:00 +02:00
<?php
require 'info.php';
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)
// - post (a reply has been made)
// - post-thread (a thread has been made)
$boards = explode(' ', $settings['boards']);
if ($action == 'all') {
2013-07-18 17:30:00 +02:00
foreach ($boards as $board) {
$b = new Catalog();
$action = generation_strategy("sb_catalog", array($board));
if ($action == 'delete') {
2015-04-02 20:54:28 +02:00
file_unlink($config['dir']['home'] . $board . '/catalog.html');
file_unlink($config['dir']['home'] . $board . '/index.rss');
2015-04-02 20:54:28 +02:00
}
elseif ($action == 'rebuild') {
2015-04-02 20:54:28 +02:00
$b->build($settings, $board);
}
2013-07-18 17:30:00 +02:00
}
} elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') && in_array($board, $boards)) {
$b = new Catalog();
2015-04-02 20:54:28 +02:00
$action = generation_strategy("sb_catalog", array($board));
if ($action == 'delete') {
2015-04-02 20:54:28 +02:00
file_unlink($config['dir']['home'] . $board . '/catalog.html');
file_unlink($config['dir']['home'] . $board . '/index.rss');
2015-04-02 20:54:28 +02:00
}
elseif ($action == 'rebuild') {
2015-04-02 20:54:28 +02:00
$b->build($settings, $board);
}
2013-07-18 17:30:00 +02:00
}
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Catalog {
2022-06-20 20:09:55 +02:00
public function build($settings, $board_name, $mod = false) {
2013-07-18 17:30:00 +02:00
global $config, $board;
2015-04-02 20:54:28 +02:00
if (!isset($board) || $board['uri'] != $board_name) {
2015-04-02 20:54:28 +02:00
if (!openBoard($board_name)) {
error(sprintf(_("Board %s doesn't exist"), $board_name));
}
}
2013-07-18 17:30:00 +02:00
$recent_images = array();
$recent_posts = array();
$stats = array();
$query = query(sprintf("SELECT *, `id` AS `thread_id`,
2014-08-08 22:48:38 +02:00
(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,
(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-08-01 02:51:43 +02:00
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
2022-06-20 20:09:55 +02:00
if ($mod)
$post['link'] = $config['root'] . $config['file_mod'] . '?/'. $board['dir'] . $config['dir']['res'] . link_for($post);
else
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post);
2013-07-18 17:30:00 +02:00
$post['board_name'] = $board['name'];
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];
}
if (isset($post['files']) && $post['files']) {
2014-04-27 15:48:47 +02:00
$files = json_decode($post['files']);
if ($files[0]) {
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'];
}
}
else if($files[0]->thumb == 'spoiler') {
$post['file'] = $config['root'] . $config['spoiler_image'];
}
else {
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
}
}
} else {
$post['file'] = $config['root'] . $config['image_deleted'];
}
if (empty($post['image_count'])) $post['image_count'] = 0;
2015-03-09 10:31:08 +01:00
$post['pubdate'] = date('r', $post['time']);
2013-07-18 17:30:00 +02:00
$recent_posts[] = $post;
}
2014-08-08 22:48:38 +02:00
$required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
2014-06-12 19:26:21 +02:00
foreach($required_scripts as $i => $s) {
if (!in_array($s, $config['additional_javascript']))
$config['additional_javascript'][] = $s;
}
2022-06-20 20:09:55 +02:00
$link = ($mod) ? $config['root'] . $config['file_mod'] . '?/' . $board['dir'] : $config['root'] . $board['dir'];
$element = Element('themes/catalog/catalog.html', Array(
2013-07-18 17:30:00 +02:00
'settings' => $settings,
'config' => $config,
'boardlist' => createBoardlist($mod),
2013-07-18 17:30:00 +02:00
'recent_images' => $recent_images,
'recent_posts' => $recent_posts,
'stats' => $stats,
'board' => $board_name,
2022-06-20 20:09:55 +02:00
'link' => $link,
'mod' => $mod
));
if ($mod) {
return $element;
} else {
file_write($config['dir']['home'] . $board_name . '/catalog.html', $element);
2015-03-09 10:31:08 +01:00
file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', Array(
'config' => $config,
'recent_posts' => $recent_posts,
'board' => $board
)));
}
2022-06-20 20:09:55 +02:00
}
2013-07-18 17:30:00 +02:00
};