TYPO3 API  SVNRelease
EmailViewHelper.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script is part of the TYPO3 project - inspiring people to share!  *
00005  *                                                                        *
00006  * TYPO3 is free software; you can redistribute it and/or modify it under *
00007  * the terms of the GNU General Public License version 2 as published by  *
00008  * the Free Software Foundation.                                          *
00009  *                                                                        *
00010  * This script is distributed in the hope that it will be useful, but     *
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00012  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
00013  * Public License for more details.                                       *
00014  *                                                                        */
00015 
00016 /**
00017  */
00018 
00019 /**
00020  * Email link view helper.
00021  * Generates an email link incorporating TYPO3s spamProtectEmailAddresses-settings.
00022  *
00023  * = Examples
00024  *
00025  * <code title="basic email link">
00026  * <f:link.email email="foo@bar.tld" />
00027  * </code>
00028  * <output>
00029  * <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">foo(at)bar.tld</a>
00030  * (depending on your spamProtectEmailAddresses-settings)
00031  * </output>
00032  *
00033  * <code title="Email link with custom linktext">
00034  * <f:link.email email="foo@bar.tld">some custom content</f:link.email>
00035  * </code>
00036  * <output>
00037  * <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">some custom content</a>
00038  * </output>
00039  *
00040  */
00041 class Tx_Fluid_ViewHelpers_Link_EmailViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
00042 
00043     /**
00044      * @var string
00045      */
00046     protected $tagName = 'a';
00047 
00048     /**
00049      * Arguments initialization
00050      *
00051      * @return void
00052      * @author Bastian Waidelich <bastian@typo3.org>
00053      */
00054     public function initializeArguments() {
00055         $this->registerUniversalTagAttributes();
00056         $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
00057         $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
00058         $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
00059         $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
00060     }
00061 
00062     /**
00063      * @param string $email The email address to be turned into a link.
00064      * @return string Rendered email link
00065      * @author Bastian Waidelich <bastian@typo3.org>
00066      */
00067     public function render($email) {
00068         if (TYPO3_MODE === 'FE') {
00069             list($linkHref, $linkText) = $GLOBALS['TSFE']->cObj->getMailTo($email, $email);
00070         } else {
00071             $linkHref = 'mailto:' . $email;
00072             $linkText = $email;
00073         }
00074         $tagContent = $this->renderChildren();
00075         if ($tagContent !== NULL) {
00076             $linkText = $tagContent;
00077         }
00078         $this->tag->setContent($linkText);
00079         $this->tag->addAttribute('href', $linkHref);
00080 
00081         return $this->tag->render();
00082     }
00083 }
00084 
00085 
00086 ?>