Browse Source

Modify api image fields

pull/40/head
Pietro Carrara 3 years ago
parent
commit
2252634892
  1. 44
      inc/api.php

44
inc/api.php

@ -45,8 +45,10 @@ class Api {
); );
$this->fileFields = array( $this->fileFields = array(
'thumbheight' => 'tn_h', 'file_id' => 'id',
'thumbwidth' => 'tn_w', 'file_path' => 'file_path',
'type' => 'mime',
'extension' => 'ext',
'height' => 'h', 'height' => 'h',
'width' => 'w', 'width' => 'w',
'size' => 'fsize', 'size' => 'fsize',
@ -90,13 +92,12 @@ class Api {
} }
private function translateFile($file, $post, &$apiPost) { private function translateFile($file, $post, &$apiPost) {
global $config;
$this->translateFields($this->fileFields, $file, $apiPost); $this->translateFields($this->fileFields, $file, $apiPost);
$apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.')); $apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.'));
$dotPos = strrpos($file->file, '.');
$apiPost['ext'] = substr($file->file, $dotPos);
$apiPost['tim'] = substr($file->file, 0, $dotPos);
if (isset ($file->thumb) && $file->thumb) { if (isset ($file->thumb) && $file->thumb) {
$apiPost['spoiler'] = $file->thumb === 'spoiler' ? 1 : 0; $apiPost['spoiler'] = $file->thumb === 'spoiler';
} }
if (isset ($file->hash) && $file->hash) { if (isset ($file->hash) && $file->hash) {
$apiPost['md5'] = base64_encode(hex2bin($file->hash)); $apiPost['md5'] = base64_encode(hex2bin($file->hash));
@ -104,6 +105,19 @@ class Api {
else if (isset ($post->filehash) && $post->filehash) { else if (isset ($post->filehash) && $post->filehash) {
$apiPost['md5'] = base64_encode(hex2bin($post->filehash)); $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
} }
// Pick the correct thumbnail
if ($file->thumb_path === 'file') {
$ext = $file->extension;
$thumbFile = $config['file_icons']['default'];
if (isset($config['file_icons'][$ext])) {
$thumbFile = $config['file_icons'][$ext];
}
$apiPost['thumb_path'] = sprintf($config['file_thumb'], $thumbFile);
} else {
$apiPost['thumb_path'] = $file->thumb_path;
}
} }
private function translatePost($post, $threadsPage = false) { private function translatePost($post, $threadsPage = false) {
@ -138,21 +152,13 @@ class Api {
} }
// Handle files // Handle files
// Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API.
if (isset($post->files) && $post->files && !$threadsPage) { if (isset($post->files) && $post->files && !$threadsPage) {
$file = $post->files[0]; $apiPost['files'] = [];
$this->translateFile($file, $post, $apiPost); foreach ($post->files as $f) {
if (sizeof($post->files) > 1) { $file = array();
$extra_files = array(); $this->translateFile($f, $post, $file);
foreach ($post->files as $i => $f) {
if ($i == 0) continue;
$extra_file = array(); $apiPost['files'][] = $file;
$this->translateFile($f, $post, $extra_file);
$extra_files[] = $extra_file;
}
$apiPost['extra_files'] = $extra_files;
} }
} }

Loading…
Cancel
Save