use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Session\Capability\IHandleUserSessions;
-use Friendica\Database\Database;
+use Friendica\Core\System;
use Friendica\Model\Photo;
use Friendica\Model\User;
-use Friendica\Module\BaseApi;
use Friendica\Module\Response;
use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPException\InternalServerErrorException;
*/
class Upload extends \Friendica\BaseModule
{
- /** @var Database */
- private $database;
-
/** @var IHandleUserSessions */
private $userSession;
/** @var bool */
private $isJson = false;
- public function __construct(IManageConfigValues $config, SystemMessages $systemMessages, IHandleUserSessions $userSession, Database $database, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+ /** @var App\Page */
+ private $page;
+
+ public function __construct(App\Page $page, IManageConfigValues $config, SystemMessages $systemMessages, IHandleUserSessions $userSession, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
- $this->database = $database;
$this->userSession = $userSession;
$this->systemMessages = $systemMessages;
$this->config = $config;
+ $this->page = $page;
}
protected function post(array $request = [])
if (!$owner) {
$this->logger->warning('Owner not found.', ['uid' => $this->userSession->getLocalUserId()]);
- return $this->return(401, $this->t('Invalid request.'));
+ $this->return(401, $this->t('Invalid request.'));
}
if (empty($_FILES['userfile']) && empty($_FILES['media'])) {
$this->logger->warning('Empty "userfile" and "media" field');
- return $this->return(401, $this->t('Invalid request.'));
+ $this->return(401, $this->t('Invalid request.'));
}
$src = '';
if ($src == '') {
$this->logger->warning('File source (temporary file) cannot be determined', ['$_FILES' => $_FILES]);
- return $this->return(401, $this->t('Invalid request.'), true);
+ $this->return(401, $this->t('Invalid request.'), true);
}
$filetype = Images::getMimeTypeBySource($src, $filename, $filetype);
if (!$image->isValid()) {
@unlink($src);
$this->logger->warning($this->t('Unable to process image.'), ['imagedata[]' => gettype($imagedata), 'filetype' => $filetype]);
- return $this->return(401, $this->t('Unable to process image.'));
+ $this->return(401, $this->t('Unable to process image.'));
}
$image->orient($src);
if ($filesize > $maximagesize) {
@unlink($src);
$this->logger->notice('Image size is too big', ['size' => $filesize, 'max' => $maximagesize]);
- return $this->return(401, $this->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
+ $this->return(401, $this->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
}
}
$result = Photo::store($image, $owner['uid'], 0, $resource_id, $filename, $album, 0, Photo::DEFAULT, $allow_cid);
if (!$result) {
$this->logger->warning('Photo::store() failed', ['result' => $result]);
- return $this->return(401, $this->t('Image upload failed.'));
+ $this->return(401, $this->t('Image upload failed.'));
}
if ($width > 640 || $height > 640) {
}
$this->logger->info('upload done');
- return $this->return(200, "\n\n" . '[url=' . $this->baseUrl . '/photos/' . $owner['nickname'] . '/image/' . $resource_id . '][img]' . $this->baseUrl . "/photo/$resource_id-$smallest." . $image->getExt() . "[/img][/url]\n\n");
+ $this->return(200, "\n\n" . '[url=' . $this->baseUrl . '/photos/' . $owner['nickname'] . '/image/' . $resource_id . '][img]' . $this->baseUrl . "/photo/$resource_id-$smallest." . $image->getExt() . "[/img][/url]\n\n");
}
/**
$this->response->addContent($message);
}
+
+ $this->page->exit($this->response->generate());
+ System::exit();
}
}