Rework using Gemini
This commit is contained in:
1 parent
911b8864ca
commit
8660ea6173
28 files changed
+872
-73
No files matched your search
@@ -36,4 +36,91 @@ class Helper {
|
||||
|
||||
return ($dialogShowFrom <= $today && $until > $today);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an obfuscated email link to protect against automated spambot harvesting.
|
||||
* Raw HTML contains no plain email address or mailto: link.
|
||||
* Splitting into data attributes with CSS bidi-override fallback renders correctly visually,
|
||||
* while JavaScript dynamically activates the live mailto link for real human visitors.
|
||||
*
|
||||
* @param string $email
|
||||
* @param string|null $label Optional text/label before or wrapping the email
|
||||
* @param array $attrs Optional HTML attributes (class, style, title, icon, etc.)
|
||||
* @return string
|
||||
*/
|
||||
public static function obfuscateEmail($email, $label = null, $attrs = []) {
|
||||
if (strpos($email, '@') === false) {
|
||||
return htmlspecialchars($email);
|
||||
}
|
||||
list($user, $domainPart) = explode('@', $email, 2);
|
||||
$lastDot = strrpos($domainPart, '.');
|
||||
if ($lastDot !== false) {
|
||||
$domain = substr($domainPart, 0, $lastDot);
|
||||
$tld = substr($domainPart, $lastDot + 1);
|
||||
} else {
|
||||
$domain = $domainPart;
|
||||
$tld = '';
|
||||
}
|
||||
|
||||
$reversed = strrev($email);
|
||||
$baseClass = isset($attrs['class']) ? $attrs['class'] . ' mail-obf' : 'mail-obf';
|
||||
$title = isset($attrs['title']) ? ' title="' . htmlspecialchars($attrs['title']) . '"' : '';
|
||||
$style = isset($attrs['style']) ? ' style="' . htmlspecialchars($attrs['style']) . '"' : '';
|
||||
$id = isset($attrs['id']) ? ' id="' . htmlspecialchars($attrs['id']) . '"' : '';
|
||||
|
||||
$content = '';
|
||||
if (isset($attrs['icon']) && !empty($attrs['icon'])) {
|
||||
$content .= $attrs['icon'] . ' ';
|
||||
}
|
||||
|
||||
if ($label !== null && $label !== '') {
|
||||
$content .= htmlspecialchars($label) . ' ';
|
||||
}
|
||||
|
||||
$content .= '<span class="mail-val c-rev">' . htmlspecialchars($reversed) . '</span>';
|
||||
|
||||
return sprintf(
|
||||
'<a href="javascript:void(0);" class="%s" data-usr="%s" data-dom="%s" data-tld="%s"%s%s%s>%s</a>',
|
||||
htmlspecialchars($baseClass),
|
||||
htmlspecialchars($user),
|
||||
htmlspecialchars($domain),
|
||||
htmlspecialchars($tld),
|
||||
$title,
|
||||
$style,
|
||||
$id,
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obfuscate plain text email (non-link).
|
||||
*/
|
||||
public static function obfuscateEmailText($email, $attrs = []) {
|
||||
if (strpos($email, '@') === false) {
|
||||
return htmlspecialchars($email);
|
||||
}
|
||||
list($user, $domainPart) = explode('@', $email, 2);
|
||||
$lastDot = strrpos($domainPart, '.');
|
||||
if ($lastDot !== false) {
|
||||
$domain = substr($domainPart, 0, $lastDot);
|
||||
$tld = substr($domainPart, $lastDot + 1);
|
||||
} else {
|
||||
$domain = $domainPart;
|
||||
$tld = '';
|
||||
}
|
||||
|
||||
$reversed = strrev($email);
|
||||
$baseClass = isset($attrs['class']) ? $attrs['class'] . ' mail-obf-text' : 'mail-obf-text';
|
||||
$style = isset($attrs['style']) ? ' style="' . htmlspecialchars($attrs['style']) . '"' : '';
|
||||
|
||||
return sprintf(
|
||||
'<span class="%s" data-usr="%s" data-dom="%s" data-tld="%s"%s><span class="mail-val c-rev">%s</span></span>',
|
||||
htmlspecialchars($baseClass),
|
||||
htmlspecialchars($user),
|
||||
htmlspecialchars($domain),
|
||||
htmlspecialchars($tld),
|
||||
$style,
|
||||
htmlspecialchars($reversed)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user