Skip to content

Commit 6a31c89

Browse files
committed
After review 0
1 parent 5c65671 commit 6a31c89

21 files changed

Lines changed: 165 additions & 100 deletions

config/parameters.yml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ parameters:
132132
env(FCKIMAGES_DIR): 'uploadimages'
133133
phplist.public_schema: '%%env(PUBLIC_SCHEMA)%%'
134134
env(PUBLIC_SCHEMA): 'https'
135+
phplist.attachment_download_url: '%env(PHPLIST_ATTACHMENT_DOWNLOAD_URL)%'
136+
env(PHPLIST_ATTACHMENT_DOWNLOAD_URL): 'https://example.com/download/'
137+
phplist.attachment_repository_path: '%env(PHPLIST_ATTACHMENT_REPOSITORY_PATH)%'
138+
env(PHPLIST_ATTACHMENT_REPOSITORY_PATH): '/tmp'

resources/translations/messages.en.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ Thank you.</target>
774774
<source>This message contains attachments that can be viewed with a webbrowser</source>
775775
<target>__This message contains attachments that can be viewed with a webbrowser</target>
776776
</trans-unit>
777-
<trans-unit id="QLlIQQh" resname="Insufficient memory to add attachment to campaign %campaignId% %tatalSize% - %memLimit%">
778-
<source>Insufficient memory to add attachment to campaign %campaignId% %tatalSize% - %memLimit%</source>
779-
<target>__Insufficient memory to add attachment to campaign %campaignId% %tatalSize% - %memLimit%</target>
777+
<trans-unit id="QLlIQQh" resname="Insufficient memory to add attachment to campaign %campaignId% %totalSize% - %memLimit%">
778+
<source>Insufficient memory to add attachment to campaign %campaignId% %totalSize% - %memLimit%</source>
779+
<target>__Insufficient memory to add attachment to campaign %campaignId% %totalSize% - %memLimit%</target>
780780
</trans-unit>
781781
<trans-unit id="HhEWxtR" resname="Add us to your address book">
782782
<source>Add us to your address book</source>

src/Domain/Common/FileHelper.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PhpList\Core\Domain\Common;
66

7+
use Throwable;
8+
79
class FileHelper
810
{
911
public function isValidFile(string $path): bool
@@ -13,14 +15,47 @@ public function isValidFile(string $path): bool
1315

1416
public function readFileContents(string $path): ?string
1517
{
16-
$filePointer = fopen($path, 'r');
18+
$filePointer = fopen($path, 'rb');
1719
if ($filePointer === false) {
1820
return null;
1921
}
2022

21-
$contents = fread($filePointer, filesize($path));
22-
fclose($filePointer);
23+
try {
24+
$contents = stream_get_contents($filePointer);
25+
if ($contents === false) {
26+
return null;
27+
}
28+
return $contents;
29+
} catch (Throwable) {
30+
return null;
31+
} finally {
32+
fclose($filePointer);
33+
}
34+
}
35+
36+
public function writeFileToDirectory(string $directory, string $originalFilename, string $contents): ?string
37+
{
38+
$pathInfo = pathinfo($originalFilename);
39+
$name = $pathInfo['filename'] === '' ? 'file' : $pathInfo['filename'];
40+
$ext = $pathInfo['extension'] ?? '';
41+
42+
$newFile = tempnam($directory, $name);
43+
if ($newFile === false) {
44+
return null;
45+
}
46+
47+
if ($ext !== '') {
48+
$newFile .= '.' . $ext;
49+
}
50+
$relativeName = basename($newFile);
51+
52+
$fullPath = $directory . '/' . $relativeName;
53+
54+
$fileHandle = fopen($fullPath, 'w');
55+
56+
fwrite($fileHandle, $contents);
57+
fclose($fileHandle);
2358

24-
return $contents === false ? null : $contents;
59+
return $fullPath;
2560
}
2661
}

src/Domain/Configuration/Service/MessagePlaceholderProcessor.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
private readonly iterable $patternResolvers,
3030
/** @var iterable<SupportingPlaceholderResolverInterface> */
3131
private readonly iterable $supportingResolvers,
32-
#[Autowire('messaging.always_add_user_track')] private readonly bool $alwaysAddUserTrack,
32+
#[Autowire('%messaging.always_add_user_track%')] private readonly bool $alwaysAddUserTrack,
3333
) {
3434
}
3535

@@ -61,12 +61,6 @@ public function process(
6161
name: 'ORGANIZATION_NAME',
6262
resolver: fn(PlaceholderContext $ctx) => $this->config->getValue(ConfigOption::OrganisationName) ?? ''
6363
);
64-
$resolver->register(
65-
name: 'CONTACTURL',
66-
resolver: fn(PlaceholderContext $ctx) => htmlspecialchars(
67-
$this->config->getValue(ConfigOption::VCardUrl) ?? ''
68-
)
69-
);
7064

7165
foreach ($this->placeholderResolvers as $placeholderResolver) {
7266
$resolver->register($placeholderResolver->name(), $placeholderResolver);
@@ -100,33 +94,33 @@ public function process(
10094
);
10195
}
10296

103-
private function appendContent(string $message, string $append): string
104-
{
105-
if (preg_match('#</body>#i', $message)) {
106-
$message = preg_replace('#</body>#i', $append . '</body>', $message);
107-
} else {
108-
$message .= $append;
109-
}
110-
111-
return $message;
112-
}
113-
11497
private function ensureStandardPlaceholders(string $value, OutputFormat $format): string
11598
{
116-
if (!strpos($value, '[FOOTER]')) {
99+
if (!str_contains($value, '[FOOTER]')) {
117100
$sep = $format === OutputFormat::Html ? '<br />' : "\n\n";
118101
$value = $this->appendContent($value, $sep . '[FOOTER]');
119102
}
120103

121-
if (!strpos($value, '[SIGNATURE]')) {
104+
if (!str_contains($value, '[SIGNATURE]')) {
122105
$sep = $format === OutputFormat::Html ? ' ' : "\n";
123106
$value = $this->appendContent($value, $sep . '[SIGNATURE]');
124107
}
125108

126-
if ($this->alwaysAddUserTrack && $format === OutputFormat::Html && !strpos($value, '[USERTRACK]')) {
109+
if ($this->alwaysAddUserTrack && $format === OutputFormat::Html && !str_contains($value, '[USERTRACK]')) {
127110
$value = $this->appendContent($value, '[USERTRACK]');
128111
}
129112

130113
return $value;
131114
}
115+
116+
private function appendContent(string $message, string $append): string
117+
{
118+
if (preg_match('#</body>#i', $message)) {
119+
$message = preg_replace('#</body>#i', $append . '</body>', $message);
120+
} else {
121+
$message .= $append;
122+
}
123+
124+
return $message;
125+
}
132126
}

src/Domain/Configuration/Service/Placeholder/BlacklistUrlValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function name(): string
2424

2525
public function __invoke(PlaceholderContext $ctx): string
2626
{
27-
$base = $this->config->getValue(ConfigOption::UnsubscribeUrl) ?? '';
27+
$base = $this->config->getValue(ConfigOption::BlacklistUrl) ?? '';
2828
$url = $this->urlBuilder->withEmail($base, $ctx->getUser()->getEmail());
2929

3030
if ($ctx->isHtml()) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Configuration\Service\Placeholder;
6+
7+
use PhpList\Core\Domain\Configuration\Model\ConfigOption;
8+
use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider;
9+
use PhpList\Core\Domain\Configuration\Model\Dto\PlaceholderContext;
10+
11+
final class ContactUrlValueResolver implements PlaceholderValueResolverInterface
12+
{
13+
public function __construct(private readonly ConfigProvider $config)
14+
{
15+
}
16+
17+
public function name(): string
18+
{
19+
return 'CONTACTURL';
20+
}
21+
22+
public function __invoke(PlaceholderContext $ctx): string
23+
{
24+
if ($ctx->isText()) {
25+
return $this->config->getValue(ConfigOption::VCardUrl) ?? '';
26+
}
27+
28+
return htmlspecialchars($this->config->getValue(ConfigOption::VCardUrl) ?? '');
29+
}
30+
}

src/Domain/Configuration/Service/Placeholder/FooterValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public function __invoke(PlaceholderContext $ctx): string
2828
return stripslashes($ctx->messagePrecacheDto->footer);
2929
}
3030

31-
return $this->config->getValue(ConfigOption::ForwardFooter);
31+
return $this->config->getValue(ConfigOption::ForwardFooter) ?? '';
3232
}
3333
}

src/Domain/Configuration/Service/Placeholder/ForwardUrlValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function __invoke(PlaceholderContext $ctx): string
3434
);
3535
}
3636

37-
return sprintf('%s%suid=%s&mid=%d ', $url, $sep, $ctx->getUser()->getUniqueId(), $ctx->messageId());
37+
return sprintf('%s%suid=%s&mid=%d', $url, $sep, $ctx->getUser()->getUniqueId(), $ctx->messageId());
3838
}
3939
}

src/Domain/Configuration/Service/Placeholder/PreferencesUrlValueResolver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ public function __invoke(PlaceholderContext $ctx): string
2525
$sep = !str_contains($url, '?') ? '?' : '&';
2626

2727
if ($ctx->isHtml()) {
28-
return sprintf('%s%suid=%s', $url, htmlspecialchars($sep), $ctx->getUser()->getUniqueId());
28+
return sprintf(
29+
'%s%suid=%s',
30+
htmlspecialchars($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'),
31+
htmlspecialchars($sep),
32+
$ctx->getUser()->getUniqueId(),
33+
);
2934
}
3035

3136
return sprintf('%s%suid=%s', $url, $sep, $ctx->getUser()->getUniqueId());

src/Domain/Configuration/Service/Placeholder/SignatureValueResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function __invoke(PlaceholderContext $ctx): string
2525
{
2626
if ($ctx->isHtml()) {
2727
if ($this->emailTextCredits) {
28-
return $this->config->getValue(ConfigOption::PoweredByText);
28+
return $this->config->getValue(ConfigOption::PoweredByText) ?? '';
2929
}
3030

3131
return preg_replace(
3232
'/src=".*power-phplist.png"/',
3333
'src="powerphplist.png"',
34-
$this->config->getValue(ConfigOption::PoweredByImage)
34+
$this->config->getValue(ConfigOption::PoweredByImage) ?? ''
3535
);
3636
}
3737

0 commit comments

Comments
 (0)