summaryrefslogtreecommitdiff
path: root/inc/api.php
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:30:13 +1000
commit2c69095a1edf7474073451285238659d0f62ce3f (patch)
tree5dee476605402c66dc2853d0836b29f6aedae62b /inc/api.php
parente9a61e2fbbd930eaa80d6a5f33420cedc59d748c (diff)
PHP8.1 fixes from Rector
Diffstat (limited to 'inc/api.php')
-rw-r--r--inc/api.php84
1 files changed, 20 insertions, 64 deletions
diff --git a/inc/api.php b/inc/api.php
index b280c25b..e9601c6e 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -16,62 +16,18 @@ class Api {
*/
$this->config = $config;
- $this->postFields = array(
- 'id' => 'no',
- 'thread' => 'resto',
- 'subject' => 'sub',
- 'body' => 'com',
- 'email' => 'email',
- 'name' => 'name',
- 'trip' => 'trip',
- 'capcode' => 'capcode',
- 'time' => 'time',
- 'omitted' => 'omitted_posts',
- 'omitted_images' => 'omitted_images',
- 'replies' => 'replies',
- 'images' => 'images',
- 'sticky' => 'sticky',
- 'locked' => 'locked',
- 'cycle' => 'cyclical',
- 'bump' => 'last_modified',
- 'embed' => 'embed',
- );
+ $this->postFields = ['id' => 'no', 'thread' => 'resto', 'subject' => 'sub', 'body' => 'com', 'email' => 'email', 'name' => 'name', 'trip' => 'trip', 'capcode' => 'capcode', 'time' => 'time', 'omitted' => 'omitted_posts', 'omitted_images' => 'omitted_images', 'replies' => 'replies', 'images' => 'images', 'sticky' => 'sticky', 'locked' => 'locked', 'cycle' => 'cyclical', 'bump' => 'last_modified', 'embed' => 'embed'];
- $this->threadsPageFields = array(
- 'id' => 'no',
- 'bump' => 'last_modified'
- );
+ $this->threadsPageFields = ['id' => 'no', 'bump' => 'last_modified'];
- $this->fileFields = array(
- 'thumbheight' => 'tn_h',
- 'thumbwidth' => 'tn_w',
- 'height' => 'h',
- 'width' => 'w',
- 'size' => 'fsize',
- );
+ $this->fileFields = ['thumbheight' => 'tn_h', 'thumbwidth' => 'tn_w', 'height' => 'h', 'width' => 'w', 'size' => 'fsize'];
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
}
}
- private static $ints = array(
- 'no' => 1,
- 'resto' => 1,
- 'time' => 1,
- 'tn_w' => 1,
- 'tn_h' => 1,
- 'w' => 1,
- 'h' => 1,
- 'fsize' => 1,
- 'omitted_posts' => 1,
- 'omitted_images' => 1,
- 'replies' => 1,
- 'images' => 1,
- 'sticky' => 1,
- 'locked' => 1,
- 'last_modified' => 1
- );
+ private static array $ints = ['no' => 1, 'resto' => 1, 'time' => 1, 'tn_w' => 1, 'tn_h' => 1, 'w' => 1, 'h' => 1, 'fsize' => 1, 'omitted_posts' => 1, 'omitted_images' => 1, 'replies' => 1, 'images' => 1, 'sticky' => 1, 'locked' => 1, 'last_modified' => 1];
private function translateFields($fields, $object, &$apiPost) {
foreach ($fields as $local => $translated) {
@@ -89,32 +45,32 @@ 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['filename'] = @substr((string) $file->name, 0, strrpos((string) $file->name, '.'));
+ $dotPos = strrpos((string) $file->file, '.');
+ $apiPost['ext'] = substr((string) $file->file, $dotPos);
+ $apiPost['tim'] = substr((string) $file->file, 0, $dotPos);
if (isset ($file->hash) && $file->hash) {
- $apiPost['md5'] = base64_encode(hex2bin($file->hash));
+ $apiPost['md5'] = base64_encode(hex2bin((string) $file->hash));
}
else if (isset ($post->filehash) && $post->filehash) {
- $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ $apiPost['md5'] = base64_encode(hex2bin((string) $post->filehash));
}
}
private function translatePost($post, $threadsPage = false) {
global $config, $board;
- $apiPost = array();
+ $apiPost = [];
$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 (isset($config['poster_ids']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread);
if ($threadsPage) return $apiPost;
// Handle country field
if (isset($post->body_nomarkup) && $this->config['country_flags']) {
$modifiers = extract_modifiers($post->body_nomarkup);
- if (isset($modifiers['flag']) && isset($modifiers['flag alt']) && preg_match('/^[a-z]{2}$/', $modifiers['flag'])) {
- $country = strtoupper($modifiers['flag']);
+ if (isset($modifiers['flag']) && isset($modifiers['flag alt']) && preg_match('/^[a-z]{2}$/', (string) $modifiers['flag'])) {
+ $country = strtoupper((string) $modifiers['flag']);
if ($country) {
$apiPost['country'] = $country;
$apiPost['country_name'] = $modifiers['flag alt'];
@@ -132,11 +88,11 @@ class Api {
$file = $post->files[0];
$this->translateFile($file, $post, $apiPost);
if (sizeof($post->files) > 1) {
- $extra_files = array();
+ $extra_files = [];
foreach ($post->files as $i => $f) {
if ($i == 0) continue;
- $extra_file = array();
+ $extra_file = [];
$this->translateFile($f, $post, $extra_file);
$extra_files[] = $extra_file;
@@ -149,7 +105,7 @@ class Api {
}
function translateThread(Thread $thread, $threadsPage = false) {
- $apiPosts = array();
+ $apiPosts = [];
$op = $this->translatePost($thread, $threadsPage);
if (!$threadsPage) $op['resto'] = 0;
$apiPosts['posts'][] = $op;
@@ -162,7 +118,7 @@ class Api {
}
function translatePage(array $threads) {
- $apiPage = array();
+ $apiPage = [];
foreach ($threads as $thread) {
$apiPage['threads'][] = $this->translateThread($thread);
}
@@ -170,7 +126,7 @@ class Api {
}
function translateCatalogPage(array $threads, $threadsPage = false) {
- $apiPage = array();
+ $apiPage = [];
foreach ($threads as $thread) {
$ts = $this->translateThread($thread, $threadsPage);
$apiPage['threads'][] = current($ts['posts']);
@@ -179,7 +135,7 @@ class Api {
}
function translateCatalog($catalog, $threadsPage = false) {
- $apiCatalog = array();
+ $apiCatalog = [];
foreach ($catalog as $page => $threads) {
$apiPage = $this->translateCatalogPage($threads, $threadsPage);
$apiPage['page'] = $page;