mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Fix #1787 convert image URLs to absolute path when sending mail
This commit is contained in:
parent
d49614d59c
commit
602d7aec79
2 changed files with 20 additions and 1 deletions
|
|
@ -635,7 +635,17 @@ class Mail
|
||||||
*/
|
*/
|
||||||
protected function convertImageURLs(array $matches)
|
protected function convertImageURLs(array $matches)
|
||||||
{
|
{
|
||||||
return preg_replace('/src=(["\']?)files/i', 'src=$1' . URL::getCurrentDomainURL(\RX_BASEURL) . 'files', $matches[0]);
|
$patterns = [
|
||||||
|
'!\b(?i:src)=(["\']?)(?:\./|' . preg_quote(\RX_BASEURL, '!') . '|)files/!',
|
||||||
|
'!\b(?:data-file-srl|editor_component|widget|id)="[^"]*"\s?!',
|
||||||
|
'!\b(?:class="zbxe_widget_output")\s?!',
|
||||||
|
];
|
||||||
|
$replacements = [
|
||||||
|
'src=$1' . URL::getCurrentDomainURL(\RX_BASEURL) . 'files/',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
];
|
||||||
|
return preg_replace($patterns, $replacements, $matches[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,15 @@ class MailTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals('<p>Hello foobar...</p>', $mail->getContent());
|
$this->assertEquals('<p>Hello foobar...</p>', $mail->getContent());
|
||||||
$this->assertEquals('text/plain', $mail->getContentType());
|
$this->assertEquals('text/plain', $mail->getContentType());
|
||||||
|
|
||||||
|
$mail->setBody('<p><img src="files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
|
||||||
|
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
|
||||||
|
$mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
|
||||||
|
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
|
||||||
|
$mail->setBody('<p><img src="/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
|
||||||
|
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
|
||||||
|
$mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/plain');
|
||||||
|
$this->assertEquals('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
|
||||||
|
|
||||||
$mail->setContentType('html');
|
$mail->setContentType('html');
|
||||||
$this->assertEquals('text/html', $mail->getContentType());
|
$this->assertEquals('text/html', $mail->getContentType());
|
||||||
$mail->setContentType('invalid');
|
$mail->setContentType('invalid');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue