summaryrefslogtreecommitdiff
path: root/inc/api.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2016-02-09 12:37:03 +0100
committerczaks <marcin@6irc.net>2016-02-09 12:37:03 +0100
commitc53f13bf90716461780fef0a2b4b6e2b5b3cb002 (patch)
tree5cd18f303da0b0e6fdc87f175adf5f5f86d881e2 /inc/api.php
parentfe66c51a19920378885fb790d341cc50c933b046 (diff)
parent028fd3df15b2e2edc96c5b84156b0b039ea16562 (diff)
Merge branch 'master' of https://github.com/vichan-devel/vichan
Diffstat (limited to 'inc/api.php')
-rw-r--r--inc/api.php35
1 files changed, 29 insertions, 6 deletions
diff --git a/inc/api.php b/inc/api.php
index c9608f06..57e4d367 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -33,6 +33,7 @@ class Api {
'sticky' => 'sticky',
'locked' => 'locked',
'bump' => 'last_modified',
+ 'embed' => 'embed',
);
$this->threadsPageFields = array(
@@ -85,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']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']);
if ($threadsPage) return $apiPost;
// Handle country field
@@ -104,16 +116,27 @@ class Api {
}
}
+ if ($config['slugify'] && !$post->thread) {
+ $apiPost['semantic_url'] = $post->slug;
+ }
+
// 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);
- $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));
+ $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;