summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author8chan <admin@8chan.co>2014-10-30 05:33:01 -0700
committerczaks <marcin@6irc.net>2015-03-31 05:28:08 +0200
commit4a22ee9245b81e9a94bcc18128cf9ad10d19d901 (patch)
treef5120b00407c1c21598495fbbd25771ec4d6af60
parent300e9e7e71bb9a3e095dca425e944e2fbf6e5117 (diff)
Extra files and IDs in API
Conflicts: inc/api.php
-rw-r--r--inc/api.php30
1 files changed, 24 insertions, 6 deletions
diff --git a/inc/api.php b/inc/api.php
index ac3b1325..eb99d3fb 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -86,11 +86,22 @@ class Api {
}
}
+ private function translateFile($file, $post, &$apiPost) {
+ $this->translateFields($this->fileFields, $file, $apiPost);
+ $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);
+ $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ }
+
private function translatePost($post, $threadsPage = false) {
+ global $config, $board;
$apiPost = array();
$fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
$this->translateFields($fields, $post, $apiPost);
+ if (isset($config['poster_ids'])) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
if ($threadsPage) return $apiPost;
// Handle country field
@@ -109,12 +120,19 @@ class Api {
// 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->translateFields($this->fileFields, $file, $apiPost);
- $apiPost['filename'] = isset($file->name) ? substr($file->name, 0, strrpos($file->name, '.')) : "";
- $dotPos = strrpos($file->file, '.');
- $apiPost['ext'] = substr($file->file, $dotPos);
- $apiPost['tim'] = substr($file->file, 0, $dotPos);
- $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ $this->translateFile($file, $post, $apiPost);
+ if (sizeof($post->files) > 1) {
+ $extra_files = array();
+ foreach ($post->files as $i => $f) {
+ if ($i == 0) continue;
+
+ $extra_file = array();
+ $this->translateFile($f, $post, $extra_file);
+
+ $extra_files[] = $extra_file;
+ }
+ $apiPost['extra_files'] = $extra_files;
+ }
}
return $apiPost;