- md5
- 1b4c9673b0dd8103a35a41dbdde01c27
- sha1
- 90a45207c15cd83797532f516e1f1ad8403fc84a
- sha256
- 4deae7640d8d3c65cbd5ecabce8d6d725c1d372475194a155ca1c07b5e020d92
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Uri\Uri;
defined('JPATH_PLATFORM') or die;
/**
* Utility class for cloaking email addresses
*
* @since 1.5
*/
abstract class JHtmlEmail
{
/**
* 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
HTMLHelper::_('webcomponent', 'system/joomla-hidden-mail.js', ['version' => 'auto', 'relative' => true]);
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 6 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha12. See them all, or every version of this file.