- md5
- 10432f22d68e4dc0b6c7f9806953271b
- sha1
- 343a699b9c4caa71cc35112e6bace877993f0c00
- sha256
- 7628aeb7446a4ed39cbc5e39c232c55528aafc20a4c2e77a6ddc33023b45f5dd
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\HTML\Helpers;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Uri\Uri;
/**
* Utility class for cloaking email addresses
*
* @since 1.5
*/
abstract class Email
{
/**
* Simple JavaScript email cloaker
*
* By default replaces an email with a mailto link with email cloaked
*
* @param string $mail The -mail address to cloak.
* @param boolean $mailto True if text and mailing address differ
* @param string $text Text for the link
* @param boolean $email True if text is an email address
* @param string $attribsBefore Any attributes before the email address
* @param string $attribsAfter Any attributes before the email address
*
* @return string The cloaked email.
*
* @since 1.5
*/
public static function cloak($mail, $mailto = true, $text = '', $email = true, $attribsBefore = '', $attribsAfter = '')
{
// Handle IDN addresses: punycode for href but utf-8 for text displayed.
if ($mailto && (empty($text) || $email)) {
// Use dedicated $text whereas $mail is used as href and must be punycoded.
$text = PunycodeHelper::emailToUTF8($text ?: $mail);
} elseif (!$mailto) {
// In that case we don't use link - so convert $mail back to utf-8.
$mail = PunycodeHelper::emailToUTF8($mail);
}
// Split email by @ symbol
$mail = explode('@', $mail);
$name = @$mail[0];
$domain = @$mail[1];
// Include the email cloaking script
Factory::getDocument()->getWebAssetManager()
->useScript('webcomponent.hidden-mail');
return '<joomla-hidden-mail '
. $attribsBefore . ' is-link="'
. $mailto . '" is-email="'
. $email . '" first="'
. base64_encode($name) . '" last="'
. base64_encode($domain) . '" text="'
. base64_encode($text) . '" base="'
. Uri::root(true) . '" ' . $attribsAfter . '>' . Text::_('JLIB_HTML_CLOAKING') . '</joomla-hidden-mail>';
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.