|
|
@ -43,8 +43,10 @@ class Api { |
|
|
|
); |
|
|
|
|
|
|
|
$this->fileFields = array( |
|
|
|
'thumbheight' => 'tn_h', |
|
|
|
'thumbwidth' => 'tn_w', |
|
|
|
'file_id' => 'id', |
|
|
|
'file_path' => 'file_path', |
|
|
|
'type' => 'mime', |
|
|
|
'extension' => 'ext', |
|
|
|
'height' => 'h', |
|
|
|
'width' => 'w', |
|
|
|
'size' => 'fsize', |
|
|
@ -88,6 +90,8 @@ class Api { |
|
|
|
} |
|
|
|
|
|
|
|
private function translateFile($file, $post, &$apiPost) { |
|
|
|
global $config; |
|
|
|
|
|
|
|
$this->translateFields($this->fileFields, $file, $apiPost); |
|
|
|
$apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.')); |
|
|
|
$dotPos = strrpos($file->file, '.'); |
|
|
@ -105,6 +109,19 @@ class Api { |
|
|
|
else if (isset ($post->filehash) && $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) { |
|
|
@ -139,21 +156,13 @@ class Api { |
|
|
|
} |
|
|
|
|
|
|
|
// 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) { |
|
|
|
$file = $post->files[0]; |
|
|
|
$this->translateFile($file, $post, $apiPost); |
|
|
|
if (sizeof($post->files) > 1) { |
|
|
|
$extra_files = array(); |
|
|
|
foreach ($post->files as $i => $f) { |
|
|
|
if ($i == 0) continue; |
|
|
|
$apiPost['files'] = []; |
|
|
|
foreach ($post->files as $f) { |
|
|
|
$file = array(); |
|
|
|
$this->translateFile($f, $post, $file); |
|
|
|
|
|
|
|
$extra_file = array(); |
|
|
|
$this->translateFile($f, $post, $extra_file); |
|
|
|
|
|
|
|
$extra_files[] = $extra_file; |
|
|
|
} |
|
|
|
$apiPost['extra_files'] = $extra_files; |
|
|
|
$apiPost['files'][] = $file; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|