PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/html/html/email.php

https://github.com/joebushi/joomla
PHP | 98 lines | 62 code | 8 blank | 28 comment | 6 complexity | 031323e9f479c17508ed769dac8f4b1a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage HTML
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. /**
  10. * Utility class for cloaking email adresses
  11. *
  12. * @static
  13. * @package Joomla.Framework
  14. * @subpackage HTML
  15. * @since 1.5
  16. */
  17. abstract class JHtmlEmail
  18. {
  19. /**
  20. * Simple Javascript email Cloaker
  21. *
  22. * By default replaces an email with a mailto link with email cloacked
  23. */
  24. public static function cloak($mail, $mailto=1, $text='', $email=1)
  25. {
  26. // convert text
  27. $mail = JHtmlEmail::_convertEncoding($mail);
  28. // split email by @ symbol
  29. $mail = explode('@', $mail);
  30. $mail_parts = explode('.', $mail[1]);
  31. // random number
  32. $rand = rand(1, 100000);
  33. $replacement = "\n <script language='JavaScript' type='text/javascript'>";
  34. $replacement .= "\n <!--";
  35. $replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
  36. $replacement .= "\n var path = 'hr' + 'ef' + '=';";
  37. $replacement .= "\n var addy". $rand ." = '". @$mail[0] ."' + '&#64;';";
  38. $replacement .= "\n addy". $rand ." = addy". $rand ." + '". implode("' + '&#46;' + '", $mail_parts) ."';";
  39. if ($mailto) {
  40. // special handling when mail text is different from mail addy
  41. if ($text) {
  42. if ($email) {
  43. // convert text
  44. $text = JHtmlEmail::_convertEncoding($text);
  45. // split email by @ symbol
  46. $text = explode('@', $text);
  47. $text_parts = explode('.', $text[1]);
  48. $replacement .= "\n var addy_text". $rand ." = '". @$text[0] ."' + '&#64;' + '". implode("' + '&#46;' + '", @$text_parts) ."';";
  49. } else {
  50. $replacement .= "\n var addy_text". $rand ." = '". $text ."';";
  51. }
  52. $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>');";
  53. $replacement .= "\n document.write(addy_text". $rand .");";
  54. $replacement .= "\n document.write('<\/a>');";
  55. } else {
  56. $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>');";
  57. $replacement .= "\n document.write(addy". $rand .");";
  58. $replacement .= "\n document.write('<\/a>');";
  59. }
  60. } else {
  61. $replacement .= "\n document.write(addy". $rand .");";
  62. }
  63. $replacement .= "\n //-->";
  64. $replacement .= '\n </script>';
  65. // XHTML compliance `No Javascript` text handling
  66. $replacement .= "<script language='JavaScript' type='text/javascript'>";
  67. $replacement .= "\n <!--";
  68. $replacement .= "\n document.write('<span style=\'display: none;\'>');";
  69. $replacement .= "\n //-->";
  70. $replacement .= "\n </script>";
  71. $replacement .= JText::_('CLOAKING');
  72. $replacement .= "\n <script language='JavaScript' type='text/javascript'>";
  73. $replacement .= "\n <!--";
  74. $replacement .= "\n document.write('</');";
  75. $replacement .= "\n document.write('span>');";
  76. $replacement .= "\n //-->";
  77. $replacement .= "\n </script>";
  78. return $replacement;
  79. }
  80. protected static function _convertEncoding($text)
  81. {
  82. // replace vowels with character encoding
  83. $text = str_replace('a', '&#97;', $text);
  84. $text = str_replace('e', '&#101;', $text);
  85. $text = str_replace('i', '&#105;', $text);
  86. $text = str_replace('o', '&#111;', $text);
  87. $text = str_replace('u', '&#117;', $text);
  88. return $text;
  89. }
  90. }