X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fwall_upload.php;h=36e313cecef2e4fd5b60bee68ee1eac1c5e0ef5e;hb=89302d0843308c8fa7cc0537cb10943e8defc8ee;hp=38819c9a581768893e913ab2c2d8ad30265e8293;hpb=ad6d11b371f90d925d13b6db523d6233346c8404;p=friendica.git diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 38819c9a58..36e313cece 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -1,6 +1,6 @@ $nick, 'blocked' => false]); if (!DBA::isResult($user)) { if ($r_json) { - echo json_encode(['error' => DI::l10n()->t('Invalid request.')]); - exit(); + System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } return; } } else { - $user_info = api_get_user($a); - $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $user_info['screen_name'], 'blocked' => false]); + $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['uid' => BaseApi::getCurrentUserID(), 'blocked' => false]); } } else { if ($r_json) { - echo json_encode(['error' => DI::l10n()->t('Invalid request.')]); - exit(); + System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } return; } @@ -87,18 +86,17 @@ function wall_upload_post(App $a, $desktopmode = true) if (!$can_post) { if ($r_json) { - echo json_encode(['error' => DI::l10n()->t('Permission denied.')]); - exit(); + System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); } notice(DI::l10n()->t('Permission denied.')); - exit(); + System::exit(); } if (empty($_FILES['userfile']) && empty($_FILES['media'])) { if ($r_json) { - echo json_encode(['error' => DI::l10n()->t('Invalid request.')]); + System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } - exit(); + System::exit(); } $src = ''; @@ -147,11 +145,10 @@ function wall_upload_post(App $a, $desktopmode = true) if ($src == "") { if ($r_json) { - echo json_encode(['error' => DI::l10n()->t('Invalid request.')]); - exit(); + System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); } notice(DI::l10n()->t('Invalid request.')); - exit(); + System::exit(); } $filetype = Images::getMimeTypeBySource($src, $filename, $filetype); @@ -164,22 +161,19 @@ function wall_upload_post(App $a, $desktopmode = true) if (!$Image->isValid()) { $msg = DI::l10n()->t('Unable to process image.'); + @unlink($src); if ($r_json) { - echo json_encode(['error' => $msg]); + System::jsonExit(['error' => $msg]); } else { echo $msg. EOL; } - @unlink($src); - exit(); + System::exit(); } $Image->orient($src); @unlink($src); $max_length = DI::config()->get('system', 'max_image_length'); - if (!$max_length) { - $max_length = MAX_IMAGE_LENGTH; - } if ($max_length > 0) { $Image->scaleDown($max_length); $filesize = strlen($Image->asString()); @@ -205,13 +199,13 @@ function wall_upload_post(App $a, $desktopmode = true) if ($filesize > $maximagesize) { Logger::notice('Image size is too big', ['size' => $filesize, 'max' => $maximagesize]); $msg = DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)); + @unlink($src); if ($r_json) { - echo json_encode(['error' => $msg]); + System::jsonExit(['error' => $msg]); } else { echo $msg. EOL; } - @unlink($src); - exit(); + System::exit(); } } @@ -231,11 +225,11 @@ function wall_upload_post(App $a, $desktopmode = true) if (!$r) { $msg = DI::l10n()->t('Image upload failed.'); if ($r_json) { - echo json_encode(['error' => $msg]); + System::jsonExit(['error' => $msg]); } else { echo $msg. EOL; } - exit(); + System::exit(); } if ($width > 640 || $height > 640) { @@ -258,8 +252,7 @@ function wall_upload_post(App $a, $desktopmode = true) $photo = Photo::selectFirst(['id', 'datasize', 'width', 'height', 'type'], ['resource-id' => $resource_id], ['order' => ['width']]); if (!$photo) { if ($r_json) { - echo json_encode(['error' => '']); - exit(); + System::jsonExit(['error' => '']); } return false; } @@ -275,8 +268,7 @@ function wall_upload_post(App $a, $desktopmode = true) $picture["preview"] = DI::baseUrl() . "/photo/{$resource_id}-{$smallest}." . $Image->getExt(); if ($r_json) { - echo json_encode(['picture' => $picture]); - exit(); + System::jsonExit(['picture' => $picture]); } Logger::info("upload done"); return $picture; @@ -285,11 +277,10 @@ function wall_upload_post(App $a, $desktopmode = true) Logger::info("upload done"); if ($r_json) { - echo json_encode(['ok' => true]); - exit(); + System::jsonExit(['ok' => true]); } echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; - exit(); + System::exit(); // NOTREACHED }