forked from leftypol/leftypol
Add catalog thumbnails for file placeholder, handle the first of multiple OP images being deleted
Thank you based lewdposter
This commit is contained in:
parent
99493b054d
commit
b227982390
1 changed files with 46 additions and 29 deletions
|
@ -68,7 +68,7 @@
|
||||||
{
|
{
|
||||||
$b->buildUkko();
|
$b->buildUkko();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Check that Ukko2 is actually enabled
|
// FIXME: Check that Ukko2 is actually enabled
|
||||||
if ($settings['enable_ukko2'] && (
|
if ($settings['enable_ukko2'] && (
|
||||||
$action === 'all' || $action === 'post' ||
|
$action === 'all' || $action === 'post' ||
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
{
|
{
|
||||||
$b->buildUkko2();
|
$b->buildUkko2();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Check that Ukko3 is actually enabled
|
// FIXME: Check that Ukko3 is actually enabled
|
||||||
if ($settings['enable_ukko3'] && (
|
if ($settings['enable_ukko3'] && (
|
||||||
$action === 'all' || $action === 'post' ||
|
$action === 'all' || $action === 'post' ||
|
||||||
|
@ -185,7 +185,7 @@
|
||||||
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
|
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
|
||||||
$config['root'] . $ukkoSettings['uri']);
|
$config['root'] . $ukkoSettings['uri']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build and save the HTML of the catalog for the Ukko3 theme
|
* Build and save the HTML of the catalog for the Ukko3 theme
|
||||||
*/
|
*/
|
||||||
|
@ -224,7 +224,7 @@
|
||||||
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
|
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
|
||||||
$config['root'] . $ukkoSettings['uri']);
|
$config['root'] . $ukkoSettings['uri']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build and save the HTML of the catalog for the Ukko theme
|
* Build and save the HTML of the catalog for the Ukko theme
|
||||||
*/
|
*/
|
||||||
|
@ -307,11 +307,11 @@
|
||||||
*/
|
*/
|
||||||
public function build($settings, $board_name) {
|
public function build($settings, $board_name) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
if ($board['uri'] != $board_name) {
|
if ($board['uri'] != $board_name) {
|
||||||
if (!openBoard($board_name)) {
|
if (!openBoard($board_name)) {
|
||||||
error(sprintf(_("Board %s doesn't exist"), $board_name));
|
error(sprintf(_("Board %s doesn't exist"), $board_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($board_name, $this->threadsCache)) {
|
if (array_key_exists($board_name, $this->threadsCache)) {
|
||||||
$threads = $this->threadsCache[$board_name];
|
$threads = $this->threadsCache[$board_name];
|
||||||
|
@ -356,7 +356,7 @@
|
||||||
$query = prepare($sql);
|
$query = prepare($sql);
|
||||||
$query->bindValue(':limit', $settings['overboard_limit'], PDO::PARAM_INT);
|
$query->bindValue(':limit', $settings['overboard_limit'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$threads = $query->fetchAll(PDO::FETCH_ASSOC);
|
$threads = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
// Save for posterity
|
// Save for posterity
|
||||||
$this->threadsCache[$board_name] = $threads;
|
$this->threadsCache[$board_name] = $threads;
|
||||||
|
@ -376,7 +376,7 @@
|
||||||
$page = 0;
|
$page = 0;
|
||||||
for ($i = 1; $i <= $totalThreads; $i++) {
|
for ($i = 1; $i <= $totalThreads; $i++) {
|
||||||
$pages[$page][] = new Thread($recent_posts[$i-1]);
|
$pages[$page][] = new Thread($recent_posts[$i-1]);
|
||||||
|
|
||||||
// If we have not yet visited all threads,
|
// If we have not yet visited all threads,
|
||||||
// and we hit the limit on the current page,
|
// and we hit the limit on the current page,
|
||||||
// skip to the next page
|
// skip to the next page
|
||||||
|
@ -385,15 +385,37 @@
|
||||||
$pages[$page] = array();
|
$pages[$page] = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = json_encode($api->translateCatalog($pages));
|
$json = json_encode($api->translateCatalog($pages));
|
||||||
file_write($config['dir']['home'] . $board_name . '/catalog.json', $json);
|
file_write($config['dir']['home'] . $board_name . '/catalog.json', $json);
|
||||||
|
|
||||||
$json = json_encode($api->translateCatalog($pages, true));
|
$json = json_encode($api->translateCatalog($pages, true));
|
||||||
file_write($config['dir']['home'] . $board_name . '/threads.json', $json);
|
file_write($config['dir']['home'] . $board_name . '/threads.json', $json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function filepathForThumb($thumb_or_special, $path_when_file) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if ($thumb_or_special === 'deleted') {
|
||||||
|
return $config['root'] . $config['image_deleted'];
|
||||||
|
} else if ($thumb_or_special === 'spoiler') {
|
||||||
|
return $config['root'] . $config['spoiler_image'];
|
||||||
|
} else if ($thumb_or_special === 'file') {
|
||||||
|
// see twig_extension_filter
|
||||||
|
$ext = mb_strtolower(mb_substr($path_when_file, mb_strrpos($path_when_file, '.') + 1));
|
||||||
|
$icons = $config['file_icons'];
|
||||||
|
// see templates/post/image.html
|
||||||
|
if (isset($icons[$ext])) {
|
||||||
|
return $config['root'] . sprintf($config['file_thumb'], $icons[$ext]);
|
||||||
|
} else {
|
||||||
|
return $config['root'] . sprintf($config['file_thumb'], $icons['default']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $config['uri_thumb'] . $thumb_or_special;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function generateRecentPosts($threads) {
|
private function generateRecentPosts($threads) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
|
|
||||||
|
@ -413,28 +435,23 @@
|
||||||
if (isset($post['files']) && $post['files']) {
|
if (isset($post['files']) && $post['files']) {
|
||||||
$files = json_decode($post['files']);
|
$files = json_decode($post['files']);
|
||||||
|
|
||||||
if ($files[0]) {
|
if (isset($files[0]) && $files[0]) {
|
||||||
if ($files[0]->file == 'deleted') {
|
$foundone = false;
|
||||||
if (count($files) > 1) {
|
foreach ($files as $file) {
|
||||||
foreach ($files as $file) {
|
if ($file->file != 'deleted') {
|
||||||
if (($file == $files[0]) || ($file->file == 'deleted'))
|
$post['file'] = $this->filepathForThumb($file->thumb, $file->file);
|
||||||
continue;
|
$foundone = true;
|
||||||
$post['file'] = $config['uri_thumb'] . $file->thumb;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($post['file']))
|
|
||||||
$post['file'] = $config['root'] . $config['image_deleted'];
|
|
||||||
} else {
|
|
||||||
$post['file'] = $config['root'] . $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;
|
|
||||||
}
|
}
|
||||||
|
if (!$foundone) {
|
||||||
|
$post['file'] = $this->filepathForThumb('deleted', null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$post['file'] = $this->filepathForThumb('deleted', null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$post['file'] = $config['root'] . $config['image_deleted'];
|
$post['file'] = $this->filepathForThumb('deleted', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($post['images']))
|
if (empty($post['images']))
|
||||||
|
@ -493,6 +510,6 @@
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'recent_posts' => $recent_posts,
|
'recent_posts' => $recent_posts,
|
||||||
'board' => $board
|
'board' => $board
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue