PageRenderTime 36ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 129 lines | 73 code | 11 blank | 45 comment | 3 complexity | 07af7ef05ccfd19549d5486a2c8146a9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage HTML
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Utility class for cloaking email addresses
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage HTML
  15. * @since 11.1
  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 cloaked
  23. *
  24. * @param string $mail The -mail address to cloak.
  25. * @param boolean $mailto True if text and mailing address differ
  26. * @param string $text Text for the link
  27. * @param boolean $email True if text is an e-mail address
  28. *
  29. * @return string The cloaked email.
  30. *
  31. * @since 11.1
  32. */
  33. public static function cloak($mail, $mailto = true, $text = '', $email = true)
  34. {
  35. // Convert text
  36. $mail = self::_convertEncoding($mail);
  37. // Split email by @ symbol
  38. $mail = explode('@', $mail);
  39. $mail_parts = explode('.', $mail[1]);
  40. // Random number
  41. $rand = rand(1, 100000);
  42. $replacement = "\n <script type='text/javascript'>";
  43. $replacement .= "\n <!--";
  44. $replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
  45. $replacement .= "\n var path = 'hr' + 'ef' + '=';";
  46. $replacement .= "\n var addy" . $rand . " = '" . @$mail[0] . "' + '&#64;';";
  47. $replacement .= "\n addy" . $rand . " = addy" . $rand . " + '" . implode("' + '&#46;' + '", $mail_parts) . "';";
  48. if ($mailto)
  49. {
  50. // Special handling when mail text is different from mail address
  51. if ($text)
  52. {
  53. if ($email)
  54. {
  55. // Convert text
  56. $text = self::_convertEncoding($text);
  57. // Split email by @ symbol
  58. $text = explode('@', $text);
  59. $text_parts = explode('.', $text[1]);
  60. $replacement .= "\n var addy_text" . $rand . " = '" . @$text[0] . "' + '&#64;' + '" . implode("' + '&#46;' + '", @$text_parts)
  61. . "';";
  62. }
  63. else
  64. {
  65. $replacement .= "\n var addy_text" . $rand . " = '" . $text . "';";
  66. }
  67. $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" . $rand . " + '\'>');";
  68. $replacement .= "\n document.write(addy_text" . $rand . ");";
  69. $replacement .= "\n document.write('<\/a>');";
  70. }
  71. else
  72. {
  73. $replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" . $rand . " + '\'>');";
  74. $replacement .= "\n document.write(addy" . $rand . ");";
  75. $replacement .= "\n document.write('<\/a>');";
  76. }
  77. }
  78. else
  79. {
  80. $replacement .= "\n document.write(addy" . $rand . ");";
  81. }
  82. $replacement .= "\n //-->";
  83. $replacement .= '\n </script>';
  84. // XHTML compliance no Javascript text handling
  85. $replacement .= "<script type='text/javascript'>";
  86. $replacement .= "\n <!--";
  87. $replacement .= "\n document.write('<span style=\'display: none;\'>');";
  88. $replacement .= "\n //-->";
  89. $replacement .= "\n </script>";
  90. $replacement .= JText::_('JLIB_HTML_CLOAKING');
  91. $replacement .= "\n <script type='text/javascript'>";
  92. $replacement .= "\n <!--";
  93. $replacement .= "\n document.write('</');";
  94. $replacement .= "\n document.write('span>');";
  95. $replacement .= "\n //-->";
  96. $replacement .= "\n </script>";
  97. return $replacement;
  98. }
  99. /**
  100. * Convert encoded text
  101. *
  102. * @param string $text Text to convert
  103. *
  104. * @return string The converted text.
  105. *
  106. * @since 11.1
  107. */
  108. protected static function _convertEncoding($text)
  109. {
  110. // Replace vowels with character encoding
  111. $text = str_replace('a', '&#97;', $text);
  112. $text = str_replace('e', '&#101;', $text);
  113. $text = str_replace('i', '&#105;', $text);
  114. $text = str_replace('o', '&#111;', $text);
  115. $text = str_replace('u', '&#117;', $text);
  116. return $text;
  117. }
  118. }