From c62762297cf2a06bad998a2b950b96102cb6e682 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 Mar 2023 19:25:17 -0400 Subject: [PATCH 01/46] Prevent template generation in media/photo/upload output --- src/Module/Media/Photo/Upload.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Module/Media/Photo/Upload.php b/src/Module/Media/Photo/Upload.php index 2b04d3582d..8b56540f43 100644 --- a/src/Module/Media/Photo/Upload.php +++ b/src/Module/Media/Photo/Upload.php @@ -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(); } } From 54afccc852f508b0c9d1dd1a22ef8c8c9c14bc9c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 Mar 2023 19:30:03 -0400 Subject: [PATCH 02/46] Prevent template generation in media/attachment/upload output --- src/Module/Media/Attachment/Upload.php | 43 ++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Module/Media/Attachment/Upload.php b/src/Module/Media/Attachment/Upload.php index 046d85bc90..b837b8df7b 100644 --- a/src/Module/Media/Attachment/Upload.php +++ b/src/Module/Media/Attachment/Upload.php @@ -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') . '
' . $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(); } } From 4366737eb826fa34b9537bd37ade08a5c97c227c Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sat, 18 Mar 2023 23:05:49 -0400 Subject: [PATCH 03/46] Fix posting/editing empty text image posts through Mastodon API --- src/Model/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 93ad4fd8f0..12184a3a55 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } From 67c0c279aa4279c09ec6753ecd55fdc6c945059d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 18 Mar 2023 23:11:28 -0400 Subject: [PATCH 04/46] Remove extra whitespace in Content\Text\HTMLTest --- tests/src/Content/Text/HTMLTest.php | 102 ++++++++++++++-------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/src/Content/Text/HTMLTest.php b/tests/src/Content/Text/HTMLTest.php index 3225d7f60a..259d0e6f02 100644 --- a/tests/src/Content/Text/HTMLTest.php +++ b/tests/src/Content/Text/HTMLTest.php @@ -627,13 +627,13 @@ its surprisingly good", e.preventDefault(); // console.log('[id=\"' + this.getAttribute('href') + '\"]'); // console.log(document.getElementById('[id=\"' + this.getAttribute('href') + '\"]')); - + document.querySelector('[ez-toc-data-id=\"' + decodeURI(this.getAttribute('href')) + '\"]').scrollIntoView({ behavior: 'smooth' }); }); }); -}; +}; document.addEventListener('DOMContentLoaded', ezTocScrollScriptJS, false); diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl index 7bce14ee1b..ee09b36f35 100644 --- a/view/theme/frio/templates/comment_item.tpl +++ b/view/theme/frio/templates/comment_item.tpl @@ -1,8 +1,8 @@ {{if $threaded}} -
+
{{else}} -
+
{{/if}}
@@ -61,6 +61,50 @@
+
+ diff --git a/view/theme/frio/templates/head.tpl b/view/theme/frio/templates/head.tpl index 7851dacbd4..b506ad2786 100644 --- a/view/theme/frio/templates/head.tpl +++ b/view/theme/frio/templates/head.tpl @@ -55,6 +55,8 @@ media="screen" /> + {{foreach $stylesheets as $stylesheetUrl => $media}} @@ -137,6 +139,7 @@ {{/if}} + {{* Include the strings which are needed for some js functions (e.g. translation) They are loaded into the html so that js functions can use them *}} diff --git a/view/theme/frio/templates/jot.tpl b/view/theme/frio/templates/jot.tpl index c38e8531c6..285b8e8d7f 100644 --- a/view/theme/frio/templates/jot.tpl +++ b/view/theme/frio/templates/jot.tpl @@ -70,7 +70,7 @@
- diff --git a/view/theme/frio/js/modal.js b/view/theme/frio/js/modal.js index 705f472c43..85c258c92f 100644 --- a/view/theme/frio/js/modal.js +++ b/view/theme/frio/js/modal.js @@ -293,48 +293,8 @@ function editpost(url) { // To make dropzone fileupload work on editing a comment, we need to // attach a new dropzone to modal - dropzoneJotEdit = new Dropzone( '#jot-text-wrap', { - paramName: 'userfile', // The name that will be used to transfer the file - maxFilesize: '{{$max_imagesize}}', // MB - url: '/media/photo/upload?response=url&album=', - accept: function(file, done) { - done(); - }, - init: function() { - this.on('success', function(file, serverResponse) { - var target = $('#profile-jot-text') - var resp = $(serverResponse).find('div#content').text() - if (target.setRangeText) { - //if setRangeText function is supported by current browser - target.setRangeText(' ' + $.trim(resp) + ' ') - } else { - target.focus() - document.execCommand('insertText', false /*no UI*/, ' ' + $.trim(resp) + ' '); - } - }); - this.on('complete', function(file) { - // Remove just uploaded file from dropzone, makes interface more clear. - // Image can be seen in posting-preview - // We need preview to get optical feedback about upload-progress. - // you see success, when the bb-code link for image is inserted - setTimeout(function(){ - dropzoneJotEdit.removeFile(file); - },5000); - }); - }, - }); - - // Enables Copy&Paste for this dropzone - $('#jot-text-wrap').on('paste', function(event){ - const items = (event.clipboardData || event.originalEvent.clipboardData).items; - items.forEach((item) => { - if (item.kind === 'file') { - // adds the file to your dropzone instance - dropzoneJotEdit.addFile(item.getAsFile()) - } - }) - }) - + console.log("modal.js max_imagesize",'{{$max_imagesize}}'); + dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', '{{$max_imagesize}}'); modal.show(); $("#jot-popup").show(); diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl index b61c1d6f87..3d9860a104 100644 --- a/view/theme/frio/templates/comment_item.tpl +++ b/view/theme/frio/templates/comment_item.tpl @@ -67,13 +67,13 @@ diff --git a/view/theme/frio/templates/jot.tpl b/view/theme/frio/templates/jot.tpl index 1b77ded421..325c8d5b3b 100644 --- a/view/theme/frio/templates/jot.tpl +++ b/view/theme/frio/templates/jot.tpl @@ -180,5 +180,5 @@ can load different content into the jot modal (e.g. the item edit jot) From 920dcca263edb51088381b7077ff336222e10bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Wed, 15 Mar 2023 21:48:17 +0100 Subject: [PATCH 37/46] render max_imagesize in header.tpl so it is reachable general from the whole website, and the dropzone-factory can use it also to create dropzones from modal.js --- mod/photos.php | 6 ------ src/App/Page.php | 14 ++++++++----- src/Content/Conversation.php | 3 --- src/Module/Item/Compose.php | 3 --- src/Module/Post/Edit.php | 2 -- src/Object/Post.php | 2 -- view/js/dropzone-factory.js | 8 ++++---- view/templates/item/compose.tpl | 2 +- view/theme/frio/js/dropzone-frio.js | 24 ---------------------- view/theme/frio/js/modal.js | 3 +-- view/theme/frio/templates/comment_item.tpl | 4 ++-- view/theme/frio/templates/head.tpl | 2 +- view/theme/frio/templates/jot.tpl | 2 +- 13 files changed, 19 insertions(+), 56 deletions(-) delete mode 100644 view/theme/frio/js/dropzone-frio.js diff --git a/mod/photos.php b/mod/photos.php index 5b225489ec..a08b569ced 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1139,8 +1139,6 @@ function photos_content(App $a) '$loading' => DI::l10n()->t('Loading...'), '$qcomment' => $qcomment, '$rand_num' => Crypto::randomDigits(12), - // Dropzone - '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1), ]); } } @@ -1196,8 +1194,6 @@ function photos_content(App $a) '$preview' => DI::l10n()->t('Preview'), '$qcomment' => $qcomment, '$rand_num' => Crypto::randomDigits(12), - // Dropzone - '$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1), ]); } @@ -1272,8 +1268,6 @@ function photos_content(App $a) '$preview' => DI::l10n()->t('Preview'), '$qcomment' => $qcomment, '$rand_num' => Crypto::randomDigits(12), - // Dropzone - '$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1), ]); } } diff --git a/src/App/Page.php b/src/App/Page.php index 965c04915c..45ec6be0fb 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -253,11 +253,15 @@ 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']; } diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index 1d7430e193..f23333911b 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -409,9 +409,6 @@ class Conversation '$compose_link_title' => $this->l10n->t('Open Compose page'), '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false), - // Dropzone - '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')) / 1000000, 1), - ]); diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index 19726eb717..f53158b1f7 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -240,9 +240,6 @@ class Compose extends BaseModule 'deny_cid' => $contact_deny_list, 'deny_gid' => $group_deny_list, ]), - - // Dropzone - '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')) / 1000000, 1), ]); } } diff --git a/src/Module/Post/Edit.php b/src/Module/Post/Edit.php index 403908cc02..5ddc250d8c 100644 --- a/src/Module/Post/Edit.php +++ b/src/Module/Post/Edit.php @@ -185,8 +185,6 @@ class Edit extends BaseModule '$compose_link_title' => $this->t('Open Compose page'), - // Dropzone - '$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000,1), ]); return $output; } diff --git a/src/Object/Post.php b/src/Object/Post.php index c6ef5e3ba1..3f4d061a17 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -1069,8 +1069,6 @@ class Post '$preview' => DI::l10n()->t('Preview'), '$indent' => $indent, '$rand_num' => Crypto::randomDigits(12), - // Dropzone - '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000,1), ]); } diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index 5aaab50362..bbf92625d8 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -1,8 +1,8 @@ var DzFactory = function () { - this.createDropzone = function(dropSelector, textareaSelector, maxImagesize) { + this.createDropzone = function(dropSelector, textareaSelector) { return new Dropzone( dropSelector, { paramName: 'userfile', // The name that will be used to transfer the file - maxFilesize: maxImagesize, // MB + maxFilesize: max_imagesize, // MB url: '/media/photo/upload?response=url&album=', accept: function(file, done) { done(); @@ -52,8 +52,8 @@ var DzFactory = function () { }) }; - this.setupDropzone = function(dropSelector, textareaSelector, maxImagesize) { - var dropzone = this.createDropzone(dropSelector, textareaSelector, maxImagesize); + this.setupDropzone = function(dropSelector, textareaSelector) { + var dropzone = this.createDropzone(dropSelector, textareaSelector); $(dropSelector).on('paste', function(event) { dzFactory.copyPaste(event, dropzone); }) diff --git a/view/templates/item/compose.tpl b/view/templates/item/compose.tpl index 499dfaffb2..09e42c90e5 100644 --- a/view/templates/item/compose.tpl +++ b/view/templates/item/compose.tpl @@ -96,5 +96,5 @@
diff --git a/view/theme/frio/js/dropzone-frio.js b/view/theme/frio/js/dropzone-frio.js deleted file mode 100644 index c165633c44..0000000000 --- a/view/theme/frio/js/dropzone-frio.js +++ /dev/null @@ -1,24 +0,0 @@ -function isInteger(value) { - return /^\d+$/.test(value); -} - -function getMBytes(value) { - var res; - if (isInteger(value)) { - res = value; - } else { - eh = value.slice(-1); - am = Number(value.slice(0, -1)); - switch (eh) { - case 'k': - res = am * 1024; - break; - case 'm': - res = am * 1024 * 1024; - break; - case 'g': - res = am * 1024 * 1024 * 1024; - } - } - return res / 1000000; -} diff --git a/view/theme/frio/js/modal.js b/view/theme/frio/js/modal.js index 85c258c92f..905e787434 100644 --- a/view/theme/frio/js/modal.js +++ b/view/theme/frio/js/modal.js @@ -293,8 +293,7 @@ function editpost(url) { // To make dropzone fileupload work on editing a comment, we need to // attach a new dropzone to modal - console.log("modal.js max_imagesize",'{{$max_imagesize}}'); - dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', '{{$max_imagesize}}'); + dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text'); modal.show(); $("#jot-popup").show(); diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl index 3d9860a104..81664cf0fe 100644 --- a/view/theme/frio/templates/comment_item.tpl +++ b/view/theme/frio/templates/comment_item.tpl @@ -67,12 +67,12 @@ - + {{* Include the strings which are needed for some js functions (e.g. translation) They are loaded into the html so that js functions can use them *}} diff --git a/view/theme/frio/templates/jot.tpl b/view/theme/frio/templates/jot.tpl index 325c8d5b3b..5c18afa86f 100644 --- a/view/theme/frio/templates/jot.tpl +++ b/view/theme/frio/templates/jot.tpl @@ -180,5 +180,5 @@ can load different content into the jot modal (e.g. the item edit jot) From c01f7f98ae88fd86331070ca24b6d640bbe90bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Thu, 16 Mar 2023 12:03:49 +0100 Subject: [PATCH 38/46] reinsert Friendica\DI (accidentially removed before) --- mod/photos.php | 1 + 1 file changed, 1 insertion(+) diff --git a/mod/photos.php b/mod/photos.php index a08b569ced..18db9c15d9 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -32,6 +32,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Photo; From fba33d3afc5cff66094f162cd5c29e59a034126f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Thu, 16 Mar 2023 12:04:15 +0100 Subject: [PATCH 39/46] add options allowedFiles and more --- view/js/dropzone-factory.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index bbf92625d8..a3a3e6c362 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -4,6 +4,9 @@ var DzFactory = function () { paramName: 'userfile', // The name that will be used to transfer the file maxFilesize: max_imagesize, // MB url: '/media/photo/upload?response=url&album=', + addRemoveLinks: true, + acceptedFiles: 'image/*', + clickable: true, accept: function(file, done) { done(); }, From 6436d2cd8ac17198704129208d1f0e499f1cd83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 10:49:12 +0100 Subject: [PATCH 40/46] changes in case of code-review --- src/Content/Conversation.php | 1 - view/js/dropzone-factory.js | 12 ++++++------ view/theme/frio/templates/comment_item.tpl | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index f23333911b..249190b1ad 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -408,7 +408,6 @@ class Conversation '$compose_link_title' => $this->l10n->t('Open Compose page'), '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false), - ]); diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index a3a3e6c362..21ea5ebbc2 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -1,6 +1,6 @@ var DzFactory = function () { - this.createDropzone = function(dropSelector, textareaSelector) { - return new Dropzone( dropSelector, { + this.createDropzone = function(dropSelector, textareaElementId) { + return new Dropzone(dropSelector, { paramName: 'userfile', // The name that will be used to transfer the file maxFilesize: max_imagesize, // MB url: '/media/photo/upload?response=url&album=', @@ -12,7 +12,7 @@ var DzFactory = function () { }, init: function() { this.on('success', function(file, serverResponse) { - const targetTextarea = document.getElementById(textareaSelector); + const targetTextarea = document.getElementById(textareaElementId); const bbcodeString = $(serverResponse).find('div#content').text(); if (targetTextarea.setRangeText) { //if setRangeText function is supported by current browser @@ -23,7 +23,7 @@ var DzFactory = function () { } }); this.on('complete', function(file) { - var dz = this; + const dz = this; // Remove just uploaded file from dropzone, makes interface more clear. // Image can be seen in posting-preview // We need preview to get optical feedback about upload-progress. @@ -55,8 +55,8 @@ var DzFactory = function () { }) }; - this.setupDropzone = function(dropSelector, textareaSelector) { - var dropzone = this.createDropzone(dropSelector, textareaSelector); + this.setupDropzone = function(dropSelector, textareaElementId) { + var dropzone = this.createDropzone(dropSelector, textareaElementId); $(dropSelector).on('paste', function(event) { dzFactory.copyPaste(event, dropzone); }) diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl index 81664cf0fe..2d977d807c 100644 --- a/view/theme/frio/templates/comment_item.tpl +++ b/view/theme/frio/templates/comment_item.tpl @@ -68,12 +68,12 @@ From 8a3361dfbe041983e5547dfe774f8ca91dd7d8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 10:54:31 +0100 Subject: [PATCH 41/46] remove upload-url parameter --- view/js/dropzone-factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index 21ea5ebbc2..a5010b95e6 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -3,7 +3,7 @@ var DzFactory = function () { return new Dropzone(dropSelector, { paramName: 'userfile', // The name that will be used to transfer the file maxFilesize: max_imagesize, // MB - url: '/media/photo/upload?response=url&album=', + url: '/media/photo/upload?album=', addRemoveLinks: true, acceptedFiles: 'image/*', clickable: true, From 399ee74e05da635df548df4911f2cd904fe2e3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 13:06:42 +0100 Subject: [PATCH 42/46] revert to original (no changes needed anymore) --- src/Module/Item/Compose.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index f53158b1f7..d44fe2cd7d 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -164,6 +164,7 @@ class Compose extends BaseModule $this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js')); $this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js')); $this->page->registerFooterScript(Theme::getPathForFile('js/compose.js')); + $contact = Contact::getById($a->getContactId()); if ($this->pConfig->get(DI::userSession()->getLocalUserId(), 'system', 'set_creation_date')) { From faa524faecdf5a8920fea9d169e60dfea32fb735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 14:22:32 +0100 Subject: [PATCH 43/46] revert changes, remove line (from code-review) --- src/App/Page.php | 1 - src/Module/Post/Edit.php | 4 +--- src/Object/Post.php | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/App/Page.php b/src/App/Page.php index 45ec6be0fb..23f542f7de 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -261,7 +261,6 @@ class Page implements ArrayAccess // Dropzone '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($config->get('system', 'maximagesize')) / 1000000, 1), - ]) . $this->page['htmlhead']; } diff --git a/src/Module/Post/Edit.php b/src/Module/Post/Edit.php index 5ddc250d8c..5fb339e179 100644 --- a/src/Module/Post/Edit.php +++ b/src/Module/Post/Edit.php @@ -28,7 +28,6 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Post; use Friendica\Model\User; @@ -36,7 +35,6 @@ use Friendica\Module\Response; use Friendica\Navigation\SystemMessages; use Friendica\Network\HTTPException; use Friendica\Util\Crypto; -use Friendica\Util\Strings; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -184,8 +182,8 @@ class Edit extends BaseModule '$shortpermset' => $this->t('Permissions'), '$compose_link_title' => $this->t('Open Compose page'), - ]); + return $output; } diff --git a/src/Object/Post.php b/src/Object/Post.php index 3f4d061a17..17c0c1f68e 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -1068,7 +1068,7 @@ class Post '$prompttext' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'), '$preview' => DI::l10n()->t('Preview'), '$indent' => $indent, - '$rand_num' => Crypto::randomDigits(12), + '$rand_num' => Crypto::randomDigits(12) ]); } From 57a7a3d6d803d0df59d17241e2d0bcce96abf275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 15:17:55 +0100 Subject: [PATCH 44/46] change responsehandling to be ready for PR #12892 --- view/js/dropzone-factory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index a5010b95e6..1b2a293374 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -13,7 +13,7 @@ var DzFactory = function () { init: function() { this.on('success', function(file, serverResponse) { const targetTextarea = document.getElementById(textareaElementId); - const bbcodeString = $(serverResponse).find('div#content').text(); + const bbcodeString = serverResponse; if (targetTextarea.setRangeText) { //if setRangeText function is supported by current browser targetTextarea.setRangeText(' ' + $.trim(bbcodeString) + ' '); From 5040bd9a1a69d0956a67f15590a4acfeb29969f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 17 Mar 2023 17:05:18 +0100 Subject: [PATCH 45/46] change response-handling (code-review) --- view/js/dropzone-factory.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index 1b2a293374..c2246dfa20 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -13,13 +13,12 @@ var DzFactory = function () { init: function() { this.on('success', function(file, serverResponse) { const targetTextarea = document.getElementById(textareaElementId); - const bbcodeString = serverResponse; if (targetTextarea.setRangeText) { //if setRangeText function is supported by current browser - targetTextarea.setRangeText(' ' + $.trim(bbcodeString) + ' '); + targetTextarea.setRangeText(' ' + $.trim(serverResponse) + ' '); } else { targetTextarea.focus(); - document.execCommand('insertText', false /*no UI*/, '\n' + $.trim(bbcodeString) + '\n'); + document.execCommand('insertText', false /*no UI*/, '\n' + $.trim(serverResponse) + '\n'); } }); this.on('complete', function(file) { From cf63cbde72e5fd41d237a3fe3aef3de4d07c9f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Sun, 19 Mar 2023 19:14:10 +0100 Subject: [PATCH 46/46] remove removelink (it is not useful at the moment) --- view/js/dropzone-factory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index c2246dfa20..ca77bb6d50 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -4,7 +4,6 @@ var DzFactory = function () { paramName: 'userfile', // The name that will be used to transfer the file maxFilesize: max_imagesize, // MB url: '/media/photo/upload?album=', - addRemoveLinks: true, acceptedFiles: 'image/*', clickable: true, accept: function(file, done) {