summaryrefslogtreecommitdiff
path: root/inc/api.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/api.php')
-rw-r--r--inc/api.php49
1 files changed, 30 insertions, 19 deletions
diff --git a/inc/api.php b/inc/api.php
index 3337c613..a8ae9eed 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -26,12 +26,6 @@ class Api {
'trip' => 'trip',
'capcode' => 'capcode',
'time' => 'time',
- 'thumbheight' => 'tn_w',
- 'thumbwidth' => 'tn_h',
- 'fileheight' => 'w',
- 'filewidth' => 'h',
- 'filesize' => 'fsize',
- 'filename' => 'filename',
'omitted' => 'omitted_posts',
'omitted_images' => 'omitted_images',
'replies' => 'replies',
@@ -46,6 +40,15 @@ class Api {
'bump' => 'last_modified'
);
+ $this->fileFields = array(
+ 'thumbheight' => 'tn_w',
+ 'thumbwidth' => 'tn_h',
+ 'height' => 'w',
+ 'width' => 'h',
+ 'size' => 'fsize',
+ 'file' => 'filename',
+ );
+
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
}
@@ -67,30 +70,26 @@ class Api {
'last_modified' => 1
);
- private function translatePost($post, $threadsPage = false) {
- $apiPost = array();
- $fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
+ private function translateFields($fields, $object, &$apiPost) {
foreach ($fields as $local => $translated) {
- if (!isset($post->$local))
+ if (!isset($object->$local))
continue;
$toInt = isset(self::$ints[$translated]);
- $val = $post->$local;
+ $val = $object->$local;
if ($val !== null && $val !== '') {
$apiPost[$translated] = $toInt ? (int) $val : $val;
}
}
+ }
- if ($threadsPage) return $apiPost;
+ private function translatePost($post, $threadsPage = false) {
+ $apiPost = array();
+ $fields = $threadsPage ? $this->threadsPageFields : $this->postFields;
+ $this->translateFields($fields, $post, $apiPost);
- if (isset($post->filename)) {
- $dotPos = strrpos($post->filename, '.');
- $apiPost['filename'] = substr($post->filename, 0, $dotPos);
- $apiPost['ext'] = substr($post->filename, $dotPos);
- $dotPos = strrpos($post->file, '.');
- $apiPost['tim'] = substr($post->file, 0, $dotPos);
- }
+ if ($threadsPage) return $apiPost;
// Handle country field
if (isset($post->body_nomarkup) && $this->config['country_flags']) {
@@ -104,6 +103,18 @@ 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->translateFields($this->fileFields, $file, $apiPost);
+ $dotPos = strrpos($file->file, '.');
+ $apiPost['filename'] = substr($file->file, 0, $dotPos);
+ $apiPost['ext'] = substr($file->file, $dotPos);
+ $dotPos = strrpos($file->file, '.');
+ $apiPost['tim'] = substr($file->file, 0, $dotPos);
+ }
+
return $apiPost;
}