basic functionality to implement an email obfuscator
This commit is contained in:
parent
0936237720
commit
ef59207085
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- ====================================================================== -->
|
||||
<!-- XML tag for obfuscating an email address against scaper bots -->
|
||||
<!-- ====================================================================== -->
|
||||
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:exsl="http://exslt.org/common">
|
||||
|
||||
<xsl:import href="../../tools/xsltsl/tokenize.xsl"/>
|
||||
|
||||
<!-- plain email is the input -->
|
||||
<xsl:template match="email">
|
||||
<xsl:variable name="email-plain">
|
||||
<xsl:value-of select="."></xsl:value-of>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- Split email on each character, creating a <token>character</token> element each -->
|
||||
<xsl:variable name="email-tokens">
|
||||
<xsl:call-template name="tokenize">
|
||||
<xsl:with-param name="string" select="$email-plain" />
|
||||
<xsl:with-param name="delimiters" select="''" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- Replace the most common characters with their respective HTML entity -->
|
||||
<xsl:variable name="email-encoded">
|
||||
<xsl:for-each select="exsl:node-set($email-tokens)/token">
|
||||
<xsl:choose>
|
||||
<!-- make sure only defined characters are replaced -->
|
||||
<xsl:when test="translate(text(), 'abcdefghijklmnopqrstuvwxyz0123456789.+-@','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') = 'x'">
|
||||
<xsl:text>&#</xsl:text>
|
||||
<xsl:choose>
|
||||
<xsl:when test="text()='a'">97</xsl:when>
|
||||
<xsl:when test="text()='b'">98</xsl:when>
|
||||
<xsl:when test="text()='c'">99</xsl:when>
|
||||
<xsl:when test="text()='d'">100</xsl:when>
|
||||
<xsl:when test="text()='e'">101</xsl:when>
|
||||
<xsl:when test="text()='f'">102</xsl:when>
|
||||
<xsl:when test="text()='g'">103</xsl:when>
|
||||
<xsl:when test="text()='h'">104</xsl:when>
|
||||
<xsl:when test="text()='i'">105</xsl:when>
|
||||
<xsl:when test="text()='j'">106</xsl:when>
|
||||
<xsl:when test="text()='k'">107</xsl:when>
|
||||
<xsl:when test="text()='l'">108</xsl:when>
|
||||
<xsl:when test="text()='m'">109</xsl:when>
|
||||
<xsl:when test="text()='n'">110</xsl:when>
|
||||
<xsl:when test="text()='o'">111</xsl:when>
|
||||
<xsl:when test="text()='p'">112</xsl:when>
|
||||
<xsl:when test="text()='q'">113</xsl:when>
|
||||
<xsl:when test="text()='r'">114</xsl:when>
|
||||
<xsl:when test="text()='s'">115</xsl:when>
|
||||
<xsl:when test="text()='t'">116</xsl:when>
|
||||
<xsl:when test="text()='u'">117</xsl:when>
|
||||
<xsl:when test="text()='v'">118</xsl:when>
|
||||
<xsl:when test="text()='w'">119</xsl:when>
|
||||
<xsl:when test="text()='x'">120</xsl:when>
|
||||
<xsl:when test="text()='y'">121</xsl:when>
|
||||
<xsl:when test="text()='z'">122</xsl:when>
|
||||
<xsl:when test="text()='0'">48</xsl:when>
|
||||
<xsl:when test="text()='1'">49</xsl:when>
|
||||
<xsl:when test="text()='2'">50</xsl:when>
|
||||
<xsl:when test="text()='3'">51</xsl:when>
|
||||
<xsl:when test="text()='4'">52</xsl:when>
|
||||
<xsl:when test="text()='5'">53</xsl:when>
|
||||
<xsl:when test="text()='6'">54</xsl:when>
|
||||
<xsl:when test="text()='7'">55</xsl:when>
|
||||
<xsl:when test="text()='8'">56</xsl:when>
|
||||
<xsl:when test="text()='9'">57</xsl:when>
|
||||
<xsl:when test="text()='.'">46</xsl:when>
|
||||
<xsl:when test="text()='+'">43</xsl:when>
|
||||
<xsl:when test="text()='-'">45</xsl:when>
|
||||
<xsl:when test="text()='@'">64</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:text>;</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="text()" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:variable> <!-- /$email-encoded -->
|
||||
|
||||
<!-- Output email address in desired form -->
|
||||
<xsl:choose>
|
||||
<!-- Should be a clickable mailto: link -->
|
||||
<xsl:when test="@mailto = 'yes'">
|
||||
<!--
|
||||
Note: Super-ugly hack to avoid that HTML entities are escaped in the href
|
||||
attribute. Therefore, the a element is created "manually"
|
||||
-->
|
||||
<xsl:text disable-output-escaping="yes"><a href="mailto:</xsl:text>
|
||||
<xsl:value-of select="$email-encoded" disable-output-escaping="yes" />
|
||||
<xsl:text disable-output-escaping="yes">"></xsl:text>
|
||||
<xsl:value-of select="$email-encoded" disable-output-escaping="yes" />
|
||||
<xsl:text disable-output-escaping="yes"></a></xsl:text>
|
||||
</xsl:when>
|
||||
<!-- Default: just the obfuscated email address as string -->
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$email-encoded" disable-output-escaping="yes" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
1
fsfe.xsl
1
fsfe.xsl
|
@ -18,6 +18,7 @@
|
|||
<xsl:include href="build/xslt/fsfe-cd.xsl" />
|
||||
<xsl:include href="build/xslt/module.xsl" />
|
||||
<xsl:include href="build/xslt/related.xsl" />
|
||||
<xsl:include href="build/xslt/email-obfuscate.xsl" />
|
||||
|
||||
<!-- HTML 5 compatibility doctype, since our XSLT parser doesn't support disabling output escaping -->
|
||||
<xsl:output method="html" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat" />
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:str="http://exslt.org/strings"
|
||||
extension-element-prefixes="str">
|
||||
|
||||
<xsl:template name="tokenize">
|
||||
<xsl:param name="string" select="''" />
|
||||
<xsl:param name="delimiters" select="' 	
'" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="not($string)" />
|
||||
<xsl:when test="not($delimiters)">
|
||||
<xsl:call-template name="str:_tokenize-characters">
|
||||
<xsl:with-param name="string" select="$string" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="str:_tokenize-delimiters">
|
||||
<xsl:with-param name="string" select="$string" />
|
||||
<xsl:with-param name="delimiters" select="$delimiters" />
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="str:_tokenize-characters">
|
||||
<xsl:param name="string" />
|
||||
<xsl:if test="$string">
|
||||
<token><xsl:value-of select="substring($string, 1, 1)" /></token>
|
||||
<xsl:call-template name="str:_tokenize-characters">
|
||||
<xsl:with-param name="string" select="substring($string, 2)" />
|
||||
</xsl:call-template>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="str:_tokenize-delimiters">
|
||||
<xsl:param name="string" />
|
||||
<xsl:param name="delimiters" />
|
||||
<xsl:variable name="delimiter" select="substring($delimiters, 1, 1)" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="not($delimiter)">
|
||||
<token><xsl:value-of select="$string" /></token>
|
||||
</xsl:when>
|
||||
<xsl:when test="contains($string, $delimiter)">
|
||||
<xsl:if test="not(starts-with($string, $delimiter))">
|
||||
<xsl:call-template name="str:_tokenize-delimiters">
|
||||
<xsl:with-param name="string" select="substring-before($string, $delimiter)" />
|
||||
<xsl:with-param name="delimiters" select="substring($delimiters, 2)" />
|
||||
</xsl:call-template>
|
||||
</xsl:if>
|
||||
<xsl:call-template name="str:_tokenize-delimiters">
|
||||
<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
|
||||
<xsl:with-param name="delimiters" select="$delimiters" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="str:_tokenize-delimiters">
|
||||
<xsl:with-param name="string" select="$string" />
|
||||
<xsl:with-param name="delimiters" select="substring($delimiters, 2)" />
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
Loading…
Reference in New Issue