|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Fluid\ViewHelpers\Link; |
|
17
|
|
|
|
|
18
|
|
|
use TYPO3\CMS\Core\Http\ApplicationType; |
|
19
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Email link ViewHelper. |
|
23
|
|
|
* Generates an email link incorporating TYPO3s `spamProtectEmailAddresses`_ TypoScript setting. |
|
24
|
|
|
* |
|
25
|
|
|
* .. _spamProtectEmailAddresses: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Setup/Config/Index.html#spamprotectemailaddresses |
|
26
|
|
|
* |
|
27
|
|
|
* Examples |
|
28
|
|
|
* ======== |
|
29
|
|
|
* |
|
30
|
|
|
* Basic email link |
|
31
|
|
|
* ---------------- |
|
32
|
|
|
* |
|
33
|
|
|
* :: |
|
34
|
|
|
* |
|
35
|
|
|
* <f:link.email email="[email protected]" /> |
|
36
|
|
|
* |
|
37
|
|
|
* Output:: |
|
38
|
|
|
* |
|
39
|
|
|
* <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">foo(at)bar.tld</a> |
|
40
|
|
|
* |
|
41
|
|
|
* Depending on `spamProtectEmailAddresses`_ setting. |
|
42
|
|
|
* |
|
43
|
|
|
* Email link with custom linktext |
|
44
|
|
|
* ------------------------------- |
|
45
|
|
|
* |
|
46
|
|
|
* :: |
|
47
|
|
|
* |
|
48
|
|
|
* <f:link.email email="[email protected]">some custom content</f:link.email> |
|
49
|
|
|
* |
|
50
|
|
|
* Output:: |
|
51
|
|
|
* |
|
52
|
|
|
* <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">some custom content</a> |
|
53
|
|
|
* |
|
54
|
|
|
* Depending on `spamProtectEmailAddresses`_ setting. |
|
55
|
|
|
*/ |
|
56
|
|
|
class EmailViewHelper extends AbstractTagBasedViewHelper |
|
57
|
|
|
{ |
|
58
|
|
|
/** |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $tagName = 'a'; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Arguments initialization |
|
65
|
|
|
*/ |
|
66
|
|
|
public function initializeArguments() |
|
67
|
|
|
{ |
|
68
|
|
|
parent::initializeArguments(); |
|
69
|
|
|
$this->registerArgument('email', 'string', 'The email address to be turned into a link', true); |
|
70
|
|
|
$this->registerUniversalTagAttributes(); |
|
71
|
|
|
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor'); |
|
72
|
|
|
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document'); |
|
73
|
|
|
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document'); |
|
74
|
|
|
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return string Rendered email link |
|
79
|
|
|
*/ |
|
80
|
|
|
public function render() |
|
81
|
|
|
{ |
|
82
|
|
|
$email = $this->arguments['email']; |
|
83
|
|
|
|
|
84
|
|
|
if (ApplicationType::fromRequest($this->renderingContext->getRequest())->isFrontend()) { |
|
|
|
|
|
|
85
|
|
|
[$linkHref, $linkText] = $GLOBALS['TSFE']->cObj->getMailTo($email, ''); |
|
86
|
|
|
$escapeSpecialCharacters = !isset($GLOBALS['TSFE']->spamProtectEmailAddresses) || $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii'; |
|
87
|
|
|
} else { |
|
88
|
|
|
$linkHref = 'mailto:' . $email; |
|
89
|
|
|
$linkText = htmlspecialchars($email); |
|
90
|
|
|
$escapeSpecialCharacters = true; |
|
91
|
|
|
} |
|
92
|
|
|
$tagContent = $this->renderChildren(); |
|
93
|
|
|
if ($tagContent !== null) { |
|
94
|
|
|
$linkText = $tagContent; |
|
95
|
|
|
} |
|
96
|
|
|
$this->tag->setContent($linkText); |
|
97
|
|
|
$this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters); |
|
98
|
|
|
$this->tag->forceClosingTag(true); |
|
99
|
|
|
return $this->tag->render(); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|