API15

JHTMLEmail/cloak: Difference between revisions

From Joomla! Documentation

Tom Hutchison (talk | contribs)
Tom Hutchison (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 112: Line 112:
}
}
</source>
</source>
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JHTMLEmail/cloak|Edit See Also]]<nowiki>]</nowiki>
</span>
{{SeeAlso:JHTMLEmail/cloak}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=cloak
  category=cloak
  category=JHTMLEmail
  category=JHTMLEmail
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 00:51, 25 March 2017

Description

Simple Javascript email Cloaker

Syntax

cloak($mail, $mailto=1, $text='', $email=1, $prefix='mailto:', $suffix='', $attribs='')
Parameter Name Default Value Description
$mail
$mailto 1
$text
$email 1
$prefix 'mailto:'
$suffix
$attribs

Defined in

libraries/joomla/html/html/email.php

Importing

jimport( 'joomla.html.html.email' );

Source Body

function cloak( $mail, $mailto=1, $text='', $email=1, $prefix='mailto:', $suffix='', $attribs='' )
{
        // convert text
        $mail                   = JHTMLEmail::_convertEncoding( $mail );
        // split email by @ symbol
        $mail                   = explode( '@', $mail );
        $mail_parts             = explode( '.', $mail[1] );
        // random number
        $rand                   = rand( 1, 100000 );
// obfuscate prefix
$prefix = JHTMLEmail::_convertEncoding( $prefix );

        $replacement    = "\n <script language='JavaScript' type='text/javascript'>";
        $replacement    .= "\n <!--";
        $replacement    .= "\n var prefix = '$prefix';";
$replacement    .= "\n var suffix = '$suffix';";
$replacement    .= "\n var attribs = '$attribs';";
        $replacement    .= "\n var path = 'hr' + 'ef' + '=';";
        $replacement    .= "\n var addy". $rand ." = '". @$mail[0] ."' + '&#64;';";
        $replacement    .= "\n addy". $rand ." = addy". $rand ." + '". implode( "' + '&#46;' + '", $mail_parts ) ."';";

        if ( $mailto ) {
                // special handling when mail text is different from mail addy
                if ( $text ) {
                        if ( $email ) {
                                // convert text
                                $text                   = JHTMLEmail::_convertEncoding( $text );
                                // split email by @ symbol
                                $text                   = explode( '@', $text );
                                $text_parts             = explode( '.', $text[1] );
                                $replacement    .= "\n var addy_text". $rand ." = '". @$text[0] ."' + '&#64;' + '". implode( "' + '&#46;' + '", @$text_parts ) ."';";
                        } else {
                                $replacement    .= "\n var addy_text". $rand ." = '". $text ."';";
                        }
                        $replacement    .= "\n document.write( '<a ' + path + '\'' + prefix + addy". $rand ." + suffix + '\'' + attribs + '>' );";
                        $replacement    .= "\n document.write( addy_text". $rand ." );";
                        $replacement    .= "\n document.write( '<\/a>' );";
                } else {
                        $replacement    .= "\n document.write( '<a ' + path + '\'' + prefix + addy". $rand ." + suffix + '\'' + attribs + '>' );";
                        $replacement    .= "\n document.write( addy". $rand ." );";
                        $replacement    .= "\n document.write( '<\/a>' );";
                }
        } else {
                $replacement    .= "\n document.write( addy". $rand ." );";
        }
        $replacement    .= "\n //-->";
        $replacement    .= "\n </script> ";

        // XHTML compliance `No Javascript` text handling
        $replacement    .= "<script language='JavaScript' type='text/javascript'>";
        $replacement    .= "\n <!--";
        $replacement    .= "\n document.write( '<span style=\'display: none;\'>' );";
        $replacement    .= "\n //-->";
        $replacement    .= "\n </script>";
        $replacement    .= JText::_('CLOAKING');
        $replacement    .= "\n <script language='JavaScript' type='text/javascript'>";
        $replacement    .= "\n <!--";
        $replacement    .= "\n document.write( '</' );";
        $replacement    .= "\n document.write( 'span>' );";
        $replacement    .= "\n //-->";
        $replacement    .= "\n </script>";

        return $replacement;
}

Examples

Code Examples