‪TYPO3CMS  ‪main
EmailSoftReferenceParser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 {
25  public function ‪parse(string $table, string $field, int ‪$uid, string $content, string $structurePath = ''): ‪SoftReferenceParserResult
26  {
27  $this->‪setTokenIdBasePrefix($table, (string)‪$uid, $field, $structurePath);
28  $elements = [];
29  // Email:
30  $parts = preg_split('/([\s\'":<>]+)([A-Za-z0-9._-]+[^-][@][A-Za-z0-9._-]+[.].[A-Za-z0-9]+)/', ' ' . $content . ' ', 10000, PREG_SPLIT_DELIM_CAPTURE);
31  foreach ($parts as $idx => $value) {
32  if ($idx % 3 === 2) {
33  // Ignore invalid emails, which haven't been filtered out by regex.
34  if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
35  continue;
36  }
37  $tokenID = $this->‪makeTokenID((string)$idx);
38  $elements[$idx] = [];
39  $elements[$idx]['matchString'] = $value;
40  if (in_array('subst', $this->parameters, true)) {
41  $parts[$idx] = '{softref:' . $tokenID . '}';
42  $elements[$idx]['subst'] = [
43  'type' => 'string',
44  'tokenID' => $tokenID,
45  'tokenValue' => $value,
46  ];
47  }
48  }
49  }
50 
52  substr(implode('', $parts), 1, -1),
53  $elements
54  );
55  }
56 }
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser\setTokenIdBasePrefix
‪setTokenIdBasePrefix(string $table, string $uid, string $field, string $structurePath)
Definition: AbstractSoftReferenceParser.php:55
‪TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult\create
‪static create(string $content, array $elements)
Definition: SoftReferenceParserResult.php:48
‪TYPO3\CMS\Core\DataHandling\SoftReference\EmailSoftReferenceParser
Definition: EmailSoftReferenceParser.php:24
‪TYPO3\CMS\Core\DataHandling\SoftReference\EmailSoftReferenceParser\parse
‪parse(string $table, string $field, int $uid, string $content, string $structurePath='')
Definition: EmailSoftReferenceParser.php:25
‪TYPO3\CMS\Core\DataHandling\SoftReference
Definition: AbstractSoftReferenceParser.php:18
‪TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult
Definition: SoftReferenceParserResult.php:43
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser\makeTokenID
‪string makeTokenID(string $index='')
Definition: AbstractSoftReferenceParser.php:35
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser
Definition: AbstractSoftReferenceParser.php:24