Warning: file_put_contents() [function.file-put-contents]: Only 0 of 196 bytes written, possibly out of free disk space in /disk2/home/symphonyweb/public_html/extensions/xmlfield/fields/field.xml.php on line 63
“E-mail link” – XSLT Utilities – Download – Symphony.
Author:
TwistedInteractive
Version:
1.0
Release Date:
28 Jun 2011
Category:
String Operations

Description

Generates human-unreadable e-mail addresses in your source-code, while using JavaScript to convert these to clickable e-mail addresses on the go!

Usage:

On pages where you want to use this template, you first need to include a small javascript-function called 'strtr'. You can do this with the following XSLT:

<xsl:call-template name="strtr-function" />

Secondly, to create an e-mail link use:

<xsl:call-template name="e-mail-link">
    <xsl:with-param name="e-mail" select="e-mail-address (for example)" />
    <xsl:with-param name="value" select="'Send a mail'" />
</xsl:call-template>

Optional parameters are attributes to add to the anchor-tag:

  • class
  • id
  • title
  • rel

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--
        E-mail links

        Generates human-unreadable e-mail addresses in your source-code, while
        using JavaScript to convert these to clickable e-mail addresses on the go!

        Usage:
            On pages where you want to use this template, you first need to include a small
            javascript-function called 'strtr'. You can do this with the following XSLT:

            <xsl:call-template name="strtr-function" />

            Secondly, to create an e-mail link use:

            <xsl:call-template name="e-mail-link">
                <xsl:with-param name="e-mail" select="e-mail-address (for example)" />
                <xsl:with-param name="value" select="'Send a mail'" />
            </xsl:call-template>

            Optional parameters are attributes to add to the anchor-tag:
            - class
            - id
            - title
            - rel
    -->

	<xsl:template name="e-mail-link">
		<xsl:param name="e-mail" />
		<xsl:param name="class" />
		<xsl:param name="id" />
		<xsl:param name="title" />
		<xsl:param name="rel" />
		<xsl:param name="value" />
		
		<!-- shift-row: -->
		<xsl:variable name="translated-email">
			<xsl:value-of select="translate($e-mail,
				'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
				'qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP')" />
		</xsl:variable>
		
		<a>
			<xsl:if test="$class != ''">
				<xsl:attribute name="class">
					<xsl:value-of select="$class" />
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="$id != ''">
				<xsl:attribute name="id">
					<xsl:value-of select="$id" />
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="$title != ''">
				<xsl:attribute name="title">
					<xsl:value-of select="$title" />
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="$rel != ''">
				<xsl:attribute name="rel">
					<xsl:value-of select="$rel" />
				</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="href">javascript:(function(){window.location='mailto:' + strtr('<xsl:value-of select="$translated-email" />', 'qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');})();</xsl:attribute>
			<xsl:value-of select="$value" />
		</a>
	</xsl:template>
	
	<xsl:template name="strtr-function">
		<script type="text/javascript">
            function strtr(e,b,f){var g="",c=0,a=0,i=0,h=0,d=false,j="",k="",l="";c=[];a=[];var m="";d=false;if(typeof b==="object"){d=this.ini_set("phpjs.strictForIn",false);b=this.krsort(b);this.ini_set("phpjs.strictForIn",d);for(g in b)if(b.hasOwnProperty(g)){c.push(g);a.push(b[g])}b=c;f=a}i=e.length;h=b.length;j=typeof b==="string";k=typeof f==="string";for(c=0;c!=i;c++){d=false;if(j){l=e.charAt(c);for(a=0;a!=h;a++)if(l==b.charAt(a)){d=true;break}}else for(a=0;a!=h;a++)if(e.substr(c,b[a].length)==b[a]){d=true;c=c+b[a].length-1;break}m+=d?k?f.charAt(a):f[a]:e.charAt(c)}return m};
		</script>
	</xsl:template>
</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details