Revert "[CLEANUP] Rework/simplify copyright header and remove @package"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / EmailViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16 /**
17 * Email link view helper.
18 * Generates an email link incorporating TYPO3s spamProtectEmailAddresses-settings.
19 *
20 * = Examples
21 *
22 * <code title="basic email link">
23 * <f:link.email email="foo@bar.tld" />
24 * </code>
25 * <output>
26 * <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">foo(at)bar.tld</a>
27 * (depending on your spamProtectEmailAddresses-settings)
28 * </output>
29 *
30 * <code title="Email link with custom linktext">
31 * <f:link.email email="foo@bar.tld">some custom content</f:link.email>
32 * </code>
33 * <output>
34 * <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">some custom content</a>
35 * </output>
36 */
37 class EmailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
38
39 /**
40 * @var string
41 */
42 protected $tagName = 'a';
43
44 /**
45 * Arguments initialization
46 *
47 * @return void
48 */
49 public function initializeArguments() {
50 $this->registerUniversalTagAttributes();
51 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
52 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
53 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
54 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
55 }
56
57 /**
58 * @param string $email The email address to be turned into a link.
59 * @return string Rendered email link
60 */
61 public function render($email) {
62 if (TYPO3_MODE === 'FE') {
63 list($linkHref, $linkText) = $GLOBALS['TSFE']->cObj->getMailTo($email, $email);
64 } else {
65 $linkHref = 'mailto:' . $email;
66 $linkText = $email;
67 }
68 $tagContent = $this->renderChildren();
69 if ($tagContent !== NULL) {
70 $linkText = $tagContent;
71 }
72 $this->tag->setContent($linkText);
73 $escapeSpecialCharacters = !isset($GLOBALS['TSFE']->spamProtectEmailAddresses) || $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii';
74 $this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters);
75 $this->tag->forceClosingTag(TRUE);
76 return $this->tag->render();
77 }
78 }