mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51: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)
|
||||
{
|
||||
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('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');
|
||||
$this->assertEquals('text/html', $mail->getContentType());
|
||||
$mail->setContentType('invalid');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue