Skip to content

Commit

Permalink
add source folder to attachment sources in html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
f-kuechler committed Oct 27, 2023
1 parent 430c1ac commit 75063a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Empty file modified src/Endpoint/Auth.php
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions src/Endpoint/Download.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ private function checkDownloadFolder(): bool

public function downloadPageContent(ConfluencePage $confluencePage, string $fileName)
{
if (!$this->checkDownloadFolder()) {
echo 'Error: The download folder does not exist or could not be created.';

return;
}

$htmlFile = $this->downloadFolder . '/' . $fileName;
file_put_contents($htmlFile, $confluencePage->getContent());
}
Expand Down
Empty file modified src/Endpoint/Dto/ConfluenceAttachment.php
100644 → 100755
Empty file.
Empty file modified src/Endpoint/Dto/ConfluenceLabel.php
100644 → 100755
Empty file.
17 changes: 14 additions & 3 deletions src/MacroReplacer/ImageAndVideoMacroReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
*/
class ImageAndVideoMacroReplacer implements MacroReplacerInterface
{
private string $sourceFolder;

public function __construct(string $sourceFolder = '')
{
if (!str_ends_with($sourceFolder, '/')) {
$sourceFolder .= '/';
}

$this->sourceFolder = $sourceFolder;
}

public function replace(string $haystack): string
{
return preg_replace_callback(
Expand All @@ -19,12 +30,12 @@ function ($match) {

//Distinguish between images and videos
if (in_array($fileExtension, ['jpg', 'jpeg', 'png', 'gif'])) {
return '<img src="' . $attachmentFileName . '">';
return '<img src="' . $this->sourceFolder . $attachmentFileName . '">';
} elseif (in_array($fileExtension, ['mp4', 'avi', 'mkv', 'mov'])) {
return '<video controls><source src="' . $attachmentFileName . '" type="video/' . $fileExtension . '">Your browser does not support the video tag.</video>';
return '<video controls><source src="' . $this->sourceFolder . $attachmentFileName . '" type="video/' . $fileExtension . '">Your browser does not support the video tag.</video>';
} else {
// By default, a link to the attachment is created
return '<a href="' . $attachmentFileName . '">' . $attachmentFileName . '</a>';
return '<a href="' . $this->sourceFolder . $attachmentFileName . '">' . $this->sourceFolder . $attachmentFileName . '</a>';
}
},
$haystack
Expand Down

0 comments on commit 75063a0

Please sign in to comment.