diff options
author | Daniel Lange <DLange@git.local> | 2023-01-11 16:05:06 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2023-01-11 16:05:06 +0100 |
commit | 6d21b208b9cfae0941bebf59b39ee04f6002b4f9 (patch) | |
tree | 43fd71c7464eaecba172810d000dc2e426bd8d94 | |
parent | 39154d99acf0359638be5d5efd51e44f5b803e4b (diff) | |
download | stikked-fit-6d21b208b9cfae0941bebf59b39ee04f6002b4f9.tar.gz stikked-fit-6d21b208b9cfae0941bebf59b39ee04f6002b4f9.tar.bz2 stikked-fit-6d21b208b9cfae0941bebf59b39ee04f6002b4f9.zip |
Fix the API in case of empty arrays and fix the /langs endpoint
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | htdocs/application/controllers/Api.php | 6 |
2 files changed, 5 insertions, 2 deletions
@@ -90,6 +90,7 @@ Copy your htdocs/application/stikked.php config file away. Upload the new versio ### Version 0.15.0-fit: +* Fix some issues in the API [Daniel Lange/FIT] * Make replying more robust in case of expired pastes [Daniel Lange/FIT] * Fix the bootstrap theme [Daniel Lange/FIT] * Fix captcha_helper for PHP 8.0+ compliance [Daniel Lange/FIT] diff --git a/htdocs/application/controllers/Api.php b/htdocs/application/controllers/Api.php index 74aac22..948ed24 100644 --- a/htdocs/application/controllers/Api.php +++ b/htdocs/application/controllers/Api.php @@ -132,7 +132,7 @@ class Api extends Main } $this->load->model('pastes'); $pastes = $this->pastes->getLists('api/recent'); - $pastes = $pastes['pastes']; + $pastes = $pastes['pastes'] ?? []; $data = array(); foreach ($pastes as $paste) { $data[] = array( @@ -158,7 +158,7 @@ class Api extends Main } $this->load->model('pastes'); $pastes = $this->pastes->getTrends('api/trending', 2); - $pastes = $pastes['pastes']; + $pastes = $pastes['pastes'] ?? []; $data = array(); foreach ($pastes as $paste) { $data[] = array( @@ -180,6 +180,8 @@ class Api extends Main } $languages = $this->languages->get_languages(); + // remove the 0 --- divider between favorite languages and the rest + unset($languages["0"]); echo json_encode($languages); } } |