Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2022-05-20 14:00:02 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-05-23 17:32:03 +0300
commitcad9a1d7f62fb5d3e2ba5eb053497ad207f5aee4 (patch)
treebc51c6458a7df127a73754d28471b6a51a3159ad /lib
parent401bdb3566dc6b483b89e57bed51ebfe6624756c (diff)
change image target in markdown content to relative path, handle it in ImageView
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/ImageService.php24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/Service/ImageService.php b/lib/Service/ImageService.php
index 8c2bc1ee2..7d047550a 100644
--- a/lib/Service/ImageService.php
+++ b/lib/Service/ImageService.php
@@ -156,6 +156,7 @@ class ImageService {
$savedFile = $saveDir->newFile($fileName, $newFileResource);
return [
'name' => $fileName,
+ 'dirname' => $saveDir->getName(),
'id' => $savedFile->getId(),
'documentId' => $textFile->getId(),
];
@@ -183,6 +184,7 @@ class ImageService {
$savedFile = $saveDir->newFile($fileName, $newFileResource);
return [
'name' => $fileName,
+ 'dirname' => $saveDir->getName(),
'id' => $savedFile->getId(),
'documentId' => $textFile->getId(),
];
@@ -227,6 +229,7 @@ class ImageService {
// get file type and name
return [
'name' => $fileName,
+ 'dirname' => $saveDir->getName(),
'id' => $targetFile->getId(),
'documentId' => $textFile->getId(),
];
@@ -457,7 +460,7 @@ class ImageService {
$attachmentsByName[$attNode->getName()] = $attNode;
}
- $contentAttachmentNames = $this->getAttachmentNamesFromContent($textFile->getContent());
+ $contentAttachmentNames = $this->getAttachmentNamesFromContent($textFile->getContent(), $fileId);
$toDelete = array_diff(array_keys($attachmentsByName), $contentAttachmentNames);
foreach ($toDelete as $name) {
@@ -476,20 +479,33 @@ class ImageService {
* @param string $content
* @return array
*/
- public static function getAttachmentNamesFromContent(string $content): array {
- $matches = [];
+ public static function getAttachmentNamesFromContent(string $content, int $fileId): array {
+ $oldMatches = [];
preg_match_all(
// simple version with .+ between the brackets
// '/\!\[.+\]\(text:\/\/image\?[^)]*imageFileName=([^)&]+)\)/',
// complex version of php-markdown
'/\!\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[\])*\])*\])*\])*\])*\])*\]\(text:\/\/image\?[^)]*imageFileName=([^)&]+)\)/',
$content,
+ $oldMatches,
+ PREG_SET_ORDER
+ );
+ $oldNames = array_map(static function (array $match) {
+ return urldecode($match[1]);
+ }, $oldMatches);
+
+ $matches = [];
+ preg_match_all(
+ '/\!\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[\])*\])*\])*\])*\])*\])*\]\(\.attachments\.'.$fileId.'\/([^)&]+)\)/',
+ $content,
$matches,
PREG_SET_ORDER
);
- return array_map(static function (array $match) {
+ $names = array_map(static function (array $match) {
return urldecode($match[1]);
}, $matches);
+
+ return array_merge($names, $oldNames);
}
/**