Source for file email.php

Documentation is available at email.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Utility class for cloaking email addresses
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.5
  18.  */
  19. abstract class JHtmlEmail
  20. {
  21.     /**
  22.      * Simple JavaScript email cloaker
  23.      *
  24.      * By default replaces an email with a mailto link with email cloaked
  25.      *
  26.      * @param   string   $mail    The -mail address to cloak.
  27.      * @param   boolean  $mailto  True if text and mailing address differ
  28.      * @param   string   $text    Text for the link
  29.      * @param   boolean  $email   True if text is an e-mail address
  30.      *
  31.      * @return  string  The cloaked email.
  32.      *
  33.      * @since   1.5
  34.      */
  35.     public static function cloak($mail$mailto true$text ''$email true)
  36.     {
  37.         // Convert text
  38.         $mail static::convertEncoding($mail);
  39.  
  40.         // Split email by @ symbol
  41.         $mail explode('@'$mail);
  42.         $mail_parts explode('.'$mail[1]);
  43.  
  44.         // Random number
  45.         $rand rand(1100000);
  46.  
  47.         $replacement "<script type='text/javascript'>";
  48.         $replacement .= "\n <!--";
  49.         $replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
  50.         $replacement .= "\n var path = 'hr' + 'ef' + '=';";
  51.         $replacement .= "\n var addy" $rand " = '" @$mail[0"' + '&#64;';";
  52.         $replacement .= "\n addy" $rand " = addy" $rand " + '" implode("' + '&#46;' + '"$mail_parts"';";
  53.  
  54.         if ($mailto)
  55.         {
  56.             // Special handling when mail text is different from mail address
  57.             if ($text)
  58.             {
  59.                 if ($email)
  60.                 {
  61.                     // Convert text
  62.                     $text static::convertEncoding($text);
  63.  
  64.                     // Split email by @ symbol
  65.                     $text explode('@'$text);
  66.                     $text_parts explode('.'$text[1]);
  67.                     $replacement .= "\n var addy_text" $rand " = '" @$text[0"' + '&#64;' + '" implode("' + '&#46;' + '"@$text_parts)
  68.                         . "';";
  69.                 }
  70.                 else
  71.                 {
  72.                     $replacement .= "\n var addy_text" $rand " = '" $text "';";
  73.                 }
  74.                 $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" $rand " + '\'>');";
  75.                 $replacement .= "\n document.write(addy_text" $rand ");";
  76.                 $replacement .= "\n document.write('<\/a>');";
  77.             }
  78.             else
  79.             {
  80.                 $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" $rand " + '\'>');";
  81.                 $replacement .= "\n document.write(addy" $rand ");";
  82.                 $replacement .= "\n document.write('<\/a>');";
  83.             }
  84.         }
  85.         else
  86.         {
  87.             $replacement .= "\n document.write(addy" $rand ");";
  88.         }
  89.         $replacement .= "\n //-->";
  90.         $replacement .= '\n </script>';
  91.  
  92.         // XHTML compliance no Javascript text handling
  93.         $replacement .= "<script type='text/javascript'>";
  94.         $replacement .= "\n <!--";
  95.         $replacement .= "\n document.write('<span style=\'display: none;\'>');";
  96.         $replacement .= "\n //-->";
  97.         $replacement .= "\n </script>";
  98.         $replacement .= JText::_('JLIB_HTML_CLOAKING');
  99.         $replacement .= "\n <script type='text/javascript'>";
  100.         $replacement .= "\n <!--";
  101.         $replacement .= "\n document.write('</');";
  102.         $replacement .= "\n document.write('span>');";
  103.         $replacement .= "\n //-->";
  104.         $replacement .= "\n </script>";
  105.  
  106.         return $replacement;
  107.     }
  108.  
  109.     /**
  110.      * Convert encoded text
  111.      *
  112.      * @param   string  $text  Text to convert
  113.      *
  114.      * @return  string  The converted text.
  115.      *
  116.      * @since   1.5
  117.      */
  118.     protected static function convertEncoding($text)
  119.     {
  120.         // Replace vowels with character encoding
  121.         $text str_replace('a''&#97;'$text);
  122.         $text str_replace('e''&#101;'$text);
  123.         $text str_replace('i''&#105;'$text);
  124.         $text str_replace('o''&#111;'$text);
  125.         $text str_replace('u''&#117;'$text);
  126.  
  127.         return $text;
  128.     }
  129. }

Documentation generated on Tue, 19 Nov 2013 15:02:25 +0100 by phpDocumentor 1.4.3