Merge remote-tracking branch 'upstream/2023.03-rc' into remove-tab
This commit is contained in:
+8
-5
@@ -253,11 +253,14 @@ class Page implements ArrayAccess
|
||||
'$touch_icon' => $touch_icon,
|
||||
'$block_public' => intval($config->get('system', 'block_public')),
|
||||
'$stylesheets' => $this->stylesheets,
|
||||
'$likeError' => $l10n->t('Like not successfull'),
|
||||
'$dislikeError' => $l10n->t('Dislike not successfull'),
|
||||
'$announceError' => $l10n->t('Sharing not successfull'),
|
||||
'$srvError' => $l10n->t('Backend error'),
|
||||
'$netError' => $l10n->t('Network error'),
|
||||
'$likeError' => $l10n->t('Like not successfull'),
|
||||
'$dislikeError' => $l10n->t('Dislike not successfull'),
|
||||
'$announceError' => $l10n->t('Sharing not successfull'),
|
||||
'$srvError' => $l10n->t('Backend error'),
|
||||
'$netError' => $l10n->t('Network error'),
|
||||
// Dropzone
|
||||
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($config->get('system', 'maximagesize')) / 1000000, 1),
|
||||
|
||||
]) . $this->page['htmlhead'];
|
||||
}
|
||||
|
||||
|
||||
@@ -1475,8 +1475,8 @@ class BBCode
|
||||
$text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '</p><ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul><p>', $text);
|
||||
$text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '</p><ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul><p>', $text);
|
||||
$text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '</p><ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul><p>', $text);
|
||||
$text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '</p><ul class="listbullet" style="list-style-type: circle;">$1</ul><p>', $text);
|
||||
$text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '</p><ul class="listdecimal" style="list-style-type: decimal;">$1</ul><p>', $text);
|
||||
$text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '</p><ul>$1</ul><p>', $text);
|
||||
$text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '</p><ol>$1</ol><p>', $text);
|
||||
$text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>', $text);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,9 +281,9 @@ class HTML
|
||||
self::tagToBBCode($doc, 'div', [], "\r", "\r");
|
||||
self::tagToBBCode($doc, 'p', [], "\n", "\n");
|
||||
|
||||
self::tagToBBCode($doc, 'ul', [], "[list]", "[/list]");
|
||||
self::tagToBBCode($doc, 'ol', [], "[list=1]", "[/list]");
|
||||
self::tagToBBCode($doc, 'li', [], "[*]", "");
|
||||
self::tagToBBCode($doc, 'ul', [], "[ul]", "\n[/ul]");
|
||||
self::tagToBBCode($doc, 'ol', [], "[ol]", "\n[/ol]");
|
||||
self::tagToBBCode($doc, 'li', [], "\n[*]", "");
|
||||
|
||||
self::tagToBBCode($doc, 'hr', [], "[hr]", "");
|
||||
|
||||
@@ -349,33 +349,6 @@ class HTML
|
||||
$message = str_replace("\n\n\n", "\n\n", $message);
|
||||
} while ($oldmessage != $message);
|
||||
|
||||
do {
|
||||
$oldmessage = $message;
|
||||
$message = str_replace(
|
||||
[
|
||||
"[/size]\n\n",
|
||||
"\n[hr]",
|
||||
"[hr]\n",
|
||||
"\n[list",
|
||||
"[/list]\n",
|
||||
"\n[/",
|
||||
"[list]\n",
|
||||
"[list=1]\n",
|
||||
"\n[*]"],
|
||||
[
|
||||
"[/size]\n",
|
||||
"[hr]",
|
||||
"[hr]",
|
||||
"[list",
|
||||
"[/list]",
|
||||
"[/",
|
||||
"[list]",
|
||||
"[list=1]",
|
||||
"[*]"],
|
||||
$message
|
||||
);
|
||||
} while ($message != $oldmessage);
|
||||
|
||||
$message = str_replace(
|
||||
['[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'],
|
||||
['[b]', '[/b]', '[i]', '[/i]'],
|
||||
|
||||
@@ -55,19 +55,17 @@ class Session
|
||||
* @param LoggerInterface $logger
|
||||
* @param Profiler $profiler
|
||||
* @param array $server
|
||||
* @return IHandleSessions
|
||||
*/
|
||||
public function createSession(App\Mode $mode, App\BaseURL $baseURL, IManageConfigValues $config, Database $dba, Cache $cacheFactory, LoggerInterface $logger, Profiler $profiler, array $server = []): IHandleSessions
|
||||
public function create(App\Mode $mode, App\BaseURL $baseURL, IManageConfigValues $config, Database $dba, Cache $cacheFactory, LoggerInterface $logger, Profiler $profiler, array $server = []): IHandleSessions
|
||||
{
|
||||
$profiler->startRecording('session');
|
||||
$session = null;
|
||||
$session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
|
||||
|
||||
try {
|
||||
if ($mode->isInstall() || $mode->isBackend()) {
|
||||
$session = new Type\Memory();
|
||||
} else {
|
||||
$session_handler = $config->get('system', 'session_handler', self::HANDLER_DEFAULT);
|
||||
$handler = null;
|
||||
|
||||
switch ($session_handler) {
|
||||
case self::HANDLER_DATABASE:
|
||||
$handler = new Handler\Database($dba, $logger, $server);
|
||||
@@ -82,10 +80,15 @@ class Session
|
||||
$handler = new Handler\Cache($cache, $logger);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$handler = null;
|
||||
}
|
||||
|
||||
$session = new Type\Native($baseURL, $handler);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$logger->notice('Unable to create session', ['mode' => $mode, 'session_handler' => $session_handler, 'exception' => $e]);
|
||||
$session = new Type\Memory();
|
||||
} finally {
|
||||
$profiler->stopRecording();
|
||||
return $session;
|
||||
|
||||
+1
-1
@@ -589,7 +589,7 @@ class Item
|
||||
public static function isValid(array $item): bool
|
||||
{
|
||||
// When there is no content then we don't post it
|
||||
if (($item['body'] . $item['title'] == '') && empty($item['quote-uri-id']) && (empty($item['uri-id']) || !Post\Media::existsByURIId($item['uri-id']))) {
|
||||
if (($item['body'] . $item['title'] == '') && empty($item['quote-uri-id']) && empty($item['attachments']) && (empty($item['uri-id']) || !Post\Media::existsByURIId($item['uri-id']))) {
|
||||
Logger::notice('No body, no title.');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ class Profile
|
||||
if (!$local_user_is_self) {
|
||||
if (!$visitor_is_authenticated) {
|
||||
// Remote follow is only available for local profiles
|
||||
if (!empty($profile['nickname']) && strpos($profile_url, DI::baseUrl()) === 0) {
|
||||
if (!empty($profile['nickname']) && strpos($profile_url, (string)DI::baseUrl()) === 0) {
|
||||
$follow_link = 'profile/' . $profile['nickname'] . '/remote_follow';
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,7 @@ use Friendica\App;
|
||||
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\Attach;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
@@ -42,9 +42,6 @@ use Psr\Log\LoggerInterface;
|
||||
*/
|
||||
class Upload extends \Friendica\BaseModule
|
||||
{
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
/** @var IHandleUserSessions */
|
||||
private $userSession;
|
||||
|
||||
@@ -57,31 +54,32 @@ class Upload extends \Friendica\BaseModule
|
||||
/** @var bool */
|
||||
private $isJson;
|
||||
|
||||
public function __construct(SystemMessages $systemMessages, IManageConfigValues $config, 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, SystemMessages $systemMessages, IManageConfigValues $config, 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->config = $config;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if ($this->isJson = !empty($request['response']) && $request['response'] == 'json') {
|
||||
$this->response->setType(Response::TYPE_JSON, 'application/json');
|
||||
}
|
||||
$this->isJson = !empty($request['response']) && $request['response'] == 'json';
|
||||
|
||||
$owner = User::getOwnerDataById($this->userSession->getLocalUserId());
|
||||
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'])) {
|
||||
$this->logger->warning('No file uploaded (empty userfile)');
|
||||
return $this->return(401, $this->t('Invalid request.'), true);
|
||||
$this->return(401, $this->t('Invalid request.'), true);
|
||||
}
|
||||
|
||||
$tempFileName = $_FILES['userfile']['tmp_name'];
|
||||
@@ -98,14 +96,14 @@ class Upload extends \Friendica\BaseModule
|
||||
@unlink($tempFileName);
|
||||
$msg = $this->t('Sorry, maybe your upload is bigger than the PHP configuration allows') . '<br />' . $this->t('Or - did you try to upload an empty file?');
|
||||
$this->logger->warning($msg, ['fileSize' => $fileSize]);
|
||||
return $this->return(401, $msg, true);
|
||||
$this->return(401, $msg, true);
|
||||
}
|
||||
|
||||
if ($maxFileSize && $fileSize > $maxFileSize) {
|
||||
@unlink($tempFileName);
|
||||
$msg = $this->t('File exceeds size limit of %s', Strings::formatBytes($maxFileSize));
|
||||
$this->logger->warning($msg, ['fileSize' => $fileSize]);
|
||||
return $this->return(401, $msg);
|
||||
$this->return(401, $msg);
|
||||
}
|
||||
|
||||
$newid = Attach::storeFile($tempFileName, $owner['uid'], $fileName, '<' . $owner['id'] . '>');
|
||||
@@ -115,16 +113,16 @@ class Upload extends \Friendica\BaseModule
|
||||
if ($newid === false) {
|
||||
$msg = $this->t('File upload failed.');
|
||||
$this->logger->warning($msg);
|
||||
return $this->return(500, $msg);
|
||||
$this->return(500, $msg);
|
||||
}
|
||||
|
||||
if ($this->isJson) {
|
||||
$content = json_encode(['ok' => true, 'id' => $newid], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
$content = $newid;
|
||||
} else {
|
||||
$content = "\n\n" . '[attachment]' . $newid . '[/attachment]' . "\n";
|
||||
}
|
||||
|
||||
return $this->response->addContent($content);
|
||||
$this->return(200, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,16 +134,23 @@ class Upload extends \Friendica\BaseModule
|
||||
*/
|
||||
private function return(int $httpCode, string $message, bool $systemMessage = false): void
|
||||
{
|
||||
$this->response->setStatus($httpCode, $message);
|
||||
|
||||
if ($this->isJson) {
|
||||
$this->response->addContent(json_encode(['error' => $message], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
$message = $httpCode >= 400 ? ['error' => $message] : ['ok' => true, 'id' => $message];
|
||||
$this->response->setType(Response::TYPE_JSON, 'application/json');
|
||||
$this->response->addContent(json_encode($message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
} else {
|
||||
if ($systemMessage) {
|
||||
$this->systemMessages->addNotice($message);
|
||||
}
|
||||
|
||||
if ($httpCode >= 400) {
|
||||
$this->response->setStatus($httpCode, $message);
|
||||
}
|
||||
|
||||
$this->response->addContent($message);
|
||||
}
|
||||
|
||||
$this->page->exit($this->response->generate());
|
||||
System::exit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ use Friendica\App;
|
||||
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;
|
||||
@@ -45,9 +44,6 @@ use Psr\Log\LoggerInterface;
|
||||
*/
|
||||
class Upload extends \Friendica\BaseModule
|
||||
{
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
/** @var IHandleUserSessions */
|
||||
private $userSession;
|
||||
|
||||
@@ -60,14 +56,17 @@ class Upload extends \Friendica\BaseModule
|
||||
/** @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 = [])
|
||||
@@ -80,12 +79,12 @@ class Upload extends \Friendica\BaseModule
|
||||
|
||||
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 = '';
|
||||
@@ -134,7 +133,7 @@ class Upload extends \Friendica\BaseModule
|
||||
|
||||
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);
|
||||
@@ -152,7 +151,7 @@ class Upload extends \Friendica\BaseModule
|
||||
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);
|
||||
@@ -185,7 +184,7 @@ class Upload extends \Friendica\BaseModule
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +202,7 @@ class Upload extends \Friendica\BaseModule
|
||||
$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) {
|
||||
@@ -223,7 +222,7 @@ class Upload extends \Friendica\BaseModule
|
||||
}
|
||||
|
||||
$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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,5 +249,8 @@ class Upload extends \Friendica\BaseModule
|
||||
|
||||
$this->response->addContent($message);
|
||||
}
|
||||
|
||||
$this->page->exit($this->response->generate());
|
||||
System::exit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user