[Posting] Respect process_links setting

This commit is contained in:
Diogo Peralta Cordeiro 2021-08-19 19:18:33 +01:00 committed by Hugo Sales
parent ab142ab52d
commit 9739cc5f21
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 17 additions and 15 deletions

View File

@ -26,7 +26,6 @@ use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use App\Core\GSFile; use App\Core\GSFile;
use App\Util\Exception\ClientException;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Modules\Component; use App\Core\Modules\Component;
use App\Entity\Attachment; use App\Entity\Attachment;
@ -36,6 +35,7 @@ use App\Entity\Link;
use App\Entity\Note; use App\Entity\Note;
use App\Entity\NoteToLink; use App\Entity\NoteToLink;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\InvalidFormException; use App\Util\Exception\InvalidFormException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use InvalidArgumentException; use InvalidArgumentException;
@ -119,7 +119,7 @@ END;
$processed_attachments = []; $processed_attachments = [];
foreach ($attachments as $f) { // where $f is a Symfony\Component\HttpFoundation\File\UploadedFile foreach ($attachments as $f) { // where $f is a Symfony\Component\HttpFoundation\File\UploadedFile
$filesize = $f->getSize(); $filesize = $f->getSize();
$max_file_size = Common::config('attachments', 'file_quota'); $max_file_size = Common::config('attachments', 'file_quota');
if ($max_file_size < $filesize) { if ($max_file_size < $filesize) {
throw new ClientException(_m('No file may be larger than {quota} bytes and the file you sent was {size} bytes. ' . throw new ClientException(_m('No file may be larger than {quota} bytes and the file you sent was {size} bytes. ' .
@ -143,20 +143,22 @@ END;
DB::flush(); DB::flush();
} }
$matched_urls = []; if (Common::config('attachments', 'process_links')) {
$processed_urls = false; $matched_urls = [];
preg_match_all(self::URL_REGEX, $content, $matched_urls, PREG_SET_ORDER); $processed_urls = false;
foreach ($matched_urls as $match) { preg_match_all(self::URL_REGEX, $content, $matched_urls, PREG_SET_ORDER);
try { foreach ($matched_urls as $match) {
$link_id = Link::getOrCreate($match[0])->getId(); try {
DB::persist(NoteToLink::create(['link_id' => $link_id, 'note_id' => $note->getId()])); $link_id = Link::getOrCreate($match[0])->getId();
$processed_urls = true; DB::persist(NoteToLink::create(['link_id' => $link_id, 'note_id' => $note->getId()]));
} catch (InvalidArgumentException) { $processed_urls = true;
continue; } catch (InvalidArgumentException) {
continue;
}
}
if ($processed_urls) {
DB::flush();
} }
}
if ($processed_urls) {
DB::flush();
} }
} }