From 9fa812b35dd23299798ee437ea9bcb84f369714b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 19 Feb 2019 01:56:41 +0100 Subject: [PATCH] Rewrites: - converted single-line if() block to multi-line and with curly braces - "imported" SPL classes to have unified code style - always initialize your variables ... :-/ - added some empty lines/spaces for better readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/api.php | 12 ++++++++---- index.php | 1 + mod/admin.php | 2 +- src/Model/ItemDeliveryData.php | 7 ++++--- src/Model/Photo.php | 5 +++++ src/Model/Storage/Database.php | 14 ++++++++++---- src/Model/Storage/SystemResource.php | 6 ++++-- src/Worker/Notifier.php | 1 - 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/api.php b/include/api.php index 13ff75bdb5..e6fd2f22ba 100644 --- a/include/api.php +++ b/include/api.php @@ -1528,8 +1528,10 @@ function api_search($type) if (api_user() === false || $user_info === false) { throw new ForbiddenException(); } - if (empty($_REQUEST['q'])) { throw new BadRequestException('q parameter is required.'); } - + if (empty($_REQUEST['q'])) { + throw new BadRequestException('q parameter is required.'); + } + $searchTerm = trim(rawurldecode($_REQUEST['q'])); $data = []; @@ -4399,6 +4401,7 @@ function api_fr_photo_delete($type) if (api_user() === false) { throw new ForbiddenException(); } + // input params $photo_id = defaults($_REQUEST, 'photo_id', null); @@ -4407,11 +4410,12 @@ function api_fr_photo_delete($type) if ($photo_id == null) { throw new BadRequestException("no photo_id specified"); } + // check if photo is existing in database - $r = Photo::exists(['resource-id' => $photo_id, 'uid' => api_user()]); - if (!$r) { + if (!Photo::exists(['resource-id' => $photo_id, 'uid' => api_user()])) { throw new BadRequestException("photo not available"); } + // now we can perform on the deletion of the photo $result = Photo::delete(['uid' => api_user(), 'resource-id' => $photo_id]); diff --git a/index.php b/index.php index e989872893..ddc851cd4e 100644 --- a/index.php +++ b/index.php @@ -15,3 +15,4 @@ require __DIR__ . '/vendor/autoload.php'; $a = Factory\DependencyFactory::setUp('index', __DIR__, false); $a->runFrontend(); + diff --git a/mod/admin.php b/mod/admin.php index fcca69644e..9486f85c98 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1565,7 +1565,7 @@ function admin_page_site(App $a) $storage_form = []; if (!is_null($storage_current_backend) && $storage_current_backend != "") { - foreach($storage_current_backend::getOptions() as $name => $info) { + foreach ($storage_current_backend::getOptions() as $name => $info) { $type = $info[0]; $info[0] = $storage_form_prefix . '_' . $name; $info['type'] = $type; diff --git a/src/Model/ItemDeliveryData.php b/src/Model/ItemDeliveryData.php index 1cd9c4f448..b1fd28e3cb 100644 --- a/src/Model/ItemDeliveryData.php +++ b/src/Model/ItemDeliveryData.php @@ -7,6 +7,7 @@ namespace Friendica\Model; use Friendica\Database\DBA; +use \BadMethodCallException; class ItemDeliveryData { @@ -71,7 +72,7 @@ class ItemDeliveryData public static function insert($item_id, array $fields) { if (empty($item_id)) { - throw new \BadMethodCallException('Empty item_id'); + throw new BadMethodCallException('Empty item_id'); } $fields['iid'] = $item_id; @@ -92,7 +93,7 @@ class ItemDeliveryData public static function update($item_id, array $fields) { if (empty($item_id)) { - throw new \BadMethodCallException('Empty item_id'); + throw new BadMethodCallException('Empty item_id'); } if (empty($fields)) { @@ -113,7 +114,7 @@ class ItemDeliveryData public static function delete($item_id) { if (empty($item_id)) { - throw new \BadMethodCallException('Empty item_id'); + throw new BadMethodCallException('Empty item_id'); } return DBA::delete('item-delivery-data', ['iid' => $item_id]); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 0778bf4196..152e870e85 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -173,6 +173,8 @@ class Photo extends BaseObject */ public static function getImageForPhoto(array $photo) { + $data = ""; + if ($photo["backend-class"] == "") { // legacy data storage in "data" column $i = self::selectFirst(["data"], ["id" => $photo["id"]]); @@ -189,6 +191,7 @@ class Photo extends BaseObject if ($data === "") { return null; } + return new Image($data, $photo["type"]); } @@ -219,11 +222,13 @@ class Photo extends BaseObject { $fields = self::getFields(); $values = array_fill(0, count($fields), ""); + $photo = array_combine($fields, $values); $photo["backend-class"] = Storage\SystemResource::class; $photo["backend-ref"] = $filename; $photo["type"] = $mimetype; $photo["cacheable"] = false; + return $photo; } diff --git a/src/Model/Storage/Database.php b/src/Model/Storage/Database.php index f9ad7fb7d4..60bd154e6a 100644 --- a/src/Model/Storage/Database.php +++ b/src/Model/Storage/Database.php @@ -50,8 +50,14 @@ class Database implements IStorage { return DBA::delete('storage', ['id' => $ref]); } - - public static function getOptions() { return []; } - - public static function saveOptions($data) { return []; } + + public static function getOptions() + { + return []; + } + + public static function saveOptions($data) + { + return []; + } } diff --git a/src/Model/Storage/SystemResource.php b/src/Model/Storage/SystemResource.php index 718a2e90af..3afe8ee6f5 100644 --- a/src/Model/Storage/SystemResource.php +++ b/src/Model/Storage/SystemResource.php @@ -6,6 +6,8 @@ namespace Friendica\Model\Storage; +use \BadMethodCallException; + /** * @brief System resource storage class * @@ -32,12 +34,12 @@ class SystemResource implements IStorage public static function put($data, $filename = "") { - throw new \BadMethodCallException(); + throw new BadMethodCallException(); } public static function delete($filename) { - throw new \BadMethodCallException(); + throw new BadMethodCallException(); } public static function getOptions() diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 4492e3ce92..57c25a68fa 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -498,7 +498,6 @@ class Notifier } DBA::close($delivery_contacts_stmt); - $url_recipients = array_filter($url_recipients); // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts // They are especially used for notifications to OStatus users that don't follow us.